forked from OSchip/llvm-project
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:
parent
955fe6f6ed
commit
c8a71468b7
|
@ -66,6 +66,7 @@ class FileEntry {
|
||||||
llvm::sys::fs::UniqueID UniqueID;
|
llvm::sys::fs::UniqueID UniqueID;
|
||||||
bool IsNamedPipe;
|
bool IsNamedPipe;
|
||||||
bool InPCH;
|
bool InPCH;
|
||||||
|
bool IsValid; // Is this \c FileEntry initialized and valid?
|
||||||
|
|
||||||
/// \brief The open file, if it is owned by the \p FileEntry.
|
/// \brief The open file, if it is owned by the \p FileEntry.
|
||||||
mutable OwningPtr<vfs::File> File;
|
mutable OwningPtr<vfs::File> File;
|
||||||
|
@ -77,11 +78,13 @@ class FileEntry {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileEntry(llvm::sys::fs::UniqueID UniqueID, bool IsNamedPipe, bool InPCH)
|
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
|
// Add a default constructor for use with llvm::StringMap
|
||||||
FileEntry()
|
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) {
|
FileEntry(const FileEntry &FE) {
|
||||||
|
@ -95,6 +98,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *getName() const { return Name; }
|
const char *getName() const { return Name; }
|
||||||
|
bool isValid() const { return IsValid; }
|
||||||
off_t getSize() const { return Size; }
|
off_t getSize() const { return Size; }
|
||||||
unsigned getUID() const { return UID; }
|
unsigned getUID() const { return UID; }
|
||||||
const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; }
|
const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; }
|
||||||
|
|
|
@ -314,7 +314,7 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
|
||||||
UniqueRealFiles.getFile(Data.UniqueID, Data.IsNamedPipe, Data.InPCH);
|
UniqueRealFiles.getFile(Data.UniqueID, Data.IsNamedPipe, Data.InPCH);
|
||||||
|
|
||||||
NamedFileEnt.setValue(&UFE);
|
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 the stat process opened the file, close it to avoid a FD leak.
|
||||||
if (F)
|
if (F)
|
||||||
delete F;
|
delete F;
|
||||||
|
@ -331,6 +331,7 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
|
||||||
UFE.Dir = DirInfo;
|
UFE.Dir = DirInfo;
|
||||||
UFE.UID = NextFileUID++;
|
UFE.UID = NextFileUID++;
|
||||||
UFE.File.reset(F);
|
UFE.File.reset(F);
|
||||||
|
UFE.IsValid = true;
|
||||||
return &UFE;
|
return &UFE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +381,7 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
|
||||||
UFE->closeFile();
|
UFE->closeFile();
|
||||||
|
|
||||||
// If we already have an entry with this inode, return it.
|
// If we already have an entry with this inode, return it.
|
||||||
if (UFE->getName())
|
if (UFE->isValid())
|
||||||
return UFE;
|
return UFE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ void LogDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
||||||
FileID FID = SM.getMainFileID();
|
FileID FID = SM.getMainFileID();
|
||||||
if (!FID.isInvalid()) {
|
if (!FID.isInvalid()) {
|
||||||
const FileEntry *FE = SM.getFileEntryForID(FID);
|
const FileEntry *FE = SM.getFileEntryForID(FID);
|
||||||
if (FE && FE->getName())
|
if (FE && FE->isValid())
|
||||||
MainFilename = FE->getName();
|
MainFilename = FE->getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ void LogDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
||||||
FileID FID = SM.getFileID(Info.getLocation());
|
FileID FID = SM.getFileID(Info.getLocation());
|
||||||
if (!FID.isInvalid()) {
|
if (!FID.isInvalid()) {
|
||||||
const FileEntry *FE = SM.getFileEntryForID(FID);
|
const FileEntry *FE = SM.getFileEntryForID(FID);
|
||||||
if (FE && FE->getName())
|
if (FE && FE->isValid())
|
||||||
DE.Filename = FE->getName();
|
DE.Filename = FE->getName();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -787,7 +787,7 @@ void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
|
||||||
FileID FID = SM.getFileID(Loc);
|
FileID FID = SM.getFileID(Loc);
|
||||||
if (!FID.isInvalid()) {
|
if (!FID.isInvalid()) {
|
||||||
const FileEntry* FE = SM.getFileEntryForID(FID);
|
const FileEntry* FE = SM.getFileEntryForID(FID);
|
||||||
if (FE && FE->getName()) {
|
if (FE && FE->isValid()) {
|
||||||
OS << FE->getName();
|
OS << FE->getName();
|
||||||
if (FE->isInPCH())
|
if (FE->isInPCH())
|
||||||
OS << " (in PCH)";
|
OS << " (in PCH)";
|
||||||
|
|
Loading…
Reference in New Issue