[cfe-commits] r39719 - in /cfe/cfe/trunk: Lex/LiteralSupport.cpp Sema/SemaExpr.cpp include/clang/Lex/LiteralSupport.h

Steve Naroff snaroff at apple.com
Wed Jul 11 09:47:30 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:47:30 2007
New Revision: 39719

URL: http://llvm.org/viewvc/llvm-project?rev=39719&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Added primitive support for 32-bit floating point literals.

Modified:
    cfe/cfe/trunk/Lex/LiteralSupport.cpp
    cfe/cfe/trunk/Sema/SemaExpr.cpp
    cfe/cfe/trunk/include/clang/Lex/LiteralSupport.h

Modified: cfe/cfe/trunk/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/LiteralSupport.cpp?rev=39719&r1=39718&r2=39719&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/LiteralSupport.cpp (original)
+++ cfe/cfe/trunk/Lex/LiteralSupport.cpp Wed Jul 11 11:47:30 2007
@@ -410,6 +410,13 @@
   return OverflowOccurred;
 }
 
+// GetFloatValue - Poor man's floatvalue (FIXME).
+float NumericLiteralParser::GetFloatValue() {
+  char floatChars[256];
+  strncpy(floatChars, ThisTokBegin, ThisTokEnd-ThisTokBegin);
+  floatChars[ThisTokEnd-ThisTokBegin] = '\0';
+  return strtof(floatChars, 0);
+}
 
 void NumericLiteralParser::Diag(SourceLocation Loc, unsigned DiagID, 
           const std::string &M) {

Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39719&r1=39718&r2=39719&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:47:30 2007
@@ -208,8 +208,9 @@
 
     return new IntegerLiteral(ResultVal, t, Tok.getLocation());
   } else if (Literal.isFloatingLiteral()) {
-    // FIXME: fill in the value and compute the real type...
-    return new FloatingLiteral(7.7, Context.FloatTy, Tok.getLocation());
+    // FIXME: handle float values > 32 (including compute the real type...).
+    return new FloatingLiteral(Literal.GetFloatValue(), Context.FloatTy, 
+                               Tok.getLocation());
   }
   return ExprResult(true);
 }

Modified: cfe/cfe/trunk/include/clang/Lex/LiteralSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=39719&r1=39718&r2=39719&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/LiteralSupport.h Wed Jul 11 11:47:30 2007
@@ -71,6 +71,10 @@
   /// value read is larger than the APInt's bits will hold), set Val to the low
   /// bits of the result and return true.  Otherwise, return false.
   bool GetIntegerValue(llvm::APInt &Val);
+  
+  /// GetFloatValue - Convert this numeric literal to a float.
+  /// FIXME: the return value is fixed size - make more general.
+  float GetFloatValue();
 
 private:  
   void Diag(SourceLocation Loc, unsigned DiagID, 





More information about the cfe-commits mailing list