On 01/27/2016 06:54 AM, Markus Armbruster wrote: > For a simple union SU, gen_visit_union() generates a visit of its > single tag member, like this: > > visit_type_SUKind(v, "type", &(*obj)->type, &err); > > For a flat union FU with base B, it generates a visit of its base > fields: > > visit_type_B_fields(v, (B **)obj, &err); > > Instead, we can simply visit the common members using the same fields > visit function we use for structs, generated with > gen_visit_struct_fields(). This function visits the base if any, then > the local members.
I like how you've split up my gen_struct/gen_union merge into a few more steps. I'll be incorporating your patch into my v10 spin. > > For a simple union SU, visit_type_SU_fields() contains exactly the old > tag member visit, because there is no base, and the tag member is the > only member. For instance, the code generated for > qapi-schema-test.json's UserDefNativeListUnion changes like this: > > @@ -740,6 +766,19 @@ out: > error_propagate(errp, err); > } > > +static void visit_type_UserDefNativeListUnion_fields(Visitor *v, > UserDefNativeListUnion **obj, Error **errp) I may try to rewrite the commit to pick a shorter example, though :) > > As you see, the generated code grows a bit, but in practice, it's lost > in the noise: qapi-schema.json's qapi-visit.c gains roughly 1%. > > This simplification became possible with commit 441cbac "qapi-visit: > Convert to QAPISchemaVisitor, fixing bugs". It's a step towards > unifying gen_struct() and gen_union(). > > Signed-off-by: Markus Armbruster <arm...@redhat.com> > --- > scripts/qapi-visit.py | 27 ++++----------------------- > 1 file changed, 4 insertions(+), 23 deletions(-) > -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature