-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathcpp_scope.h
139 lines (105 loc) · 2.78 KB
/
cpp_scope.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
/*******************************************************************\
Module: C++ Language Type Checking
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// C++ Language Type Checking
#ifndef CPROVER_CPP_CPP_SCOPE_H
#define CPROVER_CPP_CPP_SCOPE_H
#include <iosfwd>
#include <set>
#include "cpp_id.h"
class cpp_scopet:public cpp_idt
{
public:
cpp_scopet()
{
is_scope=true;
}
typedef std::set<cpp_idt *> id_sett;
enum lookup_kindt { SCOPE_ONLY, QUALIFIED, RECURSIVE };
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind)
{
id_sett result;
lookup_rec(base_name_to_lookup, kind, result);
return result;
}
id_sett lookup(
const irep_idt &base_name_to_lookup,
lookup_kindt kind,
cpp_idt::id_classt identifier_class)
{
id_sett result;
lookup_rec(base_name_to_lookup, kind, identifier_class, result);
return result;
}
id_sett
lookup_identifier(const irep_idt &id, cpp_idt::id_classt identifier_class);
cpp_idt &insert(const irep_idt &_base_name)
{
cpp_id_mapt::iterator it=
sub.insert(std::pair<irep_idt, cpp_idt>
(_base_name, cpp_idt()));
it->second.base_name=_base_name;
it->second.set_parent(*this);
return it->second;
}
cpp_idt &insert(const cpp_idt &cpp_id)
{
cpp_id_mapt::iterator it=
sub.insert(std::pair<irep_idt, cpp_idt>
(cpp_id.base_name, cpp_id));
it->second.set_parent(*this);
return it->second;
}
bool contains(const irep_idt &base_name_to_lookup);
bool is_root_scope() const
{
return id_class==id_classt::ROOT_SCOPE;
}
bool is_global_scope() const
{
return id_class==id_classt::ROOT_SCOPE ||
id_class==id_classt::NAMESPACE;
}
cpp_scopet &get_parent() const
{
return static_cast<cpp_scopet &>(cpp_idt::get_parent());
}
cpp_scopet &get_global_scope()
{
cpp_scopet *p=this;
while(!p->is_global_scope())
p=&(p->get_parent());
return *p;
}
void add_secondary_scope(cpp_scopet &other)
{
PRECONDITION(other.is_scope);
secondary_scopes.push_back(&other);
}
void add_using_scope(cpp_scopet &other)
{
PRECONDITION(other.is_scope);
using_scopes.push_back(&other);
}
class cpp_scopet &new_scope(const irep_idt &new_scope_name);
protected:
void lookup_rec(const irep_idt &base_name, lookup_kindt kind, id_sett &);
void lookup_rec(
const irep_idt &base_name,
lookup_kindt kind,
cpp_idt::id_classt id_class,
id_sett &);
};
class cpp_root_scopet:public cpp_scopet
{
public:
cpp_root_scopet()
{
id_class=id_classt::ROOT_SCOPE;
identifier="::";
}
};
std::ostream &operator << (std::ostream &out, cpp_scopet::lookup_kindt);
#endif // CPROVER_CPP_CPP_SCOPE_H