+ newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(anno, "type",
+ SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t\t" + ANNOTATE(semantics, anno));
+ newCode.add("\t" + "}");
+ return newCode;
+ }
+
+ public static String getCPInterfaceNum(SemanticsChecker semantics,
+ String commitPointLabel) {
+ HashMap<String, InterfaceConstruct> cp2Interface = semantics.CPLabel2InterfaceConstruct;
+ InterfaceConstruct iConstruct = cp2Interface.get(commitPointLabel);
+ String interfaceName = iConstruct.name;
+ String interfaceNum = Integer.toString(semantics.interface2Num
+ .get(interfaceName));
+ return interfaceNum;
+ }
+
+ /**
+ * <p>
+ * Commit point define check should be unique to each interface, meaning
+ * that they are not shared between different interfaces
+ * </p>
+ *
+ * @param semantics
+ * @param construct
+ * @return
+ */
+ public static ArrayList<String> generateCPDefineCheck(
+ SemanticsChecker semantics, CPDefineCheckConstruct construct) {
+ ArrayList<String> newCode = new ArrayList<String>();
+ // Add atomic return variable if the predicate accesses to it
+ if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
+ addAtomicReturn(semantics, construct);
+ }
+ // Generate redundant header files
+ newCode.add("\t"
+ + COMMENT("Automatically generated code for commit point define check: "
+ + construct.label));
+ newCode.add("");
+ // Add annotation
+
+ newCode.add("\t" + "if (" + construct.condition + ") {");
+ String structName = "cp_define_check", anno = "annotation_cp_define_check";
+ newCode.add("\t\t"
+ + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName));
+ String labelNum = Integer.toString(semantics.commitPointLabel2Num
+ .get(construct.label));
+ String interfaceNum = getCPInterfaceNum(semantics, construct.label);
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(structName, "label_name", "\""
+ + construct.label + "\""));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+
+ newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE_CHECK));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t\t" + ANNOTATE(semantics, anno));
+ newCode.add("\t" + "}");
+ return newCode;
+ }
+
+ /**
+ * <p>
+ * Commit point define check should be unique to each interface, meaning
+ * that they are not shared between different interfaces
+ * </p>
+ *
+ * @param semantics
+ * @param construct
+ * @return
+ */
+ public static ArrayList<String> generateCPClear(SemanticsChecker semantics,
+ CPClearConstruct construct) {
+ ArrayList<String> newCode = new ArrayList<String>();
+ // Add atomic return variable if the predicate accesses to it
+ if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
+ addAtomicReturn(semantics, construct);
+ }