summaryrefslogtreecommitdiff
path: root/src/expr-visitor.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr-visitor.cc')
-rw-r--r--src/expr-visitor.cc101
1 files changed, 55 insertions, 46 deletions
diff --git a/src/expr-visitor.cc b/src/expr-visitor.cc
index db34a49b..451c2e55 100644
--- a/src/expr-visitor.cc
+++ b/src/expr-visitor.cc
@@ -31,137 +31,146 @@ ExprVisitor::ExprVisitor(Delegate* delegate) : delegate_(delegate) {}
Result ExprVisitor::VisitExpr(Expr* expr) {
switch (expr->type) {
case ExprType::Binary:
- CHECK_RESULT(delegate_->OnBinaryExpr(expr));
+ CHECK_RESULT(delegate_->OnBinaryExpr(expr->As<BinaryExpr>()));
break;
- case ExprType::Block:
- CHECK_RESULT(delegate_->BeginBlockExpr(expr));
- CHECK_RESULT(VisitExprList(expr->block->first));
- CHECK_RESULT(delegate_->EndBlockExpr(expr));
+ case ExprType::Block: {
+ auto block_expr = expr->As<BlockExpr>();
+ CHECK_RESULT(delegate_->BeginBlockExpr(block_expr));
+ CHECK_RESULT(VisitExprList(block_expr->block->first));
+ CHECK_RESULT(delegate_->EndBlockExpr(block_expr));
break;
+ }
case ExprType::Br:
- CHECK_RESULT(delegate_->OnBrExpr(expr));
+ CHECK_RESULT(delegate_->OnBrExpr(expr->As<BrExpr>()));
break;
case ExprType::BrIf:
- CHECK_RESULT(delegate_->OnBrIfExpr(expr));
+ CHECK_RESULT(delegate_->OnBrIfExpr(expr->As<BrIfExpr>()));
break;
case ExprType::BrTable:
- CHECK_RESULT(delegate_->OnBrTableExpr(expr));
+ CHECK_RESULT(delegate_->OnBrTableExpr(expr->As<BrTableExpr>()));
break;
case ExprType::Call:
- CHECK_RESULT(delegate_->OnCallExpr(expr));
+ CHECK_RESULT(delegate_->OnCallExpr(expr->As<CallExpr>()));
break;
case ExprType::CallIndirect:
- CHECK_RESULT(delegate_->OnCallIndirectExpr(expr));
+ CHECK_RESULT(delegate_->OnCallIndirectExpr(expr->As<CallIndirectExpr>()));
break;
case ExprType::Compare:
- CHECK_RESULT(delegate_->OnCompareExpr(expr));
+ CHECK_RESULT(delegate_->OnCompareExpr(expr->As<CompareExpr>()));
break;
case ExprType::Const:
- CHECK_RESULT(delegate_->OnConstExpr(expr));
+ CHECK_RESULT(delegate_->OnConstExpr(expr->As<ConstExpr>()));
break;
case ExprType::Convert:
- CHECK_RESULT(delegate_->OnConvertExpr(expr));
+ CHECK_RESULT(delegate_->OnConvertExpr(expr->As<ConvertExpr>()));
break;
case ExprType::CurrentMemory:
- CHECK_RESULT(delegate_->OnCurrentMemoryExpr(expr));
+ CHECK_RESULT(
+ delegate_->OnCurrentMemoryExpr(expr->As<CurrentMemoryExpr>()));
break;
case ExprType::Drop:
- CHECK_RESULT(delegate_->OnDropExpr(expr));
+ CHECK_RESULT(delegate_->OnDropExpr(expr->As<DropExpr>()));
break;
case ExprType::GetGlobal:
- CHECK_RESULT(delegate_->OnGetGlobalExpr(expr));
+ CHECK_RESULT(delegate_->OnGetGlobalExpr(expr->As<GetGlobalExpr>()));
break;
case ExprType::GetLocal:
- CHECK_RESULT(delegate_->OnGetLocalExpr(expr));
+ CHECK_RESULT(delegate_->OnGetLocalExpr(expr->As<GetLocalExpr>()));
break;
case ExprType::GrowMemory:
- CHECK_RESULT(delegate_->OnGrowMemoryExpr(expr));
+ CHECK_RESULT(delegate_->OnGrowMemoryExpr(expr->As<GrowMemoryExpr>()));
break;
- case ExprType::If:
- CHECK_RESULT(delegate_->BeginIfExpr(expr));
- CHECK_RESULT(VisitExprList(expr->if_.true_->first));
- CHECK_RESULT(delegate_->AfterIfTrueExpr(expr));
- CHECK_RESULT(VisitExprList(expr->if_.false_));
- CHECK_RESULT(delegate_->EndIfExpr(expr));
+ case ExprType::If: {
+ auto if_expr = expr->As<IfExpr>();
+ CHECK_RESULT(delegate_->BeginIfExpr(if_expr));
+ CHECK_RESULT(VisitExprList(if_expr->true_->first));
+ CHECK_RESULT(delegate_->AfterIfTrueExpr(if_expr));
+ CHECK_RESULT(VisitExprList(if_expr->false_));
+ CHECK_RESULT(delegate_->EndIfExpr(if_expr));
break;
+ }
case ExprType::Load:
- CHECK_RESULT(delegate_->OnLoadExpr(expr));
+ CHECK_RESULT(delegate_->OnLoadExpr(expr->As<LoadExpr>()));
break;
- case ExprType::Loop:
- CHECK_RESULT(delegate_->BeginLoopExpr(expr));
- CHECK_RESULT(VisitExprList(expr->loop->first));
- CHECK_RESULT(delegate_->EndLoopExpr(expr));
+ case ExprType::Loop: {
+ auto loop_expr = expr->As<LoopExpr>();
+ CHECK_RESULT(delegate_->BeginLoopExpr(loop_expr));
+ CHECK_RESULT(VisitExprList(loop_expr->block->first));
+ CHECK_RESULT(delegate_->EndLoopExpr(loop_expr));
break;
+ }
case ExprType::Nop:
- CHECK_RESULT(delegate_->OnNopExpr(expr));
+ CHECK_RESULT(delegate_->OnNopExpr(expr->As<NopExpr>()));
break;
case ExprType::Rethrow:
- CHECK_RESULT(delegate_->OnRethrowExpr(expr));
+ CHECK_RESULT(delegate_->OnRethrowExpr(expr->As<RethrowExpr>()));
break;
case ExprType::Return:
- CHECK_RESULT(delegate_->OnReturnExpr(expr));
+ CHECK_RESULT(delegate_->OnReturnExpr(expr->As<ReturnExpr>()));
break;
case ExprType::Select:
- CHECK_RESULT(delegate_->OnSelectExpr(expr));
+ CHECK_RESULT(delegate_->OnSelectExpr(expr->As<SelectExpr>()));
break;
case ExprType::SetGlobal:
- CHECK_RESULT(delegate_->OnSetGlobalExpr(expr));
+ CHECK_RESULT(delegate_->OnSetGlobalExpr(expr->As<SetGlobalExpr>()));
break;
case ExprType::SetLocal:
- CHECK_RESULT(delegate_->OnSetLocalExpr(expr));
+ CHECK_RESULT(delegate_->OnSetLocalExpr(expr->As<SetLocalExpr>()));
break;
case ExprType::Store:
- CHECK_RESULT(delegate_->OnStoreExpr(expr));
+ CHECK_RESULT(delegate_->OnStoreExpr(expr->As<StoreExpr>()));
break;
case ExprType::TeeLocal:
- CHECK_RESULT(delegate_->OnTeeLocalExpr(expr));
+ CHECK_RESULT(delegate_->OnTeeLocalExpr(expr->As<TeeLocalExpr>()));
break;
case ExprType::Throw:
- CHECK_RESULT(delegate_->OnThrowExpr(expr));
+ CHECK_RESULT(delegate_->OnThrowExpr(expr->As<ThrowExpr>()));
break;
- case ExprType::TryBlock:
- CHECK_RESULT(delegate_->BeginTryExpr(expr));
- CHECK_RESULT(VisitExprList(expr->try_block.block->first));
- for (Catch* catch_ : *expr->try_block.catches) {
- CHECK_RESULT(delegate_->OnCatchExpr(expr, catch_));
+ case ExprType::TryBlock: {
+ auto try_expr = expr->As<TryExpr>();
+ CHECK_RESULT(delegate_->BeginTryExpr(try_expr));
+ CHECK_RESULT(VisitExprList(try_expr->block->first));
+ for (Catch* catch_ : try_expr->catches) {
+ CHECK_RESULT(delegate_->OnCatchExpr(try_expr, catch_));
CHECK_RESULT(VisitExprList(catch_->first));
}
- CHECK_RESULT(delegate_->EndTryExpr(expr));
+ CHECK_RESULT(delegate_->EndTryExpr(try_expr));
break;
+ }
case ExprType::Unary:
- CHECK_RESULT(delegate_->OnUnaryExpr(expr));
+ CHECK_RESULT(delegate_->OnUnaryExpr(expr->As<UnaryExpr>()));
break;
case ExprType::Unreachable:
- CHECK_RESULT(delegate_->OnUnreachableExpr(expr));
+ CHECK_RESULT(delegate_->OnUnreachableExpr(expr->As<UnreachableExpr>()));
break;
}