Equality
parent
49f7f5c7fe
commit
b50f42a606
|
@ -28,13 +28,23 @@ namespace wrap {
|
||||||
/// Argument class
|
/// Argument class
|
||||||
struct Argument {
|
struct Argument {
|
||||||
Qualified type;
|
Qualified type;
|
||||||
bool is_const, is_ref, is_ptr;
|
|
||||||
std::string name;
|
std::string name;
|
||||||
|
bool is_const, is_ref, is_ptr;
|
||||||
|
|
||||||
Argument() :
|
Argument() :
|
||||||
is_const(false), is_ref(false), is_ptr(false) {
|
is_const(false), is_ref(false), is_ptr(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Argument(const Qualified& t, const std::string& n) :
|
||||||
|
type(t), name(n), is_const(false), is_ref(false), is_ptr(false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Argument& other) const {
|
||||||
|
return type == other.type && name == other.name
|
||||||
|
&& is_const == other.is_const && is_ref == other.is_ref
|
||||||
|
&& is_ptr == other.is_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
Argument expandTemplate(const TemplateSubstitution& ts) const;
|
Argument expandTemplate(const TemplateSubstitution& ts) const;
|
||||||
|
|
||||||
/// return MATLAB class for use in isa(x,class)
|
/// return MATLAB class for use in isa(x,class)
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <boost/spirit/include/classic_push_back_actor.hpp>
|
#include <boost/spirit/include/classic_push_back_actor.hpp>
|
||||||
#include <boost/spirit/include/classic_clear_actor.hpp>
|
#include <boost/spirit/include/classic_clear_actor.hpp>
|
||||||
#include <boost/spirit/include/classic_assign_actor.hpp>
|
#include <boost/spirit/include/classic_assign_actor.hpp>
|
||||||
|
#include <boost/spirit/include/classic_confix.hpp>
|
||||||
|
|
||||||
namespace classic = BOOST_SPIRIT_CLASSIC_NS;
|
namespace classic = BOOST_SPIRIT_CLASSIC_NS;
|
||||||
|
|
||||||
|
@ -44,8 +45,17 @@ struct Qualified {
|
||||||
} Category;
|
} Category;
|
||||||
Category category;
|
Category category;
|
||||||
|
|
||||||
Qualified(const std::string& name_ = "") :
|
Qualified() :
|
||||||
name(name_), category(CLASS) {
|
category(VOID) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Qualified(const std::string& name_, Category c = CLASS) :
|
||||||
|
name(name_), category(c) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Qualified& other) const {
|
||||||
|
return namespaces == other.namespaces && name == other.name
|
||||||
|
&& category == other.category;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const {
|
bool empty() const {
|
||||||
|
@ -91,13 +101,15 @@ struct basic_rules {
|
||||||
|
|
||||||
typedef classic::rule<ScannerT> Rule;
|
typedef classic::rule<ScannerT> Rule;
|
||||||
|
|
||||||
Rule basisType_p, eigenType_p, keywords_p, stlType_p, className_p,
|
Rule comments_p, basisType_p, eigenType_p, keywords_p, stlType_p, name_p,
|
||||||
namepsace_p;
|
className_p, namepsace_p;
|
||||||
|
|
||||||
basic_rules() {
|
basic_rules() {
|
||||||
|
|
||||||
using namespace classic;
|
using namespace classic;
|
||||||
|
|
||||||
|
comments_p = comment_p("/*", "*/") | comment_p("//", eol_p);
|
||||||
|
|
||||||
basisType_p = (str_p("string") | "bool" | "size_t" | "int" | "double"
|
basisType_p = (str_p("string") | "bool" | "size_t" | "int" | "double"
|
||||||
| "char" | "unsigned char");
|
| "char" | "unsigned char");
|
||||||
|
|
||||||
|
@ -108,6 +120,8 @@ struct basic_rules {
|
||||||
|
|
||||||
stlType_p = (str_p("vector") | "list");
|
stlType_p = (str_p("vector") | "list");
|
||||||
|
|
||||||
|
name_p = lexeme_d[alpha_p >> *(alnum_p | '_')];
|
||||||
|
|
||||||
className_p = (lexeme_d[upper_p >> *(alnum_p | '_')] - eigenType_p
|
className_p = (lexeme_d[upper_p >> *(alnum_p | '_')] - eigenType_p
|
||||||
- keywords_p) | stlType_p;
|
- keywords_p) | stlType_p;
|
||||||
|
|
||||||
|
@ -163,8 +177,7 @@ struct type_grammar: public classic::grammar<type_grammar> {
|
||||||
[assign_a(self.result_.name)] //
|
[assign_a(self.result_.name)] //
|
||||||
[assign_a(self.result_.category, CLASS)];
|
[assign_a(self.result_.category, CLASS)];
|
||||||
|
|
||||||
type_p = eps_p[clear_a(self.result_)] //
|
type_p = void_p | my_basisType_p | my_eigenType_p | class_p;
|
||||||
>> void_p | my_basisType_p | my_eigenType_p | class_p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rule const& start() const {
|
Rule const& start() const {
|
||||||
|
@ -175,5 +188,5 @@ struct type_grammar: public classic::grammar<type_grammar> {
|
||||||
};
|
};
|
||||||
// type_grammar
|
// type_grammar
|
||||||
|
|
||||||
} // \namespace wrap
|
}// \namespace wrap
|
||||||
|
|
||||||
|
|
|
@ -107,30 +107,15 @@ TEST( Argument, grammar ) {
|
||||||
actual = arg0;
|
actual = arg0;
|
||||||
|
|
||||||
EXPECT(parse("char a", g, space_p).full);
|
EXPECT(parse("char a", g, space_p).full);
|
||||||
EXPECT(actual.type.namespaces.empty());
|
EXPECT(actual==Argument(Qualified("char",Qualified::BASIS),"a"));
|
||||||
EXPECT(actual.type.name=="char");
|
|
||||||
EXPECT(actual.name=="a");
|
|
||||||
EXPECT(!actual.is_const);
|
|
||||||
EXPECT(!actual.is_ref);
|
|
||||||
EXPECT(!actual.is_ptr);
|
|
||||||
actual = arg0;
|
actual = arg0;
|
||||||
|
|
||||||
EXPECT(parse("unsigned char a", g, space_p).full);
|
EXPECT(parse("unsigned char a", g, space_p).full);
|
||||||
EXPECT(actual.type.namespaces.empty());
|
EXPECT(actual==Argument(Qualified("unsigned char",Qualified::BASIS),"a"));
|
||||||
EXPECT(actual.type.name=="unsigned char");
|
|
||||||
EXPECT(actual.name=="a");
|
|
||||||
EXPECT(!actual.is_const);
|
|
||||||
EXPECT(!actual.is_ref);
|
|
||||||
EXPECT(!actual.is_ptr);
|
|
||||||
actual = arg0;
|
actual = arg0;
|
||||||
|
|
||||||
EXPECT(parse("Vector v", g, space_p).full);
|
EXPECT(parse("Vector v", g, space_p).full);
|
||||||
EXPECT(actual.type.namespaces.empty());
|
EXPECT(actual==Argument(Qualified("Vector",Qualified::EIGEN),"v"));
|
||||||
EXPECT(actual.type.name=="Vector");
|
|
||||||
EXPECT(actual.name=="v");
|
|
||||||
EXPECT(!actual.is_const);
|
|
||||||
EXPECT(!actual.is_ref);
|
|
||||||
EXPECT(!actual.is_ptr);
|
|
||||||
actual = arg0;
|
actual = arg0;
|
||||||
|
|
||||||
EXPECT(parse("const Matrix& m", g, space_p).full);
|
EXPECT(parse("const Matrix& m", g, space_p).full);
|
||||||
|
@ -150,11 +135,11 @@ struct ArgumentListGrammar: public classic::grammar<ArgumentListGrammar> {
|
||||||
wrap::ArgumentList& result_; ///< successful parse will be placed in here
|
wrap::ArgumentList& result_; ///< successful parse will be placed in here
|
||||||
|
|
||||||
Argument arg0, arg;
|
Argument arg0, arg;
|
||||||
type_grammar argument_type_g;
|
ArgumentGrammar argument_g;
|
||||||
|
|
||||||
/// Construct type grammar and specify where result is placed
|
/// Construct type grammar and specify where result is placed
|
||||||
ArgumentListGrammar(wrap::ArgumentList& result) :
|
ArgumentListGrammar(wrap::ArgumentList& result) :
|
||||||
result_(result), argument_type_g(arg.type) {
|
result_(result), argument_g(arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Definition of type grammar
|
/// Definition of type grammar
|
||||||
|
@ -172,19 +157,10 @@ struct ArgumentListGrammar: public classic::grammar<ArgumentListGrammar> {
|
||||||
|
|
||||||
// NOTE: allows for pointers to all types
|
// NOTE: allows for pointers to all types
|
||||||
// Slightly more permissive than before on basis/eigen type qualification
|
// Slightly more permissive than before on basis/eigen type qualification
|
||||||
argument_p = //
|
argument_p = self.argument_g //
|
||||||
!str_p("const")
|
[push_back_a(self.result_, self.arg)] //
|
||||||
// [assign_a(self.arg.is_const, true)] //
|
// [assign_a(self.arg, self.arg0)]
|
||||||
>> self.argument_type_g //
|
;
|
||||||
>> (!ch_p('&')
|
|
||||||
// [assign_a(self.arg.is_ref, true)]
|
|
||||||
| !ch_p('*')
|
|
||||||
// [assign_a(self.arg.is_ptr, true)]
|
|
||||||
) >> basic_rules<ScannerT>::name_p
|
|
||||||
// [assign_a[self.arg.name)]
|
|
||||||
// [push_back_a(self.result_, self.arg)]
|
|
||||||
// [assign_a(self.arg, self.arg0)]
|
|
||||||
;
|
|
||||||
|
|
||||||
argumentList_p = '(' >> !argument_p >> *(',' >> argument_p) >> ')';
|
argumentList_p = '(' >> !argument_p >> *(',' >> argument_p) >> ')';
|
||||||
}
|
}
|
||||||
|
@ -206,7 +182,13 @@ TEST( ArgumentList, grammar ) {
|
||||||
ArgumentList actual;
|
ArgumentList actual;
|
||||||
ArgumentListGrammar g(actual);
|
ArgumentListGrammar g(actual);
|
||||||
|
|
||||||
|
EXPECT(parse("(const gtsam::Point2& p4)", g, space_p).full);
|
||||||
|
EXPECT_LONGS_EQUAL(1, actual.size());
|
||||||
|
actual.clear();
|
||||||
|
|
||||||
EXPECT(parse("()", g, space_p).full);
|
EXPECT(parse("()", g, space_p).full);
|
||||||
|
EXPECT_LONGS_EQUAL(0, actual.size());
|
||||||
|
actual.clear();
|
||||||
|
|
||||||
EXPECT(parse("(char a)", g, space_p).full);
|
EXPECT(parse("(char a)", g, space_p).full);
|
||||||
|
|
||||||
|
@ -219,8 +201,6 @@ TEST( ArgumentList, grammar ) {
|
||||||
EXPECT(parse("(Point2 p1, Point3 p2)", g, space_p).full);
|
EXPECT(parse("(Point2 p1, Point3 p2)", g, space_p).full);
|
||||||
|
|
||||||
EXPECT(parse("(gtsam::Point2 p3)", g, space_p).full);
|
EXPECT(parse("(gtsam::Point2 p3)", g, space_p).full);
|
||||||
|
|
||||||
EXPECT(parse("(const gtsam::Point2& p4)", g, space_p).full);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue