check if default constructor exists. Autogenerate copy constructor by default

release/4.3a0
Duy-Nguyen Ta 2016-09-10 19:44:53 -04:00
parent 8944f02401
commit 2496de85a9
2 changed files with 22 additions and 0 deletions

View File

@ -121,10 +121,29 @@ void Constructor::python_wrapper(FileWriter& wrapperFile, Str className) const {
<< ");\n";
}
/* ************************************************************************* */
bool Constructor::hasDefaultConstructor() const {
for (size_t i = 0; i < nrOverloads(); i++) {
if (argumentList(i).size() == 0) return true;
}
return false;
}
/* ************************************************************************* */
void Constructor::emit_cython_pxd(FileWriter& pxdFile, Str className) const {
// if it can ever be constructed, add the default copy constructor by default
if (nrOverloads() > 0) {
pxdFile.oss << "\t\t" << className << "(const " << className
<< "&) except +\n";
}
for (size_t i = 0; i < nrOverloads(); i++) {
ArgumentList args = argumentList(i);
// ignore copy constructor, it's generated by default above
if (args.size() == 1 && args[0].is_const && args[0].is_ref &&
!args[0].is_ptr && args[0].type.cythonClassName() == className)
continue;
// generate the constructor
pxdFile.oss << "\t\t" << className << "(";
args.emit_cython_pxd(pxdFile);
pxdFile.oss << ") " << "except +\n";

View File

@ -45,6 +45,9 @@ struct Constructor: public OverloadedFunction {
return inst;
}
/// return true if the default constructor exists
bool hasDefaultConstructor() const;
// MATLAB code generation
// toolboxPath is main toolbox directory, e.g., ../matlab
// classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m