[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RFC 08/10] qapi script: do not add "_" for every cap
From: |
Wenchao Xia |
Subject: |
[Qemu-devel] [PATCH RFC 08/10] qapi script: do not add "_" for every capitalized char in enum |
Date: |
Tue, 5 Nov 2013 08:37:38 +0800 |
Now "enum AIOContext" will generate AIO_CONTEXT instead of A_I_O_CONTEXT,
"X86CPU" will generate X86_CPU instead of X86_C_P_U.
Signed-off-by: Wenchao Xia <address@hidden>
---
include/qapi/qmp/qerror.h | 2 +-
scripts/qapi.py | 26 +++++++++++++++++++-------
target-i386/cpu.c | 2 +-
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h
index c30c2f6..6fa07b4 100644
--- a/include/qapi/qmp/qerror.h
+++ b/include/qapi/qmp/qerror.h
@@ -160,7 +160,7 @@ void assert_no_error(Error *err);
ERROR_CLASS_GENERIC_ERROR, "Invalid JSON syntax"
#define QERR_KVM_MISSING_CAP \
- ERROR_CLASS_K_V_M_MISSING_CAP, "Using KVM without %s, %s unavailable"
+ ERROR_CLASS_KVM_MISSING_CAP, "Using KVM without %s, %s unavailable"
#define QERR_MIGRATION_ACTIVE \
ERROR_CLASS_GENERIC_ERROR, "There's a migration process in progress"
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 8e50015..9f5b63e 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -419,19 +419,31 @@ def descriminator_find_enum_define(expr):
return find_enum(descriminator_type)
-def _generate_enum_value_string(value):
+# ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1
+# ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAME2
+# ENUM24_Name -> ENUM24_NAME
+def _generate_enum_string(value):
+ c_fun_str = c_fun(value, False)
if value.isupper():
- return c_fun(value, False)
+ return c_fun_str
+
new_name = ''
- for c in c_fun(value, False):
- if c.isupper():
- new_name += '_'
+ l = len(c_fun_str)
+ for i in range(l):
+ c = c_fun_str[i]
+ # When c is upper and no "_" appear before, do more check
+ if c.isupper() and (i > 0) and c_fun_str[i - 1] != "_":
+ # Case 1: Next string is lower
+ # Case 2: previous string is digit
+ if (i < (l - 1) and c_fun_str[i + 1].islower()) or \
+ c_fun_str[i - 1].isdigit():
+ new_name += '_'
new_name += c
return new_name.lstrip('_').upper()
def generate_enum_full_value_string(enum_name, enum_value):
# generate abbrev string
- abbrev_string = de_camel_case(enum_name).upper()
+ abbrev_string = _generate_enum_string(enum_name)
# generate value string
- value_string = _generate_enum_value_string(enum_value)
+ value_string = _generate_enum_string(enum_value)
return "%s_%s" % (abbrev_string, value_string)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 864c80e..6ba1945 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -315,7 +315,7 @@ typedef struct X86RegisterInfo32 {
} X86RegisterInfo32;
#define REGISTER(reg) \
- [R_##reg] = { .name = #reg, .qapi_enum = X86_C_P_U_REGISTER32_##reg }
+ [R_##reg] = { .name = #reg, .qapi_enum = X86_CPU_REGISTER32_##reg }
X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = {
REGISTER(EAX),
REGISTER(ECX),
--
1.7.1
- Re: [Qemu-devel] [PATCH RFC 01/10] qapi: fix memleak by add implict struct functions in dealloc visitor, (continued)
[Qemu-devel] [PATCH RFC 08/10] qapi script: do not add "_" for every capitalized char in enum,
Wenchao Xia <=
[Qemu-devel] [PATCH RFC 09/10] tests: fix memleak in error path test for input visitor, Wenchao Xia, 2013/11/05
[Qemu-devel] [PATCH RFC 10/10] tests: add cases for inherited struct and union with discriminator, Wenchao Xia, 2013/11/05