diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-04-28 21:27:56 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-05-26 10:16:09 +0800 |
commit | b5080860d5f2d141b8fccceaa635378a86c996a8 (patch) | |
tree | a68c289d101e5f4d3a990da2e8c7608bb4f0fcbc /libsolidity/inlineasm/AsmAnalysis.cpp | |
parent | af2d2499c1ccd431f5ac9455c2cbb63d3891f9b0 (diff) | |
download | dexon-solidity-b5080860d5f2d141b8fccceaa635378a86c996a8.tar.gz dexon-solidity-b5080860d5f2d141b8fccceaa635378a86c996a8.tar.zst dexon-solidity-b5080860d5f2d141b8fccceaa635378a86c996a8.zip |
Implement switch statement in the assembly parser/printer
Diffstat (limited to 'libsolidity/inlineasm/AsmAnalysis.cpp')
-rw-r--r-- | libsolidity/inlineasm/AsmAnalysis.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index 65b935f2..ecc63372 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -285,6 +285,38 @@ bool AsmAnalyzer::operator()(assembly::FunctionCall const& _funCall) return success; } +bool AsmAnalyzer::operator()(Switch const& _switch) +{ + int const initialStackHeight = m_stackHeight; + if (!boost::apply_visitor(*this, *_switch.expression)) + return false; + expectDeposit(1, initialStackHeight, locationOf(*_switch.expression)); + + map<string, bool> caseNames; + for (auto const& _case: _switch.cases) + { + /// Note: the parser ensures there is only one default case + if (caseNames[_case.name]) + { + m_errors.push_back(make_shared<Error>( + Error::Type::DeclarationError, + "Duplicate case defined: " + _case.name, + _case.location + )); + return false; + } + else + caseNames[_case.name] = true; + + if (!(*this)(_case.body)) + return false; + } + + m_stackHeight--; + + return true; +} + bool AsmAnalyzer::operator()(Block const& _block) { bool success = true; |