diff mbox

[v4,3/3] qapi: Suppress unwanted space between type and identifier

Message ID 1399511680-12811-4-git-send-email-akong@redhat.com
State New
Headers show

Commit Message

Amos Kong May 8, 2014, 1:14 a.m. UTC
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.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Eric Blake May 15, 2014, 7:36 p.m. UTC | #1
On 05/07/2014 07:14 PM, Amos Kong wrote:
> 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.py | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 1bc2bd9..912787a 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -462,11 +462,14 @@  def find_enum(name):
 def is_enum(name):
     return find_enum(name) != None
 
+eatspace = '\033EATSPACE.'
+
 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
@@ -480,15 +483,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 = ""
@@ -513,7 +516,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]