From 464ecb6083f64f903df19b961e2af0075bdf3111 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 5 Apr 2022 17:53:41 -0400 Subject: Fix issue with multiple namespace openings (#2176) * #include an absolute path didn't work - because paths were taken to always be relative. * Added sample-grad-clamp-lod sample. * Fix handling multiple reopenings of namespaces. --- source/slang/slang-ast-support-types.h | 3 +++ source/slang/slang-parser.cpp | 25 +++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'source') diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h index e7c2287ff..ffe7cd553 100644 --- a/source/slang/slang-ast-support-types.h +++ b/source/slang/slang-ast-support-types.h @@ -310,6 +310,9 @@ namespace Slang template bool hasModifier() { return findModifier() != nullptr; } + /// True if has no modifiers + bool isEmpty() const { return first == nullptr; } + FilteredModifierList::Iterator begin() { return FilteredModifierList::Iterator(first); } FilteredModifierList::Iterator end() { return FilteredModifierList::Iterator(nullptr); } }; diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 961691c9a..c08f5cf34 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -2928,8 +2928,7 @@ namespace Slang // any non-null pointer we return to the AST). // NamespaceDecl* namespaceDecl = nullptr; - NodeBase* result = nullptr; - // + // In order to find out what case we are in, we start by looking // for a namespace declaration of the same name in the parent // declaration. @@ -2985,14 +2984,6 @@ namespace Slang { namespaceDecl = parser->astBuilder->create(); namespaceDecl->nameAndLoc = nameAndLoc; - - // In the case where we are creating the first - // declaration of the given namesapce, we need - // to use it as the return value of the parsing - // callback, so that it is appropriately added - // to the parent declaration. - // - result = namespaceDecl; } } @@ -3003,7 +2994,7 @@ namespace Slang // parseDeclBody(parser, namespaceDecl); - return result; + return namespaceDecl; } static NodeBase* parseUsingDecl(Parser* parser, void* /*userData*/) @@ -3590,6 +3581,16 @@ namespace Slang ContainerDecl* containerDecl, Modifiers modifiers) { + + // If this is a namespace and already added, we don't want to add to the parent + // Or add any modifiers + if (as(decl) && decl->parentDecl) + { + // Presumably we have no modifiers. + SLANG_ASSERT(modifiers.isEmpty()); + return; + } + // Add any modifiers we parsed before the declaration to the list // of modifiers on the declaration itself. // @@ -3601,9 +3602,9 @@ namespace Slang declToModify = genericDecl->inner; _addModifiers(declToModify, modifiers); - // Make sure the decl is properly nested inside its lexical parent if (containerDecl) { + // Make sure the decl is properly nested inside its lexical parent AddMember(containerDecl, decl); } } -- cgit v1.2.3