From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmg1m-0003UG-6H for qemu-devel@nongnu.org; Tue, 20 May 2014 05:08:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wmg1h-00083P-4d for qemu-devel@nongnu.org; Tue, 20 May 2014 05:08:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmg1g-00083B-U8 for qemu-devel@nongnu.org; Tue, 20 May 2014 05:08:01 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4K9805j002626 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 May 2014 05:08:00 -0400 From: Fam Zheng Date: Tue, 20 May 2014 17:07:59 +0800 Message-Id: <1400576881-6954-6-git-send-email-famz@redhat.com> In-Reply-To: <1400576881-6954-1-git-send-email-famz@redhat.com> References: <1400576881-6954-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [RFC PATCH v2 5/7] qapi: Add @arg property dictionary syntax List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi parse_args now yields one more item in an iteration - default. It is the default value for the argument, that is parsed from 'data': { '@ARG_NAME': { PROP_NAME : PROP_VALUE } } syntax added into qapi schema. ARG_NAME is the name of argument. PROP_NAME is the property name of argument, currently can be 'type', 'optional' or 'default'. 'type' defines the type of the argument, as what we have in: 'data': { 'ARG_NAME': 'TYPE_NAME' } 'optional' can be true or false. 'default' gives the default value of argument. if 'default' is set, 'optional' is ignored and the qmp handler will always get a value, hence parse_args yields an False, so that has_xxx parameter is not generated in the handler prototype. Later, in qapi-commands.py, the value will be used if user doesn't specify one. See the coming change on block-commit for example of how qmp commands can make use of this. Signed-off-by: Fam Zheng --- scripts/qapi-commands.py | 8 ++++---- scripts/qapi-types.py | 2 +- scripts/qapi-visit.py | 4 ++-- scripts/qapi.py | 20 ++++++++++++++++++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 386f17e..05904f9 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -28,7 +28,7 @@ def type_visitor(name): def generate_command_decl(name, args, ret_type): arglist="" - for argname, argtype, optional, structured in parse_args(args): + for argname, argtype, optional, structured, default in parse_args(args): argtype = c_type(argtype) if argtype == "char *": argtype = "const char *" @@ -55,7 +55,7 @@ def gen_sync_call(name, args, ret_type, indent=0): retval="" if ret_type: retval = "retval = " - for argname, argtype, optional, structured in parse_args(args): + for argname, argtype, optional, structured, default in parse_args(args): if optional: arglist += "has_%s, " % c_var(argname) arglist += "%s, " % (c_var(argname)) @@ -98,7 +98,7 @@ Visitor *v; def gen_visitor_input_vars_decl(args): ret = "" push_indent() - for argname, argtype, optional, structured in parse_args(args): + for argname, argtype, optional, structured, default in parse_args(args): if optional: ret += mcgen(''' bool has_%(argname)s = false; @@ -141,7 +141,7 @@ v = qapi_dealloc_get_visitor(md); v = qmp_input_get_visitor(mi); ''') - for argname, argtype, optional, structured in parse_args(args): + for argname, argtype, optional, structured, default in parse_args(args): if optional: ret += mcgen(''' visit_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s); diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index b463232..ba3aa2b 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -63,7 +63,7 @@ typedef struct %(name)sList def generate_struct_fields(members): ret = '' - for argname, argentry, optional, structured in parse_args(members): + for argname, argentry, optional, structured, default in parse_args(members): if optional: ret += mcgen(''' bool has_%(c_name)s; diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 06a79f1..4d9ee66 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -51,7 +51,7 @@ def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base = else: full_name = "%s_%s" % (name, fn_prefix) - for argname, argentry, optional, structured in parse_args(members): + for argname, argentry, optional, structured, default in parse_args(members): if structured: if not fn_prefix: nested_fn_prefix = argname @@ -94,7 +94,7 @@ if (err) { c_prefix=c_var(field_prefix), type=type_name(base), c_name=c_var('base')) - for argname, argentry, optional, structured in parse_args(members): + for argname, argentry, optional, structured, default in parse_args(members): if optional: ret += mcgen(''' visit_optional(m, &(*obj)->%(c_prefix)shas_%(c_name)s, "%(name)s", &err); diff --git a/scripts/qapi.py b/scripts/qapi.py index ca2f1cc..fbe3ce3 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -384,13 +384,29 @@ def parse_args(typeinfo): argname = member argentry = typeinfo[member] optional = False + argtype = argentry + default = None structured = False if member.startswith('*'): argname = member[1:] optional = True + if member.startswith('@'): + if not isinstance(argentry, OrderedDict): + raise Exception("Expecting property dictionary for argument '%s'" % member) + # Parse argument property dict + argname = member[1:] + argtype = argentry.get("type", None) + optional = argentry.get("optional", False) + default = argentry.get("default", None) + if default is not None: + optional = False if isinstance(argentry, OrderedDict): - structured = True - yield (argname, argentry, optional, structured) + structured = True + + else: + argtype = argentry + + yield (argname, argtype, optional, structured, default) def de_camel_case(name): new_name = '' -- 1.9.2