[cfe-commits] r83591 - in /cfe/trunk: include/clang/Lex/LiteralSupport.h lib/Lex/LiteralSupport.cpp

Mike Stump mrs at apple.com
Thu Oct 8 15:55:37 PDT 2009


Author: mrs
Date: Thu Oct  8 17:55:36 2009
New Revision: 83591

URL: http://llvm.org/viewvc/llvm-project?rev=83591&view=rev
Log:
This fixes support for complex literals, reworked to avoid a goto, and
to add a flag noting the presence of a Microsoft extension suffix (i8,
i16, i32, i64).  Patch by John Thompson.

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

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

==============================================================================
--- cfe/trunk/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/trunk/include/clang/Lex/LiteralSupport.h Thu Oct  8 17:55:36 2009
@@ -57,6 +57,7 @@
   bool isLongLong;
   bool isFloat;       // 1.0f
   bool isImaginary;   // 1.0i
+  bool isMicrosoftInteger;  // Microsoft suffix extension i8, i16, i32, or i64.
 
   bool isIntegerLiteral() const {
     return !saw_period && !saw_exponent;

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

==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Thu Oct  8 17:55:36 2009
@@ -298,6 +298,7 @@
   isLongLong = false;
   isFloat = false;
   isImaginary = false;
+  isMicrosoftInteger = false;
   hadError = false;
 
   if (*s == '0') { // parse radix
@@ -375,31 +376,50 @@
     case 'i':
       if (PP.getLangOptions().Microsoft) {
         // Allow i8, i16, i32, i64, and i128.
-        if (++s == ThisTokEnd) break;
-        switch (*s) {
-          case '8':
-            s++; // i8 suffix
-            break;
-          case '1':
-            if (++s == ThisTokEnd) break;
-            if (*s == '6') s++; // i16 suffix
-            else if (*s == '2') {
-              if (++s == ThisTokEnd) break;
-              if (*s == '8') s++; // i128 suffix
-            }
-            break;
-          case '3':
-            if (++s == ThisTokEnd) break;
-            if (*s == '2') s++; // i32 suffix
-            break;
-          case '6':
-            if (++s == ThisTokEnd) break;
-            if (*s == '4') s++; // i64 suffix
-            break;
-          default:
-            break;
+        if (s + 1 != ThisTokEnd) {
+          switch (s[1]) {
+            case '8':
+              s += 2; // i8 suffix
+              isMicrosoftInteger = true;
+              continue;
+            case '1':
+              s += 2;
+              if (s == ThisTokEnd) break;
+              if (*s == '6') s++; // i16 suffix
+              else if (*s == '2') {
+                if (++s == ThisTokEnd) break;
+                if (*s == '8') s++; // i128 suffix
+              }
+              isMicrosoftInteger = true;
+              continue;
+            case '3':
+              s += 2;
+              if (s == ThisTokEnd) break;
+              if (*s == '2') s++; // i32 suffix
+              isMicrosoftInteger = true;
+              continue;
+            case '6':
+              s += 2;
+              if (s == ThisTokEnd) break;
+              if (*s == '4') s++; // i64 suffix
+              isMicrosoftInteger = true;
+              continue;
+            case 'f':      // FP Suffix for "float"
+            case 'F':
+              if (!isFPConstant) break;  // Error for integer constant.
+              if (isFloat || isLong) break; // FF, LF invalid.
+              isFloat = true;
+              if (isImaginary) break;   // Cannot be repeated.
+              PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-begin),
+                      diag::ext_imaginary_constant);
+              isImaginary = true;
+              s++;
+              continue;  // Success.
+            default:
+              break;
+          }
+          break;
         }
-        break;
       }
       // fall through.
     case 'I':





More information about the cfe-commits mailing list