/// Outputs the current value of the domain. /// \par parameters: The abstract interpreter and the namespace. /// \return The domain, formatted as a JSON object. jsont dep_graph_domaint::output_json( const ai_baset &ai, const namespacet &ns) const { json_arrayt graph; for(const auto &cd : control_deps) { json_objectt &link=graph.push_back().make_object(); link["locationNumber"]= json_numbert(std::to_string(cd->location_number)); link["sourceLocation"]=json(cd->source_location); link["type"]=json_stringt("control"); } for(const auto &dd : data_deps) { json_objectt &link=graph.push_back().make_object(); link["locationNumber"]= json_numbert(std::to_string(dd->location_number)); link["sourceLocation"]=json(dd->source_location); json_stringt(dd->source_location.as_string()); link["type"]=json_stringt("data"); } return graph; }
void show_properties_json( json_arrayt &json_properties, const namespacet &ns, const irep_idt &identifier, const goto_programt &goto_program) { for(const auto &ins : goto_program.instructions) { if(!ins.is_assert()) continue; const source_locationt &source_location=ins.source_location; const irep_idt &comment=source_location.get_comment(); // const irep_idt &function=location.get_function(); const irep_idt &property_class=source_location.get_property_class(); const irep_idt description= (comment==""?"assertion":comment); irep_idt property_id=source_location.get_property_id(); json_objectt &json_property= json_properties.push_back(jsont()).make_object(); json_property["name"]=json_stringt(id2string(property_id)); json_property["class"]=json_stringt(id2string(property_class)); json_property["sourceLocation"]=json(source_location); json_property["description"]=json_stringt(id2string(description)); json_property["expression"]= json_stringt(from_expr(ns, identifier, ins.guard)); } }
void bmct::show_vcc_json(std::ostream &out) { json_objectt json_result; json_arrayt &json_vccs=json_result["vccs"].make_array(); languagest languages(ns, new_ansi_c_language()); bool has_threads=equation.has_threads(); for(symex_target_equationt::SSA_stepst::iterator s_it=equation.SSA_steps.begin(); s_it!=equation.SSA_steps.end(); s_it++) { if(!s_it->is_assert()) continue; // vcc object json_objectt &object=json_vccs.push_back(jsont()).make_object(); const source_locationt &source_location=s_it->source.pc->source_location; if(source_location.is_not_nil()) object["sourceLocation"]=json(source_location); const std::string &s=s_it->comment; if(!s.empty()) object["comment"]=json_stringt(s); // we show everything in case there are threads symex_target_equationt::SSA_stepst::const_iterator last_it=has_threads?equation.SSA_steps.end():s_it; json_arrayt &json_constraints=object["constraints"].make_array(); for(symex_target_equationt::SSA_stepst::const_iterator p_it =equation.SSA_steps.begin(); p_it!=last_it; p_it++) { if((p_it->is_assume() || p_it->is_assignment() || p_it->is_constraint()) && !p_it->ignore) { std::string string_value; languages.from_expr(p_it->cond_expr, string_value); json_constraints.push_back(json_stringt(string_value)); } } std::string string_value; languages.from_expr(s_it->cond_expr, string_value); object["expression"]=json_stringt(string_value); } out << ",\n" << json_result; }
ui_message_handlert::ui_message_handlert( uit __ui, const std::string &program):_ui(__ui) { switch(__ui) { case PLAIN: break; case XML_UI: std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << "\n"; std::cout << "<cprover>" << "\n"; { xmlt program_xml; program_xml.name="program"; program_xml.data=program; std::cout << program_xml; } break; case JSON_UI: { std::cout << "[\n"; json_objectt json_program; json_program["program"] = json_stringt(program); std::cout << json_program; } break; } }
json_objectt json(const source_locationt &location) { json_objectt result; if(!location.get_file().empty()) result["file"]=json_stringt(id2string(location.get_file())); if(!location.get_line().empty()) result["line"]=json_stringt(id2string(location.get_line())); if(!location.get_column().empty()) result["column"]=json_stringt(id2string(location.get_column())); if(!location.get_function().empty()) result["function"]=json_stringt(id2string(location.get_function())); return result; }
void ui_message_handlert::json_ui_msg( const std::string &type, const std::string &msg1, const std::string &msg2, const source_locationt &location) { json_objectt result; #if 0 if(location.is_not_nil() && !location.get_file().empty()) result.new_element(xml(location)); #endif result["messageType"] = json_stringt(type); result["messageText"] = json_stringt(msg1); //By convention a leading comma is created by every new array entry. //The first entry is generated in the constructor and does not have // a trailing comma. std::cout << ",\n" << result; }
void goto_difft::convert_function( json_objectt &result, const irep_idt &function_name) const { const goto_programt &program= goto_model2.goto_functions.function_map.at(function_name).body; if(!program.instructions.empty()) { result["sourceLocation"]= json(program.instructions.begin()->source_location); } result["name"]=json_stringt(id2string(function_name)); }
/// To convert to JSON from an irep structure by recurssively generating JSON /// for the different sub trees. /// \param irep: The irep structure to turn into json /// \param json: The json object to be filled up. void json_irept::convert_from_irep(const irept &irep, jsont &json) const { json_objectt &irep_object=json.make_object(); if(irep.id()!=ID_nil) irep_object["id"]=json_stringt(irep.id_string()); convert_sub_tree("sub", irep.get_sub(), irep_object); convert_named_sub_tree("namedSub", irep.get_named_sub(), irep_object); if(include_comments) { convert_named_sub_tree("comment", irep.get_comments(), irep_object); } }
void show_loop_ids_json( ui_message_handlert::uit ui, const goto_programt &goto_program, json_arrayt &loops) { assert(ui==ui_message_handlert::JSON_UI); //use function above forall_goto_program_instructions(it, goto_program) { if(it->is_backwards_goto()) { unsigned loop_id=it->loop_number; std::string id=id2string(it->function)+"."+std::to_string(loop_id); json_objectt &loop=loops.push_back().make_object(); loop["name"]=json_stringt(id); loop["sourceLocation"]=json(it->source_location); } } }
void convert( const namespacet &ns, const goto_tracet &goto_trace, jsont &dest) { json_arrayt &dest_array=dest.make_array(); source_locationt previous_source_location; for(const auto &step : goto_trace.steps) { const source_locationt &source_location=step.pc->source_location; jsont json_location; if(source_location.is_not_nil() && source_location.get_file()!="") json_location=json(source_location); else json_location=json_nullt(); switch(step.type) { case goto_trace_stept::typet::ASSERT: if(!step.cond_value) { irep_idt property_id; if(step.pc->is_assert()) property_id=source_location.get_property_id(); else if(step.pc->is_goto()) // unwinding, we suspect { property_id= id2string(step.pc->source_location.get_function())+ ".unwind."+std::to_string(step.pc->loop_number); } json_objectt &json_failure=dest_array.push_back().make_object(); json_failure["stepType"]=json_stringt("failure"); json_failure["hidden"]=jsont::json_boolean(step.hidden); json_failure["thread"]=json_numbert(std::to_string(step.thread_nr)); json_failure["reason"]=json_stringt(id2string(step.comment)); json_failure["property"]=json_stringt(id2string(property_id)); if(!json_location.is_null()) json_failure["sourceLocation"]=json_location; } break; case goto_trace_stept::typet::ASSIGNMENT: case goto_trace_stept::typet::DECL: { irep_idt identifier=step.lhs_object.get_identifier(); json_objectt &json_assignment=dest_array.push_back().make_object(); json_assignment["stepType"]=json_stringt("assignment"); if(!json_location.is_null()) json_assignment["sourceLocation"]=json_location; std::string value_string, binary_string, type_string, full_lhs_string; json_objectt full_lhs_value; if(step.full_lhs.is_not_nil()) full_lhs_string=from_expr(ns, identifier, step.full_lhs); #if 0 if(it.full_lhs_value.is_not_nil()) full_lhs_value_string=from_expr(ns, identifier, it.full_lhs_value); #endif if(step.full_lhs_value.is_not_nil()) full_lhs_value = json(step.full_lhs_value, ns); const symbolt *symbol; irep_idt base_name, display_name; if(!ns.lookup(identifier, symbol)) { base_name=symbol->base_name; display_name=symbol->display_name(); if(type_string=="") type_string=from_type(ns, identifier, symbol->type); json_assignment["mode"]=json_stringt(id2string(symbol->mode)); } json_assignment["value"]=full_lhs_value; json_assignment["lhs"]=json_stringt(full_lhs_string); json_assignment["hidden"]=jsont::json_boolean(step.hidden); json_assignment["thread"]=json_numbert(std::to_string(step.thread_nr)); json_assignment["assignmentType"]= json_stringt( step.assignment_type== goto_trace_stept::assignment_typet::ACTUAL_PARAMETER? "actual-parameter": "variable"); } break; case goto_trace_stept::typet::OUTPUT: { json_objectt &json_output=dest_array.push_back().make_object(); json_output["stepType"]=json_stringt("output"); json_output["hidden"]=jsont::json_boolean(step.hidden); json_output["thread"]=json_numbert(std::to_string(step.thread_nr)); json_output["outputID"]=json_stringt(id2string(step.io_id)); json_arrayt &json_values=json_output["values"].make_array(); for(const auto &arg : step.io_args) { if(arg.is_nil()) json_values.push_back(json_stringt("")); else json_values.push_back(json(arg, ns)); } if(!json_location.is_null()) json_output["sourceLocation"]=json_location; } break; case goto_trace_stept::typet::INPUT: { json_objectt &json_input=dest_array.push_back().make_object(); json_input["stepType"]=json_stringt("input"); json_input["hidden"]=jsont::json_boolean(step.hidden); json_input["thread"]=json_numbert(std::to_string(step.thread_nr)); json_input["inputID"]=json_stringt(id2string(step.io_id)); json_arrayt &json_values=json_input["values"].make_array(); for(const auto &arg : step.io_args) { if(arg.is_nil()) json_values.push_back(json_stringt("")); else json_values.push_back(json(arg, ns)); } if(!json_location.is_null()) json_input["sourceLocation"]=json_location; } break; case goto_trace_stept::typet::FUNCTION_CALL: case goto_trace_stept::typet::FUNCTION_RETURN: { std::string tag= (step.type==goto_trace_stept::typet::FUNCTION_CALL)? "function-call":"function-return"; json_objectt &json_call_return=dest_array.push_back().make_object(); json_call_return["stepType"]=json_stringt(tag); json_call_return["hidden"]=jsont::json_boolean(step.hidden); json_call_return["thread"]=json_numbert(std::to_string(step.thread_nr)); const symbolt &symbol=ns.lookup(step.identifier); json_objectt &json_function=json_call_return["function"].make_object(); json_function["displayName"]= json_stringt(id2string(symbol.display_name())); json_function["identifier"]=json_stringt(id2string(step.identifier)); json_function["sourceLocation"]=json(symbol.location); if(!json_location.is_null()) json_call_return["sourceLocation"]=json_location; } break; default: if(source_location!=previous_source_location) { // just the source location if(!json_location.is_null()) { json_objectt &json_location_only=dest_array.push_back().make_object(); json_location_only["stepType"]=json_stringt("location-only"); json_location_only["hidden"]=jsont::json_boolean(step.hidden); json_location_only["thread"]= json_numbert(std::to_string(step.thread_nr)); json_location_only["sourceLocation"]=json_location; } } } if(source_location.is_not_nil() && source_location.get_file()!="") previous_source_location=source_location; } }
std::ostream &goto_difft::output_functions(std::ostream &out) const { switch(ui) { case ui_message_handlert::PLAIN: { out << "total number of functions: " << total_functions_count << "\n"; out << "new functions: \n"; for(irep_id_sett::const_iterator it=new_functions.begin(); it!=new_functions.end(); ++it) { const goto_programt &program= goto_model2.goto_functions.function_map.at(*it).body; out << " " << program.instructions.begin()->source_location.get_file() << ": " << *it << "\n"; } out << "modified functions: \n"; for(irep_id_sett::const_iterator it=modified_functions.begin(); it!=modified_functions.end(); ++it) { const goto_programt &program= goto_model2.goto_functions.function_map.at(*it).body; out << " " << program.instructions.begin()->source_location.get_file() << ": " << *it << "\n"; } out << "deleted functions: \n"; for(irep_id_sett::const_iterator it=deleted_functions.begin(); it!=deleted_functions.end(); ++it) { const goto_programt &program= goto_model2.goto_functions.function_map.at(*it).body; out << " " << program.instructions.begin()->source_location.get_file() << ": " << *it << "\n"; } break; } case ui_message_handlert::JSON_UI: { json_objectt json_result; json_result["totalNumberOfFunctions"]= json_stringt(i2string(total_functions_count)); convert_function_group (json_result["newFunctions"].make_array(), new_functions); convert_function_group( json_result["modifiedFunctions"].make_array(), modified_functions); convert_function_group( json_result["deletedFunctions"].make_array(), deleted_functions); out << ",\n" << json_result; break; } case ui_message_handlert::XML_UI: { out << "not supported yet"; } } return out; }
void symex_parse_optionst::report_cover( const path_searcht::property_mapt &property_map) { // report unsigned goals_covered=0; for(const auto &prop_pair : property_map) if(prop_pair.second.is_failure()) goals_covered++; switch(get_ui()) { case ui_message_handlert::uit::PLAIN: { status() << "\n** coverage results:" << eom; for(const auto &prop_pair : property_map) { const auto &property=prop_pair.second; status() << "[" << prop_pair.first << "]"; if(property.source_location.is_not_nil()) status() << ' ' << property.source_location; if(!property.description.empty()) status() << ' ' << property.description; status() << ": " << (property.is_failure()?"SATISFIED":"FAILED") << eom; } status() << '\n'; break; } case ui_message_handlert::uit::XML_UI: { for(const auto &prop_pair : property_map) { const auto &property=prop_pair.second; xmlt xml_result("result"); xml_result.set_attribute("goal", id2string(prop_pair.first)); xml_result.set_attribute( "description", id2string(property.description)); xml_result.set_attribute( "status", property.is_failure()?"SATISFIED":"FAILED"); if(property.source_location.is_not_nil()) xml_result.new_element()=xml(property.source_location); if(property.is_failure()) { const namespacet ns(goto_model.symbol_table); if(cmdline.isset("trace")) { convert(ns, property.error_trace, xml_result.new_element()); } else { xmlt &xml_test=xml_result.new_element("test"); for(const auto &step : property.error_trace.steps) { if(step.is_input()) { xmlt &xml_input=xml_test.new_element("input"); xml_input.set_attribute("id", id2string(step.io_id)); if(step.io_args.size()==1) xml_input.new_element("value")= xml(step.io_args.front(), ns); } } } } std::cout << xml_result << "\n"; } break; } case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_arrayt &result_array=json_result["results"].make_array(); for(const auto &prop_pair : property_map) { const auto &property=prop_pair.second; json_objectt &result=result_array.push_back().make_object(); result["status"]= json_stringt(property.is_failure()?"satisfied":"failed"); result["goal"]=json_stringt(id2string(prop_pair.first)); result["description"]=json_stringt(id2string(property.description)); if(property.source_location.is_not_nil()) result["sourceLocation"]=json(property.source_location); if(property.is_failure()) { const namespacet ns(goto_model.symbol_table); if(cmdline.isset("trace")) { jsont &json_trace=result["trace"]; convert(ns, property.error_trace, json_trace); } else { json_arrayt &json_test=result["test"].make_array(); for(const auto &step : property.error_trace.steps) { if(step.is_input()) { json_objectt json_input; json_input["id"]=json_stringt(id2string(step.io_id)); if(step.io_args.size()==1) json_input["value"]=json(step.io_args.front(), ns); json_test.push_back(json_input); } } } } } json_result["totalGoals"]= json_numbert(std::to_string(property_map.size())); json_result["goalsCovered"]=json_numbert(std::to_string(goals_covered)); std::cout << ",\n" << json_result; break; } } status() << "** " << goals_covered << " of " << property_map.size() << " covered (" << std::fixed << std::setw(1) << std::setprecision(1) << (property_map.empty()? 100.0:100.0*goals_covered/property_map.size()) << "%)" << eom; if(get_ui()==ui_message_handlert::uit::PLAIN) { std::set<std::string> tests; for(const auto &prop_pair : property_map) if(prop_pair.second.is_failure()) tests.insert(get_test(prop_pair.second.error_trace)); std::cout << "Test suite:" << '\n'; for(const auto &t : tests) std::cout << t << '\n'; } }
void bmc_all_propertiest::report(const cover_goalst &cover_goals) { switch(bmc.ui) { case ui_message_handlert::uit::PLAIN: { status() << "\n** Results:" << eom; for(const auto &goal_pair : goal_map) status() << "[" << goal_pair.first << "] " << goal_pair.second.description << ": " << goal_pair.second.status_string() << eom; if(bmc.options.get_bool_option("trace")) { for(const auto &g : goal_map) if(g.second.status==goalt::statust::FAILURE) { std::cout << "\n" << "Trace for " << g.first << ":" << "\n"; show_goto_trace(std::cout, bmc.ns, g.second.goto_trace); } } status() << "\n** " << cover_goals.number_covered() << " of " << cover_goals.size() << " failed (" << cover_goals.iterations() << " iteration" << (cover_goals.iterations()==1?"":"s") << ")" << eom; } break; case ui_message_handlert::uit::XML_UI: { 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()); if(g.second.status==goalt::statust::FAILURE) convert(bmc.ns, g.second.goto_trace, xml_result.new_element()); std::cout << xml_result << "\n"; } break; } case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_arrayt &result_array=json_result["result"].make_array(); for(const auto &g : goal_map) { json_objectt &result=result_array.push_back().make_object(); result["property"]=json_stringt(id2string(g.first)); result["description"]=json_stringt(id2string(g.second.description)); result["status"]=json_stringt(g.second.status_string()); if(g.second.status==goalt::statust::FAILURE) { jsont &json_trace=result["trace"]; convert(bmc.ns, g.second.goto_trace, json_trace); } } std::cout << ",\n" << json_result; } break; } }
json_objectt json( const typet &type, const namespacet &ns) { if(type.id()==ID_symbol) return json(ns.follow(type), ns); json_objectt result; if(type.id()==ID_unsignedbv) { result["name"]=json_stringt("integer"); result["width"]= json_numbert(i2string(to_unsignedbv_type(type).get_width())); } else if(type.id()==ID_signedbv) { result["name"]=json_stringt("integer"); result["width"]=json_numbert(i2string(to_signedbv_type(type).get_width())); } else if(type.id()==ID_floatbv) { result["name"]=json_stringt("float"); result["width"]=json_numbert(i2string(to_floatbv_type(type).get_width())); } else if(type.id()==ID_bv) { result["name"]=json_stringt("integer"); result["width"]=json_numbert(i2string(to_bv_type(type).get_width())); } else if(type.id()==ID_c_bit_field) { result["name"]=json_stringt("integer"); result["width"]= json_numbert(i2string(to_c_bit_field_type(type).get_width())); } else if(type.id()==ID_c_enum_tag) { // we return the base type return json(ns.follow_tag(to_c_enum_tag_type(type)).subtype(), ns); } else if(type.id()==ID_fixedbv) { result["name"]=json_stringt("fixed"); result["width"]=json_numbert(i2string(to_fixedbv_type(type).get_width())); } else if(type.id()==ID_pointer) { result["name"]=json_stringt("pointer"); result["subtype"]=json(type.subtype(), ns); } else if(type.id()==ID_bool) { result["name"]=json_stringt("boolean"); } else if(type.id()==ID_array) { result["name"]=json_stringt("array"); result["subtype"]=json(type.subtype(), ns); } else if(type.id()==ID_vector) { result["name"]=json_stringt("vector"); result["subtype"]=json(type.subtype(), ns); result["size"]=json(to_vector_type(type).size(), ns); } else if(type.id()==ID_struct) { result["name"]=json_stringt("struct"); json_arrayt &members=result["members"].make_array(); const struct_typet::componentst &components= to_struct_type(type).components(); for(const auto & it : components) { json_objectt &e=members.push_back().make_object(); e["name"]=json_stringt(id2string(it.get_name())); e["type"]=json(it.type(), ns); } } else if(type.id()==ID_union) { result["name"]=json_stringt("union"); json_arrayt &members=result["members"].make_array(); const union_typet::componentst &components= to_union_type(type).components(); for(const auto & it : components) { json_objectt &e=members.push_back().make_object(); e["name"]=json_stringt(id2string(it.get_name())); e["type"]=json(it.type(), ns); } } else result["name"]=json_stringt("unknown"); return result; }
json_objectt json( const exprt &expr, const namespacet &ns) { json_objectt result; const typet &type=ns.follow(expr.type()); if(expr.id()==ID_constant) { if(type.id()==ID_unsignedbv || type.id()==ID_signedbv || type.id()==ID_c_bit_field) { std::size_t width=to_bitvector_type(type).get_width(); result["name"]=json_stringt("integer"); result["binary"]=json_stringt(expr.get_string(ID_value)); result["width"]=json_numbert(i2string(width)); const typet &underlying_type= type.id()==ID_c_bit_field?type.subtype(): type; bool is_signed=underlying_type.id()==ID_signedbv; std::string sig=is_signed?"":"unsigned "; if(width==config.ansi_c.char_width) result["c_type"]=json_stringt(sig+"char"); else if(width==config.ansi_c.int_width) result["c_type"]=json_stringt(sig+"int"); else if(width==config.ansi_c.short_int_width) result["c_type"]=json_stringt(sig+"short int"); else if(width==config.ansi_c.long_int_width) result["c_type"]=json_stringt(sig+"long int"); else if(width==config.ansi_c.long_long_int_width) result["c_type"]=json_stringt(sig+"long long int"); mp_integer i; if(!to_integer(expr, i)) result["data"]=json_stringt(integer2string(i)); } else if(type.id()==ID_c_enum) { result["name"]=json_stringt("integer"); result["binary"]=json_stringt(expr.get_string(ID_value)); result["width"]=json_numbert(type.subtype().get_string(ID_width)); result["c_type"]=json_stringt("enum"); mp_integer i; if(!to_integer(expr, i)) result["data"]=json_stringt(integer2string(i)); } else if(type.id()==ID_c_enum_tag) { constant_exprt tmp; tmp.type()=ns.follow_tag(to_c_enum_tag_type(type)); tmp.set_value(to_constant_expr(expr).get_value()); return json(tmp, ns); } else if(type.id()==ID_bv) { result["name"]=json_stringt("bitvector"); result["binary"]=json_stringt(expr.get_string(ID_value)); } else if(type.id()==ID_fixedbv) { result["name"]=json_stringt("fixed"); result["width"]=json_numbert(type.get_string(ID_width)); result["binary"]=json_stringt(expr.get_string(ID_value)); result["data"]= json_stringt(fixedbvt(to_constant_expr(expr)).to_ansi_c_string()); } else if(type.id()==ID_floatbv) { result["name"]=json_stringt("float"); result["width"]=json_numbert(type.get_string(ID_width)); result["binary"]=json_stringt(expr.get_string(ID_value)); result["data"]= json_stringt(ieee_floatt(to_constant_expr(expr)).to_ansi_c_string()); } else if(type.id()==ID_pointer) { result["name"]=json_stringt("pointer"); result["binary"]=json_stringt(expr.get_string(ID_value)); if(expr.get(ID_value)==ID_NULL) result["data"]=json_stringt("NULL"); } else if(type.id()==ID_bool) { result["name"]=json_stringt("boolean"); result["binary"]=json_stringt(expr.is_true()?"1":"0"); result["data"]=jsont::json_boolean(expr.is_true()); } else { result["name"]=json_stringt("unknown"); } } else if(expr.id()==ID_array) { result["name"]=json_stringt("array"); json_arrayt &elements=result["elements"].make_array(); unsigned index=0; forall_operands(it, expr) { json_objectt &e=elements.push_back().make_object(); e["index"]=json_numbert(i2string(index)); e["value"]=json(*it, ns); index++; }