diff options
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 12 | ||||
-rw-r--r-- | include/clang/Frontend/ASTUnit.h | 5 | ||||
-rw-r--r-- | include/clang/Lex/PreprocessingRecord.h | 34 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 10 |
4 files changed, 60 insertions, 1 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 591d905317..4df9ae7e9a 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -807,6 +807,18 @@ public: unsigned FileOffset = Entry.getOffset(); return SourceLocation::getFileLoc(FileOffset); } + + /// \brief Return the source location corresponding to the last byte of the + /// specified file. + SourceLocation getLocForEndOfFile(FileID FID) const { + bool Invalid = false; + const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); + if (Invalid || !Entry.isFile()) + return SourceLocation(); + + unsigned FileOffset = Entry.getOffset(); + return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID) - 1); + } /// \brief Returns the include location if \arg FID is a #include'd file /// otherwise it returns an invalid location. diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 970866469f..eb1576439b 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -546,6 +546,11 @@ public: /// preamble, otherwise it returns \arg Loc. SourceLocation mapLocationToPreamble(SourceLocation Loc); + bool isInPreambleFileID(SourceLocation Loc); + bool isInMainFileID(SourceLocation Loc); + SourceLocation getStartOfMainFileID(); + SourceLocation getEndOfPreambleFileID(); + /// \brief \see mapLocationFromPreamble. SourceRange mapRangeFromPreamble(SourceRange R) { return SourceRange(mapLocationFromPreamble(R.getBegin()), diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index 53da19e6c2..2947c9ef91 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -18,6 +18,7 @@ #include "clang/Basic/SourceLocation.h" #include "clang/Basic/IdentifierTable.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/Optional.h" #include "llvm/Support/Allocator.h" #include <vector> @@ -269,6 +270,13 @@ namespace clang { /// preprocessed entities that \arg Range encompasses. virtual std::pair<unsigned, unsigned> findPreprocessedEntitiesInRange(SourceRange Range) = 0; + + /// \brief Optionally returns true or false if the preallocated preprocessed + /// entity with index \arg Index came from file \arg FID. + virtual llvm::Optional<bool> isPreprocessedEntityInFileID(unsigned Index, + FileID FID) { + return llvm::Optional<bool>(); + } }; /// \brief A record of the steps taken while preprocessing a source file, @@ -386,7 +394,7 @@ namespace clang { iterator() : Self(0), Position(0) { } - iterator(PreprocessingRecord *Self, int Position) + iterator(PreprocessingRecord *Self, PPEntityID Position) : Self(Self), Position(Position) { } value_type operator*() const { @@ -471,6 +479,7 @@ namespace clang { X.Position -= D; return X; } + friend class PreprocessingRecord; }; friend class iterator; @@ -496,8 +505,20 @@ namespace clang { /// \brief Returns a pair of [Begin, End) iterators of preprocessed entities /// that source range \arg R encompasses. + /// + /// \param R the range to look for preprocessed entities. + /// std::pair<iterator, iterator> getPreprocessedEntitiesInRange(SourceRange R); + /// \brief Returns true if the preprocessed entity that \arg PPEI iterator + /// points to is coming from the file \arg FID. + /// + /// Can be used to avoid implicit deserializations of preallocated + /// preprocessed entities if we only care about entities of a specific file + /// and not from files #included in the range given at + /// \see getPreprocessedEntitiesInRange. + bool isEntityInFileID(iterator PPEI, FileID FID); + /// \brief Add a new preprocessed entity to this record. void addPreprocessedEntity(PreprocessedEntity *Entity); @@ -526,6 +547,17 @@ namespace clang { StringRef SearchPath, StringRef RelativePath); + private: + /// \brief Cached result of the last \see getPreprocessedEntitiesInRange + /// query. + struct { + SourceRange Range; + std::pair<PPEntityID, PPEntityID> Result; + } CachedRangeQuery; + + std::pair<PPEntityID, PPEntityID> + getPreprocessedEntitiesInRangeSlow(SourceRange R); + friend class ASTReader; friend class ASTWriter; }; diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 996a134659..b1a514df49 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -703,6 +703,11 @@ private: findNextPreprocessedEntity( GlobalSLocOffsetMapType::const_iterator SLocMapI) const; + /// \brief Returns (Module, Local index) pair for \arg GlobalIndex of a + /// preprocessed entity. + std::pair<Module *, unsigned> + getModulePreprocessedEntity(unsigned GlobalIndex); + void PassInterestingDeclsToConsumer(); /// \brief Produce an error diagnostic and return true. @@ -800,6 +805,11 @@ public: /// preprocessed entities that \arg Range encompasses. virtual std::pair<unsigned, unsigned> findPreprocessedEntitiesInRange(SourceRange Range); + + /// \brief Optionally returns true or false if the preallocated preprocessed + /// entity with index \arg Index came from file \arg FID. + virtual llvm::Optional<bool> isPreprocessedEntityInFileID(unsigned Index, + FileID FID); /// \brief Read the header file information for the given file entry. virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE); |