]> granicus.if.org Git - clang/commitdiff
1.0 is double, 1.0F is a float.
authorChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 03:29:23 +0000 (03:29 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 03:29:23 +0000 (03:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41412 91177308-0d34-0410-b5e6-96231b3b80d8

Lex/LiteralSupport.cpp
Lex/PPExpressions.cpp
Sema/SemaExpr.cpp
include/clang/Lex/LiteralSupport.h

index 82765522d73b9fe839237eb3fd8ce2c3e7f7e39c..04282563ea94e6a4bba425a12c7aa9476f985673 100644 (file)
@@ -202,10 +202,10 @@ NumericLiteralParser(const char *begin, const char *end,
   s = DigitsBegin = begin;
   saw_exponent = false;
   saw_period = false;
-  saw_float_suffix = false;
   isLong = false;
   isUnsigned = false;
   isLongLong = false;
+  isFloat = false;
   isImaginary = false;
   hadError = false;
   
@@ -326,8 +326,8 @@ NumericLiteralParser(const char *begin, const char *end,
     case 'f':      // FP Suffix for "float"
     case 'F':
       if (!isFPConstant) break;  // Error for integer constant.
-      if (saw_float_suffix || isLong) break; // FF, LF invalid.
-      saw_float_suffix = true;
+      if (isFloat || isLong) break; // FF, LF invalid.
+      isFloat = true;
       continue;  // Success.
     case 'u':
     case 'U':
@@ -338,7 +338,7 @@ NumericLiteralParser(const char *begin, const char *end,
     case 'l':
     case 'L':
       if (isLong || isLongLong) break;  // Cannot be repeated.
-      if (saw_float_suffix) break;      // LF invalid.
+      if (isFloat) break;               // LF invalid.
       
       // Check for long long.  The L's need to be adjacent and the same case.
       if (s+1 != ThisTokEnd && s[1] == s[0]) {
index f43243ea16536fabe9de639fcac991218faa3657..590c0eeeeff3047ea8698e5cee5914023f3133b1 100644 (file)
@@ -161,7 +161,7 @@ static bool EvaluateValue(llvm::APSInt &Result, Token &PeekTok,
     if (Literal.hadError)
       return true; // a diagnostic was already reported.
     
-    if (Literal.isFloatingLiteral()) {
+    if (Literal.isFloatingLiteral() || Literal.isImaginary) {
       PP.Diag(PeekTok, diag::err_pp_illegal_floating_literal);
       return true;
     }
index 9539a916f106c6cd202f110819d3d2a4e52fef8d..1c539558f8452a99a188b2701971bd1cc12fc44c 100644 (file)
@@ -221,8 +221,8 @@ Action::ExprResult Sema::ParseNumericConstant(const Token &Tok) {
     return new IntegerLiteral(ResultVal, t, Tok.getLocation());
   } else if (Literal.isFloatingLiteral()) {
     // FIXME: handle float values > 32 (including compute the real type...).
-    return new FloatingLiteral(Literal.GetFloatValue(), Context.FloatTy, 
-                               Tok.getLocation());
+    QualType Ty = Literal.isFloat ? Context.FloatTy : Context.DoubleTy;
+    return new FloatingLiteral(Literal.GetFloatValue(), Ty, Tok.getLocation());
   }
   return ExprResult(true);
 }
index c66740523519d2e843e0701acaf0dfa6f7586c9a..9c4c4cd924760c428bef92880fcb206986bda6ef 100644 (file)
@@ -44,7 +44,6 @@ class NumericLiteralParser {
   unsigned radix;
   
   bool saw_exponent, saw_period;
-  bool saw_float_suffix;    // 1.0f
   
 public:
   NumericLiteralParser(const char *begin, const char *end,
@@ -53,6 +52,7 @@ public:
   bool isUnsigned;
   bool isLong;        // This is *not* set for long long.
   bool isLongLong;
+  bool isFloat;       // 1.0f
   bool isImaginary;   // 1.0i
   
   bool isIntegerLiteral() const {