Fix another inner class bug: every inner class along the inherited chain has a pointe...
[IRC.git] / Robust / src / IR / Tree / SemanticCheck.java
index d123a172918e45c723c126a684dc710b2c031a69..95042d31b38833a1f307fb118bc1b04a5cdb5379 100644 (file)
@@ -10,11 +10,13 @@ public class SemanticCheck {
   Stack loopstack;
   HashSet toanalyze;
   HashMap<ClassDescriptor, Integer> completed;
-  
+  HashMap<ClassDescriptor, Vector<VarDescriptor>> inlineClass2LiveVars;
+  boolean trialcheck = false;
+
   public static final int NOCHECK=0;
   public static final int REFERENCE=1;
   public static final int INIT=2;
-  
+
   boolean checkAll;
 
   public boolean hasLayout(ClassDescriptor cd) {
@@ -32,18 +34,14 @@ public class SemanticCheck {
     this.toanalyze=new HashSet();
     this.completed=new HashMap<ClassDescriptor, Integer>();
     this.checkAll=checkAll;
+    this.inlineClass2LiveVars = new HashMap<ClassDescriptor, Vector<VarDescriptor>>();
   }
 
   public ClassDescriptor getClass(ClassDescriptor context, String classname) {
     return getClass(context, classname, INIT);
   }
-
-  public ClassDescriptor getClass(ClassDescriptor context, String classname, int fullcheck) {
-    if (context!=null) {
-      Hashtable remaptable=context.getSingleImportMappings();
-      classname=remaptable.containsKey(classname)?((String)remaptable.get(classname)):classname;
-    }
-    ClassDescriptor cd=typeutil.getClass(classname, toanalyze);
+  public ClassDescriptor getClass(ClassDescriptor context, String classnameIn, int fullcheck) {
+    ClassDescriptor cd=typeutil.getClass(context, classnameIn, toanalyze);
     checkClass(cd, fullcheck);
     return cd;
   }
@@ -56,47 +54,94 @@ public class SemanticCheck {
     if (!completed.containsKey(cd)||completed.get(cd)<fullcheck) {
       int oldstatus=completed.containsKey(cd)?completed.get(cd):0;
       completed.put(cd, fullcheck);
-      
+
       if (fullcheck>=REFERENCE&&oldstatus<INIT) {
-       //Set superclass link up
-       if (cd.getSuper()!=null) {
-         cd.setSuper(getClass(cd, cd.getSuper(), fullcheck));
-         if(cd.getSuperDesc().isInterface()) {
-           throw new Error("Error! Class " + cd.getSymbol() + " extends interface " + cd.getSuper());
+        //Set superclass link up
+        if (cd.getSuper()!=null) {
+         ClassDescriptor superdesc=getClass(cd, cd.getSuper(), fullcheck);
+         if (superdesc.isInnerClass()) {
+           cd.setAsInnerClass();
          }
-         // Link together Field, Method, and Flag tables so classes
-         // inherit these from their superclasses
-         if (oldstatus<REFERENCE) {
-           cd.getFieldTable().setParent(cd.getSuperDesc().getFieldTable());
-           cd.getMethodTable().setParent(cd.getSuperDesc().getMethodTable());
-           cd.getFlagTable().setParent(cd.getSuperDesc().getFlagTable());
+         if (superdesc.isInterface()) {
+           if (cd.getInline()) {
+             cd.setSuper(null);
+             cd.getSuperInterface().add(superdesc.getSymbol());
+           } else {
+             throw new Error("Error! Class " + cd.getSymbol() + " extends interface " + cd.getSuper());
+           }
+         } else {
+           cd.setSuperDesc(superdesc);
+
+           // Link together Field, Method, and Flag tables so classes
+           // inherit these from their superclasses
+           if (oldstatus<REFERENCE) {
+             cd.getFieldTable().setParent(cd.getSuperDesc().getFieldTable());
+             cd.getMethodTable().setParent(cd.getSuperDesc().getMethodTable());
+             cd.getFlagTable().setParent(cd.getSuperDesc().getFlagTable());
+           }
          }
-       }
-       // Link together Field, Method tables do classes inherit these from 
-       // their ancestor interfaces
-       Vector<String> sifv = cd.getSuperInterface();
-       for(int i = 0; i < sifv.size(); i++) {
-         ClassDescriptor superif = getClass(cd, sifv.elementAt(i), fullcheck);
-         if(!superif.isInterface()) {
-           throw new Error("Error! Class " + cd.getSymbol() + " implements non-interface " + superif.getSymbol());
+        }
+        // Link together Field, Method tables do classes inherit these from
+        // their ancestor interfaces
+        Vector<String> sifv = cd.getSuperInterface();
+        for(int i = 0; i < sifv.size(); i++) {
+          ClassDescriptor superif = getClass(cd, sifv.elementAt(i), fullcheck);
+          if(!superif.isInterface()) {
+            throw new Error("Error! Class " + cd.getSymbol() + " implements non-interface " + superif.getSymbol());
+          }
+          if (oldstatus<REFERENCE) {
+            cd.addSuperInterfaces(superif);
+            cd.getMethodTable().addParentIF(superif.getMethodTable());
+            cd.getFieldTable().addParentIF(superif.getFieldTable());
+          }
+        }
+      }
+      if (oldstatus<INIT&&fullcheck>=INIT) {
+        /* Check to see that fields are well typed */
+        for(Iterator field_it=cd.getFields(); field_it.hasNext(); ) {
+          FieldDescriptor fd=(FieldDescriptor)field_it.next();
+         try {
+          checkField(cd,fd);
+         } catch (Error e) {
+           System.out.println("Class/Field in "+cd+":"+fd);
+           throw e;
          }
-         if (oldstatus<REFERENCE) {
-           cd.addSuperInterfaces(superif);
-           cd.getFieldTable().addParentIF(superif.getFieldTable());
-           cd.getMethodTable().addParentIF(superif.getMethodTable());
+        }
+        for(Iterator method_it=cd.getMethods(); method_it.hasNext(); ) {
+          MethodDescriptor md=(MethodDescriptor)method_it.next();
+         try {
+          checkMethod(cd,md);
+         } catch (Error e) {
+           System.out.println("Class/Method in "+cd+":"+md);
+           throw e;
          }
-       }
+        }
       }
-      if (oldstatus<INIT&&fullcheck>=INIT) {
-       /* Check to see that fields are well typed */
-       for(Iterator field_it=cd.getFields(); field_it.hasNext();) {
-         FieldDescriptor fd=(FieldDescriptor)field_it.next();
-         checkField(cd,fd);
-       }
-       for(Iterator method_it=cd.getMethods(); method_it.hasNext();) {
-         MethodDescriptor md=(MethodDescriptor)method_it.next();
-         checkMethod(cd,md);
-       }
+    }
+  }
+  
+  public void semanticCheckClass(ClassDescriptor cd) {
+    // need to initialize typeutil object here...only place we can
+    // get class descriptors without first calling getclass
+    getClass(cd, cd.getSymbol());
+    if(cd.getInline()) {
+      
+      // for inline defined anonymous classes, we need to check its 
+      // surrounding class first to get its surrounding context
+      ClassDescriptor surroundingcd = cd.getSurroundingDesc();
+      if(toanalyze.contains(surroundingcd)) {
+         toanalyze.remove(surroundingcd);
+         semanticCheckClass(surroundingcd);
+      }
+    }
+
+    for (Iterator method_it = cd.getMethods(); method_it.hasNext(); ) {
+      MethodDescriptor md = (MethodDescriptor) method_it.next();
+      try {
+       checkMethodBody(cd, md);
+      } catch (Error e) {
+        System.out.println("Error in " + md);
+        throw e;
       }
     }
   }
@@ -121,19 +166,7 @@ public class SemanticCheck {
       } else {
         ClassDescriptor cd = (ClassDescriptor) obj;
         toanalyze.remove(cd);
-        
-        // need to initialize typeutil object here...only place we can
-        // get class descriptors without first calling getclass
-        getClass(cd, cd.getSymbol());
-        for (Iterator method_it = cd.getMethods(); method_it.hasNext();) {
-          MethodDescriptor md = (MethodDescriptor) method_it.next();
-          try {
-            checkMethodBody(cd, md);
-          } catch (Error e) {
-            System.out.println("Error in " + md);
-            throw e;
-          }
-        }
+        semanticCheckClass(cd);
       }
     }
   }
@@ -143,14 +176,10 @@ public class SemanticCheck {
       return;       /* Done */
     else if (td.isClass()) {
       String name=td.toString();
-      int index = name.lastIndexOf('.');
-      if(index != -1) {
-        name = name.substring(index+1);
-      }
       ClassDescriptor field_cd=checkAll?getClass(cd, name):getClass(cd, name, REFERENCE);
 
       if (field_cd==null)
-       throw new Error("Undefined class "+name);
+        throw new Error("Undefined class "+name);
       td.setClassDescriptor(field_cd);
       return;
     } else if (td.isTag())
@@ -170,8 +199,8 @@ public class SemanticCheck {
       ConstraintCheck cc=(ConstraintCheck) ccs.get(i);
 
       for(int j=0; j<cc.numArgs(); j++) {
-       ExpressionNode en=cc.getArg(j);
-       checkExpressionNode(td,nametable,en,null);
+        ExpressionNode en=cc.getArg(j);
+        checkExpressionNode(td,nametable,en,null);
       }
     }
   }
@@ -185,36 +214,36 @@ public class SemanticCheck {
       //Make sure the variable is declared as a parameter to the task
       VarDescriptor vd=(VarDescriptor)td.getParameterTable().get(varname);
       if (vd==null)
-       throw new Error("Parameter "+varname+" in Flag Effects not declared in "+td);
+        throw new Error("Parameter "+varname+" in Flag Effects not declared in "+td);
       fe.setVar(vd);
 
       //Make sure it correspods to a class
       TypeDescriptor type_d=vd.getType();
       if (!type_d.isClass())
-       throw new Error("Cannot have non-object argument for flag_effect");
+        throw new Error("Cannot have non-object argument for flag_effect");
 
       ClassDescriptor cd=type_d.getClassDesc();
       for(int j=0; j<fe.numEffects(); j++) {
-       FlagEffect flag=fe.getEffect(j);
-       String name=flag.getName();
-       FlagDescriptor flag_d=(FlagDescriptor)cd.getFlagTable().get(name);
-       //Make sure the flag is declared
-       if (flag_d==null)
-         throw new Error("Flag descriptor "+name+" undefined in class: "+cd.getSymbol());
-       if (flag_d.getExternal())
-         throw new Error("Attempting to modify external flag: "+name);
-       flag.setFlag(flag_d);
+        FlagEffect flag=fe.getEffect(j);
+        String name=flag.getName();
+        FlagDescriptor flag_d=(FlagDescriptor)cd.getFlagTable().get(name);
+        //Make sure the flag is declared
+        if (flag_d==null)
+          throw new Error("Flag descriptor "+name+" undefined in class: "+cd.getSymbol());
+        if (flag_d.getExternal())
+          throw new Error("Attempting to modify external flag: "+name);
+        flag.setFlag(flag_d);
       }
       for(int j=0; j<fe.numTagEffects(); j++) {
-       TagEffect tag=fe.getTagEffect(j);
-       String name=tag.getName();
-
-       Descriptor d=(Descriptor)nametable.get(name);
-       if (d==null)
-         throw new Error("Tag descriptor "+name+" undeclared");
-       else if (!(d instanceof TagVarDescriptor))
-         throw new Error(name+" is not a tag descriptor");
-       tag.setTag((TagVarDescriptor)d);
+        TagEffect tag=fe.getTagEffect(j);
+        String name=tag.getName();
+
+        Descriptor d=(Descriptor)nametable.get(name);
+        if (d==null)
+          throw new Error("Tag descriptor "+name+" undeclared");
+        else if (!(d instanceof TagVarDescriptor))
+          throw new Error(name+" is not a tag descriptor");
+        tag.setTag((TagVarDescriptor)d);
       }
     }
   }
@@ -228,10 +257,10 @@ public class SemanticCheck {
       /* Check the parameter's flag expression is well formed */
       FlagExpressionNode fen=td.getFlag(td.getParameter(i));
       if (!param_type.isClass())
-       throw new Error("Cannot have non-object argument to a task");
+        throw new Error("Cannot have non-object argument to a task");
       ClassDescriptor cd=param_type.getClassDesc();
       if (fen!=null)
-       checkFlagExpressionNode(cd, fen);
+        checkFlagExpressionNode(cd, fen);
     }
 
     checkFlagEffects(td, td.getFlagEffects(),td.getParameterTable());
@@ -247,7 +276,7 @@ public class SemanticCheck {
       FlagOpNode fon=(FlagOpNode)fen;
       checkFlagExpressionNode(cd, fon.getLeft());
       if (fon.getRight()!=null)
-       checkFlagExpressionNode(cd, fon.getRight());
+        checkFlagExpressionNode(cd, fon.getRight());
       break;
     }
 
@@ -257,7 +286,7 @@ public class SemanticCheck {
       String name=fn.getFlagName();
       FlagDescriptor fd=(FlagDescriptor)cd.getFlagTable().get(name);
       if (fd==null)
-       throw new Error("Undeclared flag: "+name);
+        throw new Error("Undeclared flag: "+name);
       fn.setFlag(fd);
       break;
     }
@@ -271,14 +300,14 @@ public class SemanticCheck {
     /* Check for abstract methods */
     if(md.isAbstract()) {
       if(!cd.isAbstract() && !cd.isInterface()) {
-       throw new Error("Error! The non-abstract Class " + cd.getSymbol() + " contains an abstract method " + md.getSymbol());
+        throw new Error("Error! The non-abstract Class " + cd.getSymbol() + " contains an abstract method " + md.getSymbol());
       }
     }
 
     /* Check return type */
     if (!md.isConstructor() && !md.isStaticBlock())
       if (!md.getReturnType().isVoid()) {
-       checkTypeDescriptor(cd, md.getReturnType());
+        checkTypeDescriptor(cd, md.getReturnType());
       }
     for(int i=0; i<md.numParameters(); i++) {
       TypeDescriptor param_type=md.getParamType(i);
@@ -292,8 +321,9 @@ public class SemanticCheck {
       VarDescriptor thisvd=new VarDescriptor(new TypeDescriptor(cd),"this");
       md.setThis(thisvd);
     }
-    if(md.isDefaultConstructor() && (cd.getSuperDesc() != null)) {
+    if(md.isDefaultConstructor() && (cd.getSuperDesc() != null) && !cd.getInline()) {
       // add the construction of it super class, can only be super()
+      // NOTE: inline class should be treated differently
       NameDescriptor nd=new NameDescriptor("super");
       MethodInvokeNode min=new MethodInvokeNode(nd);
       BlockExpressionNode ben=new BlockExpressionNode(min);
@@ -304,15 +334,16 @@ public class SemanticCheck {
 
   public void checkMethodBody(ClassDescriptor cd, MethodDescriptor md) {
     ClassDescriptor superdesc=cd.getSuperDesc();
-    if (superdesc!=null) {
+    // for inline classes, it has done this during trial check
+    if ((!cd.getInline() || this.trialcheck) && (superdesc!=null)) {
       Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
-      for(Iterator methodit=possiblematches.iterator(); methodit.hasNext();) {
-       MethodDescriptor matchmd=(MethodDescriptor)methodit.next();
-       if (md.matches(matchmd)) {
-         if (matchmd.getModifiers().isFinal()) {
-           throw new Error("Try to override final method in method:"+md+" declared in  "+cd);
-         }
-       }
+      for(Iterator methodit=possiblematches.iterator(); methodit.hasNext(); ) {
+        MethodDescriptor matchmd=(MethodDescriptor)methodit.next();
+        if (md.matches(matchmd)) {
+          if (matchmd.getModifiers().isFinal()) {
+            throw new Error("Try to override final method in method:"+md+" declared in  "+cd);
+          }
+        }
       }
     }
     BlockNode bn=state.getMethodBody(md);
@@ -345,7 +376,7 @@ public class SemanticCheck {
     case Kind.IfStatementNode:
       checkIfStatementNode(md, nametable, (IfStatementNode)bsn);
       return;
-      
+
     case Kind.SwitchStatementNode:
       checkSwitchStatementNode(md, nametable, (SwitchStatementNode)bsn);
       return;
@@ -375,11 +406,12 @@ public class SemanticCheck {
       return;
 
     case Kind.ContinueBreakNode:
-       checkContinueBreakNode(md, nametable, (ContinueBreakNode) bsn);
-       return;
+      checkContinueBreakNode(md, nametable, (ContinueBreakNode) bsn);
+      return;
 
     case Kind.SESENode:
     case Kind.GenReachNode:
+    case Kind.GenDefReachNode:
       // do nothing, no semantic check for SESEs
       return;
     }
@@ -398,6 +430,8 @@ public class SemanticCheck {
     if ((d==null)||
         (d instanceof FieldDescriptor)) {
       nametable.add(vd);
+    } else if((md instanceof MethodDescriptor) && (((MethodDescriptor)md).getClassDesc().getInline()) && !this.trialcheck) {
+      // for inline classes, the var has been checked during trial check and added into the nametable
     } else
       throw new Error(vd.getSymbol()+" in "+md+" defined a second time");
     if (dn.getExpression()!=null)
@@ -410,6 +444,8 @@ public class SemanticCheck {
     if ((d==null)||
         (d instanceof FieldDescriptor)) {
       nametable.add(vd);
+    } else if((md instanceof MethodDescriptor) && (((MethodDescriptor)md).getClassDesc().getInline()) && !this.trialcheck) {
+      // for inline classes, the var has been checked during trial check and added into the nametable
     } else
       throw new Error(vd.getSymbol()+" defined a second time");
   }
@@ -429,13 +465,13 @@ public class SemanticCheck {
   }
 
   void checkContinueBreakNode(Descriptor md, SymbolTable nametable, ContinueBreakNode cbn) {
-      if (loopstack.empty())
-         throw new Error("continue/break outside of loop");
-      Object o = loopstack.peek();
-      if(o instanceof LoopNode) {
-        LoopNode ln=(LoopNode)o;
-        cbn.setLoop(ln);
-      }
+    if (loopstack.empty())
+      throw new Error("continue/break outside of loop");
+    Object o = loopstack.peek();
+    if(o instanceof LoopNode) {
+      LoopNode ln=(LoopNode)o;
+      cbn.setLoop(ln);
+    }
   }
 
   void checkReturnNode(Descriptor d, SymbolTable nametable, ReturnNode rn) {
@@ -444,11 +480,11 @@ public class SemanticCheck {
     MethodDescriptor md=(MethodDescriptor)d;
     if (rn.getReturnExpression()!=null)
       if (md.getReturnType()==null)
-       throw new Error("Constructor can't return something.");
+        throw new Error("Constructor can't return something.");
       else if (md.getReturnType().isVoid())
-       throw new Error(md+" is void");
+        throw new Error(md+" is void");
       else
-       checkExpressionNode(md, nametable, rn.getReturnExpression(), md.getReturnType());
+        checkExpressionNode(md, nametable, rn.getReturnExpression(), md.getReturnType());
     else
     if (md.getReturnType()!=null&&!md.getReturnType().isVoid())
       throw new Error("Need to return something for "+md);
@@ -467,10 +503,10 @@ public class SemanticCheck {
     if (isn.getFalseBlock()!=null)
       checkBlockNode(md, nametable, isn.getFalseBlock());
   }
-  
+
   void checkSwitchStatementNode(Descriptor md, SymbolTable nametable, SwitchStatementNode ssn) {
     checkExpressionNode(md, nametable, ssn.getCondition(), new TypeDescriptor(TypeDescriptor.INT));
-    
+
     BlockNode sbn = ssn.getSwitchBody();
     boolean hasdefault = false;
     for(int i = 0; i < sbn.size(); i++) {
@@ -481,7 +517,7 @@ public class SemanticCheck {
       hasdefault = containdefault;
     }
   }
-  
+
   boolean checkSwitchBlockNode(Descriptor md, SymbolTable nametable, SwitchBlockNode sbn) {
     Vector<SwitchLabelNode> slnv = sbn.getSwitchConditions();
     int defaultb = 0;
@@ -501,21 +537,21 @@ public class SemanticCheck {
       return (defaultb > 0);
     }
   }
-  
+
   void checkConstantExpressionNode(Descriptor md, SymbolTable nametable, ExpressionNode en, TypeDescriptor td) {
     switch(en.kind()) {
     case Kind.FieldAccessNode:
       checkFieldAccessNode(md,nametable,(FieldAccessNode)en,td);
       return;
-     
+
     case Kind.LiteralNode:
       checkLiteralNode(md,nametable,(LiteralNode)en,td);
       return;
-      
+
     case Kind.NameNode:
       checkNameNode(md,nametable,(NameNode)en,td);
       return;
-      
+
     case Kind.OpNode:
       checkOpNode(md, nametable, (OpNode)en, td);
       return;
@@ -568,7 +604,7 @@ public class SemanticCheck {
     case Kind.TertiaryNode:
       checkTertiaryNode(md, nametable, (TertiaryNode)en, td);
       return;
-      
+
     case Kind.InstanceOfNode:
       checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td);
       return;
@@ -576,7 +612,7 @@ public class SemanticCheck {
     case Kind.ArrayInitializerNode:
       checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en, td);
       return;
-     
+
     case Kind.ClassTypeNode:
       checkClassTypeNode(md, nametable, (ClassTypeNode) en, td);
       return;
@@ -587,7 +623,7 @@ public class SemanticCheck {
   void checkClassTypeNode(Descriptor md, SymbolTable nametable, ClassTypeNode tn, TypeDescriptor td) {
     checkTypeDescriptor(((md instanceof MethodDescriptor)?((MethodDescriptor)md).getClassDesc():null), tn.getType());
   }
-  
+
   void checkCastNode(Descriptor md, SymbolTable nametable, CastNode cn, TypeDescriptor td) {
     /* Get type descriptor */
     if (cn.getType()==null) {
@@ -603,7 +639,7 @@ public class SemanticCheck {
     /* Type check */
     if (td!=null) {
       if (!typeutil.isSuperorType(td,cast_type))
-       throw new Error("Cast node returns "+cast_type+", but need "+td);
+        throw new Error("Cast node returns "+cast_type+", but need "+td);
     }
 
     ExpressionNode en=cn.getExpression();
@@ -617,25 +653,95 @@ public class SemanticCheck {
     if (typeutil.isCastable(etd, cast_type))
       return;
 
+    //rough hack to handle interfaces...should clean up
+    if (etd.isClass()&&cast_type.isClass()) {
+      ClassDescriptor cdetd=etd.getClassDesc();
+      ClassDescriptor cdcast_type=cast_type.getClassDesc();
+
+      if (cdetd.isInterface()&&!cdcast_type.getModifier().isFinal())
+       return;
+      
+      if (cdcast_type.isInterface()&&!cdetd.getModifier().isFinal())
+       return;
+    }
     /* Different branches */
     /* TODO: change if add interfaces */
     throw new Error("Cast will always fail\n"+cn.printNode(0));
   }
 
+  //FieldDescriptor checkFieldAccessNodeForParentNode( Descriptor md, SymbolTable na )
   void checkFieldAccessNode(Descriptor md, SymbolTable nametable, FieldAccessNode fan, TypeDescriptor td) {
     ExpressionNode left=fan.getExpression();
     checkExpressionNode(md,nametable,left,null);
     TypeDescriptor ltd=left.getType();
+    if (!ltd.isArray())
+      checkClass(ltd.getClassDesc(), INIT);
     String fieldname=fan.getFieldName();
 
     FieldDescriptor fd=null;
     if (ltd.isArray()&&fieldname.equals("length"))
       fd=FieldDescriptor.arrayLength;
-    else
+    else if(((left instanceof NameNode) && ((NameNode)left).isSuper())
+           ||((left instanceof FieldAccessNode) && ((FieldAccessNode)left).isSuper())){
+      fd = (FieldDescriptor) ltd.getClassDesc().getSuperDesc().getFieldTable().get(fieldname);
+    } else {
       fd=(FieldDescriptor) ltd.getClassDesc().getFieldTable().get(fieldname);
-
+    }
     if(ltd.isClassNameRef()) {
       // the field access is using a class name directly
+      if (fd==null) {
+       // check if it is to access a surrounding class in an inner class
+       if(fieldname.equals("this") || fieldname.equals("super")) {
+          ClassDescriptor icd = ((VarDescriptor)nametable.get("this")).getType().getClassDesc();
+          if(icd.isInnerClass()) {
+              NameNode nn = new NameNode(new NameDescriptor("this"));
+              nn.setVar((VarDescriptor)nametable.get("this"));
+              fan.setExpression(nn);
+              if(icd.getSurroundingDesc()==ltd.getClassDesc()) {
+                  // this is a surrounding class access inside an inner class
+                  fan.setExpression(nn);
+                  fan.setFieldName("this$0");
+                  fd = (FieldDescriptor)icd.getFieldTable().get("this$0");
+              } else if(icd==ltd.getClassDesc()) {
+                  // this is an inner class this operation 
+                  fd = new FieldDescriptor(new Modifiers(),new TypeDescriptor(icd),"this",null,false);
+              }
+              if(fieldname.equals("super")) {
+                  fan.setIsSuper();
+              }
+              fan.setField(fd);
+              return;
+          }
+       } 
+       ClassDescriptor surroundingCls=ltd.getClassDesc().getSurroundingDesc();
+       
+       while(surroundingCls!=null) {
+         fd=(FieldDescriptor) surroundingCls.getFieldTable().get(fieldname);
+         if (fd!=null) {
+           fan.left=new ClassTypeNode(new TypeDescriptor(surroundingCls));
+           break;
+         }
+         surroundingCls=surroundingCls.getSurroundingDesc();
+       }
+       
+       // check if it is to access an enum field
+       Iterator it_enum = ltd.getClassDesc().getEnum();
+       while(it_enum.hasNext()) {
+        ClassDescriptor ecd = (ClassDescriptor)it_enum.next();
+        if(ecd.getSymbol().equals(ltd.getClassDesc().getSymbol()+"$"+fieldname)) {
+          // this is an enum field access
+          if(!ecd.isStatic() && !ecd.getModifier().isStatic() && !ecd.getModifier().isPublic()) {
+            throw new Error(fieldname + " is not a public/static enum field in "+fan.printNode(0)+" in "+md);
+          }
+          TypeDescriptor tp = new TypeDescriptor(ecd);
+          tp.setClassNameRef();
+          fd=new FieldDescriptor(ecd.getModifier(), tp, ltd.getClassDesc().getSymbol()+"$"+fieldname, null, false);;
+          fd.setIsEnumClass();
+          break;
+        }
+       }
+      }
+
       if(ltd.getClassDesc().isEnum()) {
         int value = ltd.getClassDesc().getEnumConstant(fieldname);
         if(-1 == value) {
@@ -655,10 +761,24 @@ public class SemanticCheck {
       } else {
         throw new Error("Dereference of the non-static field "+ fieldname + " in "+fan.printNode(0)+" in "+md);
       }
-    } 
+    }
 
-    if (fd==null)
-      throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0)+" in "+md);
+    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;         
+           }   
+       }
+       throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0)+" in "+md);
+    }
 
     if (fd.getType().iswrapper()) {
       FieldAccessNode fan2=new FieldAccessNode(left, fieldname);
@@ -673,13 +793,13 @@ public class SemanticCheck {
       FieldDescriptor fdwr=(FieldDescriptor) ltdwr.getClassDesc().getFieldTable().get(fieldnamewr);
       fan.setField(fdwr);
       if (fdwr==null)
-         throw new Error("Unknown field "+fieldnamewr + " in "+fan.printNode(0)+" in "+md);
+        throw new Error("Unknown field "+fieldnamewr + " in "+fan.printNode(0)+" in "+md);
     } else {
       fan.setField(fd);
     }
     if (td!=null) {
       if (!typeutil.isSuperorType(td,fan.getType()))
-       throw new Error("Field node returns "+fan.getType()+", but need "+td);
+        throw new Error("Field node returns "+fan.getType()+", but need "+td);
     }
   }
 
@@ -695,7 +815,7 @@ public class SemanticCheck {
 
     if (td!=null)
       if (!typeutil.isSuperorType(td,aan.getType()))
-       throw new Error("Field node returns "+aan.getType()+", but need "+td);
+        throw new Error("Field node returns "+aan.getType()+", but need "+td);
   }
 
   void checkLiteralNode(Descriptor md, SymbolTable nametable, LiteralNode ln, TypeDescriptor td) {
@@ -722,17 +842,17 @@ public class SemanticCheck {
     if (td!=null)
       if (!typeutil.isSuperorType(td,ln.getType())) {
         Long l = ln.evaluate();
-        if((ln.getType().isByte() || ln.getType().isShort() 
-            || ln.getType().isChar() || ln.getType().isInt()) 
-            && (l != null) 
-            && (td.isByte() || td.isShort() || td.isChar() 
-                || td.isInt() || td.isLong())) {
+        if((ln.getType().isByte() || ln.getType().isShort()
+            || ln.getType().isChar() || ln.getType().isInt())
+           && (l != null)
+           && (td.isByte() || td.isShort() || td.isChar()
+               || td.isInt() || td.isLong())) {
           long lnvalue = l.longValue();
-          if((td.isByte() && ((lnvalue > 127) || (lnvalue < -128))) 
-              || (td.isShort() && ((lnvalue > 32767) || (lnvalue < -32768)))
-              || (td.isChar() && ((lnvalue > 65535) || (lnvalue < 0)))
-              || (td.isInt() && ((lnvalue > 2147483647) || (lnvalue < -2147483648)))
-              || (td.isLong() && ((lnvalue > 9223372036854775807L) || (lnvalue < -9223372036854775808L)))) {
+          if((td.isByte() && ((lnvalue > 127) || (lnvalue < -128)))
+             || (td.isShort() && ((lnvalue > 32767) || (lnvalue < -32768)))
+             || (td.isChar() && ((lnvalue > 65535) || (lnvalue < 0)))
+             || (td.isInt() && ((lnvalue > 2147483647) || (lnvalue < -2147483648)))
+             || (td.isLong() && ((lnvalue > 9223372036854775807L) || (lnvalue < -9223372036854775808L)))) {
             throw new Error("Field node returns "+ln.getType()+", but need "+td+" in "+md);
           }
         } else {
@@ -741,6 +861,64 @@ public class SemanticCheck {
       }
   }
 
+  FieldDescriptor recurseSurroundingClasses( ClassDescriptor icd, String varname ) {
+        if( null == icd || false == icd.isInnerClass() )
+           return null;
+      
+        ClassDescriptor surroundingDesc = icd.getSurroundingDesc();
+        if( null == surroundingDesc )
+           return null;
+      
+        SymbolTable fieldTable = surroundingDesc.getFieldTable();
+        FieldDescriptor fd = ( FieldDescriptor ) fieldTable.get( varname );
+        if( null != fd )
+           return fd;
+        return recurseSurroundingClasses( surroundingDesc, varname );
+  }
+  
+  FieldAccessNode fieldAccessExpression( ClassDescriptor icd, String varname, int linenum ) {
+        FieldDescriptor fd = recurseSurroundingClasses( icd, varname );
+       if( null == fd )
+               return null;
+
+       ClassDescriptor cd = fd.getClassDescriptor();
+       if(icd.getInStaticContext()) {
+         // if the inner class is in a static context, it does not have the this$0 
+         // pointer to its surrounding class. Instead, it might have reference to 
+         // its static surrounding method/block is there is any and it can refer 
+         // to static fields in its surrounding class too.
+         if(fd.isStatic()) {
+           NameNode nn = new NameNode(new NameDescriptor(cd.getSymbol()));
+           nn.setNumLine(linenum);
+           FieldAccessNode theFieldNode = new FieldAccessNode(nn,varname);
+           theFieldNode.setNumLine(linenum);
+           return theFieldNode;
+         } else {
+           throw new Error("Error: access non-static field " + cd.getSymbol() + "." + fd.getSymbol() + " in an inner class " + icd.getSymbol() + " that is declared in a static context");
+         }
+       }
+       int depth = 1;
+       int startingDepth = icd.getInnerDepth();
+
+       if( true == cd.isInnerClass() ) 
+               depth = cd.getInnerDepth();
+
+       String composed = "this";
+       NameDescriptor runningDesc = new NameDescriptor( "this" );;
+       
+       for ( int index = startingDepth; index > depth; --index ) {
+               composed = "this$" + String.valueOf( index - 1  );      
+               runningDesc = new NameDescriptor( runningDesc, composed );
+       }
+       if( false == cd.isInnerClass() )
+               runningDesc = new NameDescriptor( runningDesc, "this$" + String.valueOf(0) ); //all the way up.
+       NameDescriptor idDesc = new NameDescriptor( runningDesc, varname );
+       
+       
+       FieldAccessNode theFieldNode = ( FieldAccessNode )translateNameDescriptorintoExpression( idDesc, linenum );
+       return theFieldNode;
+  }
+
   void checkNameNode(Descriptor md, SymbolTable nametable, NameNode nn, TypeDescriptor td) {
     NameDescriptor nd=nn.getName();
     if (nd.getBase()!=null) {
@@ -751,20 +929,46 @@ public class SemanticCheck {
       checkExpressionNode(md,nametable,en,td);
     } else {
       String varname=nd.toString();
-      if(varname.equals("this")) {
+      if(varname.equals("this") || varname.equals("super")) {
         // "this"
-        nn.setVar((VarDescriptor)nametable.get("this")); 
+        nn.setVar((VarDescriptor)nametable.get("this"));
+        if(varname.equals("super")) {
+            nn.setIsSuper();
+        }
         return;
       }
       Descriptor d=(Descriptor)nametable.get(varname);
       if (d==null) {
         ClassDescriptor cd = null;
+       //check the inner class case first.
+       if((md instanceof MethodDescriptor) && false == ((MethodDescriptor)md).isStaticBlock()) {
+               cd = ((MethodDescriptor)md).getClassDesc();
+               FieldAccessNode theFieldNode =  fieldAccessExpression( cd, varname, nn.getNumLine() );
+               if( null != theFieldNode ) {
+                       nn.setExpression(( ExpressionNode )theFieldNode);
+                       checkExpressionNode(md,nametable,( ExpressionNode )theFieldNode,td);
+                       return;         
+               } else if(cd.getInline() && (this.trialcheck)) {
+                   // for the trial check of an inline class, cache the unknown var
+                   d = cd.getSurroundingNameTable().get(varname);
+                   if(null!=d) {
+                     if(!this.inlineClass2LiveVars.containsKey(cd)) {
+                       this.inlineClass2LiveVars.put(cd, new Vector<VarDescriptor>());
+                     }
+                     Vector<VarDescriptor> vars = this.inlineClass2LiveVars.get(cd);
+                     if(!vars.contains((VarDescriptor)d)) {
+                       vars.add((VarDescriptor)d);
+                     }
+                   }
+               }
+       }
+       if(null==d) {
         if((md instanceof MethodDescriptor) && ((MethodDescriptor)md).isStaticBlock()) {
           // this is a static block, all the accessed fields should be static field
           cd = ((MethodDescriptor)md).getClassDesc();
           SymbolTable fieldtbl = cd.getFieldTable();
           FieldDescriptor fd=(FieldDescriptor)fieldtbl.get(varname);
-          if((fd == null) || (!fd.isStatic())){
+          if((fd == null) || (!fd.isStatic())) {
             // 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");
@@ -805,43 +1009,45 @@ public class SemanticCheck {
             nn.setClassDesc(cd);
             return;
           } else {
-            throw new Error("Name "+varname+" undefined in: "+md);
+            throw new Error("Name "+varname+" undefined in: "+md);         
           }
         }
+       }
       }
+
       if (d instanceof VarDescriptor) {
-       nn.setVar(d);
+        nn.setVar(d);
       } else if (d instanceof FieldDescriptor) {
-       FieldDescriptor fd=(FieldDescriptor)d;
-       if (fd.getType().iswrapper()) {
-         String id=nd.getIdentifier();
-         NameDescriptor base=nd.getBase();
-         NameNode n=new NameNode(nn.getName());
-         n.setNumLine(nn.getNumLine());
-         n.setField(fd);
-         n.setVar((VarDescriptor)nametable.get("this"));        /* Need a pointer to this */
-         FieldAccessNode fan=new FieldAccessNode(n,"value");
-         fan.setNumLine(n.getNumLine());
-         FieldDescriptor fdval=(FieldDescriptor) fd.getType().getClassDesc().getFieldTable().get("value");
-         fan.setField(fdval);
-         nn.setExpression(fan);
-       } else {
-         nn.setField(fd);
-         nn.setVar((VarDescriptor)nametable.get("this"));        /* Need a pointer to this */
-       }
+        FieldDescriptor fd=(FieldDescriptor)d;
+        if (fd.getType().iswrapper()) {
+          String id=nd.getIdentifier();
+          NameDescriptor base=nd.getBase();
+          NameNode n=new NameNode(nn.getName());
+          n.setNumLine(nn.getNumLine());
+          n.setField(fd);
+          n.setVar((VarDescriptor)nametable.get("this"));        /* Need a pointer to this */
+          FieldAccessNode fan=new FieldAccessNode(n,"value");
+          fan.setNumLine(n.getNumLine());
+          FieldDescriptor fdval=(FieldDescriptor) fd.getType().getClassDesc().getFieldTable().get("value");
+          fan.setField(fdval);
+          nn.setExpression(fan);
+        } else {
+          nn.setField(fd);
+          nn.setVar((VarDescriptor)nametable.get("this"));        /* Need a pointer to this */
+        }
       } else if (d instanceof TagVarDescriptor) {
-       nn.setVar(d);
+        nn.setVar(d);
       } else throw new Error("Wrong type of descriptor");
       if (td!=null)
-       if (!typeutil.isSuperorType(td,nn.getType()))
-         throw new Error("Field node returns "+nn.getType()+", but need "+td);
+        if (!typeutil.isSuperorType(td,nn.getType()))
+          throw new Error("Field node returns "+nn.getType()+", but need "+td);
     }
   }
 
   void checkOffsetNode(Descriptor md, SymbolTable nameTable, OffsetNode ofn, TypeDescriptor td) {
     TypeDescriptor ltd=ofn.td;
     checkTypeDescriptor(((md instanceof MethodDescriptor)?((MethodDescriptor)md).getClassDesc():null),ltd);
-    
+
     String fieldname = ofn.fieldname;
     FieldDescriptor fd=null;
     if (ltd.isArray()&&fieldname.equals("length")) {
@@ -858,9 +1064,7 @@ public class SemanticCheck {
 
     if (td!=null) {
       if (!typeutil.isSuperorType(td, ofn.getType())) {
-       System.out.println(td);
-       System.out.println(ofn.getType());
-       throw new Error("Type of rside not compatible with type of lside"+ofn.printNode(0));
+        throw new Error("Type of rside not compatible with type of lside"+ofn.printNode(0));
       }
     }
   }
@@ -868,88 +1072,57 @@ public class SemanticCheck {
 
   void checkTertiaryNode(Descriptor md, SymbolTable nametable, TertiaryNode tn, TypeDescriptor td) {
     checkExpressionNode(md, nametable, tn.getCond(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
-    checkExpressionNode(md, nametable, tn.getTrueExpr(), td );
-    checkExpressionNode(md, nametable, tn.getFalseExpr(), td );
+    checkExpressionNode(md, nametable, tn.getTrueExpr(), td);
+    checkExpressionNode(md, nametable, tn.getFalseExpr(), td);
   }
 
   void checkInstanceOfNode(Descriptor md, SymbolTable nametable, InstanceOfNode tn, TypeDescriptor td) {
     if (td!=null&&!td.isBoolean())
       throw new Error("Expecting type "+td+"for instanceof expression");
-    
+
     checkTypeDescriptor(((md instanceof MethodDescriptor)?((MethodDescriptor)md).getClassDesc():null), tn.getExprType());
     checkExpressionNode(md, nametable, tn.getExpr(), null);
   }
 
   void checkArrayInitializerNode(Descriptor md, SymbolTable nametable, ArrayInitializerNode ain, TypeDescriptor td) {
-    Vector<TypeDescriptor> vec_type = new Vector<TypeDescriptor>();
     for( int i = 0; i < ain.numVarInitializers(); ++i ) {
-      checkExpressionNode(md, nametable, ain.getVarInitializer(i), td==null?td:td.dereference());
-      vec_type.add(ain.getVarInitializer(i).getType());
-    }
-    // descide the type of this variableInitializerNode
-    TypeDescriptor out_type = vec_type.elementAt(0);
-    for(int i = 1; i < vec_type.size(); i++) {
-      TypeDescriptor tmp_type = vec_type.elementAt(i);
-      if(out_type == null) {
-        if(tmp_type != null) {
-          out_type = tmp_type;
-        }
-      } else if(out_type.isNull()) {
-        if(!tmp_type.isNull() ) {
-          if(!tmp_type.isArray()) {
-            throw new Error("Error: mixed type in var initializer list");
-          } else {
-            out_type = tmp_type;
-          }
-        }
-      } else if(out_type.isArray()) {
-        if(tmp_type.isArray()) {
-          if(tmp_type.getArrayCount() > out_type.getArrayCount()) {
-            out_type = tmp_type;
-          }
-        } else if((tmp_type != null) && (!tmp_type.isNull())) {
-          throw new Error("Error: mixed type in var initializer list");
-        }
-      } else if(out_type.isInt()) {
-        if(!tmp_type.isInt()) {
-          throw new Error("Error: mixed type in var initializer list");
-        }
-      } else if(out_type.isString()) {
-        if(!tmp_type.isString()) {
-          throw new Error("Error: mixed type in var initializer list");
-        }
-      }
+      checkExpressionNode(md, nametable, ain.getVarInitializer(i), td.dereference());
     }
-    if(out_type != null) {
-      out_type = out_type.makeArray(state);
-      //out_type.setStatic();
-    }
-    ain.setType(out_type);
+    if (td==null)
+       throw new Error();
+    
+    ain.setType(td);
   }
 
   void checkAssignmentNode(Descriptor md, SymbolTable nametable, AssignmentNode an, TypeDescriptor td) {
-    boolean postinc=true;
-    if (an.getOperation().getBaseOp()==null||
-        (an.getOperation().getBaseOp().getOp()!=Operation.POSTINC&&
-         an.getOperation().getBaseOp().getOp()!=Operation.POSTDEC))
-      postinc=false;
-    if (!postinc)      
-      checkExpressionNode(md, nametable, an.getSrc(),td);
-    //TODO: Need check on validity of operation here
+    // Need to first check the lside to decide the correct type of the rside
+    // TODO: Need check on validity of operation here
     if (!((an.getDest() instanceof FieldAccessNode)||
           (an.getDest() instanceof ArrayAccessNode)||
           (an.getDest() instanceof NameNode)))
       throw new Error("Bad lside in "+an.printNode(0));
     checkExpressionNode(md, nametable, an.getDest(), null);
+    boolean postinc=true;
+    if (an.getOperation().getBaseOp()==null||
+        (an.getOperation().getBaseOp().getOp()!=Operation.POSTINC&&
+         an.getOperation().getBaseOp().getOp()!=Operation.POSTDEC))
+      postinc=false;
+    if (!postinc) {
+      if(an.getSrc() instanceof ArrayInitializerNode) {
+       checkExpressionNode(md, nametable, an.getSrc(), an.getDest().getType());
+      } else {
+        checkExpressionNode(md, nametable, an.getSrc(),td);
+      }
+    }
 
     /* We want parameter variables to tasks to be immutable */
     if (md instanceof TaskDescriptor) {
       if (an.getDest() instanceof NameNode) {
-       NameNode nn=(NameNode)an.getDest();
-       if (nn.getVar()!=null) {
-         if (((TaskDescriptor)md).getParameterTable().contains(nn.getVar().getSymbol()))
-           throw new Error("Can't modify parameter "+nn.getVar()+ " to task "+td.getSymbol());
-       }
+        NameNode nn=(NameNode)an.getDest();
+        if (nn.getVar()!=null) {
+          if (((TaskDescriptor)md).getParameterTable().contains(nn.getVar().getSymbol()))
+            throw new Error("Can't modify parameter "+nn.getVar()+ " to task "+td.getSymbol());
+        }
       }
     }
 
@@ -961,11 +1134,11 @@ public class SemanticCheck {
       NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
 
       if (!(an.getSrc().getType().isString()&&(an.getSrc() instanceof OpNode))) {
-       MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
-       rightmin.setNumLine(an.getSrc().getNumLine());
-       rightmin.addArgument(an.getSrc());
-       an.right=rightmin;
-       checkExpressionNode(md, nametable, an.getSrc(), null);
+        MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
+        rightmin.setNumLine(an.getSrc().getNumLine());
+        rightmin.addArgument(an.getSrc());
+        an.right=rightmin;
+        checkExpressionNode(md, nametable, an.getSrc(), null);
       }
     }
 
@@ -980,8 +1153,8 @@ public class SemanticCheck {
             dt = dt.dereference();
             st = st.dereference();
           } while(dt.isArray());
-          if((st.isByte() || st.isShort() || st.isChar() || st.isInt()) 
-              && (dt.isByte() || dt.isShort() || dt.isChar() || dt.isInt() || dt.isLong())) {
+          if((st.isByte() || st.isShort() || st.isChar() || st.isInt())
+             && (dt.isByte() || dt.isShort() || dt.isChar() || dt.isInt() || dt.isLong())) {
             return;
           } else {
             throw new Error("Type of rside ("+an.getSrc().getType().toPrettyString()+") not compatible with type of lside ("+an.getDest().getType().toPrettyString()+")"+an.printNode(0));
@@ -989,15 +1162,15 @@ public class SemanticCheck {
         }
       } else {
         Long l = an.getSrc().evaluate();
-        if((st.isByte() || st.isShort() || st.isChar() || st.isInt()) 
-            && (l != null) 
-            && (dt.isByte() || dt.isShort() || dt.isChar() || dt.isInt() || dt.isLong())) {
+        if((st.isByte() || st.isShort() || st.isChar() || st.isInt())
+           && (l != null)
+           && (dt.isByte() || dt.isShort() || dt.isChar() || dt.isInt() || dt.isLong())) {
           long lnvalue = l.longValue();
-          if((dt.isByte() && ((lnvalue > 127) || (lnvalue < -128))) 
-              || (dt.isShort() && ((lnvalue > 32767) || (lnvalue < -32768)))
-              || (dt.isChar() && ((lnvalue > 65535) || (lnvalue < 0)))
-              || (dt.isInt() && ((lnvalue > 2147483647) || (lnvalue < -2147483648)))
-              || (dt.isLong() && ((lnvalue > 9223372036854775807L) || (lnvalue < -9223372036854775808L)))) {
+          if((dt.isByte() && ((lnvalue > 127) || (lnvalue < -128)))
+             || (dt.isShort() && ((lnvalue > 32767) || (lnvalue < -32768)))
+             || (dt.isChar() && ((lnvalue > 65535) || (lnvalue < 0)))
+             || (dt.isInt() && ((lnvalue > 2147483647) || (lnvalue < -2147483648)))
+             || (dt.isLong() && ((lnvalue > 9223372036854775807L) || (lnvalue < -9223372036854775808L)))) {
             throw new Error("Type of rside ("+an.getSrc().getType().toPrettyString()+") not compatible with type of lside ("+an.getDest().getType().toPrettyString()+")"+an.printNode(0));
           }
         } else {
@@ -1008,7 +1181,7 @@ public class SemanticCheck {
   }
 
   void checkLoopNode(Descriptor md, SymbolTable nametable, LoopNode ln) {
-      loopstack.push(ln);
+    loopstack.push(ln);
     if (ln.getType()==LoopNode.WHILELOOP||ln.getType()==LoopNode.DOWHILELOOP) {
       checkExpressionNode(md, nametable, ln.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
       checkBlockNode(md, nametable, ln.getBody());
@@ -1018,8 +1191,8 @@ public class SemanticCheck {
       BlockNode bn=ln.getInitializer();
       bn.getVarTable().setParent(nametable);
       for(int i=0; i<bn.size(); i++) {
-       BlockStatementNode bsn=bn.get(i);
-       checkBlockStatementNode(md, bn.getVarTable(),bsn);
+        BlockStatementNode bsn=bn.get(i);
+        checkBlockStatementNode(md, bn.getVarTable(),bsn);
       }
       //check the condition
       checkExpressionNode(md, bn.getVarTable(), ln.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
@@ -1029,9 +1202,116 @@ public class SemanticCheck {
     loopstack.pop();
   }
 
-
+  void InnerClassAddParamToCtor( MethodDescriptor md, ClassDescriptor cd, SymbolTable nametable, 
+                                CreateObjectNode con, TypeDescriptor td ) {
+       
+       TypeDescriptor cdsType = new TypeDescriptor( cd );
+       ExpressionNode conExp = con.getSurroundingClassExpression();
+       //System.out.println( "The surrounding class expression si " + con );
+       if( null == conExp ) {
+               if( md.isStatic()) {
+                       throw new Error("trying to instantiate inner class: " +  con.getType() + " in a static scope" );
+               }
+               VarDescriptor thisVD = md.getThis();
+               if( null == thisVD ) {
+                       throw new Error( "this pointer is not defined in a non static scope" ); 
+               }                       
+               if( cdsType.equals( thisVD.getType() ) == false ) {
+                       throw new Error( "the type of this pointer is different than the type expected for inner class constructor. Initializing the inner class: "                             +  con.getType() + " in the wrong scope" );             
+               }       
+               //make this into an expression node.
+               NameNode nThis=new NameNode( new NameDescriptor( "this" ) );
+               con.addArgument( nThis );
+       }
+       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.
+               con.addArgument( conExp );
+       }
+       //System.out.println( " the modified createObjectNode is " + con.printNode( 0 ) + "\n" );
+}
+  
+  void trialSemanticCheck(ClassDescriptor cd) {
+    if(!cd.getInline()) {
+      throw new Error("Error! Try to do a trial check on a non-inline class " + cd.getSymbol());
+    }
+    trialcheck = true;
+      
+    for (Iterator method_it = cd.getMethods(); method_it.hasNext(); ) {
+      MethodDescriptor md = (MethodDescriptor) method_it.next();
+      try {
+        checkMethodBody(cd, md);
+      } catch (Error e) {
+        System.out.println("Error in " + md);
+        throw e;
+      }
+    }
+    trialcheck = false;
+  }
+  
+  // add all the live vars that are referred by the inline class in the surrounding 
+  // context of the inline class into the inline class' field table and pass them to 
+  // the inline class' constructors
+  // TODO: BUGFIX. These local vars should be final. But currently we've lost those 
+  // information, so we cannot have that checked.
+  void InlineClassAddParamToCtor(MethodDescriptor md, ClassDescriptor cd , SymbolTable nametable, CreateObjectNode con, TypeDescriptor td, TypeDescriptor[] tdarray ) {
+    // for an inline class, need to first add the original parameters of the CreatObjectNode
+    // into its anonymous constructor and insert a super(...) into the anonymous constructor
+    // if its super class is not null
+    MethodDescriptor cd_constructor = null;
+    for(Iterator it_methods = cd.getMethods(); it_methods.hasNext();) {
+      MethodDescriptor imd = (MethodDescriptor)it_methods.next();
+      if(imd.isConstructor()) {
+         cd_constructor = imd; // an inline class should only have one anonymous constructor
+      }
+    }
+    MethodInvokeNode min = null;
+    if(cd.getSuper()!= null) {
+      // add a super(...) into the anonymous constructor
+      NameDescriptor nd=new NameDescriptor("super");
+      min=new MethodInvokeNode(nd);
+      BlockExpressionNode ben=new BlockExpressionNode(min);
+      BlockNode bn = state.getMethodBody(cd_constructor);
+      bn.addFirstBlockStatement(ben);
+      if(cd.getSuperDesc().isInnerClass()&&!cd.getSuperDesc().isStatic()&&!cd.getSuperDesc().getInStaticContext()) {
+       // for a super class that is also an inner class with surrounding reference, add the surrounding 
+       // instance of the child instance as the parent instance's surrounding instance
+       min.addArgument(new NameNode(new NameDescriptor("surrounding$0")));
+      }
+    }
+    for(int i = 0 ; i < tdarray.length; i++) {
+      assert(null!=min);
+      TypeDescriptor itd = tdarray[i];
+      cd_constructor.addParameter(itd, itd.getSymbol()+"_from_con_node_"+i);
+      min.addArgument(new NameNode(new NameDescriptor(itd.getSymbol()+"_from_con_node_"+i)));
+    }
+    
+    // Next add the live vars into the inline class' fields
+    cd.setSurroundingNameTable(nametable);
+    // do a round of semantic check trial to get all the live vars required by the inline class
+    trialSemanticCheck(cd);
+    Vector<VarDescriptor> vars = this.inlineClass2LiveVars.remove(cd);
+    if(vars == null) {
+      return;
+    }
+    for(int i = 0; i < vars.size(); i++) {
+      Descriptor d = vars.elementAt(i);
+      if(d instanceof VarDescriptor && !d.getSymbol().equals("this")) {
+        con.addArgument(new NameNode(new NameDescriptor(d.getSymbol())));
+        cd.addField(new FieldDescriptor(new Modifiers(Modifiers.PUBLIC), ((VarDescriptor)d).getType(), d.getSymbol(), null, false));
+        cd_constructor.addParameter(((VarDescriptor)d).getType(), d.getSymbol()+"_p");
+        // add the initialize statement into this constructor
+        BlockNode obn = state.getMethodBody(cd_constructor);
+        NameNode nn=new NameNode(new NameDescriptor(d.getSymbol()));
+        NameNode fn = new NameNode (new NameDescriptor(d.getSymbol()+"_p"));
+        AssignmentNode an=new AssignmentNode(nn,fn,new AssignOperation(1));
+        obn.addFirstBlockStatement(new BlockExpressionNode(an));
+        state.addTreeCode(cd_constructor, obn);
+      }
+    }
+  }
+  
   void checkCreateObjectNode(Descriptor md, SymbolTable nametable, CreateObjectNode con,
-      TypeDescriptor td) {
+                             TypeDescriptor td) {
     TypeDescriptor[] tdarray = new TypeDescriptor[con.numArgs()];
     for (int i = 0; i < con.numArgs(); i++) {
       ExpressionNode en = con.getArg(i);
@@ -1047,7 +1327,12 @@ public class SemanticCheck {
 
     /* Check Array Initializers */
     if ((con.getArrayInitializer() != null)) {
-      checkArrayInitializerNode(md, nametable, con.getArrayInitializer(), td);
+      checkArrayInitializerNode(md, nametable, con.getArrayInitializer(), typetolookin);
+    }
+    
+    if(this.trialcheck) {
+      // for a trialcheck of an inline class, skip the rest process
+      return;
     }
 
     /* Check flag effects */
@@ -1086,10 +1371,28 @@ public class SemanticCheck {
       // Array's don't need constructor calls
       ClassDescriptor classtolookin = typetolookin.getClassDesc();
       checkClass(classtolookin, INIT);
-
-      Set methoddescriptorset = classtolookin.getMethodTable().getSet(typetolookin.getSymbol());
+      if( classtolookin.isInnerClass() ) {
+       // for inner class that is declared in a static context, it does not have 
+       // lexically enclosing instances
+       if(!classtolookin.getInStaticContext()) {
+           InnerClassAddParamToCtor( (MethodDescriptor)md, ((MethodDescriptor)md).getClassDesc() , nametable, con, td );
+       }
+       if(classtolookin.getInline()) {
+         // for an inline anonymous inner class, the live local variables that are 
+         // referred to by the inline class are passed as parameters of the constructors
+         // of the inline class
+         InlineClassAddParamToCtor( (MethodDescriptor)md, classtolookin, nametable, con, td, tdarray );
+       }
+        tdarray = new TypeDescriptor[con.numArgs()];
+        for (int i = 0; i < con.numArgs(); i++) {
+          ExpressionNode en = con.getArg(i);
+          checkExpressionNode(md, nametable, en, null);
+          tdarray[i] = en.getType();
+        }
+      }
+      Set methoddescriptorset = classtolookin.getMethodTable().getSet(classtolookin.getSymbol());
       MethodDescriptor bestmd = null;
-      NextMethod: for (Iterator methodit = methoddescriptorset.iterator(); methodit.hasNext();) {
+NextMethod: for (Iterator methodit = methoddescriptorset.iterator(); methodit.hasNext(); ) {
         MethodDescriptor currmd = (MethodDescriptor) methodit.next();
         /* Need correct number of parameters */
         if (con.numArgs() != currmd.numParameters())
@@ -1106,22 +1409,23 @@ public class SemanticCheck {
         if (bestmd == null)
           bestmd = currmd;
         else {
-          if (typeutil.isMoreSpecific(currmd, bestmd)) {
+          if (typeutil.isMoreSpecific(currmd, bestmd, true)) {
             bestmd = currmd;
           } else if (con.isGlobal() && match(currmd, bestmd)) {
             if (currmd.isGlobal() && !bestmd.isGlobal())
               bestmd = currmd;
             else if (currmd.isGlobal() && bestmd.isGlobal())
               throw new Error();
-          } else if (!typeutil.isMoreSpecific(bestmd, currmd)) {
+          } else if (!typeutil.isMoreSpecific(bestmd, currmd, true)) {
             throw new Error("No method is most specific:" + bestmd + " and " + currmd);
           }
 
           /* Is this more specific than bestmd */
         }
       }
-      if (bestmd == null)
+      if (bestmd == null) {
         throw new Error("No method found for " + con.printNode(0) + " in " + md);
+      }
       con.setConstructor(bestmd);
     }
   }
@@ -1135,7 +1439,7 @@ public class SemanticCheck {
       throw new Error();
     for(int i=0; i<md1.numParameters(); i++) {
       if (!md2.getParamType(i).equals(md1.getParamType(i)))
-       return false;
+        return false;
     }
     if (!md2.getReturnType().equals(md1.getReturnType()))
       return false;
@@ -1151,17 +1455,52 @@ public class SemanticCheck {
   ExpressionNode translateNameDescriptorintoExpression(NameDescriptor nd, int numLine) {
     String id=nd.getIdentifier();
     NameDescriptor base=nd.getBase();
-    if (base==null){
+    if (base==null) {
       NameNode nn=new NameNode(nd);
       nn.setNumLine(numLine);
       return nn;
-    }else{
+    } else {
       FieldAccessNode fan=new FieldAccessNode(translateNameDescriptorintoExpression(base,numLine),id);
       fan.setNumLine(numLine);
       return fan;
     }
   }
 
+  MethodDescriptor recurseSurroundingClassesM( ClassDescriptor icd, String varname ) {
+      if( null == icd || false == icd.isInnerClass() )
+           return null;
+    
+      ClassDescriptor surroundingDesc = icd.getSurroundingDesc();
+      if( null == surroundingDesc )
+           return null;
+    
+      SymbolTable methodTable = surroundingDesc.getMethodTable();
+      MethodDescriptor md = ( MethodDescriptor ) methodTable.get( varname );
+      if( null != md )
+           return md;
+      return recurseSurroundingClassesM( surroundingDesc, varname );
+  }
+
+  ExpressionNode methodInvocationExpression( ClassDescriptor icd, MethodDescriptor md, int linenum ) {
+       ClassDescriptor cd = md.getClassDesc();
+       int depth = 1;
+       int startingDepth = icd.getInnerDepth();
+
+       if( true == cd.isInnerClass() ) 
+               depth = cd.getInnerDepth();
+
+       String composed = "this";
+       NameDescriptor runningDesc = new NameDescriptor( "this" );;
+       
+       for ( int index = startingDepth; index > depth; --index ) {
+               composed = "this$" + String.valueOf( index - 1  );      
+               runningDesc = new NameDescriptor( runningDesc, composed );
+       }
+       if( false == cd.isInnerClass() )
+               runningDesc = new NameDescriptor( runningDesc, "this$" + String.valueOf(0) ); //all the way up.
+
+       return new NameNode(runningDesc);
+}
 
   void checkMethodInvokeNode(Descriptor md, SymbolTable nametable, MethodInvokeNode min, TypeDescriptor td) {
     /*Typecheck subexpressions
@@ -1176,6 +1515,7 @@ public class SemanticCheck {
       ExpressionNode en=min.getArg(i);
       checkExpressionNode(md,nametable,en,null);
       tdarray[i]=en.getType();
+
       if(en.getType().isClass() && en.getType().getClassDesc().isEnum()) {
         tdarray[i] = new TypeDescriptor(TypeDescriptor.INT);
       }
@@ -1184,15 +1524,12 @@ public class SemanticCheck {
     if (min.getExpression()!=null) {
       checkExpressionNode(md,nametable,min.getExpression(),null);
       typetolookin=min.getExpression().getType();
-      //if (typetolookin==null)
-      //throw new Error(md+" has null return type");
-
     } else if (min.getBaseName()!=null) {
       String rootname=min.getBaseName().getRoot();
       if (rootname.equals("super")) {
-       ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
-       typetolookin=new TypeDescriptor(supercd);
-       min.setSuper();
+        ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
+        typetolookin=new TypeDescriptor(supercd);
+        min.setSuper();
       } else if (rootname.equals("this")) {
         if(isstatic) {
           throw new Error("use this object in static method md = "+ md.toString());
@@ -1200,37 +1537,52 @@ public class SemanticCheck {
         ClassDescriptor cd=((MethodDescriptor)md).getClassDesc();
         typetolookin=new TypeDescriptor(cd);
       } else if (nametable.get(rootname)!=null) {
-       //we have an expression
-       min.setExpression(translateNameDescriptorintoExpression(min.getBaseName(),min.getNumLine()));
-       checkExpressionNode(md, nametable, min.getExpression(), null);
-       typetolookin=min.getExpression().getType();
+        //we have an expression
+        min.setExpression(translateNameDescriptorintoExpression(min.getBaseName(),min.getNumLine()));
+        checkExpressionNode(md, nametable, min.getExpression(), null);
+        typetolookin=min.getExpression().getType();
       } else {
-       if(!min.getBaseName().getSymbol().equals("System.out")) {
-         ExpressionNode nn = translateNameDescriptorintoExpression(min.getBaseName(),min.getNumLine());
-         checkExpressionNode(md, nametable, nn, null);
-         typetolookin = nn.getType();
-         if(!((nn.kind()== Kind.NameNode) && (((NameNode)nn).getField() == null)
-              && (((NameNode)nn).getVar() == null) && (((NameNode)nn).getExpression() == null))) {
-           // this is not a pure class name, need to add to 
-           min.setExpression(nn);
-         }
-       } else {
-         //we have a type
-         ClassDescriptor cd = null;
-         //if (min.getBaseName().getSymbol().equals("System.out"))
-         cd=getClass(null, "System");
-         /*else {
-            cd=getClass(min.getBaseName().getSymbol());
-           }*/
-         if (cd==null)
-           throw new Error("md = "+ md.toString()+ "  "+min.getBaseName()+" undefined");
-         typetolookin=new TypeDescriptor(cd);
-       }
+        if(!min.getBaseName().getSymbol().equals("System.out")||state.JNI) {
+          ExpressionNode nn = translateNameDescriptorintoExpression(min.getBaseName(),min.getNumLine());
+          checkExpressionNode(md, nametable, nn, null);
+          typetolookin = nn.getType();
+          if(!((nn.kind()== Kind.NameNode) && (((NameNode)nn).getField() == null)
+               && (((NameNode)nn).getVar() == null) && (((NameNode)nn).getExpression() == null))) {
+            // this is not a pure class name, need to add to
+            min.setExpression(nn);
+          }
+        } else {
+          //we have a type
+          ClassDescriptor cd = getClass(null, "System");
+
+          if (cd==null)
+            throw new Error("md = "+ md.toString()+ "  "+min.getBaseName()+" undefined");
+          typetolookin=new TypeDescriptor(cd);
+        }
       }
     } else if ((md instanceof MethodDescriptor)&&min.getMethodName().equals("super")) {
       ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
       min.methodid=supercd.getSymbol();
       typetolookin=new TypeDescriptor(supercd);
+      if(supercd.isInnerClass()&&!supercd.isStatic()&&!supercd.getInStaticContext()) {
+       // for a super class that is also an inner class with surrounding reference, add the surrounding 
+       // instance of the child instance as the parent instance's surrounding instance
+       if(((MethodDescriptor)md).isConstructor()) {
+         min.addArgument(new NameNode(new NameDescriptor("surrounding$0")));
+       } else if(((MethodDescriptor)md).getClassDesc().isInnerClass()&&!((MethodDescriptor)md).getClassDesc().isStatic()&&!((MethodDescriptor)md).getClassDesc().getInStaticContext()) {
+         min.addArgument(new NameNode(new NameDescriptor("this$0")));
+       }
+      }
+      tdarray=new TypeDescriptor[min.numArgs()];
+      for(int i=0; i<min.numArgs(); i++) {
+        ExpressionNode en=min.getArg(i);
+        checkExpressionNode(md,nametable,en,null);
+        tdarray[i]=en.getType();
+
+        if(en.getType().isClass() && en.getType().getClassDesc().isEnum()) {
+          tdarray[i] = new TypeDescriptor(TypeDescriptor.INT);
+        }
+      }
     } else if (md instanceof MethodDescriptor) {
       typetolookin=new TypeDescriptor(((MethodDescriptor)md).getClassDesc());
     } else {
@@ -1238,76 +1590,90 @@ public class SemanticCheck {
       throw new Error("Unknown method call to "+min.getMethodName()+"in task"+md.getSymbol());
     }
     if (!typetolookin.isClass())
-      throw new Error("Error with method call to "+min.getMethodName());
+      throw new Error("Error with method call to "+min.getMethodName()+" in class "+typetolookin);
     ClassDescriptor classtolookin=typetolookin.getClassDesc();
-    checkClass(classtolookin, INIT);
-    //System.out.println("Method name="+min.getMethodName());
-
+    checkClass(classtolookin, REFERENCE);
     Set methoddescriptorset=classtolookin.getMethodTable().getSet(min.getMethodName());
     MethodDescriptor bestmd=null;
 NextMethod:
-    for(Iterator methodit=methoddescriptorset.iterator(); methodit.hasNext();) {
+    for(Iterator methodit=methoddescriptorset.iterator(); methodit.hasNext(); ) {
       MethodDescriptor currmd=(MethodDescriptor)methodit.next();
       /* Need correct number of parameters */
       if (min.numArgs()!=currmd.numParameters())
-       continue;
+        continue;
       for(int i=0; i<min.numArgs(); i++) {
-       if (!typeutil.isSuperorType(currmd.getParamType(i),tdarray[i]))
-         if(((!tdarray[i].isArray() &&(tdarray[i].isInt() || tdarray[i].isLong())) 
-             && currmd.getParamType(i).isClass() && currmd.getParamType(i).getClassDesc().getSymbol().equals("Object"))) {
-           // primitive parameters vs object
-         } else {
-           continue NextMethod;
-         }
+        if (!typeutil.isSuperorType(currmd.getParamType(i),tdarray[i]))
+          if(((!tdarray[i].isArray() &&(tdarray[i].isInt() || tdarray[i].isLong()))
+              && currmd.getParamType(i).isClass() && currmd.getParamType(i).getClassDesc().getSymbol().equals("Object"))) {
+            // primitive parameters vs object
+          } else {
+            continue NextMethod;
+          }
       }
       /* Method okay so far */
       if (bestmd==null)
-       bestmd=currmd;
+        bestmd=currmd;
       else {
-       if (typeutil.isMoreSpecific(currmd,bestmd)) {
-         bestmd=currmd;
-       } else if (!typeutil.isMoreSpecific(bestmd, currmd))
-         throw new Error("No method is most specific:"+bestmd+" and "+currmd);
+        if (typeutil.isMoreSpecific(currmd,bestmd, false)) {
+          bestmd=currmd;
+        } else if (!typeutil.isMoreSpecific(bestmd, currmd, false)) {
+          // if the two methods are inherited from super class/interface, use the super class' as first priority
+          if(bestmd.getClassDesc().isInterface()&&!currmd.getClassDesc().isInterface()) {
+            bestmd = currmd;
+          } else {
+            throw new Error("No method is most specific:"+bestmd+" and "+currmd);
+          }
+        }
 
-       /* Is this more specific than bestmd */
+        /* Is this more specific than bestmd */
+      }
+    }
+    if (bestmd==null) {
+      // if this is an inner class, need to check the method table for the surrounding class
+      bestmd = recurseSurroundingClassesM(classtolookin, min.getMethodName());
+      if(bestmd == null)
+         throw new Error("No method found for :"+min.printNode(0)+" in class: " + classtolookin+" in "+md);
+      else {
+         // set the correct "this" expression here
+         ExpressionNode en=methodInvocationExpression(classtolookin, bestmd, min.getNumLine());
+         min.setExpression(en);
+         checkExpressionNode(md, nametable, min.getExpression(), null);
       }
     }
-    if (bestmd==null)
-      throw new Error("No method found for :"+min.printNode(0)+" in class: " + classtolookin+" in "+md);
     min.setMethod(bestmd);
 
     if ((td!=null)&&(min.getType()!=null)&&!typeutil.isSuperorType(td,  min.getType()))
       throw new Error(min.getType()+ " is not equal to or a subclass of "+td);
     /* Check whether we need to set this parameter to implied this */
-    if (! isstatic && !bestmd.isStatic()) {
+    if (!isstatic && !bestmd.isStatic()) {
       if (min.getExpression()==null) {
-       ExpressionNode en=new NameNode(new NameDescriptor("this"));
-       min.setExpression(en);
-       checkExpressionNode(md, nametable, min.getExpression(), null);
+        ExpressionNode en=new NameNode(new NameDescriptor("this"));
+        min.setExpression(en);
+        checkExpressionNode(md, nametable, min.getExpression(), null);
       }
     }
-    
+
     /* Check if we need to wrap primitive paratmeters to objects */
     for(int i=0; i<min.numArgs(); i++) {
       if(!tdarray[i].isArray() && (tdarray[i].isInt() || tdarray[i].isLong())
-        && min.getMethod().getParamType(i).isClass() && min.getMethod().getParamType(i).getClassDesc().getSymbol().equals("Object")) {
-       // Shall wrap this primitive parameter as a object
-       ExpressionNode exp = min.getArg(i);
-       TypeDescriptor ptd = null;
-       NameDescriptor nd=null;
-       if(exp.getType().isInt()) {
-         nd = new NameDescriptor("Integer");
-         ptd = state.getTypeDescriptor(nd);
-       } else if(exp.getType().isLong()) {
-         nd = new NameDescriptor("Long");
-         ptd = state.getTypeDescriptor(nd);
-       }
-       boolean isglobal = false;
-       String disjointId = null;
-       CreateObjectNode con=new CreateObjectNode(ptd, isglobal, disjointId);
-       con.addArgument(exp);
-       checkExpressionNode(md, nametable, con, null);
-       min.setArgument(con, i);
+         && min.getMethod().getParamType(i).isClass() && min.getMethod().getParamType(i).getClassDesc().getSymbol().equals("Object")) {
+        // Shall wrap this primitive parameter as a object
+        ExpressionNode exp = min.getArg(i);
+        TypeDescriptor ptd = null;
+        NameDescriptor nd=null;
+        if(exp.getType().isInt()) {
+          nd = new NameDescriptor("Integer");
+          ptd = state.getTypeDescriptor(nd);
+        } else if(exp.getType().isLong()) {
+          nd = new NameDescriptor("Long");
+          ptd = state.getTypeDescriptor(nd);
+        }
+        boolean isglobal = false;
+        String disjointId = null;
+        CreateObjectNode con=new CreateObjectNode(ptd, isglobal, disjointId);
+        con.addArgument(exp);
+        checkExpressionNode(md, nametable, con, null);
+        min.setArgument(con, i);
       }
     }
   }
@@ -1318,7 +1684,7 @@ NextMethod:
     if (on.getRight()!=null)
       checkExpressionNode(md, nametable, on.getRight(), null);
     TypeDescriptor ltd=on.getLeft().getType();
-    TypeDescriptor rtd=on.getRight()!=null ? on.getRight().getType() : null;
+    TypeDescriptor rtd=on.getRight()!=null?on.getRight().getType():null;
     TypeDescriptor lefttype=null;
     TypeDescriptor righttype=null;
     Operation op=on.getOp();
@@ -1327,12 +1693,12 @@ NextMethod:
     case Operation.LOGIC_OR:
     case Operation.LOGIC_AND:
       if (!(rtd.isBoolean()))
-       throw new Error();
+        throw new Error();
       on.setRightType(rtd);
 
     case Operation.LOGIC_NOT:
       if (!(ltd.isBoolean()))
-       throw new Error();
+        throw new Error();
       //no promotion
       on.setLeftType(ltd);
 
@@ -1343,13 +1709,13 @@ NextMethod:
       // 5.6.2 Binary Numeric Promotion
       //TODO unboxing of reference objects
       if (ltd.isDouble())
-       throw new Error();
+        throw new Error();
       else if (ltd.isFloat())
-       throw new Error();
+        throw new Error();
       else if (ltd.isLong())
-       lefttype=new TypeDescriptor(TypeDescriptor.LONG);
+        lefttype=new TypeDescriptor(TypeDescriptor.LONG);
       else
-       lefttype=new TypeDescriptor(TypeDescriptor.INT);
+        lefttype=new TypeDescriptor(TypeDescriptor.INT);
       on.setLeftType(lefttype);
       on.setType(lefttype);
       break;
@@ -1360,16 +1726,16 @@ NextMethod:
       // 5.6.2 Binary Numeric Promotion
       //TODO unboxing of reference objects
       if (ltd.isDouble()||rtd.isDouble())
-       throw new Error();
+        throw new Error();
       else if (ltd.isFloat()||rtd.isFloat())
-       throw new Error();
+        throw new Error();
       else if (ltd.isLong()||rtd.isLong())
-       lefttype=new TypeDescriptor(TypeDescriptor.LONG);
+        lefttype=new TypeDescriptor(TypeDescriptor.LONG);
       // 090205 hack for boolean
       else if (ltd.isBoolean()||rtd.isBoolean())
-       lefttype=new TypeDescriptor(TypeDescriptor.BOOLEAN);
+        lefttype=new TypeDescriptor(TypeDescriptor.BOOLEAN);
       else
-       lefttype=new TypeDescriptor(TypeDescriptor.INT);
+        lefttype=new TypeDescriptor(TypeDescriptor.INT);
       righttype=lefttype;
 
       on.setLeftType(lefttype);
@@ -1379,7 +1745,7 @@ NextMethod:
 
     case Operation.ISAVAILABLE:
       if (!(ltd.isPtr())) {
-       throw new Error("Can't use isavailable on non-pointers/non-parameters.");
+        throw new Error("Can't use isavailable on non-pointers/non-parameters.");
       }
       lefttype=ltd;
       on.setLeftType(lefttype);
@@ -1391,25 +1757,25 @@ NextMethod:
       // 5.6.2 Binary Numeric Promotion
       //TODO unboxing of reference objects
       if (ltd.isBoolean()||rtd.isBoolean()) {
-       if (!(ltd.isBoolean()&&rtd.isBoolean()))
-         throw new Error();
-       righttype=lefttype=new TypeDescriptor(TypeDescriptor.BOOLEAN);
+        if (!(ltd.isBoolean()&&rtd.isBoolean()))
+          throw new Error();
+        righttype=lefttype=new TypeDescriptor(TypeDescriptor.BOOLEAN);
       } else if (ltd.isPtr()||rtd.isPtr()) {
-       if (!(ltd.isPtr()&&rtd.isPtr())) {
-      if(!rtd.isEnum()) {
-        throw new Error();
-      }
-    }
-       righttype=rtd;
-       lefttype=ltd;
+        if (!(ltd.isPtr()&&rtd.isPtr())) {
+          if(!rtd.isEnum()) {
+            throw new Error();
+          }
+        }
+        righttype=rtd;
+        lefttype=ltd;
       } else if (ltd.isDouble()||rtd.isDouble())
-       righttype=lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
+        righttype=lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
       else if (ltd.isFloat()||rtd.isFloat())
-       righttype=lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
+        righttype=lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
       else if (ltd.isLong()||rtd.isLong())
-       righttype=lefttype=new TypeDescriptor(TypeDescriptor.LONG);
+        righttype=lefttype=new TypeDescriptor(TypeDescriptor.LONG);
       else
-       righttype=lefttype=new TypeDescriptor(TypeDescriptor.INT);
+        righttype=lefttype=new TypeDescriptor(TypeDescriptor.INT);
 
       on.setLeftType(lefttype);
       on.setRightType(righttype);
@@ -1425,20 +1791,20 @@ NextMethod:
       // 5.6.2 Binary Numeric Promotion
       //TODO unboxing of reference objects
       if (!ltd.isNumber()||!rtd.isNumber()) {
-       if (!ltd.isNumber())
-         throw new Error("Leftside is not number"+on.printNode(0)+"type="+ltd.toPrettyString());
-       if (!rtd.isNumber())
-         throw new Error("Rightside is not number"+on.printNode(0));
+        if (!ltd.isNumber())
+          throw new Error("Leftside is not number"+on.printNode(0)+"type="+ltd.toPrettyString());
+        if (!rtd.isNumber())
+          throw new Error("Rightside is not number"+on.printNode(0));
       }
 
       if (ltd.isDouble()||rtd.isDouble())
-       lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
+        lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
       else if (ltd.isFloat()||rtd.isFloat())
-       lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
+        lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
       else if (ltd.isLong()||rtd.isLong())
-       lefttype=new TypeDescriptor(TypeDescriptor.LONG);
+        lefttype=new TypeDescriptor(TypeDescriptor.LONG);
       else
-       lefttype=new TypeDescriptor(TypeDescriptor.INT);
+        lefttype=new TypeDescriptor(TypeDescriptor.INT);
       righttype=lefttype;
       on.setLeftType(lefttype);
       on.setRightType(righttype);
@@ -1447,30 +1813,30 @@ NextMethod:
 
     case Operation.ADD:
       if (ltd.isString()||rtd.isString()) {
-       ClassDescriptor stringcl=getClass(null, TypeUtil.StringClass);
-       TypeDescriptor stringtd=new TypeDescriptor(stringcl);
-       NameDescriptor nd=new NameDescriptor("String");
-       NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
-       if (!(ltd.isString()&&(on.getLeft() instanceof OpNode))) {
-         MethodInvokeNode leftmin=new MethodInvokeNode(valuend);
-         leftmin.setNumLine(on.getLeft().getNumLine());
-         leftmin.addArgument(on.getLeft());
-         on.left=leftmin;
-         checkExpressionNode(md, nametable, on.getLeft(), null);
-       }
+        ClassDescriptor stringcl=getClass(null, TypeUtil.StringClass);
+        TypeDescriptor stringtd=new TypeDescriptor(stringcl);
+        NameDescriptor nd=new NameDescriptor("String");
+        NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
+        if (!(ltd.isString()&&(on.getLeft() instanceof OpNode))) {
+          MethodInvokeNode leftmin=new MethodInvokeNode(valuend);
+          leftmin.setNumLine(on.getLeft().getNumLine());
+          leftmin.addArgument(on.getLeft());
+          on.left=leftmin;
+          checkExpressionNode(md, nametable, on.getLeft(), null);
+        }
 
-       if (!(rtd.isString()&&(on.getRight() instanceof OpNode))) {
-         MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
-         rightmin.setNumLine(on.getRight().getNumLine());
-         rightmin.addArgument(on.getRight());
-         on.right=rightmin;
-         checkExpressionNode(md, nametable, on.getRight(), null);
-       }
+        if (!(rtd.isString()&&(on.getRight() instanceof OpNode))) {
+          MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
+          rightmin.setNumLine(on.getRight().getNumLine());
+          rightmin.addArgument(on.getRight());
+          on.right=rightmin;
+          checkExpressionNode(md, nametable, on.getRight(), null);
+        }
 
-       on.setLeftType(stringtd);
-       on.setRightType(stringtd);
-       on.setType(stringtd);
-       break;
+        on.setLeftType(stringtd);
+        on.setRightType(stringtd);
+        on.setType(stringtd);
+        break;
       }
 
     case Operation.SUB:
@@ -1480,16 +1846,16 @@ NextMethod:
       // 5.6.2 Binary Numeric Promotion
       //TODO unboxing of reference objects
       if (ltd.isArray()||rtd.isArray()||!ltd.isNumber()||!rtd.isNumber())
-       throw new Error("Error in "+on.printNode(0));
+        throw new Error("Error in "+on.printNode(0));
 
       if (ltd.isDouble()||rtd.isDouble())
-       lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
+        lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
       else if (ltd.isFloat()||rtd.isFloat())
-       lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
+        lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
       else if (ltd.isLong()||rtd.isLong())
-       lefttype=new TypeDescriptor(TypeDescriptor.LONG);
+        lefttype=new TypeDescriptor(TypeDescriptor.LONG);
       else
-       lefttype=new TypeDescriptor(TypeDescriptor.INT);
+        lefttype=new TypeDescriptor(TypeDescriptor.INT);
       righttype=lefttype;
       on.setLeftType(lefttype);
       on.setRightType(righttype);
@@ -1500,16 +1866,16 @@ NextMethod:
     case Operation.RIGHTSHIFT:
     case Operation.URIGHTSHIFT:
       if (!rtd.isIntegerType())
-       throw new Error();
+        throw new Error();
       //5.6.1 Unary Numeric Promotion
       if (rtd.isByte()||rtd.isShort()||rtd.isInt())
-       righttype=new TypeDescriptor(TypeDescriptor.INT);
+        righttype=new TypeDescriptor(TypeDescriptor.INT);
       else
-       righttype=rtd;
+        righttype=rtd;
 
       on.setRightType(righttype);
       if (!ltd.isIntegerType())
-       throw new Error();
+        throw new Error();
 
     case Operation.UNARYPLUS:
     case Operation.UNARYMINUS:
@@ -1518,12 +1884,12 @@ NextMethod:
           case Operation.PREINC:
           case Operation.PREDEC:*/
       if (!ltd.isNumber())
-       throw new Error();
+        throw new Error();
       //5.6.1 Unary Numeric Promotion
       if (ltd.isByte()||ltd.isShort()||ltd.isInt())
-       lefttype=new TypeDescriptor(TypeDescriptor.INT);
+        lefttype=new TypeDescriptor(TypeDescriptor.INT);
       else
-       lefttype=ltd;
+        lefttype=ltd;
       on.setLeftType(lefttype);
       on.setType(lefttype);
       break;
@@ -1534,10 +1900,8 @@ NextMethod:
 
     if (td!=null)
       if (!typeutil.isSuperorType(td, on.getType())) {
-       System.out.println(td);
-       System.out.println(on.getType());
-       throw new Error("Type of rside not compatible with type of lside"+on.printNode(0));
+        throw new Error("Type of rside not compatible with type of lside"+on.printNode(0));
       }
   }
-  
+
 }