Skip to content

Commit ee29afe

Browse files
committed
[clang][NFC] Convert LookupResultKind to scoped enum
1 parent 3579fc0 commit ee29afe

File tree

10 files changed

+167
-163
lines changed

10 files changed

+167
-163
lines changed

clang/include/clang/Sema/Lookup.h

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ namespace clang {
3636

3737
class CXXBasePaths;
3838

39+
enum class LookupResultKind {
40+
/// No entity found met the criteria.
41+
NotFound = 0,
42+
43+
/// No entity found met the criteria within the current
44+
/// instantiation,, but there were dependent base classes of the
45+
/// current instantiation that could not be searched.
46+
NotFoundInCurrentInstantiation,
47+
48+
/// Name lookup found a single declaration that met the
49+
/// criteria. getFoundDecl() will return this declaration.
50+
Found,
51+
52+
/// Name lookup found a set of overloaded functions that
53+
/// met the criteria.
54+
FoundOverloaded,
55+
56+
/// Name lookup found an unresolvable value declaration
57+
/// and cannot yet complete. This only happens in C++ dependent
58+
/// contexts with dependent using declarations.
59+
FoundUnresolvedValue,
60+
61+
/// Name lookup results in an ambiguity; use
62+
/// getAmbiguityKind to figure out what kind of ambiguity
63+
/// we have.
64+
Ambiguous
65+
};
66+
3967
enum class LookupAmbiguityKind {
4068
/// Name lookup results in an ambiguity because multiple
4169
/// entities that meet the lookup criteria were found in
@@ -118,34 +146,6 @@ enum class LookupAmbiguityKind {
118146
/// results occurred for a given lookup.
119147
class LookupResult {
120148
public:
121-
enum LookupResultKind {
122-
/// No entity found met the criteria.
123-
NotFound = 0,
124-
125-
/// No entity found met the criteria within the current
126-
/// instantiation,, but there were dependent base classes of the
127-
/// current instantiation that could not be searched.
128-
NotFoundInCurrentInstantiation,
129-
130-
/// Name lookup found a single declaration that met the
131-
/// criteria. getFoundDecl() will return this declaration.
132-
Found,
133-
134-
/// Name lookup found a set of overloaded functions that
135-
/// met the criteria.
136-
FoundOverloaded,
137-
138-
/// Name lookup found an unresolvable value declaration
139-
/// and cannot yet complete. This only happens in C++ dependent
140-
/// contexts with dependent using declarations.
141-
FoundUnresolvedValue,
142-
143-
/// Name lookup results in an ambiguity; use
144-
/// getAmbiguityKind to figure out what kind of ambiguity
145-
/// we have.
146-
Ambiguous
147-
};
148-
149149
/// A little identifier for flagging temporary lookup results.
150150
enum TemporaryToken {
151151
Temporary
@@ -322,23 +322,23 @@ class LookupResult {
322322
bool isTemplateNameLookup() const { return TemplateNameLookup; }
323323

324324
bool isAmbiguous() const {
325-
return getResultKind() == Ambiguous;
325+
return getResultKind() == LookupResultKind::Ambiguous;
326326
}
327327

328328
/// Determines if this names a single result which is not an
329329
/// unresolved value using decl. If so, it is safe to call
330330
/// getFoundDecl().
331331
bool isSingleResult() const {
332-
return getResultKind() == Found;
332+
return getResultKind() == LookupResultKind::Found;
333333
}
334334

335335
/// Determines if the results are overloaded.
336336
bool isOverloadedResult() const {
337-
return getResultKind() == FoundOverloaded;
337+
return getResultKind() == LookupResultKind::FoundOverloaded;
338338
}
339339

340340
bool isUnresolvableResult() const {
341-
return getResultKind() == FoundUnresolvedValue;
341+
return getResultKind() == LookupResultKind::FoundUnresolvedValue;
342342
}
343343

344344
LookupResultKind getResultKind() const {
@@ -480,29 +480,29 @@ class LookupResult {
480480
/// Does not test the acceptance criteria.
481481
void addDecl(NamedDecl *D, AccessSpecifier AS) {
482482
Decls.addDecl(D, AS);
483-
ResultKind = Found;
483+
ResultKind = LookupResultKind::Found;
484484
}
485485

486486
/// Add all the declarations from another set of lookup
487487
/// results.
488488
void addAllDecls(const LookupResult &Other) {
489489
Decls.append(Other.Decls.begin(), Other.Decls.end());
490-
ResultKind = Found;
490+
ResultKind = LookupResultKind::Found;
491491
}
492492

493493
/// Determine whether no result was found because we could not
494494
/// search into dependent base classes of the current instantiation.
495495
bool wasNotFoundInCurrentInstantiation() const {
496-
return ResultKind == NotFoundInCurrentInstantiation;
496+
return ResultKind == LookupResultKind::NotFoundInCurrentInstantiation;
497497
}
498498

499499
/// Note that while no result was found in the current instantiation,
500500
/// there were dependent base classes that could not be searched.
501501
void setNotFoundInCurrentInstantiation() {
502-
assert((ResultKind == NotFound ||
503-
ResultKind == NotFoundInCurrentInstantiation) &&
502+
assert((ResultKind == LookupResultKind::NotFound ||
503+
ResultKind == LookupResultKind::NotFoundInCurrentInstantiation) &&
504504
Decls.empty());
505-
ResultKind = NotFoundInCurrentInstantiation;
505+
ResultKind = LookupResultKind::NotFoundInCurrentInstantiation;
506506
}
507507

508508
/// Determine whether the lookup result was shadowed by some other
@@ -524,8 +524,8 @@ class LookupResult {
524524
/// removals has been performed.
525525
void resolveKindAfterFilter() {
526526
if (Decls.empty()) {
527-
if (ResultKind != NotFoundInCurrentInstantiation)
528-
ResultKind = NotFound;
527+
if (ResultKind != LookupResultKind::NotFoundInCurrentInstantiation)
528+
ResultKind = LookupResultKind::NotFound;
529529

530530
if (Paths) {
531531
deletePaths(Paths);
@@ -534,16 +534,16 @@ class LookupResult {
534534
} else {
535535
std::optional<LookupAmbiguityKind> SavedAK;
536536
bool WasAmbiguous = false;
537-
if (ResultKind == Ambiguous) {
537+
if (ResultKind == LookupResultKind::Ambiguous) {
538538
SavedAK = Ambiguity;
539539
WasAmbiguous = true;
540540
}
541-
ResultKind = Found;
541+
ResultKind = LookupResultKind::Found;
542542
resolveKind();
543543

544544
// If we didn't make the lookup unambiguous, restore the old
545545
// ambiguity kind.
546-
if (ResultKind == Ambiguous) {
546+
if (ResultKind == LookupResultKind::Ambiguous) {
547547
(void)WasAmbiguous;
548548
assert(WasAmbiguous);
549549
Ambiguity = *SavedAK;
@@ -556,7 +556,8 @@ class LookupResult {
556556

557557
template <class DeclClass>
558558
DeclClass *getAsSingle() const {
559-
if (getResultKind() != Found) return nullptr;
559+
if (getResultKind() != LookupResultKind::Found)
560+
return nullptr;
560561
return dyn_cast<DeclClass>(getFoundDecl());
561562
}
562563

@@ -566,8 +567,8 @@ class LookupResult {
566567
/// This is intended for users who have examined the result kind
567568
/// and are certain that there is only one result.
568569
NamedDecl *getFoundDecl() const {
569-
assert(getResultKind() == Found
570-
&& "getFoundDecl called on non-unique result");
570+
assert(getResultKind() == LookupResultKind::Found &&
571+
"getFoundDecl called on non-unique result");
571572
return (*begin())->getUnderlyingDecl();
572573
}
573574

@@ -579,7 +580,8 @@ class LookupResult {
579580

580581
/// Asks if the result is a single tag decl.
581582
bool isSingleTagDecl() const {
582-
return getResultKind() == Found && isa<TagDecl>(getFoundDecl());
583+
return getResultKind() == LookupResultKind::Found &&
584+
isa<TagDecl>(getFoundDecl());
583585
}
584586

585587
/// Make these results show that the name was found in
@@ -603,7 +605,7 @@ class LookupResult {
603605

604606
/// Clears out any current state.
605607
LLVM_ATTRIBUTE_REINITIALIZES void clear() {
606-
ResultKind = NotFound;
608+
ResultKind = LookupResultKind::NotFound;
607609
Decls.clear();
608610
if (Paths) deletePaths(Paths);
609611
Paths = nullptr;
@@ -770,7 +772,7 @@ class LookupResult {
770772
}
771773

772774
void setAmbiguous(LookupAmbiguityKind AK) {
773-
ResultKind = Ambiguous;
775+
ResultKind = LookupResultKind::Ambiguous;
774776
Ambiguity = AK;
775777
}
776778

@@ -789,7 +791,7 @@ class LookupResult {
789791
static void deletePaths(CXXBasePaths *);
790792

791793
// Results.
792-
LookupResultKind ResultKind = NotFound;
794+
LookupResultKind ResultKind = LookupResultKind::NotFound;
793795
// ill-defined unless ambiguous. Still need to be initialized it will be
794796
// copied/moved.
795797
LookupAmbiguityKind Ambiguity = {};

clang/lib/Sema/SemaDecl.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
418418
NamedDecl *IIDecl = nullptr;
419419
UsingShadowDecl *FoundUsingShadow = nullptr;
420420
switch (Result.getResultKind()) {
421-
case LookupResult::NotFound:
421+
case LookupResultKind::NotFound:
422422
if (CorrectedII) {
423423
TypeNameValidatorCCC CCC(/*AllowInvalid=*/true, isClassName,
424424
AllowDeducedTemplate);
@@ -460,7 +460,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
460460
}
461461
Result.suppressDiagnostics();
462462
return nullptr;
463-
case LookupResult::NotFoundInCurrentInstantiation:
463+
case LookupResultKind::NotFoundInCurrentInstantiation:
464464
if (AllowImplicitTypename == ImplicitTypenameContext::Yes) {
465465
QualType T = Context.getDependentNameType(ElaboratedTypeKeyword::None,
466466
SS->getScopeRep(), &II);
@@ -472,12 +472,12 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
472472
return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T));
473473
}
474474
[[fallthrough]];
475-
case LookupResult::FoundOverloaded:
476-
case LookupResult::FoundUnresolvedValue:
475+
case LookupResultKind::FoundOverloaded:
476+
case LookupResultKind::FoundUnresolvedValue:
477477
Result.suppressDiagnostics();
478478
return nullptr;
479479

480-
case LookupResult::Ambiguous:
480+
case LookupResultKind::Ambiguous:
481481
// Recover from type-hiding ambiguities by hiding the type. We'll
482482
// do the lookup again when looking for an object, and we can
483483
// diagnose the error then. If we don't do this, then the error
@@ -521,7 +521,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
521521
// perform the name lookup again.
522522
break;
523523

524-
case LookupResult::Found:
524+
case LookupResultKind::Found:
525525
IIDecl = Result.getFoundDecl();
526526
FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Result.begin());
527527
break;
@@ -657,7 +657,7 @@ DeclSpec::TST Sema::isTagName(IdentifierInfo &II, Scope *S) {
657657
LookupResult R(*this, &II, SourceLocation(), LookupTagName);
658658
LookupName(R, S, false);
659659
R.suppressDiagnostics();
660-
if (R.getResultKind() == LookupResult::Found)
660+
if (R.getResultKind() == LookupResultKind::Found)
661661
if (const TagDecl *TD = R.getAsSingle<TagDecl>()) {
662662
switch (TD->getTagKind()) {
663663
case TagTypeKind::Struct:
@@ -926,7 +926,7 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS,
926926

927927
Corrected:
928928
switch (Result.getResultKind()) {
929-
case LookupResult::NotFound:
929+
case LookupResultKind::NotFound:
930930
// If an unqualified-id is followed by a '(', then we have a function
931931
// call.
932932
if (SS.isEmpty() && NextToken.is(tok::l_paren)) {
@@ -1043,7 +1043,7 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS,
10431043
Result.suppressDiagnostics();
10441044
return NameClassification::Unknown();
10451045

1046-
case LookupResult::NotFoundInCurrentInstantiation: {
1046+
case LookupResultKind::NotFoundInCurrentInstantiation: {
10471047
// We performed name lookup into the current instantiation, and there were
10481048
// dependent bases, so we treat this result the same way as any other
10491049
// dependent nested-name-specifier.
@@ -1061,12 +1061,12 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS,
10611061
return NameClassification::DependentNonType();
10621062
}
10631063

1064-
case LookupResult::Found:
1065-
case LookupResult::FoundOverloaded:
1066-
case LookupResult::FoundUnresolvedValue:
1064+
case LookupResultKind::Found:
1065+
case LookupResultKind::FoundOverloaded:
1066+
case LookupResultKind::FoundUnresolvedValue:
10671067
break;
10681068

1069-
case LookupResult::Ambiguous:
1069+
case LookupResultKind::Ambiguous:
10701070
if (getLangOpts().CPlusPlus && NextToken.is(tok::less) &&
10711071
hasAnyAcceptableTemplateNames(Result, /*AllowFunctionTemplates=*/true,
10721072
/*AllowDependent=*/false)) {
@@ -1498,11 +1498,11 @@ static bool AllowOverloadingOfFunction(const LookupResult &Previous,
14981498
// to check at least two; hence the 'any_of' check below. Note that
14991499
// the overloadable attribute is implicitly added to declarations
15001500
// that were required to have it but did not.
1501-
if (Previous.getResultKind() == LookupResult::FoundOverloaded) {
1501+
if (Previous.getResultKind() == LookupResultKind::FoundOverloaded) {
15021502
return llvm::any_of(Previous, [](const NamedDecl *ND) {
15031503
return ND->hasAttr<OverloadableAttr>();
15041504
});
1505-
} else if (Previous.getResultKind() == LookupResult::Found)
1505+
} else if (Previous.getResultKind() == LookupResultKind::Found)
15061506
return Previous.getFoundDecl()->hasAttr<OverloadableAttr>();
15071507

15081508
return false;
@@ -8290,7 +8290,7 @@ static SourceLocation getCaptureLocation(const LambdaScopeInfo *LSI,
82908290
static bool shouldWarnIfShadowedDecl(const DiagnosticsEngine &Diags,
82918291
const LookupResult &R) {
82928292
// Only diagnose if we're shadowing an unambiguous field or variable.
8293-
if (R.getResultKind() != LookupResult::Found)
8293+
if (R.getResultKind() != LookupResultKind::Found)
82948294
return false;
82958295

82968296
// Return false if warning is ignored.
@@ -10504,7 +10504,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1050410504
// Recover gracefully from an invalid redeclaration.
1050510505
D.setRedeclaration(true);
1050610506
assert((NewFD->isInvalidDecl() || !D.isRedeclaration() ||
10507-
Previous.getResultKind() != LookupResult::FoundOverloaded) &&
10507+
Previous.getResultKind() != LookupResultKind::FoundOverloaded) &&
1050810508
"previous declaration set still overloaded");
1050910509

1051010510
// Diagnose no-prototype function declarations with calling conventions that
@@ -10671,7 +10671,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1067110671

1067210672
assert((NewFD->isInvalidDecl() || NewFD->isMultiVersion() ||
1067310673
!D.isRedeclaration() ||
10674-
Previous.getResultKind() != LookupResult::FoundOverloaded) &&
10674+
Previous.getResultKind() != LookupResultKind::FoundOverloaded) &&
1067510675
"previous declaration set still overloaded");
1067610676

1067710677
NamedDecl *PrincipalDecl = (FunctionTemplate
@@ -18679,19 +18679,19 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
1867918679
RedeclarationKind::ForVisibleRedeclaration);
1868018680
LookupName(Previous, S);
1868118681
switch (Previous.getResultKind()) {
18682-
case LookupResult::Found:
18683-
case LookupResult::FoundUnresolvedValue:
18684-
PrevDecl = Previous.getAsSingle<NamedDecl>();
18685-
break;
18682+
case LookupResultKind::Found:
18683+
case LookupResultKind::FoundUnresolvedValue:
18684+
PrevDecl = Previous.getAsSingle<NamedDecl>();
18685+
break;
1868618686

18687-
case LookupResult::FoundOverloaded:
18688-
PrevDecl = Previous.getRepresentativeDecl();
18689-
break;
18687+
case LookupResultKind::FoundOverloaded:
18688+
PrevDecl = Previous.getRepresentativeDecl();
18689+
break;
1869018690

18691-
case LookupResult::NotFound:
18692-
case LookupResult::NotFoundInCurrentInstantiation:
18693-
case LookupResult::Ambiguous:
18694-
break;
18691+
case LookupResultKind::NotFound:
18692+
case LookupResultKind::NotFoundInCurrentInstantiation:
18693+
case LookupResultKind::Ambiguous:
18694+
break;
1869518695
}
1869618696
Previous.suppressDiagnostics();
1869718697

0 commit comments

Comments
 (0)