10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 22 return std::distance(Node.method_begin(), Node.method_end()) != 0;
25 AST_MATCHER(CXXRecordDecl, hasNonStaticNonImplicitMethod) {
26 return hasMethod(unless(anyOf(isStaticStorageClass(), isImplicit())))
27 .matches(Node, Finder,
Builder);
30 AST_MATCHER(CXXRecordDecl, hasNonPublicMemberVariable) {
31 return cxxRecordDecl(has(fieldDecl(unless(
isPublic()))))
32 .matches(Node, Finder,
Builder);
35 AST_POLYMORPHIC_MATCHER_P(
boolean, AST_POLYMORPHIC_SUPPORTED_TYPES(Stmt,
Decl),
42 NonPrivateMemberVariablesInClassesCheck::
43 NonPrivateMemberVariablesInClassesCheck(StringRef
Name,
46 IgnoreClassesWithAllMemberVariablesBeingPublic(
47 Options.get(
"IgnoreClassesWithAllMemberVariablesBeingPublic", false)),
48 IgnorePublicMemberVariables(
49 Options.get(
"IgnorePublicMemberVariables", false)) {}
52 MatchFinder *Finder) {
57 auto ShouldIgnoreRecord =
58 allOf(
boolean(IgnoreClassesWithAllMemberVariablesBeingPublic),
59 unless(hasNonPublicMemberVariable()));
65 auto InterestingField = fieldDecl(
66 IgnorePublicMemberVariables ? isProtected() : unless(isPrivate()));
72 Finder->addMatcher(cxxRecordDecl(anyOf(isStruct(), isClass()), hasMethods(),
73 hasNonStaticNonImplicitMethod(),
74 unless(ShouldIgnoreRecord),
75 forEach(InterestingField.bind(
"field")))
81 const MatchFinder::MatchResult &Result) {
82 const auto *Field = Result.Nodes.getNodeAs<FieldDecl>(
"field");
83 assert(Field &&
"We should have the field we are going to complain about");
85 diag(Field->getLocation(),
"member variable %0 has %1 visibility")
86 << Field << Field->getAccess();
const FunctionDecl * Decl
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
AST_MATCHER(Expr, isMacroID)
Base class for all clang-tidy checks.
const LangOptions & getLangOpts() const
Returns the language options from the context.
static constexpr llvm::StringLiteral Name
CodeCompletionBuilder Builder
static bool isPublic(const clang::AccessSpecifier AS, const clang::Linkage Link)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.