aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi.py
diff options
context:
space:
mode:
authorAmos Kong <akong@redhat.com>2014-06-10 19:25:53 +0800
committerLuiz Capitulino <lcapitulino@redhat.com>2014-06-23 11:01:24 -0400
commit05dfb26cd2bf3f50a0fbf08a68a3bd415301edc5 (patch)
tree20632f405ec37031d16ab1747627a8fede02daed /scripts/qapi.py
parent0d14eeb23325b6b1f0f9adce8baf7d1b415cba81 (diff)
qapi: Suppress unwanted space between type and identifier
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> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'scripts/qapi.py')
-rw-r--r--scripts/qapi.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py
index dc690bbf0e..0079194169 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,19 @@ 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 is_c_ptr(name):
+ suffix = "*" + eatspace
+ return c_type(name).endswith(suffix)
def genindent(count):
ret = ""
@@ -521,7 +531,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]