cprover
rename.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 "rename.h"
10 
11 #include <algorithm>
12 
13 #include "symbol.h"
14 #include "expr.h"
15 #include "namespace.h"
16 
20 void get_new_name(symbolt &symbol, const namespacet &ns)
21 {
22  get_new_name(symbol.name, ns);
23 }
24 
28 void get_new_name(irep_idt &new_name, const namespacet &ns)
29 {
30  const symbolt *symbol;
31  if(ns.lookup(new_name, symbol))
32  return;
33 
34  std::string prefix=id2string(new_name)+"_";
35 
36  new_name=prefix+std::to_string(ns.get_max(prefix)+1);
37 }
38 
42 bool rename(exprt &expr, const irep_idt &old_name,
43  const irep_idt &new_name)
44 {
45  bool result=true;
46 
47  if(expr.id()==ID_symbol)
48  {
49  if(expr.get(ID_identifier)==old_name)
50  {
51  expr.set(ID_identifier, new_name);
52  result=false;
53  }
54  }
55  else
56  {
57  if(expr.id()==ID_address_of)
58  {
59  // TODO
60  }
61  else
62  Forall_operands(it, expr)
63  if(!rename(*it, old_name, new_name))
64  result=false;
65  }
66 
67  return result;
68 }
irep_idt name
The unique identifier.
Definition: symbol.h:46
virtual bool lookup(const irep_idt &name, const symbolt *&symbol) const
Definition: namespace.cpp:139
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
Symbol table entry.
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
bool rename(exprt &expr, const irep_idt &old_name, const irep_idt &new_name)
automated variable renaming
Definition: rename.cpp:42
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:213
TO_BE_DOCUMENTED.
Definition: namespace.h:62
Base class for all expressions.
Definition: expr.h:46
#define Forall_operands(it, expr)
Definition: expr.h:23
void get_new_name(symbolt &symbol, const namespacet &ns)
automated variable renaming
Definition: rename.cpp:20
virtual unsigned get_max(const std::string &prefix) const
Definition: namespace.cpp:126
void set(const irep_namet &name, const irep_idt &value)
Definition: irep.h:214