aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/clang/Lex/PreprocessingRecord.h24
-rw-r--r--include/clang/Serialization/ASTBitCodes.h15
-rw-r--r--include/clang/Serialization/ASTReader.h31
-rw-r--r--include/clang/Serialization/Module.h2
4 files changed, 68 insertions, 4 deletions
diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h
index 0cc6cc5377..b348c4e7c7 100644
--- a/include/clang/Lex/PreprocessingRecord.h
+++ b/include/clang/Lex/PreprocessingRecord.h
@@ -271,6 +271,11 @@ namespace clang {
/// entity from being loaded.
virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) = 0;
+ /// \brief Returns a pair of [Begin, End) indices of preallocated
+ /// preprocessed entities that \arg Range encompasses.
+ virtual std::pair<unsigned, unsigned>
+ findPreprocessedEntitiesInRange(SourceRange Range) = 0;
+
/// \brief Read the preprocessed entity at the given offset.
virtual PreprocessedEntity *
ReadPreprocessedEntityAtOffset(uint64_t Offset) = 0;
@@ -280,6 +285,8 @@ namespace clang {
/// including the various preprocessing directives processed, macros
/// expanded, etc.
class PreprocessingRecord : public PPCallbacks {
+ SourceManager &SourceMgr;
+
/// \brief Whether we should include nested macro expansions in
/// the preprocessing record.
bool IncludeNestedMacroExpansions;
@@ -329,7 +336,14 @@ namespace clang {
unsigned getNumLoadedPreprocessedEntities() const {
return LoadedPreprocessedEntities.size();
}
-
+
+ /// \brief Returns a pair of [Begin, End) indices of local preprocessed
+ /// entities that \arg Range encompasses.
+ std::pair<unsigned, unsigned>
+ findLocalPreprocessedEntitiesInRange(SourceRange Range) const;
+ unsigned findBeginLocalPreprocessedEntity(SourceLocation Loc) const;
+ unsigned findEndLocalPreprocessedEntity(SourceLocation Loc) const;
+
/// \brief Allocate space for a new set of loaded preprocessed entities.
///
/// \returns The index into the set of loaded preprocessed entities, which
@@ -341,7 +355,7 @@ namespace clang {
public:
/// \brief Construct a new preprocessing record.
- explicit PreprocessingRecord(bool IncludeNestedMacroExpansions);
+ PreprocessingRecord(SourceManager &SM, bool IncludeNestedMacroExpansions);
/// \brief Allocate memory in the preprocessing record.
void *Allocate(unsigned Size, unsigned Align = 8) {
@@ -353,6 +367,8 @@ namespace clang {
size_t getTotalMemory() const;
+ SourceManager &getSourceManager() const { return SourceMgr; }
+
// Iteration over the preprocessed entities.
class iterator {
PreprocessingRecord *Self;
@@ -471,6 +487,10 @@ namespace clang {
iterator begin(bool OnlyLocalEntities = false);
iterator end(bool OnlyLocalEntities = false);
+ /// \brief Returns a pair of [Begin, End) iterators of preprocessed entities
+ /// that source range \arg R encompasses.
+ std::pair<iterator, iterator> getPreprocessedEntitiesInRange(SourceRange R);
+
/// \brief Add a new preprocessed entity to this record.
void addPreprocessedEntity(PreprocessedEntity *Entity);
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h
index f3dd8dc860..b8db49e76a 100644
--- a/include/clang/Serialization/ASTBitCodes.h
+++ b/include/clang/Serialization/ASTBitCodes.h
@@ -141,6 +141,21 @@ namespace clang {
/// preprocessing record.
typedef uint32_t PreprocessedEntityID;
+ /// \brief Source range/offset of a preprocessed entity.
+ struct PPEntityOffset {
+ /// \brief Raw source location of beginning of range.
+ unsigned Begin;
+ /// \brief Raw source location of end of range.
+ unsigned End;
+ /// \brief Offset in the AST file.
+ uint32_t BitOffset;
+
+ PPEntityOffset(SourceRange R, uint32_t BitOffset)
+ : Begin(R.getBegin().getRawEncoding()),
+ End(R.getEnd().getRawEncoding()),
+ BitOffset(BitOffset) { }
+ };
+
/// \brief The number of predefined preprocessed entity IDs.
const unsigned int NUM_PREDEF_PP_ENTITY_IDS = 1;
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index cc5c1d76e0..96b5e5835c 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -248,6 +248,12 @@ private:
/// \brief A map of negated SLocEntryIDs to the modules containing them.
ContinuousRangeMap<unsigned, Module*, 64> GlobalSLocEntryMap;
+ typedef ContinuousRangeMap<int, Module*, 64> GlobalSLocOffsetMapType;
+
+ /// \brief A map of negated SourceLocation offsets to the modules containing
+ /// them.
+ GlobalSLocOffsetMapType GlobalSLocOffsetMap;
+
/// \brief Types that have already been loaded from the chain.
///
/// When the pointer at index I is non-NULL, the type with
@@ -680,7 +686,23 @@ private:
RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
uint64_t getGlobalBitOffset(Module &M, uint32_t LocalOffset);
-
+
+ /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc.
+ serialization::PreprocessedEntityID
+ findBeginPreprocessedEntity(SourceLocation BLoc) const;
+
+ /// \brief Returns the first preprocessed entity ID that begins after \arg ELoc.
+ serialization::PreprocessedEntityID
+ findEndPreprocessedEntity(SourceLocation ELoc) const;
+
+ /// \brief \arg SLocMapI points at a chunk of a module that contains no
+ /// preprocessed entities or the entities it contains are not the ones we are
+ /// looking for. Find the next module that contains entities and return the ID
+ /// of the first entry.
+ serialization::PreprocessedEntityID
+ findNextPreprocessedEntity(
+ GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
+
void PassInterestingDeclsToConsumer();
/// \brief Produce an error diagnostic and return true.
@@ -723,6 +745,8 @@ public:
~ASTReader();
+ SourceManager &getSourceManager() const { return SourceMgr; }
+
/// \brief Load the AST file designated by the given file name.
ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type);
@@ -772,6 +796,11 @@ public:
/// entity from being loaded.
virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index);
+ /// \brief Returns a pair of [Begin, End) indices of preallocated
+ /// preprocessed entities that \arg Range encompasses.
+ virtual std::pair<unsigned, unsigned>
+ findPreprocessedEntitiesInRange(SourceRange Range);
+
/// \brief Read the preprocessed entity at the given offset.
virtual PreprocessedEntity *ReadPreprocessedEntityAtOffset(uint64_t Offset);
diff --git a/include/clang/Serialization/Module.h b/include/clang/Serialization/Module.h
index 9f063316c1..42b5a58e08 100644
--- a/include/clang/Serialization/Module.h
+++ b/include/clang/Serialization/Module.h
@@ -177,7 +177,7 @@ public:
/// \brief Remapping table for preprocessed entity IDs in this module.
ContinuousRangeMap<uint32_t, int, 2> PreprocessedEntityRemap;
- const uint32_t *PreprocessedEntityOffsets;
+ const PPEntityOffset *PreprocessedEntityOffsets;
unsigned NumPreprocessedEntities;
// === Header search information ===