tabs to spaces

release/4.3a0
Duy-Nguyen Ta 2016-11-30 05:56:07 -05:00
parent 6297b55f28
commit 4439968f05
10 changed files with 77 additions and 77 deletions

View File

@ -252,12 +252,12 @@ std::string ArgumentList::pyx_paramsList() const {
/* ************************************************************************* */
std::string ArgumentList::pyx_castParamsToPythonType() const {
if (size() == 0)
return "\t\t\tpass\n";
return " pass\n";
// cast params to their correct python argument type to pass in the function call later
string s;
for (size_t j = 0; j < size(); ++j)
s += "\t\t\t" + at(j).name + " = <" + at(j).type.pyxArgumentType()
s += " " + at(j).name + " = <" + at(j).type.pyxArgumentType()
+ ">(__params['" + at(j).name + "'])\n";
return s;
}

View File

@ -732,7 +732,7 @@ void Class::python_wrapper(FileWriter& wrapperFile) const {
void Class::emit_cython_pxd(FileWriter& pxdFile, const std::vector<Class>& allClasses) const {
pxdFile.oss << "cdef extern from \"" << includeFile << "\" namespace \""
<< qualifiedNamespaces("::") << "\":" << endl;
pxdFile.oss << "\tcdef cppclass " << pxdClassName() << " \"" << qualifiedName("::") << "\"";
pxdFile.oss << " cdef cppclass " << pxdClassName() << " \"" << qualifiedName("::") << "\"";
if (templateArgs.size()>0) {
pxdFile.oss << "[";
for(size_t i = 0; i<templateArgs.size(); ++i) {
@ -759,7 +759,7 @@ void Class::emit_cython_pxd(FileWriter& pxdFile, const std::vector<Class>& allCl
size_t numMethods = constructor.nrOverloads() + static_methods.size() +
methods_.size() + templateMethods_.size();
if (numMethods == 0)
pxdFile.oss << "\t\tpass";
pxdFile.oss << " pass";
}
/* ************************************************************************* */
@ -795,7 +795,7 @@ void Class::pyxDynamicCast(FileWriter& pyxFile, const Class& curLevel,
parentCythonClass = curLevel.parentClass->pxd_class_in_pyx();
pyxFile.oss << "def dynamic_cast_" << me << "_" << parent << "(" << parent
<< " parent):\n";
pyxFile.oss << "\treturn " << me << ".cyCreateFromShared(<" << sharedMe
pyxFile.oss << " return " << me << ".cyCreateFromShared(<" << sharedMe
<< ">dynamic_pointer_cast[" << pxd_class_in_pyx() << ","
<< parentCythonClass << "](parent." << parentObj
<< "))\n";
@ -820,23 +820,23 @@ void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector<Class>& allCl
pyxFile.oss << ":\n";
// shared variable of the corresponding cython object
pyxFile.oss << "\tcdef " << shared_pxd_class_in_pyx() << " " << shared_pxd_obj_in_pyx() << "\n";
pyxFile.oss << " cdef " << shared_pxd_class_in_pyx() << " " << shared_pxd_obj_in_pyx() << "\n";
// __cinit___
pyxFile.oss << "\tdef __cinit__(self, *args, **kwargs):\n"
"\t\tself." << shared_pxd_obj_in_pyx() << " = "
pyxFile.oss << " def __cinit__(self, *args, **kwargs):\n"
" self." << shared_pxd_obj_in_pyx() << " = "
<< shared_pxd_class_in_pyx() << "()\n";
for (size_t i = 0; i<constructor.nrOverloads(); ++i) {
pyxFile.oss << "\t\t" << (i == 0 ? "if" : "elif") << " self."
pyxFile.oss << " " << (i == 0 ? "if" : "elif") << " self."
<< pyxClassName() << "_" << i
<< "(*args, **kwargs):\n\t\t\tpass\n";
<< "(*args, **kwargs):\n pass\n";
}
if (constructor.nrOverloads()>0)
pyxFile.oss << "\t\telse:\n\t\t\traise TypeError('" << pyxClassName()
pyxFile.oss << " else:\n raise TypeError('" << pyxClassName()
<< " construction failed!')\n";
pyxInitParentObj(pyxFile, "\t\tself", "self." + shared_pxd_obj_in_pyx(), allClasses);
pyxInitParentObj(pyxFile, " self", "self." + shared_pxd_obj_in_pyx(), allClasses);
pyxFile.oss << "\n";
// Constructors
@ -844,13 +844,13 @@ void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector<Class>& allCl
if (constructor.nrOverloads()>0) pyxFile.oss << "\n";
// cyCreateFromShared
pyxFile.oss << "\t@staticmethod\n";
pyxFile.oss << "\tcdef " << pyxClassName() << " cyCreateFromShared(const "
pyxFile.oss << " @staticmethod\n";
pyxFile.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const "
<< shared_pxd_class_in_pyx() << "& other):\n"
<< "\t\tcdef " << pyxClassName() << " ret = " << pyxClassName() << "()\n"
<< "\t\tret." << shared_pxd_obj_in_pyx() << " = other\n";
pyxInitParentObj(pyxFile, "\t\tret", "other", allClasses);
pyxFile.oss << "\t\treturn ret" << "\n";
<< " cdef " << pyxClassName() << " ret = " << pyxClassName() << "()\n"
<< " ret." << shared_pxd_obj_in_pyx() << " = other\n";
pyxInitParentObj(pyxFile, " ret", "other", allClasses);
pyxFile.oss << " return ret" << "\n";
for(const StaticMethod& m: static_methods | boost::adaptors::map_values)
m.emit_cython_pyx(pyxFile, *this);

View File

@ -134,7 +134,7 @@ void Constructor::emit_cython_pxd(FileWriter& pxdFile, Str className) const {
ArgumentList args = argumentList(i);
// generate the constructor
pxdFile.oss << "\t\t" << className << "(";
pxdFile.oss << " " << className << "(";
args.emit_cython_pxd(pxdFile, className);
pxdFile.oss << ") "
<< "except +\n";
@ -145,14 +145,14 @@ void Constructor::emit_cython_pxd(FileWriter& pxdFile, Str className) const {
void Constructor::emit_cython_pyx(FileWriter& pyxFile, const Class& cls) const {
for (size_t i = 0; i < nrOverloads(); i++) {
ArgumentList args = argumentList(i);
pyxFile.oss << "\tdef " + cls.pyxClassName() + "_" + to_string(i) +
pyxFile.oss << " def " + cls.pyxClassName() + "_" + to_string(i) +
"(self, *args, **kwargs):\n";
pyxFile.oss << pyx_resolveOverloadParams(args, true);
pyxFile.oss << "\t\tself." << 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()
<< "(" << args.pyx_asParams() << "))\n";
pyxFile.oss << "\t\treturn True\n\n";
pyxFile.oss << " return True\n\n";
}
}

View File

@ -138,7 +138,7 @@ void GlobalFunction::emit_cython_pxd(FileWriter& file) const {
<< overloads[0].qualifiedNamespaces("::")
<< "\":" << endl;
for (size_t i = 0; i < nrOverloads(); ++i) {
file.oss << "\t\t";
file.oss << " ";
returnVals_[i].emit_cython_pxd(file, "");
file.oss << pyRename(name_) + " \"" + overloads[0].qualifiedName("::") +
"\"(";
@ -165,11 +165,11 @@ void GlobalFunction::emit_cython_pyx_no_overload(FileWriter& file) const {
/// Call cython corresponding function and return
string ret = pyx_functionCall("pxd", funcName, 0);
if (!returnVals_[0].isVoid()) {
file.oss << "\tcdef " << returnVals_[0].pyx_returnType()
file.oss << " cdef " << returnVals_[0].pyx_returnType()
<< " ret = " << ret << "\n";
file.oss << "\treturn " << returnVals_[0].pyx_casting("ret") << "\n";
file.oss << " return " << returnVals_[0].pyx_casting("ret") << "\n";
} else {
file.oss << "\t" << ret << "\n";
file.oss << " " << ret << "\n";
}
}
@ -186,11 +186,11 @@ void GlobalFunction::emit_cython_pyx(FileWriter& file) const {
// Dealing with overloads..
file.oss << "def " << funcName << "(*args, **kwargs):\n";
for (size_t i = 0; i < N; ++i) {
file.oss << "\tsuccess, results = " << funcName << "_" << i
file.oss << " success, results = " << funcName << "_" << i
<< "(*args, **kwargs)\n";
file.oss << "\tif success:\n\t\t\treturn results\n";
file.oss << " if success:\n return results\n";
}
file.oss << "\traise TypeError('Could not find the correct overload')\n";
file.oss << " raise TypeError('Could not find the correct overload')\n";
for (size_t i = 0; i < N; ++i) {
ArgumentList args = argumentList(i);
@ -201,12 +201,12 @@ void GlobalFunction::emit_cython_pyx(FileWriter& file) const {
/// Call cython corresponding function
string ret = pyx_functionCall("pxd", funcName, i);
if (!returnVals_[i].isVoid()) {
file.oss << "\tcdef " << returnVals_[i].pyx_returnType()
file.oss << " cdef " << returnVals_[i].pyx_returnType()
<< " ret = " << ret << "\n";
file.oss << "\treturn True, " << returnVals_[i].pyx_casting("ret") << "\n";
file.oss << " return True, " << returnVals_[i].pyx_casting("ret") << "\n";
} else {
file.oss << "\t" << ret << "\n";
file.oss << "\treturn True, None\n";
file.oss << " " << ret << "\n";
file.oss << " return True, None\n";
}
}
}

View File

@ -83,7 +83,7 @@ string Method::wrapper_call(FileWriter& wrapperFile, Str cppClassName,
/* ************************************************************************* */
void Method::emit_cython_pxd(FileWriter& file, const Class& cls) const {
for (size_t i = 0; i < nrOverloads(); ++i) {
file.oss << "\t\t";
file.oss << " ";
returnVals_[i].emit_cython_pxd(file, cls.pxdClassName());
file.oss << pyRename(name_) + " \"" + name_ + "\""
<< "(";
@ -100,10 +100,10 @@ void Method::emit_cython_pyx_no_overload(FileWriter& file,
string funcName = pyRename(name_);
// leverage python's special treatment for print
if (funcName == "print_")
file.oss << "\tdef __str__(self):\n\t\tself.print_('')\n\t\treturn ''\n";
file.oss << " def __str__(self):\n self.print_('')\n return ''\n";
// Function definition
file.oss << "\tdef " << funcName;
file.oss << " def " << funcName;
// modify name of function instantiation as python doesn't allow overloads
// e.g. template<T={A,B,C}> funcName(...) --> funcNameA, funcNameB, funcNameC
if (templateArgValue_) file.oss << templateArgValue_->pyxClassName();
@ -117,11 +117,11 @@ void Method::emit_cython_pyx_no_overload(FileWriter& file,
string caller = "self." + cls.shared_pxd_obj_in_pyx() + ".get()";
string ret = pyx_functionCall(caller, funcName, 0);
if (!returnVals_[0].isVoid()) {
file.oss << "\t\tcdef " << returnVals_[0].pyx_returnType()
file.oss << " cdef " << returnVals_[0].pyx_returnType()
<< " ret = " << ret << "\n";
file.oss << "\t\treturn " << returnVals_[0].pyx_casting("ret") << "\n";
file.oss << " return " << returnVals_[0].pyx_casting("ret") << "\n";
} else {
file.oss << "\t\t" << ret << "\n";
file.oss << " " << ret << "\n";
}
}
@ -142,17 +142,17 @@ void Method::emit_cython_pyx(FileWriter& file, const Class& cls) const {
}
// Dealing with overloads..
file.oss << "\tdef " << instantiatedName << "(self, *args, **kwargs):\n";
file.oss << " def " << instantiatedName << "(self, *args, **kwargs):\n";
for (size_t i = 0; i < N; ++i) {
file.oss << "\t\tsuccess, results = self." << instantiatedName << "_" << i
file.oss << " success, results = self." << instantiatedName << "_" << i
<< "(*args, **kwargs)\n";
file.oss << "\t\tif success:\n\t\t\treturn results\n";
file.oss << " if success:\n return results\n";
}
file.oss << "\t\traise TypeError('Could not find the correct overload')\n";
file.oss << " raise TypeError('Could not find the correct overload')\n";
for (size_t i = 0; i < N; ++i) {
ArgumentList args = argumentList(i);
file.oss << "\tdef " + instantiatedName + "_" + to_string(i) +
file.oss << " def " + instantiatedName + "_" + to_string(i) +
"(self, *args, **kwargs):\n";
file.oss << pyx_resolveOverloadParams(args, false); // lazy: always return None even if it's a void function
@ -161,12 +161,12 @@ void Method::emit_cython_pyx(FileWriter& file, const Class& cls) const {
string ret = pyx_functionCall(caller, funcName, i);
if (!returnVals_[i].isVoid()) {
file.oss << "\t\tcdef " << returnVals_[i].pyx_returnType()
file.oss << " cdef " << returnVals_[i].pyx_returnType()
<< " ret = " << ret << "\n";
file.oss << "\t\treturn True, " << returnVals_[i].pyx_casting("ret") << "\n";
file.oss << " return True, " << returnVals_[i].pyx_casting("ret") << "\n";
} else {
file.oss << "\t\t" << ret << "\n";
file.oss << "\t\treturn True, None\n";
file.oss << " " << ret << "\n";
file.oss << " return True, None\n";
}
}
}

View File

@ -337,12 +337,12 @@ void Module::emit_cython_pxd(FileWriter& pxdFile) const {
// boost shared_ptr
pxdFile.oss << "cdef extern from \"boost/shared_ptr.hpp\" namespace \"boost\":\n"
"\tcppclass shared_ptr[T]:\n"
"\t\tshared_ptr()\n"
"\t\tshared_ptr(T*)\n"
"\t\tT* get()\n"
"\t\tT& operator*()\n\n"
"\tcdef shared_ptr[T] dynamic_pointer_cast[T,U](const shared_ptr[U]& r)\n";
" cppclass shared_ptr[T]:\n"
" shared_ptr()\n"
" shared_ptr(T*)\n"
" T* get()\n"
" T& operator*()\n\n"
" cdef shared_ptr[T] dynamic_pointer_cast[T,U](const shared_ptr[U]& r)\n";
for(const TypedefPair& types: typedefs)
types.emit_cython_pxd(pxdFile);

View File

@ -73,16 +73,16 @@ public:
std::string pyx_resolveOverloadParams(const ArgumentList& args, bool isVoid, size_t indentLevel = 2) const {
std::string indent;
for (size_t i = 0; i<indentLevel; ++i) indent += "\t";
for (size_t i = 0; i<indentLevel; ++i) indent += " ";
std::string s;
s += indent + "if len(args)+len(kwargs) !=" + std::to_string(args.size()) + ":\n";
s += indent + "\treturn False";
s += indent + " return False";
s += (!isVoid) ? ", None\n" : "\n";
if (args.size() > 0) {
s += indent + "__params = kwargs.copy()\n";
s += indent + "__names = [" + args.pyx_paramsList() + "]\n";
s += indent + "for i in range(len(args)):\n";
s += indent + "\t__params[__names[i]] = args[i]\n";
s += indent + " __params[__names[i]] = args[i]\n";
for (size_t i = 0; i<args.size(); ++i) {
if (args[i].type.isNonBasicType() || args[i].type.isEigen()) {
std::string param = "__params[__names[" + std::to_string(i) + "]]";
@ -92,13 +92,13 @@ public:
s += " or not " + param + ".ndim == " +
((args[i].type.pyxClassName() == "Vector") ? "1" : "2");
s += ":\n";
s += indent + "\treturn False" + ((isVoid) ? "" : ", None") + "\n";
s += indent + " return False" + ((isVoid) ? "" : ", None") + "\n";
}
}
s += indent + "try:\n";
s += args.pyx_castParamsToPythonType();
s += indent + "except:\n";
s += indent + "\treturn False";
s += indent + " return False";
s += (!isVoid) ? ", None\n" : "\n";
}
return s;

View File

@ -60,8 +60,8 @@ string StaticMethod::wrapper_call(FileWriter& wrapperFile, Str cppClassName,
void StaticMethod::emit_cython_pxd(FileWriter& file, const Class& cls) const {
// don't support overloads for static method :-(
for(size_t i = 0; i < nrOverloads(); ++i) {
file.oss << "\t\t@staticmethod\n";
file.oss << "\t\t";
file.oss << " @staticmethod\n";
file.oss << " ";
returnVals_[i].emit_cython_pxd(file, cls.pxdClassName());
file.oss << name_ + ((i>0)?"_" + to_string(i):"") << " \"" << name_ << "\"" << "(";
argumentList(i).emit_cython_pxd(file, cls.pxdClassName());
@ -73,14 +73,14 @@ void StaticMethod::emit_cython_pxd(FileWriter& file, const Class& cls) const {
void StaticMethod::emit_cython_pyx_no_overload(FileWriter& file,
const Class& cls) const {
assert(nrOverloads() == 1);
file.oss << "\t@staticmethod\n";
file.oss << "\tdef " << name_ << "(";
file.oss << " @staticmethod\n";
file.oss << " def " << name_ << "(";
argumentList(0).emit_cython_pyx(file);
file.oss << "):\n";
/// Call cython corresponding function and return
string ret = pyx_functionCall(cls.pxd_class_in_pyx(), name_, 0);
file.oss << "\t\t";
file.oss << " ";
if (!returnVals_[0].isVoid()) {
file.oss << "return " << returnVals_[0].pyx_casting(ret) << "\n";
} else
@ -97,35 +97,35 @@ void StaticMethod::emit_cython_pyx(FileWriter& file, const Class& cls) const {
}
// Dealing with overloads..
file.oss << "\t@staticmethod\n";
file.oss << "\tdef " << name_ << "(*args, **kwargs):\n";
file.oss << " @staticmethod\n";
file.oss << " def " << name_ << "(*args, **kwargs):\n";
for (size_t i = 0; i < N; ++i) {
string funcName = name_ + "_" + to_string(i);
file.oss << "\t\tsuccess, results = " << cls.pyxClassName() << "."
file.oss << " success, results = " << cls.pyxClassName() << "."
<< funcName << "(*args, **kwargs)\n";
file.oss << "\t\tif success:\n\t\t\treturn results\n";
file.oss << " if success:\n return results\n";
}
file.oss << "\t\traise TypeError('Could not find the correct overload')\n";
file.oss << " raise TypeError('Could not find the correct overload')\n";
for(size_t i = 0; i < N; ++i) {
file.oss << "\t@staticmethod\n";
file.oss << " @staticmethod\n";
string funcName = name_ + "_" + to_string(i);
string pxdFuncName = name_ + ((i>0)?"_" + to_string(i):"");
ArgumentList args = argumentList(i);
file.oss << "\tdef " + funcName + "(*args, **kwargs):\n";
file.oss << " def " + funcName + "(*args, **kwargs):\n";
file.oss << pyx_resolveOverloadParams(args, false); // lazy: always return None even if it's a void function
/// Call cython corresponding function and return
string ret = pyx_functionCall(cls.pxd_class_in_pyx(), pxdFuncName, i);
if (!returnVals_[i].isVoid()) {
file.oss << "\t\tcdef " << returnVals_[i].pyx_returnType()
file.oss << " cdef " << returnVals_[i].pyx_returnType()
<< " ret = " << ret << "\n";
file.oss << "\t\treturn True, " << returnVals_[i].pyx_casting("ret") << "\n";
file.oss << " return True, " << returnVals_[i].pyx_casting("ret") << "\n";
}
else {
file.oss << "\t\t" << ret << "\n";
file.oss << "\t\treturn True, None\n";
file.oss << " " << ret << "\n";
file.oss << " return True, None\n";
}
file.oss << "\n";
}

View File

@ -23,7 +23,7 @@ using namespace wrap;
/* ************************************************************************* */
void TemplateMethod::emit_cython_pxd(FileWriter& file, const Class& cls) const {
for(size_t i = 0; i < nrOverloads(); ++i) {
file.oss << "\t\t";
file.oss << " ";
returnVals_[i].emit_cython_pxd(file, cls.pxdClassName());
file.oss << name_ << "[" << argName << "]" << "(";
argumentList(i).emit_cython_pxd(file, cls.pxdClassName());

View File

@ -21,7 +21,7 @@ struct TypedefPair {
void emit_cython_pxd(FileWriter& file) const {
file.oss << "cdef extern from \"" << includeFile << "\" namespace \""
<< oldType.qualifiedNamespaces("::") << "\":\n";
file.oss << "\tctypedef " << oldType.pxdClassName() << " "
file.oss << " ctypedef " << oldType.pxdClassName() << " "
<< newType.pxdClassName() << "\n";
}
};