clang 19.0.0git
ParseInit.cpp
Go to the documentation of this file.
1//===--- ParseInit.cpp - Initializer 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// This file implements initializer parsing as specified by C99 6.7.8.
10//
11//===----------------------------------------------------------------------===//
12
15#include "clang/Parse/Parser.h"
20#include "clang/Sema/Scope.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/SmallString.h"
23using namespace clang;
24
25
26/// MayBeDesignationStart - Return true if the current token might be the start
27/// of a designator. If we can tell it is impossible that it is a designator,
28/// return false.
29bool Parser::MayBeDesignationStart() {
30 switch (Tok.getKind()) {
31 default:
32 return false;
33
34 case tok::period: // designator: '.' identifier
35 return true;
36
37 case tok::l_square: { // designator: array-designator
38 if (!PP.getLangOpts().CPlusPlus)
39 return true;
40
41 // C++11 lambda expressions and C99 designators can be ambiguous all the
42 // way through the closing ']' and to the next character. Handle the easy
43 // cases here, and fall back to tentative parsing if those fail.
44 switch (PP.LookAhead(0).getKind()) {
45 case tok::equal:
46 case tok::ellipsis:
47 case tok::r_square:
48 // Definitely starts a lambda expression.
49 return false;
50
51 case tok::amp:
52 case tok::kw_this:
53 case tok::star:
54 case tok::identifier:
55 // We have to do additional analysis, because these could be the
56 // start of a constant expression or a lambda capture list.
57 break;
58
59 default:
60 // Anything not mentioned above cannot occur following a '[' in a
61 // lambda expression.
62 return true;
63 }
64
65 // Handle the complicated case below.
66 break;
67 }
68 case tok::identifier: // designation: identifier ':'
69 return PP.LookAhead(0).is(tok::colon);
70 }
71
72 // Parse up to (at most) the token after the closing ']' to determine
73 // whether this is a C99 designator or a lambda.
74 RevertingTentativeParsingAction Tentative(*this);
75
76 LambdaIntroducer Intro;
77 LambdaIntroducerTentativeParse ParseResult;
78 if (ParseLambdaIntroducer(Intro, &ParseResult)) {
79 // Hit and diagnosed an error in a lambda.
80 // FIXME: Tell the caller this happened so they can recover.
81 return true;
82 }
83
84 switch (ParseResult) {
85 case LambdaIntroducerTentativeParse::Success:
86 case LambdaIntroducerTentativeParse::Incomplete:
87 // Might be a lambda-expression. Keep looking.
88 // FIXME: If our tentative parse was not incomplete, parse the lambda from
89 // here rather than throwing away then reparsing the LambdaIntroducer.
90 break;
91
92 case LambdaIntroducerTentativeParse::MessageSend:
93 case LambdaIntroducerTentativeParse::Invalid:
94 // Can't be a lambda-expression. Treat it as a designator.
95 // FIXME: Should we disambiguate against a message-send?
96 return true;
97 }
98
99 // Once we hit the closing square bracket, we look at the next
100 // token. If it's an '=', this is a designator. Otherwise, it's a
101 // lambda expression. This decision favors lambdas over the older
102 // GNU designator syntax, which allows one to omit the '=', but is
103 // consistent with GCC.
104 return Tok.is(tok::equal);
105}
106
108 Designation &Desig) {
109 // If we have exactly one array designator, this used the GNU
110 // 'designation: array-designator' extension, otherwise there should be no
111 // designators at all!
112 if (Desig.getNumDesignators() == 1 &&
113 (Desig.getDesignator(0).isArrayDesignator() ||
115 P.Diag(Loc, diag::ext_gnu_missing_equal_designator);
116 else if (Desig.getNumDesignators() > 0)
117 P.Diag(Loc, diag::err_expected_equal_designator);
118}
119
120/// ParseInitializerWithPotentialDesignator - Parse the 'initializer' production
121/// checking to see if the token stream starts with a designator.
122///
123/// C99:
124///
125/// designation:
126/// designator-list '='
127/// [GNU] array-designator
128/// [GNU] identifier ':'
129///
130/// designator-list:
131/// designator
132/// designator-list designator
133///
134/// designator:
135/// array-designator
136/// '.' identifier
137///
138/// array-designator:
139/// '[' constant-expression ']'
140/// [GNU] '[' constant-expression '...' constant-expression ']'
141///
142/// C++20:
143///
144/// designated-initializer-list:
145/// designated-initializer-clause
146/// designated-initializer-list ',' designated-initializer-clause
147///
148/// designated-initializer-clause:
149/// designator brace-or-equal-initializer
150///
151/// designator:
152/// '.' identifier
153///
154/// We allow the C99 syntax extensions in C++20, but do not allow the C++20
155/// extension (a braced-init-list after the designator with no '=') in C99.
156///
157/// NOTE: [OBC] allows '[ objc-receiver objc-message-args ]' as an
158/// initializer (because it is an expression). We need to consider this case
159/// when parsing array designators.
160///
161/// \p CodeCompleteCB is called with Designation parsed so far.
162ExprResult Parser::ParseInitializerWithPotentialDesignator(
163 DesignatorCompletionInfo DesignatorCompletion) {
164 // If this is the old-style GNU extension:
165 // designation ::= identifier ':'
166 // Handle it as a field designator. Otherwise, this must be the start of a
167 // normal expression.
168 if (Tok.is(tok::identifier)) {
169 const IdentifierInfo *FieldName = Tok.getIdentifierInfo();
170
171 SmallString<256> NewSyntax;
172 llvm::raw_svector_ostream(NewSyntax) << '.' << FieldName->getName()
173 << " = ";
174
175 SourceLocation NameLoc = ConsumeToken(); // Eat the identifier.
176
177 assert(Tok.is(tok::colon) && "MayBeDesignationStart not working properly!");
178 SourceLocation ColonLoc = ConsumeToken();
179
180 Diag(NameLoc, diag::ext_gnu_old_style_field_designator)
181 << FixItHint::CreateReplacement(SourceRange(NameLoc, ColonLoc),
182 NewSyntax);
183
184 Designation D;
186 FieldName, SourceLocation(), NameLoc));
187 PreferredType.enterDesignatedInitializer(
188 Tok.getLocation(), DesignatorCompletion.PreferredBaseType, D);
189 return Actions.ActOnDesignatedInitializer(D, ColonLoc, true,
190 ParseInitializer());
191 }
192
193 // Desig - This is initialized when we see our first designator. We may have
194 // an objc message send with no designator, so we don't want to create this
195 // eagerly.
196 Designation Desig;
197
198 // Parse each designator in the designator list until we find an initializer.
199 while (Tok.is(tok::period) || Tok.is(tok::l_square)) {
200 if (Tok.is(tok::period)) {
201 // designator: '.' identifier
202 SourceLocation DotLoc = ConsumeToken();
203
204 if (Tok.is(tok::code_completion)) {
205 cutOffParsing();
206 Actions.CodeCompleteDesignator(DesignatorCompletion.PreferredBaseType,
207 DesignatorCompletion.InitExprs, Desig);
208 return ExprError();
209 }
210 if (Tok.isNot(tok::identifier)) {
211 Diag(Tok.getLocation(), diag::err_expected_field_designator);
212 return ExprError();
213 }
214
216 Tok.getIdentifierInfo(), DotLoc, Tok.getLocation()));
217 ConsumeToken(); // Eat the identifier.
218 continue;
219 }
220
221 // We must have either an array designator now or an objc message send.
222 assert(Tok.is(tok::l_square) && "Unexpected token!");
223
224 // Handle the two forms of array designator:
225 // array-designator: '[' constant-expression ']'
226 // array-designator: '[' constant-expression '...' constant-expression ']'
227 //
228 // Also, we have to handle the case where the expression after the
229 // designator an an objc message send: '[' objc-message-expr ']'.
230 // Interesting cases are:
231 // [foo bar] -> objc message send
232 // [foo] -> array designator
233 // [foo ... bar] -> array designator
234 // [4][foo bar] -> obsolete GNU designation with objc message send.
235 //
236 // We do not need to check for an expression starting with [[ here. If it
237 // contains an Objective-C message send, then it is not an ill-formed
238 // attribute. If it is a lambda-expression within an array-designator, then
239 // it will be rejected because a constant-expression cannot begin with a
240 // lambda-expression.
241 InMessageExpressionRAIIObject InMessage(*this, true);
242
243 BalancedDelimiterTracker T(*this, tok::l_square);
244 T.consumeOpen();
245 SourceLocation StartLoc = T.getOpenLocation();
246
247 ExprResult Idx;
248
249 // If Objective-C is enabled and this is a typename (class message
250 // send) or send to 'super', parse this as a message send
251 // expression. We handle C++ and C separately, since C++ requires
252 // much more complicated parsing.
254 // Send to 'super'.
255 if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super &&
256 NextToken().isNot(tok::period) &&
257 getCurScope()->isInObjcMethodScope()) {
258 CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
259 return ParseAssignmentExprWithObjCMessageExprStart(
260 StartLoc, ConsumeToken(), nullptr, nullptr);
261 }
262
263 // Parse the receiver, which is either a type or an expression.
264 bool IsExpr;
265 void *TypeOrExpr;
266 if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
267 SkipUntil(tok::r_square, StopAtSemi);
268 return ExprError();
269 }
270
271 // If the receiver was a type, we have a class message; parse
272 // the rest of it.
273 if (!IsExpr) {
274 CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
275 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
278 nullptr);
279 }
280
281 // If the receiver was an expression, we still don't know
282 // whether we have a message send or an array designator; just
283 // adopt the expression for further analysis below.
284 // FIXME: potentially-potentially evaluated expression above?
285 Idx = ExprResult(static_cast<Expr*>(TypeOrExpr));
286 } else if (getLangOpts().ObjC && Tok.is(tok::identifier)) {
288 SourceLocation IILoc = Tok.getLocation();
289 ParsedType ReceiverType;
290 // Three cases. This is a message send to a type: [type foo]
291 // This is a message send to super: [super foo]
292 // This is a message sent to an expr: [super.bar foo]
293 switch (Actions.getObjCMessageKind(
294 getCurScope(), II, IILoc, II == Ident_super,
295 NextToken().is(tok::period), ReceiverType)) {
297 CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
298 return ParseAssignmentExprWithObjCMessageExprStart(
299 StartLoc, ConsumeToken(), nullptr, nullptr);
300
302 CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
303 ConsumeToken(); // the identifier
304 if (!ReceiverType) {
305 SkipUntil(tok::r_square, StopAtSemi);
306 return ExprError();
307 }
308
309 // Parse type arguments and protocol qualifiers.
310 if (Tok.is(tok::less)) {
311 SourceLocation NewEndLoc;
312 TypeResult NewReceiverType
313 = parseObjCTypeArgsAndProtocolQualifiers(IILoc, ReceiverType,
314 /*consumeLastToken=*/true,
315 NewEndLoc);
316 if (!NewReceiverType.isUsable()) {
317 SkipUntil(tok::r_square, StopAtSemi);
318 return ExprError();
319 }
320
321 ReceiverType = NewReceiverType.get();
322 }
323
324 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
326 ReceiverType,
327 nullptr);
328
330 // Fall through; we'll just parse the expression and
331 // (possibly) treat this like an Objective-C message send
332 // later.
333 break;
334 }
335 }
336
337 // Parse the index expression, if we haven't already gotten one
338 // above (which can only happen in Objective-C++).
339 // Note that we parse this as an assignment expression, not a constant
340 // expression (allowing *=, =, etc) to handle the objc case. Sema needs
341 // to validate that the expression is a constant.
342 // FIXME: We also need to tell Sema that we're in a
343 // potentially-potentially evaluated context.
344 if (!Idx.get()) {
346 if (Idx.isInvalid()) {
347 SkipUntil(tok::r_square, StopAtSemi);
348 return Idx;
349 }
350 }
351
352 // Given an expression, we could either have a designator (if the next
353 // tokens are '...' or ']' or an objc message send. If this is an objc
354 // message send, handle it now. An objc-message send is the start of
355 // an assignment-expression production.
356 if (getLangOpts().ObjC && Tok.isNot(tok::ellipsis) &&
357 Tok.isNot(tok::r_square)) {
358 CheckArrayDesignatorSyntax(*this, Tok.getLocation(), Desig);
359 return ParseAssignmentExprWithObjCMessageExprStart(
360 StartLoc, SourceLocation(), nullptr, Idx.get());
361 }
362
363 // If this is a normal array designator, remember it.
364 if (Tok.isNot(tok::ellipsis)) {
366 StartLoc));
367 } else {
368 // Handle the gnu array range extension.
369 Diag(Tok, diag::ext_gnu_array_range);
370 SourceLocation EllipsisLoc = ConsumeToken();
371
373 if (RHS.isInvalid()) {
374 SkipUntil(tok::r_square, StopAtSemi);
375 return RHS;
376 }
378 Idx.get(), RHS.get(), StartLoc, EllipsisLoc));
379 }
380
381 T.consumeClose();
383 T.getCloseLocation());
384 }
385
386 // Okay, we're done with the designator sequence. We know that there must be
387 // at least one designator, because the only case we can get into this method
388 // without a designator is when we have an objc message send. That case is
389 // handled and returned from above.
390 assert(!Desig.empty() && "Designator is empty?");
391
392 // Handle a normal designator sequence end, which is an equal.
393 if (Tok.is(tok::equal)) {
394 SourceLocation EqualLoc = ConsumeToken();
395 PreferredType.enterDesignatedInitializer(
396 Tok.getLocation(), DesignatorCompletion.PreferredBaseType, Desig);
397 return Actions.ActOnDesignatedInitializer(Desig, EqualLoc, false,
398 ParseInitializer());
399 }
400
401 // Handle a C++20 braced designated initialization, which results in
402 // direct-list-initialization of the aggregate element. We allow this as an
403 // extension from C++11 onwards (when direct-list-initialization was added).
404 if (Tok.is(tok::l_brace) && getLangOpts().CPlusPlus11) {
405 PreferredType.enterDesignatedInitializer(
406 Tok.getLocation(), DesignatorCompletion.PreferredBaseType, Desig);
407 return Actions.ActOnDesignatedInitializer(Desig, SourceLocation(), false,
408 ParseBraceInitializer());
409 }
410
411 // We read some number of designators and found something that isn't an = or
412 // an initializer. If we have exactly one array designator, this
413 // is the GNU 'designation: array-designator' extension. Otherwise, it is a
414 // parse error.
415 if (Desig.getNumDesignators() == 1 &&
416 (Desig.getDesignator(0).isArrayDesignator() ||
418 Diag(Tok, diag::ext_gnu_missing_equal_designator)
420 return Actions.ActOnDesignatedInitializer(Desig, Tok.getLocation(),
421 true, ParseInitializer());
422 }
423
424 Diag(Tok, diag::err_expected_equal_designator);
425 return ExprError();
426}
427
428/// ParseBraceInitializer - Called when parsing an initializer that has a
429/// leading open brace.
430///
431/// initializer: [C99 6.7.8]
432/// '{' initializer-list '}'
433/// '{' initializer-list ',' '}'
434/// [C23] '{' '}'
435///
436/// initializer-list:
437/// designation[opt] initializer ...[opt]
438/// initializer-list ',' designation[opt] initializer ...[opt]
439///
440ExprResult Parser::ParseBraceInitializer() {
441 InMessageExpressionRAIIObject InMessage(*this, false);
442
443 BalancedDelimiterTracker T(*this, tok::l_brace);
444 T.consumeOpen();
445 SourceLocation LBraceLoc = T.getOpenLocation();
446
447 /// InitExprs - This is the actual list of expressions contained in the
448 /// initializer.
449 ExprVector InitExprs;
450
451 if (Tok.is(tok::r_brace)) {
452 // Empty initializers are a C++ feature and a GNU extension to C before C23.
453 if (!getLangOpts().CPlusPlus) {
454 Diag(LBraceLoc, getLangOpts().C23
455 ? diag::warn_c23_compat_empty_initializer
456 : diag::ext_c_empty_initializer);
457 }
458 // Match the '}'.
459 return Actions.ActOnInitList(LBraceLoc, std::nullopt, ConsumeBrace());
460 }
461
462 // Enter an appropriate expression evaluation context for an initializer list.
465
466 bool InitExprsOk = true;
467 QualType LikelyType = PreferredType.get(T.getOpenLocation());
468 DesignatorCompletionInfo DesignatorCompletion{InitExprs, LikelyType};
469 bool CalledSignatureHelp = false;
470 auto RunSignatureHelp = [&] {
471 QualType PreferredType;
472 if (!LikelyType.isNull())
473 PreferredType = Actions.ProduceConstructorSignatureHelp(
474 LikelyType->getCanonicalTypeInternal(), T.getOpenLocation(),
475 InitExprs, T.getOpenLocation(), /*Braced=*/true);
476 CalledSignatureHelp = true;
477 return PreferredType;
478 };
479
480 while (true) {
481 PreferredType.enterFunctionArgument(Tok.getLocation(), RunSignatureHelp);
482
483 // Handle Microsoft __if_exists/if_not_exists if necessary.
484 if (getLangOpts().MicrosoftExt && (Tok.is(tok::kw___if_exists) ||
485 Tok.is(tok::kw___if_not_exists))) {
486 if (ParseMicrosoftIfExistsBraceInitializer(InitExprs, InitExprsOk)) {
487 if (Tok.isNot(tok::comma)) break;
488 ConsumeToken();
489 }
490 if (Tok.is(tok::r_brace)) break;
491 continue;
492 }
493
494 // Parse: designation[opt] initializer
495
496 // If we know that this cannot be a designation, just parse the nested
497 // initializer directly.
498 ExprResult SubElt;
499 if (MayBeDesignationStart())
500 SubElt = ParseInitializerWithPotentialDesignator(DesignatorCompletion);
501 else
502 SubElt = ParseInitializer();
503
504 if (Tok.is(tok::ellipsis))
505 SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken());
506
507 SubElt = Actions.CorrectDelayedTyposInExpr(SubElt.get());
508
509 // If we couldn't parse the subelement, bail out.
510 if (SubElt.isUsable()) {
511 InitExprs.push_back(SubElt.get());
512 } else {
513 InitExprsOk = false;
514
515 // We have two ways to try to recover from this error: if the code looks
516 // grammatically ok (i.e. we have a comma coming up) try to continue
517 // parsing the rest of the initializer. This allows us to emit
518 // diagnostics for later elements that we find. If we don't see a comma,
519 // assume there is a parse error, and just skip to recover.
520 // FIXME: This comment doesn't sound right. If there is a r_brace
521 // immediately, it can't be an error, since there is no other way of
522 // leaving this loop except through this if.
523 if (Tok.isNot(tok::comma)) {
524 SkipUntil(tok::r_brace, StopBeforeMatch);
525 break;
526 }
527 }
528
529 // If we don't have a comma continued list, we're done.
530 if (Tok.isNot(tok::comma)) break;
531
532 // TODO: save comma locations if some client cares.
533 ConsumeToken();
534
535 // Handle trailing comma.
536 if (Tok.is(tok::r_brace)) break;
537 }
538
539 bool closed = !T.consumeClose();
540
541 if (InitExprsOk && closed)
542 return Actions.ActOnInitList(LBraceLoc, InitExprs,
543 T.getCloseLocation());
544
545 return ExprError(); // an error occurred.
546}
547
548
549// Return true if a comma (or closing brace) is necessary after the
550// __if_exists/if_not_exists statement.
551bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
552 bool &InitExprsOk) {
553 bool trailingComma = false;
554 IfExistsCondition Result;
555 if (ParseMicrosoftIfExistsCondition(Result))
556 return false;
557
558 BalancedDelimiterTracker Braces(*this, tok::l_brace);
559 if (Braces.consumeOpen()) {
560 Diag(Tok, diag::err_expected) << tok::l_brace;
561 return false;
562 }
563
564 switch (Result.Behavior) {
565 case IEB_Parse:
566 // Parse the declarations below.
567 break;
568
569 case IEB_Dependent:
570 Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
571 << Result.IsIfExists;
572 // Fall through to skip.
573 [[fallthrough]];
574
575 case IEB_Skip:
576 Braces.skipToEnd();
577 return false;
578 }
579
580 DesignatorCompletionInfo DesignatorCompletion{
581 InitExprs,
582 PreferredType.get(Braces.getOpenLocation()),
583 };
584 while (!isEofOrEom()) {
585 trailingComma = false;
586 // If we know that this cannot be a designation, just parse the nested
587 // initializer directly.
588 ExprResult SubElt;
589 if (MayBeDesignationStart())
590 SubElt = ParseInitializerWithPotentialDesignator(DesignatorCompletion);
591 else
592 SubElt = ParseInitializer();
593
594 if (Tok.is(tok::ellipsis))
595 SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken());
596
597 // If we couldn't parse the subelement, bail out.
598 if (!SubElt.isInvalid())
599 InitExprs.push_back(SubElt.get());
600 else
601 InitExprsOk = false;
602
603 if (Tok.is(tok::comma)) {
604 ConsumeToken();
605 trailingComma = true;
606 }
607
608 if (Tok.is(tok::r_brace))
609 break;
610 }
611
612 Braces.consumeClose();
613
614 return !trailingComma;
615}
StringRef P
static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc, Designation &Desig)
Definition: ParseInit.cpp:107
Defines the clang::TokenKind enum and support functions.
PtrTy get() const
Definition: Ownership.h:170
bool isInvalid() const
Definition: Ownership.h:166
bool isUsable() const
Definition: Ownership.h:168
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
Designation - Represent a full designation, which is a sequence of designators.
Definition: Designator.h:208
const Designator & getDesignator(unsigned Idx) const
Definition: Designator.h:219
bool empty() const
Definition: Designator.h:216
unsigned getNumDesignators() const
Definition: Designator.h:218
void AddDesignator(Designator D)
AddDesignator - Add a designator to the end of this list.
Definition: Designator.h:214
bool isArrayDesignator() const
Definition: Designator.h:108
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
Definition: Designator.h:172
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
Definition: Designator.h:142
void setRBracketLoc(SourceLocation RBracketLoc) const
Definition: Designator.h:196
bool isArrayRangeDesignator() const
Definition: Designator.h:109
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Designator.h:115
RAII object that enters a new expression evaluation context.
This represents one expression.
Definition: Expr.h:110
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 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.
StringRef getName() const
Return the actual identifier string.
static OpaquePtr getFromOpaquePtr(void *P)
Definition: Ownership.h:91
Parser - This implements a parser for the C family of languages.
Definition: Parser.h:56
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Definition: Parser.cpp:80
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
Definition: Parser.h:516
ExprResult ParseConstantExpression()
Definition: ParseExpr.cpp:230
Scope * getCurScope() const
Definition: Parser.h:470
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:1262
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
Definition: ParseExpr.cpp:166
const LangOptions & getLangOpts() const
Definition: Parser.h:463
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
Definition: Parser.h:1243
@ StopAtSemi
Stop skipping at semicolon.
Definition: Parser.h:1241
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
Definition: Parser.h:840
void enterDesignatedInitializer(SourceLocation Tok, QualType BaseType, const Designation &D)
Handles e.g. BaseType{ .D = Tok...
QualType get(SourceLocation Tok) const
Get the expected type associated with this location, if any.
Definition: Sema.h:335
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
const LangOptions & getLangOpts() const
A (possibly-)qualified type.
Definition: Type.h:738
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:805
QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, ArrayRef< Expr * > Args, SourceLocation OpenParLoc, bool Braced)
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
Definition: SemaInit.cpp:3368
void CodeCompleteDesignator(const QualType BaseType, llvm::ArrayRef< Expr * > InitExprs, const Designation &D)
Trigger code completion for a record of BaseType.
ObjCMessageKind getObjCMessageKind(Scope *S, IdentifierInfo *Name, SourceLocation NameLoc, bool IsSuper, bool HasTrailingDot, ParsedType &ReceiverType)
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion.
@ ObjCSuperMessage
The message is sent to 'super'.
Definition: Sema.h:12298
@ ObjCClassMessage
The message is a class message, and the identifier is a type name.
Definition: Sema.h:12303
@ ObjCInstanceMessage
The message is an instance message.
Definition: Sema.h:12300
ExprResult ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, SourceLocation RBraceLoc)
Definition: SemaExpr.cpp:7379
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...
Encodes a location in the source.
A trivial tuple used to represent a source range.
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
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
tok::TokenKind getKind() const
Definition: Token.h:94
bool isNot(tok::TokenKind K) const
Definition: Token.h:100
QualType getCanonicalTypeInternal() const
Definition: Type.h:2726
The JSON file list parser is used to communicate input to InstallAPI.
@ CPlusPlus
Definition: LangStandard.h:55
@ CPlusPlus11
Definition: LangStandard.h:56
@ Result
The result type of a method or function.
ActionResult< Expr * > ExprResult
Definition: Ownership.h:248
ExprResult ExprError()
Definition: Ownership.h:264
const FunctionProtoType * T
@ Braces
New-expression has a C++11 list-initializer.
Represents a complete lambda introducer.
Definition: DeclSpec.h:2830