- newCode.add(ASSIGN_TO_PTR(structName, "label_num", labelNum));
- newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
- newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE_CHECK));
- newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
- newCode.add(ANNOTATE(semantics, anno));
- newCode.add("}");
+ 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);
+ }
+ // Generate redundant header files
+ newCode.add("\t"
+ + COMMENT("Automatically generated code for commit point clear: "
+ + construct.label));
+ newCode.add("");
+ // Add annotation
+
+ newCode.add("\t" + "if (" + construct.condition + ") {");
+ String structName = "cp_clear", anno = "annotation_cp_clear";
+ newCode.add("\t\t"
+ + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_CLEAR, structName));
+
+ String labelNum = Integer.toString(semantics.commitPointLabel2Num
+ .get(construct.label));
+ String labelName = construct.label;
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_name",
+ "\"" + labelName + "\""));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num",
+ labelNum));
+
+ newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_CLEAR));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t\t" + ANNOTATE(semantics, anno));
+ newCode.add("\t" + "}");