diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-05-21 15:36:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-21 15:36:02 -0400 |
| commit | daf53bb2708982a2bcc6d6cc08fe88790ccf0bc2 (patch) | |
| tree | d72a1f5a820db75072cc1d6055a0f35cf6feaccd /source/slang/slang-ast-reflect.cpp | |
| parent | d90ae365210cdecdad7f66a7b2e3993df2cbb7d4 (diff) | |
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.
Diffstat (limited to 'source/slang/slang-ast-reflect.cpp')
| -rw-r--r-- | source/slang/slang-ast-reflect.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
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 <typeinfo> #include <assert.h> +#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<NAME*>(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 |
