/// \brief The macro definitions we have already loaded.
llvm::SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded;
+ typedef ContinuousRangeMap<serialization::MacroID,
+ std::pair<PerFileData *, int32_t>, 4>
+ GlobalMacroDefinitionMapType;
+
+ /// \brief Mapping from global macro definition IDs to the module in which the
+ /// selector resides along with the offset that should be added to the
+ /// global selector ID to produce a local ID.
+ GlobalMacroDefinitionMapType GlobalMacroDefinitionMap;
+
/// \brief Mapping from identifiers that represent macros whose definitions
/// have not yet been deserialized to the global offset where the macro
/// record resides.
return 0;
if (!MacroDefinitionsLoaded[ID - 1]) {
- unsigned Index = ID - 1;
- for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
- PerFileData &F = *Chain[N - I - 1];
- if (Index < F.LocalNumMacroDefinitions) {
- SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor);
- F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]);
- LoadPreprocessedEntity(F);
- break;
- }
- Index -= F.LocalNumMacroDefinitions;
- }
- assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain");
+ GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID);
+ assert(I != GlobalMacroDefinitionMap.end() &&
+ "Corrupted global macro definition map");
+ PerFileData &F = *I->second.first;
+ unsigned Index = ID - 1 + I->second.second;
+ SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor);
+ F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]);
+ LoadPreprocessedEntity(F);
}
return MacroDefinitionsLoaded[ID - 1];
F.MacroDefinitionOffsets = (const uint32_t *)BlobStart;
F.NumPreallocatedPreprocessingEntities = Record[0];
F.LocalNumMacroDefinitions = Record[1];
+
+ // Introduce the global -> local mapping for identifiers within this AST
+ // file
+ GlobalMacroDefinitionMap.insert(
+ std::make_pair(getTotalNumMacroDefinitions() + 1,
+ std::make_pair(&F,
+ -getTotalNumMacroDefinitions())));
+ MacroDefinitionsLoaded.resize(
+ MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions);
+
break;
case DECL_UPDATE_OFFSETS: {
}
// Allocate space for loaded slocentries, identifiers, decls and types.
- unsigned TotalNumTypes = 0,
- TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0;
+ unsigned TotalNumTypes = 0, TotalNumPreallocatedPreprocessingEntities = 0;
for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries;
TotalNumTypes += Chain[I]->LocalNumTypes;
TotalNumPreallocatedPreprocessingEntities +=
Chain[I]->NumPreallocatedPreprocessingEntities;
- TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions;
}
TypesLoaded.resize(TotalNumTypes);
- MacroDefinitionsLoaded.resize(TotalNumMacroDefs);
if (PP) {
PP->getHeaderSearchInfo().SetExternalLookup(this);
if (TotalNumPreallocatedPreprocessingEntities > 0) {