[cfe-commits] r52080 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/AST/StmtDumper.cpp lib/AST/StmtPrinter.cpp
Chris Lattner
sabre at nondot.org
Sat Jun 7 15:13:43 PDT 2008
Author: lattner
Date: Sat Jun 7 17:13:43 2008
New Revision: 52080
URL: http://llvm.org/viewvc/llvm-project?rev=52080&view=rev
Log:
Fix ast dumping to work with long double literals, e.g. we dump:
long double X() { return 1.0L; }
as:
long double X()
(CompoundStmt 0xb06a00 <t.c:2:17, col:32>
(ReturnStmt 0xb068d0 <col:19, col:26>
(FloatingLiteral 0xb02cf0 <col:26> 'long double' 1.000000)))
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/StmtDumper.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=52080&r1=52079&r2=52080&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jun 7 17:13:43 2008
@@ -271,17 +271,11 @@
bool isExact() const { return IsExact; }
- /// getValueAsDouble - This returns the value as an inaccurate double. Note
- /// that this may cause loss of precision, but is useful for debugging dumps
- /// etc.
- double getValueAsDouble() const {
- // FIXME: We need something for long double here.
- if (cast<BuiltinType>(getType())->getKind() == BuiltinType::Float)
- return Value.convertToFloat();
- else
- return Value.convertToDouble();
- }
-
+ /// getValueAsApproximateDouble - This returns the value as an inaccurate
+ /// double. Note that this may cause loss of precision, but is useful for
+ /// debugging dumps, etc.
+ double getValueAsApproximateDouble() const;
+
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
static bool classof(const Stmt *T) {
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=52080&r1=52079&r2=52080&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sat Jun 7 17:13:43 2008
@@ -22,6 +22,16 @@
// Primary Expressions.
//===----------------------------------------------------------------------===//
+/// getValueAsApproximateDouble - This returns the value as an inaccurate
+/// double. Note that this may cause loss of precision, but is useful for
+/// debugging dumps, etc.
+double FloatingLiteral::getValueAsApproximateDouble() const {
+ llvm::APFloat V = getValue();
+ V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven);
+ return V.convertToDouble();
+}
+
+
StringLiteral::StringLiteral(const char *strData, unsigned byteLength,
bool Wide, QualType t, SourceLocation firstLoc,
SourceLocation lastLoc) :
Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=52080&r1=52079&r2=52080&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Sat Jun 7 17:13:43 2008
@@ -335,7 +335,7 @@
}
void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
DumpExpr(Node);
- fprintf(F, " %f", Node->getValueAsDouble());
+ fprintf(F, " %f", Node->getValueAsApproximateDouble());
}
void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=52080&r1=52079&r2=52080&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Sat Jun 7 17:13:43 2008
@@ -577,7 +577,7 @@
}
void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
// FIXME: print value more precisely.
- OS << Node->getValueAsDouble();
+ OS << Node->getValueAsApproximateDouble();
}
void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
More information about the cfe-commits
mailing list