Changes
[IRC.git] / Robust / src / IR / Tree / LoopNode.java
1 package IR.Tree;
2
3 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 String printNode(int indent) {
30         if (type==FORLOOP) {
31             return "for("+initializer.printNode(0)+";"+condition.printNode(0)+
32                 ";"+update.printNode(0)+") "+body.printNode(indent)+"\n";
33         } else if (type==WHILELOOP) {
34             return "while("+condition.printNode(0)+") "+body.printNode(indent+INDENT)+"\n";
35         } else if (type==DOWHILELOOP) {
36             return "do "+ body.printNode(indent+INDENT)+
37                 "while("+condition.printNode(0)+")\n";
38         } else throw new Error();
39     }
40
41     public int kind() {
42         return Kind.LoopNode;
43     }
44 }