]> granicus.if.org Git - clang/commitdiff
ProcessUCNEscape(): Incorportate some feedback from Chris.
authorSteve Naroff <snaroff@apple.com>
Wed, 1 Apr 2009 11:09:15 +0000 (11:09 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 1 Apr 2009 11:09:15 +0000 (11:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68198 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/LiteralSupport.cpp

index 345291382da600d78d34002db41ae461b9cdadf7..a52d951e7543f1d62c76120398ccfeb51c56091f 100644 (file)
@@ -160,6 +160,9 @@ static void ProcessUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd,
   // FIXME: Add a warning - UCN's are only valid in C++ & C99.
   // FIXME: Handle wide strings.
   
+  // Save the beginning of the string (for error diagnostics).
+  const char *ThisTokBegin = ThisTokBuf;
+  
   // Skip the '\u' char's.
   ThisTokBuf += 2;
 
@@ -168,7 +171,7 @@ static void ProcessUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd,
     HadError = 1;
     return;
   }
-  typedef unsigned int UTF32;
+  typedef uint32_t UTF32;
   
   UTF32 UcnVal = 0;
   unsigned short UcnLen = (ThisTokBuf[-1] == 'u' ? 4 : 8);
@@ -180,7 +183,8 @@ static void ProcessUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd,
   }
   // If we didn't consume the proper number of digits, there is a problem.
   if (UcnLen) {
-    PP.Diag(Loc, diag::err_ucn_escape_incomplete);
+    PP.Diag(PP.AdvanceToTokenCharacter(Loc, ThisTokBuf-ThisTokBegin),
+            diag::err_ucn_escape_incomplete);
     HadError = 1;
     return;
   }
@@ -197,7 +201,7 @@ static void ProcessUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd,
   // The conversion below was inspired by:
   //   http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
   // First, we determine how many bytes the result will require. 
-  typedef unsigned char UTF8;
+  typedef uint8_t UTF8;
 
   unsigned short bytesToWrite = 0;
   if (UcnVal < (UTF32)0x80)
@@ -838,23 +842,23 @@ StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
         }
         continue;
       }
-      
+      // Is this a Universal Character Name escape?
       if (ThisTokBuf[1] == 'u' || ThisTokBuf[1] == 'U') {
         ProcessUCNEscape(ThisTokBuf, ThisTokEnd, ResultPtr, 
                          hadError, StringToks[i].getLocation(), ThisIsWide, PP);
-      } else {
-        // Otherwise, this is a non-UCN escape character.  Process it.
-        unsigned ResultChar = ProcessCharEscape(ThisTokBuf, ThisTokEnd, hadError,
-                                                StringToks[i].getLocation(),
-                                                ThisIsWide, PP);
-        
-        // Note: our internal rep of wide char tokens is always little-endian.
-        *ResultPtr++ = ResultChar & 0xFF;
-        
-        if (AnyWide) {
-          for (unsigned i = 1, e = wchar_tByteWidth; i != e; ++i)
-            *ResultPtr++ = ResultChar >> i*8;
-        }
+        continue;
+      }
+      // Otherwise, this is a non-UCN escape character.  Process it.
+      unsigned ResultChar = ProcessCharEscape(ThisTokBuf, ThisTokEnd, hadError,
+                                              StringToks[i].getLocation(),
+                                              ThisIsWide, PP);
+      
+      // Note: our internal rep of wide char tokens is always little-endian.
+      *ResultPtr++ = ResultChar & 0xFF;
+      
+      if (AnyWide) {
+        for (unsigned i = 1, e = wchar_tByteWidth; i != e; ++i)
+          *ResultPtr++ = ResultChar >> i*8;
       }
     }
   }