Added a helper class FunctionCopier in ASTCopier

Helper class that creates a copy of the function definition, replacing the names of the variable
declaration with a new name.
This commit is contained in:
hrkrshnn 2020-12-11 16:44:38 +01:00
parent b42fc2015c
commit 8564d08228
2 changed files with 24 additions and 0 deletions

View File

@ -171,3 +171,9 @@ TypedName ASTCopier::translate(TypedName const& _typedName)
return TypedName{_typedName.location, translateIdentifier(_typedName.name), _typedName.type}; return TypedName{_typedName.location, translateIdentifier(_typedName.name), _typedName.type};
} }
YulString FunctionCopier::translateIdentifier(YulString _name)
{
if (m_translations.count(_name))
return m_translations.at(_name);
return _name;
}

View File

@ -29,6 +29,7 @@
#include <optional> #include <optional>
#include <set> #include <set>
#include <vector> #include <vector>
#include <map>
namespace solidity::yul namespace solidity::yul
{ {
@ -117,5 +118,22 @@ std::vector<T> ASTCopier::translateVector(std::vector<T> const& _values)
return translated; return translated;
} }
/// Helper class that creates a copy of the function definition, replacing the names of the variable
/// declarations with new names.
class FunctionCopier: public ASTCopier
{
public:
FunctionCopier(
std::map<YulString, YulString> const& _translations
):
m_translations(_translations)
{}
using ASTCopier::operator();
YulString translateIdentifier(YulString _name) override;
private:
/// A mapping between old and new names. We replace the names of variable declarations contained
/// in the mapping with their new names.
std::map<YulString, YulString> const& m_translations;
};
} }