]> granicus.if.org Git - clang/commitdiff
Split FileEntry name vs. isValid
authorBen Langmuir <blangmuir@apple.com>
Thu, 27 Feb 2014 17:23:33 +0000 (17:23 +0000)
committerBen Langmuir <blangmuir@apple.com>
Thu, 27 Feb 2014 17:23:33 +0000 (17:23 +0000)
This is a small bit of refactoring in preparation for FileEntry owning
the storage for its own name.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202412 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/FileManager.h
lib/Basic/FileManager.cpp
lib/Frontend/LogDiagnosticPrinter.cpp
lib/Frontend/TextDiagnostic.cpp

index 6e345b20b397ce1e337f4105d6231260542c3667..bd85318e2ffccc6110df6f1c7419e4e2b93c5c7a 100644 (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; }
index efc08aac96de5f2ffaaa30196f0719730f94c055..d019686b772e67d71a6ab966678f0a16bc0fe3a7 100644 (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;
   }
 
index 2189b8658ed2aa2051ada6807425e8a6227d71cf..6e09a8180c9ef74c8fdb648afa148f5a45fb49d8 100644 (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 {
index a2dc9537bc05ca6611e836eed519ffe9141a3fa3..79f05c6ecd5d9c32e88f2d29cb32cbad4c22f151 100644 (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)";