diff options
Diffstat (limited to 'clang/lib/Lex/Preprocessor.cpp')
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 7fdb5d4c..031ed1e 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -72,6 +72,9 @@ using namespace clang; +/// Minimum distance between two check points, in tokens. +static constexpr unsigned CheckPointStepSize = 1024; + LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry) ExternalPreprocessorSource::~ExternalPreprocessorSource() = default; @@ -954,6 +957,11 @@ void Preprocessor::Lex(Token &Result) { } } + if (CurLexer && ++CheckPointCounter == CheckPointStepSize) { + CheckPoints[CurLexer->getFileID()].push_back(CurLexer->BufferPtr); + CheckPointCounter = 0; + } + LastTokenWasAt = Result.is(tok::at); --LexLevel; @@ -1558,3 +1566,19 @@ void Preprocessor::createPreprocessingRecord() { Record = new PreprocessingRecord(getSourceManager()); addPPCallbacks(std::unique_ptr<PPCallbacks>(Record)); } + +const char *Preprocessor::getCheckPoint(FileID FID, const char *Start) const { + if (auto It = CheckPoints.find(FID); It != CheckPoints.end()) { + const SmallVector<const char *> &FileCheckPoints = It->second; + const char *Last = nullptr; + // FIXME: Do better than a linear search. + for (const char *P : FileCheckPoints) { + if (P > Start) + break; + Last = P; + } + return Last; + } + + return nullptr; +} |