Add resolveUnaryTuples helper.

This commit is contained in:
Daniel Kirchner 2022-06-14 15:31:32 +02:00
parent 9542e46ea4
commit d30b04674e
3 changed files with 16 additions and 5 deletions

View File

@ -17,6 +17,7 @@
// SPDX-License-Identifier: GPL-3.0 // SPDX-License-Identifier: GPL-3.0
#include <libsolidity/analysis/ControlFlowBuilder.h> #include <libsolidity/analysis/ControlFlowBuilder.h>
#include <libsolidity/ast/ASTUtils.h>
#include <libyul/AST.h> #include <libyul/AST.h>
#include <libyul/backends/evm/EVMDialect.h> #include <libyul/backends/evm/EVMDialect.h>
@ -617,11 +618,7 @@ bool ControlFlowBuilder::visit(VariableDeclarationStatement const& _variableDecl
solAssert(tupleExpression->components().size() > i, ""); solAssert(tupleExpression->components().size() > i, "");
expression = tupleExpression->components()[i].get(); expression = tupleExpression->components()[i].get();
} }
while (auto tupleExpression = dynamic_cast<TupleExpression const*>(expression)) expression = resolveUnaryTuples(expression);
if (tupleExpression->components().size() == 1)
expression = tupleExpression->components().front().get();
else
break;
m_currentNode->variableOccurrences.emplace_back( m_currentNode->variableOccurrences.emplace_back(
*var, *var,
VariableOccurrence::Kind::Assignment, VariableOccurrence::Kind::Assignment,

View File

@ -85,4 +85,14 @@ VariableDeclaration const* rootConstVariableDeclaration(VariableDeclaration cons
return rootDecl; return rootDecl;
} }
Expression const* resolveUnaryTuples(Expression const* _expr)
{
while (auto const* tupleExpression = dynamic_cast<TupleExpression const*>(_expr))
if (tupleExpression->components().size() == 1)
_expr = tupleExpression->components().front().get();
else
break;
return _expr;
}
} }

View File

@ -38,4 +38,8 @@ bool isConstantVariableRecursive(VariableDeclaration const& _varDecl);
/// Returns the innermost AST node that covers the given location or nullptr if not found. /// Returns the innermost AST node that covers the given location or nullptr if not found.
ASTNode const* locateInnermostASTNode(int _offsetInFile, SourceUnit const& _sourceUnit); ASTNode const* locateInnermostASTNode(int _offsetInFile, SourceUnit const& _sourceUnit);
/// @returns @a _expr itself, in case it is not an unary tuple expression. Otherwise it descends recursively
/// into unary tuples and returns the contained expression.
Expression const* resolveUnaryTuples(Expression const* _expr);
} }