aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-06-07 17:40:47 +0800
committerchriseth <chris@ethereum.org>2017-06-08 21:52:45 +0800
commitb32d5e4cc011e91efb2e8399c692206bfeaf9ca3 (patch)
tree5397bce29d7901b951d5aff79649cc163e6c4c56 /libsolidity
parent893e6f4ec2dff8aeca4fa3b99a265f291428deac (diff)
downloaddexon-solidity-b32d5e4cc011e91efb2e8399c692206bfeaf9ca3.tar.gz
dexon-solidity-b32d5e4cc011e91efb2e8399c692206bfeaf9ca3.tar.zst
dexon-solidity-b32d5e4cc011e91efb2e8399c692206bfeaf9ca3.zip
Visitor bugfix.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/inlineasm/AsmAnalysis.cpp23
-rw-r--r--libsolidity/inlineasm/AsmAnalysis.h1
2 files changed, 18 insertions, 6 deletions
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp
index bfc6b2af..13852880 100644
--- a/libsolidity/inlineasm/AsmAnalysis.cpp
+++ b/libsolidity/inlineasm/AsmAnalysis.cpp
@@ -277,8 +277,12 @@ bool AsmAnalyzer::operator()(Switch const& _switch)
{
if (_case.value)
{
- if (!expectExpression(*_case.value))
+ int const initialStackHeight = m_stackHeight;
+ // We cannot use "expectExpression" here because *_case.value is not a
+ // Statement and would be converted to a Statement otherwise.
+ if (!(*this)(*_case.value))
success = false;
+ expectDeposit(1, initialStackHeight, _case.value->location);
m_stackHeight--;
/// Note: the parser ensures there is only one default case
@@ -345,17 +349,24 @@ bool AsmAnalyzer::expectExpression(Statement const& _statement)
int const initialHeight = m_stackHeight;
if (!boost::apply_visitor(*this, _statement))
success = false;
- if (m_stackHeight - initialHeight != 1)
+ if (!expectDeposit(1, initialHeight, locationOf(_statement)))
+ success = false;
+ return success;
+}
+
+bool AsmAnalyzer::expectDeposit(int _deposit, int _oldHeight, SourceLocation const& _location)
+{
+ if (m_stackHeight - _oldHeight != _deposit)
{
m_errorReporter.typeError(
- locationOf(_statement),
+ _location,
"Expected expression to return one item to the stack, but did return " +
- boost::lexical_cast<string>(m_stackHeight - initialHeight) +
+ boost::lexical_cast<string>(m_stackHeight - _oldHeight) +
" items."
);
- success = false;
+ return false;
}
- return success;
+ return true;
}
bool AsmAnalyzer::checkAssignment(assembly::Identifier const& _variable, size_t _valueSize)
diff --git a/libsolidity/inlineasm/AsmAnalysis.h b/libsolidity/inlineasm/AsmAnalysis.h
index 75c0c43b..dea9a972 100644
--- a/libsolidity/inlineasm/AsmAnalysis.h
+++ b/libsolidity/inlineasm/AsmAnalysis.h
@@ -89,6 +89,7 @@ public:
private:
/// Visits the statement and expects it to deposit one item onto the stack.
bool expectExpression(Statement const& _statement);
+ bool expectDeposit(int _deposit, int _oldHeight, SourceLocation const& _location);
/// Verifies that a variable to be assigned to exists and has the same size
/// as the value, @a _valueSize, unless that is equal to -1.