Trying more variations. Fixed small valgrind issue that didn't actually have an effect
parent
47fcb17ead
commit
d1b9185918
|
@ -37,6 +37,7 @@ void Method::addOverload(bool verbose, bool is_const, const std::string& name,
|
||||||
this->returnVals.push_back(retVal);
|
this->returnVals.push_back(retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
void Method::proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
void Method::proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
||||||
const string& cppClassName,
|
const string& cppClassName,
|
||||||
const std::string& matlabQualName,
|
const std::string& matlabQualName,
|
||||||
|
|
|
@ -69,22 +69,39 @@ void handle_possible_template(vector<Class>& classes, const Class& cls, const st
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Module::Module(const string& interfacePath,
|
Module::Module(const std::string& moduleName, bool enable_verbose)
|
||||||
const string& moduleName, bool enable_verbose) : name(moduleName), verbose(enable_verbose)
|
: name(moduleName), verbose(enable_verbose)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
Module::Module(const string& interfacePath,
|
||||||
|
const string& moduleName, bool enable_verbose)
|
||||||
|
: name(moduleName), verbose(enable_verbose)
|
||||||
|
{
|
||||||
|
// read interface file
|
||||||
|
string interfaceFile = interfacePath + "/" + moduleName + ".h";
|
||||||
|
string contents = file_contents(interfaceFile);
|
||||||
|
|
||||||
|
// execute parsing
|
||||||
|
parseMarkup(contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
void Module::parseMarkup(const std::string& data) {
|
||||||
// these variables will be imperatively updated to gradually build [cls]
|
// these variables will be imperatively updated to gradually build [cls]
|
||||||
// The one with postfix 0 are used to reset the variables after parse.
|
// The one with postfix 0 are used to reset the variables after parse.
|
||||||
string methodName, methodName0;
|
string methodName, methodName0;
|
||||||
bool isConst, isConst0 = false;
|
bool isConst, isConst0 = false;
|
||||||
ReturnValue retVal0(enable_verbose), retVal;
|
ReturnValue retVal0(verbose), retVal(verbose);
|
||||||
Argument arg0, arg;
|
Argument arg0, arg;
|
||||||
ArgumentList args0, args;
|
ArgumentList args0, args;
|
||||||
vector<string> arg_dup; ///keep track of duplicates
|
vector<string> arg_dup; ///keep track of duplicates
|
||||||
Constructor constructor0(enable_verbose), constructor(enable_verbose);
|
Constructor constructor0(verbose), constructor(verbose);
|
||||||
Deconstructor deconstructor0(enable_verbose), deconstructor(enable_verbose);
|
Deconstructor deconstructor0(verbose), deconstructor(verbose);
|
||||||
StaticMethod static_method0(enable_verbose), static_method(enable_verbose);
|
StaticMethod static_method0(verbose), static_method(verbose);
|
||||||
Class cls0(enable_verbose),cls(enable_verbose);
|
Class cls0(verbose),cls(verbose);
|
||||||
GlobalFunction globalFunc0(enable_verbose), globalFunc(enable_verbose);
|
GlobalFunction globalFunc0(verbose), globalFunc(verbose);
|
||||||
ForwardDeclaration fwDec0, fwDec;
|
ForwardDeclaration fwDec0, fwDec;
|
||||||
vector<string> namespaces, /// current namespace tag
|
vector<string> namespaces, /// current namespace tag
|
||||||
namespaces_return; /// namespace for current return type
|
namespaces_return; /// namespace for current return type
|
||||||
|
@ -110,7 +127,7 @@ Module::Module(const string& interfacePath,
|
||||||
(str_p("string") | "bool" | "size_t" | "int" | "double" | "char" | "unsigned char");
|
(str_p("string") | "bool" | "size_t" | "int" | "double" | "char" | "unsigned char");
|
||||||
|
|
||||||
Rule keywords_p =
|
Rule keywords_p =
|
||||||
(str_p("const") | "static" | "namespace" | basisType_p);
|
(str_p("const") | "static" | "namespace" | "void" | basisType_p);
|
||||||
|
|
||||||
Rule eigenType_p =
|
Rule eigenType_p =
|
||||||
(str_p("Vector") | "Matrix");
|
(str_p("Vector") | "Matrix");
|
||||||
|
@ -208,20 +225,21 @@ Module::Module(const string& interfacePath,
|
||||||
// (eigenType_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::EIGEN)])
|
// (eigenType_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::EIGEN)])
|
||||||
// | str_p("void")[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::VOID)]; // FIXME: allows for void in a pair
|
// | str_p("void")[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::VOID)]; // FIXME: allows for void in a pair
|
||||||
|
|
||||||
|
// current revision
|
||||||
|
Rule returnType1_p =
|
||||||
|
basisType_p[assign_a(retVal.category1, ReturnValue::BASIS)][assign_a(retVal.type1)] |
|
||||||
|
((*namespace_ret_p)[assign_a(retVal.namespaces1, namespaces_return)][clear_a(namespaces_return)]
|
||||||
|
>> (className_p[assign_a(retVal.category1, ReturnValue::CLASS)][assign_a(retVal.type1)]) >>
|
||||||
|
!ch_p('*')[assign_a(retVal.isPtr1,true)]) |
|
||||||
|
eigenType_p[assign_a(retVal.category1, ReturnValue::EIGEN)][assign_a(retVal.type1)];
|
||||||
|
|
||||||
|
// Original
|
||||||
// Rule returnType1_p =
|
// Rule returnType1_p =
|
||||||
// (eigenType_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::EIGEN)]) |
|
|
||||||
// (basisType_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::BASIS)]) |
|
// (basisType_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::BASIS)]) |
|
||||||
// ((*namespace_ret_p)[assign_a(retVal.namespaces1, namespaces_return)][clear_a(namespaces_return)]
|
// ((*namespace_ret_p)[assign_a(retVal.namespaces1, namespaces_return)][clear_a(namespaces_return)]
|
||||||
// >> (className_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::CLASS)]) >>
|
// >> (className_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::CLASS)]) >>
|
||||||
// !ch_p('*')[assign_a(retVal.isPtr1,true)]);
|
// !ch_p('*')[assign_a(retVal.isPtr1,true)]) |
|
||||||
|
// (eigenType_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::EIGEN)]);
|
||||||
// Original
|
|
||||||
Rule returnType1_p =
|
|
||||||
(basisType_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::BASIS)]) |
|
|
||||||
((*namespace_ret_p)[assign_a(retVal.namespaces1, namespaces_return)][clear_a(namespaces_return)]
|
|
||||||
>> (className_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::CLASS)]) >>
|
|
||||||
!ch_p('*')[assign_a(retVal.isPtr1,true)]) |
|
|
||||||
(eigenType_p[assign_a(retVal.type1)][assign_a(retVal.category1, ReturnValue::EIGEN)]);
|
|
||||||
|
|
||||||
Rule returnType2_p =
|
Rule returnType2_p =
|
||||||
(basisType_p[assign_a(retVal.type2)][assign_a(retVal.category2, ReturnValue::BASIS)]) |
|
(basisType_p[assign_a(retVal.type2)][assign_a(retVal.category2, ReturnValue::BASIS)]) |
|
||||||
|
@ -355,12 +373,8 @@ Module::Module(const string& interfacePath,
|
||||||
# endif
|
# endif
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// read interface file
|
|
||||||
string interfaceFile = interfacePath + "/" + moduleName + ".h";
|
|
||||||
string contents = file_contents(interfaceFile);
|
|
||||||
|
|
||||||
// and parse contents
|
// and parse contents
|
||||||
parse_info<const char*> info = parse(contents.c_str(), module_p, space_p);
|
parse_info<const char*> info = parse(data.c_str(), module_p, space_p);
|
||||||
if(!info.full) {
|
if(!info.full) {
|
||||||
printf("parsing stopped at \n%.20s\n",info.stop);
|
printf("parsing stopped at \n%.20s\n",info.stop);
|
||||||
throw ParseFailed((int)info.length);
|
throw ParseFailed((int)info.length);
|
||||||
|
@ -373,7 +387,6 @@ Module::Module(const string& interfacePath,
|
||||||
cls.methods.insert(inhereted.begin(), inhereted.end());
|
cls.methods.insert(inhereted.begin(), inhereted.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -38,9 +38,9 @@ struct Module {
|
||||||
typedef std::map<std::string, Method> Methods;
|
typedef std::map<std::string, Method> Methods;
|
||||||
|
|
||||||
std::string name; ///< module name
|
std::string name; ///< module name
|
||||||
|
bool verbose; ///< verbose flag
|
||||||
std::vector<Class> classes; ///< list of classes
|
std::vector<Class> classes; ///< list of classes
|
||||||
std::vector<TemplateInstantiationTypedef> templateInstantiationTypedefs; ///< list of template instantiations
|
std::vector<TemplateInstantiationTypedef> templateInstantiationTypedefs; ///< list of template instantiations
|
||||||
bool verbose; ///< verbose flag
|
|
||||||
std::vector<ForwardDeclaration> forward_declarations;
|
std::vector<ForwardDeclaration> forward_declarations;
|
||||||
std::vector<std::string> includes; ///< Include statements
|
std::vector<std::string> includes; ///< Include statements
|
||||||
GlobalFunctions global_functions;
|
GlobalFunctions global_functions;
|
||||||
|
@ -50,6 +50,9 @@ struct Module {
|
||||||
const std::string& moduleName,
|
const std::string& moduleName,
|
||||||
bool enable_verbose=true);
|
bool enable_verbose=true);
|
||||||
|
|
||||||
|
/// Dummy constructor that does no parsing - use only for testing
|
||||||
|
Module(const std::string& moduleName, bool enable_verbose=true);
|
||||||
|
|
||||||
//Recursive method to append all methods inhereted from parent classes
|
//Recursive method to append all methods inhereted from parent classes
|
||||||
std::map<std::string, Method> appendInheretedMethods(const Class& cls, const std::vector<Class>& classes);
|
std::map<std::string, Method> appendInheretedMethods(const Class& cls, const std::vector<Class>& classes);
|
||||||
|
|
||||||
|
@ -62,6 +65,10 @@ struct Module {
|
||||||
|
|
||||||
void generateIncludes(FileWriter& file) const;
|
void generateIncludes(FileWriter& file) const;
|
||||||
|
|
||||||
|
/// non-const function that performs parsing - typically called by constructor
|
||||||
|
/// Throws exception on failure
|
||||||
|
void parseMarkup(const std::string& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::vector<Class> ExpandTypedefInstantiations(const std::vector<Class>& classes, const std::vector<TemplateInstantiationTypedef> instantiations);
|
static std::vector<Class> ExpandTypedefInstantiations(const std::vector<Class>& classes, const std::vector<TemplateInstantiationTypedef> instantiations);
|
||||||
static std::vector<std::string> GenerateValidTypes(const std::vector<Class>& classes, const std::vector<ForwardDeclaration> forwardDeclarations);
|
static std::vector<std::string> GenerateValidTypes(const std::vector<Class>& classes, const std::vector<ForwardDeclaration> forwardDeclarations);
|
||||||
|
|
|
@ -70,6 +70,69 @@ TEST_UNSAFE( wrap, check_exception ) {
|
||||||
CHECK_EXCEPTION(module.matlab_code("actual_deps", headerPath), DependencyMissing);
|
CHECK_EXCEPTION(module.matlab_code("actual_deps", headerPath), DependencyMissing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST( wrap, small_parse ) {
|
||||||
|
string moduleName("gtsam");
|
||||||
|
Module module(moduleName, true);
|
||||||
|
|
||||||
|
string markup(
|
||||||
|
string("class Point2 { \n") +
|
||||||
|
string(" double x() const; \n") + // Method 1
|
||||||
|
string(" Matrix returnChar() const; \n") + // Method 2
|
||||||
|
string(" Point2 returnPoint2() const; \n") + // Method 3
|
||||||
|
string("};\n"));
|
||||||
|
module.parseMarkup(markup);
|
||||||
|
|
||||||
|
// check return types
|
||||||
|
LONGS_EQUAL(1, module.classes.size());
|
||||||
|
Class cls = module.classes.front();
|
||||||
|
EXPECT(assert_equal("Point2", cls.name));
|
||||||
|
EXPECT(!cls.isVirtual);
|
||||||
|
EXPECT(cls.namespaces.empty());
|
||||||
|
EXPECT(cls.static_methods.empty());
|
||||||
|
LONGS_EQUAL(3, cls.methods.size());
|
||||||
|
|
||||||
|
// Method 1
|
||||||
|
Method m1 = cls.methods.at("x");
|
||||||
|
EXPECT(assert_equal("x", m1.name));
|
||||||
|
EXPECT(m1.is_const_);
|
||||||
|
LONGS_EQUAL(1, m1.argLists.size());
|
||||||
|
LONGS_EQUAL(1, m1.returnVals.size());
|
||||||
|
|
||||||
|
ReturnValue rv1 = m1.returnVals.front();
|
||||||
|
EXPECT(!rv1.isPair);
|
||||||
|
EXPECT(!rv1.isPtr1);
|
||||||
|
EXPECT(assert_equal("double", rv1.type1));
|
||||||
|
EXPECT_LONGS_EQUAL(ReturnValue::BASIS, rv1.category1);
|
||||||
|
|
||||||
|
// Method 2
|
||||||
|
Method m2 = cls.methods.at("returnChar");
|
||||||
|
EXPECT(assert_equal("returnChar", m2.name));
|
||||||
|
EXPECT(m2.is_const_);
|
||||||
|
LONGS_EQUAL(1, m2.argLists.size());
|
||||||
|
LONGS_EQUAL(1, m2.returnVals.size());
|
||||||
|
|
||||||
|
ReturnValue rv2 = m2.returnVals.front();
|
||||||
|
EXPECT(!rv2.isPair);
|
||||||
|
EXPECT(!rv2.isPtr1);
|
||||||
|
EXPECT(assert_equal("Matrix", rv2.type1));
|
||||||
|
EXPECT_LONGS_EQUAL(ReturnValue::EIGEN, rv2.category1);
|
||||||
|
|
||||||
|
// Method 3
|
||||||
|
Method m3 = cls.methods.at("returnPoint2");
|
||||||
|
EXPECT(assert_equal("returnPoint2", m3.name));
|
||||||
|
EXPECT(m3.is_const_);
|
||||||
|
LONGS_EQUAL(1, m3.argLists.size());
|
||||||
|
LONGS_EQUAL(1, m3.returnVals.size());
|
||||||
|
|
||||||
|
ReturnValue rv3 = m3.returnVals.front();
|
||||||
|
EXPECT(!rv3.isPair);
|
||||||
|
EXPECT(!rv3.isPtr1);
|
||||||
|
EXPECT(assert_equal("Point2", rv3.type1));
|
||||||
|
EXPECT_LONGS_EQUAL(ReturnValue::CLASS, rv3.category1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST( wrap, parse_geometry ) {
|
TEST( wrap, parse_geometry ) {
|
||||||
string markup_header_path = topdir + "/wrap/tests";
|
string markup_header_path = topdir + "/wrap/tests";
|
||||||
|
|
|
@ -136,7 +136,8 @@ void createNamespaceStructure(const std::vector<std::string>& namespaces, const
|
||||||
using namespace boost::filesystem;
|
using namespace boost::filesystem;
|
||||||
path curPath = toolboxPath;
|
path curPath = toolboxPath;
|
||||||
BOOST_FOREACH(const string& subdir, namespaces) {
|
BOOST_FOREACH(const string& subdir, namespaces) {
|
||||||
curPath /= "+" + subdir;
|
// curPath /= "+" + subdir; // original - resulted in valgrind error
|
||||||
|
curPath = curPath / string(string("+") + subdir);
|
||||||
if(!is_directory(curPath)) {
|
if(!is_directory(curPath)) {
|
||||||
if(exists("+" + subdir))
|
if(exists("+" + subdir))
|
||||||
throw OutputError("Need to write files to directory " + curPath.string() + ", which already exists as a file but is not a directory");
|
throw OutputError("Need to write files to directory " + curPath.string() + ", which already exists as a file but is not a directory");
|
||||||
|
|
Loading…
Reference in New Issue