X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=blobdiff_plain;f=src%2Fedu%2Fuci%2Feecs%2FspecExtraction%2FSpecUtils.java;h=71512d864cbb3c3ae55ac5174a9e647faab2977f;hp=869b9ff81aff63566fbe77445851f7b360182977;hb=579524b6cd8994427d50cf604ee130493f59b4d3;hpb=83eae09be64a115aad7e6822d03cc87e603a60ea diff --git a/src/edu/uci/eecs/specExtraction/SpecUtils.java b/src/edu/uci/eecs/specExtraction/SpecUtils.java index 869b9ff..71512d8 100644 --- a/src/edu/uci/eecs/specExtraction/SpecUtils.java +++ b/src/edu/uci/eecs/specExtraction/SpecUtils.java @@ -123,7 +123,8 @@ public class SpecUtils { * annotations or the beginning line of the next primitive * @throws WrongAnnotationException */ - public static Primitive extractPrimitive(File file, int beginLineNum, ArrayList annotations, IntObj curIdx) + public static Primitive extractPrimitive(File file, int beginLineNum, + ArrayList annotations, IntObj curIdx) throws WrongAnnotationException { if (curIdx.getVal() == annotations.size()) // The current index points // to the end @@ -146,8 +147,9 @@ public class SpecUtils { } // Assert that we must have found one primitive if (primitive == null) { - WrongAnnotationException.err(file, curLineNum, - "Something is wrong! We must have found one primitve here!\n"); + WrongAnnotationException + .err(file, curLineNum, + "Something is wrong! We must have found one primitve here!\n"); } // Process the current "primitive" @@ -161,8 +163,9 @@ public class SpecUtils { primitive.addLine(trimmedCode); } } else { - WrongAnnotationException.err(file, curLineNum, - "The state annotation should have correct primitive syntax (sub-annotations)"); + WrongAnnotationException + .err(file, curLineNum, + "The state annotation should have correct primitive syntax (sub-annotations)"); } // Deal with other normal line. E.g. y = 1; @@ -184,7 +187,8 @@ public class SpecUtils { if (primitive.contents.size() == 0) { // The content of the primitive is // empty - WrongAnnotationException.warning(file, curLineNum, "Primitive " + primitive.name + " is empty."); + WrongAnnotationException.warning(file, curLineNum, "Primitive " + + primitive.name + " is empty."); } return primitive; } @@ -229,8 +233,9 @@ public class SpecUtils { // FIXME: We only consider the type is either a one-level pointer or a // struct String bareType = trimSpace(type.replace('*', ' ')); - return !bareType.equals("int") && !bareType.matches("unsigned\\s+int") && !bareType.equals("unsigned") - && !bareType.equals("bool") && !bareType.equals("double") && !bareType.equals("float") + return !bareType.equals("int") && !bareType.matches("unsigned\\s+int") + && !bareType.equals("unsigned") && !bareType.equals("bool") + && !bareType.equals("double") && !bareType.equals("float") && !bareType.equals("void"); } @@ -240,4 +245,67 @@ public class SpecUtils { String bareType = trimSpace(type.replace('*', ' ')); return bareType; } + + /** + *

+ * This function will automatically generate the printing statements for + * supported types when given a type and a name of the declaration. + *

+ * + * @return The auto-generated state printing statements + */ + public static Code generatePrintStatement(String type, String name) { + Code code = new Code(); + // 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")) { + // PRINT("\tx=%d\n", x); + code.addLine(SpecNaming.PRINT + "(\"\\t" + name + "=%d\\n\", " + + name + ");"); + } else if (type.equals("int *") || type.equals("unsigned *") + || type.equals("unsigned int *") + || type.equals("int unsigned *") || type.equals("double *") + || type.equals("double *") || type.equals("bool *")) { + // Supported pointer types for primitive types + // PRINT("\t*x=%d\n", *x); + code.addLine(SpecNaming.PRINT + "(\"\\t*" + name + "=%d\\n\", *" + + name + ");"); + } else if (type.equals("IntList") || type.equals("IntSet") + || type.equals("IntMap")) { + // Supported types + // PRINT("\tq: "); + // printContainer(&q); + // model_print("\n"); + code.addLine(SpecNaming.PRINT + "(\"\\t" + name + ": \");"); + code.addLine(SpecNaming.PrintContainer + "(&" + name + ");"); + code.addLine(SpecNaming.PRINT + "(\"\\n\");"); + } else if (type.equals("IntList *") || type.equals("IntSet *") + || type.equals("IntMap *")) { + // Supported pointer types + // PRINT("\tq: "); + // printContainer(q); + // model_print("\n"); + code.addLine(SpecNaming.PRINT + "(\"\\t" + name + ": \");"); + code.addLine(SpecNaming.PrintContainer + "(" + name + ");"); + code.addLine(SpecNaming.PRINT + "(\"\\n\");"); + } else if (type.equals("void")) { + // Just do nothing! + } else { + if (type.endsWith("*")) { // If it's an obvious pointer (with a STAR) + // Weak support pointer types (just print out the address) + // PRINT("\tmutex=%p\n", mutex); + code.addLine(SpecNaming.PRINT + "(\"\\t" + name + "=%p\\n\", " + + name + ");"); + } else { + code.addLine("// We do not support auto-gen print-out for type: " + + type + "."); + } + + } + + return code; + } + }