[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/43] qapi: Suppress unwanted space between type and
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PULL 05/43] qapi: Suppress unwanted space between type and identifier |
Date: |
Mon, 23 Jun 2014 12:36:05 -0400 |
From: Amos Kong <address@hidden>
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 <address@hidden>
Signed-off-by: Luiz Capitulino <address@hidden>
---
scripts/qapi-commands.py | 4 ++--
scripts/qapi.py | 23 +++++++++++++++++------
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 34f200a..053ba85 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 is_c_ptr(argtype):
ret += mcgen('''
%(argtype)s %(argname)s = NULL;
''',
@@ -227,7 +227,7 @@ def gen_marshal_input(name, args, ret_type, middle_mode):
''')
if ret_type:
- if c_type(ret_type).endswith("*"):
+ if is_c_ptr(ret_type):
retval = " %s retval = NULL;" % c_type(ret_type)
else:
retval = " %s retval;" % c_type(ret_type)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index dc690bb..0079194 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]
--
1.9.3
- [Qemu-devel] [PULL 26/43] qapi event: convert DEVICE_TRAY_MOVED, (continued)
- [Qemu-devel] [PULL 26/43] qapi event: convert DEVICE_TRAY_MOVED, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 32/43] qapi event: convert SPICE events, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 28/43] qapi event: convert BLOCK_IMAGE_CORRUPTED, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 30/43] qapi event: convert NIC_RX_FILTER_CHANGED, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 31/43] qapi event: convert VNC events, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 33/43] qmp: convert ACPI_DEVICE_OST event, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 35/43] qapi event: convert GUEST_PANICKED, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 36/43] qapi event: convert QUORUM events, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 38/43] qemu-char: introduce qemu_chr_alloc, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 40/43] qemu-char: move pty_chr_update_read_handler around, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 05/43] qapi: Suppress unwanted space between type and identifier,
Luiz Capitulino <=
- [Qemu-devel] [PULL 41/43] qemu-char: make writes thread-safe, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 04/43] qapi: add const prefix to 'char *' insider c_type(), Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 10/43] qapi script: add event support, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 34/43] qapi event: convert BALLOON_CHANGE, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 25/43] qapi event: convert DEVICE_DELETED, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 16/43] qapi event: convert POWERDOWN, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 29/43] qapi event: convert other BLOCK_JOB events, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 09/43] qapi: add event helper functions, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 19/43] qapi event: convert RESUME, Luiz Capitulino, 2014/06/23
- [Qemu-devel] [PULL 42/43] monitor: protect outbuf and mux_out with mutex, Luiz Capitulino, 2014/06/23