diff Resources/CodeGeneration/stonegentool.py @ 486:8e40355a172b bgo-commands-codegen

Unit tests OK for preambles, enums and structs in both TS and C++
author bgo-osimis
date Fri, 15 Feb 2019 14:30:26 +0100
parents 772516adcbf6
children f6b7f113cf27
line wrap: on
line diff
--- a/Resources/CodeGeneration/stonegentool.py	Fri Feb 15 12:07:09 2019 +0100
+++ b/Resources/CodeGeneration/stonegentool.py	Fri Feb 15 14:30:26 2019 +0100
@@ -22,9 +22,22 @@
 12345678901234567890123456789012345678901234567890123456789012345678901234567890
 """
 
-import json
-import re
+class GeneratedCode:
+  def __init__(self):
+    self.cppPreamble = StringIO() # file-wide preamble (#include directives, comment...)
+    self.cppEnums = StringIO()
+    self.cppStructs = StringIO()
+    self.cppDispatcher = StringIO()
+    self.cppHandler = StringIO()
 
+    self.tsPreamble = StringIO() # file-wide preamble (module directives, comment...)
+    self.tsEnums = StringIO()
+    self.tsStructs = StringIO()
+    self.tsDispatcher = StringIO()
+    self.tsHandler = StringIO()
+
+  def FlattenToFiles(self,outputDir: str):
+    raise NotImplementedError()
 
 class JsonHelpers:
     """A set of utilities to perform JSON operations"""
@@ -279,10 +292,8 @@
                     genOrderQueue, structTypes, structTypes[typeName]
                 )
 
-
 def ProcessStructType_DepthFirstRecursive(
-    genOrderQueue: List[str], structTypes: Dict[str, Dict], typeDict: Dict
-) -> None:
+    genOrderQueue: List[str], structTypes: Dict[str, Dict], typeDict: Dict) -> None:
     # let's generate the code according to the
     typeName: str = typeDict["name"]
     if typeDict["kind"] != "struct":
@@ -327,9 +338,8 @@
   tsText.write("};\n\n")
   cppText.write("};\n\n")
 
-  outputStreams['ts'].write(tsText.getvalue())
-  outputStreams['cpp'].write(cppText.getvalue())
-
+  outputStreams.tsEnums.write(tsText.getvalue())
+  outputStreams.cppEnums.write(cppText.getvalue())
 
 def ProcessStructType(
   outputStreams: GeneratedCode, typeDict) -> None:
@@ -353,9 +363,8 @@
   tsText.write("};\n\n")
   cppText.write("};\n\n")
 
-  outputStreams['ts'].write(tsText.getvalue())
-  outputStreams['cpp'].write(cppText.getvalue())
-
+  outputStreams.tsStructs.write(tsText.getvalue())
+  outputStreams.cppStructs.write(cppText.getvalue())
 
 def WritePreambles(rootName: str, outputStreams: GeneratedCode) -> None:
     outputStreams.cppPreamble.write("""// autogenerated by stonegentool on %s for module %s
@@ -363,28 +372,12 @@
 #include <string>
 #include <vector>
 #include <map>
+
 """ % (time.ctime(),rootName))
 
     outputStreams.tsPreamble.write("""// autogenerated by stonegentool on %s for module %s
 """ % (time.ctime(),rootName))
 
-class GeneratedCode:
-  def __init__(self):
-    self.cppPreamble = StringIO() # file-wide preamble (#include directives, comment...)
-    self.cppEnums = StringIO()
-    self.cppStructs = StringIO()
-    self.cppDispatcher = StringIO()
-    self.cppHandler = StringIO()
-
-    self.tsPreamble = StringIO() # file-wide preamble (module directives, comment...)
-    self.tsEnums = StringIO()
-    self.tsStructs = StringIO()
-    self.tsDispatcher = StringIO()
-    self.tsHandler = StringIO()
-
-  def FlattenToFiles(self,outputDir: str):
-    raise NotImplementedError()
-
 def ProcessSchema(schema: dict) -> Tuple[str, GeneratedCode, List[str]]:
     CheckSchemaSchema(schema)
     rootName: str = schema["root_name"]