This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 package IR.Tree;
2
3 public class LoopNode extends BlockStatementNode {
4     BlockNode initializer;
5     ExpressionNode condition;
6     BlockNode update;
7     BlockNode body;
8     int type=0;
9     public static int FORLOOP=1;
10     public static int WHILELOOP=2;
11     public static int DOWHILELOOP=3;
12
13     public LoopNode(BlockNode initializer,ExpressionNode condition, BlockNode update, BlockNode body) {
14         this.initializer=initializer;
15         this.condition=condition;
16         this.update=update;
17         this.body=body;
18         initializer.setStyle(BlockNode.EXPRLIST);
19         update.setStyle(BlockNode.EXPRLIST);
20         type=FORLOOP;
21     }
22
23     public LoopNode(ExpressionNode condition, BlockNode body, int type) {
24         this.condition=condition;
25         this.body=body;
26         this.type=type;
27     }
28     
29     public BlockNode getInitializer() {
30         return initializer;
31     }
32
33     public ExpressionNode getCondition() {
34         return condition;
35     }
36
37     public BlockNode getUpdate() {
38         return update;
39     }
40
41     public BlockNode getBody() {
42         return body;
43     }
44
45     public String printNode(int indent) {
46         if (type==FORLOOP) {
47             return "for("+initializer.printNode(0)+";"+condition.printNode(0)+
48                 ";"+update.printNode(0)+") "+body.printNode(indent)+"\n";
49         } else if (type==WHILELOOP) {
50             return "while("+condition.printNode(0)+") "+body.printNode(indent+INDENT)+"\n";
51         } else if (type==DOWHILELOOP) {
52             return "do "+ body.printNode(indent+INDENT)+
53                 "while("+condition.printNode(0)+")\n";
54         } else throw new Error();
55     }
56
57     public int getType() {
58         return type;
59     }
60
61     public int kind() {
62         return Kind.LoopNode;
63     }
64 }