]> granicus.if.org Git - clang/commitdiff
Add a new variant of Evaluate and reimplement the old Evaluate in terms of the new.
authorAnders Carlsson <andersca@mac.com>
Sun, 30 Nov 2008 16:58:53 +0000 (16:58 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 30 Nov 2008 16:58:53 +0000 (16:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60298 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/ExprConstant.cpp

index 05c0cebff075c2ec21bdcfbc3e95813dbded1c5f..66238376951f08f318b0b69203099802c2ff7b3f 100644 (file)
@@ -166,6 +166,8 @@ public:
   /// 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 Evaluate(EvalResult &Result, ASTContext &Ctx) const;
+
   // FIXME: We should come up with a better API for the isEvaluated case.
   bool Evaluate(APValue& Result, ASTContext &Ctx, bool *isEvaluated = 0) const;
 
index 931eae2b8b25535e013f48ea25a317f1c578e365..d26ba8b579a9aa2f94e7842da131e949a0a9e428 100644 (file)
@@ -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;
 }