[lld] r319787 - toString function take a const refs where possible

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 08:50:47 PST 2017


Author: sbc
Date: Tue Dec  5 08:50:46 2017
New Revision: 319787

URL: http://llvm.org/viewvc/llvm-project?rev=319787&view=rev
Log:
toString function take a const refs where possible

Differential Revision: https://reviews.llvm.org/D40824

Modified:
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/COFF/InputFiles.h
    lld/trunk/Common/Reproduce.cpp
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/DriverUtils.cpp
    lld/trunk/include/lld/Common/Reproduce.h
    lld/trunk/wasm/InputFiles.cpp
    lld/trunk/wasm/InputFiles.h
    lld/trunk/wasm/Symbols.cpp
    lld/trunk/wasm/Symbols.h

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Tue Dec  5 08:50:46 2017
@@ -426,7 +426,7 @@ static std::string createResponseFile(co
     case OPT_manifestuac:
       break;
     default:
-      OS << toString(Arg) << "\n";
+      OS << toString(*Arg) << "\n";
     }
   }
 
@@ -674,7 +674,7 @@ void LinkerDriver::invokeMSVC(opt::Input
       break;
     case OPT_opt:
       if (!StringRef(Arg->getValue()).startswith("lld"))
-        Rsp += toString(Arg) + " ";
+        Rsp += toString(*Arg) + " ";
       break;
     case OPT_INPUT: {
       if (Optional<StringRef> Path = doFindFile(Arg->getValue())) {
@@ -686,7 +686,7 @@ void LinkerDriver::invokeMSVC(opt::Input
       break;
     }
     default:
-      Rsp += toString(Arg) + "\n";
+      Rsp += toString(*Arg) + "\n";
     }
   }
 

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Tue Dec  5 08:50:46 2017
@@ -493,7 +493,7 @@ static StringRef getBasename(StringRef P
 }
 
 // Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
-std::string lld::toString(coff::InputFile *File) {
+std::string lld::toString(const coff::InputFile *File) {
   if (!File)
     return "<internal>";
   if (File->ParentName.empty())

Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Tue Dec  5 08:50:46 2017
@@ -58,7 +58,7 @@ public:
   virtual ~InputFile() {}
 
   // Returns the filename.
-  StringRef getName() { return MB.getBufferIdentifier(); }
+  StringRef getName() const { return MB.getBufferIdentifier(); }
 
   // Reads a file (the constructor doesn't do that).
   virtual void parse() = 0;
@@ -229,7 +229,7 @@ private:
 };
 } // namespace coff
 
-std::string toString(coff::InputFile *File);
+std::string toString(const coff::InputFile *File);
 } // namespace lld
 
 #endif

Modified: lld/trunk/Common/Reproduce.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/Reproduce.cpp?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/Common/Reproduce.cpp (original)
+++ lld/trunk/Common/Reproduce.cpp Tue Dec  5 08:50:46 2017
@@ -55,12 +55,12 @@ std::string lld::rewritePath(StringRef S
   return S;
 }
 
-std::string lld::toString(opt::Arg *Arg) {
-  std::string K = Arg->getSpelling();
-  if (Arg->getNumValues() == 0)
+std::string lld::toString(const opt::Arg &Arg) {
+  std::string K = Arg.getSpelling();
+  if (Arg.getNumValues() == 0)
     return K;
-  std::string V = quote(Arg->getValue());
-  if (Arg->getOption().getRenderStyle() == opt::Option::RenderJoinedStyle)
+  std::string V = quote(Arg.getValue());
+  if (Arg.getOption().getRenderStyle() == opt::Option::RenderJoinedStyle)
     return K + V;
   return K + " " + V;
 }

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Dec  5 08:50:46 2017
@@ -493,7 +493,7 @@ static StripPolicy getStrip(opt::InputAr
   return StripPolicy::Debug;
 }
 
-static uint64_t parseSectionAddress(StringRef S, opt::Arg *Arg) {
+static uint64_t parseSectionAddress(StringRef S, const opt::Arg &Arg) {
   uint64_t VA = 0;
   if (S.startswith("0x"))
     S = S.drop_front(2);
@@ -508,15 +508,15 @@ static StringMap<uint64_t> getSectionSta
     StringRef Name;
     StringRef Addr;
     std::tie(Name, Addr) = StringRef(Arg->getValue()).split('=');
-    Ret[Name] = parseSectionAddress(Addr, Arg);
+    Ret[Name] = parseSectionAddress(Addr, *Arg);
   }
 
   if (auto *Arg = Args.getLastArg(OPT_Ttext))
-    Ret[".text"] = parseSectionAddress(Arg->getValue(), Arg);
+    Ret[".text"] = parseSectionAddress(Arg->getValue(), *Arg);
   if (auto *Arg = Args.getLastArg(OPT_Tdata))
-    Ret[".data"] = parseSectionAddress(Arg->getValue(), Arg);
+    Ret[".data"] = parseSectionAddress(Arg->getValue(), *Arg);
   if (auto *Arg = Args.getLastArg(OPT_Tbss))
-    Ret[".bss"] = parseSectionAddress(Arg->getValue(), Arg);
+    Ret[".bss"] = parseSectionAddress(Arg->getValue(), *Arg);
   return Ret;
 }
 

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Tue Dec  5 08:50:46 2017
@@ -166,7 +166,7 @@ std::string elf::createResponseFile(cons
          << "\n";
       break;
     default:
-      OS << toString(Arg) << "\n";
+      OS << toString(*Arg) << "\n";
     }
   }
   return Data.str();

Modified: lld/trunk/include/lld/Common/Reproduce.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/Reproduce.h?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/include/lld/Common/Reproduce.h (original)
+++ lld/trunk/include/lld/Common/Reproduce.h Tue Dec  5 08:50:46 2017
@@ -33,7 +33,7 @@ std::string quote(StringRef S);
 std::string rewritePath(StringRef S);
 
 // Returns the string form of the given argument.
-std::string toString(llvm::opt::Arg *Arg);
+std::string toString(const llvm::opt::Arg &Arg);
 }
 
 #endif

Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Tue Dec  5 08:50:46 2017
@@ -264,7 +264,7 @@ void ArchiveFile::addMember(const Archiv
 }
 
 // Returns a string in the format of "foo.o" or "foo.a(bar.o)".
-std::string lld::toString(wasm::InputFile *File) {
+std::string lld::toString(const wasm::InputFile *File) {
   if (!File)
     return "<internal>";
 

Modified: lld/trunk/wasm/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.h?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.h (original)
+++ lld/trunk/wasm/InputFiles.h Tue Dec  5 08:50:46 2017
@@ -143,7 +143,7 @@ llvm::Optional<MemoryBufferRef> readFile
 
 } // namespace wasm
 
-std::string toString(wasm::InputFile *File);
+std::string toString(const wasm::InputFile *File);
 
 } // namespace lld
 

Modified: lld/trunk/wasm/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.cpp?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.cpp (original)
+++ lld/trunk/wasm/Symbols.cpp Tue Dec  5 08:50:46 2017
@@ -76,11 +76,11 @@ bool Symbol::isWeak() const { return Sym
 
 bool Symbol::isHidden() const { return Sym && Sym->isHidden(); }
 
-std::string lld::toString(wasm::Symbol &Sym) {
+std::string lld::toString(const wasm::Symbol &Sym) {
   return wasm::displayName(Sym.getName());
 }
 
-std::string lld::toString(wasm::Symbol::Kind &Kind) {
+std::string lld::toString(wasm::Symbol::Kind Kind) {
   switch (Kind) {
   case wasm::Symbol::DefinedFunctionKind:
     return "DefinedFunction";

Modified: lld/trunk/wasm/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.h?rev=319787&r1=319786&r2=319787&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.h (original)
+++ lld/trunk/wasm/Symbols.h Tue Dec  5 08:50:46 2017
@@ -111,8 +111,8 @@ protected:
 } // namespace wasm
 
 // Returns a symbol name for an error message.
-std::string toString(wasm::Symbol &Sym);
-std::string toString(wasm::Symbol::Kind &Kind);
+std::string toString(const wasm::Symbol &Sym);
+std::string toString(wasm::Symbol::Kind Kind);
 
 } // namespace lld
 




More information about the llvm-commits mailing list