diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index f684bc289..43e07a8fe 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -49,7 +49,7 @@ public: void operator()(yul::Identifier const&) {} void operator()(yul::ExpressionStatement const& _expr) { - std::visit(*this, _expr.expression); + (*this)(_expr.expression); } void operator()(yul::Assignment const& _assignment) { diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 631d0881c..3d0132c7a 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -163,7 +163,7 @@ vector AsmAnalyzer::operator()(Identifier const& _identifier) void AsmAnalyzer::operator()(ExpressionStatement const& _statement) { auto watcher = m_errorReporter.errorWatcher(); - vector types = std::visit(*this, _statement.expression); + vector types = (*this)(_statement.expression); if (watcher.ok() && !types.empty()) m_errorReporter.typeError( 3083_error, diff --git a/libyul/AsmData.h b/libyul/AsmData.h index c4040f320..ecd338e37 100644 --- a/libyul/AsmData.h +++ b/libyul/AsmData.h @@ -52,7 +52,7 @@ struct Identifier { langutil::SourceLocation location; YulString name; }; struct Assignment { langutil::SourceLocation location; std::vector variableNames; std::unique_ptr value; }; struct FunctionCall { langutil::SourceLocation location; Identifier functionName; std::vector arguments; }; /// Statement that contains only a single expression -struct ExpressionStatement { langutil::SourceLocation location; Expression expression; }; +struct ExpressionStatement { langutil::SourceLocation location; FunctionCall expression; }; /// Block-scope variable declaration ("let x:u256 := mload(20:u256)"), non-hoisted struct VariableDeclaration { langutil::SourceLocation location; TypedNameList variables; std::unique_ptr value; }; /// Block that creates a scope (frees declared stack variables) diff --git a/libyul/AsmJsonConverter.cpp b/libyul/AsmJsonConverter.cpp index 58b11338d..1b6ceaf70 100644 --- a/libyul/AsmJsonConverter.cpp +++ b/libyul/AsmJsonConverter.cpp @@ -99,7 +99,7 @@ Json::Value AsmJsonConverter::operator()(FunctionCall const& _node) const Json::Value AsmJsonConverter::operator()(ExpressionStatement const& _node) const { Json::Value ret = createAstNode(_node.location, "YulExpressionStatement"); - ret["expression"] = std::visit(*this, _node.expression); + ret["expression"] = (*this)(_node.expression); return ret; } diff --git a/libyul/AsmJsonImporter.cpp b/libyul/AsmJsonImporter.cpp index 5940d055c..216c9afdf 100644 --- a/libyul/AsmJsonImporter.cpp +++ b/libyul/AsmJsonImporter.cpp @@ -233,7 +233,7 @@ FunctionCall AsmJsonImporter::createFunctionCall(Json::Value const& _node) ExpressionStatement AsmJsonImporter::createExpressionStatement(Json::Value const& _node) { auto statement = createAsmNode(_node); - statement.expression = createExpression(member(_node, "expression")); + statement.expression = createFunctionCall(member(_node, "expression")); return statement; } diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index 2baefa16f..4244ab630 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -147,8 +147,8 @@ Statement Parser::parseStatement() { case Token::LParen: { - Expression expr = parseCall(std::move(elementary)); - return ExpressionStatement{locationOf(expr), expr}; + FunctionCall expr = parseCall(std::move(elementary)); + return ExpressionStatement{expr.location, std::move(expr)}; } case Token::Comma: case Token::AssemblyAssign: @@ -198,21 +198,8 @@ Statement Parser::parseStatement() break; } - if (holds_alternative(elementary)) - { - Identifier& identifier = std::get(elementary); - return ExpressionStatement{identifier.location, { move(identifier) }}; - } - else if (holds_alternative(elementary)) - { - Expression expr = std::get(elementary); - return ExpressionStatement{locationOf(expr), expr}; - } - else - { - yulAssert(false, "Invalid elementary operation."); - return {}; - } + yulAssert(false, "Invalid elementary operation."); + return {}; } Case Parser::parseCase() @@ -417,7 +404,7 @@ FunctionDefinition Parser::parseFunctionDefinition() return funDef; } -Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) +FunctionCall Parser::parseCall(Parser::ElementaryOperation&& _initialOp) { RecursionGuard recursionGuard(*this); diff --git a/libyul/AsmParser.h b/libyul/AsmParser.h index c48910064..9d77da292 100644 --- a/libyul/AsmParser.h +++ b/libyul/AsmParser.h @@ -87,7 +87,7 @@ protected: ElementaryOperation parseElementaryOperation(); VariableDeclaration parseVariableDeclaration(); FunctionDefinition parseFunctionDefinition(); - Expression parseCall(ElementaryOperation&& _initialOp); + FunctionCall parseCall(ElementaryOperation&& _initialOp); TypedName parseTypedName(); YulString expectAsmIdentifier(); diff --git a/libyul/AsmPrinter.cpp b/libyul/AsmPrinter.cpp index c5982afc9..4b9a1bd11 100644 --- a/libyul/AsmPrinter.cpp +++ b/libyul/AsmPrinter.cpp @@ -67,7 +67,7 @@ string AsmPrinter::operator()(Identifier const& _identifier) const string AsmPrinter::operator()(ExpressionStatement const& _statement) const { - return std::visit(*this, _statement.expression); + return (*this)(_statement.expression); } string AsmPrinter::operator()(Assignment const& _assignment) const diff --git a/libyul/AsmScopeFiller.cpp b/libyul/AsmScopeFiller.cpp index 0e0695410..e62b99048 100644 --- a/libyul/AsmScopeFiller.cpp +++ b/libyul/AsmScopeFiller.cpp @@ -47,7 +47,7 @@ ScopeFiller::ScopeFiller(AsmAnalysisInfo& _info, ErrorReporter& _errorReporter): bool ScopeFiller::operator()(ExpressionStatement const& _expr) { - return std::visit(*this, _expr.expression); + return (*this)(_expr.expression); } bool ScopeFiller::operator()(VariableDeclaration const& _varDecl) diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index 95f787400..5acb42405 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -254,7 +254,7 @@ void CodeTransform::operator()(Assignment const& _assignment) void CodeTransform::operator()(ExpressionStatement const& _statement) { m_assembly.setSourceLocation(_statement.location); - std::visit(*this, _statement.expression); + (*this)(_statement.expression); } void CodeTransform::operator()(FunctionCall const& _call) diff --git a/libyul/optimiser/ASTCopier.cpp b/libyul/optimiser/ASTCopier.cpp index 8dc08f6fa..dc835e91a 100644 --- a/libyul/optimiser/ASTCopier.cpp +++ b/libyul/optimiser/ASTCopier.cpp @@ -34,7 +34,8 @@ using namespace solidity::util; Statement ASTCopier::operator()(ExpressionStatement const& _statement) { - return ExpressionStatement{ _statement.location, translate(_statement.expression) }; + Expression expr = (*this)(_statement.expression); + return ExpressionStatement{ _statement.location, std::get(std::move(expr)) }; } Statement ASTCopier::operator()(VariableDeclaration const& _varDecl) diff --git a/libyul/optimiser/ASTWalker.cpp b/libyul/optimiser/ASTWalker.cpp index 057f94b88..bb4b65d11 100644 --- a/libyul/optimiser/ASTWalker.cpp +++ b/libyul/optimiser/ASTWalker.cpp @@ -107,7 +107,7 @@ void ASTModifier::operator()(FunctionCall& _funCall) void ASTModifier::operator()(ExpressionStatement& _statement) { - visit(_statement.expression); + (*this)(_statement.expression); } void ASTModifier::operator()(Assignment& _assignment) diff --git a/libyul/optimiser/DataFlowAnalyzer.cpp b/libyul/optimiser/DataFlowAnalyzer.cpp index 6755500b3..b0bcad697 100644 --- a/libyul/optimiser/DataFlowAnalyzer.cpp +++ b/libyul/optimiser/DataFlowAnalyzer.cpp @@ -397,22 +397,19 @@ std::optional> DataFlowAnalyzer::isSimpleStore( _store == evmasm::Instruction::SSTORE, "" ); - if (holds_alternative(_statement.expression)) - { - FunctionCall const& funCall = std::get(_statement.expression); - if (EVMDialect const* dialect = dynamic_cast(&m_dialect)) - if (auto const* builtin = dialect->builtin(funCall.functionName.name)) - if (builtin->instruction == _store) - if ( - holds_alternative(funCall.arguments.at(0)) && - holds_alternative(funCall.arguments.at(1)) - ) - { - YulString key = std::get(funCall.arguments.at(0)).name; - YulString value = std::get(funCall.arguments.at(1)).name; - return make_pair(key, value); - } - } + FunctionCall const& funCall = _statement.expression; + if (EVMDialect const* dialect = dynamic_cast(&m_dialect)) + if (auto const* builtin = dialect->builtin(funCall.functionName.name)) + if (builtin->instruction == _store) + if ( + holds_alternative(funCall.arguments.at(0)) && + holds_alternative(funCall.arguments.at(1)) + ) + { + YulString key = std::get(funCall.arguments.at(0)).name; + YulString value = std::get(funCall.arguments.at(1)).name; + return make_pair(key, value); + } return {}; } diff --git a/libyul/optimiser/FullInliner.cpp b/libyul/optimiser/FullInliner.cpp index 101b89c34..c2286346c 100644 --- a/libyul/optimiser/FullInliner.cpp +++ b/libyul/optimiser/FullInliner.cpp @@ -233,24 +233,15 @@ void InlineModifier::operator()(Block& _block) std::optional> InlineModifier::tryInlineStatement(Statement& _statement) { - // Only inline for expression statements, assignments and variable declarations. - Expression* e = std::visit(util::GenericVisitor{ - util::VisitorFallback{}, - [](ExpressionStatement& _s) { return &_s.expression; }, - [](Assignment& _s) { return _s.value.get(); }, - [](VariableDeclaration& _s) { return _s.value.get(); } + // Only inline direct function cfor expression statements, assignments and variable declarations. + FunctionCall* funCall = std::visit(util::GenericVisitor{ + util::VisitorFallback{}, + [](ExpressionStatement& _s) { return &_s.expression; } }, _statement); - if (e) - { - // Only inline direct function calls. - FunctionCall* funCall = std::visit(util::GenericVisitor{ - util::VisitorFallback{}, - [](FunctionCall& _e) { return &_e; } - }, *e); - if (funCall && m_driver.shallInline(*funCall, m_currentFunction)) - return performInline(_statement, *funCall); - } - return {}; + if (funCall && m_driver.shallInline(*funCall, m_currentFunction)) + return performInline(_statement, *funCall); + else + return {}; } vector InlineModifier::performInline(Statement& _statement, FunctionCall& _funCall) diff --git a/libyul/optimiser/Semantics.cpp b/libyul/optimiser/Semantics.cpp index 735ed13d0..6741a0c7c 100644 --- a/libyul/optimiser/Semantics.cpp +++ b/libyul/optimiser/Semantics.cpp @@ -194,10 +194,9 @@ TerminationFinder::ControlFlow TerminationFinder::controlFlowKind(Statement cons bool TerminationFinder::isTerminatingBuiltin(ExpressionStatement const& _exprStmnt) { - if (holds_alternative(_exprStmnt.expression)) - if (auto const* dialect = dynamic_cast(&m_dialect)) - if (auto const* builtin = dialect->builtin(std::get(_exprStmnt.expression).functionName.name)) - if (builtin->instruction) - return evmasm::SemanticInformation::terminatesControlFlow(*builtin->instruction); + if (auto const* dialect = dynamic_cast(&m_dialect)) + if (auto const* builtin = dialect->builtin(_exprStmnt.expression.functionName.name)) + if (builtin->instruction) + return evmasm::SemanticInformation::terminatesControlFlow(*builtin->instruction); return false; }