From: Alexander Alekhin Date: Thu, 22 Dec 2022 14:01:21 +0000 (+0300) Subject: Merge pull request #23002 from alalek:issue_22206 X-Git-Tag: accepted/tizen/unified/20230127.161057~1^2~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5400902a72c0e1bf7d7c811ad16123edd08a18c;p=platform%2Fupstream%2Fopencv.git 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 --- diff --git a/modules/objc/generator/gen_objc.py b/modules/objc/generator/gen_objc.py index 8302931..33f49c2 100755 --- a/modules/objc/generator/gen_objc.py +++ b/modules/objc/generator/gen_objc.py @@ -203,6 +203,7 @@ class ConstInfo(GeneralInfo): def __init__(self, decl, addedManually=False, namespaces=[], enumType=None): GeneralInfo.__init__(self, "const", decl, namespaces) self.cname = get_cname(self.name) + self.swift_name = None self.value = decl[1] self.enumType = enumType self.addedManually = addedManually @@ -780,14 +781,27 @@ class ObjectiveCWrapperGenerator(object): logging.info('ignored: %s', constinfo) 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]: - fixed_const = const_fix[constinfo.classname][objc_type][constinfo.name] - constinfo.name = fixed_const - constinfo.cname = fixed_const + if constinfo.enumType and constinfo.classpath: + new_name = constinfo.classname + '_' + constinfo.name + const_fix.setdefault(constinfo.classpath, {}).setdefault(objc_type, {})[constinfo.name] = new_name + 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): 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 = '' ci = self.getClass(constinfo.classname) @@ -1294,7 +1308,9 @@ $unrefined_call$epilogue$ret ci.enum_declarations.write(""" // C++: enum {1} ({2}) 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: if not wrote_consts_pragma: