[cfe-commits] r72258 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Fri May 22 03:23:41 PDT 2009


Author: akirtzidis
Date: Fri May 22 05:23:40 2009
New Revision: 72258

URL: http://llvm.org/viewvc/llvm-project?rev=72258&view=rev
Log:
Modification to ParseParenExpression.
Now it parses the cast expression unless 'stopIfCastExpr' is true.

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=72258&r1=72257&r2=72258&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri May 22 05:23:40 2009
@@ -686,6 +686,7 @@
     CastExpr         // Also allow '(' type-name ')' <anything>
   };
   OwningExprResult ParseParenExpression(ParenParseOption &ExprType,
+                                        bool stopIfCastExpr,
                                         TypeTy *&CastTy,
                                         SourceLocation &RParenLoc);
   

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=72258&r1=72257&r2=72258&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri May 22 05:23:40 2009
@@ -529,7 +529,8 @@
     TypeTy *CastTy;
     SourceLocation LParenLoc = Tok.getLocation();
     SourceLocation RParenLoc;
-    Res = ParseParenExpression(ParenExprType, CastTy, RParenLoc);
+    Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
+                               CastTy, RParenLoc);
     if (Res.isInvalid()) return move(Res);
     
     switch (ParenExprType) {
@@ -540,12 +541,8 @@
       // postfix-expression exist, parse them now.
       break;
     case CastExpr:
-      // We parsed '(' type-name ')' and the thing after it wasn't a '{'.  Parse
-      // the cast-expression that follows it next.
-      // TODO: For cast expression with CastTy.
-      Res = ParseCastExpression(false);
-      if (!Res.isInvalid())
-        Res = Actions.ActOnCastExpr(LParenLoc, CastTy, RParenLoc, move(Res));
+      // We have parsed the cast-expression and no postfix-expr pieces are
+      // following.
       return move(Res);
     }
 
@@ -958,7 +955,8 @@
     // expression.
     ParenParseOption ExprType = CastExpr;
     SourceLocation LParenLoc = Tok.getLocation(), RParenLoc;
-    Operand = ParseParenExpression(ExprType, CastTy, RParenLoc);
+    Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/,
+                                   CastTy, RParenLoc);
     CastRange = SourceRange(LParenLoc, RParenLoc);
 
     // If ParseParenExpression parsed a '(typename)' sequence only, then this is
@@ -1199,7 +1197,8 @@
 
 /// ParseParenExpression - This parses the unit that starts with a '(' token,
 /// based on what is allowed by ExprType.  The actual thing parsed is returned
-/// in ExprType.
+/// in ExprType. If stopIfCastExpr is true, it will only return the parsed type,
+/// not the parsed cast-expression.
 ///
 ///       primary-expression: [C99 6.5.1]
 ///         '(' expression ')'
@@ -1211,7 +1210,7 @@
 ///         '(' type-name ')' cast-expression
 ///
 Parser::OwningExprResult
-Parser::ParseParenExpression(ParenParseOption &ExprType,
+Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
                              TypeTy *&CastTy, SourceLocation &RParenLoc) {
   assert(Tok.is(tok::l_paren) && "Not a paren expr!");
   GreaterThanIsOperatorScope G(GreaterThanIsOperator, true);
@@ -1245,21 +1244,31 @@
       Result = ParseInitializer();
       ExprType = CompoundLiteral;
       if (!Result.isInvalid() && !Ty.isInvalid())
-        return Actions.ActOnCompoundLiteral(OpenLoc, Ty.get(), RParenLoc,
-                                            move(Result));
+        Result = Actions.ActOnCompoundLiteral(OpenLoc, Ty.get(), RParenLoc,
+                                              move(Result));
       return move(Result);
     }
 
     if (ExprType == CastExpr) {
-      // Note that this doesn't parse the subsequent cast-expression, it just
-      // returns the parsed type to the callee.
-      ExprType = CastExpr;
+      // We parsed '(' type-name ')' and the thing after it wasn't a '{'.
 
       if (Ty.isInvalid())
         return ExprError();
 
       CastTy = Ty.get();
-      return OwningExprResult(Actions);
+
+      if (stopIfCastExpr) {
+        // Note that this doesn't parse the subsequent cast-expression, it just
+        // returns the parsed type to the callee.
+        return OwningExprResult(Actions);
+      }
+
+      // Parse the cast-expression that follows it next.
+      // TODO: For cast expression with CastTy.
+      Result = ParseCastExpression(false);
+      if (!Result.isInvalid())
+        Result = Actions.ActOnCastExpr(OpenLoc, CastTy, RParenLoc,move(Result));
+      return move(Result);
     }
 
     Diag(Tok, diag::err_expected_lbrace_in_compound_literal);





More information about the cfe-commits mailing list