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 "expr.h"
14 #include "namespace.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  e.id()==ID_next_symbol)
34  {
35  const irep_idt &identifier=e.get(ID_identifier);
36 
37  const symbolt &symbol=ns.lookup(identifier);
38 
39  if(symbol.is_macro)
40  {
41  // inserted?
42  if(dest.insert(identifier).second)
43  stack.push(&symbol.value);
44  }
45  }
46  else
47  {
48  forall_operands(it, e)
49  stack.push(&(*it));
50  }
51  }
52 }
virtual bool lookup(const irep_idt &name, const symbolt *&symbol) const
Definition: namespace.cpp:139
Symbol table entry.
exprt value
Initial value of symbol.
Definition: symbol.h:40
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:33
const irep_idt & id() const
Definition: irep.h:189
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:213
TO_BE_DOCUMENTED.
Definition: namespace.h:62
#define forall_operands(it, expr)
Definition: expr.h:17
Base class for all expressions.
Definition: expr.h:46
std::unordered_set< irep_idt, irep_id_hash > find_macros_sett
Definition: find_macros.h:18
#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:66