Add support for tasks & flags
authorbdemsky <bdemsky>
Sat, 15 Apr 2006 01:09:40 +0000 (01:09 +0000)
committerbdemsky <bdemsky>
Sat, 15 Apr 2006 01:09:40 +0000 (01:09 +0000)
Robust/src/IR/FlagDescriptor.java [new file with mode: 0644]
Robust/src/IR/State.java
Robust/src/IR/TaskDescriptor.java [new file with mode: 0644]
Robust/src/IR/Tree/FieldNode.java [new file with mode: 0644]
Robust/src/IR/Tree/FlagExpressionNode.java [new file with mode: 0644]
Robust/src/IR/Tree/FlagOpNode.java [new file with mode: 0644]
Robust/src/IR/Tree/Kind.java
Robust/src/Lex/Keyword.java
Robust/src/Lex/Lexer.java
Robust/src/Parse/java14.cup

diff --git a/Robust/src/IR/FlagDescriptor.java b/Robust/src/IR/FlagDescriptor.java
new file mode 100644 (file)
index 0000000..f2f6bfd
--- /dev/null
@@ -0,0 +1,18 @@
+package IR;
+
+/**
+ * Descriptor 
+ *
+ * represents a symbol in the language (var name, function name, etc).
+ */
+
+public class FlagDescriptor extends Descriptor {
+
+    public FlagDescriptor(String identifier) {
+       super(identifier);
+    }
+
+    public String toString() {
+       return "Flag "+getSymbol();
+    }
+}
index f70466cb946d191a84fe9ce6a079069575353a7f..ee0d12bbf7f1c191fb593bc650095ff9b5422022 100644 (file)
@@ -85,6 +85,10 @@ public class State {
        treemethodmap.put(md,bn);
     }
 
+    public void addTreeCode(TaskDescriptor td, BlockNode bn) {
+       treemethodmap.put(td,bn);
+    }
+
     public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
        flatmethodmap.put(md,bn);
     }
diff --git a/Robust/src/IR/TaskDescriptor.java b/Robust/src/IR/TaskDescriptor.java
new file mode 100644 (file)
index 0000000..488783c
--- /dev/null
@@ -0,0 +1,79 @@
+package IR;
+import IR.Tree.ExpressionNode;
+import java.util.Vector;
+
+/**
+ * Descriptor 
+ *
+ */
+
+public class TaskDescriptor extends Descriptor {
+
+    protected String identifier;
+    protected Vector params;
+    protected SymbolTable paramtable;
+    protected VarDescriptor thisvd;
+
+
+    public TaskDescriptor(String identifier) {
+       super(identifier);
+       this.identifier=identifier;
+       this.uniqueid=count++;
+       params=new Vector();
+       paramtable=new SymbolTable();
+       thisvd=null;
+    }
+
+    public String getSafeMethodDescriptor() {
+       String st="";
+       for(int i=0;i<numParameters();i++) {
+           st+=getParamType(i).getSafeDescriptor();
+           if ((i+1)<numParameters())
+               st+="_";
+       }
+       return st;
+    }
+
+    public SymbolTable getParameterTable() {
+       return paramtable;
+    }
+
+    public void addParameter(TypeDescriptor type, String paramname) {
+       if (paramname.equals("this"))
+           throw new Error("Can't have parameter named this");
+       VarDescriptor vd=new VarDescriptor(type, paramname);
+
+       params.add(vd);
+       if (paramtable.getFromSameScope(paramname)!=null) {
+           throw new Error("Parameter "+paramname+" already defined");
+       }
+       paramtable.add(vd);
+    }
+
+    public int numParameters() {
+       return params.size();
+    }
+
+    public VarDescriptor getParameter(int i) {
+       return (VarDescriptor)params.get(i);
+    }
+
+    public String getParamName(int i) {
+       return ((VarDescriptor)params.get(i)).getName();
+    }
+
+    public TypeDescriptor getParamType(int i) {
+       return ((VarDescriptor)params.get(i)).getType();
+    }
+
+    public String toString() {
+       String st=identifier+"(";
+       for(int i=0;i<params.size();i++) {
+           st+=getParamType(i)+" "+getParamName(i);
+           if ((i+1)!=params.size())
+               st+=", ";
+       }
+       st+=")";
+       return st;
+    }
+}
diff --git a/Robust/src/IR/Tree/FieldNode.java b/Robust/src/IR/Tree/FieldNode.java
new file mode 100644 (file)
index 0000000..3ef4fa9
--- /dev/null
@@ -0,0 +1,28 @@
+package IR.Tree;
+
+import IR.*;
+
+public class FlagNode extends FlagExpressionNode {
+    FlagDescriptor flag;
+    String name;
+
+    public FlagNode(String flag) {
+       this.name=flag;
+    }
+
+    public void setFlag(FlagDescriptor flag) {
+       this.flag=flag;
+    }
+
+    public FlagDescriptor getFlag() {
+       return flag;
+    }
+
+    public int kind() {
+       return Kind.FlagNode;
+    }
+
+    public String printNode(int indent) {
+       return name;
+    }
+}
diff --git a/Robust/src/IR/Tree/FlagExpressionNode.java b/Robust/src/IR/Tree/FlagExpressionNode.java
new file mode 100644 (file)
index 0000000..6d27547
--- /dev/null
@@ -0,0 +1,8 @@
+package IR.Tree;
+import IR.TypeDescriptor;
+
+public class FlagExpressionNode extends TreeNode {
+    public String printNode(int indentlevel) {
+       return null;
+    }
+}
diff --git a/Robust/src/IR/Tree/FlagOpNode.java b/Robust/src/IR/Tree/FlagOpNode.java
new file mode 100644 (file)
index 0000000..5ce5748
--- /dev/null
@@ -0,0 +1,43 @@
+package IR.Tree;
+import IR.Operation;
+
+public class FlagOpNode extends FlagExpressionNode {
+    FlagExpressionNode left;
+    FlagExpressionNode right;
+    Operation op;
+
+    public FlagOpNode(FlagExpressionNode l, FlagExpressionNode r, Operation o) {
+       left=l;
+       right=r;
+       op=o;
+    }
+
+    public FlagOpNode(FlagExpressionNode l, Operation o) {
+       left=l;
+       right=null;
+       op=o;
+    }
+
+    public FlagExpressionNode getLeft() {
+       return left;
+    }
+
+    public FlagExpressionNode getRight() {
+       return right;
+    }
+
+    public Operation getOp() {
+       return op;
+    }
+
+    public String printNode(int indent) {
+       if (right==null)
+           return op.toString()+"("+left.printNode(indent)+")";
+       else
+           return left.printNode(indent)+" "+op.toString()+" "+right.printNode(indent);
+    }
+
+    public int kind() {
+       return Kind.FlagOpNode;
+    }
+}
index 0415fd170218dc3af9fdbf322843fc9fa17f4019..323fc42e20949e1bb327f003997c0e0a01417b3b 100644 (file)
@@ -17,4 +17,6 @@ public class Kind {
     public final static int DeclarationNode=14;
     public final static int NameNode=15;
     public final static int ArrayAccessNode=16;
+    public final static int FlagNode=17;
+    public final static int FlagOpNode=18;
 }
index 9ea982e114aee051734a0bbc2370c64245594cdc..f91131aeb28014cdaa18dddb32b4b397d98b668b 100644 (file)
@@ -68,5 +68,6 @@ class Keyword extends Token {
     key_table.put("flag", new Integer(Sym.FLAG));
     key_table.put("tag", new Integer(Sym.TAG));
     key_table.put("task", new Integer(Sym.TASK));
+    key_table.put("taskexit", new Integer(Sym.TASKEXIT));
   }
 }
index ad1a10da0ed1cf1c5b62a902e8f37f7727b36b9a..1f8775d69a44e81dd9bd70003fec10eccc1ff8d7 100644 (file)
@@ -253,7 +253,7 @@ public class Lexer {
     "synchronized", "this", "throw", "throws", "transient", "try", "void",
     "volatile", "while", 
     //keywords for failure aware computation
-    "flag", "tag", "task"};
+    "flag", "tag", "task", "taskexit"};
   Token getIdentifier() {
     // Get id string.
     StringBuffer sb = new StringBuffer().append(consume());
index f48834448050f62cbc5c9006566268122668415c..1d296fae5b6af7042598862b249ef4fa37d35776 100644 (file)
@@ -103,11 +103,6 @@ terminal ASSERT; // assert_statement
 terminal ELLIPSIS;
 terminal ENUM;
 
-//failure aware computation keywords
-terminal FLAG;
-terminal TAG;
-terminal TASK;
-non terminal ParseNode flag_declaration;
 
 // 19.2) The Syntactic Grammar
 non terminal ParseNode goal;
@@ -223,9 +218,143 @@ non terminal ParseNode assignment;
 non terminal ParseNode assignment_operator;
 non terminal ParseNode expression_opt, expression;
 //non terminal ParseNode constant_expression;
+//failure aware computation keywords
+terminal FLAG;
+terminal TAG;
+terminal TASK;
+terminal TASKEXIT;
+non terminal ParseNode flag_declaration;
+non terminal ParseNode task_declaration;
+non terminal ParseNode task_parameter_list;
+non terminal ParseNode task_parameter;
+non terminal ParseNode flag_expression;
+non terminal ParseNode flag_andexpression;
+non terminal ParseNode flag_notexpression;
+non terminal ParseNode task_exitstatement;
+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_change;
 
 start with goal;
 
+
+// Task declarations
+task_declaration ::= 
+       TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN 
+       flag_effects_opt:feo
+       method_body:body 
+       {: 
+       ParseNode pn=new ParseNode("task_declaration");
+       pn.addChild("name").addChild(id);
+       pn.addChild(tpl);
+       pn.addChild(feo);
+       pn.addChild("body").addChild(body);     
+       RESULT=pn;
+       :};
+
+task_parameter_list ::=
+               task_parameter:fp {: 
+               ParseNode pn=new ParseNode("task_parameter_list");
+               pn.addChild(fp);
+               RESULT=pn;
+       :}
+       |       task_parameter_list:fpl COMMA task_parameter:fp {: 
+               fpl.addChild(fp);
+               RESULT=fpl;
+       :}
+       ;
+
+task_parameter ::=
+               type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
+               ParseNode pn=new ParseNode("task_parameter");
+               pn.addChild(type);
+               pn.addChild(name);
+               pn.addChild(exp);
+               RESULT=pn;
+       :}
+       ;
+
+flag_expression ::= 
+       flag_andexpression:exp {: 
+               RESULT=exp;
+       :}
+       | flag_expression:exp1 OROR flag_andexpression:exp2 {: 
+               ParseNode pn=new ParseNode("or");
+               pn.addChild(exp1);
+               pn.addChild(exp2);
+               RESULT=pn;
+       :}
+       ;
+
+flag_andexpression ::= 
+       flag_notexpression:exp {: RESULT=exp; :}
+       | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {: 
+               ParseNode pn=new ParseNode("and");
+               pn.addChild(exp1);
+               pn.addChild(exp2);
+               RESULT=pn;
+       :}
+       ;
+
+flag_notexpression ::=
+       NOT flag_notexpression:exp {: 
+               ParseNode pn=new ParseNode("not");
+               pn.addChild(exp);
+               RESULT=pn;
+       :}
+       | LPAREN flag_expression:exp RPAREN {: 
+               RESULT=exp;
+       :}
+       | IDENTIFIER:id {:
+               ParseNode pn=new ParseNode("name");
+               pn.addChild(id);
+               RESULT=pn;
+       :}
+       ;
+
+task_exitstatement ::= TASKEXIT flag_effects_opt SEMICOLON{: 
+               RESULT=new ParseNode("taskexit");
+       :};
+
+flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
+       | {: RESULT = null; :}
+       ;
+
+flag_effects ::= flag_effect:fe {: 
+               ParseNode pn=new ParseNode("flag_effects_list");
+               pn.addChild(fe);
+               RESULT=pn;
+       :}
+       |       flag_effects:fes COMMA flag_effect:fe {: 
+               fes.addChild(fe);
+               RESULT=fes;
+       :};
+
+flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE {: 
+               ParseNode pn=new ParseNode("flag_effect");
+               pn.addChild(fl);
+               RESULT=pn;
+       :};
+
+flag_list ::= flag_change:fc {: 
+               ParseNode pn=new ParseNode("flag_list");
+               pn.addChild(fc);
+               RESULT=pn;
+       :}
+       |       flag_list:fl COMMA flag_change:fc {: 
+               fl.addChild(fc);
+               RESULT=fl;
+       :};
+
+flag_change ::= IDENTIFIER:id {: 
+               RESULT=new ParseNode("name").addChild(id).getRoot();
+       :} |
+       NOT IDENTIFIER:id {: 
+               RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
+       :};
+
 // 19.2) The Syntactic Grammar
 goal ::=       compilation_unit:cu
        {:
@@ -391,6 +520,10 @@ type_declaration ::=
                {:
                        RESULT=cd;
                :}
+       |       task_declaration:td 
+               {:
+                       RESULT=td;
+               :}
 //      |       interface_declaration
        |       SEMICOLON {: RESULT=new ParseNode("empty"); :}
        ;
@@ -811,6 +944,7 @@ statement_without_trailing_substatement ::=
        |       break_statement:st {: RESULT=st; :}
        |       continue_statement:st {: RESULT=st; :}
        |       return_statement:st {: RESULT=st; :}
+       |       task_exitstatement:st {: RESULT=st; :}
 //     |       synchronized_statement
 //     |       throw_statement
 //     |       try_statement