diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-22 21:11:38 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-22 21:11:38 +0000 |
commit | b657f115c3b4e262e72906a28cbcf3eaccd9460c (patch) | |
tree | 95502c386d41a13dd1c04b189247446b9fb8d18e /lib/Lex/Lexer.cpp | |
parent | add28829c7a8d3c5da9ae140f18d3c9ad2d8b599 (diff) |
Replace the -code-completion-dump option with
-code-completion-at=filename:line:column
which performs code completion at the specified location by truncating
the file at that position and enabling code completion. This approach
makes it possible to run multiple tests from a single test file, and
gives a more natural command-line interface.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82571 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r-- | lib/Lex/Lexer.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 74ac55cf2e..0f01155a8f 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -101,12 +101,16 @@ Lexer::Lexer(FileID FID, Preprocessor &PP) Features(PP.getLangOptions()) { const llvm::MemoryBuffer *InputFile = PP.getSourceManager().getBuffer(FID); - + InitLexer(InputFile->getBufferStart(), InputFile->getBufferStart(), InputFile->getBufferEnd()); // Default to keeping comments if the preprocessor wants them. SetCommentRetentionState(PP.getCommentRetentionState()); + + // If the input file is truncated, the EOF is a code-completion token. + if (PP.getSourceManager().isTruncatedFile(FID)) + IsEofCodeCompletion = true; } /// Lexer constructor - Create a new raw lexer object. This object is only @@ -1323,15 +1327,23 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) { // unterminated #if and missing newline. if (IsEofCodeCompletion) { - // We're at the end of the file, but we've been asked to conside the - // end of the file to be a code-completion token. Return the - // code-completion token. - Result.startToken(); - FormTokenWithChars(Result, CurPtr, tok::code_completion); + bool isIntendedFile = true; + if (PP && FileLoc.isFileID()) { + SourceManager &SM = PP->getSourceManager(); + isIntendedFile = SM.isTruncatedFile(SM.getFileID(FileLoc)); + } - // Only do the eof -> code_completion translation once. - IsEofCodeCompletion = false; - return true; + if (isIntendedFile) { + // We're at the end of the file, but we've been asked to consider the + // end of the file to be a code-completion token. Return the + // code-completion token. + Result.startToken(); + FormTokenWithChars(Result, CurPtr, tok::code_completion); + + // Only do the eof -> code_completion translation once. + IsEofCodeCompletion = false; + return true; + } } // If we are in a #if directive, emit an error. |