MCPcopy Create free account
hub / github.com/chigraph/chigraph / mangleFunctionName

Function mangleFunctionName

libchigraph/src/NameMangler.cpp:9–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8namespace chi {
9std::string mangleFunctionName(std::string modName, const std::string& name) {
10 // escape characters
11
12 // if it is the special main module, then just return main
13 if ((modName.substr(modName.rfind('/') + 1, modName.rfind('.')) == "main" ||
14 modName.substr(modName.rfind('\\') + 1, modName.rfind('.')) == "main") &&
15 name == "main") {
16 return "main";
17 }
18
19 // escape _
20 size_t id = modName.find('_');
21 while (id != std::string::npos) {
22 modName.replace(id, 1, "__");
23
24 id = modName.find('_', id + 2);
25 }
26
27 // escape /
28 id = modName.find('/');
29 while (id != std::string::npos) {
30 modName.replace(id, 1, "_s");
31
32 id = modName.find('/', id);
33 }
34
35 // escape .
36 id = modName.find('.');
37 while (id != std::string::npos) {
38 modName.replace(id, 1, "_d");
39
40 id = modName.find('.', id);
41 }
42
43 return modName + "_m" + name;
44}
45
46std::pair<std::string, std::string> unmangleFunctionName(std::string mangled) {
47 if (mangled == "main") { return {"main", "main"}; }

Callers 4

codegenMethod · 0.85
compileFunctionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected