diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-07-21 00:47:40 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-07-21 00:47:40 +0000 |
commit | 4c30bb148b53c8063e940ca3e049ba4d270dc9d5 (patch) | |
tree | 2e43d7060c0484949153db794fd239da10521514 /lib/Lex/PreprocessingRecord.cpp | |
parent | ffe9edd45f26873d58e7ddf79d403dd8072b748b (diff) |
Rework the detailed preprocessing record to separate preprocessing
entities generated directly by the preprocessor from those loaded from
the external source (e.g., the ASTReader). By separating these two
sets of entities into different vectors, we allow both to grow
independently, and eliminate the need for preallocating all of the
loaded preprocessing entities. This is similar to the way the recent
SourceManager refactoring treats FileIDs and the source location
address space.
As part of this, switch over to building a continuous range map to
track preprocessing entities.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135646 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PreprocessingRecord.cpp')
-rw-r--r-- | lib/Lex/PreprocessingRecord.cpp | 49 |
1 files changed, 18 insertions, 31 deletions
diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp index 9f93ab0450..6e2216ae86 100644 --- a/lib/Lex/PreprocessingRecord.cpp +++ b/lib/Lex/PreprocessingRecord.cpp @@ -47,42 +47,24 @@ void PreprocessingRecord::MaybeLoadPreallocatedEntities() const { PreprocessingRecord::PreprocessingRecord(bool IncludeNestedMacroExpansions) : IncludeNestedMacroExpansions(IncludeNestedMacroExpansions), - ExternalSource(0), NumPreallocatedEntities(0), - LoadedPreallocatedEntities(false) + ExternalSource(0), LoadedPreallocatedEntities(false) { } PreprocessingRecord::iterator PreprocessingRecord::begin(bool OnlyLocalEntities) { if (OnlyLocalEntities) - return PreprocessedEntities.begin() + NumPreallocatedEntities; + return iterator(this, 0); MaybeLoadPreallocatedEntities(); - return PreprocessedEntities.begin(); + return iterator(this, -(int)LoadedPreprocessedEntities.size()); } PreprocessingRecord::iterator PreprocessingRecord::end(bool OnlyLocalEntities) { if (!OnlyLocalEntities) MaybeLoadPreallocatedEntities(); - return PreprocessedEntities.end(); -} - -PreprocessingRecord::const_iterator -PreprocessingRecord::begin(bool OnlyLocalEntities) const { - if (OnlyLocalEntities) - return PreprocessedEntities.begin() + NumPreallocatedEntities; - - MaybeLoadPreallocatedEntities(); - return PreprocessedEntities.begin(); -} - -PreprocessingRecord::const_iterator -PreprocessingRecord::end(bool OnlyLocalEntities) const { - if (!OnlyLocalEntities) - MaybeLoadPreallocatedEntities(); - - return PreprocessedEntities.end(); + return iterator(this, PreprocessedEntities.size()); } void PreprocessingRecord::addPreprocessedEntity(PreprocessedEntity *Entity) { @@ -90,20 +72,25 @@ void PreprocessingRecord::addPreprocessedEntity(PreprocessedEntity *Entity) { } void PreprocessingRecord::SetExternalSource( - ExternalPreprocessingRecordSource &Source, - unsigned NumPreallocatedEntities) { + ExternalPreprocessingRecordSource &Source) { assert(!ExternalSource && "Preprocessing record already has an external source"); ExternalSource = &Source; - this->NumPreallocatedEntities = NumPreallocatedEntities; - PreprocessedEntities.insert(PreprocessedEntities.begin(), - NumPreallocatedEntities, 0); } -void PreprocessingRecord::SetPreallocatedEntity(unsigned Index, - PreprocessedEntity *Entity) { - assert(Index < NumPreallocatedEntities &&"Out-of-bounds preallocated entity"); - PreprocessedEntities[Index] = Entity; +unsigned PreprocessingRecord::allocateLoadedEntities(unsigned NumEntities) { + unsigned Result = LoadedPreprocessedEntities.size(); + LoadedPreprocessedEntities.resize(LoadedPreprocessedEntities.size() + + NumEntities); + return Result; +} + +void +PreprocessingRecord::setLoadedPreallocatedEntity(unsigned Index, + PreprocessedEntity *Entity) { + assert(Index < LoadedPreprocessedEntities.size() && + "Out-of-bounds preallocated entity"); + LoadedPreprocessedEntities[Index] = Entity; } void PreprocessingRecord::RegisterMacroDefinition(MacroInfo *Macro, |