@@ -101,8 +101,13 @@ enum class ObjCTypeQual {
101
101
NumQuals
102
102
};
103
103
104
- // / TypeCastState - State whether an expression is or may be a type cast.
105
- enum class TypeCastState { NotTypeCast = 0 , MaybeTypeCast, IsTypeCast };
104
+ // / If a typo should be encountered, should typo correction suggest type names,
105
+ // / non type names, or both?
106
+ enum class TypoCorrectionTypeBehavior {
107
+ AllowNonTypes,
108
+ AllowTypes,
109
+ AllowBoth,
110
+ };
106
111
107
112
// / Control what ParseCastExpression will parse.
108
113
enum class CastParseKind { AnyCastExpr = 0 , UnaryExprOnly, PrimaryExprOnly };
@@ -116,6 +121,15 @@ enum class ParenParseOption {
116
121
CastExpr // Also allow '(' type-name ')' <anything>
117
122
};
118
123
124
+ // / In a call to ParseParenExpression, are the initial parentheses part of an
125
+ // / operator that requires the parens be there (like typeof(int)) or could they
126
+ // / be something else, such as part of a compound literal or a sizeof
127
+ // / expression, etc.
128
+ enum class ParenExprKind {
129
+ PartOfOperator, // typeof(int)
130
+ Unknown, // sizeof(int) or sizeof (int)1.0f, or compound literal, etc
131
+ };
132
+
119
133
// / Describes the behavior that should be taken for an __if_exists
120
134
// / block.
121
135
enum class IfExistsBehavior {
@@ -3709,11 +3723,12 @@ class Parser : public CodeCompletionHandler {
3709
3723
// / assignment-expression ...[opt]
3710
3724
// / expression ',' assignment-expression ...[opt]
3711
3725
// / \endverbatim
3712
- ExprResult
3713
- ParseExpression (TypeCastState isTypeCast = TypeCastState::NotTypeCast );
3726
+ ExprResult ParseExpression (TypoCorrectionTypeBehavior CorrectionBehavior =
3727
+ TypoCorrectionTypeBehavior::AllowNonTypes );
3714
3728
3715
3729
ExprResult ParseConstantExpressionInExprEvalContext (
3716
- TypeCastState isTypeCast = TypeCastState::NotTypeCast);
3730
+ TypoCorrectionTypeBehavior CorrectionBehavior =
3731
+ TypoCorrectionTypeBehavior::AllowNonTypes);
3717
3732
ExprResult ParseConstantExpression ();
3718
3733
ExprResult ParseArrayBoundExpression ();
3719
3734
ExprResult ParseCaseExpression (SourceLocation CaseLoc);
@@ -3750,8 +3765,9 @@ class Parser : public CodeCompletionHandler {
3750
3765
ExprResult ParseConstraintLogicalOrExpression (bool IsTrailingRequiresClause);
3751
3766
3752
3767
// / Parse an expr that doesn't include (top-level) commas.
3753
- ExprResult ParseAssignmentExpression (
3754
- TypeCastState isTypeCast = TypeCastState::NotTypeCast);
3768
+ ExprResult
3769
+ ParseAssignmentExpression (TypoCorrectionTypeBehavior CorrectionBehavior =
3770
+ TypoCorrectionTypeBehavior::AllowNonTypes);
3755
3771
3756
3772
ExprResult ParseConditionalExpression ();
3757
3773
@@ -4017,14 +4033,15 @@ class Parser : public CodeCompletionHandler {
4017
4033
// /
4018
4034
ExprResult ParseCastExpression (CastParseKind ParseKind,
4019
4035
bool isAddressOfOperand, bool &NotCastExpr,
4020
- TypeCastState isTypeCast,
4036
+ TypoCorrectionTypeBehavior CorrectionBehavior,
4037
+ bool isVectorLiteral = false ,
4038
+ bool *NotPrimaryExpression = nullptr );
4039
+ ExprResult ParseCastExpression (CastParseKind ParseKind,
4040
+ bool isAddressOfOperand = false ,
4041
+ TypoCorrectionTypeBehavior CorrectionBehavior =
4042
+ TypoCorrectionTypeBehavior::AllowNonTypes,
4021
4043
bool isVectorLiteral = false ,
4022
4044
bool *NotPrimaryExpression = nullptr );
4023
- ExprResult
4024
- ParseCastExpression (CastParseKind ParseKind, bool isAddressOfOperand = false ,
4025
- TypeCastState isTypeCast = TypeCastState::NotTypeCast,
4026
- bool isVectorLiteral = false ,
4027
- bool *NotPrimaryExpression = nullptr );
4028
4045
4029
4046
// / Returns true if the next token cannot start an expression.
4030
4047
bool isNotExpressionStart ();
@@ -4181,10 +4198,15 @@ class Parser : public CodeCompletionHandler {
4181
4198
// / \endverbatim
4182
4199
bool ParseSimpleExpressionList (SmallVectorImpl<Expr *> &Exprs);
4183
4200
4184
- // / ParseParenExpression - This parses the unit that starts with a '(' token,
4185
- // / based on what is allowed by ExprType. The actual thing parsed is returned
4186
- // / in ExprType. If stopIfCastExpr is true, it will only return the parsed
4187
- // / type, not the parsed cast-expression.
4201
+ // / This parses the unit that starts with a '(' token, based on what is
4202
+ // / allowed by ExprType. The actual thing parsed is returned in ExprType. If
4203
+ // / StopIfCastExpr is true, it will only return the parsed type, not the
4204
+ // / parsed cast-expression. If ParenBehavior is ParenExprKind::PartOfOperator,
4205
+ // / the initial open paren and its matching close paren are known to be part
4206
+ // / of another grammar production and not part of the operand. e.g., the
4207
+ // / typeof and typeof_unqual operators in C. Otherwise, the function has to
4208
+ // / parse the parens to determine whether they're part of a cast or compound
4209
+ // / literal expression rather than a parenthesized type.
4188
4210
// /
4189
4211
// / \verbatim
4190
4212
// / primary-expression: [C99 6.5.1]
@@ -4209,7 +4231,9 @@ class Parser : public CodeCompletionHandler {
4209
4231
// / '(' '[' expression ']' { '[' expression ']' } cast-expression
4210
4232
// / \endverbatim
4211
4233
ExprResult ParseParenExpression (ParenParseOption &ExprType,
4212
- bool stopIfCastExpr, bool isTypeCast,
4234
+ bool StopIfCastExpr,
4235
+ ParenExprKind ParenBehavior,
4236
+ TypoCorrectionTypeBehavior CorrectionBehavior,
4213
4237
ParsedType &CastTy,
4214
4238
SourceLocation &RParenLoc);
4215
4239
0 commit comments