cprover
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 if(e.id() == ID_next_symbol)
46 {
47 const irep_idt &identifier=e.get(ID_identifier);
48
49 const symbolt &symbol=ns.lookup(identifier);
50
51 if(symbol.is_macro)
52 {
53 // inserted?
54 if(dest.insert(identifier).second)
55 stack.push(&symbol.value);
56 }
57 }
58 else
59 {
60 forall_operands(it, e)
61 stack.push(&(*it));
62 }
63 }
64}
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
const irep_idt & get(const irep_idt &name) const
Definition: irep.cpp:45
const irep_idt & id() const
Definition: irep.h:396
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().
Definition: namespace.cpp:138
const irep_idt & get_identifier() const
Definition: std_expr.h:109
Symbol table entry.
Definition: symbol.h:28
bool is_macro
Definition: symbol.h:61
exprt value
Initial value of symbol.
Definition: symbol.h:34
#define forall_operands(it, expr)
Definition: expr.h:18
void find_macros(const exprt &src, const namespacet &ns, find_macros_sett &dest)
Definition: find_macros.cpp:17
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:189
Symbol table entry.