summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-mt/llvm-mt.cpp
diff options
context:
space:
mode:
authorBrian Gesiak <modocache@gmail.com>2018-01-05 17:10:39 +0000
committerBrian Gesiak <modocache@gmail.com>2018-01-05 17:10:39 +0000
commit7b84de792b49e97e5c860af13d52aed8553b6e70 (patch)
tree3c0ede1392baec655c8997ba479b1e6439714812 /llvm/tools/llvm-mt/llvm-mt.cpp
parentb845fe649ff66bf3c9abd35216dd985af3794b46 (diff)
downloadbcm5719-llvm-7b84de792b49e97e5c860af13d52aed8553b6e70.tar.gz
bcm5719-llvm-7b84de792b49e97e5c860af13d52aed8553b6e70.zip
[Option] Add 'findNearest' method to catch typos
Summary: Add a method `OptTable::findNearest`, which allows users of OptTable to check user input for misspelled options. In addition, have llvm-mt check for misspelled options. For example, if a user invokes `llvm-mt /oyt:foo`, the error message will indicate that while an option named `/oyt:` does not exist, `/out:` does. The method ports the functionality of the `LookupNearestOption` method from LLVM CommandLine to libLLVMOption. This allows tools like Clang and Swift, which do not use CommandLine, to use this functionality to suggest similarly spelled options. As room for future improvement, the new method as-is cannot yet properly suggest nearby "joined" options -- that is, for an option string "-FozBar", where "-Foo" is the correct option name and "Bar" is the value being passed along with the misspelled option, this method will calculate an edit distance of 4, by deleting "Bar" and changing "z" to "o". It should instead calculate an edit distance of just 1, by changing "z" to "o" and recognizing "Bar" as a value. This commit includes a disabled test that expresses this limitation. Test Plan: `check-llvm` Reviewers: yamaguchi, v.g.vassilev, teemperor, ruiu, jroelofs Reviewed By: jroelofs Subscribers: jroelofs, llvm-commits Differential Revision: https://reviews.llvm.org/D41732 llvm-svn: 321877
Diffstat (limited to 'llvm/tools/llvm-mt/llvm-mt.cpp')
-rw-r--r--llvm/tools/llvm-mt/llvm-mt.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/tools/llvm-mt/llvm-mt.cpp b/llvm/tools/llvm-mt/llvm-mt.cpp
index 944af22cf9c..f95745e14f1 100644
--- a/llvm/tools/llvm-mt/llvm-mt.cpp
+++ b/llvm/tools/llvm-mt/llvm-mt.cpp
@@ -103,8 +103,18 @@ int main(int argc, const char **argv) {
ArrayRef<const char *> ArgsArr = makeArrayRef(argv + 1, argc);
opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
- for (auto *Arg : InputArgs.filtered(OPT_INPUT))
- reportError(Twine("invalid option ") + Arg->getSpelling());
+ for (auto *Arg : InputArgs.filtered(OPT_INPUT)) {
+ auto ArgString = Arg->getAsString(InputArgs);
+ std::string Diag;
+ raw_string_ostream OS(Diag);
+ OS << "invalid option '" << ArgString << "'";
+
+ std::string Nearest;
+ if (T.findNearest(ArgString, Nearest) < 2)
+ OS << ", did you mean '" << Nearest << "'?";
+
+ reportError(OS.str());
+ }
for (auto &Arg : InputArgs) {
if (Arg->getOption().matches(OPT_unsupported)) {
OpenPOWER on IntegriCloud