Skip to content

Commit 85d6012

Browse files
author
David Ungar
committed
Renamed “DCAnd” to “ContextAnd”
1 parent 8f67ef6 commit 85d6012

File tree

1 file changed

+55
-54
lines changed

1 file changed

+55
-54
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ class UnqualifiedLookupFactory {
128128
using Options = UnqualifiedLookup::Options;
129129

130130
private:
131-
132-
// TODO: better name than DC
133-
struct DCAndResolvedIsCascadingUse {
131+
struct ContextAndResolvedIsCascadingUse {
134132
DeclContext *const DC;
135133
const bool isCascadingUse;
136134
};
@@ -146,7 +144,6 @@ class UnqualifiedLookupFactory {
146144
DeclContext *const dynamicContext;
147145
/// Types are formally members of the metatype, i.e. the static type of the
148146
/// activation record.
149-
// DOUG: can you help clarify the above comments?
150147
DeclContext *const staticContext;
151148
using NominalTypesThatSelfMustConformTo = SmallVector<NominalTypeDecl *, 2>;
152149
NominalTypesThatSelfMustConformTo nominalTypesThatSelfMustConformTo;
@@ -215,12 +212,12 @@ class UnqualifiedLookupFactory {
215212
void performUnqualifiedLookup();
216213

217214
private:
218-
struct DCAndUnresolvedIsCascadingUse {
215+
struct ContextAndUnresolvedIsCascadingUse {
219216
DeclContext *whereToLook;
220217
Optional<bool> isCascadingUse;
221-
DCAndResolvedIsCascadingUse resolve(const bool resolution) const {
222-
return DCAndResolvedIsCascadingUse{whereToLook,
223-
isCascadingUse.getValueOr(resolution)};
218+
ContextAndResolvedIsCascadingUse resolve(const bool resolution) const {
219+
return ContextAndResolvedIsCascadingUse{
220+
whereToLook, isCascadingUse.getValueOr(resolution)};
224221
}
225222
};
226223

@@ -230,13 +227,13 @@ class UnqualifiedLookupFactory {
230227

231228
#pragma mark ASTScope-based-lookup declarations
232229

233-
void experimentallyLookInASTScopes(DCAndUnresolvedIsCascadingUse);
230+
void experimentallyLookInASTScopes(ContextAndUnresolvedIsCascadingUse);
234231

235232
std::pair<const ASTScope *, bool>
236-
operatorScopeForASTScopeLookup(DCAndUnresolvedIsCascadingUse);
233+
operatorScopeForASTScopeLookup(ContextAndUnresolvedIsCascadingUse);
237234

238-
std::pair<const ASTScope *, Optional<bool>>
239-
nonoperatorScopeForASTScopeLookup(DCAndUnresolvedIsCascadingUse) const;
235+
std::pair<const ASTScope *, Optional<bool>> nonoperatorScopeForASTScopeLookup(
236+
ContextAndUnresolvedIsCascadingUse) const;
240237

241238
struct ASTScopeLookupState {
242239
const ASTScope *scope;
@@ -285,10 +282,10 @@ class UnqualifiedLookupFactory {
285282
}
286283

287284
#pragma mark normal (non-ASTScope-based) lookup declarations
288-
289-
void lookupOperatorInDeclContexts(DCAndUnresolvedIsCascadingUse);
290285

291-
void lookupNamesIntroducedBy(const DCAndUnresolvedIsCascadingUse);
286+
void lookupOperatorInDeclContexts(ContextAndUnresolvedIsCascadingUse);
287+
288+
void lookupNamesIntroducedBy(const ContextAndUnresolvedIsCascadingUse);
292289

293290
void finishLookingInContext(AddGenericParameters addGenericParameters,
294291
DeclContext *lookupContextForThisContext,
@@ -376,7 +373,7 @@ class UnqualifiedLookupFactory {
376373
static bool resolveIsCascadingUse(const DeclContext *const dc,
377374
Optional<bool> isCascadingUse,
378375
bool onlyCareAboutFunctionBody);
379-
static bool resolveIsCascadingUse(DCAndUnresolvedIsCascadingUse x,
376+
static bool resolveIsCascadingUse(ContextAndUnresolvedIsCascadingUse x,
380377
bool onlyCareAboutFunctionBody) {
381378
return resolveIsCascadingUse(x.whereToLook, x.isCascadingUse,
382379
onlyCareAboutFunctionBody);
@@ -405,34 +402,35 @@ UnqualifiedLookupFactory::UnqualifiedLookupFactory(
405402
Options options,
406403
UnqualifiedLookup &lookupToBeCreated)
407404
:
408-
Name(Name),
409-
DC(DC),
410-
M(*DC->getParentModule()),
411-
Ctx(M.getASTContext()),
412-
TypeResolver(TypeResolver ? TypeResolver : Ctx.getLazyResolver()),
413-
Loc(Loc),
414-
SM(Ctx.SourceMgr),
415-
DebugClient(M.getDebugClient()),
416-
options(options),
417-
isOriginallyTypeLookup(options.contains(Flags::TypeLookup)),
418-
baseNLOptions(computeBaseNLOptions(options, isOriginallyTypeLookup)),
419-
Consumer(Name, lookupToBeCreated.Results, isOriginallyTypeLookup),
420-
Results(lookupToBeCreated.Results),
421-
IndexOfFirstOuterResult(lookupToBeCreated.IndexOfFirstOuterResult)
405+
Name(Name),
406+
DC(DC),
407+
M(*DC->getParentModule()),
408+
Ctx(M.getASTContext()),
409+
TypeResolver(TypeResolver ? TypeResolver : Ctx.getLazyResolver()),
410+
Loc(Loc),
411+
SM(Ctx.SourceMgr),
412+
DebugClient(M.getDebugClient()),
413+
options(options),
414+
isOriginallyTypeLookup(options.contains(Flags::TypeLookup)),
415+
baseNLOptions(computeBaseNLOptions(options, isOriginallyTypeLookup)),
416+
Consumer(Name, lookupToBeCreated.Results, isOriginallyTypeLookup),
417+
Results(lookupToBeCreated.Results),
418+
IndexOfFirstOuterResult(lookupToBeCreated.IndexOfFirstOuterResult)
422419
{}
423420
// clang-format on
424421

425422
void UnqualifiedLookupFactory::performUnqualifiedLookup() {
426423
const Optional<bool> isCascadingUseInitial =
427424
options.contains(Flags::KnownPrivate) ? Optional<bool>(false) : None;
428425

429-
DCAndUnresolvedIsCascadingUse dcAndIsCascadingUse{DC, isCascadingUseInitial};
426+
ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUse{
427+
DC, isCascadingUseInitial};
430428
if (useASTScopesForExperimentalLookup())
431-
experimentallyLookInASTScopes(dcAndIsCascadingUse);
429+
experimentallyLookInASTScopes(contextAndIsCascadingUse);
432430
else if (Name.isOperator())
433-
lookupOperatorInDeclContexts(dcAndIsCascadingUse);
431+
lookupOperatorInDeclContexts(contextAndIsCascadingUse);
434432
else
435-
lookupNamesIntroducedBy(dcAndIsCascadingUse);
433+
lookupNamesIntroducedBy(contextAndIsCascadingUse);
436434
}
437435

438436
void UnqualifiedLookupFactory::lookUpTopLevelNamesInModuleScopeContext(
@@ -465,26 +463,26 @@ bool UnqualifiedLookupFactory::useASTScopesForExperimentalLookup() const {
465463
#pragma mark ASTScope-based-lookup definitions
466464

467465
void UnqualifiedLookupFactory::experimentallyLookInASTScopes(
468-
const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg) {
466+
const ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUseArg) {
469467
const std::pair<const ASTScope *, Optional<bool>>
470468
lookupScopeAndIsCascadingUse =
471469
Name.isOperator()
472-
? operatorScopeForASTScopeLookup(dcAndIsCascadingUseArg)
473-
: nonoperatorScopeForASTScopeLookup(dcAndIsCascadingUseArg);
470+
? operatorScopeForASTScopeLookup(contextAndIsCascadingUseArg)
471+
: nonoperatorScopeForASTScopeLookup(contextAndIsCascadingUseArg);
474472
// Walk scopes outward from the innermost scope until we find something.
475473

476474
ASTScopeLookupState state{lookupScopeAndIsCascadingUse.first, nullptr,
477-
dcAndIsCascadingUseArg.whereToLook,
475+
contextAndIsCascadingUseArg.whereToLook,
478476
lookupScopeAndIsCascadingUse.second};
479477
lookInScopeForASTScopeLookup(state);
480478
}
481479

482480
std::pair<const ASTScope *, bool>
483481
UnqualifiedLookupFactory::operatorScopeForASTScopeLookup(
484-
const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg) {
482+
const ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUseArg) {
485483
// Find the source file in which we are performing the lookup.
486484
SourceFile &sourceFile =
487-
*dcAndIsCascadingUseArg.whereToLook->getParentSourceFile();
485+
*contextAndIsCascadingUseArg.whereToLook->getParentSourceFile();
488486

489487
// Find the scope from which we will initiate unqualified name lookup.
490488
const ASTScope *lookupScope =
@@ -494,22 +492,24 @@ UnqualifiedLookupFactory::operatorScopeForASTScopeLookup(
494492
return std::make_pair(
495493
&sourceFile.getScope(),
496494
resolveIsCascadingUse(lookupScope->getInnermostEnclosingDeclContext(),
497-
dcAndIsCascadingUseArg.isCascadingUse,
495+
contextAndIsCascadingUseArg.isCascadingUse,
498496
/*onlyCareAboutFunctionBody*/ true));
499497
}
500498

501499
std::pair<const ASTScope *, Optional<bool>>
502500
UnqualifiedLookupFactory::nonoperatorScopeForASTScopeLookup(
503-
const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg) const {
501+
const ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUseArg)
502+
const {
504503
// Find the source file in which we are performing the lookup.
505504
SourceFile &sourceFile =
506-
*dcAndIsCascadingUseArg.whereToLook->getParentSourceFile();
505+
*contextAndIsCascadingUseArg.whereToLook->getParentSourceFile();
507506

508507
// Find the scope from which we will initiate unqualified name lookup.
509508
const ASTScope *lookupScope =
510509
sourceFile.getScope().findInnermostEnclosingScope(Loc);
511510

512-
return std::make_pair(lookupScope, dcAndIsCascadingUseArg.isCascadingUse);
511+
return std::make_pair(lookupScope,
512+
contextAndIsCascadingUseArg.isCascadingUse);
513513
}
514514

515515
void UnqualifiedLookupFactory::lookInScopeForASTScopeLookup(
@@ -627,21 +627,22 @@ void UnqualifiedLookupFactory::lookIntoDeclarationContextForASTScopeLookup(
627627
#pragma mark context-based lookup definitions
628628

629629
void UnqualifiedLookupFactory::lookupOperatorInDeclContexts(
630-
const DCAndUnresolvedIsCascadingUse dcAndUseArg) {
631-
DCAndResolvedIsCascadingUse dcAndResolvedIsCascadingUse{
630+
const ContextAndUnresolvedIsCascadingUse contextAndUseArg) {
631+
ContextAndResolvedIsCascadingUse contextAndResolvedIsCascadingUse{
632632
// Operators are global
633-
dcAndUseArg.whereToLook->getModuleScopeContext(),
634-
resolveIsCascadingUse(dcAndUseArg, /*onlyCareAboutFunctionBody*/ true)};
635-
lookupInModuleScopeContext(dcAndResolvedIsCascadingUse.DC,
636-
dcAndResolvedIsCascadingUse.isCascadingUse);
633+
contextAndUseArg.whereToLook->getModuleScopeContext(),
634+
resolveIsCascadingUse(contextAndUseArg,
635+
/*onlyCareAboutFunctionBody*/ true)};
636+
lookupInModuleScopeContext(contextAndResolvedIsCascadingUse.DC,
637+
contextAndResolvedIsCascadingUse.isCascadingUse);
637638
}
638639

639640
// TODO: Unify with LookupVisibleDecls.cpp::lookupVisibleDeclsImpl
640641
void UnqualifiedLookupFactory::lookupNamesIntroducedBy(
641-
const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg) {
642+
const ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUseArg) {
642643

643-
DeclContext *const dc = dcAndIsCascadingUseArg.whereToLook;
644-
const auto isCascadingUseSoFar = dcAndIsCascadingUseArg.isCascadingUse;
644+
DeclContext *const dc = contextAndIsCascadingUseArg.whereToLook;
645+
const auto isCascadingUseSoFar = contextAndIsCascadingUseArg.isCascadingUse;
645646
if (dc->isModuleScopeContext())
646647
lookupInModuleScopeContext(dc, isCascadingUseSoFar);
647648
else if (auto *PBI = dyn_cast<PatternBindingInitializer>(dc))
@@ -683,7 +684,7 @@ void UnqualifiedLookupFactory::finishLookingInContext(
683684
},
684685
// Recurse into the next context.
685686
[&] {
686-
lookupNamesIntroducedBy(DCAndUnresolvedIsCascadingUse{
687+
lookupNamesIntroducedBy(ContextAndUnresolvedIsCascadingUse{
687688
lookupContextForThisContext->getParentForLookup(), isCascadingUse});
688689
});
689690
}

0 commit comments

Comments
 (0)