From 318adcc27b8d89ec1d47c445a93239dd81be0b31 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 12 Jun 2024 09:45:26 -0700 Subject: Add compiler option to treat enum types as unscoped. (#4354) --- source/slang/slang-parser.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-parser.cpp') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index f5a217354..3d9f1c199 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -4907,14 +4907,38 @@ namespace Slang // TODO: diagnose this with a warning some day, and move // toward deprecating it. // - AdvanceIf(parser, "class"); + bool isEnumClass = AdvanceIf(parser, "class"); + bool isUnscoped = false; + + if (!isEnumClass) + { + if (parser->options.optionSet.getBoolOption(CompilerOptionName::UnscopedEnum)) + { + isUnscoped = true; + } + } AdvanceIf(parser, TokenType::CompletionRequest); parser->FillPosition(decl); - decl->nameAndLoc = expectIdentifier(parser); + if (parser->tokenReader.peekTokenType() != TokenType::Identifier) + { + decl->nameAndLoc.name = generateName(parser); + decl->nameAndLoc.loc = decl->loc; + isUnscoped = true; + } + else + { + decl->nameAndLoc = expectIdentifier(parser); + } + // If the type needs to be unscoped, insert modifiers to make it so. + if (isUnscoped) + { + addModifier(decl, parser->astBuilder->create()); + addModifier(decl, parser->astBuilder->create()); + } return parseOptGenericDecl(parser, [&](GenericDecl*) { -- cgit v1.2.3