cprover
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:
24  {
25  is_scope=true;
26  }
27 
28  typedef std::set<cpp_idt *> id_sett;
29 
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 
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  {
80  }
81 
82  bool is_global_scope() const
83  {
86  }
87 
88  bool is_template_scope() const
89  {
91  }
92 
94  {
95  return static_cast<cpp_scopet &>(cpp_idt::get_parent());
96  }
97 
99  {
100  cpp_scopet *p=this;
101 
102  while(!p->is_global_scope())
103  p=&(p->get_parent());
104 
105  return *p;
106  }
107 
109  {
110  assert(other.is_scope);
111  secondary_scopes.push_back(&other);
112  }
113 
115  {
116  assert(other.is_scope);
117  using_scopes.push_back(&other);
118  }
119 
120  class cpp_scopet &new_scope(const irep_idt &new_scope_name);
121 
122 protected:
123  void lookup_rec(const irep_idt &base_name, lookup_kindt kind, id_sett &);
124 
125  void lookup_rec(
126  const irep_idt &base_name,
127  lookup_kindt kind,
129  id_sett &);
130 };
131 
133 {
134 public:
136  {
138  identifier="::";
139  }
140 };
141 
142 std::ostream &operator << (std::ostream &out, cpp_scopet::lookup_kindt);
143 
144 #endif // CPROVER_CPP_CPP_SCOPE_H
cpp_id_mapt sub
Definition: cpp_id.h:105
cpp_idt & get_parent() const
Definition: cpp_id.h:83
cpp_scopet()
Definition: cpp_scope.h:23
id_sett lookup_identifier(const irep_idt &id, cpp_idt::id_classt identifier_class)
Definition: cpp_scope.cpp:159
class cpp_scopet & new_scope(const irep_idt &new_scope_name)
Definition: cpp_scope.cpp:192
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind)
Definition: cpp_scope.h:32
cpp_scopet & get_parent() const
Definition: cpp_scope.h:93
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind, cpp_idt::id_classt identifier_class)
Definition: cpp_scope.h:39
void lookup_rec(const irep_idt &base_name, lookup_kindt kind, id_sett &)
Definition: cpp_scope.cpp:29
void add_secondary_scope(cpp_scopet &other)
Definition: cpp_scope.h:108
C++ Language Type Checking.
bool contains(const irep_idt &base_name_to_lookup)
Definition: cpp_scope.cpp:203
bool is_scope
Definition: cpp_id.h:48
cpp_idt & insert(const cpp_idt &cpp_id)
Definition: cpp_scope.h:64
irep_idt base_name
Definition: cpp_id.h:73
irep_idt identifier
Definition: cpp_id.h:73
id_classt id_class
Definition: cpp_id.h:51
scope_listt using_scopes
Definition: cpp_id.h:109
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:35
bool is_global_scope() const
Definition: cpp_scope.h:82
cpp_idt()
Definition: cpp_id.cpp:18
std::ostream & operator<<(std::ostream &out, cpp_scopet::lookup_kindt)
Definition: cpp_scope.cpp:16
id_classt
Definition: cpp_id.h:33
scope_listt secondary_scopes
Definition: cpp_id.h:109
Definition: cpp_id.h:28
bool is_root_scope() const
Definition: cpp_scope.h:77
cpp_idt & insert(const irep_idt &_base_name)
Definition: cpp_scope.h:52
std::set< cpp_idt * > id_sett
Definition: cpp_scope.h:28
cpp_scopet & get_global_scope()
Definition: cpp_scope.h:98
bool is_template_scope() const
Definition: cpp_scope.h:88
void add_using_scope(cpp_scopet &other)
Definition: cpp_scope.h:114