diff --git a/src/analyses/custom_bitvector_analysis.cpp b/src/analyses/custom_bitvector_analysis.cpp index 52f8a9ae04a..21e2c766ba3 100644 --- a/src/analyses/custom_bitvector_analysis.cpp +++ b/src/analyses/custom_bitvector_analysis.cpp @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include -#include +#include #include diff --git a/src/analyses/dependence_graph.cpp b/src/analyses/dependence_graph.cpp index 3586a4abfcc..e84ba05cb18 100644 --- a/src/analyses/dependence_graph.cpp +++ b/src/analyses/dependence_graph.cpp @@ -17,8 +17,7 @@ Date: August 2013 #include #include -#include -#include +#include #include "goto_rw.h" diff --git a/src/cbmc/bmc_cover.cpp b/src/cbmc/bmc_cover.cpp index 847bd9d00b8..8e84935c3c1 100644 --- a/src/cbmc/bmc_cover.cpp +++ b/src/cbmc/bmc_cover.cpp @@ -16,18 +16,19 @@ Author: Daniel Kroening, kroening@kroening.com #include -#include -#include #include #include -#include +#include #include #include #include -#include + +#include #include +#include +#include #include diff --git a/src/cbmc/fault_localization.cpp b/src/cbmc/fault_localization.cpp index 36329a34b03..0a3655bc624 100644 --- a/src/cbmc/fault_localization.cpp +++ b/src/cbmc/fault_localization.cpp @@ -13,12 +13,12 @@ Author: Peter Schrammel #include -#include #include -#include -#include #include -#include +#include +#include +#include +#include #include #include diff --git a/src/goto-analyzer/static_verifier.cpp b/src/goto-analyzer/static_verifier.cpp index a22d05e7ecc..305ce3dcf24 100644 --- a/src/goto-analyzer/static_verifier.cpp +++ b/src/goto-analyzer/static_verifier.cpp @@ -8,7 +8,7 @@ Author: Martin Brain, martin.brain@cs.ox.ac.uk #include "static_verifier.h" -#include +#include #include #include #include diff --git a/src/goto-analyzer/unreachable_instructions.cpp b/src/goto-analyzer/unreachable_instructions.cpp index 05e96ccfc51..8448aa2c1dd 100644 --- a/src/goto-analyzer/unreachable_instructions.cpp +++ b/src/goto-analyzer/unreachable_instructions.cpp @@ -14,7 +14,7 @@ Date: April 2016 #include "unreachable_instructions.h" #include -#include +#include #include #include diff --git a/src/goto-diff/goto_diff_base.cpp b/src/goto-diff/goto_diff_base.cpp index bfd6f5d6790..e76e4abe300 100644 --- a/src/goto-diff/goto_diff_base.cpp +++ b/src/goto-diff/goto_diff_base.cpp @@ -11,7 +11,7 @@ Author: Peter Schrammel #include "goto_diff.h" -#include +#include #include #include diff --git a/src/goto-instrument/unwind.h b/src/goto-instrument/unwind.h index 89b8ea40c08..b001a024b8d 100644 --- a/src/goto-instrument/unwind.h +++ b/src/goto-instrument/unwind.h @@ -16,7 +16,6 @@ Author: Daniel Kroening, kroening@kroening.com #include "unwindset.h" #include -#include #include class goto_modelt; diff --git a/src/goto-programs/Makefile b/src/goto-programs/Makefile index 87a1db03874..fdd55802453 100644 --- a/src/goto-programs/Makefile +++ b/src/goto-programs/Makefile @@ -25,6 +25,7 @@ SRC = adjust_float_expressions.cpp \ instrument_preconditions.cpp \ interpreter.cpp \ interpreter_evaluate.cpp \ + json_expr.cpp \ json_goto_trace.cpp \ lazy_goto_model.cpp \ link_goto_model.cpp \ @@ -67,6 +68,7 @@ SRC = adjust_float_expressions.cpp \ vcd_goto_trace.cpp \ wp.cpp \ write_goto_binary.cpp \ + xml_expr.cpp \ xml_goto_trace.cpp \ # Empty last line diff --git a/src/goto-programs/goto_inline_class.h b/src/goto-programs/goto_inline_class.h index eea4a63eba4..6adaa313329 100644 --- a/src/goto-programs/goto_inline_class.h +++ b/src/goto-programs/goto_inline_class.h @@ -14,7 +14,6 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -#include #include "goto_functions.h" diff --git a/src/util/json_expr.cpp b/src/goto-programs/json_expr.cpp similarity index 53% rename from src/util/json_expr.cpp rename to src/goto-programs/json_expr.cpp index 83f25189ed2..d8af467ee07 100644 --- a/src/util/json_expr.cpp +++ b/src/goto-programs/json_expr.cpp @@ -11,31 +11,29 @@ Author: Peter Schrammel #include "json_expr.h" -#include "namespace.h" -#include "expr.h" -#include "json.h" -#include "arith_tools.h" -#include "ieee_float.h" -#include "fixedbv.h" -#include "std_expr.h" -#include "config.h" -#include "identifier.h" -#include "invariant.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include #include +#include #include -static exprt simplify_json_expr( - const exprt &src, - const namespacet &ns) +static exprt simplify_json_expr(const exprt &src, const namespacet &ns) { - if(src.id()==ID_constant) + if(src.id() == ID_constant) { - const typet &type=ns.follow(src.type()); + const typet &type = ns.follow(src.type()); - if(type.id()==ID_pointer) + if(type.id() == ID_pointer) { const constant_exprt &c = to_constant_expr(src); @@ -72,10 +70,10 @@ static exprt simplify_json_expr( return simplify_json_expr( to_index_expr(to_address_of_expr(src).object()).array(), ns); } - else if(src.id()==ID_member && - id2string( - to_member_expr(src).get_component_name()) - .find("@")!=std::string::npos) + else if( + src.id() == ID_member && + id2string(to_member_expr(src).get_component_name()).find("@") != + std::string::npos) { // simplify expressions of the form member_expr(object, @class_identifier) return simplify_json_expr(to_member_expr(src).struct_op(), ns); @@ -84,31 +82,6 @@ static exprt simplify_json_expr( return src; } -json_objectt json(const source_locationt &location) -{ - json_objectt result; - - if(!location.get_working_directory().empty()) - result["workingDirectory"] = json_stringt(location.get_working_directory()); - - if(!location.get_file().empty()) - result["file"] = json_stringt(location.get_file()); - - if(!location.get_line().empty()) - result["line"] = json_stringt(location.get_line()); - - if(!location.get_column().empty()) - result["column"] = json_stringt(location.get_column()); - - if(!location.get_function().empty()) - result["function"] = json_stringt(location.get_function()); - - if(!location.get_java_bytecode_index().empty()) - result["bytecodeIndex"] = json_stringt(location.get_java_bytecode_index()); - - return result; -} - /// Output a CBMC type in json. /// The `mode` argument is used to correctly report types. /// \param type: a type @@ -116,81 +89,79 @@ json_objectt json(const source_locationt &location) /// \param mode: language in which the code was written; for now ID_C and /// ID_java are supported /// \return a json object -json_objectt json( - const typet &type, - const namespacet &ns, - const irep_idt &mode) +json_objectt json(const typet &type, const namespacet &ns, const irep_idt &mode) { if(type.id() == ID_symbol_type) return json(ns.follow(type), ns, mode); json_objectt result; - if(type.id()==ID_unsignedbv) + if(type.id() == ID_unsignedbv) { - result["name"]=json_stringt("integer"); - result["width"]= + result["name"] = json_stringt("integer"); + result["width"] = json_numbert(std::to_string(to_unsignedbv_type(type).get_width())); } - else if(type.id()==ID_signedbv) + else if(type.id() == ID_signedbv) { - result["name"]=json_stringt("integer"); - result["width"]= + result["name"] = json_stringt("integer"); + result["width"] = json_numbert(std::to_string(to_signedbv_type(type).get_width())); } - else if(type.id()==ID_floatbv) + else if(type.id() == ID_floatbv) { - result["name"]=json_stringt("float"); - result["width"]= + result["name"] = json_stringt("float"); + result["width"] = json_numbert(std::to_string(to_floatbv_type(type).get_width())); } - else if(type.id()==ID_bv) + else if(type.id() == ID_bv) { - result["name"]=json_stringt("integer"); - result["width"]=json_numbert(std::to_string(to_bv_type(type).get_width())); + result["name"] = json_stringt("integer"); + result["width"] = + json_numbert(std::to_string(to_bv_type(type).get_width())); } - else if(type.id()==ID_c_bit_field) + else if(type.id() == ID_c_bit_field) { - result["name"]=json_stringt("integer"); - result["width"]= + result["name"] = json_stringt("integer"); + result["width"] = json_numbert(std::to_string(to_c_bit_field_type(type).get_width())); } - else if(type.id()==ID_c_enum_tag) + 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, mode); } - else if(type.id()==ID_fixedbv) + else if(type.id() == ID_fixedbv) { - result["name"]=json_stringt("fixed"); - result["width"]= + result["name"] = json_stringt("fixed"); + result["width"] = json_numbert(std::to_string(to_fixedbv_type(type).get_width())); } - else if(type.id()==ID_pointer) + else if(type.id() == ID_pointer) { - result["name"]=json_stringt("pointer"); + result["name"] = json_stringt("pointer"); result["subtype"] = json(to_pointer_type(type).subtype(), ns, mode); } - else if(type.id()==ID_bool) + else if(type.id() == ID_bool) { - result["name"]=json_stringt("boolean"); + result["name"] = json_stringt("boolean"); } - else if(type.id()==ID_array) + else if(type.id() == ID_array) { - result["name"]=json_stringt("array"); + result["name"] = json_stringt("array"); result["subtype"] = json(to_array_type(type).subtype(), ns, mode); } - else if(type.id()==ID_vector) + else if(type.id() == ID_vector) { - result["name"]=json_stringt("vector"); + result["name"] = json_stringt("vector"); result["subtype"] = json(to_vector_type(type).subtype(), ns, mode); - result["size"]=json(to_vector_type(type).size(), ns, mode); + result["size"] = json(to_vector_type(type).size(), ns, mode); } - else if(type.id()==ID_struct) + else if(type.id() == ID_struct) { - result["name"]=json_stringt("struct"); - json_arrayt &members=result["members"].make_array(); - const struct_typet::componentst &components= + 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 &component : components) { @@ -199,11 +170,11 @@ json_objectt json( members.push_back(std::move(e)); } } - else if(type.id()==ID_union) + else if(type.id() == ID_union) { - result["name"]=json_stringt("union"); - json_arrayt &members=result["members"].make_array(); - const union_typet::componentst &components= + 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 &component : components) { @@ -213,7 +184,7 @@ json_objectt json( } } else - result["name"]=json_stringt("unknown"); + result["name"] = json_stringt("unknown"); return result; } @@ -232,94 +203,91 @@ static std::string binary(const constant_exprt &src) /// \param mode: language in which the code was written; for now ID_C and /// ID_java are supported /// \return a json object -json_objectt json( - const exprt &expr, - const namespacet &ns, - const irep_idt &mode) +json_objectt json(const exprt &expr, const namespacet &ns, const irep_idt &mode) { json_objectt result; - const typet &type=ns.follow(expr.type()); + const typet &type = ns.follow(expr.type()); - if(expr.id()==ID_constant) + if(expr.id() == ID_constant) { std::unique_ptr lang; - if(mode==ID_unknown) - lang=std::unique_ptr(get_default_language()); + if(mode == ID_unknown) + lang = std::unique_ptr(get_default_language()); else { - lang=std::unique_ptr(get_language_from_mode(mode)); + lang = std::unique_ptr(get_language_from_mode(mode)); if(!lang) - lang=std::unique_ptr(get_default_language()); + lang = std::unique_ptr(get_default_language()); } const typet &underlying_type = type.id() == ID_c_bit_field ? to_c_bit_field_type(type).subtype() : type; std::string type_string; - bool error=lang->from_type(underlying_type, type_string, ns); + bool error = lang->from_type(underlying_type, type_string, ns); CHECK_RETURN(!error); std::string value_string; lang->from_expr(expr, value_string, ns); - const constant_exprt &constant_expr=to_constant_expr(expr); - if(type.id()==ID_unsignedbv || - type.id()==ID_signedbv || - type.id()==ID_c_bit_field) + const constant_exprt &constant_expr = to_constant_expr(expr); + 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(); + std::size_t width = to_bitvector_type(type).get_width(); - result["name"]=json_stringt("integer"); + result["name"] = json_stringt("integer"); result["binary"] = json_stringt(binary(constant_expr)); - result["width"]=json_numbert(std::to_string(width)); - result["type"]=json_stringt(type_string); - result["data"]=json_stringt(value_string); + result["width"] = json_numbert(std::to_string(width)); + result["type"] = json_stringt(type_string); + result["data"] = json_stringt(value_string); } - else if(type.id()==ID_c_enum) + else if(type.id() == ID_c_enum) { - result["name"]=json_stringt("integer"); + result["name"] = json_stringt("integer"); result["binary"] = json_stringt(binary(constant_expr)); result["width"] = json_numbert(std::to_string( to_bitvector_type(to_c_enum_type(type).subtype()).get_width())); - result["type"]=json_stringt("enum"); - result["data"]=json_stringt(value_string); + result["type"] = json_stringt("enum"); + result["data"] = json_stringt(value_string); } - else if(type.id()==ID_c_enum_tag) + else if(type.id() == ID_c_enum_tag) { constant_exprt tmp( to_constant_expr(expr).get_value(), ns.follow_tag(to_c_enum_tag_type(type))); return json(tmp, ns, mode); } - else if(type.id()==ID_bv) + else if(type.id() == ID_bv) { - result["name"]=json_stringt("bitvector"); + result["name"] = json_stringt("bitvector"); result["binary"] = json_stringt(binary(constant_expr)); } - else if(type.id()==ID_fixedbv) + else if(type.id() == ID_fixedbv) { - result["name"]=json_stringt("fixed"); + result["name"] = json_stringt("fixed"); result["width"] = json_numbert(std::to_string(to_bitvector_type(type).get_width())); result["binary"] = json_stringt(binary(constant_expr)); - result["data"]= + result["data"] = json_stringt(fixedbvt(to_constant_expr(expr)).to_ansi_c_string()); } - else if(type.id()==ID_floatbv) + else if(type.id() == ID_floatbv) { - result["name"]=json_stringt("float"); + result["name"] = json_stringt("float"); result["width"] = json_numbert(std::to_string(to_bitvector_type(type).get_width())); result["binary"] = json_stringt(binary(constant_expr)); - result["data"]= + result["data"] = json_stringt(ieee_floatt(to_constant_expr(expr)).to_ansi_c_string()); } - else if(type.id()==ID_pointer) + else if(type.id() == ID_pointer) { - result["name"]=json_stringt("pointer"); - result["type"]=json_stringt(type_string); - exprt simpl_expr=simplify_json_expr(expr, ns); + result["name"] = json_stringt("pointer"); + result["type"] = json_stringt(type_string); + exprt simpl_expr = simplify_json_expr(expr, ns); if( simpl_expr.get(ID_value) == ID_NULL || // remove typecast on NULL @@ -327,49 +295,49 @@ json_objectt json( simpl_expr.type().id() == ID_pointer && to_unary_expr(simpl_expr).op().get(ID_value) == ID_NULL)) { - result["data"]=json_stringt(value_string); + result["data"] = json_stringt(value_string); } - else if(simpl_expr.id()==ID_symbol) + else if(simpl_expr.id() == ID_symbol) { - const irep_idt &ptr_id=to_symbol_expr(simpl_expr).get_identifier(); + const irep_idt &ptr_id = to_symbol_expr(simpl_expr).get_identifier(); identifiert identifier(id2string(ptr_id)); DATA_INVARIANT( !identifier.components.empty(), "pointer identifier should have non-empty components"); - result["data"]=json_stringt(identifier.components.back()); + result["data"] = json_stringt(identifier.components.back()); } } - else if(type.id()==ID_bool) + 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()); + result["name"] = json_stringt("boolean"); + result["binary"] = json_stringt(expr.is_true() ? "1" : "0"); + result["data"] = jsont::json_boolean(expr.is_true()); } - else if(type.id()==ID_c_bool) + else if(type.id() == ID_c_bool) { - result["name"]=json_stringt("integer"); + result["name"] = json_stringt("integer"); result["width"] = json_numbert(std::to_string(to_bitvector_type(type).get_width())); - result["type"]=json_stringt(type_string); - result["binary"]=json_stringt(expr.get_string(ID_value)); - result["data"]=json_stringt(value_string); + result["type"] = json_stringt(type_string); + result["binary"] = json_stringt(expr.get_string(ID_value)); + result["data"] = json_stringt(value_string); } - else if(type.id()==ID_string) + else if(type.id() == ID_string) { - result["name"]=json_stringt("string"); + result["name"] = json_stringt("string"); result["data"] = json_stringt(constant_expr.get_value()); } else { - result["name"]=json_stringt("unknown"); + result["name"] = json_stringt("unknown"); } } - else if(expr.id()==ID_array) + else if(expr.id() == ID_array) { - result["name"]=json_stringt("array"); - json_arrayt &elements=result["elements"].make_array(); + result["name"] = json_stringt("array"); + json_arrayt &elements = result["elements"].make_array(); - std::size_t index=0; + std::size_t index = 0; forall_operands(it, expr) { @@ -379,21 +347,21 @@ json_objectt json( index++; } } - else if(expr.id()==ID_struct) + else if(expr.id() == ID_struct) { - result["name"]=json_stringt("struct"); + result["name"] = json_stringt("struct"); // these are expected to have a struct type - if(type.id()==ID_struct) + if(type.id() == ID_struct) { - const struct_typet &struct_type=to_struct_type(type); - const struct_typet::componentst &components=struct_type.components(); + const struct_typet &struct_type = to_struct_type(type); + const struct_typet::componentst &components = struct_type.components(); DATA_INVARIANT( - components.size()==expr.operands().size(), + components.size() == expr.operands().size(), "number of struct components should match with its type"); - json_arrayt &members=result["members"].make_array(); - for(std::size_t m=0; m +#include + +class typet; +class exprt; +class namespacet; + +json_objectt json(const exprt &, const namespacet &, const irep_idt &mode); + +json_objectt json(const typet &, const namespacet &, const irep_idt &mode); + +#endif // CPROVER_GOTO_PROGRAMS_JSON_EXPR_H diff --git a/src/goto-programs/json_goto_trace.cpp b/src/goto-programs/json_goto_trace.cpp index 57a2338da85..9efb8c901b3 100644 --- a/src/goto-programs/json_goto_trace.cpp +++ b/src/goto-programs/json_goto_trace.cpp @@ -12,17 +12,15 @@ Author: Daniel Kroening /// Traces of GOTO Programs #include "json_goto_trace.h" -#include "goto_trace.h" -#include -#include -#include +#include #include #include #include #include -#include -#include + +#include "goto_trace.h" +#include "json_expr.h" /// Convert an ASSERT goto_trace step. /// \param [out] json_failure: The JSON object that diff --git a/src/goto-programs/json_goto_trace.h b/src/goto-programs/json_goto_trace.h index 820de78ee78..6124d4fb169 100644 --- a/src/goto-programs/json_goto_trace.h +++ b/src/goto-programs/json_goto_trace.h @@ -16,10 +16,10 @@ Date: November 2005 #include "goto_trace.h" +#include #include +#include #include -#include -#include /// This is structure is here to facilitate /// passing arguments to the conversion diff --git a/src/goto-programs/loop_ids.cpp b/src/goto-programs/loop_ids.cpp index 262e7a4ad15..4e0ae79cc6e 100644 --- a/src/goto-programs/loop_ids.cpp +++ b/src/goto-programs/loop_ids.cpp @@ -13,10 +13,8 @@ Author: Daniel Kroening, kroening@kroening.com #include -#include -#include -#include -#include +#include +#include void show_loop_ids( ui_message_handlert::uit ui, diff --git a/src/goto-programs/show_goto_functions.cpp b/src/goto-programs/show_goto_functions.cpp index 408c448d070..087a57bcbfd 100644 --- a/src/goto-programs/show_goto_functions.cpp +++ b/src/goto-programs/show_goto_functions.cpp @@ -13,8 +13,6 @@ Author: Peter Schrammel #include #include -#include -#include #include #include diff --git a/src/goto-programs/show_goto_functions_json.cpp b/src/goto-programs/show_goto_functions_json.cpp index 3e6d8655d87..da73e785eb9 100644 --- a/src/goto-programs/show_goto_functions_json.cpp +++ b/src/goto-programs/show_goto_functions_json.cpp @@ -14,7 +14,6 @@ Author: Thomas Kiley #include #include -#include #include #include #include diff --git a/src/goto-programs/show_goto_functions_xml.cpp b/src/goto-programs/show_goto_functions_xml.cpp index ffb1865ff9a..0660b0b993b 100644 --- a/src/goto-programs/show_goto_functions_xml.cpp +++ b/src/goto-programs/show_goto_functions_xml.cpp @@ -14,9 +14,9 @@ Author: Thomas Kiley #include #include -#include #include #include +#include #include diff --git a/src/goto-programs/show_properties.cpp b/src/goto-programs/show_properties.cpp index b7318488e76..75af9ba0252 100644 --- a/src/goto-programs/show_properties.cpp +++ b/src/goto-programs/show_properties.cpp @@ -13,10 +13,8 @@ Author: Daniel Kroening, kroening@kroening.com #include -#include -#include -#include -#include +#include +#include #include diff --git a/src/goto-programs/xml_expr.cpp b/src/goto-programs/xml_expr.cpp new file mode 100644 index 00000000000..5649eb6acad --- /dev/null +++ b/src/goto-programs/xml_expr.cpp @@ -0,0 +1,274 @@ +/*******************************************************************\ + +Module: Expressions in XML + +Author: Daniel Kroening + + Date: November 2005 + +\*******************************************************************/ + +/// \file +/// Expressions in XML + +#include "xml_expr.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +xmlt xml(const typet &type, const namespacet &ns) +{ + if(type.id() == ID_symbol_type) + return xml(ns.follow(type), ns); + + xmlt result; + + if(type.id() == ID_unsignedbv) + { + result.name = "integer"; + result.set_attribute("width", to_unsignedbv_type(type).get_width()); + } + else if(type.id() == ID_signedbv) + { + result.name = "integer"; + result.set_attribute("width", to_signedbv_type(type).get_width()); + } + else if(type.id() == ID_floatbv) + { + result.name = "float"; + result.set_attribute("width", to_floatbv_type(type).get_width()); + } + else if(type.id() == ID_bv) + { + result.name = "integer"; + result.set_attribute("width", to_bv_type(type).get_width()); + } + else if(type.id() == ID_c_bit_field) + { + result.name = "integer"; + result.set_attribute("width", to_c_bit_field_type(type).get_width()); + } + else if(type.id() == ID_c_enum_tag) + { + // we return the base type + return xml(ns.follow_tag(to_c_enum_tag_type(type)).subtype(), ns); + } + else if(type.id() == ID_fixedbv) + { + result.name = "fixed"; + result.set_attribute("width", to_fixedbv_type(type).get_width()); + } + else if(type.id() == ID_pointer) + { + result.name = "pointer"; + result.new_element("subtype").new_element() = + xml(to_pointer_type(type).subtype(), ns); + } + else if(type.id() == ID_bool) + { + result.name = "boolean"; + } + else if(type.id() == ID_array) + { + result.name = "array"; + result.new_element("subtype").new_element() = + xml(to_array_type(type).subtype(), ns); + } + else if(type.id() == ID_vector) + { + result.name = "vector"; + result.new_element("subtype").new_element() = + xml(to_vector_type(type).subtype(), ns); + result.new_element("size").new_element() = + xml(to_vector_type(type).size(), ns); + } + else if(type.id() == ID_struct) + { + result.name = "struct"; + const struct_typet::componentst &components = + to_struct_type(type).components(); + for(const auto &component : components) + { + xmlt &e = result.new_element("member"); + e.set_attribute("name", id2string(component.get_name())); + e.new_element("type").new_element() = xml(component.type(), ns); + } + } + else if(type.id() == ID_union) + { + result.name = "union"; + const union_typet::componentst &components = + to_union_type(type).components(); + for(const auto &component : components) + { + xmlt &e = result.new_element("member"); + e.set_attribute("name", id2string(component.get_name())); + e.new_element("type").new_element() = xml(component.type(), ns); + } + } + else + result.name = "unknown"; + + return result; +} + +xmlt xml(const exprt &expr, const namespacet &ns) +{ + xmlt 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 = "integer"; + result.set_attribute( + "binary", integer2binary(numeric_cast_v(expr), width)); + result.set_attribute("width", width); + + const typet &underlying_type = type.id() == ID_c_bit_field + ? to_c_bit_field_type(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.set_attribute("c_type", sig + "char"); + else if(width == config.ansi_c.int_width) + result.set_attribute("c_type", sig + "int"); + else if(width == config.ansi_c.short_int_width) + result.set_attribute("c_type", sig + "short int"); + else if(width == config.ansi_c.long_int_width) + result.set_attribute("c_type", sig + "long int"); + else if(width == config.ansi_c.long_long_int_width) + result.set_attribute("c_type", sig + "long long int"); + + mp_integer i; + if(!to_integer(to_constant_expr(expr), i)) + result.data = integer2string(i); + } + else if(type.id() == ID_c_enum) + { + result.name = "integer"; + result.set_attribute("binary", expr.get_string(ID_value)); + result.set_attribute( + "width", to_bitvector_type(to_c_enum_type(type).subtype()).get_width()); + result.set_attribute("c_type", "enum"); + + mp_integer i; + if(!to_integer(to_constant_expr(expr), i)) + result.data = integer2string(i); + } + else if(type.id() == ID_c_enum_tag) + { + constant_exprt tmp( + to_constant_expr(expr).get_value(), + ns.follow_tag(to_c_enum_tag_type(type))); + return xml(tmp, ns); + } + else if(type.id() == ID_bv) + { + result.name = "bitvector"; + result.set_attribute("binary", expr.get_string(ID_value)); + } + else if(type.id() == ID_fixedbv) + { + result.name = "fixed"; + result.set_attribute("width", to_bitvector_type(type).get_width()); + result.set_attribute("binary", expr.get_string(ID_value)); + result.data = fixedbvt(to_constant_expr(expr)).to_ansi_c_string(); + } + else if(type.id() == ID_floatbv) + { + result.name = "float"; + result.set_attribute("width", to_bitvector_type(type).get_width()); + result.set_attribute("binary", expr.get_string(ID_value)); + result.data = ieee_floatt(to_constant_expr(expr)).to_ansi_c_string(); + } + else if(type.id() == ID_pointer) + { + result.name = "pointer"; + result.set_attribute("binary", expr.get_string(ID_value)); + if(expr.get(ID_value) == ID_NULL) + result.data = "NULL"; + } + else if(type.id() == ID_bool) + { + result.name = "boolean"; + result.set_attribute("binary", expr.is_true() ? "1" : "0"); + result.data = expr.is_true() ? "TRUE" : "FALSE"; + } + else if(type.id() == ID_c_bool) + { + result.name = "integer"; + result.set_attribute("c_type", "_Bool"); + result.set_attribute("binary", expr.get_string(ID_value)); + const mp_integer b = numeric_cast_v(expr); + result.data = integer2string(b); + } + else + { + result.name = "unknown"; + } + } + else if(expr.id() == ID_array) + { + result.name = "array"; + + unsigned index = 0; + + forall_operands(it, expr) + { + xmlt &e = result.new_element("element"); + e.set_attribute("index", index); + e.new_element(xml(*it, ns)); + index++; + } + } + else if(expr.id() == ID_struct) + { + result.name = "struct"; + + // these are expected to have a struct type + if(type.id() == ID_struct) + { + const struct_typet &struct_type = to_struct_type(type); + const struct_typet::componentst &components = struct_type.components(); + PRECONDITION(components.size() == expr.operands().size()); + + for(unsigned m = 0; m < expr.operands().size(); m++) + { + xmlt &e = result.new_element("member"); + e.new_element() = xml(expr.operands()[m], ns); + e.set_attribute("name", id2string(components[m].get_name())); + } + } + } + else if(expr.id() == ID_union) + { + const union_exprt &union_expr = to_union_expr(expr); + result.name = "union"; + + xmlt &e = result.new_element("member"); + e.new_element(xml(union_expr.op(), ns)); + e.set_attribute("member_name", id2string(union_expr.get_component_name())); + } + else + result.name = "unknown"; + + return result; +} diff --git a/src/goto-programs/xml_expr.h b/src/goto-programs/xml_expr.h new file mode 100644 index 00000000000..1ba950360cf --- /dev/null +++ b/src/goto-programs/xml_expr.h @@ -0,0 +1,22 @@ +/*******************************************************************\ + +Module: + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + +#ifndef CPROVER_GOTO_PROGRAMS_XML_EXPR_H +#define CPROVER_GOTO_PROGRAMS_XML_EXPR_H + +#include + +class typet; +class exprt; +class namespacet; + +xmlt xml(const exprt &, const namespacet &); + +xmlt xml(const typet &, const namespacet &); + +#endif // CPROVER_GOTO_PROGRAMS_XML_EXPR_H diff --git a/src/goto-programs/xml_goto_trace.cpp b/src/goto-programs/xml_goto_trace.cpp index a6c4d413050..a60429adeba 100644 --- a/src/goto-programs/xml_goto_trace.cpp +++ b/src/goto-programs/xml_goto_trace.cpp @@ -15,12 +15,13 @@ Author: Daniel Kroening #include -#include #include +#include #include #include "printf_formatter.h" +#include "xml_expr.h" void convert( const namespacet &ns, diff --git a/src/goto-symex/show_vcc.cpp b/src/goto-symex/show_vcc.cpp index 6371121de3c..905274cd10f 100644 --- a/src/goto-symex/show_vcc.cpp +++ b/src/goto-symex/show_vcc.cpp @@ -20,8 +20,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -#include -#include +#include #include void show_vcc_plain( diff --git a/src/pointer-analysis/value_set_analysis.cpp b/src/pointer-analysis/value_set_analysis.cpp index c0566eb1d3a..b93877e9921 100644 --- a/src/pointer-analysis/value_set_analysis.cpp +++ b/src/pointer-analysis/value_set_analysis.cpp @@ -11,10 +11,9 @@ Author: Daniel Kroening, kroening@kroening.com #include "value_set_analysis.h" -#include #include -#include -#include +#include +#include #include diff --git a/src/util/Makefile b/src/util/Makefile index 58a32bf25b7..8f5fb7d734d 100644 --- a/src/util/Makefile +++ b/src/util/Makefile @@ -37,7 +37,6 @@ SRC = allocate_objects.cpp \ irep_serialization.cpp \ invariant_utils.cpp \ json.cpp \ - json_expr.cpp \ json_irep.cpp \ json_stream.cpp \ lispexpr.cpp \ @@ -103,7 +102,6 @@ SRC = allocate_objects.cpp \ validate_types.cpp \ version.cpp \ xml.cpp \ - xml_expr.cpp \ xml_irep.cpp \ # Empty last line diff --git a/src/util/json_expr.h b/src/util/json_expr.h deleted file mode 100644 index cc082020cdc..00000000000 --- a/src/util/json_expr.h +++ /dev/null @@ -1,35 +0,0 @@ -/*******************************************************************\ - -Module: Expressions in JSON - -Author: Peter Schrammel - -\*******************************************************************/ - -/// \file -/// Expressions in JSON - -#ifndef CPROVER_UTIL_JSON_EXPR_H -#define CPROVER_UTIL_JSON_EXPR_H - -#include "json.h" -#include "irep.h" - -class source_locationt; -class typet; -class exprt; -class namespacet; - -json_objectt json( - const exprt &, - const namespacet &, - const irep_idt &mode); - -json_objectt json( - const typet &, - const namespacet &, - const irep_idt &mode); - -json_objectt json(const source_locationt &); - -#endif // CPROVER_UTIL_JSON_EXPR_H diff --git a/src/util/json_irep.cpp b/src/util/json_irep.cpp index 8433bf84c5a..cc709cefeee 100644 --- a/src/util/json_irep.cpp +++ b/src/util/json_irep.cpp @@ -137,3 +137,28 @@ irept json_irept::convert_from_json(const jsont &in) const return out; } + +json_objectt json(const source_locationt &location) +{ + json_objectt result; + + if(!location.get_working_directory().empty()) + result["workingDirectory"] = json_stringt(location.get_working_directory()); + + if(!location.get_file().empty()) + result["file"] = json_stringt(location.get_file()); + + if(!location.get_line().empty()) + result["line"] = json_stringt(location.get_line()); + + if(!location.get_column().empty()) + result["column"] = json_stringt(location.get_column()); + + if(!location.get_function().empty()) + result["function"] = json_stringt(location.get_function()); + + if(!location.get_java_bytecode_index().empty()) + result["bytecodeIndex"] = json_stringt(location.get_java_bytecode_index()); + + return result; +} diff --git a/src/util/json_irep.h b/src/util/json_irep.h index 6e6fe6b1a55..cd25d34dfab 100644 --- a/src/util/json_irep.h +++ b/src/util/json_irep.h @@ -13,9 +13,9 @@ Author: Thomas Kiley, thomas.kiley@diffblue.com #define CPROVER_UTIL_JSON_IREP_H #include "irep.h" +#include "json.h" -class jsont; -class json_objectt; +class source_locationt; class json_irept { @@ -38,4 +38,6 @@ class json_irept bool include_comments; }; +json_objectt json(const source_locationt &); + #endif // CPROVER_UTIL_JSON_IREP_H diff --git a/src/util/module_dependencies.txt b/src/util/module_dependencies.txt index 6f311e1dcbc..a0f86e99c8f 100644 --- a/src/util/module_dependencies.txt +++ b/src/util/module_dependencies.txt @@ -1,5 +1,4 @@ big-int -langapi # should go away mach # system malloc # system nonstd diff --git a/src/util/ui_message.cpp b/src/util/ui_message.cpp index e3a9ea4903e..2999e7d03c6 100644 --- a/src/util/ui_message.cpp +++ b/src/util/ui_message.cpp @@ -12,12 +12,10 @@ Author: Daniel Kroening, kroening@kroening.com #include #include "cmdline.h" -#include "json.h" -#include "json_expr.h" +#include "json_irep.h" #include "json_stream.h" #include "make_unique.h" -#include "xml.h" -#include "xml_expr.h" +#include "xml_irep.h" ui_message_handlert::ui_message_handlert( message_handlert *_message_handler, diff --git a/src/util/xml_expr.cpp b/src/util/xml_expr.cpp deleted file mode 100644 index b290c8ddcbf..00000000000 --- a/src/util/xml_expr.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/*******************************************************************\ - -Module: Expressions in XML - -Author: Daniel Kroening - - Date: November 2005 - -\*******************************************************************/ - -/// \file -/// Expressions in XML - -#include "xml_expr.h" - -#include "arith_tools.h" -#include "config.h" -#include "expr.h" -#include "fixedbv.h" -#include "ieee_float.h" -#include "invariant.h" -#include "namespace.h" -#include "std_expr.h" -#include "xml.h" - -xmlt xml(const source_locationt &location) -{ - xmlt result; - - result.name="location"; - - if(!location.get_working_directory().empty()) - result.set_attribute( - "working-directory", id2string(location.get_working_directory())); - - if(!location.get_file().empty()) - result.set_attribute("file", id2string(location.get_file())); - - if(!location.get_line().empty()) - result.set_attribute("line", id2string(location.get_line())); - - if(!location.get_column().empty()) - result.set_attribute("column", id2string(location.get_column())); - - if(!location.get_function().empty()) - result.set_attribute("function", id2string(location.get_function())); - - return result; -} - -xmlt xml( - const typet &type, - const namespacet &ns) -{ - if(type.id() == ID_symbol_type) - return xml(ns.follow(type), ns); - - xmlt result; - - if(type.id()==ID_unsignedbv) - { - result.name="integer"; - result.set_attribute("width", to_unsignedbv_type(type).get_width()); - } - else if(type.id()==ID_signedbv) - { - result.name="integer"; - result.set_attribute("width", to_signedbv_type(type).get_width()); - } - else if(type.id()==ID_floatbv) - { - result.name="float"; - result.set_attribute("width", to_floatbv_type(type).get_width()); - } - else if(type.id()==ID_bv) - { - result.name="integer"; - result.set_attribute("width", to_bv_type(type).get_width()); - } - else if(type.id()==ID_c_bit_field) - { - result.name="integer"; - result.set_attribute("width", to_c_bit_field_type(type).get_width()); - } - else if(type.id()==ID_c_enum_tag) - { - // we return the base type - return xml(ns.follow_tag(to_c_enum_tag_type(type)).subtype(), ns); - } - else if(type.id()==ID_fixedbv) - { - result.name="fixed"; - result.set_attribute("width", to_fixedbv_type(type).get_width()); - } - else if(type.id()==ID_pointer) - { - result.name="pointer"; - result.new_element("subtype").new_element() = - xml(to_pointer_type(type).subtype(), ns); - } - else if(type.id()==ID_bool) - { - result.name="boolean"; - } - else if(type.id()==ID_array) - { - result.name="array"; - result.new_element("subtype").new_element() = - xml(to_array_type(type).subtype(), ns); - } - else if(type.id()==ID_vector) - { - result.name="vector"; - result.new_element("subtype").new_element() = - xml(to_vector_type(type).subtype(), ns); - result.new_element("size").new_element()= - xml(to_vector_type(type).size(), ns); - } - else if(type.id()==ID_struct) - { - result.name="struct"; - const struct_typet::componentst &components= - to_struct_type(type).components(); - for(const auto &component : components) - { - xmlt &e=result.new_element("member"); - e.set_attribute("name", id2string(component.get_name())); - e.new_element("type").new_element()=xml(component.type(), ns); - } - } - else if(type.id()==ID_union) - { - result.name="union"; - const union_typet::componentst &components= - to_union_type(type).components(); - for(const auto &component : components) - { - xmlt &e=result.new_element("member"); - e.set_attribute("name", id2string(component.get_name())); - e.new_element("type").new_element()=xml(component.type(), ns); - } - } - else - result.name="unknown"; - - return result; -} - -xmlt xml( - const exprt &expr, - const namespacet &ns) -{ - xmlt 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="integer"; - result.set_attribute( - "binary", integer2binary(numeric_cast_v(expr), width)); - result.set_attribute("width", width); - - const typet &underlying_type = type.id() == ID_c_bit_field - ? to_c_bit_field_type(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.set_attribute("c_type", sig+"char"); - else if(width==config.ansi_c.int_width) - result.set_attribute("c_type", sig+"int"); - else if(width==config.ansi_c.short_int_width) - result.set_attribute("c_type", sig+"short int"); - else if(width==config.ansi_c.long_int_width) - result.set_attribute("c_type", sig+"long int"); - else if(width==config.ansi_c.long_long_int_width) - result.set_attribute("c_type", sig+"long long int"); - - mp_integer i; - if(!to_integer(to_constant_expr(expr), i)) - result.data=integer2string(i); - } - else if(type.id()==ID_c_enum) - { - result.name="integer"; - result.set_attribute("binary", expr.get_string(ID_value)); - result.set_attribute( - "width", to_bitvector_type(to_c_enum_type(type).subtype()).get_width()); - result.set_attribute("c_type", "enum"); - - mp_integer i; - if(!to_integer(to_constant_expr(expr), i)) - result.data=integer2string(i); - } - else if(type.id()==ID_c_enum_tag) - { - constant_exprt tmp( - to_constant_expr(expr).get_value(), - ns.follow_tag(to_c_enum_tag_type(type))); - return xml(tmp, ns); - } - else if(type.id()==ID_bv) - { - result.name="bitvector"; - result.set_attribute("binary", expr.get_string(ID_value)); - } - else if(type.id()==ID_fixedbv) - { - result.name="fixed"; - result.set_attribute("width", to_bitvector_type(type).get_width()); - result.set_attribute("binary", expr.get_string(ID_value)); - result.data=fixedbvt(to_constant_expr(expr)).to_ansi_c_string(); - } - else if(type.id()==ID_floatbv) - { - result.name="float"; - result.set_attribute("width", to_bitvector_type(type).get_width()); - result.set_attribute("binary", expr.get_string(ID_value)); - result.data=ieee_floatt(to_constant_expr(expr)).to_ansi_c_string(); - } - else if(type.id()==ID_pointer) - { - result.name="pointer"; - result.set_attribute("binary", expr.get_string(ID_value)); - if(expr.get(ID_value)==ID_NULL) - result.data="NULL"; - } - else if(type.id()==ID_bool) - { - result.name="boolean"; - result.set_attribute("binary", expr.is_true()?"1":"0"); - result.data=expr.is_true()?"TRUE":"FALSE"; - } - else if(type.id()==ID_c_bool) - { - result.name="integer"; - result.set_attribute("c_type", "_Bool"); - result.set_attribute("binary", expr.get_string(ID_value)); - const mp_integer b = numeric_cast_v(expr); - result.data=integer2string(b); - } - else - { - result.name="unknown"; - } - } - else if(expr.id()==ID_array) - { - result.name="array"; - - unsigned index=0; - - forall_operands(it, expr) - { - xmlt &e=result.new_element("element"); - e.set_attribute("index", index); - e.new_element(xml(*it, ns)); - index++; - } - } - else if(expr.id()==ID_struct) - { - result.name="struct"; - - // these are expected to have a struct type - if(type.id()==ID_struct) - { - const struct_typet &struct_type=to_struct_type(type); - const struct_typet::componentst &components=struct_type.components(); - PRECONDITION(components.size() == expr.operands().size()); - - for(unsigned m=0; m #include "irep.h" -#include "xml.h" +#include "source_location.h" void convert( const irept &irep, @@ -87,3 +87,28 @@ void convert( } } } + +xmlt xml(const source_locationt &location) +{ + xmlt result; + + result.name = "location"; + + if(!location.get_working_directory().empty()) + result.set_attribute( + "working-directory", id2string(location.get_working_directory())); + + if(!location.get_file().empty()) + result.set_attribute("file", id2string(location.get_file())); + + if(!location.get_line().empty()) + result.set_attribute("line", id2string(location.get_line())); + + if(!location.get_column().empty()) + result.set_attribute("column", id2string(location.get_column())); + + if(!location.get_function().empty()) + result.set_attribute("function", id2string(location.get_function())); + + return result; +} diff --git a/src/util/xml_irep.h b/src/util/xml_irep.h index 3c931cbf5f5..294b53f295f 100644 --- a/src/util/xml_irep.h +++ b/src/util/xml_irep.h @@ -10,8 +10,10 @@ Author: Daniel Kroening, kroening@kroening.com #ifndef CPROVER_UTIL_XML_IREP_H #define CPROVER_UTIL_XML_IREP_H +#include "xml.h" + class irept; -class xmlt; +class source_locationt; void convert( const irept &irep, @@ -21,4 +23,6 @@ void convert( const xmlt &xml, irept &irep); +xmlt xml(const source_locationt &); + #endif // CPROVER_UTIL_XML_IREP_H diff --git a/unit/Makefile b/unit/Makefile index 488597b4a3d..6f638e5b4c1 100644 --- a/unit/Makefile +++ b/unit/Makefile @@ -25,6 +25,7 @@ SRC += analyses/ai/ai.cpp \ goto-programs/goto_program_symbol_type_table_consistency.cpp \ goto-programs/goto_program_table_consistency.cpp \ goto-programs/goto_trace_output.cpp \ + goto-programs/xml_expr.cpp \ goto-symex/ssa_equation.cpp \ interpreter/interpreter.cpp \ json/json_parser.cpp \ @@ -68,7 +69,6 @@ SRC += analyses/ai/ai.cpp \ util/symbol_table.cpp \ util/symbol.cpp \ util/unicode.cpp \ - util/xml_expr.cpp \ # Empty last line INCLUDES= -I ../src/ -I. diff --git a/unit/util/xml_expr.cpp b/unit/goto-programs/xml_expr.cpp similarity index 95% rename from unit/util/xml_expr.cpp rename to unit/goto-programs/xml_expr.cpp index eefcee3bcb6..67a41648d14 100644 --- a/unit/util/xml_expr.cpp +++ b/unit/goto-programs/xml_expr.cpp @@ -13,7 +13,8 @@ Author: Michael Tautschnig #include #include #include -#include + +#include TEST_CASE("Constant expression to XML") {