[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 01/16] qapi: Fix C identifiers generated for name
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v4 01/16] qapi: Fix C identifiers generated for names containing '.' |
Date: |
Thu, 14 May 2015 06:50:47 -0600 |
From: Markus Armbruster <address@hidden>
c_fun() maps '.' to '_', c_var() doesn't. Nothing prevents '.' in
QAPI names that get passed to c_var().
Which QAPI names get passed to c_fun(), to c_var(), or to both is not
obvious. Names of command parameters and struct type members get
passed to c_var().
c_var() strips a leading '*', but this cannot happen. c_fun()
doesn't.
Fix c_var() to work exactly like c_fun().
Perhaps they should be replaced by a single mapping function.
Signed-off-by: Markus Armbruster <address@hidden>
[add 'import string']
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Alberto Garcia <address@hidden>
---
scripts/qapi.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 166b74f..4b07805 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -15,6 +15,7 @@ import re
from ordereddict import OrderedDict
import os
import sys
+import string
builtin_types = {
'str': 'QTYPE_QSTRING',
@@ -752,6 +753,8 @@ def camel_case(name):
new_name += ch.lower()
return new_name
+c_var_trans = string.maketrans('.-', '__')
+
def c_var(name, protect=True):
# ANSI X3J11/88-090, 3.1.1
c89_words = set(['auto', 'break', 'case', 'char', 'const', 'continue',
@@ -781,10 +784,10 @@ def c_var(name, protect=True):
polluted_words = set(['unix', 'errno'])
if protect and (name in c89_words | c99_words | c11_words | gcc_words |
cpp_words | polluted_words):
return "q_" + name
- return name.replace('-', '_').lstrip("*")
+ return name.translate(c_var_trans)
def c_fun(name, protect=True):
- return c_var(name, protect).replace('.', '_')
+ return c_var(name, protect)
def c_list_type(name):
return '%sList' % name
--
2.1.0
- [Qemu-devel] [PATCH v4 12/16] qapi: Support downstream simple unions, (continued)
- [Qemu-devel] [PATCH v4 12/16] qapi: Support downstream simple unions, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 14/16] qapi: Support downstream alternates, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 11/16] qapi: Support downstream structs, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 15/16] qapi: Support downstream events and commands, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 16/16] qapi: Prefer '"str" + var' over '"str%s" % var', Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 13/16] qapi: Support downstream flat unions, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 03/16] qapi: Rename _generate_enum_string() to camel_to_upper(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 04/16] qapi: Rename generate_enum_full_value() to c_enum_const(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 01/16] qapi: Fix C identifiers generated for names containing '.',
Eric Blake <=
- [Qemu-devel] [PATCH v4 09/16] qapi: Make c_type() consistently convert qapi names, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 08/16] qapi: Tidy c_type logic, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 06/16] qapi: Use c_enum_const() in generate_alternate_qtypes(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 07/16] qapi: Move camel_to_upper(), c_enum_const() to closely related code, Eric Blake, 2015/05/14
- Re: [Qemu-devel] [PATCH v4 00/16] Fix qapi mangling of downstream names, Eric Blake, 2015/05/14