Array support
[IRC.git] / Robust / src / IR / Tree / CreateObjectNode.java
1 package IR.Tree;
2 import java.util.Vector;
3 import IR.TypeDescriptor;
4 import IR.MethodDescriptor;
5
6 public class CreateObjectNode extends ExpressionNode {
7     TypeDescriptor td;
8     Vector argumentlist;
9     MethodDescriptor md;
10
11     public CreateObjectNode(TypeDescriptor type) {
12         td=type;
13         argumentlist=new Vector();
14     }
15
16     public void addArgument(ExpressionNode en) {
17         argumentlist.add(en);
18     }
19
20     public void setConstructor(MethodDescriptor md) {
21         this.md=md;
22     }
23
24     public MethodDescriptor getConstructor() {
25         return md;
26     }
27
28     public TypeDescriptor getType() {
29         return td;
30     }
31
32     public int numArgs() {
33         return argumentlist.size();
34     }
35
36     public ExpressionNode getArg(int i) {
37         return (ExpressionNode) argumentlist.get(i);
38     }
39
40     public String printNode(int indent) {
41         String st;
42         boolean isarray=td.isArray();
43         if (isarray)
44             st="new "+td.toString()+"[";
45         else
46             st="new "+td.toString()+"(";
47         for(int i=0;i<argumentlist.size();i++) {
48             ExpressionNode en=(ExpressionNode)argumentlist.get(i);
49             st+=en.printNode(indent);
50             if ((i+1)!=argumentlist.size()) {
51                 if (isarray) 
52                     st+="][";
53                 else
54                     st+=", ";
55             }
56         }
57         if (isarray)
58             return st+"]";
59         else
60             return st+")";
61     }
62
63     public int kind() {
64         return Kind.CreateObjectNode;
65     }
66 }