diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-05-22 10:24:05 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-05-22 10:24:05 +0000 |
commit | d974a7b72eb84cdc735b189bcea56fd37e13ebf6 (patch) | |
tree | d9c793a015a93c6ddf6c33e35ab51c0a882a017e /lib/Parse/ParseExpr.cpp | |
parent | 0350ca519405051e8d45d12ee7d09569a6a9c4c9 (diff) |
Factor the compound literal parsing out from ParseParenExpression and into a new ParseCompoundLiteralExpression.
No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72259 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseExpr.cpp')
-rw-r--r-- | lib/Parse/ParseExpr.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index c784934177..12ba001f0e 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1239,14 +1239,8 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, MatchRHSPunctuation(tok::r_paren, OpenLoc); if (Tok.is(tok::l_brace)) { - if (!getLang().C99) // Compound literals don't exist in C90. - Diag(OpenLoc, diag::ext_c99_compound_literal); - Result = ParseInitializer(); ExprType = CompoundLiteral; - if (!Result.isInvalid() && !Ty.isInvalid()) - Result = Actions.ActOnCompoundLiteral(OpenLoc, Ty.get(), RParenLoc, - move(Result)); - return move(Result); + return ParseCompoundLiteralExpression(Ty.get(), OpenLoc, RParenLoc); } if (ExprType == CastExpr) { @@ -1294,6 +1288,26 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, return move(Result); } +/// ParseCompoundLiteralExpression - We have parsed the parenthesized type-name +/// and we are at the left brace. +/// +/// postfix-expression: [C99 6.5.2] +/// '(' type-name ')' '{' initializer-list '}' +/// '(' type-name ')' '{' initializer-list ',' '}' +/// +Parser::OwningExprResult +Parser::ParseCompoundLiteralExpression(TypeTy *Ty, + SourceLocation LParenLoc, + SourceLocation RParenLoc) { + assert(Tok.is(tok::l_brace) && "Not a compound literal!"); + if (!getLang().C99) // Compound literals don't exist in C90. + Diag(LParenLoc, diag::ext_c99_compound_literal); + OwningExprResult Result = ParseInitializer(); + if (!Result.isInvalid() && Ty) + return Actions.ActOnCompoundLiteral(LParenLoc, Ty, RParenLoc, move(Result)); + return move(Result); +} + /// ParseStringLiteralExpression - This handles the various token types that /// form string literals, and also handles string concatenation [C99 5.1.1.2, /// translation phase #6]. |