minor fix
[cdsspec-compiler.git] / src / edu / uci / eecs / specExtraction / InterfaceConstruct.java
index 2ed5367bb009df533d98b6c920eb9ffcd79d77e2..6afd5f127abd4261ec94b0285d23d56718209ae7 100644 (file)
@@ -38,6 +38,8 @@ public class InterfaceConstruct extends Construct {
        // arguments of the interface
        private FunctionHeader funcHeader;
 
+       public final boolean autoGenPrint;
+
        public InterfaceConstruct(File file, int beginLineNum, int endLineNum,
                        ArrayList<String> annotations) throws WrongAnnotationException {
                super(file, beginLineNum);
@@ -50,6 +52,8 @@ public class InterfaceConstruct extends Construct {
                this.print = new Code();
 
                processAnnotations(annotations);
+
+               autoGenPrint = print.isEmpty();
        }
 
        public FunctionHeader getFunctionHeader() {
@@ -71,6 +75,29 @@ public class InterfaceConstruct extends Construct {
                return this.name;
        }
 
+       /**
+        * <p>
+        * This function will automatically generate the printing statements for
+        * supported types if the user has not defined the "@Print" primitive
+        * </p>
+        * 
+        * @return The auto-generated state printing statements
+        * @throws WrongAnnotationException
+        */
+       private Code generateAutoPrintFunction() {
+               Code code = new Code();
+               // For RET
+               code.addLines(SpecUtils.generatePrintStatement(funcHeader.returnType,
+                               SpecNaming.RET));
+               // For arguments
+               for (VariableDeclaration decl : funcHeader.args) {
+                       String type = decl.type;
+                       String name = decl.name;
+                       code.addLines(SpecUtils.generatePrintStatement(type, name));
+               }
+               return code;
+       }
+
        /**
         * <p>
         * Assert that the interface primitive is valid; if not, throws an exception
@@ -171,6 +198,12 @@ public class InterfaceConstruct extends Construct {
                funcHeader = UtilParser.parseFuncHeader(line);
                // Record the original declaration line
                funcHeader.setHeaderLine(line);
+
+               // Once we have the compelte function declaration, we can auto-gen the
+               // print-out statements if it's not defined
+               if (autoGenPrint) {
+                       print.addLines(generateAutoPrintFunction());
+               }
        }
 
        public String toString() {