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