From 7d621c5bd1e9e7f76ffeb90a0ad0f882b88efb92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Tue, 6 Feb 2018 16:49:15 +0100 Subject: [PATCH] Fixes C++ wrapper generation with Python 2 --- tools/abstractapi.py | 6 +++--- tools/metadoc.py | 2 +- wrappers/cpp/genwrapper.py | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/abstractapi.py b/tools/abstractapi.py index bbf95dfa1..941624d89 100644 --- a/tools/abstractapi.py +++ b/tools/abstractapi.py @@ -110,7 +110,7 @@ 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, priorAncestor=False): current = self ancestor = self.parent while ancestor is not None and type(ancestor) not in types: @@ -951,7 +951,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 +1000,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 22655adf7..4c2490dd7 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 5d34caf13..9230333d9 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):