summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-01-05 23:42:56 +0000
committerJohn McCall <rjmccall@apple.com>2010-01-05 23:42:56 +0000
commit1be1c636341381eb5d919550b54784c5a73f517c (patch)
tree4b5ae3dc9cd10e877e7565f9d1a758c7fc4f88ba /clang/lib/AST/ExprConstant.cpp
parente50486bbca8ce29ecbc450ff26ee467e5fadc589 (diff)
downloadbcm5719-llvm-1be1c636341381eb5d919550b54784c5a73f517c.tar.gz
bcm5719-llvm-1be1c636341381eb5d919550b54784c5a73f517c.zip
Add Expr::EvaluateAsBooleanCondition(), which does unprincipled folding to
try to evaluate an expression as a constant boolean condition. This has the same intended semantics as used in folding conditional operators. llvm-svn: 92805
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d49a8216f3a..cc86b243424 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -73,7 +73,8 @@ static bool EvalPointerValueAsBool(APValue& Value, bool& Result) {
return true;
}
-static bool HandleConversionToBool(Expr* E, bool& Result, EvalInfo &Info) {
+static bool HandleConversionToBool(const Expr* E, bool& Result,
+ EvalInfo &Info) {
if (E->getType()->isIntegralType()) {
APSInt IntResult;
if (!EvaluateInteger(E, IntResult, Info))
@@ -1978,6 +1979,13 @@ bool Expr::EvaluateAsAny(EvalResult &Result, ASTContext &Ctx) const {
return true;
}
+bool Expr::EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const {
+ EvalResult Scratch;
+ EvalInfo Info(Ctx, Scratch);
+
+ return HandleConversionToBool(this, Result, Info);
+}
+
bool Expr::EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const {
EvalInfo Info(Ctx, Result);
OpenPOWER on IntegriCloud