Split FileEntry name vs. isValid

This is a small bit of refactoring in preparation for FileEntry owning
the storage for its own name.

llvm-svn: 202412
This commit is contained in:
Ben Langmuir 2014-02-27 17:23:33 +00:00
parent 955fe6f6ed
commit c8a71468b7
4 changed files with 12 additions and 7 deletions

View File

@ -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; }

View File

@ -314,7 +314,7 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
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(StringRef Filename, bool openFile,
UFE.Dir = DirInfo;
UFE.UID = NextFileUID++;
UFE.File.reset(F);
UFE.IsValid = true;
return &UFE;
}
@ -380,7 +381,7 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
UFE->closeFile();
// If we already have an entry with this inode, return it.
if (UFE->getName())
if (UFE->isValid())
return UFE;
}

View File

@ -130,7 +130,7 @@ void LogDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
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::HandleDiagnostic(DiagnosticsEngine::Level Level,
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 {

View File

@ -787,7 +787,7 @@ void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
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)";