Commit 04a024ec authored by François Grisez's avatar François Grisez

Revert "Fixes C++ wrapper generation with Python 2"

This reverts commit 7d621c5b and
proposes a way to fix the generation with Python 2 without
breaking abstractapi's interface.
parent 4511ad79
......@@ -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 ''
......
......@@ -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
......
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment