Mercurial > hg > orthanc-stone
comparison Resources/CodeGeneration/stonegentool.py @ 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 |
comparison
equal
deleted
inserted
replaced
473:628941d63b8c | 474:38997ceb9bc6 |
---|---|
221 | 221 |
222 if not (typeName in genOrderQueue): | 222 if not (typeName in genOrderQueue): |
223 # if we reach this point, it means the type is NOT a struct or an enum. | 223 # if we reach this point, it means the type is NOT a struct or an enum. |
224 # it is another (non directly user-defined) type that we must parse and | 224 # it is another (non directly user-defined) type that we must parse and |
225 # create. Let's do it! | 225 # create. Let's do it! |
226 (isTemplate,_,parameters) = ParseTemplateType(typeName) | 226 (isTemplate,_,dependentTypeNames) = ParseTemplateType(typeName) |
227 if isTemplate: | 227 if isTemplate: |
228 dependentTypeNames : List[str] = SplitListOfTypes(parameters) | |
229 for dependentTypeName in dependentTypeNames: | 228 for dependentTypeName in dependentTypeNames: |
230 # childAncestors = ancestors.copy() NO TEMPLATE ANCESTOR!!! | 229 # childAncestors = ancestors.copy() NO TEMPLATE ANCESTOR!!! |
231 # childAncestors.append(typeName) | 230 # childAncestors.append(typeName) |
232 ProcessTypeTree(ancestors, genOrderQueue, | 231 ProcessTypeTree(ancestors, genOrderQueue, |
233 structTypes, dependentTypeName) | 232 structTypes, dependentTypeName) |
246 "type '{typeName}'") | 245 "type '{typeName}'") |
247 typeFields : List[Dict] = typeDict['fields'] | 246 typeFields : List[Dict] = typeDict['fields'] |
248 for typeField in typeFields: | 247 for typeField in typeFields: |
249 ancestors = [typeName] | 248 ancestors = [typeName] |
250 ProcessTypeTree(ancestors, genOrderQueue | 249 ProcessTypeTree(ancestors, genOrderQueue |
251 , structTypes, typeField['name']) | 250 , structTypes, typeField['type']) |
252 # now we're pretty sure our dependencies have been processed, | 251 # now we're pretty sure our dependencies have been processed, |
253 # we can start marking our code for generation | 252 # we can start marking our code for generation |
254 genOrderQueue.append(typeName) | 253 genOrderQueue.add(typeName) |
255 | 254 |
256 def ProcessEnumerationType(processedTypes, definedType) -> None: | 255 def ProcessEnumerationType(definedType) -> (str,str): |
257 print(f"About to process enumeration: {definedType['name']}") | 256 print(f"About to process enumeration: {definedType['name']}") |
257 tsText : str = """import blah | |
258 | |
259 enum PROUT | |
260 { | |
261 value1 | |
262 value2 | |
263 }""" | |
264 | |
265 cppText : str = """import blah | |
266 | |
267 enum PROUT | |
268 { | |
269 value1 | |
270 value2 | |
271 }""" | |
272 | |
273 return (tsText,cppText) | |
274 | |
275 def ProcessStructType(typeDict) -> (str,str): | |
276 print(f"About to process enumeration: {definedType['name']}") | |
277 tsText : str = """import blah | |
278 | |
279 class PROUT | |
280 { | |
281 public value1 : Type1 | |
282 public value2 : Type2 | |
283 }""" | |
284 | |
285 cppText : str = """import blah | |
286 | |
287 class PROUT | |
288 { | |
289 public: | |
290 Type1: value1 | |
291 Type2: value2 | |
292 }""" | |
293 | |
294 return (tsText,cppText) | |
295 | |
296 | |
258 | 297 |
259 def ProcessSchema(schema : dict) -> None: | 298 def ProcessSchema(schema : dict) -> None: |
260 CheckSchemaSchema(schema) | 299 CheckSchemaSchema(schema) |
261 rootName : str = schema['root_name'] | 300 rootName : str = schema['root_name'] |
262 definedTypes : list = schema['types'] | 301 definedTypes : list = schema['types'] |
270 structTypes : Dict[str,Dict] = {} | 309 structTypes : Dict[str,Dict] = {} |
271 | 310 |
272 # the order here is the generation order | 311 # the order here is the generation order |
273 for definedType in definedTypes: | 312 for definedType in definedTypes: |
274 if definedType['kind'] == 'enum': | 313 if definedType['kind'] == 'enum': |
275 ProcessEnumerationType(genOrderQueue, definedType) | 314 ProcessEnumerationType(definedType) |
315 | |
316 for definedType in definedTypes: | |
317 if definedType['kind'] == 'struct': | |
318 structTypes[definedType['name']] = definedType | |
276 | 319 |
277 # the order here is NOT the generation order: the types | 320 # the order here is NOT the generation order: the types |
278 # will be processed according to their dependency graph | 321 # will be processed according to their dependency graph |
279 for definedType in definedTypes: | 322 for definedType in definedTypes: |
280 if definedType['kind'] == 'struct': | 323 if definedType['kind'] == 'struct': |
281 structTypes[definedType['name']] = definedType | |
282 ProcessStructType_DepthFirstRecursive(genOrderQueue,structTypes, | 324 ProcessStructType_DepthFirstRecursive(genOrderQueue,structTypes, |
283 definedType) | 325 definedType) |
284 | 326 |
285 print(f"genOrderQueue = {genOrderQueue}") | 327 for i in range(len(genOrderQueue)) |
328 typeName = genOrderQueue[i] | |
329 typeDict = structTypes[typeName] | |
330 ProcessStructType(typeDict) | |
286 | 331 |
287 if __name__ == '__main__': | 332 if __name__ == '__main__': |
288 import argparse | 333 import argparse |
289 parser = argparse.ArgumentParser( | 334 parser = argparse.ArgumentParser( |
290 usage = """stonegentool.py [-h] [-o OUT_DIR] [-v] input_schemas | 335 usage = """stonegentool.py [-h] [-o OUT_DIR] [-v] input_schemas |