Checked arithmetic by default.

This commit is contained in:
chriseth
2020-10-19 16:58:37 +02:00
parent 41000fea31
commit 527c073bb9
21 changed files with 405 additions and 98 deletions
+30 -1
View File
@@ -190,6 +190,28 @@ void SyntaxChecker::endVisit(ForStatement const&)
m_inLoopDepth--;
}
bool SyntaxChecker::visit(Block const& _block)
{
if (_block.unchecked())
{
if (m_uncheckedArithmetic)
m_errorReporter.syntaxError(
1941_error,
_block.location(),
"\"unchecked\" blocks cannot be nested."
);
m_uncheckedArithmetic = true;
}
return true;
}
void SyntaxChecker::endVisit(Block const& _block)
{
if (_block.unchecked())
m_uncheckedArithmetic = false;
}
bool SyntaxChecker::visit(Continue const& _continueStatement)
{
if (m_inLoopDepth <= 0)
@@ -288,8 +310,15 @@ bool SyntaxChecker::visit(InlineAssembly const& _inlineAssembly)
return false;
}
bool SyntaxChecker::visit(PlaceholderStatement const&)
bool SyntaxChecker::visit(PlaceholderStatement const& _placeholder)
{
if (m_uncheckedArithmetic)
m_errorReporter.syntaxError(
2573_error,
_placeholder.location(),
"The placeholder statement \"_\" cannot be used inside an \"unchecked\" block."
);
m_placeholderFound = true;
return true;
}
+6
View File
@@ -71,6 +71,9 @@ private:
bool visit(ForStatement const& _forStatement) override;
void endVisit(ForStatement const& _forStatement) override;
bool visit(Block const& _block) override;
void endVisit(Block const& _block) override;
bool visit(Continue const& _continueStatement) override;
bool visit(Break const& _breakStatement) override;
@@ -100,6 +103,9 @@ private:
/// Flag that indicates whether some version pragma was present.
bool m_versionPragmaFound = false;
/// Flag that indicates whether we are inside an unchecked block.
bool m_uncheckedArithmetic = false;
int m_inLoopDepth = 0;
std::optional<ContractKind> m_currentContractKind;