From 0350ca519405051e8d45d12ee7d09569a6a9c4c9 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 22 May 2009 10:23:40 +0000 Subject: [PATCH] Modification to ParseParenExpression. Now it parses the cast expression unless 'stopIfCastExpr' is true. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72258 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Parser.h | 1 + lib/Parse/ParseExpr.cpp | 41 ++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 69488fcda8..9cc5c9c71b 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -686,6 +686,7 @@ private: CastExpr // Also allow '(' type-name ')' }; OwningExprResult ParseParenExpression(ParenParseOption &ExprType, + bool stopIfCastExpr, TypeTy *&CastTy, SourceLocation &RParenLoc); diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index ac2d4a88df..c784934177 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -529,7 +529,8 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, 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 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, // 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 @@ Parser::ParseExprAfterTypeofSizeofAlignof(const Token &OpTok, // 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 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() { /// 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 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() { /// '(' 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 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, 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); -- 2.40.0