qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, lcapitulino@redhat.com,
	mdroth@linux.vnet.ibm.com, armbru@redhat.com
Subject: [Qemu-devel] [PATCH v5 3/3] qapi: Suppress unwanted space between type and identifier
Date: Thu, 22 May 2014 20:41:44 +0800	[thread overview]
Message-ID: <1400762504-22751-4-git-send-email-akong@redhat.com> (raw)
In-Reply-To: <1400762504-22751-1-git-send-email-akong@redhat.com>

We always generate a space between type and identifier in parameter
and variable declarations, even when idiomatic C style doesn't have
a space there.  Suppress it.

Signed-off-by: Amos Kong <akong@redhat.com>
---
 scripts/qapi-commands.py |  2 +-
 scripts/qapi.py          | 19 +++++++++++++------
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 34f200a..4b49735 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -102,7 +102,7 @@ def gen_visitor_input_vars_decl(args):
 bool has_%(argname)s = false;
 ''',
                          argname=c_var(argname))
-        if c_type(argtype).endswith("*"):
+        if c_type(argtype).endswith("*" + eatspace):
             ret += mcgen('''
 %(argtype)s %(argname)s = NULL;
 ''',
diff --git a/scripts/qapi.py b/scripts/qapi.py
index dc690bb..562d560 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -470,11 +470,17 @@ def find_enum(name):
 def is_enum(name):
     return find_enum(name) != None
 
+eatspace = '\033EATSPACE.'
+
+# 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().
 def c_type(name, is_param=False):
     if name == 'str':
         if is_param:
-            return 'const char *'
-        return 'char *'
+            return 'const char *' + eatspace
+        return 'char *' + eatspace
+
     elif name == 'int':
         return 'int64_t'
     elif (name == 'int8' or name == 'int16' or name == 'int32' or
@@ -488,15 +494,15 @@ def c_type(name, is_param=False):
     elif name == 'number':
         return 'double'
     elif type(name) == list:
-        return '%s *' % c_list_type(name[0])
+        return '%s *%s' % (c_list_type(name[0]), eatspace)
     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 *%s' % (camel_case(name), eatspace)
     else:
-        return '%s *' % name
+        return '%s *%s' % (name, eatspace)
 
 def genindent(count):
     ret = ""
@@ -521,7 +527,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 re.sub(re.escape(eatspace) + ' *', '', raw)
 
 def basename(filename):
     return filename.split("/")[-1]
-- 
1.9.0

  parent reply	other threads:[~2014-05-22 12:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-22 12:41 [Qemu-devel] [PATCH v5 0/3] qapi: fix coding style in generated code Amos Kong
2014-05-22 12:41 ` [Qemu-devel] [PATCH v5 1/3] qapi: fix coding style in parameters list Amos Kong
2014-06-02 15:45   ` Markus Armbruster
2014-05-22 12:41 ` [Qemu-devel] [PATCH v5 2/3] qapi: add const prefix to 'char *' insider c_type() Amos Kong
2014-05-22 12:41 ` Amos Kong [this message]
2014-05-22 16:49   ` [Qemu-devel] [PATCH v5 3/3] qapi: Suppress unwanted space between type and identifier Eric Blake
2014-06-02 15:43   ` Markus Armbruster
2014-06-09 19:09     ` Luiz Capitulino
2014-06-10  5:56     ` Amos Kong
2014-06-12  6:55       ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1400762504-22751-4-git-send-email-akong@redhat.com \
    --to=akong@redhat.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).