Fix python submodules inheritance detection

This commit is contained in:
Maksim Shabunin 2015-03-26 11:22:52 +03:00
parent 97bdc92d1b
commit 82adf7955f

View File

@ -255,20 +255,24 @@ class ClassInfo(object):
self.methods = {} self.methods = {}
self.props = [] self.props = []
self.consts = {} self.consts = {}
self.base = None
customname = False customname = False
if decl: if decl:
self.bases = decl[1].split()[1:] bases = decl[1].split()[1:]
if len(self.bases) > 1: if len(bases) > 1:
print("Note: Class %s has more than 1 base class (not supported by Python C extensions)" % (self.name,)) print("Note: Class %s has more than 1 base class (not supported by Python C extensions)" % (self.name,))
print(" Bases: ", " ".join(self.bases)) print(" Bases: ", " ".join(bases))
print(" Only the first base class will be used") print(" Only the first base class will be used")
self.bases = [self.bases[0].strip(",")]
#return sys.exit(-1) #return sys.exit(-1)
if self.bases and self.bases[0].startswith("cv::"): elif len(bases) == 1:
self.bases[0] = self.bases[0][4:] self.base = bases[0].strip(",")
if self.bases and self.bases[0] == "Algorithm": if self.base.startswith("cv::"):
self.isalgorithm = True self.base = self.base[4:]
if self.base == "Algorithm":
self.isalgorithm = True
self.base = self.base.replace("::", "_")
for m in decl[2]: for m in decl[2]:
if m.startswith("="): if m.startswith("="):
self.wname = m[1:] self.wname = m[1:]
@ -285,8 +289,8 @@ class ClassInfo(object):
def gen_map_code(self, all_classes): def gen_map_code(self, all_classes):
code = "static bool pyopencv_to(PyObject* src, %s& dst, const char* name)\n{\n PyObject* tmp;\n bool ok;\n" % (self.cname) code = "static bool pyopencv_to(PyObject* src, %s& dst, const char* name)\n{\n PyObject* tmp;\n bool ok;\n" % (self.cname)
code += "".join([gen_template_set_prop_from_map.substitute(propname=p.name,proptype=p.tp) for p in self.props]) code += "".join([gen_template_set_prop_from_map.substitute(propname=p.name,proptype=p.tp) for p in self.props])
if self.bases: if self.base:
code += "\n return pyopencv_to(src, (%s&)dst, name);\n}\n" % all_classes[self.bases[0].replace("::", "_")].cname code += "\n return pyopencv_to(src, (%s&)dst, name);\n}\n" % all_classes[self.base].cname
else: else:
code += "\n return true;\n}\n" code += "\n return true;\n}\n"
return code return code
@ -330,8 +334,8 @@ class ClassInfo(object):
methods_inits.write(m.get_tab_entry()) methods_inits.write(m.get_tab_entry())
baseptr = "NULL" baseptr = "NULL"
if self.bases and self.bases[0] in all_classes: if self.base and self.base in all_classes:
baseptr = "&pyopencv_" + all_classes[self.bases[0]].name + "_Type" baseptr = "&pyopencv_" + all_classes[self.base].name + "_Type"
code = gen_template_type_impl.substitute(name=self.name, wname=self.wname, cname=self.cname, code = gen_template_type_impl.substitute(name=self.name, wname=self.wname, cname=self.cname,
getset_code=getset_code.getvalue(), getset_inits=getset_inits.getvalue(), getset_code=getset_code.getvalue(), getset_inits=getset_inits.getvalue(),
@ -753,17 +757,17 @@ class PythonWrapperGenerator(object):
sys.exit(-1) sys.exit(-1)
self.classes[classinfo.name] = classinfo self.classes[classinfo.name] = classinfo
if classinfo.bases: if classinfo.base:
chunks = classinfo.bases[0].split('::') chunks = classinfo.base.split('_')
base = '_'.join(chunks) base = '_'.join(chunks)
while base not in self.classes and len(chunks)>1: while base not in self.classes and len(chunks)>1:
del chunks[-2] del chunks[-2]
base = '_'.join(chunks) base = '_'.join(chunks)
if base not in self.classes: if base not in self.classes:
print("Generator error: unable to resolve base %s for %s" print("Generator error: unable to resolve base %s for %s"
% (classinfo.bases[0], classinfo.name)) % (classinfo.base, classinfo.name))
sys.exit(-1) sys.exit(-1)
classinfo.bases[0] = "::".join(chunks) classinfo.base = base
classinfo.isalgorithm |= self.classes[base].isalgorithm classinfo.isalgorithm |= self.classes[base].isalgorithm
def split_decl_name(self, name): def split_decl_name(self, name):