Simple namespace works

release/4.3a0
Alex Cunningham 2011-12-08 20:51:05 +00:00
parent 1130cf43e0
commit 1aecb58807
3 changed files with 35 additions and 28 deletions

View File

@ -162,12 +162,12 @@ Module::Module(const string& interfacePath,
Rule namespace_p = str_p("namespace") >>
namespace_name_p[assign_a(namespaces_parent, namespaces)][push_back_a(namespaces)] // save previous state
>> confix_p('{', // start namespace
+(comments_p | class_p | namespace_p),
('}' >> (*anychar_p - ch_p(';'))) // end namespace, avoid confusion with classes
)[assign_a(namespaces, namespaces_parent)]; // switch back to parent namespace
>> ch_p('{') >>
*(class_p | namespace_p | comments_p) >>
str_p("}//\\namespace") // end namespace, avoid confusion with classes
[assign_a(namespaces, namespaces_parent)]; // switch back to parent namespace
Rule module_content_p = comments_p | namespace_p | class_p;
Rule module_content_p = comments_p | class_p | namespace_p ;
Rule module_p = *module_content_p >> !end_p;

View File

@ -22,6 +22,9 @@ class Point3 {
// another comment
// NOTE: you *must* end namespaces as follows:
}//\namespace
// another comment
/**
@ -71,8 +74,6 @@ class Test {
// even more comments at the end!
};
} // \ns_inner
// comments at the end!
// even more comments at the end!

View File

@ -15,6 +15,7 @@
* @author Frank Dellaert
**/
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <sstream>
@ -56,12 +57,11 @@ TEST( wrap, check_exception ) {
/* ************************************************************************* */
TEST( wrap, parse ) {
string path = topdir + "/wrap/tests";
string header_path = topdir + "/wrap/tests";
Module module(path.c_str(), "geometry",enable_verbose);
Module module(header_path.c_str(), "geometry",enable_verbose);
EXPECT_LONGS_EQUAL(3, module.classes.size());
//Hack to solve issues with instantiating Modules
path = topdir + "/wrap";
string path = topdir + "/wrap";
// check first class, Point2
{
@ -102,26 +102,32 @@ TEST( wrap, parse ) {
EXPECT(m1.is_const_);
}
// // Test class is the third one
// LONGS_EQUAL(3, module.classes.size());
// Class testCls = module.classes.at(2);
// EXPECT_LONGS_EQUAL( 2, testCls.constructors.size());
// EXPECT_LONGS_EQUAL(19, testCls.methods.size());
// EXPECT_LONGS_EQUAL( 0, testCls.static_methods.size());
//
// // function to parse: pair<Vector,Matrix> return_pair (Vector v, Matrix A) const;
// Method m2 = testCls.methods.front();
// EXPECT(m2.returnVal_.isPair);
// EXPECT(m2.returnVal_.category1 == ReturnValue::EIGEN);
// EXPECT(m2.returnVal_.category2 == ReturnValue::EIGEN);
// Test class is the third one
{
LONGS_EQUAL(3, module.classes.size());
Class testCls = module.classes.at(2);
EXPECT_LONGS_EQUAL( 2, testCls.constructors.size());
EXPECT_LONGS_EQUAL(19, testCls.methods.size());
EXPECT_LONGS_EQUAL( 0, testCls.static_methods.size());
// function to parse: pair<Vector,Matrix> return_pair (Vector v, Matrix A) const;
Method m2 = testCls.methods.front();
EXPECT(m2.returnVal_.isPair);
EXPECT(m2.returnVal_.category1 == ReturnValue::EIGEN);
EXPECT(m2.returnVal_.category2 == ReturnValue::EIGEN);
}
}
/* ************************************************************************* */
TEST( wrap, matlab_code ) {
// Parse into class object
string path = topdir + "/wrap/tests";
Module module(path,"geometry",enable_verbose);
path = topdir + "/wrap";
string header_path = topdir + "/wrap/tests";
Module module(header_path,"geometry",enable_verbose);
string path = topdir + "/wrap";
// clean out previous generated code
string cleanCmd = "rm -rf actual";
system(cleanCmd.c_str());
// emit MATLAB code
// make_geometry will not compile, use make testwrap to generate real make