From 43c146794aab638924d2ab838d10f8af2ebf02a7 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 5 Jun 2020 18:20:09 -0400 Subject: ASTNodes use MemoryArena (#1376) * Add a ASTBuilder to a Module Only construct on valid ASTBuilder (was being called on nullptr on occassion) * Add nodes to ASTBuilder. * Compiles with RefPtr removed from AST node types. * Initialize all AST node pointer variables in headers to nullptr; * Initialize AST node variables as nullptr. Make ASTBuilder keep a ref on node types. Make SyntaxParseCallback returns a NodeBase * Don't release canonicalType on dtor (managed by ASTBuilder). * Give ASTBuilders a name and id, to help in debugging. For now destroy the session TypeCache, to stop it holding things released when the compile request destroys ASTBuilders. * Moved the TypeCheckingCache over to Linkage from Session. * NodeBase no longer derived from RefObject. * Only add/dtor nodes that need destruction. First pass compile on linux. --- source/slang/slang-ast-reflect.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (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 689d9d93f..7d4fd0c1a 100644 --- a/source/slang/slang-ast-reflect.cpp +++ b/source/slang/slang-ast-reflect.cpp @@ -46,9 +46,18 @@ bool ReflectClassInfo::isSubClassOfSlow(const ThisType& super) const struct ASTConstructAccess { template - struct CreateImpl + struct Impl { - static void* create(ASTBuilder* astBuilder) { return astBuilder->create(); } + static void* create(ASTBuilder* astBuilder) + { + return astBuilder->create(); + } + static void destroy(void* ptr) + { + // Needed because if type has non dtor, Visual Studio claims ptr not used + SLANG_UNUSED(ptr); + reinterpret_cast(ptr)->~T(); + } }; }; @@ -57,14 +66,13 @@ struct ASTConstructAccess #define SLANG_GET_SUPER_LEAF(SUPER) &SUPER::kReflectClassInfo #define SLANG_GET_CREATE_FUNC_ABSTRACT(NAME) nullptr -#define SLANG_GET_CREATE_FUNC_NONE(NAME) &ASTConstructAccess::CreateImpl::create - -#define SLANG_GET_CREATE_FUNC_NON_VISITOR_ABSTRACT(NAME) nullptr -#define SLANG_GET_CREATE_FUNC_NON_VISITOR(NAME) &ASTConstructAccess::CreateImpl::create +#define SLANG_GET_CREATE_FUNC_NONE(NAME) &ASTConstructAccess::Impl::create +#define SLANG_GET_DESTROY_FUNC_ABSTRACT(NAME) nullptr +#define SLANG_GET_DESTROY_FUNC_NONE(NAME) &ASTConstructAccess::Impl::destroy #define SLANG_REFLECT_CLASS_INFO(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \ - /* static */const ReflectClassInfo NAME::kReflectClassInfo = { uint32_t(ASTNodeType::NAME), uint32_t(ASTNodeType::LAST), SLANG_GET_SUPER_##TYPE(SUPER), #NAME, SLANG_GET_CREATE_FUNC_##MARKER(NAME) }; + /* static */const ReflectClassInfo NAME::kReflectClassInfo = { uint32_t(ASTNodeType::NAME), uint32_t(ASTNodeType::LAST), SLANG_GET_SUPER_##TYPE(SUPER), #NAME, SLANG_GET_CREATE_FUNC_##MARKER(NAME), SLANG_GET_DESTROY_FUNC_##MARKER(NAME) }; SLANG_ALL_ASTNode_NodeBase(SLANG_REFLECT_CLASS_INFO, _) -- cgit v1.2.3