start of new file
[IRC.git] / Robust / src / IR / Tree / BuildIR.java
index bfcf62a760e92896199b3c829a967e75a16b5028..3c9847d0729cf0c575e26ec9d75df633876ff636 100644 (file)
@@ -167,30 +167,45 @@ public class BuildIR {
     }
 
     public void parseParameterList(TaskDescriptor td, ParseNode pn) {
+       
+       boolean optional;
        ParseNode paramlist=pn.getChild("task_parameter_list");
        if (paramlist==null)
            return;
-        ParseNodeVector pnv=paramlist.getChildren();
-        for(int i=0;i<pnv.size();i++) {
-            ParseNode paramn=pnv.elementAt(i);
-            TypeDescriptor type=parseTypeDescriptor(paramn);
-
-            String paramname=paramn.getChild("single").getTerminal();
-            FlagExpressionNode fen=parseFlagExpression(paramn.getChild("flag").getFirstChild());
-
-            ParseNode tagnode=paramn.getChild("tag");
+       ParseNodeVector pnv=paramlist.getChildren();
+       for(int i=0;i<pnv.size();i++) {
+           ParseNode paramn=pnv.elementAt(i);
+           if(paramn.getChild("optional")!=null){
+               optional = true;
+               paramn = paramn.getChild("optional").getFirstChild();
+               System.out.println("OPTIONAL FOUND!!!!!!!");
+           }
+           else { optional = false;
+           System.out.println("NOT OPTIONAL");
+           }
 
-            TagExpressionList tel=null;
-            if (tagnode!=null) {
-                tel=parseTagExpressionList(tagnode);
-            }
-            
-            td.addParameter(type,paramname,fen, tel);
-        }
+           TypeDescriptor type=parseTypeDescriptor(paramn);
+           
+           String paramname=paramn.getChild("single").getTerminal();
+           FlagExpressionNode fen=null;
+           if (paramn.getChild("flag")!=null)
+               fen=parseFlagExpression(paramn.getChild("flag").getFirstChild());
+           
+           ParseNode tagnode=paramn.getChild("tag");
+           
+           TagExpressionList tel=null;
+           if (tagnode!=null) {
+               tel=parseTagExpressionList(tagnode);
+           }
+           
+           td.addParameter(type,paramname,fen, tel, optional);
+       }
     }
-
+    
     public TagExpressionList parseTagExpressionList(ParseNode pn) {
-       ParseNodeVector pnv=pn.getChildren();
+       //BUG FIX: change pn.getChildren() to pn.getChild("tag_expression_list").getChildren()
+       //To test, feed in any input program that uses tags
+       ParseNodeVector pnv=pn.getChild("tag_expression_list").getChildren();
        TagExpressionList tel=new TagExpressionList();
        for(int i=0;i<pnv.size();i++) {
            ParseNode tn=pnv.elementAt(i);
@@ -209,7 +224,8 @@ public class BuildIR {
            NameDescriptor nd=parseName(snn);
            cn.setSuper(nd.toString());
        } else {
-           if (!cn.getSymbol().equals(TypeUtil.ObjectClass))
+           if (!(cn.getSymbol().equals(TypeUtil.ObjectClass)||
+                 cn.getSymbol().equals(TypeUtil.TagClass)))
                cn.setSuper(TypeUtil.ObjectClass);
        }
        cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
@@ -313,10 +329,10 @@ public class BuildIR {
        TypeDescriptor t=parseTypeDescriptor(tn);
        ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
        ParseNodeVector pnv=vn.getChildren();
+       boolean isglobal=pn.getChild("global")!=null;
+
        for(int i=0;i<pnv.size();i++) {
            ParseNode vardecl=pnv.elementAt(i);
-
-           
            ParseNode tmp=vardecl;
            TypeDescriptor arrayt=t;
            while (tmp.getChild("single")==null) {
@@ -324,16 +340,14 @@ public class BuildIR {
                tmp=tmp.getChild("array");
            }
            String identifier=tmp.getChild("single").getTerminal();
-
            ParseNode epn=vardecl.getChild("initializer");
-           
+
            ExpressionNode en=null;
            if (epn!=null)
                en=parseExpression(epn.getFirstChild());
   
-           cn.addField(new FieldDescriptor(m,arrayt,identifier, en));
+           cn.addField(new FieldDescriptor(m, arrayt, identifier, en, isglobal));
        }
-       
     }
 
     private ExpressionNode parseExpression(ParseNode pn) {
@@ -346,6 +360,7 @@ public class BuildIR {
                 isNode(pn,"comp_lte")||isNode(pn,"comp_gt")||
                 isNode(pn,"comp_gte")||isNode(pn,"leftshift")||
                 isNode(pn,"rightshift")||isNode(pn,"sub")||
+                isNode(pn,"urightshift")||isNode(pn,"sub")||
                 isNode(pn,"add")||isNode(pn,"mult")||
                 isNode(pn,"div")||isNode(pn,"mod")) {
            ParseNodeVector pnv=pn.getChildren();
@@ -355,7 +370,8 @@ public class BuildIR {
            return new OpNode(parseExpression(left),parseExpression(right),op);
        } else if (isNode(pn,"unaryplus")||
                   isNode(pn,"unaryminus")||
-                  isNode(pn,"not")) {
+                  isNode(pn,"not")||
+                  isNode(pn,"comp")) {
            ParseNode left=pn.getFirstChild();
            Operation op=new Operation(pn.getLabel());
            return new OpNode(parseExpression(left),op);
@@ -379,7 +395,8 @@ public class BuildIR {
        } else if (isNode(pn,"createobject")) {
            TypeDescriptor td=parseTypeDescriptor(pn);
            Vector args=parseArgumentList(pn);
-           CreateObjectNode con=new CreateObjectNode(td);
+           boolean isglobal=pn.getChild("global")!=null;
+           CreateObjectNode con=new CreateObjectNode(td, isglobal);
            for(int i=0;i<args.size();i++) {
                con.addArgument((ExpressionNode)args.get(i));
            }
@@ -397,6 +414,7 @@ public class BuildIR {
            return con;
        } else if (isNode(pn,"createarray")) {
            //System.out.println(pn.PPrint(3,true));
+           boolean isglobal=pn.getChild("global")!=null;
            TypeDescriptor td=parseTypeDescriptor(pn);
            Vector args=parseDimExprs(pn);
            int num=0;
@@ -404,7 +422,7 @@ public class BuildIR {
                num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
            for(int i=0;i<(args.size()+num);i++)
                td=td.makeArray(state);
-           CreateObjectNode con=new CreateObjectNode(td);
+           CreateObjectNode con=new CreateObjectNode(td, isglobal);
            for(int i=0;i<args.size();i++) {
                con.addArgument((ExpressionNode)args.get(i));
            }
@@ -415,6 +433,9 @@ public class BuildIR {
        } else if (isNode(pn,"this")) {
            NameDescriptor nd=new NameDescriptor("this");
            return new NameNode(nd);
+       } else if (isNode(pn,"isavailable")) {
+           NameDescriptor nd=new NameDescriptor(pn.getTerminal());
+           return new OpNode(new NameNode(nd),null,new Operation(Operation.ISAVAILABLE));
        } else if (isNode(pn,"methodinvoke1")) {
            NameDescriptor nd=parseName(pn.getChild("name"));
            Vector args=parseArgumentList(pn);
@@ -513,14 +534,30 @@ public class BuildIR {
        ParseNode mn=pn.getChild("modifiers");
        Modifiers m=parseModifiersList(mn);
        ParseNode cdecl=pn.getChild("constructor_declarator");
+       boolean isglobal=cdecl.getChild("global")!=null;
        String name=cdecl.getChild("name").getChild("identifier").getTerminal();
-       MethodDescriptor md=new MethodDescriptor(m, name);
+       MethodDescriptor md=new MethodDescriptor(m, name, isglobal);
        ParseNode paramnode=cdecl.getChild("parameters");
        parseParameterList(md,paramnode);
        ParseNode bodyn0=pn.getChild("body");
        ParseNode bodyn=bodyn0.getChild("constructor_body");
        cn.addMethod(md);
-       BlockNode bn=parseBlock(bodyn);
+       BlockNode bn=null;
+       if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
+           bn=parseBlock(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);
+           MethodInvokeNode min=new MethodInvokeNode(nd);
+           for(int i=0;i<args.size();i++) {
+               min.addArgument((ExpressionNode)args.get(i));
+           }
+           BlockExpressionNode ben=new BlockExpressionNode(min);
+           bn.addFirstBlockStatement(ben);
+       }
        state.addTreeCode(md,bn);
     }
 
@@ -602,6 +639,9 @@ public class BuildIR {
                ccs=parseChecks(pn.getChild("cons_checks"));
            
            blockstatements.add(new TaskExitNode(vfe, ccs));
+       } else if (isNode(pn,"atomic")) {
+           BlockNode bn=parseBlockHelper(pn);
+           blockstatements.add(new AtomicNode(bn));
        } else if (isNode(pn,"return")) {
            if (isEmpty(pn.getTerminal()))
                blockstatements.add(new ReturnNode());
@@ -671,16 +711,23 @@ public class BuildIR {
         ParseNodeVector pnv=paramlist.getChildren();
         for(int i=0;i<pnv.size();i++) {
             ParseNode paramn=pnv.elementAt(i);
-            TypeDescriptor type=parseTypeDescriptor(paramn);
 
-            ParseNode tmp=paramn;
-            while (tmp.getChild("single")==null) {
-                type=type.makeArray(state);
-                tmp=tmp.getChild("array");
+            if (isNode(paramn, "tag_parameter")) {
+                String paramname=paramn.getChild("single").getTerminal();
+                TypeDescriptor type=new TypeDescriptor(TypeDescriptor.TAG);
+                md.addTagParameter(type, paramname);
+            } else {
+                TypeDescriptor type=parseTypeDescriptor(paramn);
+                
+                ParseNode tmp=paramn;
+                while (tmp.getChild("single")==null) {
+                    type=type.makeArray(state);
+                    tmp=tmp.getChild("array");
+                }
+                String paramname=tmp.getChild("single").getTerminal();
+                
+                md.addParameter(type, paramname);
             }
-            String paramname=tmp.getChild("single").getTerminal();
-           
-            md.addParameter(type,paramname);
         }
     }
 
@@ -705,6 +752,8 @@ public class BuildIR {
                    m.addModifier(Modifiers.NATIVE);
                else if (isNode(modn,"synchronized"))
                    m.addModifier(Modifiers.SYNCHRONIZED);
+               else if (isNode(modn,"atomic"))
+                   m.addModifier(Modifiers.ATOMIC);
                else throw new Error("Unrecognized Modifier");
            }
        }