From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNMwF-0000MX-Nd for qemu-devel@nongnu.org; Tue, 11 Mar 2014 09:41:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNMwA-0006AA-6M for qemu-devel@nongnu.org; Tue, 11 Mar 2014 09:41:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7400) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNMw9-00069y-VH for qemu-devel@nongnu.org; Tue, 11 Mar 2014 09:41:42 -0400 From: Luiz Capitulino Date: Tue, 11 Mar 2014 09:41:10 -0400 Message-Id: <1394545271-27573-11-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1394545271-27573-1-git-send-email-lcapitulino@redhat.com> References: <1394545271-27573-1-git-send-email-lcapitulino@redhat.com> Subject: [Qemu-devel] [PULL 10/11] qapi script: do not add "_" for every capitalized char in enum List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: peter.maydell@linaro.org Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws From: Wenchao Xia 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 Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster Signed-off-by: Luiz Capitulino --- 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 25193c9..da75abf 100644 --- a/include/qapi/qmp/qerror.h +++ b/include/qapi/qmp/qerror.h @@ -159,7 +159,7 @@ void qerror_report_err(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 bd00d01..b474c39 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -498,17 +498,29 @@ def guardend(name): ''', name=guardname(name)) -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 "_" appears before, do more checks + 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(enum_name, enum_value): - abbrev_string = de_camel_case(enum_name).upper() - value_string = _generate_enum_value_string(enum_value) + abbrev_string = _generate_enum_string(enum_name) + 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 0e8812a..c83ab0f 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.8.1.4