From da9954400aab56bc3df60eb1b7be2489121c6166 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 18 Dec 2007 20:45:25 +0000 Subject: [PATCH] Added to FileEntry a pointer to the pair for the file, and accessors to FileEntry to query these values. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45171 91177308-0d34-0410-b5e6-96231b3b80d8 --- Basic/FileManager.cpp | 10 ++++++++-- include/clang/Basic/FileManager.h | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Basic/FileManager.cpp b/Basic/FileManager.cpp index 8ffde1f6fc..9edbd03873 100644 --- a/Basic/FileManager.cpp +++ b/Basic/FileManager.cpp @@ -65,7 +65,7 @@ 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[std::make_pair(StatBuf.st_dev, StatBuf.st_ino)]; @@ -144,7 +144,12 @@ const FileEntry *FileManager::getFile(const char *NameStart, // 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. - FileEntry &UFE = UniqueFiles[std::make_pair(StatBuf.st_dev, StatBuf.st_ino)]; + std::pair X = + UniqueFiles.insert(FileEntryMap::value_type(std::make_pair(StatBuf.st_dev, + StatBuf.st_ino), + FileEntry())); + + FileEntry &UFE = X.first->second; NamedFileEnt.setValue(&UFE); if (UFE.getName()) // Already have an entry with this inode, return it. @@ -158,6 +163,7 @@ const FileEntry *FileManager::getFile(const char *NameStart, UFE.ModTime = StatBuf.st_mtime; UFE.Dir = DirInfo; UFE.UID = NextFileUID++; + UFE.InoDev = &X.first->first; return &UFE; } diff --git a/include/clang/Basic/FileManager.h b/include/clang/Basic/FileManager.h index ce58cdc4a9..dd12c1c33b 100644 --- a/include/clang/Basic/FileManager.h +++ b/include/clang/Basic/FileManager.h @@ -42,13 +42,16 @@ class FileEntry { time_t ModTime; // Modification time of file. const DirectoryEntry *Dir; // Directory file lives in. unsigned UID; // A unique (small) ID for the file. + const std::pair* InoDev; // Pointer to inode/device number pair. friend class FileManager; public: - FileEntry() : Name(0) {} + FileEntry() : Name(0), InoDev(NULL) {} const char *getName() const { return Name; } off_t getSize() const { return Size; } unsigned getUID() const { return UID; } + ino_t getInode() const { return InoDev->second; } + dev_t getDev() const { return InoDev->first; } time_t getModificationTime() const { return ModTime; } /// getDir - Return the directory the file lives in. @@ -66,7 +69,9 @@ class FileManager { /// UniqueDirs/UniqueFiles - Cache from ID's to existing directories/files. /// std::map, DirectoryEntry> UniqueDirs; - std::map, FileEntry> UniqueFiles; + + typedef std::map, FileEntry> FileEntryMap; + FileEntryMap UniqueFiles; /// DirEntries/FileEntries - This is a cache of directory/file entries we have /// looked up. The actual Entry is owned by UniqueFiles/UniqueDirs above.