From 8930b233f8225bb6b5c2e3247b6d0593ceaecb77 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Wed, 23 Nov 2016 16:50:03 -0800 Subject: [PATCH] Fixing comments and cleaning up --- iotjava/iotpolicy/IoTCompiler.java | 131 +++++++++++------------------ 1 file changed, 47 insertions(+), 84 deletions(-) diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index 180de2e..674c98c 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -59,6 +59,7 @@ public class IoTCompiler { private String dir; private String subdir; + /** * Class constants */ @@ -73,6 +74,7 @@ public class IoTCompiler { USERDEFINED // Assumed as driver classes } + /** * Class constructors */ @@ -104,7 +106,6 @@ public class IoTCompiler { * data structures. * Additionally, the data structure handles are * returned from tree-parsing for further process. - * */ public void setDataStructures(String origInt, ParseNode pnPol, ParseNode pnReq) { @@ -183,7 +184,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodJavaLocalInterface() writes the method of the interface + * HELPER: writeMethodJavaLocalInterface() writes the method of the local interface */ private void writeMethodJavaLocalInterface(Collection methods, InterfaceDecl intDecl) { @@ -330,12 +331,6 @@ public class IoTCompiler { // Write interface header println(""); println("public interface " + intface + " {"); - // Write enum if any... - //EnumDecl enumDecl = (EnumDecl) decHandler.getEnumDecl(intface); - //writeEnumJava(enumDecl); - // Write struct if any... - //StructDecl structDecl = (StructDecl) decHandler.getStructDecl(intface); - //writeStructJava(structDecl); // Write methods writeMethodJavaLocalInterface(methods, intDecl); println("}"); @@ -491,7 +486,7 @@ public class IoTCompiler { /** - * HELPER: writeConstructorJavaStub() writes the constructor of the stub class + * HELPER: writeInitCallbackJavaStub() writes callback initialization in stub */ private void writeInitCallbackJavaStub(String intface, InterfaceDecl intDecl) { @@ -649,7 +644,7 @@ public class IoTCompiler { /** - * HELPER: writeLengthStructParamClassJavaStub() writes lengths of params + * HELPER: writeLengthStructParamClassJavaStub() writes lengths of parameters */ private void writeLengthStructParamClassJavaStub(List methParams, List methPrmTypes) { @@ -743,7 +738,7 @@ public class IoTCompiler { /** - * HELPER: writeStructRetMembersJavaStub() writes parameters of struct + * HELPER: writeStructRetMembersJavaStub() writes parameters of struct for return statement */ private void writeStructRetMembersJavaStub(String simpleType, String retType) { @@ -782,7 +777,7 @@ public class IoTCompiler { /** - * HELPER: writeStructReturnJavaStub() writes parameters if struct is present + * HELPER: writeStructReturnJavaStub() writes parameters if struct is present for return statement */ private void writeStructReturnJavaStub(String simpleType, String retType) { @@ -922,7 +917,6 @@ public class IoTCompiler { println("try {"); // Check if this is single object, array, or list of objects for (int i = 0; i < methParams.size(); i++) { - String paramType = methPrmTypes.get(i); if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object String param = methParams.get(i); @@ -995,7 +989,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodJavaStub() writes the method of the stub class + * HELPER: writeMethodJavaStub() writes the methods of the stub class */ private void writeMethodJavaStub(Collection methods, InterfaceDecl intDecl, Set callbackClasses) { @@ -1289,7 +1283,8 @@ public class IoTCompiler { /** * HELPER: writeCallbackJavaStubGeneration() writes the callback stub generation part */ - private Map writeCallbackJavaStubGeneration(List methParams, List methPrmTypes, String callbackType) { + private Map writeCallbackJavaStubGeneration(List methParams, List methPrmTypes, + String callbackType) { Map mapStubParam = new HashMap(); // Iterate over callback objects @@ -1450,7 +1445,7 @@ public class IoTCompiler { /** - * HELPER: writeStructMembersJavaSkeleton() writes parameters of struct + * HELPER: writeStructMembersJavaSkeleton() writes member parameters of struct */ private void writeStructMembersJavaSkeleton(String simpleType, String paramType, String param, String method, InterfaceDecl intDecl, int iVar) { @@ -1483,9 +1478,8 @@ public class IoTCompiler { } - /** - * HELPER: writeStructMembersInitJavaSkeleton() writes parameters of struct + * HELPER: writeStructMembersInitJavaSkeleton() writes member parameters initialization of struct */ private void writeStructMembersInitJavaSkeleton(InterfaceDecl intDecl, List methParams, List methPrmTypes, String method) { @@ -1547,7 +1541,7 @@ public class IoTCompiler { /** - * HELPER: writeStructReturnJavaSkeleton() writes parameters if struct is present + * HELPER: writeStructReturnJavaSkeleton() writes struct for return statement */ private void writeStructReturnJavaSkeleton(String simpleType, String retType) { @@ -1592,7 +1586,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodHelperReturnJavaSkeleton() writes the return value part in skeleton + * HELPER: writeMethodHelperReturnJavaSkeleton() writes return statement part in skeleton */ private void writeMethodHelperReturnJavaSkeleton(InterfaceDecl intDecl, List methParams, List methPrmTypes, String method, boolean isCallbackMethod, String callbackType) { @@ -1802,7 +1796,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodHelperStructSetupJavaSkeleton() writes the method helper of the struct in skeleton class + * HELPER: writeMethodHelperStructSetupJavaSkeleton() writes the method helper of struct setup in skeleton class */ private void writeMethodHelperStructSetupJavaSkeleton(Collection methods, InterfaceDecl intDecl) { @@ -1833,7 +1827,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodHelperStructSetupJavaCallbackSkeleton() writes the method helper of the struct in skeleton class + * HELPER: writeMethodHelperStructSetupJavaCallbackSkeleton() writes the method helper of struct setup in callback skeleton class */ private void writeMethodHelperStructSetupJavaCallbackSkeleton(Collection methods, InterfaceDecl intDecl) { @@ -1888,7 +1882,7 @@ public class IoTCompiler { /** - * HELPER: writeInputCountVarStructSkeleton() writes counter variable of struct for skeleton + * HELPER: writeInputCountVarStructSkeleton() writes input counter variable of struct for skeleton */ private boolean writeInputCountVarStructSkeleton(String method, InterfaceDecl intDecl) { @@ -2178,7 +2172,7 @@ public class IoTCompiler { /** - * HELPER: writeJavaCallbackWaitRequestInvokeMethod() writes the main loop of the skeleton class + * HELPER: writeJavaCallbackWaitRequestInvokeMethod() writes the request invoke method of the callback skeleton class */ private void writeJavaCallbackWaitRequestInvokeMethod(Collection methods, InterfaceDecl intDecl, boolean callbackExist) { @@ -2265,7 +2259,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodCplusLocalInterface() writes the method of the interface + * HELPER: writeMethodCplusLocalInterface() writes the method of the local interface */ private void writeMethodCplusLocalInterface(Collection methods, InterfaceDecl intDecl) { @@ -2430,11 +2424,6 @@ public class IoTCompiler { Set includeClasses = getIncludeClasses(methods, intDecl, intface, true); printIncludeStatements(includeClasses); println(""); println("using namespace std;\n"); - // Write enum if any... - //EnumDecl enumDecl = (EnumDecl) decHandler.getEnumDecl(intface); - //writeEnumCplus(enumDecl); - // Write struct if any... - //StructDecl structDecl = (StructDecl) decHandler.getStructDecl(intface); //writeStructCplus(structDecl); println("class " + intface); println("{"); println("public:"); @@ -2493,7 +2482,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodCplusStub() writes the method of the stub + * HELPER: writeMethodCplusStub() writes the methods of the stub */ private void writeMethodCplusStub(Collection methods, InterfaceDecl intDecl, Set callbackClasses) { @@ -2735,7 +2724,7 @@ public class IoTCompiler { /** - * HELPER: writeStructMembersCplusStub() writes parameters of struct + * HELPER: writeStructMembersCplusStub() writes member parameters of struct */ private void writeStructMembersCplusStub(String simpleType, String paramType, String param) { @@ -2770,7 +2759,7 @@ public class IoTCompiler { /** - * HELPER: writeStructParamClassCplusStub() writes parameters if struct is present + * HELPER: writeStructParamClassCplusStub() writes member parameters of struct */ private void writeStructParamClassCplusStub(List methParams, List methPrmTypes) { @@ -2801,7 +2790,7 @@ public class IoTCompiler { /** - * HELPER: writeStructRetMembersCplusStub() writes parameters of struct + * HELPER: writeStructRetMembersCplusStub() writes member parameters of struct for return statement */ private void writeStructRetMembersCplusStub(String simpleType, String retType) { @@ -2831,7 +2820,7 @@ public class IoTCompiler { /** - * HELPER: writeStructReturnCplusStub() writes parameters if struct is present + * HELPER: writeStructReturnCplusStub() writes member parameters of struct for return statement */ private void writeStructReturnCplusStub(String simpleType, String retType) { @@ -3093,7 +3082,7 @@ public class IoTCompiler { /** - * HELPER: writeInitCallbackSendInfoCplusStub() writes the initialization of callback + * HELPER: writeInitCallbackSendInfoCplusStub() writes the initialization (send info part) of callback */ private void writeInitCallbackSendInfoCplusStub(InterfaceDecl intDecl) { @@ -3542,7 +3531,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodHelperReturnCplusSkeleton() writes the return value part in skeleton + * HELPER: writeMethodHelperReturnCplusSkeleton() writes the return statement part in skeleton */ private void writeMethodInputParameters(List methParams, List methPrmTypes, Set callbackClasses, String methodId) { @@ -3567,7 +3556,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodHelperReturnCplusSkeleton() writes the return value part in skeleton + * HELPER: writeMethodHelperReturnCplusSkeleton() writes the return statement part in skeleton */ private void writeMethodHelperReturnCplusSkeleton(InterfaceDecl intDecl, List methParams, List methPrmTypes, String method, boolean isCallbackMethod, String callbackType, @@ -3672,7 +3661,7 @@ public class IoTCompiler { /** - * HELPER: writeStructMembersCplusSkeleton() writes parameters of struct + * HELPER: writeStructMembersCplusSkeleton() writes member parameters of struct */ private void writeStructMembersCplusSkeleton(String simpleType, String paramType, String param, String method, InterfaceDecl intDecl, int iVar) { @@ -3722,7 +3711,7 @@ public class IoTCompiler { /** - * HELPER: writeStructMembersInitCplusSkeleton() writes parameters of struct + * HELPER: writeStructMembersInitCplusSkeleton() writes member parameters initialization of struct */ private void writeStructMembersInitCplusSkeleton(InterfaceDecl intDecl, List methParams, List methPrmTypes, String method) { @@ -3762,7 +3751,7 @@ public class IoTCompiler { /** - * HELPER: writeStructReturnCplusSkeleton() writes parameters if struct is present + * HELPER: writeStructReturnCplusSkeleton() writes parameters of struct for return statement */ private void writeStructReturnCplusSkeleton(String simpleType, String retType) { @@ -3918,7 +3907,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodHelperStructSetupCplusSkeleton() writes the method helper of the struct in skeleton class + * HELPER: writeMethodHelperStructSetupCplusSkeleton() writes the method helper of struct in skeleton class */ private void writeMethodHelperStructSetupCplusSkeleton(Collection methods, InterfaceDecl intDecl) { @@ -3953,7 +3942,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodHelperStructSetupCplusCallbackSkeleton() writes the method helper of the struct in skeleton class + * HELPER: writeMethodHelperStructSetupCplusCallbackSkeleton() writes the method helper of struct in skeleton class */ private void writeMethodHelperStructSetupCplusCallbackSkeleton(Collection methods, InterfaceDecl intDecl) { @@ -4177,7 +4166,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodHelperCplusCallbackSkeleton() writes the method helper of the callback skeleton class + * HELPER: writeMethodHelperCplusCallbackSkeleton() writes the method helper of callback skeleton class */ private void writeMethodHelperCplusCallbackSkeleton(Collection methods, InterfaceDecl intDecl, Set callbackClasses) { @@ -4236,7 +4225,7 @@ public class IoTCompiler { /** - * HELPER: writeCplusCallbackWaitRequestInvokeMethod() writes the main loop of the skeleton class + * HELPER: writeCplusCallbackWaitRequestInvokeMethod() writes the request invoke method of the skeleton callback class */ private void writeCplusCallbackWaitRequestInvokeMethod(Collection methods, InterfaceDecl intDecl, boolean callbackExist) { @@ -4281,7 +4270,6 @@ public class IoTCompiler { } - /** * generateCplusCallbackSkeletonClass() generate callback skeletons based on the methods list in C++ */ @@ -4365,35 +4353,6 @@ public class IoTCompiler { } - /** - * generateReturnStmt() generate return statement based on methType - */ - public String generateReturnStmt(String methType) { - - // Generate dummy returns for now - if (methType.equals("short")|| - methType.equals("int") || - methType.equals("long") || - methType.equals("float")|| - methType.equals("double")) { - - return "1"; - } else if ( methType.equals("String")) { - - return "\"a\""; - } else if ( methType.equals("char") || - methType.equals("byte")) { - - return "\'a\'"; - } else if ( methType.equals("boolean")) { - - return "true"; - } else { - return "null"; - } - } - - /** * setDirectory() sets a new directory for stub files */ @@ -4447,7 +4406,7 @@ public class IoTCompiler { /**================ - * Helper functions + * Basic helper functions **================ */ boolean newline=true; @@ -4476,6 +4435,9 @@ public class IoTCompiler { } + /** + * A collection of methods with print-to-file functionality + */ private void println(String str) { if (newline) { int tab = tablevel; @@ -4546,7 +4508,7 @@ public class IoTCompiler { } - // Return parameter category, i.e. PRIMITIVES, NONPRIMITIVES, or USERDEFINED + // Return parameter category, i.e. PRIMITIVES, NONPRIMITIVES, USERDEFINED, ENUM, or STRUCT private ParamCategory getParamCategory(String paramType) { if (mapPrimitives.containsKey(paramType)) { @@ -4564,7 +4526,7 @@ public class IoTCompiler { // Return full class name for non-primitives to generate Java import statements - // e.g. java.util.Set for Set, java.util.Map for Map + // e.g. java.util.Set for Set private String getNonPrimitiveJavaClass(String paramNonPrimitives) { return mapNonPrimitivesJava.get(paramNonPrimitives); @@ -4572,7 +4534,7 @@ public class IoTCompiler { // Return full class name for non-primitives to generate Cplus include statements - // e.g. #include for Set, #include for Map + // e.g. #include for Set private String getNonPrimitiveCplusClass(String paramNonPrimitives) { return mapNonPrimitivesCplus.get(paramNonPrimitives); @@ -4622,7 +4584,7 @@ public class IoTCompiler { } - // Generate a set of standard classes for import statements + // Combine all classes for import statements private List getAllLibClasses(Collection stdLibClasses, Collection libClasses) { List allLibClasses = new ArrayList(stdLibClasses); @@ -4632,7 +4594,6 @@ public class IoTCompiler { allLibClasses.add(str); } } - return allLibClasses; } @@ -4844,6 +4805,7 @@ public class IoTCompiler { } + // Print import statements into file private void printImportStatements(Collection importClasses) { for(String cls : importClasses) { @@ -4852,6 +4814,7 @@ public class IoTCompiler { } + // Print include statements into file private void printIncludeStatements(Collection includeClasses) { for(String cls : includeClasses) { @@ -4907,6 +4870,7 @@ public class IoTCompiler { } + // Checks and gets type in C++ private String checkAndGetCplusType(String paramType) { if (getParamCategory(paramType) == ParamCategory.PRIMITIVES) { @@ -5026,7 +4990,8 @@ public class IoTCompiler { } - // Is array? For return type we put the return type as input parameter + // Is array? + // For return type we use retType as input parameter private boolean isArray(String param) { // Check for array declaration @@ -5184,5 +5149,3 @@ public class IoTCompiler { } - - -- 2.34.1