cprover
name_mangler.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Name mangling
4
5Author: Kareem Khazem <karkhaz@karkhaz.com>, 2019
6
7\*******************************************************************/
8
9#include "name_mangler.h"
10
11#include <util/get_base_name.h>
12
13#include <iomanip>
14#include <sstream>
15
17operator()(const symbolt &src, const std::string &extra_info)
18{
19 std::string basename = get_base_name(src.location.get_file().c_str(), false);
20
21 std::stringstream ss;
23 ss << std::regex_replace(
24 std::regex_replace(basename, forbidden, "_"), multi_under, "_")
25 << "_";
26
27 if(extra_info != "")
28 ss << extra_info << "_";
29 ss << src.name;
30 return irep_idt(ss.str());
31}
32
34operator()(const symbolt &src, const std::string &extra_info)
35{
36 char const *str = src.location.get_working_directory().c_str();
37 unsigned long hash = 5381;
38 int c;
39 while((c = *str++))
40 hash = ((hash << 5) + hash) + c;
41
42 uint32_t eight_nibble_hash = (uint32_t)hash;
43
44 std::stringstream ss;
45 ss << FILE_LOCAL_PREFIX << std::setfill('0') << std::setw(8) << std::hex
46 << eight_nibble_hash << "_" << extra_info << "_" << src.name;
47 return irep_idt(ss.str());
48}
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.
Definition: dstring.h:37
const char * c_str() const
Definition: dstring.h:99
irep_idt operator()(const symbolt &, const std::string &)
const std::regex multi_under
Definition: name_mangler.h:154
const std::regex forbidden
Definition: name_mangler.h:153
const irep_idt & get_working_directory() const
const irep_idt & get_file() const
Symbol table entry.
Definition: symbol.h:28
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:37
irep_idt name
The unique identifier.
Definition: symbol.h:40
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
dstringt irep_idt
Definition: irep.h:37
Mangle names of file-local functions to make them unique.
#define FILE_LOCAL_PREFIX
Definition: name_mangler.h:16