mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
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:
parent
b42fc2015c
commit
8564d08228
@ -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;
|
||||||
|
}
|
||||||
|
@ -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;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user