[cfe-commits] r112602 - in /cfe/trunk: lib/Lex/Lexer.cpp test/Lexer/ms-extensions.c

Chris Lattner sabre at nondot.org
Tue Aug 31 09:42:00 PDT 2010


Author: lattner
Date: Tue Aug 31 11:42:00 2010
New Revision: 112602

URL: http://llvm.org/viewvc/llvm-project?rev=112602&view=rev
Log:
improve isHexaLiteral to work with escaped newlines and trigraphs,
patch by Francois Pichet!

Modified:
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/test/Lexer/ms-extensions.c

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=112602&r1=112601&r2=112602&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Tue Aug 31 11:42:00 2010
@@ -921,13 +921,14 @@
 }
 
 /// isHexaLiteral - Return true if Start points to a hex constant.
-/// FIXME: This isn't correct, it will mislex:
-///     0\       <- escaped newline.
-///     x1234e+1
 /// in microsoft mode (where this is supposed to be several different tokens).
-static inline bool isHexaLiteral(const char *Start, const char *End) {
-  return ((End - Start > 2) && Start[0] == '0' && 
-          (Start[1] == 'x' || Start[1] == 'X'));
+static bool isHexaLiteral(const char *Start, const LangOptions &Features) {
+  unsigned Size;
+  char C1 = Lexer::getCharAndSizeNoWarn(Start, Size, Features);
+  if (C1 != '0')
+    return false;
+  char C2 = Lexer::getCharAndSizeNoWarn(Start + Size, Size, Features);
+  return (C2 == 'x' || C2 == 'X');
 }
 
 /// LexNumericConstant - Lex the remainder of a integer or floating point
@@ -947,7 +948,7 @@
   if ((C == '-' || C == '+') && (PrevCh == 'E' || PrevCh == 'e')) {
     // If we are in Microsoft mode, don't continue if the constant is hex.
     // For example, MSVC will accept the following as 3 tokens: 0x1234567e+1
-    if (!Features.Microsoft || !isHexaLiteral(BufferPtr, CurPtr))
+    if (!Features.Microsoft || !isHexaLiteral(BufferPtr, Features))
       return LexNumericConstant(Result, ConsumeChar(CurPtr, Size, Result));
   }
 

Modified: cfe/trunk/test/Lexer/ms-extensions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/ms-extensions.c?rev=112602&r1=112601&r2=112602&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/ms-extensions.c (original)
+++ cfe/trunk/test/Lexer/ms-extensions.c Tue Aug 31 11:42:00 2010
@@ -30,4 +30,12 @@
   int var2 = 0X1111111e+1;
   int var3 = 0xe+1;
   int var4 = 0XE+1;
+
+  int var5=    0\
+x1234e+1;
+
+  int var6=
+  /*expected-warning {{backslash and newline separated by space}} */    0\       
+x1234e+1;                      
 }
+





More information about the cfe-commits mailing list