mirror of
https://github.com/opencv/opencv.git
synced 2025-06-09 02:23:23 +08:00
Merge pull request #23002 from alalek:issue_22206
* obj-c: de-duplicate values of nested enums - prefix with outer class name * obj-c: handle enum names change in assigned values * obj-c: switch on 'const_fix' * obj-c: add NS_SWIFT_NAME
This commit is contained in:
parent
645930387c
commit
b5400902a7
@ -203,6 +203,7 @@ class ConstInfo(GeneralInfo):
|
|||||||
def __init__(self, decl, addedManually=False, namespaces=[], enumType=None):
|
def __init__(self, decl, addedManually=False, namespaces=[], enumType=None):
|
||||||
GeneralInfo.__init__(self, "const", decl, namespaces)
|
GeneralInfo.__init__(self, "const", decl, namespaces)
|
||||||
self.cname = get_cname(self.name)
|
self.cname = get_cname(self.name)
|
||||||
|
self.swift_name = None
|
||||||
self.value = decl[1]
|
self.value = decl[1]
|
||||||
self.enumType = enumType
|
self.enumType = enumType
|
||||||
self.addedManually = addedManually
|
self.addedManually = addedManually
|
||||||
@ -780,14 +781,27 @@ class ObjectiveCWrapperGenerator(object):
|
|||||||
logging.info('ignored: %s', constinfo)
|
logging.info('ignored: %s', constinfo)
|
||||||
else:
|
else:
|
||||||
objc_type = enumType.rsplit(".", 1)[-1] if enumType else ""
|
objc_type = enumType.rsplit(".", 1)[-1] if enumType else ""
|
||||||
if constinfo.classname in const_fix and objc_type in const_fix[constinfo.classname] and constinfo.name in const_fix[constinfo.classname][objc_type]:
|
if constinfo.enumType and constinfo.classpath:
|
||||||
fixed_const = const_fix[constinfo.classname][objc_type][constinfo.name]
|
new_name = constinfo.classname + '_' + constinfo.name
|
||||||
constinfo.name = fixed_const
|
const_fix.setdefault(constinfo.classpath, {}).setdefault(objc_type, {})[constinfo.name] = new_name
|
||||||
constinfo.cname = fixed_const
|
constinfo.swift_name = constinfo.name
|
||||||
|
constinfo.name = new_name
|
||||||
|
logging.info('use outer class prefix: %s', constinfo)
|
||||||
|
|
||||||
|
if constinfo.classpath in const_fix and objc_type in const_fix[constinfo.classpath]:
|
||||||
|
fixed_consts = const_fix[constinfo.classpath][objc_type]
|
||||||
|
if constinfo.name in fixed_consts:
|
||||||
|
fixed_const = fixed_consts[constinfo.name]
|
||||||
|
constinfo.name = fixed_const
|
||||||
|
constinfo.cname = fixed_const
|
||||||
|
if constinfo.value in fixed_consts:
|
||||||
|
constinfo.value = fixed_consts[constinfo.value]
|
||||||
|
|
||||||
if not self.isWrapped(constinfo.classname):
|
if not self.isWrapped(constinfo.classname):
|
||||||
logging.info('class not found: %s', constinfo)
|
logging.info('class not found: %s', constinfo)
|
||||||
constinfo.name = constinfo.classname + '_' + constinfo.name
|
if not constinfo.name.startswith(constinfo.classname + "_"):
|
||||||
|
constinfo.swift_name = constinfo.name
|
||||||
|
constinfo.name = constinfo.classname + '_' + constinfo.name
|
||||||
constinfo.classname = ''
|
constinfo.classname = ''
|
||||||
|
|
||||||
ci = self.getClass(constinfo.classname)
|
ci = self.getClass(constinfo.classname)
|
||||||
@ -1294,7 +1308,9 @@ $unrefined_call$epilogue$ret
|
|||||||
ci.enum_declarations.write("""
|
ci.enum_declarations.write("""
|
||||||
// C++: enum {1} ({2})
|
// C++: enum {1} ({2})
|
||||||
typedef NS_ENUM(int, {1}) {{
|
typedef NS_ENUM(int, {1}) {{
|
||||||
{0}\n}};\n\n""".format(",\n ".join(["%s = %s" % (c.name, c.value) for c in consts]), typeNameShort, typeName)
|
{0}\n}};\n\n""".format(
|
||||||
|
",\n ".join(["%s = %s" % (c.name + (" NS_SWIFT_NAME(" + c.swift_name + ")" if c.swift_name else ""), c.value) for c in consts]),
|
||||||
|
typeNameShort, typeName)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if not wrote_consts_pragma:
|
if not wrote_consts_pragma:
|
||||||
|
Loading…
Reference in New Issue
Block a user