summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r--clang/lib/Basic/FileManager.cpp57
1 files changed, 28 insertions, 29 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index aadafa55843..e0a7e657563 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -47,8 +47,7 @@ using namespace clang;
#define IS_DIR_SEPARATOR_CHAR(x) ((x) == '/' || (x) == '\\')
namespace {
- static std::string GetFullPath(const char *relPath)
- {
+ static std::string GetFullPath(const char *relPath) {
char *absPathStrPtr = _fullpath(NULL, relPath, 0);
assert(absPathStrPtr && "_fullpath() returned NULL!");
@@ -62,7 +61,7 @@ namespace {
class FileManager::UniqueDirContainer {
/// UniqueDirs - Cache from full path to existing directories/files.
///
- llvm::StringMap<DirectoryEntry> UniqueDirs;
+ llvm::StringMap<DirectoryEntry> UniqueDirs;
public:
DirectoryEntry &getDirectory(const char *Name, struct stat &StatBuf) {
@@ -72,7 +71,7 @@ public:
FullPath.c_str() + FullPath.size()
).getValue();
}
-
+
size_t size() { return UniqueDirs.size(); }
};
@@ -104,7 +103,7 @@ public:
class FileManager::UniqueDirContainer {
/// UniqueDirs - Cache from ID's to existing directories/files.
///
- std::map<std::pair<dev_t, ino_t>, DirectoryEntry> UniqueDirs;
+ std::map<std::pair<dev_t, ino_t>, DirectoryEntry> UniqueDirs;
public:
DirectoryEntry &getDirectory(const char *Name, struct stat &StatBuf) {
@@ -152,27 +151,27 @@ FileManager::~FileManager() {
/// getDirectory - Lookup, cache, and verify the specified directory. This
/// returns null if the directory doesn't exist.
-///
+///
const DirectoryEntry *FileManager::getDirectory(const char *NameStart,
const char *NameEnd) {
++NumDirLookups;
llvm::StringMapEntry<DirectoryEntry *> &NamedDirEnt =
DirEntries.GetOrCreateValue(NameStart, NameEnd);
-
+
// See if there is already an entry in the map.
if (NamedDirEnt.getValue())
return NamedDirEnt.getValue() == NON_EXISTENT_DIR
? 0 : NamedDirEnt.getValue();
-
+
++NumDirCacheMisses;
-
+
// By default, initialize it to invalid.
NamedDirEnt.setValue(NON_EXISTENT_DIR);
-
+
// Get the null-terminated directory name as stored as the key of the
// DirEntries map.
const char *InterndDirName = NamedDirEnt.getKeyData();
-
+
// Check to see if the directory exists.
struct stat StatBuf;
if (stat_cached(InterndDirName, &StatBuf) || // Error stat'ing.
@@ -180,13 +179,13 @@ const DirectoryEntry *FileManager::getDirectory(const char *NameStart,
return 0;
// It exists. See if we have already opened a directory with the same inode.
- // This occurs when one dir is symlinked to another, for example.
+ // This occurs when one dir is symlinked to another, for example.
DirectoryEntry &UDE = UniqueDirs.getDirectory(InterndDirName, StatBuf);
-
+
NamedDirEnt.setValue(&UDE);
if (UDE.getName()) // Already have an entry with this inode, return it.
return &UDE;
-
+
// Otherwise, we don't have this directory yet, add it. We use the string
// key from the DirEntries map as the string.
UDE.Name = InterndDirName;
@@ -199,11 +198,11 @@ const DirectoryEntry *FileManager::getDirectory(const char *NameStart,
/// getFile - Lookup, cache, and verify the specified file. This returns null
/// if the file doesn't exist.
-///
+///
const FileEntry *FileManager::getFile(const char *NameStart,
const char *NameEnd) {
++NumFileLookups;
-
+
// See if there is already an entry in the map.
llvm::StringMapEntry<FileEntry *> &NamedFileEnt =
FileEntries.GetOrCreateValue(NameStart, NameEnd);
@@ -212,7 +211,7 @@ const FileEntry *FileManager::getFile(const char *NameStart,
if (NamedFileEnt.getValue())
return NamedFileEnt.getValue() == NON_EXISTENT_FILE
? 0 : NamedFileEnt.getValue();
-
+
++NumFileCacheMisses;
// By default, initialize it to invalid.
@@ -227,7 +226,7 @@ const FileEntry *FileManager::getFile(const char *NameStart,
// Ignore duplicate //'s.
while (SlashPos > NameStart && IS_DIR_SEPARATOR_CHAR(SlashPos[-1]))
--SlashPos;
-
+
const DirectoryEntry *DirInfo;
if (SlashPos < NameStart) {
// Use the current directory if file has no path component.
@@ -237,17 +236,17 @@ const FileEntry *FileManager::getFile(const char *NameStart,
return 0; // If filename ends with a /, it's a directory.
else
DirInfo = getDirectory(NameStart, SlashPos);
-
+
if (DirInfo == 0) // Directory doesn't exist, file can't exist.
return 0;
-
+
// Get the null-terminated file name as stored as the key of the
// FileEntries map.
const char *InterndFileName = NamedFileEnt.getKeyData();
-
+
// FIXME: Use the directory info to prune this, before doing the stat syscall.
// FIXME: This will reduce the # syscalls.
-
+
// Nope, there isn't. Check to see if the file exists.
struct stat StatBuf;
//llvm::errs() << "STATING: " << Filename;
@@ -258,11 +257,11 @@ const FileEntry *FileManager::getFile(const char *NameStart,
return 0;
}
//llvm::errs() << ": exists\n";
-
+
// It exists. See if we have already opened a file with the same inode.
// This occurs when one dir is symlinked to another, for example.
FileEntry &UFE = UniqueFiles.getFile(InterndFileName, StatBuf);
-
+
NamedFileEnt.setValue(&UFE);
if (UFE.getName()) // Already have an entry with this inode, return it.
return &UFE;
@@ -286,14 +285,14 @@ void FileManager::PrintStats() const {
<< NumDirCacheMisses << " dir cache misses.\n";
llvm::errs() << NumFileLookups << " file lookups, "
<< NumFileCacheMisses << " file cache misses.\n";
-
+
//llvm::errs() << PagesMapped << BytesOfPagesMapped << FSLookups;
}
int MemorizeStatCalls::stat(const char *path, struct stat *buf) {
int result = ::stat(path, buf);
-
- if (result != 0) {
+
+ if (result != 0) {
// Cache failed 'stat' results.
struct stat empty;
StatCalls[path] = StatResult(result, empty);
@@ -303,6 +302,6 @@ int MemorizeStatCalls::stat(const char *path, struct stat *buf) {
// paths.
StatCalls[path] = StatResult(result, *buf);
}
-
- return result;
+
+ return result;
}
OpenPOWER on IntegriCloud