Skip to content

Commit 4595e80

Browse files
committed
[clang][NFC] Convert Parser::AnnotatedNameKind to scoped enum
1 parent 951292b commit 4595e80

File tree

4 files changed

+42
-41
lines changed

4 files changed

+42
-41
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ namespace clang {
5151
struct OMPTraitSet;
5252
class OMPTraitInfo;
5353

54+
enum class AnnotatedNameKind {
55+
/// Annotation has failed and emitted an error.
56+
Error,
57+
/// The identifier is a tentatively-declared name.
58+
TentativeDecl,
59+
/// The identifier is a template name. FIXME: Add an annotation for that.
60+
TemplateName,
61+
/// The identifier can't be resolved.
62+
Unresolved,
63+
/// Annotation was successful.
64+
Success
65+
};
66+
5467
/// Parser - This implements a parser for the C family of languages. After
5568
/// parsing units of the grammar, productions are invoked to handle whatever has
5669
/// been read.
@@ -940,19 +953,6 @@ class Parser : public CodeCompletionHandler {
940953
}
941954

942955
private:
943-
enum AnnotatedNameKind {
944-
/// Annotation has failed and emitted an error.
945-
ANK_Error,
946-
/// The identifier is a tentatively-declared name.
947-
ANK_TentativeDecl,
948-
/// The identifier is a template name. FIXME: Add an annotation for that.
949-
ANK_TemplateName,
950-
/// The identifier can't be resolved.
951-
ANK_Unresolved,
952-
/// Annotation was successful.
953-
ANK_Success
954-
};
955-
956956
AnnotatedNameKind
957957
TryAnnotateName(CorrectionCandidateCallback *CCC = nullptr,
958958
ImplicitTypenameContext AllowImplicitTypename =

clang/lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
216216
// Try to limit which sets of keywords should be included in typo
217217
// correction based on what the next token is.
218218
StatementFilterCCC CCC(Next);
219-
if (TryAnnotateName(&CCC) == ANK_Error) {
219+
if (TryAnnotateName(&CCC) == AnnotatedNameKind::Error) {
220220
// Handle errors here by skipping up to the next semicolon or '}', and
221221
// eat the semicolon if that's what stopped us.
222222
SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);

clang/lib/Parse/ParseTentative.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,11 +1401,11 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
14011401
// to types and identifiers, in order to try to recover from errors.
14021402
TentativeParseCCC CCC(Next);
14031403
switch (TryAnnotateName(&CCC)) {
1404-
case ANK_Error:
1404+
case AnnotatedNameKind::Error:
14051405
return TPResult::Error;
1406-
case ANK_TentativeDecl:
1406+
case AnnotatedNameKind::TentativeDecl:
14071407
return TPResult::False;
1408-
case ANK_TemplateName:
1408+
case AnnotatedNameKind::TemplateName:
14091409
// In C++17, this could be a type template for class template argument
14101410
// deduction. Try to form a type annotation for it. If we're in a
14111411
// template template argument, we'll undo this when checking the
@@ -1420,9 +1420,9 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
14201420
// A bare type template-name which can't be a template template
14211421
// argument is an error, and was probably intended to be a type.
14221422
return GreaterThanIsOperator ? TPResult::True : TPResult::False;
1423-
case ANK_Unresolved:
1423+
case AnnotatedNameKind::Unresolved:
14241424
return InvalidAsDeclSpec ? TPResult::Ambiguous : TPResult::False;
1425-
case ANK_Success:
1425+
case AnnotatedNameKind::Success:
14261426
break;
14271427
}
14281428
assert(Tok.isNot(tok::identifier) &&
@@ -1694,11 +1694,11 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
16941694
// Try to resolve the name. If it doesn't exist, assume it was
16951695
// intended to name a type and keep disambiguating.
16961696
switch (TryAnnotateName(/*CCC=*/nullptr, AllowImplicitTypename)) {
1697-
case ANK_Error:
1697+
case AnnotatedNameKind::Error:
16981698
return TPResult::Error;
1699-
case ANK_TentativeDecl:
1699+
case AnnotatedNameKind::TentativeDecl:
17001700
return TPResult::False;
1701-
case ANK_TemplateName:
1701+
case AnnotatedNameKind::TemplateName:
17021702
// In C++17, this could be a type template for class template
17031703
// argument deduction.
17041704
if (getLangOpts().CPlusPlus17) {
@@ -1717,9 +1717,9 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
17171717
return (getLangOpts().CPlusPlus17 || GreaterThanIsOperator)
17181718
? TPResult::True
17191719
: TPResult::False;
1720-
case ANK_Unresolved:
1720+
case AnnotatedNameKind::Unresolved:
17211721
return InvalidAsDeclSpec ? TPResult::Ambiguous : TPResult::False;
1722-
case ANK_Success:
1722+
case AnnotatedNameKind::Success:
17231723
break;
17241724
}
17251725

clang/lib/Parse/Parser.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ void Parser::AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation) {
18021802
/// \param AllowImplicitTypename Whether we are in a context where a dependent
18031803
/// nested-name-specifier without typename is treated as a type (e.g.
18041804
/// T::type).
1805-
Parser::AnnotatedNameKind
1805+
AnnotatedNameKind
18061806
Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
18071807
ImplicitTypenameContext AllowImplicitTypename) {
18081808
assert(Tok.is(tok::identifier) || Tok.is(tok::annot_cxxscope));
@@ -1815,13 +1815,13 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
18151815
ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
18161816
/*ObjectHasErrors=*/false,
18171817
EnteringContext))
1818-
return ANK_Error;
1818+
return AnnotatedNameKind::Error;
18191819

18201820
if (Tok.isNot(tok::identifier) || SS.isInvalid()) {
18211821
if (TryAnnotateTypeOrScopeTokenAfterScopeSpec(SS, !WasScopeAnnotation,
18221822
AllowImplicitTypename))
1823-
return ANK_Error;
1824-
return ANK_Unresolved;
1823+
return AnnotatedNameKind::Error;
1824+
return AnnotatedNameKind::Unresolved;
18251825
}
18261826

18271827
IdentifierInfo *Name = Tok.getIdentifierInfo();
@@ -1834,8 +1834,9 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
18341834
// an expression. Fall back to annotating it as a type.
18351835
if (TryAnnotateTypeOrScopeTokenAfterScopeSpec(SS, !WasScopeAnnotation,
18361836
AllowImplicitTypename))
1837-
return ANK_Error;
1838-
return Tok.is(tok::annot_typename) ? ANK_Success : ANK_TentativeDecl;
1837+
return AnnotatedNameKind::Error;
1838+
return Tok.is(tok::annot_typename) ? AnnotatedNameKind::Success
1839+
: AnnotatedNameKind::TentativeDecl;
18391840
}
18401841

18411842
Token Next = NextToken();
@@ -1863,7 +1864,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
18631864

18641865
switch (Classification.getKind()) {
18651866
case Sema::NC_Error:
1866-
return ANK_Error;
1867+
return AnnotatedNameKind::Error;
18671868

18681869
case Sema::NC_Keyword:
18691870
// The identifier was typo-corrected to a keyword.
@@ -1873,7 +1874,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
18731874
if (SS.isNotEmpty())
18741875
AnnotateScopeToken(SS, !WasScopeAnnotation);
18751876
// We've "annotated" this as a keyword.
1876-
return ANK_Success;
1877+
return AnnotatedNameKind::Success;
18771878

18781879
case Sema::NC_Unknown:
18791880
// It's not something we know about. Leave it unannotated.
@@ -1905,15 +1906,15 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
19051906
if (NewType.isUsable())
19061907
Ty = NewType.get();
19071908
else if (Tok.is(tok::eof)) // Nothing to do here, bail out...
1908-
return ANK_Error;
1909+
return AnnotatedNameKind::Error;
19091910
}
19101911

19111912
Tok.setKind(tok::annot_typename);
19121913
setTypeAnnotation(Tok, Ty);
19131914
Tok.setAnnotationEndLoc(Tok.getLocation());
19141915
Tok.setLocation(BeginLoc);
19151916
PP.AnnotateCachedTokens(Tok);
1916-
return ANK_Success;
1917+
return AnnotatedNameKind::Success;
19171918
}
19181919

19191920
case Sema::NC_OverloadSet:
@@ -1923,7 +1924,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
19231924
if (SS.isNotEmpty())
19241925
Tok.setLocation(SS.getBeginLoc());
19251926
PP.AnnotateCachedTokens(Tok);
1926-
return ANK_Success;
1927+
return AnnotatedNameKind::Success;
19271928

19281929
case Sema::NC_NonType:
19291930
if (TryAltiVecVectorToken())
@@ -1938,7 +1939,7 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
19381939
PP.AnnotateCachedTokens(Tok);
19391940
if (SS.isNotEmpty())
19401941
AnnotateScopeToken(SS, !WasScopeAnnotation);
1941-
return ANK_Success;
1942+
return AnnotatedNameKind::Success;
19421943

19431944
case Sema::NC_UndeclaredNonType:
19441945
case Sema::NC_DependentNonType:
@@ -1951,14 +1952,14 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
19511952
PP.AnnotateCachedTokens(Tok);
19521953
if (SS.isNotEmpty())
19531954
AnnotateScopeToken(SS, !WasScopeAnnotation);
1954-
return ANK_Success;
1955+
return AnnotatedNameKind::Success;
19551956

19561957
case Sema::NC_TypeTemplate:
19571958
if (Next.isNot(tok::less)) {
19581959
// This may be a type template being used as a template template argument.
19591960
if (SS.isNotEmpty())
19601961
AnnotateScopeToken(SS, !WasScopeAnnotation);
1961-
return ANK_TemplateName;
1962+
return AnnotatedNameKind::TemplateName;
19621963
}
19631964
[[fallthrough]];
19641965
case Sema::NC_Concept:
@@ -1977,17 +1978,17 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
19771978
Classification.getTemplateNameKind(), SS, SourceLocation(), Id,
19781979
/*AllowTypeAnnotation=*/!IsConceptName,
19791980
/*TypeConstraint=*/IsConceptName))
1980-
return ANK_Error;
1981+
return AnnotatedNameKind::Error;
19811982
if (SS.isNotEmpty())
19821983
AnnotateScopeToken(SS, !WasScopeAnnotation);
1983-
return ANK_Success;
1984+
return AnnotatedNameKind::Success;
19841985
}
19851986
}
19861987

19871988
// Unable to classify the name, but maybe we can annotate a scope specifier.
19881989
if (SS.isNotEmpty())
19891990
AnnotateScopeToken(SS, !WasScopeAnnotation);
1990-
return ANK_Unresolved;
1991+
return AnnotatedNameKind::Unresolved;
19911992
}
19921993

19931994
bool Parser::TryKeywordIdentFallback(bool DisableKeyword) {

0 commit comments

Comments
 (0)