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;
LOOKAHEAD(3) res = Commit_point_define_check()
)
<EOF>
- { return res; }
+ {
+ System.out.println(res);
+ return res;
+ }
}
GlobalConstruct Global_construct() :
<TAIL>
{
res.unfoldInterfaceCluster();
- System.out.println(res);
return res;
}
}
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;
+ }
}
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();
+ }
}