Overpass API regression suite coverage (Saxony) / overpass_api/statements/statement_dump.cc

overpass_api/statements/statement_dump.cc

189 of 275 instrumented lines run by the suite (68.7%) 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#include "../frontend/output.h"
20#include "statement_dump.h"
21#include "statement.h"
23#include <map>
24#include <string>
25#include <vector>
28Statement_Dump::~Statement_Dump()
2925815691 q{
3025815691 q for (std::vector< Statement_Dump* >::iterator it = substatements.begin();
3149557691 q it != substatements.end(); ++it)
3223742689 q delete *it;
3325815691 q}
36void Statement_Dump::add_statement(Statement_Dump* statement, std::string text)
3723742689 q{
3823742689 q substatements.push_back(statement);
3923742689 q}
42Statement* Statement_Dump::create_non_dump_stmt(Statement::Factory& stmt_factory)
4315828689 q{
4415828689 q if (non_dump_stmt)
453060603 q return non_dump_stmt;
4712768688 q non_dump_stmt = stmt_factory.create_statement(name_, line_number, attributes);
4912768688 q if (non_dump_stmt)
5012768688 q {
5117252688 q for (std::vector< Statement_Dump* >::const_iterator it = substatements.begin(); it != substatements.end(); ++it)
524484623 q {
534484623 q Statement* substmt = (*it)->create_non_dump_stmt(stmt_factory);
544484623 q if (substmt)
554484623 q non_dump_stmt->add_statement(substmt, "");
564484623 q }
5712768688 q }
5912768688 q return non_dump_stmt;
6015828689 q}
63std::string indent(const std::string& subresult)
647914689 q{
657914689 q std::string result;
677914689 q std::string::size_type pos = 0;
687914689 q std::string::size_type next = subresult.find('\n', pos);
6929867689 q while (next != std::string::npos)
7021953689 q {
7121953689 q result += " " + subresult.substr(pos, next-pos) + '\n';
7221953689 q pos = next + 1;
7321953689 q next = subresult.find('\n', pos);
7421953689 q }
757914689 q if (subresult.substr(pos) != "")
760 result += " " + subresult.substr(pos);
787914689 q return result;
797914689 q}
82std::string Statement_Dump::dump_xml() const
838605691 q{
848605691 q if (non_dump_stmt)
851530603 q return non_dump_stmt->dump_xml("");
877075691 q std::string result;
897075691 q if (substatements.empty())
905150687 q {
915150687 q result = std::string("<") + name_;
925150687 q for (std::map< std::string, std::string >::const_iterator it = attributes.begin();
9348472687 q it != attributes.end(); ++it)
9443322686 q result += std::string(" ") + it->first + "=\"" + escape_xml(it->second) + "\"";
955150687 q result += "/>\n";
965150687 q }
971925689 q else
981925689 q {
991925689 q result = std::string("<") + name_;
1001925689 q for (std::map< std::string, std::string >::const_iterator it = attributes.begin();
1014975689 q it != attributes.end(); ++it)
1023050662 q result += std::string(" ") + it->first + "=\"" + escape_xml(it->second) + "\"";
1031925689 q result += ">\n";
1051925689 q for (std::vector< Statement_Dump* >::const_iterator it = substatements.begin();
1069839689 q it != substatements.end(); ++it)
1077914689 q result += indent((*it)->dump_xml());
1091925689 q result += std::string("</") + name_ + ">\n";
1101925689 q }
1127075691 q return result;
116std::string Statement_Dump::dump_compact_map_ql(Statement::Factory& stmt_factory)
1186363691 q std::string result;
1196363691 q if (name_ == "osm-script")
121691691 q std::string output_val;
122691691 q std::string output_config;
123691691 q for (std::map< std::string, std::string >::const_iterator it = attributes.begin();
1241345691 q it != attributes.end(); ++it)
126654357 q if (it->first == "timeout")
1272828 q result += "[timeout:" + it->second + "]";
128626357 q else if (it->first == "element-limit")
12988 q result += "[maxsize:" + it->second + "]";
130618352 q else if (it->first == "output")
132129129 q if (stmt_factory.global_settings.get_output_handler())
133129129 q result += "[out:" + it->second + stmt_factory.global_settings.get_output_handler()->dump_config() + "]";
1340 else
1350 output_val = it->second;
137489352 q else if (it->first == "output-config")
138129129 q output_config = it->second;
139360297 q else if (it->first == "bbox")
1402323 q result += "[bbox:" + it->second + "]";
142691691 q if (output_val != "")
1430 result += "[out:" + output_val + output_config + "]";
145691691 q if (attributes.find("augmented") != attributes.end() &&
146691691 q attributes.find("augmented")->second == "deletions" &&
147691691 q attributes.find("from") != attributes.end())
1493333 q result += "[adiff:\"" + attributes.find("from")->second;
1503333 q if (attributes.find("date") != attributes.end())
1511212 q result += "\",\"" + attributes.find("date")->second;
1523333 q result += "\"]";
154658658 q else if (attributes.find("from") != attributes.end())
1564848 q result += "[diff:\"" + attributes.find("from")->second;
1574848 q if (attributes.find("date") != attributes.end())
1581111 q result += "\",\"" + attributes.find("date")->second;
1594848 q result += "\"]";
161610610 q else if (attributes.find("date") != attributes.end())
162200200 q result += "[date:\"" + attributes.find("date")->second + "\"]";
164691691 q if (!attributes.empty())
165357357 q result += ";";
166691691 q for (std::vector< Statement_Dump* >::const_iterator it = substatements.begin();
1676363691 q it != substatements.end(); ++it)
1685672689 q result += (*it)->dump_compact_map_ql(stmt_factory);
1705672689 q else
1715672689 q {
1725672689 q Statement* stmt = create_non_dump_stmt(stmt_factory);
1735672689 q if (stmt)
1745672689 q result += stmt->dump_compact_ql("");
1750 else
1760 result += "(" + name_ + ":)";
1775672689 q }
1796363691 q return result;
183std::string Statement_Dump::dump_bbox_map_ql(Statement::Factory& stmt_factory)
1840{
1850 std::string result;
1860 bool auto_timeout = true;
1870 if (name_ == "osm-script")
1880 {
1890 std::string output_val;
1900 std::string output_config;
1910 for (std::map< std::string, std::string >::const_iterator it = attributes.begin();
1920 it != attributes.end(); ++it)
1930 {
1940 if (it->first == "timeout")
1950 {
1960 result += "[timeout:" + it->second + "]";
1970 auto_timeout = false;
1980 }
1990 else if (it->first == "element-limit")
2000 result += "[maxsize:" + it->second + "]";
2010 else if (it->first == "output")
2020 {
2030 if (stmt_factory.global_settings.get_output_handler())
2040 result += "[out:" + it->second + stmt_factory.global_settings.get_output_handler()->dump_config() + "]";
2050 else
2060 output_val = it->second;
2070 }
2080 else if (it->first == "output-config")
2090 output_config = it->second;
2100 else if (it->first == "bbox")
2110 result += "[bbox:" + it->second + "]";
2120 }
2130 if (output_val != "")
2140 result += "[out:" + output_val + output_config + "]";
2160 if (attributes.find("augmented") != attributes.end() &&
2170 attributes.find("augmented")->second == "deletions" &&
2180 attributes.find("from") != attributes.end())
2190 {
2200 result += "[adiff:\"" + attributes.find("from")->second;
2210 if (attributes.find("date") != attributes.end())
2220 result += "\",\"" + attributes.find("date")->second;
2230 result += "\"]";
2240 }
2250 else if (attributes.find("from") != attributes.end())
2260 {
2270 result += "[diff:\"" + attributes.find("from")->second;
2280 if (attributes.find("date") != attributes.end())
2290 result += "\",\"" + attributes.find("date")->second;
2300 result += "\"]";
2310 }
2320 else if (attributes.find("date") != attributes.end())
2330 result += "[date:\"" + attributes.find("date")->second + "\"]";
2350 if (auto_timeout)
2360 result += "[timeout:1]";
2370 result += ";";
2380 for (std::vector< Statement_Dump* >::const_iterator it = substatements.begin();
2390 it != substatements.end(); ++it)
2400 result += (*it)->dump_bbox_map_ql(stmt_factory);
2410 }
2420 else
2430 {
2440 Statement* stmt = create_non_dump_stmt(stmt_factory);
2450 if (stmt)
2460 result += stmt->dump_compact_ql(
2470 name_ == "complete" || name_ == "difference" || name_ == "for" || name_ == "foreach"
2480 || name_ == "if" || name_ == "query" || name_ == "union" ? "(bbox)" : "");
2490 else
2500 result += "(" + name_ + ":)";
2510 }
2530 return result;
2540}
257std::string Statement_Dump::dump_pretty_map_ql(Statement::Factory& stmt_factory)
2596363691 q std::string result;
2606363691 q if (name_ == "osm-script")
262691691 q std::string output_val;
263691691 q std::string output_config;
264691691 q for (std::map< std::string, std::string >::const_iterator it = attributes.begin();
2651345691 q it != attributes.end(); ++it)
267654357 q if (it->first == "timeout")
2682828 q result += "[timeout:" + it->second + "]\n";
269626357 q else if (it->first == "element-limit")
27088 q result += "[maxsize:" + it->second + "]\n";
271618352 q else if (it->first == "output")
273129129 q if (stmt_factory.global_settings.get_output_handler())
274129129 q result += "[out:" + it->second + stmt_factory.global_settings.get_output_handler()->dump_config() + "]\n";
2750 else
2760 output_val = it->second;
278489352 q else if (it->first == "output-config")
279129129 q output_config = it->second;
280360297 q else if (it->first == "bbox")
2812323 q result += "[bbox:" + it->second + "]\n";
283691691 q if (output_val != "")
2840 result += "[out:" + output_val + output_config + "]\n";
286691691 q if (attributes.find("augmented") != attributes.end() &&
287691691 q attributes.find("augmented")->second == "deletions" &&
288691691 q attributes.find("from") != attributes.end())
2903333 q result += "[adiff:\"" + attributes.find("from")->second;
2913333 q if (attributes.find("date") != attributes.end())
2921212 q result += "\",\"" + attributes.find("date")->second;
2933333 q result += "\"]\n";
295658658 q else if (attributes.find("from") != attributes.end())
2974848 q result += "[diff:\"" + attributes.find("from")->second;
2984848 q if (attributes.find("date") != attributes.end())
2991111 q result += "\",\"" + attributes.find("date")->second;
3004848 q result += "\"]\n";
302610610 q else if (attributes.find("date") != attributes.end())
303200200 q result += "[date:\"" + attributes.find("date")->second + "\"]\n";
305691691 q if (result != "")
306357357 q result += ";\n";
307691691 q for (std::vector< Statement_Dump* >::const_iterator it = substatements.begin();
3086363691 q it != substatements.end(); ++it)
3095672689 q result += (*it)->dump_pretty_map_ql(stmt_factory) + "\n";
3115672689 q else
3125672689 q {
3135672689 q Statement* stmt = create_non_dump_stmt(stmt_factory);
3145672689 q if (stmt)
3155672689 q result += stmt->dump_pretty_ql("");
3160 else
3170 result += "(" + name_ + ":)";
3185672689 q }
3206363691 q return result;
324Statement_Dump* Statement_Dump::Factory::create_statement
325 (std::string element, int line_number, const std::map< std::string, std::string >& attributes)
32621228692 q{
32721228692 q return new Statement_Dump(element, attributes, line_number);
32821228692 q}
331Statement_Dump* Statement_Dump::Factory::create_evaluator(
332 const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,
333 const Statement::Return_Type_Checker& eval_type)
3351875170 q Statement* stmt = stmt_factory->create_evaluator(tree_it, tree_context, eval_type);
3361875170 q if (stmt)
3371863170 q return new Statement_Dump("universal_dump", std::map< std::string, std::string >(), tree_it->line_col.first, stmt);
339123 q return 0;
343Statement_Dump* Statement_Dump::Factory::create_criterion(const Token_Node_Ptr& tree_it,
344 const std::string& type, bool& can_standalone, const std::string& into)
3462736570 q Statement* stmt = stmt_factory->create_criterion(tree_it, type, can_standalone, into);
3472736570 q if (stmt)
3482727567 q return new Statement_Dump("universal_dump", std::map< std::string, std::string >(), tree_it->line_col.first, stmt);
35093 q return 0;
354std::string Statement_Dump::attribute(const std::string& key) const
3550{
3560 std::map< std::string, std::string >::const_iterator it = attributes.find(key);
3570 if (it == attributes.end())
3580 return "";
3590 else
3600 return it->second;
3610}