cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
xml_irep.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: 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
19
void
convert
(
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"
);
29
convert
(sub_irep, x_sub);
30
}
31
32
for
(
const
auto
&irep_entry : irep.
get_named_sub
())
33
{
34
if
(!
irept::is_comment
(irep_entry.first))
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
{
44
if
(!
irept::is_comment
(irep_entry.first))
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
53
void
convert
(
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"
);
71
irep.
move_to_named_sub
(named_name,
r
);
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"
);
84
irep.
move_to_named_sub
(named_name,
r
);
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
95
xmlt
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
}
dstringt::empty
bool empty() const
Definition
dstring.h:89
irept
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition
irep.h:364
irept::move_to_named_sub
void move_to_named_sub(const irep_idt &name, irept &irep)
Definition
irep.cpp:26
irept::id_string
const std::string & id_string() const
Definition
irep.h:391
irept::get_sub
subt & get_sub()
Definition
irep.h:448
irept::is_comment
static bool is_comment(const irep_idt &name)
Definition
irep.h:460
irept::move_to_sub
void move_to_sub(irept &irep)
Definition
irep.cpp:35
irept::id
const irep_idt & id() const
Definition
irep.h:388
irept::get_named_sub
named_subt & get_named_sub()
Definition
irep.h:450
source_locationt
Definition
source_location.h:20
source_locationt::get_column
const irep_idt & get_column() const
Definition
source_location.h:51
source_locationt::get_function
const irep_idt & get_function() const
Definition
source_location.h:64
source_locationt::get_working_directory
const irep_idt & get_working_directory() const
Definition
source_location.h:41
source_locationt::get_file
const irep_idt & get_file() const
Definition
source_location.h:36
source_locationt::get_line
const irep_idt & get_line() const
Definition
source_location.h:46
xmlt
Definition
xml.h:21
xmlt::set_attribute
void set_attribute(const std::string &attribute, unsigned value)
Definition
xml.cpp:198
xmlt::name
std::string name
Definition
xml.h:39
irep.h
id2string
const std::string & id2string(const irep_idt &d)
Definition
irep.h:44
r
static int8_t r
Definition
irep_hash.h:60
xml
xmlt xml(const irep_idt &property_id, const property_infot &property_info)
Definition
properties.cpp:110
source_location.h
convert
void convert(const irept &irep, xmlt &xml)
Definition
xml_irep.cpp:19
xml
xmlt xml(const source_locationt &location)
Definition
xml_irep.cpp:95
xml_irep.h
util
xml_irep.cpp
Generated by
1.17.0