Skip to content

Add rvalue constructor to xmlt #3600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/analyses/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ xmlt ai_baset::output_xml(

forall_goto_functions(f_it, goto_functions)
{
xmlt function("function");
function.set_attribute("name", id2string(f_it->first));
function.set_attribute(
"body_available",
f_it->second.body_available() ? "true" : "false");
xmlt function(
"function",
{{"name", id2string(f_it->first)},
{"body_available", f_it->second.body_available() ? "true" : "false"}},
{});

if(f_it->second.body_available())
{
Expand Down Expand Up @@ -156,15 +156,11 @@ xmlt ai_baset::output_xml(

forall_goto_program_instructions(i_it, goto_program)
{
xmlt location;
location.set_attribute(
"location_number",
std::to_string(i_it->location_number));
location.set_attribute(
"source_location",
i_it->source_location.as_string());

location.new_element(abstract_state_before(i_it)->output_xml(*this, ns));
xmlt location(
"",
{{"location_number", std::to_string(i_it->location_number)},
{"source_location", i_it->source_location.as_string()}},
{abstract_state_before(i_it)->output_xml(*this, ns)});

// Ideally we need output_instruction_xml
std::ostringstream out;
Expand Down
8 changes: 5 additions & 3 deletions src/cbmc/all_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
{
for(const auto &g : goal_map)
{
xmlt xml_result("result");
xml_result.set_attribute("property", id2string(g.first));
xml_result.set_attribute("status", g.second.status_string());
xmlt xml_result(
"result",
{{"property", id2string(g.first)},
{"status", g.second.status_string()}},
{});

if(g.second.status==goalt::statust::FAILURE)
convert(bmc.ns, g.second.goto_trace, xml_result.new_element());
Expand Down
10 changes: 6 additions & 4 deletions src/cbmc/bmc_cover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,12 @@ bool bmc_covert::operator()()
{
const goalt &goal=goal_pair.second;

xmlt xml_result("goal");
xml_result.set_attribute("id", id2string(goal_pair.first));
xml_result.set_attribute("description", goal.description);
xml_result.set_attribute("status", goal.satisfied?"SATISFIED":"FAILED");
xmlt xml_result(
"goal",
{{"id", id2string(goal_pair.first)},
{"description", goal.description},
{"status", goal.satisfied ? "SATISFIED" : "FAILED"}},
{});

if(goal.source_location.is_not_nil())
xml_result.new_element()=xml(goal.source_location);
Expand Down
4 changes: 1 addition & 3 deletions src/cbmc/fault_localization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ safety_checkert::resultt fault_localizationt::stop_on_fail()
}
case ui_message_handlert::uit::XML_UI:
{
xmlt dest("fault-localization");
xmlt xml_diagnosis=report_xml(ID_nil);
dest.new_element().swap(xml_diagnosis);
xmlt dest("fault-localization", {}, {report_xml(ID_nil)});
status() << dest;
break;
}
Expand Down
22 changes: 13 additions & 9 deletions src/goto-programs/graphml_witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,11 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace)
case goto_trace_stept::typet::ASSERT:
case goto_trace_stept::typet::GOTO:
{
xmlt edge("edge");
edge.set_attribute("source", graphml[from].node_name);
edge.set_attribute("target", graphml[to].node_name);
xmlt edge(
"edge",
{{"source", graphml[from].node_name},
{"target", graphml[to].node_name}},
{});

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

#if 0
xmlt edge2("edge");
edge2.set_attribute("source", graphml[from].node_name);
edge2.set_attribute("target", graphml[sink].node_name);
xmlt edge2("edge", {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style

{"source", graphml[from].node_name},
{"target", graphml[sink].node_name}}, {});

xmlt &data_f2=edge2.new_element("data");
data_f2.set_attribute("key", "originfile");
Expand Down Expand Up @@ -447,9 +449,11 @@ void graphml_witnesst::operator()(const symex_target_equationt &equation)
case goto_trace_stept::typet::ASSERT:
case goto_trace_stept::typet::GOTO:
{
xmlt edge("edge");
edge.set_attribute("source", graphml[from].node_name);
edge.set_attribute("target", graphml[to].node_name);
xmlt edge(
"edge",
{{"source", graphml[from].node_name},
{"target", graphml[to].node_name}},
{});

{
xmlt &data_f=edge.new_element("data");
Expand Down
3 changes: 1 addition & 2 deletions src/goto-programs/loop_ids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ void show_loop_ids(
std::string id =
id2string(function_identifier) + "." + std::to_string(loop_id);

xmlt xml_loop("loop");
xml_loop.set_attribute("name", id);
xmlt xml_loop("loop", {{"name", id}}, {});
xml_loop.new_element("loop-id").data=id;
xml_loop.new_element()=xml(it->source_location);
std::cout << xml_loop << "\n";
Expand Down
8 changes: 5 additions & 3 deletions src/goto-programs/show_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ void show_properties(
case ui_message_handlert::uit::XML_UI:
{
// use me instead
xmlt xml_property("property");
xml_property.set_attribute("name", id2string(property_id));
xml_property.set_attribute("class", id2string(property_class));
xmlt xml_property(
"property",
{{"name", id2string(property_id)},
{"class", id2string(property_class)}},
{});

xmlt &property_l=xml_property.new_element();
property_l=xml(source_location);
Expand Down
7 changes: 7 additions & 0 deletions src/util/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class xmlt
typedef std::list<xmlt> elementst;
typedef std::map<std::string, std::string> attributest;

xmlt(std::string &&_name, attributest &&_attributes, elementst &&_elements)
: name(std::move(_name)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should _name get a &&?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering how well that would work given the common case is a C string at that point. Or maybe it actually makes no difference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string has a lot of optimisation behind it (I've seen instances with copy-on-write, short-string stored in the class itself, etc.); however, disregarding this, yes, it should.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now added the &&.

attributes(std::move(_attributes)),
elements(std::move(_elements))
{
}

std::string name, data;

attributest attributes;
Expand Down