[cfe-commits] r59425 - /cfe/trunk/lib/AST/ExprConstant.cpp
Anders Carlsson
andersca at mac.com
Sun Nov 16 12:27:53 PST 2008
Author: andersca
Date: Sun Nov 16 14:27:53 2008
New Revision: 59425
URL: http://llvm.org/viewvc/llvm-project?rev=59425&view=rev
Log:
Add very limited support for evaluating complex floats.
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=59425&r1=59424&r2=59425&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Nov 16 14:27:53 2008
@@ -67,6 +67,8 @@
static bool EvaluatePointer(const Expr *E, APValue &Result, EvalInfo &Info);
static bool EvaluateInteger(const Expr *E, APSInt &Result, EvalInfo &Info);
static bool EvaluateFloat(const Expr *E, APFloat &Result, EvalInfo &Info);
+static bool EvaluateComplexFloat(const Expr *E, APValue &Result,
+ EvalInfo &Info);
//===----------------------------------------------------------------------===//
// Misc utilities
@@ -1052,6 +1054,46 @@
}
//===----------------------------------------------------------------------===//
+// Complex Float Evaluation
+//===----------------------------------------------------------------------===//
+
+namespace {
+class VISIBILITY_HIDDEN ComplexFloatExprEvaluator
+ : public StmtVisitor<ComplexFloatExprEvaluator, APValue> {
+ EvalInfo &Info;
+
+public:
+ ComplexFloatExprEvaluator(EvalInfo &info) : Info(info) {}
+
+ //===--------------------------------------------------------------------===//
+ // Visitor Methods
+ //===--------------------------------------------------------------------===//
+
+ APValue VisitStmt(Stmt *S) {
+ assert(0 && "This should be called on complex floats");
+ return APValue();
+ }
+
+ APValue VisitParenExpr(ParenExpr *E) { return Visit(E->getSubExpr()); }
+
+ APValue VisitImaginaryLiteral(ImaginaryLiteral *E) {
+ APFloat Result(0.0);
+ if (!EvaluateFloat(E->getSubExpr(), Result, Info))
+ return APValue();
+
+ return APValue(APFloat(0.0), Result);
+ }
+
+};
+} // end anonymous namespace
+
+static bool EvaluateComplexFloat(const Expr *E, APValue &Result, EvalInfo &Info)
+{
+ Result = ComplexFloatExprEvaluator(Info).Visit(const_cast<Expr*>(E));
+ return Result.isComplexFloat();
+}
+
+//===----------------------------------------------------------------------===//
// Top level TryEvaluate.
//===----------------------------------------------------------------------===//
@@ -1077,7 +1119,10 @@
Result = APValue(f);
return true;
}
- }
+ } else if (getType()->isComplexType()) {
+ if (EvaluateComplexFloat(this, Result, Info))
+ return true;
+ }
return false;
}
More information about the cfe-commits
mailing list