Mercurial > hg > orthanc-stone
changeset 474:38997ceb9bc6 bgo-commands-codegen
Ongoing work on message code generation
author | bgo-osimis |
---|---|
date | Wed, 13 Feb 2019 20:42:26 +0100 |
parents | 628941d63b8c |
children | f58fe38c8c04 |
files | Resources/CodeGeneration/stonegentool.py Resources/CodeGeneration/stonegentool_test.py Resources/CodeGeneration/test/test1.jsonc |
diffstat | 3 files changed, 99 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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()
--- 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<B>" + }, + { + "name":"ddd", + "type":"vector<D>" + } + ] + }, + { "name":"A", "kind":"struct", "fields": [