import edu.uci.eecs.specCompiler.grammerParser.utilParser.UtilParser;
import edu.uci.eecs.specCompiler.grammerParser.utilParser.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.ConditionalInterface;
import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
+/**
+ * <p> Defines a list of commonly used constant strings. </p>
+ * @author peizhaoo
+ *
+ */
public class CodeVariables {
// C++ code or library
public static final String HEADER_STDLIB = "<stdlib.h>";
public static final String SPEC_ANNO_TYPE_INTERFACE_END = "INTERFACE_END";
public static final String SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE = "POTENTIAL_CP_DEFINE";
public static final String SPEC_ANNO_TYPE_CP_DEFINE_CHECK = "CP_DEFINE_CHECK";
+ public static final String SPEC_ANNO_TYPE_CP_CLEAR = "CP_CLEAR";
public static final String SPEC_ANNO_TYPE_CP_DEFINE = "CP_DEFINE";
public static final String SPEC_ANNOTATION = "spec_annotation";
public static final String SPEC_ANNOTATION_FIELD_TYPE = "type";
public static final String ANNO_POTENTIAL_CP_DEFINE = "anno_potential_cp_define";
public static final String ANNO_CP_DEFINE = "anno_cp_define";
public static final String ANNO_CP_DEFINE_CHECK = "anno_cp_define_check";
+ public static final String ANNO_CP_CLEAR = "anno_cp_clear";
public static final String ANNO_HB_CONDITION = "anno_hb_condition";
// Specification variables
newCode.add("\t"
+ ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
+ SHORT_COMMENT(construct.name));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_name", "\"" + construct.name + "\""));
String anno = "annotation_interface_begin";
newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
String labelNum = Integer.toString(semantics.commitPointLabel2Num
.get(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" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
newCode.add("\t\t"
+ ASSIGN_TO_PTR(anno, "type",
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>();
+ 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" + "}");
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 interfaceNum = getCPInterfaceNum(semantics, construct.label);
+// newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
+// 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_CLEAR));
+ 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 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> generateCPDefine(
SemanticsChecker semantics, CPDefineConstruct construct) {
ArrayList<String> newCode = new ArrayList<String>();
+ STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName));
String labelNum = Integer.toString(semantics.commitPointLabel2Num
.get(construct.label));
+ String interfaceNum = getCPInterfaceNum(semantics, construct.label);
String potentialLabelNum = Integer
.toString(semantics.commitPointLabel2Num
.get(construct.potentialCPLabel));
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, "potential_cp_label_num",
potentialLabelNum));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "potential_label_name", "\"" + construct.potentialCPLabel + "\""));
+ 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));