diff options
author | Eric Blake <eblake@redhat.com> | 2015-11-18 01:52:38 -0700 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-12-17 08:21:26 +0100 |
commit | 7d9586f900a9043025866f84c096b1842b0bbbf6 (patch) | |
tree | 24b265803903fc8db3f78244064ce557362e4d83 | |
parent | 570cd8d1194cf68f7c9948971e52e47f20855a77 (diff) |
qapi-types: Simplify gen_struct_field[s]
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 <eblake@redhat.com>
Message-Id: <1447836791-369-4-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
-rw-r--r-- | scripts/qapi-types.py | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 403768b89f..2f2f7dfd80 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) |