qapi-visit: Rearrange code a bit
Move gen_visit_decl() to a better place. Inline generate_visit_struct_body(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Daniel P. Berrange <berrange@redhat.com> Message-Id: <1442401589-24189-15-git-send-email-armbru@redhat.com>
This commit is contained in:
parent
e98859a9b9
commit
60f8546acd
@ -19,6 +19,16 @@ implicit_structs_seen = set()
|
|||||||
struct_fields_seen = set()
|
struct_fields_seen = set()
|
||||||
|
|
||||||
|
|
||||||
|
def gen_visit_decl(name, scalar=False):
|
||||||
|
c_type = c_name(name) + ' *'
|
||||||
|
if not scalar:
|
||||||
|
c_type += '*'
|
||||||
|
return mcgen('''
|
||||||
|
void visit_type_%(c_name)s(Visitor *m, %(c_type)sobj, const char *name, Error **errp);
|
||||||
|
''',
|
||||||
|
c_name=c_name(name), c_type=c_type)
|
||||||
|
|
||||||
|
|
||||||
def gen_visit_implicit_struct(typ):
|
def gen_visit_implicit_struct(typ):
|
||||||
if typ in implicit_structs_seen:
|
if typ in implicit_structs_seen:
|
||||||
return ''
|
return ''
|
||||||
@ -117,12 +127,17 @@ out:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def gen_visit_struct_body(name):
|
def gen_visit_struct(name, base, members):
|
||||||
|
ret = gen_visit_struct_fields(name, base, members)
|
||||||
|
|
||||||
# FIXME: if *obj is NULL on entry, and visit_start_struct() assigns to
|
# FIXME: if *obj is NULL on entry, and visit_start_struct() assigns to
|
||||||
# *obj, but then visit_type_FOO_fields() fails, we should clean up *obj
|
# *obj, but then visit_type_FOO_fields() fails, we should clean up *obj
|
||||||
# rather than leaving it non-NULL. As currently written, the caller must
|
# rather than leaving it non-NULL. As currently written, the caller must
|
||||||
# call qapi_free_FOO() to avoid a memory leak of the partial FOO.
|
# call qapi_free_FOO() to avoid a memory leak of the partial FOO.
|
||||||
ret = mcgen('''
|
ret += mcgen('''
|
||||||
|
|
||||||
|
void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error **errp)
|
||||||
|
{
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
|
||||||
visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err);
|
visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err);
|
||||||
@ -133,25 +148,10 @@ def gen_visit_struct_body(name):
|
|||||||
visit_end_struct(m, &err);
|
visit_end_struct(m, &err);
|
||||||
}
|
}
|
||||||
error_propagate(errp, err);
|
error_propagate(errp, err);
|
||||||
''',
|
|
||||||
name=name, c_name=c_name(name))
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def gen_visit_struct(name, base, members):
|
|
||||||
ret = gen_visit_struct_fields(name, base, members)
|
|
||||||
ret += mcgen('''
|
|
||||||
|
|
||||||
void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error **errp)
|
|
||||||
{
|
|
||||||
''',
|
|
||||||
c_name=c_name(name))
|
|
||||||
|
|
||||||
ret += gen_visit_struct_body(name)
|
|
||||||
|
|
||||||
ret += mcgen('''
|
|
||||||
}
|
}
|
||||||
''')
|
''',
|
||||||
|
name=name, c_name=c_name(name))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
@ -342,16 +342,6 @@ out:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def gen_visit_decl(name, scalar=False):
|
|
||||||
c_type = c_name(name) + ' *'
|
|
||||||
if not scalar:
|
|
||||||
c_type += '*'
|
|
||||||
return mcgen('''
|
|
||||||
void visit_type_%(c_name)s(Visitor *m, %(c_type)sobj, const char *name, Error **errp);
|
|
||||||
''',
|
|
||||||
c_name=c_name(name), c_type=c_type)
|
|
||||||
|
|
||||||
|
|
||||||
class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
|
class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.decl = None
|
self.decl = None
|
||||||
|
Loading…
Reference in New Issue
Block a user