cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
cpp_scope.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: C++ Language Type Checking
4
5
Author: Daniel Kroening, kroening@cs.cmu.edu
6
7
\*******************************************************************/
8
11
12
#ifndef CPROVER_CPP_CPP_SCOPE_H
13
#define CPROVER_CPP_CPP_SCOPE_H
14
15
#include <iosfwd>
16
#include <set>
17
18
#include "
cpp_id.h
"
19
20
class
cpp_scopet
:
public
cpp_idt
21
{
22
public
:
23
cpp_scopet
()
24
{
25
is_scope
=
true
;
26
}
27
28
typedef
std::set<cpp_idt *>
id_sett
;
29
30
enum
lookup_kindt
{
SCOPE_ONLY
,
QUALIFIED
,
RECURSIVE
};
31
32
id_sett
lookup
(
const
irep_idt
&base_name_to_lookup,
lookup_kindt
kind)
33
{
34
id_sett
result;
35
lookup_rec
(base_name_to_lookup, kind, result);
36
return
result;
37
}
38
39
id_sett
lookup
(
40
const
irep_idt
&base_name_to_lookup,
41
lookup_kindt
kind,
42
cpp_idt::id_classt
identifier_class)
43
{
44
id_sett
result;
45
lookup_rec
(base_name_to_lookup, kind, identifier_class, result);
46
return
result;
47
}
48
49
id_sett
50
lookup_identifier
(
const
irep_idt
&
id
,
cpp_idt::id_classt
identifier_class);
51
52
cpp_idt
&
insert
(
const
irep_idt
&_base_name)
53
{
54
cpp_id_mapt::iterator it=
55
sub
.insert(std::pair<irep_idt, cpp_idt>
56
(_base_name,
cpp_idt
()));
57
58
it->second.base_name=_base_name;
59
it->second.set_parent(*
this
);
60
61
return
it->second;
62
}
63
64
cpp_idt
&
insert
(
const
cpp_idt
&cpp_id)
65
{
66
cpp_id_mapt::iterator it=
67
sub
.insert(std::pair<irep_idt, cpp_idt>
68
(cpp_id.
base_name
, cpp_id));
69
70
it->second.set_parent(*
this
);
71
72
return
it->second;
73
}
74
75
bool
contains
(
const
irep_idt
&base_name_to_lookup);
76
77
bool
is_root_scope
()
const
78
{
79
return
id_class
==
id_classt::ROOT_SCOPE
;
80
}
81
82
bool
is_global_scope
()
const
83
{
84
return
id_class
==
id_classt::ROOT_SCOPE
||
85
id_class
==
id_classt::NAMESPACE
;
86
}
87
88
cpp_scopet
&
get_parent
()
const
89
{
90
return
static_cast<
cpp_scopet
&
>
(
cpp_idt::get_parent
());
91
}
92
93
cpp_scopet
&
get_global_scope
()
94
{
95
cpp_scopet
*p=
this
;
96
97
while
(!p->
is_global_scope
())
98
p=&(p->
get_parent
());
99
100
return
*p;
101
}
102
103
void
add_secondary_scope
(
cpp_scopet
&other)
104
{
105
PRECONDITION
(other.
is_scope
);
106
secondary_scopes
.push_back(&other);
107
}
108
109
void
add_using_scope
(
cpp_scopet
&other)
110
{
111
PRECONDITION
(other.
is_scope
);
112
using_scopes
.push_back(&other);
113
}
114
115
class
cpp_scopet
&
new_scope
(
const
irep_idt
&new_scope_name);
116
117
protected
:
118
void
lookup_rec
(
const
irep_idt
&
base_name
,
lookup_kindt
kind,
id_sett
&);
119
120
void
lookup_rec
(
121
const
irep_idt
&
base_name
,
122
lookup_kindt
kind,
123
cpp_idt::id_classt
id_class
,
124
id_sett
&);
125
};
126
127
class
cpp_root_scopet
:
public
cpp_scopet
128
{
129
public
:
130
cpp_root_scopet
()
131
{
132
id_class
=
id_classt::ROOT_SCOPE
;
133
identifier
=
"::"
;
134
}
135
};
136
137
std::ostream &
operator <<
(std::ostream &out,
cpp_scopet::lookup_kindt
);
138
139
#endif
// CPROVER_CPP_CPP_SCOPE_H
cpp_idt::identifier
irep_idt identifier
Definition
cpp_id.h:72
cpp_idt::using_scopes
scope_listt using_scopes
Definition
cpp_id.h:108
cpp_idt::get_parent
cpp_idt & get_parent() const
Definition
cpp_id.h:82
cpp_idt::is_scope
bool is_scope
Definition
cpp_id.h:43
cpp_idt::id_classt
id_classt
Definition
cpp_id.h:28
cpp_idt::id_classt::NAMESPACE
@ NAMESPACE
Definition
cpp_id.h:36
cpp_idt::id_classt::ROOT_SCOPE
@ ROOT_SCOPE
Definition
cpp_id.h:39
cpp_idt::sub
cpp_id_mapt sub
Definition
cpp_id.h:104
cpp_idt::id_class
id_classt id_class
Definition
cpp_id.h:45
cpp_idt::cpp_idt
cpp_idt()
Definition
cpp_id.cpp:18
cpp_idt::secondary_scopes
scope_listt secondary_scopes
Definition
cpp_id.h:108
cpp_idt::base_name
irep_idt base_name
Definition
cpp_id.h:72
cpp_root_scopet::cpp_root_scopet
cpp_root_scopet()
Definition
cpp_scope.h:130
cpp_scopet
Definition
cpp_scope.h:21
cpp_scopet::new_scope
class cpp_scopet & new_scope(const irep_idt &new_scope_name)
Definition
cpp_scope.cpp:190
cpp_scopet::get_parent
cpp_scopet & get_parent() const
Definition
cpp_scope.h:88
cpp_scopet::insert
cpp_idt & insert(const irep_idt &_base_name)
Definition
cpp_scope.h:52
cpp_scopet::lookup
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind, cpp_idt::id_classt identifier_class)
Definition
cpp_scope.h:39
cpp_scopet::cpp_scopet
cpp_scopet()
Definition
cpp_scope.h:23
cpp_scopet::insert
cpp_idt & insert(const cpp_idt &cpp_id)
Definition
cpp_scope.h:64
cpp_scopet::get_global_scope
cpp_scopet & get_global_scope()
Definition
cpp_scope.h:93
cpp_scopet::is_global_scope
bool is_global_scope() const
Definition
cpp_scope.h:82
cpp_scopet::lookup_kindt
lookup_kindt
Definition
cpp_scope.h:30
cpp_scopet::SCOPE_ONLY
@ SCOPE_ONLY
Definition
cpp_scope.h:30
cpp_scopet::QUALIFIED
@ QUALIFIED
Definition
cpp_scope.h:30
cpp_scopet::RECURSIVE
@ RECURSIVE
Definition
cpp_scope.h:30
cpp_scopet::add_using_scope
void add_using_scope(cpp_scopet &other)
Definition
cpp_scope.h:109
cpp_scopet::lookup_identifier
id_sett lookup_identifier(const irep_idt &id, cpp_idt::id_classt identifier_class)
Definition
cpp_scope.cpp:157
cpp_scopet::id_sett
std::set< cpp_idt * > id_sett
Definition
cpp_scope.h:28
cpp_scopet::lookup_rec
void lookup_rec(const irep_idt &base_name, lookup_kindt kind, id_sett &)
Definition
cpp_scope.cpp:27
cpp_scopet::lookup
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind)
Definition
cpp_scope.h:32
cpp_scopet::is_root_scope
bool is_root_scope() const
Definition
cpp_scope.h:77
cpp_scopet::contains
bool contains(const irep_idt &base_name_to_lookup)
Definition
cpp_scope.cpp:201
cpp_scopet::add_secondary_scope
void add_secondary_scope(cpp_scopet &other)
Definition
cpp_scope.h:103
cpp_id.h
C++ Language Type Checking.
operator<<
std::ostream & operator<<(std::ostream &out, cpp_scopet::lookup_kindt)
Definition
cpp_scope.cpp:14
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
cpp
cpp_scope.h
Generated by
1.17.0