Adding Java callback support in compiler
[iot2.git] / iotjava / iotpolicy / tree / InterfaceDecl.java
index 15893e314a9b4f15a9084b89fb3accba608cb1fd..30dd3ce002804cb6e0b84a3f9c4f10624416038a 100644 (file)
@@ -38,6 +38,9 @@ public class InterfaceDecl extends Declaration {
        private List<String> listMethodTypes;                           // Method types, e.g. void
        private List<List<String>> listMethodParams;            // Method parameter names, e.g. A, B
        private List<List<String>> listMethodParamTypes;        // Method parameter types, e.g. int, int
+       private Map<String,Integer> mapHelperNumMethodId;       // Helper method Id, e.g. for callbacks, structs.
+
+       private static int helperMethodIdNum = -9999;
 
        /**
         * Class constructors
@@ -50,6 +53,7 @@ public class InterfaceDecl extends Declaration {
                listMethodTypes = new ArrayList<String>();
                listMethodParams = new ArrayList<List<String>>();
                listMethodParamTypes = new ArrayList<List<String>>();
+               mapHelperNumMethodId = new HashMap<String,Integer>();
        }
 
 
@@ -61,6 +65,7 @@ public class InterfaceDecl extends Declaration {
                listMethodTypes = new ArrayList<String>();
                listMethodParams = new ArrayList<List<String>>();
                listMethodParamTypes = new ArrayList<List<String>>();
+               mapHelperNumMethodId = new HashMap<String,Integer>();
        }
 
 
@@ -99,6 +104,29 @@ public class InterfaceDecl extends Declaration {
        }
 
 
+       /**
+        * getMethodNumId() gets Id number for a method
+        */
+       public int getMethodNumId(String method) {
+
+               return listMethods.indexOf(method);
+       }
+
+
+       /**
+        * getHelperMethodNumId() gets Id number for a method
+        */
+       public int getHelperMethodNumId(String method) {
+
+               if (!mapHelperNumMethodId.containsKey(method)) {
+                       mapHelperNumMethodId.put(method, helperMethodIdNum++);
+                       return mapHelperNumMethodId.get(method);
+               } else {
+                       return mapHelperNumMethodId.get(method);
+               }
+       }
+
+
        /**
         * getMethodIds() gets method identifiers
         */
@@ -183,25 +211,4 @@ public class InterfaceDecl extends Declaration {
                                method + "! Please check your policy file...");
                return listMethodParamTypes.get(index);
        }
-
-
-       public static void main(String[] args) {
-
-               InterfaceDecl id = new InterfaceDecl("Camera");
-               id.addNewMethod("MethodA(intA,SpeakerB)", "MethodA", "void");
-               id.addMethodParam("MethodA", "A", "int");
-               id.addMethodParam("MethodA", "B", "int");
-               id.addMethodParam("MethodB", "C", "int");
-               id.addMethodParam("MethodB", "D", "string");
-               id.addMethodParam("MethodC", "E", "string");
-               id.addMethodParam("MethodC", "F", "int");
-
-               System.out.println("Set of methods: " + id.getMethods().toString());
-               System.out.println("Set of params: " + id.getMethodParams("MethodA").toString());
-               System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodA").toString());
-               System.out.println("Set of params: " + id.getMethodParams("MethodB").toString());
-               System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodB").toString());
-               System.out.println("Set of params: " + id.getMethodParams("MethodC").toString());
-               System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodC").toString());
-       }
 }