Skip to content

Commit e803c20

Browse files
committed
[clang][NFC] Convert Parser::CXX11AttributeKind to scoped enum
1 parent 78a1d92 commit e803c20

File tree

5 files changed

+52
-40
lines changed

5 files changed

+52
-40
lines changed

clang/include/clang/Parse/Parser.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ enum class TentativeCXXTypeIdContext {
138138
AsGenericSelectionArgument,
139139
};
140140

141+
/// The kind of attribute specifier we have found.
142+
enum class CXX11AttributeKind {
143+
/// This is not an attribute specifier.
144+
NotAttributeSpecifier,
145+
/// This should be treated as an attribute-specifier.
146+
AttributeSpecifier,
147+
/// The next tokens are '[[', but this is not an attribute-specifier. This
148+
/// is ill-formed by C++11 [dcl.attr.grammar]p6.
149+
InvalidAttributeSpecifier
150+
};
151+
141152
/// Parser - This implements a parser for the C family of languages. After
142153
/// parsing units of the grammar, productions are invoked to handle whatever has
143154
/// been read.
@@ -2821,7 +2832,8 @@ class Parser : public CodeCompletionHandler {
28212832
bool isAllowedCXX11AttributeSpecifier(bool Disambiguate = false,
28222833
bool OuterMightBeMessageSend = false) {
28232834
return (Tok.isRegularKeywordAttribute() ||
2824-
isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend));
2835+
isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
2836+
CXX11AttributeKind::NotAttributeSpecifier);
28252837
}
28262838

28272839
// Check for the start of an attribute-specifier-seq in a context where an
@@ -3280,16 +3292,6 @@ class Parser : public CodeCompletionHandler {
32803292
//===--------------------------------------------------------------------===//
32813293
// C++ 7: Declarations [dcl.dcl]
32823294

3283-
/// The kind of attribute specifier we have found.
3284-
enum CXX11AttributeKind {
3285-
/// This is not an attribute specifier.
3286-
CAK_NotAttributeSpecifier,
3287-
/// This should be treated as an attribute-specifier.
3288-
CAK_AttributeSpecifier,
3289-
/// The next tokens are '[[', but this is not an attribute-specifier. This
3290-
/// is ill-formed by C++11 [dcl.attr.grammar]p6.
3291-
CAK_InvalidAttributeSpecifier
3292-
};
32933295
CXX11AttributeKind
32943296
isCXX11AttributeSpecifier(bool Disambiguate = false,
32953297
bool OuterMightBeMessageSend = false);

clang/lib/Parse/ParseDecl.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -1879,15 +1879,15 @@ bool Parser::DiagnoseProhibitedCXX11Attribute() {
18791879
assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square));
18801880

18811881
switch (isCXX11AttributeSpecifier(/*Disambiguate*/true)) {
1882-
case CAK_NotAttributeSpecifier:
1882+
case CXX11AttributeKind::NotAttributeSpecifier:
18831883
// No diagnostic: we're in Obj-C++11 and this is not actually an attribute.
18841884
return false;
18851885

1886-
case CAK_InvalidAttributeSpecifier:
1886+
case CXX11AttributeKind::InvalidAttributeSpecifier:
18871887
Diag(Tok.getLocation(), diag::err_l_square_l_square_not_attribute);
18881888
return false;
18891889

1890-
case CAK_AttributeSpecifier:
1890+
case CXX11AttributeKind::AttributeSpecifier:
18911891
// Parse and discard the attributes.
18921892
SourceLocation BeginLoc = ConsumeBracket();
18931893
ConsumeBracket();
@@ -6393,7 +6393,8 @@ bool Parser::isConstructorDeclarator(bool IsUnqualified, bool DeductionGuide,
63936393
// attribute on the first constructor parameter.
63946394
if (getLangOpts().CPlusPlus11 &&
63956395
isCXX11AttributeSpecifier(/*Disambiguate*/ false,
6396-
/*OuterMightBeMessageSend*/ true)) {
6396+
/*OuterMightBeMessageSend*/ true) !=
6397+
CXX11AttributeKind::NotAttributeSpecifier) {
63976398
return true;
63986399
}
63996400

@@ -7365,7 +7366,7 @@ void Parser::ParseDecompositionDeclarator(Declarator &D) {
73657366
BalancedDelimiterTracker T(*this, tok::l_square);
73667367
T.consumeOpen();
73677368

7368-
if (isCXX11AttributeSpecifier())
7369+
if (isCXX11AttributeSpecifier() != CXX11AttributeKind::NotAttributeSpecifier)
73697370
DiagnoseAndSkipCXX11Attributes();
73707371

73717372
// If this doesn't look like a structured binding, maybe it's a misplaced
@@ -7403,7 +7404,8 @@ void Parser::ParseDecompositionDeclarator(Declarator &D) {
74037404
}
74047405
}
74057406

7406-
if (isCXX11AttributeSpecifier())
7407+
if (isCXX11AttributeSpecifier() !=
7408+
CXX11AttributeKind::NotAttributeSpecifier)
74077409
DiagnoseAndSkipCXX11Attributes();
74087410

74097411
SourceLocation EllipsisLoc;
@@ -7438,7 +7440,8 @@ void Parser::ParseDecompositionDeclarator(Declarator &D) {
74387440
}
74397441

74407442
ParsedAttributes Attrs(AttrFactory);
7441-
if (isCXX11AttributeSpecifier()) {
7443+
if (isCXX11AttributeSpecifier() !=
7444+
CXX11AttributeKind::NotAttributeSpecifier) {
74427445
Diag(Tok, getLangOpts().CPlusPlus26
74437446
? diag::warn_cxx23_compat_decl_attrs_on_binding
74447447
: diag::ext_decl_attrs_on_binding);
@@ -7527,7 +7530,9 @@ void Parser::ParseParenDeclarator(Declarator &D) {
75277530
NextToken().is(tok::r_paren)) || // C++ int(...)
75287531
isDeclarationSpecifier(
75297532
ImplicitTypenameContext::No) || // 'int(int)' is a function.
7530-
isCXX11AttributeSpecifier()) { // 'int([[]]int)' is a function.
7533+
isCXX11AttributeSpecifier() !=
7534+
CXX11AttributeKind::NotAttributeSpecifier) { // 'int([[]]int)'
7535+
// is a function.
75317536
// This handles C99 6.7.5.3p11: in "typedef int X; void foo(X)", X is
75327537
// considered to be a type, not a K&R identifier-list.
75337538
isGrouping = false;

clang/lib/Parse/ParseDeclCXX.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -5097,7 +5097,7 @@ void Parser::DiagnoseAndSkipCXX11Attributes() {
50975097
SourceLocation Parser::SkipCXX11Attributes() {
50985098
SourceLocation EndLoc;
50995099

5100-
if (!isCXX11AttributeSpecifier())
5100+
if (isCXX11AttributeSpecifier() == CXX11AttributeKind::NotAttributeSpecifier)
51015101
return EndLoc;
51025102

51035103
do {
@@ -5119,7 +5119,8 @@ SourceLocation Parser::SkipCXX11Attributes() {
51195119
T.skipToEnd();
51205120
EndLoc = T.getCloseLocation();
51215121
}
5122-
} while (isCXX11AttributeSpecifier());
5122+
} while (isCXX11AttributeSpecifier() !=
5123+
CXX11AttributeKind::NotAttributeSpecifier);
51235124

51245125
return EndLoc;
51255126
}

clang/lib/Parse/ParseExprCXX.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,8 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
14511451
// lambda declarator and applies them to the corresponding function operator
14521452
// or operator template declaration. We accept this as a conforming extension
14531453
// in all language modes that support lambdas.
1454-
if (isCXX11AttributeSpecifier()) {
1454+
if (isCXX11AttributeSpecifier() !=
1455+
CXX11AttributeKind::NotAttributeSpecifier) {
14551456
Diag(Tok, getLangOpts().CPlusPlus23
14561457
? diag::warn_cxx20_compat_decl_attrs_on_lambda
14571458
: diag::ext_decl_attrs_on_lambda)

clang/lib/Parse/ParseTentative.cpp

+21-18
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,8 @@ bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) {
710710
/// apply if either '[' begins a message-send.
711711
///
712712
/// If Disambiguate is true, we try harder to determine whether a '[[' starts
713-
/// an attribute-specifier, and return CAK_InvalidAttributeSpecifier if not.
713+
/// an attribute-specifier, and return
714+
/// CXX11AttributeKind::InvalidAttributeSpecifier if not.
714715
///
715716
/// If OuterMightBeMessageSend is true, we assume the outer '[' is either an
716717
/// Obj-C message send or the start of an attribute. Otherwise, we assume it
@@ -737,26 +738,26 @@ bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) {
737738
///
738739
/// attribute-argument-clause:
739740
/// '(' balanced-token-seq ')'
740-
Parser::CXX11AttributeKind
741+
CXX11AttributeKind
741742
Parser::isCXX11AttributeSpecifier(bool Disambiguate,
742743
bool OuterMightBeMessageSend) {
743744
// alignas is an attribute specifier in C++ but not in C23.
744745
if (Tok.is(tok::kw_alignas) && !getLangOpts().C23)
745-
return CAK_AttributeSpecifier;
746+
return CXX11AttributeKind::AttributeSpecifier;
746747

747748
if (Tok.isRegularKeywordAttribute())
748-
return CAK_AttributeSpecifier;
749+
return CXX11AttributeKind::AttributeSpecifier;
749750

750751
if (Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square))
751-
return CAK_NotAttributeSpecifier;
752+
return CXX11AttributeKind::NotAttributeSpecifier;
752753

753754
// No tentative parsing if we don't need to look for ']]' or a lambda.
754755
if (!Disambiguate && !getLangOpts().ObjC)
755-
return CAK_AttributeSpecifier;
756+
return CXX11AttributeKind::AttributeSpecifier;
756757

757758
// '[[using ns: ...]]' is an attribute.
758759
if (GetLookAheadToken(2).is(tok::kw_using))
759-
return CAK_AttributeSpecifier;
760+
return CXX11AttributeKind::AttributeSpecifier;
760761

761762
RevertingTentativeParsingAction PA(*this);
762763

@@ -769,7 +770,8 @@ Parser::isCXX11AttributeSpecifier(bool Disambiguate,
769770
bool IsAttribute = SkipUntil(tok::r_square);
770771
IsAttribute &= Tok.is(tok::r_square);
771772

772-
return IsAttribute ? CAK_AttributeSpecifier : CAK_InvalidAttributeSpecifier;
773+
return IsAttribute ? CXX11AttributeKind::AttributeSpecifier
774+
: CXX11AttributeKind::InvalidAttributeSpecifier;
773775
}
774776

775777
// In Obj-C++11, we need to distinguish four situations:
@@ -792,28 +794,28 @@ Parser::isCXX11AttributeSpecifier(bool Disambiguate,
792794
// We hit a hard error after deciding this was not an attribute.
793795
// FIXME: Don't parse and annotate expressions when disambiguating
794796
// against an attribute.
795-
return CAK_NotAttributeSpecifier;
797+
return CXX11AttributeKind::NotAttributeSpecifier;
796798
}
797799

798800
switch (Tentative) {
799801
case LambdaIntroducerTentativeParse::MessageSend:
800802
// Case 3: The inner construct is definitely a message send, so the
801803
// outer construct is definitely not an attribute.
802-
return CAK_NotAttributeSpecifier;
804+
return CXX11AttributeKind::NotAttributeSpecifier;
803805

804806
case LambdaIntroducerTentativeParse::Success:
805807
case LambdaIntroducerTentativeParse::Incomplete:
806808
// This is a lambda-introducer or attribute-specifier.
807809
if (Tok.is(tok::r_square))
808810
// Case 1: C++11 attribute.
809-
return CAK_AttributeSpecifier;
811+
return CXX11AttributeKind::AttributeSpecifier;
810812

811813
if (OuterMightBeMessageSend)
812814
// Case 4: Lambda in message send.
813-
return CAK_NotAttributeSpecifier;
815+
return CXX11AttributeKind::NotAttributeSpecifier;
814816

815817
// Case 2: Lambda in array size / index.
816-
return CAK_InvalidAttributeSpecifier;
818+
return CXX11AttributeKind::InvalidAttributeSpecifier;
817819

818820
case LambdaIntroducerTentativeParse::Invalid:
819821
// No idea what this is; we couldn't parse it as a lambda-introducer.
@@ -830,7 +832,7 @@ Parser::isCXX11AttributeSpecifier(bool Disambiguate,
830832
while (Tok.isNot(tok::r_square)) {
831833
if (Tok.is(tok::comma)) {
832834
// Case 1: Stray commas can only occur in attributes.
833-
return CAK_AttributeSpecifier;
835+
return CXX11AttributeKind::AttributeSpecifier;
834836
}
835837

836838
// Parse the attribute-token, if present.
@@ -878,10 +880,10 @@ Parser::isCXX11AttributeSpecifier(bool Disambiguate,
878880

879881
if (IsAttribute)
880882
// Case 1: C++11 statement attribute.
881-
return CAK_AttributeSpecifier;
883+
return CXX11AttributeKind::AttributeSpecifier;
882884

883885
// Case 3: Message send.
884-
return CAK_NotAttributeSpecifier;
886+
return CXX11AttributeKind::NotAttributeSpecifier;
885887
}
886888

887889
bool Parser::TrySkipAttributes() {
@@ -2092,8 +2094,9 @@ Parser::TPResult Parser::TryParseParameterDeclarationClause(
20922094
}
20932095

20942096
// An attribute-specifier-seq here is a sign of a function declarator.
2095-
if (isCXX11AttributeSpecifier(/*Disambiguate*/false,
2096-
/*OuterMightBeMessageSend*/true))
2097+
if (isCXX11AttributeSpecifier(/*Disambiguate*/ false,
2098+
/*OuterMightBeMessageSend*/ true) !=
2099+
CXX11AttributeKind::NotAttributeSpecifier)
20972100
return TPResult::True;
20982101

20992102
ParsedAttributes attrs(AttrFactory);

0 commit comments

Comments
 (0)