]> granicus.if.org Git - clang/commitdiff
Fix ast dumping to work with long double literals, e.g. we dump:
authorChris Lattner <sabre@nondot.org>
Sat, 7 Jun 2008 22:13:43 +0000 (22:13 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 7 Jun 2008 22:13:43 +0000 (22:13 +0000)
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)))

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52080 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/Expr.cpp
lib/AST/StmtDumper.cpp
lib/AST/StmtPrinter.cpp

index 3813455864629b3650aefeaee6824ef1f4ca19a9..9a76823ff263f83c8b0af4fb0503b4f45ed5604e 100644 (file)
@@ -271,17 +271,11 @@ public:
   
   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) { 
index a89fbd621a5632b8ca733156f5f59775c1db8c3a..78c305051ee4c8739a7ad3be98262c035fd11166 100644 (file)
@@ -22,6 +22,16 @@ using namespace clang;
 // 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) : 
index 082d2a2259571c1f97b5349ea88caa0aad158345..ae6ca40460afc66a0726a0c85c5a42bd3b397aae 100644 (file)
@@ -335,7 +335,7 @@ void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
 }
 void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
   DumpExpr(Node);
-  fprintf(F, " %f", Node->getValueAsDouble());
+  fprintf(F, " %f", Node->getValueAsApproximateDouble());
 }
 
 void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
index a740facf76fc57f64f75325c948cd8b2d922d938..5e347435b6339122256547245ea7f416cf2912f0 100644 (file)
@@ -577,7 +577,7 @@ void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
 }
 void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
   // FIXME: print value more precisely.
-  OS << Node->getValueAsDouble();
+  OS << Node->getValueAsApproximateDouble();
 }
 
 void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {