Handle externally supplied variables correctly in disambiguator.

This commit is contained in:
chriseth 2018-01-19 17:23:49 +01:00
parent 5e01d767d0
commit 16c2a775fd
3 changed files with 13 additions and 4 deletions

View File

@ -34,6 +34,9 @@ using Scope = dev::solidity::assembly::Scope;
string Disambiguator::translateIdentifier(string const& _originalName)
{
if ((m_externallyUsedIdentifiers.count(_originalName)))
return _originalName;
assertThrow(!m_scopes.empty() && m_scopes.back(), OptimizerException, "");
Scope::Identifier const* id = m_scopes.back()->lookup(_originalName);
assertThrow(id, OptimizerException, "");

View File

@ -43,9 +43,14 @@ namespace yul
class Disambiguator: public ASTCopier
{
public:
Disambiguator(solidity::assembly::AsmAnalysisInfo const& _analysisInfo):
m_info(_analysisInfo)
{}
explicit Disambiguator(
solidity::assembly::AsmAnalysisInfo const& _analysisInfo,
std::set<std::string> const& _externallyUsedIdentifiers = {}
):
m_info(_analysisInfo), m_externallyUsedIdentifiers(_externallyUsedIdentifiers)
{
m_nameDispenser.m_usedNames = m_externallyUsedIdentifiers;
}
protected:
virtual void enterScope(Block const& _block) override;
@ -58,6 +63,7 @@ protected:
void leaveScopeInternal(solidity::assembly::Scope& _scope);
solidity::assembly::AsmAnalysisInfo const& m_info;
std::set<std::string> const& m_externallyUsedIdentifiers;
std::vector<solidity::assembly::Scope*> m_scopes;
std::map<void const*, std::string> m_translations;

View File

@ -86,7 +86,7 @@ pair<shared_ptr<Block>, shared_ptr<assembly::AsmAnalysisInfo>> dev::yul::test::p
assembly::Block dev::yul::test::disambiguate(string const& _source, bool _yul)
{
auto result = parse(_source, _yul);
return boost::get<Block>(Disambiguator(*result.second)(*result.first));
return boost::get<Block>(Disambiguator(*result.second, {})(*result.first));
}
string dev::yul::test::format(string const& _source, bool _yul)