# HG changeset patch # User bgo-osimis # Date 1549973184 -3600 # Node ID 52549faf47ba2aa9eb5e421173b71734ccbfe00b # Parent cef55b4e6c21bcb860f5502352abaeac3ed97501 Ongoing code generation work diff -r cef55b4e6c21 -r 52549faf47ba Resources/CodeGeneration/stonegentool.py --- a/Resources/CodeGeneration/stonegentool.py Mon Feb 11 16:01:19 2019 +0100 +++ b/Resources/CodeGeneration/stonegentool.py Tue Feb 12 13:06:24 2019 +0100 @@ -1,10 +1,59 @@ from __future__ import print_function -import sys +import sys, json + +def LoadSchema(file_path : str): + with open(file_path, 'r') as fp: + obj = json.load(fp) + return obj + +class Type: + def __init__(self, canonicalTypeName:str, dependentTypes:str): + """dependent type is the list of canonical types this type depends on. + For instance, vector> depends on map + that, in turn, depends on string and int32 that, in turn, depend on + nothing""" + self.canonicalTypeName = canonicalTypeName + self.dependentTypes = dependentTypes + def getDependentTypes(self): + return self.dependentTypes + def getCppTypeName(self): + # C++: prefix map vector and string with std::map, std::vector and std::string + # replace int32 by int32_t + # replace float32 by float + # replace float64 by double + retVal : str = self.canonicalTypeName.replace("map","std::map") + retVal : str = self.canonicalTypeName.replace("vector","std::vector") + retVal : str = self.canonicalTypeName.replace("int32","int32_t") + retVal : str = self.canonicalTypeName.replace("float32","float") + retVal : str = self.canonicalTypeName.replace("float64","double") + return retVal + def getTypeScriptTypeName(self): + # TS: replace vector with Array and map with Map + # string remains string + # replace int32 by number + # replace float32 by number + # replace float64 by number + retVal : str = self.canonicalTypeName.replace("map","Map") + retVal : str = self.canonicalTypeName.replace("vector","Array") + retVal : str = self.canonicalTypeName.replace("int32","number") + retVal : str = self.canonicalTypeName.replace("float32","number") + retVal : str = self.canonicalTypeName.replace("float64","number") + retVal : str = self.canonicalTypeName.replace("bool","boolean") + return retVal + +class Schema: + def __init__(self, root_prefix : str, defined_types : List[Type]): + self.root_prefix : str = root_prefix + self.defined_types : str = defined_types + +def ProcessSchemaPaths(inputSchemas : list[str]) - - - +def ProcessSchemas(schemaPaths): + schemas = [] + for schemaPath in schemaPaths: + schemas.append(LoadSchema(schemaPath)) + return schemas if __name__ == '__main__': import argparse @@ -22,9 +71,26 @@ mode""") args = parser.parse_args() - input_schemas = args.input_schemas.split(",") - out_dir = args.out_dir + inputSchemas = args.input_schemas.split(",") + outDir = args.out_dir + + print("input schemas = " + str(inputSchemas)) + print("out dir = " + str(outDir)) + + ProcessSchemaPaths(inputSchemas) + + - print("input schemas = " + str(input_schemas)) - print("out dir = " + str(out_dir)) +################### +## ATTIC ## +################### + +# this works +if False: + obj = json.loads("""{ + "firstName": "Alice", + "lastName": "Hall", + "age": 35 + }""") + print(obj)