From 4cb899f824ee5e4421f36506e4c77f682b238b09 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 16 Mar 2023 15:19:20 -0400 Subject: Preliminary SourceMap support (#2701) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP source map. * Split out handling of RttiTypeFuncs to a map type. * Make RttiTypeFuncsMap hold default impls. * Slightly more sophisticated RttiTypeFuncsMap * Source map decoding. * Fix tabs. * Fix asserts due to negative values. * Use less obscure mechanisms in SourceMap. --- source/core/slang-rtti-info.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'source/core/slang-rtti-info.cpp') diff --git a/source/core/slang-rtti-info.cpp b/source/core/slang-rtti-info.cpp index 043e6490a..c35444d03 100644 --- a/source/core/slang-rtti-info.cpp +++ b/source/core/slang-rtti-info.cpp @@ -2,6 +2,8 @@ #include "../../slang-com-helper.h" +#include "slang-rtti-util.h" + #include namespace Slang { @@ -191,4 +193,35 @@ StructRttiInfo StructRttiBuilder::make() return m_rttiInfo; } +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RttiTypeFuncsMap !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +RttiTypeFuncs RttiTypeFuncsMap::getFuncsForType(const RttiInfo* rttiInfo) +{ + if (auto funcsPtr = m_map.TryGetValue(rttiInfo)) + { + return *funcsPtr; + } + + // Try to get the default impl + // NOTE! funcs could be invalid if there is no default impl. + const auto funcs = RttiUtil::getDefaultTypeFuncs(rttiInfo); + + // Add to the map + m_map.Add(rttiInfo, funcs); + return funcs; +} + +void RttiTypeFuncsMap::add(const RttiInfo* rttiInfo, const RttiTypeFuncs& funcs) +{ + if (auto funcsPtr = m_map.TryGetValueOrAdd(rttiInfo, funcs)) + { + // If there are funcs set, they aren't valid otherwise this would be + // replacing, so assert on that scenario. + SLANG_ASSERT(!funcsPtr->isValid()); + + // Replace the funcs + *funcsPtr = funcs; + } +} + } // namespace Slang -- cgit v1.2.3