-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathcpp_name.h
160 lines (130 loc) · 3.33 KB
/
cpp_name.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*******************************************************************\
Module:
Author: Daniel Kroening, [email protected]
\*******************************************************************/
#ifndef CPROVER_CPP_CPP_NAME_H
#define CPROVER_CPP_CPP_NAME_H
#include <util/expr.h>
#include <util/invariant.h>
class cpp_namet:public irept
{
public:
// the subs are one of the following:
// ID_name (see namet)
// ID_operator
// ID_template_args
// ::
// ~
class namet:public irept
{
public:
namet():irept(ID_name)
{
}
explicit namet(const irep_idt &base_name):irept(ID_name)
{
set(ID_identifier, base_name);
}
namet(
const irep_idt &_base_name,
const source_locationt &_source_location):irept(ID_name)
{
set(ID_identifier, _base_name);
add_source_location()=_source_location;
}
source_locationt &add_source_location()
{
return static_cast<source_locationt &>(add(ID_C_source_location));
}
const source_locationt &source_location() const
{
return static_cast<const source_locationt &>(find(ID_C_source_location));
}
};
cpp_namet():irept(ID_cpp_name)
{
}
explicit cpp_namet(const irep_idt &base_name):irept(ID_cpp_name)
{
get_sub().push_back(namet(base_name));
}
cpp_namet(
const irep_idt &_base_name,
const source_locationt &_source_location):irept(ID_cpp_name)
{
get_sub().push_back(namet(_base_name, _source_location));
}
const source_locationt &source_location() const
{
if(get_sub().empty())
return source_locationt::nil();
else
return static_cast<const source_locationt &>(
get_sub().front().find(ID_C_source_location));
}
// void convert(std::string &identifier, std::string &base_name) const;
irep_idt get_base_name() const;
// one of three:
// 'identifier'
// 'operator X'
// '~identifier'
bool is_simple_name() const
{
const subt &sub=get_sub();
return (sub.size()==1 && sub.front().id()==ID_name) ||
(sub.size()==2 && sub.front().id()==ID_operator) ||
(sub.size()==2 && sub[0].id()=="~" && sub[1].id()==ID_name);
}
bool is_operator() const
{
if(get_sub().empty())
return false;
return get_sub().front().id()==ID_operator;
}
bool is_typename() const
{
return get_bool(ID_typename);
}
bool is_qualified() const
{
for(const auto &irep : get_sub())
{
if(irep.id() == "::")
return true;
}
return false;
}
bool is_destructor() const
{
return get_sub().size()>=1 && get_sub().front().id()=="~";
}
bool has_template_args() const
{
for(const auto &irep : get_sub())
{
if(irep.id() == ID_template_args)
return true;
}
return false;
}
std::string to_string() const;
const exprt &as_expr() const
{
return static_cast<const exprt &>(static_cast<const irept &>(*this));
}
const typet &as_type() const
{
return static_cast<const typet &>(static_cast<const irept &>(*this));
}
};
inline cpp_namet &to_cpp_name(irept &cpp_name)
{
PRECONDITION(cpp_name.id() == ID_cpp_name);
return static_cast<cpp_namet &>(cpp_name);
}
inline const cpp_namet &to_cpp_name(const irept &cpp_name)
{
PRECONDITION(cpp_name.id() == ID_cpp_name);
return static_cast<const cpp_namet &>(cpp_name);
}
#endif // CPROVER_CPP_CPP_NAME_H