[llvm] r184328 - Remove more uses of sys::Path.

Rafael Espindola rafael.espindola at gmail.com
Wed Jun 19 10:49:07 PDT 2013


Author: rafael
Date: Wed Jun 19 12:49:07 2013
New Revision: 184328

URL: http://llvm.org/viewvc/llvm-project?rev=184328&view=rev
Log:
Remove more uses of sys::Path.

Modified:
    llvm/trunk/tools/llvm-ar/Archive.cpp
    llvm/trunk/tools/llvm-ar/Archive.h
    llvm/trunk/tools/llvm-ar/ArchiveReader.cpp
    llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp
    llvm/trunk/tools/llvm-ar/llvm-ar.cpp

Modified: llvm/trunk/tools/llvm-ar/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/Archive.cpp?rev=184328&r1=184327&r2=184328&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/Archive.cpp (original)
+++ llvm/trunk/tools/llvm-ar/Archive.cpp Wed Jun 19 12:49:07 2013
@@ -67,7 +67,7 @@ ArchiveMember::ArchiveMember(Archive* PA
 // This method allows an ArchiveMember to be replaced with the data for a
 // different file, presumably as an update to the member. It also makes sure
 // the flags are reset correctly.
-bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
+bool ArchiveMember::replaceWith(StringRef newFile, std::string* ErrMsg) {
   bool Exists;
   if (sys::fs::exists(newFile.str(), Exists) || !Exists) {
     if (ErrMsg)
@@ -136,10 +136,9 @@ bool ArchiveMember::replaceWith(const sy
 // Archive constructor - this is the only constructor that gets used for the
 // Archive class. Everything else (default,copy) is deprecated. This just
 // initializes and maps the file into memory, if requested.
-Archive::Archive(const sys::Path& filename, LLVMContext& C)
-  : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
-    symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) {
-}
+Archive::Archive(StringRef filename, LLVMContext &C)
+    : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
+      symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) {}
 
 bool
 Archive::mapToMemory(std::string* ErrMsg) {

Modified: llvm/trunk/tools/llvm-ar/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/Archive.h?rev=184328&r1=184327&r2=184328&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/Archive.h (original)
+++ llvm/trunk/tools/llvm-ar/Archive.h Wed Jun 19 12:49:07 2013
@@ -152,7 +152,7 @@ class ArchiveMember : public ilist_node<
     /// be readable on entry to this method.
     /// @returns true if an error occurred, false otherwise
     /// @brief Replace contents of archive member with a new file.
-    bool replaceWith(const sys::Path &aFile, std::string* ErrMsg);
+    bool replaceWith(StringRef aFile, std::string* ErrMsg);
 
   /// @}
   /// @name Data
@@ -266,10 +266,10 @@ class Archive {
     /// the returned Archive object has at that time.
     /// @returns An Archive* that represents the new archive file.
     /// @brief Create an empty Archive.
-    static Archive* CreateEmpty(
-      const sys::Path& Filename,///< Name of the archive to (eventually) create.
-      LLVMContext& C            ///< Context to use for global information
-    );
+    static Archive *CreateEmpty(
+        StringRef Filename, ///< Name of the archive to (eventually) create.
+        LLVMContext &C      ///< Context to use for global information
+        );
 
     /// Open an existing archive and load its contents in preparation for
     /// editing. After this call, the member ilist is completely populated based
@@ -277,11 +277,11 @@ class Archive {
     /// you intend to modify the archive or traverse its contents (e.g. for
     /// printing).
     /// @brief Open and load an archive file
-    static Archive* OpenAndLoad(
-      const sys::Path& filePath,  ///< The file path to open and load
-      LLVMContext& C,       ///< The context to use for global information
-      std::string* ErrorMessage   ///< An optional error string
-    );
+    static Archive *OpenAndLoad(
+        StringRef filePath,       ///< The file path to open and load
+        LLVMContext &C,           ///< The context to use for global information
+        std::string *ErrorMessage ///< An optional error string
+        );
 
     /// This destructor cleans up the Archive object, releases all memory, and
     /// closes files. It does nothing with the archive file on disk. If you
@@ -296,7 +296,7 @@ class Archive {
   public:
     /// @returns the path to the archive file.
     /// @brief Get the archive path.
-    const sys::Path& getPath() { return archPath; }
+    StringRef getPath() { return archPath; }
 
     /// This method is provided so that editing methods can be invoked directly
     /// on the Archive's iplist of ArchiveMember. However, it is recommended
@@ -405,11 +405,10 @@ class Archive {
     /// given by \p where.
     /// @returns true if an error occurred, false otherwise
     /// @brief Add a file to the archive.
-    bool addFileBefore(
-      const sys::Path& filename, ///< The file to be added
-      iterator where,            ///< Insertion point
-      std::string* ErrMsg        ///< Optional error message location
-    );
+    bool addFileBefore(StringRef filename, ///< The file to be added
+                       iterator where,     ///< Insertion point
+                       std::string *ErrMsg ///< Optional error message location
+                       );
 
   /// @}
   /// @name Implementation
@@ -417,7 +416,7 @@ class Archive {
   protected:
     /// @brief Construct an Archive for \p filename and optionally  map it
     /// into memory.
-    explicit Archive(const sys::Path& filename, LLVMContext& C);
+    explicit Archive(StringRef filename, LLVMContext& C);
 
     /// @returns A fully populated ArchiveMember or 0 if an error occurred.
     /// @brief Parse the header of a member starting at \p At
@@ -477,7 +476,7 @@ class Archive {
   /// @name Data
   /// @{
   protected:
-    sys::Path archPath;       ///< Path to the archive file we read/write
+    std::string archPath;     ///< Path to the archive file we read/write
     MembersList members;      ///< The ilist of ArchiveMember
     MemoryBuffer *mapfile;    ///< Raw Archive contents mapped into memory
     const char* base;         ///< Base of the memory mapped file data

Modified: llvm/trunk/tools/llvm-ar/ArchiveReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/ArchiveReader.cpp?rev=184328&r1=184327&r2=184328&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/ArchiveReader.cpp (original)
+++ llvm/trunk/tools/llvm-ar/ArchiveReader.cpp Wed Jun 19 12:49:07 2013
@@ -265,9 +265,9 @@ Archive::loadArchive(std::string* error)
 
 // Open and completely load the archive file.
 Archive*
-Archive::OpenAndLoad(const sys::Path& File, LLVMContext& C,
+Archive::OpenAndLoad(StringRef File, LLVMContext& C,
                      std::string* ErrorMessage) {
-  OwningPtr<Archive> result ( new Archive(File, C));
+  OwningPtr<Archive> result(new Archive(File, C));
   if (result->mapToMemory(ErrorMessage))
     return NULL;
   if (!result->loadArchive(ErrorMessage))
@@ -282,8 +282,7 @@ Archive::getAllModules(std::vector<Modul
 
   for (iterator I=begin(), E=end(); I != E; ++I) {
     if (I->isBitcode()) {
-      std::string FullMemberName = archPath.str() +
-        "(" + I->getPath().str() + ")";
+      std::string FullMemberName = archPath + "(" + I->getPath().str() + ")";
       MemoryBuffer *Buffer =
         MemoryBuffer::getMemBufferCopy(StringRef(I->getData(), I->getSize()),
                                        FullMemberName.c_str());
@@ -395,8 +394,7 @@ Archive::findModuleDefiningSymbol(const
     return 0;
 
   // Now, load the bitcode module to get the Module.
-  std::string FullMemberName = archPath.str() + "(" +
-    mbr->getPath().str() + ")";
+  std::string FullMemberName = archPath + "(" + mbr->getPath().str() + ")";
   MemoryBuffer *Buffer =
     MemoryBuffer::getMemBufferCopy(StringRef(mbr->getData(), mbr->getSize()),
                                    FullMemberName.c_str());
@@ -445,8 +443,8 @@ Archive::findModulesDefiningSymbols(std:
       if (mbr->isBitcode()) {
         // Get the symbols
         std::vector<std::string> symbols;
-        std::string FullMemberName = archPath.str() + "(" +
-          mbr->getPath().str() + ")";
+        std::string FullMemberName =
+            archPath + "(" + mbr->getPath().str() + ")";
         Module* M = 
           GetBitcodeSymbols(At, mbr->getSize(), FullMemberName, Context,
                             symbols, error);
@@ -526,9 +524,8 @@ bool Archive::isBitcodeArchive() {
   for (iterator I = begin(), E = end(); I != E; ++I) {
     if (!I->isBitcode())
       continue;
-    
-    std::string FullMemberName = 
-      archPath.str() + "(" + I->getPath().str() + ")";
+
+    std::string FullMemberName = archPath + "(" + I->getPath().str() + ")";
 
     MemoryBuffer *Buffer =
       MemoryBuffer::getMemBufferCopy(StringRef(I->getData(), I->getSize()),

Modified: llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp?rev=184328&r1=184327&r2=184328&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp (original)
+++ llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp Wed Jun 19 12:49:07 2013
@@ -67,7 +67,7 @@ static inline unsigned numVbrBytes(unsig
 }
 
 // Create an empty archive.
-Archive* Archive::CreateEmpty(const sys::Path& FilePath, LLVMContext& C) {
+Archive* Archive::CreateEmpty(StringRef FilePath, LLVMContext& C) {
   Archive* result = new Archive(FilePath, C);
   return result;
 }
@@ -153,9 +153,8 @@ Archive::fillHeader(const ArchiveMember
 
 // Insert a file into the archive before some other member. This also takes care
 // of extracting the necessary flags and information from the file.
-bool
-Archive::addFileBefore(const sys::Path& filePath, iterator where,
-                        std::string* ErrMsg) {
+bool Archive::addFileBefore(StringRef filePath, iterator where,
+                            std::string *ErrMsg) {
   bool Exists;
   if (sys::fs::exists(filePath.str(), Exists) || !Exists) {
     if (ErrMsg)
@@ -231,8 +230,8 @@ Archive::writeMember(
   // symbol table if it's a bitcode file.
   if (CreateSymbolTable && member.isBitcode()) {
     std::vector<std::string> symbols;
-    std::string FullMemberName = archPath.str() + "(" + member.getPath().str()
-      + ")";
+    std::string FullMemberName =
+        (archPath + "(" + member.getPath() + ")").str();
     Module* M =
       GetBitcodeSymbols(data, fSize, FullMemberName, Context, symbols, ErrMsg);
 
@@ -305,7 +304,7 @@ Archive::writeToDisk(bool CreateSymbolTa
   }
 
   // Create a temporary file to store the archive in
-  sys::Path TmpArchive = archPath;
+  sys::Path TmpArchive(archPath);
   if (TmpArchive.createTemporaryFileOnDisk(ErrMsg))
     return true;
 
@@ -321,7 +320,7 @@ Archive::writeToDisk(bool CreateSymbolTa
   if (!ArchiveFile.is_open() || ArchiveFile.bad()) {
     TmpArchive.eraseFromDisk();
     if (ErrMsg)
-      *ErrMsg = "Error opening archive file: " + archPath.str();
+      *ErrMsg = "Error opening archive file: " + archPath;
     return true;
   }
 
@@ -355,7 +354,7 @@ Archive::writeToDisk(bool CreateSymbolTa
     // ensure compatibility with other archivers we need to put the symbol
     // table first in the file. Unfortunately, this means mapping the file
     // we just wrote back in and copying it to the destination file.
-    sys::Path FinalFilePath = archPath;
+    sys::Path FinalFilePath(archPath);
 
     // Map in the archive we just wrote.
     {
@@ -416,14 +415,14 @@ Archive::writeToDisk(bool CreateSymbolTa
   // this because we cannot replace an open file on Windows.
   cleanUpMemory();
 
-  if (TmpArchive.renamePathOnDisk(archPath, ErrMsg))
+  if (TmpArchive.renamePathOnDisk(sys::Path(archPath), ErrMsg))
     return true;
 
   // Set correct read and write permissions after temporary file is moved
   // to final destination path.
-  if (archPath.makeReadableOnDisk(ErrMsg))
+  if (sys::Path(archPath).makeReadableOnDisk(ErrMsg))
     return true;
-  if (archPath.makeWriteableOnDisk(ErrMsg))
+  if (sys::Path(archPath).makeWriteableOnDisk(ErrMsg))
     return true;
 
   return false;

Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=184328&r1=184327&r2=184328&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Wed Jun 19 12:49:07 2013
@@ -552,7 +552,7 @@ doQuickAppend(std::string* ErrMsg) {
   // Append them quickly.
   for (std::set<std::string>::iterator PI = Paths.begin(), PE = Paths.end();
        PI != PE; ++PI) {
-    if (TheArchive->addFileBefore(sys::Path(*PI),TheArchive->end(),ErrMsg))
+    if (TheArchive->addFileBefore(*PI, TheArchive->end(), ErrMsg))
       return true;
   }
 
@@ -620,11 +620,11 @@ doReplaceOrInsert(std::string* ErrMsg) {
         if (OnlyUpdate) {
           // Replace the item only if it is newer.
           if (si->modTime > I->getModTime())
-            if (I->replaceWith(sys::Path(*found), ErrMsg))
+            if (I->replaceWith(*found, ErrMsg))
               return true;
         } else {
           // Replace the item regardless of time stamp
-          if (I->replaceWith(sys::Path(*found), ErrMsg))
+          if (I->replaceWith(*found, ErrMsg))
             return true;
         }
       } else {
@@ -649,7 +649,7 @@ doReplaceOrInsert(std::string* ErrMsg) {
   if (!remaining.empty()) {
     for (std::set<std::string>::iterator PI = remaining.begin(),
          PE = remaining.end(); PI != PE; ++PI) {
-      if (TheArchive->addFileBefore(sys::Path(*PI),insert_spot, ErrMsg))
+      if (TheArchive->addFileBefore(*PI, insert_spot, ErrMsg))
         return true;
     }
   }
@@ -697,11 +697,11 @@ int main(int argc, char **argv) {
     // Produce a warning if we should and we're creating the archive
     if (!Create)
       errs() << argv[0] << ": creating " << ArchivePath.str() << "\n";
-    TheArchive = Archive::CreateEmpty(ArchivePath, Context);
+    TheArchive = Archive::CreateEmpty(ArchivePath.str(), Context);
     TheArchive->writeToDisk();
   } else {
     std::string Error;
-    TheArchive = Archive::OpenAndLoad(ArchivePath, Context, &Error);
+    TheArchive = Archive::OpenAndLoad(ArchivePath.str(), Context, &Error);
     if (TheArchive == 0) {
       errs() << argv[0] << ": error loading '" << ArchivePath.str() << "': "
              << Error << "!\n";





More information about the llvm-commits mailing list