Skip to content

Commit 6493fed

Browse files
committed
add a few more missed cases
Created using spr 1.3.6-beta.1
2 parents 243c8cf + e4332e4 commit 6493fed

File tree

26 files changed

+306
-228
lines changed

26 files changed

+306
-228
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,51 @@ enum class ObjCTypeQual {
104104
/// TypeCastState - State whether an expression is or may be a type cast.
105105
enum class TypeCastState { NotTypeCast = 0, MaybeTypeCast, IsTypeCast };
106106

107+
/// Control what ParseCastExpression will parse.
108+
enum class CastParseKind { AnyCastExpr = 0, UnaryExprOnly, PrimaryExprOnly };
109+
110+
/// ParenParseOption - Control what ParseParenExpression will parse.
111+
enum class ParenParseOption {
112+
SimpleExpr, // Only parse '(' expression ')'
113+
FoldExpr, // Also allow fold-expression <anything>
114+
CompoundStmt, // Also allow '(' compound-statement ')'
115+
CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
116+
CastExpr // Also allow '(' type-name ')' <anything>
117+
};
118+
119+
/// Describes the behavior that should be taken for an __if_exists
120+
/// block.
121+
enum class IfExistsBehavior {
122+
/// Parse the block; this code is always used.
123+
Parse,
124+
/// Skip the block entirely; this code is never used.
125+
Skip,
126+
/// Parse the block as a dependent block, which may be used in
127+
/// some template instantiations but not others.
128+
Dependent
129+
};
130+
131+
/// Specifies the context in which type-id/expression
132+
/// disambiguation will occur.
133+
enum class TentativeCXXTypeIdContext {
134+
InParens,
135+
Unambiguous,
136+
AsTemplateArgument,
137+
InTrailingReturnType,
138+
AsGenericSelectionArgument,
139+
};
140+
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+
107152
/// Parser - This implements a parser for the C family of languages. After
108153
/// parsing units of the grammar, productions are invoked to handle whatever has
109154
/// been read.
@@ -1888,14 +1933,7 @@ class Parser : public CodeCompletionHandler {
18881933

18891934
ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
18901935

1891-
ExprResult ParseRHSOfBinaryExpression(ExprResult LHS,
1892-
prec::Level MinPrec);
1893-
/// Control what ParseCastExpression will parse.
1894-
enum CastParseKind {
1895-
AnyCastExpr = 0,
1896-
UnaryExprOnly,
1897-
PrimaryExprOnly
1898-
};
1936+
ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec);
18991937

19001938
bool isRevertibleTypeTrait(const IdentifierInfo *Id,
19011939
clang::tok::TokenKind *Kind = nullptr);
@@ -1955,14 +1993,6 @@ class Parser : public CodeCompletionHandler {
19551993
/// used for misc language extensions.
19561994
bool ParseSimpleExpressionList(SmallVectorImpl<Expr *> &Exprs);
19571995

1958-
/// ParenParseOption - Control what ParseParenExpression will parse.
1959-
enum ParenParseOption {
1960-
SimpleExpr, // Only parse '(' expression ')'
1961-
FoldExpr, // Also allow fold-expression <anything>
1962-
CompoundStmt, // Also allow '(' compound-statement ')'
1963-
CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
1964-
CastExpr // Also allow '(' type-name ')' <anything>
1965-
};
19661996
ExprResult ParseParenExpression(ParenParseOption &ExprType,
19671997
bool stopIfCastExpr,
19681998
bool isTypeCast,
@@ -2228,18 +2258,6 @@ class Parser : public CodeCompletionHandler {
22282258
SourceLocation *TrailingElseLoc,
22292259
ParsedAttributes &Attrs);
22302260

2231-
/// Describes the behavior that should be taken for an __if_exists
2232-
/// block.
2233-
enum IfExistsBehavior {
2234-
/// Parse the block; this code is always used.
2235-
IEB_Parse,
2236-
/// Skip the block entirely; this code is never used.
2237-
IEB_Skip,
2238-
/// Parse the block as a dependent block, which may be used in
2239-
/// some template instantiations but not others.
2240-
IEB_Dependent
2241-
};
2242-
22432261
/// Describes the condition of a Microsoft __if_exists or
22442262
/// __if_not_exists block.
22452263
struct IfExistsCondition {
@@ -2631,22 +2649,12 @@ class Parser : public CodeCompletionHandler {
26312649
DeclSpec::FriendSpecified IsFriend = DeclSpec::FriendSpecified::No,
26322650
const ParsedTemplateInfo *TemplateInfo = nullptr);
26332651

2634-
/// Specifies the context in which type-id/expression
2635-
/// disambiguation will occur.
2636-
enum TentativeCXXTypeIdContext {
2637-
TypeIdInParens,
2638-
TypeIdUnambiguous,
2639-
TypeIdAsTemplateArgument,
2640-
TypeIdInTrailingReturnType,
2641-
TypeIdAsGenericSelectionArgument,
2642-
};
2643-
26442652
/// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
26452653
/// whether the parens contain an expression or a type-id.
26462654
/// Returns true for a type-id and false for an expression.
26472655
bool isTypeIdInParens(bool &isAmbiguous) {
26482656
if (getLangOpts().CPlusPlus)
2649-
return isCXXTypeId(TypeIdInParens, isAmbiguous);
2657+
return isCXXTypeId(TentativeCXXTypeIdContext::InParens, isAmbiguous);
26502658
isAmbiguous = false;
26512659
return isTypeSpecifierQualifier();
26522660
}
@@ -2665,7 +2673,8 @@ class Parser : public CodeCompletionHandler {
26652673
bool isTypeIdForGenericSelection() {
26662674
if (getLangOpts().CPlusPlus) {
26672675
bool isAmbiguous;
2668-
return isCXXTypeId(TypeIdAsGenericSelectionArgument, isAmbiguous);
2676+
return isCXXTypeId(TentativeCXXTypeIdContext::AsGenericSelectionArgument,
2677+
isAmbiguous);
26692678
}
26702679
return isTypeSpecifierQualifier();
26712680
}
@@ -2676,7 +2685,7 @@ class Parser : public CodeCompletionHandler {
26762685
bool isTypeIdUnambiguously() {
26772686
if (getLangOpts().CPlusPlus) {
26782687
bool isAmbiguous;
2679-
return isCXXTypeId(TypeIdUnambiguous, isAmbiguous);
2688+
return isCXXTypeId(TentativeCXXTypeIdContext::Unambiguous, isAmbiguous);
26802689
}
26812690
return isTypeSpecifierQualifier();
26822691
}
@@ -2823,7 +2832,8 @@ class Parser : public CodeCompletionHandler {
28232832
bool isAllowedCXX11AttributeSpecifier(bool Disambiguate = false,
28242833
bool OuterMightBeMessageSend = false) {
28252834
return (Tok.isRegularKeywordAttribute() ||
2826-
isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend));
2835+
isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
2836+
CXX11AttributeKind::NotAttributeSpecifier);
28272837
}
28282838

28292839
// Check for the start of an attribute-specifier-seq in a context where an
@@ -3282,16 +3292,6 @@ class Parser : public CodeCompletionHandler {
32823292
//===--------------------------------------------------------------------===//
32833293
// C++ 7: Declarations [dcl.dcl]
32843294

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

clang/lib/Parse/ParseDecl.cpp

Lines changed: 13 additions & 8 deletions
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

Lines changed: 6 additions & 5 deletions
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
}
@@ -5289,17 +5290,17 @@ void Parser::ParseMicrosoftIfExistsClassDeclaration(
52895290
}
52905291

52915292
switch (Result.Behavior) {
5292-
case IEB_Parse:
5293+
case IfExistsBehavior::Parse:
52935294
// Parse the declarations below.
52945295
break;
52955296

5296-
case IEB_Dependent:
5297+
case IfExistsBehavior::Dependent:
52975298
Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
52985299
<< Result.IsIfExists;
52995300
// Fall through to skip.
53005301
[[fallthrough]];
53015302

5302-
case IEB_Skip:
5303+
case IfExistsBehavior::Skip:
53035304
Braces.skipToEnd();
53045305
return;
53055306
}

0 commit comments

Comments
 (0)