summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/CommentCommandTraits.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-05-08 22:14:28 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-05-08 22:14:28 +0000
commitaa9b280c79bcf4addb3e3d5c70e8fe08110c5e4c (patch)
tree6497b1074d600ddaa6976986694000029044c52a /clang/lib/AST/CommentCommandTraits.cpp
parentabdd7f197a9cbca7d4001ee0f19152ac509676ee (diff)
downloadbcm5719-llvm-aa9b280c79bcf4addb3e3d5c70e8fe08110c5e4c.tar.gz
bcm5719-llvm-aa9b280c79bcf4addb3e3d5c70e8fe08110c5e4c.zip
[doc parsing]: Also do typo correction for
dynamically registered commands. // rdar://12381408 llvm-svn: 181477
Diffstat (limited to 'clang/lib/AST/CommentCommandTraits.cpp')
-rw-r--r--clang/lib/AST/CommentCommandTraits.cpp49
1 files changed, 30 insertions, 19 deletions
diff --git a/clang/lib/AST/CommentCommandTraits.cpp b/clang/lib/AST/CommentCommandTraits.cpp
index e4cc84afb78..dc4744a53c5 100644
--- a/clang/lib/AST/CommentCommandTraits.cpp
+++ b/clang/lib/AST/CommentCommandTraits.cpp
@@ -43,30 +43,41 @@ const CommandInfo *CommandTraits::getCommandInfo(unsigned CommandID) const {
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];
}
OpenPOWER on IntegriCloud