diff options
author | Anders Carlsson <andersca@mac.com> | 2008-11-30 16:58:53 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-11-30 16:58:53 +0000 |
commit | 5b45d4ef1ea3f04ec863daf8aa29be6c6e021750 (patch) | |
tree | 9e4e2ee2d0c09878e9f7cf32b308f219efbc0af8 /lib/AST/ExprConstant.cpp | |
parent | fcb4d09531abbf2a5cf398c2f946fb3bc2875f64 (diff) |
Add a new variant of Evaluate and reimplement the old Evaluate in terms of the new.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60298 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 931eae2b8b..d26ba8b579 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -1160,33 +1160,43 @@ APValue ComplexFloatExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) /// any crazy technique (that has nothing to do with language standards) that /// we want to. If this function returns true, it returns the folded constant /// in Result. -bool Expr::Evaluate(APValue &Result, ASTContext &Ctx, bool *isEvaluated) const { - Expr::EvalResult EvalResult; - EvalInfo Info(Ctx, EvalResult); +bool Expr::Evaluate(EvalResult &Result, ASTContext &Ctx) const { + EvalInfo Info(Ctx, Result); if (getType()->isIntegerType()) { llvm::APSInt sInt(32); if (!EvaluateInteger(this, sInt, Info)) return false; - Result = APValue(sInt); + Result.Val = APValue(sInt); } else if (getType()->isPointerType()) { - if (!EvaluatePointer(this, Result, Info)) + if (!EvaluatePointer(this, Result.Val, Info)) return false; } else if (getType()->isRealFloatingType()) { llvm::APFloat f(0.0); if (!EvaluateFloat(this, f, Info)) return false; - Result = APValue(f); + Result.Val = APValue(f); } else if (getType()->isComplexType()) { - if (!EvaluateComplexFloat(this, Result, Info)) + if (!EvaluateComplexFloat(this, Result.Val, Info)) return false; } else return false; + return true; +} + +bool Expr::Evaluate(APValue &Result, ASTContext &Ctx, bool *isEvaluated) const { + EvalResult EvalResult; + + if (!Evaluate(EvalResult, Ctx)) + return false; + + Result = EvalResult.Val; if (isEvaluated) *isEvaluated = !EvalResult.HasSideEffects; + return true; } |