aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Option/OptTable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r--llvm/lib/Option/OptTable.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index 16404d3..2b7fcf5 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -6,14 +6,15 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Option/OptTable.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
-#include "llvm/Option/Option.h"
#include "llvm/Option/OptSpecifier.h"
-#include "llvm/Option/OptTable.h"
+#include "llvm/Option/Option.h"
+#include "llvm/Support/CommandLine.h" // for expandResponseFiles
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
@@ -490,6 +491,33 @@ InputArgList OptTable::ParseArgs(ArrayRef<const char *> ArgArr,
return Args;
}
+InputArgList OptTable::parseArgs(int Argc, char *const *Argv,
+ OptSpecifier Unknown, StringSaver &Saver,
+ function_ref<void(StringRef)> ErrorFn) const {
+ SmallVector<const char *, 0> NewArgv;
+ // The environment variable specifies initial options which can be overridden
+ // by commnad line options.
+ cl::expandResponseFiles(Argc, Argv, EnvVar, Saver, NewArgv);
+
+ unsigned MAI, MAC;
+ opt::InputArgList Args = ParseArgs(makeArrayRef(NewArgv), MAI, MAC);
+ if (MAC)
+ ErrorFn((Twine(Args.getArgString(MAI)) + ": missing argument").str());
+
+ // For each unknwon option, call ErrorFn with a formatted error message. The
+ // message includes a suggested alternative option spelling if available.
+ std::string Nearest;
+ for (const opt::Arg *A : Args.filtered(Unknown)) {
+ std::string Spelling = A->getAsString(Args);
+ if (findNearest(Spelling, Nearest) > 1)
+ ErrorFn("unknown argument '" + A->getAsString(Args) + "'");
+ else
+ ErrorFn("unknown argument '" + A->getAsString(Args) +
+ "', did you mean '" + Nearest + "'?");
+ }
+ return Args;
+}
+
static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) {
const Option O = Opts.getOption(Id);
std::string Name = O.getPrefixedName();