[cfe-commits] r71983 - in /cfe/trunk/lib/Sema: Sema.h SemaExprCXX.cpp
Douglas Gregor
dgregor at apple.com
Mon May 18 11:41:23 PDT 2009
On May 17, 2009, at 11:41 AM, Anders Carlsson wrote:
> Author: andersca
> Date: Sun May 17 13:41:29 2009
> New Revision: 71983
>
> URL: http://llvm.org/viewvc/llvm-project?rev=71983&view=rev
> Log:
> Implement Sema::ActOnFinishFullExpr and create a
> CXXExprWithTemporaries node if necessary.
>
> Modified:
> cfe/trunk/lib/Sema/Sema.h
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>
> Modified: cfe/trunk/lib/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=71983&r1=71982&r2=71983&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/Sema.h (original)
> +++ cfe/trunk/lib/Sema/Sema.h Sun May 17 13:41:29 2009
> @@ -162,7 +162,11 @@
> /// in the top level function. Clients should always use
> getSwitchStack() to
> /// handle the case when they are in a block.
> llvm::SmallVector<SwitchStmt*, 8> FunctionSwitchStack;
> -
> +
> + /// ExprTemporaries - This is the stack of temporaries that are
> created by
> + /// the current full expression.
> + llvm::SmallVector<CXXTempVarDecl*, 8> ExprTemporaries;
> +
> /// CurFunctionNeedsScopeChecking - This is set to true when a
> function or
> /// ObjC method body contains a VLA or an ObjC try block, which
> introduce
> /// scopes that need to be checked for goto conditions. If a
> function does
> @@ -1583,6 +1587,8 @@
> TypeTy *Ty,
> SourceLocation RParen);
>
> + virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr);
> +
> bool RequireCompleteDeclContext(const CXXScopeSpec &SS);
>
> DeclContext *computeDeclContext(const CXXScopeSpec &SS);
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=71983&r1=71982&r2=71983&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun May 17 13:41:29 2009
> @@ -164,8 +164,11 @@
> CallExpr::hasAnyTypeDependentArguments(Exprs, NumExprs)) {
> exprs.release();
>
> - // FIXME: Is this correct?
> + // FIXME: Is this correct (I don't think so). Instead, we
> should have an
> + // CXXUnresolvedTemporaryObjectExpr node for this.
> CXXTempVarDecl *Temp = CXXTempVarDecl::Create(Context,
> CurContext, Ty);
> + ExprTemporaries.push_back(Temp);
> +
> return Owned(new (Context) CXXTemporaryObjectExpr(Context, Temp,
> 0, Ty,
> TyBeginLoc,
> Exprs, NumExprs,
> @@ -190,6 +193,8 @@
> if (const RecordType *RT = Ty->getAsRecordType()) {
> CXXRecordDecl *Record = cast<CXXRecordDecl>(RT->getDecl());
>
> + // FIXME: We should always create a CXXTemporaryObjectExpr here
> unless
> + // both the ctor and dtor are trivial.
> if (NumExprs > 1 || Record->hasUserDeclaredConstructor()) {
> CXXConstructorDecl *Constructor
> = PerformInitializationByConstructor(Ty, Exprs, NumExprs,
> @@ -203,7 +208,8 @@
> return ExprError();
>
> CXXTempVarDecl *Temp = CXXTempVarDecl::Create(Context,
> CurContext, Ty);
> -
> + ExprTemporaries.push_back(Temp);
> +
> exprs.release();
> return Owned(new (Context) CXXTemporaryObjectExpr(Context, Temp,
> Constructor,
> Ty,
> @@ -1494,3 +1500,18 @@
> }
> return QualType();
> }
> +
> +Sema::OwningExprResult Sema::ActOnFinishFullExpr(ExprArg Arg) {
> + Expr *FullExpr = Arg.takeAs<Expr>();
> + assert(FullExpr && "Null full expr!");
> +
> + if (!ExprTemporaries.empty()) {
> + // Create a cleanup expr.
> + FullExpr =
> + new (Context) CXXExprWithTemporaries(FullExpr,
> &ExprTemporaries[0],
> + ExprTemporaries.size());
> + ExprTemporaries.clear();
> + }
> +
> + return Owned(FullExpr);
> +}
This is coming along very nicely! Should we add some asserts() in
various places to be sure that we've captured all of the temporaries?
For example, at the end of a compound expression, we could
assert(ExprTemporaries.empty() && " Temporaries node captured in
compound expression");
- Doug
More information about the cfe-commits
mailing list