From 116d8879e6e417d4bf437e4f191f2e86f7736384 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 14 Nov 2011 23:30:34 +0000 Subject: Print a typo correction hint for unknown warning flags. $ clang -Wololo t.c warning: unknown warning option '-Wololo'; did you mean '-Wall'? [-Wunknown-warning-option] llvm-svn: 144591 --- clang/lib/Basic/DiagnosticIDs.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'clang/lib/Basic/DiagnosticIDs.cpp') diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp index b14cdc9ba3d..39fee69adbe 100644 --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/lib/Basic/DiagnosticIDs.cpp @@ -681,6 +681,27 @@ bool DiagnosticIDs::getDiagnosticsInGroup( return false; } +StringRef DiagnosticIDs::getNearestWarningOption(StringRef Group) { + StringRef Best; + unsigned BestDistance = 0; + for (const WarningOption *i = OptionTable, *e = OptionTable + OptionTableSize; + i != e; ++i) { + // Don't suggest ignored warning flags. + if (!i->Members && !i->SubGroups) + continue; + + unsigned Distance = i->getName().edit_distance(Group, true, BestDistance); + + // Check if this is a better match. + if (Best.empty() || Distance < BestDistance) { + Best = i->getName(); + BestDistance = Distance; + } + } + + return Best; +} + /// ProcessDiag - This is the method used to report a diagnostic that is /// finally fully formed. bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const { -- cgit v1.2.3