cprover
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 <iostream>
15
16#include <util/cprover_prefix.h>
17#include <util/prefix.h>
18#include <util/xml_irep.h>
19
20#include "goto_functions.h"
21
25 : list_only(_list_only)
26{}
27
38 const goto_functionst &goto_functions)
39{
40 xmlt xml_functions=xmlt("functions");
41
42 const auto sorted = goto_functions.sorted();
43
44 for(const auto &function_entry : sorted)
45 {
46 const irep_idt &function_name = function_entry->first;
47 const goto_functionst::goto_functiont &function = function_entry->second;
48
49 xmlt &xml_function=xml_functions.new_element("function");
50 xml_function.set_attribute("name", id2string(function_name));
51 xml_function.set_attribute_bool(
52 "is_body_available", function.body_available());
53 bool is_internal=
54 has_prefix(id2string(function_name), CPROVER_PREFIX) ||
55 has_prefix(id2string(function_name), "java::array[") ||
56 has_prefix(id2string(function_name), "java::org.cprover") ||
57 has_prefix(id2string(function_name), "java::java");
58 xml_function.set_attribute_bool("is_internal", is_internal);
59
60 if(list_only)
61 continue;
62
63 if(function.body_available())
64 {
65 xmlt &xml_instructions=xml_function.new_element("instructions");
66 for(const goto_programt::instructiont &instruction :
67 function.body.instructions)
68 {
69 xmlt &instruction_entry=xml_instructions.new_element("instruction");
70
71 instruction_entry.set_attribute(
72 "instruction_id", instruction.to_string());
73
74 if(instruction.code().source_location().is_not_nil())
75 {
76 instruction_entry.new_element(
77 xml(instruction.code().source_location()));
78 }
79
80 std::ostringstream instruction_builder;
81 instruction.output(instruction_builder);
82
83 xmlt &instruction_value=
84 instruction_entry.new_element("instruction_value");
85 instruction_value.data=instruction_builder.str();
86 instruction_value.elements.clear();
87 }
88 }
89 }
90 return xml_functions;
91}
92
101 const goto_functionst &goto_functions,
102 std::ostream &out,
103 bool append)
104{
105 if(append)
106 {
107 out << "\n";
108 }
109 out << convert(goto_functions);
110}
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:39
A collection of goto functions.
std::vector< function_mapt::const_iterator > sorted() const
returns a vector of the iterators in alphabetical order
::goto_functiont goto_functiont
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
void set_attribute_bool(const std::string &attribute, bool value)
Definition xml.h:72
xmlt & new_element(const std::string &key)
Definition xml.h:95
void set_attribute(const std::string &attribute, unsigned value)
Definition xml.cpp:198
elementst elements
Definition xml.h:42
std::string data
Definition xml.h:39
void output(std::ostream &out, unsigned indent=0) const
Definition xml.cpp:33
bool has_prefix(const std::string &s, const std::string &prefix)
Definition converter.cpp:13
#define CPROVER_PREFIX
Goto Programs with Functions.
const std::string & id2string(const irep_idt &d)
Definition irep.h:47
xmlt xml(const irep_idt &property_id, const property_infot &property_info)