[cfe-commits] r59428 - /cfe/trunk/lib/AST/ExprConstant.cpp

Anders Carlsson andersca at mac.com
Sun Nov 16 13:51:21 PST 2008


Author: andersca
Date: Sun Nov 16 15:51:21 2008
New Revision: 59428

URL: http://llvm.org/viewvc/llvm-project?rev=59428&view=rev
Log:
More complex float evaluator support.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

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

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Nov 16 15:51:21 2008
@@ -1084,6 +1084,24 @@
     return APValue(APFloat(0.0), Result);
   }
 
+  APValue VisitCastExpr(CastExpr *E) {
+    Expr* SubExpr = E->getSubExpr();
+
+    if (SubExpr->getType()->isRealFloatingType()) {
+      APFloat Result(0.0);
+                     
+      if (!EvaluateFloat(SubExpr, Result, Info))
+        return APValue();
+      
+      return APValue(Result, APFloat(0.0));
+    }
+
+    // FIXME: Handle more casts.
+    return APValue();
+  }
+  
+  APValue VisitBinaryOperator(const BinaryOperator *E);
+
 };
 } // end anonymous namespace
 
@@ -1093,6 +1111,33 @@
   return Result.isComplexFloat();
 }
 
+APValue ComplexFloatExprEvaluator::VisitBinaryOperator(const BinaryOperator *E)
+{
+  APValue Result, RHS;
+  
+  if (!EvaluateComplexFloat(E->getLHS(), Result, Info))
+    return APValue();
+  
+  if (!EvaluateComplexFloat(E->getRHS(), RHS, Info))
+    return APValue();
+  
+  switch (E->getOpcode()) {
+  default: return APValue();
+  case BinaryOperator::Add:
+    Result.getComplexFloatReal().add(RHS.getComplexFloatReal(),
+                                     APFloat::rmNearestTiesToEven);
+    Result.getComplexFloatImag().add(RHS.getComplexFloatImag(),
+                                     APFloat::rmNearestTiesToEven);
+  case BinaryOperator::Sub:
+    Result.getComplexFloatReal().subtract(RHS.getComplexFloatReal(),
+                                          APFloat::rmNearestTiesToEven);
+    Result.getComplexFloatImag().subtract(RHS.getComplexFloatImag(),
+                                          APFloat::rmNearestTiesToEven);
+  }
+
+  return Result;
+}
+
 //===----------------------------------------------------------------------===//
 // Top level Expr::Evaluate method.
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list