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/PathV2.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, Buffer) != llvm::errc::success)
233 return std::make_pair((GlobalModuleIndex *)0, EC_NotFound);
235 /// \brief The bitstream reader from which we'll read the AST file.
236 llvm::BitstreamReader Reader((const unsigned char *)Buffer->getBufferStart(),
237 (const unsigned char *)Buffer->getBufferEnd());
239 /// \brief The main bitstream cursor for the main block.
240 llvm::BitstreamCursor Cursor(Reader);
242 // Sniff for the signature.
243 if (Cursor.Read(8) != 'B' ||
244 Cursor.Read(8) != 'C' ||
245 Cursor.Read(8) != 'G' ||
246 Cursor.Read(8) != 'I') {
247 return std::make_pair((GlobalModuleIndex *)0, EC_IOError);
250 return std::make_pair(new GlobalModuleIndex(Buffer.take(), Cursor), EC_None);
254 GlobalModuleIndex::getKnownModules(SmallVectorImpl<ModuleFile *> &ModuleFiles) {
256 for (unsigned I = 0, N = Modules.size(); I != N; ++I) {
257 if (ModuleFile *MF = Modules[I].File)
258 ModuleFiles.push_back(MF);
262 void GlobalModuleIndex::getModuleDependencies(
264 SmallVectorImpl<ModuleFile *> &Dependencies) {
265 // Look for information about this module file.
266 llvm::DenseMap<ModuleFile *, unsigned>::iterator Known
267 = ModulesByFile.find(File);
268 if (Known == ModulesByFile.end())
271 // Record dependencies.
272 Dependencies.clear();
273 ArrayRef<unsigned> StoredDependencies = Modules[Known->second].Dependencies;
274 for (unsigned I = 0, N = StoredDependencies.size(); I != N; ++I) {
275 if (ModuleFile *MF = Modules[I].File)
276 Dependencies.push_back(MF);
280 bool GlobalModuleIndex::lookupIdentifier(StringRef Name, HitSet &Hits) {
283 // If there's no identifier index, there is nothing we can do.
284 if (!IdentifierIndex)
287 // Look into the identifier index.
288 ++NumIdentifierLookups;
289 IdentifierIndexTable &Table
290 = *static_cast<IdentifierIndexTable *>(IdentifierIndex);
291 IdentifierIndexTable::iterator Known = Table.find(Name);
292 if (Known == Table.end()) {
296 SmallVector<unsigned, 2> ModuleIDs = *Known;
297 for (unsigned I = 0, N = ModuleIDs.size(); I != N; ++I) {
298 if (ModuleFile *MF = Modules[ModuleIDs[I]].File)
302 ++NumIdentifierLookupHits;
306 bool GlobalModuleIndex::loadedModuleFile(ModuleFile *File) {
307 // Look for the module in the global module index based on the module name.
308 StringRef Name = llvm::sys::path::stem(File->FileName);
309 llvm::StringMap<unsigned>::iterator Known = UnresolvedModules.find(Name);
310 if (Known == UnresolvedModules.end()) {
314 // Rectify this module with the global module index.
315 ModuleInfo &Info = Modules[Known->second];
317 // If the size and modification time match what we expected, record this
320 if (File->File->getSize() == Info.Size &&
321 File->File->getModificationTime() == Info.ModTime) {
323 ModulesByFile[File] = Known->second;
328 // One way or another, we have resolved this module file.
329 UnresolvedModules.erase(Known);
333 void GlobalModuleIndex::printStats() {
334 std::fprintf(stderr, "*** Global Module Index Statistics:\n");
335 if (NumIdentifierLookups) {
336 fprintf(stderr, " %u / %u identifier lookups succeeded (%f%%)\n",
337 NumIdentifierLookupHits, NumIdentifierLookups,
338 (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups);
340 std::fprintf(stderr, "\n");
343 //----------------------------------------------------------------------------//
344 // Global module index writer.
345 //----------------------------------------------------------------------------//
348 /// \brief Provides information about a specific module file.
349 struct ModuleFileInfo {
350 /// \brief The numberic ID for this module file.
353 /// \brief The set of modules on which this module depends. Each entry is
355 SmallVector<unsigned, 4> Dependencies;
358 /// \brief Builder that generates the global module index file.
359 class GlobalModuleIndexBuilder {
360 FileManager &FileMgr;
362 /// \brief Mapping from files to module file information.
363 typedef llvm::MapVector<const FileEntry *, ModuleFileInfo> ModuleFilesMap;
365 /// \brief Information about each of the known module files.
366 ModuleFilesMap ModuleFiles;
368 /// \brief Mapping from identifiers to the list of module file IDs that
369 /// consider this identifier to be interesting.
370 typedef llvm::StringMap<SmallVector<unsigned, 2> > InterestingIdentifierMap;
372 /// \brief A mapping from all interesting identifiers to the set of module
373 /// files in which those identifiers are considered interesting.
374 InterestingIdentifierMap InterestingIdentifiers;
376 /// \brief Write the block-info block for the global module index file.
377 void emitBlockInfoBlock(llvm::BitstreamWriter &Stream);
379 /// \brief Retrieve the module file information for the given file.
380 ModuleFileInfo &getModuleFileInfo(const FileEntry *File) {
381 llvm::MapVector<const FileEntry *, ModuleFileInfo>::iterator Known
382 = ModuleFiles.find(File);
383 if (Known != ModuleFiles.end())
384 return Known->second;
386 unsigned NewID = ModuleFiles.size();
387 ModuleFileInfo &Info = ModuleFiles[File];
393 explicit GlobalModuleIndexBuilder(FileManager &FileMgr) : FileMgr(FileMgr){}
395 /// \brief Load the contents of the given module file into the builder.
397 /// \returns true if an error occurred, false otherwise.
398 bool loadModuleFile(const FileEntry *File);
400 /// \brief Write the index to the given bitstream.
401 void writeIndex(llvm::BitstreamWriter &Stream);
405 static void emitBlockID(unsigned ID, const char *Name,
406 llvm::BitstreamWriter &Stream,
407 SmallVectorImpl<uint64_t> &Record) {
409 Record.push_back(ID);
410 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
412 // Emit the block name if present.
413 if (Name == 0 || Name[0] == 0) return;
416 Record.push_back(*Name++);
417 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record);
420 static void emitRecordID(unsigned ID, const char *Name,
421 llvm::BitstreamWriter &Stream,
422 SmallVectorImpl<uint64_t> &Record) {
424 Record.push_back(ID);
426 Record.push_back(*Name++);
427 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
431 GlobalModuleIndexBuilder::emitBlockInfoBlock(llvm::BitstreamWriter &Stream) {
432 SmallVector<uint64_t, 64> Record;
433 Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3);
435 #define BLOCK(X) emitBlockID(X ## _ID, #X, Stream, Record)
436 #define RECORD(X) emitRecordID(X, #X, Stream, Record)
437 BLOCK(GLOBAL_INDEX_BLOCK);
438 RECORD(INDEX_METADATA);
440 RECORD(IDENTIFIER_INDEX);
448 class InterestingASTIdentifierLookupTrait
449 : public serialization::reader::ASTIdentifierLookupTraitBase {
452 /// \brief The identifier and whether it is "interesting".
453 typedef std::pair<StringRef, bool> data_type;
455 data_type ReadData(const internal_key_type& k,
456 const unsigned char* d,
458 // The first bit indicates whether this identifier is interesting.
459 // That's all we care about.
460 using namespace clang::io;
461 unsigned RawID = ReadUnalignedLE32(d);
462 bool IsInteresting = RawID & 0x01;
463 return std::make_pair(k, IsInteresting);
468 bool GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
469 // Open the module file.
470 OwningPtr<llvm::MemoryBuffer> Buffer;
471 std::string ErrorStr;
472 Buffer.reset(FileMgr.getBufferForFile(File, &ErrorStr, /*isVolatile=*/true));
477 // Initialize the input stream
478 llvm::BitstreamReader InStreamFile;
479 llvm::BitstreamCursor InStream;
480 InStreamFile.init((const unsigned char *)Buffer->getBufferStart(),
481 (const unsigned char *)Buffer->getBufferEnd());
482 InStream.init(InStreamFile);
484 // Sniff for the signature.
485 if (InStream.Read(8) != 'C' ||
486 InStream.Read(8) != 'P' ||
487 InStream.Read(8) != 'C' ||
488 InStream.Read(8) != 'H') {
492 // Record this module file and assign it a unique ID (if it doesn't have
494 unsigned ID = getModuleFileInfo(File).ID;
496 // Search for the blocks and records we care about.
497 enum { Other, ControlBlock, ASTBlock } State = Other;
500 llvm::BitstreamEntry Entry = InStream.advance();
501 switch (Entry.Kind) {
502 case llvm::BitstreamEntry::Error:
506 case llvm::BitstreamEntry::Record:
507 // In the 'other' state, just skip the record. We don't care.
508 if (State == Other) {
509 InStream.skipRecord(Entry.ID);
513 // Handle potentially-interesting records below.
516 case llvm::BitstreamEntry::SubBlock:
517 if (Entry.ID == CONTROL_BLOCK_ID) {
518 if (InStream.EnterSubBlock(CONTROL_BLOCK_ID))
521 // Found the control block.
522 State = ControlBlock;
526 if (Entry.ID == AST_BLOCK_ID) {
527 if (InStream.EnterSubBlock(AST_BLOCK_ID))
530 // Found the AST block.
535 if (InStream.SkipBlock())
540 case llvm::BitstreamEntry::EndBlock:
545 // Read the given record.
546 SmallVector<uint64_t, 64> Record;
548 unsigned Code = InStream.readRecord(Entry.ID, Record, &Blob);
550 // Handle module dependencies.
551 if (State == ControlBlock && Code == IMPORTS) {
552 // Load each of the imported PCH files.
553 unsigned Idx = 0, N = Record.size();
555 // Read information about the AST file.
557 // Skip the imported kind
560 // Skip the import location
563 // Load stored size/modification time.
564 off_t StoredSize = (off_t)Record[Idx++];
565 time_t StoredModTime = (time_t)Record[Idx++];
567 // Retrieve the imported file name.
568 unsigned Length = Record[Idx++];
569 SmallString<128> ImportedFile(Record.begin() + Idx,
570 Record.begin() + Idx + Length);
573 // Find the imported module file.
574 const FileEntry *DependsOnFile
575 = FileMgr.getFile(ImportedFile, /*openFile=*/false,
576 /*cacheFailure=*/false);
577 if (!DependsOnFile ||
578 (StoredSize != DependsOnFile->getSize()) ||
579 (StoredModTime != DependsOnFile->getModificationTime()))
582 // Record the dependency.
583 unsigned DependsOnID = getModuleFileInfo(DependsOnFile).ID;
584 getModuleFileInfo(File).Dependencies.push_back(DependsOnID);
590 // Handle the identifier table
591 if (State == ASTBlock && Code == IDENTIFIER_TABLE && Record[0] > 0) {
592 typedef OnDiskChainedHashTable<InterestingASTIdentifierLookupTrait>
593 InterestingIdentifierTable;
594 llvm::OwningPtr<InterestingIdentifierTable>
595 Table(InterestingIdentifierTable::Create(
596 (const unsigned char *)Blob.data() + Record[0],
597 (const unsigned char *)Blob.data()));
598 for (InterestingIdentifierTable::data_iterator D = Table->data_begin(),
599 DEnd = Table->data_end();
601 std::pair<StringRef, bool> Ident = *D;
603 InterestingIdentifiers[Ident.first].push_back(ID);
605 (void)InterestingIdentifiers[Ident.first];
609 // We don't care about this record.
617 /// \brief Trait used to generate the identifier index as an on-disk hash
619 class IdentifierIndexWriterTrait {
621 typedef StringRef key_type;
622 typedef StringRef key_type_ref;
623 typedef SmallVector<unsigned, 2> data_type;
624 typedef const SmallVector<unsigned, 2> &data_type_ref;
626 static unsigned ComputeHash(key_type_ref Key) {
627 return llvm::HashString(Key);
630 std::pair<unsigned,unsigned>
631 EmitKeyDataLength(raw_ostream& Out, key_type_ref Key, data_type_ref Data) {
632 unsigned KeyLen = Key.size();
633 unsigned DataLen = Data.size() * 4;
634 clang::io::Emit16(Out, KeyLen);
635 clang::io::Emit16(Out, DataLen);
636 return std::make_pair(KeyLen, DataLen);
639 void EmitKey(raw_ostream& Out, key_type_ref Key, unsigned KeyLen) {
640 Out.write(Key.data(), KeyLen);
643 void EmitData(raw_ostream& Out, key_type_ref Key, data_type_ref Data,
645 for (unsigned I = 0, N = Data.size(); I != N; ++I)
646 clang::io::Emit32(Out, Data[I]);
652 void GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) {
653 using namespace llvm;
655 // Emit the file header.
656 Stream.Emit((unsigned)'B', 8);
657 Stream.Emit((unsigned)'C', 8);
658 Stream.Emit((unsigned)'G', 8);
659 Stream.Emit((unsigned)'I', 8);
661 // Write the block-info block, which describes the records in this bitcode
663 emitBlockInfoBlock(Stream);
665 Stream.EnterSubblock(GLOBAL_INDEX_BLOCK_ID, 3);
667 // Write the metadata.
668 SmallVector<uint64_t, 2> Record;
669 Record.push_back(CurrentVersion);
670 Stream.EmitRecord(INDEX_METADATA, Record);
672 // Write the set of known module files.
673 for (ModuleFilesMap::iterator M = ModuleFiles.begin(),
674 MEnd = ModuleFiles.end();
677 Record.push_back(M->second.ID);
678 Record.push_back(M->first->getSize());
679 Record.push_back(M->first->getModificationTime());
682 StringRef Name(M->first->getName());
683 Record.push_back(Name.size());
684 Record.append(Name.begin(), Name.end());
687 Record.push_back(M->second.Dependencies.size());
688 Record.append(M->second.Dependencies.begin(), M->second.Dependencies.end());
689 Stream.EmitRecord(MODULE, Record);
692 // Write the identifier -> module file mapping.
694 OnDiskChainedHashTableGenerator<IdentifierIndexWriterTrait> Generator;
695 IdentifierIndexWriterTrait Trait;
697 // Populate the hash table.
698 for (InterestingIdentifierMap::iterator I = InterestingIdentifiers.begin(),
699 IEnd = InterestingIdentifiers.end();
701 Generator.insert(I->first(), I->second, Trait);
704 // Create the on-disk hash table in a buffer.
705 SmallString<4096> IdentifierTable;
706 uint32_t BucketOffset;
708 llvm::raw_svector_ostream Out(IdentifierTable);
709 // Make sure that no bucket is at offset 0
710 clang::io::Emit32(Out, 0);
711 BucketOffset = Generator.Emit(Out, Trait);
714 // Create a blob abbreviation
715 BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
716 Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_INDEX));
717 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
718 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
719 unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev);
721 // Write the identifier table
723 Record.push_back(IDENTIFIER_INDEX);
724 Record.push_back(BucketOffset);
725 Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str());
731 GlobalModuleIndex::ErrorCode
732 GlobalModuleIndex::writeIndex(FileManager &FileMgr, StringRef Path) {
733 llvm::SmallString<128> IndexPath;
735 llvm::sys::path::append(IndexPath, IndexFileName);
737 // Coordinate building the global index file with other processes that might
738 // try to do the same.
739 llvm::LockFileManager Locked(IndexPath);
741 case llvm::LockFileManager::LFS_Error:
744 case llvm::LockFileManager::LFS_Owned:
745 // We're responsible for building the index ourselves. Do so below.
748 case llvm::LockFileManager::LFS_Shared:
749 // Someone else is responsible for building the index. We don't care
750 // when they finish, so we're done.
754 // The module index builder.
755 GlobalModuleIndexBuilder Builder(FileMgr);
757 // Load each of the module files.
759 for (llvm::sys::fs::directory_iterator D(Path, EC), DEnd;
762 // If this isn't a module file, we don't care.
763 if (llvm::sys::path::extension(D->path()) != ".pcm") {
764 // ... unless it's a .pcm.lock file, which indicates that someone is
765 // in the process of rebuilding a module. They'll rebuild the index
766 // at the end of that translation unit, so we don't have to.
767 if (llvm::sys::path::extension(D->path()) == ".pcm.lock")
773 // If we can't find the module file, skip it.
774 const FileEntry *ModuleFile = FileMgr.getFile(D->path());
778 // Load this module file.
779 if (Builder.loadModuleFile(ModuleFile))
783 // The output buffer, into which the global index will be written.
784 SmallVector<char, 16> OutputBuffer;
786 llvm::BitstreamWriter OutputStream(OutputBuffer);
787 Builder.writeIndex(OutputStream);
790 // Write the global index file to a temporary file.
791 llvm::SmallString<128> IndexTmpPath;
793 if (llvm::sys::fs::unique_file(IndexPath + "-%%%%%%%%", TmpFD, IndexTmpPath))
796 // Open the temporary global index file for output.
797 llvm::raw_fd_ostream Out(TmpFD, true);
802 Out.write(OutputBuffer.data(), OutputBuffer.size());
807 // Remove the old index file. It isn't relevant any more.
808 bool OldIndexExisted;
809 llvm::sys::fs::remove(IndexPath.str(), OldIndexExisted);
811 // Rename the newly-written index file to the proper name.
812 if (llvm::sys::fs::rename(IndexTmpPath.str(), IndexPath.str())) {
813 // Rename failed; just remove the
814 llvm::sys::fs::remove(IndexTmpPath.str(), OldIndexExisted);
823 class GlobalIndexIdentifierIterator : public IdentifierIterator {
824 /// \brief The current position within the identifier lookup table.
825 IdentifierIndexTable::key_iterator Current;
827 /// \brief The end position within the identifier lookup table.
828 IdentifierIndexTable::key_iterator End;
831 explicit GlobalIndexIdentifierIterator(IdentifierIndexTable &Idx) {
832 Current = Idx.key_begin();
836 virtual StringRef Next() {
840 StringRef Result = *Current;
847 IdentifierIterator *GlobalModuleIndex::createIdentifierIterator() const {
848 IdentifierIndexTable &Table =
849 *static_cast<IdentifierIndexTable *>(IdentifierIndex);
850 return new GlobalIndexIdentifierIterator(Table);