# HG changeset patch # User bgo-osimis # Date 1550086946 -3600 # Node ID 38997ceb9bc634e54e4ce1bbf6e084eb1aa22f9a # Parent 628941d63b8c1dc9340c46350a14a6619956751b Ongoing work on message code generation diff -r 628941d63b8c -r 38997ceb9bc6 Resources/CodeGeneration/stonegentool.py --- a/Resources/CodeGeneration/stonegentool.py Wed Feb 13 12:07:00 2019 +0100 +++ b/Resources/CodeGeneration/stonegentool.py Wed Feb 13 20:42:26 2019 +0100 @@ -223,9 +223,8 @@ # if we reach this point, it means the type is NOT a struct or an enum. # it is another (non directly user-defined) type that we must parse and # create. Let's do it! - (isTemplate,_,parameters) = ParseTemplateType(typeName) + (isTemplate,_,dependentTypeNames) = ParseTemplateType(typeName) if isTemplate: - dependentTypeNames : List[str] = SplitListOfTypes(parameters) for dependentTypeName in dependentTypeNames: # childAncestors = ancestors.copy() NO TEMPLATE ANCESTOR!!! # childAncestors.append(typeName) @@ -248,13 +247,53 @@ for typeField in typeFields: ancestors = [typeName] ProcessTypeTree(ancestors, genOrderQueue - , structTypes, typeField['name']) + , structTypes, typeField['type']) # now we're pretty sure our dependencies have been processed, # we can start marking our code for generation - genOrderQueue.append(typeName) + genOrderQueue.add(typeName) + +def ProcessEnumerationType(definedType) -> (str,str): + print(f"About to process enumeration: {definedType['name']}") + tsText : str = """import blah + + enum PROUT + { + value1 + value2 + }""" + + cppText : str = """import blah + + enum PROUT + { + value1 + value2 + }""" + + return (tsText,cppText) -def ProcessEnumerationType(processedTypes, definedType) -> None: +def ProcessStructType(typeDict) -> (str,str): print(f"About to process enumeration: {definedType['name']}") + tsText : str = """import blah + + class PROUT + { + public value1 : Type1 + public value2 : Type2 + }""" + + cppText : str = """import blah + + class PROUT + { + public: + Type1: value1 + Type2: value2 + }""" + + return (tsText,cppText) + + def ProcessSchema(schema : dict) -> None: CheckSchemaSchema(schema) @@ -272,17 +311,23 @@ # the order here is the generation order for definedType in definedTypes: if definedType['kind'] == 'enum': - ProcessEnumerationType(genOrderQueue, definedType) + ProcessEnumerationType(definedType) + + for definedType in definedTypes: + if definedType['kind'] == 'struct': + structTypes[definedType['name']] = definedType # the order here is NOT the generation order: the types # will be processed according to their dependency graph for definedType in definedTypes: if definedType['kind'] == 'struct': - structTypes[definedType['name']] = definedType ProcessStructType_DepthFirstRecursive(genOrderQueue,structTypes, definedType) - print(f"genOrderQueue = {genOrderQueue}") + for i in range(len(genOrderQueue)) + typeName = genOrderQueue[i] + typeDict = structTypes[typeName] + ProcessStructType(typeDict) if __name__ == '__main__': import argparse diff -r 628941d63b8c -r 38997ceb9bc6 Resources/CodeGeneration/stonegentool_test.py --- a/Resources/CodeGeneration/stonegentool_test.py Wed Feb 13 12:07:00 2019 +0100 +++ b/Resources/CodeGeneration/stonegentool_test.py Wed Feb 13 20:42:26 2019 +0100 @@ -1,4 +1,5 @@ -from stonegentool import EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema +from stonegentool import \ +EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema,ProcessSchema import unittest import os @@ -85,8 +86,36 @@ obj = LoadSchema(fn) self.assertRaises(Exception,CheckSchemaSchema,obj) + def test_GenOrderQueue(self): + fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc') + obj = LoadSchema(fn) + genOrderQueue,structTypes = ProcessSchema(obj) + print(f"genOrderQueue = {genOrderQueue}") + print("") + def test_GenerateTypeScriptEnumeration(self): + pass + def test_GenerateCppEnumeration(self): + pass + + def test_GenerateTypeScriptClasses(self): + pass + + def test_GenerateCppClasses(self): + pass + + def test_GenerateTypeScriptHandlerInterface(self): + pass + + def test_GenerateCppHandlerInterface(self): + pass + + def test_GenerateTypeScriptDispatcher(self): + pass + + def test_GenerateCppDispatcher(self): + pass # def test(self): # s = 'hello world' @@ -96,4 +125,5 @@ # s.split(2) if __name__ == '__main__': - unittest.main() \ No newline at end of file + print("") + unittest.main() diff -r 628941d63b8c -r 38997ceb9bc6 Resources/CodeGeneration/test/test1.jsonc --- a/Resources/CodeGeneration/test/test1.jsonc Wed Feb 13 12:07:00 2019 +0100 +++ b/Resources/CodeGeneration/test/test1.jsonc Wed Feb 13 20:42:26 2019 +0100 @@ -20,6 +20,20 @@ ] }, { + "name":"C", + "kind":"struct", + "fields": [ + { + "name":"someBs", + "type":"vector" + }, + { + "name":"ddd", + "type":"vector" + } + ] + }, + { "name":"A", "kind":"struct", "fields": [