// 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);
this.print = new Code();
processAnnotations(annotations);
+
+ autoGenPrint = print.isEmpty();
}
public FunctionHeader getFunctionHeader() {
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
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() {