94179eea6be06b0784de6ef07e9d915311d15b61
[IRC.git] / Robust / src / IR / Tree / BlockNode.java
1 package IR.Tree;
2 import java.util.Vector;
3
4 public 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
19     public void setStyle(int style) {
20         printStyle=style;
21     }
22
23     public int size() {
24         return blockstatements.size();
25     }
26
27     public BlockStatementNode get(int i) {
28         return (BlockStatementNode) blockstatements.get(i);
29     }
30
31     public String printNode(int indent) {
32         if (printStyle==NORMAL) {
33             String st="{\n";
34             for(int i=0;i<blockstatements.size();i++) {
35                 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
36                 st+=printSpace(indent+INDENT)+bsn.printNode(indent+INDENT);
37                 if (!((bsn instanceof SubBlockNode)||
38                       (bsn instanceof LoopNode)||
39                       (bsn instanceof IfStatementNode)))
40                     st+=";\n";
41                 if (bsn instanceof IfStatementNode)
42                     st+="\n";
43             }
44             st+=printSpace(indent)+"}";
45             return st;
46         } else if (printStyle==NOBRACES) {
47             String st="";
48             for(int i=0;i<blockstatements.size();i++) {
49                 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
50                 st+=printSpace(indent)+bsn.printNode(indent);
51                 if (!((bsn instanceof SubBlockNode)||
52                       (bsn instanceof LoopNode)||
53                       (bsn instanceof IfStatementNode)))
54                     st+=";";
55             }
56             return st;
57         } else if (printStyle==EXPRLIST) {
58             String st="";
59             for(int i=0;i<blockstatements.size();i++) {
60                 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
61                 st+=bsn.printNode(0);
62                 if ((i+1)!=blockstatements.size())
63                     st+=", ";
64             }
65             return st;
66         } else throw new Error();
67     }
68     
69     public int kind() {
70         return Kind.BlockNode;
71     }
72 }