changes
[cdsspec-compiler.git] / src / edu / uci / eecs / specCompiler / codeGenerator / SemanticsChecker.java
index cb5792a892eb0a37d7444503fc3419e0d79d222c..ed20aa86ef6ed9a7765572315669e5283fcda979 100644 (file)
@@ -6,6 +6,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 
 import edu.uci.eecs.specCompiler.grammerParser.ParseException;
+import edu.uci.eecs.specCompiler.specExtraction.CPClearConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.ClassBeginConstruct;
@@ -21,6 +22,15 @@ import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.SourceFileInfo;
 import edu.uci.eecs.specCompiler.specExtraction.SpecExtractor;
 
+/**
+ * <p>
+ * A specificaiton semantics checker that checks the consistency of the
+ * specifications after they are extracted from the source code.
+ * </p>
+ * 
+ * @author peizhaoo
+ * 
+ */
 public class SemanticsChecker {
        public final HashMap<File, SourceFileInfo> srcFilesInfo;
        public final ArrayList<Construct> constructs;
@@ -28,7 +38,7 @@ public class SemanticsChecker {
        public final HashMap<String, PotentialCPDefineConstruct> potentialCPLabel2Construct;
        public final HashMap<String, InterfaceConstruct> interfaceName2Construct;
        public final HashMap<String, InterfaceDefineConstruct> interfaceName2DefineConstruct;
-       public final HashMap<String, ArrayList<InterfaceConstruct>> CPLabel2InterfaceConstruct;
+       public final HashMap<String, InterfaceConstruct> CPLabel2InterfaceConstruct;
 
        public final HashMap<String, Integer> interface2Num;
        public final HashMap<Integer, String> num2Interface;
@@ -59,7 +69,7 @@ public class SemanticsChecker {
                this.potentialCPLabel2Construct = new HashMap<String, PotentialCPDefineConstruct>();
                this.interfaceName2Construct = new HashMap<String, InterfaceConstruct>();
                this.interfaceName2DefineConstruct = new HashMap<String, InterfaceDefineConstruct>();
-               this.CPLabel2InterfaceConstruct = new HashMap<String, ArrayList<InterfaceConstruct>>();
+               this.CPLabel2InterfaceConstruct = new HashMap<String, InterfaceConstruct>();
                this.entryPointConstructs = new ArrayList<EntryPointConstruct>();
                this.classBeginConstruct = null;
                this.classEndConstruct = null;
@@ -211,11 +221,18 @@ public class SemanticsChecker {
 
                                for (int j = 0; j < iConstruct.commitPointSet.size(); j++) {
                                        String label = iConstruct.commitPointSet.get(j);
+                                       // if (!CPLabel2InterfaceConstruct.containsKey(label)) {
+                                       // CPLabel2InterfaceConstruct.put(label,
+                                       // new ArrayList<InterfaceConstruct>());
+                                       // }
+                                       // CPLabel2InterfaceConstruct.get(label).add(iConstruct);
                                        if (!CPLabel2InterfaceConstruct.containsKey(label)) {
-                                               CPLabel2InterfaceConstruct.put(label,
-                                                               new ArrayList<InterfaceConstruct>());
+                                               CPLabel2InterfaceConstruct.put(label, iConstruct);
+                                       } else {
+                                               throw new SemanticsCheckerException(
+                                                               "Commit point has multiple interfaces!");
                                        }
-                                       CPLabel2InterfaceConstruct.get(label).add(iConstruct);
+
                                }
                        }
                }
@@ -263,6 +280,15 @@ public class SemanticsChecker {
                                commitPointLabel2Num.put(label, _commitPointNum++);
                                num2CommitPointLabel.put(_commitPointNum, label);
 
+                               CPLabel2Construct.put(label, construct);
+                       } else if (construct instanceof CPClearConstruct) {
+                               CPClearConstruct theConstruct = (CPClearConstruct) construct;
+                               label = theConstruct.label;
+                               checkLabelDuplication(construct, label);
+                               // Number the commit point define check label
+                               commitPointLabel2Num.put(label, _commitPointNum++);
+                               num2CommitPointLabel.put(_commitPointNum, label);
+
                                CPLabel2Construct.put(label, construct);
                        } else if (construct instanceof CPDefineConstruct) {
                                CPDefineConstruct theConstruct = (CPDefineConstruct) construct;