1 //===--- GlobalModuleIndex.cpp - Global Module Index ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the GlobalModuleIndex class.
12 //===----------------------------------------------------------------------===//
14 #include "ASTReaderInternals.h"
15 #include "clang/Basic/FileManager.h"
16 #include "clang/Basic/OnDiskHashTable.h"
17 #include "clang/Serialization/ASTBitCodes.h"
18 #include "clang/Serialization/GlobalModuleIndex.h"
19 #include "clang/Serialization/Module.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/MapVector.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/Bitcode/BitstreamReader.h"
25 #include "llvm/Bitcode/BitstreamWriter.h"
26 #include "llvm/Support/FileSystem.h"
27 #include "llvm/Support/LockFileManager.h"
28 #include "llvm/Support/MemoryBuffer.h"
29 #include "llvm/Support/Path.h"
31 using namespace clang;
32 using namespace serialization;
34 //----------------------------------------------------------------------------//
36 //----------------------------------------------------------------------------//
39 /// \brief The block containing the index.
40 GLOBAL_INDEX_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID
43 /// \brief Describes the record types in the index.
44 enum IndexRecordTypes {
45 /// \brief Contains version information and potentially other metadata,
46 /// used to determine if we can read this global index file.
48 /// \brief Describes a module, including its file name and dependencies.
50 /// \brief The index for identifiers.
55 /// \brief The name of the global index file.
56 static const char * const IndexFileName = "modules.idx";
58 /// \brief The global index file version.
59 static const unsigned CurrentVersion = 1;
61 //----------------------------------------------------------------------------//
62 // Global module index reader.
63 //----------------------------------------------------------------------------//
67 /// \brief Trait used to read the identifier index from the on-disk hash
69 class IdentifierIndexReaderTrait {
71 typedef StringRef external_key_type;
72 typedef StringRef internal_key_type;
73 typedef SmallVector<unsigned, 2> data_type;
75 static bool EqualKey(const internal_key_type& a, const internal_key_type& b) {
79 static unsigned ComputeHash(const internal_key_type& a) {
80 return llvm::HashString(a);
83 static std::pair<unsigned, unsigned>
84 ReadKeyDataLength(const unsigned char*& d) {
85 using namespace clang::io;
86 unsigned KeyLen = ReadUnalignedLE16(d);
87 unsigned DataLen = ReadUnalignedLE16(d);
88 return std::make_pair(KeyLen, DataLen);
91 static const internal_key_type&
92 GetInternalKey(const external_key_type& x) { return x; }
94 static const external_key_type&
95 GetExternalKey(const internal_key_type& x) { return x; }
97 static internal_key_type ReadKey(const unsigned char* d, unsigned n) {
98 return StringRef((const char *)d, n);
101 static data_type ReadData(const internal_key_type& k,
102 const unsigned char* d,
104 using namespace clang::io;
107 while (DataLen > 0) {
108 unsigned ID = ReadUnalignedLE32(d);
109 Result.push_back(ID);
117 typedef OnDiskChainedHashTable<IdentifierIndexReaderTrait> IdentifierIndexTable;
121 GlobalModuleIndex::GlobalModuleIndex(llvm::MemoryBuffer *Buffer,
122 llvm::BitstreamCursor Cursor)
123 : Buffer(Buffer), IdentifierIndex(),
124 NumIdentifierLookups(), NumIdentifierLookupHits()
126 // Read the global index.
127 bool InGlobalIndexBlock = false;
130 llvm::BitstreamEntry Entry = Cursor.advance();
132 switch (Entry.Kind) {
133 case llvm::BitstreamEntry::Error:
136 case llvm::BitstreamEntry::EndBlock:
137 if (InGlobalIndexBlock) {
138 InGlobalIndexBlock = false;
145 case llvm::BitstreamEntry::Record:
146 // Entries in the global index block are handled below.
147 if (InGlobalIndexBlock)
152 case llvm::BitstreamEntry::SubBlock:
153 if (!InGlobalIndexBlock && Entry.ID == GLOBAL_INDEX_BLOCK_ID) {
154 if (Cursor.EnterSubBlock(GLOBAL_INDEX_BLOCK_ID))
157 InGlobalIndexBlock = true;
158 } else if (Cursor.SkipBlock()) {
164 SmallVector<uint64_t, 64> Record;
166 switch ((IndexRecordTypes)Cursor.readRecord(Entry.ID, Record, &Blob)) {
168 // Make sure that the version matches.
169 if (Record.size() < 1 || Record[0] != CurrentVersion)
175 unsigned ID = Record[Idx++];
177 // Make room for this module's information.
178 if (ID == Modules.size())
179 Modules.push_back(ModuleInfo());
181 Modules.resize(ID + 1);
183 // Size/modification time for this module file at the time the
184 // global index was built.
185 Modules[ID].Size = Record[Idx++];
186 Modules[ID].ModTime = Record[Idx++];
189 unsigned NameLen = Record[Idx++];
190 Modules[ID].FileName.assign(Record.begin() + Idx,
191 Record.begin() + Idx + NameLen);
195 unsigned NumDeps = Record[Idx++];
196 Modules[ID].Dependencies.insert(Modules[ID].Dependencies.end(),
197 Record.begin() + Idx,
198 Record.begin() + Idx + NumDeps);
201 // Make sure we're at the end of the record.
202 assert(Idx == Record.size() && "More module info?");
204 // Record this module as an unresolved module.
205 UnresolvedModules[llvm::sys::path::stem(Modules[ID].FileName)] = ID;
209 case IDENTIFIER_INDEX:
210 // Wire up the identifier index.
212 IdentifierIndex = IdentifierIndexTable::Create(
213 (const unsigned char *)Blob.data() + Record[0],
214 (const unsigned char *)Blob.data(),
215 IdentifierIndexReaderTrait());
222 GlobalModuleIndex::~GlobalModuleIndex() { }
224 std::pair<GlobalModuleIndex *, GlobalModuleIndex::ErrorCode>
225 GlobalModuleIndex::readIndex(StringRef Path) {
226 // Load the index file, if it's there.
227 llvm::SmallString<128> IndexPath;
229 llvm::sys::path::append(IndexPath, IndexFileName);
231 llvm::OwningPtr<llvm::MemoryBuffer> Buffer;
232 if (llvm::MemoryBuffer::getFile(IndexPath.c_str(), Buffer) !=
234 return std::make_pair((GlobalModuleIndex *)0, EC_NotFound);
236 /// \brief The bitstream reader from which we'll read the AST file.
237 llvm::BitstreamReader Reader((const unsigned char *)Buffer->getBufferStart(),
238 (const unsigned char *)Buffer->getBufferEnd());
240 /// \brief The main bitstream cursor for the main block.
241 llvm::BitstreamCursor Cursor(Reader);
243 // Sniff for the signature.
244 if (Cursor.Read(8) != 'B' ||
245 Cursor.Read(8) != 'C' ||
246 Cursor.Read(8) != 'G' ||
247 Cursor.Read(8) != 'I') {
248 return std::make_pair((GlobalModuleIndex *)0, EC_IOError);
251 return std::make_pair(new GlobalModuleIndex(Buffer.take(), Cursor), EC_None);
255 GlobalModuleIndex::getKnownModules(SmallVectorImpl<ModuleFile *> &ModuleFiles) {
257 for (unsigned I = 0, N = Modules.size(); I != N; ++I) {
258 if (ModuleFile *MF = Modules[I].File)
259 ModuleFiles.push_back(MF);
263 void GlobalModuleIndex::getModuleDependencies(
265 SmallVectorImpl<ModuleFile *> &Dependencies) {
266 // Look for information about this module file.
267 llvm::DenseMap<ModuleFile *, unsigned>::iterator Known
268 = ModulesByFile.find(File);
269 if (Known == ModulesByFile.end())
272 // Record dependencies.
273 Dependencies.clear();
274 ArrayRef<unsigned> StoredDependencies = Modules[Known->second].Dependencies;
275 for (unsigned I = 0, N = StoredDependencies.size(); I != N; ++I) {
276 if (ModuleFile *MF = Modules[I].File)
277 Dependencies.push_back(MF);
281 bool GlobalModuleIndex::lookupIdentifier(StringRef Name, HitSet &Hits) {
284 // If there's no identifier index, there is nothing we can do.
285 if (!IdentifierIndex)
288 // Look into the identifier index.
289 ++NumIdentifierLookups;
290 IdentifierIndexTable &Table
291 = *static_cast<IdentifierIndexTable *>(IdentifierIndex);
292 IdentifierIndexTable::iterator Known = Table.find(Name);
293 if (Known == Table.end()) {
297 SmallVector<unsigned, 2> ModuleIDs = *Known;
298 for (unsigned I = 0, N = ModuleIDs.size(); I != N; ++I) {
299 if (ModuleFile *MF = Modules[ModuleIDs[I]].File)
303 ++NumIdentifierLookupHits;
307 bool GlobalModuleIndex::loadedModuleFile(ModuleFile *File) {
308 // Look for the module in the global module index based on the module name.
309 StringRef Name = llvm::sys::path::stem(File->FileName);
310 llvm::StringMap<unsigned>::iterator Known = UnresolvedModules.find(Name);
311 if (Known == UnresolvedModules.end()) {
315 // Rectify this module with the global module index.
316 ModuleInfo &Info = Modules[Known->second];
318 // If the size and modification time match what we expected, record this
321 if (File->File->getSize() == Info.Size &&
322 File->File->getModificationTime() == Info.ModTime) {
324 ModulesByFile[File] = Known->second;
329 // One way or another, we have resolved this module file.
330 UnresolvedModules.erase(Known);
334 void GlobalModuleIndex::printStats() {
335 std::fprintf(stderr, "*** Global Module Index Statistics:\n");
336 if (NumIdentifierLookups) {
337 fprintf(stderr, " %u / %u identifier lookups succeeded (%f%%)\n",
338 NumIdentifierLookupHits, NumIdentifierLookups,
339 (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups);
341 std::fprintf(stderr, "\n");
344 //----------------------------------------------------------------------------//
345 // Global module index writer.
346 //----------------------------------------------------------------------------//
349 /// \brief Provides information about a specific module file.
350 struct ModuleFileInfo {
351 /// \brief The numberic ID for this module file.
354 /// \brief The set of modules on which this module depends. Each entry is
356 SmallVector<unsigned, 4> Dependencies;
359 /// \brief Builder that generates the global module index file.
360 class GlobalModuleIndexBuilder {
361 FileManager &FileMgr;
363 /// \brief Mapping from files to module file information.
364 typedef llvm::MapVector<const FileEntry *, ModuleFileInfo> ModuleFilesMap;
366 /// \brief Information about each of the known module files.
367 ModuleFilesMap ModuleFiles;
369 /// \brief Mapping from identifiers to the list of module file IDs that
370 /// consider this identifier to be interesting.
371 typedef llvm::StringMap<SmallVector<unsigned, 2> > InterestingIdentifierMap;
373 /// \brief A mapping from all interesting identifiers to the set of module
374 /// files in which those identifiers are considered interesting.
375 InterestingIdentifierMap InterestingIdentifiers;
377 /// \brief Write the block-info block for the global module index file.
378 void emitBlockInfoBlock(llvm::BitstreamWriter &Stream);
380 /// \brief Retrieve the module file information for the given file.
381 ModuleFileInfo &getModuleFileInfo(const FileEntry *File) {
382 llvm::MapVector<const FileEntry *, ModuleFileInfo>::iterator Known
383 = ModuleFiles.find(File);
384 if (Known != ModuleFiles.end())
385 return Known->second;
387 unsigned NewID = ModuleFiles.size();
388 ModuleFileInfo &Info = ModuleFiles[File];
394 explicit GlobalModuleIndexBuilder(FileManager &FileMgr) : FileMgr(FileMgr){}
396 /// \brief Load the contents of the given module file into the builder.
398 /// \returns true if an error occurred, false otherwise.
399 bool loadModuleFile(const FileEntry *File);
401 /// \brief Write the index to the given bitstream.
402 void writeIndex(llvm::BitstreamWriter &Stream);
406 static void emitBlockID(unsigned ID, const char *Name,
407 llvm::BitstreamWriter &Stream,
408 SmallVectorImpl<uint64_t> &Record) {
410 Record.push_back(ID);
411 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
413 // Emit the block name if present.
414 if (Name == 0 || Name[0] == 0) return;
417 Record.push_back(*Name++);
418 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record);
421 static void emitRecordID(unsigned ID, const char *Name,
422 llvm::BitstreamWriter &Stream,
423 SmallVectorImpl<uint64_t> &Record) {
425 Record.push_back(ID);
427 Record.push_back(*Name++);
428 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
432 GlobalModuleIndexBuilder::emitBlockInfoBlock(llvm::BitstreamWriter &Stream) {
433 SmallVector<uint64_t, 64> Record;
434 Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3);
436 #define BLOCK(X) emitBlockID(X ## _ID, #X, Stream, Record)
437 #define RECORD(X) emitRecordID(X, #X, Stream, Record)
438 BLOCK(GLOBAL_INDEX_BLOCK);
439 RECORD(INDEX_METADATA);
441 RECORD(IDENTIFIER_INDEX);
449 class InterestingASTIdentifierLookupTrait
450 : public serialization::reader::ASTIdentifierLookupTraitBase {
453 /// \brief The identifier and whether it is "interesting".
454 typedef std::pair<StringRef, bool> data_type;
456 data_type ReadData(const internal_key_type& k,
457 const unsigned char* d,
459 // The first bit indicates whether this identifier is interesting.
460 // That's all we care about.
461 using namespace clang::io;
462 unsigned RawID = ReadUnalignedLE32(d);
463 bool IsInteresting = RawID & 0x01;
464 return std::make_pair(k, IsInteresting);
469 bool GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
470 // Open the module file.
471 OwningPtr<llvm::MemoryBuffer> Buffer;
472 std::string ErrorStr;
473 Buffer.reset(FileMgr.getBufferForFile(File, &ErrorStr, /*isVolatile=*/true));
478 // Initialize the input stream
479 llvm::BitstreamReader InStreamFile;
480 llvm::BitstreamCursor InStream;
481 InStreamFile.init((const unsigned char *)Buffer->getBufferStart(),
482 (const unsigned char *)Buffer->getBufferEnd());
483 InStream.init(InStreamFile);
485 // Sniff for the signature.
486 if (InStream.Read(8) != 'C' ||
487 InStream.Read(8) != 'P' ||
488 InStream.Read(8) != 'C' ||
489 InStream.Read(8) != 'H') {
493 // Record this module file and assign it a unique ID (if it doesn't have
495 unsigned ID = getModuleFileInfo(File).ID;
497 // Search for the blocks and records we care about.
498 enum { Other, ControlBlock, ASTBlock } State = Other;
501 llvm::BitstreamEntry Entry = InStream.advance();
502 switch (Entry.Kind) {
503 case llvm::BitstreamEntry::Error:
507 case llvm::BitstreamEntry::Record:
508 // In the 'other' state, just skip the record. We don't care.
509 if (State == Other) {
510 InStream.skipRecord(Entry.ID);
514 // Handle potentially-interesting records below.
517 case llvm::BitstreamEntry::SubBlock:
518 if (Entry.ID == CONTROL_BLOCK_ID) {
519 if (InStream.EnterSubBlock(CONTROL_BLOCK_ID))
522 // Found the control block.
523 State = ControlBlock;
527 if (Entry.ID == AST_BLOCK_ID) {
528 if (InStream.EnterSubBlock(AST_BLOCK_ID))
531 // Found the AST block.
536 if (InStream.SkipBlock())
541 case llvm::BitstreamEntry::EndBlock:
546 // Read the given record.
547 SmallVector<uint64_t, 64> Record;
549 unsigned Code = InStream.readRecord(Entry.ID, Record, &Blob);
551 // Handle module dependencies.
552 if (State == ControlBlock && Code == IMPORTS) {
553 // Load each of the imported PCH files.
554 unsigned Idx = 0, N = Record.size();
556 // Read information about the AST file.
558 // Skip the imported kind
561 // Skip the import location
564 // Load stored size/modification time.
565 off_t StoredSize = (off_t)Record[Idx++];
566 time_t StoredModTime = (time_t)Record[Idx++];
568 // Retrieve the imported file name.
569 unsigned Length = Record[Idx++];
570 SmallString<128> ImportedFile(Record.begin() + Idx,
571 Record.begin() + Idx + Length);
574 // Find the imported module file.
575 const FileEntry *DependsOnFile
576 = FileMgr.getFile(ImportedFile, /*openFile=*/false,
577 /*cacheFailure=*/false);
578 if (!DependsOnFile ||
579 (StoredSize != DependsOnFile->getSize()) ||
580 (StoredModTime != DependsOnFile->getModificationTime()))
583 // Record the dependency.
584 unsigned DependsOnID = getModuleFileInfo(DependsOnFile).ID;
585 getModuleFileInfo(File).Dependencies.push_back(DependsOnID);
591 // Handle the identifier table
592 if (State == ASTBlock && Code == IDENTIFIER_TABLE && Record[0] > 0) {
593 typedef OnDiskChainedHashTable<InterestingASTIdentifierLookupTrait>
594 InterestingIdentifierTable;
595 llvm::OwningPtr<InterestingIdentifierTable>
596 Table(InterestingIdentifierTable::Create(
597 (const unsigned char *)Blob.data() + Record[0],
598 (const unsigned char *)Blob.data()));
599 for (InterestingIdentifierTable::data_iterator D = Table->data_begin(),
600 DEnd = Table->data_end();
602 std::pair<StringRef, bool> Ident = *D;
604 InterestingIdentifiers[Ident.first].push_back(ID);
606 (void)InterestingIdentifiers[Ident.first];
610 // We don't care about this record.
618 /// \brief Trait used to generate the identifier index as an on-disk hash
620 class IdentifierIndexWriterTrait {
622 typedef StringRef key_type;
623 typedef StringRef key_type_ref;
624 typedef SmallVector<unsigned, 2> data_type;
625 typedef const SmallVector<unsigned, 2> &data_type_ref;
627 static unsigned ComputeHash(key_type_ref Key) {
628 return llvm::HashString(Key);
631 std::pair<unsigned,unsigned>
632 EmitKeyDataLength(raw_ostream& Out, key_type_ref Key, data_type_ref Data) {
633 unsigned KeyLen = Key.size();
634 unsigned DataLen = Data.size() * 4;
635 clang::io::Emit16(Out, KeyLen);
636 clang::io::Emit16(Out, DataLen);
637 return std::make_pair(KeyLen, DataLen);
640 void EmitKey(raw_ostream& Out, key_type_ref Key, unsigned KeyLen) {
641 Out.write(Key.data(), KeyLen);
644 void EmitData(raw_ostream& Out, key_type_ref Key, data_type_ref Data,
646 for (unsigned I = 0, N = Data.size(); I != N; ++I)
647 clang::io::Emit32(Out, Data[I]);
653 void GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) {
654 using namespace llvm;
656 // Emit the file header.
657 Stream.Emit((unsigned)'B', 8);
658 Stream.Emit((unsigned)'C', 8);
659 Stream.Emit((unsigned)'G', 8);
660 Stream.Emit((unsigned)'I', 8);
662 // Write the block-info block, which describes the records in this bitcode
664 emitBlockInfoBlock(Stream);
666 Stream.EnterSubblock(GLOBAL_INDEX_BLOCK_ID, 3);
668 // Write the metadata.
669 SmallVector<uint64_t, 2> Record;
670 Record.push_back(CurrentVersion);
671 Stream.EmitRecord(INDEX_METADATA, Record);
673 // Write the set of known module files.
674 for (ModuleFilesMap::iterator M = ModuleFiles.begin(),
675 MEnd = ModuleFiles.end();
678 Record.push_back(M->second.ID);
679 Record.push_back(M->first->getSize());
680 Record.push_back(M->first->getModificationTime());
683 StringRef Name(M->first->getName());
684 Record.push_back(Name.size());
685 Record.append(Name.begin(), Name.end());
688 Record.push_back(M->second.Dependencies.size());
689 Record.append(M->second.Dependencies.begin(), M->second.Dependencies.end());
690 Stream.EmitRecord(MODULE, Record);
693 // Write the identifier -> module file mapping.
695 OnDiskChainedHashTableGenerator<IdentifierIndexWriterTrait> Generator;
696 IdentifierIndexWriterTrait Trait;
698 // Populate the hash table.
699 for (InterestingIdentifierMap::iterator I = InterestingIdentifiers.begin(),
700 IEnd = InterestingIdentifiers.end();
702 Generator.insert(I->first(), I->second, Trait);
705 // Create the on-disk hash table in a buffer.
706 SmallString<4096> IdentifierTable;
707 uint32_t BucketOffset;
709 llvm::raw_svector_ostream Out(IdentifierTable);
710 // Make sure that no bucket is at offset 0
711 clang::io::Emit32(Out, 0);
712 BucketOffset = Generator.Emit(Out, Trait);
715 // Create a blob abbreviation
716 BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
717 Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_INDEX));
718 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
719 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
720 unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev);
722 // Write the identifier table
724 Record.push_back(IDENTIFIER_INDEX);
725 Record.push_back(BucketOffset);
726 Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str());
732 GlobalModuleIndex::ErrorCode
733 GlobalModuleIndex::writeIndex(FileManager &FileMgr, StringRef Path) {
734 llvm::SmallString<128> IndexPath;
736 llvm::sys::path::append(IndexPath, IndexFileName);
738 // Coordinate building the global index file with other processes that might
739 // try to do the same.
740 llvm::LockFileManager Locked(IndexPath);
742 case llvm::LockFileManager::LFS_Error:
745 case llvm::LockFileManager::LFS_Owned:
746 // We're responsible for building the index ourselves. Do so below.
749 case llvm::LockFileManager::LFS_Shared:
750 // Someone else is responsible for building the index. We don't care
751 // when they finish, so we're done.
755 // The module index builder.
756 GlobalModuleIndexBuilder Builder(FileMgr);
758 // Load each of the module files.
760 for (llvm::sys::fs::directory_iterator D(Path, EC), DEnd;
763 // If this isn't a module file, we don't care.
764 if (llvm::sys::path::extension(D->path()) != ".pcm") {
765 // ... unless it's a .pcm.lock file, which indicates that someone is
766 // in the process of rebuilding a module. They'll rebuild the index
767 // at the end of that translation unit, so we don't have to.
768 if (llvm::sys::path::extension(D->path()) == ".pcm.lock")
774 // If we can't find the module file, skip it.
775 const FileEntry *ModuleFile = FileMgr.getFile(D->path());
779 // Load this module file.
780 if (Builder.loadModuleFile(ModuleFile))
784 // The output buffer, into which the global index will be written.
785 SmallVector<char, 16> OutputBuffer;
787 llvm::BitstreamWriter OutputStream(OutputBuffer);
788 Builder.writeIndex(OutputStream);
791 // Write the global index file to a temporary file.
792 llvm::SmallString<128> IndexTmpPath;
794 if (llvm::sys::fs::createUniqueFile(IndexPath + "-%%%%%%%%", TmpFD,
798 // Open the temporary global index file for output.
799 llvm::raw_fd_ostream Out(TmpFD, true);
804 Out.write(OutputBuffer.data(), OutputBuffer.size());
809 // Remove the old index file. It isn't relevant any more.
810 bool OldIndexExisted;
811 llvm::sys::fs::remove(IndexPath.str(), OldIndexExisted);
813 // Rename the newly-written index file to the proper name.
814 if (llvm::sys::fs::rename(IndexTmpPath.str(), IndexPath.str())) {
815 // Rename failed; just remove the
816 llvm::sys::fs::remove(IndexTmpPath.str(), OldIndexExisted);
825 class GlobalIndexIdentifierIterator : public IdentifierIterator {
826 /// \brief The current position within the identifier lookup table.
827 IdentifierIndexTable::key_iterator Current;
829 /// \brief The end position within the identifier lookup table.
830 IdentifierIndexTable::key_iterator End;
833 explicit GlobalIndexIdentifierIterator(IdentifierIndexTable &Idx) {
834 Current = Idx.key_begin();
838 virtual StringRef Next() {
842 StringRef Result = *Current;
849 IdentifierIterator *GlobalModuleIndex::createIdentifierIterator() const {
850 IdentifierIndexTable &Table =
851 *static_cast<IdentifierIndexTable *>(IdentifierIndex);
852 return new GlobalIndexIdentifierIterator(Table);