From 9230faf9a38eed0c2b8645ef7fc0b005466889f3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 31 Oct 2020 01:59:28 +0000 Subject: [PATCH] Simplify StackTooDeepError in Yul --- libyul/backends/evm/EVMCodeTransform.cpp | 11 +++++++---- libyul/backends/evm/EVMCodeTransform.h | 12 +++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index 7877e8831..40cd5e729 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -483,8 +483,10 @@ void CodeTransform::operator()(FunctionDefinition const& _function) if (stackLayout.size() > 17) { - StackTooDeepError error(_function.name, YulString{}, static_cast(stackLayout.size()) - 17); - error << errinfo_comment( + StackTooDeepError error( + _function.name, + YulString{}, + static_cast(stackLayout.size()) - 17, "The function " + _function.name.str() + " has " + @@ -716,8 +718,9 @@ size_t CodeTransform::variableHeightDiff(Scope::Variable const& _var, YulString size_t limit = _forSwap ? 17 : 16; if (heightDiff > limit) { - m_stackErrors.emplace_back(_varName, heightDiff - limit); - m_stackErrors.back() << errinfo_comment( + m_stackErrors.emplace_back( + _varName, + heightDiff - limit, "Variable " + _varName.str() + " is " + diff --git a/libyul/backends/evm/EVMCodeTransform.h b/libyul/backends/evm/EVMCodeTransform.h index 45443ae7d..5eea25e9c 100644 --- a/libyul/backends/evm/EVMCodeTransform.h +++ b/libyul/backends/evm/EVMCodeTransform.h @@ -43,10 +43,16 @@ class EVMAssembly; struct StackTooDeepError: virtual YulException { - StackTooDeepError(YulString _variable, int _depth): variable(_variable), depth(_depth) {} - StackTooDeepError(YulString _functionName, YulString _variable, int _depth): + StackTooDeepError(YulString _variable, int _depth, std::string const& _message): + variable(_variable), depth(_depth) + { + *this << util::errinfo_comment(_message); + } + StackTooDeepError(YulString _functionName, YulString _variable, int _depth, std::string const& _message): functionName(_functionName), variable(_variable), depth(_depth) - {} + { + *this << util::errinfo_comment(_message); + } YulString functionName; YulString variable; int depth;