import java.util.HashMap;
import java.util.HashSet;
+import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct.DefineVar;
import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct;
import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
import edu.uci.eecs.specCompiler.specExtraction.Construct;
import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
public class SemanticsChecker {
public final ArrayList<SpecConstruct> constructs;
- public final HashMap<String, SpecConstruct> label2Construct;
+ public final HashMap<String, SpecConstruct> CPLabel2Construct;
+ public final HashMap<String, SpecConstruct> potentialCPLabel2Construct;
public final HashMap<String, SpecConstruct> interfaceName2Construct;
+ public final HashSet<DefineVar> defineVars;
public SemanticsChecker(ArrayList<SpecConstruct> constructs) {
this.constructs = constructs;
- this.label2Construct = new HashMap<String, SpecConstruct>();
+ this.CPLabel2Construct = new HashMap<String, SpecConstruct>();
+ this.potentialCPLabel2Construct = new HashMap<String, SpecConstruct>();
this.interfaceName2Construct = new HashMap<String, SpecConstruct>();
+ this.defineVars = new HashSet<DefineVar>();
}
- private void checkHBLabelConsistency(String interfaceName, String label)
+ private void checkHBLabelConsistency(ConditionalInterface inst)
throws SemanticsCheckerException {
+ String interfaceName = inst.interfaceName,
+ label = inst.hbConditionLabel;
if (!interfaceName2Construct.containsKey(interfaceName)) {
throw new SemanticsCheckerException(
- "In global construct, no interface \""
- + interfaceName + "\"!");
- } else {
+ "In global construct, no interface \"" + interfaceName
+ + "\"!");
+ } else if (!label.equals("")){
InterfaceConstruct iConstruct = (InterfaceConstruct) interfaceName2Construct
.get(interfaceName).construct;
if (!iConstruct.hbConditions.containsKey(label)) {
throw new SemanticsCheckerException("Interface "
- + interfaceName
- + " doesn't contain HB_codition: " + label
- + "!");
+ + interfaceName + " doesn't contain HB_codition: "
+ + label + "!");
}
}
}
+ private void checkLabelDuplication(Construct construct, String label)
+ throws SemanticsCheckerException {
+ if (potentialCPLabel2Construct.containsKey(label) ||
+ CPLabel2Construct.containsKey(label))
+ throw new SemanticsCheckerException("In construct: " + construct
+ + "\"" + label + "\" has duplication.");
+ }
+
public void check() throws SemanticsCheckerException {
boolean hasGlobalConstruct = false;
// First grab the information from the interface
if (inst instanceof InterfaceConstruct) {
InterfaceConstruct iConstruct = (InterfaceConstruct) inst;
interfaceName2Construct.put(iConstruct.name, constructs.get(i));
+ for (int j = 0; j < iConstruct.action.defineVars.size(); j++) {
+ DefineVar var = iConstruct.action.defineVars.get(j);
+ var.renameVarName("__" + iConstruct.name + "_" + var.varName + "__");
+ }
}
}
+ String label;
for (int i = 0; i < constructs.size(); i++) {
SpecConstruct inst = constructs.get(i);
Construct construct = inst.construct;
throw new SemanticsCheckerException(
"More than one global construct!");
}
-
HashMap<ConditionalInterface, HashSet<ConditionalInterface>> hbConditions = theConstruct.hbRelations;
for (ConditionalInterface left : hbConditions.keySet()) {
HashSet<ConditionalInterface> set = hbConditions.get(left);
- checkHBLabelConsistency(left.interfaceName, left.hbConditionLabel);
+ checkHBLabelConsistency(left);
for (ConditionalInterface right : set) {
- checkHBLabelConsistency(right.interfaceName, right.hbConditionLabel);
+ checkHBLabelConsistency(right);
}
}
} else if (construct instanceof PotentialCPDefineConstruct) {
PotentialCPDefineConstruct theConstruct = (PotentialCPDefineConstruct) construct;
- label2Construct.put(theConstruct.label, inst);
+ label = theConstruct.label;
+ checkLabelDuplication(construct, label);
+ potentialCPLabel2Construct.put(label, inst);
} else if (construct instanceof CPDefineCheckConstruct) {
CPDefineCheckConstruct theConstruct = (CPDefineCheckConstruct) construct;
- label2Construct.put(theConstruct.label, inst);
+ label = theConstruct.label;
+ checkLabelDuplication(construct, label);
+ CPLabel2Construct.put(label, inst);
+ } else if (construct instanceof CPDefineConstruct) {
+ CPDefineConstruct theConstruct = (CPDefineConstruct) construct;
+ label = theConstruct.label;
+ checkLabelDuplication(construct, label);
+ CPLabel2Construct.put(label, inst);
}
}
}
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Interface name 2 Construct:\n");
+ for (String interfaceName : interfaceName2Construct.keySet()) {
+ sb.append(interfaceName + "\t" + interfaceName2Construct.get(interfaceName) + "\n");
+ }
+
+ sb.append("Potential commit point label 2 Construct:\n");
+ for (String label : potentialCPLabel2Construct.keySet()) {
+ sb.append(label + "\t" + potentialCPLabel2Construct.get(label) + "\n");
+ }
+
+ sb.append("Commit point label 2 Construct:\n");
+ for (String label : CPLabel2Construct.keySet()) {
+ sb.append(label + "\t" + CPLabel2Construct.get(label) + "\n");
+ }
+ return sb.toString();
+ }
}