cprover
cpp_id.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_ID_H
13 #define CPROVER_CPP_CPP_ID_H
14 
15 #include <list>
16 #include <map>
17 #include <string>
18 #include <set>
19 #include <iosfwd>
20 
21 #include <util/expr.h>
22 #include <util/invariant.h>
23 #include <util/std_types.h>
24 
25 class cpp_scopet;
26 
27 class cpp_idt
28 {
29 public:
30  cpp_idt();
31 
32  enum class id_classt
33  {
34  UNKNOWN,
35  SYMBOL,
36  TYPEDEF,
37  CLASS,
38  ENUM,
39  TEMPLATE,
41  NAMESPACE,
44  ROOT_SCOPE,
45  };
46 
49 
51 
52  bool is_class() const
53  {
54  return id_class==id_classt::CLASS;
55  }
56 
57  bool is_enum() const
58  {
59  return id_class==id_classt::ENUM;
60  }
61 
62  bool is_namespace() const
63  {
65  }
66 
67  bool is_typedef() const
68  {
70  }
71 
72  bool is_template_scope() const
73  {
75  }
76 
78 
79  // if it is a member or method, what class is it in?
82 
83  // scope data
84  std::string prefix, suffix;
85  unsigned compound_counter;
86 
88  {
89  PRECONDITION(parent!=nullptr);
90  return *parent;
91  }
92 
93  void set_parent(cpp_idt &_parent)
94  {
95  assert(_parent.is_scope);
96  parent=&_parent;
97  }
98 
99  void clear()
100  {
101  *this=cpp_idt();
102  }
103 
104  void print(std::ostream &out, unsigned indent=0) const;
105  void print_fields(std::ostream &out, unsigned indent=0) const;
106 
107 protected:
108  typedef std::multimap<irep_idt, cpp_idt> cpp_id_mapt;
110 
111  // These are used for base classes and 'using' clauses.
112  typedef std::vector<cpp_idt *> scope_listt;
115 };
116 
117 std::ostream &operator<<(std::ostream &out, const cpp_idt &cpp_id);
118 std::ostream &operator<<(std::ostream &out, const cpp_idt::id_classt &id_class);
119 
120 #endif // CPROVER_CPP_CPP_ID_H
Definition: cpp_id.h:28
std::multimap< irep_idt, cpp_idt > cpp_id_mapt
Definition: cpp_id.h:108
irep_idt identifier
Definition: cpp_id.h:77
bool is_member
Definition: cpp_id.h:47
exprt this_expr
Definition: cpp_id.h:81
void clear()
Definition: cpp_id.h:99
scope_listt using_scopes
Definition: cpp_id.h:113
std::string prefix
Definition: cpp_id.h:84
cpp_idt & get_parent() const
Definition: cpp_id.h:87
bool is_namespace() const
Definition: cpp_id.h:62
bool is_scope
Definition: cpp_id.h:48
id_classt
Definition: cpp_id.h:33
bool is_typedef() const
Definition: cpp_id.h:67
cpp_id_mapt sub
Definition: cpp_id.h:109
id_classt id_class
Definition: cpp_id.h:50
void print(std::ostream &out, unsigned indent=0) const
Definition: cpp_id.cpp:33
bool is_constructor
Definition: cpp_id.h:48
bool is_method
Definition: cpp_id.h:47
bool is_template_scope() const
Definition: cpp_id.h:72
cpp_idt()
Definition: cpp_id.cpp:20
bool is_static_member
Definition: cpp_id.h:47
bool is_class() const
Definition: cpp_id.h:52
void print_fields(std::ostream &out, unsigned indent=0) const
Definition: cpp_id.cpp:46
void set_parent(cpp_idt &_parent)
Definition: cpp_id.h:93
scope_listt secondary_scopes
Definition: cpp_id.h:113
bool is_enum() const
Definition: cpp_id.h:57
std::vector< cpp_idt * > scope_listt
Definition: cpp_id.h:112
unsigned compound_counter
Definition: cpp_id.h:85
irep_idt class_identifier
Definition: cpp_id.h:80
irep_idt base_name
Definition: cpp_id.h:77
std::string suffix
Definition: cpp_id.h:84
cpp_idt * parent
Definition: cpp_id.h:114
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
Base class for all expressions.
Definition: expr.h:54
std::ostream & operator<<(std::ostream &out, const cpp_idt &cpp_id)
Definition: cpp_id.cpp:94
#define PRECONDITION(CONDITION)
Definition: invariant.h:464
Pre-defined types.