From patchwork Thu Feb 25 23:38:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8427701 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EF1D7C0554 for ; Thu, 25 Feb 2016 23:43:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 494AF2039C for ; Thu, 25 Feb 2016 23:43:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0603920395 for ; Thu, 25 Feb 2016 23:43:01 +0000 (UTC) Received: from localhost ([::1]:46456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ5Yi-0001eL-CO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Feb 2016 18:43:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ5Ux-0002kB-BX for qemu-devel@nongnu.org; Thu, 25 Feb 2016 18:39:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aZ5Uu-0005Pf-HP for qemu-devel@nongnu.org; Thu, 25 Feb 2016 18:39:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44520) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ5Uu-0005PX-7C for qemu-devel@nongnu.org; Thu, 25 Feb 2016 18:39:04 -0500 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 (Postfix) with ESMTPS id C618E8E3E4; Thu, 25 Feb 2016 23:39:03 +0000 (UTC) Received: from red.redhat.com (ovpn-113-105.phx2.redhat.com [10.3.113.105]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1PNd2NZ002433; Thu, 25 Feb 2016 18:39:03 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 25 Feb 2016 16:38:30 -0700 Message-Id: <1456443528-13901-2-git-send-email-eblake@redhat.com> In-Reply-To: <1456443528-13901-1-git-send-email-eblake@redhat.com> References: <1456443528-13901-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v2 01/19] qapi: Rename 'fields' to 'members' in internal interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP C types and JSON objects don't have fields, but members. We shouldn't gratuitously invent terminology. This patch is a strict renaming of generator code and static genarated functions, plus the naming of the dummy filler member for empty structs, before the next patch exposes some of that naming to the rest of the code base. Suggested-by: Markus Armbruster Signed-off-by: Eric Blake --- v2: new patch --- scripts/qapi.py | 20 ++++++++++---------- scripts/qapi-commands.py | 4 ++-- scripts/qapi-event.py | 4 ++-- scripts/qapi-types.py | 10 +++++----- scripts/qapi-visit.py | 40 ++++++++++++++++++++-------------------- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 8497777..6c52fe5 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -328,7 +328,7 @@ class QAPISchemaParser(object): # -def find_base_fields(base): +def find_base_members(base): base_struct_define = find_struct(base) if not base_struct_define: return None @@ -357,11 +357,11 @@ def discriminator_find_enum_define(expr): if not (discriminator and base): return None - base_fields = find_base_fields(base) - if not base_fields: + base_members = find_base_members(base) + if not base_members: return None - discriminator_type = base_fields.get(discriminator) + discriminator_type = base_members.get(discriminator) if not discriminator_type: return None @@ -569,14 +569,14 @@ def check_union(expr, expr_info): raise QAPIExprError(expr_info, "Flat union '%s' must have a base" % name) - base_fields = find_base_fields(base) - assert base_fields + base_members = find_base_members(base) + assert base_members # The value of member 'discriminator' must name a non-optional # member of the base struct. check_name(expr_info, "Discriminator of flat union '%s'" % name, discriminator) - discriminator_type = base_fields.get(discriminator) + discriminator_type = base_members.get(discriminator) if not discriminator_type: raise QAPIExprError(expr_info, "Discriminator '%s' is not a member of base " @@ -971,7 +971,7 @@ class QAPISchemaObjectType(QAPISchemaType): assert self.variants.tag_member in self.members self.variants.check_clash(schema, self.info, seen) - # Check that the members of this type do not cause duplicate JSON fields, + # Check that the members of this type do not cause duplicate JSON members, # and update seen to track the members seen so far. Report any errors # on behalf of info, which is not necessarily self.info def check_clash(self, schema, info, seen): @@ -1649,8 +1649,8 @@ def gen_err_check(label='out', skiperr=False): label=label) -def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False, - label='out'): +def gen_visit_members(members, prefix='', need_cast=False, skiperr=False, + label='out'): ret = '' if skiperr: errparg = 'NULL' diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index f831621..f44e01f 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -111,7 +111,7 @@ def gen_marshal_input_visit(arg_type, dealloc=False): v = qmp_input_get_visitor(qiv); ''') - ret += gen_visit_fields(arg_type.members, skiperr=dealloc) + ret += gen_visit_members(arg_type.members, skiperr=dealloc) if dealloc: ret += mcgen(''' @@ -175,7 +175,7 @@ def gen_marshal(name, arg_type, ret_type): ret += gen_marshal_input_visit(arg_type) ret += gen_call(name, arg_type, ret_type) - # 'goto out' produced by gen_marshal_input_visit->gen_visit_fields() + # 'goto out' produced by gen_marshal_input_visit->gen_visit_members() # for each arg_type member, and by gen_call() for ret_type if (arg_type and arg_type.members) or ret_type: ret += mcgen(''' diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index 544ae12..fb579dd 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -67,8 +67,8 @@ def gen_event_send(name, arg_type): ''', name=name) ret += gen_err_check() - ret += gen_visit_fields(arg_type.members, need_cast=True, - label='out_obj') + ret += gen_visit_members(arg_type.members, need_cast=True, + label='out_obj') ret += mcgen(''' out_obj: visit_end_struct(v, err ? NULL : &err); diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index eac90d2..19d1fff 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -38,7 +38,7 @@ struct %(c_name)s { c_name=c_name(name), c_type=element_type.c_type()) -def gen_struct_fields(members): +def gen_struct_members(members): ret = '' for memb in members: if memb.optional: @@ -77,22 +77,22 @@ struct %(c_name)s { /* Members inherited from %(c_name)s: */ ''', c_name=base.c_name()) - ret += gen_struct_fields(base.members) + ret += gen_struct_members(base.members) ret += mcgen(''' /* Own members: */ ''') - ret += gen_struct_fields(members) + ret += gen_struct_members(members) if variants: ret += gen_variants(variants) - # Make sure that all structs have at least one field; this avoids + # Make sure that all structs have at least one member; this avoids # potential issues with attempting to malloc space for zero-length # structs in C, and also incompatibility with C++ (where an empty # struct is size 1). if not (base and base.members) and not members and not variants: ret += mcgen(''' - char qapi_dummy_field_for_empty_struct; + char qapi_dummy_for_empty_struct; ''') ret += mcgen(''' diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 2308268..1e52f76 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -15,9 +15,9 @@ from qapi import * import re -# visit_type_FOO_fields() is always emitted; track if a forward declaration +# visit_type_FOO_members() is always emitted; track if a forward declaration # or implementation has already been output. -struct_fields_seen = set() +object_members_seen = set() def gen_visit_decl(name, scalar=False): @@ -30,32 +30,32 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_type)sobj, Error ** c_name=c_name(name), c_type=c_type) -def gen_visit_fields_decl(typ): - if typ.name in struct_fields_seen: +def gen_visit_members_decl(typ): + if typ.name in object_members_seen: return '' - struct_fields_seen.add(typ.name) + object_members_seen.add(typ.name) return mcgen(''' -static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s *obj, Error **errp); +static void visit_type_%(c_type)s_members(Visitor *v, %(c_type)s *obj, Error **errp); ''', c_type=typ.c_name()) -def gen_visit_struct_fields(name, base, members, variants): +def gen_visit_object_members(name, base, members, variants): ret = '' if base: - ret += gen_visit_fields_decl(base) + ret += gen_visit_members_decl(base) if variants: for var in variants.variants: # Ugly special case for simple union TODO get rid of it if not var.simple_union_type(): - ret += gen_visit_fields_decl(var.type) + ret += gen_visit_members_decl(var.type) - struct_fields_seen.add(name) + object_members_seen.add(name) ret += mcgen(''' -static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **errp) +static void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) { Error *err = NULL; @@ -64,12 +64,12 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **er if base: ret += mcgen(''' - visit_type_%(c_type)s_fields(v, (%(c_type)s *)obj, &err); + visit_type_%(c_type)s_members(v, (%(c_type)s *)obj, &err); ''', c_type=base.c_name()) ret += gen_err_check() - ret += gen_visit_fields(members, prefix='obj->') + ret += gen_visit_members(members, prefix='obj->') if variants: ret += mcgen(''' @@ -94,7 +94,7 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **er c_name=c_name(var.name)) else: ret += mcgen(''' - visit_type_%(c_type)s_fields(v, &obj->u.%(c_name)s, &err); + visit_type_%(c_type)s_members(v, &obj->u.%(c_name)s, &err); ''', c_type=var.type.c_name(), c_name=c_name(var.name)) @@ -108,7 +108,7 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **er } ''') - # 'goto out' produced for base, by gen_visit_fields() for each member, + # 'goto out' produced for base, by gen_visit_members() for each member, # and if variants were present if base or members or variants: ret += mcgen(''' @@ -174,7 +174,7 @@ def gen_visit_alternate(name, variants): if var.type.alternate_qtype() == 'QTYPE_QINT': promote_int = 'false' if isinstance(var.type, QAPISchemaObjectType): - ret += gen_visit_fields_decl(var.type) + ret += gen_visit_members_decl(var.type) ret += mcgen(''' @@ -202,7 +202,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error if (err) { break; } - visit_type_%(c_type)s_fields(v, &(*obj)->u.%(c_name)s, &err); + visit_type_%(c_type)s_members(v, &(*obj)->u.%(c_name)s, &err); error_propagate(errp, err); err = NULL; visit_end_struct(v, &err); @@ -235,10 +235,10 @@ out: def gen_visit_object(name, base, members, variants): - ret = gen_visit_struct_fields(name, base, members, variants) + ret = gen_visit_object_members(name, base, members, variants) # 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_members() fails, we should clean up *obj # 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. ret += mcgen(''' @@ -254,7 +254,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error if (!*obj) { goto out_obj; } - visit_type_%(c_name)s_fields(v, *obj, &err); + visit_type_%(c_name)s_members(v, *obj, &err); error_propagate(errp, err); err = NULL; out_obj: