Modify ParseArgs to return the InputArgList by value - there's no need for dynamic allocation/ownership here

The one caller that does anything other than keep this variable on the
stack is the single use of DerivedArgList in Clang, which is a bit more
interesting but can probably be cleaned up/simplified a bit further
(have DerivedArgList take ownership of the InputArgList rather than
needing to reference its Args indirectly) which I'll try to after this.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240345 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie
2015-06-22 22:06:37 +00:00
parent cf300d8b0e
commit 0c17f95006
5 changed files with 115 additions and 96 deletions

View File

@@ -113,27 +113,27 @@ int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
LibOptTable Table;
unsigned MissingIndex;
unsigned MissingCount;
std::unique_ptr<llvm::opt::InputArgList> Args(
Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount));
llvm::opt::InputArgList Args =
Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount);
if (MissingCount) {
llvm::errs() << "missing arg value for \""
<< Args->getArgString(MissingIndex)
<< "\", expected " << MissingCount
<< Args.getArgString(MissingIndex) << "\", expected "
<< MissingCount
<< (MissingCount == 1 ? " argument.\n" : " arguments.\n");
return 1;
}
for (auto *Arg : Args->filtered(OPT_UNKNOWN))
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
llvm::errs() << "ignoring unknown argument: " << Arg->getSpelling() << "\n";
if (Args->filtered_begin(OPT_INPUT) == Args->filtered_end()) {
if (Args.filtered_begin(OPT_INPUT) == Args.filtered_end()) {
llvm::errs() << "no input files.\n";
return 1;
}
std::vector<StringRef> SearchPaths = getSearchPaths(Args.get(), Saver);
std::vector<StringRef> SearchPaths = getSearchPaths(&Args, Saver);
std::vector<llvm::NewArchiveIterator> Members;
for (auto *Arg : Args->filtered(OPT_INPUT)) {
for (auto *Arg : Args.filtered(OPT_INPUT)) {
Optional<std::string> Path = findInputFile(Arg->getValue(), SearchPaths);
if (!Path.hasValue()) {
llvm::errs() << Arg->getValue() << ": no such file or directory\n";
@@ -143,8 +143,8 @@ int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
llvm::sys::path::filename(Arg->getValue()));
}
std::pair<StringRef, std::error_code> Result = llvm::writeArchive(
getOutputPath(Args.get()), Members, /*WriteSymtab=*/true);
std::pair<StringRef, std::error_code> Result =
llvm::writeArchive(getOutputPath(&Args), Members, /*WriteSymtab=*/true);
if (Result.second) {
if (Result.first.empty())
Result.first = ArgsArr[0];