提交 12f254fd 编写于 作者: E Eric Blake 提交者: Markus Armbruster

qapi: Inline gen_visit_members() into lone caller

Commit 82ca8e46 noticed that we had multiple implementations of
visiting every member of a struct, and consolidated it into
gen_visit_fields() (now gen_visit_members()) with enough
parameters to cater to slight differences between the clients.
But recent exposure of implicit types has meant that we are now
down to a single use of that method, so we can clean up the
unused conditionals and just inline it into the remaining
caller: gen_visit_object_members().

Likewise, gen_err_check() no longer needs optional parameters,
as the lone use of non-defaults was via gen_visit_members().

No change to generated code.
Suggested-by: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NEric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-11-git-send-email-eblake@redhat.com>
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
上级 c1ff0e6c
...@@ -51,7 +51,24 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) ...@@ -51,7 +51,24 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
c_type=base.c_name()) c_type=base.c_name())
ret += gen_err_check() ret += gen_err_check()
ret += gen_visit_members(members, prefix='obj->') for memb in members:
if memb.optional:
ret += mcgen('''
if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) {
''',
name=memb.name, c_name=c_name(memb.name))
push_indent()
ret += mcgen('''
visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, &err);
''',
c_type=memb.type.c_name(), name=memb.name,
c_name=c_name(memb.name))
ret += gen_err_check()
if memb.optional:
pop_indent()
ret += mcgen('''
}
''')
if variants: if variants:
ret += mcgen(''' ret += mcgen('''
...@@ -90,8 +107,8 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) ...@@ -90,8 +107,8 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
} }
''') ''')
# 'goto out' produced for base, by gen_visit_members() for each member, # 'goto out' produced for base, for each member, and if variants were
# and if variants were present # present
if base or members or variants: if base or members or variants:
ret += mcgen(''' ret += mcgen('''
......
...@@ -1657,54 +1657,12 @@ def gen_params(arg_type, extra): ...@@ -1657,54 +1657,12 @@ def gen_params(arg_type, extra):
return ret return ret
def gen_err_check(label='out', skiperr=False): def gen_err_check():
if skiperr:
return ''
return mcgen(''' return mcgen('''
if (err) { if (err) {
goto %(label)s; goto out;
}
''',
label=label)
def gen_visit_members(members, prefix='', need_cast=False, skiperr=False,
label='out'):
ret = ''
if skiperr:
errparg = 'NULL'
else:
errparg = '&err'
for memb in members:
if memb.optional:
ret += mcgen('''
if (visit_optional(v, "%(name)s", &%(prefix)shas_%(c_name)s)) {
''',
prefix=prefix, c_name=c_name(memb.name),
name=memb.name)
push_indent()
# Ugly: sometimes we need to cast away const
if need_cast and memb.type.name == 'str':
cast = '(char **)'
else:
cast = ''
ret += mcgen('''
visit_type_%(c_type)s(v, "%(name)s", %(cast)s&%(prefix)s%(c_name)s, %(errp)s);
''',
c_type=memb.type.c_name(), prefix=prefix, cast=cast,
c_name=c_name(memb.name), name=memb.name,
errp=errparg)
ret += gen_err_check(skiperr=skiperr, label=label)
if memb.optional:
pop_indent()
ret += mcgen('''
} }
''') ''')
return ret
# #
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册