11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "llvm/ADT/Hashing.h" 14 #include "llvm/ADT/SmallVector.h" 15 #include "../utils/OptionsUtils.h" 25 constexpr
char DefaultForbiddenSuperClassNames[] =
26 "ABNewPersonViewController;" 27 "ABPeoplePickerNavigationController;" 28 "ABPersonViewController;" 29 "ABUnknownPersonViewController;" 37 "UIImagePickerController;" 57 ast_matchers::internal::Matcher<ObjCInterfaceDecl>, Base) {
58 for (
const auto *SuperClass = Node.getSuperClass();
59 SuperClass !=
nullptr;
60 SuperClass = SuperClass->getSuperClass()) {
61 if (Base.matches(*SuperClass, Finder, Builder)) {
70 ForbiddenSubclassingCheck::ForbiddenSubclassingCheck(
74 ForbiddenSuperClassNames(
76 Options.get(
"ClassNames", DefaultForbiddenSuperClassNames))) {
89 std::vector<StringRef>(
90 ForbiddenSuperClassNames.begin(),
91 ForbiddenSuperClassNames.end())))
98 const MatchFinder::MatchResult &
Result) {
99 const auto *SubClass = Result.Nodes.getNodeAs<ObjCInterfaceDecl>(
101 assert(SubClass !=
nullptr);
102 const auto *SuperClass = Result.Nodes.getNodeAs<ObjCInterfaceDecl>(
104 assert(SuperClass !=
nullptr);
105 diag(SubClass->getLocation(),
106 "Objective-C interface %0 subclasses %1, which is not " 107 "intended to be subclassed")
116 "ForbiddenSuperClassNames",
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.
std::string serializeStringList(ArrayRef< std::string > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
LangOptions getLangOpts() const
Returns the language options from the context.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Base class for all clang-tidy checks.
void storeOptions(ClangTidyOptions::OptionMap &Options) override
Should store all options supported by this check with their current values or default values for opti...
std::vector< std::string > parseStringList(StringRef Option)
Parse a semicolon separated list of strings.
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
AST_MATCHER_P(FunctionDecl, throws, internal::Matcher< Type >, InnerMatcher)
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.