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  void lookup(
33  const irep_idt &base_name,
34  lookup_kindt kind,
35  id_sett &id_set);
36 
37  void lookup(
38  const irep_idt &base_name,
39  lookup_kindt kind,
41  id_sett &id_set);
42 
43  void lookup_identifier(
44  const irep_idt &identifier,
45  cpp_idt::id_classt id_class,
46  id_sett &id_set);
47 
48  cpp_idt &insert(const irep_idt &_base_name)
49  {
50  cpp_id_mapt::iterator it=
51  sub.insert(std::pair<irep_idt, cpp_idt>
52  (_base_name, cpp_idt()));
53 
54  it->second.base_name=_base_name;
55  it->second.set_parent(*this);
56 
57  return it->second;
58  }
59 
60  cpp_idt &insert(const cpp_idt &cpp_id)
61  {
62  cpp_id_mapt::iterator it=
63  sub.insert(std::pair<irep_idt, cpp_idt>
64  (cpp_id.base_name, cpp_id));
65 
66  it->second.set_parent(*this);
67 
68  return it->second;
69  }
70 
71  bool contains(const irep_idt &base_name);
72 
73  bool is_root_scope() const
74  {
75  return id_class==id_classt::ROOT_SCOPE;
76  }
77 
78  bool is_global_scope() const
79  {
80  return id_class==id_classt::ROOT_SCOPE ||
81  id_class==id_classt::NAMESPACE;
82  }
83 
84  bool is_template_scope() const
85  {
86  return id_class==id_classt::TEMPLATE_SCOPE;
87  }
88 
90  {
91  return static_cast<cpp_scopet &>(cpp_idt::get_parent());
92  }
93 
95  {
96  cpp_scopet *p=this;
97 
98  while(!p->is_global_scope())
99  p=&(p->get_parent());
100 
101  return *p;
102  }
103 
105  {
106  assert(other.is_scope);
107  secondary_scopes.push_back(&other);
108  }
109 
111  {
112  assert(other.is_scope);
113  using_scopes.push_back(&other);
114  }
115 
116  class cpp_scopet &new_scope(const irep_idt &new_scope_name);
117 };
118 
120 {
121 public:
123  {
125  identifier="::";
126  }
127 };
128 
129 std::ostream &operator << (std::ostream &out, cpp_scopet::lookup_kindt);
130 
131 #endif // CPROVER_CPP_CPP_SCOPE_H
cpp_id_mapt sub
Definition: cpp_id.h:105
void lookup(const irep_idt &base_name, lookup_kindt kind, id_sett &id_set)
Definition: cpp_scope.cpp:29
cpp_idt & get_parent() const
Definition: cpp_id.h:83
cpp_scopet()
Definition: cpp_scope.h:23
class cpp_scopet & new_scope(const irep_idt &new_scope_name)
Definition: cpp_scope.cpp:200
cpp_scopet & get_parent() const
Definition: cpp_scope.h:89
void add_secondary_scope(cpp_scopet &other)
Definition: cpp_scope.h:104
C++ Language Type Checking.
bool is_scope
Definition: cpp_id.h:48
cpp_idt & insert(const cpp_idt &cpp_id)
Definition: cpp_scope.h:60
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
bool is_global_scope() const
Definition: cpp_scope.h:78
cpp_idt()
Definition: cpp_id.cpp:18
bool contains(const irep_idt &base_name)
Definition: cpp_scope.cpp:212
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:73
cpp_idt & insert(const irep_idt &_base_name)
Definition: cpp_scope.h:48
std::set< cpp_idt * > id_sett
Definition: cpp_scope.h:28
cpp_scopet & get_global_scope()
Definition: cpp_scope.h:94
bool is_template_scope() const
Definition: cpp_scope.h:84
void lookup_identifier(const irep_idt &identifier, cpp_idt::id_classt id_class, id_sett &id_set)
Definition: cpp_scope.cpp:172
void add_using_scope(cpp_scopet &other)
Definition: cpp_scope.h:110