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