diff options
Diffstat (limited to 'lib/Parse/ParseExpr.cpp')
-rw-r--r-- | lib/Parse/ParseExpr.cpp | 139 |
1 files changed, 48 insertions, 91 deletions
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index c7be0d3ff2b9..956ba36d3c88 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -22,77 +22,16 @@ //===----------------------------------------------------------------------===// #include "clang/Parse/Parser.h" +#include "RAIIObjectsForParser.h" +#include "clang/Basic/PrettyStackTrace.h" #include "clang/Sema/DeclSpec.h" -#include "clang/Sema/Scope.h" #include "clang/Sema/ParsedTemplate.h" +#include "clang/Sema/Scope.h" #include "clang/Sema/TypoCorrection.h" -#include "clang/Basic/PrettyStackTrace.h" -#include "RAIIObjectsForParser.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" using namespace clang; -/// \brief Return the precedence of the specified binary operator token. -static prec::Level getBinOpPrecedence(tok::TokenKind Kind, - bool GreaterThanIsOperator, - bool CPlusPlus0x) { - switch (Kind) { - case tok::greater: - // C++ [temp.names]p3: - // [...] When parsing a template-argument-list, the first - // non-nested > is taken as the ending delimiter rather than a - // greater-than operator. [...] - if (GreaterThanIsOperator) - return prec::Relational; - return prec::Unknown; - - case tok::greatergreater: - // C++0x [temp.names]p3: - // - // [...] Similarly, the first non-nested >> is treated as two - // consecutive but distinct > tokens, the first of which is - // taken as the end of the template-argument-list and completes - // the template-id. [...] - if (GreaterThanIsOperator || !CPlusPlus0x) - return prec::Shift; - return prec::Unknown; - - default: return prec::Unknown; - case tok::comma: return prec::Comma; - case tok::equal: - case tok::starequal: - case tok::slashequal: - case tok::percentequal: - case tok::plusequal: - case tok::minusequal: - case tok::lesslessequal: - case tok::greatergreaterequal: - case tok::ampequal: - case tok::caretequal: - case tok::pipeequal: return prec::Assignment; - case tok::question: return prec::Conditional; - case tok::pipepipe: return prec::LogicalOr; - case tok::ampamp: return prec::LogicalAnd; - case tok::pipe: return prec::InclusiveOr; - case tok::caret: return prec::ExclusiveOr; - case tok::amp: return prec::And; - case tok::exclaimequal: - case tok::equalequal: return prec::Equality; - case tok::lessequal: - case tok::less: - case tok::greaterequal: return prec::Relational; - case tok::lessless: return prec::Shift; - case tok::plus: - case tok::minus: return prec::Additive; - case tok::percent: - case tok::slash: - case tok::star: return prec::Multiplicative; - case tok::periodstar: - case tok::arrowstar: return prec::PointerToMember; - } -} - - /// \brief Simple precedence-based parser for binary/ternary operators. /// /// Note: we diverge from the C99 grammar when parsing the assignment-expression @@ -282,7 +221,7 @@ ExprResult Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) { prec::Level NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator, - getLangOpts().CPlusPlus0x); + getLangOpts().CPlusPlus11); SourceLocation ColonLoc; while (1) { @@ -383,7 +322,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) { // they only appear on the RHS of assignments later. ExprResult RHS; bool RHSIsInitList = false; - if (getLangOpts().CPlusPlus0x && Tok.is(tok::l_brace)) { + if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { RHS = ParseBraceInitializer(); RHSIsInitList = true; } else if (getLangOpts().CPlusPlus && NextTokPrec <= prec::Conditional) @@ -398,7 +337,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) { // operator immediately to the right of the RHS. prec::Level ThisPrec = NextTokPrec; NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator, - getLangOpts().CPlusPlus0x); + getLangOpts().CPlusPlus11); // Assignment and conditional expressions are right-associative. bool isRightAssoc = ThisPrec == prec::Conditional || @@ -426,7 +365,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) { LHS = ExprError(); NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator, - getLangOpts().CPlusPlus0x); + getLangOpts().CPlusPlus11); } assert(NextTokPrec <= ThisPrec && "Recursion didn't work!"); @@ -1036,7 +975,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::annot_typename: if (isStartOfObjCClassMessageMissingOpenBracket()) { ParsedType Type = getTypeAnnotation(Tok); - + // Fake up a Declarator to use with ActOnTypeName. DeclSpec DS(AttrFactory); DS.SetRangeStart(Tok.getLocation()); @@ -1046,7 +985,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, unsigned DiagID; DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(), PrevSpec, DiagID, Type); - + Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); if (Ty.isInvalid()) @@ -1058,7 +997,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, break; } // Fall through - + case tok::annot_decltype: case tok::kw_char: case tok::kw_wchar_t: @@ -1078,7 +1017,15 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::kw_void: case tok::kw_typename: case tok::kw_typeof: - case tok::kw___vector: { + case tok::kw___vector: + case tok::kw_image1d_t: + case tok::kw_image1d_array_t: + case tok::kw_image1d_buffer_t: + case tok::kw_image2d_t: + case tok::kw_image2d_array_t: + case tok::kw_image3d_t: + case tok::kw_sampler_t: + case tok::kw_event_t: { if (!getLangOpts().CPlusPlus) { Diag(Tok, diag::err_expected_expression); return ExprError(); @@ -1097,7 +1044,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, DeclSpec DS(AttrFactory); ParseCXXSimpleTypeSpecifier(DS); if (Tok.isNot(tok::l_paren) && - (!getLangOpts().CPlusPlus0x || Tok.isNot(tok::l_brace))) + (!getLangOpts().CPlusPlus11 || Tok.isNot(tok::l_brace))) return ExprError(Diag(Tok, diag::err_expected_lparen_after_type) << DS.getSourceRange()); @@ -1241,10 +1188,13 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::kw___is_union: case tok::kw___is_final: case tok::kw___has_trivial_constructor: + case tok::kw___has_trivial_move_constructor: case tok::kw___has_trivial_copy: case tok::kw___has_trivial_assign: + case tok::kw___has_trivial_move_assign: case tok::kw___has_trivial_destructor: case tok::kw___has_nothrow_assign: + case tok::kw___has_nothrow_move_assign: case tok::kw___has_nothrow_copy: case tok::kw___has_nothrow_constructor: case tok::kw___has_virtual_destructor: @@ -1282,7 +1232,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, return ExprError(); } case tok::l_square: - if (getLangOpts().CPlusPlus0x) { + if (getLangOpts().CPlusPlus11) { if (getLangOpts().ObjC1) { // C++11 lambda expressions and Objective-C message sends both start with a // square bracket. There are three possibilities here: @@ -1381,7 +1331,7 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { T.consumeOpen(); Loc = T.getOpenLocation(); ExprResult Idx; - if (getLangOpts().CPlusPlus0x && Tok.is(tok::l_brace)) { + if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); Idx = ParseBraceInitializer(); } else @@ -1459,7 +1409,7 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteCall(getCurScope(), LHS.get(), - llvm::ArrayRef<Expr *>()); + ArrayRef<Expr *>()); cutOffParsing(); return ExprError(); } @@ -1663,11 +1613,11 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, /// unary-expression: [C99 6.5.3] /// 'sizeof' unary-expression /// 'sizeof' '(' type-name ')' -/// [C++0x] 'sizeof' '...' '(' identifier ')' +/// [C++11] 'sizeof' '...' '(' identifier ')' /// [GNU] '__alignof' unary-expression /// [GNU] '__alignof' '(' type-name ')' /// [C11] '_Alignof' '(' type-name ')' -/// [C++0x] 'alignof' '(' type-id ')' +/// [C++11] 'alignof' '(' type-id ')' /// \endverbatim ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() { assert((Tok.is(tok::kw_sizeof) || Tok.is(tok::kw___alignof) || @@ -1677,7 +1627,7 @@ ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() { Token OpTok = Tok; ConsumeToken(); - // [C++0x] 'sizeof' '...' '(' identifier ')' + // [C++11] 'sizeof' '...' '(' identifier ')' if (Tok.is(tok::ellipsis) && OpTok.is(tok::kw_sizeof)) { SourceLocation EllipsisLoc = ConsumeToken(); SourceLocation LParenLoc, RParenLoc; @@ -1748,6 +1698,9 @@ ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() { CastTy.getAsOpaquePtr(), CastRange); + if (OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof)) + Diag(OpTok, diag::ext_alignof_expr) << OpTok.getIdentifierInfo(); + // If we get here, the operand to the sizeof/alignof was an expresion. if (!Operand.isInvalid()) Operand = Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(), @@ -2008,12 +1961,16 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, Tok.is(tok::kw___bridge_retained) || Tok.is(tok::kw___bridge_retain))); if (BridgeCast && !getLangOpts().ObjCAutoRefCount) { - StringRef BridgeCastName = Tok.getName(); - SourceLocation BridgeKeywordLoc = ConsumeToken(); - if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc)) - Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc) - << BridgeCastName - << FixItHint::CreateReplacement(BridgeKeywordLoc, ""); + if (Tok.isNot(tok::kw___bridge)) { + StringRef BridgeCastName = Tok.getName(); + SourceLocation BridgeKeywordLoc = ConsumeToken(); + if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc)) + Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc) + << BridgeCastName + << FixItHint::CreateReplacement(BridgeKeywordLoc, ""); + } + else + ConsumeToken(); // consume __bridge BridgeCast = false; } @@ -2360,10 +2317,10 @@ ExprResult Parser::ParseGenericSelectionExpression() { /// [C++0x] braced-init-list /// \endverbatim bool Parser::ParseExpressionList(SmallVectorImpl<Expr*> &Exprs, - SmallVectorImpl<SourceLocation> &CommaLocs, - void (Sema::*Completer)(Scope *S, - Expr *Data, - llvm::ArrayRef<Expr *> Args), + SmallVectorImpl<SourceLocation> &CommaLocs, + void (Sema::*Completer)(Scope *S, + Expr *Data, + ArrayRef<Expr *> Args), Expr *Data) { while (1) { if (Tok.is(tok::code_completion)) { @@ -2376,7 +2333,7 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr*> &Exprs, } ExprResult Expr; - if (getLangOpts().CPlusPlus0x && Tok.is(tok::l_brace)) { + if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); Expr = ParseBraceInitializer(); } else |