Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[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   String label=null;
15
16   public BlockNode() {
17     blockstatements=new Vector();
18     table=new SymbolTable();
19   }
20
21   public SymbolTable getVarTable() {
22     return table;
23   }
24
25   public void addBlockStatement(BlockStatementNode bsn) {
26     blockstatements.add(bsn);
27   }
28
29   public void addFirstBlockStatement(BlockStatementNode bsn) {
30     blockstatements.insertElementAt(bsn,0);
31   }
32
33   public void addBlockStatementAt(BlockStatementNode bsn, int i) {
34     blockstatements.insertElementAt(bsn,i);
35   }
36
37   public void setStyle(int style) {
38     printStyle=style;
39   }
40
41   public int size() {
42     return blockstatements.size();
43   }
44
45   public BlockStatementNode get(int i) {
46     return (BlockStatementNode) blockstatements.get(i);
47   }
48
49   public String printNode(int indent) {
50     if (printStyle==NORMAL) {
51       String st="{\n";
52       for(int i=0; i<blockstatements.size(); i++) {
53         BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
54         st+=printSpace(indent+INDENT)+bsn.printNode(indent+INDENT);
55         if (!((bsn instanceof SubBlockNode)||
56               (bsn instanceof LoopNode)||
57               (bsn instanceof IfStatementNode)))
58           st+=";\n";
59         if (bsn instanceof IfStatementNode)
60           st+="\n";
61       }
62       st+=printSpace(indent)+"}";
63       return st;
64     } else if (printStyle==NOBRACES) {
65       String st="";
66       for(int i=0; i<blockstatements.size(); i++) {
67         BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
68         st+=printSpace(indent)+bsn.printNode(indent);
69         if (!((bsn instanceof SubBlockNode)||
70               (bsn instanceof LoopNode)||
71               (bsn instanceof IfStatementNode)))
72           st+=";";
73       }
74       return st;
75     } else if (printStyle==EXPRLIST) {
76       String st="";
77       for(int i=0; i<blockstatements.size(); i++) {
78         BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
79         st+=bsn.printNode(0);
80         if ((i+1)!=blockstatements.size())
81           st+=", ";
82       }
83       return st;
84     } else throw new Error();
85   }
86
87   public int kind() {
88     return Kind.BlockNode;
89   }
90
91   public void setLabel(String l) {
92     label=l;
93   }
94
95   public String getLabel() {
96     return label;
97   }
98
99 }