changes on the loop termination analysis: associate a labeled statement with a corres...
[IRC.git] / Robust / src / IR / Tree / BlockNode.java
1 package IR.Tree;
2 import java.util.Vector;
3 import IR.*;
4
5 public class BlockNode extends TreeNode {
6   Vector blockstatements;
7   int printStyle=0;
8   protected SymbolTable table;
9
10   public final static int NORMAL=0;
11   public final static int NOBRACES=1;
12   public final static int EXPRLIST=2;
13
14   public BlockNode() {
15     blockstatements=new Vector();
16     table=new SymbolTable();
17   }
18
19   public SymbolTable getVarTable() {
20     return table;
21   }
22
23   public void addBlockStatement(BlockStatementNode bsn) {
24     blockstatements.add(bsn);
25   }
26
27   public void addFirstBlockStatement(BlockStatementNode bsn) {
28     blockstatements.insertElementAt(bsn,0);
29   }
30
31   public void addBlockStatementAt(BlockStatementNode bsn, int i) {
32     blockstatements.insertElementAt(bsn,i);
33   }
34
35   public void setStyle(int style) {
36     printStyle=style;
37   }
38
39   public int size() {
40     return blockstatements.size();
41   }
42
43   public BlockStatementNode get(int i) {
44     return (BlockStatementNode) blockstatements.get(i);
45   }
46
47   public String printNode(int indent) {
48     if (printStyle==NORMAL) {
49       String st="{\n";
50       for(int i=0; i<blockstatements.size(); i++) {
51         BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
52         st+=printSpace(indent+INDENT)+bsn.printNode(indent+INDENT);
53         if (!((bsn instanceof SubBlockNode)||
54               (bsn instanceof LoopNode)||
55               (bsn instanceof IfStatementNode)))
56           st+=";\n";
57         if (bsn instanceof IfStatementNode)
58           st+="\n";
59       }
60       st+=printSpace(indent)+"}";
61       return st;
62     } else if (printStyle==NOBRACES) {
63       String st="";
64       for(int i=0; i<blockstatements.size(); i++) {
65         BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
66         st+=printSpace(indent)+bsn.printNode(indent);
67         if (!((bsn instanceof SubBlockNode)||
68               (bsn instanceof LoopNode)||
69               (bsn instanceof IfStatementNode)))
70           st+=";";
71       }
72       return st;
73     } else if (printStyle==EXPRLIST) {
74       String st="";
75       for(int i=0; i<blockstatements.size(); i++) {
76         BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
77         st+=bsn.printNode(0);
78         if ((i+1)!=blockstatements.size())
79           st+=", ";
80       }
81       return st;
82     } else throw new Error();
83   }
84
85   public int kind() {
86     return Kind.BlockNode;
87   }
88
89 }