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>
This commit is contained in:
Eric Blake 2015-11-18 01:52:38 -07:00 committed by Markus Armbruster
parent 570cd8d119
commit 7d9586f900

View File

@ -36,37 +36,18 @@ 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))
return ret
def gen_struct_fields(local_members, base):
ret = ''
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 += mcgen('''
/* Own members: */
''')
for memb in local_members:
ret += gen_struct_field(memb)
c_type=memb.type.c_type(), c_name=c_name(memb.name))
return ret
@ -77,7 +58,16 @@ struct %(c_name)s {
''',
c_name=c_name(name))
ret += gen_struct_fields(members, base)
if base:
ret += mcgen('''
/* Members inherited from %(c_name)s: */
''',
c_name=base.c_name())
ret += gen_struct_fields(base.members)
ret += mcgen('''
/* Own members: */
''')
ret += gen_struct_fields(members)
if variants:
ret += gen_variants(variants)