more fix
authorPeizhao Ou <peizhaoo@uci.edu>
Mon, 17 Mar 2014 21:19:45 +0000 (14:19 -0700)
committerPeizhao Ou <peizhaoo@uci.edu>
Mon, 17 Mar 2014 21:19:45 +0000 (14:19 -0700)
src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java
src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java

index 93dae99..af9bde4 100644 (file)
@@ -254,11 +254,6 @@ public class CodeGenerator {
                // }
 
                // Sort code additions
-               HashSet<String> headers = CodeVariables.getAllHeaders(_semantics);
-               ArrayList<String> headerCode = new ArrayList<String>();
-               for (String header : headers) {
-                       headerCode.add("#include " + header);
-               }
                for (File file : codeAdditions.keySet()) {
                        ArrayList<CodeAddition> additions = codeAdditions.get(file);
 
@@ -269,12 +264,8 @@ public class CodeGenerator {
                        // Insert generated annotation to the source files
                        ArrayList<String> newContent = insertAnnotation2Src(additions,
                                        content);
-                       ArrayList<String> finalContent = new ArrayList<String>(
-                                       headerCode.size() + newContent.size());
-                       finalContent.addAll(headerCode);
-                       finalContent.addAll(newContent);
                        // Write it back to file
-                       ParserUtils.write2File(file, finalContent);
+                       ParserUtils.write2File(file, newContent);
                }
        }
 
index 39ef342..53f40bb 100644 (file)
@@ -581,23 +581,23 @@ public class CodeVariables {
                newCode.add(header.getTemplateFullStr());
                newCode.add(header.getFuncStr() + " {");
                // Wrapper function body
-               newCode.add(COMMENT("Interface begins"));
+               newCode.add("\t" + COMMENT("Interface begins"));
                // Interface begin
                String structName = "interface_begin";
-               newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN,
+               newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN,
                                "interface_begin"));
-               newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+               newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
 
                String anno = "annotation_interface_begin";
-               newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
-               newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN));
-               newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
-               newCode.add(ANNOTATE(semantics, anno));
+               newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+               newCode.add("\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN));
+               newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+               newCode.add("\t" + ANNOTATE(semantics, anno));
                // Call original renamed function
                if (header.returnType.equals("void")) {
-                       newCode.add(header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";");
+                       newCode.add("\t" + header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";");
                } else {
-                       newCode.add(DECLARE_DEFINE(header.returnType, MACRO_RETURN,
+                       newCode.add("\t" + DECLARE_DEFINE(header.returnType, MACRO_RETURN,
                                        header.getRenamedCall(SPEC_INTERFACE_WRAPPER)));
                }
                // HB conditions
@@ -605,32 +605,32 @@ public class CodeVariables {
                        String condition = construct.hbConditions.get(label);
                        String hbCondNum = Integer.toString(semantics.hbLabel2Num
                                        .get(label));
-                       newCode.add("if " + BRACE(condition) + " {");
+                       newCode.add("\t" + "if " + BRACE(condition) + " {");
                        structName = "hb_condition";
-                       newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
-                       newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+                       newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
+                       newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
 
-                       newCode.add(ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum));
+                       newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum));
                        anno = "annotation_hb_condition";
-                       newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
-                       newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
-                       newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
-                       newCode.add(ANNOTATE(semantics, anno));
-                       newCode.add("}");
+                       newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+                       newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
+                       newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+                       newCode.add("\t\t" + ANNOTATE(semantics, anno));
+                       newCode.add("\t" + "}");
                        newCode.add("");
                }
                // Also add the true condition if any
                if (semantics.containsConditionalInterface(new ConditionalInterface(
                                interfaceName, ""))) {
                        structName = "hb_condition";
-                       newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
-                       newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
-                       newCode.add(ASSIGN_TO_PTR(structName, "hb_condition_num", "0"));
+                       newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
+                       newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+                       newCode.add("\t" + ASSIGN_TO_PTR(structName, "hb_condition_num", "0"));
                        anno = "annotation_hb_condition";
-                       newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
-                       newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
-                       newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
-                       newCode.add(ANNOTATE(semantics, anno));
+                       newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+                       newCode.add("\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
+                       newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+                       newCode.add("\t" + ANNOTATE(semantics, anno));
                        newCode.add("");
                }
                // Interface end
@@ -638,31 +638,31 @@ public class CodeVariables {
                if (!header.returnType.equals("void") || header.args.size() > 0) {
                        infoStructType = interfaceName + "_info";
                        infoName = "info";
-                       newCode.add(DECLARE_DEFINE(infoStructType + "*", infoName,
+                       newCode.add("\t" + DECLARE_DEFINE(infoStructType + "*", infoName,
                                        BRACE(infoStructType + "*") + " malloc(sizeof("
                                                        + infoStructType + "))"));
                        if (!header.returnType.equals("void")) {
-                               newCode.add(ASSIGN_TO_PTR(infoName, MACRO_RETURN, MACRO_RETURN));
+                               newCode.add("\t" + ASSIGN_TO_PTR(infoName, MACRO_RETURN, MACRO_RETURN));
                        }
                        for (int i = 0; i < header.args.size(); i++) {
                                String argName = header.args.get(i).name;
-                               newCode.add(ASSIGN_TO_PTR(infoName, argName, argName));
+                               newCode.add("\t" + ASSIGN_TO_PTR(infoName, argName, argName));
                        }
                } else {
                        infoName = "NULL";
                }
                structName = "interface_end";
                anno = "annoation_interface_end";
-               newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName));
-               newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
-               newCode.add(ASSIGN_TO_PTR(structName, "info", infoName));
-               newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
-               newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END));
-               newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
-               newCode.add(ANNOTATE(semantics, anno));
+               newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName));
+               newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+               newCode.add("\t" + ASSIGN_TO_PTR(structName, "info", infoName));
+               newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+               newCode.add("\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END));
+               newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+               newCode.add("\t" + ANNOTATE(semantics, anno));
                // Return __RET__ if it's not void
                if (!header.returnType.equals("void")) {
-                       newCode.add("return " + MACRO_RETURN + ";");
+                       newCode.add("\t" + "return " + MACRO_RETURN + ";");
                }
                // End of the wrapper function
                newCode.add("}");
@@ -746,21 +746,21 @@ public class CodeVariables {
                        addAtomicReturn(semantics, construct);
                }
                // Generate redundant header files
-               newCode.add(COMMENT("Automatically generated code for commit point define check: "
+               newCode.add("\t" + COMMENT("Automatically generated code for commit point define check: "
                                + construct.label));
                newCode.add("");
                // Add annotation
-               newCode.add("if (" + construct.condition + ") {");
+               newCode.add("\t" + "if (" + construct.condition + ") {");
                String structName = "cp_define_check", anno = "annotation_cp_define_check";
-               newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName));
+               newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName));
                String labelNum = Integer.toString(semantics.commitPointLabel2Num
                                .get(construct.label));
-               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("}");
+               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_DEFINE_CHECK));
+               newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+               newCode.add("\t\t" + ANNOTATE(semantics, anno));
+               newCode.add("\t" + "}");
                return newCode;
        }
 
@@ -768,26 +768,26 @@ public class CodeVariables {
                        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: "
+               newCode.add("\t" + COMMENT("Automatically generated code for commit point define: "
                                + construct.label));
                newCode.add("");
                // Add annotation
-               newCode.add("if (" + construct.condition + ") {");
+               newCode.add("\t" + "if (" + construct.condition + ") {");
                String structName = "cp_define", anno = "annotation_cp_define";
-               newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName));
+               newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName));
                String labelNum = Integer.toString(semantics.commitPointLabel2Num
                                .get(construct.label));
                String potentialLabelNum = Integer
                                .toString(semantics.commitPointLabel2Num
                                                .get(construct.potentialCPLabel));
-               newCode.add(ASSIGN_TO_PTR(structName, "label_num", labelNum));
-               newCode.add(ASSIGN_TO_PTR(structName, "potential_cp_label_num",
+               newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
+               newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "potential_cp_label_num",
                                potentialLabelNum));
-               newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
-               newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE));
-               newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
-               newCode.add(ANNOTATE(semantics, anno));
-               newCode.add("}");
+               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));
+               newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+               newCode.add("\t\t" + ANNOTATE(semantics, anno));
+               newCode.add("\t" + "}");
                return newCode;
        }
 }