Fix some inner class related bugs: 1) whenever a class is added into the class list...
authorjzhou <jzhou>
Tue, 20 Dec 2011 00:15:20 +0000 (00:15 +0000)
committerjzhou <jzhou>
Tue, 20 Dec 2011 00:15:20 +0000 (00:15 +0000)
Robust/src/ClassLibrary/MGC/gnu/Arrays.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/SemanticCheck.java

index 394d749c9f51787ef8d7d958bdab29e3cc899476..ca5498c5ed5121af241d881b88e05f2021db3e42 100644 (file)
@@ -3249,7 +3249,8 @@ public class Arrays
      */
     public Object/*E*/ set(int index, Object/*E*/ element)
     {
-      E old = a[index];
+      
+      Object/*E*/ old = a[index];
       a[index] = element;
       return old;
     }
@@ -3307,7 +3308,10 @@ public class Arrays
      */
     public Object[] toArray()
     {
-      return (Object[]) a.clone();
+      //return (Object[]) a.clone();
+      Object[] ta = new Object[a.length];
+      System.arraycopy(a, 0, ta, 0, a.length);
+      return ta;
     }
 
     /**
index 7b14d103ae23a3b77740012cd5399cba77eeb99e..ca56794da9a5b32970e0efea9b69f48900c19f7a 100644 (file)
@@ -253,10 +253,7 @@ public class BuildIR {
     ecd.setModifiers(parseModifiersList(pn.getChild("modifiers")));
     parseEnumBody(ecd, pn.getChild("enumbody"));
 
-    if (analyzeset != null)
-      analyzeset.add(ecd);
-    ecd.setSourceFileName(currsourcefile);
-    state.addClass(ecd);
+    addClass2State(ecd);
 
     popChainMaps();
     return ecd;
@@ -290,10 +287,7 @@ public class BuildIR {
     parseAnnotationTypeBody(cn,pn.getChild("body"));
     popChainMaps();
 
-    if (analyzeset != null)
-      analyzeset.add(cn);
-    cn.setSourceFileName(currsourcefile);
-    state.addClass(cn);
+    addClass2State(cn);
 
     return cn;
   }
@@ -355,10 +349,7 @@ public class BuildIR {
     }
     cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
     parseInterfaceBody(cn, pn.getChild("interfacebody"));
-    if (analyzeset != null)
-      analyzeset.add(cn);
-    cn.setSourceFileName(currsourcefile);
-    state.addClass(cn);
+    addClass2State(cn);
     popChainMaps();
     return cn;
   }
@@ -569,6 +560,22 @@ public class BuildIR {
     return tel;
   }
 
+  private void addClass2State(ClassDescriptor cn) {
+    if (analyzeset != null)
+      analyzeset.add(cn);
+    cn.setSourceFileName(currsourcefile);
+    state.addClass(cn);
+    // create this$n representing a final reference to the next surrounding class. each inner class should have whatever inner class
+    // pointers the surrounding class has + a pointer to the surrounding class.
+    if( true )
+    {
+      this.isRunningRecursiveInnerClass = true; //fOR dEBUGGING PURPOSES IN ORDER TO DUMP STRINGS WHILE IN THIS CODE PATH
+      addOuterClassReferences( cn, cn, 0 );
+      addOuterClassParam( cn, cn, 0 );
+      this.isRunningRecursiveInnerClass = false;
+    }
+  }
+  
   public ClassDescriptor parseTypeDecl(ParseNode pn) {
     ClassDescriptor cn=new ClassDescriptor(packageName, pn.getChild("name").getTerminal(), false);
     pushChainMaps();
@@ -618,21 +625,9 @@ public class BuildIR {
     popChainMaps();
 
     cn.setSourceFileName(currsourcefile);
-
-
     
-    if (analyzeset != null)
-      analyzeset.add(cn);
-    state.addClass(cn);
-//create this$n representing a final reference to the next surrounding class. each inner class should have whatever inner class
-//pointers the surrounding class has + a pointer to the surrounding class.
-   if( true )
-   {
-       this.isRunningRecursiveInnerClass = true; //fOR dEBUGGING PURPOSES IN ORDER TO DUMP STRINGS WHILE IN THIS CODE PATH
-       addOuterClassReferences( cn, 0 );
-       addOuterClassParam( cn, 0 );
-       this.isRunningRecursiveInnerClass = false;
-    }
+    addClass2State(cn);
+
     return cn;
   }
 
@@ -648,14 +643,14 @@ private void initializeOuterMember( MethodDescriptor md, String fieldName, Strin
          state.addTreeCode(md, obn);
 }
 
-private void addOuterClassParam( ClassDescriptor cn, int depth )
+private void addOuterClassParam( ClassDescriptor cn, ClassDescriptor ocn, int depth )
 {
        Iterator nullCheckItr = cn.getInnerClasses();
        if( false == nullCheckItr.hasNext() )
                return;
 
        //create a typedescriptor of type cn
-       TypeDescriptor theTypeDesc = new TypeDescriptor( cn );
+       TypeDescriptor theTypeDesc = new TypeDescriptor( ocn );
        
        for(Iterator it=cn.getInnerClasses(); it.hasNext(); ) {
                ClassDescriptor icd=(ClassDescriptor)it.next();
@@ -672,19 +667,19 @@ private void addOuterClassParam( ClassDescriptor cn, int depth )
                                //System.out.println( "The added param is " + md.toString() + "\n" );
                        }
                }
-               addOuterClassParam( icd, depth + 1 );
+               addOuterClassParam( icd, ocn, depth + 1 );
                
        }
        
 }
-private void addOuterClassReferences( ClassDescriptor cn, int depth )
+private void addOuterClassReferences( ClassDescriptor cn, ClassDescriptor ocn, int depth )
 {
        //SYMBOLTABLE does not have a length or empty method, hence could not define a hasInnerClasses method in classDescriptor
        Iterator nullCheckItr = cn.getInnerClasses();
        if( false == nullCheckItr.hasNext() )
                return;
 
-       String tempCopy = cn.getClassName();
+       String tempCopy = ocn.getClassName();
        //MESSY HACK FOLLOWS
        int i = 0;
 
@@ -715,7 +710,7 @@ private void addOuterClassReferences( ClassDescriptor cn, int depth )
                        //System.out.println( fieldTable.toString() );
                }*/
                icd.setInnerDepth( depth + 1 );
-               addOuterClassReferences( icd, depth + 1 );      
+               addOuterClassReferences( icd, ocn, depth + 1 ); 
        }
 }
 
@@ -844,10 +839,7 @@ private void addOuterClassReferences( ClassDescriptor cn, int depth )
    }
     popChainMaps();
 
-     if (analyzeset != null)
-      analyzeset.add(icn);
-    icn.setSourceFileName(currsourcefile);
-    state.addClass(icn);
+    addClass2State(icn);
 
     return icn;
   }
@@ -1206,10 +1198,7 @@ private void addOuterClassReferences( ClassDescriptor cn, int depth )
       }
       popChainMaps();
 
-      if (analyzeset != null)
-       analyzeset.add(cnnew);
-      cnnew.setSourceFileName(currsourcefile);
-      state.addClass(cnnew);
+      addClass2State(cnnew);
 
       return con;
     } else if (isNode(pn,"createarray")) {
index dc08789b384c65b0a51cab3ba4ce225c8bb19530..24254c2e601d89819377673ccaf0af211b2607cd 100644 (file)
@@ -1240,6 +1240,18 @@ public class SemanticCheck {
                //make this into an expression node.
                NameNode nThis=new NameNode( new NameDescriptor( "this" ) );
                con.addArgument( nThis );
+               if(cd.isInnerClass()&&!cd.isStatic()) {
+                 // add all the ith lexically enclosing instance if applicable
+                 Iterator it_fields = cd.getFields();
+                 int index = 0;
+                 while(it_fields.hasNext()) {
+                   FieldDescriptor fd = (FieldDescriptor)(it_fields.next());
+                   if(fd.getSymbol().startsWith("this$")) {
+                     con.addArgument(new NameNode(new NameDescriptor("this$"+index)));
+                     index++;
+                   }
+                 }
+               }
        }
        else {
                //REVISIT : here i am storing the expression as an expressionNode which does not implement type, there is no way for me to semantic check this argument.