Initial cleaning up in compiler, fixing bugs
authorrtrimana <rtrimana@uci.edu>
Tue, 8 Nov 2016 19:55:04 +0000 (11:55 -0800)
committerrtrimana <rtrimana@uci.edu>
Tue, 8 Nov 2016 19:55:04 +0000 (11:55 -0800)
iotjava/Makefile
iotjava/iotpolicy/IoTCompiler.java

index bd1c55579e93cc278982dd0431b0df70b843d585..feafe5160c1deb5f2360afb39a8db6a25b857ace 100644 (file)
@@ -27,6 +27,20 @@ PHONY += runtime
 runtime:
        $(JAVAC) -classpath . iotruntime/master/*.java -d $(BIN_DIR)
 
+# TODO: Can remove this later - just to test-compile the resulted files from the compiler
+PHONY += compile
+compile:
+       cd $(BIN_DIR)/iotpolicy/output_files; cp *.java ./Java
+       cd $(BIN_DIR)/iotpolicy/output_files; cp *.hpp ./Cplus
+       cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:.. *.java
+       cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./*.hpp --std=c++11 -pthread -pg
+
+PHONY += clean
+clean:
+       cd $(BIN_DIR)/iotpolicy/output_files; rm -rf *.class *.gch
+       cd $(BIN_DIR)/iotpolicy/output_files/Java; rm -rf *.class
+       cd $(BIN_DIR)/iotpolicy/output_files/Cplus; rm -rf *.gch
+
 # RMI compilation and run
 PHONY += rmi
 rmi:
index 4bbeb6a8c023917a4a42cf19e0112f754428dec4..4450f1d3c74a7e39b0a00069a92c158e9bb266cc 100644 (file)
@@ -194,10 +194,8 @@ public class IoTCompiler {
                                for (int i = 0; i < methParams.size(); i++) {
                                        // Check for params with driver class types and exchange it 
                                        //              with its remote interface
-                                       String paramType = checkAndGetParamClass(methPrmTypes.get(i));
-                                       String paramComplete = checkAndGetCplusArray(paramType, methParams.get(i));
-                                       //print(paramType + " " + methParams.get(i));
-                                       print(paramComplete);
+                                       String paramType = checkAndGetParamClass(methPrmTypes.get(i), false);
+                                       print(paramType + " " + methParams.get(i));
                                        // Check if this is the last element (don't print a comma)
                                        if (i != methParams.size() - 1) {
                                                print(", ");
@@ -234,7 +232,10 @@ public class IoTCompiler {
                        DeclarationHandler decHandler = mapIntDeclHand.get(intface);
                        InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(intface);
                        List<String> methods = intDecl.getMethods();
+
+                       // DEBUGGG
                        Set<String> includeClasses = getIncludeClasses(methods, intDecl);
+
                        printIncludeStatements(includeClasses);
                        println("");
                        println("using namespace std;");
@@ -252,7 +253,7 @@ public class IoTCompiler {
                                for (int i = 0; i < methParams.size(); i++) {
                                        // Check for params with driver class types and exchange it 
                                        //              with its remote interface
-                                       String paramType = checkAndGetParamClass(methPrmTypes.get(i));
+                                       String paramType = checkAndGetParamClass(methPrmTypes.get(i), true);
                                        paramType = checkAndGetCplusType(paramType);
                                        // Check for arrays - translate into vector in C++
                                        String paramComplete = checkAndGetCplusArray(paramType, methParams.get(i));
@@ -306,7 +307,9 @@ public class IoTCompiler {
                                        print("public " + intDecl.getMethodType(method) + " " +
                                                intDecl.getMethodId(method) + "(");
                                        for (int i = 0; i < methParams.size(); i++) {
-                                               print(methPrmTypes.get(i) + " " + methParams.get(i));
+                                               String paramType = checkAndGetParamClass(methPrmTypes.get(i), false);
+                                               print(paramType + " " + methParams.get(i));
+                                               //print(methPrmTypes.get(i) + " " + methParams.get(i));
                                                // Check if this is the last element (don't print a comma)
                                                if (i != methParams.size() - 1) {
                                                        print(", ");
@@ -361,10 +364,9 @@ public class IoTCompiler {
                                        print("virtual " + convertType(intDecl.getMethodType(method)) + " " +
                                                intDecl.getMethodId(method) + "(");
                                        for (int i = 0; i < methParams.size(); i++) {
-
-                                               String methPrmType = checkAndGetCplusType(methPrmTypes.get(i));
+                                               String methPrmType = checkAndGetParamClass(methPrmTypes.get(i), true);
+                                               methPrmType = checkAndGetCplusType(methPrmType);
                                                String methParamComplete = checkAndGetCplusArray(methPrmType, methParams.get(i));
-                                               //print(methPrmType + " " + methParam);
                                                print(methParamComplete);
                                                // Check if this is the last element (don't print a comma)
                                                if (i != methParams.size() - 1) {
@@ -471,17 +473,11 @@ public class IoTCompiler {
 
                                        List<String> methParams = intDecl.getMethodParams(method);
                                        List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-
-                                       //System.out.println("\n\nMethod param: " + intDecl.getMethodParams(method));
-                                       //System.out.println("\n\nMethod param type: " + intDecl.getMethodParamTypes(method));
-                                       //System.out.println("\n\n");
-
                                        print(convertType(intDecl.getMethodType(method)) + " " +
                                                intDecl.getMethodId(method) + "(");
                                        for (int i = 0; i < methParams.size(); i++) {
                                                String methPrmType = checkAndGetCplusType(methPrmTypes.get(i));
                                                String methParamComplete = checkAndGetCplusArray(methPrmType, methParams.get(i));
-                                               //print(methPrmType + " " + methParam);
                                                print(methParamComplete);
                                                // Check if this is the last element (don't print a comma)
                                                if (i != methParams.size() - 1) {
@@ -520,11 +516,11 @@ public class IoTCompiler {
                        methType.equals("double")) {
 
                        return "1";
-               } else if ( methType.equals("String") ||
-                                       methType.equals("byte")) {
+               } else if ( methType.equals("String")) {
   
                        return "\"a\"";
-               } else if ( methType.equals("char")) {
+               } else if ( methType.equals("char") ||
+                                       methType.equals("byte")) {
 
                        return "\'a\'";
                } else if ( methType.equals("boolean")) {
@@ -759,10 +755,12 @@ public class IoTCompiler {
                                String simpleType = getSimpleType(methPrmTypes.get(i));
                                String param = methParams.get(i);
                                if (getParamCategory(simpleType) == ParamCategory.NONPRIMITIVES) {
-                                       includeClasses.add(getNonPrimitiveCplusClass(simpleType));
+                                       includeClasses.add("<" + getNonPrimitiveCplusClass(simpleType) + ">");
+                               } else if (getParamCategory(simpleType) == ParamCategory.USERDEFINED) {
+                                       includeClasses.add("\"" + exchangeParamType(simpleType) + ".hpp\"");
                                } else if (param.contains("[]")) {
                                // Check if this is array for C++; translate into vector
-                                       includeClasses.add("vector");
+                                       includeClasses.add("<vector>");
                                }
                        }
                }
@@ -781,7 +779,7 @@ public class IoTCompiler {
        private void printIncludeStatements(Set<String> includeClasses) {
 
                for(String cls : includeClasses) {
-                       println("#include <" + cls + ">");
+                       println("#include " + cls);
                }
        }
 
@@ -842,11 +840,15 @@ public class IoTCompiler {
 
        // Get simple types, e.g. HashSet for HashSet<...>
        // Basically strip off the "<...>"
-       private String checkAndGetParamClass(String paramType) {
+       private String checkAndGetParamClass(String paramType, boolean needPtr) {
 
                // Check if this is generics
                if(getParamCategory(paramType) == ParamCategory.USERDEFINED) {
-                       return exchangeParamType(paramType);
+                       // If true then return with pointer (C++)
+                       if (needPtr)
+                               return exchangeParamType(paramType) + "*";
+                       else    // Java, so no pointer needed
+                               return exchangeParamType(paramType);
                } else
                        return paramType;
        }