FileManager.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename,
  203. CacheFailure);
  204. if (DirInfo == nullptr) { // Directory doesn't exist, file can't exist.
  205. if (!CacheFailure)
  206. SeenFileEntries.erase(Filename);
  207. return nullptr;
  208. }
  209. // FIXME: Use the directory info to prune this, before doing the stat syscall.
  210. // FIXME: This will reduce the # syscalls.
  211. // Nope, there isn't. Check to see if the file exists.
  212. std::unique_ptr<vfs::File> F;
  213. FileData Data;
  214. if (getStatValue(InterndFileName, Data, true, openFile ? &F : nullptr)) {
  215. // There's no real file at the given path.
  216. if (!CacheFailure)
  217. SeenFileEntries.erase(Filename);
  218. return nullptr;
  219. }
  220. assert((openFile || !F) && "undesired open file");
  221. // It exists. See if we have already opened a file with the same inode.
  222. // This occurs when one dir is symlinked to another, for example.
  223. FileEntry &UFE = UniqueRealFiles[Data.UniqueID];
  224. NamedFileEnt.second = &UFE;
  225. // If the name returned by getStatValue is different than Filename, re-intern
  226. // the name.
  227. if (Data.Name != Filename) {
  228. auto &NamedFileEnt =
  229. *SeenFileEntries.insert(std::make_pair(Data.Name, nullptr)).first;
  230. if (!NamedFileEnt.second)
  231. NamedFileEnt.second = &UFE;
  232. else
  233. assert(NamedFileEnt.second == &UFE &&
  234. "filename from getStatValue() refers to wrong file");
  235. InterndFileName = NamedFileEnt.first().data();
  236. }
  237. if (UFE.isValid()) { // Already have an entry with this inode, return it.
  238. // FIXME: this hack ensures that if we look up a file by a virtual path in
  239. // the VFS that the getDir() will have the virtual path, even if we found
  240. // the file by a 'real' path first. This is required in order to find a
  241. // module's structure when its headers/module map are mapped in the VFS.
  242. // We should remove this as soon as we can properly support a file having
  243. // multiple names.
  244. if (DirInfo != UFE.Dir && Data.IsVFSMapped)
  245. UFE.Dir = DirInfo;
  246. // Always update the name to use the last name by which a file was accessed.
  247. // FIXME: Neither this nor always using the first name is correct; we want
  248. // to switch towards a design where we return a FileName object that
  249. // encapsulates both the name by which the file was accessed and the
  250. // corresponding FileEntry.
  251. UFE.Name = InterndFileName;
  252. return &UFE;
  253. }
  254. // Otherwise, we don't have this file yet, add it.
  255. UFE.Name = InterndFileName;
  256. UFE.Size = Data.Size;
  257. UFE.ModTime = Data.ModTime;
  258. UFE.Dir = DirInfo;
  259. UFE.UID = NextFileUID++;
  260. UFE.UniqueID = Data.UniqueID;
  261. UFE.IsNamedPipe = Data.IsNamedPipe;
  262. UFE.InPCH = Data.InPCH;
  263. UFE.File = std::move(F);
  264. UFE.IsValid = true;
  265. return &UFE;
  266. }
  267. const FileEntry *
  268. FileManager::getVirtualFile(StringRef Filename, off_t Size,
  269. time_t ModificationTime) {
  270. ++NumFileLookups;
  271. // See if there is already an entry in the map.
  272. auto &NamedFileEnt =
  273. *SeenFileEntries.insert(std::make_pair(Filename, nullptr)).first;
  274. // See if there is already an entry in the map.
  275. if (NamedFileEnt.second && NamedFileEnt.second != NON_EXISTENT_FILE)
  276. return NamedFileEnt.second;
  277. ++NumFileCacheMisses;
  278. // By default, initialize it to invalid.
  279. NamedFileEnt.second = NON_EXISTENT_FILE;
  280. addAncestorsAsVirtualDirs(Filename);
  281. FileEntry *UFE = nullptr;
  282. // Now that all ancestors of Filename are in the cache, the
  283. // following call is guaranteed to find the DirectoryEntry from the
  284. // cache.
  285. const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename,
  286. /*CacheFailure=*/true);
  287. assert(DirInfo &&
  288. "The directory of a virtual file should already be in the cache.");
  289. // Check to see if the file exists. If so, drop the virtual file
  290. FileData Data;
  291. const char *InterndFileName = NamedFileEnt.first().data();
  292. if (getStatValue(InterndFileName, Data, true, nullptr) == 0) {
  293. Data.Size = Size;
  294. Data.ModTime = ModificationTime;
  295. UFE = &UniqueRealFiles[Data.UniqueID];
  296. NamedFileEnt.second = UFE;
  297. // If we had already opened this file, close it now so we don't
  298. // leak the descriptor. We're not going to use the file
  299. // descriptor anyway, since this is a virtual file.
  300. if (UFE->File)
  301. UFE->closeFile();
  302. // If we already have an entry with this inode, return it.
  303. if (UFE->isValid())
  304. return UFE;
  305. UFE->UniqueID = Data.UniqueID;
  306. UFE->IsNamedPipe = Data.IsNamedPipe;
  307. UFE->InPCH = Data.InPCH;
  308. }
  309. if (!UFE) {
  310. UFE = new FileEntry();
  311. VirtualFileEntries.push_back(UFE);
  312. NamedFileEnt.second = UFE;
  313. }
  314. UFE->Name = InterndFileName;
  315. UFE->Size = Size;
  316. UFE->ModTime = ModificationTime;
  317. UFE->Dir = DirInfo;
  318. UFE->UID = NextFileUID++;
  319. UFE->File.reset();
  320. return UFE;
  321. }
  322. bool FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const {
  323. StringRef pathRef(path.data(), path.size());
  324. if (FileSystemOpts.WorkingDir.empty()
  325. || llvm::sys::path::is_absolute(pathRef))
  326. return false;
  327. SmallString<128> NewPath(FileSystemOpts.WorkingDir);
  328. llvm::sys::path::append(NewPath, pathRef);
  329. path = NewPath;
  330. return true;
  331. }
  332. bool FileManager::makeAbsolutePath(SmallVectorImpl<char> &Path) const {
  333. bool Changed = FixupRelativePath(Path);
  334. if (!llvm::sys::path::is_absolute(StringRef(Path.data(), Path.size()))) {
  335. llvm::sys::fs::make_absolute(Path);
  336. Changed = true;
  337. }
  338. return Changed;
  339. }
  340. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
  341. FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
  342. bool ShouldCloseOpenFile) {
  343. uint64_t FileSize = Entry->getSize();
  344. // If there's a high enough chance that the file have changed since we
  345. // got its size, force a stat before opening it.
  346. if (isVolatile)
  347. FileSize = -1;
  348. const char *Filename = Entry->getName();
  349. // If the file is already open, use the open file descriptor.
  350. if (Entry->File) {
  351. auto Result =
  352. Entry->File->getBuffer(Filename, FileSize,
  353. /*RequiresNullTerminator=*/true, isVolatile);
  354. // FIXME: we need a set of APIs that can make guarantees about whether a
  355. // FileEntry is open or not.
  356. if (ShouldCloseOpenFile)
  357. Entry->closeFile();
  358. return Result;
  359. }
  360. // Otherwise, open the file.
  361. if (FileSystemOpts.WorkingDir.empty())
  362. return FS->getBufferForFile(Filename, FileSize,
  363. /*RequiresNullTerminator=*/true, isVolatile);
  364. SmallString<128> FilePath(Entry->getName());
  365. FixupRelativePath(FilePath);
  366. return FS->getBufferForFile(FilePath, FileSize,
  367. /*RequiresNullTerminator=*/true, isVolatile);
  368. }
  369. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
  370. FileManager::getBufferForFile(StringRef Filename) {
  371. if (FileSystemOpts.WorkingDir.empty())
  372. return FS->getBufferForFile(Filename);
  373. SmallString<128> FilePath(Filename);
  374. FixupRelativePath(FilePath);
  375. return FS->getBufferForFile(FilePath.c_str());
  376. }
  377. /// getStatValue - Get the 'stat' information for the specified path,
  378. /// using the cache to accelerate it if possible. This returns true
  379. /// if the path points to a virtual file or does not exist, or returns
  380. /// false if it's an existent real file. If FileDescriptor is NULL,
  381. /// do directory look-up instead of file look-up.
  382. bool FileManager::getStatValue(const char *Path, FileData &Data, bool isFile,
  383. std::unique_ptr<vfs::File> *F) {
  384. // FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
  385. // absolute!
  386. if (FileSystemOpts.WorkingDir.empty())
  387. return FileSystemStatCache::get(Path, Data, isFile, F,StatCache.get(), *FS);
  388. SmallString<128> FilePath(Path);
  389. FixupRelativePath(FilePath);
  390. return FileSystemStatCache::get(FilePath.c_str(), Data, isFile, F,
  391. StatCache.get(), *FS);
  392. }
  393. bool FileManager::getNoncachedStatValue(StringRef Path,
  394. vfs::Status &Result) {
  395. SmallString<128> FilePath(Path);
  396. FixupRelativePath(FilePath);
  397. llvm::ErrorOr<vfs::Status> S = FS->status(FilePath.c_str());
  398. if (!S)
  399. return true;
  400. Result = *S;
  401. return false;
  402. }
  403. void FileManager::invalidateCache(const FileEntry *Entry) {
  404. assert(Entry && "Cannot invalidate a NULL FileEntry");
  405. SeenFileEntries.erase(Entry->getName());
  406. // FileEntry invalidation should not block future optimizations in the file
  407. // caches. Possible alternatives are cache truncation (invalidate last N) or
  408. // invalidation of the whole cache.
  409. UniqueRealFiles.erase(Entry->getUniqueID());
  410. }
  411. void FileManager::GetUniqueIDMapping(
  412. SmallVectorImpl<const FileEntry *> &UIDToFiles) const {
  413. UIDToFiles.clear();
  414. UIDToFiles.resize(NextFileUID);
  415. // Map file entries
  416. for (llvm::StringMap<FileEntry*, llvm::BumpPtrAllocator>::const_iterator
  417. FE = SeenFileEntries.begin(), FEEnd = SeenFileEntries.end();
  418. FE != FEEnd; ++FE)
  419. if (FE->getValue() && FE->getValue() != NON_EXISTENT_FILE)
  420. UIDToFiles[FE->getValue()->getUID()] = FE->getValue();
  421. // Map virtual file entries
  422. for (SmallVectorImpl<FileEntry *>::const_iterator
  423. VFE = VirtualFileEntries.begin(), VFEEnd = VirtualFileEntries.end();
  424. VFE != VFEEnd; ++VFE)
  425. if (*VFE && *VFE != NON_EXISTENT_FILE)
  426. UIDToFiles[(*VFE)->getUID()] = *VFE;
  427. }
  428. void FileManager::modifyFileEntry(FileEntry *File,
  429. off_t Size, time_t ModificationTime) {
  430. File->Size = Size;
  431. File->ModTime = ModificationTime;
  432. }
  433. /// Remove '.' and '..' path components from the given absolute path.
  434. /// \return \c true if any changes were made.
  435. // FIXME: Move this to llvm::sys::path.
  436. bool FileManager::removeDotPaths(SmallVectorImpl<char> &Path, bool RemoveDotDot) {
  437. using namespace llvm::sys;
  438. SmallVector<StringRef, 16> ComponentStack;
  439. StringRef P(Path.data(), Path.size());
  440. // Skip the root path, then look for traversal in the components.
  441. StringRef Rel = path::relative_path(P);
  442. for (StringRef C : llvm::make_range(path::begin(Rel), path::end(Rel))) {
  443. if (C == ".")
  444. continue;
  445. if (RemoveDotDot) {
  446. if (C == "..") {
  447. if (!ComponentStack.empty())
  448. ComponentStack.pop_back();
  449. continue;
  450. }
  451. }
  452. ComponentStack.push_back(C);
  453. }
  454. SmallString<256> Buffer = path::root_path(P);
  455. for (StringRef C : ComponentStack)
  456. path::append(Buffer, C);
  457. bool Changed = (Path != Buffer);
  458. Path.swap(Buffer);
  459. return Changed;
  460. }
  461. StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
  462. // FIXME: use llvm::sys::fs::canonical() when it gets implemented
  463. llvm::DenseMap<const DirectoryEntry *, llvm::StringRef>::iterator Known
  464. = CanonicalDirNames.find(Dir);
  465. if (Known != CanonicalDirNames.end())
  466. return Known->second;
  467. StringRef CanonicalName(Dir->getName());
  468. #ifdef LLVM_ON_UNIX
  469. char CanonicalNameBuf[PATH_MAX];
  470. if (realpath(Dir->getName(), CanonicalNameBuf))
  471. CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
  472. #else
  473. SmallString<256> CanonicalNameBuf(CanonicalName);
  474. llvm::sys::fs::make_absolute(CanonicalNameBuf);
  475. llvm::sys::path::native(CanonicalNameBuf);
  476. // We've run into needing to remove '..' here in the wild though, so
  477. // remove it.
  478. // On Windows, symlinks are significantly less prevalent, so removing
  479. // '..' is pretty safe.
  480. // Ideally we'd have an equivalent of `realpath` and could implement
  481. // sys::fs::canonical across all the platforms.
  482. removeDotPaths(CanonicalNameBuf, /*RemoveDotDot*/true);
  483. CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
  484. #endif
  485. CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName));
  486. return CanonicalName;
  487. }
  488. void FileManager::PrintStats() const {
  489. llvm::errs() << "\n*** File Manager Stats:\n";
  490. llvm::errs() << UniqueRealFiles.size() << " real files found, "
  491. << UniqueRealDirs.size() << " real dirs found.\n";
  492. llvm::errs() << VirtualFileEntries.size() << " virtual files found, "
  493. << VirtualDirectoryEntries.size() << " virtual dirs found.\n";
  494. llvm::errs() << NumDirLookups << " dir lookups, "
  495. << NumDirCacheMisses << " dir cache misses.\n";
  496. llvm::errs() << NumFileLookups << " file lookups, "
  497. << NumFileCacheMisses << " file cache misses.\n";
  498. //llvm::errs() << PagesMapped << BytesOfPagesMapped << FSLookups;
  499. }
  500. // Virtual destructors for abstract base classes that need live in Basic.
  501. PCHContainerWriter::~PCHContainerWriter() {}
  502. PCHContainerReader::~PCHContainerReader() {}