10 #include "llvm/ADT/STLExtras.h" 15 #include "clang/AST/CommentCommandInfo.inc" 19 NextID(
llvm::array_lengthof(Commands)), Allocator(Allocator) {
25 for (CommentOptions::BlockCommandNamesTy::const_iterator
36 return getRegisteredCommandInfo(Name);
42 return getRegisteredCommandInfo(CommandID);
53 const unsigned MaxEditDistance = 1;
55 unsigned BestEditDistance = MaxEditDistance;
58 auto ConsiderCorrection = [&](
const CommandInfo *Command) {
59 StringRef Name = Command->Name;
61 unsigned MinPossibleEditDistance =
abs((
int)Name.size() - (int)Typo.size());
62 if (MinPossibleEditDistance <= BestEditDistance) {
63 unsigned EditDistance = Typo.edit_distance(Name,
true, BestEditDistance);
64 if (EditDistance < BestEditDistance) {
65 BestEditDistance = EditDistance;
68 if (EditDistance == BestEditDistance)
69 BestCommand.push_back(Command);
73 for (
const auto &Command : Commands)
74 ConsiderCorrection(&Command);
76 for (
const auto *Command : RegisteredCommands)
77 if (!Command->IsUnknownCommand)
78 ConsiderCorrection(Command);
80 return BestCommand.size() == 1 ? BestCommand[0] :
nullptr;
83 CommandInfo *CommandTraits::createCommandInfoWithName(StringRef CommandName) {
84 char *Name = Allocator.Allocate<
char>(CommandName.size() + 1);
85 memcpy(Name, CommandName.data(), CommandName.size());
86 Name[CommandName.size()] =
'\0';
94 &&
"Too many commands. We have limited bits for the command ID.");
97 RegisteredCommands.push_back(Info);
103 StringRef CommandName) {
104 CommandInfo *Info = createCommandInfoWithName(CommandName);
110 CommandInfo *Info = createCommandInfoWithName(CommandName);
116 unsigned CommandID) {
117 if (CommandID < llvm::array_lengthof(Commands))
118 return &Commands[CommandID];
122 const CommandInfo *CommandTraits::getRegisteredCommandInfo(
123 StringRef Name)
const {
124 for (
unsigned i = 0, e = RegisteredCommands.size();
i != e; ++
i) {
125 if (RegisteredCommands[
i]->Name == Name)
126 return RegisteredCommands[
i];
131 const CommandInfo *CommandTraits::getRegisteredCommandInfo(
132 unsigned CommandID)
const {
133 return RegisteredCommands[CommandID - llvm::array_lengthof(Commands)];
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
__DEVICE__ long long abs(long long __n)
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Dataflow Directional Tag Classes.