diff options
Diffstat (limited to 'lib/Lex/PPLexerChange.cpp')
-rw-r--r-- | lib/Lex/PPLexerChange.cpp | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index d827f58..be4defe 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/lib/Lex/PPLexerChange.cpp @@ -13,15 +13,15 @@ //===----------------------------------------------------------------------===// #include "clang/Lex/Preprocessor.h" -#include "clang/Lex/HeaderSearch.h" -#include "clang/Lex/MacroInfo.h" -#include "clang/Lex/LexDiagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" +#include "clang/Lex/HeaderSearch.h" +#include "clang/Lex/LexDiagnostic.h" +#include "clang/Lex/MacroInfo.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PathV2.h" -#include "llvm/ADT/StringSwitch.h" using namespace clang; PPCallbacks::~PPCallbacks() {} @@ -158,15 +158,17 @@ void Preprocessor::EnterSourceFileWithPTH(PTHLexer *PL, /// tokens from it instead of the current buffer. void Preprocessor::EnterMacro(Token &Tok, SourceLocation ILEnd, MacroInfo *Macro, MacroArgs *Args) { - PushIncludeMacroStack(); - CurDirLookup = 0; - + TokenLexer *TokLexer; if (NumCachedTokenLexers == 0) { - CurTokenLexer.reset(new TokenLexer(Tok, ILEnd, Macro, Args, *this)); + TokLexer = new TokenLexer(Tok, ILEnd, Macro, Args, *this); } else { - CurTokenLexer.reset(TokenLexerCache[--NumCachedTokenLexers]); - CurTokenLexer->Init(Tok, ILEnd, Macro, Args); + TokLexer = TokenLexerCache[--NumCachedTokenLexers]; + TokLexer->Init(Tok, ILEnd, Macro, Args); } + + PushIncludeMacroStack(); + CurDirLookup = 0; + CurTokenLexer.reset(TokLexer); if (CurLexerKind != CLK_LexAfterModuleImport) CurLexerKind = CLK_TokenLexer; } @@ -186,18 +188,20 @@ void Preprocessor::EnterMacro(Token &Tok, SourceLocation ILEnd, void Preprocessor::EnterTokenStream(const Token *Toks, unsigned NumToks, bool DisableMacroExpansion, bool OwnsTokens) { - // Save our current state. - PushIncludeMacroStack(); - CurDirLookup = 0; - // Create a macro expander to expand from the specified token stream. + TokenLexer *TokLexer; if (NumCachedTokenLexers == 0) { - CurTokenLexer.reset(new TokenLexer(Toks, NumToks, DisableMacroExpansion, - OwnsTokens, *this)); + TokLexer = new TokenLexer(Toks, NumToks, DisableMacroExpansion, + OwnsTokens, *this); } else { - CurTokenLexer.reset(TokenLexerCache[--NumCachedTokenLexers]); - CurTokenLexer->Init(Toks, NumToks, DisableMacroExpansion, OwnsTokens); + TokLexer = TokenLexerCache[--NumCachedTokenLexers]; + TokLexer->Init(Toks, NumToks, DisableMacroExpansion, OwnsTokens); } + + // Save our current state. + PushIncludeMacroStack(); + CurDirLookup = 0; + CurTokenLexer.reset(TokLexer); if (CurLexerKind != CLK_LexAfterModuleImport) CurLexerKind = CLK_TokenLexer; } @@ -328,6 +332,17 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) { CurLexer->BufferPtr = EndPos; CurLexer->FormTokenWithChars(Result, EndPos, tok::eof); + if (isCodeCompletionEnabled()) { + // Inserting the code-completion point increases the source buffer by 1, + // but the main FileID was created before inserting the point. + // Compensate by reducing the EOF location by 1, otherwise the location + // will point to the next FileID. + // FIXME: This is hacky, the code-completion point should probably be + // inserted before the main FileID is created. + if (CurLexer->getFileLoc() == CodeCompletionFileLoc) + Result.setLocation(Result.getLocation().getLocWithOffset(-1)); + } + if (!isIncrementalProcessingEnabled()) // We're done with lexing. CurLexer.reset(); @@ -380,7 +395,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) { SmallString<128> RelativePath; computeRelativePath(FileMgr, Dir, Header, RelativePath); Diag(StartLoc, diag::warn_uncovered_module_header) - << RelativePath; + << Mod->getFullModuleName() << RelativePath; } } } |