aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/CacheTokens.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-11-23 19:19:34 +0000
committerChris Lattner <sabre@nondot.org>2010-11-23 19:19:34 +0000
commit10e286aa8d39fb51a21412850265d9dae74613ee (patch)
tree94ef75b4f0ebc54bbbf60c7e7c17fee034a99492 /lib/Frontend/CacheTokens.cpp
parent6c6feaca2b1f006e4aaed60c784fe876b63f56d2 (diff)
rework the stat cache, pulling it out of FileManager.h into
its own header and giving it some more structure. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120030 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/CacheTokens.cpp')
-rw-r--r--lib/Frontend/CacheTokens.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/Frontend/CacheTokens.cpp b/lib/Frontend/CacheTokens.cpp
index 2defce340f..94bee6b868 100644
--- a/lib/Frontend/CacheTokens.cpp
+++ b/lib/Frontend/CacheTokens.cpp
@@ -13,11 +13,12 @@
//===----------------------------------------------------------------------===//
#include "clang/Frontend/Utils.h"
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
-#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/FileSystemStatCache.h"
#include "clang/Basic/IdentifierTable.h"
-#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/OnDiskHashTable.h"
+#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/StringExtras.h"
@@ -510,26 +511,31 @@ namespace {
/// as input to PTH generation. StatListener populates the PTHWriter's
/// file map with stat information for directories as well as negative stats.
/// Stat information for files are populated elsewhere.
-class StatListener : public StatSysCallCache {
+class StatListener : public FileSystemStatCache {
PTHMap &PM;
public:
StatListener(PTHMap &pm) : PM(pm) {}
~StatListener() {}
- int stat(const char *path, struct stat *buf) {
- int result = StatSysCallCache::stat(path, buf);
-
- if (result != 0) // Failed 'stat'.
- PM.insert(PTHEntryKeyVariant(path), PTHEntry());
- else if (S_ISDIR(buf->st_mode)) {
+ LookupResult getStat(const char *Path, struct stat &StatBuf) {
+ LookupResult Result = FileSystemStatCache::statChained(Path, StatBuf);
+
+ // If the chained cache didn't know anything about the file, do the stat now
+ // so we can record the result.
+ if (Result == CacheMiss)
+ Result = ::stat(Path, &StatBuf) ? CacheHitMissing : CacheHitExists;
+
+ if (Result == CacheHitMissing) // Failed 'stat'.
+ PM.insert(PTHEntryKeyVariant(Path), PTHEntry());
+ else if (S_ISDIR(StatBuf.st_mode)) {
// Only cache directories with absolute paths.
- if (!llvm::sys::Path(path).isAbsolute())
- return result;
+ if (!llvm::sys::Path(Path).isAbsolute())
+ return Result;
- PM.insert(PTHEntryKeyVariant(buf, path), PTHEntry());
+ PM.insert(PTHEntryKeyVariant(&StatBuf, Path), PTHEntry());
}
- return result;
+ return Result;
}
};
} // end anonymous namespace