diff options
author | Lu Guanqun <guanqun.lu@gmail.com> | 2016-01-19 10:16:13 +0800 |
---|---|---|
committer | Lu Guanqun <guanqun.lu@gmail.com> | 2016-01-19 10:16:13 +0800 |
commit | c8886ed5cfc4f0b7bf4e8d52eb94da7137c9b70e (patch) | |
tree | 1c8d6e62a0ba7d9a7ef00608548295ae01d97d4f /libsolidity | |
parent | e130bc7e7cc647b15c448133f725a060910da587 (diff) | |
download | dexon-solidity-c8886ed5cfc4f0b7bf4e8d52eb94da7137c9b70e.tar.gz dexon-solidity-c8886ed5cfc4f0b7bf4e8d52eb94da7137c9b70e.tar.zst dexon-solidity-c8886ed5cfc4f0b7bf4e8d52eb94da7137c9b70e.zip |
code changes according to Chris's comments
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/SyntaxChecker.cpp | 25 | ||||
-rw-r--r-- | libsolidity/analysis/SyntaxChecker.h | 9 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 2 |
3 files changed, 16 insertions, 20 deletions
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 92743461..f1cdaf0f 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -42,36 +42,29 @@ void SyntaxChecker::syntaxError(SourceLocation const& _location, std::string con bool SyntaxChecker::visit(WhileStatement const& _whileStatement) { - _whileStatement.body().annotation().isInLoop = true; + m_inLoopDepth++; return true; } -bool SyntaxChecker::visit(ForStatement const& _forStatement) +void SyntaxChecker::endVisit(WhileStatement const& _whileStatement) { - _forStatement.body().annotation().isInLoop = true; - return true; + m_inLoopDepth--; } -bool SyntaxChecker::visit(Block const& _blockStatement) +bool SyntaxChecker::visit(ForStatement const& _forStatement) { - bool inLoop = _blockStatement.annotation().isInLoop; - for (auto& statement : _blockStatement.statements()) - statement->annotation().isInLoop = inLoop; + m_inLoopDepth++; return true; } -bool SyntaxChecker::visit(IfStatement const& _ifStatement) +void SyntaxChecker::endVisit(ForStatement const& _forStatement) { - bool inLoop = _ifStatement.annotation().isInLoop; - _ifStatement.trueStatement().annotation().isInLoop = inLoop; - if (_ifStatement.falseStatement()) - _ifStatement.falseStatement()->annotation().isInLoop = inLoop; - return true; + m_inLoopDepth--; } bool SyntaxChecker::visit(Continue const& _continueStatement) { - if (!_continueStatement.annotation().isInLoop) + if (m_inLoopDepth <= 0) // we're not in a for/while loop, report syntax error syntaxError(_continueStatement.location(), "\"continue\" has to be in a \"for\" or \"while\" loop."); return true; @@ -79,7 +72,7 @@ bool SyntaxChecker::visit(Continue const& _continueStatement) bool SyntaxChecker::visit(Break const& _breakStatement) { - if (!_breakStatement.annotation().isInLoop) + if (m_inLoopDepth <= 0) // we're not in a for/while loop, report syntax error syntaxError(_breakStatement.location(), "\"break\" has to be in a \"for\" or \"while\" loop."); return true; diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h index 66f6d94d..c836d49f 100644 --- a/libsolidity/analysis/SyntaxChecker.h +++ b/libsolidity/analysis/SyntaxChecker.h @@ -32,7 +32,7 @@ namespace solidity * The module that performs syntax analysis on the AST: * - whether continue/break is in a for/while loop. */ -class SyntaxChecker : private ASTConstVisitor +class SyntaxChecker: private ASTConstVisitor { public: /// @param _errors the reference to the list of errors and warnings to add them found during type checking. @@ -45,13 +45,16 @@ private: void syntaxError(SourceLocation const& _location, std::string const& _description); virtual bool visit(WhileStatement const& _whileStatement) override; + virtual void endVisit(WhileStatement const& _whileStatement) override; virtual bool visit(ForStatement const& _forStatement) override; - virtual bool visit(Block const& _blockStatement) override; - virtual bool visit(IfStatement const& _ifStatement) override; + virtual void endVisit(ForStatement const& _forStatement) override; + virtual bool visit(Continue const& _continueStatement) override; virtual bool visit(Break const& _breakStatement) override; ErrorList& m_errors; + + int m_inLoopDepth = 0; }; } diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 8a0d2f5e..8ff63056 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -126,7 +126,7 @@ bool CompilerStack::parse() SyntaxChecker syntaxChecker(m_errors); for (Source const* source: m_sourceOrder) if (!syntaxChecker.checkSyntax(*source->ast)) - return false; + noErrors = false; DocStringAnalyser docStringAnalyser(m_errors); for (Source const* source: m_sourceOrder) |