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();
if (numMethods == 0)
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);
// ignore copy constructor, it's generated above by default
if (args.size() == 1 && args[0].is_const && args[0].is_ref &&
!args[0].is_ptr) {
cout << args[0].type.cythonClass() << " vs " << className << endl;
if (args[0].type.cythonClass() == className ||
args[0].type.cythonClass() == "This")
!args[0].is_ptr && (args[0].type.cythonClass() == className ||
args[0].type.cythonClass() == "This"))
continue;
}
// generate the constructor
pxdFile.oss << "\t\t" << className << "(";

View File

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