allow shorter spec --- @Interface is not mandatory
[cdsspec-compiler.git] / src / edu / uci / eecs / specExtraction / InterfaceConstruct.java
index 232acaf2b34bc5529db9d64bb10af8547059f1ca..1ff0cb05514cc3c8e7c01d56587cee307c6bcd03 100644 (file)
@@ -21,9 +21,16 @@ import edu.uci.eecs.utilParser.UtilParser;
  * 
  */
 public class InterfaceConstruct extends Construct {
+       // The interface label of the current interface; If not specified, we use
+       // the actual interface name to represent this interface
        private String name;
-       public final Code transition;
+       // Each interface interface will have an auto-generated struct that
+       // represents the return value and the arguments of that interface method
+       // call. We will mangle the interface label name to get this name in case we
+       // have other name conflict
+       private String structName;
        public final Code preCondition;
+       public final Code transition;
        public final Code postCondition;
        public final Code print;
 
@@ -44,8 +51,9 @@ public class InterfaceConstruct extends Construct {
                super(file, beginLineNum);
                this.endLineNum = endLineNum;
                this.name = null;
-               this.transition = new Code();
+               this.structName = null;
                this.preCondition = new Code();
+               this.transition = new Code();
                this.postCondition = new Code();
                this.print = new Code();
 
@@ -164,7 +172,8 @@ public class InterfaceConstruct extends Construct {
                        if (primitive.contents.size() == 0)
                                continue;
                        if (name.equals(SpecNaming.Interface)) {
-                               this.name = extractInterfaceName(file, primitive);
+                               String interName = extractInterfaceName(file, primitive); 
+                               setNames(interName);
                        } else if (name.equals(SpecNaming.Transition)) {
                                this.transition.addLines(primitive.contents);
                        } else if (name.equals(SpecNaming.PreCondition)) {
@@ -195,6 +204,12 @@ public class InterfaceConstruct extends Construct {
                // Record the original declaration line
                funcHeader.setHeaderLine(line);
 
+               // If users have not defined @Interface, we should use the function name
+               // as the interface label
+               if (name == null) {
+                       setNames(funcHeader.funcName.bareName);
+               }
+
                // Once we have the compelte function declaration, we can auto-gen the
                // print-out statements if it's not defined
                if (autoGenPrint) {
@@ -226,4 +241,19 @@ public class InterfaceConstruct extends Construct {
        public void setEndLineNumFunction(int endLineNumFunction) {
                this.endLineNumFunction = endLineNumFunction;
        }
+
+       public String getStructName() {
+               return structName;
+       }
+
+       private void setNames(String name) {
+               this.name = name;
+               if (name == null)
+                       return;
+               structName = createStructName(name);
+       }
+       
+       static public String createStructName(String labelName) {
+               return "__struct_" + labelName + "__";
+       }
 }