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