ctypedefs for all instantiated classes
parent
10f510119a
commit
d719b9b7ae
|
@ -309,6 +309,8 @@ vector<Class> Class::expandTemplate(Str templateArg,
|
||||||
inst.templateArgs.clear();
|
inst.templateArgs.clear();
|
||||||
inst.typedefName = qualifiedName("::") + "<" + instName.qualifiedName("::")
|
inst.typedefName = qualifiedName("::") + "<" + instName.qualifiedName("::")
|
||||||
+ ">";
|
+ ">";
|
||||||
|
inst.templateInstTypeList.push_back(instName);
|
||||||
|
inst.templateClass = *this;
|
||||||
result.push_back(inst);
|
result.push_back(inst);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -702,9 +704,11 @@ void Class::emit_cython_pxd(FileWriter& pxdFile) const {
|
||||||
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";
|
pxdFile.oss << "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
void Class::pyxInitParentObj(FileWriter& pyxFile, const std::string& pyObj, const std::string& cySharedObj, const std::vector<Class>& allClasses) const {
|
void Class::pyxInitParentObj(FileWriter& pyxFile, const std::string& pyObj, const std::string& cySharedObj, const std::vector<Class>& allClasses) const {
|
||||||
if (parentClass) {
|
if (parentClass) {
|
||||||
pyxFile.oss << pyObj << "." << parentClass->pyxCythonObj() << " = "
|
pyxFile.oss << pyObj << "." << parentClass->pyxCythonObj() << " = "
|
||||||
|
@ -725,6 +729,7 @@ void Class::pyxInitParentObj(FileWriter& pyxFile, const std::string& pyObj, cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector<Class>& allClasses) const {
|
void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector<Class>& allClasses) const {
|
||||||
pyxFile.oss << "cdef class " << pythonClassName();
|
pyxFile.oss << "cdef class " << pythonClassName();
|
||||||
if (parentClass) pyxFile.oss << "(" << parentClass->pythonClassName() << ")";
|
if (parentClass) pyxFile.oss << "(" << parentClass->pythonClassName() << ")";
|
||||||
|
|
|
@ -61,8 +61,8 @@ private:
|
||||||
|
|
||||||
boost::optional<Qualified> parentClass; ///< The *single* parent
|
boost::optional<Qualified> parentClass; ///< The *single* parent
|
||||||
Methods methods_; ///< Class methods, including all expanded/instantiated template methods
|
Methods methods_; ///< Class methods, including all expanded/instantiated template methods
|
||||||
Methods nontemplateMethods_;
|
Methods nontemplateMethods_; ///< only nontemplate methods
|
||||||
TemplateMethods templateMethods_;
|
TemplateMethods templateMethods_; ///< only template methods
|
||||||
// Method& mutableMethod(Str key);
|
// Method& mutableMethod(Str key);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -72,6 +72,10 @@ public:
|
||||||
// Then the instance variables are set directly by the Module constructor
|
// Then the instance variables are set directly by the Module constructor
|
||||||
std::vector<std::string> templateArgs; ///< Template arguments
|
std::vector<std::string> templateArgs; ///< Template arguments
|
||||||
std::string typedefName; ///< The name to typedef *from*, if this class is actually a typedef, i.e. typedef [typedefName] [name]
|
std::string typedefName; ///< The name to typedef *from*, if this class is actually a typedef, i.e. typedef [typedefName] [name]
|
||||||
|
std::vector<Qualified> templateInstTypeList; ///< the original typelist used to instantiate this class from a template.
|
||||||
|
///< Empty if it's not an instantiation
|
||||||
|
boost::optional<Qualified> templateClass = boost::none; ///< qualified name of the original template class from which this class was instantiated.
|
||||||
|
///< boost::none if not an instantiation
|
||||||
bool isVirtual; ///< Whether the class is part of a virtual inheritance chain
|
bool isVirtual; ///< Whether the class is part of a virtual inheritance chain
|
||||||
bool isSerializable; ///< Whether we can use boost.serialization to serialize the class - creates exports
|
bool isSerializable; ///< Whether we can use boost.serialization to serialize the class - creates exports
|
||||||
bool hasSerialization; ///< Whether we should create the serialization functions
|
bool hasSerialization; ///< Whether we should create the serialization functions
|
||||||
|
|
|
@ -288,20 +288,29 @@ void Module::cython_code(const string& toolboxPath) const {
|
||||||
|
|
||||||
fs::create_directories(toolboxPath);
|
fs::create_directories(toolboxPath);
|
||||||
|
|
||||||
// create the unified .cpp switch file
|
/// Create cython pxd file
|
||||||
string pxdFileName = toolboxPath + "/" + name + "_wrapper" + ".pxd";
|
string pxdFileName = toolboxPath + "/" + name + "_wrapper" + ".pxd";
|
||||||
string pyxFileName = toolboxPath + "/" + name + ".pyx";
|
|
||||||
FileWriter pxdFile(pxdFileName, verbose, "#");
|
FileWriter pxdFile(pxdFileName, verbose, "#");
|
||||||
FileWriter pyxFile(pyxFileName, verbose, "#");
|
//... wrap all classes
|
||||||
|
|
||||||
// create cython pxd file
|
|
||||||
for(const Class& cls: uninstantiatedClasses)
|
for(const Class& cls: uninstantiatedClasses)
|
||||||
cls.emit_cython_pxd(pxdFile);
|
cls.emit_cython_pxd(pxdFile);
|
||||||
// finish wrapper file
|
//... ctypedef for template instantiations
|
||||||
|
for(const Class& cls: expandedClasses) {
|
||||||
|
if (cls.templateClass) {
|
||||||
|
pxdFile.oss << "ctypedef " << cls.templateClass->cythonClassName() << "[";
|
||||||
|
for (size_t i = 0; i<cls.templateInstTypeList.size(); ++i)
|
||||||
|
pxdFile.oss << cls.templateInstTypeList[i].cythonClassName()
|
||||||
|
<< ((i==cls.templateInstTypeList.size()-1)?"":", ");
|
||||||
|
pxdFile.oss << "] " << cls.cythonClassName() << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// finish pxd wrapper file
|
||||||
pxdFile.oss << "\n";
|
pxdFile.oss << "\n";
|
||||||
pxdFile.emit(true);
|
pxdFile.emit(true);
|
||||||
|
|
||||||
// create cython pyx file
|
/// Create cython pyx file
|
||||||
|
string pyxFileName = toolboxPath + "/" + name + ".pyx";
|
||||||
|
FileWriter pyxFile(pyxFileName, verbose, "#");
|
||||||
for(const Class& cls: expandedClasses)
|
for(const Class& cls: expandedClasses)
|
||||||
cls.emit_cython_pyx(pyxFile, expandedClasses);
|
cls.emit_cython_pyx(pyxFile, expandedClasses);
|
||||||
pyxFile.oss << "\n";
|
pyxFile.oss << "\n";
|
||||||
|
@ -361,7 +370,7 @@ vector<Class> Module::ExpandTypedefInstantiations(const vector<Class>& classes,
|
||||||
|
|
||||||
// Remove all template classes
|
// Remove all template classes
|
||||||
for(size_t i = 0; i < expandedClasses.size(); ++i)
|
for(size_t i = 0; i < expandedClasses.size(); ++i)
|
||||||
if(!expandedClasses[size_t(i)].templateArgs.empty()) {
|
if(!expandedClasses[i].templateArgs.empty()) {
|
||||||
expandedClasses.erase(expandedClasses.begin() + size_t(i));
|
expandedClasses.erase(expandedClasses.begin() + size_t(i));
|
||||||
-- i;
|
-- i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,8 @@ Class TemplateInstantiationTypedef::findAndExpand(
|
||||||
for (size_t i = 1; i < typeList.size(); ++i)
|
for (size_t i = 1; i < typeList.size(); ++i)
|
||||||
classInst.typedefName += (", " + typeList[i].qualifiedName("::"));
|
classInst.typedefName += (", " + typeList[i].qualifiedName("::"));
|
||||||
classInst.typedefName += ">";
|
classInst.typedefName += ">";
|
||||||
|
classInst.templateClass = *matchedClass;
|
||||||
|
classInst.templateInstTypeList = typeList;
|
||||||
|
|
||||||
return classInst;
|
return classInst;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue