CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
xml_irep.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening
6
7 Date: November 2005
8
9\*******************************************************************/
10
11#include "xml_irep.h"
12
13#include <iostream>
14#include <string>
15
16#include "irep.h"
17#include "source_location.h"
18
20 const irept &irep,
21 xmlt &xml)
22{
23 if(irep.id()!=ID_nil)
24 xml.new_element("id").data=irep.id_string();
25
26 for(const auto &sub_irep : irep.get_sub())
27 {
28 xmlt &x_sub=xml.new_element("sub");
30 }
31
32 for(const auto &irep_entry : irep.get_named_sub())
33 {
35 {
36 xmlt &x_nsub = xml.new_element("named_sub");
37 x_nsub.set_attribute("name", id2string(irep_entry.first));
38 convert(irep_entry.second, x_nsub);
39 }
40 }
41
42 for(const auto &irep_entry : irep.get_named_sub())
43 {
45 {
46 xmlt &x_com = xml.new_element("comment");
47 x_com.set_attribute("name", id2string(irep_entry.first));
48 convert(irep_entry.second, x_com);
49 }
50 }
51}
52
54 const xmlt &xml,
55 irept &irep)
56{
57 irep.id(ID_nil);
58
59 xmlt::elementst::const_iterator it = xml.elements.begin();
60 for(; it != xml.elements.end(); it++)
61 {
62 if(it->name=="id")
63 {
64 irep.id(it->data);
65 }
66 else if(it->name=="named_sub")
67 {
68 irept r;
69 convert(*it, r);
70 std::string named_name = it->get_attribute("name");
72 }
73 else if(it->name=="sub")
74 {
75 irept r;
76 convert(*it, r);
77 irep.move_to_sub(r);
78 }
79 else if(it->name=="comment")
80 {
81 irept r;
82 convert(*it, r);
83 std::string named_name = it->get_attribute("name");
85 }
86 else
87 {
88 // Should not happen
89 std::cout << "Unknown sub found (" << it->name << "); malformed xml?";
90 std::cout << "\n";
91 }
92 }
93}
94
95xmlt xml(const source_locationt &location)
96{
97 xmlt result;
98
99 result.name = "location";
100
101 if(!location.get_working_directory().empty())
102 result.set_attribute(
103 "working-directory", id2string(location.get_working_directory()));
104
105 if(!location.get_file().empty())
106 result.set_attribute("file", id2string(location.get_file()));
107
108 if(!location.get_line().empty())
109 result.set_attribute("line", id2string(location.get_line()));
110
111 if(!location.get_column().empty())
112 result.set_attribute("column", id2string(location.get_column()));
113
114 if(!location.get_function().empty())
115 result.set_attribute("function", id2string(location.get_function()));
116
117 return result;
118}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition irep.h:364
void move_to_named_sub(const irep_idt &name, irept &irep)
Definition irep.cpp:26
const std::string & id_string() const
Definition irep.h:391
subt & get_sub()
Definition irep.h:448
static bool is_comment(const irep_idt &name)
Definition irep.h:460
void move_to_sub(irept &irep)
Definition irep.cpp:35
const irep_idt & id() const
Definition irep.h:388
named_subt & get_named_sub()
Definition irep.h:450
const irep_idt & get_column() const
const irep_idt & get_function() const
const irep_idt & get_working_directory() const
const irep_idt & get_file() const
const irep_idt & get_line() const
Definition xml.h:21
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
std::string name
Definition xml.h:39
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
static int8_t r
Definition irep_hash.h:60
void convert(const irept &irep, xmlt &xml)
Definition xml_irep.cpp:19
xmlt xml(const source_locationt &location)
Definition xml_irep.cpp:95