diff options
Diffstat (limited to 'lib/Sema/TreeTransform.h')
-rw-r--r-- | lib/Sema/TreeTransform.h | 360 |
1 files changed, 172 insertions, 188 deletions
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 619ad330b95b..294d74244673 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -574,6 +574,10 @@ public: /// \brief Transform the captures and body of a lambda expression. ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator); + ExprResult TransformAddressOfOperand(Expr *E); + ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, + bool IsAddressOfOperand); + #define STMT(Node, Parent) \ StmtResult Transform##Node(Node *S); #define EXPR(Node, Parent) \ @@ -1162,32 +1166,23 @@ public: /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - StmtResult RebuildAsmStmt(SourceLocation AsmLoc, - bool IsSimple, - bool IsVolatile, - unsigned NumOutputs, - unsigned NumInputs, - IdentifierInfo **Names, - MultiExprArg Constraints, - MultiExprArg Exprs, - Expr *AsmString, - MultiExprArg Clobbers, - SourceLocation RParenLoc, - bool MSAsm) { - return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, - NumInputs, Names, move(Constraints), - Exprs, AsmString, Clobbers, - RParenLoc, MSAsm); + StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, + bool IsVolatile, unsigned NumOutputs, + unsigned NumInputs, IdentifierInfo **Names, + MultiExprArg Constraints, MultiExprArg Exprs, + Expr *AsmString, MultiExprArg Clobbers, + SourceLocation RParenLoc) { + return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, + NumInputs, Names, Constraints, Exprs, + AsmString, Clobbers, RParenLoc); } /// \brief Build a new MS style inline asm statement. /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, - SourceLocation LBraceLoc, - ArrayRef<Token> AsmToks, - SourceLocation EndLoc) { + StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, + ArrayRef<Token> AsmToks, SourceLocation EndLoc) { return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc); } @@ -1199,7 +1194,7 @@ public: Stmt *TryBody, MultiStmtArg CatchStmts, Stmt *Finally) { - return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), + return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, Finally); } @@ -1325,7 +1320,7 @@ public: StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, MultiStmtArg Handlers) { - return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); + return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); } /// \brief Build a new C++0x range-based for statement. @@ -1339,7 +1334,8 @@ public: Stmt *LoopVar, SourceLocation RParenLoc) { return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, - Cond, Inc, LoopVar, RParenLoc); + Cond, Inc, LoopVar, RParenLoc, + Sema::BFRK_Rebuild); } /// \brief Build a new C++0x range-based for statement. @@ -1478,7 +1474,7 @@ public: if (Result.isInvalid()) return ExprError(); - return move(Result); + return Result; } /// \brief Build a new array subscript expression. @@ -1503,7 +1499,7 @@ public: SourceLocation RParenLoc, Expr *ExecConfig = 0) { return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, - move(Args), RParenLoc, ExecConfig); + Args, RParenLoc, ExecConfig); } /// \brief Build a new member access expression. @@ -1638,15 +1634,15 @@ public: SourceLocation RBraceLoc, QualType ResultTy) { ExprResult Result - = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); + = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); if (Result.isInvalid() || ResultTy->isDependentType()) - return move(Result); + return Result; // Patch in the result type we were given, which may have been computed // when the initial InitListExpr was built. InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); ILE->setType(ResultTy); - return move(Result); + return Result; } /// \brief Build a new designated initializer expression. @@ -1664,8 +1660,7 @@ public: if (Result.isInvalid()) return ExprError(); - ArrayExprs.release(); - return move(Result); + return Result; } /// \brief Build a new value-initialized expression. @@ -1696,7 +1691,7 @@ public: ExprResult RebuildParenListExpr(SourceLocation LParenLoc, MultiExprArg SubExprs, SourceLocation RParenLoc) { - return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs)); + return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); } /// \brief Build a new address-of-label expression. @@ -1974,8 +1969,7 @@ public: SourceLocation LParenLoc, SourceLocation RParenLoc) { return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, - MultiExprArg(getSema(), 0, 0), - RParenLoc); + MultiExprArg(), RParenLoc); } /// \brief Build a new C++ "new" expression. @@ -1995,7 +1989,7 @@ public: Expr *Initializer) { return getSema().BuildCXXNew(StartLoc, UseGlobal, PlacementLParen, - move(PlacementArgs), + PlacementArgs, PlacementRParen, TypeIdParens, AllocatedType, @@ -2083,7 +2077,8 @@ public: NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, - const TemplateArgumentListInfo *TemplateArgs) { + const TemplateArgumentListInfo *TemplateArgs, + bool IsAddressOfOperand) { CXXScopeSpec SS; SS.Adopt(QualifierLoc); @@ -2091,7 +2086,8 @@ public: return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, TemplateArgs); - return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); + return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo, + IsAddressOfOperand); } /// \brief Build a new template-id expression. @@ -2120,13 +2116,13 @@ public: bool RequiresZeroInit, CXXConstructExpr::ConstructionKind ConstructKind, SourceRange ParenRange) { - ASTOwningVector<Expr*> ConvertedArgs(SemaRef); - if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, + SmallVector<Expr*, 8> ConvertedArgs; + if (getSema().CompleteConstructorCall(Constructor, Args, Loc, ConvertedArgs)) return ExprError(); return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, - move_arg(ConvertedArgs), + ConvertedArgs, HadMultipleCandidates, RequiresZeroInit, ConstructKind, ParenRange); @@ -2142,7 +2138,7 @@ public: SourceLocation RParenLoc) { return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, - move(Args), + Args, RParenLoc); } @@ -2156,7 +2152,7 @@ public: SourceLocation RParenLoc) { return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, - move(Args), + Args, RParenLoc); } @@ -2288,7 +2284,7 @@ public: ReceiverTypeInfo->getType(), /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs, - RBracLoc, move(Args)); + RBracLoc, Args); } /// \brief Build a new Objective-C instance message. @@ -2303,7 +2299,7 @@ public: Receiver->getType(), /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs, - RBracLoc, move(Args)); + RBracLoc, Args); } /// \brief Build a new Objective-C ivar reference expression. @@ -2326,7 +2322,7 @@ public: return ExprError(); if (Result.get()) - return move(Result); + return Result; return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), /*FIXME:*/IvarLoc, IsArrow, @@ -2355,7 +2351,7 @@ public: return ExprError(); if (Result.get()) - return move(Result); + return Result; return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), /*FIXME:*/PropertyLoc, IsArrow, @@ -2398,7 +2394,7 @@ public: return ExprError(); if (Result.get()) - return move(Result); + return Result; return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), /*FIXME:*/IsaLoc, IsArrow, @@ -2424,21 +2420,17 @@ public: // Build a reference to the __builtin_shufflevector builtin FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); - ExprResult Callee - = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false, - Builtin->getType(), - VK_LValue, BuiltinLoc)); - Callee = SemaRef.UsualUnaryConversions(Callee.take()); - if (Callee.isInvalid()) - return ExprError(); + Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, + SemaRef.Context.BuiltinFnTy, + VK_RValue, BuiltinLoc); + QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); + Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, + CK_BuiltinFnToFnPtr).take(); // Build the CallExpr - unsigned NumSubExprs = SubExprs.size(); - Expr **Subs = (Expr **)SubExprs.release(); ExprResult TheCall = SemaRef.Owned( - new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), - Subs, NumSubExprs, - Builtin->getCallResultType(), + new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs, + Builtin->getCallResultType(), Expr::getValueKindForType(Builtin->getResultType()), RParenLoc)); @@ -2478,6 +2470,7 @@ public: case TemplateArgument::Declaration: case TemplateArgument::Pack: case TemplateArgument::TemplateExpansion: + case TemplateArgument::NullPtr: llvm_unreachable("Pack expansion pattern has no parameter packs"); case TemplateArgument::Type: @@ -2515,10 +2508,7 @@ public: // Just create the expression; there is not any interesting semantic // analysis here because we can't actually build an AtomicExpr until // we are sure it is semantically sound. - unsigned NumSubExprs = SubExprs.size(); - Expr **Subs = (Expr **)SubExprs.release(); - return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs, - NumSubExprs, RetTy, Op, + return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, RParenLoc); } @@ -2963,6 +2953,7 @@ void TreeTransform<Derived>::InventTemplateArgumentLoc( case TemplateArgument::Declaration: case TemplateArgument::Integral: case TemplateArgument::Pack: + case TemplateArgument::NullPtr: Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); break; } @@ -2976,8 +2967,10 @@ bool TreeTransform<Derived>::TransformTemplateArgument( switch (Arg.getKind()) { case TemplateArgument::Null: case TemplateArgument::Integral: - Output = Input; - return false; + case TemplateArgument::Pack: + case TemplateArgument::Declaration: + case TemplateArgument::NullPtr: + llvm_unreachable("Unexpected TemplateArgument"); case TemplateArgument::Type: { TypeSourceInfo *DI = Input.getTypeSourceInfo(); @@ -2991,28 +2984,6 @@ bool TreeTransform<Derived>::TransformTemplateArgument( return false; } - case TemplateArgument::Declaration: { - // FIXME: we should never have to transform one of these. - DeclarationName Name; - if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) - Name = ND->getDeclName(); - TemporaryBase Rebase(*this, Input.getLocation(), Name); - Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); - if (!D) return true; - - Expr *SourceExpr = Input.getSourceDeclExpression(); - if (SourceExpr) { - EnterExpressionEvaluationContext Unevaluated(getSema(), - Sema::ConstantEvaluated); - ExprResult E = getDerived().TransformExpr(SourceExpr); - E = SemaRef.ActOnConstantExpression(E); - SourceExpr = (E.isInvalid() ? 0 : E.take()); - } - - Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); - return false; - } - case TemplateArgument::Template: { NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); if (QualifierLoc) { @@ -3051,35 +3022,6 @@ bool TreeTransform<Derived>::TransformTemplateArgument( Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); return false; } - - case TemplateArgument::Pack: { - SmallVector<TemplateArgument, 4> TransformedArgs; - TransformedArgs.reserve(Arg.pack_size()); - for (TemplateArgument::pack_iterator A = Arg.pack_begin(), - AEnd = Arg.pack_end(); - A != AEnd; ++A) { - - // FIXME: preserve source information here when we start - // caring about parameter packs. - - TemplateArgumentLoc InputArg; - TemplateArgumentLoc OutputArg; - getDerived().InventTemplateArgumentLoc(*A, InputArg); - if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) - return true; - - TransformedArgs.push_back(OutputArg.getArgument()); - } - - TemplateArgument *TransformedArgsPtr - = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; - std::copy(TransformedArgs.begin(), TransformedArgs.end(), - TransformedArgsPtr); - Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, - TransformedArgs.size()), - Input.getLocInfo()); - return false; - } } // Work around bogus GCC warning @@ -4260,6 +4202,8 @@ TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); + NewTL.setLParenLoc(TL.getLParenLoc()); + NewTL.setRParenLoc(TL.getRParenLoc()); NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) NewTL.setArg(i, ParamDecls[i]); @@ -4283,6 +4227,8 @@ QualType TreeTransform<Derived>::TransformFunctionNoProtoType( FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); + NewTL.setLParenLoc(TL.getLParenLoc()); + NewTL.setRParenLoc(TL.getRParenLoc()); NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); return Result; @@ -4339,7 +4285,8 @@ template<typename Derived> QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, TypeOfExprTypeLoc TL) { // typeof expressions are not potentially evaluated contexts - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, + Sema::ReuseLambdaContextDecl); ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); if (E.isInvalid()) @@ -5099,7 +5046,7 @@ TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, bool SubStmtInvalid = false; bool SubStmtChanged = false; - ASTOwningVector<Stmt*> Statements(getSema()); + SmallVector<Stmt*, 8> Statements; for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); B != BEnd; ++B) { StmtResult Result = getDerived().TransformStmt(*B); @@ -5126,7 +5073,7 @@ TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, return SemaRef.Owned(S); return getDerived().RebuildCompoundStmt(S->getLBracLoc(), - move_arg(Statements), + Statements, S->getRBracLoc(), IsStmtExpr); } @@ -5533,14 +5480,14 @@ TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { template<typename Derived> StmtResult -TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { +TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { - ASTOwningVector<Expr*> Constraints(getSema()); - ASTOwningVector<Expr*> Exprs(getSema()); + SmallVector<Expr*, 8> Constraints; + SmallVector<Expr*, 8> Exprs; SmallVector<IdentifierInfo *, 4> Names; ExprResult AsmString; - ASTOwningVector<Expr*> Clobbers(getSema()); + SmallVector<Expr*, 8> Clobbers; bool ExprsChanged = false; @@ -5585,23 +5532,15 @@ TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { // Go through the clobbers. for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) - Clobbers.push_back(S->getClobber(I)); + Clobbers.push_back(S->getClobberStringLiteral(I)); // No need to transform the asm string literal. AsmString = SemaRef.Owned(S->getAsmString()); - - return getDerived().RebuildAsmStmt(S->getAsmLoc(), - S->isSimple(), - S->isVolatile(), - S->getNumOutputs(), - S->getNumInputs(), - Names.data(), - move_arg(Constraints), - move_arg(Exprs), - AsmString.get(), - move_arg(Clobbers), - S->getRParenLoc(), - S->isMSAsm()); + return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), + S->isVolatile(), S->getNumOutputs(), + S->getNumInputs(), Names.data(), + Constraints, Exprs, AsmString.get(), + Clobbers, S->getRParenLoc()); } template<typename Derived> @@ -5624,7 +5563,7 @@ TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { // Transform the @catch statements (if present). bool AnyCatchChanged = false; - ASTOwningVector<Stmt*> CatchStmts(SemaRef); + SmallVector<Stmt*, 8> CatchStmts; for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); if (Catch.isInvalid()) @@ -5651,7 +5590,7 @@ TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { // Build a new statement. return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), - move_arg(CatchStmts), Finally.get()); + CatchStmts, Finally.get()); } template<typename Derived> @@ -5855,7 +5794,7 @@ TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { // Transform the handlers. bool HandlerChanged = false; - ASTOwningVector<Stmt*> Handlers(SemaRef); + SmallVector<Stmt*, 8> Handlers; for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); @@ -5872,7 +5811,7 @@ TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { return SemaRef.Owned(S); return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), - move_arg(Handlers)); + Handlers); } template<typename Derived> @@ -6205,10 +6144,22 @@ TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { E->getRParen()); } +/// \brief The operand of a unary address-of operator has special rules: it's +/// allowed to refer to a non-static member of a class even if there's no 'this' +/// object available. +template<typename Derived> +ExprResult +TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { + if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) + return getDerived().TransformDependentScopeDeclRefExpr(DRE, true); + else + return getDerived().TransformExpr(E); +} + template<typename Derived> ExprResult TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { - ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); + ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr()); if (SubExpr.isInvalid()) return ExprError(); @@ -6338,7 +6289,8 @@ TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( // C++0x [expr.sizeof]p1: // The operand is either an expression, which is an unevaluated operand // [...] - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, + Sema::ReuseLambdaContextDecl); ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); if (SubExpr.isInvalid()) @@ -6386,7 +6338,7 @@ TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { // Transform arguments. bool ArgChanged = false; - ASTOwningVector<Expr*> Args(SemaRef); + SmallVector<Expr*, 8> Args; if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, &ArgChanged)) return ExprError(); @@ -6394,13 +6346,13 @@ TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { if (!getDerived().AlwaysRebuild() && Callee.get() == E->getCallee() && !ArgChanged) - return SemaRef.MaybeBindToTemporary(E);; + return SemaRef.MaybeBindToTemporary(E); // FIXME: Wrong source location information for the '('. SourceLocation FakeLParenLoc = ((Expr *)Callee.get())->getSourceRange().getBegin(); return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, - move_arg(Args), + Args, E->getRParenLoc()); } @@ -6499,6 +6451,9 @@ TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { RHS.get() == E->getRHS()) return SemaRef.Owned(E); + Sema::FPContractStateRAII FPContractState(getSema()); + getSema().FPFeatures.fp_contract = E->isFPContractable(); + return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get()); } @@ -6645,7 +6600,7 @@ ExprResult TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { bool InitChanged = false; - ASTOwningVector<Expr*, 4> Inits(SemaRef); + SmallVector<Expr*, 4> Inits; if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, Inits, &InitChanged)) return ExprError(); @@ -6653,7 +6608,7 @@ TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { if (!getDerived().AlwaysRebuild() && !InitChanged) return SemaRef.Owned(E); - return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), + return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, E->getRBraceLoc(), E->getType()); } @@ -6668,7 +6623,7 @@ TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { return ExprError(); // transform the designators. - ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); + SmallVector<Expr*, 4> ArrayExprs; bool ExprChanged = false; for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), DEnd = E->designators_end(); @@ -6720,7 +6675,7 @@ TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { !ExprChanged) return SemaRef.Owned(E); - return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), + return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, E->getEqualOrColonLoc(), E->usesGNUSyntax(), Init.get()); } @@ -6768,13 +6723,13 @@ template<typename Derived> ExprResult TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { bool ArgumentChanged = false; - ASTOwningVector<Expr*, 4> Inits(SemaRef); + SmallVector<Expr*, 4> Inits; if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, &ArgumentChanged)) return ExprError(); return getDerived().RebuildParenListExpr(E->getLParenLoc(), - move_arg(Inits), + Inits, E->getRParenLoc()); } @@ -6875,13 +6830,13 @@ TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { static_cast<Expr *>(Object.get())->getLocEnd()); // Transform the call arguments. - ASTOwningVector<Expr*> Args(SemaRef); + SmallVector<Expr*, 8> Args; if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, Args)) return ExprError(); return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, - move_arg(Args), + Args, E->getLocEnd()); } @@ -6905,7 +6860,11 @@ TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { if (Callee.isInvalid()) return ExprError(); - ExprResult First = getDerived().TransformExpr(E->getArg(0)); + ExprResult First; + if (E->getOperator() == OO_Amp) + First = getDerived().TransformAddressOfOperand(E->getArg(0)); + else + First = getDerived().TransformExpr(E->getArg(0)); if (First.isInvalid()) return ExprError(); @@ -6922,6 +6881,9 @@ TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) return SemaRef.MaybeBindToTemporary(E); + Sema::FPContractStateRAII FPContractState(getSema()); + getSema().FPFeatures.fp_contract = E->isFPContractable(); + return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), E->getOperatorLoc(), Callee.get(), @@ -6950,7 +6912,7 @@ TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { // Transform arguments. bool ArgChanged = false; - ASTOwningVector<Expr*> Args(SemaRef); + SmallVector<Expr*, 8> Args; if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, &ArgChanged)) return ExprError(); @@ -6964,7 +6926,7 @@ TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { SourceLocation FakeLParenLoc = ((Expr *)Callee.get())->getSourceRange().getBegin(); return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, - move_arg(Args), + Args, E->getRParenLoc(), EC.get()); } @@ -6989,9 +6951,6 @@ TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { SourceLocation FakeLAngleLoc = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); - SourceLocation FakeRParenLoc - = SemaRef.PP.getLocForEndOfToken( - E->getSubExpr()->getSourceRange().getEnd()); return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), E->getStmtClass(), FakeLAngleLoc, @@ -6999,7 +6958,7 @@ TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { FakeRAngleLoc, FakeRAngleLoc, SubExpr.get(), - FakeRParenLoc); + E->getRParenLoc()); } template<typename Derived> @@ -7074,7 +7033,8 @@ TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { // after we perform semantic analysis. We speculatively assume it is // unevaluated; it will get fixed later if the subexpression is in fact // potentially evaluated. - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, + Sema::ReuseLambdaContextDecl); ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); if (SubExpr.isInvalid()) @@ -7222,7 +7182,7 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { // Transform the placement arguments (if any). bool ArgumentChanged = false; - ASTOwningVector<Expr*> PlacementArgs(SemaRef); + SmallVector<Expr*, 8> PlacementArgs; if (getDerived().TransformExprs(E->getPlacementArgs(), E->getNumPlacementArgs(), true, PlacementArgs, &ArgumentChanged)) @@ -7313,7 +7273,7 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { return getDerived().RebuildCXXNewExpr(E->getLocStart(), E->isGlobalNew(), /*FIXME:*/E->getLocStart(), - move_arg(PlacementArgs), + PlacementArgs, /*FIXME:*/E->getLocStart(), E->getTypeIdParens(), AllocType, @@ -7512,7 +7472,8 @@ TreeTransform<Derived>::TransformUnresolvedLookupExpr( // If we have template arguments, rebuild them, then rebuild the // templateid expression. TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); - if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), + if (Old->hasExplicitTemplateArgs() && + getDerived().TransformTemplateArguments(Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs)) return ExprError(); @@ -7732,6 +7693,14 @@ template<typename Derived> ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( DependentScopeDeclRefExpr *E) { + return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false); +} + +template<typename Derived> +ExprResult +TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( + DependentScopeDeclRefExpr *E, + bool IsAddressOfOperand) { NestedNameSpecifierLoc QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); if (!QualifierLoc) @@ -7758,7 +7727,8 @@ TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, TemplateKWLoc, NameInfo, - /*TemplateArgs*/ 0); + /*TemplateArgs*/ 0, + IsAddressOfOperand); } TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); @@ -7770,7 +7740,8 @@ TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, TemplateKWLoc, NameInfo, - &TransArgs); + &TransArgs, + IsAddressOfOperand); } template<typename Derived> @@ -7796,7 +7767,7 @@ TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { return ExprError(); bool ArgumentChanged = false; - ASTOwningVector<Expr*> Args(SemaRef); + SmallVector<Expr*, 8> Args; if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, &ArgumentChanged)) return ExprError(); @@ -7813,7 +7784,7 @@ TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), Constructor, E->isElidable(), - move_arg(Args), + Args, E->hadMultipleCandidates(), E->requiresZeroInitialization(), E->getConstructionKind(), @@ -7857,7 +7828,7 @@ TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( return ExprError(); bool ArgumentChanged = false; - ASTOwningVector<Expr*> Args(SemaRef); + SmallVector<Expr*, 8> Args; Args.reserve(E->getNumArgs()); if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, &ArgumentChanged)) @@ -7874,19 +7845,13 @@ TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( return getDerived().RebuildCXXTemporaryObjectExpr(T, /*FIXME:*/T->getTypeLoc().getEndLoc(), - move_arg(Args), + Args, E->getLocEnd()); } template<typename Derived> ExprResult TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { - // Create the local class that will describe the lambda. - CXXRecordDecl *Class - = getSema().createLambdaClosureType(E->getIntroducerRange(), - /*KnownDependent=*/false); - getDerived().transformedLocalDecl(E->getLambdaClass(), Class); - // Transform the type of the lambda parameters and start the definition of // the lambda itself. TypeSourceInfo *MethodTy @@ -7894,6 +7859,13 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { if (!MethodTy) return ExprError(); + // Create the local class that will describe the lambda. + CXXRecordDecl *Class + = getSema().createLambdaClosureType(E->getIntroducerRange(), + MethodTy, + /*KnownDependent=*/false); + getDerived().transformedLocalDecl(E->getLambdaClass(), Class); + // Transform lambda parameters. llvm::SmallVector<QualType, 4> ParamTypes; llvm::SmallVector<ParmVarDecl *, 4> Params; @@ -8038,7 +8010,7 @@ TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( return ExprError(); bool ArgumentChanged = false; - ASTOwningVector<Expr*> Args(SemaRef); + SmallVector<Expr*, 8> Args; Args.reserve(E->arg_size()); if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, &ArgumentChanged)) @@ -8052,7 +8024,7 @@ TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( // FIXME: we're faking the locations of the commas return getDerived().RebuildCXXUnresolvedConstructExpr(T, E->getLParenLoc(), - move_arg(Args), + Args, E->getRParenLoc()); } @@ -8346,6 +8318,13 @@ TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( template<typename Derived> ExprResult +TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { + // Default behavior is to do nothing with this transformation. + return SemaRef.Owned(E); +} + +template<typename Derived> +ExprResult TreeTransform<Derived>::TransformMaterializeTemporaryExpr( MaterializeTemporaryExpr *E) { return getDerived().TransformExpr(E->GetTemporaryExpr()); @@ -8576,7 +8555,7 @@ ExprResult TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { // Transform arguments. bool ArgChanged = false; - ASTOwningVector<Expr*> Args(SemaRef); + SmallVector<Expr*, 8> Args; Args.reserve(E->getNumArgs()); if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, &ArgChanged)) @@ -8602,7 +8581,7 @@ TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { SelLocs, E->getMethodDecl(), E->getLeftLoc(), - move_arg(Args), + Args, E->getRightLoc()); } @@ -8627,7 +8606,7 @@ TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { SelLocs, E->getMethodDecl(), E->getLeftLoc(), - move_arg(Args), + Args, E->getRightLoc()); } @@ -8740,7 +8719,7 @@ template<typename Derived> ExprResult TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { bool ArgumentChanged = false; - ASTOwningVector<Expr*> SubExprs(SemaRef); + SmallVector<Expr*, 8> SubExprs; SubExprs.reserve(E->getNumSubExprs()); if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, SubExprs, &ArgumentChanged)) @@ -8751,7 +8730,7 @@ TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { return SemaRef.Owned(E); return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), - move_arg(SubExprs), + SubExprs, E->getRParenLoc()); } @@ -8854,7 +8833,7 @@ ExprResult TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { QualType RetTy = getDerived().TransformType(E->getType()); bool ArgumentChanged = false; - ASTOwningVector<Expr*> SubExprs(SemaRef); + SmallVector<Expr*, 8> SubExprs; SubExprs.reserve(E->getNumSubExprs()); if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, SubExprs, &ArgumentChanged)) @@ -8864,7 +8843,7 @@ TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { !ArgumentChanged) return SemaRef.Owned(E); - return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs), + return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, RetTy, E->getOp(), E->getRParenLoc()); } @@ -9185,7 +9164,7 @@ TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, if (Result.isInvalid()) return ExprError(); - return move(Result); + return Result; } } @@ -9200,7 +9179,12 @@ TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, // IsAcceptableNonMemberOperatorCandidate for each of these? Functions.append(ULE->decls_begin(), ULE->decls_end()); } else { - Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); + // If we've resolved this to a particular non-member function, just call + // that function. If we resolved it to a member function, + // CreateOverloaded* will find that function for us. + NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); + if (!isa<CXXMethodDecl>(ND)) + Functions.addDecl(ND); } // Add any functions found via argument-dependent lookup. @@ -9240,7 +9224,7 @@ TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, if (Result.isInvalid()) return ExprError(); - return move(Result); + return Result; } template<typename Derived> |