18 #include "llvm/ADT/SmallString.h" 19 using namespace clang;
25 bool Parser::MayBeDesignationStart() {
68 RevertingTentativeParsingAction Tentative(*
this);
71 LambdaIntroducerTentativeParse ParseResult;
72 if (ParseLambdaIntroducer(Intro, &ParseResult)) {
78 switch (ParseResult) {
79 case LambdaIntroducerTentativeParse::Success:
80 case LambdaIntroducerTentativeParse::Incomplete:
86 case LambdaIntroducerTentativeParse::MessageSend:
87 case LambdaIntroducerTentativeParse::Invalid:
98 return Tok.
is(tok::equal);
109 P.
Diag(Loc, diag::ext_gnu_missing_equal_designator);
111 P.
Diag(Loc, diag::err_expected_equal_designator);
138 ExprResult Parser::ParseInitializerWithPotentialDesignator() {
144 if (Tok.
is(tok::identifier)) {
148 llvm::raw_svector_ostream(NewSyntax) <<
'.' << FieldName->
getName()
153 assert(Tok.
is(tok::colon) &&
"MayBeDesignationStart not working properly!");
156 Diag(NameLoc, diag::ext_gnu_old_style_field_designator)
172 while (Tok.
is(tok::period) || Tok.
is(tok::l_square)) {
173 if (Tok.
is(tok::period)) {
177 if (Tok.
isNot(tok::identifier)) {
189 assert(Tok.
is(tok::l_square) &&
"Unexpected token!");
226 return ParseAssignmentExprWithObjCMessageExprStart(
233 if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
242 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
252 Idx =
ExprResult(static_cast<Expr*>(TypeOrExpr));
262 NextToken().is(tok::period), ReceiverType)) {
265 return ParseAssignmentExprWithObjCMessageExprStart(
277 if (Tok.
is(tok::less)) {
280 = parseObjCTypeArgsAndProtocolQualifiers(IILoc, ReceiverType,
288 ReceiverType = NewReceiverType.
get();
291 return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
324 Tok.
isNot(tok::r_square)) {
326 return ParseAssignmentExprWithObjCMessageExprStart(
331 if (Tok.
isNot(tok::ellipsis)) {
335 Diag(Tok, diag::ext_gnu_array_range);
345 StartLoc, EllipsisLoc));
357 assert(!Desig.
empty() &&
"Designator is empty?");
360 if (Tok.
is(tok::equal)) {
373 Diag(Tok, diag::ext_gnu_missing_equal_designator)
376 true, ParseInitializer());
379 Diag(Tok, diag::err_expected_equal_designator);
405 ExprVector InitExprs;
407 if (Tok.
is(tok::r_brace)) {
410 Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
419 bool InitExprsOk =
true;
423 if (
getLangOpts().MicrosoftExt && (Tok.
is(tok::kw___if_exists) ||
424 Tok.
is(tok::kw___if_not_exists))) {
425 if (ParseMicrosoftIfExistsBraceInitializer(InitExprs, InitExprsOk)) {
426 if (Tok.
isNot(tok::comma))
break;
429 if (Tok.
is(tok::r_brace))
break;
438 if (MayBeDesignationStart())
439 SubElt = ParseInitializerWithPotentialDesignator();
441 SubElt = ParseInitializer();
443 if (Tok.
is(tok::ellipsis))
450 InitExprs.push_back(SubElt.
get());
462 if (Tok.
isNot(tok::comma)) {
469 if (Tok.
isNot(tok::comma))
break;
475 if (Tok.
is(tok::r_brace))
break;
480 if (InitExprsOk && closed)
490 bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
492 bool trailingComma =
false;
494 if (ParseMicrosoftIfExistsCondition(Result))
499 Diag(Tok, diag::err_expected) << tok::l_brace;
503 switch (Result.Behavior) {
509 Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
510 << Result.IsIfExists;
519 while (!isEofOrEom()) {
520 trailingComma =
false;
524 if (MayBeDesignationStart())
525 SubElt = ParseInitializerWithPotentialDesignator();
527 SubElt = ParseInitializer();
529 if (Tok.
is(tok::ellipsis))
534 InitExprs.push_back(SubElt.
get());
538 if (Tok.
is(tok::comma)) {
540 trailingComma =
true;
543 if (Tok.
is(tok::r_brace))
549 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.
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
const LangOptions & getLangOpts() const
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation Loc, bool GNUSyntax, ExprResult Init)
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.