From: Eric Blake <ebl...@redhat.com> Simplify gen_struct_fields() back to a single iteration over a list of fields (like it was prior to commit f87ab7f9), by moving the generated comments to gen_object(). Then, inline gen_struct_field() into its only caller.
Signed-off-by: Eric Blake <ebl...@redhat.com> Message-Id: <1447836791-369-4-git-send-email-ebl...@redhat.com> Signed-off-by: Markus Armbruster <arm...@redhat.com> --- scripts/qapi-types.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 403768b..2f2f7df 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -36,48 +36,38 @@ struct %(c_name)s { c_name=c_name(name), c_type=element_type.c_type()) -def gen_struct_field(member): +def gen_struct_fields(members): ret = '' - - if member.optional: - ret += mcgen(''' + for memb in members: + if memb.optional: + ret += mcgen(''' bool has_%(c_name)s; ''', - c_name=c_name(member.name)) - ret += mcgen(''' + c_name=c_name(memb.name)) + ret += mcgen(''' %(c_type)s %(c_name)s; ''', - c_type=member.type.c_type(), c_name=c_name(member.name)) + c_type=memb.type.c_type(), c_name=c_name(memb.name)) return ret -def gen_struct_fields(local_members, base): - ret = '' +def gen_object(name, base, members, variants): + ret = mcgen(''' + +struct %(c_name)s { +''', + c_name=c_name(name)) if base: ret += mcgen(''' /* Members inherited from %(c_name)s: */ ''', c_name=base.c_name()) - for memb in base.members: - ret += gen_struct_field(memb) + ret += gen_struct_fields(base.members) ret += mcgen(''' /* Own members: */ ''') - - for memb in local_members: - ret += gen_struct_field(memb) - return ret - - -def gen_object(name, base, members, variants): - ret = mcgen(''' - -struct %(c_name)s { -''', - c_name=c_name(name)) - - ret += gen_struct_fields(members, base) + ret += gen_struct_fields(members) if variants: ret += gen_variants(variants) -- 2.4.3