X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=src%2Fedu%2Fuci%2Feecs%2FspecExtraction%2FGlobalConstruct.java;h=d8f6dd42491bfaaa62b17b9e3c06efd8840a4e6e;hb=3f2abaf79b5d1cb74a405eb6a8c4f0471e41daa6;hp=b2e52a03d5b333626b5b014a8e433a91d4c22184;hpb=ab66367c9abeae3f68837ad1f48a11a54e4a55bf;p=cdsspec-compiler.git diff --git a/src/edu/uci/eecs/specExtraction/GlobalConstruct.java b/src/edu/uci/eecs/specExtraction/GlobalConstruct.java index b2e52a0..d8f6dd4 100644 --- a/src/edu/uci/eecs/specExtraction/GlobalConstruct.java +++ b/src/edu/uci/eecs/specExtraction/GlobalConstruct.java @@ -21,6 +21,7 @@ public class GlobalConstruct extends Construct { public final ArrayList declState; public final Code initState; public final Code copyState; + public final Code clearState; public final Code finalState; public final Code printState; public final ArrayList commutativityRules; @@ -31,6 +32,8 @@ public class GlobalConstruct extends Construct { public final boolean autoGenInitial; // Whether we have auto-gen the state copying code public final boolean autoGenCopy; + // Whether we have auto-gen the state clearing code + public final boolean autoGenClear; // Whether we have auto-gen the state printing code public final boolean autoGenPrint; @@ -40,6 +43,7 @@ public class GlobalConstruct extends Construct { declState = new ArrayList(); initState = new Code(); copyState = new Code(); + clearState = new Code(); finalState = new Code(); printState = new Code(); commutativityRules = new ArrayList(); @@ -64,6 +68,12 @@ public class GlobalConstruct extends Construct { copyState.addLines(code); } + autoGenClear = clearState.isEmpty(); + if (autoGenClear) { + Code code = generateAutoClearFunction(); + clearState.addLines(code); + } + autoGenPrint = printState.isEmpty(); if (autoGenPrint) { Code code = generateAutoPrintFunction(); @@ -167,6 +177,35 @@ public class GlobalConstruct extends Construct { return code; } + + /** + *

+ * This function will automatically generate the clear statements for + * supported types if the user has not defined the "@Clear" primitive + *

+ * + * @return The auto-generated state copy statements + * @throws WrongAnnotationException + */ + private Code generateAutoClearFunction() throws WrongAnnotationException { + Code code = new Code(); + if (emptyState) // Empty state should have empty copy function + return code; + + // FIXME: Just try our best to generate recycling statements + for (VariableDeclaration decl : declState) { + String type = decl.type; + String name = decl.name; + if (type.equals("IntList *") || type.equals("IntSet *") + || type.equals("IntMap *")) { + // Supported pointer types + // if (stack) delete stack; + code.addLine("if (" + name + ") delete " + name + ";"); + } + } + + return code; + } /** *

@@ -209,6 +248,7 @@ public class GlobalConstruct extends Construct { if (!name.equals(SpecNaming.DeclareState) && !name.equals(SpecNaming.InitalState) && !name.equals(SpecNaming.CopyState) + && !name.equals(SpecNaming.ClearState) && !name.equals(SpecNaming.FinalState) && !name.equals(SpecNaming.Commutativity) && !name.equals(SpecNaming.PrintState)) { @@ -292,6 +332,8 @@ public class GlobalConstruct extends Construct { initState.addLines(primitive.contents); } else if (name.equals(SpecNaming.CopyState)) { copyState.addLines(primitive.contents); + } else if (name.equals(SpecNaming.ClearState)) { + clearState.addLines(primitive.contents); } else if (name.equals(SpecNaming.FinalState)) { finalState.addLines(primitive.contents); } else if (name.equals(SpecNaming.PrintState)) {