From ac0ee0286cf0145a24f8f5f33beedaf3a41245ba Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 19 Feb 2018 19:12:59 -0500 Subject: [PATCH] qapi-types: Refactor base fields output Move code from gen_union() into gen_struct_fields() in order for a later patch to share code when enumerating inherited fields for struct types. No change to generated code. Backports commit f87ab7f9bd956250c48b5c6e9b607b537fd21543 from qemu --- qemu/scripts/qapi-types.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/qemu/scripts/qapi-types.py b/qemu/scripts/qapi-types.py index aa64aaec..2ad6e008 100644 --- a/qemu/scripts/qapi-types.py +++ b/qemu/scripts/qapi-types.py @@ -49,10 +49,21 @@ def gen_struct_field(name, typ, optional): return ret -def gen_struct_fields(members): +def gen_struct_fields(local_members, base=None): ret = '' - for memb in members: + 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.name, memb.type, memb.optional) + ret += mcgen(''' + /* Own members: */ +''') + + for memb in local_members: ret += gen_struct_field(memb.name, memb.type, memb.optional) return ret @@ -122,14 +133,7 @@ struct %(c_name)s { ''', c_name=c_name(name)) if base: - ret += mcgen(''' - /* Members inherited from %(c_name)s: */ -''', - c_name=c_name(base.name)) - ret += gen_struct_fields(base.members) - ret += mcgen(''' - /* Own members: */ -''') + ret += gen_struct_fields([], base) else: ret += mcgen(''' %(c_type)s kind;