More complex float evaluator support.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59428 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 625a414..7276786 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -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.
//===----------------------------------------------------------------------===//