xso-proc: fix order-dependent compilation bug

The test case which is added fails to compile unless one puts the
`parent` field before the `id` field. The cause is explained somewhat by
the change, but I'll spell it out here nontheless.

Previously, the loop in `Compound::make_as_item_iter_statemachine`
assumed that the serialisation order of fields would match their
declaration order. That is not generally true: attributes must be
serialised before element content, because they must be emitted before
the element header is closed.

This change thus splits the generated states into "header" states (for
everything before the end of the element header (think `>`)) and
"body" states (for everything after and including the end of the
element header). After all fields have been processed, we can then
add the data fields of the body fields to the header states so that
they are carried through the generated state machine until they are
needed in the body.
This commit is contained in:
Jonas Schäfer 2025-04-18 10:46:09 +02:00
commit 0fd69d2ff8
3 changed files with 94 additions and 34 deletions

View file

@ -46,6 +46,9 @@ Version NEXT:
doc(hidden), to not clutter hand-written documentation with auto
generated garbage (something certain big tech companies could take
an example of, honestly).
- Fixed bug where putting an attribute field below any non-attribute
field in a struct definition would cause a compile-time error when
deriving `AsXml`.
Version 0.1.2:
2024-07-26 Jonas Schäfer <jonas@zombofant.net>