CBMC
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 
89  {
90  return static_cast<cpp_scopet &>(cpp_idt::get_parent());
91  }
92 
94  {
95  cpp_scopet *p=this;
96 
97  while(!p->is_global_scope())
98  p=&(p->get_parent());
99 
100  return *p;
101  }
102 
104  {
105  PRECONDITION(other.is_scope);
106  secondary_scopes.push_back(&other);
107  }
108 
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,
124  id_sett &);
125 };
126 
128 {
129 public:
131  {
133  identifier="::";
134  }
135 };
136 
137 std::ostream &operator << (std::ostream &out, cpp_scopet::lookup_kindt);
138 
139 #endif // CPROVER_CPP_CPP_SCOPE_H
Definition: cpp_id.h:23
irep_idt identifier
Definition: cpp_id.h:72
scope_listt using_scopes
Definition: cpp_id.h:108
cpp_idt & get_parent() const
Definition: cpp_id.h:82
bool is_scope
Definition: cpp_id.h:43
id_classt
Definition: cpp_id.h:28
cpp_id_mapt sub
Definition: cpp_id.h:104
id_classt id_class
Definition: cpp_id.h:45
cpp_idt()
Definition: cpp_id.cpp:18
scope_listt secondary_scopes
Definition: cpp_id.h:108
irep_idt base_name
Definition: cpp_id.h:72
class cpp_scopet & new_scope(const irep_idt &new_scope_name)
Definition: cpp_scope.cpp:190
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()
Definition: cpp_scope.h:23
bool is_global_scope() const
Definition: cpp_scope.h:82
cpp_scopet & get_parent() const
Definition: cpp_scope.h:88
cpp_idt & insert(const cpp_idt &cpp_id)
Definition: cpp_scope.h:64
@ SCOPE_ONLY
Definition: cpp_scope.h:30
void add_using_scope(cpp_scopet &other)
Definition: cpp_scope.h:109
id_sett lookup_identifier(const irep_idt &id, cpp_idt::id_classt identifier_class)
Definition: cpp_scope.cpp:157
std::set< cpp_idt * > id_sett
Definition: cpp_scope.h:28
void lookup_rec(const irep_idt &base_name, lookup_kindt kind, id_sett &)
Definition: cpp_scope.cpp:27
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind)
Definition: cpp_scope.h:32
cpp_idt & insert(const irep_idt &_base_name)
Definition: cpp_scope.h:52
bool is_root_scope() const
Definition: cpp_scope.h:77
bool contains(const irep_idt &base_name_to_lookup)
Definition: cpp_scope.cpp:201
void add_secondary_scope(cpp_scopet &other)
Definition: cpp_scope.h:103
cpp_scopet & get_global_scope()
Definition: cpp_scope.h:93
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
C++ Language Type Checking.
std::ostream & operator<<(std::ostream &out, cpp_scopet::lookup_kindt)
Definition: cpp_scope.cpp:14
#define PRECONDITION(CONDITION)
Definition: invariant.h:463