adding a test case
[IRC.git] / Robust / src / IR / Tree / LoopNode.java
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   String label=null;
13
14   public LoopNode(BlockNode initializer,ExpressionNode condition, BlockNode update, BlockNode body, String label) {
15     this.initializer=initializer;
16     this.condition=condition;
17     this.update=update;
18     this.body=body;
19     initializer.setStyle(BlockNode.EXPRLIST);
20     update.setStyle(BlockNode.EXPRLIST);
21     type=FORLOOP;
22     this.label=label;
23   }
24
25   public LoopNode(ExpressionNode condition, BlockNode body, int type, String label) {
26     this.condition=condition;
27     this.body=body;
28     this.type=type;
29     this.label=label;
30   }
31
32   public BlockNode getInitializer() {
33     return initializer;
34   }
35
36   public ExpressionNode getCondition() {
37     return condition;
38   }
39
40   public BlockNode getUpdate() {
41     return update;
42   }
43
44   public BlockNode getBody() {
45     return body;
46   }
47
48   public String printNode(int indent) {
49     if (type==FORLOOP) {
50       return "for("+initializer.printNode(0)+";"+condition.printNode(0)+
51              ";"+update.printNode(0)+") "+body.printNode(indent)+"\n";
52     } else if (type==WHILELOOP) {
53       return "while("+condition.printNode(0)+") "+body.printNode(indent+INDENT)+"\n";
54     } else if (type==DOWHILELOOP) {
55       return "do "+ body.printNode(indent+INDENT)+
56              "while("+condition.printNode(0)+")\n";
57     } else throw new Error();
58   }
59
60   public int getType() {
61     return type;
62   }
63
64   public int kind() {
65     return Kind.LoopNode;
66   }
67   
68   public void setLabel(String l) {
69     label=l;
70   }
71
72   public String getLabel() {
73     return label;
74   }
75 }