[cfe-commits] r60298 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/ExprConstant.cpp

Anders Carlsson andersca at mac.com
Sun Nov 30 08:58:54 PST 2008


Author: andersca
Date: Sun Nov 30 10:58:53 2008
New Revision: 60298

URL: http://llvm.org/viewvc/llvm-project?rev=60298&view=rev
Log:
Add a new variant of Evaluate and reimplement the old Evaluate in terms of the new.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=60298&r1=60297&r2=60298&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Nov 30 10:58:53 2008
@@ -166,6 +166,8 @@
   /// 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;
 

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=60298&r1=60297&r2=60298&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Nov 30 10:58:53 2008
@@ -1160,33 +1160,43 @@
 /// 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;
 }
 





More information about the cfe-commits mailing list