r202412 - Split FileEntry name vs. isValid
Ben Langmuir
blangmuir at apple.com
Thu Feb 27 09:23:34 PST 2014
Author: benlangmuir
Date: Thu Feb 27 11:23:33 2014
New Revision: 202412
URL: http://llvm.org/viewvc/llvm-project?rev=202412&view=rev
Log:
Split FileEntry name vs. isValid
This is a small bit of refactoring in preparation for FileEntry owning
the storage for its own name.
Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp
cfe/trunk/lib/Frontend/TextDiagnostic.cpp
Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=202412&r1=202411&r2=202412&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Thu Feb 27 11:23:33 2014
@@ -66,6 +66,7 @@ class FileEntry {
llvm::sys::fs::UniqueID UniqueID;
bool IsNamedPipe;
bool InPCH;
+ bool IsValid; // Is this \c FileEntry initialized and valid?
/// \brief The open file, if it is owned by the \p FileEntry.
mutable OwningPtr<vfs::File> File;
@@ -77,11 +78,13 @@ class FileEntry {
public:
FileEntry(llvm::sys::fs::UniqueID UniqueID, bool IsNamedPipe, bool InPCH)
- : Name(0), UniqueID(UniqueID), IsNamedPipe(IsNamedPipe), InPCH(InPCH)
+ : Name(0), UniqueID(UniqueID), IsNamedPipe(IsNamedPipe), InPCH(InPCH),
+ IsValid(false)
{}
// Add a default constructor for use with llvm::StringMap
FileEntry()
- : Name(0), UniqueID(0, 0), IsNamedPipe(false), InPCH(false)
+ : Name(0), UniqueID(0, 0), IsNamedPipe(false), InPCH(false),
+ IsValid(false)
{}
FileEntry(const FileEntry &FE) {
@@ -95,6 +98,7 @@ public:
}
const char *getName() const { return Name; }
+ bool isValid() const { return IsValid; }
off_t getSize() const { return Size; }
unsigned getUID() const { return UID; }
const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; }
Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=202412&r1=202411&r2=202412&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Thu Feb 27 11:23:33 2014
@@ -314,7 +314,7 @@ const FileEntry *FileManager::getFile(St
UniqueRealFiles.getFile(Data.UniqueID, Data.IsNamedPipe, Data.InPCH);
NamedFileEnt.setValue(&UFE);
- if (UFE.getName()) { // Already have an entry with this inode, return it.
+ if (UFE.isValid()) { // Already have an entry with this inode, return it.
// If the stat process opened the file, close it to avoid a FD leak.
if (F)
delete F;
@@ -331,6 +331,7 @@ const FileEntry *FileManager::getFile(St
UFE.Dir = DirInfo;
UFE.UID = NextFileUID++;
UFE.File.reset(F);
+ UFE.IsValid = true;
return &UFE;
}
@@ -380,7 +381,7 @@ FileManager::getVirtualFile(StringRef Fi
UFE->closeFile();
// If we already have an entry with this inode, return it.
- if (UFE->getName())
+ if (UFE->isValid())
return UFE;
}
Modified: cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp?rev=202412&r1=202411&r2=202412&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp Thu Feb 27 11:23:33 2014
@@ -130,7 +130,7 @@ void LogDiagnosticPrinter::HandleDiagnos
FileID FID = SM.getMainFileID();
if (!FID.isInvalid()) {
const FileEntry *FE = SM.getFileEntryForID(FID);
- if (FE && FE->getName())
+ if (FE && FE->isValid())
MainFilename = FE->getName();
}
}
@@ -157,7 +157,7 @@ void LogDiagnosticPrinter::HandleDiagnos
FileID FID = SM.getFileID(Info.getLocation());
if (!FID.isInvalid()) {
const FileEntry *FE = SM.getFileEntryForID(FID);
- if (FE && FE->getName())
+ if (FE && FE->isValid())
DE.Filename = FE->getName();
}
} else {
Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=202412&r1=202411&r2=202412&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Thu Feb 27 11:23:33 2014
@@ -787,7 +787,7 @@ void TextDiagnostic::emitDiagnosticLoc(S
FileID FID = SM.getFileID(Loc);
if (!FID.isInvalid()) {
const FileEntry* FE = SM.getFileEntryForID(FID);
- if (FE && FE->getName()) {
+ if (FE && FE->isValid()) {
OS << FE->getName();
if (FE->isInPCH())
OS << " (in PCH)";
More information about the cfe-commits
mailing list