From 2e2c7943da89b0100db3bba4b11267b5a857ca92 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 20 Feb 2024 23:13:29 -0800 Subject: Language server robustness fix. (#3607) * Language server robustness fix. * Allow parameter name to be the same as its type. * fix * Fix test. --- source/slang/slang-parser.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'source/slang/slang-parser.cpp') 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(); 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(); - 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(); parameter->modifiers = ParseModifiers(this); - + currentLookupScope = currentScope->parent; _parseTraditionalParamDeclCommonBase(this, parameter, kDeclaratorParseOption_AllowEmpty); - + resetLookupScope(); return parameter; } -- cgit v1.2.3