summaryrefslogtreecommitdiffstats
path: root/clang
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
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')
-rw-r--r--clang/include/clang/AST/Expr.h5
-rw-r--r--clang/lib/AST/ExprConstant.cpp10
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 0cb22df92ff..98ecda9b835 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -241,6 +241,11 @@ public:
/// stack based objects.
bool EvaluateAsAny(EvalResult &Result, ASTContext &Ctx) const;
+ /// EvaluateAsBooleanCondition - Return true if this is a constant
+ /// which we we can fold and convert to a boolean condition using
+ /// any crazy technique that we want to.
+ bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const;
+
/// isEvaluatable - Call Evaluate to see if this expression can be constant
/// folded, but discard the result.
bool isEvaluatable(ASTContext &Ctx) const;
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