CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
namespace.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9
10#ifndef CPROVER_UTIL_NAMESPACE_H
11#define CPROVER_UTIL_NAMESPACE_H
12
13#include "invariant.h"
14#include "irep.h"
15
16class exprt;
17class symbolt;
18class typet;
19class symbol_exprt;
20class tag_typet;
21class union_typet;
22class struct_typet;
24class c_enum_typet;
25class union_tag_typet;
30
36{
37public:
38 // service methods
39
45 const symbolt &lookup(const irep_idt &name) const
46 {
47 const symbolt *symbol;
48 bool not_found = lookup(name, symbol);
50 !not_found,
51 "we are assuming that a name exists in the namespace "
52 "when this function is called - identifier " +
53 id2string(name) + " was not found");
54 return *symbol;
55 }
56
57 const symbolt &lookup(const symbol_exprt &) const;
58 const symbolt &lookup(const tag_typet &) const;
59
60 virtual ~namespace_baset();
61
62 void follow_macros(exprt &) const;
63
64 const union_typet &follow_tag(const union_tag_typet &) const;
65 const struct_typet &follow_tag(const struct_tag_typet &) const;
66 const c_enum_typet &follow_tag(const c_enum_tag_typet &) const;
68
73 virtual std::size_t
74 smallest_unused_suffix(const std::string &prefix) const = 0;
75
82 virtual bool lookup(const irep_idt &name, const symbolt *&symbol) const=0;
83};
84
91{
92public:
93 // constructors
96
104
112
114
117 bool lookup(const irep_idt &name, const symbolt *&symbol) const override;
118
120 std::size_t smallest_unused_suffix(const std::string &prefix) const override;
121
124 {
125 return *symbol_table1;
126 }
127
128protected:
130};
131
137{
138public:
139 // constructors
143
144 explicit multi_namespacet(const symbol_table_baset &symbol_table)
146 {
147 add(symbol_table);
148 }
149
150 // these do the actual lookup
152
154 bool lookup(const irep_idt &name, const symbolt *&symbol) const override;
156 std::size_t smallest_unused_suffix(const std::string &prefix) const override;
157
162 void add(const symbol_table_baset &symbol_table)
163 {
164 symbol_table_list.push_back(&symbol_table);
165 }
166
167protected:
168 typedef std::vector<const symbol_table_baset *> symbol_table_listt;
170};
171
172#endif // CPROVER_UTIL_NAMESPACE_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
C enum tag type, i.e., c_enum_typet with an identifier.
Definition c_types.h:352
The type of C enums.
Definition c_types.h:239
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:56
A multi namespace is essentially a namespace, with a list of namespaces.
Definition namespace.h:137
void add(const symbol_table_baset &symbol_table)
Add symbol table to the list of symbol tables this multi-namespace is working with.
Definition namespace.h:162
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
multi_namespacet(const symbol_table_baset &symbol_table)
Definition namespace.h:144
std::size_t smallest_unused_suffix(const std::string &prefix) const override
See documentation for namespace_baset::smallest_unused_suffix().
symbol_table_listt symbol_table_list
Definition namespace.h:169
std::vector< const symbol_table_baset * > symbol_table_listt
Definition namespace.h:168
Basic interface for a namespace.
Definition namespace.h:36
const symbolt & lookup(const irep_idt &name) const
Lookup a symbol in the namespace.
Definition namespace.h:45
void follow_macros(exprt &) const
Follow macros to their values in a given expression.
Definition namespace.cpp:93
virtual bool lookup(const irep_idt &name, const symbolt *&symbol) const =0
Searches for a symbol named name.
virtual std::size_t smallest_unused_suffix(const std::string &prefix) const =0
Returns the minimal integer n such that there is no symbol (in any of the symbol tables) whose name i...
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
Definition namespace.cpp:49
virtual ~namespace_baset()
Definition namespace.cpp:20
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
const symbol_table_baset * symbol_table1
Definition namespace.h:129
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
namespacet(const symbol_table_baset &_symbol_table1, const symbol_table_baset &_symbol_table2)
Definition namespace.h:97
namespacet(const symbol_table_baset &_symbol_table)
Definition namespace.h:94
const symbol_table_baset & get_symbol_table() const
Return first symbol table registered with the namespace.
Definition namespace.h:123
const symbol_table_baset * symbol_table2
Definition namespace.h:129
std::size_t smallest_unused_suffix(const std::string &prefix) const override
See documentation for namespace_baset::smallest_unused_suffix().
namespacet(const symbol_table_baset *_symbol_table1, const symbol_table_baset *_symbol_table2)
Definition namespace.h:105
A struct or union tag type.
Definition std_types.h:451
A struct tag type, i.e., struct_typet with an identifier.
Definition std_types.h:493
Structure type, corresponds to C style structs.
Definition std_types.h:231
Base type for structs and unions.
Definition std_types.h:62
Expression to hold a symbol (variable)
Definition std_expr.h:131
The symbol table base class interface.
Symbol table entry.
Definition symbol.h:28
A tag-based type, i.e., typet with an identifier.
Definition std_types.h:396
The type of an expression, extends irept.
Definition type.h:29
A union tag type, i.e., union_typet with an identifier.
Definition c_types.h:199
The union type.
Definition c_types.h:147
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423