diff options
| author | David Blaikie <dblaikie@gmail.com> | 2015-06-22 22:06:37 +0000 |
|---|---|---|
| committer | David Blaikie <dblaikie@gmail.com> | 2015-06-22 22:06:37 +0000 |
| commit | db3d31d0be935559fae6cc1b4d850a7e638a464e (patch) | |
| tree | f106dc61feaa45cfa9b362a9d875edd04e0c6d30 /llvm/lib | |
| parent | 69533a5a85cca7c89a68f794eb0355f605131adc (diff) | |
| download | bcm5719-llvm-db3d31d0be935559fae6cc1b4d850a7e638a464e.tar.gz bcm5719-llvm-db3d31d0be935559fae6cc1b4d850a7e638a464e.zip | |
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.
llvm-svn: 240345
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/LibDriver/LibDriver.cpp | 20 | ||||
| -rw-r--r-- | llvm/lib/Option/OptTable.cpp | 22 |
2 files changed, 21 insertions, 21 deletions
diff --git a/llvm/lib/LibDriver/LibDriver.cpp b/llvm/lib/LibDriver/LibDriver.cpp index e441fe84c39..9f2b12f75b8 100644 --- a/llvm/lib/LibDriver/LibDriver.cpp +++ b/llvm/lib/LibDriver/LibDriver.cpp @@ -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]; diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index cec1717454f..2160b15c1cf 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -247,12 +247,12 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index, return new Arg(getOption(TheUnknownOptionID), Str, Index++, Str); } -InputArgList *OptTable::ParseArgs(ArrayRef<const char *> ArgArr, - unsigned &MissingArgIndex, - unsigned &MissingArgCount, - unsigned FlagsToInclude, - unsigned FlagsToExclude) const { - InputArgList *Args = new InputArgList(ArgArr.begin(), ArgArr.end()); +InputArgList OptTable::ParseArgs(ArrayRef<const char *> ArgArr, + unsigned &MissingArgIndex, + unsigned &MissingArgCount, + unsigned FlagsToInclude, + unsigned FlagsToExclude) const { + InputArgList Args(ArgArr.begin(), ArgArr.end()); // FIXME: Handle '@' args (or at least error on them). @@ -260,19 +260,19 @@ InputArgList *OptTable::ParseArgs(ArrayRef<const char *> ArgArr, unsigned Index = 0, End = ArgArr.size(); while (Index < End) { // Ingore nullptrs, they are response file's EOL markers - if (Args->getArgString(Index) == nullptr) { + if (Args.getArgString(Index) == nullptr) { ++Index; continue; } // Ignore empty arguments (other things may still take them as arguments). - StringRef Str = Args->getArgString(Index); + StringRef Str = Args.getArgString(Index); if (Str == "") { ++Index; continue; } unsigned Prev = Index; - Arg *A = ParseOneArg(*Args, Index, FlagsToInclude, FlagsToExclude); + Arg *A = ParseOneArg(Args, Index, FlagsToInclude, FlagsToExclude); assert(Index > Prev && "Parser failed to consume argument."); // Check for missing argument error. @@ -284,10 +284,10 @@ InputArgList *OptTable::ParseArgs(ArrayRef<const char *> ArgArr, break; } - Args->append(A); + Args.append(A); } - return Args; + return std::move(Args); } static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) { |

