diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-09-04 03:32:04 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-09-04 03:32:04 +0000 |
commit | a3deaeeb52acdc863ee98eb5bb20b419518bc592 (patch) | |
tree | 8fdb5366843aa16255db9672562976d83ca98c98 /clang/lib/Lex/Lexer.cpp | |
parent | 09ade9bb8b73587234b1703225beb9b4eed32cd0 (diff) | |
download | bcm5719-llvm-a3deaeeb52acdc863ee98eb5bb20b419518bc592.tar.gz bcm5719-llvm-a3deaeeb52acdc863ee98eb5bb20b419518bc592.zip |
Fix Lexer::ComputePreamble when MaxLines parameter is non-zero.
The function was only counting lines that included tokens and not empty lines,
but MaxLines (mainly initiated to the line where the code-completion point resides)
is a count of overall lines (even empty ones).
llvm-svn: 139085
Diffstat (limited to 'clang/lib/Lex/Lexer.cpp')
-rw-r--r-- | clang/lib/Lex/Lexer.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index 64b87449226..e9db93ee436 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -519,7 +519,22 @@ Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer, Token TheTok; Token IfStartTok; unsigned IfCount = 0; - unsigned Line = 0; + + unsigned MaxLineOffset = 0; + if (MaxLines) { + const char *CurPtr = Buffer->getBufferStart(); + unsigned CurLine = 0; + while (CurPtr != Buffer->getBufferEnd()) { + char ch = *CurPtr++; + if (ch == '\n') { + ++CurLine; + if (CurLine == MaxLines) + break; + } + } + if (CurPtr != Buffer->getBufferEnd()) + MaxLineOffset = CurPtr - Buffer->getBufferStart(); + } do { TheLexer.LexFromRawLexer(TheTok); @@ -543,11 +558,11 @@ Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer, // Keep track of the # of lines in the preamble. if (TheTok.isAtStartOfLine()) { - ++Line; + unsigned TokOffset = TheTok.getLocation().getRawEncoding() - StartOffset; // If we were asked to limit the number of lines in the preamble, // and we're about to exceed that limit, we're done. - if (MaxLines && Line >= MaxLines) + if (MaxLineOffset && TokOffset >= MaxLineOffset) break; } |