[PATCH] D61382: Option spell checking: Penalize delimiter flags if input has no argument
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 1 09:43:17 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359701: Option spell checking: Penalize delimiter flags if input has no argument (authored by nico, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D61382?vs=197556&id=197574#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61382/new/
https://reviews.llvm.org/D61382
Files:
llvm/trunk/lib/Option/OptTable.cpp
llvm/trunk/unittests/Option/OptionParsingTest.cpp
llvm/trunk/unittests/Option/Opts.td
Index: llvm/trunk/lib/Option/OptTable.cpp
===================================================================
--- llvm/trunk/lib/Option/OptTable.cpp
+++ llvm/trunk/lib/Option/OptTable.cpp
@@ -301,6 +301,15 @@
unsigned Distance =
CandidateRef.edit_distance(NormalizedName, /*AllowReplacements=*/true,
/*MaxEditDistance=*/BestDistance);
+ if (RHS.empty() && CandidateHasDelimiter) {
+ // The Candidate ends with a = or : delimiter, but the option passed in
+ // didn't contain the delimiter (or doesn't have anything after it).
+ // In that case, penalize the correction: `-nodefaultlibs` is more
+ // likely to be a spello for `-nodefaultlib` than `-nodefaultlib:` even
+ // though both have an unmodified editing distance of 1, since the
+ // latter would need an argument.
+ ++Distance;
+ }
if (Distance < BestDistance) {
BestDistance = Distance;
NearestString = (Candidate + RHS).str();
Index: llvm/trunk/unittests/Option/OptionParsingTest.cpp
===================================================================
--- llvm/trunk/unittests/Option/OptionParsingTest.cpp
+++ llvm/trunk/unittests/Option/OptionParsingTest.cpp
@@ -298,10 +298,19 @@
EXPECT_EQ(1U, T.findNearest("/framb:foo", Nearest));
EXPECT_EQ(Nearest, "/cramb:foo");
- // `--glormp` should have an editing distance of 1 to `--glormp=`.
- EXPECT_EQ(1U, T.findNearest("--glormp", Nearest));
- EXPECT_EQ(Nearest, "--glormp=");
- EXPECT_EQ(0U, T.findNearest("--glormp=foo", Nearest));
+ // `--glormp` should have an editing distance > 0 from `--glormp=`.
+ EXPECT_GT(T.findNearest("--glorrmp", Nearest), 0U);
+ EXPECT_EQ(Nearest, "--glorrmp=");
+ EXPECT_EQ(0U, T.findNearest("--glorrmp=foo", Nearest));
+
+ // `--blurmps` should correct to `--blurmp`, not `--blurmp=`, even though
+ // both naively have an editing distance of 1.
+ EXPECT_EQ(1U, T.findNearest("--blurmps", Nearest));
+ EXPECT_EQ(Nearest, "--blurmp");
+
+ // ...but `--blurmps=foo` should correct to `--blurmp=foo`.
+ EXPECT_EQ(1U, T.findNearest("--blurmps=foo", Nearest));
+ EXPECT_EQ(Nearest, "--blurmp=foo");
// Flags should be included and excluded as specified.
EXPECT_EQ(1U, T.findNearest("-doopf", Nearest, /*FlagsToInclude=*/OptFlag2));
Index: llvm/trunk/unittests/Option/Opts.td
===================================================================
--- llvm/trunk/unittests/Option/Opts.td
+++ llvm/trunk/unittests/Option/Opts.td
@@ -37,6 +37,9 @@
def Ermgh : Joined<["--"], "ermgh">, HelpText<"The ermgh option">, MetaVarName<"ERMGH">, Flags<[OptFlag1]>;
def Fjormp : Flag<["--"], "fjormp">, HelpText<"The fjormp option">, Flags<[OptFlag1]>;
-def Glormp_eq : Flag<["--"], "glormp=">;
+def Glorrmp_eq : Flag<["--"], "glorrmp=">;
+
+def Blurmpq : Flag<["--"], "blurmp">;
+def Blurmpq_eq : Flag<["--"], "blurmp=">;
def DashDash : Option<["--"], "", KIND_REMAINING_ARGS>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61382.197574.patch
Type: text/x-patch
Size: 2979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190501/d026b897/attachment.bin>
More information about the llvm-commits
mailing list