diff options
| author | Yong He <yonghe@outlook.com> | 2024-02-06 16:30:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-06 16:30:31 -0800 |
| commit | ab41d548db376c6b52869004d1b6e21b88b4c9c8 (patch) | |
| tree | 61aacddad8b8c56d77cf63ab3b650fdb28bbe0e6 /source/slang/slang-parser.cpp | |
| parent | 6365e00179179f2bc0bc25af3d51d528501498d5 (diff) | |
Improve Capability System (#3555)
* Improve capability system.
* Update documentation.
* Tuning semantics.
* LSP: hierarchical diagnostics.
* Fix test.
* Fix test.
Diffstat (limited to 'source/slang/slang-parser.cpp')
| -rw-r--r-- | source/slang/slang-parser.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 4b6d9b2d0..45fa5a125 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -3537,6 +3537,28 @@ namespace Slang return fileDecl; } + static NodeBase* parseRequireCapabilityDecl(Parser* parser, void*) + { + auto decl = parser->astBuilder->create<RequireCapabilityDecl>(); + parser->FillPosition(decl); + List<CapabilityName> capNames; + while (parser->LookAheadToken(TokenType::Identifier)) + { + auto capNameToken = parser->ReadToken(TokenType::Identifier); + CapabilityName capName = findCapabilityName(capNameToken.getContent()); + if (capName != CapabilityName::Invalid) + capNames.add(capName); + else + parser->sink->diagnose(capNameToken, Diagnostics::unknownCapability, capNameToken.getContent()); + if (AdvanceIf(parser, "+") || AdvanceIf(parser, ",")) + continue; + break; + } + decl->inferredCapabilityRequirements = CapabilitySet(capNames); + parser->ReadToken(TokenType::Semicolon); + return decl; + } + static NodeBase* parseConstructorDecl(Parser* parser, void* /*userData*/) { ConstructorDecl* decl = parser->astBuilder->create<ConstructorDecl>(); @@ -4351,7 +4373,20 @@ namespace Slang Decl* declToModify = decl; if(auto genericDecl = as<GenericDecl>(decl)) declToModify = genericDecl->inner; - _addModifiers(declToModify, modifiers); + + if (as<ModuleDeclarationDecl>(decl)) + { + // Modifiers on module declaration should be added to the module itself. + auto moduleDecl = getModuleDecl(containerDecl); + if (moduleDecl) + { + _addModifiers(moduleDecl, modifiers); + } + } + else + { + _addModifiers(declToModify, modifiers); + } if (containerDecl) { @@ -7901,7 +7936,7 @@ namespace Slang _makeParseDecl("__ignored_block", parseIgnoredBlockDecl ), _makeParseDecl("__transparent_block", parseTransparentBlockDecl), _makeParseDecl("__file_decl", parseFileDecl), - + _makeParseDecl("__require_capability", parseRequireCapabilityDecl), // !!!!!!!!!!!!!!!!!!!!!! Modifer !!!!!!!!!!!!!!!!!!!!!! |
