diff options
Diffstat (limited to 'clang/lib/Parse/ParseExpr.cpp')
| -rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 59 | 
1 files changed, 55 insertions, 4 deletions
| diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 4dcdfbf993e..e1439d63780 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -473,12 +473,14 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {  ///  ExprResult Parser::ParseCastExpression(bool isUnaryExpression,                                         bool isAddressOfOperand, -                                       TypeCastState isTypeCast) { +                                       TypeCastState isTypeCast, +                                       bool isVectorLiteral) {    bool NotCastExpr;    ExprResult Res = ParseCastExpression(isUnaryExpression,                                         isAddressOfOperand,                                         NotCastExpr, -                                       isTypeCast); +                                       isTypeCast, +                                       isVectorLiteral);    if (NotCastExpr)      Diag(Tok, diag::err_expected_expression);    return Res; @@ -694,7 +696,8 @@ class CastExpressionIdValidator : public CorrectionCandidateCallback {  ExprResult Parser::ParseCastExpression(bool isUnaryExpression,                                         bool isAddressOfOperand,                                         bool &NotCastExpr, -                                       TypeCastState isTypeCast) { +                                       TypeCastState isTypeCast, +                                       bool isVectorLiteral) {    ExprResult Res;    tok::TokenKind SavedKind = Tok.getKind();    NotCastExpr = false; @@ -722,6 +725,9 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,      Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,                                 isTypeCast == IsTypeCast, CastTy, RParenLoc); +    if (isVectorLiteral) +        return Res; +      switch (ParenExprType) {      case SimpleExpr:   break;    // Nothing else to do.      case CompoundStmt: break;  // Nothing else to do. @@ -2350,6 +2356,48 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,          return ParseCompoundLiteralExpression(Ty.get(), OpenLoc, RParenLoc);        } +      if (Tok.is(tok::l_paren)) { +        // This could be OpenCL vector Literals +        if (getLangOpts().OpenCL) +        { +          TypeResult Ty; +          { +            InMessageExpressionRAIIObject InMessage(*this, false); +            Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); +          } +          if(Ty.isInvalid()) +          { +             return ExprError(); +          } +          QualType QT = Ty.get().get().getCanonicalType(); +          if (QT->isVectorType()) +          { +            // We parsed '(' vector-type-name ')' followed by '(' + +            // Parse the cast-expression that follows it next. +            // isVectorLiteral = true will make sure we don't parse any +            // Postfix expression yet +            Result = ParseCastExpression(/*isUnaryExpression=*/false, +                                         /*isAddressOfOperand=*/false, +                                         /*isTypeCast=*/IsTypeCast, +                                         /*isVectorLiteral=*/true); + +            if (!Result.isInvalid()) { +              Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc, +                                             DeclaratorInfo, CastTy, +                                             RParenLoc, Result.get()); +            } + +            // After we performed the cast we can check for postfix-expr pieces. +            if (!Result.isInvalid()) { +              Result = ParsePostfixExpressionSuffix(Result); +            } + +            return Result; +          } +        } +      } +        if (ExprType == CastExpr) {          // We parsed '(' type-name ')' and the thing after it wasn't a '{'. @@ -2379,10 +2427,13 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,          }          // Parse the cast-expression that follows it next. +        // isVectorLiteral = true will make sure we don't parse any +        // Postfix expression yet          // TODO: For cast expression with CastTy.          Result = ParseCastExpression(/*isUnaryExpression=*/false,                                       /*isAddressOfOperand=*/false, -                                     /*isTypeCast=*/IsTypeCast); +                                     /*isTypeCast=*/IsTypeCast, +                                     /*isVectorLiteral=*/true);          if (!Result.isInvalid()) {            Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,                                           DeclaratorInfo, CastTy,  | 

