checking in changes
[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 setStyle(int style) {
28         printStyle=style;
29     }
30
31     public int size() {
32         return blockstatements.size();
33     }
34
35     public BlockStatementNode get(int i) {
36         return (BlockStatementNode) blockstatements.get(i);
37     }
38
39     public String printNode(int indent) {
40         if (printStyle==NORMAL) {
41             String st="{\n";
42             for(int i=0;i<blockstatements.size();i++) {
43                 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
44                 st+=printSpace(indent+INDENT)+bsn.printNode(indent+INDENT);
45                 if (!((bsn instanceof SubBlockNode)||
46                       (bsn instanceof LoopNode)||
47                       (bsn instanceof IfStatementNode)))
48                     st+=";\n";
49                 if (bsn instanceof IfStatementNode)
50                     st+="\n";
51             }
52             st+=printSpace(indent)+"}";
53             return st;
54         } else if (printStyle==NOBRACES) {
55             String st="";
56             for(int i=0;i<blockstatements.size();i++) {
57                 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
58                 st+=printSpace(indent)+bsn.printNode(indent);
59                 if (!((bsn instanceof SubBlockNode)||
60                       (bsn instanceof LoopNode)||
61                       (bsn instanceof IfStatementNode)))
62                     st+=";";
63             }
64             return st;
65         } else if (printStyle==EXPRLIST) {
66             String st="";
67             for(int i=0;i<blockstatements.size();i++) {
68                 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
69                 st+=bsn.printNode(0);
70                 if ((i+1)!=blockstatements.size())
71                     st+=", ";
72             }
73             return st;
74         } else throw new Error();
75     }
76     
77     public int kind() {
78         return Kind.BlockNode;
79     }
80 }