changeset 469:52549faf47ba bgo-commands-codegen

Ongoing code generation work
author bgo-osimis
date Tue, 12 Feb 2019 13:06:24 +0100
parents cef55b4e6c21
children db093eb6b29d
files Resources/CodeGeneration/stonegentool.py
diffstat 1 files changed, 74 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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<map<string,int32>> depends on map<string,int32>
+       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)