5 #ifndef CPROVER_GOTO_PROGRAMS_NAME_MANGLER_H
6 #define CPROVER_GOTO_PROGRAMS_NAME_MANGLER_H
16 #define FILE_LOCAL_PREFIX CPROVER_PREFIX "file_local_"
29 template <
class MangleFun>
52 std::map<irep_idt, irep_idt> renamed_funs;
53 std::vector<symbolt> new_syms;
54 std::vector<symbol_tablet::symbolst::const_iterator> old_syms;
60 const symbolt &sym = sym_it->second;
62 if(sym.
type.
id() != ID_code)
71 new_sym.
name = mangled;
77 new_syms.push_back(new_sym);
78 old_syms.push_back(sym_it);
81 renamed_funs.insert(std::make_pair(sym.
name, mangled));
86 for(
const auto &sym : new_syms)
88 for(
const auto &sym : old_syms)
94 const symbolt &sym = it->second;
98 if(rename(e) && rename(t))
101 symbolt &new_sym = it.get_writeable_symbol();
108 if(!fun.second.body_available())
110 for(
auto &ins : fun.second.body.instructions)
112 rename(ins.code_nonconst());
113 if(ins.has_condition())
114 rename(ins.condition_nonconst());
119 for(
const auto &pair : renamed_funs)
124 "There should exist an entry in the function_map for the original name "
125 "of the function that we renamed '" +
126 std::string(pair.first.c_str()) +
"'");
129 pair.second, std::move(found->second));
131 log.
debug() <<
"Found a mangled name that already exists: "
132 << std::string(pair.second.c_str()) <<
log.
eom;
150 :
forbidden(
"[^\\w]", std::regex::ECMAScript),
Mangle identifiers by hashing their working directory with djb2 hash.
irep_idt operator()(const symbolt &, const std::string &)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
Mangle identifiers by including their filename.
irep_idt operator()(const symbolt &, const std::string &)
const std::regex multi_under
const std::regex forbidden
Mangles the names in an entire program and its symbol table.
void mangle()
Mangle all file-local function symbols in the program.
const std::string & extra_info
function_name_manglert(message_handlert &mh, goto_modelt &gm, const std::string &extra_info)
function_mapt function_map
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
const irep_idt & id() const
Class that provides messages with a built-in verbosity 'level'.
void insert(const class symbol_exprt &old_expr, const class symbol_exprt &new_expr)
const symbolst & symbols
Read-only field, used to look up symbols given their names.
virtual void erase(const symbolst::const_iterator &entry) override
Remove a symbol from the symbol table.
virtual iteratort begin() override
virtual iteratort end() override
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
irep_idt base_name
Base (non-scoped) name.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
irep_idt pretty_name
Language-specific display name.
exprt value
Initial value of symbol.
The type of an expression, extends irept.