Cython pxd: putting template instantiations at the correct place right after a template class

release/4.3a0
Duy-Nguyen Ta 2016-09-12 18:36:45 -04:00
parent 6044bffd8a
commit 53dbe25c50
3 changed files with 20 additions and 21 deletions

View File

@ -759,8 +759,6 @@ void Class::emit_cython_pxd(FileWriter& pxdFile, const std::vector<Class>& allCl
methods_.size() + templateMethods_.size(); methods_.size() + templateMethods_.size();
if (numMethods == 0) if (numMethods == 0)
pxdFile.oss << "\t\tpass"; pxdFile.oss << "\t\tpass";
pxdFile.oss << "\n\n";
} }
/* ************************************************************************* */ /* ************************************************************************* */

View File

@ -141,12 +141,9 @@ void Constructor::emit_cython_pxd(FileWriter& pxdFile, Str className) const {
ArgumentList args = argumentList(i); ArgumentList args = argumentList(i);
// ignore copy constructor, it's generated above by default // ignore copy constructor, it's generated above by default
if (args.size() == 1 && args[0].is_const && args[0].is_ref && if (args.size() == 1 && args[0].is_const && args[0].is_ref &&
!args[0].is_ptr) { !args[0].is_ptr && (args[0].type.cythonClass() == className ||
cout << args[0].type.cythonClass() << " vs " << className << endl; args[0].type.cythonClass() == "This"))
if (args[0].type.cythonClass() == className ||
args[0].type.cythonClass() == "This")
continue; continue;
}
// generate the constructor // generate the constructor
pxdFile.oss << "\t\t" << className << "("; pxdFile.oss << "\t\t" << className << "(";

View File

@ -344,21 +344,25 @@ void Module::emit_cython_pxd(FileWriter& pxdFile) const {
types.emit_cython_pxd(pxdFile); types.emit_cython_pxd(pxdFile);
//... wrap all classes //... wrap all classes
for(const Class& cls: uninstantiatedClasses) for (const Class& cls : uninstantiatedClasses) {
cls.emit_cython_pxd(pxdFile, uninstantiatedClasses); cls.emit_cython_pxd(pxdFile, uninstantiatedClasses);
pxdFile.oss << "\n";
//... ctypedef for template instantiations
// TODO: put them in the correct place!!! //... ctypedef for template instantiations
for(const Class& cls: expandedClasses) { for (const Class& expCls : expandedClasses) {
if (cls.templateClass) { if (!expCls.templateClass || expCls.templateClass->name_ != cls.name_)
pxdFile.oss << "ctypedef " << cls.templateClass->cythonClass() << "["; continue;
for (size_t i = 0; i<cls.templateInstTypeList.size(); ++i) pxdFile.oss << "ctypedef " << expCls.templateClass->cythonClass()
pxdFile.oss << cls.templateInstTypeList[i].cythonClass() << "[";
<< ((i==cls.templateInstTypeList.size()-1)?"":", "); for (size_t i = 0; i < expCls.templateInstTypeList.size(); ++i)
pxdFile.oss << "] " << cls.cythonClass() << "\n"; pxdFile.oss << expCls.templateInstTypeList[i].cythonClass()
} << ((i == expCls.templateInstTypeList.size() - 1)
? ""
: ", ");
pxdFile.oss << "] " << expCls.cythonClass() << "\n";
}
pxdFile.oss << "\n\n";
} }
pxdFile.oss << "\n";
pxdFile.emit(true); pxdFile.emit(true);
} }