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