@@ -2011,6 +2011,7 @@
# Since: 4.0
##
{ 'enum': 'XDbgBlockGraphNodeType',
+ 'prefix': 'X_DBG_BLOCK_GRAPH_NODE_TYPE', # TODO drop
'data': [ 'block-backend', 'block-job', 'block-driver' ] }
##
@@ -3746,7 +3747,7 @@
#
# Since: 4.1
##
-{ 'enum': 'BlkdebugIOType', 'prefix': 'BLKDEBUG_IO_TYPE',
+{ 'enum': 'BlkdebugIOType',
'data': [ 'read', 'write', 'write-zeroes', 'discard', 'flush',
'block-status' ] }
@@ -92,6 +92,7 @@
# Since: 2.12
##
{ 'enum': 'OffAutoPCIBAR',
+ 'prefix': 'OFF_AUTOPCIBAR', # TODO drop
'data': [ 'off', 'auto', 'bar0', 'bar1', 'bar2', 'bar3', 'bar4', 'bar5' ] }
##
@@ -20,7 +20,6 @@
# Since: 2.5
##
{ 'enum': 'QCryptoTLSCredsEndpoint',
- 'prefix': 'QCRYPTO_TLS_CREDS_ENDPOINT',
'data': ['client', 'server']}
##
@@ -36,7 +35,6 @@
# Since: 2.6
##
{ 'enum': 'QCryptoSecretFormat',
- 'prefix': 'QCRYPTO_SECRET_FORMAT',
'data': ['raw', 'base64']}
##
@@ -123,7 +121,6 @@
# Since: 2.6
##
{ 'enum': 'QCryptoCipherMode',
- 'prefix': 'QCRYPTO_CIPHER_MODE',
'data': ['ecb', 'cbc', 'xts', 'ctr']}
##
@@ -160,7 +157,7 @@
# Since: 2.6
##
{ 'enum': 'QCryptoBlockFormat',
-# 'prefix': 'QCRYPTO_BLOCK_FORMAT',
+ 'prefix': 'Q_CRYPTO_BLOCK_FORMAT', # TODO drop
'data': ['qcow', 'luks']}
##
@@ -363,6 +360,7 @@
# Since: 5.1
##
{ 'enum': 'QCryptoBlockLUKSKeyslotState',
+ 'prefix': 'Q_CRYPTO_BLOCKLUKS_KEYSLOT_STATE', # TODO drop
'data': [ 'active', 'inactive' ] }
##
@@ -48,7 +48,6 @@
# Since: 8.0
##
{ 'enum': 'QCryptodevBackendType',
- 'prefix': 'QCRYPTODEV_BACKEND_TYPE',
'data': ['builtin', 'vhost-user', 'lkcf']}
##
@@ -42,6 +42,7 @@
# Since: 9.0
##
{ 'enum': 'EbpfProgramID',
+ 'prefix': 'EBPF_PROGRAMID', # TODO drop
'if': 'CONFIG_EBPF',
'data': [ { 'name': 'rss' } ] }
@@ -686,6 +686,7 @@
# Since: 5.0
##
{ 'enum': 'HmatLBMemoryHierarchy',
+ 'prefix': 'HMATLB_MEMORY_HIERARCHY', # TODO drop
'data': [ 'memory', 'first-level', 'second-level', 'third-level' ] }
##
@@ -712,6 +713,7 @@
# Since: 5.0
##
{ 'enum': 'HmatLBDataType',
+ 'prefix': 'HMATLB_DATA_TYPE', # TODO drop
'data': [ 'access-latency', 'read-latency', 'write-latency',
'access-bandwidth', 'read-bandwidth', 'write-bandwidth' ] }
@@ -571,6 +571,7 @@
# Since: 5.0
##
{ 'enum': 'MultiFDCompression',
+ 'prefix': 'MULTIFD_COMPRESSION',
'data': [ 'none', 'zlib',
{ 'name': 'zstd', 'if': 'CONFIG_ZSTD' },
{ 'name': 'qpl', 'if': 'CONFIG_QPL' },
@@ -949,6 +949,7 @@
# Since: 1.3
##
{ 'enum': 'QKeyCode',
+ 'prefix': 'Q_KEY_CODE',
'data': [ 'unmapped',
'shift', 'shift_r', 'alt', 'alt_r', 'ctrl',
'ctrl_r', 'menu', 'esc', '1', '2', '3', '4', '5', '6', '7', '8',
@@ -1396,6 +1397,7 @@
# Since: 3.0
##
{ 'enum' : 'DisplayGLMode',
+ 'prefix' : 'DISPLAYGL_MODE', # TODO drop
'data' : [ 'off', 'on', 'core', 'es' ] }
##
@@ -40,22 +40,28 @@ def camel_to_upper(value: str) -> str:
ENUM_Name2 -> ENUM_NAME2
ENUM24_Name -> ENUM24_NAME
"""
- c_fun_str = c_name(value, False)
- if value.isupper():
- return c_fun_str
+ ret = value[0]
+ upc = value[0].isupper()
- new_name = ''
- length = len(c_fun_str)
- for i in range(length):
- char = c_fun_str[i]
- # When char is upper case and no '_' appears before, do more checks
- if char.isupper() and (i > 0) and c_fun_str[i - 1] != '_':
- if i < length - 1 and c_fun_str[i + 1].islower():
- new_name += '_'
- elif c_fun_str[i - 1].isdigit():
- new_name += '_'
- new_name += char
- return new_name.lstrip('_').upper()
+ # Copy remainder of ``value`` to ``ret`` with '_' inserted
+ for ch in value[1:]:
+ if ch.isupper() == upc:
+ pass
+ elif upc:
+ # ``ret`` ends in upper case, next char isn't: insert '_'
+ # before the last upper case char unless there is one
+ # already, or it's at the beginning
+ if len(ret) > 2 and ret[-2].isalnum():
+ ret = ret[:-1] + '_' + ret[-1]
+ else:
+ # ``ret`` doesn't end in upper case, next char is: insert
+ # '_' before it
+ if ret[-1].isalnum():
+ ret += '_'
+ ret += ch
+ upc = ch.isupper()
+
+ return c_name(ret.upper()).lstrip('_')
def c_enum_const(type_name: str,
@@ -68,9 +74,9 @@ def c_enum_const(type_name: str,
:param const_name: The name of this constant.
:param prefix: Optional, prefix that overrides the type_name.
"""
- if prefix is not None:
- type_name = prefix
- return camel_to_upper(type_name) + '_' + c_name(const_name, False).upper()
+ if prefix is None:
+ prefix = camel_to_upper(type_name)
+ return prefix + '_' + c_name(const_name, False).upper()
def c_name(name: str, protect: bool = True) -> str:
@@ -1249,7 +1249,7 @@ def _def_predefineds(self) -> None:
[{'name': n} for n in qtypes], None)
self._def_definition(QAPISchemaEnumType(
- 'QType', None, None, None, None, qtype_values, 'QTYPE'))
+ 'QType', None, None, None, None, qtype_values, None))
def _make_features(
self,
@@ -1,7 +1,6 @@
module ./builtin
object q_empty
enum QType
- prefix QTYPE
member none
member qnull
member qnum
@@ -1,7 +1,6 @@
module ./builtin
object q_empty
enum QType
- prefix QTYPE
member none
member qnull
member qnum
@@ -1,7 +1,6 @@
module ./builtin
object q_empty
enum QType
- prefix QTYPE
member none
member qnull
member qnum
@@ -1,7 +1,6 @@
module ./builtin
object q_empty
enum QType
- prefix QTYPE
member none
member qnull
member qnum
@@ -1,7 +1,6 @@
module ./builtin
object q_empty
enum QType
- prefix QTYPE
member none
member qnull
member qnum
@@ -1,7 +1,6 @@
module ./builtin
object q_empty
enum QType
- prefix QTYPE
member none
member qnull
member qnum
@@ -1,7 +1,6 @@
module ./builtin
object q_empty
enum QType
- prefix QTYPE
member none
member qnull
member qnum
@@ -119,6 +119,7 @@
'data': [ 'value-a', 'value-b' ] }
{ 'enum': 'TestUnionEnumA',
+ 'prefix': 'TEST_UNION_ENUMA', # TODO drop
'data': [ 'value-a1', 'value-a2' ] }
{ 'struct': 'TestUnionTypeA1',
@@ -1,7 +1,6 @@
module ./builtin
object q_empty
enum QType
- prefix QTYPE
member none
member qnull
member qnum
@@ -109,6 +108,7 @@ enum TestUnionEnum
member value-a
member value-b
enum TestUnionEnumA
+ prefix TEST_UNION_ENUMA
member value-a1
member value-a2
object TestUnionTypeA1