diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-08-09 20:45:32 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-08-09 20:45:32 +0000 |
commit | 028d3e4d0fc16abb55ab566f909d9a30951a7325 (patch) | |
tree | c85eeda07ad4838b7aa3a010200930713d1a6038 /clang/lib/Lex | |
parent | f4804c696d55bb048d976637d953d83bebfeee9d (diff) | |
download | bcm5719-llvm-028d3e4d0fc16abb55ab566f909d9a30951a7325.tar.gz bcm5719-llvm-028d3e4d0fc16abb55ab566f909d9a30951a7325.zip |
Use precompiled preambles for in-process code completion.
llvm-svn: 110596
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r-- | clang/lib/Lex/Lexer.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index 5e435908beb..b492d776917 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/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); |