diff --git a/wrap/Argument.cpp b/wrap/Argument.cpp index cc235207a..dbf1e93f9 100644 --- a/wrap/Argument.cpp +++ b/wrap/Argument.cpp @@ -28,12 +28,37 @@ using namespace std; using namespace wrap; +/* ************************************************************************* */ +Argument Argument::expandTemplate(const string& templateArg, + const Qualified& qualifiedType, const Qualified& expandedClass) const { + Argument instArg = *this; + if (type.name == templateArg) { + instArg.type = qualifiedType; + } else if (type.name == "This") { + instArg.type = expandedClass; + } + return instArg; +} + +/* ************************************************************************* */ +ArgumentList ArgumentList::expandTemplate(const string& templateArg, + const Qualified& qualifiedType, const Qualified& expandedClass) const { + ArgumentList instArgList; + BOOST_FOREACH(const Argument& arg, *this) { + Argument instArg = arg.expandTemplate(templateArg, qualifiedType, + expandedClass); + instArgList.push_back(instArg); + } + return instArgList; +} + /* ************************************************************************* */ string Argument::matlabClass(const string& delim) const { string result; BOOST_FOREACH(const string& ns, type.namespaces) result += ns + delim; - if (type.name == "string" || type.name == "unsigned char" || type.name == "char") + if (type.name == "string" || type.name == "unsigned char" + || type.name == "char") return result + "char"; if (type.name == "Vector" || type.name == "Matrix") return result + "double"; @@ -46,8 +71,9 @@ string Argument::matlabClass(const string& delim) const { /* ************************************************************************* */ bool Argument::isScalar() const { - return (type.name == "bool" || type.name == "char" || type.name == "unsigned char" - || type.name == "int" || type.name == "size_t" || type.name == "double"); + return (type.name == "bool" || type.name == "char" + || type.name == "unsigned char" || type.name == "int" + || type.name == "size_t" || type.name == "double"); } /* ************************************************************************* */ @@ -128,7 +154,8 @@ string ArgumentList::names() const { /* ************************************************************************* */ bool ArgumentList::allScalar() const { BOOST_FOREACH(Argument arg, *this) - if (!arg.isScalar()) return false; + if (!arg.isScalar()) + return false; return true; } diff --git a/wrap/Argument.h b/wrap/Argument.h index 5a14d1295..5fba1daef 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -35,6 +35,9 @@ struct Argument { is_const(false), is_ref(false), is_ptr(false) { } + Argument expandTemplate(const std::string& templateArg, + const Qualified& qualifiedType, const Qualified& expandedClass) const; + /// return MATLAB class for use in isa(x,class) std::string matlabClass(const std::string& delim = "") const; @@ -60,6 +63,9 @@ struct ArgumentList: public std::vector { /// Check if all arguments scalar bool allScalar() const; + ArgumentList expandTemplate(const std::string& templateArg, + const Qualified& qualifiedType, const Qualified& expandedClass) const; + // MATLAB code generation: /** @@ -93,8 +99,9 @@ struct ArgumentList: public std::vector { * @param wrapperName of method or function * @param staticMethod flag to emit "this" in call */ - void emit_conditional_call(FileWriter& proxyFile, const ReturnValue& returnVal, - const std::string& wrapperName, int id, bool staticMethod = false) const; + void emit_conditional_call(FileWriter& proxyFile, + const ReturnValue& returnVal, const std::string& wrapperName, int id, + bool staticMethod = false) const; }; template @@ -108,7 +115,7 @@ inline void verifyArguments(const std::vector& validArgs, std::string fullType = arg.type.qualifiedName("::"); if (find(validArgs.begin(), validArgs.end(), fullType) == validArgs.end()) - throw DependencyMissing(fullType, t.name); + throw DependencyMissing(fullType, t.name_); } } } diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 8533fe6f7..e7dca4ace 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -239,63 +239,6 @@ void Class::pointer_constructor_fragments(FileWriter& proxyFile, "}\n"; } -/* ************************************************************************* */ -static vector expandArgumentListsTemplate( - const vector& argLists, const string& templateArg, - const Qualified& qualifiedType, const Qualified& expandedClass) { - vector result; - BOOST_FOREACH(const ArgumentList& argList, argLists) { - ArgumentList instArgList; - BOOST_FOREACH(const Argument& arg, argList) { - Argument instArg = arg; - if (arg.type.name == templateArg) { - instArg.type = qualifiedType; - } else if (arg.type.name == "This") { - instArg.type = expandedClass; - } - instArgList.push_back(instArg); - } - result.push_back(instArgList); - } - return result; -} - -/* ************************************************************************* */ -// TODO, Method, StaticMethod, and GlobalFunction should have common base ? -template -METHOD expandMethodTemplate(const METHOD& method, const string& templateArg, - const Qualified& qualifiedType, const Qualified& expandedClass) { - // Create new instance - METHOD instMethod = method; - // substitute template in arguments - instMethod.argLists = expandArgumentListsTemplate(method.argLists, - templateArg, qualifiedType, expandedClass); - // do the same for return types - instMethod.returnVals.clear(); - BOOST_FOREACH(const ReturnValue& retVal, method.returnVals) { - ReturnValue instRetVal = retVal.substituteTemplate(templateArg, - qualifiedType, expandedClass); - instMethod.returnVals.push_back(instRetVal); - } - // return new method - return instMethod; -} - -/* ************************************************************************* */ -template -static map expandMethodTemplate( - const map& methods, const string& templateArg, - const Qualified& qualifiedType, const Qualified& expandedClass) { - map result; - typedef pair NamedMethod; - BOOST_FOREACH(NamedMethod namedMethod, methods) { - namedMethod.second = expandMethodTemplate(namedMethod.second, templateArg, - qualifiedType, expandedClass); - result.insert(namedMethod); - } - return result; -} - /* ************************************************************************* */ Class Class::expandTemplate(const string& templateArg, const Qualified& instName, const Qualified& expandedClass) const { @@ -304,8 +247,8 @@ Class Class::expandTemplate(const string& templateArg, expandedClass); inst.static_methods = expandMethodTemplate(static_methods, templateArg, instName, expandedClass); - inst.constructor.args_list = expandArgumentListsTemplate( - constructor.args_list, templateArg, instName, expandedClass); + inst.constructor.args_list = inst.constructor.expandArgumentListsTemplate( + templateArg, instName, expandedClass); inst.constructor.name = inst.name; inst.deconstructor.name = inst.name; return inst; @@ -335,14 +278,17 @@ void Class::addMethod(bool verbose, bool is_const, const string& name, // Check if templated if (!templateArgName.empty() && templateArgValues.size() > 0) { // Create method to expand - Method method; - method.addOverload(verbose, is_const, name, args, retVal); // For all values of the template argument, create a new method BOOST_FOREACH(const Qualified& instName, templateArgValues) { - Method expanded = // - expandMethodTemplate(method, templateArgName, instName, *this); - methods[name].addOverload(verbose, is_const, name, expanded.argLists[0], - expanded.returnVals[0], instName); + string expandedName = name + instName.name; + // substitute template in arguments + ArgumentList expandedArgs = args.expandTemplate(templateArgName, instName, + name); + // do the same for return types + ReturnValue expandedRetVal = retVal.expandTemplate(templateArgName, + instName, name); + methods[expandedName].addOverload(verbose, is_const, expandedName, + expandedArgs, expandedRetVal, instName); } } else // just add overload @@ -446,7 +392,7 @@ void Class::comment_fragment(FileWriter& proxyFile) const { const Method& m = name_m.second; BOOST_FOREACH(ArgumentList argList, m.argLists) { proxyFile.oss << "%"; - argList.emit_prototype(proxyFile, m.name); + argList.emit_prototype(proxyFile, m.name_); proxyFile.oss << " : returns " << m.returnVals[0].return_type(false) << endl; } @@ -458,7 +404,7 @@ void Class::comment_fragment(FileWriter& proxyFile) const { const StaticMethod& m = name_m.second; BOOST_FOREACH(ArgumentList argList, m.argLists) { proxyFile.oss << "%"; - argList.emit_prototype(proxyFile, m.name); + argList.emit_prototype(proxyFile, m.name_); proxyFile.oss << " : returns " << m.returnVals[0].return_type(false) << endl; } diff --git a/wrap/Constructor.cpp b/wrap/Constructor.cpp index fdbbf0e42..a44f0893d 100644 --- a/wrap/Constructor.cpp +++ b/wrap/Constructor.cpp @@ -36,6 +36,19 @@ string Constructor::matlab_wrapper_name(const string& className) const { return str; } +/* ************************************************************************* */ +vector Constructor::expandArgumentListsTemplate( + const string& templateArg, const Qualified& qualifiedType, + const Qualified& expandedClass) const { + vector result; + BOOST_FOREACH(const ArgumentList& argList, args_list) { + ArgumentList instArgList = argList.expandTemplate(templateArg, + qualifiedType, expandedClass); + result.push_back(instArgList); + } + return result; +} + /* ************************************************************************* */ void Constructor::proxy_fragment(FileWriter& file, const std::string& wrapperName, bool hasParent, const int id, const ArgumentList args) const { diff --git a/wrap/Constructor.h b/wrap/Constructor.h index 5438c515c..49a731a7d 100644 --- a/wrap/Constructor.h +++ b/wrap/Constructor.h @@ -38,6 +38,11 @@ struct Constructor { std::string name; bool verbose_; + // TODO eliminate copy/paste with function + std::vector expandArgumentListsTemplate( + const std::string& templateArg, const Qualified& qualifiedType, + const Qualified& expandedClass) const; + // MATLAB code generation // toolboxPath is main toolbox directory, e.g., ../matlab // classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m diff --git a/wrap/GlobalFunction.cpp b/wrap/GlobalFunction.cpp index afc099070..05b954652 100644 --- a/wrap/GlobalFunction.cpp +++ b/wrap/GlobalFunction.cpp @@ -17,16 +17,9 @@ using namespace std; /* ************************************************************************* */ void GlobalFunction::addOverload(bool verbose, const Qualified& overload, - const ArgumentList& args, const ReturnValue& retVal) { - if (name.empty()) - name = overload.name; - else if (overload.name != name) - throw std::runtime_error( - "GlobalFunction::addOverload: tried to add overload with name " - + overload.name + " instead of expected " + name); - verbose_ = verbose; - argLists.push_back(args); - returnVals.push_back(retVal); + const ArgumentList& args, const ReturnValue& retVal, + const Qualified& instName) { + Function::addOverload(verbose, overload.name, args, retVal, instName); overloads.push_back(overload); } @@ -48,7 +41,7 @@ void GlobalFunction::matlab_proxy(const std::string& toolboxPath, ArgumentList args = argLists.at(i); if (!grouped_functions.count(str_ns)) - grouped_functions[str_ns] = GlobalFunction(name, verbose_); + grouped_functions[str_ns] = GlobalFunction(name_, verbose_); grouped_functions[str_ns].argLists.push_back(args); grouped_functions[str_ns].returnVals.push_back(ret); @@ -82,7 +75,7 @@ void GlobalFunction::generateSingleFunction(const std::string& toolboxPath, const string matlabUniqueName = overload1.qualifiedName(""); const string cppName = overload1.qualifiedName("::"); - mfunctionFile.oss << "function varargout = " << name << "(varargin)\n"; + mfunctionFile.oss << "function varargout = " << name_ << "(varargin)\n"; for (size_t overload = 0; overload < argLists.size(); ++overload) { const ArgumentList& args = argLists[overload]; diff --git a/wrap/GlobalFunction.h b/wrap/GlobalFunction.h index b31bd313d..17d89d6f5 100644 --- a/wrap/GlobalFunction.h +++ b/wrap/GlobalFunction.h @@ -9,34 +9,28 @@ #pragma once -#include "Argument.h" -#include "ReturnValue.h" +#include "Function.h" namespace wrap { -struct GlobalFunction { +struct GlobalFunction: public Function { - bool verbose_; - std::string name; - - // each overload, regardless of namespace - std::vector argLists; ///< arugments for each overload - std::vector returnVals; ///< returnVals for each overload - std::vector overloads; ///< Stack of qualified names + std::vector overloads; ///< Stack of qualified names // Constructor only used in Module GlobalFunction(bool verbose = true) : - verbose_(verbose) { + Function(verbose) { } // Used to reconstruct - GlobalFunction(const std::string& name_, bool verbose = true) : - verbose_(verbose), name(name_) { + GlobalFunction(const std::string& name, bool verbose = true) : + Function(name,verbose) { } - // adds an overloaded version of this function + // adds an overloaded version of this function, void addOverload(bool verbose, const Qualified& overload, - const ArgumentList& args, const ReturnValue& retVal); + const ArgumentList& args, const ReturnValue& retVal, + const Qualified& instName = Qualified()); // codegen function called from Module to build the cpp and matlab versions of the function void matlab_proxy(const std::string& toolboxPath, diff --git a/wrap/Method.cpp b/wrap/Method.cpp index c003b5885..e218b45ec 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -29,20 +29,12 @@ using namespace std; using namespace wrap; /* ************************************************************************* */ -void Method::addOverload(bool verbose, bool is_const, const std::string& name, +void Method::addOverload(bool verbose, bool is_const, const std::string& name_, const ArgumentList& args, const ReturnValue& retVal, const Qualified& instName) { - if (!this->name.empty() && this->name != name) - throw std::runtime_error( - "Method::addOverload: tried to add overload with name " + name - + " instead of expected " + this->name); - else - this->name = name; - verbose_ = verbose; + + Function::addOverload(verbose, name_, args, retVal); is_const_ = is_const; - argLists.push_back(args); - returnVals.push_back(retVal); - templateArgValues.push_back(instName); } /* ************************************************************************* */ @@ -53,14 +45,14 @@ void Method::proxy_wrapper_fragments(FileWriter& proxyFile, vector& functionNames) const { // Create function header - proxyFile.oss << " function varargout = " << name << "(this, varargin)\n"; + proxyFile.oss << " function varargout = " << name_ << "(this, varargin)\n"; // Emit comments for documentation - string up_name = boost::to_upper_copy(name); + string up_name = boost::to_upper_copy(name_); proxyFile.oss << " % " << up_name << " usage: "; unsigned int argLCount = 0; BOOST_FOREACH(ArgumentList argList, argLists) { - argList.emit_prototype(proxyFile, name); + argList.emit_prototype(proxyFile, name_); if (argLCount != argLists.size() - 1) proxyFile.oss << ", "; else @@ -80,7 +72,7 @@ void Method::proxy_wrapper_fragments(FileWriter& proxyFile, proxyFile.oss << " % " << "Method Overloads" << endl; BOOST_FOREACH(ArgumentList argList, argLists) { proxyFile.oss << " % "; - argList.emit_prototype(proxyFile, name); + argList.emit_prototype(proxyFile, name_); proxyFile.oss << endl; } } @@ -94,7 +86,7 @@ void Method::proxy_wrapper_fragments(FileWriter& proxyFile, // Output C++ wrapper code const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName, - matlabUniqueName, 0, id, typeAttributes, templateArgValues[0]); + matlabUniqueName, 0, id, typeAttributes, templateArgValue_); // Add to function list functionNames.push_back(wrapFunctionName); @@ -105,13 +97,16 @@ void Method::proxy_wrapper_fragments(FileWriter& proxyFile, // Output proxy matlab code proxyFile.oss << " " << (overload == 0 ? "" : "else"); const int id = (int) functionNames.size(); + string expanded = wrapperName; + if (!templateArgValue_.empty()) + expanded += templateArgValue_.name; argLists[overload].emit_conditional_call(proxyFile, returnVals[overload], - wrapperName, id); + expanded, id); // Output C++ wrapper code const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName, matlabUniqueName, overload, id, typeAttributes, - templateArgValues[overload]); + templateArgValue_); // Add to function list functionNames.push_back(wrapFunctionName); @@ -119,7 +114,7 @@ void Method::proxy_wrapper_fragments(FileWriter& proxyFile, proxyFile.oss << " else\n"; proxyFile.oss << " error('Arguments do not match any overload of function " - << matlabQualName << "." << name << "');" << endl; + << matlabQualName << "." << name_ << "');" << endl; proxyFile.oss << " end\n"; } @@ -134,7 +129,7 @@ string Method::wrapper_fragment(FileWriter& wrapperFile, // generate code - const string wrapFunctionName = matlabUniqueName + "_" + name + "_" + const string wrapFunctionName = matlabUniqueName + "_" + name_ + "_" + boost::lexical_cast(id); const ArgumentList& args = argLists[overload]; @@ -154,7 +149,7 @@ string Method::wrapper_fragment(FileWriter& wrapperFile, // check arguments // extra argument obj -> nargin-1 is passed ! // example: checkArguments("equals",nargout,nargin-1,2); - wrapperFile.oss << " checkArguments(\"" << name << "\",nargout,nargin-1," + wrapperFile.oss << " checkArguments(\"" << name_ << "\",nargout,nargin-1," << args.size() << ");\n"; // get class pointer @@ -166,7 +161,7 @@ string Method::wrapper_fragment(FileWriter& wrapperFile, // call method and wrap result // example: out[0]=wrap(self->return_field(t)); - string expanded = "obj->" + name; + string expanded = "obj->" + name_; if (!instName.empty()) expanded += ("<" + instName.qualifiedName("::") + ">"); expanded += ("(" + args.names() + ")"); diff --git a/wrap/Method.h b/wrap/Method.h index 3f7973db6..36a53b3d7 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -18,30 +18,19 @@ #pragma once -#include "Argument.h" -#include "ReturnValue.h" -#include "TypeAttributesTable.h" - -#include -#include +#include "Function.h" namespace wrap { /// Method class -struct Method { +struct Method : public Function { /// Constructor creates empty object Method(bool verbose = true) : - verbose_(verbose), is_const_(false) { + Function(verbose), is_const_(false) { } - // Then the instance variables are set directly by the Module constructor - bool verbose_; bool is_const_; - std::string name; - std::vector argLists; - std::vector returnVals; - std::vector templateArgValues; ///< value of template argument if applicable // The first time this function is called, it initializes the class members // with those in rhs, but in subsequent calls it adds additional argument diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 498048ee7..f75e1d683 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -274,7 +274,7 @@ void Module::parseMarkup(const std::string& data) { '(' >> argumentList_p >> ')' >> ';' >> *comments_p) [bl::bind(&StaticMethod::addOverload, bl::var(cls.static_methods)[bl::var(methodName)], - verbose, bl::var(methodName), bl::var(args), bl::var(retVal))] + verbose, bl::var(methodName), bl::var(args), bl::var(retVal), Qualified())] [assign_a(retVal,retVal0)] [clear_a(args)]; @@ -313,7 +313,7 @@ void Module::parseMarkup(const std::string& data) { [assign_a(globalFunction.namespaces,namespaces)] [bl::bind(&GlobalFunction::addOverload, bl::var(global_functions)[bl::var(globalFunction.name)], - verbose, bl::var(globalFunction), bl::var(args), bl::var(retVal))] + verbose, bl::var(globalFunction), bl::var(args), bl::var(retVal), Qualified())] [assign_a(retVal,retVal0)] [clear_a(globalFunction)] [clear_a(args)]; diff --git a/wrap/Qualified.h b/wrap/Qualified.h index f38587fbb..def2343cd 100644 --- a/wrap/Qualified.h +++ b/wrap/Qualified.h @@ -44,6 +44,10 @@ struct Qualified { name.clear(); } + bool operator!=(const Qualified& other) const { + return other.name!=name || other.namespaces != namespaces; + } + /// Return a qualified string using given delimiter std::string qualifiedName(const std::string& delimiter = "") const { std::string result; diff --git a/wrap/ReturnValue.cpp b/wrap/ReturnValue.cpp index ea2cb1489..84d662e81 100644 --- a/wrap/ReturnValue.cpp +++ b/wrap/ReturnValue.cpp @@ -59,7 +59,7 @@ void ReturnType::wrapTypeUnwrap(FileWriter& wrapperFile) const { } /* ************************************************************************* */ -ReturnValue ReturnValue::substituteTemplate(const string& templateArg, +ReturnValue ReturnValue::expandTemplate(const string& templateArg, const Qualified& qualifiedType, const Qualified& expandedClass) const { ReturnValue instRetVal = *this; if (type1.name == templateArg) { diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h index 6e6e149de..1caaeae22 100644 --- a/wrap/ReturnValue.h +++ b/wrap/ReturnValue.h @@ -86,9 +86,22 @@ struct ReturnValue { } /// Substitute template argument - ReturnValue substituteTemplate(const std::string& templateArg, + ReturnValue expandTemplate(const std::string& templateArg, const Qualified& qualifiedType, const Qualified& expandedClass) const; + // TODO use transform ? + static std::vector ExpandTemplate( + std::vector returnVals, const std::string& templateArg, + const Qualified& qualifiedType, const Qualified& expandedClass) { + std::vector result; + BOOST_FOREACH(const ReturnValue& retVal, returnVals) { + ReturnValue instRetVal = retVal.expandTemplate(templateArg, + qualifiedType, expandedClass); + result.push_back(instRetVal); + } + return result; + } + std::string return_type(bool add_ptr) const; std::string matlab_returnType() const; @@ -102,18 +115,4 @@ struct ReturnValue { }; -template -inline void verifyReturnTypes(const std::vector& validtypes, - const std::map& vt) { - typedef typename std::map::value_type NamedMethod; - BOOST_FOREACH(const NamedMethod& namedMethod, vt) { - const T& t = namedMethod.second; - BOOST_FOREACH(const ReturnValue& retval, t.returnVals) { - retval.type1.verify(validtypes, t.name); - if (retval.isPair) - retval.type2.verify(validtypes, t.name); - } - } -} - } // \namespace wrap diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index 870773973..f8eba744f 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -29,15 +29,6 @@ using namespace std; using namespace wrap; -/* ************************************************************************* */ -void StaticMethod::addOverload(bool verbose, const std::string& name, - const ArgumentList& args, const ReturnValue& retVal) { - this->verbose = verbose; - this->name = name; - this->argLists.push_back(args); - this->returnVals.push_back(retVal); -} - /* ************************************************************************* */ void StaticMethod::proxy_wrapper_fragments(FileWriter& file, FileWriter& wrapperFile, const string& cppClassName, @@ -45,16 +36,16 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& file, const string& wrapperName, const TypeAttributesTable& typeAttributes, vector& functionNames) const { - string upperName = name; + string upperName = name_; upperName[0] = std::toupper(upperName[0], std::locale()); file.oss << " function varargout = " << upperName << "(varargin)\n"; //Comments for documentation - string up_name = boost::to_upper_copy(name); + string up_name = boost::to_upper_copy(name_); file.oss << " % " << up_name << " usage: "; unsigned int argLCount = 0; BOOST_FOREACH(ArgumentList argList, argLists) { - argList.emit_prototype(file, name); + argList.emit_prototype(file, name_); if (argLCount != argLists.size() - 1) file.oss << ", "; else @@ -105,7 +96,7 @@ string StaticMethod::wrapper_fragment(FileWriter& file, // generate code - const string wrapFunctionName = matlabUniqueName + "_" + name + "_" + const string wrapFunctionName = matlabUniqueName + "_" + name_ + "_" + boost::lexical_cast(id); const ArgumentList& args = argLists[overload]; @@ -124,7 +115,7 @@ string StaticMethod::wrapper_fragment(FileWriter& file, // check arguments // NOTE: for static functions, there is no object passed - file.oss << " checkArguments(\"" << matlabUniqueName << "." << name + file.oss << " checkArguments(\"" << matlabUniqueName << "." << name_ << "\",nargout,nargin," << args.size() << ");\n"; // unwrap arguments, see Argument.cpp @@ -132,10 +123,10 @@ string StaticMethod::wrapper_fragment(FileWriter& file, // call method with default type and wrap result if (returnVal.type1.name != "void") - returnVal.wrap_result(cppClassName + "::" + name + "(" + args.names() + ")", + returnVal.wrap_result(cppClassName + "::" + name_ + "(" + args.names() + ")", file, typeAttributes); else - file.oss << cppClassName + "::" + name + "(" + args.names() + ");\n"; + file.oss << cppClassName + "::" + name_ + "(" + args.names() + ");\n"; // finish file.oss << "}\n"; diff --git a/wrap/StaticMethod.h b/wrap/StaticMethod.h index e1855f4c2..14162b3c8 100644 --- a/wrap/StaticMethod.h +++ b/wrap/StaticMethod.h @@ -19,32 +19,18 @@ #pragma once -#include "Argument.h" -#include "ReturnValue.h" -#include "TypeAttributesTable.h" +#include "Function.h" namespace wrap { /// StaticMethod class -struct StaticMethod { +struct StaticMethod: public Function { /// Constructor creates empty object StaticMethod(bool verbosity = true) : - verbose(verbosity) { + Function(verbosity) { } - // Then the instance variables are set directly by the Module constructor - bool verbose; - std::string name; - std::vector argLists; - std::vector returnVals; - - // The first time this function is called, it initializes the class members - // with those in rhs, but in subsequent calls it adds additional argument - // lists as function overloads. - void addOverload(bool verbose, const std::string& name, - const ArgumentList& args, const ReturnValue& retVal); - // MATLAB code generation // classPath is class directory, e.g., ../matlab/@Point2 void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index 4365b085a..743370c6d 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -97,7 +97,7 @@ TEST( wrap, Small ) { // Method 1 Method m1 = cls.method("x"); - EXPECT(assert_equal("x", m1.name)); + EXPECT(assert_equal("x", m1.name_)); EXPECT(m1.is_const_); LONGS_EQUAL(1, m1.argLists.size()); LONGS_EQUAL(1, m1.returnVals.size()); @@ -110,7 +110,7 @@ TEST( wrap, Small ) { // Method 2 Method m2 = cls.method("returnMatrix"); - EXPECT(assert_equal("returnMatrix", m2.name)); + EXPECT(assert_equal("returnMatrix", m2.name_)); EXPECT(m2.is_const_); LONGS_EQUAL(1, m2.argLists.size()); LONGS_EQUAL(1, m2.returnVals.size()); @@ -123,7 +123,7 @@ TEST( wrap, Small ) { // Method 3 Method m3 = cls.method("returnPoint2"); - EXPECT(assert_equal("returnPoint2", m3.name)); + EXPECT(assert_equal("returnPoint2", m3.name_)); EXPECT(m3.is_const_); LONGS_EQUAL(1, m3.argLists.size()); LONGS_EQUAL(1, m3.returnVals.size()); @@ -137,7 +137,7 @@ TEST( wrap, Small ) { // Static Method 1 // static Vector returnVector(); StaticMethod sm1 = cls.static_methods.at("returnVector"); - EXPECT(assert_equal("returnVector", sm1.name)); + EXPECT(assert_equal("returnVector", sm1.name_)); LONGS_EQUAL(1, sm1.argLists.size()); LONGS_EQUAL(1, sm1.returnVals.size()); @@ -199,7 +199,7 @@ TEST( wrap, Geometry ) { EXPECT(assert_equal("char", m1.returnVals.front().type1.name)); EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnVals.front().type1.category); EXPECT(!m1.returnVals.front().isPair); - EXPECT(assert_equal("returnChar", m1.name)); + EXPECT(assert_equal("returnChar", m1.name_)); LONGS_EQUAL(1, m1.argLists.size()); EXPECT_LONGS_EQUAL(0, m1.argLists.front().size()); EXPECT(m1.is_const_); @@ -213,7 +213,7 @@ TEST( wrap, Geometry ) { EXPECT(assert_equal("VectorNotEigen", m1.returnVals.front().type1.name)); EXPECT_LONGS_EQUAL(ReturnType::CLASS, m1.returnVals.front().type1.category); EXPECT(!m1.returnVals.front().isPair); - EXPECT(assert_equal("vectorConfusion", m1.name)); + EXPECT(assert_equal("vectorConfusion", m1.name_)); LONGS_EQUAL(1, m1.argLists.size()); EXPECT_LONGS_EQUAL(0, m1.argLists.front().size()); EXPECT(!m1.is_const_); @@ -255,7 +255,7 @@ TEST( wrap, Geometry ) { LONGS_EQUAL(1, m1.returnVals.size()); EXPECT(assert_equal("double", m1.returnVals.front().type1.name)); EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnVals.front().type1.category); - EXPECT(assert_equal("norm", m1.name)); + EXPECT(assert_equal("norm", m1.name_)); LONGS_EQUAL(1, m1.argLists.size()); EXPECT_LONGS_EQUAL(0, m1.argLists.front().size()); EXPECT(m1.is_const_); @@ -316,7 +316,7 @@ TEST( wrap, Geometry ) { CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end()); { GlobalFunction gfunc = module.global_functions.at("aGlobalFunction"); - EXPECT(assert_equal("aGlobalFunction", gfunc.name)); + EXPECT(assert_equal("aGlobalFunction", gfunc.name_)); LONGS_EQUAL(1, gfunc.returnVals.size()); EXPECT(assert_equal("Vector", gfunc.returnVals.front().type1.name)); EXPECT_LONGS_EQUAL(1, gfunc.argLists.size()); @@ -390,7 +390,7 @@ TEST( wrap, parse_namespaces ) { CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end()); { GlobalFunction gfunc = module.global_functions.at("aGlobalFunction"); - EXPECT(assert_equal("aGlobalFunction", gfunc.name)); + EXPECT(assert_equal("aGlobalFunction", gfunc.name_)); LONGS_EQUAL(2, gfunc.returnVals.size()); EXPECT(assert_equal("Vector", gfunc.returnVals.front().type1.name)); EXPECT_LONGS_EQUAL(2, gfunc.argLists.size());