# HG changeset patch # User Alain Mazy # Date 1557992970 -7200 # Node ID 1b47f17863ba1caf6dc23107a81de115e78e055a # Parent 163ac23b8bff23a253deae8c4b92f8940623044b codegen: using an ordereddict loader instead of sort the keys -> the delcared ordered in the yaml is preserved in the generated code which is more meaningfull than the alphabetical order diff -r 163ac23b8bff -r 1b47f17863ba Resources/CodeGeneration/README.md --- a/Resources/CodeGeneration/README.md Thu May 16 09:25:42 2019 +0200 +++ b/Resources/CodeGeneration/README.md Thu May 16 09:49:30 2019 +0200 @@ -17,4 +17,4 @@ source ~/apps/emsdk/emsdk_env.sh -Install Python and the following packages `pip install pyyaml jinja2` +Install Python and the following packages `pip install pyyaml yamlloader jinja2` diff -r 163ac23b8bff -r 1b47f17863ba Resources/CodeGeneration/stonegentool.py --- a/Resources/CodeGeneration/stonegentool.py Thu May 16 09:25:42 2019 +0200 +++ b/Resources/CodeGeneration/stonegentool.py Thu May 16 09:49:30 2019 +0200 @@ -7,6 +7,7 @@ from io import StringIO import time import datetime +import yamlloader """ 1 2 3 4 5 6 7 @@ -186,7 +187,6 @@ RegisterTemplateFunction(template,NeedsCppConstruction) RegisterTemplateFunction(template, DefaultValueToTs) RegisterTemplateFunction(template, DefaultValueToCpp) - RegisterTemplateFunction(template, sorted) return template def MakeTemplateFromFile(templateFileName): @@ -533,7 +533,7 @@ if not (nextCh == ' ' or nextCh == '\n'): lineNumber = schemaText.count("\n",0,i) + 1 raise RuntimeError("Error at line " + str(lineNumber) + " in the schema: colons must be followed by a space or a newline!") - schema = yaml.load(schemaText, Loader = yaml.SafeLoader) + schema = yaml.load(schemaText, Loader = yamlloader.ordereddict.SafeLoader) return schema def GetTemplatingDictFromSchemaFilename(fn): diff -r 163ac23b8bff -r 1b47f17863ba Resources/CodeGeneration/template.in.h.j2 --- a/Resources/CodeGeneration/template.in.h.j2 Thu May 16 09:25:42 2019 +0200 +++ b/Resources/CodeGeneration/template.in.h.j2 Thu May 16 09:49:30 2019 +0200 @@ -394,9 +394,9 @@ struct {{struct['name']}} { -{% if struct %}{% if struct['fields'] %}{% for key in sorted(struct['fields']) %} {{CanonToCpp(struct['fields'][key]['type'])}} {{key}}; +{% if struct %}{% if struct['fields'] %}{% for key in struct['fields'] %} {{CanonToCpp(struct['fields'][key]['type'])}} {{key}}; {% endfor %}{% endif %}{% endif %} - {{struct['name']}}({% if struct %}{% if struct['fields'] %}{% for key in sorted(struct['fields']) %}{{CanonToCpp(struct['fields'][key]['type'])}} {{key}} = {% if struct['fields'][key]['defaultValue'] %}{{DefaultValueToCpp(rootName,enums,struct['fields'][key])}} {%else%} {{CanonToCpp(struct['fields'][key]['type'])}}() {%endif%} {{ ", " if not loop.last }}{% endfor %}{% endif %}{% endif %}) + {{struct['name']}}({% if struct %}{% if struct['fields'] %}{% for key in struct['fields'] %}{{CanonToCpp(struct['fields'][key]['type'])}} {{key}} = {% if struct['fields'][key]['defaultValue'] %}{{DefaultValueToCpp(rootName,enums,struct['fields'][key])}} {%else%} {{CanonToCpp(struct['fields'][key]['type'])}}() {%endif%} {{ ", " if not loop.last }}{% endfor %}{% endif %}{% endif %}) { {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} this->{{key}} = {{key}}; {% endfor %}{% endif %}{% endif %} }