Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kxml_compiler]Simplify the generated code for single sequence child elements #21

Open
martonmiklos opened this issue Jan 16, 2019 · 4 comments
Assignees
Labels
kxml_compiler kxml_compiler

Comments

@martonmiklos
Copy link
Collaborator

martonmiklos commented Jan 16, 2019

Hi guys,

I am have an XSD generated code where there are a lot elements which have only have one sequence type child (and no attributes).
Example:
Library -> Symbols -> Symbol::List

In this example (I think) it would be very convenient if the Symbol::List could be accessed directly from the Library itself.
(Currently I access them with

lib->symbols().symbolList()
).

I have implemented it in my simplify_single_child_lists:
https://github.com/cornelius/kode/compare/master...martonmiklos:simplify_single_child_lists?expand=1

If you have a bit time and find this feature useful please take a look on it.
Any review comment is welcome!

@dfaure-kdab
Copy link
Collaborator

I have to ask... how about simplifying the XSD instead? ;-)

Also, this means that if the Symbols element is modified later to gain attributes or other children, the existing code won't compile anymore... which breaks the X in XML (extensible).

@martonmiklos
Copy link
Collaborator Author

Well I am generating code from XSD for an existing XML file format.

If attributes/childs added to the parsed XML the parser (generated with this simplified method) will still parse the XML, just leaving out the new elements/attributes. BTW. the current code has the same scenario.

If new attributes/childs added to the schema the generated code will be the same as it is generated by the current code.

@dfaure-kdab
Copy link
Collaborator

What I mean is:

  • Today Symbols has no attributes, with your patch, you write C++ code that says lib->symbolList()
  • Next month someone adds an attribute, the simplification can no longer be done, this C++ code doesn't compile anymore.

Without the patch, the code is lib->symbols().symbolList() in both cases, so it keeps compiling.

@martonmiklos
Copy link
Collaborator Author

martonmiklos commented Jan 17, 2019

Ah I understand your concern now!

The patch adds this feature together with a command line option (which is disabled by default).

In my use case I am parsing XML files generated with an existing software where the format of the mentioned sections will unlikely to be changed. It might be the case that someone else has the similar needs.

What do you think shall I merge it upstream or not?

@martonmiklos martonmiklos added the kxml_compiler kxml_compiler label Dec 5, 2019
@martonmiklos martonmiklos self-assigned this Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kxml_compiler kxml_compiler
Projects
None yet
Development

No branches or pull requests

2 participants