Skip to content

Commit 9133f75

Browse files
author
Daniel Kroening
authored
Merge pull request #3600 from tautschnig/xml-raii
Add rvalue constructor to xmlt
2 parents 0ebc228 + 61f23cc commit 9133f75

File tree

8 files changed

+48
-38
lines changed

8 files changed

+48
-38
lines changed

src/analyses/ai.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ xmlt ai_baset::output_xml(
124124

125125
forall_goto_functions(f_it, goto_functions)
126126
{
127-
xmlt function("function");
128-
function.set_attribute("name", id2string(f_it->first));
129-
function.set_attribute(
130-
"body_available",
131-
f_it->second.body_available() ? "true" : "false");
127+
xmlt function(
128+
"function",
129+
{{"name", id2string(f_it->first)},
130+
{"body_available", f_it->second.body_available() ? "true" : "false"}},
131+
{});
132132

133133
if(f_it->second.body_available())
134134
{
@@ -156,15 +156,11 @@ xmlt ai_baset::output_xml(
156156

157157
forall_goto_program_instructions(i_it, goto_program)
158158
{
159-
xmlt location;
160-
location.set_attribute(
161-
"location_number",
162-
std::to_string(i_it->location_number));
163-
location.set_attribute(
164-
"source_location",
165-
i_it->source_location.as_string());
166-
167-
location.new_element(abstract_state_before(i_it)->output_xml(*this, ns));
159+
xmlt location(
160+
"",
161+
{{"location_number", std::to_string(i_it->location_number)},
162+
{"source_location", i_it->source_location.as_string()}},
163+
{abstract_state_before(i_it)->output_xml(*this, ns)});
168164

169165
// Ideally we need output_instruction_xml
170166
std::ostringstream out;

src/cbmc/all_properties.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,11 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
250250
{
251251
for(const auto &g : goal_map)
252252
{
253-
xmlt xml_result("result");
254-
xml_result.set_attribute("property", id2string(g.first));
255-
xml_result.set_attribute("status", g.second.status_string());
253+
xmlt xml_result(
254+
"result",
255+
{{"property", id2string(g.first)},
256+
{"status", g.second.status_string()}},
257+
{});
256258

257259
if(g.second.status==goalt::statust::FAILURE)
258260
convert(bmc.ns, g.second.goto_trace, xml_result.new_element());

src/cbmc/bmc_cover.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,12 @@ bool bmc_covert::operator()()
293293
{
294294
const goalt &goal=goal_pair.second;
295295

296-
xmlt xml_result("goal");
297-
xml_result.set_attribute("id", id2string(goal_pair.first));
298-
xml_result.set_attribute("description", goal.description);
299-
xml_result.set_attribute("status", goal.satisfied?"SATISFIED":"FAILED");
296+
xmlt xml_result(
297+
"goal",
298+
{{"id", id2string(goal_pair.first)},
299+
{"description", goal.description},
300+
{"status", goal.satisfied ? "SATISFIED" : "FAILED"}},
301+
{});
300302

301303
if(goal.source_location.is_not_nil())
302304
xml_result.new_element()=xml(goal.source_location);

src/cbmc/fault_localization.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,7 @@ safety_checkert::resultt fault_localizationt::stop_on_fail()
298298
}
299299
case ui_message_handlert::uit::XML_UI:
300300
{
301-
xmlt dest("fault-localization");
302-
xmlt xml_diagnosis=report_xml(ID_nil);
303-
dest.new_element().swap(xml_diagnosis);
301+
xmlt dest("fault-localization", {}, {report_xml(ID_nil)});
304302
status() << dest;
305303
break;
306304
}

src/goto-programs/graphml_witness.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace)
264264
case goto_trace_stept::typet::ASSERT:
265265
case goto_trace_stept::typet::GOTO:
266266
{
267-
xmlt edge("edge");
268-
edge.set_attribute("source", graphml[from].node_name);
269-
edge.set_attribute("target", graphml[to].node_name);
267+
xmlt edge(
268+
"edge",
269+
{{"source", graphml[from].node_name},
270+
{"target", graphml[to].node_name}},
271+
{});
270272

271273
{
272274
xmlt &data_f=edge.new_element("data");
@@ -302,9 +304,9 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace)
302304
val.data="["+(it->cond_value ? cond : neg_cond)+"]";
303305

304306
#if 0
305-
xmlt edge2("edge");
306-
edge2.set_attribute("source", graphml[from].node_name);
307-
edge2.set_attribute("target", graphml[sink].node_name);
307+
xmlt edge2("edge", {
308+
{"source", graphml[from].node_name},
309+
{"target", graphml[sink].node_name}}, {});
308310

309311
xmlt &data_f2=edge2.new_element("data");
310312
data_f2.set_attribute("key", "originfile");
@@ -447,9 +449,11 @@ void graphml_witnesst::operator()(const symex_target_equationt &equation)
447449
case goto_trace_stept::typet::ASSERT:
448450
case goto_trace_stept::typet::GOTO:
449451
{
450-
xmlt edge("edge");
451-
edge.set_attribute("source", graphml[from].node_name);
452-
edge.set_attribute("target", graphml[to].node_name);
452+
xmlt edge(
453+
"edge",
454+
{{"source", graphml[from].node_name},
455+
{"target", graphml[to].node_name}},
456+
{});
453457

454458
{
455459
xmlt &data_f=edge.new_element("data");

src/goto-programs/loop_ids.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ void show_loop_ids(
5959
std::string id =
6060
id2string(function_identifier) + "." + std::to_string(loop_id);
6161

62-
xmlt xml_loop("loop");
63-
xml_loop.set_attribute("name", id);
62+
xmlt xml_loop("loop", {{"name", id}}, {});
6463
xml_loop.new_element("loop-id").data=id;
6564
xml_loop.new_element()=xml(it->source_location);
6665
std::cout << xml_loop << "\n";

src/goto-programs/show_properties.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ void show_properties(
7373
case ui_message_handlert::uit::XML_UI:
7474
{
7575
// use me instead
76-
xmlt xml_property("property");
77-
xml_property.set_attribute("name", id2string(property_id));
78-
xml_property.set_attribute("class", id2string(property_class));
76+
xmlt xml_property(
77+
"property",
78+
{{"name", id2string(property_id)},
79+
{"class", id2string(property_class)}},
80+
{});
7981

8082
xmlt &property_l=xml_property.new_element();
8183
property_l=xml(source_location);

src/util/xml.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class xmlt
2727
typedef std::list<xmlt> elementst;
2828
typedef std::map<std::string, std::string> attributest;
2929

30+
xmlt(std::string &&_name, attributest &&_attributes, elementst &&_elements)
31+
: name(std::move(_name)),
32+
attributes(std::move(_attributes)),
33+
elements(std::move(_elements))
34+
{
35+
}
36+
3037
std::string name, data;
3138

3239
attributest attributes;

0 commit comments

Comments
 (0)