mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-09-24 10:48:17 +00:00
implement unary - + operators
This commit is contained in:
parent
041b24b601
commit
7bf795588e
|
@ -263,6 +263,18 @@ struct arith_visitor : boost::static_visitor<datum> {
|
|||
from_string_converter<T>::convert(a),
|
||||
from_string_converter<U>::convert(b));
|
||||
}
|
||||
|
||||
/*
|
||||
* Unary version.
|
||||
*/
|
||||
template<typename T>
|
||||
datum operator() (T const &a) const {
|
||||
typedef typename from_string_converter<T>::type a_type;
|
||||
|
||||
Operator<typename preferred_type<a_type, a_type>::type> op;
|
||||
return op(from_string_converter<T>::convert(a));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -369,6 +381,18 @@ datum::operator%=(datum const &other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
datum
|
||||
datum::operator+() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
datum
|
||||
datum::operator-() const
|
||||
{
|
||||
return boost::apply_visitor(arith_visitor<std::negate>(), value_);
|
||||
}
|
||||
|
||||
datum
|
||||
operator+(datum const &a, datum const &b) {
|
||||
return datum(a) += b;
|
||||
|
|
|
@ -84,6 +84,8 @@ public:
|
|||
datum &operator/=(datum const &other);
|
||||
datum &operator%=(datum const &other);
|
||||
bool operator!() const;
|
||||
datum operator+() const;
|
||||
datum operator-() const;
|
||||
|
||||
bool compare(datum const &other) const;
|
||||
bool compare_with_type(datum const &other) const;
|
||||
|
|
|
@ -293,6 +293,8 @@ struct parser_grammar : public grammar<parser_grammar, parser_closure::context_t
|
|||
basic =
|
||||
( '(' >> tern_expr[basic.val = arg1] >> ')' )
|
||||
| ch_p('!') >> tern_expr[basic.val = !arg1]
|
||||
| ch_p('+') >> tern_expr[basic.val = arg1]
|
||||
| ch_p('-') >> tern_expr[basic.val = -arg1]
|
||||
| variable[basic.val = arg1]
|
||||
| function[basic.val = arg1]
|
||||
| value[basic.val = arg1]
|
||||
|
|
Loading…
Reference in a new issue