From daf53bb2708982a2bcc6d6cc08fe88790ccf0bc2 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 21 May 2020 15:36:02 -0400 Subject: Non virtual accept implementation on AST types (#1351) * First pass impl of making accept on AST node types non virtual. * A single switch for ITypeVistor on Val type. * Use ORIGIN to choose ITypeVisitor dispatch. * Don't use ORIGIN - we don't need special handling for ITypeVisitor on Val derived types. --- source/slang/slang-ast-reflect.cpp | 79 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'source/slang/slang-ast-reflect.cpp') diff --git a/source/slang/slang-ast-reflect.cpp b/source/slang/slang-ast-reflect.cpp index 471daf92b..eb511689d 100644 --- a/source/slang/slang-ast-reflect.cpp +++ b/source/slang/slang-ast-reflect.cpp @@ -9,6 +9,8 @@ #include #include +#include "slang-visitor.h" + #include "slang-ast-generated-macro.h" namespace Slang @@ -66,5 +68,82 @@ struct CreateImpl SLANG_ALL_ASTNode_NodeBase(SLANG_REFLECT_CLASS_INFO, _) SLANG_ALL_ASTNode_Substitutions(SLANG_REFLECT_CLASS_INFO, _) +// We dispatch to non 'abstract' types +#define SLANG_CASE_NONE(NAME) case ASTNodeType::NAME: return visitor->dispatch_##NAME(static_cast(this), extra); +#define SLANG_CASE_ABSTRACT(NAME) + +#define SLANG_CASE_DISPATCH(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) SLANG_CASE_##MARKER(NAME) + +void Val::accept(IValVisitor* visitor, void* extra) +{ + const ReflectClassInfo& classInfo = getClassInfo(); + const ASTNodeType astType = ASTNodeType(classInfo.m_classId); + + switch (astType) + { + SLANG_CHILDREN_ASTNode_Val(SLANG_CASE_DISPATCH, _) + default: SLANG_ASSERT(!"Unknown type"); + } +} + +void Type::accept(ITypeVisitor* visitor, void* extra) +{ + const ReflectClassInfo& classInfo = getClassInfo(); + const ASTNodeType astType = ASTNodeType(classInfo.m_classId); + + switch (astType) + { + SLANG_CHILDREN_ASTNode_Type(SLANG_CASE_DISPATCH, _) + default: SLANG_ASSERT(!"Unknown type"); + } +} + +void Modifier::accept(IModifierVisitor* visitor, void* extra) +{ + const ReflectClassInfo& classInfo = getClassInfo(); + const ASTNodeType astType = ASTNodeType(classInfo.m_classId); + + switch (astType) + { + SLANG_CHILDREN_ASTNode_Modifier(SLANG_CASE_DISPATCH, _) + default: SLANG_ASSERT(!"Unknown type"); + } +} + +void DeclBase::accept(IDeclVisitor* visitor, void* extra) +{ + const ReflectClassInfo& classInfo = getClassInfo(); + const ASTNodeType astType = ASTNodeType(classInfo.m_classId); + + switch (astType) + { + SLANG_CHILDREN_ASTNode_DeclBase(SLANG_CASE_DISPATCH, _) + default: SLANG_ASSERT(!"Unknown type"); + } +} + +void Expr::accept(IExprVisitor* visitor, void* extra) +{ + const ReflectClassInfo& classInfo = getClassInfo(); + const ASTNodeType astType = ASTNodeType(classInfo.m_classId); + + switch (astType) + { + SLANG_CHILDREN_ASTNode_Expr(SLANG_CASE_DISPATCH, _) + default: SLANG_ASSERT(!"Unknown type"); + } +} + +void Stmt::accept(IStmtVisitor* visitor, void* extra) +{ + const ReflectClassInfo& classInfo = getClassInfo(); + const ASTNodeType astType = ASTNodeType(classInfo.m_classId); + + switch (astType) + { + SLANG_CHILDREN_ASTNode_Stmt(SLANG_CASE_DISPATCH, _) + default: SLANG_ASSERT(!"Unknown type"); + } +} } // namespace Slang -- cgit v1.2.3