From 04a024ec9e8e6515993e1bea2765b9c078563494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Thu, 8 Feb 2018 14:14:40 +0100 Subject: [PATCH] Revert "Fixes C++ wrapper generation with Python 2" This reverts commit 7d621c5bd1e9e7f76ffeb90a0ad0f882b88efb92 and proposes a way to fix the generation with Python 2 without breaking abstractapi's interface. --- tools/abstractapi.py | 11 ++++++++--- tools/metadoc.py | 2 +- wrappers/cpp/genwrapper.py | 12 ++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/abstractapi.py b/tools/abstractapi.py index 941624d89..2ea931971 100644 --- a/tools/abstractapi.py +++ b/tools/abstractapi.py @@ -110,7 +110,12 @@ class Object(object): def __lt__(self, other): return self.name < other.name - def find_first_ancestor_by_type(self, types, priorAncestor=False): + def find_first_ancestor_by_type(self, *types, **kargs): + try: + priorAncestor = kargs['priorAncestor'] + except KeyError: + priorAncestor = False + current = self ancestor = self.parent while ancestor is not None and type(ancestor) not in types: @@ -951,7 +956,7 @@ class Translator: if namespace is not None: return namespace.name if namespace is not GlobalNs else None else: - namespace = obj.find_first_ancestor_by_type((Enum, Class, Namespace, Interface)) + namespace = obj.find_first_ancestor_by_type(Enum, Class, Namespace, Interface) return metaname.Name.find_common_parent(self._get_object_name(obj), namespace.name) @@ -1000,7 +1005,7 @@ class CLangTranslator(CLikeLangTranslator): raise TypeError('invalid enumerator value type: {0}'.format(value)) def translate_method_as_prototype(self, method, **params): - _class = method.find_first_ancestor_by_type((Class,)) + _class = method.find_first_ancestor_by_type(Class) params = '{const}{className} *obj'.format( className=_class.name.to_c(), const='const ' if method.isconst else '' diff --git a/tools/metadoc.py b/tools/metadoc.py index 4c2490dd7..22655adf7 100644 --- a/tools/metadoc.py +++ b/tools/metadoc.py @@ -417,7 +417,7 @@ class Translator: else: if namespace is None: description = ref.find_root() - namespaceObj = description.relatedObject.find_first_ancestor_by_type((abstractapi.Namespace, abstractapi.Class)) + namespaceObj = description.relatedObject.find_first_ancestor_by_type(abstractapi.Namespace, abstractapi.Class) namespace = namespaceObj.name if namespace.is_prefix_of(ref.relatedObject.name): commonName = namespace diff --git a/wrappers/cpp/genwrapper.py b/wrappers/cpp/genwrapper.py index 9230333d9..5d34caf13 100755 --- a/wrappers/cpp/genwrapper.py +++ b/wrappers/cpp/genwrapper.py @@ -136,8 +136,8 @@ class CppTranslator(object): return classDict def _generate_wrapper_callback(self, listenedClass, method): - namespace = method.find_first_ancestor_by_type((AbsApi.Namespace,)) - listenedClass = method.find_first_ancestor_by_type((AbsApi.Interface,)).listenedClass + namespace = method.find_first_ancestor_by_type(AbsApi.Namespace) + listenedClass = method.find_first_ancestor_by_type(AbsApi.Interface).listenedClass params = {} params['name'] = method.name.to_snake_case(fullName=True) + '_cb' @@ -188,7 +188,7 @@ class CppTranslator(object): return res def translate_method(self, method, genImpl=True): - namespace = method.find_first_ancestor_by_type((AbsApi.Class, AbsApi.Interface)) + namespace = method.find_first_ancestor_by_type(AbsApi.Class, AbsApi.Interface) methodDict = { 'declPrototype': method.translate_as_prototype(self.langTranslator, namespace=namespace), @@ -235,7 +235,7 @@ class CppTranslator(object): def _generate_wrapped_arguments(self, method, usedNamespace=None): args = [] if method.type == AbsApi.Method.Type.Instance: - _class = method.find_first_ancestor_by_type((AbsApi.Class,)) + _class = method.find_first_ancestor_by_type(AbsApi.Class) argStr = '(::{0} *)mPrivPtr'.format(_class.name.to_camel_case(fullName=True)) args.append(argStr) @@ -414,14 +414,14 @@ class ClassHeader(object): decl = 'class ' + class_.name.translate(translator) self._add_prior_declaration(decl) else: - rootClass = class_.find_first_ancestor_by_type((AbsApi.Namespace,), priorAncestor=True) + rootClass = class_.find_first_ancestor_by_type(AbsApi.Namespace, priorAncestor=True) self._add_include(includes, 'internal', rootClass.name.to_snake_case()) elif isinstance(type_, AbsApi.EnumType): enum = type_.desc if enum.parent == self.rootNs: headerFile = 'enums' else: - rootClass = enum.find_first_ancestor_by_type((AbsApi.Namespace, ), priorAncestor=True) + rootClass = enum.find_first_ancestor_by_type(AbsApi.Namespace, priorAncestor=True) headerFile = rootClass.name.to_snake_case() self._add_include(includes, 'internal', headerFile) elif isinstance(type_, AbsApi.BaseType):