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 
29  ns(ns)
30 {}
31 
40  const goto_functionst &goto_functions)
41 {
42  xmlt xml_functions=xmlt("functions");
43  for(const auto &function_entry : goto_functions.function_map)
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=(has_prefix(id2string(function_name), CPROVER_PREFIX) ||
53  function_name==goto_functions.entry_point());
54  xml_function.set_attribute_bool("is_internal", is_internal);
55 
56  if(function.body_available())
57  {
58  xmlt &xml_instructions=xml_function.new_element("instructions");
59  for(const goto_programt::instructiont &instruction :
60  function.body.instructions)
61  {
62  xmlt &instruction_entry=xml_instructions.new_element("instruction");
63 
64  instruction_entry.set_attribute(
65  "instruction_id", instruction.to_string());
66 
67  if(instruction.code.source_location().is_not_nil())
68  {
69  instruction_entry.new_element(
70  xml(instruction.code.source_location()));
71  }
72 
73  std::ostringstream instruction_builder;
74  function.body.output_instruction(
75  ns, function_name, instruction_builder, instruction);
76 
77  xmlt &instruction_value=
78  instruction_entry.new_element("instruction_value");
79  instruction_value.data=instruction_builder.str();
80  instruction_value.elements.clear();
81  }
82  }
83  }
84  return xml_functions;
85 }
86 
95  const goto_functionst &goto_functions,
96  std::ostream &out,
97  bool append)
98 {
99  if(append)
100  {
101  out << "\n";
102  }
103  out << convert(goto_functions);
104 }
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
#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:25
elementst elements
Definition: xml.h:33
Symbol Table + CFG.
void set_attribute(const std::string &attribute, unsigned value)
Definition: xml.cpp:174
TO_BE_DOCUMENTED.
Definition: namespace.h:62
Definition: xml.h:18
std::string data
Definition: xml.h:30
xmlt & new_element(const std::string &name)
Definition: xml.h:86
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
show_goto_functions_xmlt(const namespacet &ns)
For outputting the GOTO program in a readable xml format.
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...