String idCode) {
ArrayList<String> code = new ArrayList<String>();
code.add("static " + IDType + " " + interfaceName + "_id() {");
- if (idCode != null) {
+ if (!idCode.equals("")) {
code.add(DECLARE_DEFINE(IDType, MACRO_ID, idCode));
} else {
code.add(DECLARE_DEFINE(IDType, MACRO_ID, DEFAULT_ID));
InterfaceConstruct construct, FunctionHeader header) {
String interfaceName = construct.name;
ArrayList<String> code = new ArrayList<String>();
- code.add("bool " + interfaceName + "_check_action(void *info, "
+ code.add("static bool " + interfaceName + "_check_action(void *info, "
+ IDType + " " + MACRO_ID + ") {");
code.add(DECLARE("bool", "check_passed"));
String infoStructType = interfaceName + "_info", infoStructName = "theInfo";
}
code.add("");
// __COND_SAT
- code.add(DECLARE_DEFINE("bool", MACRO_COND, construct.condition));
+ if (!construct.condition.equals("")) {
+ code.add(DECLARE_DEFINE("bool", MACRO_COND, construct.condition));
+ }
// Check
- code.add(ASSIGN("check_passed", construct.check));
- code.add("if (!check_passed) return false;");
+ if (!construct.check.equals("")) {
+ code.add(ASSIGN("check_passed", construct.check));
+ code.add("if (!check_passed) return false;");
+ }
// Action
- code.addAll(construct.action);
+ if (construct.action.size() > 0) {
+ code.addAll(construct.action);
+ }
// Post_check
- code.add(ASSIGN("check_passed", construct.postCheck));
- code.add("if (!check_passed) return false;");
+ if (!construct.postCheck.equals("")) {
+ code.add(ASSIGN("check_passed", construct.postCheck));
+ code.add("if (!check_passed) return false;");
+ }
// Post_action
- code.addAll(construct.postAction);
+ if (construct.postAction.size() > 0) {
+ code.addAll(construct.postAction);
+ }
+
code.add("}");
return code;
funcDefine.set(0, headLine);
}
- private static void makeVariablesStatic(ArrayList<String> varDecls) {
- for (int i = 0; i < varDecls.size(); i++) {
- String varDecl = varDecls.get(i);
- varDecl = "static " + varDecl;
- varDecls.set(i, varDecl);
- }
+ private static String makeVariablesStatic(VariableDeclaration varDecl) {
+ String res = "static " + varDecl.type + " " + varDecl.name + ";";
+ return res;
}
private static FunctionHeader getFunctionHeader(SemanticsChecker semantics,
if (headerLine.startsWith("template")) {
headerLine = content.get(construct.beginLineNum + 1);
}
+ headerLine = headerLine.substring(0, headerLine.indexOf(')') + 1);
try {
return SpecParser.parseFuncHeader(headerLine);
} catch (ParseException e) {
HashSet<String> allHeaders = getAllHeaders(semantics);
// All headers needed by the interface decalration
- newCode.add(COMMENT("/* Include all the header files that contains the interface declaration */"));
+ newCode.add(COMMENT("Include all the header files that contains the interface declaration"));
for (String header : allHeaders) {
newCode.add(INCLUDE(header));
}
newCode.add("");
SequentialDefineSubConstruct code = construct.code;
+ // User-defined structs first
+ newCode.add(COMMENT("All other user-defined structs"));
+ ArrayList<ArrayList<String>> declareStructs = code.declareStructs;
+ for (int i = 0; i < declareStructs.size(); i++) {
+ ArrayList<String> declareStruct = declareStructs.get(i);
+ newCode.addAll(declareStruct);
+ newCode.add("");
+ }
// User-defined functions
newCode.add(COMMENT("All other user-defined functions"));
ArrayList<ArrayList<String>> defineFuncs = code.defineFuncs;
ArrayList<VariableDeclaration> varDecls = code.declareVar;
for (int i = 0; i < varDecls.size(); i++) {
VariableDeclaration varDecl = varDecls.get(i);
- newCode.add(DECLARE(varDecl.type, varDecl.name));
+ // Don't forget to make them static
+ newCode.add(makeVariablesStatic(varDecl));
}
newCode.add("");
newCode.add("}");
newCode.add(COMMENT("End of Global construct generation in class"));
- // printCode(newCode);
+ printCode(newCode);
return newCode;
}
return newCode;
}
+ public static ArrayList<String> generateEntryPointInitCall() {
+ ArrayList<String> newCode = new ArrayList<String>(1);
+ newCode.add("__sequential_init();");
+ return newCode;
+ }
+
public static ArrayList<String> generateInterfaceWrapper(
SemanticsChecker semantics, InterfaceConstruct construct) {
ArrayList<String> newCode = new ArrayList<String>();
.get(construct.name));
// Rename the interface
renameInterface(semantics, construct);
- InterfaceDefineConstruct defineConstruct = semantics.interfaceName2DefineConstruct.get(interfaceName);
+ InterfaceDefineConstruct defineConstruct = semantics.interfaceName2DefineConstruct
+ .get(interfaceName);
if (defineConstruct != null) {
renameInterface(semantics, defineConstruct);
}
-
+
// Generate wrapper header
newCode.add(header.toString() + " {");
// Wrapper function body
newCode.add("}");
return newCode;
}
-
+
public static ArrayList<String> generateCPDefineCheck(
SemanticsChecker semantics, CPDefineCheckConstruct construct) {
ArrayList<String> newCode = new ArrayList<String>();
newCode.add("}");
return newCode;
}
-
+
public static ArrayList<String> generateCPDefine(
SemanticsChecker semantics, CPDefineConstruct construct) {
ArrayList<String> newCode = new ArrayList<String>();