qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH RFC 02/19] qapi: Fix C identifiers generated for nam


From: Markus Armbruster
Subject: [Qemu-devel] [PATCH RFC 02/19] qapi: Fix C identifiers generated for names containing '.'
Date: Thu, 2 Apr 2015 19:28:46 +0200

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>
---
 scripts/qapi.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 8e5b4ad..6d102df 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -693,6 +693,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',
@@ -722,10 +724,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
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]