19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/Support/raw_ostream.h"
21 using namespace clang;
27 bool Parser::MayBeDesignationStart() {
70 TentativeParsingAction Tentative(*
this);
73 bool SkippedInits =
false;
91 return Kind == tok::equal;
102 P.
Diag(Loc, diag::ext_gnu_missing_equal_designator);
104 P.
Diag(Loc, diag::err_expected_equal_designator);
131 ExprResult Parser::ParseInitializerWithPotentialDesignator() {
137 if (Tok.
is(tok::identifier)) {
141 llvm::raw_svector_ostream(NewSyntax) <<
'.' << FieldName->
getName()
146 assert(Tok.
is(tok::colon) &&
"MayBeDesignationStart not working properly!");
149 Diag(NameLoc, diag::ext_gnu_old_style_field_designator)
165 while (Tok.
is(tok::period) || Tok.
is(tok::l_square)) {
166 if (Tok.
is(tok::period)) {
170 if (Tok.
isNot(tok::identifier)) {
182 assert(Tok.
is(tok::l_square) &&
"Unexpected token!");
219 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
228 if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
237 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
247 Idx =
ExprResult(static_cast<Expr*>(TypeOrExpr));
257 NextToken().is(tok::period), ReceiverType)) {
260 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
274 if (Tok.
is(tok::less)) {
277 = parseObjCTypeArgsAndProtocolQualifiers(IILoc, ReceiverType,
285 ReceiverType = NewReceiverType.
get();
288 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
321 Tok.
isNot(tok::r_square)) {
323 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
330 if (Tok.
isNot(tok::ellipsis)) {
334 Diag(Tok, diag::ext_gnu_array_range);
338 if (RHS.isInvalid()) {
344 StartLoc, EllipsisLoc));
349 T.getCloseLocation());
356 assert(!Desig.
empty() &&
"Designator is empty?");
359 if (Tok.
is(tok::equal)) {
372 Diag(Tok, diag::ext_gnu_missing_equal_designator)
375 true, ParseInitializer());
378 Diag(Tok, diag::err_expected_equal_designator);
404 ExprVector InitExprs;
406 if (Tok.
is(tok::r_brace)) {
409 Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
414 bool InitExprsOk =
true;
418 if (
getLangOpts().MicrosoftExt && (Tok.
is(tok::kw___if_exists) ||
419 Tok.
is(tok::kw___if_not_exists))) {
420 if (ParseMicrosoftIfExistsBraceInitializer(InitExprs, InitExprsOk)) {
421 if (Tok.
isNot(tok::comma))
break;
424 if (Tok.
is(tok::r_brace))
break;
433 if (MayBeDesignationStart())
434 SubElt = ParseInitializerWithPotentialDesignator();
436 SubElt = ParseInitializer();
438 if (Tok.
is(tok::ellipsis))
445 InitExprs.push_back(SubElt.
get());
457 if (Tok.
isNot(tok::comma)) {
464 if (Tok.
isNot(tok::comma))
break;
470 if (Tok.
is(tok::r_brace))
break;
473 bool closed = !T.consumeClose();
475 if (InitExprsOk && closed)
477 T.getCloseLocation());
485 bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
487 bool trailingComma =
false;
489 if (ParseMicrosoftIfExistsCondition(Result))
493 if (Braces.consumeOpen()) {
494 Diag(Tok, diag::err_expected) << tok::l_brace;
498 switch (Result.Behavior) {
504 Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
505 << Result.IsIfExists;
513 while (!isEofOrEom()) {
514 trailingComma =
false;
518 if (MayBeDesignationStart())
519 SubElt = ParseInitializerWithPotentialDesignator();
521 SubElt = ParseInitializer();
523 if (Tok.
is(tok::ellipsis))
528 InitExprs.push_back(SubElt.
get());
532 if (Tok.
is(tok::comma)) {
534 trailingComma =
true;
537 if (Tok.
is(tok::r_brace))
541 Braces.consumeClose();
543 return !trailingComma;
const LangOptions & getLangOpts() const
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
ActionResult< Expr * > ExprResult
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
const Token & NextToken()
The message is a class message, and the identifier is a type name.
OpaquePtr< QualType > ParsedType
const LangOptions & getLangOpts() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation Loc, bool GNUSyntax, ExprResult Init)
tok::TokenKind getKind() const
bool isArrayDesignator() const
StringRef getName() const
Return the actual identifier string.
The message is an instance message.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
bool isNot(tok::TokenKind K) const
ObjCMessageKind getObjCMessageKind(Scope *S, IdentifierInfo *Name, SourceLocation NameLoc, bool IsSuper, bool HasTrailingDot, ParsedType &ReceiverType)
const IdentifierInfo * getField() const
The result type of a method or function.
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion...
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
Scope * getCurScope() const
bool isArrayRangeDesignator() const
const Designator & getDesignator(unsigned Idx) const
The message is sent to 'super'.
ExprResult ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, SourceLocation RBraceLoc)
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
bool is(tok::TokenKind K) const
bool isInObjcMethodScope() const
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc, Designation &Desig)
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
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.
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
void AddDesignator(Designator D)
AddDesignator - Add a designator to the end of this list.
SourceLocation ConsumeToken()
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, 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...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
Represents a complete lambda introducer.
static Designator getArray(Expr *Index, SourceLocation LBracketLoc)
A trivial tuple used to represent a source range.
static Designator getArrayRange(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
unsigned getNumDesignators() const
static OpaquePtr getFromOpaquePtr(void *P)
SourceLocation ColonLoc
Location of ':'.
Stop skipping at specified token, but don't skip the token itself.
IdentifierInfo * getIdentifierInfo() const