/* This file is part of solidity. solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with solidity. If not, see . */ #pragma once #include #include #include #include #include #include namespace yul { struct Dialect; /** * Pass to normalize identifier suffixes. * * That is, for each function scope, nested suffixes get flattened and all suffixes * renumbered by their base name. * Function names are not modified. * * Prerequisites: Disambiguator, FunctionHoister */ class VarNameCleaner: public ASTModifier { public: VarNameCleaner( Block const& _ast, Dialect const& _dialect, std::set _blacklist = {} ); using ASTModifier::operator(); void operator()(VariableDeclaration& _varDecl) override; void operator()(Identifier& _identifier) override; void operator()(FunctionDefinition& _funDef) override; private: /// Tries to rename a list of variables. void renameVariables(std::vector& _variables); /// @returns suffix-stripped name, if a suffix was detected, none otherwise. YulString stripSuffix(YulString const& _name) const; /// Looks out for a "clean name" the given @p name could be trimmed down to. /// @returns a trimmed down and "clean name" in case it found one, none otherwise. YulString findCleanName(YulString const& name) const; /// Tests whether a given name was already used within this pass /// or is on the blacklist. bool isUsedName(YulString const& _name) const; Dialect const& m_dialect; std::set m_blacklist; /// Set of names that are in use. std::set m_usedNames; /// Maps old to new names. std::map m_translatedNames; /// Whether the traverse is inside a function definition. /// Used to assert that a function definition cannot be inside another. bool m_insideFunction = false; }; }