FileManager.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. //===--- FileManager.cpp - File System Probing and Caching ----------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the FileManager interface.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // TODO: This should index all interesting directories with dirent calls.
  15. // getdirentries ?
  16. // opendir/readdir_r/closedir ?
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #include "clang/Basic/FileManager.h"
  20. #include "clang/Basic/FileSystemStatCache.h"
  21. #include "clang/Frontend/PCHContainerOperations.h"
  22. #include "llvm/ADT/SmallString.h"
  23. #include "llvm/Config/llvm-config.h"
  24. #include "llvm/Support/FileSystem.h"
  25. #include "llvm/Support/MemoryBuffer.h"
  26. #include "llvm/Support/Path.h"
  27. #include "llvm/Support/raw_ostream.h"
  28. #include <map>
  29. #include <set>
  30. #include <string>
  31. #include <system_error>
  32. using namespace clang;
  33. /// NON_EXISTENT_DIR - A special value distinct from null that is used to
  34. /// represent a dir name that doesn't exist on the disk.
  35. #define NON_EXISTENT_DIR reinterpret_cast<DirectoryEntry*>((intptr_t)-1)
  36. /// NON_EXISTENT_FILE - A special value distinct from null that is used to
  37. /// represent a filename that doesn't exist on the disk.
  38. #define NON_EXISTENT_FILE reinterpret_cast<FileEntry*>((intptr_t)-1)
  39. //===----------------------------------------------------------------------===//
  40. // Common logic.
  41. //===----------------------------------------------------------------------===//
  42. FileManager::FileManager(const FileSystemOptions &FSO,
  43. IntrusiveRefCntPtr<vfs::FileSystem> FS)
  44. : FS(FS), FileSystemOpts(FSO),
  45. SeenDirEntries(64), SeenFileEntries(64), NextFileUID(0) {
  46. NumDirLookups = NumFileLookups = 0;
  47. NumDirCacheMisses = NumFileCacheMisses = 0;
  48. // If the caller doesn't provide a virtual file system, just grab the real
  49. // file system.
  50. if (!FS)
  51. this->FS = vfs::getRealFileSystem();
  52. }
  53. FileManager::~FileManager() {
  54. for (unsigned i = 0, e = VirtualFileEntries.size(); i != e; ++i)
  55. delete VirtualFileEntries[i];
  56. for (unsigned i = 0, e = VirtualDirectoryEntries.size(); i != e; ++i)
  57. delete VirtualDirectoryEntries[i];
  58. }
  59. void FileManager::addStatCache(std::unique_ptr<FileSystemStatCache> statCache,
  60. bool AtBeginning) {
  61. assert(statCache && "No stat cache provided?");
  62. if (AtBeginning || !StatCache.get()) {
  63. statCache->setNextStatCache(std::move(StatCache));
  64. StatCache = std::move(statCache);
  65. return;
  66. }
  67. FileSystemStatCache *LastCache = StatCache.get();
  68. while (LastCache->getNextStatCache())
  69. LastCache = LastCache->getNextStatCache();
  70. LastCache->setNextStatCache(std::move(statCache));
  71. }
  72. void FileManager::removeStatCache(FileSystemStatCache *statCache) {
  73. if (!statCache)
  74. return;
  75. if (StatCache.get() == statCache) {
  76. // This is the first stat cache.
  77. StatCache = StatCache->takeNextStatCache();
  78. return;
  79. }
  80. // Find the stat cache in the list.
  81. FileSystemStatCache *PrevCache = StatCache.get();
  82. while (PrevCache && PrevCache->getNextStatCache() != statCache)
  83. PrevCache = PrevCache->getNextStatCache();
  84. assert(PrevCache && "Stat cache not found for removal");
  85. PrevCache->setNextStatCache(statCache->takeNextStatCache());
  86. }
  87. void FileManager::clearStatCaches() {
  88. StatCache.reset();
  89. }
  90. /// \brief Retrieve the directory that the given file name resides in.
  91. /// Filename can point to either a real file or a virtual file.
  92. static const DirectoryEntry *getDirectoryFromFile(FileManager &FileMgr,
  93. StringRef Filename,
  94. bool CacheFailure) {
  95. if (Filename.empty())
  96. return nullptr;
  97. if (llvm::sys::path::is_separator(Filename[Filename.size() - 1]))
  98. return nullptr; // If Filename is a directory.
  99. StringRef DirName = llvm::sys::path::parent_path(Filename);
  100. // Use the current directory if file has no path component.
  101. if (DirName.empty())
  102. DirName = ".";
  103. return FileMgr.getDirectory(DirName, CacheFailure);
  104. }
  105. /// Add all ancestors of the given path (pointing to either a file or
  106. /// a directory) as virtual directories.
  107. void FileManager::addAncestorsAsVirtualDirs(StringRef Path) {
  108. StringRef DirName = llvm::sys::path::parent_path(Path);
  109. if (DirName.empty())
  110. return;
  111. auto &NamedDirEnt =
  112. *SeenDirEntries.insert(std::make_pair(DirName, nullptr)).first;
  113. // When caching a virtual directory, we always cache its ancestors
  114. // at the same time. Therefore, if DirName is already in the cache,
  115. // we don't need to recurse as its ancestors must also already be in
  116. // the cache.
  117. if (NamedDirEnt.second)
  118. return;
  119. // Add the virtual directory to the cache.
  120. DirectoryEntry *UDE = new DirectoryEntry;
  121. UDE->Name = NamedDirEnt.first().data();
  122. NamedDirEnt.second = UDE;
  123. VirtualDirectoryEntries.push_back(UDE);
  124. // Recursively add the other ancestors.
  125. addAncestorsAsVirtualDirs(DirName);
  126. }
  127. const DirectoryEntry *FileManager::getDirectory(StringRef DirName,
  128. bool CacheFailure) {
  129. // stat doesn't like trailing separators except for root directory.
  130. // At least, on Win32 MSVCRT, stat() cannot strip trailing '/'.
  131. // (though it can strip '\\')
  132. if (DirName.size() > 1 &&
  133. DirName != llvm::sys::path::root_path(DirName) &&
  134. llvm::sys::path::is_separator(DirName.back()))
  135. DirName = DirName.substr(0, DirName.size()-1);
  136. #ifdef LLVM_ON_WIN32
  137. // Fixing a problem with "clang C:test.c" on Windows.
  138. // Stat("C:") does not recognize "C:" as a valid directory
  139. std::string DirNameStr;
  140. if (DirName.size() > 1 && DirName.back() == ':' &&
  141. DirName.equals_lower(llvm::sys::path::root_name(DirName))) {
  142. DirNameStr = DirName.str() + '.';
  143. DirName = DirNameStr;
  144. }
  145. #endif
  146. ++NumDirLookups;
  147. auto &NamedDirEnt =
  148. *SeenDirEntries.insert(std::make_pair(DirName, nullptr)).first;
  149. // See if there was already an entry in the map. Note that the map
  150. // contains both virtual and real directories.
  151. if (NamedDirEnt.second)
  152. return NamedDirEnt.second == NON_EXISTENT_DIR ? nullptr
  153. : NamedDirEnt.second;
  154. ++NumDirCacheMisses;
  155. // By default, initialize it to invalid.
  156. NamedDirEnt.second = NON_EXISTENT_DIR;
  157. // Get the null-terminated directory name as stored as the key of the
  158. // SeenDirEntries map.
  159. const char *InterndDirName = NamedDirEnt.first().data();
  160. // Check to see if the directory exists.
  161. FileData Data;
  162. if (getStatValue(InterndDirName, Data, false, nullptr /*directory lookup*/)) {
  163. // There's no real directory at the given path.
  164. if (!CacheFailure)
  165. SeenDirEntries.erase(DirName);
  166. return nullptr;
  167. }
  168. // It exists. See if we have already opened a directory with the
  169. // same inode (this occurs on Unix-like systems when one dir is
  170. // symlinked to another, for example) or the same path (on
  171. // Windows).
  172. DirectoryEntry &UDE = UniqueRealDirs[Data.UniqueID];
  173. NamedDirEnt.second = &UDE;
  174. if (!UDE.getName()) {
  175. // We don't have this directory yet, add it. We use the string
  176. // key from the SeenDirEntries map as the string.
  177. UDE.Name = InterndDirName;
  178. }
  179. return &UDE;
  180. }
  181. const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
  182. bool CacheFailure) {
  183. ++NumFileLookups;
  184. // See if there is already an entry in the map.
  185. auto &NamedFileEnt =
  186. *SeenFileEntries.insert(std::make_pair(Filename, nullptr)).first;
  187. // See if there is already an entry in the map.
  188. if (NamedFileEnt.second)
  189. return NamedFileEnt.second == NON_EXISTENT_FILE ? nullptr
  190. : NamedFileEnt.second;
  191. ++NumFileCacheMisses;
  192. // By default, initialize it to invalid.
  193. NamedFileEnt.second = NON_EXISTENT_FILE;
  194. // Get the null-terminated file name as stored as the key of the
  195. // SeenFileEntries map.
  196. const char *InterndFileName = NamedFileEnt.first().data();
  197. // Look up the directory for the file. When looking up something like
  198. // sys/foo.h we'll discover all of the search directories that have a 'sys'
  199. // subdirectory. This will let us avoid having to waste time on known-to-fail
  200. // searches when we go to find sys/bar.h, because all the search directories
  201. // without a 'sys' subdir will get a cached failure result.
  202. #if 0 // HLSL Change Starts - do not probe for directories
  203. const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename,
  204. CacheFailure);
  205. if (DirInfo == nullptr) { // Directory doesn't exist, file can't exist.
  206. if (!CacheFailure)
  207. SeenFileEntries.erase(Filename);
  208. return nullptr;
  209. }
  210. #else
  211. const DirectoryEntry *DirInfo = nullptr;
  212. #endif // HLSL Change Ends - do not probe for directories
  213. // FIXME: Use the directory info to prune this, before doing the stat syscall.
  214. // FIXME: This will reduce the # syscalls.
  215. // Nope, there isn't. Check to see if the file exists.
  216. std::unique_ptr<vfs::File> F;
  217. FileData Data;
  218. if (getStatValue(InterndFileName, Data, true, openFile ? &F : nullptr)) {
  219. // There's no real file at the given path.
  220. if (!CacheFailure)
  221. SeenFileEntries.erase(Filename);
  222. return nullptr;
  223. }
  224. assert((openFile || !F) && "undesired open file");
  225. // It exists. See if we have already opened a file with the same inode.
  226. // This occurs when one dir is symlinked to another, for example.
  227. FileEntry &UFE = UniqueRealFiles[Data.UniqueID];
  228. NamedFileEnt.second = &UFE;
  229. // If the name returned by getStatValue is different than Filename, re-intern
  230. // the name.
  231. if (Data.Name != Filename) {
  232. auto &NamedFileEnt =
  233. *SeenFileEntries.insert(std::make_pair(Data.Name, nullptr)).first;
  234. if (!NamedFileEnt.second)
  235. NamedFileEnt.second = &UFE;
  236. else
  237. assert(NamedFileEnt.second == &UFE &&
  238. "filename from getStatValue() refers to wrong file");
  239. InterndFileName = NamedFileEnt.first().data();
  240. }
  241. // HLSL Change Starts - do not probe for directories before looking for file
  242. // This way the include handler can report all the included files paths as existing.
  243. DirInfo = getDirectoryFromFile(*this, Filename, CacheFailure);
  244. if (DirInfo == nullptr) { // Directory doesn't exist, file can't exist.
  245. if (!CacheFailure)
  246. SeenFileEntries.erase(Filename);
  247. return nullptr;
  248. }
  249. // HLSL Change Ends - do not probe for directories
  250. if (UFE.isValid()) { // Already have an entry with this inode, return it.
  251. // FIXME: this hack ensures that if we look up a file by a virtual path in
  252. // the VFS that the getDir() will have the virtual path, even if we found
  253. // the file by a 'real' path first. This is required in order to find a
  254. // module's structure when its headers/module map are mapped in the VFS.
  255. // We should remove this as soon as we can properly support a file having
  256. // multiple names.
  257. if (DirInfo != UFE.Dir && Data.IsVFSMapped)
  258. UFE.Dir = DirInfo;
  259. // Always update the name to use the last name by which a file was accessed.
  260. // FIXME: Neither this nor always using the first name is correct; we want
  261. // to switch towards a design where we return a FileName object that
  262. // encapsulates both the name by which the file was accessed and the
  263. // corresponding FileEntry.
  264. UFE.Name = InterndFileName;
  265. return &UFE;
  266. }
  267. // Otherwise, we don't have this file yet, add it.
  268. UFE.Name = InterndFileName;
  269. UFE.Size = Data.Size;
  270. UFE.ModTime = Data.ModTime;
  271. UFE.Dir = DirInfo;
  272. UFE.UID = NextFileUID++;
  273. UFE.UniqueID = Data.UniqueID;
  274. UFE.IsNamedPipe = Data.IsNamedPipe;
  275. UFE.InPCH = Data.InPCH;
  276. UFE.File = std::move(F);
  277. UFE.IsValid = true;
  278. return &UFE;
  279. }
  280. const FileEntry *
  281. FileManager::getVirtualFile(StringRef Filename, off_t Size,
  282. time_t ModificationTime) {
  283. ++NumFileLookups;
  284. // See if there is already an entry in the map.
  285. auto &NamedFileEnt =
  286. *SeenFileEntries.insert(std::make_pair(Filename, nullptr)).first;
  287. // See if there is already an entry in the map.
  288. if (NamedFileEnt.second && NamedFileEnt.second != NON_EXISTENT_FILE)
  289. return NamedFileEnt.second;
  290. ++NumFileCacheMisses;
  291. // By default, initialize it to invalid.
  292. NamedFileEnt.second = NON_EXISTENT_FILE;
  293. addAncestorsAsVirtualDirs(Filename);
  294. FileEntry *UFE = nullptr;
  295. // Now that all ancestors of Filename are in the cache, the
  296. // following call is guaranteed to find the DirectoryEntry from the
  297. // cache.
  298. const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename,
  299. /*CacheFailure=*/true);
  300. assert(DirInfo &&
  301. "The directory of a virtual file should already be in the cache.");
  302. // Check to see if the file exists. If so, drop the virtual file
  303. FileData Data;
  304. const char *InterndFileName = NamedFileEnt.first().data();
  305. if (getStatValue(InterndFileName, Data, true, nullptr) == 0) {
  306. Data.Size = Size;
  307. Data.ModTime = ModificationTime;
  308. UFE = &UniqueRealFiles[Data.UniqueID];
  309. NamedFileEnt.second = UFE;
  310. // If we had already opened this file, close it now so we don't
  311. // leak the descriptor. We're not going to use the file
  312. // descriptor anyway, since this is a virtual file.
  313. if (UFE->File)
  314. UFE->closeFile();
  315. // If we already have an entry with this inode, return it.
  316. if (UFE->isValid())
  317. return UFE;
  318. UFE->UniqueID = Data.UniqueID;
  319. UFE->IsNamedPipe = Data.IsNamedPipe;
  320. UFE->InPCH = Data.InPCH;
  321. }
  322. if (!UFE) {
  323. UFE = new FileEntry();
  324. VirtualFileEntries.push_back(UFE);
  325. NamedFileEnt.second = UFE;
  326. }
  327. UFE->Name = InterndFileName;
  328. UFE->Size = Size;
  329. UFE->ModTime = ModificationTime;
  330. UFE->Dir = DirInfo;
  331. UFE->UID = NextFileUID++;
  332. UFE->File.reset();
  333. return UFE;
  334. }
  335. void FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const {
  336. StringRef pathRef(path.data(), path.size());
  337. if (FileSystemOpts.WorkingDir.empty()
  338. || llvm::sys::path::is_absolute(pathRef))
  339. return;
  340. SmallString<128> NewPath(FileSystemOpts.WorkingDir);
  341. llvm::sys::path::append(NewPath, pathRef);
  342. path = NewPath;
  343. }
  344. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
  345. FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
  346. bool ShouldCloseOpenFile) {
  347. uint64_t FileSize = Entry->getSize();
  348. // If there's a high enough chance that the file have changed since we
  349. // got its size, force a stat before opening it.
  350. if (isVolatile)
  351. FileSize = -1;
  352. const char *Filename = Entry->getName();
  353. // If the file is already open, use the open file descriptor.
  354. if (Entry->File) {
  355. auto Result =
  356. Entry->File->getBuffer(Filename, FileSize,
  357. /*RequiresNullTerminator=*/true, isVolatile);
  358. // FIXME: we need a set of APIs that can make guarantees about whether a
  359. // FileEntry is open or not.
  360. if (ShouldCloseOpenFile)
  361. Entry->closeFile();
  362. return Result;
  363. }
  364. // Otherwise, open the file.
  365. if (FileSystemOpts.WorkingDir.empty())
  366. return FS->getBufferForFile(Filename, FileSize,
  367. /*RequiresNullTerminator=*/true, isVolatile);
  368. SmallString<128> FilePath(Entry->getName());
  369. FixupRelativePath(FilePath);
  370. return FS->getBufferForFile(FilePath, FileSize,
  371. /*RequiresNullTerminator=*/true, isVolatile);
  372. }
  373. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
  374. FileManager::getBufferForFile(StringRef Filename) {
  375. if (FileSystemOpts.WorkingDir.empty())
  376. return FS->getBufferForFile(Filename);
  377. SmallString<128> FilePath(Filename);
  378. FixupRelativePath(FilePath);
  379. return FS->getBufferForFile(FilePath.c_str());
  380. }
  381. /// getStatValue - Get the 'stat' information for the specified path,
  382. /// using the cache to accelerate it if possible. This returns true
  383. /// if the path points to a virtual file or does not exist, or returns
  384. /// false if it's an existent real file. If FileDescriptor is NULL,
  385. /// do directory look-up instead of file look-up.
  386. bool FileManager::getStatValue(const char *Path, FileData &Data, bool isFile,
  387. std::unique_ptr<vfs::File> *F) {
  388. // FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
  389. // absolute!
  390. if (FileSystemOpts.WorkingDir.empty())
  391. return FileSystemStatCache::get(Path, Data, isFile, F,StatCache.get(), *FS);
  392. SmallString<128> FilePath(Path);
  393. FixupRelativePath(FilePath);
  394. return FileSystemStatCache::get(FilePath.c_str(), Data, isFile, F,
  395. StatCache.get(), *FS);
  396. }
  397. bool FileManager::getNoncachedStatValue(StringRef Path,
  398. vfs::Status &Result) {
  399. SmallString<128> FilePath(Path);
  400. FixupRelativePath(FilePath);
  401. llvm::ErrorOr<vfs::Status> S = FS->status(FilePath.c_str());
  402. if (!S)
  403. return true;
  404. Result = *S;
  405. return false;
  406. }
  407. void FileManager::invalidateCache(const FileEntry *Entry) {
  408. assert(Entry && "Cannot invalidate a NULL FileEntry");
  409. SeenFileEntries.erase(Entry->getName());
  410. // FileEntry invalidation should not block future optimizations in the file
  411. // caches. Possible alternatives are cache truncation (invalidate last N) or
  412. // invalidation of the whole cache.
  413. UniqueRealFiles.erase(Entry->getUniqueID());
  414. }
  415. void FileManager::GetUniqueIDMapping(
  416. SmallVectorImpl<const FileEntry *> &UIDToFiles) const {
  417. UIDToFiles.clear();
  418. UIDToFiles.resize(NextFileUID);
  419. // Map file entries
  420. for (llvm::StringMap<FileEntry*, llvm::BumpPtrAllocator>::const_iterator
  421. FE = SeenFileEntries.begin(), FEEnd = SeenFileEntries.end();
  422. FE != FEEnd; ++FE)
  423. if (FE->getValue() && FE->getValue() != NON_EXISTENT_FILE)
  424. UIDToFiles[FE->getValue()->getUID()] = FE->getValue();
  425. // Map virtual file entries
  426. for (SmallVectorImpl<FileEntry *>::const_iterator
  427. VFE = VirtualFileEntries.begin(), VFEEnd = VirtualFileEntries.end();
  428. VFE != VFEEnd; ++VFE)
  429. if (*VFE && *VFE != NON_EXISTENT_FILE)
  430. UIDToFiles[(*VFE)->getUID()] = *VFE;
  431. }
  432. void FileManager::modifyFileEntry(FileEntry *File,
  433. off_t Size, time_t ModificationTime) {
  434. File->Size = Size;
  435. File->ModTime = ModificationTime;
  436. }
  437. /// Remove '.' path components from the given absolute path.
  438. /// \return \c true if any changes were made.
  439. // FIXME: Move this to llvm::sys::path.
  440. bool FileManager::removeDotPaths(SmallVectorImpl<char> &Path) {
  441. using namespace llvm::sys;
  442. SmallVector<StringRef, 16> ComponentStack;
  443. StringRef P(Path.data(), Path.size());
  444. // Skip the root path, then look for traversal in the components.
  445. StringRef Rel = path::relative_path(P);
  446. bool AnyDots = false;
  447. for (StringRef C : llvm::make_range(path::begin(Rel), path::end(Rel))) {
  448. if (C == ".") {
  449. AnyDots = true;
  450. continue;
  451. }
  452. ComponentStack.push_back(C);
  453. }
  454. if (!AnyDots)
  455. return false;
  456. SmallString<256> Buffer = path::root_path(P);
  457. for (StringRef C : ComponentStack)
  458. path::append(Buffer, C);
  459. Path.swap(Buffer);
  460. return true;
  461. }
  462. StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
  463. // FIXME: use llvm::sys::fs::canonical() when it gets implemented
  464. llvm::DenseMap<const DirectoryEntry *, llvm::StringRef>::iterator Known
  465. = CanonicalDirNames.find(Dir);
  466. if (Known != CanonicalDirNames.end())
  467. return Known->second;
  468. StringRef CanonicalName(Dir->getName());
  469. #ifdef LLVM_ON_UNIX
  470. char CanonicalNameBuf[PATH_MAX];
  471. if (realpath(Dir->getName(), CanonicalNameBuf)) {
  472. unsigned Len = strlen(CanonicalNameBuf);
  473. char *Mem = static_cast<char *>(CanonicalNameStorage.Allocate(Len, 1));
  474. memcpy(Mem, CanonicalNameBuf, Len);
  475. CanonicalName = StringRef(Mem, Len);
  476. }
  477. #else
  478. SmallString<256> CanonicalNameBuf(CanonicalName);
  479. llvm::sys::fs::make_absolute(CanonicalNameBuf);
  480. llvm::sys::path::native(CanonicalNameBuf);
  481. removeDotPaths(CanonicalNameBuf);
  482. #endif
  483. CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName));
  484. return CanonicalName;
  485. }
  486. void FileManager::PrintStats() const {
  487. llvm::errs() << "\n*** File Manager Stats:\n";
  488. llvm::errs() << UniqueRealFiles.size() << " real files found, "
  489. << UniqueRealDirs.size() << " real dirs found.\n";
  490. llvm::errs() << VirtualFileEntries.size() << " virtual files found, "
  491. << VirtualDirectoryEntries.size() << " virtual dirs found.\n";
  492. llvm::errs() << NumDirLookups << " dir lookups, "
  493. << NumDirCacheMisses << " dir cache misses.\n";
  494. llvm::errs() << NumFileLookups << " file lookups, "
  495. << NumFileCacheMisses << " file cache misses.\n";
  496. //llvm::errs() << PagesMapped << BytesOfPagesMapped << FSLookups;
  497. }
  498. // Virtual destructors for abstract base classes that need live in Basic.
  499. PCHContainerWriter::~PCHContainerWriter() {}
  500. PCHContainerReader::~PCHContainerReader() {}