extend grammar for parameter annotation. forgot to handle this case in the past
[IRC.git] / Robust / src / IR / Tree / BuildIR.java
index 04ba43b1f4c7dc7299828c37d29f487e5f6c1fe3..663f23955cd7aba87584a28ed29bb8968207990d 100644 (file)
@@ -1,11 +1,8 @@
 package IR.Tree;
 import IR.*;
 import Util.Lattice;
-
 import java.util.*;
 
-
-
 public class BuildIR {
   State state;
 
@@ -148,27 +145,27 @@ public class BuildIR {
     }
   }
 
-public void parseInitializers(ClassDescriptor cn){
-  Vector fv=cn.getFieldVec();
+  public void parseInitializers(ClassDescriptor cn){
+    Vector fv=cn.getFieldVec();
     int pos = 0;
-  for(int i=0;i<fv.size();i++) {
+    for(int i=0;i<fv.size();i++) {
       FieldDescriptor fd=(FieldDescriptor)fv.get(i);
       if(fd.getExpressionNode()!=null) {
-         Iterator methodit = cn.getMethods();
-          while(methodit.hasNext()){
-            MethodDescriptor currmd=(MethodDescriptor)methodit.next();
-            if(currmd.isConstructor()){
-              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);
-            }
-          }
-          pos++;
+       Iterator methodit = cn.getMethods();
+       while(methodit.hasNext()){
+         MethodDescriptor currmd=(MethodDescriptor)methodit.next();
+         if(currmd.isConstructor()){
+           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);
+         }
+       }
+       pos++;
       }
-  }
-    }  
-
+    }
+  }  
+  
   private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {
     ClassDescriptor ecd=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
     ecd.setAsEnum();
@@ -504,16 +501,33 @@ public void parseInitializers(ClassDescriptor cn){
   private void parseLocationOrder(ClassDescriptor cd, ParseNode pn) {
     ParseNodeVector pnv = pn.getChildren();
     Lattice<String> locOrder =
-        new Lattice<String>("_top_","_bottom_");
+        new Lattice<String>("_top_","_bottom_");            
+    Set<String> spinLocSet=new HashSet<String>();
     for (int i = 0; i < pnv.size(); i++) {
       ParseNode loc = pnv.elementAt(i);
-      String lowerLoc=loc.getChildren().elementAt(0).getLabel();
-      String higherLoc= loc.getChildren().elementAt(1).getLabel();
-      locOrder.put(higherLoc, lowerLoc);
-      if (locOrder.isIntroducingCycle(higherLoc)) {
-        throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc
-            + " introduces a cycle.");
+      if(isNode(loc,"location_property")){
+        String spinLoc=loc.getChildren().elementAt(0).getLabel();
+        spinLocSet.add(spinLoc);
+      }else{
+        String lowerLoc=loc.getChildren().elementAt(0).getLabel();
+        String higherLoc= loc.getChildren().elementAt(1).getLabel();
+        locOrder.put(higherLoc, lowerLoc);
+        if (locOrder.isIntroducingCycle(higherLoc)) {
+          throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc
+              + " introduces a cycle.");
+        }
+      }
+    }
+    if(spinLocSet.size()>0){
+      //checking if location is actually defined in the hierarchy
+      for (Iterator iterator = spinLocSet.iterator(); iterator.hasNext();) {
+        String locID = (String) iterator.next();
+        if(!locOrder.containsKey(locID)){
+          throw new Error("Error: The spinning location '"+
+              locID + "' is not defined in the hierarchy of the class '"+cd +"'.");
+        }
       }
+      state.addLocationPropertySet(cd, spinLocSet);
     }
     state.addLocationOrder(cd, locOrder);
   }
@@ -730,6 +744,8 @@ public void parseInitializers(ClassDescriptor cn){
     }    
   }
 
+  int innerCount=0;
+
   private ExpressionNode parseExpression(ParseNode pn) {
     if (isNode(pn,"assignment"))
       return parseAssignmentExpression(pn);
@@ -808,6 +824,22 @@ public void parseInitializers(ClassDescriptor cn){
        con.addFlagEffects(fe);
       }
 
+      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);
+      cnnew.setSuper(td.getSymbol());
+      parseClassBody(cnnew, pn.getChild("decl").getChild("classbody"));
+      Vector args=parseArgumentList(pn);
+
+      CreateObjectNode con=new CreateObjectNode(td, false, null);
+      con.setNumLine(pn.getLine());
+      for(int i=0; i<args.size(); i++) {
+       con.addArgument((ExpressionNode)args.get(i));
+      }
+
       return con;
     } else if (isNode(pn,"createarray")) {
       //System.out.println(pn.PPrint(3,true));
@@ -1404,7 +1436,8 @@ public void parseInitializers(ClassDescriptor cn){
        String paramname=paramn.getChild("single").getTerminal();
        TypeDescriptor type=new TypeDescriptor(TypeDescriptor.TAG);
        md.addTagParameter(type, paramname);
-      } else {
+      } else  {
+        
        TypeDescriptor type=parseTypeDescriptor(paramn);
 
        ParseNode tmp=paramn;
@@ -1415,6 +1448,11 @@ public void parseInitializers(ClassDescriptor cn){
        String paramname=tmp.getChild("single").getTerminal();
 
        md.addParameter(type, paramname);
+  if(isNode(paramn, "annotation_parameter")){
+    ParseNode bodynode=paramn.getChild("annotation_body");
+    parseParameterAnnotation(bodynode,type);
+  }
+  
       }
     }
   }
@@ -1474,7 +1512,19 @@ public void parseInitializers(ClassDescriptor cn){
       }
     }
   }
-
+  
+  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 boolean isNode(ParseNode pn, String label) {
     if (pn.getLabel().equals(label))
       return true;