From e42cc7c555d312b9b9bb8963e9001d3f3227769b Mon Sep 17 00:00:00 2001 From: jzhou Date: Sat, 12 Nov 2011 00:34:57 +0000 Subject: [PATCH 1/1] Need a new inner class feature: let the anonymous inner class be able to access local variable that is final. Add test about this new feature into the unit test of inner class. This feature is not implemented yet. So disable the inner test in Tests/DoTest temorarily. Will add it back when our compiler can pass this unit test. And it seems that the this___enclosing field of inner classes is no longer used, disable it. Add a new method valueOf(int) into Interger class --- Robust/src/ClassLibrary/Integer.java | 16 +++++++++++++ Robust/src/IR/Tree/SemanticCheck.java | 34 +++++++++++++-------------- Robust/src/Tests/DoTests | 2 +- Robust/src/Tests/inner.java | 13 ++++++++++ Robust/src/Tests/innerCallback.java | 3 +++ 5 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 Robust/src/Tests/innerCallback.java diff --git a/Robust/src/ClassLibrary/Integer.java b/Robust/src/ClassLibrary/Integer.java index 6943cf87..a9272d03 100644 --- a/Robust/src/ClassLibrary/Integer.java +++ b/Robust/src/ClassLibrary/Integer.java @@ -134,4 +134,20 @@ public class Integer { value |= value >>> 16; return bitCount(~value); } + + /** + * Returns an Integer object wrapping the value. + * In contrast to the Integer constructor, this method + * will cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the Integer + */ + public static Integer valueOf(int val) + { + //if (val < MIN_CACHE || val > MAX_CACHE) + return new Integer(val); + /*else + return intCache[val - MIN_CACHE];*/ + } } diff --git a/Robust/src/IR/Tree/SemanticCheck.java b/Robust/src/IR/Tree/SemanticCheck.java index 22f9546f..ece917d7 100644 --- a/Robust/src/IR/Tree/SemanticCheck.java +++ b/Robust/src/IR/Tree/SemanticCheck.java @@ -94,11 +94,11 @@ public class SemanticCheck { } } if (oldstatus=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()) { diff --git a/Robust/src/Tests/DoTests b/Robust/src/Tests/DoTests index 0cfd99df..bddaa4ee 100755 --- a/Robust/src/Tests/DoTests +++ b/Robust/src/Tests/DoTests @@ -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 diff --git a/Robust/src/Tests/inner.java b/Robust/src/Tests/inner.java index 6000c3e3..4d54a35e 100644 --- a/Robust/src/Tests/inner.java +++ b/Robust/src/Tests/inner.java @@ -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 index 00000000..d9035e75 --- /dev/null +++ b/Robust/src/Tests/innerCallback.java @@ -0,0 +1,3 @@ +public interface innerCallback { + public void call(); +} \ No newline at end of file -- 2.34.1