25bool Parser::MayBeDesignationStart() {
26 switch (Tok.getKind()) {
34 if (!PP.getLangOpts().CPlusPlus)
40 switch (PP.LookAhead(0).getKind()) {
65 return PP.LookAhead(0).is(tok::colon);
70 RevertingTentativeParsingAction Tentative(*
this);
72 LambdaIntroducer Intro;
73 LambdaIntroducerTentativeParse ParseResult;
74 if (ParseLambdaIntroducer(Intro, &ParseResult)) {
80 switch (ParseResult) {
81 case LambdaIntroducerTentativeParse::Success:
82 case LambdaIntroducerTentativeParse::Incomplete:
88 case LambdaIntroducerTentativeParse::MessageSend:
89 case LambdaIntroducerTentativeParse::Invalid:
100 return Tok.is(tok::equal);
111 P.
Diag(Loc, diag::ext_gnu_missing_equal_designator);
113 P.
Diag(Loc, diag::err_expected_equal_designator);
116ExprResult Parser::ParseInitializerWithPotentialDesignator(
117 DesignatorCompletionInfo DesignatorCompletion) {
122 if (Tok.is(tok::identifier)) {
123 const IdentifierInfo *FieldName = Tok.getIdentifierInfo();
125 SmallString<256> NewSyntax;
126 llvm::raw_svector_ostream(NewSyntax) <<
'.' << FieldName->
getName()
131 assert(Tok.is(tok::colon) &&
"MayBeDesignationStart not working properly!");
134 Diag(NameLoc, diag::ext_gnu_old_style_field_designator)
140 FieldName, SourceLocation(), NameLoc));
141 PreferredType.enterDesignatedInitializer(
142 Tok.getLocation(), DesignatorCompletion.PreferredBaseType, D);
143 return Actions.ActOnDesignatedInitializer(D, ColonLoc,
true,
153 while (Tok.is(tok::period) || Tok.is(tok::l_square)) {
154 if (Tok.is(tok::period)) {
158 if (Tok.is(tok::code_completion)) {
160 Actions.CodeCompletion().CodeCompleteDesignator(
161 DesignatorCompletion.PreferredBaseType,
162 DesignatorCompletion.InitExprs, Desig);
165 if (Tok.isNot(tok::identifier)) {
166 Diag(Tok.getLocation(), diag::err_expected_field_designator);
171 Tok.getIdentifierInfo(), DotLoc, Tok.getLocation()));
177 assert(Tok.is(tok::l_square) &&
"Unexpected token!");
200 SourceLocation StartLoc =
T.getOpenLocation();
210 if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super &&
214 return ParseAssignmentExprWithObjCMessageExprStart(
221 if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
230 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
240 Idx =
ExprResult(
static_cast<Expr*
>(TypeOrExpr));
242 IdentifierInfo *II = Tok.getIdentifierInfo();
243 SourceLocation IILoc = Tok.getLocation();
248 switch (Actions.ObjC().getObjCMessageKind(
253 return ParseAssignmentExprWithObjCMessageExprStart(
265 if (Tok.is(tok::less)) {
266 SourceLocation NewEndLoc;
268 = parseObjCTypeArgsAndProtocolQualifiers(IILoc, ReceiverType,
276 ReceiverType = NewReceiverType.
get();
279 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
312 Tok.isNot(tok::r_square)) {
314 return ParseAssignmentExprWithObjCMessageExprStart(
315 StartLoc, SourceLocation(),
nullptr, Idx.
get());
319 if (Tok.isNot(tok::ellipsis)) {
324 Diag(Tok, diag::ext_gnu_array_range);
328 if (RHS.isInvalid()) {
333 Idx.
get(), RHS.get(), StartLoc, EllipsisLoc));
338 T.getCloseLocation());
345 assert(!Desig.
empty() &&
"Designator is empty?");
348 if (Tok.is(tok::equal)) {
350 PreferredType.enterDesignatedInitializer(
351 Tok.getLocation(), DesignatorCompletion.PreferredBaseType, Desig);
352 return Actions.ActOnDesignatedInitializer(Desig, EqualLoc,
false,
360 PreferredType.enterDesignatedInitializer(
361 Tok.getLocation(), DesignatorCompletion.PreferredBaseType, Desig);
362 return Actions.ActOnDesignatedInitializer(Desig, SourceLocation(),
false,
363 ParseBraceInitializer());
373 Diag(Tok, diag::ext_gnu_missing_equal_designator)
375 return Actions.ActOnDesignatedInitializer(Desig, Tok.getLocation(),
376 true, ParseInitializer());
379 Diag(Tok, diag::err_expected_equal_designator);
384 assert(Tok.getKind() == tok::annot_embed);
385 EmbedAnnotationData *
Data =
386 reinterpret_cast<EmbedAnnotationData *
>(Tok.getAnnotationValue());
388 ASTContext &Context = Actions.getASTContext();
389 SourceLocation StartLoc = ConsumeAnnotationToken();
390 if (
Data->BinaryData.size() == 1) {
392 Context, llvm::APInt(
CHAR_BIT, (
unsigned char)
Data->BinaryData.back()),
395 auto CreateStringLiteralFromStringRef = [&](StringRef Str, QualType Ty) {
396 llvm::APSInt ArraySize =
401 false, ArrayTy, StartLoc);
404 StringLiteral *BinaryDataArg = CreateStringLiteralFromStringRef(
406 Res = Actions.ActOnEmbedExpr(StartLoc, BinaryDataArg,
Data->FileName);
416 SourceLocation LBraceLoc =
T.getOpenLocation();
420 ExprVector InitExprs;
422 if (Tok.is(tok::r_brace)) {
426 ? diag::warn_c23_compat_empty_initializer
427 : diag::ext_c_empty_initializer);
430 return Actions.ActOnInitList(LBraceLoc, {}, ConsumeBrace());
434 EnterExpressionEvaluationContext EnterContext(
437 bool InitExprsOk =
true;
438 QualType LikelyType = PreferredType.get(
T.getOpenLocation());
439 DesignatorCompletionInfo DesignatorCompletion{InitExprs, LikelyType};
440 bool CalledSignatureHelp =
false;
441 auto RunSignatureHelp = [&] {
442 QualType PreferredType;
444 PreferredType = Actions.CodeCompletion().ProduceConstructorSignatureHelp(
446 InitExprs,
T.getOpenLocation(),
true);
447 CalledSignatureHelp =
true;
448 return PreferredType;
452 PreferredType.enterFunctionArgument(Tok.getLocation(), RunSignatureHelp);
455 if (
getLangOpts().MicrosoftExt && (Tok.is(tok::kw___if_exists) ||
456 Tok.is(tok::kw___if_not_exists))) {
457 if (ParseMicrosoftIfExistsBraceInitializer(InitExprs, InitExprsOk)) {
458 if (Tok.isNot(tok::comma))
break;
461 if (Tok.is(tok::r_brace))
break;
470 if (MayBeDesignationStart())
471 SubElt = ParseInitializerWithPotentialDesignator(DesignatorCompletion);
472 else if (Tok.getKind() == tok::annot_embed)
473 SubElt = createEmbedExpr();
475 SubElt = ParseInitializer();
477 if (Tok.is(tok::ellipsis))
482 InitExprs.push_back(SubElt.
get());
494 if (Tok.isNot(tok::comma)) {
501 if (Tok.isNot(tok::comma))
break;
507 if (Tok.is(tok::r_brace))
break;
510 bool closed = !
T.consumeClose();
512 if (InitExprsOk && closed)
513 return Actions.ActOnInitList(LBraceLoc, InitExprs,
514 T.getCloseLocation());
523 ExprVector InitExprs;
525 if (!Tok.is(tok::r_brace) &&
526 ParseExpressionList(InitExprs, {},
534 return Actions.ActOnCXXExpansionInitList(InitExprs,
T.getOpenLocation(),
535 T.getCloseLocation());
538bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
540 bool trailingComma =
false;
542 if (ParseMicrosoftIfExistsCondition(
Result))
546 if (
Braces.consumeOpen()) {
547 Diag(Tok, diag::err_expected) << tok::l_brace;
551 switch (
Result.Behavior) {
557 Diag(
Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
567 DesignatorCompletionInfo DesignatorCompletion{
569 PreferredType.get(
Braces.getOpenLocation()),
571 while (!isEofOrEom()) {
572 trailingComma =
false;
576 if (MayBeDesignationStart())
577 SubElt = ParseInitializerWithPotentialDesignator(DesignatorCompletion);
579 SubElt = ParseInitializer();
581 if (Tok.is(tok::ellipsis))
586 InitExprs.push_back(SubElt.
get());
590 if (Tok.is(tok::comma)) {
592 trailingComma =
true;
595 if (Tok.is(tok::r_brace))
601 return !trailingComma;
610 if (DeclForInitializer && !Actions.ExprEvalContexts.empty()) {
611 if (
auto *VD = dyn_cast<VarDecl>(DeclForInitializer);
612 VD && VD->isFileVarDecl() &&
613 (!VD->getType()->isReferenceType() || VD->isConstexpr()))
614 Actions.ExprEvalContexts.back().DeclForInitializer = VD;
618 if (Tok.isNot(tok::l_brace)) {
621 init = ParseBraceInitializer();
static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc, Designation &Desig)
This file declares facilities that support code completion.
This file declares semantic analysis for Objective-C.
Defines the clang::TokenKind enum and support functions.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
CanQualType UnsignedCharTy
llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const
Make an APSInt of the appropriate width and signedness for the given Value and integer Type.
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Decl - This represents one declaration (or definition), e.g.
Designation - Represent a full designation, which is a sequence of designators.
const Designator & getDesignator(unsigned Idx) const
unsigned getNumDesignators() const
void AddDesignator(Designator D)
AddDesignator - Add a designator to the end of this list.
bool isArrayDesignator() const
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
void setRBracketLoc(SourceLocation RBracketLoc) const
bool isArrayRangeDesignator() const
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
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.
StringRef getName() const
Return the actual identifier string.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
static OpaquePtr getFromOpaquePtr(void *P)
Parser - This implements a parser for the C family of languages.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
ExprResult ParseConstantExpression()
Scope * getCurScope() const
friend class InMessageExpressionRAIIObject
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 ...
const LangOptions & getLangOpts() const
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtSemi
Stop skipping at semicolon.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseAssignmentExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Parse an expr that doesn't include (top-level) commas.
friend class BalancedDelimiterTracker
bool isNull() const
Return true if this QualType doesn't point to a type yet.
@ ObjCClassMessage
The message is a class message, and the identifier is a type name.
@ ObjCInstanceMessage
The message is an instance message.
@ ObjCSuperMessage
The message is sent to 'super'.
Encodes a location in the source.
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
QualType getCanonicalTypeInternal() const
Top level wrappers for InstallAPI frontend operations.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Skip
Skip the block entirely; this code is never used.
@ Parse
Parse the block; this code is always used.
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
const FunctionProtoType * T
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
ActionResult< Expr * > ExprResult
@ Braces
New-expression has a C++11 list-initializer.