As static blocks is compiled as a method without returntype, previous isConstructor...
authorjzhou <jzhou>
Fri, 4 Feb 2011 01:43:36 +0000 (01:43 +0000)
committerjzhou <jzhou>
Fri, 4 Feb 2011 01:43:36 +0000 (01:43 +0000)
Robust/src/IR/MethodDescriptor.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/SemanticCheck.java

index beaee6be6fa4e3f6e34bc009312e9d722933474c..3f58a7cefec0f645ac1fbcc3ba70bcfcb3766b83 100644 (file)
@@ -127,7 +127,7 @@ public class MethodDescriptor extends Descriptor {
   }
 
   public boolean isConstructor() {
-    return (returntype==null);
+    return (returntype==null) && !isstaticblock;
   }
 
   public TypeDescriptor getReturnType() {
index 391d0cd76afff3a755fea18a5e408c2cabad5ebe..e29eaa9ebfef401e34928acdfda8a3154e13bca9 100644 (file)
@@ -672,7 +672,7 @@ public class BuildIR {
               BlockStatementNode bsn = bn.get(ii);
               obn.addBlockStatement(bsn);
             }
-            //TODO state.addTreeCode(md, obn);
+            state.addTreeCode(md, obn);
             bn = null;
           }
           en = null;
@@ -1022,7 +1022,7 @@ public class BuildIR {
         BlockStatementNode bsn = bn.get(i);
         obn.addBlockStatement(bsn);
       }
-      //TODO state.addTreeCode(md, obn);
+      state.addTreeCode(md, obn);
       bn = null;
     }
   }
index 5f0adb6e4c34824943605df188bb01466c7e13a4..692054232d7fc48e7d03db38bf90d2e3d9393737 100644 (file)
@@ -247,7 +247,7 @@ public class SemanticCheck {
       }
     }
     /* Check return type */
-    if (!md.isConstructor())
+    if (!md.isConstructor() && !md.isStaticBlock())
       if (!md.getReturnType().isVoid())
        checkTypeDescriptor(md.getReturnType());
 
@@ -710,8 +710,18 @@ public class SemanticCheck {
           SymbolTable fieldtbl = cd.getFieldTable();
           FieldDescriptor fd=(FieldDescriptor)fieldtbl.get(varname);
           if((fd == null) || (!fd.isStatic())){
-            // no such field in the class or it is not a static field
-            throw new Error("Name "+varname+" should not be used in static block: "+md);
+            // no such field in the class, check if this is a class
+            if(varname.equals("this")) {
+              throw new Error("Error: access this obj in a static block");
+            }
+            cd=getClass(varname);
+            if(cd != null) {
+              // this is a class name
+              nn.setClassDesc(cd);
+              return;
+            } else {
+              throw new Error("Name "+varname+" should not be used in static block: "+md);
+            }
           } else {
             // this is a static field
             nn.setField(fd);