Commit 675c1de5 authored by Daniel Clifford's avatar Daniel Clifford Committed by Commit Bot

[torque] Remove try/catch (only support try/label)

In the process, also fix the make-torque-parser.py script to work in its new
location.

Bug: v8:7793
Change-Id: I376a5f73ec9f7cc87995928397c6e399b1a490d8
Reviewed-on: https://chromium-review.googlesource.com/1084838
Commit-Queue: Daniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53504}
parent 94aac004
......@@ -29,7 +29,6 @@ BREAK: 'break';
GOTO: 'goto';
OTHERWISE: 'otherwise';
TRY: 'try';
CATCH: 'catch';
LABEL: 'label';
LABELS: 'labels';
TAIL: 'tail';
......@@ -244,8 +243,8 @@ returnStatement: RETURN expression?;
breakStatement: BREAK;
continueStatement: CONTINUE;
gotoStatement: GOTO labelReference argumentList?;
handlerWithStatement: (CATCH IDENTIFIER | LABEL labelDeclaration) statementBlock;
tryCatch: TRY statementBlock handlerWithStatement+;
handlerWithStatement: LABEL labelDeclaration statementBlock;
tryLabelStatement: TRY statementBlock handlerWithStatement+;
diagnosticStatement: ((ASSERT_TOKEN | CHECK_TOKEN) '(' expression ')') | UNREACHABLE_TOKEN | DEBUG_TOKEN;
......@@ -261,7 +260,7 @@ statement : variableDeclarationWithInitialization ';'
| whileLoop
| forOfLoop
| forLoop
| tryCatch
| tryLabelStatement
;
statementList : statement*;
......
......@@ -232,8 +232,10 @@ class TorqueBaseListener : public TorqueListener {
void exitHandlerWithStatement(
TorqueParser::HandlerWithStatementContext* /*ctx*/) override {}
void enterTryCatch(TorqueParser::TryCatchContext* /*ctx*/) override {}
void exitTryCatch(TorqueParser::TryCatchContext* /*ctx*/) override {}
void enterTryLabelStatement(
TorqueParser::TryLabelStatementContext* /*ctx*/) override {}
void exitTryLabelStatement(
TorqueParser::TryLabelStatementContext* /*ctx*/) override {}
void enterDiagnosticStatement(
TorqueParser::DiagnosticStatementContext* /*ctx*/) override {}
......
......@@ -248,7 +248,8 @@ class TorqueBaseVisitor : public TorqueVisitor {
return visitChildren(ctx);
}
antlrcpp::Any visitTryCatch(TorqueParser::TryCatchContext* ctx) override {
antlrcpp::Any visitTryLabelStatement(
TorqueParser::TryLabelStatementContext* ctx) override {
return visitChildren(ctx);
}
......
This diff is collapsed.
......@@ -54,50 +54,49 @@ class TorqueLexer : public antlr4::Lexer {
GOTO = 39,
OTHERWISE = 40,
TRY = 41,
CATCH = 42,
LABEL = 43,
LABELS = 44,
TAIL = 45,
ISNT = 46,
IS = 47,
LET = 48,
EXTERN = 49,
ASSERT_TOKEN = 50,
CHECK_TOKEN = 51,
UNREACHABLE_TOKEN = 52,
DEBUG_TOKEN = 53,
ASSIGNMENT = 54,
ASSIGNMENT_OPERATOR = 55,
EQUAL = 56,
PLUS = 57,
MINUS = 58,
MULTIPLY = 59,
DIVIDE = 60,
MODULO = 61,
BIT_OR = 62,
BIT_AND = 63,
BIT_NOT = 64,
MAX = 65,
MIN = 66,
NOT_EQUAL = 67,
LESS_THAN = 68,
LESS_THAN_EQUAL = 69,
GREATER_THAN = 70,
GREATER_THAN_EQUAL = 71,
SHIFT_LEFT = 72,
SHIFT_RIGHT = 73,
SHIFT_RIGHT_ARITHMETIC = 74,
VARARGS = 75,
EQUALITY_OPERATOR = 76,
INCREMENT = 77,
DECREMENT = 78,
NOT = 79,
STRING_LITERAL = 80,
IDENTIFIER = 81,
WS = 82,
BLOCK_COMMENT = 83,
LINE_COMMENT = 84,
DECIMAL_LITERAL = 85
LABEL = 42,
LABELS = 43,
TAIL = 44,
ISNT = 45,
IS = 46,
LET = 47,
EXTERN = 48,
ASSERT_TOKEN = 49,
CHECK_TOKEN = 50,
UNREACHABLE_TOKEN = 51,
DEBUG_TOKEN = 52,
ASSIGNMENT = 53,
ASSIGNMENT_OPERATOR = 54,
EQUAL = 55,
PLUS = 56,
MINUS = 57,
MULTIPLY = 58,
DIVIDE = 59,
MODULO = 60,
BIT_OR = 61,
BIT_AND = 62,
BIT_NOT = 63,
MAX = 64,
MIN = 65,
NOT_EQUAL = 66,
LESS_THAN = 67,
LESS_THAN_EQUAL = 68,
GREATER_THAN = 69,
GREATER_THAN_EQUAL = 70,
SHIFT_LEFT = 71,
SHIFT_RIGHT = 72,
SHIFT_RIGHT_ARITHMETIC = 73,
VARARGS = 74,
EQUALITY_OPERATOR = 75,
INCREMENT = 76,
DECREMENT = 77,
NOT = 78,
STRING_LITERAL = 79,
IDENTIFIER = 80,
WS = 81,
BLOCK_COMMENT = 82,
LINE_COMMENT = 83,
DECIMAL_LITERAL = 84
};
explicit TorqueLexer(antlr4::CharStream* input);
......
......@@ -221,8 +221,10 @@ class TorqueListener : public antlr4::tree::ParseTreeListener {
virtual void exitHandlerWithStatement(
TorqueParser::HandlerWithStatementContext* ctx) = 0;
virtual void enterTryCatch(TorqueParser::TryCatchContext* ctx) = 0;
virtual void exitTryCatch(TorqueParser::TryCatchContext* ctx) = 0;
virtual void enterTryLabelStatement(
TorqueParser::TryLabelStatementContext* ctx) = 0;
virtual void exitTryLabelStatement(
TorqueParser::TryLabelStatementContext* ctx) = 0;
virtual void enterDiagnosticStatement(
TorqueParser::DiagnosticStatementContext* ctx) = 0;
......
This diff is collapsed.
......@@ -54,50 +54,49 @@ class TorqueParser : public antlr4::Parser {
GOTO = 39,
OTHERWISE = 40,
TRY = 41,
CATCH = 42,
LABEL = 43,
LABELS = 44,
TAIL = 45,
ISNT = 46,
IS = 47,
LET = 48,
EXTERN = 49,
ASSERT_TOKEN = 50,
CHECK_TOKEN = 51,
UNREACHABLE_TOKEN = 52,
DEBUG_TOKEN = 53,
ASSIGNMENT = 54,
ASSIGNMENT_OPERATOR = 55,
EQUAL = 56,
PLUS = 57,
MINUS = 58,
MULTIPLY = 59,
DIVIDE = 60,
MODULO = 61,
BIT_OR = 62,
BIT_AND = 63,
BIT_NOT = 64,
MAX = 65,
MIN = 66,
NOT_EQUAL = 67,
LESS_THAN = 68,
LESS_THAN_EQUAL = 69,
GREATER_THAN = 70,
GREATER_THAN_EQUAL = 71,
SHIFT_LEFT = 72,
SHIFT_RIGHT = 73,
SHIFT_RIGHT_ARITHMETIC = 74,
VARARGS = 75,
EQUALITY_OPERATOR = 76,
INCREMENT = 77,
DECREMENT = 78,
NOT = 79,
STRING_LITERAL = 80,
IDENTIFIER = 81,
WS = 82,
BLOCK_COMMENT = 83,
LINE_COMMENT = 84,
DECIMAL_LITERAL = 85
LABEL = 42,
LABELS = 43,
TAIL = 44,
ISNT = 45,
IS = 46,
LET = 47,
EXTERN = 48,
ASSERT_TOKEN = 49,
CHECK_TOKEN = 50,
UNREACHABLE_TOKEN = 51,
DEBUG_TOKEN = 52,
ASSIGNMENT = 53,
ASSIGNMENT_OPERATOR = 54,
EQUAL = 55,
PLUS = 56,
MINUS = 57,
MULTIPLY = 58,
DIVIDE = 59,
MODULO = 60,
BIT_OR = 61,
BIT_AND = 62,
BIT_NOT = 63,
MAX = 64,
MIN = 65,
NOT_EQUAL = 66,
LESS_THAN = 67,
LESS_THAN_EQUAL = 68,
GREATER_THAN = 69,
GREATER_THAN_EQUAL = 70,
SHIFT_LEFT = 71,
SHIFT_RIGHT = 72,
SHIFT_RIGHT_ARITHMETIC = 73,
VARARGS = 74,
EQUALITY_OPERATOR = 75,
INCREMENT = 76,
DECREMENT = 77,
NOT = 78,
STRING_LITERAL = 79,
IDENTIFIER = 80,
WS = 81,
BLOCK_COMMENT = 82,
LINE_COMMENT = 83,
DECIMAL_LITERAL = 84
};
enum {
......@@ -149,7 +148,7 @@ class TorqueParser : public antlr4::Parser {
RuleContinueStatement = 45,
RuleGotoStatement = 46,
RuleHandlerWithStatement = 47,
RuleTryCatch = 48,
RuleTryLabelStatement = 48,
RuleDiagnosticStatement = 49,
RuleStatement = 50,
RuleStatementList = 51,
......@@ -232,7 +231,7 @@ class TorqueParser : public antlr4::Parser {
class ContinueStatementContext;
class GotoStatementContext;
class HandlerWithStatementContext;
class TryCatchContext;
class TryLabelStatementContext;
class DiagnosticStatementContext;
class StatementContext;
class StatementListContext;
......@@ -1066,11 +1065,9 @@ class TorqueParser : public antlr4::Parser {
HandlerWithStatementContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
size_t getRuleIndex() const override;
StatementBlockContext* statementBlock();
antlr4::tree::TerminalNode* CATCH();
antlr4::tree::TerminalNode* IDENTIFIER();
antlr4::tree::TerminalNode* LABEL();
LabelDeclarationContext* labelDeclaration();
StatementBlockContext* statementBlock();
void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override;
......@@ -1080,9 +1077,10 @@ class TorqueParser : public antlr4::Parser {
HandlerWithStatementContext* handlerWithStatement();
class TryCatchContext : public antlr4::ParserRuleContext {
class TryLabelStatementContext : public antlr4::ParserRuleContext {
public:
TryCatchContext(antlr4::ParserRuleContext* parent, size_t invokingState);
TryLabelStatementContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* TRY();
StatementBlockContext* statementBlock();
......@@ -1095,7 +1093,7 @@ class TorqueParser : public antlr4::Parser {
antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor* visitor) override;
};
TryCatchContext* tryCatch();
TryLabelStatementContext* tryLabelStatement();
class DiagnosticStatementContext : public antlr4::ParserRuleContext {
public:
......@@ -1133,7 +1131,7 @@ class TorqueParser : public antlr4::Parser {
WhileLoopContext* whileLoop();
ForOfLoopContext* forOfLoop();
ForLoopContext* forLoop();
TryCatchContext* tryCatch();
TryLabelStatementContext* tryLabelStatement();
void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override;
......
......@@ -162,8 +162,8 @@ class TorqueVisitor : public antlr4::tree::AbstractParseTreeVisitor {
virtual antlrcpp::Any visitHandlerWithStatement(
TorqueParser::HandlerWithStatementContext* context) = 0;
virtual antlrcpp::Any visitTryCatch(
TorqueParser::TryCatchContext* context) = 0;
virtual antlrcpp::Any visitTryLabelStatement(
TorqueParser::TryLabelStatementContext* context) = 0;
virtual antlrcpp::Any visitDiagnosticStatement(
TorqueParser::DiagnosticStatementContext* context) = 0;
......
......@@ -506,36 +506,25 @@ antlrcpp::Any AstGenerator::visitForOfLoop(
return implicit_cast<Statement*>(result);
}
antlrcpp::Any AstGenerator::visitTryCatch(
TorqueParser::TryCatchContext* context) {
TryCatchStatement* result = RegisterNode(new TryCatchStatement{
Pos(context),
context->statementBlock()->accept(this).as<Statement*>(),
{}});
antlrcpp::Any AstGenerator::visitTryLabelStatement(
TorqueParser::TryLabelStatementContext* context) {
TryLabelStatement* result = RegisterNode(new TryLabelStatement{
Pos(context), context->statementBlock()->accept(this).as<Statement*>()});
for (auto* handler : context->handlerWithStatement()) {
if (handler->CATCH() != nullptr) {
CatchBlock* catch_block = RegisterNode(new CatchBlock{
Pos(handler->statementBlock()),
{},
handler->statementBlock()->accept(this).as<Statement*>()});
catch_block->caught = handler->IDENTIFIER()->getSymbol()->getText();
result->catch_blocks.push_back(catch_block);
} else {
handler->labelDeclaration()->accept(this);
auto parameter_list = handler->labelDeclaration()->parameterList();
ParameterList label_parameters = parameter_list == nullptr
? ParameterList()
: handler->labelDeclaration()
->parameterList()
->accept(this)
.as<ParameterList>();
LabelBlock* label_block = RegisterNode(new LabelBlock{
Pos(handler->statementBlock()),
handler->labelDeclaration()->IDENTIFIER()->getSymbol()->getText(),
label_parameters,
handler->statementBlock()->accept(this).as<Statement*>()});
result->label_blocks.push_back(label_block);
}
handler->labelDeclaration()->accept(this);
auto parameter_list = handler->labelDeclaration()->parameterList();
ParameterList label_parameters = parameter_list == nullptr
? ParameterList()
: handler->labelDeclaration()
->parameterList()
->accept(this)
.as<ParameterList>();
LabelBlock* label_block = RegisterNode(new LabelBlock{
Pos(handler->statementBlock()),
handler->labelDeclaration()->IDENTIFIER()->getSymbol()->getText(),
label_parameters,
handler->statementBlock()->accept(this).as<Statement*>()});
result->label_blocks.push_back(label_block);
}
return implicit_cast<Statement*>(result);
}
......
......@@ -108,7 +108,8 @@ class AstGenerator : public TorqueBaseVisitor {
antlrcpp::Any visitPrimaryExpression(
TorqueParser::PrimaryExpressionContext* context) override;
antlrcpp::Any visitTryCatch(TorqueParser::TryCatchContext* context) override;
antlrcpp::Any visitTryLabelStatement(
TorqueParser::TryLabelStatementContext* context) override;
antlrcpp::Any visitStatementScope(
TorqueParser::StatementScopeContext* context) override;
......
......@@ -63,7 +63,7 @@ DECLARE_CONTEXTUAL_VARIABLE(CurrentSourcePosition, SourcePosition)
V(TailCallStatement) \
V(VarDeclarationStatement) \
V(GotoStatement) \
V(TryCatchStatement)
V(TryLabelStatement)
#define AST_DECLARATION_NODE_KIND_LIST(V) \
V(TypeDeclaration) \
......@@ -88,7 +88,6 @@ DECLARE_CONTEXTUAL_VARIABLE(CurrentSourcePosition, SourcePosition)
AST_STATEMENT_NODE_KIND_LIST(V) \
AST_DECLARATION_NODE_KIND_LIST(V) \
AST_CALLABLE_NODE_KIND_LIST(V) \
V(CatchBlock) \
V(LabelBlock)
struct AstNode {
......@@ -525,14 +524,6 @@ struct ForOfLoopStatement : Statement {
Statement* body;
};
struct CatchBlock : AstNode {
DEFINE_AST_NODE_LEAF_BOILERPLATE(CatchBlock)
CatchBlock(SourcePosition p, const std::string& c, Statement* b)
: AstNode(kKind, p), caught(std::move(c)), body(std::move(b)) {}
std::string caught;
Statement* body;
};
struct LabelBlock : AstNode {
DEFINE_AST_NODE_LEAF_BOILERPLATE(LabelBlock)
LabelBlock(SourcePosition p, const std::string& l,
......@@ -546,12 +537,11 @@ struct LabelBlock : AstNode {
Statement* body;
};
struct TryCatchStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(TryCatchStatement)
TryCatchStatement(SourcePosition p, Statement* t, std::vector<CatchBlock*> c)
: Statement(kKind, p), try_block(std::move(t)), catch_blocks(c) {}
struct TryLabelStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(TryLabelStatement)
TryLabelStatement(SourcePosition p, Statement* t)
: Statement(kKind, p), try_block(std::move(t)) {}
Statement* try_block;
std::vector<CatchBlock*> catch_blocks;
std::vector<LabelBlock*> label_blocks;
};
......
......@@ -258,13 +258,13 @@ void DeclarationVisitor::Visit(ForOfLoopStatement* stmt) {
changed_vars);
}
void DeclarationVisitor::Visit(TryCatchStatement* stmt) {
// Activate a new scope to declare catch handler labels, they should not be
// visible outside the catch.
void DeclarationVisitor::Visit(TryLabelStatement* stmt) {
// Activate a new scope to declare handler labels, they should not be
// visible outside the label block.
{
Declarations::NodeScopeActivator scope(declarations(), stmt);
// Declare catch labels
// Declare labels
for (LabelBlock* block : stmt->label_blocks) {
CurrentSourcePosition::Scope scope(block->pos);
Label* shared_label = declarations()->DeclareLabel(block->label);
......@@ -284,20 +284,13 @@ void DeclarationVisitor::Visit(TryCatchStatement* stmt) {
}
}
if (global_context_.verbose()) {
std::cout << " declaring catch for exception " << block->label << "\n";
std::cout << " declaring label " << block->label << "\n";
}
}
// Try catch not supported yet
DCHECK_EQ(stmt->catch_blocks.size(), 0);
Visit(stmt->try_block);
}
for (CatchBlock* block : stmt->catch_blocks) {
Visit(block->body);
}
for (LabelBlock* block : stmt->label_blocks) {
Visit(block->body);
}
......
......@@ -247,7 +247,7 @@ class DeclarationVisitor : public FileVisitor {
Visit(expr->location);
}
void Visit(TryCatchStatement* stmt);
void Visit(TryLabelStatement* stmt);
void GenerateHeader(std::string& file_name) {
std::stringstream new_contents_stream;
......
......@@ -871,7 +871,7 @@ const Type* ImplementationVisitor::Visit(ForOfLoopStatement* stmt) {
return TypeOracle::GetVoidType();
}
const Type* ImplementationVisitor::Visit(TryCatchStatement* stmt) {
const Type* ImplementationVisitor::Visit(TryLabelStatement* stmt) {
ScopedIndent indent(this);
Label* try_done = declarations()->DeclarePrivateLabel("try_done");
GenerateLabelDefinition(try_done);
......
......@@ -129,7 +129,7 @@ class ImplementationVisitor : public FileVisitor {
VisitResult Visit(StringLiteralExpression* expr);
VisitResult Visit(NumberLiteralExpression* expr);
const Type* Visit(TryCatchStatement* stmt);
const Type* Visit(TryLabelStatement* stmt);
const Type* Visit(ReturnStatement* stmt);
const Type* Visit(GotoStatement* stmt);
const Type* Visit(IfStatement* stmt);
......
......@@ -14,7 +14,7 @@ import re
cwd = os.getcwd()
tools = ntpath.dirname(sys.argv[0]);
grammar = tools + '/../src/torque/Torque.g4'
grammar = tools + '/../../src/torque/Torque.g4'
basename = ntpath.basename(grammar)
dirname = ntpath.dirname(grammar)
os.chdir(dirname)
......@@ -31,7 +31,7 @@ def fix_file(filename):
copyright = '// Copyright 2018 the V8 project authors. All rights reserved.\n'
copyright += '// Use of this source code is governed by a BSD-style license that can be\n'
copyright += '// found in the LICENSE file.\n'
file_path = tools + '/../src/torque/' + filename;
file_path = tools + '/../../src/torque/' + filename;
temp_file_path = file_path + '.tmp'
output_file = open(temp_file_path, 'w')
output_file.write(copyright);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment