summaryrefslogtreecommitdiff
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-02-28 09:21:19 -0500
committerGitHub <noreply@github.com>2020-02-28 09:21:19 -0500
commit6e9f407ad42ce635528b30f21366f903903a3682 (patch)
treea271d4118bd355fc71cc1dd6b7fb36de7e26f3dc /source/slang/slang.cpp
parent5e31e9f074ea0bb795b50272f904aebc520d3714 (diff)
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.
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp25
1 files changed, 13 insertions, 12 deletions
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<NAME>());
-
-#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<Slang::RefObject>(info));
+ }
+ }
// Make sure our source manager is initialized
builtinSourceManager.initialize(nullptr, nullptr);