Checking in code to put flags into createobjectnodes
authorbdemsky <bdemsky>
Thu, 18 May 2006 23:06:21 +0000 (23:06 +0000)
committerbdemsky <bdemsky>
Thu, 18 May 2006 23:06:21 +0000 (23:06 +0000)
Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/CreateObjectNode.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/Parse/java14.cup
Robust/src/designnotes

index f2f95aa4766b6406f0adf4e73dc7914eca1c3617..d119eae896464773dd29d53f0de7c4a0a0e3aca3 100644 (file)
@@ -138,7 +138,19 @@ public class BuildFlat {
            //Call to constructor
            FlatCall fc=new FlatCall(md, null, out_temp, temps);
            last.addNext(fc);
-           return new NodePair(fn,fc); 
+           last=fc;
+           if (con.getFlagEffects()!=null) {
+               FlatFlagActionNode ffan=new FlatFlagActionNode(false);
+               FlagEffects fes=con.getFlagEffects();
+               TempDescriptor flagtemp=outtemp;
+               for(int j=0;j<fes.numEffects();j++) {
+                   FlagEffect fe=fes.getEffect(j);
+                   ffan.addFlagAction(flagtemp, fe.getFlag(), fe.getStatus());
+               }
+               last.addNext(ffan);
+               last=ffan;
+           }
+           return new NodePair(fn,last); 
        } else {
            FlatNode first=null;
            FlatNode last=null;
index c9368be4d7d59b2dcf84cf08a2a47246f7e5d3c0..6e29795869a20d02a0d9250f0a0ce4d5f0b44d95 100644 (file)
@@ -292,6 +292,12 @@ public class BuildIR {
            for(int i=0;i<args.size();i++) {
                con.addArgument((ExpressionNode)args.get(i));
            }
+           /* Could have flag set here */
+           if (pn.getChild("flag_list")!=null) {
+               FlagEffects fe=new FlagEffects(null);
+               parseFlagEffect(fe, pn.getChild("flag_list"));
+               con.addFlagEffects(fe);
+           }
            return con;
        } else if (isNode(pn,"createarray")) {
            System.out.println(pn.PPrint(3,true));
index afeae5fbb1d479aba5110fad14b404f59c9a5c96..6cbb9bf9bb543130f73a233d55a1977dd8d0595b 100644 (file)
@@ -7,12 +7,21 @@ public class CreateObjectNode extends ExpressionNode {
     TypeDescriptor td;
     Vector argumentlist;
     MethodDescriptor md;
+    FlagEffects fe;
 
     public CreateObjectNode(TypeDescriptor type) {
        td=type;
        argumentlist=new Vector();
     }
 
+    public void addFlagEffects(FlagEffects fe) {
+       this.fe=fe;
+    }
+
+    public FlagEffects getFlagEffects() {
+       return fe;
+    }
+
     public void addArgument(ExpressionNode en) {
        argumentlist.add(en);
     }
index 9a78cb420a94aec88e3865b70d0776a2806874e0..5782b95f1bb8ea555815c55f2e3489ac12020858 100644 (file)
@@ -457,6 +457,24 @@ public class SemanticCheck {
 
        TypeDescriptor typetolookin=con.getType();
        checkTypeDescriptor(typetolookin);
+
+       /* Check flag effects */
+       if (con.getFlagEffects()!=null) {
+           FlagEffects fe=con.getFlagEffects();
+           ClassDescriptor cd=typetolookin.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());
+               flag.setFlag(flag_d);
+           }
+       }
+
+
        if ((!typetolookin.isClass())&&(!typetolookin.isArray())) 
            throw new Error("Can't allocate primitive type:"+con.printNode(0));
 
@@ -754,9 +772,7 @@ public class SemanticCheck {
        default:
            throw new Error();
        }
-
-     
-
+   
        if (td!=null)
            if (!typeutil.isSuperorType(td, on.getType())) {
                System.out.println(td);
index 8811df087d3bcaa0b6d23b056ac90ab1b5fbcd75..52c5e099354969f2535ed5bf28ed94fe8e679064 100644 (file)
@@ -235,6 +235,7 @@ non terminal ParseNode flag_effects_opt;
 non terminal ParseNode flag_effects;
 non terminal ParseNode flag_effect;
 non terminal ParseNode flag_list;
+non terminal ParseNode flag_list_opt;
 non terminal ParseNode flag_change;
 
 start with goal;
@@ -339,6 +340,10 @@ flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE {:
                RESULT=pn;
        :};
 
+flag_list_opt ::= LPAREN flag_list:fl RPAREN {:RESULT=fl;:}
+       | {: RESULT = new ParseNode("empty"); :}
+       ;
+
 flag_list ::= flag_change:fc {: 
                ParseNode pn=new ParseNode("flag_list");
                pn.addChild(fc);
@@ -1168,10 +1173,11 @@ primary_no_new_array ::=
 //     |       name DOT THIS
        ;
 class_instance_creation_expression ::=
-               NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {: 
+               NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_effects_opt:feo {: 
                ParseNode pn=new ParseNode("createobject");
                pn.addChild(type);
                pn.addChild(args);
+               pn.addChild(feo);
                RESULT=pn;
        :}
 //     |       NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
index 968817c743691b408f0479f9b18dce0eaed6c67d..eba714f0f91fac9360edbe252e248647ab7717d4 100644 (file)
@@ -7,8 +7,8 @@ Assumptions:
 Task parameters can't be modified
 
 How do we handle new object allocation?
-Idea #1: Simply lose precision -- don't even attempt analysis
-         Improvement - let set flags at allocation
+Idea #1: Set flags at allocation
+        Only allow flag setting at exit for parameters
 
 Non parameter variables: 
 1) Type must contain flags