aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Lexer.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-08-09 20:45:32 +0000
committerDouglas Gregor <dgregor@apple.com>2010-08-09 20:45:32 +0000
commitdf95a13ec73d2cdaea79555cb412d767f4963120 (patch)
tree0a4ce9f2fe7d41a48249fcc3ae97342c66b443e6 /lib/Lex/Lexer.cpp
parenta277e7764bbe2752f900bf595654f9ad433f3961 (diff)
Use precompiled preambles for in-process code completion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110596 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r--lib/Lex/Lexer.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 5e435908be..b492d77691 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -311,7 +311,7 @@ namespace {
}
std::pair<unsigned, bool>
-Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer) {
+Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer, unsigned MaxLines) {
// Create a lexer starting at the beginning of the file. Note that we use a
// "fake" file source location at offset 1 so that the lexer will track our
// position within the file.
@@ -325,6 +325,8 @@ Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer) {
Token TheTok;
Token IfStartTok;
unsigned IfCount = 0;
+ unsigned Line = 0;
+
do {
TheLexer.LexFromRawLexer(TheTok);
@@ -345,6 +347,16 @@ Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer) {
InPreprocessorDirective = false;
}
+ // Keep track of the # of lines in the preamble.
+ if (TheTok.isAtStartOfLine()) {
+ ++Line;
+
+ // 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)
+ break;
+ }
+
// Comments are okay; skip over them.
if (TheTok.getKind() == tok::comment)
continue;
@@ -418,7 +430,9 @@ Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer) {
TheTok = HashTok;
}
- // We hit a token
+ // We hit a token that we don't recognize as being in the
+ // "preprocessing only" part of the file, so we're no longer in
+ // the preamble.
break;
} while (true);