bb572c18b5ef6eafb285b1982e529f21f9a20bbe
[cdsspec-compiler.git] / src / edu / uci / eecs / specCompiler / codeGenerator / CodeVariables.java
1 package edu.uci.eecs.specCompiler.codeGenerator;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.HashSet;
6 import java.io.File;
7
8 import edu.uci.eecs.specCompiler.grammerParser.utilParser.UtilParser;
9 import edu.uci.eecs.specCompiler.grammerParser.utilParser.ParseException;
10 import edu.uci.eecs.specCompiler.specExtraction.CPClearConstruct;
11 import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
12 import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct;
13 import edu.uci.eecs.specCompiler.specExtraction.CommutativityRule;
14 import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
15 import edu.uci.eecs.specCompiler.specExtraction.Construct;
16 import edu.uci.eecs.specCompiler.specExtraction.FunctionHeader;
17 import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
18 import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct;
19 import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct;
20 import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
21 import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
22 import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
23
24 /**
25  * <p>
26  * Defines a list of commonly used constant strings.
27  * </p>
28  * 
29  * @author peizhaoo
30  * 
31  */
32 public class CodeVariables {
33         // C++ code or library
34         public static final String HEADER_STDLIB = "<stdlib.h>";
35         public static final String HEADER_THREADS = "<threads.h>";
36         public static final String HEADER_STDINT = "<stdint.h>";
37         public static final String HEADER_MODELMEMORY = "<model_memory.h>";
38         public static final String HEADER_MODELTYPES = "<modeltypes.h>";
39         public static final String ThreadIDType = "thread_id_t";
40         public static final String BOOLEAN = "bool";
41         public static final String UINT64 = "uint64_t";
42
43         // Model checker code
44         public static final String HEADER_CDSANNOTATE = "<cdsannotate.h>";
45         public static final String HEADER_COMMON = "<common.h>";
46         public static final String HEADER_SPECANNOTATION = "<specannotation.h>";
47         public static final String HEADER_CDSTRACE = "<cdstrace.h>";
48         public static final String CDSAnnotate = "cdsannotate";
49         // public static final String CDSAnnotate = "cdsannotate";
50         public static final String CDSAnnotateType = "SPEC_ANALYSIS";
51         public static final String IDType = "call_id_t";
52
53         public static final String SPEC_ANNO_TYPE = "spec_anno_type";
54         public static final String SPEC_ANNO_TYPE_INIT = "INIT";
55         public static final String SPEC_ANNO_TYPE_HB_INIT = "HB_INIT";
56         public static final String SPEC_ANNO_TYPE_INTERFACE_BEGIN = "INTERFACE_BEGIN";
57         public static final String SPEC_ANNO_TYPE_HB_CONDITION = "HB_CONDITION";
58         public static final String SPEC_ANNO_TYPE_INTERFACE_END = "INTERFACE_END";
59         public static final String SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE = "POTENTIAL_CP_DEFINE";
60         public static final String SPEC_ANNO_TYPE_CP_DEFINE_CHECK = "CP_DEFINE_CHECK";
61         public static final String SPEC_ANNO_TYPE_CP_CLEAR = "CP_CLEAR";
62         public static final String SPEC_ANNO_TYPE_CP_DEFINE = "CP_DEFINE";
63         public static final String SPEC_ANNOTATION = "spec_annotation";
64         public static final String SPEC_ANNOTATION_FIELD_TYPE = "type";
65         public static final String SPEC_ANNOTATION_FIELD_ANNO = "annotation";
66
67         public static final String ANNO_INIT = "anno_init";
68         public static final String ANNO_HB_INIT = "anno_hb_init";
69         public static final String ANNO_COMMUTATIVITY_RULE = "anno_commutativity_rule";
70         public static final String ANNO_INTERFACE_BEGIN = "anno_interface_begin";
71         public static final String ANNO_INTERFACE_END = "anno_interface_end";
72         public static final String ANNO_POTENTIAL_CP_DEFINE = "anno_potential_cp_define";
73         public static final String ANNO_CP_DEFINE = "anno_cp_define";
74         public static final String ANNO_CP_DEFINE_CHECK = "anno_cp_define_check";
75         public static final String ANNO_CP_CLEAR = "anno_cp_clear";
76         public static final String ANNO_HB_CONDITION = "anno_hb_condition";
77
78         // Specification variables
79         public static final String SPEC_INTERFACE_WRAPPER = "__wrapper_";
80         public static final String DEFAULT_ID = "0";
81
82         // Specification library
83         public static final String HEADER_SPEC_LIB = "<spec_lib.h>";
84         public static final String SPEC_QUEUE = "spec_queue";
85         public static final String SPEC_STACK = "spec_stack";
86         public static final String SPEC_DEQUE = "spec_deque";
87         public static final String SPEC_HASHTABLE = "spec_hashtable";
88         public static final String SPEC_PRIVATE_HASHTABLE = "spec_private_hashtable";
89         public static final String SPEC_TAG = "spec_tag";
90         public static final String SPEC_TAG_CURRENT = "current";
91         public static final String SPEC_TAG_NEXT = "next";
92
93         // Macro
94         public static final String MACRO_ID = "__ID__";
95         public static final String MACRO_COND = "__COND_SAT__";
96         public static final String MACRO_RETURN = "__RET__";
97         public static final String MACRO_ATOMIC_RETURN = "__ATOMIC_RET__";
98         public static final String MACRO_THREAD_ID = "__TID__";
99
100         public static void printCode(ArrayList<String> code) {
101                 for (int i = 0; i < code.size(); i++) {
102                         System.out.println(code.get(i));
103                 }
104         }
105
106         private static String COMMENT(String comment) {
107                 return "/* " + comment + " */";
108         }
109
110         private static String SHORT_COMMENT(String comment) {
111                 return " // " + comment;
112         }
113
114         private static String INCLUDE(String header) {
115                 return "#include " + header;
116         }
117
118         private static String DEFINE(String left, String right) {
119                 return "#define " + left + " " + right;
120         }
121
122         private static String UNDEFINE(String macro) {
123                 return "#undef " + macro;
124         }
125
126         private static String GET_FIELD_BY_PTR(String ptr, String field) {
127                 return ptr + "->" + field;
128         }
129
130         private static String GET_FIELD(String var, String field) {
131                 return var + "->" + field;
132         }
133
134         private static String BRACE(String val) {
135                 return "(" + val + ")";
136         }
137
138         private static String ASSIGN(String structName, String field, String val) {
139                 return structName + "." + field + " = " + val + ";";
140         }
141
142         private static String ASSIGN(String varName, String val) {
143                 return varName + " = " + val + ";";
144         }
145
146         private static String ASSIGN_PTR(String structName, String field, String val) {
147                 return structName + "." + field + " = &" + val + ";";
148         }
149
150         private static String ASSIGN_TO_PTR(String structName, String field,
151                         String val) {
152                 return structName + "->" + field + " = " + val + ";";
153         }
154
155         private static String ASSIGN_PTR_TO_PTR(String structName, String field,
156                         String val) {
157                 return structName + "->" + field + " = &" + val + ";";
158         }
159
160         private static String STRUCT_NEW_DECLARE_DEFINE(String type, String name) {
161                 return "struct " + type + " *" + name + " = (struct " + type
162                                 + "*) malloc(sizeof(struct " + type + "));";
163         }
164
165         private static String DECLARE(String type, String name) {
166                 return type + " " + name + ";";
167         }
168
169         private static String DECLARE(VariableDeclaration varDecl) {
170                 String type = varDecl.type, name = varDecl.name;
171                 return type + " " + name + ";";
172         }
173
174         private static String DECLARE_DEFINE(String type, String var, String val) {
175                 return type + " " + var + " = " + val + ";";
176         }
177
178         private static String ANNOTATE(SemanticsChecker semantics, String structName) {
179                 return CDSAnnotate + "(" + CDSAnnotateType + ", " + structName + ");";
180         }
181
182         private static ArrayList<String> DEFINE_INFO_STRUCT(String interfaceName,
183                         FunctionHeader header) {
184                 ArrayList<String> code = new ArrayList<String>();
185                 code.add("typedef struct " + interfaceName + "_info {");
186                 if (!header.returnType.equals("void")) {
187                         code.add(DECLARE(header.returnType, MACRO_RETURN));
188                 }
189                 for (int i = 0; i < header.args.size(); i++) {
190                         code.add(DECLARE(header.args.get(i)));
191                 }
192                 code.add("} " + interfaceName + "_info;");
193                 return code;
194         }
195
196         private static ArrayList<String> DEFINE_ID_FUNC(
197                         InterfaceConstruct construct, FunctionHeader header) {
198                 String interfaceName = construct.name;
199                 ArrayList<String> code = new ArrayList<String>();
200                 String idCode = construct.idCode;
201                 code.add("inline static " + IDType + " " + interfaceName + "_id("
202                                 + "void *info, " + ThreadIDType + " " + MACRO_THREAD_ID + ") {");
203
204                 // Read info struct
205                 if (!header.returnType.equals("void") || header.args.size() != 0) {
206                         String infoStructType = interfaceName + "_info", infoStructName = "theInfo";
207                         code.add(DECLARE_DEFINE("\t" + infoStructType + "*",
208                                         infoStructName, BRACE(infoStructType + "*") + "info"));
209                         if (!header.returnType.equals("void")) {
210                                 code.add((DECLARE_DEFINE("\t" + header.returnType,
211                                                 MACRO_RETURN,
212                                                 GET_FIELD_BY_PTR(infoStructName, MACRO_RETURN))));
213                         }
214                         for (int i = 0; i < header.args.size(); i++) {
215                                 String type = header.args.get(i).type, var = header.args.get(i).name;
216                                 code.add("\t"
217                                                 + (DECLARE_DEFINE(type, var,
218                                                                 GET_FIELD_BY_PTR(infoStructName, var))));
219                         }
220                         code.add("");
221                 }
222
223                 if (!idCode.equals("")) {
224                         code.add("\t" + DECLARE_DEFINE(IDType, MACRO_ID, idCode));
225                 } else {
226                         code.add("\t" + DECLARE_DEFINE(IDType, MACRO_ID, DEFAULT_ID));
227                 }
228                 code.add("\treturn " + MACRO_ID + ";");
229                 code.add("}");
230                 return code;
231         }
232
233         private static ArrayList<String> DEFINE_CHECK_ACTION_FUNC(
234                         InterfaceConstruct construct, FunctionHeader header) {
235                 String interfaceName = construct.name;
236                 ArrayList<String> code = new ArrayList<String>();
237                 code.add("inline static bool " + interfaceName
238                                 + "_check_action(void *info, " + IDType + " " + MACRO_ID + ", "
239                                 + ThreadIDType + " " + MACRO_THREAD_ID + ") {");
240                 code.add("\t" + DECLARE("bool", "check_passed"));
241                 // Read info struct
242                 if (!header.returnType.equals("void") || header.args.size() != 0) {
243                         String infoStructType = interfaceName + "_info", infoStructName = "theInfo";
244                         code.add("\t"
245                                         + DECLARE_DEFINE(infoStructType + "*", infoStructName,
246                                                         BRACE(infoStructType + "*") + "info"));
247                         if (!header.returnType.equals("void")) {
248                                 code.add("\t"
249                                                 + (DECLARE_DEFINE(header.returnType, MACRO_RETURN,
250                                                                 GET_FIELD_BY_PTR(infoStructName, MACRO_RETURN))));
251                         }
252                         for (int i = 0; i < header.args.size(); i++) {
253                                 String type = header.args.get(i).type, var = header.args.get(i).name;
254                                 code.add("\t"
255                                                 + (DECLARE_DEFINE(type, var,
256                                                                 GET_FIELD_BY_PTR(infoStructName, var))));
257                         }
258                         code.add("");
259                 }
260                 // __COND_SAT
261                 if (!construct.condition.equals("")) {
262                         code.add("\t"
263                                         + DECLARE_DEFINE("bool", MACRO_COND, construct.condition));
264                 }
265                 // Check
266                 if (!construct.check.equals("")) {
267                         code.add("\t" + ASSIGN("check_passed", construct.check));
268                         code.add("\tif (!check_passed)");
269                         code.add("\t\treturn false;");
270
271                 }
272                 // Action
273                 if (construct.action.size() > 0) {
274                         addAllCodeWithIndent(code, construct.action, "\t");
275                 }
276                 // Post_check
277                 if (!construct.postCheck.equals("")) {
278                         code.add("\t" + ASSIGN("check_passed", construct.postCheck));
279                         code.add("\tif (!check_passed)");
280                         code.add("\t\treturn false;");
281                 }
282                 // Post_action
283                 if (construct.postAction.size() > 0) {
284                         addAllCodeWithIndent(code, construct.postAction, "\t");
285                 }
286                 // Return true finally
287                 code.add("\treturn true;");
288
289                 code.add("}");
290
291                 return code;
292         }
293
294         private static void addAllCodeWithIndent(ArrayList<String> allCode,
295                         ArrayList<String> target, String indent) {
296                 for (int i = 0; i < target.size(); i++) {
297                         allCode.add(indent + target.get(i));
298                 }
299         }
300
301         public static HashSet<String> getAllHeaders(SemanticsChecker semantics) {
302                 HashSet<String> headers = new HashSet<String>();
303                 for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
304                         File f = semantics.interfaceName2Construct.get(interfaceName).file;
305                         headers.addAll(semantics.srcFilesInfo.get(f).headers);
306                 }
307                 headers.add(HEADER_STDLIB);
308                 headers.add(HEADER_STDINT);
309                 headers.add(HEADER_MODELMEMORY);
310                 headers.add(HEADER_MODELTYPES);
311                 headers.add(HEADER_SPEC_LIB);
312                 headers.add(HEADER_STDINT);
313                 headers.add(HEADER_CDSANNOTATE);
314                 // headers.add(HEADER_COMMON);
315                 headers.add(HEADER_SPECANNOTATION);
316                 return headers;
317         }
318
319         private static void makeFunctionStatic(ArrayList<String> funcDefine) {
320                 String headLine = funcDefine.get(0);
321                 headLine = "inline static " + headLine;
322                 funcDefine.set(0, headLine);
323         }
324
325         private static String makeVariablesStatic(VariableDeclaration varDecl) {
326                 String res = "static " + varDecl.type + " " + varDecl.name + ";";
327                 return res;
328         }
329
330         private static FunctionHeader getFunctionHeader(SemanticsChecker semantics,
331                         Construct construct) {
332                 ArrayList<String> content = semantics.srcFilesInfo.get(construct.file).content;
333                 String headerLine = content.get(construct.beginLineNum + 1), templateLine = null;
334                 if (headerLine.startsWith("template")) {
335                         templateLine = headerLine;
336                         headerLine = content.get(construct.beginLineNum + 2);
337                 }
338                 headerLine = headerLine.substring(0, headerLine.indexOf(')') + 1);
339                 try {
340                         FunctionHeader header = UtilParser.parseFuncHeader(headerLine);
341                         if (templateLine != null) {
342                                 ArrayList<VariableDeclaration> templateArgs = UtilParser
343                                                 .getTemplateArg(templateLine);
344                                 header.setTemplateList(templateArgs);
345                         }
346                         return header;
347                 } catch (ParseException e) {
348                         e.printStackTrace();
349                 }
350                 return null;
351         }
352
353         public static ArrayList<String> generateGlobalVarDeclaration(
354                         SemanticsChecker semantics, GlobalConstruct construct) {
355                 ArrayList<String> newCode = new ArrayList<String>();
356                 HashSet<String> allHeaders = getAllHeaders(semantics);
357
358                 SequentialDefineSubConstruct code = construct.code;
359                 // User-defined structs first
360                 newCode.add(COMMENT("All other user-defined structs"));
361                 ArrayList<ArrayList<String>> declareStructs = code.declareStructs;
362                 for (int i = 0; i < declareStructs.size(); i++) {
363                         ArrayList<String> declareStruct = declareStructs.get(i);
364                         newCode.addAll(declareStruct);
365                         newCode.add("");
366                 }
367                 // User-defined variables
368                 ArrayList<VariableDeclaration> varDecls = code.declareVar;
369                 for (int i = 0; i < varDecls.size(); i++) {
370                         VariableDeclaration varDecl = varDecls.get(i);
371                         // Don't forget to make them static
372                         newCode.add(makeVariablesStatic(varDecl));
373                 }
374                 // User-defined functions
375                 newCode.add(COMMENT("All other user-defined functions"));
376                 ArrayList<ArrayList<String>> defineFuncs = code.defineFuncs;
377                 for (int i = 0; i < defineFuncs.size(); i++) {
378                         ArrayList<String> defineFunc = defineFuncs.get(i);
379                         makeFunctionStatic(defineFunc);
380                         newCode.addAll(defineFunc);
381                         newCode.add("");
382                 }
383
384                 for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
385                         InterfaceConstruct iConstruct = semantics.interfaceName2Construct
386                                         .get(interfaceName);
387                         FunctionHeader funcHeader = getFunctionHeader(semantics, iConstruct);
388                         // Define necessary info structure
389                         if (!funcHeader.returnType.equals("void")
390                                         || funcHeader.args.size() > 0) {
391                                 newCode.add(COMMENT("Definition of interface info struct: "
392                                                 + interfaceName));
393                                 newCode.addAll(DEFINE_INFO_STRUCT(interfaceName, funcHeader));
394                                 newCode.add(COMMENT("End of info struct definition: "
395                                                 + interfaceName));
396                                 newCode.add("");
397                         }
398
399                         // Define ID function
400                         newCode.add(COMMENT("ID function of interface: " + interfaceName));
401                         newCode.addAll(DEFINE_ID_FUNC(iConstruct, funcHeader));
402                         newCode.add(COMMENT("End of ID function: " + interfaceName));
403                         newCode.add("");
404
405                         // Define check_action function
406                         newCode.add(COMMENT("Check action function of interface: "
407                                         + interfaceName));
408                         newCode.addAll(DEFINE_CHECK_ACTION_FUNC(iConstruct, funcHeader));
409                         newCode.add(COMMENT("End of check action function: "
410                                         + interfaceName));
411                         newCode.add("");
412                 }
413                 // Interface function pointer table
414                 String interfaceSize = Integer
415                                 .toString(semantics.interfaceName2Construct.size());
416                 newCode.add(DEFINE("INTERFACE_SIZE", interfaceSize));
417                 // Make it static
418                 newCode.add("static " + DECLARE("void**", "func_ptr_table"));
419                 // Happens-before initialization rules
420                 // Should make it static
421                 newCode.add("static " + DECLARE(ANNO_HB_INIT + "**", "hb_init_table"));
422                 
423                 // Declare the Commutativity Rule table
424                 newCode.add("static " + DECLARE(ANNO_COMMUTATIVITY_RULE + "**", "commutativity_rule_table"));
425                 // Define the Commutativity Rule condition functions
426                 ArrayList<CommutativityRule> rules = semantics.getGlobalConstruct().commutativityRules;
427                 for (int i = 0; i < rules.size(); i++) {
428                         CommutativityRule rule = rules.get(i);
429                         String infoStructType1 = rule.method1 + "_info";
430                         String infoStructType2 = rule.method2 + "_info";
431                         String condition = rule.condition;
432                         
433                         // Declare
434                         
435                         // Replace the "_M1." and "_M2." with the actual info struct
436                         condition.replaceAll("_M1\\.", infoStructType1 + "->");
437                         condition.replaceAll("_M2\\.", infoStructType2 + "->");
438                         
439                         // Cast the "void*" type to the actual info type
440                         
441                         newCode.add(e)
442                 }
443                 
444
445                 newCode.add("");
446                 
447                 // Beginning initialization
448                 // Define the __SPEC_INIT__ function to initialize user-defined
449                 // variables
450                 newCode.add(COMMENT("Initialization of sequential varialbes"));
451                 newCode.add("static void __SPEC_INIT__() {");
452                 addAllCodeWithIndent(newCode, construct.code.initVar, "\t");
453                 newCode.add("}");
454                 newCode.add("");
455
456                 // Define the __SPEC_CLEAN__ function for clean-up
457                 newCode.add(COMMENT("Cleanup routine of sequential variables"));
458                 newCode.add("static void __SPEC_CLEANUP__() {");
459                 addAllCodeWithIndent(newCode, construct.code.cleanupCode, "\t");
460                 newCode.add("}");
461                 newCode.add("");
462                 
463                 newCode.add(COMMENT("Define function for sequential code initialization"));
464                 newCode.add("inline static void __sequential_init() {");
465                 
466                 // Init func_ptr_table
467                 newCode.add("\t" + COMMENT("Init func_ptr_table"));
468                 newCode.add("\t"
469                                 + ASSIGN("func_ptr_table", "(void**) malloc(sizeof(void*) * "
470                                                 + semantics.interface2Num.size() + " * 2)"));
471                 for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
472                         String interfaceNum = Integer.toString(semantics.interface2Num
473                                         .get(interfaceName));
474                         newCode.add("\t"
475                                         + ASSIGN("func_ptr_table[2 * " + interfaceNum + "]",
476                                                         "(void*) &" + interfaceName + "_id"));
477                         newCode.add("\t"
478                                         + ASSIGN("func_ptr_table[2 * " + interfaceNum + " + 1]",
479                                                         "(void*) &" + interfaceName + "_check_action"));
480                 }
481                 
482                 // Init Commutativity rules table
483                 
484                 
485                 // Init Happens-before rules table
486                 newCode.addAll(generateHBInitAnnotation(semantics));
487                 
488                 // Init Commutativity rules table
489                 newCode.addAll(generateCommutativityAnnotation(semantics));
490
491                 // Pass init info, including function table info & HB rules
492                 newCode.add("\t"
493                                 + COMMENT("Pass init info, including function table info & HB rules & Commutativity Rules"));
494                 String structName = "anno_init", anno = "init";
495                 newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INIT, structName));
496                 newCode.add("\t"
497                                 + ASSIGN_TO_PTR(structName, "init_func", "(void*) __SPEC_INIT__"));
498                 newCode.add("\t"
499                                 + ASSIGN_TO_PTR(structName, "cleanup_func", "(void*) __SPEC_CLEANUP__"));
500                 newCode.add("\t"
501                                 + ASSIGN_TO_PTR(structName, "func_table", "func_ptr_table"));
502                 newCode.add("\t"
503                                 + ASSIGN_TO_PTR(structName, "func_table_size", "INTERFACE_SIZE"));
504                 newCode.add("\t"
505                                 + ASSIGN_TO_PTR(structName, "hb_init_table", "hb_init_table"));
506                 newCode.add("\t"
507                                 + ASSIGN_TO_PTR(structName, "hb_init_table_size",
508                                                 "HB_INIT_TABLE_SIZE"));
509                 
510                 newCode.add("\t"
511                                 + ASSIGN_TO_PTR(structName, "commutativity_rule_table", "hb_init_table"));
512                 newCode.add("\t"
513                                 + ASSIGN_TO_PTR(structName, "hb_init_table_size",
514                                                 "HB_INIT_TABLE_SIZE"));
515                 
516                 newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
517                 newCode.add("\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INIT));
518                 newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
519                 newCode.add("\t" + ANNOTATE(semantics, anno));
520
521                 newCode.add("");
522                 newCode.add("}");
523                 newCode.add("");
524
525                 newCode.add(COMMENT("End of Global construct generation in class"));
526
527                 // printCode(newCode);
528                 return newCode;
529         }
530
531         public static ArrayList<String> generateStaticVarDefine(
532                         SemanticsChecker semantics, GlobalConstruct construct) {
533                 ArrayList<String> newCode = new ArrayList<String>();
534                 String className = semantics.getClassName();
535                 if (className == null)
536                         return newCode; // No need to define any static variables
537                 String templateList = semantics.getTemplateStr();
538                 String varPrefix;
539                 if (templateList == null) {
540                         varPrefix = className + "::";
541                 } else {
542                         varPrefix = className + templateList + "::";
543                 }
544                 String templateDecl = semantics.getTemplateFullStr();
545                 if (templateList == null) {
546                         newCode.add(DECLARE("void**", varPrefix + "func_ptr_table"));
547                         newCode.add(DECLARE("anno_hb_init**", varPrefix + "hb_init_table"));
548                         for (int i = 0; i < construct.code.declareVar.size(); i++) {
549                                 VariableDeclaration varDecl = construct.code.declareVar.get(i);
550                                 newCode.add(DECLARE(varDecl.type, varPrefix + varDecl.name));
551                         }
552                 } else {
553                         newCode.add(templateDecl);
554                         newCode.add(DECLARE("void**", varPrefix + "func_ptr_table"));
555                         newCode.add(templateDecl);
556                         newCode.add(DECLARE("anno_hb_init**", varPrefix + "hb_init_table"));
557                         for (int i = 0; i < construct.code.declareVar.size(); i++) {
558                                 VariableDeclaration varDecl = construct.code.declareVar.get(i);
559                                 newCode.add(templateDecl);
560                                 newCode.add(DECLARE(varDecl.type, varPrefix + varDecl.name));
561                         }
562                 }
563                 return newCode;
564         }
565
566         private static ArrayList<String> generateHBInitAnnotation(
567                         SemanticsChecker semantics) {
568                 ArrayList<String> newCode = new ArrayList<String>();
569
570                 int hbConditionInitIdx = 0;
571                 for (ConditionalInterface left : semantics.getHBConditions().keySet()) {
572                         for (ConditionalInterface right : semantics.getHBConditions().get(
573                                         left)) {
574                                 String structVarName = "hbConditionInit" + hbConditionInitIdx;
575                                 // String annotationVarName = "hb_init" + hbConditionInitIdx;
576                                 hbConditionInitIdx++;
577                                 String interfaceNumBefore = Integer
578                                                 .toString(semantics.interface2Num
579                                                                 .get(left.interfaceName)), hbLabelNumBefore = Integer
580                                                 .toString(semantics.hbLabel2Num
581                                                                 .get(left.hbConditionLabel)), interfaceNumAfter = Integer
582                                                 .toString(semantics.interface2Num
583                                                                 .get(right.interfaceName)), hbLabelNumAfter = Integer
584                                                 .toString(semantics.hbLabel2Num
585                                                                 .get(right.hbConditionLabel));
586                                 newCode.add("\t" + COMMENT(left + " -> " + right));
587
588                                 newCode.add("\t"
589                                                 + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_INIT, structVarName));
590                                 newCode.add("\t"
591                                                 + ASSIGN_TO_PTR(structVarName, "interface_num_before",
592                                                                 interfaceNumBefore)
593                                                 + SHORT_COMMENT(left.interfaceName));
594                                 newCode.add("\t"
595                                                 + ASSIGN_TO_PTR(structVarName,
596                                                                 "hb_condition_num_before", hbLabelNumBefore)
597                                                 + SHORT_COMMENT(left.hbConditionLabel));
598                                 newCode.add("\t"
599                                                 + ASSIGN_TO_PTR(structVarName, "interface_num_after",
600                                                                 interfaceNumAfter)
601                                                 + SHORT_COMMENT(right.interfaceName));
602                                 newCode.add("\t"
603                                                 + ASSIGN_TO_PTR(structVarName,
604                                                                 "hb_condition_num_after", hbLabelNumAfter)
605                                                 + SHORT_COMMENT(right.hbConditionLabel));
606                         }
607                 }
608                 // Init hb_init_table
609                 newCode.add("\t" + COMMENT("Init hb_init_table"));
610                 newCode.add("\t"
611                                 + ASSIGN("hb_init_table", "(" + ANNO_HB_INIT
612                                                 + "**) malloc(sizeof(" + ANNO_HB_INIT + "*) * "
613                                                 + hbConditionInitIdx + ")"));
614                 // Define HB_INIT_TABLE_SIZE
615                 newCode.add("\t"
616                                 + DEFINE("HB_INIT_TABLE_SIZE",
617                                                 Integer.toString(hbConditionInitIdx)));
618                 for (int i = 0; i < hbConditionInitIdx; i++) {
619                         newCode.add("\t"
620                                         + ASSIGN("hb_init_table[" + i + "]", "hbConditionInit" + i));
621                 }
622                 return newCode;
623         }
624
625         private static ArrayList<String> generateCommutativityAnnotation(
626                         SemanticsChecker semantics) {
627                 ArrayList<String> newCode = new ArrayList<String>();
628                 ArrayList<CommutativityRule> rules = semantics.getGlobalConstruct().commutativityRules;
629                 for (CommutativityRule rule : rules) {
630
631                 }
632
633                 // Init commutativity_rule_table
634                 newCode.add("\t" + COMMENT("Init commutativity_rule_table"));
635                 newCode.add("\t"
636                                 + ASSIGN("hb_init_table", "(" + ANNO_HB_INIT
637                                                 + "**) malloc(sizeof(" + ANNO_HB_INIT + "*) * "
638                                                 + hbConditionInitIdx + ")"));
639                 // Define HB_INIT_TABLE_SIZE
640                 newCode.add("\t"
641                                 + DEFINE("HB_INIT_TABLE_SIZE",
642                                                 Integer.toString(hbConditionInitIdx)));
643                 for (int i = 0; i < hbConditionInitIdx; i++) {
644                         newCode.add("\t"
645                                         + ASSIGN("hb_init_table[" + i + "]", "hbConditionInit" + i));
646                 }
647                 return newCode;
648         }
649
650         public static ArrayList<String> generateEntryPointInitCall() {
651                 ArrayList<String> newCode = new ArrayList<String>();
652                 newCode.add("\t" + "__sequential_init();");
653                 return newCode;
654         }
655
656         public static ArrayList<String> generateInterfaceWrapperDeclaration(
657                         SemanticsChecker semantics, InterfaceConstruct construct) {
658                 FunctionHeader header = getFunctionHeader(semantics, construct);
659                 ArrayList<String> declaration = new ArrayList<String>();
660                 declaration.add(header.getRenamedHeader(SPEC_INTERFACE_WRAPPER)
661                                 .getDeclaration() + ";");
662                 return declaration;
663         }
664
665         // Only generate the definition of the wrapper, don't do any renaming
666         public static ArrayList<String> generateInterfaceWrapperDefinition(
667                         SemanticsChecker semantics, InterfaceConstruct construct) {
668                 ArrayList<String> newCode = new ArrayList<String>();
669                 String interfaceName = construct.name;
670
671                 FunctionHeader header = getFunctionHeader(semantics, construct);
672                 String interfaceNum = Integer.toString(semantics.interface2Num
673                                 .get(construct.name));
674
675                 newCode.add(header.getTemplateFullStr());
676                 newCode.add(header.getFuncStr() + " {");
677                 // Wrapper function body
678                 newCode.add("\t" + COMMENT("Interface begins"));
679                 // Interface begin
680                 String structName = "interface_begin";
681                 newCode.add("\t"
682                                 + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN,
683                                                 "interface_begin"));
684                 newCode.add("\t"
685                                 + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
686                                 + SHORT_COMMENT(construct.name));
687                 newCode.add("\t\t"
688                                 + ASSIGN_TO_PTR(structName, "interface_name", "\""
689                                                 + construct.name + "\""));
690
691                 String anno = "annotation_interface_begin";
692                 newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
693                 newCode.add("\t"
694                                 + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN));
695                 newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
696                 newCode.add("\t" + ANNOTATE(semantics, anno));
697                 // Call original renamed function
698                 if (header.returnType.equals("void")) {
699                         newCode.add("\t" + header.getRenamedCall(SPEC_INTERFACE_WRAPPER)
700                                         + ";");
701                 } else {
702                         newCode.add("\t"
703                                         + DECLARE_DEFINE(header.returnType, MACRO_RETURN,
704                                                         header.getRenamedCall(SPEC_INTERFACE_WRAPPER)));
705                 }
706                 // HB conditions
707                 for (String label : construct.hbConditions.keySet()) {
708                         String condition = construct.hbConditions.get(label);
709                         String hbCondNum = Integer.toString(semantics.hbLabel2Num
710                                         .get(label));
711                         newCode.add("\t" + "if " + BRACE(condition) + " {");
712                         structName = "hb_condition";
713                         newCode.add("\t\t"
714                                         + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
715                         newCode.add("\t\t"
716                                         + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
717                                         + SHORT_COMMENT(construct.name));
718
719                         newCode.add("\t\t"
720                                         + ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum));
721                         anno = "annotation_hb_condition";
722                         newCode.add("\t\t"
723                                         + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
724                         newCode.add("\t\t"
725                                         + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
726                         newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
727                         newCode.add("\t\t" + ANNOTATE(semantics, anno));
728                         newCode.add("\t" + "}");
729                         newCode.add("");
730                 }
731                 // Also add the true condition if any
732                 if (semantics.containsConditionalInterface(new ConditionalInterface(
733                                 interfaceName, ""))) {
734                         structName = "hb_condition";
735                         newCode.add("\t"
736                                         + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
737                         newCode.add("\t"
738                                         + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
739                                         + SHORT_COMMENT(construct.name));
740                         newCode.add("\t"
741                                         + ASSIGN_TO_PTR(structName, "hb_condition_num", "0"));
742                         anno = "annotation_hb_condition";
743                         newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
744                         newCode.add("\t"
745                                         + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
746                         newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
747                         newCode.add("\t" + ANNOTATE(semantics, anno));
748                         newCode.add("");
749                 }
750                 // Interface end
751                 String infoStructType = null, infoName = null;
752                 if (!header.returnType.equals("void") || header.args.size() > 0) {
753                         infoStructType = interfaceName + "_info";
754                         infoName = "info";
755                         newCode.add("\t"
756                                         + DECLARE_DEFINE(infoStructType + "*", infoName,
757                                                         BRACE(infoStructType + "*") + " malloc(sizeof("
758                                                                         + infoStructType + "))"));
759                         if (!header.returnType.equals("void")) {
760                                 newCode.add("\t"
761                                                 + ASSIGN_TO_PTR(infoName, MACRO_RETURN, MACRO_RETURN));
762                         }
763                         for (int i = 0; i < header.args.size(); i++) {
764                                 String argName = header.args.get(i).name;
765                                 newCode.add("\t" + ASSIGN_TO_PTR(infoName, argName, argName));
766                         }
767                 } else {
768                         infoName = "NULL";
769                 }
770                 structName = "interface_end";
771                 anno = "annoation_interface_end";
772                 newCode.add("\t"
773                                 + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName));
774                 newCode.add("\t"
775                                 + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
776                                 + SHORT_COMMENT(construct.name));
777                 newCode.add("\t" + ASSIGN_TO_PTR(structName, "info", infoName));
778                 newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
779                 newCode.add("\t"
780                                 + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END));
781                 newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
782                 newCode.add("\t" + ANNOTATE(semantics, anno));
783                 // Return __RET__ if it's not void
784                 if (!header.returnType.equals("void")) {
785                         newCode.add("\t" + "return " + MACRO_RETURN + ";");
786                 }
787                 // End of the wrapper function
788                 newCode.add("}");
789
790                 // printCode(newCode);
791                 return newCode;
792         }
793
794         // Rename the interface name for declaration or definition
795         public static void renameInterface(SemanticsChecker semantics,
796                         Construct construct) {
797                 FunctionHeader header = getFunctionHeader(semantics, construct);
798                 ArrayList<String> content = semantics.srcFilesInfo.get(construct.file).content;
799                 int lineNum = construct.beginLineNum;
800                 String headerLine = content.get(construct.beginLineNum);
801                 if (headerLine.startsWith("template")) {
802                         headerLine = content.get(construct.beginLineNum + 1);
803                         lineNum++;
804                 }
805                 String newLine = header.getRenamedHeader(SPEC_INTERFACE_WRAPPER)
806                                 .toString();
807                 String oldLine = content.get(lineNum + 1);
808
809                 if (construct instanceof InterfaceConstruct) {
810                         InterfaceConstruct iConstruct = (InterfaceConstruct) construct;
811                         InterfaceDefineConstruct defineConstruct = semantics.interfaceName2DefineConstruct
812                                         .get(iConstruct.name);
813                         if (defineConstruct != null) { // There is a defineConstruct
814                                 newLine = newLine + " ;";
815                                 renameInterface(semantics, defineConstruct);
816                         } else { // This is a declare & define construct
817                                 if (oldLine.indexOf('{') != -1)
818                                         newLine = newLine + " {";
819                         }
820                 } else {
821                         if (oldLine.indexOf('{') != -1)
822                                 newLine = newLine + " {";
823                 }
824
825                 content.set(lineNum + 1, newLine);
826         }
827
828         public static void addAtomicReturn(SemanticsChecker semantics,
829                         Construct construct) {
830                 int lineNum = construct.beginLineNum - 1;
831                 ArrayList<String> content = semantics.srcFilesInfo.get(construct.file).content;
832                 String oldLine = content.get(lineNum);
833                 String newLine = "uint64_t " + MACRO_ATOMIC_RETURN + " = " + oldLine;
834                 content.set(lineNum, newLine);
835         }
836
837         public static ArrayList<String> generatePotentialCPDefine(
838                         SemanticsChecker semantics, PotentialCPDefineConstruct construct) {
839                 ArrayList<String> newCode = new ArrayList<String>();
840                 // Add atomic return variable if the predicate accesses to it
841                 if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
842                         addAtomicReturn(semantics, construct);
843                 }
844                 // Generate redundant header files
845                 newCode.add("\t"
846                                 + COMMENT("Automatically generated code for potential commit point: "
847                                                 + construct.label));
848                 newCode.add("");
849                 // Add annotation
850                 newCode.add("\t" + "if (" + construct.condition + ") {");
851                 String structName = "potential_cp_define", anno = "annotation_potential_cp_define";
852                 newCode.add("\t\t"
853                                 + STRUCT_NEW_DECLARE_DEFINE(ANNO_POTENTIAL_CP_DEFINE,
854                                                 structName));
855                 String labelNum = Integer.toString(semantics.commitPointLabel2Num
856                                 .get(construct.label));
857                 newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
858                 newCode.add("\t\t"
859                                 + ASSIGN_TO_PTR(structName, "label_name", "\""
860                                                 + construct.label + "\""));
861                 if (construct.isAdditionalOrderingPoint) {
862                         newCode.add("\t\t"
863                                         + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
864                 } else {
865                         newCode.add("\t\t"
866                                         + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
867                 }
868                 newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
869                 newCode.add("\t\t"
870                                 + ASSIGN_TO_PTR(anno, "type",
871                                                 SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE));
872                 newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
873                 newCode.add("\t\t" + ANNOTATE(semantics, anno));
874                 newCode.add("\t" + "}");
875                 return newCode;
876         }
877
878         public static String getCPInterfaceNum(SemanticsChecker semantics,
879                         String commitPointLabel) {
880                 HashMap<String, InterfaceConstruct> cp2Interface = semantics.CPLabel2InterfaceConstruct;
881                 InterfaceConstruct iConstruct = cp2Interface.get(commitPointLabel);
882                 String interfaceName = iConstruct.name;
883                 String interfaceNum = Integer.toString(semantics.interface2Num
884                                 .get(interfaceName));
885                 return interfaceNum;
886         }
887
888         /**
889          * <p>
890          * Commit point define check should be unique to each interface, meaning
891          * that they are not shared between different interfaces
892          * </p>
893          * 
894          * @param semantics
895          * @param construct
896          * @return
897          */
898         public static ArrayList<String> generateCPDefineCheck(
899                         SemanticsChecker semantics, CPDefineCheckConstruct construct) {
900                 ArrayList<String> newCode = new ArrayList<String>();
901                 // Add atomic return variable if the predicate accesses to it
902                 if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
903                         addAtomicReturn(semantics, construct);
904                 }
905                 // Generate redundant header files
906                 newCode.add("\t"
907                                 + COMMENT("Automatically generated code for commit point define check: "
908                                                 + construct.label));
909                 newCode.add("");
910                 // Add annotation
911
912                 newCode.add("\t" + "if (" + construct.condition + ") {");
913                 String structName = "cp_define_check", anno = "annotation_cp_define_check";
914                 newCode.add("\t\t"
915                                 + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName));
916                 String labelNum = Integer.toString(semantics.commitPointLabel2Num
917                                 .get(construct.label));
918                 String interfaceNum = getCPInterfaceNum(semantics, construct.label);
919                 newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
920                 newCode.add("\t\t"
921                                 + ASSIGN_TO_PTR(structName, "label_name", "\""
922                                                 + construct.label + "\""));
923                 newCode.add("\t\t"
924                                 + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
925                 if (construct.isAdditionalOrderingPoint) {
926                         newCode.add("\t\t"
927                                         + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
928                 } else {
929                         newCode.add("\t\t"
930                                         + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
931                 }
932                 newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
933                 newCode.add("\t\t"
934                                 + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE_CHECK));
935                 newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
936                 newCode.add("\t\t" + ANNOTATE(semantics, anno));
937                 newCode.add("\t" + "}");
938                 return newCode;
939         }
940
941         /**
942          * <p>
943          * Commit point define check should be unique to each interface, meaning
944          * that they are not shared between different interfaces
945          * </p>
946          * 
947          * @param semantics
948          * @param construct
949          * @return
950          */
951         public static ArrayList<String> generateCPClear(SemanticsChecker semantics,
952                         CPClearConstruct construct) {
953                 ArrayList<String> newCode = new ArrayList<String>();
954                 // Add atomic return variable if the predicate accesses to it
955                 if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
956                         addAtomicReturn(semantics, construct);
957                 }
958                 // Generate redundant header files
959                 newCode.add("\t"
960                                 + COMMENT("Automatically generated code for commit point clear: "
961                                                 + construct.label));
962                 newCode.add("");
963                 // Add annotation
964
965                 newCode.add("\t" + "if (" + construct.condition + ") {");
966                 String structName = "cp_clear", anno = "annotation_cp_clear";
967                 newCode.add("\t\t"
968                                 + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_CLEAR, structName));
969                 // String labelNum = Integer.toString(semantics.commitPointLabel2Num
970                 // .get(construct.label));
971                 // String interfaceNum = getCPInterfaceNum(semantics, construct.label);
972                 // newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num",
973                 // labelNum));
974                 // newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_num",
975                 // interfaceNum));
976                 newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
977                 newCode.add("\t\t"
978                                 + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_CLEAR));
979                 newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
980                 newCode.add("\t\t" + ANNOTATE(semantics, anno));
981                 newCode.add("\t" + "}");
982                 return newCode;
983         }
984
985         /**
986          * <p>
987          * Commit point define should be unique to each interface, meaning that they
988          * are not shared between different interfaces
989          * </p>
990          * 
991          * @param semantics
992          * @param construct
993          * @return
994          */
995         public static ArrayList<String> generateCPDefine(
996                         SemanticsChecker semantics, CPDefineConstruct construct) {
997                 ArrayList<String> newCode = new ArrayList<String>();
998                 // Generate redundant header files
999                 newCode.add("\t"
1000                                 + COMMENT("Automatically generated code for commit point define: "
1001                                                 + construct.label));
1002                 newCode.add("");
1003                 // Add annotation
1004                 newCode.add("\t" + "if (" + construct.condition + ") {");
1005                 String structName = "cp_define", anno = "annotation_cp_define";
1006                 newCode.add("\t\t"
1007                                 + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName));
1008                 String labelNum = Integer.toString(semantics.commitPointLabel2Num
1009                                 .get(construct.label));
1010                 String interfaceNum = getCPInterfaceNum(semantics, construct.label);
1011                 String potentialLabelNum = Integer
1012                                 .toString(semantics.commitPointLabel2Num
1013                                                 .get(construct.potentialCPLabel));
1014                 newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
1015                 newCode.add("\t\t"
1016                                 + ASSIGN_TO_PTR(structName, "label_name", "\""
1017                                                 + construct.label + "\""));
1018                 newCode.add("\t\t"
1019                                 + ASSIGN_TO_PTR(structName, "potential_cp_label_num",
1020                                                 potentialLabelNum));
1021                 newCode.add("\t\t"
1022                                 + ASSIGN_TO_PTR(structName, "potential_label_name", "\""
1023                                                 + construct.potentialCPLabel + "\""));
1024                 newCode.add("\t\t"
1025                                 + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
1026                 if (construct.isAdditionalOrderingPoint) {
1027                         newCode.add("\t\t"
1028                                         + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
1029                 } else {
1030                         newCode.add("\t\t"
1031                                         + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
1032                 }
1033                 newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
1034                 newCode.add("\t\t"
1035                                 + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE));
1036                 newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
1037                 newCode.add("\t\t" + ANNOTATE(semantics, anno));
1038                 newCode.add("\t" + "}");
1039                 return newCode;
1040         }
1041 }