aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi-commands.py11
-rw-r--r--scripts/qapi-event.py18
-rw-r--r--scripts/qapi.py16
3 files changed, 21 insertions, 24 deletions
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index c68659a7b1..833768ef0e 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -17,19 +17,12 @@ import re
def gen_command_decl(name, arg_type, ret_type):
- argstr = ''
- if arg_type:
- for memb in arg_type.members:
- if memb.optional:
- argstr += 'bool has_%s, ' % c_name(memb.name)
- argstr += '%s %s, ' % (memb.type.c_type(is_param=True),
- c_name(memb.name))
return mcgen('''
-%(c_type)s qmp_%(c_name)s(%(args)sError **errp);
+%(c_type)s qmp_%(c_name)s(%(params)s);
''',
c_type=(ret_type and ret_type.c_type()) or 'void',
c_name=c_name(name),
- args=argstr)
+ params=gen_params(arg_type, 'Error **errp'))
def gen_err_check(err):
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 5873a05888..d15fad98f3 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -15,21 +15,9 @@ from qapi import *
def gen_event_send_proto(name, arg_type):
- api_name = "void qapi_event_send_%s(" % c_name(name).lower()
- l = len(api_name)
-
- if arg_type:
- for m in arg_type.members:
- if m.optional:
- api_name += "bool has_%s,\n" % c_name(m.name)
- api_name += "".ljust(l)
-
- api_name += "%s %s,\n" % (m.type.c_type(is_param=True),
- c_name(m.name))
- api_name += "".ljust(l)
-
- api_name += "Error **errp)"
- return api_name
+ return 'void qapi_event_send_%(c_name)s(%(param)s)' % {
+ 'c_name': c_name(name.lower()),
+ 'param': gen_params(arg_type, 'Error **errp')}
def gen_event_send_decl(name, arg_type):
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 7ac72f6a78..6b6f1aecdc 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1469,6 +1469,22 @@ extern const char *const %(c_name)s_lookup[];
c_name=c_name(name))
return ret
+def gen_params(arg_type, extra):
+ if not arg_type:
+ return extra
+ assert not arg_type.variants
+ ret = ''
+ sep = ''
+ for memb in arg_type.members:
+ ret += sep
+ sep = ', '
+ if memb.optional:
+ ret += 'bool has_%s, ' % c_name(memb.name)
+ ret += '%s %s' % (memb.type.c_type(is_param=True), c_name(memb.name))
+ if extra:
+ ret += sep + extra
+ return ret
+
#
# Common command line parsing
#