From 7e221aa7a1c5d7e5fa0bd4c2730b114f67a37f90 Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Thu, 1 Dec 2011 22:06:03 +0000 Subject: [PATCH] Added comment support in wrap --- .cproject | 229 ++++++++++-------- gtsam-broken.h | 187 -------------- gtsam.h | 197 +++++++++++++++ gtsam/geometry/Pose3.h | 4 +- wrap/Module.cpp | 31 ++- wrap/geometry.h | 21 +- .../tests/expected/@Test/return_Point2Ptr.cpp | 11 + wrap/tests/expected/@Test/return_Point2Ptr.m | 4 + wrap/tests/expected/make_geometry.m | 1 + wrap/tests/testSpirit.cpp | 55 +++-- wrap/tests/testWrap.cpp | 9 +- 11 files changed, 422 insertions(+), 327 deletions(-) delete mode 100644 gtsam-broken.h create mode 100644 wrap/tests/expected/@Test/return_Point2Ptr.cpp create mode 100644 wrap/tests/expected/@Test/return_Point2Ptr.m diff --git a/.cproject b/.cproject index a35bd2fed..bdbc3c0dd 100644 --- a/.cproject +++ b/.cproject @@ -375,6 +375,14 @@ true true + + make + -j2 + testGaussianFactor.run + true + true + true + make -j2 @@ -401,7 +409,6 @@ make - tests/testBayesTree.run true false @@ -409,7 +416,6 @@ make - testBinaryBayesNet.run true false @@ -457,7 +463,6 @@ make - testSymbolicBayesNet.run true false @@ -465,7 +470,6 @@ make - tests/testSymbolicFactor.run true false @@ -473,7 +477,6 @@ make - testSymbolicFactorGraph.run true false @@ -489,20 +492,11 @@ make - tests/testBayesTree true false true - - make - -j2 - testGaussianFactor.run - true - true - true - make -j2 @@ -529,6 +523,7 @@ make + testGraph.run true false @@ -600,6 +595,7 @@ make + testInference.run true false @@ -607,6 +603,7 @@ make + testGaussianFactor.run true false @@ -614,6 +611,7 @@ make + testJunctionTree.run true false @@ -621,6 +619,7 @@ make + testSymbolicBayesNet.run true false @@ -628,6 +627,7 @@ make + testSymbolicFactorGraph.run true false @@ -681,22 +681,6 @@ true true - - make - -j2 - tests/testPose2.run - true - true - true - - - make - -j2 - tests/testPose3.run - true - true - true - make -j2 @@ -713,6 +697,22 @@ true true + + make + -j2 + tests/testPose2.run + true + true + true + + + make + -j2 + tests/testPose3.run + true + true + true + make -j2 @@ -737,15 +737,7 @@ true true - - make - -j2 - all - true - true - true - - + make -j2 check @@ -753,14 +745,6 @@ true true - - make - -j2 - clean - true - true - true - make -j2 @@ -801,7 +785,15 @@ true true - + + make + -j2 + all + true + true + true + + make -j2 check @@ -809,6 +801,14 @@ true true + + make + -j2 + clean + true + true + true + make -j2 @@ -1131,7 +1131,6 @@ make - testErrors.run true false @@ -1539,6 +1538,7 @@ make + testSimulated2DOriented.run true false @@ -1578,6 +1578,7 @@ make + testSimulated2D.run true false @@ -1585,6 +1586,7 @@ make + testSimulated3D.run true false @@ -1832,6 +1834,7 @@ make + tests/testGaussianISAM2 true false @@ -1853,46 +1856,6 @@ true true - - make - -j2 - install - true - true - true - - - make - -j2 - clean - true - true - true - - - make - -j2 - check - true - true - true - - - make - -j2 - all - true - true - true - - - make - -j2 - dist - true - true - true - make -j2 @@ -1989,6 +1952,78 @@ true true + + make + -j2 + install + true + true + true + + + make + -j2 + clean + true + true + true + + + make + -j2 + check + true + true + true + + + make + -j2 + all + true + true + true + + + make + -j2 + dist + true + true + true + + + make + -j2 + check + true + true + true + + + make + -j2 + install + true + true + true + + + make + -j2 + tests/testSpirit.run + true + true + true + + + make + -j2 + tests/testWrap.run + true + true + true + make -j2 @@ -2029,22 +2064,6 @@ true true - - make - -j2 - check - true - true - true - - - make - -j2 - install - true - true - true - diff --git a/gtsam-broken.h b/gtsam-broken.h deleted file mode 100644 index 6d7fbe4b0..000000000 --- a/gtsam-broken.h +++ /dev/null @@ -1,187 +0,0 @@ -// These are considered to be broken and will be added back as they start working -// It's assumed that there have been interface changes that might break this - -class Pose3 { - Point3* _translation() const; - Rot3* _rotation() const; -}; - -class Ordering{ - Ordering(string key); - void print(string s) const; - bool equals(const Ordering& ord, double tol) const; - Ordering subtract(const Ordering& keys) const; - void unique (); - void reverse (); - void push_back(string s); -}; - -class GaussianFactorSet { - GaussianFactorSet(); - void push_back(GaussianFactor* factor); -}; - -class Simulated2DValues { - Simulated2DValues(); - void print(string s) const; - void insertPose(int i, const Point2& p); - void insertPoint(int j, const Point2& p); - int nrPoses() const; - int nrPoints() const; - Point2* pose(int i); - Point2* point(int j); -}; - -class Simulated2DOrientedValues { - Simulated2DOrientedValues(); - void print(string s) const; - void insertPose(int i, const Pose2& p); - void insertPoint(int j, const Point2& p); - int nrPoses() const; - int nrPoints() const; - Pose2* pose(int i); - Point2* point(int j); -}; - -class Simulated2DPosePrior { - Simulated2DPosePrior(Point2& mu, const SharedDiagonal& model, int i); - void print(string s) const; - double error(const Simulated2DValues& c) const; -}; - -class Simulated2DOrientedPosePrior { - Simulated2DOrientedPosePrior(Pose2& mu, const SharedDiagonal& model, int i); - void print(string s) const; - double error(const Simulated2DOrientedValues& c) const; -}; - -class Simulated2DPointPrior { - Simulated2DPointPrior(Point2& mu, const SharedDiagonal& model, int i); - void print(string s) const; - double error(const Simulated2DValues& c) const; -}; - -class Simulated2DOdometry { - Simulated2DOdometry(Point2& mu, const SharedDiagonal& model, int i1, int i2); - void print(string s) const; - double error(const Simulated2DValues& c) const; -}; - -class Simulated2DOrientedOdometry { - Simulated2DOrientedOdometry(Pose2& mu, const SharedDiagonal& model, int i1, int i2); - void print(string s) const; - double error(const Simulated2DOrientedValues& c) const; -}; - -class Simulated2DMeasurement { - Simulated2DMeasurement(Point2& mu, const SharedDiagonal& model, int i, int j); - void print(string s) const; - double error(const Simulated2DValues& c) const; -}; - -// These are currently broken -// Solve by parsing a namespace pose2SLAM::Values and making a Pose2SLAMValues class -// We also have to solve the shared pointer mess to avoid duplicate methods - -class GaussianFactor { - GaussianFactor(string key1, - Matrix A1, - Vector b_in, - const SharedDiagonal& model); - GaussianFactor(string key1, - Matrix A1, - string key2, - Matrix A2, - Vector b_in, - const SharedDiagonal& model); - GaussianFactor(string key1, - Matrix A1, - string key2, - Matrix A2, - string key3, - Matrix A3, - Vector b_in, - const SharedDiagonal& model); - bool involves(string key) const; - Matrix getA(string key) const; - pair matrix(const Ordering& ordering) const; - pair eliminate(string key) const; -}; - -class GaussianFactorGraph { - GaussianConditional* eliminateOne(string key); - GaussianBayesNet* eliminate_(const Ordering& ordering); - VectorValues* optimize_(const Ordering& ordering); - pair matrix(const Ordering& ordering) const; - VectorValues* steepestDescent_(const VectorValues& x0) const; - VectorValues* conjugateGradientDescent_(const VectorValues& x0) const; -}; - - -class Pose2Values{ - Pose2Values(); - Pose2 get(string key) const; - void insert(string name, const Pose2& val); - void print(string s) const; - void clear(); - int size(); -}; - -class Pose2Factor { - Pose2Factor(string key1, string key2, - const Pose2& measured, Matrix measurement_covariance); - void print(string name) const; - double error(const Pose2Values& c) const; - size_t size() const; - GaussianFactor* linearize(const Pose2Values& config) const; -}; - -class Pose2Graph{ - Pose2Graph(); - void print(string s) const; - GaussianFactorGraph* linearize_(const Pose2Values& config) const; - void push_back(Pose2Factor* factor); -}; - -class SymbolicFactor{ - SymbolicFactor(const Ordering& keys); - void print(string s) const; -}; - -class Simulated2DPosePrior { - GaussianFactor* linearize(const Simulated2DValues& config) const; -}; - -class Simulated2DOrientedPosePrior { - GaussianFactor* linearize(const Simulated2DOrientedValues& config) const; -}; - -class Simulated2DPointPrior { - GaussianFactor* linearize(const Simulated2DValues& config) const; -}; - -class Simulated2DOdometry { - GaussianFactor* linearize(const Simulated2DValues& config) const; -}; - -class Simulated2DOrientedOdometry { - GaussianFactor* linearize(const Simulated2DOrientedValues& config) const; -}; - -class Simulated2DMeasurement { - GaussianFactor* linearize(const Simulated2DValues& config) const; -}; - -class Pose2SLAMOptimizer { - Pose2SLAMOptimizer(string dataset_name); - void print(string s) const; - void update(Vector x) const; - Vector optimize() const; - double error() const; - Matrix a1() const; - Matrix a2() const; - Vector b1() const; - Vector b2() const; -}; - - diff --git a/gtsam.h b/gtsam.h index 9b4eb1437..ed746c033 100644 --- a/gtsam.h +++ b/gtsam.h @@ -1,3 +1,17 @@ +/** + * GTSAM Wrap Module definition + * + * These are the current classes available through the matlab toolbox interface, + * add more functions/classes as they are available. + * + * Requirements: + * Constructors must appear in a class before any methods + * Methods can only return Matrix, Vector, double, int, void, and a shared_ptr to any other object + * Comments can use either C++ or C style + * Static methods are not supported + * Methods must start with a lowercase letter + */ + class Point2 { Point2(); Point2(double x, double y); @@ -88,6 +102,8 @@ class Pose3 { Pose3* between_(const Pose3& p2); Vector localCoordinates(const Pose3& p); Pose3* retract_(Vector v); + Point3* translation_() const; + Rot3* rotation_() const; }; class SharedGaussian { @@ -233,3 +249,184 @@ class GaussianSequentialSolver { GaussianFactor* marginalFactor(int j) const; Matrix marginalCovariance(int j) const; }; + +//// These are considered to be broken and will be added back as they start working +//// It's assumed that there have been interface changes that might break this +// +//class Ordering{ +// Ordering(string key); +// void print(string s) const; +// bool equals(const Ordering& ord, double tol) const; +// Ordering subtract(const Ordering& keys) const; +// void unique (); +// void reverse (); +// void push_back(string s); +//}; +// +//class GaussianFactorSet { +// GaussianFactorSet(); +// void push_back(GaussianFactor* factor); +//}; +// +//class Simulated2DValues { +// Simulated2DValues(); +// void print(string s) const; +// void insertPose(int i, const Point2& p); +// void insertPoint(int j, const Point2& p); +// int nrPoses() const; +// int nrPoints() const; +// Point2* pose(int i); +// Point2* point(int j); +//}; +// +//class Simulated2DOrientedValues { +// Simulated2DOrientedValues(); +// void print(string s) const; +// void insertPose(int i, const Pose2& p); +// void insertPoint(int j, const Point2& p); +// int nrPoses() const; +// int nrPoints() const; +// Pose2* pose(int i); +// Point2* point(int j); +//}; +// +//class Simulated2DPosePrior { +// Simulated2DPosePrior(Point2& mu, const SharedDiagonal& model, int i); +// void print(string s) const; +// double error(const Simulated2DValues& c) const; +//}; +// +//class Simulated2DOrientedPosePrior { +// Simulated2DOrientedPosePrior(Pose2& mu, const SharedDiagonal& model, int i); +// void print(string s) const; +// double error(const Simulated2DOrientedValues& c) const; +//}; +// +//class Simulated2DPointPrior { +// Simulated2DPointPrior(Point2& mu, const SharedDiagonal& model, int i); +// void print(string s) const; +// double error(const Simulated2DValues& c) const; +//}; +// +//class Simulated2DOdometry { +// Simulated2DOdometry(Point2& mu, const SharedDiagonal& model, int i1, int i2); +// void print(string s) const; +// double error(const Simulated2DValues& c) const; +//}; +// +//class Simulated2DOrientedOdometry { +// Simulated2DOrientedOdometry(Pose2& mu, const SharedDiagonal& model, int i1, int i2); +// void print(string s) const; +// double error(const Simulated2DOrientedValues& c) const; +//}; +// +//class Simulated2DMeasurement { +// Simulated2DMeasurement(Point2& mu, const SharedDiagonal& model, int i, int j); +// void print(string s) const; +// double error(const Simulated2DValues& c) const; +//}; +// +//// These are currently broken +//// Solve by parsing a namespace pose2SLAM::Values and making a Pose2SLAMValues class +//// We also have to solve the shared pointer mess to avoid duplicate methods +// +//class GaussianFactor { +// GaussianFactor(string key1, +// Matrix A1, +// Vector b_in, +// const SharedDiagonal& model); +// GaussianFactor(string key1, +// Matrix A1, +// string key2, +// Matrix A2, +// Vector b_in, +// const SharedDiagonal& model); +// GaussianFactor(string key1, +// Matrix A1, +// string key2, +// Matrix A2, +// string key3, +// Matrix A3, +// Vector b_in, +// const SharedDiagonal& model); +// bool involves(string key) const; +// Matrix getA(string key) const; +// pair matrix(const Ordering& ordering) const; +// pair eliminate(string key) const; +//}; +// +//class GaussianFactorGraph { +// GaussianConditional* eliminateOne(string key); +// GaussianBayesNet* eliminate_(const Ordering& ordering); +// VectorValues* optimize_(const Ordering& ordering); +// pair matrix(const Ordering& ordering) const; +// VectorValues* steepestDescent_(const VectorValues& x0) const; +// VectorValues* conjugateGradientDescent_(const VectorValues& x0) const; +//}; +// +// +//class Pose2Values{ +// Pose2Values(); +// Pose2 get(string key) const; +// void insert(string name, const Pose2& val); +// void print(string s) const; +// void clear(); +// int size(); +//}; +// +//class Pose2Factor { +// Pose2Factor(string key1, string key2, +// const Pose2& measured, Matrix measurement_covariance); +// void print(string name) const; +// double error(const Pose2Values& c) const; +// size_t size() const; +// GaussianFactor* linearize(const Pose2Values& config) const; +//}; +// +//class Pose2Graph{ +// Pose2Graph(); +// void print(string s) const; +// GaussianFactorGraph* linearize_(const Pose2Values& config) const; +// void push_back(Pose2Factor* factor); +//}; +// +//class SymbolicFactor{ +// SymbolicFactor(const Ordering& keys); +// void print(string s) const; +//}; +// +//class Simulated2DPosePrior { +// GaussianFactor* linearize(const Simulated2DValues& config) const; +//}; +// +//class Simulated2DOrientedPosePrior { +// GaussianFactor* linearize(const Simulated2DOrientedValues& config) const; +//}; +// +//class Simulated2DPointPrior { +// GaussianFactor* linearize(const Simulated2DValues& config) const; +//}; +// +//class Simulated2DOdometry { +// GaussianFactor* linearize(const Simulated2DValues& config) const; +//}; +// +//class Simulated2DOrientedOdometry { +// GaussianFactor* linearize(const Simulated2DOrientedValues& config) const; +//}; +// +//class Simulated2DMeasurement { +// GaussianFactor* linearize(const Simulated2DValues& config) const; +//}; +// +//class Pose2SLAMOptimizer { +// Pose2SLAMOptimizer(string dataset_name); +// void print(string s) const; +// void update(Vector x) const; +// Vector optimize() const; +// double error() const; +// Matrix a1() const; +// Matrix a2() const; +// Vector b1() const; +// Vector b2() const; +//}; diff --git a/gtsam/geometry/Pose3.h b/gtsam/geometry/Pose3.h index f8e40efd1..27147cdca 100644 --- a/gtsam/geometry/Pose3.h +++ b/gtsam/geometry/Pose3.h @@ -56,12 +56,12 @@ namespace gtsam { T(2, 1), T(2, 2)), t_(T(0, 3), T(1, 3), T(2, 3)) {} const Rot3& rotation() const { return R_; } - boost::shared_ptr _rotation() const { + boost::shared_ptr rotation_() const { return boost::shared_ptr(new Rot3(R_)); } const Point3& translation() const { return t_; } - boost::shared_ptr _translation() const { + boost::shared_ptr translation_() const { return boost::shared_ptr(new Point3(t_)); } diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 7a01161e1..922983de2 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -19,6 +19,7 @@ //#define BOOST_SPIRIT_DEBUG #include +#include #include #include @@ -59,6 +60,8 @@ Module::Module(const string& interfacePath, // - The types unsigned int and bool should be specified as int. // ---------------------------------------------------------------------------- + Rule comments_p = comment_p("/*", "*/") | comment_p("//"); + // lexeme_d turns off white space skipping // http://www.boost.org/doc/libs/1_37_0/libs/spirit/classic/doc/directives.html @@ -90,7 +93,7 @@ Module::Module(const string& interfacePath, Rule argumentList_p = !argument_p >> * (',' >> argument_p); Rule constructor_p = - (className_p >> '(' >> argumentList_p >> ')' >> ';') + (className_p >> '(' >> argumentList_p >> ')' >> ';' >> !comments_p) [assign_a(constructor.args,args)] [assign_a(args,args0)] [push_back_a(cls.constructors, constructor)] @@ -119,20 +122,25 @@ Module::Module(const string& interfacePath, Rule method_p = (returnType_p >> methodName_p[assign_a(method.name_)] >> '(' >> argumentList_p >> ')' >> - !str_p("const")[assign_a(method.is_const_,true)] >> ';') + !str_p("const")[assign_a(method.is_const_,true)] >> ';' >> *comments_p) [assign_a(method.args_,args)] [assign_a(args,args0)] [push_back_a(cls.methods, method)] [assign_a(method,method0)]; - Rule class_p = str_p("class") >> className_p[assign_a(cls.name)] >> '{' >> - *constructor_p >> - *method_p >> + Rule class_p = str_p("class") >> className_p[assign_a(cls.name)] >> '{' >> + *comments_p >> + *constructor_p >> + *comments_p >> + *method_p >> + *comments_p >> '}' >> ";"; - Rule module_p = +class_p + Rule module_p = *comments_p >> +(class_p [push_back_a(classes,cls)] - [assign_a(cls,cls0)] + [assign_a(cls,cls0)] + >> *comments_p) + >> *comments_p >> !end_p; //---------------------------------------------------------------------------- @@ -162,9 +170,12 @@ Module::Module(const string& interfacePath, string interfaceFile = interfacePath + "/" + moduleName + ".h"; string contents = file_contents(interfaceFile); - // Comment parser : does not work for some reason - rule<> comment_p = str_p("/*") >> +anychar_p >> "*/"; - rule<> skip_p = space_p; // | comment_p; + // FIXME: Comment parser does not work for some reason - see confix parsers +// rule<> comment_p = str_p("/*") >> +anychar_p >> "*/"; +// rule<> skip_p = space_p | comment_p; +// rule<> skip_p = space_p | comment_p("//"); // FIXME: also doesn't work +// rule<> skip_p = space_p | comment_p("/*", "*/"); // FIXME: Doesn't compile + rule<> skip_p = space_p; // and parse contents parse_info info = parse(contents.c_str(), module_p, skip_p); diff --git a/wrap/geometry.h b/wrap/geometry.h index 9b1d80b00..70500a46d 100644 --- a/wrap/geometry.h +++ b/wrap/geometry.h @@ -1,3 +1,4 @@ + // comments! class Point2 { Point2(); @@ -12,14 +13,22 @@ class Point3 { double norm() const; }; +// another comment + class Test { + /* a comment! */ + // another comment Test(); - bool return_bool (bool value); + bool return_bool (bool value); // comment after a line! size_t return_size_t (size_t value); int return_int (int value); double return_double (double value); + // comments in the middle! + + // (more) comments in the middle! + string return_string (string value); Vector return_vector1(Vector value); Matrix return_matrix1(Matrix value); @@ -32,8 +41,18 @@ class Test { Test* return_TestPtr(Test* value); + Point2* return_Point2Ptr(bool value); + pair create_ptrs (); pair return_ptrs (Test* p1, Test* p2); void print(); + + // comments at the end! + + // even more comments at the end! }; + +// comments at the end! + +// even more comments at the end! diff --git a/wrap/tests/expected/@Test/return_Point2Ptr.cpp b/wrap/tests/expected/@Test/return_Point2Ptr.cpp new file mode 100644 index 000000000..e30ffe722 --- /dev/null +++ b/wrap/tests/expected/@Test/return_Point2Ptr.cpp @@ -0,0 +1,11 @@ +// automatically generated by wrap on 2011-Dec-01 +#include +#include +void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) +{ + checkArguments("return_Point2Ptr",nargout,nargin-1,1); + shared_ptr self = unwrap_shared_ptr< Test >(in[0],"Test"); + bool value = unwrap< bool >(in[1]); + shared_ptr result = self->return_Point2Ptr(value); + out[0] = wrap_shared_ptr(result,"Point2"); +} diff --git a/wrap/tests/expected/@Test/return_Point2Ptr.m b/wrap/tests/expected/@Test/return_Point2Ptr.m new file mode 100644 index 000000000..2da8b3710 --- /dev/null +++ b/wrap/tests/expected/@Test/return_Point2Ptr.m @@ -0,0 +1,4 @@ +function result = return_Point2Ptr(obj,value) +% usage: obj.return_Point2Ptr(value) + error('need to compile return_Point2Ptr.cpp'); +end diff --git a/wrap/tests/expected/make_geometry.m b/wrap/tests/expected/make_geometry.m index cad4eab1d..c27fd466c 100644 --- a/wrap/tests/expected/make_geometry.m +++ b/wrap/tests/expected/make_geometry.m @@ -41,6 +41,7 @@ mex -O5 return_matrix2.cpp mex -O5 return_pair.cpp mex -O5 return_field.cpp mex -O5 return_TestPtr.cpp +mex -O5 return_Point2Ptr.cpp mex -O5 create_ptrs.cpp mex -O5 return_ptrs.cpp mex -O5 print.cpp diff --git a/wrap/tests/testSpirit.cpp b/wrap/tests/testSpirit.cpp index a1862f439..5310ecff6 100644 --- a/wrap/tests/testSpirit.cpp +++ b/wrap/tests/testSpirit.cpp @@ -17,7 +17,9 @@ #include #include +#include #include +#include using namespace std; using namespace BOOST_SPIRIT_CLASSIC_NS; @@ -36,31 +38,31 @@ Rule basisType_p = (str_p("string") | "bool" | "size_t" | "int" | "double" | "Ve /* ************************************************************************* */ TEST( spirit, real ) { // check if we can parse 8.99 as a real - CHECK(parse("8.99", real_p, space_p).full); + EXPECT(parse("8.99", real_p, space_p).full); // make sure parsing fails on this one - CHECK(!parse("zztop", real_p, space_p).full); + EXPECT(!parse("zztop", real_p, space_p).full); } /* ************************************************************************* */ TEST( spirit, string ) { // check if we can parse a string - CHECK(parse("double", str_p("double"), space_p).full); + EXPECT(parse("double", str_p("double"), space_p).full); } /* ************************************************************************* */ TEST( spirit, sequence ) { // check that we skip white space - CHECK(parse("int int", str_p("int") >> *str_p("int"), space_p).full); - CHECK(parse("int --- - -- -", str_p("int") >> *ch_p('-'), space_p).full); - CHECK(parse("const \t string", str_p("const") >> str_p("string"), space_p).full); + EXPECT(parse("int int", str_p("int") >> *str_p("int"), space_p).full); + EXPECT(parse("int --- - -- -", str_p("int") >> *ch_p('-'), space_p).full); + EXPECT(parse("const \t string", str_p("const") >> str_p("string"), space_p).full); // note that (see spirit FAQ) the vanilla rule<> does not deal with whitespace rule<>vanilla_p = str_p("const") >> str_p("string"); - CHECK(!parse("const \t string", vanilla_p, space_p).full); + EXPECT(!parse("const \t string", vanilla_p, space_p).full); // to fix it, we need to use rulephrase_level_p = str_p("const") >> str_p("string"); - CHECK(parse("const \t string", phrase_level_p, space_p).full); + EXPECT(parse("const \t string", phrase_level_p, space_p).full); } /* ************************************************************************* */ @@ -81,24 +83,49 @@ Rule constMethod_p = basisType_p >> methodName_p >> '(' >> ')' >> "const" >> ';' /* ************************************************************************* */ TEST( spirit, basisType_p ) { - CHECK(!parse("Point3", basisType_p, space_p).full); - CHECK(parse("string", basisType_p, space_p).full); + EXPECT(!parse("Point3", basisType_p, space_p).full); + EXPECT(parse("string", basisType_p, space_p).full); } /* ************************************************************************* */ TEST( spirit, className_p ) { - CHECK(parse("Point3", className_p, space_p).full); + EXPECT(parse("Point3", className_p, space_p).full); } /* ************************************************************************* */ TEST( spirit, classRef_p ) { - CHECK(parse("Point3 &", classRef_p, space_p).full); - CHECK(parse("Point3&", classRef_p, space_p).full); + EXPECT(parse("Point3 &", classRef_p, space_p).full); + EXPECT(parse("Point3&", classRef_p, space_p).full); } /* ************************************************************************* */ TEST( spirit, constMethod_p ) { - CHECK(parse("double norm() const;", constMethod_p, space_p).full); + EXPECT(parse("double norm() const;", constMethod_p, space_p).full); +} + +/* ************************************************************************* */ +TEST( spirit, comments ) { +// Rule name_p = lexeme_d[alpha_p >> *(alnum_p | '_')]; +// +// Rule argument_p = +// ((basisType_p[assign_a(arg.type)] | eigenType | classPtr_p | classRef_p) >> name_p[assign_a(arg.name)]) +// [push_back_a(args, arg)] +// [assign_a(arg,arg0)]; +// +// Rule void_p = str_p("void")[assign_a(method.returns_)]; + + vector all_strings; + string actual; +// Rule slash_comment_p = str_p("//"); +// Rule comments_p = anychar_p[assign_a(actual)] +// Rule comments_p = lexeme_d[*(anychar_p)[assign_a(actual)] + +// Rule line_p = (*anychar_p - comment_p("//"))[assign_a(actual)] >> !(comment_p("//") >> *anychar_p); // FAIL: matches everything +// Rule line_p = *anychar_p[assign_a(actual)] >> !(comment_p("//") >> *anychar_p); // FAIL: matches last letter +// Rule line_p = (*anychar_p - comment_p("//"))[assign_a(actual)] >> !(comment_p("//") >> *anychar_p); +// +// EXPECT(parse("not commentq // comment", line_p, eol_p).full); +// EXPECT(assert_equal(string("not comments "), actual)); } /* ************************************************************************* */ diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index e343aad16..39621c10f 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -105,6 +105,7 @@ TEST( wrap, matlab_code ) { EXPECT(files_equal(path + "/tests/expected/@Test/return_pair.cpp" , "actual/@Test/return_pair.cpp" )); EXPECT(files_equal(path + "/tests/expected/@Test/return_field.cpp" , "actual/@Test/return_field.cpp" )); EXPECT(files_equal(path + "/tests/expected/@Test/return_TestPtr.cpp", "actual/@Test/return_TestPtr.cpp")); + EXPECT(files_equal(path + "/tests/expected/@Test/return_Point2Ptr.cpp", "actual/@Test/return_Point2Ptr.cpp")); EXPECT(files_equal(path + "/tests/expected/@Test/return_ptrs.cpp" , "actual/@Test/return_ptrs.cpp" )); EXPECT(files_equal(path + "/tests/expected/@Test/print.m" , "actual/@Test/print.m" )); EXPECT(files_equal(path + "/tests/expected/@Test/print.cpp" , "actual/@Test/print.cpp" )); @@ -112,14 +113,6 @@ TEST( wrap, matlab_code ) { EXPECT(files_equal(path + "/tests/expected/make_geometry.m" , "actual/make_geometry.m" )); } -///* ************************************************************************* */ -//TEST( wrap, strip_comments ) { -// string full_string = "This is the first line // comments\n// comments at beginning of line\n"; -// string act_string = strip_comments(full_string); -// string exp_string = "This is the first line \n\n"; -// EXPECT(assert_equal(exp_string, act_string)); -//} - /* ************************************************************************* */ int main() { TestResult tr; return TestRegistry::runAllTests(tr); } /* ************************************************************************* */