aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/LiteralSupport.cpp
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2009-04-01 11:09:15 +0000
committerSteve Naroff <snaroff@apple.com>2009-04-01 11:09:15 +0000
commit4e93b34fdb798abfa0534062a139f2c37cbf876e (patch)
tree1e5091c99270a902d14265d0baf1a2b5dab618d6 /lib/Lex/LiteralSupport.cpp
parentcf6bde343ff5653744ca782e04d5a9c54b260042 (diff)
ProcessUCNEscape(): Incorportate some feedback from Chris.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68198 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/LiteralSupport.cpp')
-rw-r--r--lib/Lex/LiteralSupport.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp
index 345291382d..a52d951e75 100644
--- a/lib/Lex/LiteralSupport.cpp
+++ b/lib/Lex/LiteralSupport.cpp
@@ -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;
}
}
}