cprover
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 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 }
Symbol table entry.
const irep_idt & get_identifier() const
Definition: std_expr.h:128
exprt value
Initial value of symbol.
Definition: symbol.h:37
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:30
const irep_idt & id() const
Definition: irep.h:189
API to expression classes.
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:213
TO_BE_DOCUMENTED.
Definition: namespace.h:74
#define forall_operands(it, expr)
Definition: expr.h:17
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
Definition: std_expr.h:210
std::unordered_set< irep_idt > find_macros_sett
Definition: find_macros.h:18
Base class for all expressions.
Definition: expr.h:42
#define stack(x)
Definition: parser.h:144
void find_macros(const exprt &src, const namespacet &ns, find_macros_sett &dest)
Definition: find_macros.cpp:17
bool is_macro
Definition: symbol.h:63
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See namespace_baset::lookup().
Definition: namespace.cpp:130