CBMC
Loading...
Searching...
No Matches
show_goto_functions_xml.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Goto Program
4
5Author: Thomas Kiley
6
7\*******************************************************************/
8
11
13
14#include <util/cprover_prefix.h>
15#include <util/xml_irep.h>
16
17#include "goto_functions.h"
18
19#include <iostream>
20
26
37 const goto_functionst &goto_functions)
38{
39 xmlt xml_functions=xmlt("functions");
40
41 const auto sorted = goto_functions.sorted();
42
43 for(const auto &function_entry : sorted)
44 {
45 const irep_idt &function_name = function_entry->first;
46 const goto_functionst::goto_functiont &function = function_entry->second;
47
48 xmlt &xml_function=xml_functions.new_element("function");
49 xml_function.set_attribute("name", id2string(function_name));
50 xml_function.set_attribute_bool(
51 "is_body_available", function.body_available());
52 bool is_internal = function_name.starts_with(CPROVER_PREFIX) ||
53 function_name.starts_with("java::array[") ||
54 function_name.starts_with("java::org.cprover") ||
55 function_name.starts_with("java::java");
56 xml_function.set_attribute_bool("is_internal", is_internal);
57
58 if(list_only)
59 continue;
60
61 if(function.body_available())
62 {
63 xmlt &xml_instructions=xml_function.new_element("instructions");
64 for(const goto_programt::instructiont &instruction :
65 function.body.instructions)
66 {
67 xmlt &instruction_entry=xml_instructions.new_element("instruction");
68
69 instruction_entry.set_attribute(
70 "instruction_id", instruction.to_string());
71
72 if(instruction.code().source_location().is_not_nil())
73 {
74 instruction_entry.new_element(
75 xml(instruction.code().source_location()));
76 }
77
78 std::ostringstream instruction_builder;
79 instruction.output(instruction_builder);
80
82 instruction_entry.new_element("instruction_value");
84 instruction_value.elements.clear();
85 }
86 }
87 }
88 return xml_functions;
89}
90
99 const goto_functionst &goto_functions,
100 std::ostream &out,
101 bool append)
102{
103 if(append)
104 {
105 out << "\n";
106 }
107 out << convert(goto_functions);
108}
virtual void output(const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program, std::ostream &out) const
Output the abstract states for a single function.
Definition ai.cpp:39
virtual void clear()
Reset the abstract state.
Definition ai.h:265
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
bool starts_with(const char *s) const
equivalent of as_string().starts_with(s)
Definition dstring.h:95
A collection of goto functions.
::goto_functiont goto_functiont
std::vector< function_mapt::const_iterator > sorted() const
returns a vector of the iterators in alphabetical order
This class represents an instruction in the GOTO intermediate representation.
xmlt convert(const goto_functionst &goto_functions)
Walks through all of the functions in the program and returns an xml object representing all their fu...
show_goto_functions_xmlt(bool _list_only=false)
For outputting the GOTO program in a readable xml format.
void operator()(const goto_functionst &goto_functions, std::ostream &out, bool append=true)
Print the xml object generated by show_goto_functions_xmlt::show_goto_functions to the provided strea...
Definition xml.h:21
#define CPROVER_PREFIX
Goto Programs with Functions.
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
xmlt xml(const irep_idt &property_id, const property_infot &property_info)