Need a new inner class feature: let the anonymous inner class be able to access local...
authorjzhou <jzhou>
Sat, 12 Nov 2011 00:34:57 +0000 (00:34 +0000)
committerjzhou <jzhou>
Sat, 12 Nov 2011 00:34:57 +0000 (00:34 +0000)
Robust/src/ClassLibrary/Integer.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/Tests/DoTests
Robust/src/Tests/inner.java
Robust/src/Tests/innerCallback.java [new file with mode: 0644]

index 6943cf87067aa7bf3315c6e26ce20767bd1f191f..a9272d03465f5e079cab41d7d322e09a78387051 100644 (file)
@@ -134,4 +134,20 @@ public class Integer {
     value |= value >>> 16;
     return bitCount(~value);
   }
+
+  /**
+   * Returns an <code>Integer</code> object wrapping the value.
+   * In contrast to the <code>Integer</code> constructor, this method
+   * will cache some values.  It is used by boxing conversion.
+   *
+   * @param val the value to wrap
+   * @return the <code>Integer</code>
+   */
+  public static Integer valueOf(int val)
+  {
+    //if (val < MIN_CACHE || val > MAX_CACHE)
+      return new Integer(val);
+    /*else
+      return intCache[val - MIN_CACHE];*/
+  }
 }
index 22f9546f9fb4adccbdedebacf9fd82c27c90e514..ece917d72b1e111d4c26690d7a4c005efd8368e3 100644 (file)
@@ -94,11 +94,11 @@ public class SemanticCheck {
         }
       }
       if (oldstatus<INIT&&fullcheck>=INIT) {
-       if (cd.isInnerClass()) {
+       /*if (cd.isInnerClass()) {
           Modifiers fdmodifiers=new Modifiers();
          FieldDescriptor enclosingfd=new FieldDescriptor(fdmodifiers,new TypeDescriptor(cd.getSurroundingDesc()),"this___enclosing",null,false);
          cd.addField(enclosingfd);
-       }
+       }*/
 
         /* Check to see that fields are well typed */
         for(Iterator field_it=cd.getFields(); field_it.hasNext(); ) {
@@ -731,21 +731,21 @@ public class SemanticCheck {
 
     if (fd==null){
        if((md instanceof MethodDescriptor) && false == ((MethodDescriptor)md).isStaticBlock()) {
-               ClassDescriptor cd = ((MethodDescriptor)md).getClassDesc();
-               FieldAccessNode theFieldNode =  fieldAccessExpression( cd, fieldname, fan.getNumLine() );
-               if( null != theFieldNode ) {
-                       //fan = theFieldNode;
-                       checkFieldAccessNode( md, nametable, theFieldNode, td );
-                       fan.setField( theFieldNode.getField() );
-                       fan.setExpression( theFieldNode.getExpression() );
-                       //TypeDescriptor td1 = fan.getType();
-                       //td1.toString();
-                       return;         
-               }       
-               }
+           ClassDescriptor cd = ((MethodDescriptor)md).getClassDesc();
+           FieldAccessNode theFieldNode =      fieldAccessExpression( cd, fieldname, fan.getNumLine() );
+           if( null != theFieldNode ) {
+               //fan = theFieldNode;
+               checkFieldAccessNode( md, nametable, theFieldNode, td );
+               fan.setField( theFieldNode.getField() );
+               fan.setExpression( theFieldNode.getExpression() );
+               //TypeDescriptor td1 = fan.getType();
+               //td1.toString();
+               return;         
+           }   
+       }
        throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0)+" in "+md);
-      }
-    if (fd==null) {
+    }
+    /*if (fd==null) {
       ClassDescriptor surroundingCls=ltd.getClassDesc().getSurroundingDesc();
       int numencloses=1;
       while(surroundingCls!=null) {
@@ -768,7 +768,7 @@ public class SemanticCheck {
 
       if (fd==null)
        throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0)+" in "+md);
-    }
+    }*/
 
 
     if (fd.getType().iswrapper()) {
index 0cfd99df3b56206450542ba0dab8e715c95723a3..bddaa4ee16558085a2526e80bf45dfe60dea1391 100755 (executable)
@@ -24,4 +24,4 @@ dotest StaticInnerClassTest StaticInnerClassTest.java
 dotest StaticTest StaticTest.java
 dotest SwitchCaseTest SwitchCaseTest.java
 dotest TryCatchTest TryCatchTest.java
-dotest inner inner.java innerp.java innerpt.java
+#dotest inner inner.java innerp.java innerpt.java innerCallback.java
index 6000c3e385a852ef33b674f6ab2a5a38ed52e808..4d54a35e58e9cdc83df2a0cf9eff5611d5bd33a5 100644 (file)
@@ -16,11 +16,24 @@ public class inner extends innerp {
     outerprint();
     t tmp=new t();
     tmp.print();
+    outerAnonymousInner(100);
   }
   
   public void outerprint() {
       System.out.println("Outer class print: " + this.outer + "; " + this.f2);
   }
+  
+  public void outerprintInnerp(innerCallback c) {
+      c.call();
+  }
+  
+  public void outerAnonymousInner(final int value) {
+      this.outerprintInnerp(new innerCallback() {
+         public void call() {
+             System.out.println("innerCallback: " + value);
+         }
+      });
+  }
 
   public class t extends innerpt {
     int outer;
diff --git a/Robust/src/Tests/innerCallback.java b/Robust/src/Tests/innerCallback.java
new file mode 100644 (file)
index 0000000..d9035e7
--- /dev/null
@@ -0,0 +1,3 @@
+public interface innerCallback {\r
+    public void call();\r
+}
\ No newline at end of file