18 #include "llvm/ADT/SmallString.h" 19 using namespace clang;
25 bool Parser::MayBeDesignationStart() {
70 RevertingTentativeParsingAction Tentative(*
this);
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);
157 ExprResult Parser::ParseInitializerWithPotentialDesignator() {
163 if (Tok.
is(tok::identifier)) {
167 llvm::raw_svector_ostream(NewSyntax) <<
'.' << FieldName->
getName()
172 assert(Tok.
is(tok::colon) &&
"MayBeDesignationStart not working properly!");
175 Diag(NameLoc, diag::ext_gnu_old_style_field_designator)
191 while (Tok.
is(tok::period) || Tok.
is(tok::l_square)) {
192 if (Tok.
is(tok::period)) {
196 if (Tok.
isNot(tok::identifier)) {
208 assert(Tok.
is(tok::l_square) &&
"Unexpected token!");
245 return ParseAssignmentExprWithObjCMessageExprStart(
252 if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
261 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
271 Idx =
ExprResult(static_cast<Expr*>(TypeOrExpr));
281 NextToken().is(tok::period), ReceiverType)) {
284 return ParseAssignmentExprWithObjCMessageExprStart(
296 if (Tok.
is(tok::less)) {
299 = parseObjCTypeArgsAndProtocolQualifiers(IILoc, ReceiverType,
307 ReceiverType = NewReceiverType.
get();
310 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
343 Tok.
isNot(tok::r_square)) {
345 return ParseAssignmentExprWithObjCMessageExprStart(
350 if (Tok.
isNot(tok::ellipsis)) {
354 Diag(Tok, diag::ext_gnu_array_range);
364 StartLoc, EllipsisLoc));
376 assert(!Desig.
empty() &&
"Designator is empty?");
379 if (Tok.
is(tok::equal)) {
390 ParseBraceInitializer());
400 Diag(Tok, diag::ext_gnu_missing_equal_designator)
403 true, ParseInitializer());
406 Diag(Tok, diag::err_expected_equal_designator);
432 ExprVector InitExprs;
434 if (Tok.
is(tok::r_brace)) {
437 Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
446 bool InitExprsOk =
true;
450 if (
getLangOpts().MicrosoftExt && (Tok.
is(tok::kw___if_exists) ||
451 Tok.
is(tok::kw___if_not_exists))) {
452 if (ParseMicrosoftIfExistsBraceInitializer(InitExprs, InitExprsOk)) {
453 if (Tok.
isNot(tok::comma))
break;
456 if (Tok.
is(tok::r_brace))
break;
465 if (MayBeDesignationStart())
466 SubElt = ParseInitializerWithPotentialDesignator();
468 SubElt = ParseInitializer();
470 if (Tok.
is(tok::ellipsis))
477 InitExprs.push_back(SubElt.
get());
489 if (Tok.
isNot(tok::comma)) {
496 if (Tok.
isNot(tok::comma))
break;
502 if (Tok.
is(tok::r_brace))
break;
507 if (InitExprsOk && closed)
517 bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
519 bool trailingComma =
false;
521 if (ParseMicrosoftIfExistsCondition(Result))
526 Diag(Tok, diag::err_expected) << tok::l_brace;
530 switch (Result.Behavior) {
536 Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
537 << Result.IsIfExists;
546 while (!isEofOrEom()) {
547 trailingComma =
false;
551 if (MayBeDesignationStart())
552 SubElt = ParseInitializerWithPotentialDesignator();
554 SubElt = ParseInitializer();
556 if (Tok.
is(tok::ellipsis))
561 InitExprs.push_back(SubElt.
get());
565 if (Tok.
is(tok::comma)) {
567 trailingComma =
true;
570 if (Tok.
is(tok::r_brace))
576 return !trailingComma;
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
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)) {...
SourceLocation getCloseLocation() const
const IdentifierInfo * getField() const
bool isArrayRangeDesignator() const
Parser - This implements a parser for the C family of languages.
RAII object that enters a new expression evaluation context.
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body...
tok::TokenKind getKind() const
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 Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
The message is a class message, and the identifier is a type name.
One of these records is kept for each identifier that is lexed.
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
const LangOptions & getLangOpts() const
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...
unsigned getNumDesignators() const
The message is an instance message.
bool isArrayDesignator() const
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
ObjCMessageKind getObjCMessageKind(Scope *S, IdentifierInfo *Name, SourceLocation NameLoc, bool IsSuper, bool HasTrailingDot, ParsedType &ReceiverType)
SourceLocation getOpenLocation() 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...
const LangOptions & getLangOpts() const
const Designator & getDesignator(unsigned Idx) const
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Encodes a location in the source.
IdentifierInfo * getIdentifierInfo() const
The message is sent to 'super'.
ExprResult ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, SourceLocation RBraceLoc)
Scope * getCurScope() const
StringRef getName() const
Return the actual identifier string.
bool isNot(tok::TokenKind K) const
Dataflow Directional Tag Classes.
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.
ActionResult< Expr * > ExprResult
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
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.
Designation - Represent a full designation, which is a sequence of designators.
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)
static OpaquePtr getFromOpaquePtr(void *P)
SourceLocation ColonLoc
Location of ':'.
Stop skipping at specified token, but don't skip the token itself.