parsing passed
authorPeizhao Ou <peizhaoo@uci.edu>
Fri, 11 Oct 2013 23:18:03 +0000 (16:18 -0700)
committerPeizhao Ou <peizhaoo@uci.edu>
Fri, 11 Oct 2013 23:18:03 +0000 (16:18 -0700)
grammer/spec-compiler.jj
src/edu/uci/eecs/specCompiler/specExtraction/CPDefineCheckConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/CPDefineConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/GlobalConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/InterfaceConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/PotentialCPDefineConstruct.java

index a006e7bca3e5a463650b80f917e11477270df1d0..ca38b5facb925cb5208d3bf36b535214c16c3c1f 100644 (file)
@@ -69,6 +69,9 @@ package edu.uci.eecs.specCompiler.grammerParser;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 
 import edu.uci.eecs.specCompiler.specExtraction.Construct;
 import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
@@ -301,7 +304,10 @@ Construct Start() :
        LOOKAHEAD(3) res = Commit_point_define_check()
        )
        <EOF>
-       { return res; }
+       {
+               System.out.println(res);
+               return res;
+       }
 }
 
 GlobalConstruct Global_construct() :
@@ -321,7 +327,6 @@ GlobalConstruct Global_construct() :
        <TAIL>
        {
                res.unfoldInterfaceCluster();
-               System.out.println(res);
                return res;
        }
 }
@@ -425,73 +430,128 @@ void Happens_before(GlobalConstruct inst) :
 
 InterfaceConstruct Interface() :
 {
-       InterfaceConstruct res; 
+       InterfaceConstruct res;
+       String interfaceName, condition, idCode, check, action, postAction,
+               postCheck, commitPoint, hbLabel, hbCondition;
+       ArrayList<String> commitPointSet;
+       HashMap<String, String> hbConditions;
 }
 {
-       { res = null; }
+       {
+               res = null;
+               condition = "";
+               idCode = "";
+               check = "";
+               action = "";
+               postAction = "";
+               postCheck = "";
+               commitPointSet = new ArrayList<String>();
+               hbConditions = new HashMap<String, String>();
+       }
        <HEAD> 
                <BEGIN>
-                       <INTERFACE> <IDENTIFIER>
-                       <COMMIT_POINT_SET> <IDENTIFIER> (<OR> <IDENTIFIER>)*
-                       (<CONDITION> C_CPP_CODE())?
-                       (<HB_CONDITION> <IDENTIFIER> C_CPP_CODE())*
-                       (<ID> C_CPP_CODE())?
-                       (<CHECK> C_CPP_CODE())?
-                       (<ACTION> C_CPP_CODE())?
-                       (<POST_ACTION> C_CPP_CODE())?
-                       (<POST_CHECK> C_CPP_CODE())?
+                       <INTERFACE> (interfaceName = <IDENTIFIER>.image)
+                       <COMMIT_POINT_SET>
+                               (commitPoint = <IDENTIFIER>.image
+                               { commitPointSet.add(commitPoint); }
+                               )
+                               (<OR>
+                                       (commitPoint = <IDENTIFIER>.image)
+                                       {
+                                               if (commitPointSet.contains(commitPoint)) {
+                                                       throw new ParseException(interfaceName + " has" +
+                                                               "duplicate commit point labels");
+                                               }
+                                               commitPointSet.add(commitPoint);
+                                       }
+                               )*
+
+                       (<CONDITION> (condition = C_CPP_CODE()))?
+                       (
+                               <HB_CONDITION>
+                               (hbLabel = <IDENTIFIER>.image)
+                               (hbCondition = C_CPP_CODE())
+                               {
+                                       if (hbConditions.containsKey(hbLabel)) {
+                                               throw new ParseException(interfaceName + " has" +
+                                                       "duplicate happens-before condtion labels");
+                                       }
+                                       hbConditions.put(hbLabel, hbCondition);
+                               }
+                       )*
+                       (<ID> (idCode = C_CPP_CODE()))?
+                       (<CHECK> (check = C_CPP_CODE()))?
+                       (<ACTION> (action = C_CPP_CODE()))?
+                       (<POST_ACTION> (postAction = C_CPP_CODE()))?
+                       (<POST_CHECK> (postCheck = C_CPP_CODE()))?
                <END>
        <TAIL>
-       { return res; }
+       {
+               res = new InterfaceConstruct(interfaceName, commitPointSet, condition,
+                       hbConditions, idCode, check, action, postAction, postCheck);
+               return res;
+       }
 }
 
 PotentialCPDefineConstruct Potential_commit_point_define() :
 {
-       PotentialCPDefineConstruct res; 
+       PotentialCPDefineConstruct res;
+       String label, condition;
 }
 {
 
        { res = null; }
        <HEAD> 
                <BEGIN>
-                       <POTENTIAL_COMMIT_POINT_DEFINE> C_CPP_CODE()
-                       <LABEL> <IDENTIFIER>
+                       <POTENTIAL_COMMIT_POINT_DEFINE> (condition = C_CPP_CODE())
+                       <LABEL> (label = <IDENTIFIER>.image)
                <END>
        <TAIL>
-       { return res; }
+       {
+               res = new PotentialCPDefineConstruct(label, condition); 
+               return res;
+       }
 }
 
 
 CPDefineConstruct Commit_point_define() :
 {
-       CPDefineConstruct res;  
+       CPDefineConstruct res;
+       String label, potentialCPLabel, condition;
 }
 {
 
        { res = null; }
        <HEAD> 
                <BEGIN>
-                       <COMMIT_POINT_DEFINE> C_CPP_CODE()
-                       <POTENTIAL_COMMIT_POINT_LABEL> <IDENTIFIER>
-                       <LABEL> <IDENTIFIER>
+                       <COMMIT_POINT_DEFINE> (condition = C_CPP_CODE())
+                       <POTENTIAL_COMMIT_POINT_LABEL> (potentialCPLabel = <IDENTIFIER>.image)
+                       <LABEL> (label = <IDENTIFIER>.image)
                <END>
        <TAIL>
-       { return res; }
+       {
+               res = new CPDefineConstruct(label, potentialCPLabel, condition);
+               return res;
+       }
 }
 
 
 CPDefineCheckConstruct Commit_point_define_check() :
 {
        CPDefineCheckConstruct res;     
+       String label, condition;
 }
 {
 
        { res = null; }
        <HEAD> 
                <BEGIN> 
-                       <COMMIT_POINT_DEFINE_CHECK> C_CPP_CODE()
-                       <LABEL> <IDENTIFIER>
+                       <COMMIT_POINT_DEFINE_CHECK> (condition = C_CPP_CODE())
+                       <LABEL> (label = <IDENTIFIER>.image)
                <END>
        <TAIL>
-       { return res; }
+       {
+               res = new CPDefineCheckConstruct(label, condition);
+               return res;
+       }
 }
index 9edd764f7a4019e1207a665264faf93c138f1b8d..ed504e1b55725e2fb41b0a35e58a71ec11a3814a 100644 (file)
@@ -1,5 +1,19 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
 public class CPDefineCheckConstruct extends Construct {
-
+       public final String label;
+       public final String condition;
+       
+       public CPDefineCheckConstruct(String label, String condition) {
+               this.label = label;
+               this.condition = condition;
+       }
+       
+       public String toString() {
+               StringBuffer res = new StringBuffer();
+               res.append("@Commit_point_define_check:\n");
+               res.append("Label: " + label + "\n");
+               res.append("Condition: " + condition + "\n");
+               return res.toString();
+       }
 }
index e351dc9cbec58f3c1ccb3ee9182044dd0ee770d9..7d22728e4821a72c6a344997da15919e8d870964 100644 (file)
@@ -1,5 +1,22 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
 public class CPDefineConstruct extends Construct {
-
+       public final String label;
+       public final String potentialCPLabel;
+       public final String condition;
+       
+       public CPDefineConstruct(String label, String potentialCPLabel, String condition) {
+               this.label = label;
+               this.potentialCPLabel = potentialCPLabel;
+               this.condition = condition;
+       }
+       
+       public String toString() {
+               StringBuffer res = new StringBuffer();
+               res.append("@Potential_commit_point_define:\n");
+               res.append("Label: " + label + "\n");
+               res.append("Potential_CP_label: " + potentialCPLabel + "\n");
+               res.append("Condition: " + condition + "\n");
+               return res.toString();
+       }
 }
index 88c2bfb7abd73d236519cba463f808c0f3d1dab3..ef0a815673fe179bd4f59b78a83eeed73ed4b428 100644 (file)
@@ -64,11 +64,11 @@ public class GlobalConstruct extends Construct {
        }
        
        public String toString() {
-               StringBuilder sb = new StringBuilder();
-               sb.append("Code:\n");
+               StringBuilder sb = new StringBuilder("GlobalConstruct:\n");
+               sb.append("@Code:\n");
                sb.append(code);
                
-               sb.append("Happens_before:\n");
+               sb.append("@Happens_before:\n");
                for (ConditionalInterface left : hbRelations.keySet()) {
                        HashSet<ConditionalInterface> rights = hbRelations.get(left);
                        sb.append(left + " -> ");
index e18bc398f02aea903232c0662a46d2ccf568576d..c301c4e926ae02893a24f76f6092bf7b852a2261 100644 (file)
@@ -1,5 +1,57 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+
 public class InterfaceConstruct extends Construct {
+       public final String name;
+       public final ArrayList<String> commitPointSet;
+       public final String condition;
+       public final HashMap<String, String> hbConditions;
+       public final String idCode;
+       public final String check;
+       public final String action;
+       public final String postAction;
+       public final String postCheck;
 
+       public InterfaceConstruct(String name, ArrayList<String> commitPointSet,
+                       String condition, HashMap<String, String> hbConditions, String idCode,
+                       String check, String action, String postAction, String postCheck) {
+               this.name = name;
+               this.commitPointSet = commitPointSet;
+               this.condition = condition;
+               this.hbConditions = hbConditions;
+               this.idCode = idCode;
+               this.check = check;
+               this.action = action;
+               this.postAction = postAction;
+               this.postCheck = postCheck;
+       }
+       
+       public String toString() {
+               StringBuilder sb = new StringBuilder("InterfaceConstruct:\n");
+               sb.append("@Interface: " + name + "\n");
+               sb.append("@Commit_point_set: ");
+               for (String commitPoint : commitPointSet) {
+                       sb.append(commitPoint + " | ");
+               }
+               sb.append(".\n");
+               sb.append("@Condition: ");
+               sb.append(condition + "\n");
+               sb.append("@HBConditions: \n");
+               for (String hbLabel : hbConditions.keySet()) {
+                       String hbCondition = hbConditions.get(hbLabel);
+                       sb.append(hbLabel + " :: " + hbCondition + "\n");
+               }
+               sb.append("@ID: ");
+               sb.append(idCode + "\n");
+               sb.append("@Check: " + check + "\n");
+               sb.append("@Action:\n");
+               sb.append(action + "\n");
+               sb.append("@Post_action:\n");
+               sb.append(postAction + "\n");
+               sb.append("@Post_check: " + postCheck + "\n");
+               
+               return sb.toString();
+       }
 }
index 946697e90d0422db939877a74a45a6c5aca44e17..3f68610c2520a3191828fc9256da874ecbeaf33c 100644 (file)
@@ -1,5 +1,19 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
 public class PotentialCPDefineConstruct extends Construct {
-
+       public final String label;
+       public final String condition;
+       
+       public PotentialCPDefineConstruct(String label, String condition) {
+               this.label = label;
+               this.condition = condition;
+       }
+       
+       public String toString() {
+               StringBuffer res = new StringBuffer();
+               res.append("@Potential_commit_point_define:\n");
+               res.append("Label: " + label + "\n");
+               res.append("Condition: " + condition + "\n");
+               return res.toString();
+       }
 }