try to generate in-place code
[cdsspec-compiler.git] / src / edu / uci / eecs / specCompiler / codeGenerator / CodeGenerator.java
index b53b482f582570f7608b388c6fda5e17bba769cc..ab3e7ec9b7b50ba0f5ae2f4a160ed69841a9c305 100644 (file)
@@ -14,6 +14,7 @@ import edu.uci.eecs.specCompiler.specExtraction.Construct;
 import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.SpecConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.SpecExtractor;
 import edu.uci.eecs.specCompiler.specExtraction.SpecNotMatchException;
@@ -94,27 +95,46 @@ public class CodeGenerator {
                GlobalConstruct construct = (GlobalConstruct) inst.construct; 
                ArrayList<String> newCode = new ArrayList<String>();
                
+               // Generate the inner class definition
+               newCode.add("class Sequential {\n");
+               newCode.add("public:\n");
+               
                // Generate the code in global construct first
-               String globalCode = construct.code;
-               int begin = 0, end = 0;
-               while (end < globalCode.length()) {
-                       if (globalCode.charAt(end) == '\n') {
-                               String line = globalCode.substring(begin, end);
-                               newCode.add(line);
-                               begin = end + 1;
-                       }
-                       end++;
-               }
+               SequentialDefineSubConstruct globalCode = construct.code;
+               breakCodeLines(newCode, globalCode.declareVar);
+               breakCodeLines(newCode, globalCode.defineFunc);
                
-               // Generate code from the DefineVar and __COND_SAT__
+               // Generate code from the DefineVar, __COND_SAT__ and __ID__
                
                
+               // Generate the end of the inner class definition
+               newCode.add("};\n");
+//             printCode(newCode);
+               
                CodeAddition addition = new CodeAddition(lineNum, newCode);
                if (!codeAdditions.containsKey(inst.file)) {
                        codeAdditions.put(inst.file, new ArrayList<CodeAddition>());
                }
                codeAdditions.get(inst.file).add(addition);
        }
+       
+       private void breakCodeLines(ArrayList<String> newCode, String code) {
+               int begin = 0, end = 0;
+               while (end < code.length()) {
+                       if (code.charAt(end) == '\n') {
+                               String line = code.substring(begin, end);
+                               newCode.add(line);
+                               begin = end + 1;
+                       }
+                       end++;
+               }
+       }
+       
+       private void printCode(ArrayList<String> code) {
+               for (int i = 0; i < code.size(); i++) {
+                       System.out.println(code.get(i));
+               }
+       }
 
        private void interface2Code(SpecConstruct inst) {
                int lineNum = inst.endLineNum + 1;