cprover
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 #include <sstream>
16 
17 #include <util/xml_expr.h>
18 #include <util/cprover_prefix.h>
19 #include <util/prefix.h>
20 
21 #include <langapi/language_util.h>
22 
23 #include "goto_functions.h"
24 #include "goto_model.h"
25 
30  const namespacet &_ns,
31  bool _list_only)
32  : ns(_ns), list_only(_list_only)
33 {}
34 
45  const goto_functionst &goto_functions)
46 {
47  xmlt xml_functions=xmlt("functions");
48 
49  const auto sorted = goto_functions.sorted();
50 
51  for(const auto &function_entry : sorted)
52  {
53  const irep_idt &function_name = function_entry->first;
54  const goto_functionst::goto_functiont &function = function_entry->second;
55 
56  xmlt &xml_function=xml_functions.new_element("function");
57  xml_function.set_attribute("name", id2string(function_name));
58  xml_function.set_attribute_bool(
59  "is_body_available", function.body_available());
60  bool is_internal=
61  has_prefix(id2string(function_name), CPROVER_PREFIX) ||
62  has_prefix(id2string(function_name), "java::array[") ||
63  has_prefix(id2string(function_name), "java::org.cprover") ||
64  has_prefix(id2string(function_name), "java::java");
65  xml_function.set_attribute_bool("is_internal", is_internal);
66 
67  if(list_only)
68  continue;
69 
70  if(function.body_available())
71  {
72  xmlt &xml_instructions=xml_function.new_element("instructions");
73  for(const goto_programt::instructiont &instruction :
74  function.body.instructions)
75  {
76  xmlt &instruction_entry=xml_instructions.new_element("instruction");
77 
78  instruction_entry.set_attribute(
79  "instruction_id", instruction.to_string());
80 
81  if(instruction.code.source_location().is_not_nil())
82  {
83  instruction_entry.new_element(
84  xml(instruction.code.source_location()));
85  }
86 
87  std::ostringstream instruction_builder;
88  function.body.output_instruction(
89  ns, function_name, instruction_builder, instruction);
90 
91  xmlt &instruction_value=
92  instruction_entry.new_element("instruction_value");
93  instruction_value.data=instruction_builder.str();
94  instruction_value.elements.clear();
95  }
96  }
97  }
98  return xml_functions;
99 }
100 
109  const goto_functionst &goto_functions,
110  std::ostream &out,
111  bool append)
112 {
113  if(append)
114  {
115  out << "\n";
116  }
117  out << convert(goto_functions);
118 }
void set_attribute_bool(const std::string &attribute, bool value)
Definition: xml.h:63
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
bool is_not_nil() const
Definition: irep.h:173
std::string to_string() const
Definition: goto_program.h:391
#define CPROVER_PREFIX
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...
Goto Programs with Functions.
xmlt xml(const source_locationt &location)
Definition: xml_expr.cpp:26
This class represents an instruction in the GOTO intermediate representation.
Definition: goto_program.h:178
elementst elements
Definition: xml.h:33
Symbol Table + CFG.
void set_attribute(const std::string &attribute, unsigned value)
Definition: xml.cpp:175
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:93
::goto_functiont goto_functiont
Definition: xml.h:18
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
A collection of goto functions.
std::string data
Definition: xml.h:30
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:35
xmlt & new_element(const std::string &key)
Definition: xml.h:86
show_goto_functions_xmlt(const namespacet &_ns, bool _list_only=false)
For outputting the GOTO program in a readable xml format.
std::vector< function_mapt::const_iterator > sorted() const
returns a vector of the iterators in alphabetical order
const source_locationt & source_location() const
Definition: expr.h:228
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...