Fix a bug of field initialization. Previously the field initializations are done...
authorjzhou <jzhou>
Thu, 10 Mar 2011 03:09:09 +0000 (03:09 +0000)
committerjzhou <jzhou>
Thu, 10 Mar 2011 03:09:09 +0000 (03:09 +0000)
Robust/src/IR/Tree/BlockNode.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/Tests/InitializerTest.java

index 297bbc34b8dc8428024ad3a533f99ce8b33069b6..f62e6fa0041d7849af57cd130d1a569f7e588d48 100644 (file)
@@ -27,6 +27,10 @@ public class BlockNode extends TreeNode {
   public void addFirstBlockStatement(BlockStatementNode bsn) {
     blockstatements.insertElementAt(bsn,0);
   }
+  
+  public void addBlockStatementAt(BlockStatementNode bsn, int i) {
+    blockstatements.insertElementAt(bsn,i);
+  }
 
   public void setStyle(int style) {
     printStyle=style;
index 742a9da9f2395b3ae8af98f9ef14f687034151b1..b2e2a1ec0378dee173f2cdaedbae655c6a4daa7d 100644 (file)
@@ -144,19 +144,21 @@ public class BuildIR {
 
  public void parseInitializers(ClassDescriptor cn){
        Vector fv=cn.getFieldVec();
+    int pos = 0;
        for(int i=0;i<fv.size();i++) {
            FieldDescriptor fd=(FieldDescriptor)fv.get(i);
            if(fd.getExpressionNode()!=null) {
-               Iterator methodit = cn.getMethods();
-               while(methodit.hasNext()){
-                   MethodDescriptor currmd=(MethodDescriptor)methodit.next();
-                   if(currmd.isConstructor()){
-                       BlockNode bn=state.getMethodBody(currmd);
-                       NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
-                       AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
-                       bn.addFirstBlockStatement(new BlockExpressionNode(an));                 
-                   }
-               }
+         Iterator methodit = cn.getMethods();
+          while(methodit.hasNext()){
+            MethodDescriptor currmd=(MethodDescriptor)methodit.next();
+            if(currmd.isConstructor()){
+              BlockNode bn=state.getMethodBody(currmd);
+          NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
+          AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
+          bn.addBlockStatementAt(new BlockExpressionNode(an), pos);
+            }
+          }
+          pos++;
            }
        }
     }  
@@ -814,7 +816,6 @@ public class BuildIR {
       for(int i=0; i<num; i++)
     td=td.makeArray(state);
       CreateObjectNode con=new CreateObjectNode(td, false, null);
-      // TODO array initializers
       ParseNode ipn = pn.getChild("initializer");     
       Vector initializers=parseVariableInitializerList(ipn);
       ArrayInitializerNode ain = new ArrayInitializerNode(initializers);
index 12e41c9967dc373ff1642d42c5c157657f6a129c..3d9c97b9287d6a29d1d2dcd094552ab32f6fda6f 100644 (file)
@@ -17,6 +17,7 @@ class Foo{
     private float f=6;
     private boolean g=true;
     private char h='h';
+    private int[] i = new int[3];
     
      public Foo(int alpha){
         a=alpha;
@@ -35,6 +36,7 @@ class Foo{
        System.out.println("f="+f);
        System.out.println("g="+g);
        System.out.println("h="+h);
+    System.out.println("i.length = " + i.length);
     }
 
 }