added tertiary expression
[IRC.git] / Robust / src / IR / Tree / BuildIR.java
index b692207fd31114af6cc0a0faec656de35b92f037..deb48958b54ee370040eea360b02bdb385a9fabe 100644 (file)
@@ -5,14 +5,14 @@ import java.util.*;
 
 public class BuildIR {
   State state;
-  
+
   private int m_taskexitnum;
-  
+
   public BuildIR(State state) {
     this.state=state;
     this.m_taskexitnum = 0;
   }
-  
+
   public void buildtree() {
     for(Iterator it=state.parsetrees.iterator(); it.hasNext();) {
       ParseNode pn=(ParseNode)it.next();
@@ -274,7 +274,6 @@ public class BuildIR {
 
   private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
     ParseNode tn=pn.getChild("type");
-
     String type_st=tn.getTerminal();
     if(type_st.equals("byte")) {
       return state.getTypeDescriptor(TypeDescriptor.BYTE);
@@ -399,7 +398,11 @@ public class BuildIR {
       TypeDescriptor td=parseTypeDescriptor(pn);
       Vector args=parseArgumentList(pn);
       boolean isglobal=pn.getChild("global")!=null;
-      CreateObjectNode con=new CreateObjectNode(td, isglobal);
+      String disjointId=null;
+      if( pn.getChild("disjoint") != null) {
+       disjointId = pn.getChild("disjoint").getTerminal();
+      }
+      CreateObjectNode con=new CreateObjectNode(td, isglobal, disjointId);
       for(int i=0; i<args.size(); i++) {
        con.addArgument((ExpressionNode)args.get(i));
       }
@@ -418,6 +421,10 @@ public class BuildIR {
     } else if (isNode(pn,"createarray")) {
       //System.out.println(pn.PPrint(3,true));
       boolean isglobal=pn.getChild("global")!=null;
+      String disjointId=null;
+      if( pn.getChild("disjoint") != null) {
+       disjointId = pn.getChild("disjoint").getTerminal();
+      }
       TypeDescriptor td=parseTypeDescriptor(pn);
       Vector args=parseDimExprs(pn);
       int num=0;
@@ -425,7 +432,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, isglobal);
+      CreateObjectNode con=new CreateObjectNode(td, isglobal, disjointId);
       for(int i=0; i<args.size(); i++) {
        con.addArgument((ExpressionNode)args.get(i));
       }
@@ -457,7 +464,8 @@ public class BuildIR {
       }
       return min;
     } else if (isNode(pn,"fieldaccess")) {
-      ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());          String fieldname=pn.getChild("field").getTerminal();
+      ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
+      String fieldname=pn.getChild("field").getTerminal();
       return new FieldAccessNode(en,fieldname);
     } else if (isNode(pn,"arrayaccess")) {
       ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
@@ -467,6 +475,15 @@ public class BuildIR {
       return new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
     } else if (isNode(pn,"cast2")) {
       return new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
+    } else if (isNode(pn, "getoffset")) {
+      TypeDescriptor td=parseTypeDescriptor(pn);
+      String fieldname = pn.getChild("field").getTerminal();
+      //System.out.println("Checking the values of: "+ " td.toString()= " + td.toString()+ "  fieldname= " + fieldname);
+      return new OffsetNode(td, fieldname);
+    } else if (isNode(pn, "tert")) {
+      return new TertiaryNode(parseExpression(pn.getChild("cond").getFirstChild()),
+                             parseExpression(pn.getChild("trueexpr").getFirstChild()),
+                             parseExpression(pn.getChild("falseexpr").getFirstChild()) );
     } else {
       System.out.println("---------------------");
       System.out.println(pn.PPrint(3,true));
@@ -565,7 +582,7 @@ public class BuildIR {
   }
 
   public BlockNode parseBlock(ParseNode pn) {
-      this.m_taskexitnum = 0;
+    this.m_taskexitnum = 0;
     if (pn==null||isEmpty(pn.getTerminal()))
       return new BlockNode();
     ParseNode bsn=pn.getChild("block_statement_list");
@@ -594,6 +611,15 @@ public class BuildIR {
     return bn;
   }
 
+  public Vector parseSESEBlock(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)));
+    }
+    return bv;
+  }
+
   public Vector parseBlockStatement(ParseNode pn) {
     Vector blockstatements=new Vector();
     if (isNode(pn,"tag_declaration")) {
@@ -680,6 +706,19 @@ public class BuildIR {
       ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
       BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
       blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
+    } else if (isNode(pn,"sese")) {
+      SESENode start=new SESENode();
+      SESENode end  =new SESENode();
+      start.setEnd( end   );
+      end.setStart( start );
+      blockstatements.add(start);
+      blockstatements.addAll(parseSESEBlock(blockstatements,pn.getChild("body").getFirstChild()));
+      blockstatements.add(end);
+    } else if (isNode(pn,"continue")) {
+       blockstatements.add(new ContinueBreakNode(false));
+    } else if (isNode(pn,"break")) {
+       blockstatements.add(new ContinueBreakNode(true));
+
     } else {
       System.out.println("---------------");
       System.out.println(pn.PPrint(3,true));