10#include "llvm/ADT/ArrayRef.h"
11#include "llvm/ADT/StringRef.h"
12#include "llvm/Support/Regex.h"
16static std::optional<std::string>
18 llvm::StringRef DropPrefix =
"",
unsigned MaxEditDistance = 3) {
19 if (MaxEditDistance != ~0
U)
22 for (
const llvm::StringRef &Item : Allowed) {
23 if (Item.equals_insensitive(Search)) {
24 assert(Item != Search &&
"This should be handled earlier on.");
29 unsigned Distance = Item.edit_distance(Search);
30 if (Distance < MaxEditDistance) {
31 MaxEditDistance = Distance;
37 if (!DropPrefix.empty()) {
39 for (
const llvm::StringRef &Item : Allowed) {
41 if (!NoPrefix.consume_front(DropPrefix))
43 if (NoPrefix.equals_insensitive(Search)) {
44 if (NoPrefix == Search)
50 unsigned Distance = NoPrefix.edit_distance(Search);
51 if (Distance < MaxEditDistance) {
52 MaxEditDistance = Distance;
62std::optional<std::string>
65 static constexpr llvm::StringRef Allowed[] = {
66#define ATTR(X) "attr::" #X,
67#include "clang/Basic/AttrList.inc"
74std::optional<std::string>
77 static constexpr llvm::StringRef Allowed[] = {
78#define CAST_OPERATION(Name) "CK_" #Name,
79#include "clang/AST/OperationKinds.def"
86std::optional<std::string>
89 static constexpr llvm::StringRef Allowed[] = {
90#define GEN_CLANG_CLAUSE_CLASS
91#define CLAUSE_CLASS(Enum, Str, Class) #Enum,
92#include "llvm/Frontend/OpenMP/OMP.inc"
99std::optional<std::string>
102 static constexpr llvm::StringRef Allowed[] = {
103#define UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) "UETT_" #Name,
104#define CXX11_UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) "UETT_" #Name,
105#include "clang/Basic/TokenKinds.def"
107 if (
Value.isString())
112static constexpr std::pair<llvm::StringRef, llvm::Regex::RegexFlags>
114 {
"NoFlags", llvm::Regex::RegexFlags::NoFlags},
115 {
"IgnoreCase", llvm::Regex::RegexFlags::IgnoreCase},
116 {
"Newline", llvm::Regex::RegexFlags::Newline},
117 {
"BasicRegex", llvm::Regex::RegexFlags::BasicRegex},
120static std::optional<llvm::Regex::RegexFlags>
122 for (
const auto &StringFlag :
RegexMap) {
123 if (Flag == StringFlag.first)
124 return StringFlag.second;
130 for (
const auto &StringFlag :
RegexMap) {
131 if (Flag.edit_distance(StringFlag.first) < 3)
132 return StringFlag.first;
137std::optional<llvm::Regex::RegexFlags>
139 llvm::Regex::RegexFlags>::getFlags(llvm::StringRef Flags) {
140 std::optional<llvm::Regex::RegexFlags> Flag;
141 SmallVector<StringRef, 4>
Split;
142 Flags.split(Split,
'|', -1,
false);
143 for (StringRef OrFlag : Split) {
144 if (std::optional<llvm::Regex::RegexFlags> NextFlag =
146 Flag = Flag.value_or(llvm::Regex::NoFlags) | *NextFlag;
153std::optional<std::string>
156 if (!
Value.isString())
159 llvm::StringRef(
Value.getString()).split(Split,
'|', -1,
false);
160 for (llvm::StringRef &Flag : Split) {
161 if (std::optional<llvm::StringRef> BestGuess =
169 return llvm::join(Split,
" | ");
static std::optional< llvm::StringRef > getCloseRegexMatch(llvm::StringRef Flag)
static constexpr std::pair< llvm::StringRef, llvm::Regex::RegexFlags > RegexMap[]
static std::optional< llvm::Regex::RegexFlags > getRegexFlag(llvm::StringRef Flag)
static std::optional< std::string > getBestGuess(llvm::StringRef Search, llvm::ArrayRef< llvm::StringRef > Allowed, llvm::StringRef DropPrefix="", unsigned MaxEditDistance=3)
Functions templates and classes to wrap matcher construct functions.
llvm::omp::Clause OpenMPClauseKind
OpenMP clauses.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
CastKind
CastKind - The kind of operation required for a conversion.
Helper template class to just from argument type to the right is/get functions in VariantValue.