Go to the documentation of this file.
10 #include "../utils/Matchers.h"
11 #include "../utils/OptionsUtils.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 #include "clang/Lex/Token.h"
32 "declaration uses identifier '%0', which is %select{a reserved "
33 "identifier|not a reserved identifier|reserved in the global namespace}1";
43 ReservedIdentifierCheck::ReservedIdentifierCheck(StringRef
Name,
46 Invert(Options.get(
"Invert", false)),
48 Options.get(
"AllowedIdentifiers",
""))) {}
59 std::unique_copy(Str.begin(), Str.end(), std::back_inserter(Result),
60 [
C](
char A,
char B) { return A == C && B == C; });
67 return Name.contains(
"__");
68 return Name.startswith(
"__");
71 static Optional<std::string>
79 return Name.size() >= 2 &&
Name[0] ==
'_' && std::isupper(
Name[1]);
84 return std::string(
Name.drop_front(1));
89 bool IsInGlobalNamespace) {
90 return IsInGlobalNamespace &&
Name.size() >= 1 &&
Name[0] ==
'_';
93 static Optional<std::string>
96 return std::string(
Name.drop_front(1));
101 assert(!
Name.empty());
102 if (
Name[0] ==
'_' || std::isupper(
Name[0]))
109 static Optional<RenamerClangTidyCheck::FailureInfo>
111 const LangOptions &
LangOpts,
bool Invert,
112 ArrayRef<StringRef> AllowedIdentifiers) {
113 assert(!
Name.empty());
114 if (llvm::is_contained(AllowedIdentifiers,
Name))
123 Optional<FailureInfo>
Info;
124 auto AppendFailure = [&](StringRef
Kind, std::string &&Fixup) {
126 Info = FailureInfo{std::string(
Kind), std::move(Fixup)};
129 Info->Fixup = std::move(Fixup);
132 auto InProgressFixup = [&] {
134 .map([](
const FailureInfo &
Info) {
return StringRef(
Info.Fixup); })
142 IsInGlobalNamespace))
154 Optional<RenamerClangTidyCheck::FailureInfo>
155 ReservedIdentifierCheck::getDeclFailureInfo(
const NamedDecl *
Decl,
156 const SourceManager &)
const {
157 assert(
Decl &&
Decl->getIdentifier() && !
Decl->getName().empty() &&
158 !
Decl->isImplicit() &&
159 "Decl must be an explicit identifier with a name.");
161 isa<TranslationUnitDecl>(
Decl->getDeclContext()),
165 Optional<RenamerClangTidyCheck::FailureInfo>
166 ReservedIdentifierCheck::getMacroFailureInfo(
const Token &MacroNameTok,
167 const SourceManager &)
const {
172 RenamerClangTidyCheck::DiagInfo
173 ReservedIdentifierCheck::getDiagInfo(
const NamingCheckId &
ID,
174 const NamingCheckFailure &Failure)
const {
175 return DiagInfo{
Message, [&](DiagnosticBuilder &Diag) {
llvm::StringMap< ClangTidyValue > OptionMap
static std::string getNonReservedFixup(std::string Name)
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Derived classes that override this function should call this method from the overridden method.
static const char Message[]
static bool startsWithUnderscoreCapital(StringRef Name)
const LangOptions & getLangOpts() const
Returns the language options from the context.
static const char DoubleUnderscoreTag[]
static Optional< std::string > getUnderscoreGlobalNamespaceFixup(StringRef Name, bool IsInGlobalNamespace)
static int getMessageSelectIndex(StringRef Tag)
static bool startsWithUnderscoreInGlobalNamespace(StringRef Name, bool IsInGlobalNamespace)
const FunctionDecl * Decl
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
static const char GlobalUnderscoreTag[]
static Optional< std::string > getDoubleUnderscoreFixup(StringRef Name, const LangOptions &LangOpts)
static Optional< std::string > getUnderscoreCapitalFixup(StringRef Name)
Base class for clang-tidy checks that want to flag declarations and/or macros for renaming based on c...
static std::string collapseConsecutive(StringRef Str, char C)
std::string serializeStringList(ArrayRef< StringRef > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
static Optional< RenamerClangTidyCheck::FailureInfo > getFailureInfoImpl(StringRef Name, bool IsInGlobalNamespace, const LangOptions &LangOpts, bool Invert, ArrayRef< StringRef > AllowedIdentifiers)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< StringRef > parseStringList(StringRef Option)
Parse a semicolon separated list of strings.
static bool hasReservedDoubleUnderscore(StringRef Name, const LangOptions &LangOpts)
static const char UnderscoreCapitalTag[]
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
Information describing a failed check.
static const char NonReservedTag[]