diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2014-11-24 09:15:30 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2014-11-24 09:15:30 +0000 |
commit | 9f4dbff6669c8037f3b036bcf580d14f1a4f12a5 (patch) | |
tree | 47df2c12b57214af6c31e47404b005675b8b7ffc /lib/Parse/ParseInit.cpp | |
parent | f73d5f23a889b93d89ddef61ac0995df40286bb8 (diff) |
Notes
Diffstat (limited to 'lib/Parse/ParseInit.cpp')
-rw-r--r-- | lib/Parse/ParseInit.cpp | 84 |
1 files changed, 33 insertions, 51 deletions
diff --git a/lib/Parse/ParseInit.cpp b/lib/Parse/ParseInit.cpp index 37f74bbcd51b..8536420088f3 100644 --- a/lib/Parse/ParseInit.cpp +++ b/lib/Parse/ParseInit.cpp @@ -66,47 +66,29 @@ bool Parser::MayBeDesignationStart() { } // Parse up to (at most) the token after the closing ']' to determine - // whether this is a C99 designator or a lambda. + // whether this is a C99 designator or a lambda. TentativeParsingAction Tentative(*this); - ConsumeBracket(); - while (true) { - switch (Tok.getKind()) { - case tok::equal: - case tok::amp: - case tok::identifier: - case tok::kw_this: - // These tokens can occur in a capture list or a constant-expression. - // Keep looking. - ConsumeToken(); - continue; - - case tok::comma: - // Since a comma cannot occur in a constant-expression, this must - // be a lambda. - Tentative.Revert(); - return false; - - case tok::r_square: { - // Once we hit the closing square bracket, we look at the next - // token. If it's an '=', this is a designator. Otherwise, it's a - // lambda expression. This decision favors lambdas over the older - // GNU designator syntax, which allows one to omit the '=', but is - // consistent with GCC. - ConsumeBracket(); - tok::TokenKind Kind = Tok.getKind(); - Tentative.Revert(); - return Kind == tok::equal; - } - - default: - // Anything else cannot occur in a lambda capture list, so it - // must be a designator. - Tentative.Revert(); - return true; - } + + LambdaIntroducer Intro; + bool SkippedInits = false; + Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro, &SkippedInits)); + + if (DiagID) { + // If this can't be a lambda capture list, it's a designator. + Tentative.Revert(); + return true; } - - return true; + + // Once we hit the closing square bracket, we look at the next + // token. If it's an '=', this is a designator. Otherwise, it's a + // lambda expression. This decision favors lambdas over the older + // GNU designator syntax, which allows one to omit the '=', but is + // consistent with GCC. + tok::TokenKind Kind = Tok.getKind(); + // FIXME: If we didn't skip any inits, parse the lambda from here + // rather than throwing away then reparsing the LambdaIntroducer. + Tentative.Revert(); + return Kind == tok::equal; } static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc, @@ -237,7 +219,7 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator() { return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, ConsumeToken(), ParsedType(), - 0); + nullptr); } // Parse the receiver, which is either a type or an expression. @@ -255,7 +237,7 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator() { return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, SourceLocation(), ParsedType::getFromOpaquePtr(TypeOrExpr), - 0); + nullptr); } // If the receiver was an expression, we still don't know @@ -282,7 +264,7 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator() { return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, ConsumeToken(), ParsedType(), - 0); + nullptr); ConsumeToken(); // the identifier if (!ReceiverType) { SkipUntil(tok::r_square, StopAtSemi); @@ -292,7 +274,7 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator() { return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, SourceLocation(), ReceiverType, - 0); + nullptr); case Sema::ObjCInstanceMessage: // Fall through; we'll just parse the expression and @@ -327,12 +309,12 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator() { return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, SourceLocation(), ParsedType(), - Idx.take()); + Idx.get()); } // If this is a normal array designator, remember it. if (Tok.isNot(tok::ellipsis)) { - Desig.AddDesignator(Designator::getArray(Idx.release(), StartLoc)); + Desig.AddDesignator(Designator::getArray(Idx.get(), StartLoc)); } else { // Handle the gnu array range extension. Diag(Tok, diag::ext_gnu_array_range); @@ -343,8 +325,8 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator() { SkipUntil(tok::r_square, StopAtSemi); return RHS; } - Desig.AddDesignator(Designator::getArrayRange(Idx.release(), - RHS.release(), + Desig.AddDesignator(Designator::getArrayRange(Idx.get(), + RHS.get(), StartLoc, EllipsisLoc)); } @@ -444,7 +426,7 @@ ExprResult Parser::ParseBraceInitializer() { // If we couldn't parse the subelement, bail out. if (!SubElt.isInvalid()) { - InitExprs.push_back(SubElt.release()); + InitExprs.push_back(SubElt.get()); } else { InitExprsOk = false; @@ -493,7 +475,7 @@ bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, BalancedDelimiterTracker Braces(*this, tok::l_brace); if (Braces.consumeOpen()) { - Diag(Tok, diag::err_expected_lbrace); + Diag(Tok, diag::err_expected) << tok::l_brace; return false; } @@ -512,7 +494,7 @@ bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, return false; } - while (Tok.isNot(tok::eof)) { + while (!isEofOrEom()) { trailingComma = false; // If we know that this cannot be a designation, just parse the nested // initializer directly. @@ -527,7 +509,7 @@ bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, // If we couldn't parse the subelement, bail out. if (!SubElt.isInvalid()) - InitExprs.push_back(SubElt.release()); + InitExprs.push_back(SubElt.get()); else InitExprsOk = false; |