allow shorter spec --- @Interface is not mandatory
[cdsspec-compiler.git] / src / edu / uci / eecs / codeGenerator / CodeGeneratorUtils.java
index 99c4f2e17ca038260ad55f0e10ff0a6c01c44cea..4100a0a3d5acddb338b9b1ee87605d63ac5e3a63 100644 (file)
@@ -197,9 +197,10 @@ public class CodeGeneratorUtils {
                        for (InterfaceConstruct construct : list) {
                                // Declare custom value struct for the interface
                                String name = construct.getName();
+                               String structName = construct.getStructName();
                                code.addLine(ShortComment("Declare custom value struct for "
                                                + name));
-                               code.addLine("typedef struct " + name + " {");
+                               code.addLine("typedef struct " + structName + " {");
                                FunctionHeader funcHeader = construct.getFunctionHeader();
                                // RET
                                if (!funcHeader.returnType.equals("void"))
@@ -209,7 +210,7 @@ public class CodeGeneratorUtils {
                                for (VariableDeclaration decl : funcHeader.args) {
                                        code.addLine(TabbedLine(Declare(decl)));
                                }
-                               code.addLine("} " + name + ";");
+                               code.addLine("} " + structName + ";");
                                code.addLine("");
                        }
                }
@@ -498,11 +499,15 @@ public class CodeGeneratorUtils {
                                        + SpecNaming.AppendStr(rule.method2) + ") {"));
                        // Initialize M1 & M2 in commutativity rule
                        // e.g. ENQ *M1 = (ENQ*) m1->value;
+                       String structName1 = InterfaceConstruct
+                                       .createStructName(rule.method1);
+                       String structName2 = InterfaceConstruct
+                                       .createStructName(rule.method2);
                        code.addLine(TabbedLine(
-                                       DeclareDefine(rule.method1, "*M1", "(" + rule.method1
+                                       DeclareDefine(structName1, "*M1", "(" + structName1
                                                        + "*) m1->value"), 2));
                        code.addLine(TabbedLine(
-                                       DeclareDefine(rule.method2, "*M2", "(" + rule.method2
+                                       DeclareDefine(structName2, "*M2", "(" + structName2
                                                        + "*) m2->value"), 2));
                        code.addLine(TabbedLine("return " + rule.condition + ";", 2));
                        code.addLine(TabbedLine("}"));
@@ -520,6 +525,7 @@ public class CodeGeneratorUtils {
 
                                // Define interface functions
                                String name = construct.getName();
+                               String structName = construct.getStructName();
                                code.addLine("/**********    " + name
                                                + " functions    **********/");
                                // Define @Transition for INTERFACE
@@ -861,10 +867,11 @@ public class CodeGeneratorUtils {
                        String inst, InterfaceConstruct construct) {
                Code res = new Code();
                String name = construct.getName();
+               String structName = construct.getStructName();
                res.addLine(ShortComment("Initialize fields for " + name));
                // The very first assignment "
-               res.addLine(DeclareDefine(name, "*" + inst, "(" + name + "*) "
-                               + methodInst + "->" + SpecNaming.MethodValueField));
+               res.addLine(DeclareDefine(structName, "*" + inst, "(" + structName
+                               + "*) " + methodInst + "->" + SpecNaming.MethodValueField));
                // Don't leave out the RET field
                if (!construct.getFunctionHeader().isReturnVoid()) {
                        res.addLine(DeclareDefine(construct.getFunctionHeader().returnType,
@@ -975,6 +982,7 @@ public class CodeGeneratorUtils {
                Code code = new Code();
 
                String name = construct.getName();
+               String structName = construct.getStructName();
                String beginLine = construct.getFunctionHeader().getHeaderLine();
                Pattern regexpSpace = Pattern.compile("^(\\s*)\\S.*$");
                Matcher matcherSpace = regexpSpace.matcher(beginLine);
@@ -1017,8 +1025,9 @@ public class CodeGeneratorUtils {
                // The very first assignment "
                code.addLine(prefixTabs
                                + "\t"
-                               + DeclareDefine(name, "*" + SpecNaming.InterfaceValueInst,
-                                               SpecNaming.New + Brace(name)));
+                               + DeclareDefine(structName,
+                                               "*" + SpecNaming.InterfaceValueInst, SpecNaming.New
+                                                               + Brace(structName)));
                // Don't leave out the RET field
                if (!construct.getFunctionHeader().isReturnVoid())
                        code.addLine(prefixTabs