summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-ir.cc4
-rw-r--r--src/binary-writer.cc4
-rw-r--r--src/expr-visitor.cc4
-rw-r--r--src/ir.h4
-rw-r--r--src/wast-parser.cc42
-rw-r--r--src/wat-writer.cc4
6 files changed, 31 insertions, 31 deletions
diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc
index 19fec5c9..06f4fa00 100644
--- a/src/binary-reader-ir.cc
+++ b/src/binary-reader-ir.cc
@@ -1010,7 +1010,7 @@ Result BinaryReaderIR::AppendCatch(Catch&& catch_) {
return Result::Error;
}
- if (try_->kind == TryKind::Invalid) {
+ if (try_->kind == TryKind::Plain) {
try_->kind = TryKind::Catch;
} else if (try_->kind != TryKind::Catch) {
PrintError("catch not allowed in try-delegate");
@@ -1041,7 +1041,7 @@ Result BinaryReaderIR::OnDelegateExpr(Index depth) {
auto* try_ = cast<TryExpr>(label->context);
- if (try_->kind == TryKind::Invalid) {
+ if (try_->kind == TryKind::Plain) {
try_->kind = TryKind::Delegate;
} else if (try_->kind != TryKind::Delegate) {
PrintError("delegate not allowed in try-catch");
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index 5638bd4e..a1760023 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -1012,8 +1012,8 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) {
GetLabelVarDepth(&try_expr->delegate_target),
"delegate depth");
break;
- case TryKind::Invalid:
- // Should not occur.
+ case TryKind::Plain:
+ WriteOpcode(stream_, Opcode::End);
break;
}
break;
diff --git a/src/expr-visitor.cc b/src/expr-visitor.cc
index fa572285..369c63bb 100644
--- a/src/expr-visitor.cc
+++ b/src/expr-visitor.cc
@@ -110,8 +110,8 @@ Result ExprVisitor::VisitExpr(Expr* root_expr) {
case TryKind::Delegate:
CHECK_RESULT(delegate_->OnDelegateExpr(try_expr));
break;
- case TryKind::Invalid:
- // Should not happen.
+ case TryKind::Plain:
+ CHECK_RESULT(delegate_->EndTryExpr(try_expr));
break;
}
}
diff --git a/src/ir.h b/src/ir.h
index d68cd141..4e49a09e 100644
--- a/src/ir.h
+++ b/src/ir.h
@@ -378,7 +378,7 @@ struct Catch {
typedef std::vector<Catch> CatchVector;
enum class TryKind {
- Invalid,
+ Plain,
Catch,
Delegate
};
@@ -603,7 +603,7 @@ class IfExpr : public ExprMixin<ExprType::If> {
class TryExpr : public ExprMixin<ExprType::Try> {
public:
explicit TryExpr(const Location& loc = Location())
- : ExprMixin<ExprType::Try>(loc), kind(TryKind::Invalid) {}
+ : ExprMixin<ExprType::Try>(loc), kind(TryKind::Plain) {}
TryKind kind;
Block block;
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index 22dd5322..9fb09c5a 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -2597,8 +2597,6 @@ Result WastParser::ParseBlockInstr(std::unique_ptr<Expr>* out_expr) {
CHECK_RESULT(ParseVar(&var));
expr->delegate_target = var;
expr->kind = TryKind::Delegate;
- } else {
- return ErrorExpected({"catch", "catch_all", "delegate"});
}
CHECK_RESULT(ErrorIfLpar({"a valid try clause"}));
expr->block.end_loc = GetLocation();
@@ -2767,26 +2765,28 @@ Result WastParser::ParseExpr(ExprList* exprs) {
EXPECT(Do);
CHECK_RESULT(ParseInstrList(&expr->block.exprs));
EXPECT(Rpar);
- EXPECT(Lpar);
- TokenType type = Peek();
- switch (type) {
- case TokenType::Catch:
- case TokenType::CatchAll:
- CHECK_RESULT(ParseCatchExprList(&expr->catches));
- expr->kind = TryKind::Catch;
- break;
- case TokenType::Delegate: {
- Consume();
- Var var;
- CHECK_RESULT(ParseVar(&var));
- expr->delegate_target = var;
- expr->kind = TryKind::Delegate;
- EXPECT(Rpar);
- break;
+ if (PeekMatch(TokenType::Lpar)) {
+ Consume();
+ TokenType type = Peek();
+ switch (type) {
+ case TokenType::Catch:
+ case TokenType::CatchAll:
+ CHECK_RESULT(ParseCatchExprList(&expr->catches));
+ expr->kind = TryKind::Catch;
+ break;
+ case TokenType::Delegate: {
+ Consume();
+ Var var;
+ CHECK_RESULT(ParseVar(&var));
+ expr->delegate_target = var;
+ expr->kind = TryKind::Delegate;
+ EXPECT(Rpar);
+ break;
+ }
+ default:
+ ErrorExpected({"catch", "catch_all", "delegate"});
+ break;
}
- default:
- ErrorExpected({"catch", "catch_all", "delegate"});
- break;
}
CHECK_RESULT(ErrorIfLpar({"a valid try clause"}));
expr->block.end_loc = GetLocation();
diff --git a/src/wat-writer.cc b/src/wat-writer.cc
index 74964888..07e48799 100644
--- a/src/wat-writer.cc
+++ b/src/wat-writer.cc
@@ -1171,8 +1171,8 @@ void WatWriter::FlushExprTree(const ExprTree& expr_tree) {
WriteVar(try_expr->delegate_target, NextChar::None);
WritePuts(")", NextChar::Newline);
break;
- case TryKind::Invalid:
- // Should not occur.
+ case TryKind::Plain:
+ // Nothing to do.
break;
}
WriteCloseNewline();