6851ea892bd6ebc2ed73d1f665ca015659b14ef4
[IRC.git] / Robust / src / IR / Tree / BlockNode.java
1 package IR.Tree;
2 import java.util.Vector;
3
4 class BlockNode extends TreeNode {
5     Vector blockstatements;
6     int printStyle=0;
7     public final static int NORMAL=0;
8     public final static int NOBRACES=1;
9     public final static int EXPRLIST=2;
10     
11     public BlockNode() {
12         blockstatements=new Vector();
13     }
14
15     public void addBlockStatement(BlockStatementNode bsn) {
16         blockstatements.add(bsn);
17     }
18     public void setStyle(int style) {
19         printStyle=style;
20     }
21
22     public String printNode(int indent) {
23         if (printStyle==NORMAL) {
24             String st="{\n";
25             for(int i=0;i<blockstatements.size();i++) {
26                 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
27                 st+=printSpace(indent+INDENT)+bsn.printNode(indent+INDENT);
28                 if (!((bsn instanceof SubBlockNode)||
29                       (bsn instanceof LoopNode)||
30                       (bsn instanceof IfStatementNode)))
31                     st+=";\n";
32                 if (bsn instanceof IfStatementNode)
33                     st+="\n";
34             }
35             st+=printSpace(indent)+"}";
36             return st;
37         } else if (printStyle==NOBRACES) {
38             String st="";
39             for(int i=0;i<blockstatements.size();i++) {
40                 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
41                 st+=printSpace(indent)+bsn.printNode(indent);
42                 if (!((bsn instanceof SubBlockNode)||
43                       (bsn instanceof LoopNode)||
44                       (bsn instanceof IfStatementNode)))
45                     st+=";";
46             }
47             return st;
48         } else if (printStyle==EXPRLIST) {
49             String st="";
50             for(int i=0;i<blockstatements.size();i++) {
51                 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
52                 st+=bsn.printNode(0);
53                 if ((i+1)!=blockstatements.size())
54                     st+=", ";
55             }
56             return st;
57         } else throw new Error();
58     }
59 }