1 //===--- PTHLexer.cpp - Lex from a token stream ---------------------------===//
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 PTHLexer interface.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Lex/PTHLexer.h"
15 #include "clang/Basic/FileManager.h"
16 #include "clang/Basic/FileSystemStatCache.h"
17 #include "clang/Basic/IdentifierTable.h"
18 #include "clang/Basic/TokenKinds.h"
19 #include "clang/Lex/LexDiagnostic.h"
20 #include "clang/Lex/PTHManager.h"
21 #include "clang/Lex/Preprocessor.h"
22 #include "clang/Lex/Token.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/Support/EndianStream.h"
25 #include "llvm/Support/MemoryBuffer.h"
27 #include <system_error>
28 using namespace clang;
30 static const unsigned StoredTokenSize = 1 + 1 + 2 + 4 + 4;
32 //===----------------------------------------------------------------------===//
34 //===----------------------------------------------------------------------===//
36 PTHLexer::PTHLexer(Preprocessor &PP, FileID FID, const unsigned char *D,
37 const unsigned char *ppcond, PTHManager &PM)
38 : PreprocessorLexer(&PP, FID), TokBuf(D), CurPtr(D), LastHashTokPtr(nullptr),
39 PPCond(ppcond), CurPPCondPtr(ppcond), PTHMgr(PM) {
41 FileStartLoc = PP.getSourceManager().getLocForStartOfFile(FID);
44 bool PTHLexer::Lex(Token& Tok) {
45 //===--------------------------------------==//
46 // Read the raw token data.
47 //===--------------------------------------==//
48 using namespace llvm::support;
50 // Shadow CurPtr into an automatic variable.
51 const unsigned char *CurPtrShadow = CurPtr;
53 // Read in the data for the token.
54 unsigned Word0 = endian::readNext<uint32_t, little, aligned>(CurPtrShadow);
55 uint32_t IdentifierID =
56 endian::readNext<uint32_t, little, aligned>(CurPtrShadow);
58 endian::readNext<uint32_t, little, aligned>(CurPtrShadow);
60 tok::TokenKind TKind = (tok::TokenKind) (Word0 & 0xFF);
61 Token::TokenFlags TFlags = (Token::TokenFlags) ((Word0 >> 8) & 0xFF);
62 uint32_t Len = Word0 >> 16;
64 CurPtr = CurPtrShadow;
66 //===--------------------------------------==//
67 // Construct the token itself.
68 //===--------------------------------------==//
73 assert(!LexingRawMode);
74 Tok.setLocation(FileStartLoc.getLocWithOffset(FileOffset));
77 // Handle identifiers.
78 if (Tok.isLiteral()) {
79 Tok.setLiteralData((const char*) (PTHMgr.SpellingBase + IdentifierID));
81 else if (IdentifierID) {
83 IdentifierInfo *II = PTHMgr.GetIdentifierInfo(IdentifierID-1);
85 Tok.setIdentifierInfo(II);
87 // Change the kind of this identifier to the appropriate token kind, e.g.
88 // turning "for" into a keyword.
89 Tok.setKind(II->getTokenID());
91 if (II->isHandleIdentifierCase())
92 return PP->HandleIdentifier(Tok);
97 //===--------------------------------------==//
99 //===--------------------------------------==//
100 if (TKind == tok::eof) {
101 // Save the end-of-file token.
104 assert(!ParsingPreprocessorDirective);
105 assert(!LexingRawMode);
107 return LexEndOfFile(Tok);
110 if (TKind == tok::hash && Tok.isAtStartOfLine()) {
111 LastHashTokPtr = CurPtr - StoredTokenSize;
112 assert(!LexingRawMode);
113 PP->HandleDirective(Tok);
118 if (TKind == tok::eod) {
119 assert(ParsingPreprocessorDirective);
120 ParsingPreprocessorDirective = false;
128 bool PTHLexer::LexEndOfFile(Token &Result) {
129 // If we hit the end of the file while parsing a preprocessor directive,
130 // end the preprocessor directive first. The next token returned will
131 // then be the end of file.
132 if (ParsingPreprocessorDirective) {
133 ParsingPreprocessorDirective = false; // Done parsing the "line".
134 return true; // Have a token.
137 assert(!LexingRawMode);
139 // If we are in a #if directive, emit an error.
140 while (!ConditionalStack.empty()) {
141 if (PP->getCodeCompletionFileLoc() != FileStartLoc)
142 PP->Diag(ConditionalStack.back().IfLoc,
143 diag::err_pp_unterminated_conditional);
144 ConditionalStack.pop_back();
147 // Finally, let the preprocessor handle this.
148 return PP->HandleEndOfFile(Result);
151 // FIXME: We can just grab the last token instead of storing a copy
153 void PTHLexer::getEOF(Token& Tok) {
154 assert(EofToken.is(tok::eof));
158 void PTHLexer::DiscardToEndOfLine() {
159 assert(ParsingPreprocessorDirective && ParsingFilename == false &&
160 "Must be in a preprocessing directive!");
162 // We assume that if the preprocessor wishes to discard to the end of
163 // the line that it also means to end the current preprocessor directive.
164 ParsingPreprocessorDirective = false;
166 // Skip tokens by only peeking at their token kind and the flags.
167 // We don't need to actually reconstruct full tokens from the token buffer.
168 // This saves some copies and it also reduces IdentifierInfo* lookup.
169 const unsigned char* p = CurPtr;
171 // Read the token kind. Are we at the end of the file?
172 tok::TokenKind x = (tok::TokenKind) (uint8_t) *p;
173 if (x == tok::eof) break;
175 // Read the token flags. Are we at the start of the next line?
176 Token::TokenFlags y = (Token::TokenFlags) (uint8_t) p[1];
177 if (y & Token::StartOfLine) break;
179 // Skip to the next token.
180 p += StoredTokenSize;
186 /// SkipBlock - Used by Preprocessor to skip the current conditional block.
187 bool PTHLexer::SkipBlock() {
188 using namespace llvm::support;
189 assert(CurPPCondPtr && "No cached PP conditional information.");
190 assert(LastHashTokPtr && "No known '#' token.");
192 const unsigned char *HashEntryI = nullptr;
196 // Read the token offset from the side-table.
197 uint32_t Offset = endian::readNext<uint32_t, little, aligned>(CurPPCondPtr);
199 // Read the target table index from the side-table.
200 TableIdx = endian::readNext<uint32_t, little, aligned>(CurPPCondPtr);
202 // Compute the actual memory address of the '#' token data for this entry.
203 HashEntryI = TokBuf + Offset;
205 // Optmization: "Sibling jumping". #if...#else...#endif blocks can
206 // contain nested blocks. In the side-table we can jump over these
207 // nested blocks instead of doing a linear search if the next "sibling"
208 // entry is not at a location greater than LastHashTokPtr.
209 if (HashEntryI < LastHashTokPtr && TableIdx) {
210 // In the side-table we are still at an entry for a '#' token that
211 // is earlier than the last one we saw. Check if the location we would
212 // stride gets us closer.
213 const unsigned char* NextPPCondPtr =
214 PPCond + TableIdx*(sizeof(uint32_t)*2);
215 assert(NextPPCondPtr >= CurPPCondPtr);
216 // Read where we should jump to.
217 const unsigned char *HashEntryJ =
218 TokBuf + endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
220 if (HashEntryJ <= LastHashTokPtr) {
221 // Jump directly to the next entry in the side table.
222 HashEntryI = HashEntryJ;
223 TableIdx = endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
224 CurPPCondPtr = NextPPCondPtr;
228 while (HashEntryI < LastHashTokPtr);
229 assert(HashEntryI == LastHashTokPtr && "No PP-cond entry found for '#'");
230 assert(TableIdx && "No jumping from #endifs.");
232 // Update our side-table iterator.
233 const unsigned char* NextPPCondPtr = PPCond + TableIdx*(sizeof(uint32_t)*2);
234 assert(NextPPCondPtr >= CurPPCondPtr);
235 CurPPCondPtr = NextPPCondPtr;
237 // Read where we should jump to.
239 TokBuf + endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
240 uint32_t NextIdx = endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
242 // By construction NextIdx will be zero if this is a #endif. This is useful
243 // to know to obviate lexing another token.
244 bool isEndif = NextIdx == 0;
246 // This case can occur when we see something like this:
249 // /* a comment or nothing */
252 // If we are skipping the first #if block it will be the case that CurPtr
253 // already points 'elif'. Just return.
255 if (CurPtr > HashEntryI) {
256 assert(CurPtr == HashEntryI + StoredTokenSize);
257 // Did we reach a #endif? If so, go ahead and consume that token as well.
259 CurPtr += StoredTokenSize * 2;
261 LastHashTokPtr = HashEntryI;
266 // Otherwise, we need to advance. Update CurPtr to point to the '#' token.
269 // Update the location of the last observed '#'. This is useful if we
270 // are skipping multiple blocks.
271 LastHashTokPtr = CurPtr;
273 // Skip the '#' token.
274 assert(((tok::TokenKind)*CurPtr) == tok::hash);
275 CurPtr += StoredTokenSize;
277 // Did we reach a #endif? If so, go ahead and consume that token as well.
279 CurPtr += StoredTokenSize * 2;
285 SourceLocation PTHLexer::getSourceLocation() {
286 // getSourceLocation is not on the hot path. It is used to get the location
287 // of the next token when transitioning back to this lexer when done
288 // handling a #included file. Just read the necessary data from the token
289 // data buffer to construct the SourceLocation object.
290 // NOTE: This is a virtual function; hence it is defined out-of-line.
291 using namespace llvm::support;
293 const unsigned char *OffsetPtr = CurPtr + (StoredTokenSize - 4);
294 uint32_t Offset = endian::readNext<uint32_t, little, aligned>(OffsetPtr);
295 return FileStartLoc.getLocWithOffset(Offset);
298 //===----------------------------------------------------------------------===//
299 // PTH file lookup: map from strings to file data.
300 //===----------------------------------------------------------------------===//
302 /// PTHFileLookup - This internal data structure is used by the PTHManager
303 /// to map from FileEntry objects managed by FileManager to offsets within
307 const uint32_t TokenOff;
308 const uint32_t PPCondOff;
310 PTHFileData(uint32_t tokenOff, uint32_t ppCondOff)
311 : TokenOff(tokenOff), PPCondOff(ppCondOff) {}
313 uint32_t getTokenOffset() const { return TokenOff; }
314 uint32_t getPPCondOffset() const { return PPCondOff; }
318 class PTHFileLookupCommonTrait {
320 typedef std::pair<unsigned char, StringRef> internal_key_type;
321 typedef unsigned hash_value_type;
322 typedef unsigned offset_type;
324 static hash_value_type ComputeHash(internal_key_type x) {
325 return llvm::HashString(x.second);
328 static std::pair<unsigned, unsigned>
329 ReadKeyDataLength(const unsigned char*& d) {
330 using namespace llvm::support;
332 (unsigned)endian::readNext<uint16_t, little, unaligned>(d);
333 unsigned dataLen = (unsigned) *(d++);
334 return std::make_pair(keyLen, dataLen);
337 static internal_key_type ReadKey(const unsigned char* d, unsigned) {
338 unsigned char k = *(d++); // Read the entry kind.
339 return std::make_pair(k, (const char*) d);
343 } // end anonymous namespace
345 class PTHManager::PTHFileLookupTrait : public PTHFileLookupCommonTrait {
347 typedef const FileEntry* external_key_type;
348 typedef PTHFileData data_type;
350 static internal_key_type GetInternalKey(const FileEntry* FE) {
351 return std::make_pair((unsigned char) 0x1, FE->getName());
354 static bool EqualKey(internal_key_type a, internal_key_type b) {
355 return a.first == b.first && a.second == b.second;
358 static PTHFileData ReadData(const internal_key_type& k,
359 const unsigned char* d, unsigned) {
360 assert(k.first == 0x1 && "Only file lookups can match!");
361 using namespace llvm::support;
362 uint32_t x = endian::readNext<uint32_t, little, unaligned>(d);
363 uint32_t y = endian::readNext<uint32_t, little, unaligned>(d);
364 return PTHFileData(x, y);
368 class PTHManager::PTHStringLookupTrait {
370 typedef uint32_t data_type;
371 typedef const std::pair<const char*, unsigned> external_key_type;
372 typedef external_key_type internal_key_type;
373 typedef uint32_t hash_value_type;
374 typedef unsigned offset_type;
376 static bool EqualKey(const internal_key_type& a,
377 const internal_key_type& b) {
378 return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0
382 static hash_value_type ComputeHash(const internal_key_type& a) {
383 return llvm::HashString(StringRef(a.first, a.second));
386 // This hopefully will just get inlined and removed by the optimizer.
387 static const internal_key_type&
388 GetInternalKey(const external_key_type& x) { return x; }
390 static std::pair<unsigned, unsigned>
391 ReadKeyDataLength(const unsigned char*& d) {
392 using namespace llvm::support;
393 return std::make_pair(
394 (unsigned)endian::readNext<uint16_t, little, unaligned>(d),
398 static std::pair<const char*, unsigned>
399 ReadKey(const unsigned char* d, unsigned n) {
400 assert(n >= 2 && d[n-1] == '\0');
401 return std::make_pair((const char*) d, n-1);
404 static uint32_t ReadData(const internal_key_type& k, const unsigned char* d,
406 using namespace llvm::support;
407 return endian::readNext<uint32_t, little, unaligned>(d);
411 //===----------------------------------------------------------------------===//
412 // PTHManager methods.
413 //===----------------------------------------------------------------------===//
415 PTHManager::PTHManager(
416 std::unique_ptr<const llvm::MemoryBuffer> buf,
417 std::unique_ptr<PTHFileLookup> fileLookup, const unsigned char *idDataTable,
418 std::unique_ptr<IdentifierInfo *[], llvm::FreeDeleter> perIDCache,
419 std::unique_ptr<PTHStringIdLookup> stringIdLookup, unsigned numIds,
420 const unsigned char *spellingBase, const char *originalSourceFile)
421 : Buf(std::move(buf)), PerIDCache(std::move(perIDCache)),
422 FileLookup(std::move(fileLookup)), IdDataTable(idDataTable),
423 StringIdLookup(std::move(stringIdLookup)), NumIds(numIds), PP(nullptr),
424 SpellingBase(spellingBase), OriginalSourceFile(originalSourceFile) {}
426 PTHManager::~PTHManager() {
429 static void InvalidPTH(DiagnosticsEngine &Diags, const char *Msg) {
430 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0")) << Msg;
433 PTHManager *PTHManager::Create(StringRef file, DiagnosticsEngine &Diags) {
434 // Memory map the PTH file.
435 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileOrErr =
436 llvm::MemoryBuffer::getFile(file);
439 // FIXME: Add ec.message() to this diag.
440 Diags.Report(diag::err_invalid_pth_file) << file;
443 std::unique_ptr<llvm::MemoryBuffer> File = std::move(FileOrErr.get());
445 using namespace llvm::support;
447 // Get the buffer ranges and check if there are at least three 32-bit
448 // words at the end of the file.
449 const unsigned char *BufBeg = (const unsigned char*)File->getBufferStart();
450 const unsigned char *BufEnd = (const unsigned char*)File->getBufferEnd();
452 // Check the prologue of the file.
453 if ((BufEnd - BufBeg) < (signed)(sizeof("cfe-pth") + 4 + 4) ||
454 memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth")) != 0) {
455 Diags.Report(diag::err_invalid_pth_file) << file;
459 // Read the PTH version.
460 const unsigned char *p = BufBeg + (sizeof("cfe-pth"));
461 unsigned Version = endian::readNext<uint32_t, little, aligned>(p);
463 if (Version < PTHManager::Version) {
465 Version < PTHManager::Version
466 ? "PTH file uses an older PTH format that is no longer supported"
467 : "PTH file uses a newer PTH format that cannot be read");
471 // Compute the address of the index table at the end of the PTH file.
472 const unsigned char *PrologueOffset = p;
474 if (PrologueOffset >= BufEnd) {
475 Diags.Report(diag::err_invalid_pth_file) << file;
479 // Construct the file lookup table. This will be used for mapping from
480 // FileEntry*'s to cached tokens.
481 const unsigned char* FileTableOffset = PrologueOffset + sizeof(uint32_t)*2;
482 const unsigned char *FileTable =
483 BufBeg + endian::readNext<uint32_t, little, aligned>(FileTableOffset);
485 if (!(FileTable > BufBeg && FileTable < BufEnd)) {
486 Diags.Report(diag::err_invalid_pth_file) << file;
487 return nullptr; // FIXME: Proper error diagnostic?
490 std::unique_ptr<PTHFileLookup> FL(PTHFileLookup::Create(FileTable, BufBeg));
492 // Warn if the PTH file is empty. We still want to create a PTHManager
493 // as the PTH could be used with -include-pth.
495 InvalidPTH(Diags, "PTH file contains no cached source data");
497 // Get the location of the table mapping from persistent ids to the
498 // data needed to reconstruct identifiers.
499 const unsigned char* IDTableOffset = PrologueOffset + sizeof(uint32_t)*0;
500 const unsigned char *IData =
501 BufBeg + endian::readNext<uint32_t, little, aligned>(IDTableOffset);
503 if (!(IData >= BufBeg && IData < BufEnd)) {
504 Diags.Report(diag::err_invalid_pth_file) << file;
508 // Get the location of the hashtable mapping between strings and
510 const unsigned char* StringIdTableOffset = PrologueOffset + sizeof(uint32_t)*1;
511 const unsigned char *StringIdTable =
512 BufBeg + endian::readNext<uint32_t, little, aligned>(StringIdTableOffset);
513 if (!(StringIdTable >= BufBeg && StringIdTable < BufEnd)) {
514 Diags.Report(diag::err_invalid_pth_file) << file;
518 std::unique_ptr<PTHStringIdLookup> SL(
519 PTHStringIdLookup::Create(StringIdTable, BufBeg));
521 // Get the location of the spelling cache.
522 const unsigned char* spellingBaseOffset = PrologueOffset + sizeof(uint32_t)*3;
523 const unsigned char *spellingBase =
524 BufBeg + endian::readNext<uint32_t, little, aligned>(spellingBaseOffset);
525 if (!(spellingBase >= BufBeg && spellingBase < BufEnd)) {
526 Diags.Report(diag::err_invalid_pth_file) << file;
530 // Get the number of IdentifierInfos and pre-allocate the identifier cache.
531 uint32_t NumIds = endian::readNext<uint32_t, little, aligned>(IData);
533 // Pre-allocate the persistent ID -> IdentifierInfo* cache. We use calloc()
534 // so that we in the best case only zero out memory once when the OS returns
536 std::unique_ptr<IdentifierInfo *[], llvm::FreeDeleter> PerIDCache;
539 PerIDCache.reset((IdentifierInfo **)calloc(NumIds, sizeof(PerIDCache[0])));
541 InvalidPTH(Diags, "Could not allocate memory for processing PTH file");
546 // Compute the address of the original source file.
547 const unsigned char* originalSourceBase = PrologueOffset + sizeof(uint32_t)*4;
549 endian::readNext<uint16_t, little, unaligned>(originalSourceBase);
550 if (!len) originalSourceBase = nullptr;
552 // Create the new PTHManager.
553 return new PTHManager(std::move(File), std::move(FL), IData,
554 std::move(PerIDCache), std::move(SL), NumIds,
555 spellingBase, (const char *)originalSourceBase);
558 IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) {
559 using namespace llvm::support;
560 // Look in the PTH file for the string data for the IdentifierInfo object.
561 const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*PersistentID;
562 const unsigned char *IDData =
563 (const unsigned char *)Buf->getBufferStart() +
564 endian::readNext<uint32_t, little, aligned>(TableEntry);
565 assert(IDData < (const unsigned char*)Buf->getBufferEnd());
567 // Allocate the object.
568 std::pair<IdentifierInfo,const unsigned char*> *Mem =
569 Alloc.Allocate<std::pair<IdentifierInfo,const unsigned char*> >();
571 Mem->second = IDData;
572 assert(IDData[0] != '\0');
573 IdentifierInfo *II = new ((void*) Mem) IdentifierInfo();
575 // Store the new IdentifierInfo in the cache.
576 PerIDCache[PersistentID] = II;
577 assert(II->getNameStart() && II->getNameStart()[0] != '\0');
581 IdentifierInfo* PTHManager::get(StringRef Name) {
582 // Double check our assumption that the last character isn't '\0'.
583 assert(Name.empty() || Name.back() != '\0');
584 PTHStringIdLookup::iterator I =
585 StringIdLookup->find(std::make_pair(Name.data(), Name.size()));
586 if (I == StringIdLookup->end()) // No identifier found?
589 // Match found. Return the identifier!
591 return GetIdentifierInfo(*I-1);
594 PTHLexer *PTHManager::CreateLexer(FileID FID) {
595 const FileEntry *FE = PP->getSourceManager().getFileEntryForID(FID);
599 using namespace llvm::support;
601 // Lookup the FileEntry object in our file lookup data structure. It will
602 // return a variant that indicates whether or not there is an offset within
603 // the PTH file that contains cached tokens.
604 PTHFileLookup::iterator I = FileLookup->find(FE);
606 if (I == FileLookup->end()) // No tokens available?
609 const PTHFileData& FileData = *I;
611 const unsigned char *BufStart = (const unsigned char *)Buf->getBufferStart();
612 // Compute the offset of the token data within the buffer.
613 const unsigned char* data = BufStart + FileData.getTokenOffset();
615 // Get the location of pp-conditional table.
616 const unsigned char* ppcond = BufStart + FileData.getPPCondOffset();
617 uint32_t Len = endian::readNext<uint32_t, little, aligned>(ppcond);
618 if (Len == 0) ppcond = nullptr;
620 assert(PP && "No preprocessor set yet!");
621 return new PTHLexer(*PP, FID, data, ppcond, *this);
624 //===----------------------------------------------------------------------===//
626 //===----------------------------------------------------------------------===//
633 llvm::sys::fs::UniqueID UniqueID;
637 PTHStatData(uint64_t Size, time_t ModTime, llvm::sys::fs::UniqueID UniqueID,
639 : Size(Size), ModTime(ModTime), UniqueID(UniqueID), HasData(true),
640 IsDirectory(IsDirectory) {}
642 PTHStatData() : HasData(false) {}
645 class PTHStatLookupTrait : public PTHFileLookupCommonTrait {
647 typedef StringRef external_key_type; // const char*
648 typedef PTHStatData data_type;
650 static internal_key_type GetInternalKey(StringRef path) {
651 // The key 'kind' doesn't matter here because it is ignored in EqualKey.
652 return std::make_pair((unsigned char) 0x0, path);
655 static bool EqualKey(internal_key_type a, internal_key_type b) {
656 // When doing 'stat' lookups we don't care about the kind of 'a' and 'b',
658 return a.second == b.second;
661 static data_type ReadData(const internal_key_type& k, const unsigned char* d,
664 if (k.first /* File or Directory */) {
665 bool IsDirectory = true;
666 if (k.first == 0x1 /* File */) {
668 d += 4 * 2; // Skip the first 2 words.
671 using namespace llvm::support;
673 uint64_t File = endian::readNext<uint64_t, little, unaligned>(d);
674 uint64_t Device = endian::readNext<uint64_t, little, unaligned>(d);
675 llvm::sys::fs::UniqueID UniqueID(Device, File);
676 time_t ModTime = endian::readNext<uint64_t, little, unaligned>(d);
677 uint64_t Size = endian::readNext<uint64_t, little, unaligned>(d);
678 return data_type(Size, ModTime, UniqueID, IsDirectory);
681 // Negative stat. Don't read anything.
685 } // end anonymous namespace
688 class PTHStatCache : public FileSystemStatCache {
689 typedef llvm::OnDiskChainedHashTable<PTHStatLookupTrait> CacheTy;
693 PTHStatCache(PTHManager::PTHFileLookup &FL)
694 : Cache(FL.getNumBuckets(), FL.getNumEntries(), FL.getBuckets(),
697 LookupResult getStat(StringRef Path, FileData &Data, bool isFile,
698 std::unique_ptr<vfs::File> *F,
699 vfs::FileSystem &FS) override {
700 // Do the lookup for the file's data in the PTH file.
701 CacheTy::iterator I = Cache.find(Path);
703 // If we don't get a hit in the PTH file just forward to 'stat'.
704 if (I == Cache.end())
705 return statChained(Path, Data, isFile, F, FS);
707 const PTHStatData &D = *I;
714 Data.ModTime = D.ModTime;
715 Data.UniqueID = D.UniqueID;
716 Data.IsDirectory = D.IsDirectory;
717 Data.IsNamedPipe = false;
725 std::unique_ptr<FileSystemStatCache> PTHManager::createStatCache() {
726 return llvm::make_unique<PTHStatCache>(*FileLookup);