From 3986d95de1f3d91e4ec2193bc70c6c4b4fdbd1bd Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 24 Oct 2022 12:33:54 -0700 Subject: [NFC] Inherit from Visitor in OverriddenVisitor (#5182) Doing so shortens the code by removing duplicate logic. Also this will avoid a compile error in a future PR, as by inheriting from Visitor we include functions like visitFunction which were otherwise missing from OverriddenVisitor. We could duplicate those like we duplicated the expression logic, but just removing all the duplication seems best. I manually verified OverriddenVisitor still provides the same error messages as before. --- src/wasm-traversal.h | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'src') diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 1f3cb9ca4..b70c17154 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -74,7 +74,7 @@ template struct Visitor { // A visitor which must be overridden for each visitor that is reached. template -struct OverriddenVisitor { +struct OverriddenVisitor : public Visitor { // Expression visitors, which must be overridden #define DELEGATE(CLASS_TO_VISIT) \ ReturnType visit##CLASS_TO_VISIT(CLASS_TO_VISIT* curr) { \ @@ -86,22 +86,6 @@ struct OverriddenVisitor { } #include "wasm-delegations.def" - - ReturnType visit(Expression* curr) { - assert(curr); - - switch (curr->_id) { -#define DELEGATE(CLASS_TO_VISIT) \ - case Expression::Id::CLASS_TO_VISIT##Id: \ - return static_cast(this)->visit##CLASS_TO_VISIT( \ - static_cast(curr)) - -#include "wasm-delegations.def" - - default: - WASM_UNREACHABLE("unexpected expression type"); - } - } }; // Visit with a single unified visitor, called on every node, instead of -- cgit v1.2.3