10#include "llvm/ADT/STLExtras.h"
16#include "clang/AST/CommentCommandInfo.inc"
20 : NextID(
std::size(Commands)), Allocator(Allocator) {
26 for (CommentOptions::BlockCommandNamesTy::const_iterator
37 return getRegisteredCommandInfo(Name);
43 return getRegisteredCommandInfo(CommandID);
54 const unsigned MaxEditDistance = 1;
56 unsigned BestEditDistance = MaxEditDistance;
59 auto ConsiderCorrection = [&](
const CommandInfo *Command) {
60 StringRef Name = Command->Name;
62 unsigned MinPossibleEditDistance =
abs((
int)Name.size() - (
int)Typo.size());
63 if (MinPossibleEditDistance <= BestEditDistance) {
64 unsigned EditDistance = Typo.edit_distance(Name,
true, BestEditDistance);
65 if (EditDistance < BestEditDistance) {
66 BestEditDistance = EditDistance;
69 if (EditDistance == BestEditDistance)
70 BestCommand.push_back(Command);
74 for (
const auto &Command : Commands)
75 ConsiderCorrection(&Command);
77 for (
const auto *Command : RegisteredCommands)
78 if (!Command->IsUnknownCommand)
79 ConsiderCorrection(Command);
81 return BestCommand.size() == 1 ? BestCommand[0] :
nullptr;
84CommandInfo *CommandTraits::createCommandInfoWithName(StringRef CommandName) {
85 char *Name = Allocator.Allocate<
char>(CommandName.size() + 1);
86 memcpy(Name, CommandName.data(), CommandName.size());
87 Name[CommandName.size()] =
'\0';
95 &&
"Too many commands. We have limited bits for the command ID.");
98 RegisteredCommands.push_back(Info);
104 StringRef CommandName) {
105 CommandInfo *Info = createCommandInfoWithName(CommandName);
111 CommandInfo *Info = createCommandInfoWithName(CommandName);
117 unsigned CommandID) {
118 if (CommandID < std::size(Commands))
119 return &Commands[CommandID];
123const CommandInfo *CommandTraits::getRegisteredCommandInfo(
124 StringRef Name)
const {
125 for (
unsigned i = 0, e = RegisteredCommands.size(); i != e; ++i) {
126 if (RegisteredCommands[i]->Name == Name)
127 return RegisteredCommands[i];
132const CommandInfo *CommandTraits::getRegisteredCommandInfo(
133 unsigned CommandID)
const {
134 return RegisteredCommands[CommandID - std::size(Commands)];
__DEVICE__ long long abs(long long __n)
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
The JSON file list parser is used to communicate input to InstallAPI.