@@ -48,30 +48,32 @@ void ASTScopeImpl::unqualifiedLookup(
4848const ASTScopeImpl *ASTScopeImpl::findStartingScopeForLookup (
4949 SourceFile *sourceFile, const SourceLoc loc) {
5050 auto *const fileScope = sourceFile->getScope ().impl ;
51- const auto *innermost = fileScope->findInnermostEnclosingScope (loc, nullptr );
51+ const auto *innermost = fileScope->findInnermostEnclosingScope (
52+ sourceFile->getParentModule (), loc, nullptr );
5253 ASTScopeAssert (innermost->getWasExpanded (),
5354 " If looking in a scope, it must have been expanded." );
5455
5556 return innermost;
5657}
5758
5859ASTScopeImpl *
59- ASTScopeImpl::findInnermostEnclosingScope (SourceLoc loc,
60+ ASTScopeImpl::findInnermostEnclosingScope (ModuleDecl *parentModule,
61+ SourceLoc loc,
6062 NullablePtr<raw_ostream> os) {
61- return findInnermostEnclosingScopeImpl (loc, os, getSourceManager () ,
62- getScopeCreator ());
63+ return findInnermostEnclosingScopeImpl (parentModule, loc, os ,
64+ getSourceManager (), getScopeCreator ());
6365}
6466
6567ASTScopeImpl *ASTScopeImpl::findInnermostEnclosingScopeImpl (
66- SourceLoc loc, NullablePtr<raw_ostream> os, SourceManager &sourceMgr ,
67- ScopeCreator &scopeCreator) {
68+ ModuleDecl *parentModule, SourceLoc loc, NullablePtr<raw_ostream> os,
69+ SourceManager &sourceMgr, ScopeCreator &scopeCreator) {
6870 if (!getWasExpanded ())
6971 expandAndBeCurrent (scopeCreator);
70- auto child = findChildContaining (loc, sourceMgr);
72+ auto child = findChildContaining (parentModule, loc, sourceMgr);
7173 if (!child)
7274 return this ;
73- return child.get ()->findInnermostEnclosingScopeImpl (loc, os, sourceMgr ,
74- scopeCreator);
75+ return child.get ()->findInnermostEnclosingScopeImpl (parentModule, loc, os ,
76+ sourceMgr, scopeCreator);
7577}
7678
7779// / If the \p loc is in a new buffer but \p range is not, consider the location
@@ -89,10 +91,10 @@ static SourceLoc translateLocForReplacedRange(SourceManager &sourceMgr,
8991}
9092
9193NullablePtr<ASTScopeImpl>
92- ASTScopeImpl::findChildContaining (SourceLoc loc,
94+ ASTScopeImpl::findChildContaining (ModuleDecl *parentModule,
95+ SourceLoc loc,
9396 SourceManager &sourceMgr) const {
94- auto *moduleDecl = this ->getSourceFile ()->getParentModule ();
95- auto *locSourceFile = moduleDecl->getSourceFileContainingLocation (loc);
97+ auto *locSourceFile = parentModule->getSourceFileContainingLocation (loc);
9698
9799 // Use binary search to find the child that contains this location.
98100 auto *const *child = llvm::lower_bound (
@@ -109,7 +111,7 @@ ASTScopeImpl::findChildContaining(SourceLoc loc,
109111 // Note that `scope->getSourceFile()` returns the root of the source tree,
110112 // not the source file containing the location of the ASTScope.
111113 auto scopeStart = scope->getSourceRangeOfThisASTNode ().Start ;
112- auto *scopeSourceFile = moduleDecl ->getSourceFileContainingLocation (scopeStart);
114+ auto *scopeSourceFile = parentModule ->getSourceFileContainingLocation (scopeStart);
113115
114116 if (scopeSourceFile != locSourceFile) {
115117 // To compare a source location that is possibly inside a macro expansion
@@ -624,7 +626,8 @@ llvm::SmallVector<LabeledStmt *, 4>
624626ASTScopeImpl::lookupLabeledStmts (SourceFile *sourceFile, SourceLoc loc) {
625627 // Find the innermost scope from which to start our search.
626628 auto *const fileScope = sourceFile->getScope ().impl ;
627- const auto *innermost = fileScope->findInnermostEnclosingScope (loc, nullptr );
629+ const auto *innermost = fileScope->findInnermostEnclosingScope (
630+ sourceFile->getParentModule (), loc, nullptr );
628631 ASTScopeAssert (innermost->getWasExpanded (),
629632 " If looking in a scope, it must have been expanded." );
630633
@@ -652,7 +655,8 @@ std::pair<CaseStmt *, CaseStmt *> ASTScopeImpl::lookupFallthroughSourceAndDest(
652655 SourceFile *sourceFile, SourceLoc loc) {
653656 // Find the innermost scope from which to start our search.
654657 auto *const fileScope = sourceFile->getScope ().impl ;
655- const auto *innermost = fileScope->findInnermostEnclosingScope (loc, nullptr );
658+ const auto *innermost = fileScope->findInnermostEnclosingScope (
659+ sourceFile->getParentModule (), loc, nullptr );
656660 ASTScopeAssert (innermost->getWasExpanded (),
657661 " If looking in a scope, it must have been expanded." );
658662
@@ -686,7 +690,8 @@ void ASTScopeImpl::lookupEnclosingMacroScope(
686690 return ;
687691
688692 auto *fileScope = sourceFile->getScope ().impl ;
689- auto *scope = fileScope->findInnermostEnclosingScope (loc, nullptr );
693+ auto *scope = fileScope->findInnermostEnclosingScope (
694+ sourceFile->getParentModule (), loc, nullptr );
690695 do {
691696 auto *freestanding = scope->getFreestandingMacro ().getPtrOrNull ();
692697 if (freestanding && consume (freestanding))
0 commit comments