summaryrefslogtreecommitdiffstats
path: root/clang/Lex/Lexer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-22 06:29:05 +0000
committerChris Lattner <sabre@nondot.org>2007-07-22 06:29:05 +0000
commitb9b8597c2304ecbb08ed1ed5dc899a604cef5144 (patch)
treec958e1ae8d44d25d5bb0f0c556f43d5a528baad9 /clang/Lex/Lexer.cpp
parent6b4db176eaf5b7fd28d0e4abfee2652047fd9df0 (diff)
downloadbcm5719-llvm-b9b8597c2304ecbb08ed1ed5dc899a604cef5144.tar.gz
bcm5719-llvm-b9b8597c2304ecbb08ed1ed5dc899a604cef5144.zip
avoid recursion between SkipBCPLComment and SkipWhitespace. In cases like this:
// foo // bar // baz we'd get two levels of call (bcpl & whitespace) for each line, leading to some seriously deep stacks in some cases. llvm-svn: 40384
Diffstat (limited to 'clang/Lex/Lexer.cpp')
-rw-r--r--clang/Lex/Lexer.cpp46
1 files changed, 22 insertions, 24 deletions
diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp
index e92fc94da2e..bdf8387b976 100644
--- a/clang/Lex/Lexer.cpp
+++ b/clang/Lex/Lexer.cpp
@@ -607,18 +607,6 @@ void Lexer::SkipWhitespace(Token &Result, const char *CurPtr) {
if (PrevChar != '\n' && PrevChar != '\r')
Result.setFlag(Token::LeadingSpace);
- // If the next token is obviously a // or /* */ comment, skip it efficiently
- // too (without going through the big switch stmt).
- if (Char == '/' && CurPtr[1] == '/' && !KeepCommentMode) {
- BufferPtr = CurPtr;
- SkipBCPLComment(Result, CurPtr+1);
- return;
- }
- if (Char == '/' && CurPtr[1] == '*' && !KeepCommentMode) {
- BufferPtr = CurPtr;
- SkipBlockComment(Result, CurPtr+2);
- return;
- }
BufferPtr = CurPtr;
}
@@ -707,16 +695,6 @@ bool Lexer::SkipBCPLComment(Token &Result, const char *CurPtr) {
Result.setFlag(Token::StartOfLine);
// No leading whitespace seen so far.
Result.clearFlag(Token::LeadingSpace);
-
- // It is common for the tokens immediately after a // comment to be
- // whitespace (indentation for the next line). Instead of going through the
- // big switch, handle it efficiently now.
- if (isWhitespace(*CurPtr)) {
- Result.setFlag(Token::LeadingSpace);
- SkipWhitespace(Result, CurPtr+1);
- return true;
- }
-
BufferPtr = CurPtr;
return true;
}
@@ -1145,8 +1123,24 @@ LexNextToken:
case '\t':
case '\f':
case '\v':
+ SkipHorizontalWhitespace:
Result.setFlag(Token::LeadingSpace);
SkipWhitespace(Result, CurPtr);
+
+ SkipIgnoredUnits:
+ CurPtr = BufferPtr;
+
+ // If the next token is obviously a // or /* */ comment, skip it efficiently
+ // too (without going through the big switch stmt).
+ if (CurPtr[0] == '/' && CurPtr[1] == '/' && !KeepCommentMode) {
+ SkipBCPLComment(Result, CurPtr+2);
+ goto SkipIgnoredUnits;
+ } else if (CurPtr[0] == '/' && CurPtr[1] == '*' && !KeepCommentMode) {
+ SkipBlockComment(Result, CurPtr+2);
+ goto SkipIgnoredUnits;
+ } else if (isHorizontalWhitespace(*CurPtr)) {
+ goto SkipHorizontalWhitespace;
+ }
goto LexNextToken; // GCC isn't tail call eliminating.
case 'L':
@@ -1306,8 +1300,12 @@ LexNextToken:
// 6.4.9: Comments
Char = getCharAndSize(CurPtr, SizeTmp);
if (Char == '/') { // BCPL comment.
- if (SkipBCPLComment(Result, ConsumeChar(CurPtr, SizeTmp, Result)))
- goto LexNextToken; // GCC isn't tail call eliminating.
+ if (SkipBCPLComment(Result, ConsumeChar(CurPtr, SizeTmp, Result))) {
+ // It is common for the tokens immediately after a // comment to be
+ // whitespace (indentation for the next line). Instead of going through the
+ // big switch, handle it efficiently now.
+ goto SkipIgnoredUnits;
+ }
return; // KeepCommentMode
} else if (Char == '*') { // /**/ comment.
if (SkipBlockComment(Result, ConsumeChar(CurPtr, SizeTmp, Result)))
OpenPOWER on IntegriCloud