[clang] e70a8a6 - [clang][NFC] Convert `Sema::NameClassificationKind` to scoped enum
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 30 22:13:36 PDT 2025
Author: Vlad Serebrennikov
Date: 2025-05-01T08:13:30+03:00
New Revision: e70a8a6e0e9c3700bcfe7e9cce3c5edee6a51022
URL: https://github.com/llvm/llvm-project/commit/e70a8a6e0e9c3700bcfe7e9cce3c5edee6a51022
DIFF: https://github.com/llvm/llvm-project/commit/e70a8a6e0e9c3700bcfe7e9cce3c5edee6a51022.diff
LOG: [clang][NFC] Convert `Sema::NameClassificationKind` to scoped enum
Added:
Modified:
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseTentative.cpp
clang/lib/Parse/Parser.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 11ec4d42eca8c..28313f45b1228 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -528,6 +528,47 @@ enum class BuiltinCountedByRefKind {
BinaryExpr,
};
+/// Describes the result of the name lookup and resolution performed
+/// by \c Sema::ClassifyName().
+enum class NameClassificationKind {
+ /// This name is not a type or template in this context, but might be
+ /// something else.
+ Unknown,
+ /// Classification failed; an error has been produced.
+ Error,
+ /// The name has been typo-corrected to a keyword.
+ Keyword,
+ /// The name was classified as a type.
+ Type,
+ /// The name was classified as a specific non-type, non-template
+ /// declaration. ActOnNameClassifiedAsNonType should be called to
+ /// convert the declaration to an expression.
+ NonType,
+ /// The name was classified as an ADL-only function name.
+ /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the
+ /// result to an expression.
+ UndeclaredNonType,
+ /// The name denotes a member of a dependent type that could not be
+ /// resolved. ActOnNameClassifiedAsDependentNonType should be called to
+ /// convert the result to an expression.
+ DependentNonType,
+ /// The name was classified as an overload set, and an expression
+ /// representing that overload set has been formed.
+ /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable
+ /// expression referencing the overload set.
+ OverloadSet,
+ /// The name was classified as a template whose specializations are types.
+ TypeTemplate,
+ /// The name was classified as a variable template name.
+ VarTemplate,
+ /// The name was classified as a function template name.
+ FunctionTemplate,
+ /// The name was classified as an ADL-only function template name.
+ UndeclaredTemplate,
+ /// The name was classified as a concept name.
+ Concept,
+};
+
/// Sema - This implements semantic analysis and AST building for C.
/// \nosubgrouping
class Sema final : public SemaBase {
@@ -3290,47 +3331,6 @@ class Sema final : public SemaBase {
SourceLocation NameLoc,
bool IsTemplateTypeArg);
- /// Describes the result of the name lookup and resolution performed
- /// by \c ClassifyName().
- enum NameClassificationKind {
- /// This name is not a type or template in this context, but might be
- /// something else.
- NC_Unknown,
- /// Classification failed; an error has been produced.
- NC_Error,
- /// The name has been typo-corrected to a keyword.
- NC_Keyword,
- /// The name was classified as a type.
- NC_Type,
- /// The name was classified as a specific non-type, non-template
- /// declaration. ActOnNameClassifiedAsNonType should be called to
- /// convert the declaration to an expression.
- NC_NonType,
- /// The name was classified as an ADL-only function name.
- /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the
- /// result to an expression.
- NC_UndeclaredNonType,
- /// The name denotes a member of a dependent type that could not be
- /// resolved. ActOnNameClassifiedAsDependentNonType should be called to
- /// convert the result to an expression.
- NC_DependentNonType,
- /// The name was classified as an overload set, and an expression
- /// representing that overload set has been formed.
- /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable
- /// expression referencing the overload set.
- NC_OverloadSet,
- /// The name was classified as a template whose specializations are types.
- NC_TypeTemplate,
- /// The name was classified as a variable template name.
- NC_VarTemplate,
- /// The name was classified as a function template name.
- NC_FunctionTemplate,
- /// The name was classified as an ADL-only function template name.
- NC_UndeclaredTemplate,
- /// The name was classified as a concept name.
- NC_Concept,
- };
-
class NameClassification {
NameClassificationKind Kind;
union {
@@ -3343,62 +3343,66 @@ class Sema final : public SemaBase {
explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
public:
- NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
+ NameClassification(ParsedType Type)
+ : Kind(NameClassificationKind::Type), Type(Type) {}
- NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {}
+ NameClassification(const IdentifierInfo *Keyword)
+ : Kind(NameClassificationKind::Keyword) {}
- static NameClassification Error() { return NameClassification(NC_Error); }
+ static NameClassification Error() {
+ return NameClassification(NameClassificationKind::Error);
+ }
static NameClassification Unknown() {
- return NameClassification(NC_Unknown);
+ return NameClassification(NameClassificationKind::Unknown);
}
static NameClassification OverloadSet(ExprResult E) {
- NameClassification Result(NC_OverloadSet);
+ NameClassification Result(NameClassificationKind::OverloadSet);
Result.Expr = E;
return Result;
}
static NameClassification NonType(NamedDecl *D) {
- NameClassification Result(NC_NonType);
+ NameClassification Result(NameClassificationKind::NonType);
Result.NonTypeDecl = D;
return Result;
}
static NameClassification UndeclaredNonType() {
- return NameClassification(NC_UndeclaredNonType);
+ return NameClassification(NameClassificationKind::UndeclaredNonType);
}
static NameClassification DependentNonType() {
- return NameClassification(NC_DependentNonType);
+ return NameClassification(NameClassificationKind::DependentNonType);
}
static NameClassification TypeTemplate(TemplateName Name) {
- NameClassification Result(NC_TypeTemplate);
+ NameClassification Result(NameClassificationKind::TypeTemplate);
Result.Template = Name;
return Result;
}
static NameClassification VarTemplate(TemplateName Name) {
- NameClassification Result(NC_VarTemplate);
+ NameClassification Result(NameClassificationKind::VarTemplate);
Result.Template = Name;
return Result;
}
static NameClassification FunctionTemplate(TemplateName Name) {
- NameClassification Result(NC_FunctionTemplate);
+ NameClassification Result(NameClassificationKind::FunctionTemplate);
Result.Template = Name;
return Result;
}
static NameClassification Concept(TemplateName Name) {
- NameClassification Result(NC_Concept);
+ NameClassification Result(NameClassificationKind::Concept);
Result.Template = Name;
return Result;
}
static NameClassification UndeclaredTemplate(TemplateName Name) {
- NameClassification Result(NC_UndeclaredTemplate);
+ NameClassification Result(NameClassificationKind::UndeclaredTemplate);
Result.Template = Name;
return Result;
}
@@ -3406,38 +3410,40 @@ class Sema final : public SemaBase {
NameClassificationKind getKind() const { return Kind; }
ExprResult getExpression() const {
- assert(Kind == NC_OverloadSet);
+ assert(Kind == NameClassificationKind::OverloadSet);
return Expr;
}
ParsedType getType() const {
- assert(Kind == NC_Type);
+ assert(Kind == NameClassificationKind::Type);
return Type;
}
NamedDecl *getNonTypeDecl() const {
- assert(Kind == NC_NonType);
+ assert(Kind == NameClassificationKind::NonType);
return NonTypeDecl;
}
TemplateName getTemplateName() const {
- assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||
- Kind == NC_VarTemplate || Kind == NC_Concept ||
- Kind == NC_UndeclaredTemplate);
+ assert(Kind == NameClassificationKind::TypeTemplate ||
+ Kind == NameClassificationKind::FunctionTemplate ||
+ Kind == NameClassificationKind::VarTemplate ||
+ Kind == NameClassificationKind::Concept ||
+ Kind == NameClassificationKind::UndeclaredTemplate);
return Template;
}
TemplateNameKind getTemplateNameKind() const {
switch (Kind) {
- case NC_TypeTemplate:
+ case NameClassificationKind::TypeTemplate:
return TNK_Type_template;
- case NC_FunctionTemplate:
+ case NameClassificationKind::FunctionTemplate:
return TNK_Function_template;
- case NC_VarTemplate:
+ case NameClassificationKind::VarTemplate:
return TNK_Var_template;
- case NC_Concept:
+ case NameClassificationKind::Concept:
return TNK_Concept_template;
- case NC_UndeclaredTemplate:
+ case NameClassificationKind::UndeclaredTemplate:
return TNK_Undeclared_template;
default:
llvm_unreachable("unsupported name classification.");
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 0747790b96d2f..9dd9d9c637592 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3570,28 +3570,28 @@ Parser::DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS, AccessSpecifier AS,
getCurScope(), SS, Name, AfterScope.getLocation(), Next,
/*CCC=*/nullptr);
switch (Classification.getKind()) {
- case Sema::NC_Error:
+ case NameClassificationKind::Error:
SkipMalformedDecl();
return true;
- case Sema::NC_Keyword:
+ case NameClassificationKind::Keyword:
llvm_unreachable("typo correction is not possible here");
- case Sema::NC_Type:
- case Sema::NC_TypeTemplate:
- case Sema::NC_UndeclaredNonType:
- case Sema::NC_UndeclaredTemplate:
+ case NameClassificationKind::Type:
+ case NameClassificationKind::TypeTemplate:
+ case NameClassificationKind::UndeclaredNonType:
+ case NameClassificationKind::UndeclaredTemplate:
// Not a previously-declared non-type entity.
MightBeDeclarator = false;
break;
- case Sema::NC_Unknown:
- case Sema::NC_NonType:
- case Sema::NC_DependentNonType:
- case Sema::NC_OverloadSet:
- case Sema::NC_VarTemplate:
- case Sema::NC_FunctionTemplate:
- case Sema::NC_Concept:
+ case NameClassificationKind::Unknown:
+ case NameClassificationKind::NonType:
+ case NameClassificationKind::DependentNonType:
+ case NameClassificationKind::OverloadSet:
+ case NameClassificationKind::VarTemplate:
+ case NameClassificationKind::FunctionTemplate:
+ case NameClassificationKind::Concept:
// Might be a redeclaration of a prior entity.
break;
}
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index 7883deaba489e..fcd76c75c9bfb 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -2275,10 +2275,10 @@ bool Parser::NameAfterArrowIsNonType() {
Sema::NameClassification Classification =
Actions.ClassifyName(getCurScope(), SS, Name, NameLoc, Next, &CCC);
switch (Classification.getKind()) {
- case Sema::NC_OverloadSet:
- case Sema::NC_NonType:
- case Sema::NC_VarTemplate:
- case Sema::NC_FunctionTemplate:
+ case NameClassificationKind::OverloadSet:
+ case NameClassificationKind::NonType:
+ case NameClassificationKind::VarTemplate:
+ case NameClassificationKind::FunctionTemplate:
return true;
default:
break;
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index a610e56760328..120d44238ea35 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1862,7 +1862,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
// double-check before committing to that interpretation. C++20 requires that
// we interpret this as a template-id if it can be, but if it can't be, then
// this is an error recovery case.
- if (Classification.getKind() == Sema::NC_UndeclaredTemplate &&
+ if (Classification.getKind() == NameClassificationKind::UndeclaredTemplate &&
isTemplateArgumentList(1) == TPResult::False) {
// It's not a template-id; re-classify without the '<' as a hint.
Token FakeNext = Next;
@@ -1873,10 +1873,10 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
}
switch (Classification.getKind()) {
- case Sema::NC_Error:
+ case NameClassificationKind::Error:
return AnnotatedNameKind::Error;
- case Sema::NC_Keyword:
+ case NameClassificationKind::Keyword:
// The identifier was typo-corrected to a keyword.
Tok.setIdentifierInfo(Name);
Tok.setKind(Name->getTokenID());
@@ -1886,11 +1886,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
// We've "annotated" this as a keyword.
return AnnotatedNameKind::Success;
- case Sema::NC_Unknown:
+ case NameClassificationKind::Unknown:
// It's not something we know about. Leave it unannotated.
break;
- case Sema::NC_Type: {
+ case NameClassificationKind::Type: {
if (TryAltiVecVectorToken())
// vector has been found as a type id when altivec is enabled but
// this is followed by a declaration specifier so this is really the
@@ -1927,7 +1927,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
return AnnotatedNameKind::Success;
}
- case Sema::NC_OverloadSet:
+ case NameClassificationKind::OverloadSet:
Tok.setKind(tok::annot_overload_set);
setExprAnnotation(Tok, Classification.getExpression());
Tok.setAnnotationEndLoc(NameLoc);
@@ -1936,7 +1936,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
PP.AnnotateCachedTokens(Tok);
return AnnotatedNameKind::Success;
- case Sema::NC_NonType:
+ case NameClassificationKind::NonType:
if (TryAltiVecVectorToken())
// vector has been found as a non-type id when altivec is enabled but
// this is followed by a declaration specifier so this is really the
@@ -1951,9 +1951,10 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
AnnotateScopeToken(SS, !WasScopeAnnotation);
return AnnotatedNameKind::Success;
- case Sema::NC_UndeclaredNonType:
- case Sema::NC_DependentNonType:
- Tok.setKind(Classification.getKind() == Sema::NC_UndeclaredNonType
+ case NameClassificationKind::UndeclaredNonType:
+ case NameClassificationKind::DependentNonType:
+ Tok.setKind(Classification.getKind() ==
+ NameClassificationKind::UndeclaredNonType
? tok::annot_non_type_undeclared
: tok::annot_non_type_dependent);
setIdentifierAnnotation(Tok, Name);
@@ -1964,7 +1965,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
AnnotateScopeToken(SS, !WasScopeAnnotation);
return AnnotatedNameKind::Success;
- case Sema::NC_TypeTemplate:
+ case NameClassificationKind::TypeTemplate:
if (Next.isNot(tok::less)) {
// This may be a type template being used as a template template argument.
if (SS.isNotEmpty())
@@ -1972,11 +1973,12 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
return AnnotatedNameKind::TemplateName;
}
[[fallthrough]];
- case Sema::NC_Concept:
- case Sema::NC_VarTemplate:
- case Sema::NC_FunctionTemplate:
- case Sema::NC_UndeclaredTemplate: {
- bool IsConceptName = Classification.getKind() == Sema::NC_Concept;
+ case NameClassificationKind::Concept:
+ case NameClassificationKind::VarTemplate:
+ case NameClassificationKind::FunctionTemplate:
+ case NameClassificationKind::UndeclaredTemplate: {
+ bool IsConceptName =
+ Classification.getKind() == NameClassificationKind::Concept;
// We have a template name followed by '<'. Consume the identifier token so
// we reach the '<' and annotate it.
if (Next.is(tok::less))
More information about the cfe-commits
mailing list