From 6e9f407ad42ce635528b30f21366f903903a3682 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 28 Feb 2020 09:21:19 -0500 Subject: Constant time dynamic cast (#1250) * Constant time dynamic cast. * Use getClassInfo virtual function. Fix problem because of instanciation of specializations was in wrong order for clang. * Improve comments. * Improve comment. * Ensure s_first is defined before kClassInfo, to ensure construction ordering. --- source/slang/slang.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 08c996fd2..6c1a59ea4 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -116,20 +116,21 @@ void Session::init() // Set all the shared library function pointers to nullptr ::memset(m_sharedLibraryFunctions, 0, sizeof(m_sharedLibraryFunctions)); + { + static auto res = SyntaxClassBase::ClassInfo::initRanges(); + } + // Initialize the lookup table of syntax classes: - #define SYNTAX_CLASS(NAME, BASE) \ - mapNameToSyntaxClass.Add(getNamePool()->getName(#NAME), getClass()); - -#include "slang-object-meta-begin.h" -#include "slang-syntax-base-defs.h" -#include "slang-expr-defs.h" -#include "slang-decl-defs.h" -#include "slang-modifier-defs.h" -#include "slang-stmt-defs.h" -#include "slang-type-defs.h" -#include "slang-val-defs.h" -#include "slang-object-meta-end.h" + // We can just iterate over the class pointers. + // NOTE! That this adds the names of the abstract classes too(!) + { + const SyntaxClassBase::ClassInfo* info = SyntaxClassBase::ClassInfo::s_first; + for (; info; info = info->m_next) + { + mapNameToSyntaxClass.Add(getNamePool()->getName(info->m_name), SyntaxClass(info)); + } + } // Make sure our source manager is initialized builtinSourceManager.initialize(nullptr, nullptr); -- cgit v1.2.3