From f5f0740be8102b4d719575d97b00dbd21b54ffbe Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 14 Mar 2024 14:45:57 -0700 Subject: Support unscoped enums. (#3771) --- source/slang/core.meta.slang | 3 +++ source/slang/slang-ast-modifier.h | 4 ++++ source/slang/slang-check-modifier.cpp | 10 +++++++++- source/slang/slang-lookup.cpp | 3 ++- 4 files changed, 18 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 54a82c4f0..237daac56 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -2345,6 +2345,9 @@ attribute_syntax [spv_target_env_1_3] : SPIRVTargetEnv13Attribute; __attributeTarget(VarDeclBase) attribute_syntax [disable_array_flattening] : DisableArrayFlatteningAttribute; +__attributeTarget(EnumDecl) +attribute_syntax [UnscopedEnum] : UnscopedEnumAttribute; + // Statement Attributes __attributeTarget(LoopStmt) diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h index 49dc1b81f..32852496c 100644 --- a/source/slang/slang-ast-modifier.h +++ b/source/slang/slang-ast-modifier.h @@ -713,6 +713,10 @@ class CallAttribute : public Attribute }; // `[call]` +class UnscopedEnumAttribute : public Attribute +{ + SLANG_AST_CLASS(UnscopedEnumAttribute) +}; // [[vk_push_constant]] [[push_constant]] class PushConstantAttribute : public Attribute diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp index 6359096b9..eae993dc7 100644 --- a/source/slang/slang-check-modifier.cpp +++ b/source/slang/slang-check-modifier.cpp @@ -1173,7 +1173,15 @@ namespace Slang // the right syntax class to instantiate. // - return checkAttribute(hlslUncheckedAttribute, syntaxNode); + auto checkedAttr = checkAttribute(hlslUncheckedAttribute, syntaxNode); + + if (as(checkedAttr)) + { + if (auto parentDecl = as(getParentDecl(as(syntaxNode)))) + parentDecl->invalidateMemberDictionary(); + return getASTBuilder()->create(); + } + return checkedAttr; } if (auto decl = as(syntaxNode)) diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index 04a855c3c..301c86aa8 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -648,7 +648,8 @@ static void _lookUpMembersInValue( // in the *type* of that value. // auto valueType = getTypeForDeclRef(astBuilder, valueDeclRef, SourceLoc()); - + if (auto typeType = as(valueType)) + valueType = typeType->getType(); return _lookUpMembersInType(astBuilder, name, valueType, request, ioResult, breadcrumbs); } -- cgit v1.2.3