Refactored emit call
parent
e2ab47b610
commit
0eaabd700b
|
@ -175,20 +175,9 @@ void ArgumentList::emit_prototype(FileWriter& file, const string& name) const {
|
||||||
}
|
}
|
||||||
file.oss << ")";
|
file.oss << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void ArgumentList::emit_call(FileWriter& proxyFile,
|
void ArgumentList::proxy_check_arguments(FileWriter& proxyFile) const {
|
||||||
const ReturnValue& returnVal, const string& wrapperName, int id,
|
|
||||||
bool staticMethod) const {
|
|
||||||
returnVal.emit_matlab(proxyFile);
|
|
||||||
proxyFile.oss << wrapperName << "(" << id;
|
|
||||||
if (!staticMethod)
|
|
||||||
proxyFile.oss << ", this";
|
|
||||||
proxyFile.oss << ", varargin{:});\n";
|
|
||||||
}
|
|
||||||
/* ************************************************************************* */
|
|
||||||
void ArgumentList::emit_conditional_call(FileWriter& proxyFile,
|
|
||||||
const ReturnValue& returnVal, const string& wrapperName, int id,
|
|
||||||
bool staticMethod) const {
|
|
||||||
// Check nr of arguments
|
// Check nr of arguments
|
||||||
proxyFile.oss << "if length(varargin) == " << size();
|
proxyFile.oss << "if length(varargin) == " << size();
|
||||||
if (size() > 0)
|
if (size() > 0)
|
||||||
|
@ -203,10 +192,6 @@ void ArgumentList::emit_conditional_call(FileWriter& proxyFile,
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
proxyFile.oss << "\n";
|
proxyFile.oss << "\n";
|
||||||
|
|
||||||
// output call to C++ wrapper
|
|
||||||
proxyFile.oss << " ";
|
|
||||||
emit_call(proxyFile, returnVal, wrapperName, id, staticMethod);
|
|
||||||
}
|
}
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
||||||
|
|
|
@ -88,26 +88,12 @@ struct ArgumentList: public std::vector<Argument> {
|
||||||
void emit_prototype(FileWriter& file, const std::string& name) const;
|
void emit_prototype(FileWriter& file, const std::string& name) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* emit emit MATLAB call to proxy
|
* emit checking arguments to MATLAB proxy
|
||||||
* @param proxyFile output stream
|
* @param proxyFile output stream
|
||||||
* @param returnVal the return value
|
|
||||||
* @param wrapperName of method or function
|
|
||||||
* @param staticMethod flag to emit "this" in call
|
|
||||||
*/
|
*/
|
||||||
void emit_call(FileWriter& proxyFile, const ReturnValue& returnVal,
|
void proxy_check_arguments(FileWriter& proxyFile) const;
|
||||||
const std::string& wrapperName, int id, bool staticMethod = false) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* emit conditional MATLAB call to proxy (checking arguments first)
|
|
||||||
* @param proxyFile output stream
|
|
||||||
* @param returnVal the return value
|
|
||||||
* @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;
|
|
||||||
|
|
||||||
|
/// Output stream operator
|
||||||
friend std::ostream& operator<<(std::ostream& os,
|
friend std::ostream& operator<<(std::ostream& os,
|
||||||
const ArgumentList& argList) {
|
const ArgumentList& argList) {
|
||||||
os << "(";
|
os << "(";
|
||||||
|
@ -120,6 +106,7 @@ struct ArgumentList: public std::vector<Argument> {
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -29,12 +29,11 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
bool Function::initializeOrCheck(const std::string& name,
|
bool Function::initializeOrCheck(const string& name, const Qualified& instName,
|
||||||
const Qualified& instName, bool verbose) {
|
bool verbose) {
|
||||||
|
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
throw std::runtime_error(
|
throw runtime_error("Function::initializeOrCheck called with empty name");
|
||||||
"Function::initializeOrCheck called with empty name");
|
|
||||||
|
|
||||||
// Check if this overload is give to the correct method
|
// Check if this overload is give to the correct method
|
||||||
if (name_.empty()) {
|
if (name_.empty()) {
|
||||||
|
@ -44,7 +43,7 @@ bool Function::initializeOrCheck(const std::string& name,
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (name_ != name || templateArgValue_ != instName || verbose_ != verbose)
|
if (name_ != name || templateArgValue_ != instName || verbose_ != verbose)
|
||||||
throw std::runtime_error(
|
throw runtime_error(
|
||||||
"Function::initializeOrCheck called with different arguments: with name "
|
"Function::initializeOrCheck called with different arguments: with name "
|
||||||
+ name + " instead of expected " + name_
|
+ name + " instead of expected " + name_
|
||||||
+ ", or with template argument " + instName.qualifiedName(":")
|
+ ", or with template argument " + instName.qualifiedName(":")
|
||||||
|
@ -55,3 +54,26 @@ bool Function::initializeOrCheck(const std::string& name,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
void Function::emit_call(FileWriter& proxyFile, const ReturnValue& returnVal,
|
||||||
|
const string& wrapperName, int id, bool staticMethod) const {
|
||||||
|
returnVal.emit_matlab(proxyFile);
|
||||||
|
proxyFile.oss << wrapperName << "(" << id;
|
||||||
|
if (!staticMethod)
|
||||||
|
proxyFile.oss << ", this";
|
||||||
|
proxyFile.oss << ", varargin{:});\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
void Function::emit_conditional_call(FileWriter& proxyFile,
|
||||||
|
const ReturnValue& returnVal, const ArgumentList& args,
|
||||||
|
const string& wrapperName, int id, bool staticMethod) const {
|
||||||
|
|
||||||
|
// Check all arguments
|
||||||
|
args.proxy_check_arguments(proxyFile);
|
||||||
|
|
||||||
|
// output call to C++ wrapper
|
||||||
|
proxyFile.oss << " ";
|
||||||
|
emit_call(proxyFile, returnVal, wrapperName, id, staticMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -50,6 +50,16 @@ public:
|
||||||
else
|
else
|
||||||
return name_ + templateArgValue_.name;
|
return name_ + templateArgValue_.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Emit function call to MATLAB (no argument checking)
|
||||||
|
void emit_call(FileWriter& proxyFile, const ReturnValue& returnVal,
|
||||||
|
const std::string& wrapperName, int id, bool staticMethod) const;
|
||||||
|
|
||||||
|
/// Emit checking arguments and function call to MATLAB
|
||||||
|
void emit_conditional_call(FileWriter& proxyFile,
|
||||||
|
const ReturnValue& returnVal, const ArgumentList& args,
|
||||||
|
const std::string& wrapperName, int id, bool staticMethod) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -80,7 +80,8 @@ void GlobalFunction::generateSingleFunction(const string& toolboxPath,
|
||||||
|
|
||||||
// Output proxy matlab code
|
// Output proxy matlab code
|
||||||
mfunctionFile.oss << " " << (i == 0 ? "" : "else");
|
mfunctionFile.oss << " " << (i == 0 ? "" : "else");
|
||||||
args.emit_conditional_call(mfunctionFile, returnVal, wrapperName, id, true); // true omits "this"
|
emit_conditional_call(mfunctionFile, returnVal, args, wrapperName, id,
|
||||||
|
true); // true omits "this"
|
||||||
|
|
||||||
// Output C++ wrapper code
|
// Output C++ wrapper code
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,7 @@ void MethodBase::proxy_wrapper_fragments(FileWriter& proxyFile,
|
||||||
// TODO: document why is it OK to not check arguments in this case
|
// TODO: document why is it OK to not check arguments in this case
|
||||||
proxyFile.oss << " ";
|
proxyFile.oss << " ";
|
||||||
const int id = (int) functionNames.size();
|
const int id = (int) functionNames.size();
|
||||||
argumentList(0).emit_call(proxyFile, returnValue(0), wrapperName, id,
|
emit_call(proxyFile, returnValue(0), wrapperName, id, isStatic());
|
||||||
isStatic());
|
|
||||||
|
|
||||||
// Output C++ wrapper code
|
// Output C++ wrapper code
|
||||||
const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName,
|
const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName,
|
||||||
|
@ -71,7 +70,7 @@ void MethodBase::proxy_wrapper_fragments(FileWriter& proxyFile,
|
||||||
// Output proxy matlab code
|
// Output proxy matlab code
|
||||||
proxyFile.oss << " " << (i == 0 ? "" : "else");
|
proxyFile.oss << " " << (i == 0 ? "" : "else");
|
||||||
const int id = (int) functionNames.size();
|
const int id = (int) functionNames.size();
|
||||||
argumentList(i).emit_conditional_call(proxyFile, returnValue(i),
|
emit_conditional_call(proxyFile, returnValue(i), argumentList(i),
|
||||||
wrapperName, id, isStatic());
|
wrapperName, id, isStatic());
|
||||||
|
|
||||||
// Output C++ wrapper code
|
// Output C++ wrapper code
|
||||||
|
|
Loading…
Reference in New Issue