clang 20.0.0git
ParseExpr.cpp
Go to the documentation of this file.
1//===--- ParseExpr.cpp - Expression Parsing -------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Provides the Expression parsing implementation.
11///
12/// Expressions in C99 basically consist of a bunch of binary operators with
13/// unary operators and other random stuff at the leaves.
14///
15/// In the C99 grammar, these unary operators bind tightest and are represented
16/// as the 'cast-expression' production. Everything else is either a binary
17/// operator (e.g. '/') or a ternary operator ("?:"). The unary leaves are
18/// handled by ParseCastExpression, the higher level pieces are handled by
19/// ParseBinaryExpression.
20///
21//===----------------------------------------------------------------------===//
22
24#include "clang/AST/ExprCXX.h"
27#include "clang/Parse/Parser.h"
29#include "clang/Sema/DeclSpec.h"
32#include "clang/Sema/Scope.h"
33#include "clang/Sema/SemaCUDA.h"
35#include "clang/Sema/SemaObjC.h"
38#include "clang/Sema/SemaSYCL.h"
40#include "llvm/ADT/SmallVector.h"
41#include <optional>
42using namespace clang;
43
44/// Simple precedence-based parser for binary/ternary operators.
45///
46/// Note: we diverge from the C99 grammar when parsing the assignment-expression
47/// production. C99 specifies that the LHS of an assignment operator should be
48/// parsed as a unary-expression, but consistency dictates that it be a
49/// conditional-expession. In practice, the important thing here is that the
50/// LHS of an assignment has to be an l-value, which productions between
51/// unary-expression and conditional-expression don't produce. Because we want
52/// consistency, we parse the LHS as a conditional-expression, then check for
53/// l-value-ness in semantic analysis stages.
54///
55/// \verbatim
56/// pm-expression: [C++ 5.5]
57/// cast-expression
58/// pm-expression '.*' cast-expression
59/// pm-expression '->*' cast-expression
60///
61/// multiplicative-expression: [C99 6.5.5]
62/// Note: in C++, apply pm-expression instead of cast-expression
63/// cast-expression
64/// multiplicative-expression '*' cast-expression
65/// multiplicative-expression '/' cast-expression
66/// multiplicative-expression '%' cast-expression
67///
68/// additive-expression: [C99 6.5.6]
69/// multiplicative-expression
70/// additive-expression '+' multiplicative-expression
71/// additive-expression '-' multiplicative-expression
72///
73/// shift-expression: [C99 6.5.7]
74/// additive-expression
75/// shift-expression '<<' additive-expression
76/// shift-expression '>>' additive-expression
77///
78/// compare-expression: [C++20 expr.spaceship]
79/// shift-expression
80/// compare-expression '<=>' shift-expression
81///
82/// relational-expression: [C99 6.5.8]
83/// compare-expression
84/// relational-expression '<' compare-expression
85/// relational-expression '>' compare-expression
86/// relational-expression '<=' compare-expression
87/// relational-expression '>=' compare-expression
88///
89/// equality-expression: [C99 6.5.9]
90/// relational-expression
91/// equality-expression '==' relational-expression
92/// equality-expression '!=' relational-expression
93///
94/// AND-expression: [C99 6.5.10]
95/// equality-expression
96/// AND-expression '&' equality-expression
97///
98/// exclusive-OR-expression: [C99 6.5.11]
99/// AND-expression
100/// exclusive-OR-expression '^' AND-expression
101///
102/// inclusive-OR-expression: [C99 6.5.12]
103/// exclusive-OR-expression
104/// inclusive-OR-expression '|' exclusive-OR-expression
105///
106/// logical-AND-expression: [C99 6.5.13]
107/// inclusive-OR-expression
108/// logical-AND-expression '&&' inclusive-OR-expression
109///
110/// logical-OR-expression: [C99 6.5.14]
111/// logical-AND-expression
112/// logical-OR-expression '||' logical-AND-expression
113///
114/// conditional-expression: [C99 6.5.15]
115/// logical-OR-expression
116/// logical-OR-expression '?' expression ':' conditional-expression
117/// [GNU] logical-OR-expression '?' ':' conditional-expression
118/// [C++] the third operand is an assignment-expression
119///
120/// assignment-expression: [C99 6.5.16]
121/// conditional-expression
122/// unary-expression assignment-operator assignment-expression
123/// [C++] throw-expression [C++ 15]
124///
125/// assignment-operator: one of
126/// = *= /= %= += -= <<= >>= &= ^= |=
127///
128/// expression: [C99 6.5.17]
129/// assignment-expression ...[opt]
130/// expression ',' assignment-expression ...[opt]
131/// \endverbatim
133 ExprResult LHS(ParseAssignmentExpression(isTypeCast));
134 return ParseRHSOfBinaryExpression(LHS, prec::Comma);
135}
136
137/// This routine is called when the '@' is seen and consumed.
138/// Current token is an Identifier and is not a 'try'. This
139/// routine is necessary to disambiguate \@try-statement from,
140/// for example, \@encode-expression.
141///
143Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
144 ExprResult LHS(ParseObjCAtExpression(AtLoc));
145 return ParseRHSOfBinaryExpression(LHS, prec::Comma);
146}
147
148/// This routine is called when a leading '__extension__' is seen and
149/// consumed. This is necessary because the token gets consumed in the
150/// process of disambiguating between an expression and a declaration.
152Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) {
153 ExprResult LHS(true);
154 {
155 // Silence extension warnings in the sub-expression
156 ExtensionRAIIObject O(Diags);
157
158 LHS = ParseCastExpression(AnyCastExpr);
159 }
160
161 if (!LHS.isInvalid())
162 LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__,
163 LHS.get());
164
165 return ParseRHSOfBinaryExpression(LHS, prec::Comma);
166}
167
168/// Parse an expr that doesn't include (top-level) commas.
170 if (Tok.is(tok::code_completion)) {
171 cutOffParsing();
173 getCurScope(), PreferredType.get(Tok.getLocation()));
174 return ExprError();
175 }
176
177 if (Tok.is(tok::kw_throw))
178 return ParseThrowExpression();
179 if (Tok.is(tok::kw_co_yield))
180 return ParseCoyieldExpression();
181
182 ExprResult LHS = ParseCastExpression(AnyCastExpr,
183 /*isAddressOfOperand=*/false,
184 isTypeCast);
185 return ParseRHSOfBinaryExpression(LHS, prec::Assignment);
186}
187
189 if (Tok.is(tok::code_completion)) {
190 cutOffParsing();
192 getCurScope(), PreferredType.get(Tok.getLocation()));
193 return ExprError();
194 }
195
196 ExprResult LHS = ParseCastExpression(
197 AnyCastExpr, /*isAddressOfOperand=*/false, NotTypeCast);
198 return ParseRHSOfBinaryExpression(LHS, prec::Conditional);
199}
200
201/// Parse an assignment expression where part of an Objective-C message
202/// send has already been parsed.
203///
204/// In this case \p LBracLoc indicates the location of the '[' of the message
205/// send, and either \p ReceiverName or \p ReceiverExpr is non-null indicating
206/// the receiver of the message.
207///
208/// Since this handles full assignment-expression's, it handles postfix
209/// expressions and other binary operators for these expressions as well.
211Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc,
212 SourceLocation SuperLoc,
213 ParsedType ReceiverType,
214 Expr *ReceiverExpr) {
215 ExprResult R
216 = ParseObjCMessageExpressionBody(LBracLoc, SuperLoc,
217 ReceiverType, ReceiverExpr);
218 R = ParsePostfixExpressionSuffix(R);
219 return ParseRHSOfBinaryExpression(R, prec::Assignment);
220}
221
224 assert(Actions.ExprEvalContexts.back().Context ==
226 "Call this function only if your ExpressionEvaluationContext is "
227 "already ConstantEvaluated");
228 ExprResult LHS(ParseCastExpression(AnyCastExpr, false, isTypeCast));
229 ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
230 return Actions.ActOnConstantExpression(Res);
231}
232
234 // C++03 [basic.def.odr]p2:
235 // An expression is potentially evaluated unless it appears where an
236 // integral constant expression is required (see 5.19) [...].
237 // C++98 and C++11 have no such rule, but this is only a defect in C++98.
238 EnterExpressionEvaluationContext ConstantEvaluated(
241}
242
244 EnterExpressionEvaluationContext ConstantEvaluated(
246 // If we parse the bound of a VLA... we parse a non-constant
247 // constant-expression!
248 Actions.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
250}
251
253 EnterExpressionEvaluationContext ConstantEvaluated(
255 ExprResult LHS(ParseCastExpression(AnyCastExpr, false, NotTypeCast));
256 ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
257 return Actions.ActOnCaseExpr(CaseLoc, Res);
258}
259
260/// Parse a constraint-expression.
261///
262/// \verbatim
263/// constraint-expression: C++2a[temp.constr.decl]p1
264/// logical-or-expression
265/// \endverbatim
267 EnterExpressionEvaluationContext ConstantEvaluated(
269 ExprResult LHS(ParseCastExpression(AnyCastExpr));
270 ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::LogicalOr));
271 if (Res.isUsable() && !Actions.CheckConstraintExpression(Res.get())) {
272 Actions.CorrectDelayedTyposInExpr(Res);
273 return ExprError();
274 }
275 return Res;
276}
277
278/// \brief Parse a constraint-logical-and-expression.
279///
280/// \verbatim
281/// C++2a[temp.constr.decl]p1
282/// constraint-logical-and-expression:
283/// primary-expression
284/// constraint-logical-and-expression '&&' primary-expression
285///
286/// \endverbatim
288Parser::ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause) {
289 EnterExpressionEvaluationContext ConstantEvaluated(
291 bool NotPrimaryExpression = false;
292 auto ParsePrimary = [&] () {
293 ExprResult E = ParseCastExpression(PrimaryExprOnly,
294 /*isAddressOfOperand=*/false,
295 /*isTypeCast=*/NotTypeCast,
296 /*isVectorLiteral=*/false,
297 &NotPrimaryExpression);
298 if (E.isInvalid())
299 return ExprError();
300 auto RecoverFromNonPrimary = [&] (ExprResult E, bool Note) {
301 E = ParsePostfixExpressionSuffix(E);
302 // Use InclusiveOr, the precedence just after '&&' to not parse the
303 // next arguments to the logical and.
304 E = ParseRHSOfBinaryExpression(E, prec::InclusiveOr);
305 if (!E.isInvalid())
306 Diag(E.get()->getExprLoc(),
307 Note
308 ? diag::note_unparenthesized_non_primary_expr_in_requires_clause
309 : diag::err_unparenthesized_non_primary_expr_in_requires_clause)
312 PP.getLocForEndOfToken(E.get()->getEndLoc()), ")")
313 << E.get()->getSourceRange();
314 return E;
315 };
316
317 if (NotPrimaryExpression ||
318 // Check if the following tokens must be a part of a non-primary
319 // expression
320 getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
321 /*CPlusPlus11=*/true) > prec::LogicalAnd ||
322 // Postfix operators other than '(' (which will be checked for in
323 // CheckConstraintExpression).
324 Tok.isOneOf(tok::period, tok::plusplus, tok::minusminus) ||
325 (Tok.is(tok::l_square) && !NextToken().is(tok::l_square))) {
326 E = RecoverFromNonPrimary(E, /*Note=*/false);
327 if (E.isInvalid())
328 return ExprError();
329 NotPrimaryExpression = false;
330 }
331 bool PossibleNonPrimary;
332 bool IsConstraintExpr =
333 Actions.CheckConstraintExpression(E.get(), Tok, &PossibleNonPrimary,
334 IsTrailingRequiresClause);
335 if (!IsConstraintExpr || PossibleNonPrimary) {
336 // Atomic constraint might be an unparenthesized non-primary expression
337 // (such as a binary operator), in which case we might get here (e.g. in
338 // 'requires 0 + 1 && true' we would now be at '+', and parse and ignore
339 // the rest of the addition expression). Try to parse the rest of it here.
340 if (PossibleNonPrimary)
341 E = RecoverFromNonPrimary(E, /*Note=*/!IsConstraintExpr);
343 return ExprError();
344 }
345 return E;
346 };
347 ExprResult LHS = ParsePrimary();
348 if (LHS.isInvalid())
349 return ExprError();
350 while (Tok.is(tok::ampamp)) {
351 SourceLocation LogicalAndLoc = ConsumeToken();
352 ExprResult RHS = ParsePrimary();
353 if (RHS.isInvalid()) {
354 Actions.CorrectDelayedTyposInExpr(LHS);
355 return ExprError();
356 }
357 ExprResult Op = Actions.ActOnBinOp(getCurScope(), LogicalAndLoc,
358 tok::ampamp, LHS.get(), RHS.get());
359 if (!Op.isUsable()) {
360 Actions.CorrectDelayedTyposInExpr(RHS);
361 Actions.CorrectDelayedTyposInExpr(LHS);
362 return ExprError();
363 }
364 LHS = Op;
365 }
366 return LHS;
367}
368
369/// \brief Parse a constraint-logical-or-expression.
370///
371/// \verbatim
372/// C++2a[temp.constr.decl]p1
373/// constraint-logical-or-expression:
374/// constraint-logical-and-expression
375/// constraint-logical-or-expression '||'
376/// constraint-logical-and-expression
377///
378/// \endverbatim
380Parser::ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause) {
381 ExprResult LHS(ParseConstraintLogicalAndExpression(IsTrailingRequiresClause));
382 if (!LHS.isUsable())
383 return ExprError();
384 while (Tok.is(tok::pipepipe)) {
385 SourceLocation LogicalOrLoc = ConsumeToken();
386 ExprResult RHS =
387 ParseConstraintLogicalAndExpression(IsTrailingRequiresClause);
388 if (!RHS.isUsable()) {
389 Actions.CorrectDelayedTyposInExpr(LHS);
390 return ExprError();
391 }
392 ExprResult Op = Actions.ActOnBinOp(getCurScope(), LogicalOrLoc,
393 tok::pipepipe, LHS.get(), RHS.get());
394 if (!Op.isUsable()) {
395 Actions.CorrectDelayedTyposInExpr(RHS);
396 Actions.CorrectDelayedTyposInExpr(LHS);
397 return ExprError();
398 }
399 LHS = Op;
400 }
401 return LHS;
402}
403
404bool Parser::isNotExpressionStart() {
405 tok::TokenKind K = Tok.getKind();
406 if (K == tok::l_brace || K == tok::r_brace ||
407 K == tok::kw_for || K == tok::kw_while ||
408 K == tok::kw_if || K == tok::kw_else ||
409 K == tok::kw_goto || K == tok::kw_try)
410 return true;
411 // If this is a decl-specifier, we can't be at the start of an expression.
412 return isKnownToBeDeclarationSpecifier();
413}
414
415bool Parser::isFoldOperator(prec::Level Level) const {
416 return Level > prec::Unknown && Level != prec::Conditional &&
417 Level != prec::Spaceship;
418}
419
420bool Parser::isFoldOperator(tok::TokenKind Kind) const {
421 return isFoldOperator(getBinOpPrecedence(Kind, GreaterThanIsOperator, true));
422}
423
424/// Parse a binary expression that starts with \p LHS and has a
425/// precedence of at least \p MinPrec.
427Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
428 prec::Level NextTokPrec = getBinOpPrecedence(Tok.getKind(),
429 GreaterThanIsOperator,
431 SourceLocation ColonLoc;
432
433 auto SavedType = PreferredType;
434 while (true) {
435 // Every iteration may rely on a preferred type for the whole expression.
436 PreferredType = SavedType;
437 // If this token has a lower precedence than we are allowed to parse (e.g.
438 // because we are called recursively, or because the token is not a binop),
439 // then we are done!
440 if (NextTokPrec < MinPrec)
441 return LHS;
442
443 // Consume the operator, saving the operator token for error reporting.
444 Token OpToken = Tok;
445 ConsumeToken();
446
447 if (OpToken.is(tok::caretcaret)) {
448 return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or));
449 }
450
451 // If we're potentially in a template-id, we may now be able to determine
452 // whether we're actually in one or not.
453 if (OpToken.isOneOf(tok::comma, tok::greater, tok::greatergreater,
454 tok::greatergreatergreater) &&
455 checkPotentialAngleBracketDelimiter(OpToken))
456 return ExprError();
457
458 // Bail out when encountering a comma followed by a token which can't
459 // possibly be the start of an expression. For instance:
460 // int f() { return 1, }
461 // We can't do this before consuming the comma, because
462 // isNotExpressionStart() looks at the token stream.
463 if (OpToken.is(tok::comma) && isNotExpressionStart()) {
464 PP.EnterToken(Tok, /*IsReinject*/true);
465 Tok = OpToken;
466 return LHS;
467 }
468
469 // If the next token is an ellipsis, then this is a fold-expression. Leave
470 // it alone so we can handle it in the paren expression.
471 if (isFoldOperator(NextTokPrec) && Tok.is(tok::ellipsis)) {
472 // FIXME: We can't check this via lookahead before we consume the token
473 // because that tickles a lexer bug.
474 PP.EnterToken(Tok, /*IsReinject*/true);
475 Tok = OpToken;
476 return LHS;
477 }
478
479 // In Objective-C++, alternative operator tokens can be used as keyword args
480 // in message expressions. Unconsume the token so that it can reinterpreted
481 // as an identifier in ParseObjCMessageExpressionBody. i.e., we support:
482 // [foo meth:0 and:0];
483 // [foo not_eq];
485 Tok.isOneOf(tok::colon, tok::r_square) &&
486 OpToken.getIdentifierInfo() != nullptr) {
487 PP.EnterToken(Tok, /*IsReinject*/true);
488 Tok = OpToken;
489 return LHS;
490 }
491
492 // Special case handling for the ternary operator.
493 ExprResult TernaryMiddle(true);
494 if (NextTokPrec == prec::Conditional) {
495 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
496 // Parse a braced-init-list here for error recovery purposes.
497 SourceLocation BraceLoc = Tok.getLocation();
498 TernaryMiddle = ParseBraceInitializer();
499 if (!TernaryMiddle.isInvalid()) {
500 Diag(BraceLoc, diag::err_init_list_bin_op)
501 << /*RHS*/ 1 << PP.getSpelling(OpToken)
502 << Actions.getExprRange(TernaryMiddle.get());
503 TernaryMiddle = ExprError();
504 }
505 } else if (Tok.isNot(tok::colon)) {
506 // Don't parse FOO:BAR as if it were a typo for FOO::BAR.
508
509 // Handle this production specially:
510 // logical-OR-expression '?' expression ':' conditional-expression
511 // In particular, the RHS of the '?' is 'expression', not
512 // 'logical-OR-expression' as we might expect.
513 TernaryMiddle = ParseExpression();
514 } else {
515 // Special case handling of "X ? Y : Z" where Y is empty:
516 // logical-OR-expression '?' ':' conditional-expression [GNU]
517 TernaryMiddle = nullptr;
518 Diag(Tok, diag::ext_gnu_conditional_expr);
519 }
520
521 if (TernaryMiddle.isInvalid()) {
522 Actions.CorrectDelayedTyposInExpr(LHS);
523 LHS = ExprError();
524 TernaryMiddle = nullptr;
525 }
526
527 if (!TryConsumeToken(tok::colon, ColonLoc)) {
528 // Otherwise, we're missing a ':'. Assume that this was a typo that
529 // the user forgot. If we're not in a macro expansion, we can suggest
530 // a fixit hint. If there were two spaces before the current token,
531 // suggest inserting the colon in between them, otherwise insert ": ".
532 SourceLocation FILoc = Tok.getLocation();
533 const char *FIText = ": ";
534 const SourceManager &SM = PP.getSourceManager();
535 if (FILoc.isFileID() || PP.isAtStartOfMacroExpansion(FILoc, &FILoc)) {
536 assert(FILoc.isFileID());
537 bool IsInvalid = false;
538 const char *SourcePtr =
539 SM.getCharacterData(FILoc.getLocWithOffset(-1), &IsInvalid);
540 if (!IsInvalid && *SourcePtr == ' ') {
541 SourcePtr =
542 SM.getCharacterData(FILoc.getLocWithOffset(-2), &IsInvalid);
543 if (!IsInvalid && *SourcePtr == ' ') {
544 FILoc = FILoc.getLocWithOffset(-1);
545 FIText = ":";
546 }
547 }
548 }
549
550 Diag(Tok, diag::err_expected)
551 << tok::colon << FixItHint::CreateInsertion(FILoc, FIText);
552 Diag(OpToken, diag::note_matching) << tok::question;
553 ColonLoc = Tok.getLocation();
554 }
555 }
556
557 PreferredType.enterBinary(Actions, Tok.getLocation(), LHS.get(),
558 OpToken.getKind());
559 // Parse another leaf here for the RHS of the operator.
560 // ParseCastExpression works here because all RHS expressions in C have it
561 // as a prefix, at least. However, in C++, an assignment-expression could
562 // be a throw-expression, which is not a valid cast-expression.
563 // Therefore we need some special-casing here.
564 // Also note that the third operand of the conditional operator is
565 // an assignment-expression in C++, and in C++11, we can have a
566 // braced-init-list on the RHS of an assignment. For better diagnostics,
567 // parse as if we were allowed braced-init-lists everywhere, and check that
568 // they only appear on the RHS of assignments later.
569 ExprResult RHS;
570 bool RHSIsInitList = false;
571 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
572 RHS = ParseBraceInitializer();
573 RHSIsInitList = true;
574 } else if (getLangOpts().CPlusPlus && NextTokPrec <= prec::Conditional)
576 else
577 RHS = ParseCastExpression(AnyCastExpr);
578
579 if (RHS.isInvalid()) {
580 // FIXME: Errors generated by the delayed typo correction should be
581 // printed before errors from parsing the RHS, not after.
582 Actions.CorrectDelayedTyposInExpr(LHS);
583 if (TernaryMiddle.isUsable())
584 TernaryMiddle = Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
585 LHS = ExprError();
586 }
587
588 // Remember the precedence of this operator and get the precedence of the
589 // operator immediately to the right of the RHS.
590 prec::Level ThisPrec = NextTokPrec;
591 NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
593
594 // Assignment and conditional expressions are right-associative.
595 bool isRightAssoc = ThisPrec == prec::Conditional ||
596 ThisPrec == prec::Assignment;
597
598 // Get the precedence of the operator to the right of the RHS. If it binds
599 // more tightly with RHS than we do, evaluate it completely first.
600 if (ThisPrec < NextTokPrec ||
601 (ThisPrec == NextTokPrec && isRightAssoc)) {
602 if (!RHS.isInvalid() && RHSIsInitList) {
603 Diag(Tok, diag::err_init_list_bin_op)
604 << /*LHS*/0 << PP.getSpelling(Tok) << Actions.getExprRange(RHS.get());
605 RHS = ExprError();
606 }
607 // If this is left-associative, only parse things on the RHS that bind
608 // more tightly than the current operator. If it is left-associative, it
609 // is okay, to bind exactly as tightly. For example, compile A=B=C=D as
610 // A=(B=(C=D)), where each paren is a level of recursion here.
611 // The function takes ownership of the RHS.
612 RHS = ParseRHSOfBinaryExpression(RHS,
613 static_cast<prec::Level>(ThisPrec + !isRightAssoc));
614 RHSIsInitList = false;
615
616 if (RHS.isInvalid()) {
617 // FIXME: Errors generated by the delayed typo correction should be
618 // printed before errors from ParseRHSOfBinaryExpression, not after.
619 Actions.CorrectDelayedTyposInExpr(LHS);
620 if (TernaryMiddle.isUsable())
621 TernaryMiddle = Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
622 LHS = ExprError();
623 }
624
625 NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
627 }
628
629 if (!RHS.isInvalid() && RHSIsInitList) {
630 if (ThisPrec == prec::Assignment) {
631 Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists)
632 << Actions.getExprRange(RHS.get());
633 } else if (ColonLoc.isValid()) {
634 Diag(ColonLoc, diag::err_init_list_bin_op)
635 << /*RHS*/1 << ":"
636 << Actions.getExprRange(RHS.get());
637 LHS = ExprError();
638 } else {
639 Diag(OpToken, diag::err_init_list_bin_op)
640 << /*RHS*/1 << PP.getSpelling(OpToken)
641 << Actions.getExprRange(RHS.get());
642 LHS = ExprError();
643 }
644 }
645
646 ExprResult OrigLHS = LHS;
647 if (!LHS.isInvalid()) {
648 // Combine the LHS and RHS into the LHS (e.g. build AST).
649 if (TernaryMiddle.isInvalid()) {
650 // If we're using '>>' as an operator within a template
651 // argument list (in C++98), suggest the addition of
652 // parentheses so that the code remains well-formed in C++0x.
653 if (!GreaterThanIsOperator && OpToken.is(tok::greatergreater))
654 SuggestParentheses(OpToken.getLocation(),
655 diag::warn_cxx11_right_shift_in_template_arg,
656 SourceRange(Actions.getExprRange(LHS.get()).getBegin(),
657 Actions.getExprRange(RHS.get()).getEnd()));
658
659 ExprResult BinOp =
660 Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(),
661 OpToken.getKind(), LHS.get(), RHS.get());
662 if (BinOp.isInvalid())
663 BinOp = Actions.CreateRecoveryExpr(LHS.get()->getBeginLoc(),
664 RHS.get()->getEndLoc(),
665 {LHS.get(), RHS.get()});
666
667 LHS = BinOp;
668 } else {
669 ExprResult CondOp = Actions.ActOnConditionalOp(
670 OpToken.getLocation(), ColonLoc, LHS.get(), TernaryMiddle.get(),
671 RHS.get());
672 if (CondOp.isInvalid()) {
673 std::vector<clang::Expr *> Args;
674 // TernaryMiddle can be null for the GNU conditional expr extension.
675 if (TernaryMiddle.get())
676 Args = {LHS.get(), TernaryMiddle.get(), RHS.get()};
677 else
678 Args = {LHS.get(), RHS.get()};
679 CondOp = Actions.CreateRecoveryExpr(LHS.get()->getBeginLoc(),
680 RHS.get()->getEndLoc(), Args);
681 }
682
683 LHS = CondOp;
684 }
685 // In this case, ActOnBinOp or ActOnConditionalOp performed the
686 // CorrectDelayedTyposInExpr check.
687 if (!getLangOpts().CPlusPlus)
688 continue;
689 }
690
691 // Ensure potential typos aren't left undiagnosed.
692 if (LHS.isInvalid()) {
693 Actions.CorrectDelayedTyposInExpr(OrigLHS);
694 Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
695 Actions.CorrectDelayedTyposInExpr(RHS);
696 }
697 }
698}
699
700/// Parse a cast-expression, unary-expression or primary-expression, based
701/// on \p ExprType.
702///
703/// \p isAddressOfOperand exists because an id-expression that is the
704/// operand of address-of gets special treatment due to member pointers.
705///
706ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
707 bool isAddressOfOperand,
708 TypeCastState isTypeCast,
709 bool isVectorLiteral,
710 bool *NotPrimaryExpression) {
711 bool NotCastExpr;
712 ExprResult Res = ParseCastExpression(ParseKind,
713 isAddressOfOperand,
714 NotCastExpr,
715 isTypeCast,
716 isVectorLiteral,
717 NotPrimaryExpression);
718 if (NotCastExpr)
719 Diag(Tok, diag::err_expected_expression);
720 return Res;
721}
722
723namespace {
724class CastExpressionIdValidator final : public CorrectionCandidateCallback {
725 public:
726 CastExpressionIdValidator(Token Next, bool AllowTypes, bool AllowNonTypes)
727 : NextToken(Next), AllowNonTypes(AllowNonTypes) {
728 WantTypeSpecifiers = WantFunctionLikeCasts = AllowTypes;
729 }
730
731 bool ValidateCandidate(const TypoCorrection &candidate) override {
732 NamedDecl *ND = candidate.getCorrectionDecl();
733 if (!ND)
734 return candidate.isKeyword();
735
736 if (isa<TypeDecl>(ND))
737 return WantTypeSpecifiers;
738
739 if (!AllowNonTypes || !CorrectionCandidateCallback::ValidateCandidate(candidate))
740 return false;
741
742 if (!NextToken.isOneOf(tok::equal, tok::arrow, tok::period))
743 return true;
744
745 for (auto *C : candidate) {
746 NamedDecl *ND = C->getUnderlyingDecl();
747 if (isa<ValueDecl>(ND) && !isa<FunctionDecl>(ND))
748 return true;
749 }
750 return false;
751 }
752
753 std::unique_ptr<CorrectionCandidateCallback> clone() override {
754 return std::make_unique<CastExpressionIdValidator>(*this);
755 }
756
757 private:
758 Token NextToken;
759 bool AllowNonTypes;
760};
761}
762
763bool Parser::isRevertibleTypeTrait(const IdentifierInfo *II,
764 tok::TokenKind *Kind) {
765 if (RevertibleTypeTraits.empty()) {
766#define RTT_JOIN(X, Y) X##Y
767#define REVERTIBLE_TYPE_TRAIT(Name) \
768 RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] = RTT_JOIN(tok::kw_, Name)
769
770 REVERTIBLE_TYPE_TRAIT(__is_abstract);
771 REVERTIBLE_TYPE_TRAIT(__is_aggregate);
772 REVERTIBLE_TYPE_TRAIT(__is_arithmetic);
773 REVERTIBLE_TYPE_TRAIT(__is_array);
774 REVERTIBLE_TYPE_TRAIT(__is_assignable);
775 REVERTIBLE_TYPE_TRAIT(__is_base_of);
776 REVERTIBLE_TYPE_TRAIT(__is_bounded_array);
777 REVERTIBLE_TYPE_TRAIT(__is_class);
778 REVERTIBLE_TYPE_TRAIT(__is_complete_type);
779 REVERTIBLE_TYPE_TRAIT(__is_compound);
780 REVERTIBLE_TYPE_TRAIT(__is_const);
781 REVERTIBLE_TYPE_TRAIT(__is_constructible);
782 REVERTIBLE_TYPE_TRAIT(__is_convertible);
783 REVERTIBLE_TYPE_TRAIT(__is_convertible_to);
784 REVERTIBLE_TYPE_TRAIT(__is_destructible);
785 REVERTIBLE_TYPE_TRAIT(__is_empty);
786 REVERTIBLE_TYPE_TRAIT(__is_enum);
787 REVERTIBLE_TYPE_TRAIT(__is_floating_point);
788 REVERTIBLE_TYPE_TRAIT(__is_final);
789 REVERTIBLE_TYPE_TRAIT(__is_function);
790 REVERTIBLE_TYPE_TRAIT(__is_fundamental);
791 REVERTIBLE_TYPE_TRAIT(__is_integral);
792 REVERTIBLE_TYPE_TRAIT(__is_interface_class);
793 REVERTIBLE_TYPE_TRAIT(__is_layout_compatible);
794 REVERTIBLE_TYPE_TRAIT(__is_literal);
795 REVERTIBLE_TYPE_TRAIT(__is_lvalue_expr);
796 REVERTIBLE_TYPE_TRAIT(__is_lvalue_reference);
797 REVERTIBLE_TYPE_TRAIT(__is_member_function_pointer);
798 REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer);
799 REVERTIBLE_TYPE_TRAIT(__is_member_pointer);
800 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
801 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
802 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
803 REVERTIBLE_TYPE_TRAIT(__is_nullptr);
804 REVERTIBLE_TYPE_TRAIT(__is_object);
805 REVERTIBLE_TYPE_TRAIT(__is_pod);
806 REVERTIBLE_TYPE_TRAIT(__is_pointer);
807 REVERTIBLE_TYPE_TRAIT(__is_polymorphic);
808 REVERTIBLE_TYPE_TRAIT(__is_reference);
809 REVERTIBLE_TYPE_TRAIT(__is_referenceable);
810 REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr);
811 REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference);
812 REVERTIBLE_TYPE_TRAIT(__is_same);
813 REVERTIBLE_TYPE_TRAIT(__is_scalar);
814 REVERTIBLE_TYPE_TRAIT(__is_scoped_enum);
815 REVERTIBLE_TYPE_TRAIT(__is_sealed);
816 REVERTIBLE_TYPE_TRAIT(__is_signed);
817 REVERTIBLE_TYPE_TRAIT(__is_standard_layout);
818 REVERTIBLE_TYPE_TRAIT(__is_trivial);
819 REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable);
820 REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible);
821 REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable);
822 REVERTIBLE_TYPE_TRAIT(__is_unbounded_array);
823 REVERTIBLE_TYPE_TRAIT(__is_union);
824 REVERTIBLE_TYPE_TRAIT(__is_unsigned);
825 REVERTIBLE_TYPE_TRAIT(__is_void);
826 REVERTIBLE_TYPE_TRAIT(__is_volatile);
827 REVERTIBLE_TYPE_TRAIT(__reference_binds_to_temporary);
828#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
829 REVERTIBLE_TYPE_TRAIT(RTT_JOIN(__, Trait));
830#include "clang/Basic/TransformTypeTraits.def"
831#undef REVERTIBLE_TYPE_TRAIT
832#undef RTT_JOIN
833 }
834 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known =
835 RevertibleTypeTraits.find(II);
836 if (Known != RevertibleTypeTraits.end()) {
837 if (Kind)
838 *Kind = Known->second;
839 return true;
840 }
841 return false;
842}
843
844ExprResult Parser::ParseBuiltinPtrauthTypeDiscriminator() {
846
847 BalancedDelimiterTracker T(*this, tok::l_paren);
848 if (T.expectAndConsume())
849 return ExprError();
850
852 if (Ty.isInvalid()) {
853 SkipUntil(tok::r_paren, StopAtSemi);
854 return ExprError();
855 }
856
857 SourceLocation EndLoc = Tok.getLocation();
858 T.consumeClose();
859 return Actions.ActOnUnaryExprOrTypeTraitExpr(
860 Loc, UETT_PtrAuthTypeDiscriminator,
861 /*isType=*/true, Ty.get().getAsOpaquePtr(), SourceRange(Loc, EndLoc));
862}
863
864/// Parse a cast-expression, or, if \pisUnaryExpression is true, parse
865/// a unary-expression.
866///
867/// \p isAddressOfOperand exists because an id-expression that is the operand
868/// of address-of gets special treatment due to member pointers. NotCastExpr
869/// is set to true if the token is not the start of a cast-expression, and no
870/// diagnostic is emitted in this case and no tokens are consumed.
871///
872/// \verbatim
873/// cast-expression: [C99 6.5.4]
874/// unary-expression
875/// '(' type-name ')' cast-expression
876///
877/// unary-expression: [C99 6.5.3]
878/// postfix-expression
879/// '++' unary-expression
880/// '--' unary-expression
881/// [Coro] 'co_await' cast-expression
882/// unary-operator cast-expression
883/// 'sizeof' unary-expression
884/// 'sizeof' '(' type-name ')'
885/// [C++11] 'sizeof' '...' '(' identifier ')'
886/// [GNU] '__alignof' unary-expression
887/// [GNU] '__alignof' '(' type-name ')'
888/// [C11] '_Alignof' '(' type-name ')'
889/// [C++11] 'alignof' '(' type-id ')'
890/// [GNU] '&&' identifier
891/// [C++11] 'noexcept' '(' expression ')' [C++11 5.3.7]
892/// [C++] new-expression
893/// [C++] delete-expression
894///
895/// unary-operator: one of
896/// '&' '*' '+' '-' '~' '!'
897/// [GNU] '__extension__' '__real' '__imag'
898///
899/// primary-expression: [C99 6.5.1]
900/// [C99] identifier
901/// [C++] id-expression
902/// constant
903/// string-literal
904/// [C++] boolean-literal [C++ 2.13.5]
905/// [C++11] 'nullptr' [C++11 2.14.7]
906/// [C++11] user-defined-literal
907/// '(' expression ')'
908/// [C11] generic-selection
909/// [C++2a] requires-expression
910/// '__func__' [C99 6.4.2.2]
911/// [GNU] '__FUNCTION__'
912/// [MS] '__FUNCDNAME__'
913/// [MS] 'L__FUNCTION__'
914/// [MS] '__FUNCSIG__'
915/// [MS] 'L__FUNCSIG__'
916/// [GNU] '__PRETTY_FUNCTION__'
917/// [GNU] '(' compound-statement ')'
918/// [GNU] '__builtin_va_arg' '(' assignment-expression ',' type-name ')'
919/// [GNU] '__builtin_offsetof' '(' type-name ',' offsetof-member-designator')'
920/// [GNU] '__builtin_choose_expr' '(' assign-expr ',' assign-expr ','
921/// assign-expr ')'
922/// [GNU] '__builtin_FILE' '(' ')'
923/// [CLANG] '__builtin_FILE_NAME' '(' ')'
924/// [GNU] '__builtin_FUNCTION' '(' ')'
925/// [MS] '__builtin_FUNCSIG' '(' ')'
926/// [GNU] '__builtin_LINE' '(' ')'
927/// [CLANG] '__builtin_COLUMN' '(' ')'
928/// [GNU] '__builtin_source_location' '(' ')'
929/// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')'
930/// [GNU] '__null'
931/// [OBJC] '[' objc-message-expr ']'
932/// [OBJC] '\@selector' '(' objc-selector-arg ')'
933/// [OBJC] '\@protocol' '(' identifier ')'
934/// [OBJC] '\@encode' '(' type-name ')'
935/// [OBJC] objc-string-literal
936/// [C++] simple-type-specifier '(' expression-list[opt] ')' [C++ 5.2.3]
937/// [C++11] simple-type-specifier braced-init-list [C++11 5.2.3]
938/// [C++] typename-specifier '(' expression-list[opt] ')' [C++ 5.2.3]
939/// [C++11] typename-specifier braced-init-list [C++11 5.2.3]
940/// [C++] 'const_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
941/// [C++] 'dynamic_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
942/// [C++] 'reinterpret_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
943/// [C++] 'static_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
944/// [C++] 'typeid' '(' expression ')' [C++ 5.2p1]
945/// [C++] 'typeid' '(' type-id ')' [C++ 5.2p1]
946/// [C++] 'this' [C++ 9.3.2]
947/// [G++] unary-type-trait '(' type-id ')'
948/// [G++] binary-type-trait '(' type-id ',' type-id ')' [TODO]
949/// [EMBT] array-type-trait '(' type-id ',' integer ')'
950/// [clang] '^' block-literal
951///
952/// constant: [C99 6.4.4]
953/// integer-constant
954/// floating-constant
955/// enumeration-constant -> identifier
956/// character-constant
957///
958/// id-expression: [C++ 5.1]
959/// unqualified-id
960/// qualified-id
961///
962/// unqualified-id: [C++ 5.1]
963/// identifier
964/// operator-function-id
965/// conversion-function-id
966/// '~' class-name
967/// template-id
968///
969/// new-expression: [C++ 5.3.4]
970/// '::'[opt] 'new' new-placement[opt] new-type-id
971/// new-initializer[opt]
972/// '::'[opt] 'new' new-placement[opt] '(' type-id ')'
973/// new-initializer[opt]
974///
975/// delete-expression: [C++ 5.3.5]
976/// '::'[opt] 'delete' cast-expression
977/// '::'[opt] 'delete' '[' ']' cast-expression
978///
979/// [GNU/Embarcadero] unary-type-trait:
980/// '__is_arithmetic'
981/// '__is_floating_point'
982/// '__is_integral'
983/// '__is_lvalue_expr'
984/// '__is_rvalue_expr'
985/// '__is_complete_type'
986/// '__is_void'
987/// '__is_array'
988/// '__is_function'
989/// '__is_reference'
990/// '__is_lvalue_reference'
991/// '__is_rvalue_reference'
992/// '__is_fundamental'
993/// '__is_object'
994/// '__is_scalar'
995/// '__is_compound'
996/// '__is_pointer'
997/// '__is_member_object_pointer'
998/// '__is_member_function_pointer'
999/// '__is_member_pointer'
1000/// '__is_const'
1001/// '__is_volatile'
1002/// '__is_trivial'
1003/// '__is_standard_layout'
1004/// '__is_signed'
1005/// '__is_unsigned'
1006///
1007/// [GNU] unary-type-trait:
1008/// '__has_nothrow_assign'
1009/// '__has_nothrow_copy'
1010/// '__has_nothrow_constructor'
1011/// '__has_trivial_assign' [TODO]
1012/// '__has_trivial_copy' [TODO]
1013/// '__has_trivial_constructor'
1014/// '__has_trivial_destructor'
1015/// '__has_virtual_destructor'
1016/// '__is_abstract' [TODO]
1017/// '__is_class'
1018/// '__is_empty' [TODO]
1019/// '__is_enum'
1020/// '__is_final'
1021/// '__is_pod'
1022/// '__is_polymorphic'
1023/// '__is_sealed' [MS]
1024/// '__is_trivial'
1025/// '__is_union'
1026/// '__has_unique_object_representations'
1027///
1028/// [Clang] unary-type-trait:
1029/// '__is_aggregate'
1030/// '__trivially_copyable'
1031///
1032/// binary-type-trait:
1033/// [GNU] '__is_base_of'
1034/// [MS] '__is_convertible_to'
1035/// '__is_convertible'
1036/// '__is_same'
1037///
1038/// [Embarcadero] array-type-trait:
1039/// '__array_rank'
1040/// '__array_extent'
1041///
1042/// [Embarcadero] expression-trait:
1043/// '__is_lvalue_expr'
1044/// '__is_rvalue_expr'
1045/// \endverbatim
1046///
1047ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
1048 bool isAddressOfOperand,
1049 bool &NotCastExpr,
1050 TypeCastState isTypeCast,
1051 bool isVectorLiteral,
1052 bool *NotPrimaryExpression) {
1053 ExprResult Res;
1054 tok::TokenKind SavedKind = Tok.getKind();
1055 auto SavedType = PreferredType;
1056 NotCastExpr = false;
1057
1058 // Are postfix-expression suffix operators permitted after this
1059 // cast-expression? If not, and we find some, we'll parse them anyway and
1060 // diagnose them.
1061 bool AllowSuffix = true;
1062
1063 // This handles all of cast-expression, unary-expression, postfix-expression,
1064 // and primary-expression. We handle them together like this for efficiency
1065 // and to simplify handling of an expression starting with a '(' token: which
1066 // may be one of a parenthesized expression, cast-expression, compound literal
1067 // expression, or statement expression.
1068 //
1069 // If the parsed tokens consist of a primary-expression, the cases below
1070 // break out of the switch; at the end we call ParsePostfixExpressionSuffix
1071 // to handle the postfix expression suffixes. Cases that cannot be followed
1072 // by postfix exprs should set AllowSuffix to false.
1073 switch (SavedKind) {
1074 case tok::l_paren: {
1075 // If this expression is limited to being a unary-expression, the paren can
1076 // not start a cast expression.
1077 ParenParseOption ParenExprType;
1078 switch (ParseKind) {
1079 case CastParseKind::UnaryExprOnly:
1080 assert(getLangOpts().CPlusPlus && "not possible to get here in C");
1081 [[fallthrough]];
1082 case CastParseKind::AnyCastExpr:
1083 ParenExprType = ParenParseOption::CastExpr;
1084 break;
1085 case CastParseKind::PrimaryExprOnly:
1086 ParenExprType = FoldExpr;
1087 break;
1088 }
1089 ParsedType CastTy;
1090 SourceLocation RParenLoc;
1091 Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
1092 isTypeCast == IsTypeCast, CastTy, RParenLoc);
1093
1094 // FIXME: What should we do if a vector literal is followed by a
1095 // postfix-expression suffix? Usually postfix operators are permitted on
1096 // literals.
1097 if (isVectorLiteral)
1098 return Res;
1099
1100 switch (ParenExprType) {
1101 case SimpleExpr: break; // Nothing else to do.
1102 case CompoundStmt: break; // Nothing else to do.
1103 case CompoundLiteral:
1104 // We parsed '(' type-name ')' '{' ... '}'. If any suffixes of
1105 // postfix-expression exist, parse them now.
1106 break;
1107 case CastExpr:
1108 // We have parsed the cast-expression and no postfix-expr pieces are
1109 // following.
1110 return Res;
1111 case FoldExpr:
1112 // We only parsed a fold-expression. There might be postfix-expr pieces
1113 // afterwards; parse them now.
1114 break;
1115 }
1116
1117 break;
1118 }
1119
1120 // primary-expression
1121 case tok::numeric_constant:
1122 case tok::binary_data:
1123 // constant: integer-constant
1124 // constant: floating-constant
1125
1126 Res = Actions.ActOnNumericConstant(Tok, /*UDLScope*/getCurScope());
1127 ConsumeToken();
1128 break;
1129
1130 case tok::kw_true:
1131 case tok::kw_false:
1132 Res = ParseCXXBoolLiteral();
1133 break;
1134
1135 case tok::kw___objc_yes:
1136 case tok::kw___objc_no:
1137 Res = ParseObjCBoolLiteral();
1138 break;
1139
1140 case tok::kw_nullptr:
1141 if (getLangOpts().CPlusPlus)
1142 Diag(Tok, diag::warn_cxx98_compat_nullptr);
1143 else
1144 Diag(Tok, getLangOpts().C23 ? diag::warn_c23_compat_keyword
1145 : diag::ext_c_nullptr) << Tok.getName();
1146
1147 Res = Actions.ActOnCXXNullPtrLiteral(ConsumeToken());
1148 break;
1149
1150 case tok::annot_primary_expr:
1151 case tok::annot_overload_set:
1152 Res = getExprAnnotation(Tok);
1153 if (!Res.isInvalid() && Tok.getKind() == tok::annot_overload_set)
1154 Res = Actions.ActOnNameClassifiedAsOverloadSet(getCurScope(), Res.get());
1155 ConsumeAnnotationToken();
1156 if (!Res.isInvalid() && Tok.is(tok::less))
1157 checkPotentialAngleBracket(Res);
1158 break;
1159
1160 case tok::annot_non_type:
1161 case tok::annot_non_type_dependent:
1162 case tok::annot_non_type_undeclared: {
1163 CXXScopeSpec SS;
1164 Token Replacement;
1165 Res = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
1166 assert(!Res.isUnset() &&
1167 "should not perform typo correction on annotation token");
1168 break;
1169 }
1170
1171 case tok::annot_embed: {
1172 injectEmbedTokens();
1173 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1174 isVectorLiteral, NotPrimaryExpression);
1175 }
1176
1177 case tok::kw___super:
1178 case tok::kw_decltype:
1179 // Annotate the token and tail recurse.
1181 return ExprError();
1182 assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super));
1183 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1184 isVectorLiteral, NotPrimaryExpression);
1185
1186 case tok::identifier:
1187 ParseIdentifier: { // primary-expression: identifier
1188 // unqualified-id: identifier
1189 // constant: enumeration-constant
1190 // Turn a potentially qualified name into a annot_typename or
1191 // annot_cxxscope if it would be valid. This handles things like x::y, etc.
1192 if (getLangOpts().CPlusPlus) {
1193 // Avoid the unnecessary parse-time lookup in the common case
1194 // where the syntax forbids a type.
1195 Token Next = NextToken();
1196
1197 if (Next.is(tok::ellipsis) && Tok.is(tok::identifier) &&
1198 GetLookAheadToken(2).is(tok::l_square)) {
1199 // Annotate the token and tail recurse.
1200 // If the token is not annotated, then it might be an expression pack
1201 // indexing
1203 Tok.is(tok::annot_pack_indexing_type))
1204 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1205 isVectorLiteral, NotPrimaryExpression);
1206 }
1207
1208 // If this identifier was reverted from a token ID, and the next token
1209 // is a parenthesis, this is likely to be a use of a type trait. Check
1210 // those tokens.
1211 else if (Next.is(tok::l_paren) && Tok.is(tok::identifier) &&
1215 if (isRevertibleTypeTrait(II, &Kind)) {
1216 Tok.setKind(Kind);
1217 return ParseCastExpression(ParseKind, isAddressOfOperand,
1218 NotCastExpr, isTypeCast,
1219 isVectorLiteral, NotPrimaryExpression);
1220 }
1221 }
1222
1223 else if ((!ColonIsSacred && Next.is(tok::colon)) ||
1224 Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
1225 tok::l_brace)) {
1226 // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
1228 return ExprError();
1229 if (!Tok.is(tok::identifier))
1230 return ParseCastExpression(ParseKind, isAddressOfOperand,
1231 NotCastExpr, isTypeCast,
1232 isVectorLiteral,
1233 NotPrimaryExpression);
1234 }
1235 }
1236
1237 // Consume the identifier so that we can see if it is followed by a '(' or
1238 // '.'.
1239 IdentifierInfo &II = *Tok.getIdentifierInfo();
1241
1242 // Support 'Class.property' and 'super.property' notation.
1243 if (getLangOpts().ObjC && Tok.is(tok::period) &&
1244 (Actions.getTypeName(II, ILoc, getCurScope()) ||
1245 // Allow the base to be 'super' if in an objc-method.
1246 (&II == Ident_super && getCurScope()->isInObjcMethodScope()))) {
1247 ConsumeToken();
1248
1249 if (Tok.is(tok::code_completion) && &II != Ident_super) {
1250 cutOffParsing();
1252 getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc);
1253 return ExprError();
1254 }
1255 // Allow either an identifier or the keyword 'class' (in C++).
1256 if (Tok.isNot(tok::identifier) &&
1257 !(getLangOpts().CPlusPlus && Tok.is(tok::kw_class))) {
1258 Diag(Tok, diag::err_expected_property_name);
1259 return ExprError();
1260 }
1261 IdentifierInfo &PropertyName = *Tok.getIdentifierInfo();
1262 SourceLocation PropertyLoc = ConsumeToken();
1263
1264 Res = Actions.ObjC().ActOnClassPropertyRefExpr(II, PropertyName, ILoc,
1265 PropertyLoc);
1266 break;
1267 }
1268
1269 // In an Objective-C method, if we have "super" followed by an identifier,
1270 // the token sequence is ill-formed. However, if there's a ':' or ']' after
1271 // that identifier, this is probably a message send with a missing open
1272 // bracket. Treat it as such.
1273 if (getLangOpts().ObjC && &II == Ident_super && !InMessageExpression &&
1274 getCurScope()->isInObjcMethodScope() &&
1275 ((Tok.is(tok::identifier) &&
1276 (NextToken().is(tok::colon) || NextToken().is(tok::r_square))) ||
1277 Tok.is(tok::code_completion))) {
1278 Res = ParseObjCMessageExpressionBody(SourceLocation(), ILoc, nullptr,
1279 nullptr);
1280 break;
1281 }
1282
1283 // If we have an Objective-C class name followed by an identifier
1284 // and either ':' or ']', this is an Objective-C class message
1285 // send that's missing the opening '['. Recovery
1286 // appropriately. Also take this path if we're performing code
1287 // completion after an Objective-C class name.
1288 if (getLangOpts().ObjC &&
1289 ((Tok.is(tok::identifier) && !InMessageExpression) ||
1290 Tok.is(tok::code_completion))) {
1291 const Token& Next = NextToken();
1292 if (Tok.is(tok::code_completion) ||
1293 Next.is(tok::colon) || Next.is(tok::r_square))
1294 if (ParsedType Typ = Actions.getTypeName(II, ILoc, getCurScope()))
1295 if (Typ.get()->isObjCObjectOrInterfaceType()) {
1296 // Fake up a Declarator to use with ActOnTypeName.
1297 DeclSpec DS(AttrFactory);
1298 DS.SetRangeStart(ILoc);
1299 DS.SetRangeEnd(ILoc);
1300 const char *PrevSpec = nullptr;
1301 unsigned DiagID;
1302 DS.SetTypeSpecType(TST_typename, ILoc, PrevSpec, DiagID, Typ,
1303 Actions.getASTContext().getPrintingPolicy());
1304
1305 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
1307 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
1308 if (Ty.isInvalid())
1309 break;
1310
1311 Res = ParseObjCMessageExpressionBody(SourceLocation(),
1313 Ty.get(), nullptr);
1314 break;
1315 }
1316 }
1317
1318 // Make sure to pass down the right value for isAddressOfOperand.
1319 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
1320 isAddressOfOperand = false;
1321
1322 // Function designators are allowed to be undeclared (C99 6.5.1p2), so we
1323 // need to know whether or not this identifier is a function designator or
1324 // not.
1325 UnqualifiedId Name;
1326 CXXScopeSpec ScopeSpec;
1327 SourceLocation TemplateKWLoc;
1328 Token Replacement;
1329 CastExpressionIdValidator Validator(
1330 /*Next=*/Tok,
1331 /*AllowTypes=*/isTypeCast != NotTypeCast,
1332 /*AllowNonTypes=*/isTypeCast != IsTypeCast);
1333 Validator.IsAddressOfOperand = isAddressOfOperand;
1334 if (Tok.isOneOf(tok::periodstar, tok::arrowstar)) {
1335 Validator.WantExpressionKeywords = false;
1336 Validator.WantRemainingKeywords = false;
1337 } else {
1338 Validator.WantRemainingKeywords = Tok.isNot(tok::r_paren);
1339 }
1340 Name.setIdentifier(&II, ILoc);
1341 Res = Actions.ActOnIdExpression(
1342 getCurScope(), ScopeSpec, TemplateKWLoc, Name, Tok.is(tok::l_paren),
1343 isAddressOfOperand, &Validator,
1344 /*IsInlineAsmIdentifier=*/false,
1345 Tok.is(tok::r_paren) ? nullptr : &Replacement);
1346 if (!Res.isInvalid() && Res.isUnset()) {
1347 UnconsumeToken(Replacement);
1348 return ParseCastExpression(ParseKind, isAddressOfOperand,
1349 NotCastExpr, isTypeCast,
1350 /*isVectorLiteral=*/false,
1351 NotPrimaryExpression);
1352 }
1353 Res = tryParseCXXPackIndexingExpression(Res);
1354 if (!Res.isInvalid() && Tok.is(tok::less))
1355 checkPotentialAngleBracket(Res);
1356 break;
1357 }
1358 case tok::char_constant: // constant: character-constant
1359 case tok::wide_char_constant:
1360 case tok::utf8_char_constant:
1361 case tok::utf16_char_constant:
1362 case tok::utf32_char_constant:
1363 Res = Actions.ActOnCharacterConstant(Tok, /*UDLScope*/getCurScope());
1364 ConsumeToken();
1365 break;
1366 case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2]
1367 case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU]
1368 case tok::kw___FUNCDNAME__: // primary-expression: __FUNCDNAME__ [MS]
1369 case tok::kw___FUNCSIG__: // primary-expression: __FUNCSIG__ [MS]
1370 case tok::kw_L__FUNCTION__: // primary-expression: L__FUNCTION__ [MS]
1371 case tok::kw_L__FUNCSIG__: // primary-expression: L__FUNCSIG__ [MS]
1372 case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU]
1373 // Function local predefined macros are represented by PredefinedExpr except
1374 // when Microsoft extensions are enabled and one of these macros is adjacent
1375 // to a string literal or another one of these macros.
1376 if (!(getLangOpts().MicrosoftExt &&
1379 Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind);
1380 ConsumeToken();
1381 break;
1382 }
1383 [[fallthrough]]; // treat MS function local macros as concatenable strings
1384 case tok::string_literal: // primary-expression: string-literal
1385 case tok::wide_string_literal:
1386 case tok::utf8_string_literal:
1387 case tok::utf16_string_literal:
1388 case tok::utf32_string_literal:
1389 Res = ParseStringLiteralExpression(true);
1390 break;
1391 case tok::kw__Generic: // primary-expression: generic-selection [C11 6.5.1]
1392 Res = ParseGenericSelectionExpression();
1393 break;
1394 case tok::kw___builtin_available:
1395 Res = ParseAvailabilityCheckExpr(Tok.getLocation());
1396 break;
1397 case tok::kw___builtin_va_arg:
1398 case tok::kw___builtin_offsetof:
1399 case tok::kw___builtin_choose_expr:
1400 case tok::kw___builtin_astype: // primary-expression: [OCL] as_type()
1401 case tok::kw___builtin_convertvector:
1402 case tok::kw___builtin_COLUMN:
1403 case tok::kw___builtin_FILE:
1404 case tok::kw___builtin_FILE_NAME:
1405 case tok::kw___builtin_FUNCTION:
1406 case tok::kw___builtin_FUNCSIG:
1407 case tok::kw___builtin_LINE:
1408 case tok::kw___builtin_source_location:
1409 if (NotPrimaryExpression)
1410 *NotPrimaryExpression = true;
1411 // This parses the complete suffix; we can return early.
1412 return ParseBuiltinPrimaryExpression();
1413 case tok::kw___null:
1414 Res = Actions.ActOnGNUNullExpr(ConsumeToken());
1415 break;
1416
1417 case tok::plusplus: // unary-expression: '++' unary-expression [C99]
1418 case tok::minusminus: { // unary-expression: '--' unary-expression [C99]
1419 if (NotPrimaryExpression)
1420 *NotPrimaryExpression = true;
1421 // C++ [expr.unary] has:
1422 // unary-expression:
1423 // ++ cast-expression
1424 // -- cast-expression
1425 Token SavedTok = Tok;
1426 ConsumeToken();
1427
1428 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedTok.getKind(),
1429 SavedTok.getLocation());
1430 // One special case is implicitly handled here: if the preceding tokens are
1431 // an ambiguous cast expression, such as "(T())++", then we recurse to
1432 // determine whether the '++' is prefix or postfix.
1433 Res = ParseCastExpression(getLangOpts().CPlusPlus ?
1434 UnaryExprOnly : AnyCastExpr,
1435 /*isAddressOfOperand*/false, NotCastExpr,
1436 NotTypeCast);
1437 if (NotCastExpr) {
1438 // If we return with NotCastExpr = true, we must not consume any tokens,
1439 // so put the token back where we found it.
1440 assert(Res.isInvalid());
1441 UnconsumeToken(SavedTok);
1442 return ExprError();
1443 }
1444 if (!Res.isInvalid()) {
1445 Expr *Arg = Res.get();
1446 Res = Actions.ActOnUnaryOp(getCurScope(), SavedTok.getLocation(),
1447 SavedKind, Arg);
1448 if (Res.isInvalid())
1449 Res = Actions.CreateRecoveryExpr(SavedTok.getLocation(),
1450 Arg->getEndLoc(), Arg);
1451 }
1452 return Res;
1453 }
1454 case tok::amp: { // unary-expression: '&' cast-expression
1455 if (NotPrimaryExpression)
1456 *NotPrimaryExpression = true;
1457 // Special treatment because of member pointers
1458 SourceLocation SavedLoc = ConsumeToken();
1459 PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc);
1460
1461 Res = ParseCastExpression(AnyCastExpr, /*isAddressOfOperand=*/true);
1462 if (!Res.isInvalid()) {
1463 Expr *Arg = Res.get();
1464 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg);
1465 if (Res.isInvalid())
1466 Res = Actions.CreateRecoveryExpr(Tok.getLocation(), Arg->getEndLoc(),
1467 Arg);
1468 }
1469 return Res;
1470 }
1471
1472 case tok::star: // unary-expression: '*' cast-expression
1473 case tok::plus: // unary-expression: '+' cast-expression
1474 case tok::minus: // unary-expression: '-' cast-expression
1475 case tok::tilde: // unary-expression: '~' cast-expression
1476 case tok::exclaim: // unary-expression: '!' cast-expression
1477 case tok::kw___real: // unary-expression: '__real' cast-expression [GNU]
1478 case tok::kw___imag: { // unary-expression: '__imag' cast-expression [GNU]
1479 if (NotPrimaryExpression)
1480 *NotPrimaryExpression = true;
1481 SourceLocation SavedLoc = ConsumeToken();
1482 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc);
1483 Res = ParseCastExpression(AnyCastExpr);
1484 if (!Res.isInvalid()) {
1485 Expr *Arg = Res.get();
1486 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg,
1487 isAddressOfOperand);
1488 if (Res.isInvalid())
1489 Res = Actions.CreateRecoveryExpr(SavedLoc, Arg->getEndLoc(), Arg);
1490 }
1491 return Res;
1492 }
1493
1494 case tok::kw_co_await: { // unary-expression: 'co_await' cast-expression
1495 if (NotPrimaryExpression)
1496 *NotPrimaryExpression = true;
1497 SourceLocation CoawaitLoc = ConsumeToken();
1498 Res = ParseCastExpression(AnyCastExpr);
1499 if (!Res.isInvalid())
1500 Res = Actions.ActOnCoawaitExpr(getCurScope(), CoawaitLoc, Res.get());
1501 return Res;
1502 }
1503
1504 case tok::kw___extension__:{//unary-expression:'__extension__' cast-expr [GNU]
1505 // __extension__ silences extension warnings in the subexpression.
1506 if (NotPrimaryExpression)
1507 *NotPrimaryExpression = true;
1508 ExtensionRAIIObject O(Diags); // Use RAII to do this.
1509 SourceLocation SavedLoc = ConsumeToken();
1510 Res = ParseCastExpression(AnyCastExpr);
1511 if (!Res.isInvalid())
1512 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
1513 return Res;
1514 }
1515 case tok::kw__Alignof: // unary-expression: '_Alignof' '(' type-name ')'
1516 diagnoseUseOfC11Keyword(Tok);
1517 [[fallthrough]];
1518 case tok::kw_alignof: // unary-expression: 'alignof' '(' type-id ')'
1519 case tok::kw___alignof: // unary-expression: '__alignof' unary-expression
1520 // unary-expression: '__alignof' '(' type-name ')'
1521 case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression
1522 // unary-expression: 'sizeof' '(' type-name ')'
1523 // unary-expression: '__datasizeof' unary-expression
1524 // unary-expression: '__datasizeof' '(' type-name ')'
1525 case tok::kw___datasizeof:
1526 case tok::kw_vec_step: // unary-expression: OpenCL 'vec_step' expression
1527 // unary-expression: '__builtin_omp_required_simd_align' '(' type-name ')'
1528 case tok::kw___builtin_omp_required_simd_align:
1529 case tok::kw___builtin_vectorelements:
1530 if (NotPrimaryExpression)
1531 *NotPrimaryExpression = true;
1532 AllowSuffix = false;
1533 Res = ParseUnaryExprOrTypeTraitExpression();
1534 break;
1535 case tok::ampamp: { // unary-expression: '&&' identifier
1536 if (NotPrimaryExpression)
1537 *NotPrimaryExpression = true;
1538 SourceLocation AmpAmpLoc = ConsumeToken();
1539 if (Tok.isNot(tok::identifier))
1540 return ExprError(Diag(Tok, diag::err_expected) << tok::identifier);
1541
1542 if (getCurScope()->getFnParent() == nullptr)
1543 return ExprError(Diag(Tok, diag::err_address_of_label_outside_fn));
1544
1545 Diag(AmpAmpLoc, diag::ext_gnu_address_of_label);
1547 Tok.getLocation());
1548 Res = Actions.ActOnAddrLabel(AmpAmpLoc, Tok.getLocation(), LD);
1549 ConsumeToken();
1550 AllowSuffix = false;
1551 break;
1552 }
1553 case tok::kw_const_cast:
1554 case tok::kw_dynamic_cast:
1555 case tok::kw_reinterpret_cast:
1556 case tok::kw_static_cast:
1557 case tok::kw_addrspace_cast:
1558 if (NotPrimaryExpression)
1559 *NotPrimaryExpression = true;
1560 Res = ParseCXXCasts();
1561 break;
1562 case tok::kw___builtin_bit_cast:
1563 if (NotPrimaryExpression)
1564 *NotPrimaryExpression = true;
1565 Res = ParseBuiltinBitCast();
1566 break;
1567 case tok::kw_typeid:
1568 if (NotPrimaryExpression)
1569 *NotPrimaryExpression = true;
1570 Res = ParseCXXTypeid();
1571 break;
1572 case tok::kw___uuidof:
1573 if (NotPrimaryExpression)
1574 *NotPrimaryExpression = true;
1575 Res = ParseCXXUuidof();
1576 break;
1577 case tok::kw_this:
1578 Res = ParseCXXThis();
1579 break;
1580 case tok::kw___builtin_sycl_unique_stable_name:
1581 Res = ParseSYCLUniqueStableNameExpression();
1582 break;
1583
1584 case tok::annot_typename:
1585 if (isStartOfObjCClassMessageMissingOpenBracket()) {
1587
1588 // Fake up a Declarator to use with ActOnTypeName.
1589 DeclSpec DS(AttrFactory);
1590 DS.SetRangeStart(Tok.getLocation());
1591 DS.SetRangeEnd(Tok.getLastLoc());
1592
1593 const char *PrevSpec = nullptr;
1594 unsigned DiagID;
1595 DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(),
1596 PrevSpec, DiagID, Type,
1597 Actions.getASTContext().getPrintingPolicy());
1598
1599 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
1601 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
1602 if (Ty.isInvalid())
1603 break;
1604
1605 ConsumeAnnotationToken();
1606 Res = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
1607 Ty.get(), nullptr);
1608 break;
1609 }
1610 [[fallthrough]];
1611
1612 case tok::annot_decltype:
1613 case tok::annot_pack_indexing_type:
1614 case tok::kw_char:
1615 case tok::kw_wchar_t:
1616 case tok::kw_char8_t:
1617 case tok::kw_char16_t:
1618 case tok::kw_char32_t:
1619 case tok::kw_bool:
1620 case tok::kw_short:
1621 case tok::kw_int:
1622 case tok::kw_long:
1623 case tok::kw___int64:
1624 case tok::kw___int128:
1625 case tok::kw__ExtInt:
1626 case tok::kw__BitInt:
1627 case tok::kw_signed:
1628 case tok::kw_unsigned:
1629 case tok::kw_half:
1630 case tok::kw_float:
1631 case tok::kw_double:
1632 case tok::kw___bf16:
1633 case tok::kw__Float16:
1634 case tok::kw___float128:
1635 case tok::kw___ibm128:
1636 case tok::kw_void:
1637 case tok::kw_auto:
1638 case tok::kw_typename:
1639 case tok::kw_typeof:
1640 case tok::kw___vector:
1641 case tok::kw__Accum:
1642 case tok::kw__Fract:
1643 case tok::kw__Sat:
1644#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1645#include "clang/Basic/OpenCLImageTypes.def"
1646 {
1647 if (!getLangOpts().CPlusPlus) {
1648 Diag(Tok, diag::err_expected_expression);
1649 return ExprError();
1650 }
1651
1652 // Everything henceforth is a postfix-expression.
1653 if (NotPrimaryExpression)
1654 *NotPrimaryExpression = true;
1655
1656 if (SavedKind == tok::kw_typename) {
1657 // postfix-expression: typename-specifier '(' expression-list[opt] ')'
1658 // typename-specifier braced-init-list
1660 return ExprError();
1661
1663 // We are trying to parse a simple-type-specifier but might not get such
1664 // a token after error recovery.
1665 return ExprError();
1666 }
1667
1668 // postfix-expression: simple-type-specifier '(' expression-list[opt] ')'
1669 // simple-type-specifier braced-init-list
1670 //
1671 DeclSpec DS(AttrFactory);
1672
1673 ParseCXXSimpleTypeSpecifier(DS);
1674 if (Tok.isNot(tok::l_paren) &&
1675 (!getLangOpts().CPlusPlus11 || Tok.isNot(tok::l_brace)))
1676 return ExprError(Diag(Tok, diag::err_expected_lparen_after_type)
1677 << DS.getSourceRange());
1678
1679 if (Tok.is(tok::l_brace))
1680 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1681
1682 Res = ParseCXXTypeConstructExpression(DS);
1683 break;
1684 }
1685
1686 case tok::annot_cxxscope: { // [C++] id-expression: qualified-id
1687 // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
1688 // (We can end up in this situation after tentative parsing.)
1690 return ExprError();
1691 if (!Tok.is(tok::annot_cxxscope))
1692 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1693 isTypeCast, isVectorLiteral,
1694 NotPrimaryExpression);
1695
1696 Token Next = NextToken();
1697 if (Next.is(tok::annot_template_id)) {
1698 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Next);
1699 if (TemplateId->Kind == TNK_Type_template) {
1700 // We have a qualified template-id that we know refers to a
1701 // type, translate it into a type and continue parsing as a
1702 // cast expression.
1703 CXXScopeSpec SS;
1704 ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
1705 /*ObjectHasErrors=*/false,
1706 /*EnteringContext=*/false);
1707 AnnotateTemplateIdTokenAsType(SS, ImplicitTypenameContext::Yes);
1708 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1709 isTypeCast, isVectorLiteral,
1710 NotPrimaryExpression);
1711 }
1712 }
1713
1714 // Parse as an id-expression.
1715 Res = ParseCXXIdExpression(isAddressOfOperand);
1716 break;
1717 }
1718
1719 case tok::annot_template_id: { // [C++] template-id
1720 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1721 if (TemplateId->Kind == TNK_Type_template) {
1722 // We have a template-id that we know refers to a type,
1723 // translate it into a type and continue parsing as a cast
1724 // expression.
1725 CXXScopeSpec SS;
1726 AnnotateTemplateIdTokenAsType(SS, ImplicitTypenameContext::Yes);
1727 return ParseCastExpression(ParseKind, isAddressOfOperand,
1728 NotCastExpr, isTypeCast, isVectorLiteral,
1729 NotPrimaryExpression);
1730 }
1731
1732 // Fall through to treat the template-id as an id-expression.
1733 [[fallthrough]];
1734 }
1735
1736 case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id
1737 Res = ParseCXXIdExpression(isAddressOfOperand);
1738 break;
1739
1740 case tok::coloncolon: {
1741 // ::foo::bar -> global qualified name etc. If TryAnnotateTypeOrScopeToken
1742 // annotates the token, tail recurse.
1744 return ExprError();
1745 if (!Tok.is(tok::coloncolon))
1746 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1747 isVectorLiteral, NotPrimaryExpression);
1748
1749 // ::new -> [C++] new-expression
1750 // ::delete -> [C++] delete-expression
1751 SourceLocation CCLoc = ConsumeToken();
1752 if (Tok.is(tok::kw_new)) {
1753 if (NotPrimaryExpression)
1754 *NotPrimaryExpression = true;
1755 Res = ParseCXXNewExpression(true, CCLoc);
1756 AllowSuffix = false;
1757 break;
1758 }
1759 if (Tok.is(tok::kw_delete)) {
1760 if (NotPrimaryExpression)
1761 *NotPrimaryExpression = true;
1762 Res = ParseCXXDeleteExpression(true, CCLoc);
1763 AllowSuffix = false;
1764 break;
1765 }
1766
1767 // This is not a type name or scope specifier, it is an invalid expression.
1768 Diag(CCLoc, diag::err_expected_expression);
1769 return ExprError();
1770 }
1771
1772 case tok::kw_new: // [C++] new-expression
1773 if (NotPrimaryExpression)
1774 *NotPrimaryExpression = true;
1775 Res = ParseCXXNewExpression(false, Tok.getLocation());
1776 AllowSuffix = false;
1777 break;
1778
1779 case tok::kw_delete: // [C++] delete-expression
1780 if (NotPrimaryExpression)
1781 *NotPrimaryExpression = true;
1782 Res = ParseCXXDeleteExpression(false, Tok.getLocation());
1783 AllowSuffix = false;
1784 break;
1785
1786 case tok::kw_requires: // [C++2a] requires-expression
1787 Res = ParseRequiresExpression();
1788 AllowSuffix = false;
1789 break;
1790
1791 case tok::kw_noexcept: { // [C++0x] 'noexcept' '(' expression ')'
1792 if (NotPrimaryExpression)
1793 *NotPrimaryExpression = true;
1794 Diag(Tok, diag::warn_cxx98_compat_noexcept_expr);
1795 SourceLocation KeyLoc = ConsumeToken();
1796 BalancedDelimiterTracker T(*this, tok::l_paren);
1797
1798 if (T.expectAndConsume(diag::err_expected_lparen_after, "noexcept"))
1799 return ExprError();
1800 // C++11 [expr.unary.noexcept]p1:
1801 // The noexcept operator determines whether the evaluation of its operand,
1802 // which is an unevaluated operand, can throw an exception.
1805 Res = ParseExpression();
1806
1807 T.consumeClose();
1808
1809 if (!Res.isInvalid())
1810 Res = Actions.ActOnNoexceptExpr(KeyLoc, T.getOpenLocation(), Res.get(),
1811 T.getCloseLocation());
1812 AllowSuffix = false;
1813 break;
1814 }
1815
1816#define TYPE_TRAIT(N,Spelling,K) \
1817 case tok::kw_##Spelling:
1818#include "clang/Basic/TokenKinds.def"
1819 Res = ParseTypeTrait();
1820 break;
1821
1822 case tok::kw___array_rank:
1823 case tok::kw___array_extent:
1824 if (NotPrimaryExpression)
1825 *NotPrimaryExpression = true;
1826 Res = ParseArrayTypeTrait();
1827 break;
1828
1829 case tok::kw___builtin_ptrauth_type_discriminator:
1830 return ParseBuiltinPtrauthTypeDiscriminator();
1831
1832 case tok::kw___is_lvalue_expr:
1833 case tok::kw___is_rvalue_expr:
1834 if (NotPrimaryExpression)
1835 *NotPrimaryExpression = true;
1836 Res = ParseExpressionTrait();
1837 break;
1838
1839 case tok::at: {
1840 if (NotPrimaryExpression)
1841 *NotPrimaryExpression = true;
1842 SourceLocation AtLoc = ConsumeToken();
1843 return ParseObjCAtExpression(AtLoc);
1844 }
1845 case tok::caret:
1846 Res = ParseBlockLiteralExpression();
1847 break;
1848 case tok::code_completion: {
1849 cutOffParsing();
1851 getCurScope(), PreferredType.get(Tok.getLocation()));
1852 return ExprError();
1853 }
1854#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
1855#include "clang/Basic/TransformTypeTraits.def"
1856 // HACK: libstdc++ uses some of the transform-type-traits as alias
1857 // templates, so we need to work around this.
1858 if (!NextToken().is(tok::l_paren)) {
1859 Tok.setKind(tok::identifier);
1860 Diag(Tok, diag::ext_keyword_as_ident)
1861 << Tok.getIdentifierInfo()->getName() << 0;
1862 goto ParseIdentifier;
1863 }
1864 goto ExpectedExpression;
1865 case tok::l_square:
1866 if (getLangOpts().CPlusPlus) {
1867 if (getLangOpts().ObjC) {
1868 // C++11 lambda expressions and Objective-C message sends both start with a
1869 // square bracket. There are three possibilities here:
1870 // we have a valid lambda expression, we have an invalid lambda
1871 // expression, or we have something that doesn't appear to be a lambda.
1872 // If we're in the last case, we fall back to ParseObjCMessageExpression.
1873 Res = TryParseLambdaExpression();
1874 if (!Res.isInvalid() && !Res.get()) {
1875 // We assume Objective-C++ message expressions are not
1876 // primary-expressions.
1877 if (NotPrimaryExpression)
1878 *NotPrimaryExpression = true;
1879 Res = ParseObjCMessageExpression();
1880 }
1881 break;
1882 }
1883 Res = ParseLambdaExpression();
1884 break;
1885 }
1886 if (getLangOpts().ObjC) {
1887 Res = ParseObjCMessageExpression();
1888 break;
1889 }
1890 [[fallthrough]];
1891 default:
1892 ExpectedExpression:
1893 NotCastExpr = true;
1894 return ExprError();
1895 }
1896
1897 // Check to see whether Res is a function designator only. If it is and we
1898 // are compiling for OpenCL, we need to return an error as this implies
1899 // that the address of the function is being taken, which is illegal in CL.
1900
1901 if (ParseKind == PrimaryExprOnly)
1902 // This is strictly a primary-expression - no postfix-expr pieces should be
1903 // parsed.
1904 return Res;
1905
1906 if (!AllowSuffix) {
1907 // FIXME: Don't parse a primary-expression suffix if we encountered a parse
1908 // error already.
1909 if (Res.isInvalid())
1910 return Res;
1911
1912 switch (Tok.getKind()) {
1913 case tok::l_square:
1914 case tok::l_paren:
1915 case tok::plusplus:
1916 case tok::minusminus:
1917 // "expected ';'" or similar is probably the right diagnostic here. Let
1918 // the caller decide what to do.
1919 if (Tok.isAtStartOfLine())
1920 return Res;
1921
1922 [[fallthrough]];
1923 case tok::period:
1924 case tok::arrow:
1925 break;
1926
1927 default:
1928 return Res;
1929 }
1930
1931 // This was a unary-expression for which a postfix-expression suffix is
1932 // not permitted by the grammar (eg, a sizeof expression or
1933 // new-expression or similar). Diagnose but parse the suffix anyway.
1934 Diag(Tok.getLocation(), diag::err_postfix_after_unary_requires_parens)
1935 << Tok.getKind() << Res.get()->getSourceRange()
1937 << FixItHint::CreateInsertion(PP.getLocForEndOfToken(PrevTokLocation),
1938 ")");
1939 }
1940
1941 // These can be followed by postfix-expr pieces.
1942 PreferredType = SavedType;
1943 Res = ParsePostfixExpressionSuffix(Res);
1944 if (getLangOpts().OpenCL &&
1945 !getActions().getOpenCLOptions().isAvailableOption(
1946 "__cl_clang_function_pointers", getLangOpts()))
1947 if (Expr *PostfixExpr = Res.get()) {
1948 QualType Ty = PostfixExpr->getType();
1949 if (!Ty.isNull() && Ty->isFunctionType()) {
1950 Diag(PostfixExpr->getExprLoc(),
1951 diag::err_opencl_taking_function_address_parser);
1952 return ExprError();
1953 }
1954 }
1955
1956 return Res;
1957}
1958
1959/// Once the leading part of a postfix-expression is parsed, this
1960/// method parses any suffixes that apply.
1961///
1962/// \verbatim
1963/// postfix-expression: [C99 6.5.2]
1964/// primary-expression
1965/// postfix-expression '[' expression ']'
1966/// postfix-expression '[' braced-init-list ']'
1967/// postfix-expression '[' expression-list [opt] ']' [C++23 12.4.5]
1968/// postfix-expression '(' argument-expression-list[opt] ')'
1969/// postfix-expression '.' identifier
1970/// postfix-expression '->' identifier
1971/// postfix-expression '++'
1972/// postfix-expression '--'
1973/// '(' type-name ')' '{' initializer-list '}'
1974/// '(' type-name ')' '{' initializer-list ',' '}'
1975///
1976/// argument-expression-list: [C99 6.5.2]
1977/// argument-expression ...[opt]
1978/// argument-expression-list ',' assignment-expression ...[opt]
1979/// \endverbatim
1981Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1982 // Now that the primary-expression piece of the postfix-expression has been
1983 // parsed, see if there are any postfix-expression pieces here.
1985 auto SavedType = PreferredType;
1986 while (true) {
1987 // Each iteration relies on preferred type for the whole expression.
1988 PreferredType = SavedType;
1989 switch (Tok.getKind()) {
1990 case tok::code_completion:
1991 if (InMessageExpression)
1992 return LHS;
1993
1994 cutOffParsing();
1996 getCurScope(), LHS, PreferredType.get(Tok.getLocation()));
1997 return ExprError();
1998
1999 case tok::identifier:
2000 // If we see identifier: after an expression, and we're not already in a
2001 // message send, then this is probably a message send with a missing
2002 // opening bracket '['.
2003 if (getLangOpts().ObjC && !InMessageExpression &&
2004 (NextToken().is(tok::colon) || NextToken().is(tok::r_square))) {
2005 LHS = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
2006 nullptr, LHS.get());
2007 break;
2008 }
2009 // Fall through; this isn't a message send.
2010 [[fallthrough]];
2011
2012 default: // Not a postfix-expression suffix.
2013 return LHS;
2014 case tok::l_square: { // postfix-expression: p-e '[' expression ']'
2015 // If we have a array postfix expression that starts on a new line and
2016 // Objective-C is enabled, it is highly likely that the user forgot a
2017 // semicolon after the base expression and that the array postfix-expr is
2018 // actually another message send. In this case, do some look-ahead to see
2019 // if the contents of the square brackets are obviously not a valid
2020 // expression and recover by pretending there is no suffix.
2021 if (getLangOpts().ObjC && Tok.isAtStartOfLine() &&
2022 isSimpleObjCMessageExpression())
2023 return LHS;
2024
2025 // Reject array indices starting with a lambda-expression. '[[' is
2026 // reserved for attributes.
2027 if (CheckProhibitedCXX11Attribute()) {
2028 (void)Actions.CorrectDelayedTyposInExpr(LHS);
2029 return ExprError();
2030 }
2031 BalancedDelimiterTracker T(*this, tok::l_square);
2032 T.consumeOpen();
2033 Loc = T.getOpenLocation();
2034 ExprResult Length, Stride;
2035 SourceLocation ColonLocFirst, ColonLocSecond;
2036 ExprVector ArgExprs;
2037 bool HasError = false;
2038 PreferredType.enterSubscript(Actions, Tok.getLocation(), LHS.get());
2039
2040 // We try to parse a list of indexes in all language mode first
2041 // and, in we find 0 or one index, we try to parse an OpenMP/OpenACC array
2042 // section. This allow us to support C++23 multi dimensional subscript and
2043 // OpenMP/OpenACC sections in the same language mode.
2044 if ((!getLangOpts().OpenMP && !AllowOpenACCArraySections) ||
2045 Tok.isNot(tok::colon)) {
2046 if (!getLangOpts().CPlusPlus23) {
2047 ExprResult Idx;
2048 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
2049 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2050 Idx = ParseBraceInitializer();
2051 } else {
2052 Idx = ParseExpression(); // May be a comma expression
2053 }
2054 LHS = Actions.CorrectDelayedTyposInExpr(LHS);
2055 Idx = Actions.CorrectDelayedTyposInExpr(Idx);
2056 if (Idx.isInvalid()) {
2057 HasError = true;
2058 } else {
2059 ArgExprs.push_back(Idx.get());
2060 }
2061 } else if (Tok.isNot(tok::r_square)) {
2062 if (ParseExpressionList(ArgExprs)) {
2063 LHS = Actions.CorrectDelayedTyposInExpr(LHS);
2064 HasError = true;
2065 }
2066 }
2067 }
2068
2069 // Handle OpenACC first, since 'AllowOpenACCArraySections' is only enabled
2070 // when actively parsing a 'var' in a 'var-list' during clause/'cache'
2071 // parsing, so it is the most specific, and best allows us to handle
2072 // OpenACC and OpenMP at the same time.
2073 if (ArgExprs.size() <= 1 && AllowOpenACCArraySections) {
2074 ColonProtectionRAIIObject RAII(*this);
2075 if (Tok.is(tok::colon)) {
2076 // Consume ':'
2077 ColonLocFirst = ConsumeToken();
2078 if (Tok.isNot(tok::r_square))
2079 Length = Actions.CorrectDelayedTyposInExpr(ParseExpression());
2080 }
2081 } else if (ArgExprs.size() <= 1 && getLangOpts().OpenMP) {
2082 ColonProtectionRAIIObject RAII(*this);
2083 if (Tok.is(tok::colon)) {
2084 // Consume ':'
2085 ColonLocFirst = ConsumeToken();
2086 if (Tok.isNot(tok::r_square) &&
2087 (getLangOpts().OpenMP < 50 ||
2088 ((Tok.isNot(tok::colon) && getLangOpts().OpenMP >= 50)))) {
2089 Length = ParseExpression();
2090 Length = Actions.CorrectDelayedTyposInExpr(Length);
2091 }
2092 }
2093 if (getLangOpts().OpenMP >= 50 &&
2094 (OMPClauseKind == llvm::omp::Clause::OMPC_to ||
2095 OMPClauseKind == llvm::omp::Clause::OMPC_from) &&
2096 Tok.is(tok::colon)) {
2097 // Consume ':'
2098 ColonLocSecond = ConsumeToken();
2099 if (Tok.isNot(tok::r_square)) {
2100 Stride = ParseExpression();
2101 }
2102 }
2103 }
2104
2105 SourceLocation RLoc = Tok.getLocation();
2106 LHS = Actions.CorrectDelayedTyposInExpr(LHS);
2107
2108 if (!LHS.isInvalid() && !HasError && !Length.isInvalid() &&
2109 !Stride.isInvalid() && Tok.is(tok::r_square)) {
2110 if (ColonLocFirst.isValid() || ColonLocSecond.isValid()) {
2111 // Like above, AllowOpenACCArraySections is 'more specific' and only
2112 // enabled when actively parsing a 'var' in a 'var-list' during
2113 // clause/'cache' construct parsing, so it is more specific. So we
2114 // should do it first, so that the correct node gets created.
2115 if (AllowOpenACCArraySections) {
2116 assert(!Stride.isUsable() && !ColonLocSecond.isValid() &&
2117 "Stride/second colon not allowed for OpenACC");
2118 LHS = Actions.OpenACC().ActOnArraySectionExpr(
2119 LHS.get(), Loc, ArgExprs.empty() ? nullptr : ArgExprs[0],
2120 ColonLocFirst, Length.get(), RLoc);
2121 } else {
2122 LHS = Actions.OpenMP().ActOnOMPArraySectionExpr(
2123 LHS.get(), Loc, ArgExprs.empty() ? nullptr : ArgExprs[0],
2124 ColonLocFirst, ColonLocSecond, Length.get(), Stride.get(),
2125 RLoc);
2126 }
2127 } else {
2128 LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.get(), Loc,
2129 ArgExprs, RLoc);
2130 }
2131 } else {
2132 LHS = ExprError();
2133 }
2134
2135 // Match the ']'.
2136 T.consumeClose();
2137 break;
2138 }
2139
2140 case tok::l_paren: // p-e: p-e '(' argument-expression-list[opt] ')'
2141 case tok::lesslessless: { // p-e: p-e '<<<' argument-expression-list '>>>'
2142 // '(' argument-expression-list[opt] ')'
2143 tok::TokenKind OpKind = Tok.getKind();
2144 InMessageExpressionRAIIObject InMessage(*this, false);
2145
2146 Expr *ExecConfig = nullptr;
2147
2148 BalancedDelimiterTracker PT(*this, tok::l_paren);
2149
2150 if (OpKind == tok::lesslessless) {
2151 ExprVector ExecConfigExprs;
2152 SourceLocation OpenLoc = ConsumeToken();
2153
2154 if (ParseSimpleExpressionList(ExecConfigExprs)) {
2155 (void)Actions.CorrectDelayedTyposInExpr(LHS);
2156 LHS = ExprError();
2157 }
2158
2159 SourceLocation CloseLoc;
2160 if (TryConsumeToken(tok::greatergreatergreater, CloseLoc)) {
2161 } else if (LHS.isInvalid()) {
2162 SkipUntil(tok::greatergreatergreater, StopAtSemi);
2163 } else {
2164 // There was an error closing the brackets
2165 Diag(Tok, diag::err_expected) << tok::greatergreatergreater;
2166 Diag(OpenLoc, diag::note_matching) << tok::lesslessless;
2167 SkipUntil(tok::greatergreatergreater, StopAtSemi);
2168 LHS = ExprError();
2169 }
2170
2171 if (!LHS.isInvalid()) {
2172 if (ExpectAndConsume(tok::l_paren))
2173 LHS = ExprError();
2174 else
2175 Loc = PrevTokLocation;
2176 }
2177
2178 if (!LHS.isInvalid()) {
2179 ExprResult ECResult = Actions.CUDA().ActOnExecConfigExpr(
2180 getCurScope(), OpenLoc, ExecConfigExprs, CloseLoc);
2181 if (ECResult.isInvalid())
2182 LHS = ExprError();
2183 else
2184 ExecConfig = ECResult.get();
2185 }
2186 } else {
2187 PT.consumeOpen();
2188 Loc = PT.getOpenLocation();
2189 }
2190
2191 ExprVector ArgExprs;
2192 auto RunSignatureHelp = [&]() -> QualType {
2193 QualType PreferredType =
2195 LHS.get(), ArgExprs, PT.getOpenLocation());
2196 CalledSignatureHelp = true;
2197 return PreferredType;
2198 };
2199 if (OpKind == tok::l_paren || !LHS.isInvalid()) {
2200 if (Tok.isNot(tok::r_paren)) {
2201 if (ParseExpressionList(ArgExprs, [&] {
2202 PreferredType.enterFunctionArgument(Tok.getLocation(),
2203 RunSignatureHelp);
2204 })) {
2205 (void)Actions.CorrectDelayedTyposInExpr(LHS);
2206 // If we got an error when parsing expression list, we don't call
2207 // the CodeCompleteCall handler inside the parser. So call it here
2208 // to make sure we get overload suggestions even when we are in the
2209 // middle of a parameter.
2210 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
2211 RunSignatureHelp();
2212 LHS = ExprError();
2213 } else if (LHS.isInvalid()) {
2214 for (auto &E : ArgExprs)
2216 }
2217 }
2218 }
2219
2220 // Match the ')'.
2221 if (LHS.isInvalid()) {
2222 SkipUntil(tok::r_paren, StopAtSemi);
2223 } else if (Tok.isNot(tok::r_paren)) {
2224 bool HadDelayedTypo = false;
2225 if (Actions.CorrectDelayedTyposInExpr(LHS).get() != LHS.get())
2226 HadDelayedTypo = true;
2227 for (auto &E : ArgExprs)
2228 if (Actions.CorrectDelayedTyposInExpr(E).get() != E)
2229 HadDelayedTypo = true;
2230 // If there were delayed typos in the LHS or ArgExprs, call SkipUntil
2231 // instead of PT.consumeClose() to avoid emitting extra diagnostics for
2232 // the unmatched l_paren.
2233 if (HadDelayedTypo)
2234 SkipUntil(tok::r_paren, StopAtSemi);
2235 else
2236 PT.consumeClose();
2237 LHS = ExprError();
2238 } else {
2239 Expr *Fn = LHS.get();
2240 SourceLocation RParLoc = Tok.getLocation();
2241 LHS = Actions.ActOnCallExpr(getCurScope(), Fn, Loc, ArgExprs, RParLoc,
2242 ExecConfig);
2243 if (LHS.isInvalid()) {
2244 ArgExprs.insert(ArgExprs.begin(), Fn);
2245 LHS =
2246 Actions.CreateRecoveryExpr(Fn->getBeginLoc(), RParLoc, ArgExprs);
2247 }
2248 PT.consumeClose();
2249 }
2250
2251 break;
2252 }
2253 case tok::arrow:
2254 case tok::period: {
2255 // postfix-expression: p-e '->' template[opt] id-expression
2256 // postfix-expression: p-e '.' template[opt] id-expression
2257 tok::TokenKind OpKind = Tok.getKind();
2258 SourceLocation OpLoc = ConsumeToken(); // Eat the "." or "->" token.
2259
2260 CXXScopeSpec SS;
2261 ParsedType ObjectType;
2262 bool MayBePseudoDestructor = false;
2263 Expr* OrigLHS = !LHS.isInvalid() ? LHS.get() : nullptr;
2264
2265 PreferredType.enterMemAccess(Actions, Tok.getLocation(), OrigLHS);
2266
2267 if (getLangOpts().CPlusPlus && !LHS.isInvalid()) {
2268 Expr *Base = OrigLHS;
2269 const Type* BaseType = Base->getType().getTypePtrOrNull();
2270 if (BaseType && Tok.is(tok::l_paren) &&
2271 (BaseType->isFunctionType() ||
2272 BaseType->isSpecificPlaceholderType(BuiltinType::BoundMember))) {
2273 Diag(OpLoc, diag::err_function_is_not_record)
2274 << OpKind << Base->getSourceRange()
2275 << FixItHint::CreateRemoval(OpLoc);
2276 return ParsePostfixExpressionSuffix(Base);
2277 }
2278
2279 LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base, OpLoc,
2280 OpKind, ObjectType,
2281 MayBePseudoDestructor);
2282 if (LHS.isInvalid()) {
2283 // Clang will try to perform expression based completion as a
2284 // fallback, which is confusing in case of member references. So we
2285 // stop here without any completions.
2286 if (Tok.is(tok::code_completion)) {
2287 cutOffParsing();
2288 return ExprError();
2289 }
2290 break;
2291 }
2292 ParseOptionalCXXScopeSpecifier(
2293 SS, ObjectType, LHS.get() && LHS.get()->containsErrors(),
2294 /*EnteringContext=*/false, &MayBePseudoDestructor);
2295 if (SS.isNotEmpty())
2296 ObjectType = nullptr;
2297 }
2298
2299 if (Tok.is(tok::code_completion)) {
2300 tok::TokenKind CorrectedOpKind =
2301 OpKind == tok::arrow ? tok::period : tok::arrow;
2302 ExprResult CorrectedLHS(/*Invalid=*/true);
2303 if (getLangOpts().CPlusPlus && OrigLHS) {
2304 // FIXME: Creating a TentativeAnalysisScope from outside Sema is a
2305 // hack.
2306 Sema::TentativeAnalysisScope Trap(Actions);
2307 CorrectedLHS = Actions.ActOnStartCXXMemberReference(
2308 getCurScope(), OrigLHS, OpLoc, CorrectedOpKind, ObjectType,
2309 MayBePseudoDestructor);
2310 }
2311
2312 Expr *Base = LHS.get();
2313 Expr *CorrectedBase = CorrectedLHS.get();
2314 if (!CorrectedBase && !getLangOpts().CPlusPlus)
2315 CorrectedBase = Base;
2316
2317 // Code completion for a member access expression.
2318 cutOffParsing();
2320 getCurScope(), Base, CorrectedBase, OpLoc, OpKind == tok::arrow,
2321 Base && ExprStatementTokLoc == Base->getBeginLoc(),
2322 PreferredType.get(Tok.getLocation()));
2323
2324 return ExprError();
2325 }
2326
2327 if (MayBePseudoDestructor && !LHS.isInvalid()) {
2328 LHS = ParseCXXPseudoDestructor(LHS.get(), OpLoc, OpKind, SS,
2329 ObjectType);
2330 break;
2331 }
2332
2333 // Either the action has told us that this cannot be a
2334 // pseudo-destructor expression (based on the type of base
2335 // expression), or we didn't see a '~' in the right place. We
2336 // can still parse a destructor name here, but in that case it
2337 // names a real destructor.
2338 // Allow explicit constructor calls in Microsoft mode.
2339 // FIXME: Add support for explicit call of template constructor.
2340 SourceLocation TemplateKWLoc;
2341 UnqualifiedId Name;
2342 if (getLangOpts().ObjC && OpKind == tok::period &&
2343 Tok.is(tok::kw_class)) {
2344 // Objective-C++:
2345 // After a '.' in a member access expression, treat the keyword
2346 // 'class' as if it were an identifier.
2347 //
2348 // This hack allows property access to the 'class' method because it is
2349 // such a common method name. For other C++ keywords that are
2350 // Objective-C method names, one must use the message send syntax.
2353 Name.setIdentifier(Id, Loc);
2354 } else if (ParseUnqualifiedId(
2355 SS, ObjectType, LHS.get() && LHS.get()->containsErrors(),
2356 /*EnteringContext=*/false,
2357 /*AllowDestructorName=*/true,
2358 /*AllowConstructorName=*/
2359 getLangOpts().MicrosoftExt && SS.isNotEmpty(),
2360 /*AllowDeductionGuide=*/false, &TemplateKWLoc, Name)) {
2361 (void)Actions.CorrectDelayedTyposInExpr(LHS);
2362 LHS = ExprError();
2363 }
2364
2365 if (!LHS.isInvalid())
2366 LHS = Actions.ActOnMemberAccessExpr(getCurScope(), LHS.get(), OpLoc,
2367 OpKind, SS, TemplateKWLoc, Name,
2368 CurParsedObjCImpl ? CurParsedObjCImpl->Dcl
2369 : nullptr);
2370 if (!LHS.isInvalid()) {
2371 if (Tok.is(tok::less))
2372 checkPotentialAngleBracket(LHS);
2373 } else if (OrigLHS && Name.isValid()) {
2374 // Preserve the LHS if the RHS is an invalid member.
2375 LHS = Actions.CreateRecoveryExpr(OrigLHS->getBeginLoc(),
2376 Name.getEndLoc(), {OrigLHS});
2377 }
2378 break;
2379 }
2380 case tok::plusplus: // postfix-expression: postfix-expression '++'
2381 case tok::minusminus: // postfix-expression: postfix-expression '--'
2382 if (!LHS.isInvalid()) {
2383 Expr *Arg = LHS.get();
2384 LHS = Actions.ActOnPostfixUnaryOp(getCurScope(), Tok.getLocation(),
2385 Tok.getKind(), Arg);
2386 if (LHS.isInvalid())
2387 LHS = Actions.CreateRecoveryExpr(Arg->getBeginLoc(),
2388 Tok.getLocation(), Arg);
2389 }
2390 ConsumeToken();
2391 break;
2392 }
2393 }
2394}
2395
2396/// ParseExprAfterUnaryExprOrTypeTrait - We parsed a typeof/sizeof/alignof/
2397/// vec_step and we are at the start of an expression or a parenthesized
2398/// type-id. OpTok is the operand token (typeof/sizeof/alignof). Returns the
2399/// expression (isCastExpr == false) or the type (isCastExpr == true).
2400///
2401/// \verbatim
2402/// unary-expression: [C99 6.5.3]
2403/// 'sizeof' unary-expression
2404/// 'sizeof' '(' type-name ')'
2405/// [Clang] '__datasizeof' unary-expression
2406/// [Clang] '__datasizeof' '(' type-name ')'
2407/// [GNU] '__alignof' unary-expression
2408/// [GNU] '__alignof' '(' type-name ')'
2409/// [C11] '_Alignof' '(' type-name ')'
2410/// [C++0x] 'alignof' '(' type-id ')'
2411///
2412/// [GNU] typeof-specifier:
2413/// typeof ( expressions )
2414/// typeof ( type-name )
2415/// [GNU/C++] typeof unary-expression
2416/// [C23] typeof-specifier:
2417/// typeof '(' typeof-specifier-argument ')'
2418/// typeof_unqual '(' typeof-specifier-argument ')'
2419///
2420/// typeof-specifier-argument:
2421/// expression
2422/// type-name
2423///
2424/// [OpenCL 1.1 6.11.12] vec_step built-in function:
2425/// vec_step ( expressions )
2426/// vec_step ( type-name )
2427/// \endverbatim
2429Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
2430 bool &isCastExpr,
2431 ParsedType &CastTy,
2432 SourceRange &CastRange) {
2433
2434 assert(OpTok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual, tok::kw_sizeof,
2435 tok::kw___datasizeof, tok::kw___alignof, tok::kw_alignof,
2436 tok::kw__Alignof, tok::kw_vec_step,
2437 tok::kw___builtin_omp_required_simd_align,
2438 tok::kw___builtin_vectorelements) &&
2439 "Not a typeof/sizeof/alignof/vec_step expression!");
2440
2442
2443 // If the operand doesn't start with an '(', it must be an expression.
2444 if (Tok.isNot(tok::l_paren)) {
2445 // If construct allows a form without parenthesis, user may forget to put
2446 // pathenthesis around type name.
2447 if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
2448 tok::kw_alignof, tok::kw__Alignof)) {
2449 if (isTypeIdUnambiguously()) {
2450 DeclSpec DS(AttrFactory);
2451 ParseSpecifierQualifierList(DS);
2452 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
2454 ParseDeclarator(DeclaratorInfo);
2455
2456 SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation());
2457 SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation);
2458 if (LParenLoc.isInvalid() || RParenLoc.isInvalid()) {
2459 Diag(OpTok.getLocation(),
2460 diag::err_expected_parentheses_around_typename)
2461 << OpTok.getName();
2462 } else {
2463 Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
2464 << OpTok.getName() << FixItHint::CreateInsertion(LParenLoc, "(")
2465 << FixItHint::CreateInsertion(RParenLoc, ")");
2466 }
2467 isCastExpr = true;
2468 return ExprEmpty();
2469 }
2470 }
2471
2472 isCastExpr = false;
2473 if (OpTok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual) &&
2475 Diag(Tok, diag::err_expected_after) << OpTok.getIdentifierInfo()
2476 << tok::l_paren;
2477 return ExprError();
2478 }
2479
2480 Operand = ParseCastExpression(UnaryExprOnly);
2481 } else {
2482 // If it starts with a '(', we know that it is either a parenthesized
2483 // type-name, or it is a unary-expression that starts with a compound
2484 // literal, or starts with a primary-expression that is a parenthesized
2485 // expression.
2486 ParenParseOption ExprType = CastExpr;
2487 SourceLocation LParenLoc = Tok.getLocation(), RParenLoc;
2488
2489 Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/,
2490 false, CastTy, RParenLoc);
2491 CastRange = SourceRange(LParenLoc, RParenLoc);
2492
2493 // If ParseParenExpression parsed a '(typename)' sequence only, then this is
2494 // a type.
2495 if (ExprType == CastExpr) {
2496 isCastExpr = true;
2497 return ExprEmpty();
2498 }
2499
2500 if (getLangOpts().CPlusPlus ||
2501 !OpTok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual)) {
2502 // GNU typeof in C requires the expression to be parenthesized. Not so for
2503 // sizeof/alignof or in C++. Therefore, the parenthesized expression is
2504 // the start of a unary-expression, but doesn't include any postfix
2505 // pieces. Parse these now if present.
2506 if (!Operand.isInvalid())
2507 Operand = ParsePostfixExpressionSuffix(Operand.get());
2508 }
2509 }
2510
2511 // If we get here, the operand to the typeof/sizeof/alignof was an expression.
2512 isCastExpr = false;
2513 return Operand;
2514}
2515
2516/// Parse a __builtin_sycl_unique_stable_name expression. Accepts a type-id as
2517/// a parameter.
2518ExprResult Parser::ParseSYCLUniqueStableNameExpression() {
2519 assert(Tok.is(tok::kw___builtin_sycl_unique_stable_name) &&
2520 "Not __builtin_sycl_unique_stable_name");
2521
2522 SourceLocation OpLoc = ConsumeToken();
2523 BalancedDelimiterTracker T(*this, tok::l_paren);
2524
2525 // __builtin_sycl_unique_stable_name expressions are always parenthesized.
2526 if (T.expectAndConsume(diag::err_expected_lparen_after,
2527 "__builtin_sycl_unique_stable_name"))
2528 return ExprError();
2529
2531
2532 if (Ty.isInvalid()) {
2533 T.skipToEnd();
2534 return ExprError();
2535 }
2536
2537 if (T.consumeClose())
2538 return ExprError();
2539
2540 return Actions.SYCL().ActOnUniqueStableNameExpr(
2541 OpLoc, T.getOpenLocation(), T.getCloseLocation(), Ty.get());
2542}
2543
2544/// Parse a sizeof or alignof expression.
2545///
2546/// \verbatim
2547/// unary-expression: [C99 6.5.3]
2548/// 'sizeof' unary-expression
2549/// 'sizeof' '(' type-name ')'
2550/// [C++11] 'sizeof' '...' '(' identifier ')'
2551/// [Clang] '__datasizeof' unary-expression
2552/// [Clang] '__datasizeof' '(' type-name ')'
2553/// [GNU] '__alignof' unary-expression
2554/// [GNU] '__alignof' '(' type-name ')'
2555/// [C11] '_Alignof' '(' type-name ')'
2556/// [C++11] 'alignof' '(' type-id ')'
2557/// \endverbatim
2558ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() {
2559 assert(Tok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
2560 tok::kw_alignof, tok::kw__Alignof, tok::kw_vec_step,
2561 tok::kw___builtin_omp_required_simd_align,
2562 tok::kw___builtin_vectorelements) &&
2563 "Not a sizeof/alignof/vec_step expression!");
2564 Token OpTok = Tok;
2565 ConsumeToken();
2566
2567 // [C++11] 'sizeof' '...' '(' identifier ')'
2568 if (Tok.is(tok::ellipsis) && OpTok.is(tok::kw_sizeof)) {
2569 SourceLocation EllipsisLoc = ConsumeToken();
2570 SourceLocation LParenLoc, RParenLoc;
2571 IdentifierInfo *Name = nullptr;
2572 SourceLocation NameLoc;
2573 if (Tok.is(tok::l_paren)) {
2574 BalancedDelimiterTracker T(*this, tok::l_paren);
2575 T.consumeOpen();
2576 LParenLoc = T.getOpenLocation();
2577 if (Tok.is(tok::identifier)) {
2578 Name = Tok.getIdentifierInfo();
2579 NameLoc = ConsumeToken();
2580 T.consumeClose();
2581 RParenLoc = T.getCloseLocation();
2582 if (RParenLoc.isInvalid())
2583 RParenLoc = PP.getLocForEndOfToken(NameLoc);
2584 } else {
2585 Diag(Tok, diag::err_expected_parameter_pack);
2586 SkipUntil(tok::r_paren, StopAtSemi);
2587 }
2588 } else if (Tok.is(tok::identifier)) {
2589 Name = Tok.getIdentifierInfo();
2590 NameLoc = ConsumeToken();
2591 LParenLoc = PP.getLocForEndOfToken(EllipsisLoc);
2592 RParenLoc = PP.getLocForEndOfToken(NameLoc);
2593 Diag(LParenLoc, diag::err_paren_sizeof_parameter_pack)
2594 << Name
2595 << FixItHint::CreateInsertion(LParenLoc, "(")
2596 << FixItHint::CreateInsertion(RParenLoc, ")");
2597 } else {
2598 Diag(Tok, diag::err_sizeof_parameter_pack);
2599 }
2600
2601 if (!Name)
2602 return ExprError();
2603
2607
2609 OpTok.getLocation(),
2610 *Name, NameLoc,
2611 RParenLoc);
2612 }
2613
2614 if (getLangOpts().CPlusPlus &&
2615 OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
2616 Diag(OpTok, diag::warn_cxx98_compat_alignof);
2617 else if (getLangOpts().C23 && OpTok.is(tok::kw_alignof))
2618 Diag(OpTok, diag::warn_c23_compat_keyword) << OpTok.getName();
2619
2623
2624 bool isCastExpr;
2625 ParsedType CastTy;
2626 SourceRange CastRange;
2627 ExprResult Operand = ParseExprAfterUnaryExprOrTypeTrait(OpTok,
2628 isCastExpr,
2629 CastTy,
2630 CastRange);
2631
2632 UnaryExprOrTypeTrait ExprKind = UETT_SizeOf;
2633 switch (OpTok.getKind()) {
2634 case tok::kw_alignof:
2635 case tok::kw__Alignof:
2636 ExprKind = UETT_AlignOf;
2637 break;
2638 case tok::kw___alignof:
2639 ExprKind = UETT_PreferredAlignOf;
2640 break;
2641 case tok::kw_vec_step:
2642 ExprKind = UETT_VecStep;
2643 break;
2644 case tok::kw___builtin_omp_required_simd_align:
2645 ExprKind = UETT_OpenMPRequiredSimdAlign;
2646 break;
2647 case tok::kw___datasizeof:
2648 ExprKind = UETT_DataSizeOf;
2649 break;
2650 case tok::kw___builtin_vectorelements:
2651 ExprKind = UETT_VectorElements;
2652 break;
2653 default:
2654 break;
2655 }
2656
2657 if (isCastExpr)
2658 return Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
2659 ExprKind,
2660 /*IsType=*/true,
2661 CastTy.getAsOpaquePtr(),
2662 CastRange);
2663
2664 if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
2665 Diag(OpTok, diag::ext_alignof_expr) << OpTok.getIdentifierInfo();
2666
2667 // If we get here, the operand to the sizeof/alignof was an expression.
2668 if (!Operand.isInvalid())
2670 ExprKind,
2671 /*IsType=*/false,
2672 Operand.get(),
2673 CastRange);
2674 return Operand;
2675}
2676
2677/// ParseBuiltinPrimaryExpression
2678///
2679/// \verbatim
2680/// primary-expression: [C99 6.5.1]
2681/// [GNU] '__builtin_va_arg' '(' assignment-expression ',' type-name ')'
2682/// [GNU] '__builtin_offsetof' '(' type-name ',' offsetof-member-designator')'
2683/// [GNU] '__builtin_choose_expr' '(' assign-expr ',' assign-expr ','
2684/// assign-expr ')'
2685/// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')'
2686/// [GNU] '__builtin_FILE' '(' ')'
2687/// [CLANG] '__builtin_FILE_NAME' '(' ')'
2688/// [GNU] '__builtin_FUNCTION' '(' ')'
2689/// [MS] '__builtin_FUNCSIG' '(' ')'
2690/// [GNU] '__builtin_LINE' '(' ')'
2691/// [CLANG] '__builtin_COLUMN' '(' ')'
2692/// [GNU] '__builtin_source_location' '(' ')'
2693/// [OCL] '__builtin_astype' '(' assignment-expression ',' type-name ')'
2694///
2695/// [GNU] offsetof-member-designator:
2696/// [GNU] identifier
2697/// [GNU] offsetof-member-designator '.' identifier
2698/// [GNU] offsetof-member-designator '[' expression ']'
2699/// \endverbatim
2700ExprResult Parser::ParseBuiltinPrimaryExpression() {
2701 ExprResult Res;
2702 const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo();
2703
2704 tok::TokenKind T = Tok.getKind();
2705 SourceLocation StartLoc = ConsumeToken(); // Eat the builtin identifier.
2706
2707 // All of these start with an open paren.
2708 if (Tok.isNot(tok::l_paren))
2709 return ExprError(Diag(Tok, diag::err_expected_after) << BuiltinII
2710 << tok::l_paren);
2711
2712 BalancedDelimiterTracker PT(*this, tok::l_paren);
2713 PT.consumeOpen();
2714
2715 // TODO: Build AST.
2716
2717 switch (T) {
2718 default: llvm_unreachable("Not a builtin primary expression!");
2719 case tok::kw___builtin_va_arg: {
2721
2722 if (ExpectAndConsume(tok::comma)) {
2723 SkipUntil(tok::r_paren, StopAtSemi);
2724 Expr = ExprError();
2725 }
2726
2728
2729 if (Tok.isNot(tok::r_paren)) {
2730 Diag(Tok, diag::err_expected) << tok::r_paren;
2731 Expr = ExprError();
2732 }
2733
2734 if (Expr.isInvalid() || Ty.isInvalid())
2735 Res = ExprError();
2736 else
2737 Res = Actions.ActOnVAArg(StartLoc, Expr.get(), Ty.get(), ConsumeParen());
2738 break;
2739 }
2740 case tok::kw___builtin_offsetof: {
2743 if (Tok.getLocation().isMacroID()) {
2744 StringRef MacroName = Lexer::getImmediateMacroNameForDiagnostics(
2746 if (MacroName == "offsetof")
2748 }
2749 TypeResult Ty;
2750 {
2751 OffsetOfStateRAIIObject InOffsetof(*this, OOK);
2752 Ty = ParseTypeName();
2753 if (Ty.isInvalid()) {
2754 SkipUntil(tok::r_paren, StopAtSemi);
2755 return ExprError();
2756 }
2757 }
2758
2759 if (ExpectAndConsume(tok::comma)) {
2760 SkipUntil(tok::r_paren, StopAtSemi);
2761 return ExprError();
2762 }
2763
2764 // We must have at least one identifier here.
2765 if (Tok.isNot(tok::identifier)) {
2766 Diag(Tok, diag::err_expected) << tok::identifier;
2767 SkipUntil(tok::r_paren, StopAtSemi);
2768 return ExprError();
2769 }
2770
2771 // Keep track of the various subcomponents we see.
2773
2774 Comps.push_back(Sema::OffsetOfComponent());
2775 Comps.back().isBrackets = false;
2776 Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
2777 Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken();
2778
2779 // FIXME: This loop leaks the index expressions on error.
2780 while (true) {
2781 if (Tok.is(tok::period)) {
2782 // offsetof-member-designator: offsetof-member-designator '.' identifier
2783 Comps.push_back(Sema::OffsetOfComponent());
2784 Comps.back().isBrackets = false;
2785 Comps.back().LocStart = ConsumeToken();
2786
2787 if (Tok.isNot(tok::identifier)) {
2788 Diag(Tok, diag::err_expected) << tok::identifier;
2789 SkipUntil(tok::r_paren, StopAtSemi);
2790 return ExprError();
2791 }
2792 Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
2793 Comps.back().LocEnd = ConsumeToken();
2794 } else if (Tok.is(tok::l_square)) {
2795 if (CheckProhibitedCXX11Attribute())
2796 return ExprError();
2797
2798 // offsetof-member-designator: offsetof-member-design '[' expression ']'
2799 Comps.push_back(Sema::OffsetOfComponent());
2800 Comps.back().isBrackets = true;
2801 BalancedDelimiterTracker ST(*this, tok::l_square);
2802 ST.consumeOpen();
2803 Comps.back().LocStart = ST.getOpenLocation();
2804 Res = ParseExpression();
2805 if (Res.isInvalid()) {
2806 SkipUntil(tok::r_paren, StopAtSemi);
2807 return Res;
2808 }
2809 Comps.back().U.E = Res.get();
2810
2811 ST.consumeClose();
2812 Comps.back().LocEnd = ST.getCloseLocation();
2813 } else {
2814 if (Tok.isNot(tok::r_paren)) {
2815 PT.consumeClose();
2816 Res = ExprError();
2817 } else if (Ty.isInvalid()) {
2818 Res = ExprError();
2819 } else {
2820 PT.consumeClose();
2821 Res = Actions.ActOnBuiltinOffsetOf(getCurScope(), StartLoc, TypeLoc,
2822 Ty.get(), Comps,
2823 PT.getCloseLocation());
2824 }
2825 break;
2826 }
2827 }
2828 break;
2829 }
2830 case tok::kw___builtin_choose_expr: {
2832 if (Cond.isInvalid()) {
2833 SkipUntil(tok::r_paren, StopAtSemi);
2834 return Cond;
2835 }
2836 if (ExpectAndConsume(tok::comma)) {
2837 SkipUntil(tok::r_paren, StopAtSemi);
2838 return ExprError();
2839 }
2840
2842 if (Expr1.isInvalid()) {
2843 SkipUntil(tok::r_paren, StopAtSemi);
2844 return Expr1;
2845 }
2846 if (ExpectAndConsume(tok::comma)) {
2847 SkipUntil(tok::r_paren, StopAtSemi);
2848 return ExprError();
2849 }
2850
2852 if (Expr2.isInvalid()) {
2853 SkipUntil(tok::r_paren, StopAtSemi);
2854 return Expr2;
2855 }
2856 if (Tok.isNot(tok::r_paren)) {
2857 Diag(Tok, diag::err_expected) << tok::r_paren;
2858 return ExprError();
2859 }
2860 Res = Actions.ActOnChooseExpr(StartLoc, Cond.get(), Expr1.get(),
2861 Expr2.get(), ConsumeParen());
2862 break;
2863 }
2864 case tok::kw___builtin_astype: {
2865 // The first argument is an expression to be converted, followed by a comma.
2867 if (Expr.isInvalid()) {
2868 SkipUntil(tok::r_paren, StopAtSemi);
2869 return ExprError();
2870 }
2871
2872 if (ExpectAndConsume(tok::comma)) {
2873 SkipUntil(tok::r_paren, StopAtSemi);
2874 return ExprError();
2875 }
2876
2877 // Second argument is the type to bitcast to.
2878 TypeResult DestTy = ParseTypeName();
2879 if (DestTy.isInvalid())
2880 return ExprError();
2881
2882 // Attempt to consume the r-paren.
2883 if (Tok.isNot(tok::r_paren)) {
2884 Diag(Tok, diag::err_expected) << tok::r_paren;
2885 SkipUntil(tok::r_paren, StopAtSemi);
2886 return ExprError();
2887 }
2888
2889 Res = Actions.ActOnAsTypeExpr(Expr.get(), DestTy.get(), StartLoc,
2890 ConsumeParen());
2891 break;
2892 }
2893 case tok::kw___builtin_convertvector: {
2894 // The first argument is an expression to be converted, followed by a comma.
2896 if (Expr.isInvalid()) {
2897 SkipUntil(tok::r_paren, StopAtSemi);
2898 return ExprError();
2899 }
2900
2901 if (ExpectAndConsume(tok::comma)) {
2902 SkipUntil(tok::r_paren, StopAtSemi);
2903 return ExprError();
2904 }
2905
2906 // Second argument is the type to bitcast to.
2907 TypeResult DestTy = ParseTypeName();
2908 if (DestTy.isInvalid())
2909 return ExprError();
2910
2911 // Attempt to consume the r-paren.
2912 if (Tok.isNot(tok::r_paren)) {
2913 Diag(Tok, diag::err_expected) << tok::r_paren;
2914 SkipUntil(tok::r_paren, StopAtSemi);
2915 return ExprError();
2916 }
2917
2918 Res = Actions.ActOnConvertVectorExpr(Expr.get(), DestTy.get(), StartLoc,
2919 ConsumeParen());
2920 break;
2921 }
2922 case tok::kw___builtin_COLUMN:
2923 case tok::kw___builtin_FILE:
2924 case tok::kw___builtin_FILE_NAME:
2925 case tok::kw___builtin_FUNCTION:
2926 case tok::kw___builtin_FUNCSIG:
2927 case tok::kw___builtin_LINE:
2928 case tok::kw___builtin_source_location: {
2929 // Attempt to consume the r-paren.
2930 if (Tok.isNot(tok::r_paren)) {
2931 Diag(Tok, diag::err_expected) << tok::r_paren;
2932 SkipUntil(tok::r_paren, StopAtSemi);
2933 return ExprError();
2934 }
2935 SourceLocIdentKind Kind = [&] {
2936 switch (T) {
2937 case tok::kw___builtin_FILE:
2939 case tok::kw___builtin_FILE_NAME:
2941 case tok::kw___builtin_FUNCTION:
2943 case tok::kw___builtin_FUNCSIG:
2945 case tok::kw___builtin_LINE:
2947 case tok::kw___builtin_COLUMN:
2949 case tok::kw___builtin_source_location:
2951 default:
2952 llvm_unreachable("invalid keyword");
2953 }
2954 }();
2955 Res = Actions.ActOnSourceLocExpr(Kind, StartLoc, ConsumeParen());
2956 break;
2957 }
2958 }
2959
2960 if (Res.isInvalid())
2961 return ExprError();
2962
2963 // These can be followed by postfix-expr pieces because they are
2964 // primary-expressions.
2965 return ParsePostfixExpressionSuffix(Res.get());
2966}
2967
2968bool Parser::tryParseOpenMPArrayShapingCastPart() {
2969 assert(Tok.is(tok::l_square) && "Expected open bracket");
2970 bool ErrorFound = true;
2971 TentativeParsingAction TPA(*this);
2972 do {
2973 if (Tok.isNot(tok::l_square))
2974 break;
2975 // Consume '['
2976 ConsumeBracket();
2977 // Skip inner expression.
2978 while (!SkipUntil(tok::r_square, tok::annot_pragma_openmp_end,
2980 ;
2981 if (Tok.isNot(tok::r_square))
2982 break;
2983 // Consume ']'
2984 ConsumeBracket();
2985 // Found ')' - done.
2986 if (Tok.is(tok::r_paren)) {
2987 ErrorFound = false;
2988 break;
2989 }
2990 } while (Tok.isNot(tok::annot_pragma_openmp_end));
2991 TPA.Revert();
2992 return !ErrorFound;
2993}
2994
2995/// ParseParenExpression - This parses the unit that starts with a '(' token,
2996/// based on what is allowed by ExprType. The actual thing parsed is returned
2997/// in ExprType. If stopIfCastExpr is true, it will only return the parsed type,
2998/// not the parsed cast-expression.
2999///
3000/// \verbatim
3001/// primary-expression: [C99 6.5.1]
3002/// '(' expression ')'
3003/// [GNU] '(' compound-statement ')' (if !ParenExprOnly)
3004/// postfix-expression: [C99 6.5.2]
3005/// '(' type-name ')' '{' initializer-list '}'
3006/// '(' type-name ')' '{' initializer-list ',' '}'
3007/// cast-expression: [C99 6.5.4]
3008/// '(' type-name ')' cast-expression
3009/// [ARC] bridged-cast-expression
3010/// [ARC] bridged-cast-expression:
3011/// (__bridge type-name) cast-expression
3012/// (__bridge_transfer type-name) cast-expression
3013/// (__bridge_retained type-name) cast-expression
3014/// fold-expression: [C++1z]
3015/// '(' cast-expression fold-operator '...' ')'
3016/// '(' '...' fold-operator cast-expression ')'
3017/// '(' cast-expression fold-operator '...'
3018/// fold-operator cast-expression ')'
3019/// [OPENMP] Array shaping operation
3020/// '(' '[' expression ']' { '[' expression ']' } cast-expression
3021/// \endverbatim
3023Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
3024 bool isTypeCast, ParsedType &CastTy,
3025 SourceLocation &RParenLoc) {
3026 assert(Tok.is(tok::l_paren) && "Not a paren expr!");
3027 ColonProtectionRAIIObject ColonProtection(*this, false);
3028 BalancedDelimiterTracker T(*this, tok::l_paren);
3029 if (T.consumeOpen())
3030 return ExprError();
3031 SourceLocation OpenLoc = T.getOpenLocation();
3032
3033 PreferredType.enterParenExpr(Tok.getLocation(), OpenLoc);
3034
3035 ExprResult Result(true);
3036 bool isAmbiguousTypeId;
3037 CastTy = nullptr;
3038
3039 if (Tok.is(tok::code_completion)) {
3040 cutOffParsing();
3042 getCurScope(), PreferredType.get(Tok.getLocation()),
3043 /*IsParenthesized=*/ExprType >= CompoundLiteral);
3044 return ExprError();
3045 }
3046
3047 // Diagnose use of bridge casts in non-arc mode.
3048 bool BridgeCast = (getLangOpts().ObjC &&
3049 Tok.isOneOf(tok::kw___bridge,
3050 tok::kw___bridge_transfer,
3051 tok::kw___bridge_retained,
3052 tok::kw___bridge_retain));
3053 if (BridgeCast && !getLangOpts().ObjCAutoRefCount) {
3054 if (!TryConsumeToken(tok::kw___bridge)) {
3055 StringRef BridgeCastName = Tok.getName();
3056 SourceLocation BridgeKeywordLoc = ConsumeToken();
3057 if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
3058 Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc)
3059 << BridgeCastName
3060 << FixItHint::CreateReplacement(BridgeKeywordLoc, "");
3061 }
3062 BridgeCast = false;
3063 }
3064
3065 // None of these cases should fall through with an invalid Result
3066 // unless they've already reported an error.
3067 if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
3068 Diag(Tok, OpenLoc.isMacroID() ? diag::ext_gnu_statement_expr_macro
3069 : diag::ext_gnu_statement_expr);
3070
3071 checkCompoundToken(OpenLoc, tok::l_paren, CompoundToken::StmtExprBegin);
3072
3073 if (!getCurScope()->getFnParent() && !getCurScope()->getBlockParent()) {
3074 Result = ExprError(Diag(OpenLoc, diag::err_stmtexpr_file_scope));
3075 } else {
3076 // Find the nearest non-record decl context. Variables declared in a
3077 // statement expression behave as if they were declared in the enclosing
3078 // function, block, or other code construct.
3079 DeclContext *CodeDC = Actions.CurContext;
3080 while (CodeDC->isRecord() || isa<EnumDecl>(CodeDC)) {
3081 CodeDC = CodeDC->getParent();
3082 assert(CodeDC && !CodeDC->isFileContext() &&
3083 "statement expr not in code context");
3084 }
3085 Sema::ContextRAII SavedContext(Actions, CodeDC, /*NewThisContext=*/false);
3086
3087 Actions.ActOnStartStmtExpr();
3088
3089 StmtResult Stmt(ParseCompoundStatement(true));
3090 ExprType = CompoundStmt;
3091
3092 // If the substmt parsed correctly, build the AST node.
3093 if (!Stmt.isInvalid()) {
3094 Result = Actions.ActOnStmtExpr(getCurScope(), OpenLoc, Stmt.get(),
3095 Tok.getLocation());
3096 } else {
3097 Actions.ActOnStmtExprError();
3098 }
3099 }
3100 } else if (ExprType >= CompoundLiteral && BridgeCast) {
3101 tok::TokenKind tokenKind = Tok.getKind();
3102 SourceLocation BridgeKeywordLoc = ConsumeToken();
3103
3104 // Parse an Objective-C ARC ownership cast expression.
3106 if (tokenKind == tok::kw___bridge)
3107 Kind = OBC_Bridge;
3108 else if (tokenKind == tok::kw___bridge_transfer)
3110 else if (tokenKind == tok::kw___bridge_retained)
3112 else {
3113 // As a hopefully temporary workaround, allow __bridge_retain as
3114 // a synonym for __bridge_retained, but only in system headers.
3115 assert(tokenKind == tok::kw___bridge_retain);
3117 if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
3118 Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain)
3119 << FixItHint::CreateReplacement(BridgeKeywordLoc,
3120 "__bridge_retained");
3121 }
3122
3124 T.consumeClose();
3125 ColonProtection.restore();
3126 RParenLoc = T.getCloseLocation();
3127
3128 PreferredType.enterTypeCast(Tok.getLocation(), Ty.get().get());
3129 ExprResult SubExpr = ParseCastExpression(AnyCastExpr);
3130
3131 if (Ty.isInvalid() || SubExpr.isInvalid())
3132 return ExprError();
3133
3134 return Actions.ObjC().ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind,
3135 BridgeKeywordLoc, Ty.get(),
3136 RParenLoc, SubExpr.get());
3137 } else if (ExprType >= CompoundLiteral &&
3138 isTypeIdInParens(isAmbiguousTypeId)) {
3139
3140 // Otherwise, this is a compound literal expression or cast expression.
3141
3142 // In C++, if the type-id is ambiguous we disambiguate based on context.
3143 // If stopIfCastExpr is true the context is a typeof/sizeof/alignof
3144 // in which case we should treat it as type-id.
3145 // if stopIfCastExpr is false, we need to determine the context past the
3146 // parens, so we defer to ParseCXXAmbiguousParenExpression for that.
3147 if (isAmbiguousTypeId && !stopIfCastExpr) {
3148 ExprResult res = ParseCXXAmbiguousParenExpression(ExprType, CastTy, T,
3149 ColonProtection);
3150 RParenLoc = T.getCloseLocation();
3151 return res;
3152 }
3153
3154 // Parse the type declarator.
3155 DeclSpec DS(AttrFactory);
3156 ParseSpecifierQualifierList(DS);
3157 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
3159 ParseDeclarator(DeclaratorInfo);
3160
3161 // If our type is followed by an identifier and either ':' or ']', then
3162 // this is probably an Objective-C message send where the leading '[' is
3163 // missing. Recover as if that were the case.
3164 if (!DeclaratorInfo.isInvalidType() && Tok.is(tok::identifier) &&
3165 !InMessageExpression && getLangOpts().ObjC &&
3166 (NextToken().is(tok::colon) || NextToken().is(tok::r_square))) {
3167 TypeResult Ty;
3168 {
3169 InMessageExpressionRAIIObject InMessage(*this, false);
3170 Ty = Actions.ActOnTypeName(DeclaratorInfo);
3171 }
3172 Result = ParseObjCMessageExpressionBody(SourceLocation(),
3174 Ty.get(), nullptr);
3175 } else {
3176 // Match the ')'.
3177 T.consumeClose();
3178 ColonProtection.restore();
3179 RParenLoc = T.getCloseLocation();
3180 if (Tok.is(tok::l_brace)) {
3181 ExprType = CompoundLiteral;
3182 TypeResult Ty;
3183 {
3184 InMessageExpressionRAIIObject InMessage(*this, false);
3185 Ty = Actions.ActOnTypeName(DeclaratorInfo);
3186 }
3187 return ParseCompoundLiteralExpression(Ty.get(), OpenLoc, RParenLoc);
3188 }
3189
3190 if (Tok.is(tok::l_paren)) {
3191 // This could be OpenCL vector Literals
3192 if (getLangOpts().OpenCL)
3193 {
3194 TypeResult Ty;
3195 {
3196 InMessageExpressionRAIIObject InMessage(*this, false);
3197 Ty = Actions.ActOnTypeName(DeclaratorInfo);
3198 }
3199 if(Ty.isInvalid())
3200 {
3201 return ExprError();
3202 }
3203 QualType QT = Ty.get().get().getCanonicalType();
3204 if (QT->isVectorType())
3205 {
3206 // We parsed '(' vector-type-name ')' followed by '('
3207
3208 // Parse the cast-expression that follows it next.
3209 // isVectorLiteral = true will make sure we don't parse any
3210 // Postfix expression yet
3211 Result = ParseCastExpression(/*isUnaryExpression=*/AnyCastExpr,
3212 /*isAddressOfOperand=*/false,
3213 /*isTypeCast=*/IsTypeCast,
3214 /*isVectorLiteral=*/true);
3215
3216 if (!Result.isInvalid()) {
3217 Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
3218 DeclaratorInfo, CastTy,
3219 RParenLoc, Result.get());
3220 }
3221
3222 // After we performed the cast we can check for postfix-expr pieces.
3223 if (!Result.isInvalid()) {
3224 Result = ParsePostfixExpressionSuffix(Result);
3225 }
3226
3227 return Result;
3228 }
3229 }
3230 }
3231
3232 if (ExprType == CastExpr) {
3233 // We parsed '(' type-name ')' and the thing after it wasn't a '{'.
3234
3235 if (DeclaratorInfo.isInvalidType())
3236 return ExprError();
3237
3238 // Note that this doesn't parse the subsequent cast-expression, it just
3239 // returns the parsed type to the callee.
3240 if (stopIfCastExpr) {
3241 TypeResult Ty;
3242 {
3243 InMessageExpressionRAIIObject InMessage(*this, false);
3244 Ty = Actions.ActOnTypeName(DeclaratorInfo);
3245 }
3246 CastTy = Ty.get();
3247 return ExprResult();
3248 }
3249
3250 // Reject the cast of super idiom in ObjC.
3251 if (Tok.is(tok::identifier) && getLangOpts().ObjC &&
3252 Tok.getIdentifierInfo() == Ident_super &&
3253 getCurScope()->isInObjcMethodScope() &&
3254 GetLookAheadToken(1).isNot(tok::period)) {
3255 Diag(Tok.getLocation(), diag::err_illegal_super_cast)
3256 << SourceRange(OpenLoc, RParenLoc);
3257 return ExprError();
3258 }
3259
3260 PreferredType.enterTypeCast(Tok.getLocation(), CastTy.get());
3261 // Parse the cast-expression that follows it next.
3262 // TODO: For cast expression with CastTy.
3263 Result = ParseCastExpression(/*isUnaryExpression=*/AnyCastExpr,
3264 /*isAddressOfOperand=*/false,
3265 /*isTypeCast=*/IsTypeCast);
3266 if (!Result.isInvalid()) {
3267 Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
3268 DeclaratorInfo, CastTy,
3269 RParenLoc, Result.get());
3270 }
3271 return Result;
3272 }
3273
3274 Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
3275 return ExprError();
3276 }
3277 } else if (ExprType >= FoldExpr && Tok.is(tok::ellipsis) &&
3278 isFoldOperator(NextToken().getKind())) {
3279 ExprType = FoldExpr;
3280 return ParseFoldExpression(ExprResult(), T);
3281 } else if (isTypeCast) {
3282 // Parse the expression-list.
3283 InMessageExpressionRAIIObject InMessage(*this, false);
3284 ExprVector ArgExprs;
3285
3286 if (!ParseSimpleExpressionList(ArgExprs)) {
3287 // FIXME: If we ever support comma expressions as operands to
3288 // fold-expressions, we'll need to allow multiple ArgExprs here.
3289 if (ExprType >= FoldExpr && ArgExprs.size() == 1 &&
3290 isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis)) {
3291 ExprType = FoldExpr;
3292 return ParseFoldExpression(ArgExprs[0], T);
3293 }
3294
3295 ExprType = SimpleExpr;
3296 Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
3297 ArgExprs);
3298 }
3299 } else if (getLangOpts().OpenMP >= 50 && OpenMPDirectiveParsing &&
3300 ExprType == CastExpr && Tok.is(tok::l_square) &&
3301 tryParseOpenMPArrayShapingCastPart()) {
3302 bool ErrorFound = false;
3303 SmallVector<Expr *, 4> OMPDimensions;
3304 SmallVector<SourceRange, 4> OMPBracketsRanges;
3305 do {
3306 BalancedDelimiterTracker TS(*this, tok::l_square);
3307 TS.consumeOpen();
3308 ExprResult NumElements =
3310 if (!NumElements.isUsable()) {
3311 ErrorFound = true;
3312 while (!SkipUntil(tok::r_square, tok::r_paren,
3314 ;
3315 }
3316 TS.consumeClose();
3317 OMPDimensions.push_back(NumElements.get());
3318 OMPBracketsRanges.push_back(TS.getRange());
3319 } while (Tok.isNot(tok::r_paren));
3320 // Match the ')'.
3321 T.consumeClose();
3322 RParenLoc = T.getCloseLocation();
3324 if (ErrorFound) {
3325 Result = ExprError();
3326 } else if (!Result.isInvalid()) {
3328 Result.get(), OpenLoc, RParenLoc, OMPDimensions, OMPBracketsRanges);
3329 }
3330 return Result;
3331 } else {
3332 InMessageExpressionRAIIObject InMessage(*this, false);
3333
3335 if (!getLangOpts().CPlusPlus && Result.isUsable()) {
3336 // Correct typos in non-C++ code earlier so that implicit-cast-like
3337 // expressions are parsed correctly.
3339 }
3340
3341 if (ExprType >= FoldExpr && isFoldOperator(Tok.getKind()) &&
3342 NextToken().is(tok::ellipsis)) {
3343 ExprType = FoldExpr;
3344 return ParseFoldExpression(Result, T);
3345 }
3346 ExprType = SimpleExpr;
3347
3348 // Don't build a paren expression unless we actually match a ')'.
3349 if (!Result.isInvalid() && Tok.is(tok::r_paren))
3350 Result =
3351 Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.get());
3352 }
3353
3354 // Match the ')'.
3355 if (Result.isInvalid()) {
3356 SkipUntil(tok::r_paren, StopAtSemi);
3357 return ExprError();
3358 }
3359
3360 T.consumeClose();
3361 RParenLoc = T.getCloseLocation();
3362 return Result;
3363}
3364
3365/// ParseCompoundLiteralExpression - We have parsed the parenthesized type-name
3366/// and we are at the left brace.
3367///
3368/// \verbatim
3369/// postfix-expression: [C99 6.5.2]
3370/// '(' type-name ')' '{' initializer-list '}'
3371/// '(' type-name ')' '{' initializer-list ',' '}'
3372/// \endverbatim
3374Parser::ParseCompoundLiteralExpression(ParsedType Ty,
3375 SourceLocation LParenLoc,
3376 SourceLocation RParenLoc) {
3377 assert(Tok.is(tok::l_brace) && "Not a compound literal!");
3378 if (!getLangOpts().C99) // Compound literals don't exist in C90.
3379 Diag(LParenLoc, diag::ext_c99_compound_literal);
3380 PreferredType.enterTypeCast(Tok.getLocation(), Ty.get());
3381 ExprResult Result = ParseInitializer();
3382 if (!Result.isInvalid() && Ty)
3383 return Actions.ActOnCompoundLiteral(LParenLoc, Ty, RParenLoc, Result.get());
3384 return Result;
3385}
3386
3387/// ParseStringLiteralExpression - This handles the various token types that
3388/// form string literals, and also handles string concatenation [C99 5.1.1.2,
3389/// translation phase #6].
3390///
3391/// \verbatim
3392/// primary-expression: [C99 6.5.1]
3393/// string-literal
3394/// \verbatim
3395ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral) {
3396 return ParseStringLiteralExpression(AllowUserDefinedLiteral,
3397 /*Unevaluated=*/false);
3398}
3399
3401 return ParseStringLiteralExpression(/*AllowUserDefinedLiteral=*/false,
3402 /*Unevaluated=*/true);
3403}
3404
3405ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral,
3406 bool Unevaluated) {
3407 assert(tokenIsLikeStringLiteral(Tok, getLangOpts()) &&
3408 "Not a string-literal-like token!");
3409
3410 // String concatenation.
3411 // Note: some keywords like __FUNCTION__ are not considered to be strings
3412 // for concatenation purposes, unless Microsoft extensions are enabled.
3413 SmallVector<Token, 4> StringToks;
3414
3415 do {
3416 StringToks.push_back(Tok);
3418 } while (tokenIsLikeStringLiteral(Tok, getLangOpts()));
3419
3420 if (Unevaluated) {
3421 assert(!AllowUserDefinedLiteral && "UDL are always evaluated");
3422 return Actions.ActOnUnevaluatedStringLiteral(StringToks);
3423 }
3424
3425 // Pass the set of string tokens, ready for concatenation, to the actions.
3426 return Actions.ActOnStringLiteral(StringToks,
3427 AllowUserDefinedLiteral ? getCurScope()
3428 : nullptr);
3429}
3430
3431/// ParseGenericSelectionExpression - Parse a C11 generic-selection
3432/// [C11 6.5.1.1].
3433///
3434/// \verbatim
3435/// generic-selection:
3436/// _Generic ( assignment-expression , generic-assoc-list )
3437/// generic-assoc-list:
3438/// generic-association
3439/// generic-assoc-list , generic-association
3440/// generic-association:
3441/// type-name : assignment-expression
3442/// default : assignment-expression
3443/// \endverbatim
3444///
3445/// As an extension, Clang also accepts:
3446/// \verbatim
3447/// generic-selection:
3448/// _Generic ( type-name, generic-assoc-list )
3449/// \endverbatim
3450ExprResult Parser::ParseGenericSelectionExpression() {
3451 assert(Tok.is(tok::kw__Generic) && "_Generic keyword expected");
3452
3453 diagnoseUseOfC11Keyword(Tok);
3454
3455 SourceLocation KeyLoc = ConsumeToken();
3456 BalancedDelimiterTracker T(*this, tok::l_paren);
3457 if (T.expectAndConsume())
3458 return ExprError();
3459
3460 // We either have a controlling expression or we have a controlling type, and
3461 // we need to figure out which it is.
3462 TypeResult ControllingType;
3463 ExprResult ControllingExpr;
3464 if (isTypeIdForGenericSelection()) {
3465 ControllingType = ParseTypeName();
3466 if (ControllingType.isInvalid()) {
3467 SkipUntil(tok::r_paren, StopAtSemi);
3468 return ExprError();
3469 }
3470 const auto *LIT = cast<LocInfoType>(ControllingType.get().get());
3471 SourceLocation Loc = LIT->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
3472 Diag(Loc, getLangOpts().C2y ? diag::warn_c2y_compat_generic_with_type_arg
3473 : diag::ext_c2y_generic_with_type_arg);
3474 } else {
3475 // C11 6.5.1.1p3 "The controlling expression of a generic selection is
3476 // not evaluated."
3479 ControllingExpr =
3481 if (ControllingExpr.isInvalid()) {
3482 SkipUntil(tok::r_paren, StopAtSemi);
3483 return ExprError();
3484 }
3485 }
3486
3487 if (ExpectAndConsume(tok::comma)) {
3488 SkipUntil(tok::r_paren, StopAtSemi);
3489 return ExprError();
3490 }
3491
3492 SourceLocation DefaultLoc;
3494 ExprVector Exprs;
3495 do {
3496 ParsedType Ty;
3497 if (Tok.is(tok::kw_default)) {
3498 // C11 6.5.1.1p2 "A generic selection shall have no more than one default
3499 // generic association."
3500 if (!DefaultLoc.isInvalid()) {
3501 Diag(Tok, diag::err_duplicate_default_assoc);
3502 Diag(DefaultLoc, diag::note_previous_default_assoc);
3503 SkipUntil(tok::r_paren, StopAtSemi);
3504 return ExprError();
3505 }
3506 DefaultLoc = ConsumeToken();
3507 Ty = nullptr;
3508 } else {
3511 if (TR.isInvalid()) {
3512 SkipUntil(tok::r_paren, StopAtSemi);
3513 return ExprError();
3514 }
3515 Ty = TR.get();
3516 }
3517 Types.push_back(Ty);
3518
3519 if (ExpectAndConsume(tok::colon)) {
3520 SkipUntil(tok::r_paren, StopAtSemi);
3521 return ExprError();
3522 }
3523
3524 // FIXME: These expressions should be parsed in a potentially potentially
3525 // evaluated context.
3526 ExprResult ER(
3528 if (ER.isInvalid()) {
3529 SkipUntil(tok::r_paren, StopAtSemi);
3530 return ExprError();
3531 }
3532 Exprs.push_back(ER.get());
3533 } while (TryConsumeToken(tok::comma));
3534
3535 T.consumeClose();
3536 if (T.getCloseLocation().isInvalid())
3537 return ExprError();
3538
3539 void *ExprOrTy = ControllingExpr.isUsable()
3540 ? ControllingExpr.get()
3541 : ControllingType.get().getAsOpaquePtr();
3542
3543 return Actions.ActOnGenericSelectionExpr(
3544 KeyLoc, DefaultLoc, T.getCloseLocation(), ControllingExpr.isUsable(),
3545 ExprOrTy, Types, Exprs);
3546}
3547
3548/// Parse A C++1z fold-expression after the opening paren and optional
3549/// left-hand-side expression.
3550///
3551/// \verbatim
3552/// fold-expression:
3553/// ( cast-expression fold-operator ... )
3554/// ( ... fold-operator cast-expression )
3555/// ( cast-expression fold-operator ... fold-operator cast-expression )
3556ExprResult Parser::ParseFoldExpression(ExprResult LHS,
3558 if (LHS.isInvalid()) {
3559 T.skipToEnd();
3560 return true;
3561 }
3562
3563 tok::TokenKind Kind = tok::unknown;
3564 SourceLocation FirstOpLoc;
3565 if (LHS.isUsable()) {
3566 Kind = Tok.getKind();
3567 assert(isFoldOperator(Kind) && "missing fold-operator");
3568 FirstOpLoc = ConsumeToken();
3569 }
3570
3571 assert(Tok.is(tok::ellipsis) && "not a fold-expression");
3572 SourceLocation EllipsisLoc = ConsumeToken();
3573
3574 ExprResult RHS;
3575 if (Tok.isNot(tok::r_paren)) {
3576 if (!isFoldOperator(Tok.getKind()))
3577 return Diag(Tok.getLocation(), diag::err_expected_fold_operator);
3578
3579 if (Kind != tok::unknown && Tok.getKind() != Kind)
3580 Diag(Tok.getLocation(), diag::err_fold_operator_mismatch)
3581 << SourceRange(FirstOpLoc);
3582 Kind = Tok.getKind();
3583 ConsumeToken();
3584
3585 RHS = ParseExpression();
3586 if (RHS.isInvalid()) {
3587 T.skipToEnd();
3588 return true;
3589 }
3590 }
3591
3592 Diag(EllipsisLoc, getLangOpts().CPlusPlus17
3593 ? diag::warn_cxx14_compat_fold_expression
3594 : diag::ext_fold_expression);
3595
3596 T.consumeClose();
3597 return Actions.ActOnCXXFoldExpr(getCurScope(), T.getOpenLocation(), LHS.get(),
3598 Kind, EllipsisLoc, RHS.get(),
3599 T.getCloseLocation());
3600}
3601
3602void Parser::injectEmbedTokens() {
3604 reinterpret_cast<EmbedAnnotationData *>(Tok.getAnnotationValue());
3606 Data->BinaryData.size() * 2 - 1),
3607 Data->BinaryData.size() * 2 - 1);
3608 unsigned I = 0;
3609 for (auto &Byte : Data->BinaryData) {
3610 Toks[I].startToken();
3611 Toks[I].setKind(tok::binary_data);
3612 Toks[I].setLocation(Tok.getLocation());
3613 Toks[I].setLength(1);
3614 Toks[I].setLiteralData(&Byte);
3615 if (I != ((Data->BinaryData.size() - 1) * 2)) {
3616 Toks[I + 1].startToken();
3617 Toks[I + 1].setKind(tok::comma);
3618 Toks[I + 1].setLocation(Tok.getLocation());
3619 }
3620 I += 2;
3621 }
3622 PP.EnterTokenStream(std::move(Toks), /*DisableMacroExpansion=*/true,
3623 /*IsReinject=*/true);
3624 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
3625}
3626
3627/// ParseExpressionList - Used for C/C++ (argument-)expression-list.
3628///
3629/// \verbatim
3630/// argument-expression-list:
3631/// assignment-expression
3632/// argument-expression-list , assignment-expression
3633///
3634/// [C++] expression-list:
3635/// [C++] assignment-expression
3636/// [C++] expression-list , assignment-expression
3637///
3638/// [C++0x] expression-list:
3639/// [C++0x] initializer-list
3640///
3641/// [C++0x] initializer-list
3642/// [C++0x] initializer-clause ...[opt]
3643/// [C++0x] initializer-list , initializer-clause ...[opt]
3644///
3645/// [C++0x] initializer-clause:
3646/// [C++0x] assignment-expression
3647/// [C++0x] braced-init-list
3648/// \endverbatim
3649bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
3650 llvm::function_ref<void()> ExpressionStarts,
3651 bool FailImmediatelyOnInvalidExpr,
3652 bool EarlyTypoCorrection) {
3653 bool SawError = false;
3654 while (true) {
3655 if (ExpressionStarts)
3656 ExpressionStarts();
3657
3659 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
3660 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3661 Expr = ParseBraceInitializer();
3662 } else
3664
3665 if (EarlyTypoCorrection)
3667
3668 if (Tok.is(tok::ellipsis))
3669 Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
3670 else if (Tok.is(tok::code_completion)) {
3671 // There's nothing to suggest in here as we parsed a full expression.
3672 // Instead fail and propagate the error since caller might have something
3673 // the suggest, e.g. signature help in function call. Note that this is
3674 // performed before pushing the \p Expr, so that signature help can report
3675 // current argument correctly.
3676 SawError = true;
3677 cutOffParsing();
3678 break;
3679 }
3680 if (Expr.isInvalid()) {
3681 SawError = true;
3682 if (FailImmediatelyOnInvalidExpr)
3683 break;
3684 SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
3685 } else {
3686 Exprs.push_back(Expr.get());
3687 }
3688
3689 if (Tok.isNot(tok::comma))
3690 break;
3691 // Move to the next argument, remember where the comma was.
3692 Token Comma = Tok;
3693 ConsumeToken();
3694 checkPotentialAngleBracketDelimiter(Comma);
3695 }
3696 if (SawError) {
3697 // Ensure typos get diagnosed when errors were encountered while parsing the
3698 // expression list.
3699 for (auto &E : Exprs) {
3701 if (Expr.isUsable()) E = Expr.get();
3702 }
3703 }
3704 return SawError;
3705}
3706
3707/// ParseSimpleExpressionList - A simple comma-separated list of expressions,
3708/// used for misc language extensions.
3709///
3710/// \verbatim
3711/// simple-expression-list:
3712/// assignment-expression
3713/// simple-expression-list , assignment-expression
3714/// \endverbatim
3715bool Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr *> &Exprs) {
3716 while (true) {
3718 if (Expr.isInvalid())
3719 return true;
3720
3721 Exprs.push_back(Expr.get());
3722
3723 // We might be parsing the LHS of a fold-expression. If we reached the fold
3724 // operator, stop.
3725 if (Tok.isNot(tok::comma) || NextToken().is(tok::ellipsis))
3726 return false;
3727
3728 // Move to the next argument, remember where the comma was.
3729 Token Comma = Tok;
3730 ConsumeToken();
3731 checkPotentialAngleBracketDelimiter(Comma);
3732 }
3733}
3734
3735/// ParseBlockId - Parse a block-id, which roughly looks like int (int x).
3736///
3737/// \verbatim
3738/// [clang] block-id:
3739/// [clang] specifier-qualifier-list block-declarator
3740/// \endverbatim
3741void Parser::ParseBlockId(SourceLocation CaretLoc) {
3742 if (Tok.is(tok::code_completion)) {
3743 cutOffParsing();
3746 return;
3747 }
3748
3749 // Parse the specifier-qualifier-list piece.
3750 DeclSpec DS(AttrFactory);
3751 ParseSpecifierQualifierList(DS);
3752
3753 // Parse the block-declarator.
3754 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
3756 DeclaratorInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition);
3757 ParseDeclarator(DeclaratorInfo);
3758
3759 MaybeParseGNUAttributes(DeclaratorInfo);
3760
3761 // Inform sema that we are starting a block.
3762 Actions.ActOnBlockArguments(CaretLoc, DeclaratorInfo, getCurScope());
3763}
3764
3765/// ParseBlockLiteralExpression - Parse a block literal, which roughly looks
3766/// like ^(int x){ return x+1; }
3767///
3768/// \verbatim
3769/// block-literal:
3770/// [clang] '^' block-args[opt] compound-statement
3771/// [clang] '^' block-id compound-statement
3772/// [clang] block-args:
3773/// [clang] '(' parameter-list ')'
3774/// \endverbatim
3775ExprResult Parser::ParseBlockLiteralExpression() {
3776 assert(Tok.is(tok::caret) && "block literal starts with ^");
3777 SourceLocation CaretLoc = ConsumeToken();
3778
3779 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), CaretLoc,
3780 "block literal parsing");
3781
3782 // Enter a scope to hold everything within the block. This includes the
3783 // argument decls, decls within the compound expression, etc. This also
3784 // allows determining whether a variable reference inside the block is
3785 // within or outside of the block.
3786 ParseScope BlockScope(this, Scope::BlockScope | Scope::FnScope |
3788
3789 // Inform sema that we are starting a block.
3790 Actions.ActOnBlockStart(CaretLoc, getCurScope());
3791
3792 // Parse the return type if present.
3793 DeclSpec DS(AttrFactory);
3794 Declarator ParamInfo(DS, ParsedAttributesView::none(),
3796 ParamInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition);
3797 // FIXME: Since the return type isn't actually parsed, it can't be used to
3798 // fill ParamInfo with an initial valid range, so do it manually.
3799 ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation()));
3800
3801 // If this block has arguments, parse them. There is no ambiguity here with
3802 // the expression case, because the expression case requires a parameter list.
3803 if (Tok.is(tok::l_paren)) {
3804 ParseParenDeclarator(ParamInfo);
3805 // Parse the pieces after the identifier as if we had "int(...)".
3806 // SetIdentifier sets the source range end, but in this case we're past
3807 // that location.
3808 SourceLocation Tmp = ParamInfo.getSourceRange().getEnd();
3809 ParamInfo.SetIdentifier(nullptr, CaretLoc);
3810 ParamInfo.SetRangeEnd(Tmp);
3811 if (ParamInfo.isInvalidType()) {
3812 // If there was an error parsing the arguments, they may have
3813 // tried to use ^(x+y) which requires an argument list. Just
3814 // skip the whole block literal.
3815 Actions.ActOnBlockError(CaretLoc, getCurScope());
3816 return ExprError();
3817 }
3818
3819 MaybeParseGNUAttributes(ParamInfo);
3820
3821 // Inform sema that we are starting a block.
3822 Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope());
3823 } else if (!Tok.is(tok::l_brace)) {
3824 ParseBlockId(CaretLoc);
3825 } else {
3826 // Otherwise, pretend we saw (void).
3827 SourceLocation NoLoc;
3828 ParamInfo.AddTypeInfo(
3829 DeclaratorChunk::getFunction(/*HasProto=*/true,
3830 /*IsAmbiguous=*/false,
3831 /*RParenLoc=*/NoLoc,
3832 /*ArgInfo=*/nullptr,
3833 /*NumParams=*/0,
3834 /*EllipsisLoc=*/NoLoc,
3835 /*RParenLoc=*/NoLoc,
3836 /*RefQualifierIsLvalueRef=*/true,
3837 /*RefQualifierLoc=*/NoLoc,
3838 /*MutableLoc=*/NoLoc, EST_None,
3839 /*ESpecRange=*/SourceRange(),
3840 /*Exceptions=*/nullptr,
3841 /*ExceptionRanges=*/nullptr,
3842 /*NumExceptions=*/0,
3843 /*NoexceptExpr=*/nullptr,
3844 /*ExceptionSpecTokens=*/nullptr,
3845 /*DeclsInPrototype=*/std::nullopt,
3846 CaretLoc, CaretLoc, ParamInfo),
3847 CaretLoc);
3848
3849 MaybeParseGNUAttributes(ParamInfo);
3850
3851 // Inform sema that we are starting a block.
3852 Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope());
3853 }
3854
3855
3856 ExprResult Result(true);
3857 if (!Tok.is(tok::l_brace)) {
3858 // Saw something like: ^expr
3859 Diag(Tok, diag::err_expected_expression);
3860 Actions.ActOnBlockError(CaretLoc, getCurScope());
3861 return ExprError();
3862 }
3863
3864 StmtResult Stmt(ParseCompoundStatementBody());
3865 BlockScope.Exit();
3866 if (!Stmt.isInvalid())
3867 Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.get(), getCurScope());
3868 else
3869 Actions.ActOnBlockError(CaretLoc, getCurScope());
3870 return Result;
3871}
3872
3873/// ParseObjCBoolLiteral - This handles the objective-c Boolean literals.
3874///
3875/// '__objc_yes'
3876/// '__objc_no'
3877ExprResult Parser::ParseObjCBoolLiteral() {
3878 tok::TokenKind Kind = Tok.getKind();
3879 return Actions.ObjC().ActOnObjCBoolLiteral(ConsumeToken(), Kind);
3880}
3881
3882/// Validate availability spec list, emitting diagnostics if necessary. Returns
3883/// true if invalid.
3885 ArrayRef<AvailabilitySpec> AvailSpecs) {
3886 llvm::SmallSet<StringRef, 4> Platforms;
3887 bool HasOtherPlatformSpec = false;
3888 bool Valid = true;
3889 for (const auto &Spec : AvailSpecs) {
3890 if (Spec.isOtherPlatformSpec()) {
3891 if (HasOtherPlatformSpec) {
3892 P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_star);
3893 Valid = false;
3894 }
3895
3896 HasOtherPlatformSpec = true;
3897 continue;
3898 }
3899
3900 bool Inserted = Platforms.insert(Spec.getPlatform()).second;
3901 if (!Inserted) {
3902 // Rule out multiple version specs referring to the same platform.
3903 // For example, we emit an error for:
3904 // @available(macos 10.10, macos 10.11, *)
3905 StringRef Platform = Spec.getPlatform();
3906 P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_platform)
3907 << Spec.getEndLoc() << Platform;
3908 Valid = false;
3909 }
3910 }
3911
3912 if (!HasOtherPlatformSpec) {
3913 SourceLocation InsertWildcardLoc = AvailSpecs.back().getEndLoc();
3914 P.Diag(InsertWildcardLoc, diag::err_availability_query_wildcard_required)
3915 << FixItHint::CreateInsertion(InsertWildcardLoc, ", *");
3916 return true;
3917 }
3918
3919 return !Valid;
3920}
3921
3922/// Parse availability query specification.
3923///
3924/// availability-spec:
3925/// '*'
3926/// identifier version-tuple
3927std::optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() {
3928 if (Tok.is(tok::star)) {
3930 } else {
3931 // Parse the platform name.
3932 if (Tok.is(tok::code_completion)) {
3933 cutOffParsing();
3935 return std::nullopt;
3936 }
3937 if (Tok.isNot(tok::identifier)) {
3938 Diag(Tok, diag::err_avail_query_expected_platform_name);
3939 return std::nullopt;
3940 }
3941
3942 IdentifierLoc *PlatformIdentifier = ParseIdentifierLoc();
3943 SourceRange VersionRange;
3944 VersionTuple Version = ParseVersionTuple(VersionRange);
3945
3946 if (Version.empty())
3947 return std::nullopt;
3948
3949 StringRef GivenPlatform = PlatformIdentifier->Ident->getName();
3950 StringRef Platform =
3951 AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
3952
3953 if (AvailabilityAttr::getPrettyPlatformName(Platform).empty() ||
3954 (GivenPlatform.contains("xros") || GivenPlatform.contains("xrOS"))) {
3955 Diag(PlatformIdentifier->Loc,
3956 diag::err_avail_query_unrecognized_platform_name)
3957 << GivenPlatform;
3958 return std::nullopt;
3959 }
3960
3961 return AvailabilitySpec(Version, Platform, PlatformIdentifier->Loc,
3962 VersionRange.getEnd());
3963 }
3964}
3965
3966ExprResult Parser::ParseAvailabilityCheckExpr(SourceLocation BeginLoc) {
3967 assert(Tok.is(tok::kw___builtin_available) ||
3968 Tok.isObjCAtKeyword(tok::objc_available));
3969
3970 // Eat the available or __builtin_available.
3971 ConsumeToken();
3972
3973 BalancedDelimiterTracker Parens(*this, tok::l_paren);
3974 if (Parens.expectAndConsume())
3975 return ExprError();
3976
3978 bool HasError = false;
3979 while (true) {
3980 std::optional<AvailabilitySpec> Spec = ParseAvailabilitySpec();
3981 if (!Spec)
3982 HasError = true;
3983 else
3984 AvailSpecs.push_back(*Spec);
3985
3986 if (!TryConsumeToken(tok::comma))
3987 break;
3988 }
3989
3990 if (HasError) {
3991 SkipUntil(tok::r_paren, StopAtSemi);
3992 return ExprError();
3993 }
3994
3995 CheckAvailabilitySpecList(*this, AvailSpecs);
3996
3997 if (Parens.consumeClose())
3998 return ExprError();
3999
4000 return Actions.ObjC().ActOnObjCAvailabilityCheckExpr(
4001 AvailSpecs, BeginLoc, Parens.getCloseLocation());
4002}
Defines the clang::ASTContext interface.
StringRef P
#define SM(sm)
Definition: Cuda.cpp:83
Expr * E
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1152
Defines the clang::Expr interface and subclasses for C++ expressions.
#define X(type, name)
Definition: Value.h:143
static bool CheckAvailabilitySpecList(Parser &P, ArrayRef< AvailabilitySpec > AvailSpecs)
Validate availability spec list, emitting diagnostics if necessary.
Definition: ParseExpr.cpp:3884
#define REVERTIBLE_TYPE_TRAIT(Name)
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
uint32_t Id
Definition: SemaARM.cpp:1143
This file declares semantic analysis for CUDA constructs.
This file declares facilities that support code completion.
SourceLocation Loc
Definition: SemaObjC.cpp:758
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenACC constructs and clauses.
This file declares semantic analysis for OpenMP constructs and clauses.
This file declares semantic analysis for SYCL constructs.
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:712
bool isUnset() const
Definition: Ownership.h:167
PtrTy get() const
Definition: Ownership.h:170
bool isInvalid() const
Definition: Ownership.h:166
bool isUsable() const
Definition: Ownership.h:168
One specifier in an @available expression.
Definition: Availability.h:31
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:74
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
Definition: DeclSpec.h:210
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3498
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1606
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1425
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2079
bool isFileContext() const
Definition: DeclBase.h:2150
bool isRecord() const
Definition: DeclBase.h:2159
Captures information about "declaration specifiers".
Definition: DeclSpec.h:247
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1900
RAII object that enters a new expression evaluation context.
This represents one expression.
Definition: Expr.h:110
bool containsErrors() const
Whether this expression contains subexpressions which had errors, e.g.
Definition: Expr.h:245
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Definition: Diagnostic.h:134
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:123
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:97
One of these records is kept for each identifier that is lexed.
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
StringRef getName() const
Return the actual identifier string.
Represents the declaration of a label.
Definition: Decl.h:499
static StringRef getImmediateMacroNameForDiagnostics(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
Retrieve the name of the immediate macro expansion.
Definition: Lexer.cpp:1107
This represents a decl that may have a name.
Definition: Decl.h:249
void * getAsOpaquePtr() const
Definition: Ownership.h:90
PtrTy get() const
Definition: Ownership.h:80
static const ParsedAttributesView & none()
Definition: ParsedAttr.h:838
Parser - This implements a parser for the C family of languages.
Definition: Parser.h:58
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Definition: ParseDecl.cpp:50
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Definition: Parser.cpp:81
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
Definition: Parser.h:549
Sema & getActions() const
Definition: Parser.h:499
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
Definition: Parser.h:878
ExprResult ParseCaseExpression(SourceLocation CaseLoc)
Definition: ParseExpr.cpp:252
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
Definition: ParseExpr.cpp:380
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
Definition: Parser.h:577
ExprResult ParseConstantExpression()
Definition: ParseExpr.cpp:233
ExprResult ParseConditionalExpression()
Definition: ParseExpr.cpp:188
bool TryConsumeToken(tok::TokenKind Expected)
Definition: Parser.h:557
Scope * getCurScope() const
Definition: Parser.h:503
ExprResult ParseArrayBoundExpression()
Definition: ParseExpr.cpp:243
ExprResult ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-and-expression.
Definition: ParseExpr.cpp:288
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
Definition: Parser.h:1295
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
Definition: ParseExpr.cpp:169
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
Definition: ParseExpr.cpp:223
const LangOptions & getLangOpts() const
Definition: Parser.h:496
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
Definition: ParseExpr.cpp:132
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
Definition: Parser.h:1276
@ StopAtSemi
Stop skipping at semicolon.
Definition: Parser.h:1274
bool TryAnnotateTypeOrScopeToken(ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No)
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
Definition: Parser.cpp:2000
TypeCastState
TypeCastState - State whether an expression is or may be a type cast.
Definition: Parser.h:1838
ExprResult ParseUnevaluatedStringLiteralExpression()
ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral=false)
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
Definition: Parser.h:873
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
Definition: ParseExpr.cpp:266
void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS)
void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, SourceLocation OpLoc)
void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op)
QualType get(SourceLocation Tok) const
Get the expected type associated with this location, if any.
Definition: Sema.h:349
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
SourceManager & getSourceManager() const
llvm::BumpPtrAllocator & getPreprocessorAllocator()
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
bool isAtStartOfMacroExpansion(SourceLocation loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the first token of the macro expansion.
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
If a crash happens while one of these objects are live, the message is printed out along with the spe...
A (possibly-)qualified type.
Definition: Type.h:941
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1008
@ BlockScope
This is a scope that corresponds to a block/closure object.
Definition: Scope.h:75
@ CompoundStmtScope
This is a compound statement scope.
Definition: Scope.h:134
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
Definition: Scope.h:51
@ DeclScope
This is a scope that can contain a declaration.
Definition: Scope.h:63
ExprResult ActOnExecConfigExpr(Scope *S, SourceLocation LLLLoc, MultiExprArg ExecConfig, SourceLocation GGGLoc)
Definition: SemaCUDA.cpp:54
@ PCC_Type
Code completion occurs where only a type is permitted.
void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data)
Perform code-completion in an expression context when we know what type we're looking for.
QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef< Expr * > Args, SourceLocation OpenParLoc)
Determines the preferred type of the current function argument, by examining the signatures of all po...
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
void CodeCompleteObjCClassPropertyRefExpr(Scope *S, const IdentifierInfo &ClassName, SourceLocation ClassNameLoc, bool IsBaseExprStatement)
void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, SourceLocation OpLoc, bool IsArrow, bool IsBaseExprStatement, QualType PreferredType)
void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, QualType PreferredType)
ExprResult ActOnObjCBridgedCast(Scope *S, SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, ParsedType Type, SourceLocation RParenLoc, Expr *SubExpr)
ExprResult ActOnClassPropertyRefExpr(const IdentifierInfo &receiverName, const IdentifierInfo &propertyName, SourceLocation receiverNameLoc, SourceLocation propertyNameLoc)
ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, bool Value)
ExprResult ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef< AvailabilitySpec > AvailSpecs, SourceLocation AtLoc, SourceLocation RParen)
ExprResult ActOnArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, Expr *Length, SourceLocation RBLoc)
Checks and creates an Array Section used in an OpenACC construct/clause.
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > Brackets)
ExprResult ActOnUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, ParsedType ParsedTy)
Definition: SemaSYCL.cpp:147
A RAII object to temporarily push a declaration context.
Definition: Sema.h:3010
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
Definition: Sema.h:12119
ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, Expr *Input, bool IsAfterAmp=false)
Unary Operators. 'Tok' is the token for the operator.
Definition: SemaExpr.cpp:15588
ExprResult ActOnConstantExpression(ExprResult Res)
Definition: SemaExpr.cpp:19378
ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, Expr *Operand, SourceLocation RParen)
ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, ParsedType Ty, SourceLocation RParenLoc, Expr *InitExpr)
Definition: SemaExpr.cpp:6954
SemaOpenMP & OpenMP()
Definition: Sema.h:1219
void ActOnStartStmtExpr()
Definition: SemaExpr.cpp:15607
void ActOnStmtExprError()
Definition: SemaExpr.cpp:15613
SemaCUDA & CUDA()
Definition: Sema.h:1164
ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, CorrectionCandidateCallback *CCC=nullptr, bool IsInlineAsmIdentifier=false, Token *KeywordReplacement=nullptr)
Definition: SemaExpr.cpp:2650
ExprResult ActOnCharacterConstant(const Token &Tok, Scope *UDLScope=nullptr)
Definition: SemaExpr.cpp:3518
ExprResult ActOnStartCXXMemberReference(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, ParsedType &ObjectType, bool &MayBePseudoDestructor)
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
Definition: SemaStmt.cpp:464
SemaSYCL & SYCL()
Definition: Sema.h:1239
ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc)
ActOnCXXNullPtrLiteral - Parse 'nullptr'.
SemaObjC & ObjC()
Definition: Sema.h:1204
bool CheckConstraintExpression(const Expr *CE, Token NextToken=Token(), bool *PossibleNonPrimary=nullptr, bool IsTrailingRequiresClause=false)
Check whether the given expression is a valid constraint expression.
Definition: SemaConcept.cpp:92
ASTContext & getASTContext() const
Definition: Sema.h:600
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Definition: SemaExpr.cpp:15594
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
Definition: SemaExpr.cpp:7823
ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc)
Definition: SemaExpr.cpp:15882
ExprResult ActOnUnevaluatedStringLiteral(ArrayRef< Token > StringToks)
Definition: SemaExpr.cpp:1951
SourceRange getExprRange(Expr *E) const
Definition: SemaExpr.cpp:502
SemaCodeCompletion & CodeCompletion()
Definition: Sema.h:1159
SemaOpenACC & OpenACC()
Definition: Sema.h:1209
@ ReuseLambdaContextDecl
Definition: Sema.h:6535
ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E)
ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Member, Decl *ObjCImpDecl)
The main callback when the parser finds something like expression .
ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef< ParsedType > ArgTypes, ArrayRef< Expr * > ArgExprs)
ControllingExprOrType is either an opaque pointer coming out of a ParsedType or an Expr *.
Definition: SemaExpr.cpp:1621
void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockError - If there is an error parsing a block, this callback is invoked to pop the informati...
Definition: SemaExpr.cpp:16068
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:1137
ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc)
Definition: SemaExpr.cpp:16430
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
Definition: SemaExpr.cpp:4081
ExprResult ActOnSourceLocExpr(SourceLocIdentKind Kind, SourceLocation BuiltinLoc, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16515
ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr)
ActOnConditionalOp - Parse a ?: operation.
Definition: SemaExpr.cpp:8691
LabelDecl * LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, SourceLocation GnuLabelLoc=SourceLocation())
LookupOrCreateLabel - Do a name lookup of a label with the specified name.
TypeResult ActOnTypeName(Declarator &D)
Definition: SemaType.cpp:6340
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion.
ExprResult ActOnStringLiteral(ArrayRef< Token > StringToks, Scope *UDLScope=nullptr)
ActOnStringLiteral - The specified tokens were lexed as pasted string fragments (e....
Definition: SemaExpr.cpp:2030
ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr)
Binary Operators. 'Tok' is the token for the operator.
Definition: SemaExpr.cpp:15049
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=nullptr, bool IsCtorOrDtorName=false, bool WantNontrivialTypeSourceInfo=false, bool IsClassTemplateDeductionContext=true, ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type.
Definition: SemaDecl.cpp:287
ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind)
Definition: SemaExpr.cpp:3514
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Parse a __builtin_astype expression.
Definition: SemaExpr.cpp:6616
ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16267
ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, Declarator &D, ParsedType &Ty, SourceLocation RParenLoc, Expr *CastExpr)
Definition: SemaExpr.cpp:7651
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition: Sema.h:7930
ExprResult ActOnSizeofParameterPackExpr(Scope *S, SourceLocation OpLoc, IdentifierInfo &Name, SourceLocation NameLoc, SourceLocation RParenLoc)
Called when an expression computing the size of a parameter pack is parsed.
ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc)
Definition: SemaExpr.cpp:15621
ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, tok::TokenKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc)
Handle a C++1z fold-expression: ( expr op ... op expr ).
ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, Scope *CurScope)
ActOnBlockStmtExpr - This is called when the body of a block statement literal was successfully compl...
Definition: SemaExpr.cpp:16078
@ OOK_Macro
Definition: Sema.h:3870
@ OOK_Builtin
Definition: Sema.h:3867
ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Kind, Expr *Input)
Definition: SemaExpr.cpp:4727
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
Definition: SemaExpr.cpp:20889
ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope=nullptr)
Definition: SemaExpr.cpp:3651
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
Definition: SemaExpr.cpp:15920
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
Definition: SemaExpr.cpp:4800
ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Definition: SemaExpr.cpp:6356
ExprResult ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, bool IsType, void *TyOrEx, SourceRange ArgRange)
ActOnUnaryExprOrTypeTraitExpr - Handle sizeof(type) and sizeof expr and the same for alignof and __al...
Definition: SemaExpr.cpp:4657
void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, Scope *CurScope)
ActOnBlockArguments - This callback allows processing of block arguments.
Definition: SemaExpr.cpp:15949
ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
ActOnConvertVectorExpr - create a new convert-vector expression from the provided arguments.
Definition: SemaExpr.cpp:6637
ExprResult ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc, SourceLocation TypeLoc, ParsedType ParsedArgTy, ArrayRef< OffsetOfComponent > Components, SourceLocation RParenLoc)
Definition: SemaExpr.cpp:15863
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, bool RecoverUncorrectedTypos=false, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet)
Act on the result of classifying a name as an overload set.
Definition: SemaDecl.cpp:1262
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:350
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
Token - This structure provides full information about a lexed token.
Definition: Token.h:36
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:187
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:132
const char * getName() const
Definition: Token.h:174
void setKind(tok::TokenKind K)
Definition: Token.h:95
SourceLocation getAnnotationEndLoc() const
Definition: Token.h:146
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
Definition: Token.h:99
void * getAnnotationValue() const
Definition: Token.h:234
tok::TokenKind getKind() const
Definition: Token.h:94
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
Definition: Token.h:276
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
Definition: Token.h:101
bool isNot(tok::TokenKind K) const
Definition: Token.h:100
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
Definition: Lexer.cpp:61
bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const
Determine whether the token kind starts a simple-type-specifier.
Definition: Lexer.cpp:78
SourceLocation getLastLoc() const
Definition: Token.h:155
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
The base class of the type hierarchy.
Definition: Type.h:1829
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
Definition: Type.h:8284
bool isFunctionType() const
Definition: Type.h:7992
bool isVectorType() const
Definition: Type.h:8104
Simple class containing the result of Sema::CorrectTypo.
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:1025
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
The JSON file list parser is used to communicate input to InstallAPI.
@ TST_typename
Definition: Specifiers.h:84
@ OpenCL
Definition: LangStandard.h:66
@ CPlusPlus23
Definition: LangStandard.h:61
@ CPlusPlus
Definition: LangStandard.h:56
@ CPlusPlus11
Definition: LangStandard.h:57
@ CPlusPlus17
Definition: LangStandard.h:59
bool tokenIsLikeStringLiteral(const Token &Tok, const LangOptions &LO)
Return true if the token is a string literal, or a function local predefined macro,...
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:51
ExprResult ExprEmpty()
Definition: Ownership.h:271
@ Result
The result type of a method or function.
ObjCBridgeCastKind
The kind of bridging performed by the Objective-C bridge cast.
@ OBC_Bridge
Bridging via __bridge, which does nothing but reinterpret the bits.
@ OBC_BridgeTransfer
Bridging via __bridge_transfer, which transfers ownership of an Objective-C pointer into ARC.
@ OBC_BridgeRetained
Bridging via __bridge_retain, which makes an ARC object available as a +1 C pointer.
ActionResult< Expr * > ExprResult
Definition: Ownership.h:248
ExprResult ExprError()
Definition: Ownership.h:264
prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, bool CPlusPlus11)
Return the precedence of the specified binary operator token.
@ TNK_Type_template
The name refers to a template whose specialization produces a type.
Definition: TemplateKinds.h:30
const FunctionProtoType * T
SourceLocIdentKind
Definition: Expr.h:4738
@ Parens
New-expression has a C++98 paren-delimited initializer.
@ EST_None
no exception specification
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl * > DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), SourceLocation TrailingReturnTypeLoc=SourceLocation(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
Definition: DeclSpec.cpp:161
Helper class to shuttle information about #embed directives from the preprocessor to the parser throu...
Wraps an identifier and optional source location for the identifier.
Definition: ParsedAttr.h:103
SourceLocation Loc
Definition: ParsedAttr.h:104
IdentifierInfo * Ident
Definition: ParsedAttr.h:105
Information about a template-id annotation token.
TemplateNameKind Kind
The kind of template that Template refers to.