@@ -48,30 +48,32 @@ void ASTScopeImpl::unqualifiedLookup(
48
48
const ASTScopeImpl *ASTScopeImpl::findStartingScopeForLookup (
49
49
SourceFile *sourceFile, const SourceLoc loc) {
50
50
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 );
52
53
ASTScopeAssert (innermost->getWasExpanded (),
53
54
" If looking in a scope, it must have been expanded." );
54
55
55
56
return innermost;
56
57
}
57
58
58
59
ASTScopeImpl *
59
- ASTScopeImpl::findInnermostEnclosingScope (SourceLoc loc,
60
+ ASTScopeImpl::findInnermostEnclosingScope (ModuleDecl *parentModule,
61
+ SourceLoc loc,
60
62
NullablePtr<raw_ostream> os) {
61
- return findInnermostEnclosingScopeImpl (loc, os, getSourceManager () ,
62
- getScopeCreator ());
63
+ return findInnermostEnclosingScopeImpl (parentModule, loc, os ,
64
+ getSourceManager (), getScopeCreator ());
63
65
}
64
66
65
67
ASTScopeImpl *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) {
68
70
if (!getWasExpanded ())
69
71
expandAndBeCurrent (scopeCreator);
70
- auto child = findChildContaining (loc, sourceMgr);
72
+ auto child = findChildContaining (parentModule, loc, sourceMgr);
71
73
if (!child)
72
74
return this ;
73
- return child.get ()->findInnermostEnclosingScopeImpl (loc, os, sourceMgr ,
74
- scopeCreator);
75
+ return child.get ()->findInnermostEnclosingScopeImpl (parentModule, loc, os ,
76
+ sourceMgr, scopeCreator);
75
77
}
76
78
77
79
// / 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,
89
91
}
90
92
91
93
NullablePtr<ASTScopeImpl>
92
- ASTScopeImpl::findChildContaining (SourceLoc loc,
94
+ ASTScopeImpl::findChildContaining (ModuleDecl *parentModule,
95
+ SourceLoc loc,
93
96
SourceManager &sourceMgr) const {
94
- auto *moduleDecl = this ->getSourceFile ()->getParentModule ();
95
- auto *locSourceFile = moduleDecl->getSourceFileContainingLocation (loc);
97
+ auto *locSourceFile = parentModule->getSourceFileContainingLocation (loc);
96
98
97
99
// Use binary search to find the child that contains this location.
98
100
auto *const *child = llvm::lower_bound (
@@ -109,7 +111,7 @@ ASTScopeImpl::findChildContaining(SourceLoc loc,
109
111
// Note that `scope->getSourceFile()` returns the root of the source tree,
110
112
// not the source file containing the location of the ASTScope.
111
113
auto scopeStart = scope->getSourceRangeOfThisASTNode ().Start ;
112
- auto *scopeSourceFile = moduleDecl ->getSourceFileContainingLocation (scopeStart);
114
+ auto *scopeSourceFile = parentModule ->getSourceFileContainingLocation (scopeStart);
113
115
114
116
if (scopeSourceFile != locSourceFile) {
115
117
// To compare a source location that is possibly inside a macro expansion
@@ -624,7 +626,8 @@ llvm::SmallVector<LabeledStmt *, 4>
624
626
ASTScopeImpl::lookupLabeledStmts (SourceFile *sourceFile, SourceLoc loc) {
625
627
// Find the innermost scope from which to start our search.
626
628
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 );
628
631
ASTScopeAssert (innermost->getWasExpanded (),
629
632
" If looking in a scope, it must have been expanded." );
630
633
@@ -652,7 +655,8 @@ std::pair<CaseStmt *, CaseStmt *> ASTScopeImpl::lookupFallthroughSourceAndDest(
652
655
SourceFile *sourceFile, SourceLoc loc) {
653
656
// Find the innermost scope from which to start our search.
654
657
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 );
656
660
ASTScopeAssert (innermost->getWasExpanded (),
657
661
" If looking in a scope, it must have been expanded." );
658
662
@@ -686,7 +690,8 @@ void ASTScopeImpl::lookupEnclosingMacroScope(
686
690
return ;
687
691
688
692
auto *fileScope = sourceFile->getScope ().impl ;
689
- auto *scope = fileScope->findInnermostEnclosingScope (loc, nullptr );
693
+ auto *scope = fileScope->findInnermostEnclosingScope (
694
+ sourceFile->getParentModule (), loc, nullptr );
690
695
do {
691
696
auto *freestanding = scope->getFreestandingMacro ().getPtrOrNull ();
692
697
if (freestanding && consume (freestanding))
0 commit comments