r181477 - [doc parsing]: Also do typo correction for

Fariborz Jahanian fjahanian at apple.com
Wed May 8 15:14:28 PDT 2013


Author: fjahanian
Date: Wed May  8 17:14:28 2013
New Revision: 181477

URL: http://llvm.org/viewvc/llvm-project?rev=181477&view=rev
Log:
[doc parsing]: Also do typo correction for
dynamically registered commands. 
// rdar://12381408

Modified:
    cfe/trunk/lib/AST/CommentCommandTraits.cpp
    cfe/trunk/test/Sema/warn-documentation-fixits.cpp

Modified: cfe/trunk/lib/AST/CommentCommandTraits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentCommandTraits.cpp?rev=181477&r1=181476&r2=181477&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentCommandTraits.cpp (original)
+++ cfe/trunk/lib/AST/CommentCommandTraits.cpp Wed May  8 17:14:28 2013
@@ -43,30 +43,41 @@ const CommandInfo *CommandTraits::getCom
   return getRegisteredCommandInfo(CommandID);
 }
 
-const CommandInfo *
-CommandTraits::getTypoCorrectCommandInfo(StringRef Typo) const {
+static void
+HelperTypoCorrectCommandInfo(SmallVectorImpl<const CommandInfo *> &BestCommand,
+                             StringRef Typo, const CommandInfo *Command) {
   const unsigned MaxEditDistance = 1;
   unsigned BestEditDistance = MaxEditDistance + 1;
+  StringRef Name = Command->Name;
+  
+  unsigned MinPossibleEditDistance = abs((int)Name.size() - (int)Typo.size());
+  if (MinPossibleEditDistance > 0 &&
+      Typo.size() / MinPossibleEditDistance < 1)
+    return;
+  unsigned EditDistance = Typo.edit_distance(Name, true, MaxEditDistance);
+  if (EditDistance > MaxEditDistance)
+    return;
+  if (EditDistance == BestEditDistance)
+    BestCommand.push_back(Command);
+  else if (EditDistance < BestEditDistance) {
+    BestCommand.clear();
+    BestCommand.push_back(Command);
+    BestEditDistance = EditDistance;
+  }
+}
+
+const CommandInfo *
+CommandTraits::getTypoCorrectCommandInfo(StringRef Typo) const {
   SmallVector<const CommandInfo *, 2> BestCommand;
   
   int NumOfCommands = sizeof(Commands) / sizeof(CommandInfo);
-  for (int i = 0; i < NumOfCommands; i++) {
-    StringRef Name = Commands[i].Name;
-    unsigned MinPossibleEditDistance = abs((int)Name.size() - (int)Typo.size());
-    if (MinPossibleEditDistance > 0 &&
-        Typo.size() / MinPossibleEditDistance < 1)
-      continue;
-    unsigned EditDistance = Typo.edit_distance(Name, true, MaxEditDistance);
-    if (EditDistance > MaxEditDistance)
-      continue;
-    if (EditDistance == BestEditDistance)
-      BestCommand.push_back(&Commands[i]);
-    else if (EditDistance < BestEditDistance) {
-      BestCommand.clear();
-      BestCommand.push_back(&Commands[i]);
-      BestEditDistance = EditDistance;
-    }
-  }
+  for (int i = 0; i < NumOfCommands; i++)
+    HelperTypoCorrectCommandInfo(BestCommand, Typo, &Commands[i]);
+  
+  for (unsigned i = 0, e = RegisteredCommands.size(); i != e; ++i)
+    if (!RegisteredCommands[i]->IsUnknownCommand)
+      HelperTypoCorrectCommandInfo(BestCommand, Typo, RegisteredCommands[i]);
+  
   return (BestCommand.size() != 1) ? NULL : BestCommand[0];
 }
 

Modified: cfe/trunk/test/Sema/warn-documentation-fixits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation-fixits.cpp?rev=181477&r1=181476&r2=181477&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation-fixits.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation-fixits.cpp Wed May  8 17:14:28 2013
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -fcomment-block-commands=foobar -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -fcomment-block-commands=foobar -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 // expected-warning at +1 {{parameter 'ZZZZZZZZZZ' not found in the function declaration}} expected-note at +1 {{did you mean 'a'?}}
 /// \param ZZZZZZZZZZ Blah blah.
@@ -63,6 +63,10 @@ void test_deprecated_9(int a);
 /// \retur int in FooBar
 int FooBar();
 
+// expected-warning at +1  {{unknown command tag name 'fooba'; did you mean 'foobar'?}}
+/// \fooba bbb IS_DOXYGEN_END
+int gorf();
+
 // CHECK: fix-it:"{{.*}}":{5:12-5:22}:"a"
 // CHECK: fix-it:"{{.*}}":{9:12-9:15}:"aaa"
 // CHECK: fix-it:"{{.*}}":{13:13-13:23}:"T"
@@ -75,3 +79,4 @@ int FooBar();
 // CHECK: fix-it:"{{.*}}":{50:27-50:27}:" __attribute__((deprecated))"
 // CHECK: fix-it:"{{.*}}":{58:30-58:30}:" MY_ATTR_DEPRECATED"
 // CHECK: fix-it:"{{.*}}":{63:6-63:11}:"return"
+// CHECK: fix-it:"{{.*}}":{67:6-67:11}:"foobar"





More information about the cfe-commits mailing list