From 43168129d05ed1942d6948f77b89f922cb7ab8d4 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 10 Apr 2009 04:54:13 +0000 Subject: [PATCH] Add Expr::EvaluateAsLValue which will (believe it or not) try to evaluate an Expr as an LValue. llvm-svn: 68763 --- clang/include/clang/AST/Expr.h | 3 +++ clang/lib/AST/ExprConstant.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 92b39632b876..6fd2970153e2 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -229,6 +229,9 @@ public: /// must be called on an expression that constant folds to an integer. llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; + /// EvaluateAsLValue - Evaluate an expression to see if it's a valid LValue. + bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; + /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an /// integer constant expression with the value zero, or if this is one that is /// cast to void*. diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 643e066c7b46..327fff0c0b16 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -1651,6 +1651,12 @@ bool Expr::Evaluate(EvalResult &Result, ASTContext &Ctx) const { return true; } +bool Expr::EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const { + EvalInfo Info(Ctx, Result); + + return EvaluateLValue(this, Result.Val, Info) && !Result.HasSideEffects; +} + /// isEvaluatable - Call Evaluate to see if this expression can be constant /// folded, but discard the result. bool Expr::isEvaluatable(ASTContext &Ctx) const {