From 81569f720883735ee6eee0a16173df63d2180d12 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Jan 2020 19:13:25 +0100 Subject: [PATCH] Remove Scope::Label. --- libyul/AsmAnalysis.cpp | 12 ---------- libyul/AsmScope.cpp | 8 ------- libyul/AsmScope.h | 5 +--- libyul/backends/evm/EVMCodeTransform.cpp | 30 ------------------------ libyul/backends/evm/EVMCodeTransform.h | 4 ---- 5 files changed, 1 insertion(+), 58 deletions(-) diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 5a88671ce..148eeabfe 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -123,10 +123,6 @@ bool AsmAnalyzer::operator()(Identifier const& _identifier) } ++m_stackHeight; }, - [&](Scope::Label const&) - { - ++m_stackHeight; - }, [&](Scope::Function const&) { m_errorReporter.typeError( @@ -293,14 +289,6 @@ bool AsmAnalyzer::operator()(FunctionCall const& _funCall) ); success = false; }, - [&](Scope::Label const&) - { - m_errorReporter.typeError( - _funCall.functionName.location, - "Attempt to call label instead of function." - ); - success = false; - }, [&](Scope::Function const& _fun) { /// TODO: compare types too diff --git a/libyul/AsmScope.cpp b/libyul/AsmScope.cpp index ae39fc10d..86dbce483 100644 --- a/libyul/AsmScope.cpp +++ b/libyul/AsmScope.cpp @@ -25,14 +25,6 @@ using namespace solidity; using namespace solidity::yul; using namespace solidity::util; -bool Scope::registerLabel(YulString _name) -{ - if (exists(_name)) - return false; - identifiers[_name] = Label(); - return true; -} - bool Scope::registerVariable(YulString _name, YulType const& _type) { if (exists(_name)) diff --git a/libyul/AsmScope.h b/libyul/AsmScope.h index a452e04ba..6da1ff1e0 100644 --- a/libyul/AsmScope.h +++ b/libyul/AsmScope.h @@ -37,20 +37,17 @@ namespace solidity::yul struct Scope { using YulType = YulString; - using LabelID = size_t; struct Variable { YulType type; }; - struct Label { }; struct Function { std::vector arguments; std::vector returns; }; - using Identifier = std::variant; + using Identifier = std::variant; bool registerVariable(YulString _name, YulType const& _type); - bool registerLabel(YulString _name); bool registerFunction( YulString _name, std::vector _arguments, diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index 9f95d1257..f8ce12017 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -88,7 +88,6 @@ void VariableReferenceCounter::increaseRefIfFound(YulString _variableName) { ++m_context.variableReferences[&_var]; }, - [=](Scope::Label const&) { }, [=](Scope::Function const&) { } }); } @@ -286,7 +285,6 @@ void CodeTransform::operator()(FunctionCall const& _call) Scope::Function* function = nullptr; yulAssert(m_scope->lookup(_call.functionName.name, GenericVisitor{ [=](Scope::Variable&) { yulAssert(false, "Expected function name."); }, - [=](Scope::Label&) { yulAssert(false, "Expected function name."); }, [&](Scope::Function& _function) { function = &_function; } }), "Function name not found."); yulAssert(function, ""); @@ -323,10 +321,6 @@ void CodeTransform::operator()(Identifier const& _identifier) m_assembly.appendConstant(u256(0)); decreaseReference(_identifier.name, _var); }, - [=](Scope::Label& _label) - { - m_assembly.appendLabelReference(labelID(_label)); - }, [=](Scope::Function&) { yulAssert(false, "Function not removed during desugaring."); @@ -634,30 +628,6 @@ void CodeTransform::operator()(Block const& _block) BOOST_THROW_EXCEPTION(m_stackErrors.front()); } -AbstractAssembly::LabelID CodeTransform::labelFromIdentifier(Identifier const& _identifier) -{ - AbstractAssembly::LabelID label = AbstractAssembly::LabelID(-1); - if (!m_scope->lookup(_identifier.name, GenericVisitor{ - [=](Scope::Variable&) { yulAssert(false, "Expected label"); }, - [&](Scope::Label& _label) - { - label = labelID(_label); - }, - [=](Scope::Function&) { yulAssert(false, "Expected label"); } - })) - { - yulAssert(false, "Identifier not found."); - } - return label; -} - -AbstractAssembly::LabelID CodeTransform::labelID(Scope::Label const& _label) -{ - if (!m_context->labelIDs.count(&_label)) - m_context->labelIDs[&_label] = m_assembly.newLabelId(); - return m_context->labelIDs[&_label]; -} - AbstractAssembly::LabelID CodeTransform::functionEntryID(YulString _name, Scope::Function const& _function) { if (!m_context->functionEntryIDs.count(&_function)) diff --git a/libyul/backends/evm/EVMCodeTransform.h b/libyul/backends/evm/EVMCodeTransform.h index 2c2c5991d..fb50be95f 100644 --- a/libyul/backends/evm/EVMCodeTransform.h +++ b/libyul/backends/evm/EVMCodeTransform.h @@ -53,7 +53,6 @@ struct StackTooDeepError: virtual YulException struct CodeTransformContext { - std::map labelIDs; std::map functionEntryIDs; std::map variableStackHeights; std::map variableReferences; @@ -187,9 +186,6 @@ public: private: AbstractAssembly::LabelID labelFromIdentifier(Identifier const& _identifier); - /// @returns the label ID corresponding to the given label, allocating a new one if - /// necessary. - AbstractAssembly::LabelID labelID(Scope::Label const& _label); AbstractAssembly::LabelID functionEntryID(YulString _name, Scope::Function const& _function); /// Generates code for an expression that is supposed to return a single value. void visitExpression(Expression const& _expression);