aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Lexer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-08-31 16:42:00 +0000
committerChris Lattner <sabre@nondot.org>2010-08-31 16:42:00 +0000
commit6ab55ebab20086f725c4017b48ef8d7691ef870f (patch)
treee58a0210fa151e400fe36d1afee6783a1ee5022e /lib/Lex/Lexer.cpp
parent01829d3afafdfd355cbe93537bc408aeeed964c6 (diff)
improve isHexaLiteral to work with escaped newlines and trigraphs,
patch by Francois Pichet! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112602 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r--lib/Lex/Lexer.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 98277a444f..917829be47 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -921,13 +921,14 @@ FinishIdentifier:
}
/// 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 @@ void Lexer::LexNumericConstant(Token &Result, const char *CurPtr) {
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));
}