[cfe-commits] r72259 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Fri May 22 03:24:05 PDT 2009
Author: akirtzidis
Date: Fri May 22 05:24:05 2009
New Revision: 72259
URL: http://llvm.org/viewvc/llvm-project?rev=72259&view=rev
Log:
Factor the compound literal parsing out from ParseParenExpression and into a new ParseCompoundLiteralExpression.
No functionality change.
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExpr.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=72259&r1=72258&r2=72259&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri May 22 05:24:05 2009
@@ -690,6 +690,10 @@
TypeTy *&CastTy,
SourceLocation &RParenLoc);
+ OwningExprResult ParseCompoundLiteralExpression(TypeTy *Ty,
+ SourceLocation LParenLoc,
+ SourceLocation RParenLoc);
+
OwningExprResult ParseStringLiteralExpression();
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=72259&r1=72258&r2=72259&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri May 22 05:24:05 2009
@@ -1239,14 +1239,8 @@
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 @@
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].
More information about the cfe-commits
mailing list