CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
find_macros.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#include "find_macros.h"
10
11#include <stack>
12
13#include "namespace.h"
14#include "std_expr.h"
15#include "symbol.h"
16
18 const exprt &src,
19 const namespacet &ns,
20 find_macros_sett &dest)
21{
22 std::stack<const exprt *> stack;
23
24 // use stack, these may be nested deeply
25 stack.push(&src);
26
27 while(!stack.empty())
28 {
29 const exprt &e=*stack.top();
30 stack.pop();
31
32 if(e.id() == ID_symbol)
33 {
34 const irep_idt &identifier = to_symbol_expr(e).get_identifier();
35
36 const symbolt &symbol = ns.lookup(identifier);
37
38 if(symbol.is_macro)
39 {
40 // inserted?
41 if(dest.insert(identifier).second)
42 stack.push(&symbol.value);
43 }
44 }
45 else
46 {
47 for(const auto &op : e.operands())
48 stack.push(&op);
49 }
50 }
51}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
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
operandst & operands()
Definition expr.h:94
const irep_idt & id() const
Definition irep.h:388
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Symbol table entry.
Definition symbol.h:28
bool is_macro
Definition symbol.h:62
exprt value
Initial value of symbol.
Definition symbol.h:34
void find_macros(const exprt &src, const namespacet &ns, find_macros_sett &dest)
std::unordered_set< irep_idt > find_macros_sett
Definition find_macros.h:20
API to expression classes.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition std_expr.h:272
Symbol table entry.