Overpass API regression suite coverage (Nova Scotia) / 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()
2922833611 q{
3022833611 q for (std::vector< Statement_Dump* >::iterator it = substatements.begin();
3143833611 q it != substatements.end(); ++it)
3221000608 q delete *it;
3322833611 q}
36void Statement_Dump::add_statement(Statement_Dump* statement, std::string text)
3721000608 q{
3821000608 q substatements.push_back(statement);
3921000608 q}
42Statement* Statement_Dump::create_non_dump_stmt(Statement::Factory& stmt_factory)
4314000608 q{
4414000608 q if (non_dump_stmt)
452622530 q return non_dump_stmt;
4711378607 q non_dump_stmt = stmt_factory.create_statement(name_, line_number, attributes);
4911378607 q if (non_dump_stmt)
5011378607 q {
5115226607 q for (std::vector< Statement_Dump* >::const_iterator it = substatements.begin(); it != substatements.end(); ++it)
523848558 q {
533848558 q Statement* substmt = (*it)->create_non_dump_stmt(stmt_factory);
543848558 q if (substmt)
553848558 q non_dump_stmt->add_statement(substmt, "");
563848558 q }
5711378607 q }
5911378607 q return non_dump_stmt;
6014000608 q}
63std::string indent(const std::string& subresult)
647000608 q{
657000608 q std::string result;
677000608 q std::string::size_type pos = 0;
687000608 q std::string::size_type next = subresult.find('\n', pos);
6926862608 q while (next != std::string::npos)
7019862608 q {
7119862608 q result += " " + subresult.substr(pos, next-pos) + '\n';
7219862608 q pos = next + 1;
7319862608 q next = subresult.find('\n', pos);
7419862608 q }
757000608 q if (subresult.substr(pos) != "")
760 result += " " + subresult.substr(pos);
787000608 q return result;
797000608 q}
82std::string Statement_Dump::dump_xml() const
837611611 q{
847611611 q if (non_dump_stmt)
851311530 q return non_dump_stmt->dump_xml("");
876300611 q std::string result;
896300611 q if (substatements.empty())
904599605 q {
914599605 q result = std::string("<") + name_;
924599605 q for (std::map< std::string, std::string >::const_iterator it = attributes.begin();
9343286605 q it != attributes.end(); ++it)
9438687604 q result += std::string(" ") + it->first + "=\"" + escape_xml(it->second) + "\"";
954599605 q result += "/>\n";
964599605 q }
971701608 q else
981701608 q {
991701608 q result = std::string("<") + name_;
1001701608 q for (std::map< std::string, std::string >::const_iterator it = attributes.begin();
1014395608 q it != attributes.end(); ++it)
1022694583 q result += std::string(" ") + it->first + "=\"" + escape_xml(it->second) + "\"";
1031701608 q result += ">\n";
1051701608 q for (std::vector< Statement_Dump* >::const_iterator it = substatements.begin();
1068701608 q it != substatements.end(); ++it)
1077000608 q result += indent((*it)->dump_xml());
1091701608 q result += std::string("</") + name_ + ">\n";
1101701608 q }
1126300611 q return result;
116std::string Statement_Dump::dump_compact_map_ql(Statement::Factory& stmt_factory)
1185687611 q std::string result;
1195687611 q if (name_ == "osm-script")
121611611 q std::string output_val;
122611611 q std::string output_config;
123611611 q for (std::map< std::string, std::string >::const_iterator it = attributes.begin();
1241173611 q it != attributes.end(); ++it)
126562316 q if (it->first == "timeout")
1271010 q result += "[timeout:" + it->second + "]";
128552316 q else if (it->first == "element-limit")
12999 q result += "[maxsize:" + it->second + "]";
130543311 q else if (it->first == "output")
132112112 q if (stmt_factory.global_settings.get_output_handler())
133112112 q result += "[out:" + it->second + stmt_factory.global_settings.get_output_handler()->dump_config() + "]";
1340 else
1350 output_val = it->second;
137431311 q else if (it->first == "output-config")
138112112 q output_config = it->second;
139319259 q else if (it->first == "bbox")
1402020 q result += "[bbox:" + it->second + "]";
142611611 q if (output_val != "")
1430 result += "[out:" + output_val + output_config + "]";
145611611 q if (attributes.find("augmented") != attributes.end() &&
146611611 q attributes.find("augmented")->second == "deletions" &&
147611611 q attributes.find("from") != attributes.end())
1493232 q result += "[adiff:\"" + attributes.find("from")->second;
1503232 q if (attributes.find("date") != attributes.end())
1511616 q result += "\",\"" + attributes.find("date")->second;
1523232 q result += "\"]";
154579579 q else if (attributes.find("from") != attributes.end())
1564444 q result += "[diff:\"" + attributes.find("from")->second;
1574444 q if (attributes.find("date") != attributes.end())
15844 q result += "\",\"" + attributes.find("date")->second;
1594444 q result += "\"]";
161535535 q else if (attributes.find("date") != attributes.end())
162171171 q result += "[date:\"" + attributes.find("date")->second + "\"]";
164611611 q if (!attributes.empty())
165316316 q result += ";";
166611611 q for (std::vector< Statement_Dump* >::const_iterator it = substatements.begin();
1675687611 q it != substatements.end(); ++it)
1685076608 q result += (*it)->dump_compact_map_ql(stmt_factory);
1705076608 q else
1715076608 q {
1725076608 q Statement* stmt = create_non_dump_stmt(stmt_factory);
1735076608 q if (stmt)
1745076608 q result += stmt->dump_compact_ql("");
1750 else
1760 result += "(" + name_ + ":)";
1775076608 q }
1795687611 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)
2595687611 q std::string result;
2605687611 q if (name_ == "osm-script")
262611611 q std::string output_val;
263611611 q std::string output_config;
264611611 q for (std::map< std::string, std::string >::const_iterator it = attributes.begin();
2651173611 q it != attributes.end(); ++it)
267562316 q if (it->first == "timeout")
2681010 q result += "[timeout:" + it->second + "]\n";
269552316 q else if (it->first == "element-limit")
27099 q result += "[maxsize:" + it->second + "]\n";
271543311 q else if (it->first == "output")
273112112 q if (stmt_factory.global_settings.get_output_handler())
274112112 q result += "[out:" + it->second + stmt_factory.global_settings.get_output_handler()->dump_config() + "]\n";
2750 else
2760 output_val = it->second;
278431311 q else if (it->first == "output-config")
279112112 q output_config = it->second;
280319259 q else if (it->first == "bbox")
2812020 q result += "[bbox:" + it->second + "]\n";
283611611 q if (output_val != "")
2840 result += "[out:" + output_val + output_config + "]\n";
286611611 q if (attributes.find("augmented") != attributes.end() &&
287611611 q attributes.find("augmented")->second == "deletions" &&
288611611 q attributes.find("from") != attributes.end())
2903232 q result += "[adiff:\"" + attributes.find("from")->second;
2913232 q if (attributes.find("date") != attributes.end())
2921616 q result += "\",\"" + attributes.find("date")->second;
2933232 q result += "\"]\n";
295579579 q else if (attributes.find("from") != attributes.end())
2974444 q result += "[diff:\"" + attributes.find("from")->second;
2984444 q if (attributes.find("date") != attributes.end())
29944 q result += "\",\"" + attributes.find("date")->second;
3004444 q result += "\"]\n";
302535535 q else if (attributes.find("date") != attributes.end())
303171171 q result += "[date:\"" + attributes.find("date")->second + "\"]\n";
305611611 q if (result != "")
306316316 q result += ";\n";
307611611 q for (std::vector< Statement_Dump* >::const_iterator it = substatements.begin();
3085687611 q it != substatements.end(); ++it)
3095076608 q result += (*it)->dump_pretty_map_ql(stmt_factory) + "\n";
3115076608 q else
3125076608 q {
3135076608 q Statement* stmt = create_non_dump_stmt(stmt_factory);
3145076608 q if (stmt)
3155076608 q result += stmt->dump_pretty_ql("");
3160 else
3170 result += "(" + name_ + ":)";
3185076608 q }
3205687611 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)
32618903612 q{
32718903612 q return new Statement_Dump(element, attributes, line_number);
32818903612 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)
3351644158 q Statement* stmt = stmt_factory->create_evaluator(tree_it, tree_context, eval_type);
3361644158 q if (stmt)
3371629158 q return new Statement_Dump("universal_dump", std::map< std::string, std::string >(), tree_it->line_col.first, stmt);
339154 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)
3462313497 q Statement* stmt = stmt_factory->create_criterion(tree_it, type, can_standalone, into);
3472313497 q if (stmt)
3482304495 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}