diff options
| author | Yong He <yonghe@outlook.com> | 2024-02-20 23:13:29 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-20 23:13:29 -0800 |
| commit | 2e2c7943da89b0100db3bba4b11267b5a857ca92 (patch) | |
| tree | 8cbf8010e964cdbb7381fa15b1062b2c43cbd870 /source/slang/slang-parser.cpp | |
| parent | 2ee05c1257c916e5c804a6b565a2a6aa362050e0 (diff) | |
Language server robustness fix. (#3607)
* Language server robustness fix.
* Allow parameter name to be the same as its type.
* fix
* Fix test.
Diffstat (limited to 'source/slang/slang-parser.cpp')
| -rw-r--r-- | source/slang/slang-parser.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index b208e1098..ad4e65bf2 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -105,7 +105,8 @@ namespace Slang int sameTokenPeekedTimes = 0; Scope* outerScope = nullptr; - Scope* currentScope = nullptr; + Scope* currentLookupScope = nullptr; // Scope where expr lookup should initiate from. + Scope* currentScope = nullptr; // Scope where new decl definitions should be inserted into. ModuleDecl* currentModule = nullptr; bool hasSeenCompletionToken = false; @@ -126,20 +127,20 @@ namespace Slang { node->loc = tokenReader.peekLoc(); } - void PushScope(ContainerDecl* containerDecl) + + void resetLookupScope() { - // TODO(JS): - // - // Previously Scope was ref counted. This meant that if a scope was pushed, but not used when popped - // it's memory would be freed. - // - // Here the memory is consumed and will not be freed until the astBuilder goes out of scope. + currentLookupScope = currentScope; + } + void PushScope(ContainerDecl* containerDecl) + { Scope* newScope = astBuilder->create<Scope>(); newScope->containerDecl = containerDecl; newScope->parent = currentScope; currentScope = newScope; containerDecl->ownedScope = newScope; + resetLookupScope(); } void pushScopeAndSetParent(ContainerDecl* containerDecl) @@ -151,6 +152,7 @@ namespace Slang void PopScope() { currentScope = currentScope->parent; + resetLookupScope(); } ModuleDecl* getCurrentModuleDecl() @@ -2554,7 +2556,7 @@ namespace Slang Token typeName = parser->ReadToken(TokenType::Identifier); auto basicType = parser->astBuilder->create<VarExpr>(); - basicType->scope = parser->currentScope; + basicType->scope = parser->currentLookupScope; basicType->loc = typeName.loc; basicType->name = typeName.getNameOrNull(); @@ -5591,9 +5593,9 @@ namespace Slang { ParamDecl* parameter = astBuilder->create<ParamDecl>(); parameter->modifiers = ParseModifiers(this); - + currentLookupScope = currentScope->parent; _parseTraditionalParamDeclCommonBase(this, parameter, kDeclaratorParseOption_AllowEmpty); - + resetLookupScope(); return parameter; } |
