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 <string>
12 
13 #include "symbol.h"
14 #include "namespace.h"
15 
19 void get_new_name(symbolt &symbol, const namespacet &ns)
20 {
21  get_new_name(symbol.name, ns);
22 }
23 
27 void get_new_name(irep_idt &new_name, const namespacet &ns, char delimiter)
28 {
29  const symbolt *symbol;
30  if(ns.lookup(new_name, symbol))
31  return; // name not taken yet
32 
33  std::string prefix = id2string(new_name) + delimiter;
34 
35  new_name = prefix + std::to_string(ns.smallest_unused_suffix(prefix));
36 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
get_new_name
void get_new_name(symbolt &symbol, const namespacet &ns)
automated variable renaming
Definition: rename.cpp:19
to_string
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Definition: string_constraint.cpp:55
namespace.h
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:92
namespacet::lookup
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Definition: namespace.cpp:140
namespacet::smallest_unused_suffix
std::size_t smallest_unused_suffix(const std::string &prefix) const override
See documentation for namespace_baset::smallest_unused_suffix().
Definition: namespace.cpp:122
rename.h
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
symbol.h
Symbol table entry.
symbolt
Symbol table entry.
Definition: symbol.h:28
symbolt::name
irep_idt name
The unique identifier.
Definition: symbol.h:40