[cfe-commits] r38879 - in /cfe/cfe/trunk: Parse/ParseExpr.cpp include/clang/Parse/Parser.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:25:26 PDT 2007
Author: sabre
Date: Wed Jul 11 11:25:26 2007
New Revision: 38879
URL: http://llvm.org/viewvc/llvm-project?rev=38879&view=rev
Log:
Fix incorrect parsing of the ?: middle term, which is supposed to be
parsed as 'expression'. This implements test/Parser/statements.c
Modified:
cfe/cfe/trunk/Parse/ParseExpr.cpp
cfe/cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=38879&r1=38878&r2=38879&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:25:26 2007
@@ -45,10 +45,6 @@
-Parser::ExprResult Parser::ParseExpression() {
- return ParseBinaryExpression();
-}
-
// Expr that doesn't include commas.
Parser::ExprResult Parser::ParseAssignmentExpression() {
return ParseExpression();
@@ -197,7 +193,7 @@
/// assignment-expression
/// expression ',' assignment-expression
///
-Parser::ExprResult Parser::ParseBinaryExpression() {
+Parser::ExprResult Parser::ParseExpression() {
ExprResult LHS = ParseCastExpression(false);
if (LHS.isInvalid) return LHS;
@@ -223,13 +219,21 @@
// Parse the RHS of the operator.
ExprResult RHS;
-
- // Special case handling of "X ? Y : Z" were Y is empty. This is a GCC
- // extension.
- if (OpToken.getKind() != tok::question || Tok.getKind() != tok::colon) {
+
+ // In the normal case, just parse another leaf here.
+ if (OpToken.getKind() != tok::question) {
RHS = ParseCastExpression(false);
if (RHS.isInvalid) return RHS;
+ } else if (Tok.getKind() != tok::colon) {
+ // Handle this production specially:
+ // logical-OR-expression '?' expression ':' conditional-expression
+ // In particular, the RHS of the '?' is 'expression', not
+ // 'logical-OR-expression' as we might expect.
+ RHS = ParseExpression();
+ if (RHS.isInvalid) return RHS;
} else {
+ // Special case handling of "X ? Y : Z" where Y is empty:
+ // logical-OR-expression '?' ':' conditional-expression [GNU]
RHS = ExprResult(false);
Diag(Tok, diag::ext_gnu_conditional_expr);
}
Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=38879&r1=38878&r2=38879&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:25:26 2007
@@ -180,7 +180,6 @@
//ExprResult ParseExpression(); // Above.
ExprResult ParseAssignmentExpression(); // Expr that doesn't include commas.
- ExprResult ParseBinaryExpression();
ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec);
ExprResult ParseCastExpression(bool isUnaryExpression);
ExprResult ParseSizeofAlignofExpression();
More information about the cfe-commits
mailing list