Moved to header
parent
60d7b80055
commit
a8de6c4dc3
|
@ -11,6 +11,18 @@
|
||||||
|
|
||||||
#include "FullyOverloadedFunction.h"
|
#include "FullyOverloadedFunction.h"
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
|
#endif
|
||||||
|
#include <boost/lambda/bind.hpp>
|
||||||
|
#include <boost/lambda/lambda.hpp>
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace bl = boost::lambda;
|
||||||
|
|
||||||
namespace wrap {
|
namespace wrap {
|
||||||
|
|
||||||
struct GlobalFunction: public FullyOverloadedFunction {
|
struct GlobalFunction: public FullyOverloadedFunction {
|
||||||
|
@ -49,5 +61,62 @@ private:
|
||||||
|
|
||||||
typedef std::map<std::string, GlobalFunction> GlobalFunctions;
|
typedef std::map<std::string, GlobalFunction> GlobalFunctions;
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
|
||||||
|
struct GlobalFunctionGrammar: public classic::grammar<GlobalFunctionGrammar> {
|
||||||
|
|
||||||
|
GlobalFunctions& global_functions_; ///< successful parse will be placed in here
|
||||||
|
|
||||||
|
/// Construct type grammar and specify where result is placed
|
||||||
|
GlobalFunctionGrammar(GlobalFunctions& global_functions) :
|
||||||
|
global_functions_(global_functions) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Definition of type grammar
|
||||||
|
template<typename ScannerT>
|
||||||
|
struct definition: BasicRules<ScannerT> {
|
||||||
|
|
||||||
|
// using BasicRules<ScannerT>::name_p;
|
||||||
|
// using BasicRules<ScannerT>::className_p;
|
||||||
|
using BasicRules<ScannerT>::comments_p;
|
||||||
|
|
||||||
|
ArgumentList args;
|
||||||
|
ArgumentListGrammar argumentList_g;
|
||||||
|
|
||||||
|
ReturnValue retVal0, retVal;
|
||||||
|
ReturnValueGrammar returnValue_g;
|
||||||
|
|
||||||
|
Qualified globalFunction;
|
||||||
|
|
||||||
|
classic::rule<ScannerT> globalFunctionName_p, global_function_p;
|
||||||
|
|
||||||
|
definition(GlobalFunctionGrammar const& self) :
|
||||||
|
argumentList_g(args), returnValue_g(retVal) {
|
||||||
|
|
||||||
|
using namespace classic;
|
||||||
|
bool verbose = false; // TODO
|
||||||
|
|
||||||
|
globalFunctionName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
||||||
|
|
||||||
|
// parse a global function
|
||||||
|
global_function_p = (returnValue_g
|
||||||
|
>> globalFunctionName_p[assign_a(globalFunction.name_)]
|
||||||
|
>> argumentList_g >> ';' >> *comments_p) //
|
||||||
|
[bl::bind(&GlobalFunction::addOverload,
|
||||||
|
bl::var(self.global_functions_)[bl::var(globalFunction.name_)],
|
||||||
|
bl::var(globalFunction), bl::var(args), bl::var(retVal),
|
||||||
|
boost::none, verbose)] //
|
||||||
|
[assign_a(retVal, retVal0)][clear_a(globalFunction)][clear_a(args)];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
classic::rule<ScannerT> const& start() const {
|
||||||
|
return global_function_p;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
// GlobalFunctionGrammar
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
||||||
|
|
|
@ -29,74 +29,6 @@ TEST( GlobalFunction, Constructor ) {
|
||||||
GlobalFunction f;
|
GlobalFunction f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
|
||||||
#endif
|
|
||||||
#include <boost/lambda/bind.hpp>
|
|
||||||
#include <boost/lambda/lambda.hpp>
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace bl = boost::lambda;
|
|
||||||
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
|
|
||||||
struct GlobalFunctionGrammar: public classic::grammar<GlobalFunctionGrammar> {
|
|
||||||
|
|
||||||
GlobalFunctions& global_functions_; ///< successful parse will be placed in here
|
|
||||||
|
|
||||||
/// Construct type grammar and specify where result is placed
|
|
||||||
GlobalFunctionGrammar(GlobalFunctions& global_functions) :
|
|
||||||
global_functions_(global_functions) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Definition of type grammar
|
|
||||||
template<typename ScannerT>
|
|
||||||
struct definition: BasicRules<ScannerT> {
|
|
||||||
|
|
||||||
// using BasicRules<ScannerT>::name_p;
|
|
||||||
// using BasicRules<ScannerT>::className_p;
|
|
||||||
using BasicRules<ScannerT>::comments_p;
|
|
||||||
|
|
||||||
ArgumentList args;
|
|
||||||
ArgumentListGrammar argumentList_g;
|
|
||||||
|
|
||||||
ReturnValue retVal0, retVal;
|
|
||||||
ReturnValueGrammar returnValue_g;
|
|
||||||
|
|
||||||
Qualified globalFunction;
|
|
||||||
|
|
||||||
classic::rule<ScannerT> globalFunctionName_p, global_function_p;
|
|
||||||
|
|
||||||
definition(GlobalFunctionGrammar const& self) :
|
|
||||||
argumentList_g(args), returnValue_g(retVal) {
|
|
||||||
|
|
||||||
using namespace classic;
|
|
||||||
bool verbose = false; // TODO
|
|
||||||
|
|
||||||
globalFunctionName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
|
||||||
|
|
||||||
// parse a global function
|
|
||||||
global_function_p = (returnValue_g
|
|
||||||
>> globalFunctionName_p[assign_a(globalFunction.name_)]
|
|
||||||
>> argumentList_g >> ';' >> *comments_p) //
|
|
||||||
[bl::bind(&GlobalFunction::addOverload,
|
|
||||||
bl::var(self.global_functions_)[bl::var(globalFunction.name_)],
|
|
||||||
bl::var(globalFunction), bl::var(args), bl::var(retVal),
|
|
||||||
boost::none, verbose)] //
|
|
||||||
[assign_a(retVal, retVal0)][clear_a(globalFunction)][clear_a(args)];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
classic::rule<ScannerT> const& start() const {
|
|
||||||
return global_function_p;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
};
|
|
||||||
// GlobalFunctionGrammar
|
|
||||||
|
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
TEST( GlobalFunction, Grammar ) {
|
TEST( GlobalFunction, Grammar ) {
|
||||||
|
|
||||||
|
@ -110,6 +42,7 @@ TEST( GlobalFunction, Grammar ) {
|
||||||
EXPECT(parse("Vector aGlobalFunction();", g, space_p).full);
|
EXPECT(parse("Vector aGlobalFunction();", g, space_p).full);
|
||||||
EXPECT(parse("Vector overloadedGlobalFunction(int a);", g, space_p).full);
|
EXPECT(parse("Vector overloadedGlobalFunction(int a);", g, space_p).full);
|
||||||
EXPECT(parse("Vector overloadedGlobalFunction(int a, double b);", g, space_p).full);
|
EXPECT(parse("Vector overloadedGlobalFunction(int a, double b);", g, space_p).full);
|
||||||
|
LONGS_EQUAL(2,actual.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue