From d898d561e3c76ecf38db434ec7fbb4bbd0e25cb2 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 18 Nov 2020 14:52:58 -0500 Subject: Serialized stdlib working (#1603) * #include an absolute path didn't work - because paths were taken to always be relative. * Mangling/module name extraction for GenericDecl * Add comment on SerialFilter to explain re-enabling Stmt. * Support setting up SyntaxDecl when reconstructed after deserialization. * Improvements to setup SyntaxDecl. * Fix typo so can read compressed SourceLocs. * Fix issue with SourceManger. --- source/slang/slang-serialize-container.cpp | 71 +++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 11 deletions(-) (limited to 'source/slang/slang-serialize-container.cpp') diff --git a/source/slang/slang-serialize-container.cpp b/source/slang/slang-serialize-container.cpp index 067e6637a..abdc382f9 100644 --- a/source/slang/slang-serialize-container.cpp +++ b/source/slang/slang-serialize-container.cpp @@ -12,6 +12,8 @@ #include "slang-serialize-source-loc.h" #include "slang-serialize-factory.h" +#include "slang-parser.h" + #include "slang-mangled-lexer.h" namespace Slang { @@ -490,27 +492,74 @@ static List& _getCandidateExtensionList( astRootNode = reader.getPointer(SerialIndex(1)).dynamicCast(); // 2) Add the extensions to the module mapTypeToCandidateExtensions cache + // 3) We need to fix the callback pointers for parsing { ModuleDecl* moduleDecl = as(astRootNode); - + + // Maps from keyword name name to index in (syntaxParseInfos) + // Will be filled in lazily if needed (for SyntaxDecl setup) + Dictionary syntaxKeywordDict; + + // Get the parse infos + const auto syntaxParseInfos = getSyntaxParseInfos(); + SLANG_ASSERT(syntaxParseInfos.getCount()); + for (auto& obj : reader.getObjects()) { - if (Type* type = obj.dynamicCast()) + if (obj.m_kind == SerialTypeKind::NodeBase) { - type->_setASTBuilder(astBuilder); - } + NodeBase* nodeBase = (NodeBase*)obj.m_ptr; + SLANG_ASSERT(nodeBase); - if (ExtensionDecl* extensionDecl = obj.dynamicCast()) - { - if (auto targetDeclRefType = as(extensionDecl->targetType)) + if (Type* type = dynamicCast(nodeBase)) + { + type->_setASTBuilder(astBuilder); + } + else if (ExtensionDecl* extensionDecl = dynamicCast(nodeBase)) { - // Attach our extension to that type as a candidate... - if (auto aggTypeDeclRef = targetDeclRefType->declRef.as()) + if (auto targetDeclRefType = as(extensionDecl->targetType)) { - auto aggTypeDecl = aggTypeDeclRef.getDecl(); + // Attach our extension to that type as a candidate... + if (auto aggTypeDeclRef = targetDeclRefType->declRef.as()) + { + auto aggTypeDecl = aggTypeDeclRef.getDecl(); - _getCandidateExtensionList(aggTypeDecl, moduleDecl->mapTypeToCandidateExtensions).add(extensionDecl); + _getCandidateExtensionList(aggTypeDecl, moduleDecl->mapTypeToCandidateExtensions).add(extensionDecl); + } + } + } + else if (SyntaxDecl* syntaxDecl = dynamicCast(nodeBase)) + { + // Set up the dictionary lazily + if (syntaxKeywordDict.Count() == 0) + { + NamePool* namePool = options.session->getNamePool(); + for (Index i = 0; i < syntaxParseInfos.getCount(); ++i) + { + const auto& entry = syntaxParseInfos[i]; + syntaxKeywordDict.Add(namePool->getName(entry.keywordName), i); + } + // Must have something in it at this point + SLANG_ASSERT(syntaxKeywordDict.Count()); + } + + // Look up the index + Index* entryIndexPtr = syntaxKeywordDict.TryGetValue(syntaxDecl->getName()); + if (entryIndexPtr) + { + // Set up SyntaxDecl based on the ParseSyntaxIndo + auto& info = syntaxParseInfos[*entryIndexPtr]; + syntaxDecl->parseCallback = *info.callback; + syntaxDecl->parseUserData = const_cast(info.classInfo); + } + else + { + // If we don't find a setup entry, we use `parseSimpleSyntax`, and set + // the parseUserData to the ReflectClassInfo (as parseSimpleSyntax needs this) + syntaxDecl->parseCallback = &parseSimpleSyntax; + SLANG_ASSERT(syntaxDecl->syntaxClass.classInfo); + syntaxDecl->parseUserData = const_cast(syntaxDecl->syntaxClass.classInfo); } } } -- cgit v1.2.3