+
+ autoGenPrint = printState.isEmpty();
+ if (autoGenPrint) {
+ Code code = generateAutoPrintFunction();
+ printState.addLines(code);
+ }
+ }
+
+ /**
+ * <p>
+ * This function will automatically generate the initial statements for
+ * supported types if the user has not defined the "@Initial" primitive
+ * </p>
+ *
+ * @return The auto-generated state intialization statements
+ * @throws WrongAnnotationException
+ */
+ private Code generateAutoInitalFunction() throws WrongAnnotationException {
+ Code code = new Code();
+ if (emptyState) // Empty state should have empty initial function
+ return code;
+ for (VariableDeclaration decl : declState) {
+ String type = decl.type;
+ String name = decl.name;
+ // Primitive types
+ if (type.equals("int") || type.equals("unsigned")
+ || type.equals("unsigned int")
+ || type.equals("int unsigned") || type.equals("double")
+ || type.equals("double") || type.equals("bool")) {
+ // x = 0;
+ code.addLine(name + " = 0;");
+ } else if (type.equals("IntList") || type.equals("IntSet")
+ || type.equals("IntMap")) {
+ // Supported types
+ // q = IntList();
+ code.addLine(name + " = " + type + "();");
+ } else if (type.equals("IntList *") || type.equals("IntSet *")
+ || type.equals("IntMap *")) {
+ // Supported pointer types
+ // q = new IntList;
+ String originalType = SpecUtils.trimSpace(type
+ .replace('*', ' '));
+ code.addLine(name + " = new " + originalType + "();");
+ } else {
+ WrongAnnotationException
+ .err(file,
+ beginLineNum,
+ "You have types in the state declaration that we do not support auto-gen initial function.");
+ }
+ }
+
+ return code;