Skip to content

Commit e70a8a6

Browse files
committed
[clang][NFC] Convert Sema::NameClassificationKind to scoped enum
1 parent 4acfd83 commit e70a8a6

File tree

4 files changed

+106
-98
lines changed

4 files changed

+106
-98
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,47 @@ enum class BuiltinCountedByRefKind {
528528
BinaryExpr,
529529
};
530530

531+
/// Describes the result of the name lookup and resolution performed
532+
/// by \c Sema::ClassifyName().
533+
enum class NameClassificationKind {
534+
/// This name is not a type or template in this context, but might be
535+
/// something else.
536+
Unknown,
537+
/// Classification failed; an error has been produced.
538+
Error,
539+
/// The name has been typo-corrected to a keyword.
540+
Keyword,
541+
/// The name was classified as a type.
542+
Type,
543+
/// The name was classified as a specific non-type, non-template
544+
/// declaration. ActOnNameClassifiedAsNonType should be called to
545+
/// convert the declaration to an expression.
546+
NonType,
547+
/// The name was classified as an ADL-only function name.
548+
/// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the
549+
/// result to an expression.
550+
UndeclaredNonType,
551+
/// The name denotes a member of a dependent type that could not be
552+
/// resolved. ActOnNameClassifiedAsDependentNonType should be called to
553+
/// convert the result to an expression.
554+
DependentNonType,
555+
/// The name was classified as an overload set, and an expression
556+
/// representing that overload set has been formed.
557+
/// ActOnNameClassifiedAsOverloadSet should be called to form a suitable
558+
/// expression referencing the overload set.
559+
OverloadSet,
560+
/// The name was classified as a template whose specializations are types.
561+
TypeTemplate,
562+
/// The name was classified as a variable template name.
563+
VarTemplate,
564+
/// The name was classified as a function template name.
565+
FunctionTemplate,
566+
/// The name was classified as an ADL-only function template name.
567+
UndeclaredTemplate,
568+
/// The name was classified as a concept name.
569+
Concept,
570+
};
571+
531572
/// Sema - This implements semantic analysis and AST building for C.
532573
/// \nosubgrouping
533574
class Sema final : public SemaBase {
@@ -3290,47 +3331,6 @@ class Sema final : public SemaBase {
32903331
SourceLocation NameLoc,
32913332
bool IsTemplateTypeArg);
32923333

3293-
/// Describes the result of the name lookup and resolution performed
3294-
/// by \c ClassifyName().
3295-
enum NameClassificationKind {
3296-
/// This name is not a type or template in this context, but might be
3297-
/// something else.
3298-
NC_Unknown,
3299-
/// Classification failed; an error has been produced.
3300-
NC_Error,
3301-
/// The name has been typo-corrected to a keyword.
3302-
NC_Keyword,
3303-
/// The name was classified as a type.
3304-
NC_Type,
3305-
/// The name was classified as a specific non-type, non-template
3306-
/// declaration. ActOnNameClassifiedAsNonType should be called to
3307-
/// convert the declaration to an expression.
3308-
NC_NonType,
3309-
/// The name was classified as an ADL-only function name.
3310-
/// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the
3311-
/// result to an expression.
3312-
NC_UndeclaredNonType,
3313-
/// The name denotes a member of a dependent type that could not be
3314-
/// resolved. ActOnNameClassifiedAsDependentNonType should be called to
3315-
/// convert the result to an expression.
3316-
NC_DependentNonType,
3317-
/// The name was classified as an overload set, and an expression
3318-
/// representing that overload set has been formed.
3319-
/// ActOnNameClassifiedAsOverloadSet should be called to form a suitable
3320-
/// expression referencing the overload set.
3321-
NC_OverloadSet,
3322-
/// The name was classified as a template whose specializations are types.
3323-
NC_TypeTemplate,
3324-
/// The name was classified as a variable template name.
3325-
NC_VarTemplate,
3326-
/// The name was classified as a function template name.
3327-
NC_FunctionTemplate,
3328-
/// The name was classified as an ADL-only function template name.
3329-
NC_UndeclaredTemplate,
3330-
/// The name was classified as a concept name.
3331-
NC_Concept,
3332-
};
3333-
33343334
class NameClassification {
33353335
NameClassificationKind Kind;
33363336
union {
@@ -3343,101 +3343,107 @@ class Sema final : public SemaBase {
33433343
explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
33443344

33453345
public:
3346-
NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
3346+
NameClassification(ParsedType Type)
3347+
: Kind(NameClassificationKind::Type), Type(Type) {}
33473348

3348-
NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {}
3349+
NameClassification(const IdentifierInfo *Keyword)
3350+
: Kind(NameClassificationKind::Keyword) {}
33493351

3350-
static NameClassification Error() { return NameClassification(NC_Error); }
3352+
static NameClassification Error() {
3353+
return NameClassification(NameClassificationKind::Error);
3354+
}
33513355

33523356
static NameClassification Unknown() {
3353-
return NameClassification(NC_Unknown);
3357+
return NameClassification(NameClassificationKind::Unknown);
33543358
}
33553359

33563360
static NameClassification OverloadSet(ExprResult E) {
3357-
NameClassification Result(NC_OverloadSet);
3361+
NameClassification Result(NameClassificationKind::OverloadSet);
33583362
Result.Expr = E;
33593363
return Result;
33603364
}
33613365

33623366
static NameClassification NonType(NamedDecl *D) {
3363-
NameClassification Result(NC_NonType);
3367+
NameClassification Result(NameClassificationKind::NonType);
33643368
Result.NonTypeDecl = D;
33653369
return Result;
33663370
}
33673371

33683372
static NameClassification UndeclaredNonType() {
3369-
return NameClassification(NC_UndeclaredNonType);
3373+
return NameClassification(NameClassificationKind::UndeclaredNonType);
33703374
}
33713375

33723376
static NameClassification DependentNonType() {
3373-
return NameClassification(NC_DependentNonType);
3377+
return NameClassification(NameClassificationKind::DependentNonType);
33743378
}
33753379

33763380
static NameClassification TypeTemplate(TemplateName Name) {
3377-
NameClassification Result(NC_TypeTemplate);
3381+
NameClassification Result(NameClassificationKind::TypeTemplate);
33783382
Result.Template = Name;
33793383
return Result;
33803384
}
33813385

33823386
static NameClassification VarTemplate(TemplateName Name) {
3383-
NameClassification Result(NC_VarTemplate);
3387+
NameClassification Result(NameClassificationKind::VarTemplate);
33843388
Result.Template = Name;
33853389
return Result;
33863390
}
33873391

33883392
static NameClassification FunctionTemplate(TemplateName Name) {
3389-
NameClassification Result(NC_FunctionTemplate);
3393+
NameClassification Result(NameClassificationKind::FunctionTemplate);
33903394
Result.Template = Name;
33913395
return Result;
33923396
}
33933397

33943398
static NameClassification Concept(TemplateName Name) {
3395-
NameClassification Result(NC_Concept);
3399+
NameClassification Result(NameClassificationKind::Concept);
33963400
Result.Template = Name;
33973401
return Result;
33983402
}
33993403

34003404
static NameClassification UndeclaredTemplate(TemplateName Name) {
3401-
NameClassification Result(NC_UndeclaredTemplate);
3405+
NameClassification Result(NameClassificationKind::UndeclaredTemplate);
34023406
Result.Template = Name;
34033407
return Result;
34043408
}
34053409

34063410
NameClassificationKind getKind() const { return Kind; }
34073411

34083412
ExprResult getExpression() const {
3409-
assert(Kind == NC_OverloadSet);
3413+
assert(Kind == NameClassificationKind::OverloadSet);
34103414
return Expr;
34113415
}
34123416

34133417
ParsedType getType() const {
3414-
assert(Kind == NC_Type);
3418+
assert(Kind == NameClassificationKind::Type);
34153419
return Type;
34163420
}
34173421

34183422
NamedDecl *getNonTypeDecl() const {
3419-
assert(Kind == NC_NonType);
3423+
assert(Kind == NameClassificationKind::NonType);
34203424
return NonTypeDecl;
34213425
}
34223426

34233427
TemplateName getTemplateName() const {
3424-
assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||
3425-
Kind == NC_VarTemplate || Kind == NC_Concept ||
3426-
Kind == NC_UndeclaredTemplate);
3428+
assert(Kind == NameClassificationKind::TypeTemplate ||
3429+
Kind == NameClassificationKind::FunctionTemplate ||
3430+
Kind == NameClassificationKind::VarTemplate ||
3431+
Kind == NameClassificationKind::Concept ||
3432+
Kind == NameClassificationKind::UndeclaredTemplate);
34273433
return Template;
34283434
}
34293435

34303436
TemplateNameKind getTemplateNameKind() const {
34313437
switch (Kind) {
3432-
case NC_TypeTemplate:
3438+
case NameClassificationKind::TypeTemplate:
34333439
return TNK_Type_template;
3434-
case NC_FunctionTemplate:
3440+
case NameClassificationKind::FunctionTemplate:
34353441
return TNK_Function_template;
3436-
case NC_VarTemplate:
3442+
case NameClassificationKind::VarTemplate:
34373443
return TNK_Var_template;
3438-
case NC_Concept:
3444+
case NameClassificationKind::Concept:
34393445
return TNK_Concept_template;
3440-
case NC_UndeclaredTemplate:
3446+
case NameClassificationKind::UndeclaredTemplate:
34413447
return TNK_Undeclared_template;
34423448
default:
34433449
llvm_unreachable("unsupported name classification.");

clang/lib/Parse/ParseDecl.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,28 +3570,28 @@ Parser::DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS, AccessSpecifier AS,
35703570
getCurScope(), SS, Name, AfterScope.getLocation(), Next,
35713571
/*CCC=*/nullptr);
35723572
switch (Classification.getKind()) {
3573-
case Sema::NC_Error:
3573+
case NameClassificationKind::Error:
35743574
SkipMalformedDecl();
35753575
return true;
35763576

3577-
case Sema::NC_Keyword:
3577+
case NameClassificationKind::Keyword:
35783578
llvm_unreachable("typo correction is not possible here");
35793579

3580-
case Sema::NC_Type:
3581-
case Sema::NC_TypeTemplate:
3582-
case Sema::NC_UndeclaredNonType:
3583-
case Sema::NC_UndeclaredTemplate:
3580+
case NameClassificationKind::Type:
3581+
case NameClassificationKind::TypeTemplate:
3582+
case NameClassificationKind::UndeclaredNonType:
3583+
case NameClassificationKind::UndeclaredTemplate:
35843584
// Not a previously-declared non-type entity.
35853585
MightBeDeclarator = false;
35863586
break;
35873587

3588-
case Sema::NC_Unknown:
3589-
case Sema::NC_NonType:
3590-
case Sema::NC_DependentNonType:
3591-
case Sema::NC_OverloadSet:
3592-
case Sema::NC_VarTemplate:
3593-
case Sema::NC_FunctionTemplate:
3594-
case Sema::NC_Concept:
3588+
case NameClassificationKind::Unknown:
3589+
case NameClassificationKind::NonType:
3590+
case NameClassificationKind::DependentNonType:
3591+
case NameClassificationKind::OverloadSet:
3592+
case NameClassificationKind::VarTemplate:
3593+
case NameClassificationKind::FunctionTemplate:
3594+
case NameClassificationKind::Concept:
35953595
// Might be a redeclaration of a prior entity.
35963596
break;
35973597
}

clang/lib/Parse/ParseTentative.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,10 +2275,10 @@ bool Parser::NameAfterArrowIsNonType() {
22752275
Sema::NameClassification Classification =
22762276
Actions.ClassifyName(getCurScope(), SS, Name, NameLoc, Next, &CCC);
22772277
switch (Classification.getKind()) {
2278-
case Sema::NC_OverloadSet:
2279-
case Sema::NC_NonType:
2280-
case Sema::NC_VarTemplate:
2281-
case Sema::NC_FunctionTemplate:
2278+
case NameClassificationKind::OverloadSet:
2279+
case NameClassificationKind::NonType:
2280+
case NameClassificationKind::VarTemplate:
2281+
case NameClassificationKind::FunctionTemplate:
22822282
return true;
22832283
default:
22842284
break;

clang/lib/Parse/Parser.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
18621862
// double-check before committing to that interpretation. C++20 requires that
18631863
// we interpret this as a template-id if it can be, but if it can't be, then
18641864
// this is an error recovery case.
1865-
if (Classification.getKind() == Sema::NC_UndeclaredTemplate &&
1865+
if (Classification.getKind() == NameClassificationKind::UndeclaredTemplate &&
18661866
isTemplateArgumentList(1) == TPResult::False) {
18671867
// It's not a template-id; re-classify without the '<' as a hint.
18681868
Token FakeNext = Next;
@@ -1873,10 +1873,10 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
18731873
}
18741874

18751875
switch (Classification.getKind()) {
1876-
case Sema::NC_Error:
1876+
case NameClassificationKind::Error:
18771877
return AnnotatedNameKind::Error;
18781878

1879-
case Sema::NC_Keyword:
1879+
case NameClassificationKind::Keyword:
18801880
// The identifier was typo-corrected to a keyword.
18811881
Tok.setIdentifierInfo(Name);
18821882
Tok.setKind(Name->getTokenID());
@@ -1886,11 +1886,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
18861886
// We've "annotated" this as a keyword.
18871887
return AnnotatedNameKind::Success;
18881888

1889-
case Sema::NC_Unknown:
1889+
case NameClassificationKind::Unknown:
18901890
// It's not something we know about. Leave it unannotated.
18911891
break;
18921892

1893-
case Sema::NC_Type: {
1893+
case NameClassificationKind::Type: {
18941894
if (TryAltiVecVectorToken())
18951895
// vector has been found as a type id when altivec is enabled but
18961896
// this is followed by a declaration specifier so this is really the
@@ -1927,7 +1927,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
19271927
return AnnotatedNameKind::Success;
19281928
}
19291929

1930-
case Sema::NC_OverloadSet:
1930+
case NameClassificationKind::OverloadSet:
19311931
Tok.setKind(tok::annot_overload_set);
19321932
setExprAnnotation(Tok, Classification.getExpression());
19331933
Tok.setAnnotationEndLoc(NameLoc);
@@ -1936,7 +1936,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
19361936
PP.AnnotateCachedTokens(Tok);
19371937
return AnnotatedNameKind::Success;
19381938

1939-
case Sema::NC_NonType:
1939+
case NameClassificationKind::NonType:
19401940
if (TryAltiVecVectorToken())
19411941
// vector has been found as a non-type id when altivec is enabled but
19421942
// this is followed by a declaration specifier so this is really the
@@ -1951,9 +1951,10 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
19511951
AnnotateScopeToken(SS, !WasScopeAnnotation);
19521952
return AnnotatedNameKind::Success;
19531953

1954-
case Sema::NC_UndeclaredNonType:
1955-
case Sema::NC_DependentNonType:
1956-
Tok.setKind(Classification.getKind() == Sema::NC_UndeclaredNonType
1954+
case NameClassificationKind::UndeclaredNonType:
1955+
case NameClassificationKind::DependentNonType:
1956+
Tok.setKind(Classification.getKind() ==
1957+
NameClassificationKind::UndeclaredNonType
19571958
? tok::annot_non_type_undeclared
19581959
: tok::annot_non_type_dependent);
19591960
setIdentifierAnnotation(Tok, Name);
@@ -1964,19 +1965,20 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
19641965
AnnotateScopeToken(SS, !WasScopeAnnotation);
19651966
return AnnotatedNameKind::Success;
19661967

1967-
case Sema::NC_TypeTemplate:
1968+
case NameClassificationKind::TypeTemplate:
19681969
if (Next.isNot(tok::less)) {
19691970
// This may be a type template being used as a template template argument.
19701971
if (SS.isNotEmpty())
19711972
AnnotateScopeToken(SS, !WasScopeAnnotation);
19721973
return AnnotatedNameKind::TemplateName;
19731974
}
19741975
[[fallthrough]];
1975-
case Sema::NC_Concept:
1976-
case Sema::NC_VarTemplate:
1977-
case Sema::NC_FunctionTemplate:
1978-
case Sema::NC_UndeclaredTemplate: {
1979-
bool IsConceptName = Classification.getKind() == Sema::NC_Concept;
1976+
case NameClassificationKind::Concept:
1977+
case NameClassificationKind::VarTemplate:
1978+
case NameClassificationKind::FunctionTemplate:
1979+
case NameClassificationKind::UndeclaredTemplate: {
1980+
bool IsConceptName =
1981+
Classification.getKind() == NameClassificationKind::Concept;
19801982
// We have a template name followed by '<'. Consume the identifier token so
19811983
// we reach the '<' and annotate it.
19821984
if (Next.is(tok::less))

0 commit comments

Comments
 (0)