Undo unrelated changes

release/4.3a0
dellaert 2017-08-06 17:42:20 -07:00
parent 3bbea0f301
commit c5a0f1a839
4 changed files with 95 additions and 95 deletions

View File

@ -176,7 +176,7 @@ void Class::matlab_proxy(Str toolboxPath, Str wrapperName,
proxyFile.oss << " methods(Static = true)\n"; proxyFile.oss << " methods(Static = true)\n";
// Static methods // Static methods
for(const StaticMethods::value_type& name_m: static_methods_) { for(const StaticMethods::value_type& name_m: static_methods) {
const StaticMethod& m = name_m.second; const StaticMethod& m = name_m.second;
m.proxy_wrapper_fragments(proxyFile, wrapperFile, cppName, matlabQualName, m.proxy_wrapper_fragments(proxyFile, wrapperFile, cppName, matlabQualName,
matlabUniqueName, wrapperName, typeAttributes, functionNames); matlabUniqueName, wrapperName, typeAttributes, functionNames);
@ -295,7 +295,7 @@ void Class::pointer_constructor_fragments(FileWriter& proxyFile,
Class Class::expandTemplate(const TemplateSubstitution& ts) const { Class Class::expandTemplate(const TemplateSubstitution& ts) const {
Class inst = *this; Class inst = *this;
inst.methods_ = expandMethodTemplate(methods_, ts); inst.methods_ = expandMethodTemplate(methods_, ts);
inst.static_methods_ = expandMethodTemplate(static_methods_, ts); inst.static_methods = expandMethodTemplate(static_methods, ts);
inst.constructor = constructor.expandTemplate(ts); inst.constructor = constructor.expandTemplate(ts);
inst.deconstructor.name = inst.name(); inst.deconstructor.name = inst.name();
return inst; return inst;
@ -409,11 +409,11 @@ void Class::verifyAll(vector<string>& validTypes, bool& hasSerialiable) const {
// verify all of the function arguments // verify all of the function arguments
//TODO:verifyArguments<ArgumentList>(validTypes, constructor.args_list); //TODO:verifyArguments<ArgumentList>(validTypes, constructor.args_list);
verifyArguments<StaticMethod>(validTypes, static_methods_); verifyArguments<StaticMethod>(validTypes, static_methods);
verifyArguments<Method>(validTypes, methods_); verifyArguments<Method>(validTypes, methods_);
// verify function return types // verify function return types
verifyReturnTypes<StaticMethod>(validTypes, static_methods_); verifyReturnTypes<StaticMethod>(validTypes, static_methods);
verifyReturnTypes<Method>(validTypes, methods_); verifyReturnTypes<Method>(validTypes, methods_);
// verify parents // verify parents
@ -517,9 +517,9 @@ void Class::comment_fragment(FileWriter& proxyFile) const {
for(const Methods::value_type& name_m: methods_) for(const Methods::value_type& name_m: methods_)
name_m.second.comment_fragment(proxyFile); name_m.second.comment_fragment(proxyFile);
if (!static_methods_.empty()) if (!static_methods.empty())
proxyFile.oss << "%\n%-------Static Methods-------\n"; proxyFile.oss << "%\n%-------Static Methods-------\n";
for(const StaticMethods::value_type& name_m: static_methods_) for(const StaticMethods::value_type& name_m: static_methods)
name_m.second.comment_fragment(proxyFile); name_m.second.comment_fragment(proxyFile);
if (hasSerialization) { if (hasSerialization) {
@ -721,7 +721,7 @@ string Class::getSerializationExport() const {
void Class::python_wrapper(FileWriter& wrapperFile) const { void Class::python_wrapper(FileWriter& wrapperFile) const {
wrapperFile.oss << "class_<" << name() << ">(\"" << name() << "\")\n"; wrapperFile.oss << "class_<" << name() << ">(\"" << name() << "\")\n";
constructor.python_wrapper(wrapperFile, name()); constructor.python_wrapper(wrapperFile, name());
for(const StaticMethod& m: static_methods_ | boost::adaptors::map_values) for(const StaticMethod& m: static_methods | boost::adaptors::map_values)
m.python_wrapper(wrapperFile, name()); m.python_wrapper(wrapperFile, name());
for(const Method& m: methods_ | boost::adaptors::map_values) for(const Method& m: methods_ | boost::adaptors::map_values)
m.python_wrapper(wrapperFile, name()); m.python_wrapper(wrapperFile, name());
@ -729,64 +729,64 @@ void Class::python_wrapper(FileWriter& wrapperFile) const {
} }
/* ************************************************************************* */ /* ************************************************************************* */
void Class::emit_cython_pxd(FileWriter& file) const { void Class::emit_cython_pxd(FileWriter& pxdFile) const {
file.oss << "cdef extern from \"" << includeFile << "\""; pxdFile.oss << "cdef extern from \"" << includeFile << "\"";
string ns = qualifiedNamespaces("::"); string ns = qualifiedNamespaces("::");
if (!ns.empty()) if (!ns.empty())
file.oss << " namespace \"" << ns << "\""; pxdFile.oss << " namespace \"" << ns << "\"";
file.oss << ":" << endl; pxdFile.oss << ":" << endl;
file.oss << " cdef cppclass " << pxdClassName() << " \"" << qualifiedName("::") << "\""; pxdFile.oss << " cdef cppclass " << pxdClassName() << " \"" << qualifiedName("::") << "\"";
if (templateArgs.size()>0) { if (templateArgs.size()>0) {
file.oss << "["; pxdFile.oss << "[";
for(size_t i = 0; i<templateArgs.size(); ++i) { for(size_t i = 0; i<templateArgs.size(); ++i) {
file.oss << templateArgs[i]; pxdFile.oss << templateArgs[i];
if (i<templateArgs.size()-1) file.oss << ","; if (i<templateArgs.size()-1) pxdFile.oss << ",";
} }
file.oss << "]"; pxdFile.oss << "]";
} }
if (parentClass) file.oss << "(" << parentClass->pxdClassName() << ")"; if (parentClass) pxdFile.oss << "(" << parentClass->pxdClassName() << ")";
file.oss << ":\n"; pxdFile.oss << ":\n";
constructor.emit_cython_pxd(file, *this); constructor.emit_cython_pxd(pxdFile, *this);
if (constructor.nrOverloads()>0) file.oss << "\n"; if (constructor.nrOverloads()>0) pxdFile.oss << "\n";
for(const StaticMethod& m: static_methods_ | boost::adaptors::map_values) for(const StaticMethod& m: static_methods | boost::adaptors::map_values)
m.emit_cython_pxd(file, *this); m.emit_cython_pxd(pxdFile, *this);
if (static_methods_.size()>0) file.oss << "\n"; if (static_methods.size()>0) pxdFile.oss << "\n";
for(const Method& m: nontemplateMethods_ | boost::adaptors::map_values) for(const Method& m: nontemplateMethods_ | boost::adaptors::map_values)
m.emit_cython_pxd(file, *this); m.emit_cython_pxd(pxdFile, *this);
for(const TemplateMethod& m: templateMethods_ | boost::adaptors::map_values) for(const TemplateMethod& m: templateMethods_ | boost::adaptors::map_values)
m.emit_cython_pxd(file, *this); m.emit_cython_pxd(pxdFile, *this);
size_t numMethods = constructor.nrOverloads() + static_methods_.size() + size_t numMethods = constructor.nrOverloads() + static_methods.size() +
methods_.size() + templateMethods_.size(); methods_.size() + templateMethods_.size();
if (numMethods == 0) if (numMethods == 0)
file.oss << " pass\n"; pxdFile.oss << " pass\n";
} }
/* ************************************************************************* */ /* ************************************************************************* */
void Class::emit_cython_wrapper_pxd(FileWriter& file) const { void Class::emit_cython_wrapper_pxd(FileWriter& pxdFile) const {
file.oss << "\ncdef class " << pyxClassName(); pxdFile.oss << "\ncdef class " << pyxClassName();
if (getParent()) if (getParent())
file.oss << "(" << getParent()->pyxClassName() << ")"; pxdFile.oss << "(" << getParent()->pyxClassName() << ")";
file.oss << ":\n"; pxdFile.oss << ":\n";
file.oss << " cdef " << shared_pxd_class_in_pyx() << " " pxdFile.oss << " cdef " << shared_pxd_class_in_pyx() << " "
<< shared_pxd_obj_in_pyx() << "\n"; << shared_pxd_obj_in_pyx() << "\n";
// cyCreateFromShared // cyCreateFromShared
file.oss << " @staticmethod\n"; pxdFile.oss << " @staticmethod\n";
file.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const " pxdFile.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const "
<< shared_pxd_class_in_pyx() << "& other)\n"; << shared_pxd_class_in_pyx() << "& other)\n";
for(const StaticMethod& m: static_methods_ | boost::adaptors::map_values) for(const StaticMethod& m: static_methods | boost::adaptors::map_values)
m.emit_cython_wrapper_pxd(file, *this); m.emit_cython_wrapper_pxd(pxdFile, *this);
if (static_methods_.size()>0) file.oss << "\n"; if (static_methods.size()>0) pxdFile.oss << "\n";
} }
/* ************************************************************************* */ /* ************************************************************************* */
void Class::pyxInitParentObj(FileWriter& file, const std::string& pyObj, void Class::pyxInitParentObj(FileWriter& pyxFile, const std::string& pyObj,
const std::string& cySharedObj, const std::string& cySharedObj,
const std::vector<Class>& allClasses) const { const std::vector<Class>& allClasses) const {
if (parentClass) { if (parentClass) {
file.oss << pyObj << "." << parentClass->shared_pxd_obj_in_pyx() << " = " pyxFile.oss << pyObj << "." << parentClass->shared_pxd_obj_in_pyx() << " = "
<< "<" << parentClass->shared_pxd_class_in_pyx() << ">(" << "<" << parentClass->shared_pxd_class_in_pyx() << ">("
<< cySharedObj << ")\n"; << cySharedObj << ")\n";
// Find the parent class with name "parentClass" and point its cython obj // Find the parent class with name "parentClass" and point its cython obj
@ -800,27 +800,27 @@ void Class::pyxInitParentObj(FileWriter& file, const std::string& pyObj,
cerr << "Can't find parent class: " << parentClass->pxdClassName(); cerr << "Can't find parent class: " << parentClass->pxdClassName();
throw std::runtime_error("Parent class not found!"); throw std::runtime_error("Parent class not found!");
} }
parent_it->pyxInitParentObj(file, pyObj, cySharedObj, allClasses); parent_it->pyxInitParentObj(pyxFile, pyObj, cySharedObj, allClasses);
} }
} }
/* ************************************************************************* */ /* ************************************************************************* */
void Class::pyxDynamicCast(FileWriter& file, const Class& curLevel, void Class::pyxDynamicCast(FileWriter& pyxFile, const Class& curLevel,
const std::vector<Class>& allClasses) const { const std::vector<Class>& allClasses) const {
std::string me = this->pyxClassName(), sharedMe = this->shared_pxd_class_in_pyx(); std::string me = this->pyxClassName(), sharedMe = this->shared_pxd_class_in_pyx();
if (curLevel.parentClass) { if (curLevel.parentClass) {
std::string parent = curLevel.parentClass->pyxClassName(), std::string parent = curLevel.parentClass->pyxClassName(),
parentObj = curLevel.parentClass->shared_pxd_obj_in_pyx(), parentObj = curLevel.parentClass->shared_pxd_obj_in_pyx(),
parentCythonClass = curLevel.parentClass->pxd_class_in_pyx(); parentCythonClass = curLevel.parentClass->pxd_class_in_pyx();
file.oss << "def dynamic_cast_" << me << "_" << parent << "(" << parent pyxFile.oss << "def dynamic_cast_" << me << "_" << parent << "(" << parent
<< " parent):\n"; << " parent):\n";
file.oss << " try:\n"; pyxFile.oss << " try:\n";
file.oss << " return " << me << ".cyCreateFromShared(<" << sharedMe pyxFile.oss << " return " << me << ".cyCreateFromShared(<" << sharedMe
<< ">dynamic_pointer_cast[" << pxd_class_in_pyx() << "," << ">dynamic_pointer_cast[" << pxd_class_in_pyx() << ","
<< parentCythonClass << "](parent." << parentObj << parentCythonClass << "](parent." << parentObj
<< "))\n"; << "))\n";
file.oss << " except:\n"; pyxFile.oss << " except:\n";
file.oss << " raise TypeError('dynamic cast failed!')\n"; pyxFile.oss << " raise TypeError('dynamic cast failed!')\n";
// Move up higher to one level: Find the parent class with name "parentClass" // Move up higher to one level: Find the parent class with name "parentClass"
auto parent_it = find_if(allClasses.begin(), allClasses.end(), auto parent_it = find_if(allClasses.begin(), allClasses.end(),
[&curLevel](const Class& cls) { [&curLevel](const Class& cls) {
@ -831,51 +831,51 @@ void Class::pyxDynamicCast(FileWriter& file, const Class& curLevel,
cerr << "Can't find parent class: " << parentClass->pxdClassName(); cerr << "Can't find parent class: " << parentClass->pxdClassName();
throw std::runtime_error("Parent class not found!"); throw std::runtime_error("Parent class not found!");
} }
pyxDynamicCast(file, *parent_it, allClasses); pyxDynamicCast(pyxFile, *parent_it, allClasses);
} }
} }
/* ************************************************************************* */ /* ************************************************************************* */
void Class::emit_cython_pyx(FileWriter& file, const std::vector<Class>& allClasses) const { void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector<Class>& allClasses) const {
file.oss << "cdef class " << pyxClassName(); pyxFile.oss << "cdef class " << pyxClassName();
if (parentClass) file.oss << "(" << parentClass->pyxClassName() << ")"; if (parentClass) pyxFile.oss << "(" << parentClass->pyxClassName() << ")";
file.oss << ":\n"; pyxFile.oss << ":\n";
// __init___ // __init___
file.oss << " def __init__(self, *args, **kwargs):\n"; pyxFile.oss << " def __init__(self, *args, **kwargs):\n";
file.oss << " cdef list __params\n"; pyxFile.oss << " cdef list __params\n";
file.oss << " self." << shared_pxd_obj_in_pyx() << " = " << shared_pxd_class_in_pyx() << "()\n"; pyxFile.oss << " self." << shared_pxd_obj_in_pyx() << " = " << shared_pxd_class_in_pyx() << "()\n";
file.oss << " if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'):\n return\n"; pyxFile.oss << " if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'):\n return\n";
// Constructors // Constructors
constructor.emit_cython_pyx(file, *this); constructor.emit_cython_pyx(pyxFile, *this);
file.oss << " if (self." << shared_pxd_obj_in_pyx() << ".use_count()==0):\n"; pyxFile.oss << " if (self." << shared_pxd_obj_in_pyx() << ".use_count()==0):\n";
file.oss << " raise TypeError('" << pyxClassName() pyxFile.oss << " raise TypeError('" << pyxClassName()
<< " construction failed!')\n"; << " construction failed!')\n";
pyxInitParentObj(file, " self", "self." + shared_pxd_obj_in_pyx(), allClasses); pyxInitParentObj(pyxFile, " self", "self." + shared_pxd_obj_in_pyx(), allClasses);
file.oss << "\n"; pyxFile.oss << "\n";
// cyCreateFromShared // cyCreateFromShared
file.oss << " @staticmethod\n"; pyxFile.oss << " @staticmethod\n";
file.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const " pyxFile.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const "
<< shared_pxd_class_in_pyx() << "& other):\n" << shared_pxd_class_in_pyx() << "& other):\n"
<< " if other.get() == NULL:\n" << " if other.get() == NULL:\n"
<< " raise RuntimeError('Cannot create object from a nullptr!')\n" << " raise RuntimeError('Cannot create object from a nullptr!')\n"
<< " cdef " << pyxClassName() << " return_value = " << pyxClassName() << "(cyCreateFromShared=True)\n" << " cdef " << pyxClassName() << " return_value = " << pyxClassName() << "(cyCreateFromShared=True)\n"
<< " return_value." << shared_pxd_obj_in_pyx() << " = other\n"; << " return_value." << shared_pxd_obj_in_pyx() << " = other\n";
pyxInitParentObj(file, " return_value", "other", allClasses); pyxInitParentObj(pyxFile, " return_value", "other", allClasses);
file.oss << " return return_value" << "\n\n"; pyxFile.oss << " return return_value" << "\n\n";
for(const StaticMethod& m: static_methods_ | boost::adaptors::map_values) for(const StaticMethod& m: static_methods | boost::adaptors::map_values)
m.emit_cython_pyx(file, *this); m.emit_cython_pyx(pyxFile, *this);
if (static_methods_.size()>0) file.oss << "\n"; if (static_methods.size()>0) pyxFile.oss << "\n";
for(const Method& m: methods_ | boost::adaptors::map_values) for(const Method& m: methods_ | boost::adaptors::map_values)
m.emit_cython_pyx(file, *this); m.emit_cython_pyx(pyxFile, *this);
pyxDynamicCast(file, *this, allClasses); pyxDynamicCast(pyxFile, *this, allClasses);
file.oss << "\n\n"; pyxFile.oss << "\n\n";
} }
/* ************************************************************************* */ /* ************************************************************************* */

View File

@ -67,7 +67,7 @@ private:
public: public:
StaticMethods static_methods_; ///< Static methods StaticMethods static_methods; ///< Static methods
// 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
@ -177,7 +177,7 @@ public:
friend std::ostream& operator<<(std::ostream& os, const Class& cls) { friend std::ostream& operator<<(std::ostream& os, const Class& cls) {
os << "class " << cls.name() << "{\n"; os << "class " << cls.name() << "{\n";
os << cls.constructor << ";\n"; os << cls.constructor << ";\n";
for(const StaticMethod& m: cls.static_methods_ | boost::adaptors::map_values) for(const StaticMethod& m: cls.static_methods | boost::adaptors::map_values)
os << m << ";\n"; os << m << ";\n";
for(const Method& m: cls.methods_ | boost::adaptors::map_values) for(const Method& m: cls.methods_ | boost::adaptors::map_values)
os << m << ";\n"; os << m << ";\n";
@ -272,7 +272,7 @@ struct ClassGrammar: public classic::grammar<ClassGrammar> {
>> staticMethodName_p[assign_a(methodName)] >> argumentList_g >> ';' >> staticMethodName_p[assign_a(methodName)] >> argumentList_g >> ';'
>> *comments_p) // >> *comments_p) //
[bl::bind(&StaticMethod::addOverload, [bl::bind(&StaticMethod::addOverload,
bl::var(self.cls_.static_methods_)[bl::var(methodName)], bl::var(self.cls_.static_methods)[bl::var(methodName)],
bl::var(methodName), bl::var(args), bl::var(retVal), boost::none, bl::var(methodName), bl::var(args), bl::var(retVal), boost::none,
verbose)] // verbose)] //
[assign_a(retVal, retVal0)][clear_a(args)]; [assign_a(retVal, retVal0)][clear_a(args)];

View File

@ -129,31 +129,31 @@ bool Constructor::hasDefaultConstructor() const {
} }
/* ************************************************************************* */ /* ************************************************************************* */
void Constructor::emit_cython_pxd(FileWriter& file, const Class& cls) const { void Constructor::emit_cython_pxd(FileWriter& pxdFile, const Class& cls) const {
for (size_t i = 0; i < nrOverloads(); i++) { for (size_t i = 0; i < nrOverloads(); i++) {
ArgumentList args = argumentList(i); ArgumentList args = argumentList(i);
// generate the constructor // generate the constructor
file.oss << " " << cls.pxdClassName() << "("; pxdFile.oss << " " << cls.pxdClassName() << "(";
args.emit_cython_pxd(file, cls.pxdClassName(), cls.templateArgs); args.emit_cython_pxd(pxdFile, cls.pxdClassName(), cls.templateArgs);
file.oss << ") " << "except +\n"; pxdFile.oss << ") " << "except +\n";
} }
} }
/* ************************************************************************* */ /* ************************************************************************* */
void Constructor::emit_cython_pyx(FileWriter& file, const Class& cls) const { void Constructor::emit_cython_pyx(FileWriter& pyxFile, const Class& cls) const {
for (size_t i = 0; i < nrOverloads(); i++) { for (size_t i = 0; i < nrOverloads(); i++) {
ArgumentList args = argumentList(i); ArgumentList args = argumentList(i);
file.oss << " try:\n"; pyxFile.oss << " try:\n";
file.oss << pyx_resolveOverloadParams(args, true, 3); pyxFile.oss << pyx_resolveOverloadParams(args, true, 3);
file.oss pyxFile.oss
<< argumentList(i).pyx_convertEigenTypeAndStorageOrder(" "); << argumentList(i).pyx_convertEigenTypeAndStorageOrder(" ");
file.oss << " self." << cls.shared_pxd_obj_in_pyx() << " = " pyxFile.oss << " self." << cls.shared_pxd_obj_in_pyx() << " = "
<< cls.shared_pxd_class_in_pyx() << "(new " << cls.pxd_class_in_pyx() << cls.shared_pxd_class_in_pyx() << "(new " << cls.pxd_class_in_pyx()
<< "(" << args.pyx_asParams() << "))\n"; << "(" << args.pyx_asParams() << "))\n";
file.oss << " except:\n"; pyxFile.oss << " except:\n";
file.oss << " pass\n"; pyxFile.oss << " pass\n";
} }
} }

View File

@ -360,26 +360,26 @@ void Module::emit_cython_pxd(FileWriter& pxdFile) const {
for (const Class& cls : uninstantiatedClasses) { for (const Class& cls : uninstantiatedClasses) {
cls.emit_cython_pxd(pxdFile); cls.emit_cython_pxd(pxdFile);
for (const Class& expanded : expandedClasses) { for (const Class& expCls : expandedClasses) {
bool matchingNonTemplated = !expanded.templateClass bool matchingNonTemplated = !expCls.templateClass
&& expanded.pxdClassName() == cls.pxdClassName(); && expCls.pxdClassName() == cls.pxdClassName();
bool isTemplatedFromCls = expanded.templateClass bool isTemplatedFromCls = expCls.templateClass
&& expanded.templateClass->pxdClassName() == cls.pxdClassName(); && expCls.templateClass->pxdClassName() == cls.pxdClassName();
// ctypedef for template instantiations // ctypedef for template instantiations
if (isTemplatedFromCls) { if (isTemplatedFromCls) {
pxdFile.oss << "\n"; pxdFile.oss << "\n";
pxdFile.oss << "ctypedef " << expanded.templateClass->pxdClassName() pxdFile.oss << "ctypedef " << expCls.templateClass->pxdClassName()
<< "["; << "[";
for (size_t i = 0; i < expanded.templateInstTypeList.size(); ++i) for (size_t i = 0; i < expCls.templateInstTypeList.size(); ++i)
pxdFile.oss << expanded.templateInstTypeList[i].pxdClassName() pxdFile.oss << expCls.templateInstTypeList[i].pxdClassName()
<< ((i == expanded.templateInstTypeList.size() - 1) ? "" : ", "); << ((i == expCls.templateInstTypeList.size() - 1) ? "" : ", ");
pxdFile.oss << "] " << expanded.pxdClassName() << "\n"; pxdFile.oss << "] " << expCls.pxdClassName() << "\n";
} }
// Python wrapper class // Python wrapper class
if (isTemplatedFromCls || matchingNonTemplated) { if (isTemplatedFromCls || matchingNonTemplated) {
expanded.emit_cython_wrapper_pxd(pxdFile); expCls.emit_cython_wrapper_pxd(pxdFile);
} }
} }
pxdFile.oss << "\n\n"; pxdFile.oss << "\n\n";