diff options
| author | Nate Begeman <natebegeman@mac.com> | 2009-08-09 17:55:44 +0000 | 
|---|---|---|
| committer | Nate Begeman <natebegeman@mac.com> | 2009-08-09 17:55:44 +0000 | 
| commit | a96114ed087b924b9e8c912dacf364d5738666be (patch) | |
| tree | 149994da557bc5b4cd714afac00666b9ac2a0cfc /clang/lib/Parse | |
| parent | f4c2eee251597e552e83685ba634896aeb390130 (diff) | |
| download | bcm5719-llvm-a96114ed087b924b9e8c912dacf364d5738666be.tar.gz bcm5719-llvm-a96114ed087b924b9e8c912dacf364d5738666be.zip  | |
AltiVec-style vector initializer syntax, vec4 a = (vec4)(a, b, c, d);
In addition to being defined by the AltiVec PIM, this is also the vector
initializer syntax used by OpenCL, so that vector literals are compatible
with macro arguments.
llvm-svn: 78535
Diffstat (limited to 'clang/lib/Parse')
| -rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 31 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseExprCXX.cpp | 5 | 
2 files changed, 26 insertions, 10 deletions
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 62bd9ae73ce..6e7deef95dc 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -407,11 +407,13 @@ Parser::ParseRHSOfBinaryExpression(OwningExprResult LHS, unsigned MinPrec) {  /// due to member pointers.  ///  Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, -                                                     bool isAddressOfOperand) { +                                                     bool isAddressOfOperand, +                                                     bool parseParenAsExprList){    bool NotCastExpr;    OwningExprResult Res = ParseCastExpression(isUnaryExpression,                                               isAddressOfOperand, -                                             NotCastExpr); +                                             NotCastExpr, +                                             parseParenAsExprList);    if (NotCastExpr)      Diag(Tok, diag::err_expected_expression);    return move(Res); @@ -530,7 +532,8 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression,  ///  Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression,                                                       bool isAddressOfOperand, -                                                     bool &NotCastExpr) { +                                                     bool &NotCastExpr, +                                                     bool parseParenAsExprList){    OwningExprResult Res(Actions);    tok::TokenKind SavedKind = Tok.getKind();    NotCastExpr = false; @@ -555,7 +558,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression,      SourceLocation LParenLoc = Tok.getLocation();      SourceLocation RParenLoc;      Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/, -                               CastTy, RParenLoc); +                               parseParenAsExprList, CastTy, RParenLoc);      if (Res.isInvalid()) return move(Res);      switch (ParenExprType) { @@ -1021,7 +1024,7 @@ Parser::ParseExprAfterTypeofSizeofAlignof(const Token &OpTok,      // operands.      EnterExpressionEvaluationContext Unevaluated(Actions,                                                   Action::Unevaluated); -    Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/, +    Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/, false,                                     CastTy, RParenLoc);      CastRange = SourceRange(LParenLoc, RParenLoc); @@ -1278,7 +1281,8 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() {  ///  Parser::OwningExprResult  Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, -                             TypeTy *&CastTy, SourceLocation &RParenLoc) { +                             bool parseAsExprList, TypeTy *&CastTy,  +                             SourceLocation &RParenLoc) {    assert(Tok.is(tok::l_paren) && "Not a paren expr!");    GreaterThanIsOperatorScope G(GreaterThanIsOperator, true);    SourceLocation OpenLoc = ConsumeParen(); @@ -1338,14 +1342,25 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,        // Parse the cast-expression that follows it next.        // TODO: For cast expression with CastTy. -      Result = ParseCastExpression(false); +      Result = ParseCastExpression(false, false, true);        if (!Result.isInvalid()) -        Result = Actions.ActOnCastExpr(OpenLoc, CastTy, RParenLoc,move(Result)); +        Result = Actions.ActOnCastExpr(CurScope, OpenLoc, CastTy, RParenLoc, +                                       move(Result));        return move(Result);      }      Diag(Tok, diag::err_expected_lbrace_in_compound_literal);      return ExprError(); +  } else if (parseAsExprList) { +    // Parse the expression-list. +    ExprVector ArgExprs(Actions); +    CommaLocsTy CommaLocs; + +    if (!ParseExpressionList(ArgExprs, CommaLocs)) { +      ExprType = SimpleExpr; +      Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),  +                                          move_arg(ArgExprs)); +    }    } else {      Result = ParseExpression();      ExprType = SimpleExpr; diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 91b4d4d5a96..46526e47dd8 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -1154,7 +1154,7 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,        // will be consumed.        Result = ParseCastExpression(false/*isUnaryExpression*/,                                     false/*isAddressofOperand*/, -                                   NotCastExpr); +                                   NotCastExpr, false);      }      // If we parsed a cast-expression, it's really a type-id, otherwise it's @@ -1196,7 +1196,8 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,      // Result is what ParseCastExpression returned earlier.      if (!Result.isInvalid()) -      Result = Actions.ActOnCastExpr(LParenLoc, CastTy, RParenLoc,move(Result)); +      Result = Actions.ActOnCastExpr(CurScope, LParenLoc, CastTy, RParenLoc,  +                                     move(Result));      return move(Result);    }  | 

