diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 20c4084e0..1fda16ef6 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -672,8 +672,8 @@ void Class::python_wrapper(FileWriter& wrapperFile) const { } /* ************************************************************************* */ -void Class::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile) const { - string cythonClassName = qualifiedName("_"); +void Class::emit_cython_pxd(FileWriter& pxdFile) const { + string cythonClassName = qualifiedName("_", 1); pxdFile.oss << "cdef extern from \"" << includeFile << "\" namespace \"" << qualifiedNamespaces("::") << "\":" << endl; pxdFile.oss << "\tcdef cppclass " << cythonClassName << " \"" << qualifiedName("::") << "\""; @@ -688,13 +688,7 @@ void Class::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile) const { if (parentClass) pxdFile.oss << "(" << parentClass->qualifiedName("_") << ")"; pxdFile.oss << ":\n"; - pyxFile.oss << "cdef class " << name(); - if (parentClass) pyxFile.oss << "(" << parentClass->name() << ")"; - pyxFile.oss << ":\n"; - pyxFile.oss << "\tcdef shared_ptr[" << cythonClassName << "] " - << "gt" << name() << "_\n"; - - constructor.cython_wrapper(pxdFile, pyxFile, cythonClassName); + constructor.emit_cython_pxd(pxdFile, cythonClassName); if (constructor.nrOverloads()>0) pxdFile.oss << "\n"; for(const StaticMethod& m: static_methods | boost::adaptors::map_values) @@ -710,6 +704,17 @@ void Class::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile) const { if (numMethods == 0) pxdFile.oss << "\t\tpass"; pxdFile.oss << "\n\n"; +} + +void Class::emit_cython_pyx(FileWriter& pyxFile) const { + string cythonClassName = qualifiedName("_", 1); + pyxFile.oss << "cdef class " << name(); + if (parentClass) pyxFile.oss << "(" << parentClass->name() << ")"; + pyxFile.oss << ":\n"; + pyxFile.oss << "\tcdef shared_ptr[" << cythonClassName << "] " + << "gt" << name() << "_\n"; + + constructor.emit_cython_pyx(pyxFile, cythonClassName); pyxFile.oss << "\n"; } diff --git a/wrap/Class.h b/wrap/Class.h index ad9fec9e9..c9b80ba30 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -148,7 +148,8 @@ public: void python_wrapper(FileWriter& wrapperFile) const; // emit cython wrapper - void cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile) const; + void emit_cython_pxd(FileWriter& pxdFile) const; + void emit_cython_pyx(FileWriter& pyxFile) const; friend std::ostream& operator<<(std::ostream& os, const Class& cls) { os << "class " << cls.name() << "{\n"; diff --git a/wrap/Constructor.cpp b/wrap/Constructor.cpp index a15197813..fce4a25d6 100644 --- a/wrap/Constructor.cpp +++ b/wrap/Constructor.cpp @@ -121,7 +121,7 @@ void Constructor::python_wrapper(FileWriter& wrapperFile, Str className) const { } /* ************************************************************************* */ -void Constructor::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile, Str className) const { +void Constructor::emit_cython_pxd(FileWriter& pxdFile, Str className) const { for (size_t i = 0; i < nrOverloads(); i++) { ArgumentList args = argumentList(i); pxdFile.oss << "\t\t" << className << "("; @@ -131,3 +131,7 @@ void Constructor::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile, Str c } /* ************************************************************************* */ +void Constructor::emit_cython_pyx(FileWriter& pyxFile, Str className) const { +} + +/* ************************************************************************* */ diff --git a/wrap/Constructor.h b/wrap/Constructor.h index ed55715b8..ace630c4b 100644 --- a/wrap/Constructor.h +++ b/wrap/Constructor.h @@ -79,7 +79,8 @@ struct Constructor: public OverloadedFunction { void python_wrapper(FileWriter& wrapperFile, Str className) const; // emit cython wrapper - void cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile, Str className) const; + void emit_cython_pxd(FileWriter& pxdFile, Str className) const; + void emit_cython_pyx(FileWriter& pyxFile, Str className) const; friend std::ostream& operator<<(std::ostream& os, const Constructor& m) { for (size_t i = 0; i < m.nrOverloads(); i++) diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 1036ee8ca..e7e4ec819 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -294,13 +294,16 @@ void Module::cython_code(const string& toolboxPath) const { FileWriter pxdFile(pxdFileName, verbose, "#"); FileWriter pyxFile(pyxFileName, verbose, "#"); - // create proxy class and wrapper code + // create cython pxd file for(const Class& cls: uninstantiatedClasses) - cls.cython_wrapper(pxdFile, pyxFile); - + cls.emit_cython_pxd(pxdFile); // finish wrapper file pxdFile.oss << "\n"; pxdFile.emit(true); + + // create cython pyx file + for(const Class& cls: uninstantiatedClasses) + cls.emit_cython_pyx(pyxFile); pyxFile.oss << "\n"; pyxFile.emit(true); } diff --git a/wrap/Qualified.h b/wrap/Qualified.h index 31148ebe6..52bf19914 100644 --- a/wrap/Qualified.h +++ b/wrap/Qualified.h @@ -137,9 +137,9 @@ public: } /// Return a qualified string using given delimiter - std::string qualifiedName(const std::string& delimiter = "") const { + std::string qualifiedName(const std::string& delimiter = "", size_t fromLevel = 0) const { std::string result; - for (std::size_t i = 0; i < namespaces_.size(); ++i) + for (std::size_t i = fromLevel; i < namespaces_.size(); ++i) result += (namespaces_[i] + delimiter); result += name_; return result;