All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com,
	lcapitulino@redhat.com, Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH V6 10/10] qapi script: do not add "_" for every capitalized char in enum
Date: Tue, 11 Feb 2014 05:48:41 +0800	[thread overview]
Message-ID: <1392068921-3327-11-git-send-email-xiawenc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1392068921-3327-1-git-send-email-xiawenc@linux.vnet.ibm.com>

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 <xiawenc@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 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 73c67b7..78db342 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 62a97c1..4bea3a4 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -419,19 +419,31 @@ def discriminator_find_enum_define(expr):
 
     return find_enum(discriminator_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 "_" 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_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 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.7.1

  parent reply	other threads:[~2014-02-11  5:49 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-10 21:48 [Qemu-devel] [PATCH V6 00/10] qapi script: support enum as discriminator and better enum name Wenchao Xia
2014-02-10 21:48 ` [Qemu-devel] [PATCH V6 01/10] qapi script: remember enum values Wenchao Xia
2014-02-10 21:48 ` [Qemu-devel] [PATCH V6 02/10] qapi script: add check for duplicated key Wenchao Xia
2014-02-13 15:14   ` Markus Armbruster
2014-02-14  1:50     ` Wenchao Xia
2014-02-17  8:28       ` Markus Armbruster
2014-02-10 21:48 ` [Qemu-devel] [PATCH V6 03/10] qapi script: check correctness of discriminator values in union Wenchao Xia
2014-02-13 15:14   ` Markus Armbruster
2014-02-14  2:43     ` Wenchao Xia
2014-02-14  9:23       ` Markus Armbruster
2014-02-17  1:50         ` Wenchao Xia
2014-02-17  8:11           ` Markus Armbruster
2014-02-17 13:59           ` Luiz Capitulino
2014-02-10 21:48 ` [Qemu-devel] [PATCH V6 04/10] qapi script: code move for generate_enum_name() Wenchao Xia
2014-02-10 21:48 ` [Qemu-devel] [PATCH V6 05/10] qapi script: use same function to generate enum string Wenchao Xia
2014-02-10 21:48 ` [Qemu-devel] [PATCH V6 06/10] qapi script: support pre-defined enum type as discriminator in union Wenchao Xia
2014-02-10 21:48 ` [Qemu-devel] [PATCH V6 07/10] qapi: convert BlockdevOptions to use enum discriminator Wenchao Xia
2014-02-10 21:48 ` [Qemu-devel] [PATCH V6 08/10] qapi script: do not allow string discriminator Wenchao Xia
2014-02-13 15:18   ` Markus Armbruster
2014-02-10 21:48 ` [Qemu-devel] [PATCH V6 09/10] tests: add cases for inherited struct and union with discriminator Wenchao Xia
2014-02-13 14:53   ` Markus Armbruster
2014-02-13 15:11     ` Luiz Capitulino
2014-02-14  2:47       ` Wenchao Xia
2014-02-10 21:48 ` Wenchao Xia [this message]
2014-02-11 13:17 ` [Qemu-devel] [PATCH V6 00/10] qapi script: support enum as discriminator and better enum name Eric Blake
2014-02-11 19:13 ` Luiz Capitulino
2014-02-13 15:22   ` Luiz Capitulino
2014-02-13 15:23 ` Markus Armbruster
2014-02-14  2:53   ` Wenchao Xia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392068921-3327-11-git-send-email-xiawenc@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.