testReturnValue with prototype grammar
parent
bba78e48e4
commit
58806b75d2
|
@ -2409,6 +2409,14 @@
|
||||||
<useDefaultCommand>true</useDefaultCommand>
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
<runAllBuilders>true</runAllBuilders>
|
<runAllBuilders>true</runAllBuilders>
|
||||||
</target>
|
</target>
|
||||||
|
<target name="testReturnValue.run" path="build/wrap/tests" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
|
<buildCommand>make</buildCommand>
|
||||||
|
<buildArguments>-j4</buildArguments>
|
||||||
|
<buildTarget>testReturnValue.run</buildTarget>
|
||||||
|
<stopOnError>true</stopOnError>
|
||||||
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
<runAllBuilders>true</runAllBuilders>
|
||||||
|
</target>
|
||||||
<target name="schedulingExample.run" path="build/gtsam_unstable/discrete/tests" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
<target name="schedulingExample.run" path="build/gtsam_unstable/discrete/tests" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
<buildCommand>make</buildCommand>
|
<buildCommand>make</buildCommand>
|
||||||
<buildArguments>-j5</buildArguments>
|
<buildArguments>-j5</buildArguments>
|
||||||
|
|
|
@ -124,8 +124,6 @@ struct ArgumentList: public std::vector<Argument> {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const bool T = true;
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
|
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
|
||||||
struct ArgumentGrammar: public classic::grammar<ArgumentGrammar> {
|
struct ArgumentGrammar: public classic::grammar<ArgumentGrammar> {
|
||||||
|
@ -175,7 +173,7 @@ 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 arg, arg0;
|
||||||
ArgumentGrammar argument_g;
|
ArgumentGrammar argument_g;
|
||||||
|
|
||||||
/// Construct type grammar and specify where result is placed
|
/// Construct type grammar and specify where result is placed
|
||||||
|
@ -192,17 +190,10 @@ struct ArgumentListGrammar: public classic::grammar<ArgumentListGrammar> {
|
||||||
Rule argument_p, argumentList_p;
|
Rule argument_p, argumentList_p;
|
||||||
|
|
||||||
definition(ArgumentListGrammar const& self) {
|
definition(ArgumentListGrammar const& self) {
|
||||||
|
|
||||||
using namespace wrap;
|
|
||||||
using namespace classic;
|
using namespace classic;
|
||||||
|
|
||||||
// NOTE: allows for pointers to all types
|
|
||||||
// Slightly more permissive than before on basis/eigen type qualification
|
|
||||||
argument_p = self.argument_g //
|
argument_p = self.argument_g //
|
||||||
[push_back_a(self.result_, self.arg)] //
|
[classic::push_back_a(self.result_, self.arg)] //
|
||||||
// [assign_a(self.arg, self.arg0)]
|
[assign_a(self.arg, self.arg0)];
|
||||||
;
|
|
||||||
|
|
||||||
argumentList_p = '(' >> !argument_p >> *(',' >> argument_p) >> ')';
|
argumentList_p = '(' >> !argument_p >> *(',' >> argument_p) >> ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ public:
|
||||||
return namespaces_.empty() && name_.empty();
|
return namespaces_.empty() && name_.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
virtual void clear() {
|
||||||
namespaces_.clear();
|
namespaces_.clear();
|
||||||
name_.clear();
|
name_.clear();
|
||||||
category = VOID;
|
category = VOID;
|
||||||
|
@ -231,5 +231,9 @@ public:
|
||||||
};
|
};
|
||||||
// type_grammar
|
// type_grammar
|
||||||
|
|
||||||
|
// Needed for other parsers in Argument.h and ReturnType.h
|
||||||
|
static const bool T = true;
|
||||||
|
|
||||||
|
|
||||||
}// \namespace wrap
|
}// \namespace wrap
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,19 @@ struct ReturnType: Qualified {
|
||||||
bool isPtr;
|
bool isPtr;
|
||||||
|
|
||||||
/// Makes a void type
|
/// Makes a void type
|
||||||
ReturnType() :
|
ReturnType(bool ptr = false) :
|
||||||
isPtr(false) {
|
isPtr(ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make a Class type, no namespaces
|
/// Constructor, no namespaces
|
||||||
ReturnType(const std::string& name) :
|
ReturnType(const std::string& name, Qualified::Category c = Qualified::CLASS,
|
||||||
Qualified(name,Qualified::CLASS), isPtr(false) {
|
bool ptr = false) :
|
||||||
|
Qualified(name, c), isPtr(ptr) {
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void clear() {
|
||||||
|
Qualified::clear();
|
||||||
|
isPtr = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if this type is in a set of valid types
|
/// Check if this type is in a set of valid types
|
||||||
|
|
|
@ -35,6 +35,22 @@ struct ReturnValue {
|
||||||
isPair(false), type1(type) {
|
isPair(false), type1(type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Constructor
|
||||||
|
ReturnValue(const ReturnType& t1, const ReturnType& t2) :
|
||||||
|
isPair(true), type1(t1), type2(t2) {
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void clear() {
|
||||||
|
type1.clear();
|
||||||
|
type2.clear();
|
||||||
|
isPair = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const ReturnValue& other) const {
|
||||||
|
return isPair == other.isPair && type1 == other.type1
|
||||||
|
&& type2 == other.type2;
|
||||||
|
}
|
||||||
|
|
||||||
/// Substitute template argument
|
/// Substitute template argument
|
||||||
ReturnValue expandTemplate(const TemplateSubstitution& ts) const;
|
ReturnValue expandTemplate(const TemplateSubstitution& ts) const;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||||
|
* Atlanta, Georgia 30332-0415
|
||||||
|
* All Rights Reserved
|
||||||
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
||||||
|
|
||||||
|
* See LICENSE for the license information
|
||||||
|
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file testReturnValue.cpp
|
||||||
|
* @brief Unit test for ReturnValue class & parser
|
||||||
|
* @author Frank Dellaert
|
||||||
|
* @date Nov 30, 2014
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <wrap/ReturnValue.h>
|
||||||
|
#include <CppUnitLite/TestHarness.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace wrap;
|
||||||
|
|
||||||
|
//******************************************************************************
|
||||||
|
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
|
||||||
|
struct ReturnValueGrammar: public classic::grammar<ReturnValueGrammar> {
|
||||||
|
|
||||||
|
wrap::ReturnValue& result_; ///< successful parse will be placed in here
|
||||||
|
|
||||||
|
TypeGrammar returnType1_g, returnType2_g;
|
||||||
|
|
||||||
|
/// Construct type grammar and specify where result is placed
|
||||||
|
ReturnValueGrammar(wrap::ReturnValue& result) :
|
||||||
|
result_(result), returnType1_g(result.type1), returnType2_g(result.type2) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Definition of type grammar
|
||||||
|
template<typename ScannerT>
|
||||||
|
struct definition: basic_rules<ScannerT> {
|
||||||
|
|
||||||
|
typedef classic::rule<ScannerT> Rule;
|
||||||
|
|
||||||
|
Rule pair_p, returnValue_p;
|
||||||
|
|
||||||
|
definition(ReturnValueGrammar const& self) {
|
||||||
|
|
||||||
|
using namespace wrap;
|
||||||
|
using namespace classic;
|
||||||
|
|
||||||
|
pair_p = (str_p("pair") >> '<' >> self.returnType1_g >> ','
|
||||||
|
>> self.returnType2_g >> '>')[assign_a(self.result_.isPair, T)];
|
||||||
|
|
||||||
|
returnValue_p = pair_p | self.returnType1_g;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule const& start() const {
|
||||||
|
return returnValue_p;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
// ReturnValueGrammar
|
||||||
|
|
||||||
|
//******************************************************************************
|
||||||
|
TEST( ReturnValue, grammar ) {
|
||||||
|
|
||||||
|
using classic::space_p;
|
||||||
|
|
||||||
|
// Create type grammar that will place result in actual
|
||||||
|
ReturnValue actual;
|
||||||
|
ReturnValueGrammar g(actual);
|
||||||
|
|
||||||
|
EXPECT(parse("VectorNotEigen", g, space_p).full);
|
||||||
|
EXPECT(actual==ReturnValue(ReturnType("VectorNotEigen",Qualified::CLASS)));
|
||||||
|
actual.clear();
|
||||||
|
|
||||||
|
EXPECT(parse("double", g, space_p).full);
|
||||||
|
EXPECT(actual==ReturnValue(ReturnType("double",Qualified::BASIS)));
|
||||||
|
actual.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//******************************************************************************
|
||||||
|
int main() {
|
||||||
|
TestResult tr;
|
||||||
|
return TestRegistry::runAllTests(tr);
|
||||||
|
}
|
||||||
|
//******************************************************************************
|
Loading…
Reference in New Issue