2015-08-21 07:04:50 +00:00
|
|
|
#
|
|
|
|
# QAPI visitor generator
|
|
|
|
#
|
|
|
|
# Copyright IBM, Corp. 2011
|
2018-02-19 18:08:37 +00:00
|
|
|
# Copyright (C) 2014-2015 Red Hat, Inc.
|
2015-08-21 07:04:50 +00:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
# Michael Roth <mdroth@linux.vnet.ibm.com>
|
|
|
|
# Markus Armbruster <armbru@redhat.com>
|
|
|
|
#
|
|
|
|
# This work is licensed under the terms of the GNU GPL, version 2.
|
|
|
|
# See the COPYING file in the top-level directory.
|
|
|
|
|
|
|
|
from ordereddict import OrderedDict
|
|
|
|
from qapi import *
|
|
|
|
import re
|
|
|
|
|
|
|
|
implicit_structs = []
|
|
|
|
|
|
|
|
def generate_visit_implicit_struct(type):
|
|
|
|
global implicit_structs
|
|
|
|
if type in implicit_structs:
|
|
|
|
return ''
|
|
|
|
implicit_structs.append(type)
|
|
|
|
return mcgen('''
|
|
|
|
|
|
|
|
static void visit_type_implicit_%(c_type)s(Visitor *m, %(c_type)s **obj, Error **errp)
|
|
|
|
{
|
|
|
|
Error *err = NULL;
|
|
|
|
|
|
|
|
visit_start_implicit_struct(m, (void **)obj, sizeof(%(c_type)s), &err);
|
|
|
|
if (!err) {
|
|
|
|
visit_type_%(c_type)s_fields(m, obj, errp);
|
2018-02-19 17:58:24 +00:00
|
|
|
visit_end_implicit_struct(m);
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
error_propagate(errp, err);
|
|
|
|
}
|
|
|
|
''',
|
|
|
|
c_type=type_name(type))
|
|
|
|
|
2018-02-19 19:34:13 +00:00
|
|
|
def generate_visit_struct_fields(name, members, base = None):
|
2015-08-21 07:04:50 +00:00
|
|
|
ret = ''
|
|
|
|
|
|
|
|
if base:
|
|
|
|
ret += generate_visit_implicit_struct(base)
|
|
|
|
|
|
|
|
ret += mcgen('''
|
|
|
|
|
2018-02-19 19:34:13 +00:00
|
|
|
static void visit_type_%(name)s_fields(Visitor *m, %(name)s **obj, Error **errp)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
|
|
|
Error *err = NULL;
|
|
|
|
''',
|
2018-02-19 20:03:31 +00:00
|
|
|
name=c_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
push_indent()
|
|
|
|
|
|
|
|
if base:
|
|
|
|
ret += mcgen('''
|
2018-02-19 19:34:13 +00:00
|
|
|
visit_type_implicit_%(type)s(m, &(*obj)->%(c_name)s, &err);
|
2015-08-21 07:04:50 +00:00
|
|
|
if (err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
''',
|
2018-02-19 19:44:59 +00:00
|
|
|
type=type_name(base), c_name=c_name('base'))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2018-02-19 19:28:44 +00:00
|
|
|
for argname, argentry, optional in parse_args(members):
|
2015-08-21 07:04:50 +00:00
|
|
|
if optional:
|
|
|
|
ret += mcgen('''
|
2018-02-19 19:34:13 +00:00
|
|
|
visit_optional(m, &(*obj)->has_%(c_name)s, "%(name)s", &err);
|
|
|
|
if (!err && (*obj)->has_%(c_name)s) {
|
2015-08-21 07:04:50 +00:00
|
|
|
''',
|
2018-02-19 19:44:59 +00:00
|
|
|
c_name=c_name(argname), name=argname)
|
2015-08-21 07:04:50 +00:00
|
|
|
push_indent()
|
|
|
|
|
2018-02-19 19:28:44 +00:00
|
|
|
ret += mcgen('''
|
2018-02-19 19:34:13 +00:00
|
|
|
visit_type_%(type)s(m, &(*obj)->%(c_name)s, "%(name)s", &err);
|
2015-08-21 07:04:50 +00:00
|
|
|
''',
|
2018-02-19 19:44:59 +00:00
|
|
|
type=type_name(argentry), c_name=c_name(argname),
|
2018-02-19 19:28:44 +00:00
|
|
|
name=argname)
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
if optional:
|
|
|
|
pop_indent()
|
|
|
|
ret += mcgen('''
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
ret += mcgen('''
|
|
|
|
if (err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
|
|
|
|
pop_indent()
|
|
|
|
if re.search('^ *goto out\\;', ret, re.MULTILINE):
|
|
|
|
ret += mcgen('''
|
|
|
|
|
|
|
|
out:
|
|
|
|
''')
|
|
|
|
ret += mcgen('''
|
|
|
|
error_propagate(errp, err);
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
def generate_visit_struct_body(name):
|
2015-08-21 07:04:50 +00:00
|
|
|
ret = mcgen('''
|
|
|
|
Error *err = NULL;
|
|
|
|
|
2018-02-19 20:03:31 +00:00
|
|
|
visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err);
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
if (!err) {
|
|
|
|
if (*obj) {
|
2018-02-19 20:03:31 +00:00
|
|
|
visit_type_%(c_name)s_fields(m, obj, errp);
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
visit_end_struct(m, &err);
|
|
|
|
}
|
|
|
|
error_propagate(errp, err);
|
|
|
|
''',
|
2018-02-19 20:03:31 +00:00
|
|
|
name=name, c_name=c_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def generate_visit_struct(expr):
|
|
|
|
|
2018-02-19 19:13:27 +00:00
|
|
|
name = expr['struct']
|
2015-08-21 07:04:50 +00:00
|
|
|
members = expr['data']
|
|
|
|
base = expr.get('base')
|
|
|
|
|
2018-02-19 19:34:13 +00:00
|
|
|
ret = generate_visit_struct_fields(name, members, base)
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
ret += mcgen('''
|
|
|
|
|
|
|
|
void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
''',
|
2018-02-19 20:03:31 +00:00
|
|
|
name=c_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret += generate_visit_struct_body(name)
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
ret += mcgen('''
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
return ret
|
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
def generate_visit_list(name):
|
2015-08-21 07:04:50 +00:00
|
|
|
return mcgen('''
|
|
|
|
|
|
|
|
void visit_type_%(name)sList(Visitor *m, %(name)sList **obj, const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
Error *err = NULL;
|
|
|
|
GenericList *i, **prev;
|
|
|
|
|
|
|
|
visit_start_list(m, name, &err);
|
|
|
|
if (err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (prev = (GenericList **)obj;
|
2018-02-19 17:58:24 +00:00
|
|
|
!err && (i = visit_next_list(m, prev)) != NULL;
|
2015-08-21 07:04:50 +00:00
|
|
|
prev = &i) {
|
|
|
|
%(name)sList *native_i = (%(name)sList *)i;
|
|
|
|
visit_type_%(name)s(m, &native_i->value, NULL, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
error_propagate(errp, err);
|
|
|
|
err = NULL;
|
2018-02-19 17:58:24 +00:00
|
|
|
visit_end_list(m);
|
2015-08-21 07:04:50 +00:00
|
|
|
out:
|
|
|
|
error_propagate(errp, err);
|
|
|
|
}
|
|
|
|
''',
|
2018-02-19 20:01:01 +00:00
|
|
|
name=type_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
def generate_visit_enum(name):
|
2015-08-21 07:04:50 +00:00
|
|
|
return mcgen('''
|
|
|
|
|
|
|
|
void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
visit_type_enum(m, (int *)obj, %(name)s_lookup, "%(name)s", name, errp);
|
|
|
|
}
|
|
|
|
''',
|
2018-02-19 20:01:01 +00:00
|
|
|
name=c_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2018-02-19 18:44:13 +00:00
|
|
|
def generate_visit_alternate(name, members):
|
2015-08-21 07:04:50 +00:00
|
|
|
ret = mcgen('''
|
|
|
|
|
|
|
|
void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
Error *err = NULL;
|
|
|
|
|
|
|
|
visit_start_implicit_struct(m, (void**) obj, sizeof(%(name)s), &err);
|
|
|
|
if (err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
visit_get_next_type(m, (int*) &(*obj)->kind, %(name)s_qtypes, name, &err);
|
|
|
|
if (err) {
|
|
|
|
goto out_end;
|
|
|
|
}
|
|
|
|
switch ((*obj)->kind) {
|
|
|
|
''',
|
2018-02-19 20:09:04 +00:00
|
|
|
name=c_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2018-02-19 18:49:54 +00:00
|
|
|
# For alternate, always use the default enum type automatically generated
|
2018-02-19 20:09:04 +00:00
|
|
|
# as name + 'Kind'
|
|
|
|
disc_type = c_name(name) + 'Kind'
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
for key in members:
|
2018-02-19 18:14:35 +00:00
|
|
|
assert (members[key] in builtin_types.keys()
|
2015-08-21 07:04:50 +00:00
|
|
|
or find_struct(members[key])
|
|
|
|
or find_union(members[key])
|
2018-02-19 18:49:54 +00:00
|
|
|
or find_enum(members[key])), "Invalid alternate member"
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2018-02-19 19:49:13 +00:00
|
|
|
enum_full_value = c_enum_const(disc_type, key)
|
2015-08-21 07:04:50 +00:00
|
|
|
ret += mcgen('''
|
|
|
|
case %(enum_full_value)s:
|
|
|
|
visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, name, &err);
|
|
|
|
break;
|
|
|
|
''',
|
|
|
|
enum_full_value = enum_full_value,
|
|
|
|
c_type = type_name(members[key]),
|
2018-02-19 19:44:59 +00:00
|
|
|
c_name = c_name(key))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
ret += mcgen('''
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
out_end:
|
|
|
|
error_propagate(errp, err);
|
|
|
|
err = NULL;
|
2018-02-19 17:58:24 +00:00
|
|
|
visit_end_implicit_struct(m);
|
2015-08-21 07:04:50 +00:00
|
|
|
out:
|
|
|
|
error_propagate(errp, err);
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def generate_visit_union(expr):
|
|
|
|
|
|
|
|
name = expr['union']
|
|
|
|
members = expr['data']
|
|
|
|
|
|
|
|
base = expr.get('base')
|
|
|
|
discriminator = expr.get('discriminator')
|
|
|
|
|
|
|
|
enum_define = discriminator_find_enum_define(expr)
|
|
|
|
if enum_define:
|
|
|
|
# Use the enum type as discriminator
|
|
|
|
ret = ""
|
2018-02-19 20:06:21 +00:00
|
|
|
disc_type = c_name(enum_define['enum_name'])
|
2015-08-21 07:04:50 +00:00
|
|
|
else:
|
2018-02-19 18:29:36 +00:00
|
|
|
# There will always be a discriminator in the C switch code, by default
|
2018-02-19 20:05:08 +00:00
|
|
|
# it is an enum type generated silently
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret = generate_visit_enum(name + 'Kind')
|
2018-02-19 20:05:08 +00:00
|
|
|
disc_type = c_name(name) + 'Kind'
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
if base:
|
2018-02-19 18:29:36 +00:00
|
|
|
assert discriminator
|
|
|
|
base_fields = find_struct(base)['data'].copy()
|
|
|
|
del base_fields[discriminator]
|
2018-02-19 19:34:13 +00:00
|
|
|
ret += generate_visit_struct_fields(name, base_fields)
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
if discriminator:
|
|
|
|
for key in members:
|
|
|
|
ret += generate_visit_implicit_struct(members[key])
|
|
|
|
|
|
|
|
ret += mcgen('''
|
|
|
|
|
|
|
|
void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
Error *err = NULL;
|
|
|
|
|
|
|
|
visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err);
|
|
|
|
if (err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (*obj) {
|
|
|
|
''',
|
2018-02-19 20:05:08 +00:00
|
|
|
name=c_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
if base:
|
|
|
|
ret += mcgen('''
|
|
|
|
visit_type_%(name)s_fields(m, obj, &err);
|
|
|
|
if (err) {
|
|
|
|
goto out_obj;
|
|
|
|
}
|
|
|
|
''',
|
2018-02-19 20:06:21 +00:00
|
|
|
name=c_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
if not discriminator:
|
2018-02-19 21:13:05 +00:00
|
|
|
tag = 'kind'
|
2015-08-21 07:04:50 +00:00
|
|
|
disc_key = "type"
|
|
|
|
else:
|
2018-02-19 21:13:05 +00:00
|
|
|
tag = discriminator
|
2015-08-21 07:04:50 +00:00
|
|
|
disc_key = discriminator
|
|
|
|
ret += mcgen('''
|
2018-02-19 21:13:05 +00:00
|
|
|
visit_type_%(disc_type)s(m, &(*obj)->%(c_tag)s, "%(disc_key)s", &err);
|
2015-08-21 07:04:50 +00:00
|
|
|
if (err) {
|
|
|
|
goto out_obj;
|
|
|
|
}
|
|
|
|
if (!visit_start_union(m, !!(*obj)->data, &err) || err) {
|
|
|
|
goto out_obj;
|
|
|
|
}
|
2018-02-19 21:13:05 +00:00
|
|
|
switch ((*obj)->%(c_tag)s) {
|
2015-08-21 07:04:50 +00:00
|
|
|
''',
|
|
|
|
disc_type = disc_type,
|
2018-02-19 21:13:05 +00:00
|
|
|
c_tag=c_name(tag),
|
2015-08-21 07:04:50 +00:00
|
|
|
disc_key = disc_key)
|
|
|
|
|
|
|
|
for key in members:
|
|
|
|
if not discriminator:
|
|
|
|
fmt = 'visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "data", &err);'
|
|
|
|
else:
|
|
|
|
fmt = 'visit_type_implicit_%(c_type)s(m, &(*obj)->%(c_name)s, &err);'
|
|
|
|
|
2018-02-19 19:49:13 +00:00
|
|
|
enum_full_value = c_enum_const(disc_type, key)
|
2015-08-21 07:04:50 +00:00
|
|
|
ret += mcgen('''
|
|
|
|
case %(enum_full_value)s:
|
|
|
|
''' + fmt + '''
|
|
|
|
break;
|
|
|
|
''',
|
|
|
|
enum_full_value = enum_full_value,
|
|
|
|
c_type=type_name(members[key]),
|
2018-02-19 19:44:59 +00:00
|
|
|
c_name=c_name(key))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
ret += mcgen('''
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
out_obj:
|
|
|
|
error_propagate(errp, err);
|
|
|
|
err = NULL;
|
|
|
|
visit_end_union(m, !!(*obj)->data, &err);
|
|
|
|
error_propagate(errp, err);
|
|
|
|
err = NULL;
|
|
|
|
}
|
|
|
|
visit_end_struct(m, &err);
|
|
|
|
out:
|
|
|
|
error_propagate(errp, err);
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
def generate_declaration(name, builtin_type=False):
|
2015-08-21 07:04:50 +00:00
|
|
|
ret = ""
|
|
|
|
if not builtin_type:
|
2018-02-19 20:03:31 +00:00
|
|
|
name = c_name(name)
|
2015-08-21 07:04:50 +00:00
|
|
|
ret += mcgen('''
|
|
|
|
|
|
|
|
void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **errp);
|
|
|
|
''',
|
2018-02-19 18:08:37 +00:00
|
|
|
name=name)
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2018-02-19 18:08:37 +00:00
|
|
|
|
|
|
|
ret += mcgen('''
|
2015-08-21 07:04:50 +00:00
|
|
|
void visit_type_%(name)sList(Visitor *m, %(name)sList **obj, const char *name, Error **errp);
|
|
|
|
''',
|
|
|
|
name=name)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
def generate_enum_declaration(name):
|
2018-02-19 18:08:37 +00:00
|
|
|
ret = mcgen('''
|
2015-08-21 07:04:50 +00:00
|
|
|
void visit_type_%(name)sList(Visitor *m, %(name)sList **obj, const char *name, Error **errp);
|
|
|
|
''',
|
2018-02-19 20:01:01 +00:00
|
|
|
name=c_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
return ret
|
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
def generate_decl_enum(name):
|
2015-08-21 07:04:50 +00:00
|
|
|
return mcgen('''
|
|
|
|
|
|
|
|
void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error **errp);
|
|
|
|
''',
|
2018-02-19 20:01:01 +00:00
|
|
|
name=c_name(name))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
do_builtins = False
|
|
|
|
|
2018-02-19 20:19:07 +00:00
|
|
|
(input_file, output_dir, do_c, do_h, prefix, opts) = \
|
|
|
|
parse_command_line("b", ["builtins"])
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
for o, a in opts:
|
2018-02-19 20:19:07 +00:00
|
|
|
if o in ("-b", "--builtins"):
|
2015-08-21 07:04:50 +00:00
|
|
|
do_builtins = True
|
|
|
|
|
2018-02-19 20:31:47 +00:00
|
|
|
c_comment = '''
|
2015-08-21 07:04:50 +00:00
|
|
|
/*
|
|
|
|
* schema-defined QAPI visitor functions
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2011
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
|
|
* See the COPYING.LIB file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
2018-02-19 20:31:47 +00:00
|
|
|
'''
|
|
|
|
h_comment = '''
|
2015-08-21 07:04:50 +00:00
|
|
|
/*
|
|
|
|
* schema-defined QAPI visitor functions
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2011
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
|
|
* See the COPYING.LIB file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
2018-02-19 20:31:47 +00:00
|
|
|
'''
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2018-02-19 20:31:47 +00:00
|
|
|
(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
|
|
|
|
'qapi-visit.c', 'qapi-visit.h',
|
|
|
|
c_comment, h_comment)
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2018-02-19 20:31:47 +00:00
|
|
|
fdef.write(mcgen('''
|
|
|
|
#include "qemu-common.h"
|
|
|
|
#include "%(prefix)sqapi-visit.h"
|
|
|
|
''',
|
|
|
|
prefix = prefix))
|
|
|
|
|
|
|
|
fdecl.write(mcgen('''
|
2015-08-21 07:04:50 +00:00
|
|
|
#include "qapi/visitor.h"
|
|
|
|
#include "%(prefix)sqapi-types.h"
|
|
|
|
|
|
|
|
''',
|
2018-02-19 20:31:47 +00:00
|
|
|
prefix=prefix))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
exprs = parse_schema(input_file)
|
|
|
|
|
|
|
|
# to avoid header dependency hell, we always generate declarations
|
|
|
|
# for built-in types in our header files and simply guard them
|
|
|
|
fdecl.write(guardstart("QAPI_VISIT_BUILTIN_VISITOR_DECL"))
|
2018-02-19 18:14:35 +00:00
|
|
|
for typename in builtin_types.keys():
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
fdecl.write(generate_declaration(typename, builtin_type=True))
|
2015-08-21 07:04:50 +00:00
|
|
|
fdecl.write(guardend("QAPI_VISIT_BUILTIN_VISITOR_DECL"))
|
|
|
|
|
|
|
|
# ...this doesn't work for cases where we link in multiple objects that
|
|
|
|
# have the functions defined, so we use -b option to provide control
|
|
|
|
# over these cases
|
|
|
|
if do_builtins:
|
2018-02-19 18:14:35 +00:00
|
|
|
for typename in builtin_types.keys():
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
fdef.write(generate_visit_list(typename))
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
for expr in exprs:
|
2018-02-19 19:13:27 +00:00
|
|
|
if expr.has_key('struct'):
|
2015-08-21 07:04:50 +00:00
|
|
|
ret = generate_visit_struct(expr)
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret += generate_visit_list(expr['struct'])
|
2015-08-21 07:04:50 +00:00
|
|
|
fdef.write(ret)
|
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret = generate_declaration(expr['struct'])
|
2015-08-21 07:04:50 +00:00
|
|
|
fdecl.write(ret)
|
|
|
|
elif expr.has_key('union'):
|
|
|
|
ret = generate_visit_union(expr)
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret += generate_visit_list(expr['union'])
|
2015-08-21 07:04:50 +00:00
|
|
|
fdef.write(ret)
|
|
|
|
|
|
|
|
enum_define = discriminator_find_enum_define(expr)
|
|
|
|
ret = ""
|
|
|
|
if not enum_define:
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret = generate_decl_enum('%sKind' % expr['union'])
|
|
|
|
ret += generate_declaration(expr['union'])
|
2015-08-21 07:04:50 +00:00
|
|
|
fdecl.write(ret)
|
2018-02-19 18:49:54 +00:00
|
|
|
elif expr.has_key('alternate'):
|
|
|
|
ret = generate_visit_alternate(expr['alternate'], expr['data'])
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret += generate_visit_list(expr['alternate'])
|
2018-02-19 18:49:54 +00:00
|
|
|
fdef.write(ret)
|
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret = generate_decl_enum('%sKind' % expr['alternate'])
|
|
|
|
ret += generate_declaration(expr['alternate'])
|
2018-02-19 18:49:54 +00:00
|
|
|
fdecl.write(ret)
|
2015-08-21 07:04:50 +00:00
|
|
|
elif expr.has_key('enum'):
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret = generate_visit_list(expr['enum'])
|
|
|
|
ret += generate_visit_enum(expr['enum'])
|
2015-08-21 07:04:50 +00:00
|
|
|
fdef.write(ret)
|
|
|
|
|
qapi: Drop unused and useless parameters and variables
gen_sync_call()'s parameter indent is useless: gen_sync_call() uses it
only as optional argument for push_indent() and pop_indent(), their
default is four, and gen_sync_call()'s only caller passes four. Drop
the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always
"QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(),
gen_marshal_input_decl(), generate_visit_struct_body(),
generate_visit_list(), generate_visit_enum(), generate_declaration(),
generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(),
generate_enum_lookup(), generate_visit_struct_fields(), check_event().
Backports commit 5aa05d3f72e556752167f7005d6a3dea0f4432c5 from qemu
2018-02-19 21:11:32 +00:00
|
|
|
ret = generate_decl_enum(expr['enum'])
|
|
|
|
ret += generate_enum_declaration(expr['enum'])
|
2015-08-21 07:04:50 +00:00
|
|
|
fdecl.write(ret)
|
|
|
|
|
2018-02-19 20:31:47 +00:00
|
|
|
close_output(fdef, fdecl)
|