CBMC
show_goto_functions_xml.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Goto Program
4 
5 Author: 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
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
xmlt::elements
elementst elements
Definition: xml.h:42
goto_programt::instructiont::code
const goto_instruction_codet & code() const
Get the code represented by this instruction.
Definition: goto_program.h:195
goto_programt::instructiont::output
std::ostream & output(std::ostream &) const
Output this instruction to the given stream.
Definition: goto_program.cpp:47
goto_programt::instructiont::to_string
std::string to_string() const
Definition: goto_program.h:553
goto_functionst::sorted
std::vector< function_mapt::const_iterator > sorted() const
returns a vector of the iterators in alphabetical order
Definition: goto_functions.cpp:64
prefix.h
xml_irep.h
show_goto_functions_xmlt::convert
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...
Definition: show_goto_functions_xml.cpp:37
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:380
has_prefix
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:47
xml
xmlt xml(const irep_idt &property_id, const property_infot &property_info)
Definition: properties.cpp:110
show_goto_functions_xml.h
show_goto_functions_xmlt::list_only
bool list_only
Definition: show_goto_functions_xml.h:30
cprover_prefix.h
xmlt
Definition: xml.h:20
show_goto_functions_xmlt::operator()
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: show_goto_functions_xml.cpp:100
goto_functionst::goto_functiont
::goto_functiont goto_functiont
Definition: goto_functions.h:27
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:24
show_goto_functions_xmlt::show_goto_functions_xmlt
show_goto_functions_xmlt(bool _list_only=false)
For outputting the GOTO program in a readable xml format.
Definition: show_goto_functions_xml.cpp:24
xmlt::set_attribute
void set_attribute(const std::string &attribute, unsigned value)
Definition: xml.cpp:198
xmlt::set_attribute_bool
void set_attribute_bool(const std::string &attribute, bool value)
Definition: xml.h:72
CPROVER_PREFIX
#define CPROVER_PREFIX
Definition: cprover_prefix.h:14
goto_functions.h
xmlt::data
std::string data
Definition: xml.h:39
goto_programt::instructiont
This class represents an instruction in the GOTO intermediate representation.
Definition: goto_program.h:180
exprt::source_location
const source_locationt & source_location() const
Definition: expr.h:211
xmlt::new_element
xmlt & new_element(const std::string &key)
Definition: xml.h:95