implemented PCLOC annotation.
[IRC.git] / Robust / src / IR / Tree / BuildIR.java
index f42d7d82eaa844269b0cad2ec01fc7ea69457f31..c8efb8e7bc29898770e26fdbb7b1bb8a90733140 100644 (file)
@@ -5,15 +5,17 @@ import Util.Pair;
 
 import java.io.File;
 import java.util.*;
-
+import java.io.*;
+import java.lang.Throwable;
 public class BuildIR {
   State state;
-
+  private boolean isRunningRecursiveInnerClass;
   private int m_taskexitnum;
 
   public BuildIR(State state) {
     this.state=state;
     this.m_taskexitnum = 0;
+    this.isRunningRecursiveInnerClass = false;
   }
 
   public void buildtree(ParseNode pn, Set toanalyze, String sourcefile) {
@@ -32,16 +34,31 @@ public class BuildIR {
 
   //This is all single imports and a subset of the
   //multi imports that have been resolved.
-  Hashtable mandatoryImports;
+  ChainHashMap mandatoryImports;
   //maps class names in file to full name
   //Note may map a name to an ERROR.
-  Hashtable multiimports;
-  NameDescriptor packages;
+  ChainHashMap multiimports;
+  String packageName;
+
+  String currsourcefile;
+  Set analyzeset;
+
+  void pushChainMaps() {
+    mandatoryImports=mandatoryImports.makeChild();
+    multiimports=multiimports.makeChild();
+  }
+  
+  void popChainMaps() {
+    mandatoryImports=mandatoryImports.getParent();
+    multiimports=multiimports.getParent();
+  }
 
   /** Parse the classes in this file */
   public void parseFile(ParseNode pn, Set toanalyze, String sourcefile) {
-    mandatoryImports = new Hashtable();
-    multiimports = new Hashtable();
+    mandatoryImports = new ChainHashMap();
+    multiimports = new ChainHashMap();
+    currsourcefile=sourcefile;
+    analyzeset=toanalyze;
 
     if(state.JNI) {
       //add java.lang as our default multi-import
@@ -70,7 +87,7 @@ public class BuildIR {
     }
 
     ParseNode ppn=pn.getChild("packages").getChild("package");
-    String packageName = null;
+    packageName = null;
     if ((ppn!=null) && !state.MGC){
       NameDescriptor nd = parseClassName(ppn.getChild("name"));
       packageName = nd.getPathFromRootToHere();
@@ -87,12 +104,9 @@ public class BuildIR {
         if (isEmpty(type_pn)) /* Skip the semicolon */
           continue;
         if (isNode(type_pn, "class_declaration")) {
-          ClassDescriptor cn = parseTypeDecl(type_pn, packageName);
-          cn.setSourceFileName(sourcefile);
+          ClassDescriptor cn = parseTypeDecl(type_pn);
           parseInitializers(cn);
-          if (toanalyze != null)
-            toanalyze.add(cn);
-          state.addClass(cn);
+
           // for inner classes/enum
           HashSet tovisit = new HashSet();
           Iterator it_icds = cn.getInnerClasses();
@@ -104,36 +118,11 @@ public class BuildIR {
             ClassDescriptor cd = (ClassDescriptor) tovisit.iterator().next();
             tovisit.remove(cd);
             parseInitializers(cd);
-            if (toanalyze != null) {
-              toanalyze.add(cd);
-            }
-            cd.setSourceFileName(sourcefile);
-            state.addClass(cd);
 
             Iterator it_ics = cd.getInnerClasses();
             while (it_ics.hasNext()) {
               tovisit.add(it_ics.next());
             }
-
-            Iterator it_ienums = cd.getEnum();
-            while (it_ienums.hasNext()) {
-              ClassDescriptor iecd = (ClassDescriptor) it_ienums.next();
-              if (toanalyze != null) {
-                toanalyze.add(iecd);
-              }
-              iecd.setSourceFileName(sourcefile);
-              state.addClass(iecd);
-            }
-          }
-
-          Iterator it_enums = cn.getEnum();
-          while (it_enums.hasNext()) {
-            ClassDescriptor ecd = (ClassDescriptor) it_enums.next();
-            if (toanalyze != null) {
-              toanalyze.add(ecd);
-            }
-            ecd.setSourceFileName(sourcefile);
-            state.addClass(ecd);
           }
         } else if (isNode(type_pn, "task_declaration")) {
           TaskDescriptor td = parseTaskDecl(type_pn);
@@ -142,35 +131,13 @@ public class BuildIR {
           state.addTask(td);
         } else if (isNode(type_pn, "interface_declaration")) {
           // TODO add version for normal Java later
-          ClassDescriptor cn = parseInterfaceDecl(type_pn, packageName);
-          if (toanalyze != null)
-            toanalyze.add(cn);
-          cn.setSourceFileName(sourcefile);
-          state.addClass(cn);
-
-          // for enum
-          Iterator it_enums = cn.getEnum();
-          while (it_enums.hasNext()) {
-            ClassDescriptor ecd = (ClassDescriptor) it_enums.next();
-            if (toanalyze != null) {
-              toanalyze.add(ecd);
-            }
-            ecd.setSourceFileName(sourcefile);
-            state.addClass(ecd);
-          }
+          ClassDescriptor cn = parseInterfaceDecl(type_pn, null);
         } else if (isNode(type_pn, "enum_declaration")) {
           // TODO add version for normal Java later
           ClassDescriptor cn = parseEnumDecl(null, type_pn);
-          if (toanalyze != null)
-            toanalyze.add(cn);
-          cn.setSourceFileName(sourcefile);
-          state.addClass(cn);
+
         } else if(isNode(type_pn,"annotation_type_declaration")) {
           ClassDescriptor cn=parseAnnotationTypeDecl(type_pn);
-          if (toanalyze != null)
-            toanalyze.add(cn);
-          cn.setSourceFileName(sourcefile);
-          state.addClass(cn);
         } else {
           throw new Error(type_pn.getLabel());
         }
@@ -179,7 +146,6 @@ public class BuildIR {
   }
 
 
-
   //This kind of breaks away from tradition a little bit by doing the file checks here
   // instead of in Semantic check, but doing it here is easier because we have a mapping early on
   // if I wait until semantic check, I have to change ALL the type descriptors to match the new
@@ -210,7 +176,6 @@ public class BuildIR {
       }
     }
 
-
     if(!found) {
       throw new Error("Import package " + importPath + " in  " + currentSource
                       + " cannot be resolved.");
@@ -219,27 +184,61 @@ public class BuildIR {
 
   public void parseInitializers(ClassDescriptor cn) {
     Vector fv=cn.getFieldVec();
+    Iterator methodit = cn.getMethods();
+    HashMap<MethodDescriptor, Integer> md2pos = new HashMap<MethodDescriptor, Integer>();
+    while(methodit.hasNext()) {
+      MethodDescriptor currmd=(MethodDescriptor)methodit.next();
+      if(currmd.isConstructor()) {
+        BlockNode bn=state.getMethodBody(currmd);
+        // if there are super(...) invokation, the initializers should be invoked after that
+        int i = 0;
+        for(; i < bn.size(); i++) {
+          if(Kind.BlockExpressionNode==bn.get(i).kind()
+                 &&(((BlockExpressionNode)bn.get(i)).getExpression() instanceof MethodInvokeNode)
+                 &&((MethodInvokeNode)(((BlockExpressionNode)bn.get(i)).getExpression())).getMethodName().equals("super")) {
+            break;
+          }
+        }
+        if(i==bn.size()) {
+          md2pos.put(currmd, 0);
+        } else {
+          md2pos.put(currmd, i+1);
+        }
+      }
+    }
     int pos = 0;
     for(int i=0; i<fv.size(); i++) {
       FieldDescriptor fd=(FieldDescriptor)fv.get(i);
       if(fd.getExpressionNode()!=null) {
-        Iterator methodit = cn.getMethods();
+        methodit = cn.getMethods();
         while(methodit.hasNext()) {
           MethodDescriptor currmd=(MethodDescriptor)methodit.next();
           if(currmd.isConstructor()) {
+            int offset = md2pos.get(currmd);
             BlockNode bn=state.getMethodBody(currmd);
             NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
             AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
-            bn.addBlockStatementAt(new BlockExpressionNode(an), pos);
+            bn.addBlockStatementAt(new BlockExpressionNode(an), pos+offset);
           }
         }
         pos++;
       }
     }
   }
+  
+  private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {    
+    String basename=pn.getChild("name").getTerminal();
+    String classname=(cn!=null)?cn.getClassName()+"$"+basename:basename;
+    ClassDescriptor ecd=new ClassDescriptor(cn!=null?cn.getPackage():null, classname, false);
+    
+    if (cn!=null) {
+      if (packageName==null)
+       cn.getSingleImportMappings().put(basename,classname);
+      else
+       cn.getSingleImportMappings().put(basename,packageName+"."+classname);
+    }
 
-  private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {
-    ClassDescriptor ecd=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
+    pushChainMaps();
     ecd.setImports(mandatoryImports, multiimports);
     ecd.setAsEnum();
     if(cn != null) {
@@ -253,6 +252,10 @@ public class BuildIR {
     }
     ecd.setModifiers(parseModifiersList(pn.getChild("modifiers")));
     parseEnumBody(ecd, pn.getChild("enumbody"));
+
+    addClass2State(ecd);
+
+    popChainMaps();
     return ecd;
   }
 
@@ -275,12 +278,17 @@ public class BuildIR {
 
   private ClassDescriptor parseAnnotationTypeDecl(ParseNode pn) {
     ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal(), true);
+    pushChainMaps();
     cn.setImports(mandatoryImports, multiimports);
     ParseNode modifiers=pn.getChild("modifiers");
     if(modifiers!=null) {
       cn.setModifiers(parseModifiersList(modifiers));
     }
     parseAnnotationTypeBody(cn,pn.getChild("body"));
+    popChainMaps();
+
+    addClass2State(cn);
+
     return cn;
   }
 
@@ -311,15 +319,18 @@ public class BuildIR {
     }
   }
 
-  public ClassDescriptor parseInterfaceDecl(ParseNode pn, String packageName) {
-    ClassDescriptor cn;
-    if(packageName == null) {
-      cn=new ClassDescriptor(pn.getChild("name").getTerminal(), true);
-    } else  {
-      String newClassname = packageName + "." + pn.getChild("name").getTerminal();
-      cn= new ClassDescriptor(packageName, newClassname, true);
+  public ClassDescriptor parseInterfaceDecl(ParseNode pn, ClassDescriptor outerclass) {
+    String basename=pn.getChild("name").getTerminal();
+    String classname=((outerclass==null)?"":(outerclass.getClassName()+"$"))+basename;
+    if (outerclass!=null) {
+      if (packageName==null)
+       outerclass.getSingleImportMappings().put(basename,classname);
+      else
+       outerclass.getSingleImportMappings().put(basename,packageName+"."+classname);
     }
+    ClassDescriptor cn= new ClassDescriptor(packageName, classname, true);
 
+    pushChainMaps();
     cn.setImports(mandatoryImports, multiimports);
     //cn.setAsInterface();
     if (!isEmpty(pn.getChild("superIF").getTerminal())) {
@@ -331,11 +342,15 @@ public class BuildIR {
         if (isNode(decl,"type")) {
           NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
           cn.addSuperInterface(nd.toString());
-        }
+        } else if (isNode(decl, "interface_declaration")) {
+          ClassDescriptor innercn = parseInterfaceDecl(decl, cn);
+       } else throw new Error();
       }
     }
     cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
     parseInterfaceBody(cn, pn.getChild("interfacebody"));
+    addClass2State(cn);
+    popChainMaps();
     return cn;
   }
 
@@ -350,7 +365,9 @@ public class BuildIR {
           parseInterfaceConstant(cn,decl);
         } else if (isNode(decl,"method")) {
           parseInterfaceMethod(cn,decl.getChild("method_declaration"));
-        } else throw new Error();
+        } else if (isNode(decl, "interface_declaration")) {
+         parseInterfaceDecl(decl, cn);
+       } else throw new Error(decl.PPrint(2, true));
       }
     }
   }
@@ -372,20 +389,9 @@ public class BuildIR {
     md.getModifiers().addModifier(Modifiers.PUBLIC);
     md.getModifiers().addModifier(Modifiers.ABSTRACT);
     try {
-      BlockNode bn=parseBlock(bodyn);
+      BlockNode bn=parseBlock(cn, md, md.isStatic()||md.isStaticBlock(), bodyn);
       cn.addMethod(md);
       state.addTreeCode(md,bn);
-
-      // this is a hack for investigating new language features
-      // at the AST level, someday should evolve into a nice compiler
-      // option *wink*
-      //if( cn.getSymbol().equals( ***put a class in here like:     "Test" ) &&
-      //    md.getSymbol().equals( ***put your method in here like: "main" )
-      //) {
-      //  bn.setStyle( BlockNode.NORMAL );
-      //  System.out.println( bn.printNode( 0 ) );
-      //}
-
     } catch (Exception e) {
       System.out.println("Error with method:"+md.getSymbol());
       e.printStackTrace();
@@ -400,7 +406,7 @@ public class BuildIR {
   public TaskDescriptor parseTaskDecl(ParseNode pn) {
     TaskDescriptor td=new TaskDescriptor(pn.getChild("name").getTerminal());
     ParseNode bodyn=pn.getChild("body");
-    BlockNode bn=parseBlock(bodyn);
+    BlockNode bn=parseBlock(null, null, false, bodyn);
     parseParameterList(td, pn);
     state.addTreeCode(td,bn);
     if (pn.getChild("flag_effects_list")!=null)
@@ -554,16 +560,25 @@ public class BuildIR {
     return tel;
   }
 
-  public ClassDescriptor parseTypeDecl(ParseNode pn, String packageName) {
-    ClassDescriptor cn;
-    // if is in no package, then create a class descriptor with just the name.
-    // else add the package on
-    if(packageName == null) {
-      cn=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
-    } else  {
-      String newClassname = packageName + "." + pn.getChild("name").getTerminal();
-      cn= new ClassDescriptor(packageName, newClassname, false);
+  private void addClass2State(ClassDescriptor cn) {
+    if (analyzeset != null)
+      analyzeset.add(cn);
+    cn.setSourceFileName(currsourcefile);
+    state.addClass(cn);
+    // create this$n representing a final reference to the next surrounding class. each inner class should have whatever inner class
+    // pointers the surrounding class has + a pointer to the surrounding class.
+    if( true )
+    {
+      this.isRunningRecursiveInnerClass = true; //fOR dEBUGGING PURPOSES IN ORDER TO DUMP STRINGS WHILE IN THIS CODE PATH
+      addOuterClassReferences( cn, cn, 0 );
+      addOuterClassParam( cn, cn, 0 );
+      this.isRunningRecursiveInnerClass = false;
     }
+  }
+  
+  public ClassDescriptor parseTypeDecl(ParseNode pn) {
+    ClassDescriptor cn=new ClassDescriptor(packageName, pn.getChild("name").getTerminal(), false);
+    pushChainMaps();
     cn.setImports(mandatoryImports, multiimports);
     if (!isEmpty(pn.getChild("super").getTerminal())) {
       /* parse superclass name */
@@ -605,9 +620,100 @@ public class BuildIR {
       md.setDefaultConstructor();
       cn.addMethod(md);
     }
+
+
+    popChainMaps();
+
+    cn.setSourceFileName(currsourcefile);
+    
+    addClass2State(cn);
+
     return cn;
   }
 
+private void initializeOuterMember( MethodDescriptor md, String fieldName, String formalParameter ) {
+        BlockNode obn = state.getMethodBody(md);
+         NameNode nn=new NameNode( new NameDescriptor( fieldName ) );
+        NameNode fn = new NameNode ( new NameDescriptor( formalParameter ) );
+          //nn.setNumLine(en.getNumLine())
+         AssignmentNode an=new AssignmentNode(nn,fn,new AssignOperation(1));
+         //an.setNumLine(pn.getLine());
+         obn.addFirstBlockStatement(new BlockExpressionNode(an));
+       // System.out.print( "The code inserted is : " + obn.printNode( 0 ) + "\n" );
+         state.addTreeCode(md, obn);
+}
+
+private void addOuterClassParam( ClassDescriptor cn, ClassDescriptor ocn, int depth )
+{
+       Iterator nullCheckItr = cn.getInnerClasses();
+       if( false == nullCheckItr.hasNext() )
+               return;
+
+       //create a typedescriptor of type cn
+       TypeDescriptor theTypeDesc = new TypeDescriptor( ocn );
+       
+       for(Iterator it=cn.getInnerClasses(); it.hasNext(); ) {
+               ClassDescriptor icd=(ClassDescriptor)it.next();
+               if(icd.isStatic()||icd.getInStaticContext()) {
+                   continue;
+               }
+               
+               //iterate over all ctors of I.Cs and add a new param
+               for(Iterator method_it=icd.getMethods(); method_it.hasNext(); ) {
+                        MethodDescriptor md=(MethodDescriptor)method_it.next();
+                        if( md.isConstructor() ){
+                               md.addParameter( theTypeDesc, "surrounding___DOLLAR___" + String.valueOf(depth) );      
+                               initializeOuterMember( md, "this___DOLLAR___" + String.valueOf( depth ), "surrounding___DOLLAR___" + String.valueOf(depth) );
+                               //System.out.println( "The added param is " + md.toString() + "\n" );
+                       }
+               }
+               addOuterClassParam( icd, ocn, depth + 1 );
+               
+       }
+       
+}
+private void addOuterClassReferences( ClassDescriptor cn, ClassDescriptor ocn, int depth )
+{
+       //SYMBOLTABLE does not have a length or empty method, hence could not define a hasInnerClasses method in classDescriptor
+       Iterator nullCheckItr = cn.getInnerClasses();
+       if( false == nullCheckItr.hasNext() )
+               return;
+
+       String tempCopy = ocn.getClassName();
+       //MESSY HACK FOLLOWS
+       int i = 0;
+
+       ParseNode theNode = new ParseNode( "field_declaration" );
+       theNode.addChild("modifier").addChild( new ParseNode( "modifier_list" ) ).addChild("final");
+       ParseNode theTypeNode = new ParseNode("type");
+       ParseNode tempChildNode = theTypeNode.addChild("class").addChild( "name" );
+               //tempChildNode.addChild("base").addChild( new ParseNode("empty") );
+       tempChildNode.addChild("identifier").addChild ( tempCopy );
+       theNode.addChild("type").addChild( theTypeNode );
+       ParseNode variableDeclaratorID = new ParseNode("single");
+       String theStr = "this___DOLLAR___" + String.valueOf( depth );
+       variableDeclaratorID.addChild( theStr );
+       ParseNode variableDeclarator = new ParseNode( "variable_declarator" );
+       variableDeclarator.addChild( variableDeclaratorID );
+       ParseNode variableDeclaratorList = new ParseNode("variable_declarators_list");
+       variableDeclaratorList.addChild( variableDeclarator );
+       theNode.addChild("variables").addChild( variableDeclaratorList );
+
+       for(Iterator it=cn.getInnerClasses(); it.hasNext(); ) {
+               ClassDescriptor icd=(ClassDescriptor)it.next();
+               if(icd.isStatic() || icd.getInStaticContext()) {
+                 continue;
+               }
+               parseFieldDecl( icd, theNode );         
+               /*if( true ) {
+                       SymbolTable fieldTable = icd.getFieldTable();
+                       //System.out.println( fieldTable.toString() );
+               }*/
+               icd.setInnerDepth( depth + 1 );
+               addOuterClassReferences( icd, ocn, depth + 1 ); 
+       }
+}
+
   private void parseClassBody(ClassDescriptor cn, ParseNode pn) {
     ParseNode decls=pn.getChild("class_body_declaration_list");
     if (decls!=null) {
@@ -629,6 +735,7 @@ public class BuildIR {
   private void parseClassMember(ClassDescriptor cn, ParseNode pn) {
     ParseNode fieldnode=pn.getChild("field");
     if (fieldnode!=null) {
+      //System.out.println( pn.PPrint( 0, true ) );
       parseFieldDecl(cn,fieldnode.getChild("field_declaration"));
       return;
     }
@@ -642,9 +749,15 @@ public class BuildIR {
       parseInnerClassDecl(cn,innerclassnode);
       return;
     }
+     ParseNode innerinterfacenode=pn.getChild("interface_declaration");
+    if (innerinterfacenode!=null) {
+      parseInterfaceDecl(innerinterfacenode, cn);
+      return;
+    }
+
     ParseNode enumnode=pn.getChild("enum_declaration");
     if (enumnode!=null) {
-      parseEnumDecl(cn,enumnode);
+      ClassDescriptor ecn=parseEnumDecl(cn,enumnode);
       return;
     }
     ParseNode flagnode=pn.getChild("flag");
@@ -657,17 +770,29 @@ public class BuildIR {
     if(emptynode != null) {
       return;
     }
+    System.out.println("Unrecognized node:"+pn.PPrint(2,true));
     throw new Error();
   }
 
+//10/9/2011 changed this function to enable creation of default constructor for inner classes.
+//the change was refactoring this function with the corresponding version for normal classes. sganapat
   private ClassDescriptor parseInnerClassDecl(ClassDescriptor cn, ParseNode pn) {
-    ClassDescriptor icn=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
+    String basename=pn.getChild("name").getTerminal();
+    String classname=cn.getClassName()+"$"+basename;
+
+    if (cn.getPackage()==null)
+      cn.getSingleImportMappings().put(basename,classname);
+    else
+      cn.getSingleImportMappings().put(basename,cn.getPackage()+"."+classname);
+    
+    ClassDescriptor icn=new ClassDescriptor(cn.getPackage(), classname, false);
+    pushChainMaps();
     icn.setImports(mandatoryImports, multiimports);
-    icn.setAsInnerClass();
     icn.setSurroundingClass(cn.getSymbol());
     icn.setSurrounding(cn);
     cn.addInnerClass(icn);
-    if (!isEmpty(pn.getChild("super").getTerminal())) {
+
+     if (!isEmpty(pn.getChild("super").getTerminal())) {
       /* parse superclass name */
       ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
       NameDescriptor nd=parseClassName(snn);
@@ -691,11 +816,31 @@ public class BuildIR {
       }
     }
     icn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
-    if(!icn.isStatic()) {
-      throw new Error("Error: inner class " + icn.getSymbol() + " in Class " +
-                      cn.getSymbol() + " is not a nested class and is not supported yet!");
-    }
+
+   if (!icn.isStatic())
+     icn.setAsInnerClass();
+
     parseClassBody(icn, pn.getChild("classbody"));
+
+    boolean hasConstructor = false;
+    for(Iterator method_it=icn.getMethods(); method_it.hasNext(); ) {
+      MethodDescriptor md=(MethodDescriptor)method_it.next();
+      hasConstructor |= md.isConstructor();
+    }
+//sganapat adding change to allow proper construction of inner class objects
+    if((!hasConstructor) && (!icn.isEnum())) {
+      // add a default constructor for this class
+      MethodDescriptor md = new MethodDescriptor(new Modifiers(Modifiers.PUBLIC),
+                                                 icn.getSymbol(), false);
+      BlockNode bn=new BlockNode();
+      state.addTreeCode(md,bn);
+      md.setDefaultConstructor();
+      icn.addMethod(md);
+   }
+    popChainMaps();
+
+    addClass2State(icn);
+
     return icn;
   }
 
@@ -738,6 +883,8 @@ public class BuildIR {
   //we do not want to apply our resolveName function (i.e. deal with imports)
   //otherwise, if base == null, we do just want to resolve name.
   private NameDescriptor parseClassName(ParseNode nn) {
+    
+
     ParseNode base=nn.getChild("base");
     ParseNode id=nn.getChild("identifier");
     String classname = id.getTerminal();
@@ -825,6 +972,11 @@ public class BuildIR {
       ParseNode vardecl=pnv.elementAt(i);
       ParseNode tmp=vardecl;
       TypeDescriptor arrayt=t;
+       if( this.isRunningRecursiveInnerClass && false )
+       {       
+               System.out.println( "the length of the list is " + String.valueOf( pnv.size() ) );
+               System.out.println( "\n the parse node is \n" + tmp.PPrint( 0, true ) );
+       }
       while (tmp.getChild("single")==null) {
         arrayt=arrayt.makeArray(state);
         tmp=tmp.getChild("array");
@@ -833,8 +985,9 @@ public class BuildIR {
       ParseNode epn=vardecl.getChild("initializer");
 
       ExpressionNode en=null;
+      
       if (epn!=null) {
-        en=parseExpression(epn.getFirstChild());
+        en=parseExpression(cn, null, m.isStatic(), epn.getFirstChild());
         en.setNumLine(epn.getFirstChild().getLine());
         if(m.isStatic()) {
           // for static field, the initializer should be considered as a
@@ -890,9 +1043,12 @@ public class BuildIR {
 
   int innerCount=0;
 
-  private ExpressionNode parseExpression(ParseNode pn) {
+  private ExpressionNode parseExpression(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn) {
     if (isNode(pn,"assignment"))
-      return parseAssignmentExpression(pn);
+       {
+          //System.out.println( "parsing a field decl in my class that has assignment in initialization " + pn.PPrint( 0, true ) + "\n");
+      return parseAssignmentExpression(cn, md, isStaticContext, pn);
+       }
     else if (isNode(pn,"logical_or")||isNode(pn,"logical_and")||
              isNode(pn,"bitwise_or")||isNode(pn,"bitwise_xor")||
              isNode(pn,"bitwise_and")||isNode(pn,"equal")||
@@ -907,7 +1063,7 @@ public class BuildIR {
       ParseNode left=pnv.elementAt(0);
       ParseNode right=pnv.elementAt(1);
       Operation op=new Operation(pn.getLabel());
-      OpNode on=new OpNode(parseExpression(left),parseExpression(right),op);
+      OpNode on=new OpNode(parseExpression(cn, md, isStaticContext, left),parseExpression(cn, md, isStaticContext,  right),op);
       on.setNumLine(pn.getLine());
       return on;
     } else if (isNode(pn,"unaryplus")||
@@ -916,14 +1072,14 @@ public class BuildIR {
                isNode(pn,"comp")) {
       ParseNode left=pn.getFirstChild();
       Operation op=new Operation(pn.getLabel());
-      OpNode on=new OpNode(parseExpression(left),op);
+      OpNode on=new OpNode(parseExpression(cn, md, isStaticContext, left),op);
       on.setNumLine(pn.getLine());
       return on;
     } else if (isNode(pn,"postinc")||
                isNode(pn,"postdec")) {
       ParseNode left=pn.getFirstChild();
       AssignOperation op=new AssignOperation(pn.getLabel());
-      AssignmentNode an=new AssignmentNode(parseExpression(left),null,op);
+      AssignmentNode an=new AssignmentNode(parseExpression(cn, md, isStaticContext, left),null,op);
       an.setNumLine(pn.getLine());
       return an;
 
@@ -931,7 +1087,7 @@ public class BuildIR {
                isNode(pn,"predec")) {
       ParseNode left=pn.getFirstChild();
       AssignOperation op=isNode(pn,"preinc")?new AssignOperation(AssignOperation.PLUSEQ):new AssignOperation(AssignOperation.MINUSEQ);
-      AssignmentNode an=new AssignmentNode(parseExpression(left),
+      AssignmentNode an=new AssignmentNode(parseExpression(cn, md, isStaticContext, left),
                                            new LiteralNode("integer",new Integer(1)),op);
       an.setNumLine(pn.getLine());
       return an;
@@ -945,13 +1101,30 @@ public class BuildIR {
     } else if (isNode(pn, "createobject")) {
       TypeDescriptor td = parseTypeDescriptor(pn);
 
-      Vector args = parseArgumentList(pn);
+      Vector args = parseArgumentList(cn, md, isStaticContext, pn);
       boolean isglobal = pn.getChild("global") != null || pn.getChild("scratch") != null;
       String disjointId = null;
       if (pn.getChild("disjoint") != null) {
         disjointId = pn.getChild("disjoint").getTerminal();
       }
+      ParseNode idChild = (pn.getChild( "id" ));
+      ParseNode baseChild = (pn.getChild( "base" ));
+      
       CreateObjectNode con = new CreateObjectNode(td, isglobal, disjointId);
+      if( null != idChild && null != idChild.getFirstChild() ) {
+       idChild = idChild.getFirstChild();
+       //System.out.println( "\nThe object passed has this expression " + idChild.PPrint( 0, true ) );
+       ExpressionNode en = parseExpression(cn, md, isStaticContext, idChild ); 
+       //System.out.println( "\nThe object passed has this expression " + en.printNode( 0 ) );
+       con.setSurroundingExpression( en );
+      }
+      else if( null != baseChild  && null != baseChild.getFirstChild()  ) {
+       baseChild = baseChild.getFirstChild();
+       //System.out.println( "\nThe object passed has this expression " + baseChild.PPrint( 0, true ) );
+       ExpressionNode en = parseExpression(cn, md, isStaticContext, baseChild ); 
+       //System.out.println( "\nThe object passed has this expression " + en.printNode( 0 ) );
+       con.setSurroundingExpression( en );     
+      }
       con.setNumLine(pn.getLine());
       for (int i = 0; i < args.size(); i++) {
         con.addArgument((ExpressionNode) args.get(i));
@@ -969,20 +1142,63 @@ public class BuildIR {
 
       return con;
     } else if (isNode(pn,"createobjectcls")) {
-      //TODO:::  FIX BUG!!!  static fields in caller context need to become parameters
       TypeDescriptor td=parseTypeDescriptor(pn);
       innerCount++;
-      ClassDescriptor cnnew=new ClassDescriptor(td.getSymbol()+"$"+innerCount, false);
+      ClassDescriptor cnnew=new ClassDescriptor(packageName,td.getSymbol()+"$"+innerCount, false);
+      pushChainMaps();
       cnnew.setImports(mandatoryImports, multiimports);
       cnnew.setSuper(td.getSymbol());
+      cnnew.setInline();
+      // the inline anonymous class does not have modifiers, it cannot be static 
+      // it is always implicit final
+      cnnew.setModifiers(new Modifiers(Modifiers.FINAL));
+      cnnew.setAsInnerClass();
+      cnnew.setSurroundingClass(cn.getSymbol());
+      cnnew.setSurrounding(cn);
+      cn.addInnerClass(cnnew);
+      // Note that if the inner class is declared in a static context, it does NOT 
+      // have lexically enclosing instances.
+      if((null!=md)&&(md.isStatic()||md.isStaticBlock())) {
+       cnnew.setSurroundingBlock(md);
+       cnnew.setInStaticContext();
+      } else if (isStaticContext) {
+       cnnew.setInStaticContext();
+      }
       parseClassBody(cnnew, pn.getChild("decl").getChild("classbody"));
-      Vector args=parseArgumentList(pn);
-
-      CreateObjectNode con=new CreateObjectNode(td, false, null);
+      boolean hasConstructor = false;
+      for(Iterator method_it=cnnew.getMethods(); method_it.hasNext(); ) {
+         MethodDescriptor cmd=(MethodDescriptor)method_it.next();
+         hasConstructor |= cmd.isConstructor();
+      }
+      if(hasConstructor) {
+         // anonymous class should not have explicit constructors
+         throw new Error("Error! Anonymous class " + cnnew.getSymbol() + " in " + cn.getSymbol() + " has explicit constructors!");
+      } else if(!cnnew.isEnum()) {
+         // add a default constructor for this class
+         MethodDescriptor cmd = new MethodDescriptor(new Modifiers(Modifiers.PUBLIC|Modifiers.FINAL),cnnew.getSymbol(), false);
+         BlockNode bn=new BlockNode();
+         state.addTreeCode(cmd,bn);
+         cmd.setDefaultConstructor();
+         cnnew.addMethod(cmd);
+      }
+      TypeDescriptor tdnew=state.getTypeDescriptor(cnnew.getSymbol());
+
+      Vector args=parseArgumentList(cn, md, isStaticContext, pn);
+      ParseNode idChild = pn.getChild( "id" );
+      ParseNode baseChild = pn.getChild( "base" );
+      //System.out.println("\n to print idchild and basechild for ");
+      /*if( null != idChild )
+       System.out.println( "\n trying to create an inner class and the id child passed is "  + idChild.PPrint( 0, true ) );
+      if( null != baseChild )
+       System.out.println( "\n trying to create an inner class and the base child passed is "  + baseChild.PPrint( 0, true ) );*/
+      CreateObjectNode con=new CreateObjectNode(tdnew, false, null);
       con.setNumLine(pn.getLine());
       for(int i=0; i<args.size(); i++) {
         con.addArgument((ExpressionNode)args.get(i));
       }
+      popChainMaps();
+
+      addClass2State(cnnew);
 
       return con;
     } else if (isNode(pn,"createarray")) {
@@ -994,7 +1210,7 @@ public class BuildIR {
         disjointId = pn.getChild("disjoint").getTerminal();
       }
       TypeDescriptor td=parseTypeDescriptor(pn);
-      Vector args=parseDimExprs(pn);
+      Vector args=parseDimExprs(cn, md, isStaticContext, pn);
       int num=0;
       if (pn.getChild("dims_opt").getLiteral()!=null)
         num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
@@ -1017,7 +1233,7 @@ public class BuildIR {
       CreateObjectNode con=new CreateObjectNode(td, false, null);
       con.setNumLine(pn.getLine());
       ParseNode ipn = pn.getChild("initializer");
-      Vector initializers=parseVariableInitializerList(ipn);
+      Vector initializers=parseVariableInitializerList(cn, md, isStaticContext, ipn);
       ArrayInitializerNode ain = new ArrayInitializerNode(initializers);
       ain.setNumLine(pn.getLine());
       con.addArrayInitializer(ain);
@@ -1032,6 +1248,14 @@ public class BuildIR {
       NameNode nn=new NameNode(nd);
       nn.setNumLine(pn.getLine());
       return nn;
+    } else if (isNode(pn,"parentclass")) {
+      NameDescriptor nd=new NameDescriptor(pn.getChild("name").getFirstChild().getFirstChild().getTerminal());
+      NameNode nn=new NameNode(nd);
+      nn.setNumLine(pn.getLine());
+       //because inner classes pass right thru......
+      FieldAccessNode fan=new FieldAccessNode(nn,"this");
+      fan.setNumLine(pn.getLine());
+      return fan;
     } else if (isNode(pn,"isavailable")) {
       NameDescriptor nd=new NameDescriptor(pn.getTerminal());
       NameNode nn=new NameNode(nd);
@@ -1039,7 +1263,7 @@ public class BuildIR {
       return new OpNode(nn,null,new Operation(Operation.ISAVAILABLE));
     } else if (isNode(pn,"methodinvoke1")) {
       NameDescriptor nd=parseName(pn.getChild("name"));
-      Vector args=parseArgumentList(pn);
+      Vector args=parseArgumentList(cn, md, isStaticContext, pn);
       MethodInvokeNode min=new MethodInvokeNode(nd);
       min.setNumLine(pn.getLine());
       for(int i=0; i<args.size(); i++) {
@@ -1048,8 +1272,8 @@ public class BuildIR {
       return min;
     } else if (isNode(pn,"methodinvoke2")) {
       String methodid=pn.getChild("id").getTerminal();
-      ExpressionNode exp=parseExpression(pn.getChild("base").getFirstChild());
-      Vector args=parseArgumentList(pn);
+      ExpressionNode exp=parseExpression(cn, md, isStaticContext, pn.getChild("base").getFirstChild());
+      Vector args=parseArgumentList(cn, md, isStaticContext, pn);
       MethodInvokeNode min=new MethodInvokeNode(methodid,exp);
       min.setNumLine(pn.getLine());
       for(int i=0; i<args.size(); i++) {
@@ -1057,32 +1281,48 @@ public class BuildIR {
       }
       return min;
     } else if (isNode(pn,"fieldaccess")) {
-      ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
+      ExpressionNode en=parseExpression(cn, md, isStaticContext, pn.getChild("base").getFirstChild());
       String fieldname=pn.getChild("field").getTerminal();
 
       FieldAccessNode fan=new FieldAccessNode(en,fieldname);
       fan.setNumLine(pn.getLine());
       return fan;
+    } else if (isNode(pn,"superfieldaccess")) {
+       ExpressionNode en=new NameNode(new NameDescriptor("super"));
+       String fieldname=pn.getChild("field").getTerminal();
+
+       FieldAccessNode fan=new FieldAccessNode(en,fieldname);
+       fan.setNumLine(pn.getLine());
+       return fan;
+    } else if (isNode(pn,"supernamefieldaccess")) {
+       ExpressionNode en=parseExpression(cn, md, isStaticContext, pn.getChild("base").getFirstChild());
+       ExpressionNode exp = new FieldAccessNode(en, "super");
+       exp.setNumLine(pn.getLine());
+       String fieldname=pn.getChild("field").getTerminal();
+
+       FieldAccessNode fan=new FieldAccessNode(exp,fieldname);
+       fan.setNumLine(pn.getLine());
+       return fan;
     } else if (isNode(pn,"arrayaccess")) {
-      ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
-      ExpressionNode index=parseExpression(pn.getChild("index").getFirstChild());
+      ExpressionNode en=parseExpression(cn, md, isStaticContext, pn.getChild("base").getFirstChild());
+      ExpressionNode index=parseExpression(cn, md, isStaticContext, pn.getChild("index").getFirstChild());
       ArrayAccessNode aan=new ArrayAccessNode(en,index);
       aan.setNumLine(pn.getLine());
       return aan;
     } else if (isNode(pn,"cast1")) {
       try {
-        CastNode cn=new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
-        cn.setNumLine(pn.getLine());
-        return cn;
+        CastNode castn=new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(cn, md, isStaticContext, pn.getChild("exp").getFirstChild()));
+        castn.setNumLine(pn.getLine());
+        return castn;
       } catch (Exception e) {
         System.out.println(pn.PPrint(1,true));
         e.printStackTrace();
         throw new Error();
       }
     } else if (isNode(pn,"cast2")) {
-      CastNode cn=new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
-      cn.setNumLine(pn.getLine());
-      return cn;
+      CastNode castn=new CastNode(parseExpression(cn, md, isStaticContext, pn.getChild("type").getFirstChild()),parseExpression(cn, md, isStaticContext, pn.getChild("exp").getFirstChild()));
+      castn.setNumLine(pn.getLine());
+      return castn;
     } else if (isNode(pn, "getoffset")) {
       TypeDescriptor td=parseTypeDescriptor(pn);
       String fieldname = pn.getChild("field").getTerminal();
@@ -1090,20 +1330,20 @@ public class BuildIR {
       return new OffsetNode(td, fieldname);
     } else if (isNode(pn, "tert")) {
 
-      TertiaryNode tn=new TertiaryNode(parseExpression(pn.getChild("cond").getFirstChild()),
-                                       parseExpression(pn.getChild("trueexpr").getFirstChild()),
-                                       parseExpression(pn.getChild("falseexpr").getFirstChild()) );
+      TertiaryNode tn=new TertiaryNode(parseExpression(cn, md, isStaticContext, pn.getChild("cond").getFirstChild()),
+                                       parseExpression(cn, md, isStaticContext, pn.getChild("trueexpr").getFirstChild()),
+                                       parseExpression(cn, md, isStaticContext, pn.getChild("falseexpr").getFirstChild()) );
       tn.setNumLine(pn.getLine());
 
       return tn;
     } else if (isNode(pn, "instanceof")) {
-      ExpressionNode exp=parseExpression(pn.getChild("exp").getFirstChild());
+      ExpressionNode exp=parseExpression(cn, md, isStaticContext, pn.getChild("exp").getFirstChild());
       TypeDescriptor t=parseTypeDescriptor(pn);
       InstanceOfNode ion=new InstanceOfNode(exp,t);
       ion.setNumLine(pn.getLine());
       return ion;
     } else if (isNode(pn, "array_initializer")) {
-      Vector initializers=parseVariableInitializerList(pn);
+      Vector initializers=parseVariableInitializerList(cn, md, isStaticContext, pn);
       return new ArrayInitializerNode(initializers);
     } else if (isNode(pn, "class_type")) {
       TypeDescriptor td=parseTypeDescriptor(pn);
@@ -1119,26 +1359,26 @@ public class BuildIR {
     }
   }
 
-  private Vector parseDimExprs(ParseNode pn) {
+  private Vector parseDimExprs(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn) {
     Vector arglist=new Vector();
     ParseNode an=pn.getChild("dim_exprs");
     if (an==null)       /* No argument list */
       return arglist;
     ParseNodeVector anv=an.getChildren();
     for(int i=0; i<anv.size(); i++) {
-      arglist.add(parseExpression(anv.elementAt(i)));
+      arglist.add(parseExpression(cn, md, isStaticContext, anv.elementAt(i)));
     }
     return arglist;
   }
 
-  private Vector parseArgumentList(ParseNode pn) {
+  private Vector parseArgumentList(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn) {
     Vector arglist=new Vector();
     ParseNode an=pn.getChild("argument_list");
     if (an==null)       /* No argument list */
       return arglist;
     ParseNodeVector anv=an.getChildren();
     for(int i=0; i<anv.size(); i++) {
-      arglist.add(parseExpression(anv.elementAt(i)));
+      arglist.add(parseExpression(cn, md, isStaticContext, anv.elementAt(i)));
     }
     return arglist;
   }
@@ -1155,28 +1395,28 @@ public class BuildIR {
       ParseNode var=cpn.getChild("var");
       ParseNode exp=cpn.getChild("exp").getFirstChild();
       varlist.add(var.getTerminal());
-      arglist.add(parseExpression(exp));
+      arglist.add(parseExpression(null, null, false, exp));
     }
     return new Vector[] {varlist, arglist};
   }
 
-  private Vector parseVariableInitializerList(ParseNode pn) {
+  private Vector parseVariableInitializerList(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn) {
     Vector varInitList=new Vector();
     ParseNode vin=pn.getChild("var_init_list");
     if (vin==null)       /* No argument list */
       return varInitList;
     ParseNodeVector vinv=vin.getChildren();
     for(int i=0; i<vinv.size(); i++) {
-      varInitList.add(parseExpression(vinv.elementAt(i)));
+      varInitList.add(parseExpression(cn, md, isStaticContext, vinv.elementAt(i)));
     }
     return varInitList;
   }
 
-  private ExpressionNode parseAssignmentExpression(ParseNode pn) {
+  private ExpressionNode parseAssignmentExpression(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn) {
     AssignOperation ao=new AssignOperation(pn.getChild("op").getTerminal());
     ParseNodeVector pnv=pn.getChild("args").getChildren();
 
-    AssignmentNode an=new AssignmentNode(parseExpression(pnv.elementAt(0)),parseExpression(pnv.elementAt(1)),ao);
+    AssignmentNode an=new AssignmentNode(parseExpression(cn, md, isStaticContext, pnv.elementAt(0)),parseExpression(cn, md, isStaticContext, pnv.elementAt(1)),ao);
     an.setNumLine(pn.getLine());
     return an;
   }
@@ -1187,7 +1427,7 @@ public class BuildIR {
     ParseNode bodyn=pn.getChild("body");
     MethodDescriptor md=parseMethodHeader(headern);
     try {
-      BlockNode bn=parseBlock(bodyn);
+      BlockNode bn=parseBlock(cn, md, md.isStatic()||md.isStaticBlock(), bodyn);
       bn.setNumLine(pn.getLine()); // assume that method header is located at the beginning of method body
       cn.addMethod(md);
       state.addTreeCode(md,bn);
@@ -1227,13 +1467,13 @@ public class BuildIR {
     cn.addMethod(md);
     BlockNode bn=null;
     if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
-      bn=parseBlock(bodyn);
+      bn=parseBlock(cn, md, md.isStatic()||md.isStaticBlock(), bodyn);
     else
       bn=new BlockNode();
     if (bodyn!=null&&bodyn.getChild("superinvoke")!=null) {
       ParseNode sin=bodyn.getChild("superinvoke");
       NameDescriptor nd=new NameDescriptor("super");
-      Vector args=parseArgumentList(sin);
+      Vector args=parseArgumentList(cn, md, true, sin);
       MethodInvokeNode min=new MethodInvokeNode(nd);
       min.setNumLine(sin.getLine());
       for(int i=0; i<args.size(); i++) {
@@ -1245,7 +1485,7 @@ public class BuildIR {
     } else if (bodyn!=null&&bodyn.getChild("explconstrinv")!=null) {
       ParseNode eci=bodyn.getChild("explconstrinv");
       NameDescriptor nd=new NameDescriptor(cn.getSymbol());
-      Vector args=parseArgumentList(eci);
+      Vector args=parseArgumentList(cn, md, true, eci);
       MethodInvokeNode min=new MethodInvokeNode(nd);
       min.setNumLine(eci.getLine());
       for(int i=0; i<args.size(); i++) {
@@ -1278,7 +1518,7 @@ public class BuildIR {
     cn.incStaticBlocks();
     BlockNode bn=null;
     if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
-      bn=parseBlock(bodyn);
+      bn=parseBlock(cn, md, true, bodyn);
     else
       bn=new BlockNode();
     if(isfirst) {
@@ -1294,19 +1534,19 @@ public class BuildIR {
     }
   }
 
-  public BlockNode parseBlock(ParseNode pn) {
+  public BlockNode parseBlock(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn) {
     this.m_taskexitnum = 0;
     if (pn==null||isEmpty(pn.getTerminal()))
       return new BlockNode();
     ParseNode bsn=pn.getChild("block_statement_list");
-    return parseBlockHelper(bsn);
+    return parseBlockHelper(cn, md, isStaticContext, bsn);
   }
 
-  private BlockNode parseBlockHelper(ParseNode pn) {
+  private BlockNode parseBlockHelper(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn) {
     ParseNodeVector pnv=pn.getChildren();
     BlockNode bn=new BlockNode();
     for(int i=0; i<pnv.size(); i++) {
-      Vector bsv=parseBlockStatement(pnv.elementAt(i));
+      Vector bsv=parseBlockStatement(cn, md, isStaticContext, pnv.elementAt(i));
       for(int j=0; j<bsv.size(); j++) {
         bn.addBlockStatement((BlockStatementNode)bsv.get(j));
       }
@@ -1314,26 +1554,34 @@ public class BuildIR {
     return bn;
   }
 
-  public BlockNode parseSingleBlock(ParseNode pn) {
+  public BlockNode parseSingleBlock(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn, String label){
     BlockNode bn=new BlockNode();
-    Vector bsv=parseBlockStatement(pn);
+    Vector bsv=parseBlockStatement(cn, md, isStaticContext, pn,label);
     for(int j=0; j<bsv.size(); j++) {
       bn.addBlockStatement((BlockStatementNode)bsv.get(j));
     }
     bn.setStyle(BlockNode.NOBRACES);
     return bn;
   }
+  
+  public BlockNode parseSingleBlock(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn) {
+    return parseSingleBlock(cn, md, isStaticContext, pn, null);
+  }
 
-  public Vector parseSESEBlock(Vector parentbs, ParseNode pn) {
+  public Vector parseSESEBlock(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, Vector parentbs, ParseNode pn) {
     ParseNodeVector pnv=pn.getChildren();
     Vector bv=new Vector();
     for(int i=0; i<pnv.size(); i++) {
-      bv.addAll(parseBlockStatement(pnv.elementAt(i)));
+      bv.addAll(parseBlockStatement(cn, md, isStaticContext, pnv.elementAt(i)));
     }
     return bv;
   }
+  
+  public Vector parseBlockStatement(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn){
+    return parseBlockStatement(cn, md, isStaticContext, pn,null);
+  }
 
-  public Vector parseBlockStatement(ParseNode pn) {
+  public Vector parseBlockStatement(ClassDescriptor cn, MethodDescriptor md, boolean isStaticContext, ParseNode pn, String label) {
     Vector blockstatements=new Vector();
     if (isNode(pn,"tag_declaration")) {
       String name=pn.getChild("single").getTerminal();
@@ -1366,7 +1614,7 @@ public class BuildIR {
 
         ExpressionNode en=null;
         if (epn!=null)
-          en=parseExpression(epn.getFirstChild());
+          en=parseExpression(cn, md, isStaticContext, epn.getFirstChild());
 
         DeclarationNode dn=new DeclarationNode(new VarDescriptor(arrayt, identifier),en);
         dn.setNumLine(tmp.getLine());
@@ -1383,20 +1631,20 @@ public class BuildIR {
     } else if (isNode(pn,"nop")) {
       /* Do Nothing */
     } else if (isNode(pn,"expression")) {
-      BlockExpressionNode ben=new BlockExpressionNode(parseExpression(pn.getFirstChild()));
+      BlockExpressionNode ben=new BlockExpressionNode(parseExpression(cn, md, isStaticContext, pn.getFirstChild()));
       ben.setNumLine(pn.getLine());
       blockstatements.add(ben);
     } else if (isNode(pn,"ifstatement")) {
-      IfStatementNode isn=new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
-                                              parseSingleBlock(pn.getChild("statement").getFirstChild()),
-                                              pn.getChild("else_statement")!=null?parseSingleBlock(pn.getChild("else_statement").getFirstChild()):null);
+      IfStatementNode isn=new IfStatementNode(parseExpression(cn, md, isStaticContext, pn.getChild("condition").getFirstChild()),
+                                              parseSingleBlock(cn, md, isStaticContext, pn.getChild("statement").getFirstChild()),
+                                              pn.getChild("else_statement")!=null?parseSingleBlock(cn, md, isStaticContext, pn.getChild("else_statement").getFirstChild()):null);
       isn.setNumLine(pn.getLine());
 
       blockstatements.add(isn);
     } else if (isNode(pn,"switch_statement")) {
       // TODO add version for normal Java later
-      SwitchStatementNode ssn=new SwitchStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
-                                                      parseSingleBlock(pn.getChild("statement").getFirstChild()));
+      SwitchStatementNode ssn=new SwitchStatementNode(parseExpression(cn, md, isStaticContext, pn.getChild("condition").getFirstChild()),
+                                                      parseSingleBlock(cn, md, isStaticContext, pn.getChild("statement").getFirstChild()));
       ssn.setNumLine(pn.getLine());
       blockstatements.add(ssn);
     } else if (isNode(pn,"switch_block_list")) {
@@ -1412,7 +1660,7 @@ public class BuildIR {
           for(int j=0; j<labelv.size(); j++) {
             ParseNode labeldecl=labelv.elementAt(j);
             if(isNode(labeldecl, "switch_label")) {
-              SwitchLabelNode sln=new SwitchLabelNode(parseExpression(labeldecl.getChild("constant_expression").getFirstChild()), false);
+              SwitchLabelNode sln=new SwitchLabelNode(parseExpression(cn, md, isStaticContext, labeldecl.getChild("constant_expression").getFirstChild()), false);
               sln.setNumLine(labeldecl.getLine());
               slv.addElement(sln);
             } else if(isNode(labeldecl, "default_switch_label")) {
@@ -1423,7 +1671,7 @@ public class BuildIR {
           }
 
           SwitchBlockNode sbn=new SwitchBlockNode(slv,
-                                                  parseSingleBlock(sblockdecl.getChild("switch_statements").getFirstChild()));
+                                                  parseSingleBlock(cn, md, isStaticContext, sblockdecl.getChild("switch_statements").getFirstChild()));
           sbn.setNumLine(sblockdecl.getLine());
 
           blockstatements.add(sbn);
@@ -1435,13 +1683,13 @@ public class BuildIR {
       // Do not fully support exceptions now. Only make sure that if there are no
       // exceptions thrown, the execution is right
       ParseNode tpn = pn.getChild("tryblock").getFirstChild();
-      BlockNode bn=parseBlockHelper(tpn);
+      BlockNode bn=parseBlockHelper(cn, md, isStaticContext, tpn);
       blockstatements.add(new SubBlockNode(bn));
 
       ParseNode fbk = pn.getChild("finallyblock");
       if(fbk != null) {
         ParseNode fpn = fbk.getFirstChild();
-        BlockNode fbn=parseBlockHelper(fpn);
+        BlockNode fbn=parseBlockHelper(cn, md, isStaticContext, fpn);
         blockstatements.add(new SubBlockNode(fbn));
       }
     } else if (isNode(pn, "throwstatement")) {
@@ -1458,13 +1706,13 @@ public class BuildIR {
       ten.setNumLine(pn.getLine());
       blockstatements.add(ten);
     } else if (isNode(pn,"atomic")) {
-      BlockNode bn=parseBlockHelper(pn);
+      BlockNode bn=parseBlockHelper(cn, md, isStaticContext, pn);
       AtomicNode an=new AtomicNode(bn);
       an.setNumLine(pn.getLine());
       blockstatements.add(an);
     } else if (isNode(pn,"synchronized")) {
-      BlockNode bn=parseBlockHelper(pn.getChild("block"));
-      ExpressionNode en=parseExpression(pn.getChild("expr").getFirstChild());
+      BlockNode bn=parseBlockHelper(cn, md, isStaticContext, pn.getChild("block"));
+      ExpressionNode en=parseExpression(cn, md, isStaticContext, pn.getChild("expr").getFirstChild());
       SynchronizedNode sn=new SynchronizedNode(en, bn);
       sn.setNumLine(pn.getLine());
       blockstatements.add(sn);
@@ -1472,13 +1720,13 @@ public class BuildIR {
       if (isEmpty(pn.getTerminal()))
         blockstatements.add(new ReturnNode());
       else {
-        ExpressionNode en=parseExpression(pn.getFirstChild());
+        ExpressionNode en=parseExpression(cn, md, isStaticContext, pn.getFirstChild());
         ReturnNode rn=new ReturnNode(en);
         rn.setNumLine(pn.getLine());
         blockstatements.add(rn);
       }
     } else if (isNode(pn,"block_statement_list")) {
-      BlockNode bn=parseBlockHelper(pn);
+      BlockNode bn=parseBlockHelper(cn, md, isStaticContext, pn);
       blockstatements.add(new SubBlockNode(bn));
     } else if (isNode(pn,"empty")) {
       /* nop */
@@ -1486,38 +1734,38 @@ public class BuildIR {
       ParseNodeVector pnv=pn.getChildren();
       BlockNode bn=new BlockNode();
       for(int i=0; i<pnv.size(); i++) {
-        ExpressionNode en=parseExpression(pnv.elementAt(i));
+        ExpressionNode en=parseExpression(cn, md, isStaticContext, pnv.elementAt(i));
         blockstatements.add(new BlockExpressionNode(en));
       }
       bn.setStyle(BlockNode.EXPRLIST);
     } else if (isNode(pn,"forstatement")) {
-      BlockNode init=parseSingleBlock(pn.getChild("initializer").getFirstChild());
-      BlockNode update=parseSingleBlock(pn.getChild("update").getFirstChild());
-      ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
-      BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
+      BlockNode init=parseSingleBlock(cn, md, isStaticContext, pn.getChild("initializer").getFirstChild());
+      BlockNode update=parseSingleBlock(cn, md, isStaticContext, pn.getChild("update").getFirstChild());
+      ExpressionNode condition=parseExpression(cn, md, isStaticContext, pn.getChild("condition").getFirstChild());
+      BlockNode body=parseSingleBlock(cn, md, isStaticContext, pn.getChild("statement").getFirstChild());
       if(condition == null) {
         // no condition clause, make a 'true' expression as the condition
         condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
       }
-      LoopNode ln=new LoopNode(init,condition,update,body);
+      LoopNode ln=new LoopNode(init,condition,update,body,label);
       ln.setNumLine(pn.getLine());
       blockstatements.add(ln);
     } else if (isNode(pn,"whilestatement")) {
-      ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
-      BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
+      ExpressionNode condition=parseExpression(cn, md, isStaticContext, pn.getChild("condition").getFirstChild());
+      BlockNode body=parseSingleBlock(cn, md, isStaticContext, pn.getChild("statement").getFirstChild());
       if(condition == null) {
         // no condition clause, make a 'true' expression as the condition
         condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
       }
-      blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP));
+      blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP,label));
     } else if (isNode(pn,"dowhilestatement")) {
-      ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
-      BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
+      ExpressionNode condition=parseExpression(cn, md, isStaticContext, pn.getChild("condition").getFirstChild());
+      BlockNode body=parseSingleBlock(cn, md, isStaticContext, pn.getChild("statement").getFirstChild());
       if(condition == null) {
         // no condition clause, make a 'true' expression as the condition
         condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
       }
-      blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
+      blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP,label));
     } else if (isNode(pn,"sese")) {
       ParseNode pnID=pn.getChild("identifier");
       String stID=null;
@@ -1530,7 +1778,7 @@ public class BuildIR {
       start.setEnd(end);
       end.setStart(start);
       blockstatements.add(start);
-      blockstatements.addAll(parseSESEBlock(blockstatements,pn.getChild("body").getFirstChild()));
+      blockstatements.addAll(parseSESEBlock(cn, md, isStaticContext, blockstatements,pn.getChild("body").getFirstChild()));
       blockstatements.add(end);
     } else if (isNode(pn,"continue")) {
       ContinueBreakNode cbn=new ContinueBreakNode(false);
@@ -1543,14 +1791,18 @@ public class BuildIR {
       ParseNode idopt_pn=pn.getChild("identifier_opt");
       ParseNode name_pn=idopt_pn.getChild("name");
       // name_pn.getTerminal() gives you the label
+
     } else if (isNode(pn,"genreach")) {
       String graphName = pn.getChild("graphName").getTerminal();
       blockstatements.add(new GenReachNode(graphName) );
 
+    } else if (isNode(pn,"gen_def_reach")) {
+      String outputName = pn.getChild("outputName").getTerminal();
+      blockstatements.add(new GenDefReachNode(outputName) );
+
     } else if(isNode(pn,"labeledstatement")) {
-      String label = pn.getChild("name").getTerminal();
-      BlockNode bn=parseSingleBlock(pn.getChild("statement").getFirstChild());
-      bn.setLabel(label);
+      String labeledstatement = pn.getChild("name").getTerminal();
+      BlockNode bn=parseSingleBlock(cn, md, isStaticContext, pn.getChild("statement").getFirstChild(),labeledstatement);
       blockstatements.add(new SubBlockNode(bn));
     } else {
       System.out.println("---------------");
@@ -1605,8 +1857,8 @@ public class BuildIR {
 
         md.addParameter(type, paramname);
         if(isNode(paramn, "annotation_parameter")) {
-          ParseNode bodynode=paramn.getChild("annotation_body");
-          parseParameterAnnotation(bodynode,type);
+          ParseNode listnode=paramn.getChild("annotation_list");
+          parseParameterAnnotation(listnode,type);
         }
 
       }
@@ -1670,15 +1922,21 @@ public class BuildIR {
     }
   }
 
-  private void parseParameterAnnotation(ParseNode body_list,TypeDescriptor type) {
-    ParseNode body_node = body_list.getFirstChild();
-    if (isNode(body_node, "marker_annotation")) {
-      type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
-    } else if (isNode(body_node, "single_annotation")) {
-      type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal(),
-                                                        body_node.getChild("element_value").getTerminal()));
-    } else if (isNode(body_node, "normal_annotation")) {
-      throw new Error("Annotation with multiple data members is not supported yet.");
+  private void parseParameterAnnotation(ParseNode pn,TypeDescriptor type) {
+    ParseNodeVector pnv = pn.getChildren();
+    for (int i = 0; i < pnv.size(); i++) {
+      ParseNode body_list = pnv.elementAt(i);
+      if (isNode(body_list, "annotation_body")) {
+        ParseNode body_node = body_list.getFirstChild();
+        if (isNode(body_node, "marker_annotation")) {
+          type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
+        } else if (isNode(body_node, "single_annotation")) {
+          type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal(),
+                                                   body_node.getChild("element_value").getTerminal()));
+        } else if (isNode(body_node, "normal_annotation")) {
+          throw new Error("Annotation with multiple data members is not supported yet.");
+        }
+      }
     }
   }