toString function take a const refs where possible

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

llvm-svn: 319787
This commit is contained in:
Sam Clegg 2017-12-05 16:50:46 +00:00
parent 20569e96e9
commit 7e7566323d
11 changed files with 24 additions and 24 deletions

View File

@ -426,7 +426,7 @@ static std::string createResponseFile(const opt::InputArgList &Args,
case OPT_manifestuac:
break;
default:
OS << toString(Arg) << "\n";
OS << toString(*Arg) << "\n";
}
}
@ -674,7 +674,7 @@ void LinkerDriver::invokeMSVC(opt::InputArgList &Args) {
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::InputArgList &Args) {
break;
}
default:
Rsp += toString(Arg) + "\n";
Rsp += toString(*Arg) + "\n";
}
}

View File

@ -493,7 +493,7 @@ static StringRef getBasename(StringRef Path) {
}
// 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())

View File

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

View File

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

View File

@ -493,7 +493,7 @@ static StripPolicy getStrip(opt::InputArgList &Args) {
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> getSectionStartMap(opt::InputArgList &Args) {
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;
}

View File

@ -166,7 +166,7 @@ std::string elf::createResponseFile(const opt::InputArgList &Args) {
<< "\n";
break;
default:
OS << toString(Arg) << "\n";
OS << toString(*Arg) << "\n";
}
}
return Data.str();

View File

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

View File

@ -264,7 +264,7 @@ void ArchiveFile::addMember(const Archive::Symbol *Sym) {
}
// 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>";

View File

@ -143,7 +143,7 @@ llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
} // namespace wasm
std::string toString(wasm::InputFile *File);
std::string toString(const wasm::InputFile *File);
} // namespace lld

View File

@ -76,11 +76,11 @@ bool Symbol::isWeak() const { return Sym && Sym->isWeak(); }
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";

View File

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