Overpass API regression suite coverage (Saxony) / overpass_api/statements/unary_operators.h

overpass_api/statements/unary_operators.h

24 of 26 instrumented lines run by the suite (92.3%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#ifndef DE__OSM3S___OVERPASS_API__STATEMENTS__UNARY_OPERATORS_H
20#define DE__OSM3S___OVERPASS_API__STATEMENTS__UNARY_OPERATORS_H
23#include "../data/tag_store.h"
24#include "../data/utils.h"
25#include "evaluator.h"
26#include "statement.h"
27#include "unary_functions.h"
29#include <map>
30#include <string>
31#include <vector>
34/* === Unary Operators ===
36Unary operators need for execution an operand.
37They are always written in prefix notation.
38The operators can be grouped with parentheses:
39The two variants
41 <Operator><Evaluator>
43and
45 (<Operator><Evaluator>)
47have as standalone expressions precisely the same semantics.
48The parenthesis variant exists to override operator precedence.
50The order of precedence is as follows, ordered weak to strong binding:
51* logical disjunction
52* logical conjunction
53* equality, inequality
54* less, less-equal, greater, greater-equal
55* plus, binary minus
56* times, divided
57* logical negation
58* unary minus
60In the following, the operators are ordered by precedence, stronger binding last.
61*/
63class Evaluator_Prefix_Operator : public Evaluator_Unary_Function
65public:
66 Evaluator_Prefix_Operator(int line_number_);
6828851 q static bool applicable_by_subtree_structure(const Token_Node_Ptr& tree_it) { return !tree_it->lhs && tree_it->rhs; }
69 static void add_substatements(Statement* result, const std::string& operator_name, const Token_Node_Ptr& tree_it,
70 Statement::QL_Context tree_context, Statement::Factory& stmt_factory, Error_Output* error_output);
71};
74template< typename Evaluator_ >
75struct Evaluator_Prefix_Operator_Syntax : public Evaluator_Prefix_Operator
77 Evaluator_Prefix_Operator_Syntax(int line_number_, const std::map< std::string, std::string >& input_attributes)
7823642 q : Evaluator_Prefix_Operator(line_number_)
7923642 q {
8023642 q std::map< std::string, std::string > attributes;
8123642 q eval_attributes_array(Evaluator_::stmt_name(), attributes, input_attributes);
8223642 q }
84 virtual std::string dump_xml(const std::string& indent) const
855942 q {
865942 q return indent + "<" + Evaluator_::stmt_name() + ">\n"
875942 q + (rhs ? rhs->dump_xml(indent + " ") : "")
885942 q + indent + "</" + Evaluator_::stmt_name() + ">\n";
895942 q }
91 virtual std::string dump_compact_ql(const std::string&) const
9211842 q {
9311842 q if (!rhs)
940 return Evaluator_::stmt_operator();
9511842 q if (rhs->get_operator_priority() < get_operator_priority())
962210 q return Evaluator_::stmt_operator() + "(" + rhs->dump_compact_ql("") + ")";
979637 q return Evaluator_::stmt_operator() + rhs->dump_compact_ql("");
9811842 q }
1000 virtual std::string get_name() const { return Evaluator_::stmt_name(); }
10117642 q virtual int get_operator_priority() const { return operator_priority(Evaluator_::stmt_operator(), true); }
102};
105/* ==== Boolean Negation ====
107The boolean negation evaluates to "1" if its argument evaluates to a representation of boolean false.
108Otherwise it evaluates to "1".
109Representations of boolean false are the empty std::string and every std::string that is a numerical representation of zero.
110Every other std::string represents boolean true.
112Its syntax is
114 ! <Evaluator>
116The whitespace is optional.
117*/
119class Evaluator_Not : public Evaluator_Prefix_Operator_Syntax< Evaluator_Not >
121public:
122 static Operator_Stmt_Maker< Evaluator_Not > statement_maker;
123 static Operator_Eval_Maker< Evaluator_Not > evaluator_maker;
1243008692 q static std::string stmt_operator() { return "!"; }
1252924692 q static std::string stmt_name() { return "eval-not"; }
127 Evaluator_Not(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
12810419 q : Evaluator_Prefix_Operator_Syntax< Evaluator_Not >(line_number_, input_attributes) {}
130 virtual std::string process(const std::string& rhs_result) const;
131};
134/* ==== Unary Minus ====
136The unary minus operator negates its argument.
137If the argument is an integer or a floating point number then it is negated as integer resp. floating point number.
138Otherwise the unary minus operator returns "NaN".
140The syntax for unary minus is:
142 - <Evaluator>
144The whitespace is optional.
145*/
147class Evaluator_Negate : public Evaluator_Prefix_Operator_Syntax< Evaluator_Negate >
149public:
150 static Operator_Stmt_Maker< Evaluator_Negate > statement_maker;
151 static Operator_Eval_Maker< Evaluator_Negate > evaluator_maker;
1523058692 q static std::string stmt_operator() { return "-"; }
1532966692 q static std::string stmt_name() { return "eval-negate"; }
155 Evaluator_Negate(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
15613228 q : Evaluator_Prefix_Operator_Syntax< Evaluator_Negate >(line_number_, input_attributes) {}
158 virtual std::string process(const std::string& rhs_result) const;
159};
162#endif