summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-26 23:12:30 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-26 23:12:30 +0000
commitfbb08bc2e2fd4dd8598a404f41043a8c31780e49 (patch)
treeabdb93d89236c2b813aa020f23101f035e56eb62
parent871422eca917f4528394bf7652388fa9c023a0b8 (diff)
downloadbcm5719-llvm-fbb08bc2e2fd4dd8598a404f41043a8c31780e49.tar.gz
bcm5719-llvm-fbb08bc2e2fd4dd8598a404f41043a8c31780e49.zip
Added optional pass-by-reference argument "isExact" to
NumericLiteralParser::GetFloatValue(). Upon method return, this flag has the value true if the returned APFloat can exactly represent the number in the parsed text, and false otherwise. Modified the implementation of GetFloatValue() to parse literals using APFloat's convertFromString method (which allows us to set the value of isExact). llvm-svn: 44339
-rw-r--r--clang/Lex/LiteralSupport.cpp22
-rw-r--r--clang/include/clang/Lex/LiteralSupport.h7
2 files changed, 21 insertions, 8 deletions
diff --git a/clang/Lex/LiteralSupport.cpp b/clang/Lex/LiteralSupport.cpp
index 21ead21bfec..ebc66271dbd 100644
--- a/clang/Lex/LiteralSupport.cpp
+++ b/clang/Lex/LiteralSupport.cpp
@@ -410,17 +410,27 @@ bool NumericLiteralParser::GetIntegerValue(llvm::APInt &Val) {
}
llvm::APFloat NumericLiteralParser::
-GetFloatValue(const llvm::fltSemantics &Format) {
+GetFloatValue(const llvm::fltSemantics &Format, bool* isExact) {
+ using llvm::APFloat;
+
char floatChars[256];
strncpy(floatChars, ThisTokBegin, ThisTokEnd-ThisTokBegin);
floatChars[ThisTokEnd-ThisTokBegin] = '\0';
-#if 0
- // This doesn't work yet.
- return llvm::APFloat(Format, floatChars);
+
+#if 1
+ APFloat V (Format, APFloat::fcZero, false);
+
+ APFloat::opStatus status;
+ status = V.convertFromString(floatChars,APFloat::rmTowardZero);
+
+ if (isExact)
+ *isExact = status == APFloat::opOK;
+
+ return V;
#else
// FIXME: this is horrible!
- llvm::APFloat V(strtod(floatChars, 0));
- V.convert(Format, llvm::APFloat::rmTowardZero);
+ APFloat V(strtod(floatChars, 0));
+ V.convert(Format, APFloat::rmTowardZero);
return V;
#endif
}
diff --git a/clang/include/clang/Lex/LiteralSupport.h b/clang/include/clang/Lex/LiteralSupport.h
index e8650fc8fa7..25556600769 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -77,8 +77,11 @@ public:
/// GetFloatValue - Convert this numeric literal to a floating value, using
/// the specified APFloat fltSemantics (specifying float, double, etc).
- ///
- llvm::APFloat GetFloatValue(const llvm::fltSemantics &Format);
+ /// The optional bool isExact (passed-by-reference) has its value
+ /// set to true if the returned APFloat can represent the number in the
+ /// literal exactly, and false otherwise.
+ llvm::APFloat GetFloatValue(const llvm::fltSemantics &Format,
+ bool* isExact = NULL);
private:
void Diag(SourceLocation Loc, unsigned DiagID,
OpenPOWER on IntegriCloud