From patchwork Fri Apr 25 07:56:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 342670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id A6A62140166 for ; Fri, 25 Apr 2014 17:57:38 +1000 (EST) Received: from localhost ([::1]:56457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wdb0q-0007KM-CG for incoming@patchwork.ozlabs.org; Fri, 25 Apr 2014 03:57:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wdb0L-0006T8-RA for qemu-devel@nongnu.org; Fri, 25 Apr 2014 03:57:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wdb0F-0000lk-Cb for qemu-devel@nongnu.org; Fri, 25 Apr 2014 03:57:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11418) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wdb0F-0000lW-3N for qemu-devel@nongnu.org; Fri, 25 Apr 2014 03:56:59 -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 s3P7uune009753 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Apr 2014 03:56:56 -0400 Received: from amosk.info.com (vpn1-114-184.nay.redhat.com [10.66.114.184]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3P7ufOT017168; Fri, 25 Apr 2014 03:56:51 -0400 From: Amos Kong To: qemu-devel@nongnu.org Date: Fri, 25 Apr 2014 15:56:36 +0800 Message-Id: <1398412596-31686-3-git-send-email-akong@redhat.com> In-Reply-To: <1398412596-31686-1-git-send-email-akong@redhat.com> References: <1398412596-31686-1-git-send-email-akong@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: pbonzini@redhat.com, famz@redhat.com, mdroth@linux.vnet.ibm.com, anthony@codemonkey.ws, armbru@redhat.com Subject: [Qemu-devel] [PATCH v2 2/2] qapi: add a special string in c_type()'s result to each redundant space 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 Currently we always add a space after c_type in mcgen(), there is some redundant space in generated code. The space isn't needed for points by the coding style. char * value; ^ qapi_free_NameInfo(NameInfo * obj) ^ This patch added a special string 'EATSPACE' in the end of c_type()'s result only for point type. The string and the following space will be striped in mcgen(). Signed-off-by: Amos Kong Reviewed-by: Eric Blake --- scripts/qapi-commands.py | 2 +- scripts/qapi.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 9734ab0..0ebb1b9 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -26,7 +26,7 @@ def type_visitor(name): def generate_command_decl(name, args, ret_type): arglist="" for argname, argtype, optional, structured in parse_args(args): - argtype = c_type(argtype) + argtype = c_type(argtype).replace('EATSPACE', '') if argtype == "char *": argtype = "const char *" if optional: diff --git a/scripts/qapi.py b/scripts/qapi.py index b474c39..b46c518 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -423,7 +423,7 @@ def is_enum(name): def c_type(name): if name == 'str': - return 'char *' + return 'char *EATSPACE' elif name == 'int': return 'int64_t' elif (name == 'int8' or name == 'int16' or name == 'int32' or @@ -437,15 +437,15 @@ def c_type(name): elif name == 'number': return 'double' elif type(name) == list: - return '%s *' % c_list_type(name[0]) + return '%s *EATSPACE' % c_list_type(name[0]) elif is_enum(name): return name elif name == None or len(name) == 0: return 'void' elif name == name.upper(): - return '%sEvent *' % camel_case(name) + return '%sEvent *EATSPACE' % camel_case(name) else: - return '%s *' % name + return '%s *EATSPACE' % name def genindent(count): ret = "" @@ -470,7 +470,8 @@ def cgen(code, **kwds): return '\n'.join(lines) % kwds + '\n' def mcgen(code, **kwds): - return cgen('\n'.join(code.split('\n')[1:-1]), **kwds) + raw = cgen('\n'.join(code.split('\n')[1:-1]), **kwds) + return raw.replace('*EATSPACE ', '*') def basename(filename): return filename.split("/")[-1]