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
+13 -6
View File
@@ -1096,16 +1096,23 @@ ASTPointer<ParameterList> Parser::parseParameterList(
return nodeFactory.createNode<ParameterList>(parameters);
}
ASTPointer<Block> Parser::parseBlock(ASTPointer<ASTString> const& _docString)
ASTPointer<Block> Parser::parseBlock(bool _allowUnchecked, ASTPointer<ASTString> const& _docString)
{
RecursionGuard recursionGuard(*this);
ASTNodeFactory nodeFactory(*this);
bool const unchecked = m_scanner->currentToken() == Token::Unchecked;
if (unchecked)
{
if (!_allowUnchecked)
parserError(5296_error, "\"unchecked\" blocks can only be used inside regular blocks.");
m_scanner->next();
}
expectToken(Token::LBrace);
vector<ASTPointer<Statement>> statements;
try
{
while (m_scanner->currentToken() != Token::RBrace)
statements.push_back(parseStatement());
statements.push_back(parseStatement(true));
nodeFactory.markEndPosition();
}
catch (FatalError const&)
@@ -1122,10 +1129,10 @@ ASTPointer<Block> Parser::parseBlock(ASTPointer<ASTString> const& _docString)
expectTokenOrConsumeUntil(Token::RBrace, "Block");
else
expectToken(Token::RBrace);
return nodeFactory.createNode<Block>(_docString, statements);
return nodeFactory.createNode<Block>(_docString, unchecked, statements);
}
ASTPointer<Statement> Parser::parseStatement()
ASTPointer<Statement> Parser::parseStatement(bool _allowUnchecked)
{
RecursionGuard recursionGuard(*this);
ASTPointer<ASTString> docString;
@@ -1144,9 +1151,9 @@ ASTPointer<Statement> Parser::parseStatement()
return parseDoWhileStatement(docString);
case Token::For:
return parseForStatement(docString);
case Token::Unchecked:
case Token::LBrace:
return parseBlock(docString);
// starting from here, all statements must be terminated by a semicolon
return parseBlock(_allowUnchecked, docString);
case Token::Continue:
statement = ASTNodeFactory(*this).createNode<Continue>(docString);
m_scanner->next();