MCPcopy Create free account
hub / github.com/argotorg/solidity / findSimplification

Method findSimplification

libyul/optimiser/NameSimplifier.cpp:78–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78void NameSimplifier::findSimplification(YulName const& _name)
79{
80 if (m_translations.count(_name))
81 return;
82
83 std::string name = _name.str();
84
85 static auto replacements = std::vector<std::pair<std::regex, std::string>>{
86 {std::regex("_\\$|\\$_"), "_"}, // remove type mangling delimiters
87 {std::regex("_[0-9]+([^0-9a-fA-Fx])"), "$1"}, // removes AST IDs that are not hex.
88 {std::regex("_[0-9]+$"), ""}, // removes AST IDs that are not hex.
89 {std::regex("_t_"), "_"}, // remove type prefixes
90 {std::regex("__"), "_"},
91 {std::regex("(abi_..code.*)_to_.*"), "$1"}, // removes _to... for abi functions
92 {std::regex("(stringliteral_?[0-9a-f][0-9a-f][0-9a-f][0-9a-f])[0-9a-f]*"), "$1"}, // shorten string literal
93 {std::regex("tuple_"), ""},
94 {std::regex("_memory_ptr"), ""},
95 {std::regex("_calldata_ptr"), "_calldata"},
96 {std::regex("_fromStack"), ""},
97 {std::regex("_storage_storage"), "_storage"},
98 {std::regex("(storage.*)_?storage"), "$1"},
99 {std::regex("_memory_memory"), "_memory"},
100 {std::regex("_contract\\$_([^_]*)_?"), "$1_"},
101 {std::regex("index_access_(t_)?array"), "index_access"},
102 {std::regex("[0-9]*_$"), ""}
103 };
104
105 for (auto const& [pattern, substitute]: replacements)
106 {
107 std::string candidate = regex_replace(name, pattern, substitute);
108 if (!candidate.empty() && !m_context.dispenser.illegalName(YulName(candidate)))
109 name = candidate;
110 }
111
112 if (name != _name.str())
113 {
114 YulName newName{name};
115 m_context.dispenser.markUsed(newName);
116 m_translations[_name] = std::move(newName);
117 }
118}
119
120void NameSimplifier::translate(YulName& _name)
121{

Callers

nothing calls this directly

Calls 6

regex_replaceFunction · 0.85
strMethod · 0.80
illegalNameMethod · 0.80
countMethod · 0.45
emptyMethod · 0.45
markUsedMethod · 0.45

Tested by

no test coverage detected