mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
NameDispenser: Added three public functions.
The private function `illegalName` was converted into a public function. A new public getter function `usedNames()` returns a reference to `m_usedNames`. A public function reset that would change all `m_usedNames` to *only* the names that are used in the AST. Also resets the counter. This will be used before the final NameSimplifier step in the optimization phase. The first two functions were added so that `NameSimplifier` could use it instead of traversing the AST using `NameCollector` to find used names.
This commit is contained in:
parent
e8843fe1d3
commit
cf6fe5a777
@ -35,8 +35,9 @@ using namespace solidity::yul;
|
||||
using namespace solidity::util;
|
||||
|
||||
NameDispenser::NameDispenser(Dialect const& _dialect, Block const& _ast, set<YulString> _reservedNames):
|
||||
NameDispenser(_dialect, NameCollector(_ast).names() + std::move(_reservedNames))
|
||||
NameDispenser(_dialect, NameCollector(_ast).names() + _reservedNames)
|
||||
{
|
||||
m_reservedNames = move(_reservedNames);
|
||||
}
|
||||
|
||||
NameDispenser::NameDispenser(Dialect const& _dialect, set<YulString> _usedNames):
|
||||
@ -61,3 +62,9 @@ bool NameDispenser::illegalName(YulString _name)
|
||||
{
|
||||
return isRestrictedIdentifier(m_dialect, _name) || m_usedNames.count(_name);
|
||||
}
|
||||
|
||||
void NameDispenser::reset(Block const& _ast)
|
||||
{
|
||||
m_usedNames = NameCollector(_ast).names() + m_reservedNames;
|
||||
m_counter = 0;
|
||||
}
|
||||
|
@ -51,11 +51,19 @@ public:
|
||||
/// return it.
|
||||
void markUsed(YulString _name) { m_usedNames.insert(_name); }
|
||||
|
||||
private:
|
||||
std::set<YulString> const& usedNames() { return m_usedNames; }
|
||||
|
||||
/// Returns true if `_name` is either used or is a restricted identifier.
|
||||
bool illegalName(YulString _name);
|
||||
|
||||
/// Resets `m_usedNames` with *only* the names that are used in the AST. Also resets value of
|
||||
/// `m_counter` to zero.
|
||||
void reset(Block const& _ast);
|
||||
|
||||
private:
|
||||
Dialect const& m_dialect;
|
||||
std::set<YulString> m_usedNames;
|
||||
std::set<YulString> m_reservedNames;
|
||||
size_t m_counter = 0;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user