adding a test case
[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 import IR.Tree.ExpressionNode;
6
7 public class CreateObjectNode extends ExpressionNode {
8   TypeDescriptor td;
9   Vector argumentlist;
10   MethodDescriptor md;
11   FlagEffects fe;
12   boolean isglobal;
13   String disjointId;
14   ArrayInitializerNode ain;
15 //The next 2 are unused but i will delete them once i am fully done with inner classes.
16   TypeDescriptor surroundingClass;
17   boolean isCreatedFromSurroundingClassName;
18   
19   ExpressionNode surroundingClassObject;
20   boolean isSurroundingClassExpSet;
21
22   public CreateObjectNode(TypeDescriptor type, boolean isglobal, String disjointId) {
23     td=type;
24    // surroundingClass = new TypeDescriptor("becauseTDdoesnthavedefaultconstructor");
25     argumentlist=new Vector();
26     this.isglobal=isglobal;
27     this.disjointId=disjointId;
28     this.ain = null;
29     isSurroundingClassExpSet = false;
30   }
31
32   public boolean isGlobal() {
33     return isglobal;
34   }
35
36   public String getDisjointId() {
37     return disjointId;
38   }
39
40   public void addFlagEffects(FlagEffects fe) {
41     this.fe=fe;
42   }
43
44   public FlagEffects getFlagEffects() {
45     return fe;
46   }
47
48   public void addArgument(ExpressionNode en) {
49     argumentlist.add(en);
50   }
51
52   public void setConstructor(MethodDescriptor md) {
53     this.md=md;
54   }
55
56   public MethodDescriptor getConstructor() {
57     return md;
58   }
59
60   public TypeDescriptor getType() {
61     return td;
62   }
63
64   public int numArgs() {
65     return argumentlist.size();
66   }
67
68   public ExpressionNode getArg(int i) {
69     return (ExpressionNode) argumentlist.get(i);
70   }
71
72   public void addArrayInitializer(ArrayInitializerNode ain) {
73     this.ain = ain;
74   }
75
76   public ArrayInitializerNode getArrayInitializer() {
77     return this.ain;
78   }
79
80   public String printNode(int indent) {
81     String st;
82     boolean isarray=td.isArray();
83     if (isarray)
84       st="new "+td.toString()+"[";
85     else
86       st="new "+td.toString()+"(";
87     for(int i=0; i<argumentlist.size(); i++) {
88       ExpressionNode en=(ExpressionNode)argumentlist.get(i);
89       st+=en.printNode(indent);
90       if ((i+1)!=argumentlist.size()) {
91         if (isarray)
92           st+="][";
93         else
94           st+=", ";
95       }
96     }
97     if (isarray)
98       st += "]";
99     else
100       st += ")";
101     if(isarray && this.ain != null) {
102       st += "{";
103       st += this.ain.printNode(indent);
104       st += "}";
105     }
106     return st;
107   }
108
109   public int kind() {
110     return Kind.CreateObjectNode;
111   }
112
113   public Long evaluate() {
114     eval = null;
115     return eval; //null;
116   }
117
118   public void setSurroundingExpression( ExpressionNode en ) {
119         
120         //System.out.println( "The expression node is : " + en );
121         surroundingClassObject = en ;
122         //System.out.println( "The expression node is : " + surroundingClassObject );
123         isSurroundingClassExpSet = true;
124   }
125   
126   public ExpressionNode getSurroundingClassExpression() {
127         if( false == isSurroundingClassExpSet )
128                 return null;
129         return surroundingClassObject;
130   }
131 }