From patchwork Tue May 5 12:30:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 468095 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D60401409F8 for ; Tue, 5 May 2015 22:32:44 +1000 (AEST) Received: from localhost ([::1]:38912 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ypc1j-0003pA-29 for incoming@patchwork.ozlabs.org; Tue, 05 May 2015 08:32:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ypc0u-0002WP-HN for qemu-devel@nongnu.org; Tue, 05 May 2015 08:31:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ypc0q-0002nj-3u for qemu-devel@nongnu.org; Tue, 05 May 2015 08:31:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49089) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ypc0p-0002nY-Rw for qemu-devel@nongnu.org; Tue, 05 May 2015 08:31:48 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t45CV4mq021631 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 May 2015 08:31:04 -0400 Received: from red.redhat.com (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t45CUvnD009312; Tue, 5 May 2015 08:31:03 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 5 May 2015 06:30:49 -0600 Message-Id: <1430829055-4739-9-git-send-email-eblake@redhat.com> In-Reply-To: <1430829055-4739-1-git-send-email-eblake@redhat.com> References: <1430829055-4739-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, akong@redhat.com, berto@igalia.com, armbru@redhat.com, mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v3 08/14] qapi: Make c_type() consistently convert qapi names 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Continuing the string of cleanups for supporting downstream names containing '.', this patch focuses on ensuring c_type() can handle a downstream name. This patch alone does not fix the places where generator output should be calling this function but was open-coding things instead, but it gets us a step closer. Note that we generate a List type for our builtins; the code has to make sure that ['int'] maps to 'intList' (and not 'q_intList'), and that a member with type 'int' still maps to the C type 'int'; on the other hand, a member with a name of 'int' will still map to 'q_int' when going through c_name(). This patch had to teach type_name() to special-case builtins, since it is used by c_list_type() which in turn feeds c_type(). Signed-off-by: Eric Blake --- scripts/qapi.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index b9822c6..a1dfc85 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -769,6 +769,9 @@ def c_enum_const(type_name, const_name): c_name_trans = string.maketrans('.-', '__') +# This function is used for converting the name portion of 'name':'type' +# into a valid C name, for use as a struct member or substring of a +# function name. def c_name(name, protect=True): # ANSI X3J11/88-090, 3.1.1 c89_words = set(['auto', 'break', 'case', 'char', 'const', 'continue', @@ -800,13 +803,18 @@ def c_name(name, protect=True): return "q_" + name return name.translate(c_name_trans) +# This function is used for computing the C type of a 'member':['name'] array. def c_list_type(name): - return '%sList' % name + return type_name(name) + 'List' +# This function is used for converting the type of 'member':'name' into a +# substring for use in C pointer types or function names. def type_name(name): if type(name) == list: return c_list_type(name[0]) - return name + if name in builtin_types.keys(): + return name + return c_name(name) def add_name(name, info, meta, implicit = False): global all_names @@ -864,6 +872,7 @@ def is_enum(name): eatspace = '\033EATSPACE.' +# This function is used for computing the full C type of 'member':'name'. # A special suffix is added in c_type() for pointer types, and it's # stripped in mcgen(). So please notice this when you check the return # value of c_type() outside mcgen(). @@ -888,13 +897,13 @@ def c_type(name, is_param=False): elif type(name) == list: return '%s *%s' % (c_list_type(name[0]), eatspace) elif is_enum(name): - return name + return c_name(name) elif name == None or len(name) == 0: return 'void' elif name in events: return '%sEvent *%s' % (camel_case(name), eatspace) else: - return '%s *%s' % (name, eatspace) + return '%s *%s' % (c_name(name), eatspace) def is_c_ptr(name): suffix = "*" + eatspace