Author: Vlad Serebrennikov Date: 2025-04-30T02:23:39+03:00 New Revision: 4595e8092ed5ce69b3ce33e989d7bea3a25fc289
URL: https://github.com/llvm/llvm-project/commit/4595e8092ed5ce69b3ce33e989d7bea3a25fc289 DIFF: https://github.com/llvm/llvm-project/commit/4595e8092ed5ce69b3ce33e989d7bea3a25fc289.diff LOG: [clang][NFC] Convert `Parser::AnnotatedNameKind` to scoped enum Added: Modified: clang/include/clang/Parse/Parser.h clang/lib/Parse/ParseStmt.cpp clang/lib/Parse/ParseTentative.cpp clang/lib/Parse/Parser.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index d9cf3813a1828..dbbb80fdd9943 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -51,6 +51,19 @@ namespace clang { struct OMPTraitSet; class OMPTraitInfo; +enum class AnnotatedNameKind { + /// Annotation has failed and emitted an error. + Error, + /// The identifier is a tentatively-declared name. + TentativeDecl, + /// The identifier is a template name. FIXME: Add an annotation for that. + TemplateName, + /// The identifier can't be resolved. + Unresolved, + /// Annotation was successful. + Success +}; + /// Parser - This implements a parser for the C family of languages. After /// parsing units of the grammar, productions are invoked to handle whatever has /// been read. @@ -940,19 +953,6 @@ class Parser : public CodeCompletionHandler { } private: - enum AnnotatedNameKind { - /// Annotation has failed and emitted an error. - ANK_Error, - /// The identifier is a tentatively-declared name. - ANK_TentativeDecl, - /// The identifier is a template name. FIXME: Add an annotation for that. - ANK_TemplateName, - /// The identifier can't be resolved. - ANK_Unresolved, - /// Annotation was successful. - ANK_Success - }; - AnnotatedNameKind TryAnnotateName(CorrectionCandidateCallback *CCC = nullptr, ImplicitTypenameContext AllowImplicitTypename = diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 4e801f4ef890f..f50a245621185 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -216,7 +216,7 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes( // Try to limit which sets of keywords should be included in typo // correction based on what the next token is. StatementFilterCCC CCC(Next); - if (TryAnnotateName(&CCC) == ANK_Error) { + if (TryAnnotateName(&CCC) == AnnotatedNameKind::Error) { // Handle errors here by skipping up to the next semicolon or '}', and // eat the semicolon if that's what stopped us. SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index ff27ef70944a4..0994ff126e7e5 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -1401,11 +1401,11 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, // to types and identifiers, in order to try to recover from errors. TentativeParseCCC CCC(Next); switch (TryAnnotateName(&CCC)) { - case ANK_Error: + case AnnotatedNameKind::Error: return TPResult::Error; - case ANK_TentativeDecl: + case AnnotatedNameKind::TentativeDecl: return TPResult::False; - case ANK_TemplateName: + case AnnotatedNameKind::TemplateName: // In C++17, this could be a type template for class template argument // deduction. Try to form a type annotation for it. If we're in a // template template argument, we'll undo this when checking the @@ -1420,9 +1420,9 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, // A bare type template-name which can't be a template template // argument is an error, and was probably intended to be a type. return GreaterThanIsOperator ? TPResult::True : TPResult::False; - case ANK_Unresolved: + case AnnotatedNameKind::Unresolved: return InvalidAsDeclSpec ? TPResult::Ambiguous : TPResult::False; - case ANK_Success: + case AnnotatedNameKind::Success: break; } assert(Tok.isNot(tok::identifier) && @@ -1694,11 +1694,11 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, // Try to resolve the name. If it doesn't exist, assume it was // intended to name a type and keep disambiguating. switch (TryAnnotateName(/*CCC=*/nullptr, AllowImplicitTypename)) { - case ANK_Error: + case AnnotatedNameKind::Error: return TPResult::Error; - case ANK_TentativeDecl: + case AnnotatedNameKind::TentativeDecl: return TPResult::False; - case ANK_TemplateName: + case AnnotatedNameKind::TemplateName: // In C++17, this could be a type template for class template // argument deduction. if (getLangOpts().CPlusPlus17) { @@ -1717,9 +1717,9 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, return (getLangOpts().CPlusPlus17 || GreaterThanIsOperator) ? TPResult::True : TPResult::False; - case ANK_Unresolved: + case AnnotatedNameKind::Unresolved: return InvalidAsDeclSpec ? TPResult::Ambiguous : TPResult::False; - case ANK_Success: + case AnnotatedNameKind::Success: break; } diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index a82aea162716a..0954c31519c5a 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1802,7 +1802,7 @@ void Parser::AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation) { /// \param AllowImplicitTypename Whether we are in a context where a dependent /// nested-name-specifier without typename is treated as a type (e.g. /// T::type). -Parser::AnnotatedNameKind +AnnotatedNameKind Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, ImplicitTypenameContext AllowImplicitTypename) { assert(Tok.is(tok::identifier) || Tok.is(tok::annot_cxxscope)); @@ -1815,13 +1815,13 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr, /*ObjectHasErrors=*/false, EnteringContext)) - return ANK_Error; + return AnnotatedNameKind::Error; if (Tok.isNot(tok::identifier) || SS.isInvalid()) { if (TryAnnotateTypeOrScopeTokenAfterScopeSpec(SS, !WasScopeAnnotation, AllowImplicitTypename)) - return ANK_Error; - return ANK_Unresolved; + return AnnotatedNameKind::Error; + return AnnotatedNameKind::Unresolved; } IdentifierInfo *Name = Tok.getIdentifierInfo(); @@ -1834,8 +1834,9 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, // an expression. Fall back to annotating it as a type. if (TryAnnotateTypeOrScopeTokenAfterScopeSpec(SS, !WasScopeAnnotation, AllowImplicitTypename)) - return ANK_Error; - return Tok.is(tok::annot_typename) ? ANK_Success : ANK_TentativeDecl; + return AnnotatedNameKind::Error; + return Tok.is(tok::annot_typename) ? AnnotatedNameKind::Success + : AnnotatedNameKind::TentativeDecl; } Token Next = NextToken(); @@ -1863,7 +1864,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, switch (Classification.getKind()) { case Sema::NC_Error: - return ANK_Error; + return AnnotatedNameKind::Error; case Sema::NC_Keyword: // The identifier was typo-corrected to a keyword. @@ -1873,7 +1874,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, if (SS.isNotEmpty()) AnnotateScopeToken(SS, !WasScopeAnnotation); // We've "annotated" this as a keyword. - return ANK_Success; + return AnnotatedNameKind::Success; case Sema::NC_Unknown: // It's not something we know about. Leave it unannotated. @@ -1905,7 +1906,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, if (NewType.isUsable()) Ty = NewType.get(); else if (Tok.is(tok::eof)) // Nothing to do here, bail out... - return ANK_Error; + return AnnotatedNameKind::Error; } Tok.setKind(tok::annot_typename); @@ -1913,7 +1914,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, Tok.setAnnotationEndLoc(Tok.getLocation()); Tok.setLocation(BeginLoc); PP.AnnotateCachedTokens(Tok); - return ANK_Success; + return AnnotatedNameKind::Success; } case Sema::NC_OverloadSet: @@ -1923,7 +1924,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, if (SS.isNotEmpty()) Tok.setLocation(SS.getBeginLoc()); PP.AnnotateCachedTokens(Tok); - return ANK_Success; + return AnnotatedNameKind::Success; case Sema::NC_NonType: if (TryAltiVecVectorToken()) @@ -1938,7 +1939,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, PP.AnnotateCachedTokens(Tok); if (SS.isNotEmpty()) AnnotateScopeToken(SS, !WasScopeAnnotation); - return ANK_Success; + return AnnotatedNameKind::Success; case Sema::NC_UndeclaredNonType: case Sema::NC_DependentNonType: @@ -1951,14 +1952,14 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, PP.AnnotateCachedTokens(Tok); if (SS.isNotEmpty()) AnnotateScopeToken(SS, !WasScopeAnnotation); - return ANK_Success; + return AnnotatedNameKind::Success; case Sema::NC_TypeTemplate: if (Next.isNot(tok::less)) { // This may be a type template being used as a template template argument. if (SS.isNotEmpty()) AnnotateScopeToken(SS, !WasScopeAnnotation); - return ANK_TemplateName; + return AnnotatedNameKind::TemplateName; } [[fallthrough]]; case Sema::NC_Concept: @@ -1977,17 +1978,17 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, Classification.getTemplateNameKind(), SS, SourceLocation(), Id, /*AllowTypeAnnotation=*/!IsConceptName, /*TypeConstraint=*/IsConceptName)) - return ANK_Error; + return AnnotatedNameKind::Error; if (SS.isNotEmpty()) AnnotateScopeToken(SS, !WasScopeAnnotation); - return ANK_Success; + return AnnotatedNameKind::Success; } } // Unable to classify the name, but maybe we can annotate a scope specifier. if (SS.isNotEmpty()) AnnotateScopeToken(SS, !WasScopeAnnotation); - return ANK_Unresolved; + return AnnotatedNameKind::Unresolved; } bool Parser::TryKeywordIdentFallback(bool DisableKeyword) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits