summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-01-17 14:43:31 -0800
committerGitHub <noreply@github.com>2025-01-17 14:43:31 -0800
commitd1a13a730406646029cedd018bb9806943209baa (patch)
tree93f609f80111b923810d627209eed41f68fcba4f /source
parentfc77070fdc9bfa599e8d66b21743778de3011e53 (diff)
Allow __subscript<T> syntax. (#6124)
* Allow __subscript<T> syntax. * Fix.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-parser.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 6ae41a2eb..98cfd121c 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -3932,28 +3932,38 @@ static void parseStorageDeclBody(Parser* parser, ContainerDecl* decl)
static NodeBase* parseSubscriptDecl(Parser* parser, void* /*userData*/)
{
- SubscriptDecl* decl = parser->astBuilder->create<SubscriptDecl>();
- parser->FillPosition(decl);
- parser->PushScope(decl);
+ return parseOptGenericDecl(
+ parser,
+ [&](GenericDecl* genericParent)
+ {
+ SubscriptDecl* decl = parser->astBuilder->create<SubscriptDecl>();
+ parser->FillPosition(decl);
+ parser->PushScope(decl);
- // TODO: the use of this name here is a bit magical...
- decl->nameAndLoc.name = getName(parser, "operator[]");
+ // TODO: the use of this name here is a bit magical...
+ decl->nameAndLoc.name = getName(parser, "operator[]");
- parseParameterList(parser, decl);
+ parseParameterList(parser, decl);
- if (AdvanceIf(parser, TokenType::RightArrow))
- {
- decl->returnType = parser->ParseTypeExp();
- }
- else
- {
- decl->returnType.exp = parser->astBuilder->create<IncompleteExpr>();
- }
+ if (AdvanceIf(parser, TokenType::RightArrow))
+ {
+ decl->returnType = parser->ParseTypeExp();
+ }
+ else
+ {
+ decl->returnType.exp = parser->astBuilder->create<IncompleteExpr>();
+ }
- parseStorageDeclBody(parser, decl);
+ auto funcScope = parser->currentScope;
+ parser->PopScope();
+ maybeParseGenericConstraints(parser, genericParent);
+ parser->PushScope(funcScope);
- parser->PopScope();
- return decl;
+ parseStorageDeclBody(parser, decl);
+
+ parser->PopScope();
+ return decl;
+ });
}
/// Peek in the token stream and return `true` if it looks like a modern-style variable declaration