CBMC
Loading...
Searching...
No Matches
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 <cstdint>
14#include <iomanip>
15#include <sstream>
16
18operator()(const symbolt &src, const std::string &extra_info)
19{
20 std::string basename = get_base_name(src.location.get_file().c_str(), false);
21
22 std::stringstream ss;
24 ss << std::regex_replace(
25 std::regex_replace(basename, forbidden, "_"), multi_under, "_")
26 << "_";
27
28 if(extra_info != "")
29 ss << extra_info << "_";
30 ss << src.name;
31 return irep_idt(ss.str());
32}
33
35operator()(const symbolt &src, const std::string &extra_info)
36{
37 char const *str = src.location.get_working_directory().c_str();
38 unsigned long hash = 5381;
39 int c;
40 while((c = *str++))
41 hash = ((hash << 5) + hash) + c;
42
44
45 std::stringstream ss;
46 ss << FILE_LOCAL_PREFIX << std::setfill('0') << std::setw(8) << std::hex
47 << eight_nibble_hash << "_" << extra_info << "_" << src.name;
48 return irep_idt(ss.str());
49}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
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:38
irep_idt operator()(const symbolt &, const std::string &)
const std::regex multi_under
const std::regex forbidden
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
Mangle names of file-local functions to make them unique.
#define FILE_LOCAL_PREFIX
dstringt irep_idt