From 1e95c6edd26b5378071ef534fe07a35c9fac1c76 Mon Sep 17 00:00:00 2001 From: jzhou Date: Fri, 4 Feb 2011 01:43:36 +0000 Subject: [PATCH] As static blocks is compiled as a method without returntype, previous isConstructor check should be updated --- Robust/src/IR/MethodDescriptor.java | 2 +- Robust/src/IR/Tree/BuildIR.java | 4 ++-- Robust/src/IR/Tree/SemanticCheck.java | 16 +++++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Robust/src/IR/MethodDescriptor.java b/Robust/src/IR/MethodDescriptor.java index beaee6be..3f58a7ce 100644 --- a/Robust/src/IR/MethodDescriptor.java +++ b/Robust/src/IR/MethodDescriptor.java @@ -127,7 +127,7 @@ public class MethodDescriptor extends Descriptor { } public boolean isConstructor() { - return (returntype==null); + return (returntype==null) && !isstaticblock; } public TypeDescriptor getReturnType() { diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 391d0cd7..e29eaa9e 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -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; } } diff --git a/Robust/src/IR/Tree/SemanticCheck.java b/Robust/src/IR/Tree/SemanticCheck.java index 5f0adb6e..69205423 100644 --- a/Robust/src/IR/Tree/SemanticCheck.java +++ b/Robust/src/IR/Tree/SemanticCheck.java @@ -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); -- 2.34.1