cprover
fresh_symbol.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Fresh auxiliary symbol creation
4 
5 Author: Chris Smowton, chris.smowton@diffblue.com
6 
7 \*******************************************************************/
8 
11 
12 #include "fresh_symbol.h"
13 
14 #include "invariant.h"
15 #include "namespace.h"
16 #include "rename.h"
17 #include "symbol.h"
18 #include "symbol_table_base.h"
19 
29  const typet &type,
30  const std::string &name_prefix,
31  const std::string &basename_prefix,
32  const source_locationt &source_location,
33  const irep_idt &symbol_mode,
34  symbol_table_baset &symbol_table)
35 {
36  namespacet ns(symbol_table);
37  irep_idt identifier = basename_prefix;
38  std::size_t prefix_size = 0;
39  if(!name_prefix.empty())
40  {
41  identifier = name_prefix + "::" + basename_prefix;
42  prefix_size = name_prefix.size() + 2;
43  }
44  get_new_name(identifier, ns, '$');
45  std::string basename = id2string(identifier).substr(prefix_size);
46 
47  auxiliary_symbolt new_symbol(basename, type);
48  new_symbol.name = identifier;
49  new_symbol.location = source_location;
50  new_symbol.mode = symbol_mode;
51  std::pair<symbolt &, bool> res = symbol_table.insert(std::move(new_symbol));
52  CHECK_RETURN(res.second);
53 
54  return res.first;
55 }
The type of an expression.
Definition: type.h:22
irep_idt name
The unique identifier.
Definition: symbol.h:43
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
Symbol table entry.
irep_idt mode
Language mode.
Definition: symbol.h:52
Fresh auxiliary symbol creation.
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:30
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:266
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
Definition: symbol.h:135
TO_BE_DOCUMENTED.
Definition: namespace.h:74
size_t size() const
Definition: dstring.h:89
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:40
symbolt & get_fresh_aux_symbol(const typet &type, const std::string &name_prefix, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &symbol_mode, symbol_table_baset &symbol_table)
Installs a fresh-named symbol with the requested name pattern.
Author: Diffblue Ltd.
The symbol table base class interface.
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
void get_new_name(symbolt &symbol, const namespacet &ns)
automated variable renaming
Definition: rename.cpp:19