Commit f21bdee9646b17f3c48f149696e7a6045a3981bc

Authored by Benjamin Renard
2 parents de7354f6 a0761bde

Merge branch 'master' of https://gitlab.irap.omp.eu/CDPP/AMDA_Kernel

src/expressionParser/ExpressionContainer.hh
  1 +#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
  2 +#define BOOST_MPL_LIMIT_LIST_SIZE 30
  3 +#include <boost/mpl/list.hpp>
  4 +
1 5 #ifndef EXPRESSIONCONTAINER_HH_
2 6 #define EXPRESSIONCONTAINER_HH_
3 7  
... ... @@ -22,6 +26,9 @@ struct op_powerTen{};
22 26 struct op_plusSign {};
23 27 struct op_minusSign {};
24 28 struct op_const {};
  29 +struct fun_three{};
  30 +struct fun_two{};
  31 +struct fun_one{};
25 32  
26 33 namespace Expression{
27 34  
... ... @@ -30,6 +37,8 @@ template &lt;typename tag&gt; struct binop;
30 37 template <typename tag> struct unop;
31 38 template <typename tag> struct comop;
32 39 template <typename tag> struct funcop;
  40 +template <typename tag> struct triop;
  41 +template <typename tag> struct forop;
33 42  
34 43 typedef boost::variant<var,
35 44 boost::recursive_wrapper<unop <op_not> >,
... ... @@ -49,7 +58,10 @@ typedef boost::variant&lt;var,
49 58 boost::recursive_wrapper<binop<op_powerTen> >,
50 59 boost::recursive_wrapper<unop<op_minusSign> >,
51 60 boost::recursive_wrapper<unop<op_plusSign> >,
52   - boost::recursive_wrapper<unop<op_const> >
  61 + boost::recursive_wrapper<unop<op_const> >,
  62 + boost::recursive_wrapper<binop<fun_one> >,
  63 + boost::recursive_wrapper<triop<fun_two> >,
  64 + boost::recursive_wrapper<forop<fun_three> >
53 65 > ExpressionContainer;
54 66  
55 67  
... ... @@ -76,6 +88,25 @@ template &lt;typename tag&gt; struct unop
76 88 explicit unop(const ExpressionContainer& o) : oper1(o) { }
77 89 ExpressionContainer oper1;
78 90 };
  91 +template <typename tag> struct triop
  92 +{
  93 + explicit triop(const ExpressionContainer& functionId,
  94 + const ExpressionContainer& l
  95 + , const ExpressionContainer& r)
  96 + : oper1(functionId), oper2(l), oper3(r) { }
  97 +ExpressionContainer oper1, oper2, oper3;
  98 +};
  99 +
  100 +template <typename tag> struct forop
  101 +{
  102 + explicit forop(const ExpressionContainer& functionId,
  103 + const ExpressionContainer& l,
  104 + const ExpressionContainer& m,
  105 + const ExpressionContainer& r)
  106 + : oper1(functionId), oper2(l), oper3(m),oper4(r) { }
  107 +ExpressionContainer oper1, oper2, oper3,oper4;
  108 +};
  109 +
79 110  
80 111 } /* namespace Expression */
81 112  
... ...
src/expressionParser/ExpressionParser.cc
... ... @@ -5,6 +5,11 @@
5 5 * Author: akka
6 6 */
7 7  
  8 +#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
  9 +#define BOOST_MPL_LIMIT_LIST_SIZE 30
  10 +#include <boost/mpl/list.hpp>
  11 +
  12 +
8 13 #include <sstream>
9 14  
10 15 #include "ParserLogger.hh"
... ...
src/expressionParser/ExpressionPrinter.hh
... ... @@ -44,6 +44,11 @@ public:
44 44 // Constants
45 45 void operator()(const unop<op_const>& u) const{printUnique("",u.oper1);}
46 46  
  47 + // Functions
  48 + void operator()(const forop<fun_three>& b) const { printFunctionThree(b.oper1, b.oper2, b.oper3, b.oper4); }
  49 + void operator()(const triop<fun_two>& b) const { printFunctionTwo(b.oper1, b.oper2, b.oper3); }
  50 + void operator()(const binop<fun_one>& b) const { printFunctionOne(b.oper1, b.oper2); }
  51 +
47 52 // printer
48 53 void print(const std::string& op, const ExpressionContainer& l, const ExpressionContainer& r) const
49 54 {
... ... @@ -75,6 +80,37 @@ public:
75 80 boost::apply_visitor(*this, r);
76 81 _os << ")";
77 82 }
  83 +
  84 + void printFunctionThree(const ExpressionContainer& functionId, const ExpressionContainer& l, const ExpressionContainer& m, const ExpressionContainer& r) const
  85 + {
  86 + boost::apply_visitor(*this, functionId);
  87 + _os << "(";
  88 + boost::apply_visitor(*this, l);
  89 + _os << ',';
  90 + boost::apply_visitor(*this, m);
  91 + _os << ',';
  92 + boost::apply_visitor(*this, r);
  93 + _os << ")";
  94 + }
  95 +
  96 + void printFunctionTwo(const ExpressionContainer& functionId, const ExpressionContainer& l, const ExpressionContainer& r) const
  97 + {
  98 + boost::apply_visitor(*this, functionId);
  99 + _os << "(";
  100 + boost::apply_visitor(*this, l);
  101 + _os << ',';
  102 + boost::apply_visitor(*this, r);
  103 + _os << ")";
  104 + }
  105 +
  106 + void printFunctionOne(const ExpressionContainer& functionId, const ExpressionContainer& l) const
  107 + {
  108 + boost::apply_visitor(*this, functionId);
  109 + _os << "(";
  110 + boost::apply_visitor(*this, l);
  111 + _os << ")";
  112 + }
  113 +
78 114 };
79 115  
80 116 std::ostream& operator<<(std::ostream& os, const ExpressionContainer& e)
... ...
src/expressionParser/ParserGrammar.hh
  1 +#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
  2 +#define BOOST_MPL_LIMIT_LIST_SIZE 30
  3 +#include <boost/mpl/list.hpp>
  4 +
1 5 #ifndef PARSERGRAMMAR_HH_
2 6 #define PARSERGRAMMAR_HH_
3 7  
... ... @@ -8,6 +12,7 @@
8 12 #include "CustomFoldDirective.hh"
9 13 #include "ParserToolbox.hh"
10 14 #include "Properties.hh"
  15 +#include "FunctionInfo.hh"
11 16  
12 17 namespace AMDA {
13 18 namespace parser {
... ... @@ -46,8 +51,11 @@ public:
46 51 pow_ = fold<funcop<op_power> >(greater_.alias())[powOperator_ >> greater_];
47 52  
48 53 greater_= fold<comop<op_greater> >(lower_.alias())[greaterOperator_ >> lower_];
49   - lower_ = fold<comop<op_lower> >( not_.alias())[lowerOperator_ >> not_];
  54 + lower_ = fold<comop<op_lower> >( functions_.alias())[lowerOperator_ >> functions_];
50 55  
  56 + functions_ = (threeArgsFunction>>"(">>funArgs_>>componentOperator_>>funArgs_>>componentOperator_>>funArgs_>>")")[_val= boost::phoenix::construct<Expression::forop <fun_three>>(_1,_2,_3,_4)] ||
  57 + (twoArgsFunction>>"(">>funArgs_>>componentOperator_>>funArgs_>>")")[_val= boost::phoenix::construct<Expression::triop <fun_two>>(_1,_2,_3)]||
  58 + (oneArgsFunction>>"(">>funArgs_>>")")[_val= boost::phoenix::construct<Expression::binop <fun_one>>(_1,_2)]|not_[_val=_1];
51 59 // UNARY OPERATIONS
52 60 not_ = (notOperator_ > const_) [_val = boost::phoenix::construct<Expression::unop <op_not>>(_1)] | const_[_val = _1];
53 61  
... ... @@ -55,7 +63,7 @@ public:
55 63 param_= (definedParams >>('(' >> (spectArgs_|vectorArgs_)>>')'))[_val='$'+_1+"["+qi::_2+"]"] ||
56 64 definedParams[_val='$'+_1]| simple[_val = _1];
57 65  
58   -
  66 + funArgs_=((expr_ |var_) |functions_);
59 67 simple = (('(' > expr_ > ')') | var_);
60 68 var_ = (+qi::char_('0','9') >> -qi::char_('.') >> -(+qi::char_('0','9'))) | ((qi::char_('.') >> +qi::char_('0','9')));
61 69 vectorArgs_%=qi::raw[qi::int_ > -(qi::char_(',')>>qi::int_) ];
... ... @@ -74,6 +82,7 @@ public:
74 82 greaterOrEqualOperator_ = qi::string(">=");
75 83 lowerOrEqualOperator_ = qi::string("<=");
76 84 lowerOperator_ = qi::char_("<");
  85 + componentOperator_ = qi::char_(",");
77 86  
78 87 // Define available constants
79 88 std::map<std::string, std::string> existingConstants = ParserToolbox::getConstants(lProperties);
... ... @@ -86,10 +95,23 @@ public:
86 95 for(std::vector<std::string>::iterator it = existingParams.begin(); it != existingParams.end(); ++it) {
87 96 definedParams.add(*it,*it);
88 97 }
  98 +
  99 + // Defined functions available
  100 + std::map<std::string,FunctionInfo> existingFunctions = ParserToolbox::getFunctions(lProperties);
  101 + for(auto const& x : existingFunctions ) {
  102 + if (x.second.getNbArgs()==1) {
  103 + oneArgsFunction.add(x.second.getIHMName(), x.second.getKernelName());
  104 + }else if (x.second.getNbArgs()==2) {
  105 + twoArgsFunction.add(x.second.getIHMName(), x.second.getKernelName());
  106 + }else {
  107 + threeArgsFunction.add(x.second.getIHMName(), x.second.getKernelName());
  108 + }
  109 + }
  110 +
89 111  
90 112 BOOST_SPIRIT_DEBUG_NODES((expr_)(or_)(and_)(equal_)(unequal_)(greaterOrEqual_)(lowerOrEqual_)(lower_)(sum_)
91 113 (difference_)(factor_)(division_)(simple)(notOperator_)(andOperator_)(orOperator_)(equalOperator_)(unequalOperator_)
92   - (sumOperator_)(differenceOperator_)(factorOperator_)(divisionOperator_)(greater_)(lower_));
  114 + (sumOperator_)(differenceOperator_)(factorOperator_)(divisionOperator_)(greater_)(lower_)(functions_));
93 115 }
94 116  
95 117 private:
... ... @@ -113,7 +135,9 @@ private:
113 135 ,lowerOrEqual_
114 136 ,lower_
115 137 ,const_
116   - ,param_;
  138 + ,param_
  139 + ,functions_
  140 + ,funArgs_;
117 141  
118 142  
119 143 qi::rule<It, Skipper> notOperator_
... ... @@ -129,11 +153,14 @@ private:
129 153 , greaterOperator_
130 154 , greaterOrEqualOperator_
131 155 ,lowerOrEqualOperator_
  156 + ,componentOperator_
132 157 ,lowerOperator_ ;
133 158  
134 159 qi::symbols<char, std::string> definedConstants;
135   -
136 160 qi::symbols<char, std::string> definedParams;
  161 + qi::symbols<char, std::string> twoArgsFunction;
  162 + qi::symbols<char, std::string> oneArgsFunction;
  163 + qi::symbols<char, std::string> threeArgsFunction;
137 164 };
138 165  
139 166 }
... ...