summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-parser.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-04-28 08:52:49 -0400
committerGitHub <noreply@github.com>2022-04-28 08:52:49 -0400
commit1f3298e3eecff60170f16b40739b4448d6403b8d (patch)
treeee2689627e00241e50f52af33ffcbaac701d09fc /source/slang/slang-parser.cpp
parent634f5414f332f904c7db968810b3d6f0ca253959 (diff)
Disable `class` keyword to define a new type (#2212)
* #include an absolute path didn't work - because paths were taken to always be relative. * Disable class keyword. * Add class keyword test. * Fix test diagnostic.
Diffstat (limited to 'source/slang/slang-parser.cpp')
-rw-r--r--source/slang/slang-parser.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 40bb91d77..466feecf1 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -2179,10 +2179,36 @@ namespace Slang
}
else if( parser->LookAheadToken("class") )
{
- auto decl = parser->ParseClass();
- typeSpec.decl = decl;
- typeSpec.expr = createDeclRefType(parser, decl);
- return typeSpec;
+ // TODO(JS): Class type doesn't currently have the correct semantics. This is covered here
+ // https://github.com/shader-slang/slang/issues/2206
+ //
+ // For now the use of `class` is disabled.
+ // The remaining code around `class` left intact as likely will be the basis for the future
+ // implementation.
+
+ const bool disableClass = true;
+
+ if (disableClass)
+ {
+ parser->sink->diagnose(parser->tokenReader.peekLoc(), Diagnostics::classIsReservedKeyword);
+
+ // Consume `class`
+ advanceToken(parser);
+
+ // Indicate in recovering state.
+ parser->isRecovering = true;
+
+ // Check to confirm the result is invalid
+ SLANG_ASSERT(typeSpec.decl == nullptr && typeSpec.expr == nullptr);
+ return typeSpec;
+ }
+ else
+ {
+ auto decl = parser->ParseClass();
+ typeSpec.decl = decl;
+ typeSpec.expr = createDeclRefType(parser, decl);
+ return typeSpec;
+ }
}
else if(parser->LookAheadToken("enum"))
{
@@ -2293,6 +2319,11 @@ namespace Slang
Modifiers modifiers = inModifiers;
auto typeSpec = _parseTypeSpec(parser, modifiers);
+ if (typeSpec.expr == nullptr && typeSpec.decl == nullptr)
+ {
+ return nullptr;
+ }
+
// We may need to build up multiple declarations in a group,
// but the common case will be when we have just a single
// declaration