llvm.org GIT mirror llvm / 0fbb8da
Re-revert "[Option] Fix PR37006 prefix choice in findNearest" Summary: Reverting due to a test failure in an llvm-mt test on some buildbots, namely http://green.lab.llvm.org/green/job/clang-stage2-configure-Rlto/26020/. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332812 91177308-0d34-0410-b5e6-96231b3b80d8 Brian Gesiak 1 year, 2 months ago
3 changed file(s) with 25 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
251251 unsigned MinimumLength) const {
252252 assert(!Option.empty());
253253
254 // Consider each [option prefix + option name] pair as a candidate, finding
255 // the closest match.
254 // Consider each option as a candidate, finding the closest match.
256255 unsigned BestDistance = UINT_MAX;
257256 for (const Info &CandidateInfo :
258257 ArrayRef(OptionInfos).drop_front(FirstSearchableIndex)) {
259258 StringRef CandidateName = CandidateInfo.Name;
260259
261 // We can eliminate some option prefix/name pairs as candidates right away:
262 // * Ignore option candidates with empty names, such as "--", or names
263 // that do not meet the minimum length.
260 // Ignore option candidates with empty names, such as "--", or names
261 // that do not meet the minimum length.
264262 if (CandidateName.empty() || CandidateName.size() < MinimumLength)
265263 continue;
266264
267 // * If FlagsToInclude were specified, ignore options that don't include
268 // those flags.
265 // If FlagsToInclude were specified, ignore options that don't include
266 // those flags.
269267 if (FlagsToInclude && !(CandidateInfo.Flags & FlagsToInclude))
270268 continue;
271 // * Ignore options that contain the FlagsToExclude.
269 // Ignore options that contain the FlagsToExclude.
272270 if (CandidateInfo.Flags & FlagsToExclude)
273271 continue;
274272
275 // * Ignore positional argument option candidates (which do not
276 // have prefixes).
273 // Ignore positional argument option candidates (which do not
274 // have prefixes).
277275 if (!CandidateInfo.Prefixes)
278276 continue;
279
280 // Now check if the candidate ends with a character commonly used when
277 // Find the most appropriate prefix. For example, if a user asks for
278 // "--helm", suggest "--help" over "-help".
279 StringRef Prefix = CandidateInfo.Prefixes[0];
280 for (int P = 1; CandidateInfo.Prefixes[P]; P++) {
281 if (Option.startswith(CandidateInfo.Prefixes[P]))
282 Prefix = CandidateInfo.Prefixes[P];
283 }
284
285 // Check if the candidate ends with a character commonly used when
281286 // delimiting an option from its value, such as '=' or ':'. If it does,
282287 // attempt to split the given option based on that delimiter.
283288 std::string Delimiter = "";
291296 else
292297 std::tie(LHS, RHS) = Option.split(Last);
293298
294 // Consider each possible prefix for each candidate to find the most
295 // appropriate one. For example, if a user asks for "--helm", suggest
296 // "--help" over "-help".
297 for (int P = 0; const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) {
298 std::string NormalizedName = (LHS + Delimiter).str();
299 StringRef Candidate = (CandidatePrefix + CandidateName).str();
300 unsigned Distance =
301 Candidate.edit_distance(NormalizedName, /*AllowReplacements=*/true,
302 /*MaxEditDistance=*/BestDistance);
303 if (Distance < BestDistance) {
304 BestDistance = Distance;
305 NearestString = (Candidate + RHS).str();
306 }
299 std::string NormalizedName =
300 (LHS.drop_front(Prefix.size()) + Delimiter).str();
301 unsigned Distance =
302 CandidateName.edit_distance(NormalizedName, /*AllowReplacements=*/true,
303 /*MaxEditDistance=*/BestDistance);
304 if (Distance < BestDistance) {
305 BestDistance = Distance;
306 NearestString = (Prefix + CandidateName + RHS).str();
307307 }
308308 }
309309 return BestDistance;
282282 EXPECT_EQ(Nearest, "-blorp");
283283 EXPECT_EQ(1U, T.findNearest("--blorm", Nearest));
284284 EXPECT_EQ(Nearest, "--blorp");
285 EXPECT_EQ(1U, T.findNearest("-blarg", Nearest));
286 EXPECT_EQ(Nearest, "-blarn");
287 EXPECT_EQ(1U, T.findNearest("--blarm", Nearest));
288 EXPECT_EQ(Nearest, "--blarn");
289285 EXPECT_EQ(1U, T.findNearest("-fjormp", Nearest));
290286 EXPECT_EQ(Nearest, "--fjormp");
291287
2929 def SlurpJoined : Option<["-"], "slurpjoined", KIND_REMAINING_ARGS_JOINED>;
3030
3131 def Blorp : Flag<["-", "--"], "blorp">, HelpText<"The blorp option">, Flags<[OptFlag1]>;
32 def Blarn : Flag<["--", "-"], "blarn">, HelpText<"The blarn option">, Flags<[OptFlag1]>;
3332 def Cramb : Joined<["/"], "cramb:">, HelpText<"The cramb option">, MetaVarName<"CRAMB">, Flags<[OptFlag1]>;
3433 def Doopf1 : Flag<["-"], "doopf1">, HelpText<"The doopf1 option">, Flags<[OptFlag1]>;
3534 def Doopf2 : Flag<["-"], "doopf2">, HelpText<"The doopf2 option">, Flags<[OptFlag2]>;