mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
code changes according to Chris's comments
This commit is contained in:
parent
e130bc7e7c
commit
c8886ed5cf
@ -42,36 +42,29 @@ void SyntaxChecker::syntaxError(SourceLocation const& _location, std::string con
|
|||||||
|
|
||||||
bool SyntaxChecker::visit(WhileStatement const& _whileStatement)
|
bool SyntaxChecker::visit(WhileStatement const& _whileStatement)
|
||||||
{
|
{
|
||||||
_whileStatement.body().annotation().isInLoop = true;
|
m_inLoopDepth++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SyntaxChecker::endVisit(WhileStatement const& _whileStatement)
|
||||||
|
{
|
||||||
|
m_inLoopDepth--;
|
||||||
|
}
|
||||||
|
|
||||||
bool SyntaxChecker::visit(ForStatement const& _forStatement)
|
bool SyntaxChecker::visit(ForStatement const& _forStatement)
|
||||||
{
|
{
|
||||||
_forStatement.body().annotation().isInLoop = true;
|
m_inLoopDepth++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyntaxChecker::visit(Block const& _blockStatement)
|
void SyntaxChecker::endVisit(ForStatement const& _forStatement)
|
||||||
{
|
{
|
||||||
bool inLoop = _blockStatement.annotation().isInLoop;
|
m_inLoopDepth--;
|
||||||
for (auto& statement : _blockStatement.statements())
|
|
||||||
statement->annotation().isInLoop = inLoop;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SyntaxChecker::visit(IfStatement const& _ifStatement)
|
|
||||||
{
|
|
||||||
bool inLoop = _ifStatement.annotation().isInLoop;
|
|
||||||
_ifStatement.trueStatement().annotation().isInLoop = inLoop;
|
|
||||||
if (_ifStatement.falseStatement())
|
|
||||||
_ifStatement.falseStatement()->annotation().isInLoop = inLoop;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyntaxChecker::visit(Continue const& _continueStatement)
|
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
|
// we're not in a for/while loop, report syntax error
|
||||||
syntaxError(_continueStatement.location(), "\"continue\" has to be in a \"for\" or \"while\" loop.");
|
syntaxError(_continueStatement.location(), "\"continue\" has to be in a \"for\" or \"while\" loop.");
|
||||||
return true;
|
return true;
|
||||||
@ -79,7 +72,7 @@ bool SyntaxChecker::visit(Continue const& _continueStatement)
|
|||||||
|
|
||||||
bool SyntaxChecker::visit(Break const& _breakStatement)
|
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
|
// we're not in a for/while loop, report syntax error
|
||||||
syntaxError(_breakStatement.location(), "\"break\" has to be in a \"for\" or \"while\" loop.");
|
syntaxError(_breakStatement.location(), "\"break\" has to be in a \"for\" or \"while\" loop.");
|
||||||
return true;
|
return true;
|
||||||
|
@ -32,7 +32,7 @@ namespace solidity
|
|||||||
* The module that performs syntax analysis on the AST:
|
* The module that performs syntax analysis on the AST:
|
||||||
* - whether continue/break is in a for/while loop.
|
* - whether continue/break is in a for/while loop.
|
||||||
*/
|
*/
|
||||||
class SyntaxChecker : private ASTConstVisitor
|
class SyntaxChecker: private ASTConstVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// @param _errors the reference to the list of errors and warnings to add them found during type checking.
|
/// @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);
|
void syntaxError(SourceLocation const& _location, std::string const& _description);
|
||||||
|
|
||||||
virtual bool visit(WhileStatement const& _whileStatement) override;
|
virtual bool visit(WhileStatement const& _whileStatement) override;
|
||||||
|
virtual void endVisit(WhileStatement const& _whileStatement) override;
|
||||||
virtual bool visit(ForStatement const& _forStatement) override;
|
virtual bool visit(ForStatement const& _forStatement) override;
|
||||||
virtual bool visit(Block const& _blockStatement) override;
|
virtual void endVisit(ForStatement const& _forStatement) override;
|
||||||
virtual bool visit(IfStatement const& _ifStatement) override;
|
|
||||||
virtual bool visit(Continue const& _continueStatement) override;
|
virtual bool visit(Continue const& _continueStatement) override;
|
||||||
virtual bool visit(Break const& _breakStatement) override;
|
virtual bool visit(Break const& _breakStatement) override;
|
||||||
|
|
||||||
ErrorList& m_errors;
|
ErrorList& m_errors;
|
||||||
|
|
||||||
|
int m_inLoopDepth = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ bool CompilerStack::parse()
|
|||||||
SyntaxChecker syntaxChecker(m_errors);
|
SyntaxChecker syntaxChecker(m_errors);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (!syntaxChecker.checkSyntax(*source->ast))
|
if (!syntaxChecker.checkSyntax(*source->ast))
|
||||||
return false;
|
noErrors = false;
|
||||||
|
|
||||||
DocStringAnalyser docStringAnalyser(m_errors);
|
DocStringAnalyser docStringAnalyser(m_errors);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
|
Loading…
Reference in New Issue
Block a user