CBMC
find_macros.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: 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 }
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:384
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Definition: namespace.cpp:148
const irep_idt & get_identifier() const
Definition: std_expr.h:160
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)
Definition: find_macros.cpp:17
std::unordered_set< irep_idt > find_macros_sett
Definition: find_macros.h:18
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.