+ // Add annotation
+ newCode.add("if (" + construct.condition + ") {");
+ String structName = "potential_cp_define", anno = "annotation_potential_cp_define";
+ newCode.add(DECLARE(ANNO_POTENTIAL_CP_DEFINE, structName));
+ String labelNum = Integer.toString(semantics.commitPointLabel2Num
+ .get(construct.label));
+ newCode.add(ASSIGN(structName, "label_num", labelNum));
+ newCode.add(DECLARE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE));
+ newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(ANNOTATE(anno));
+ newCode.add("}");
+ return newCode;
+ }
+
+ 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(COMMENT("Automatically generated code for commit point define check: "
+ + construct.label));
+ newCode.add(COMMENT("Include redundant headers"));
+ newCode.add(INCLUDE(HEADER_STDINT));
+ newCode.add(INCLUDE(HEADER_CDSANNOTATE));
+ newCode.add("");
+ // Add annotation
+ newCode.add("if (" + construct.condition + ") {");
+ String structName = "cp_define_check", anno = "annotation_cp_define_check";
+ newCode.add(DECLARE(ANNO_CP_DEFINE_CHECK, structName));
+ String labelNum = Integer.toString(semantics.commitPointLabel2Num
+ .get(construct.label));
+ newCode.add(ASSIGN(structName, "label_num", labelNum));
+ newCode.add(DECLARE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE_CHECK));
+ newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(ANNOTATE(anno));
+ newCode.add("}");
+ return newCode;
+ }
+
+ public static ArrayList<String> generateCPDefine(
+ SemanticsChecker semantics, CPDefineConstruct construct) {
+ ArrayList<String> newCode = new ArrayList<String>();
+ // Generate redundant header files
+ newCode.add(COMMENT("Automatically generated code for commit point define check: "
+ + construct.label));
+ newCode.add("");
+ // Add annotation
+ newCode.add("if (" + construct.condition + ") {");
+ String structName = "cp_define", anno = "annotation_cp_define";
+ newCode.add(DECLARE(ANNO_CP_DEFINE, structName));
+ String labelNum = Integer.toString(semantics.commitPointLabel2Num
+ .get(construct.label));
+ newCode.add(ASSIGN(structName, "label_num", labelNum));
+ newCode.add(DECLARE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE));
+ newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(ANNOTATE(anno));
+ newCode.add("}");