11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 23 return std::distance(Node.method_begin(), Node.method_end()) != 0;
26 AST_MATCHER(CXXRecordDecl, hasNonStaticNonImplicitMethod) {
27 return hasMethod(unless(anyOf(isStaticStorageClass(), isImplicit())))
28 .matches(Node, Finder, Builder);
31 AST_MATCHER(CXXRecordDecl, hasNonPublicMemberVariable) {
32 return cxxRecordDecl(has(fieldDecl(unless(
isPublic()))))
33 .matches(Node, Finder, Builder);
36 AST_POLYMORPHIC_MATCHER_P(
boolean, AST_POLYMORPHIC_SUPPORTED_TYPES(Stmt, Decl),
43 NonPrivateMemberVariablesInClassesCheck::
44 NonPrivateMemberVariablesInClassesCheck(StringRef
Name,
47 IgnoreClassesWithAllMemberVariablesBeingPublic(
48 Options.get(
"IgnoreClassesWithAllMemberVariablesBeingPublic", false)),
49 IgnorePublicMemberVariables(
50 Options.get(
"IgnorePublicMemberVariables", false)) {}
53 MatchFinder *Finder) {
58 auto ShouldIgnoreRecord =
59 allOf(
boolean(IgnoreClassesWithAllMemberVariablesBeingPublic),
60 unless(hasNonPublicMemberVariable()));
66 auto InterestingField = fieldDecl(
67 IgnorePublicMemberVariables ? isProtected() : unless(isPrivate()));
73 Finder->addMatcher(cxxRecordDecl(anyOf(isStruct(), isClass()), hasMethods(),
74 hasNonStaticNonImplicitMethod(),
75 unless(ShouldIgnoreRecord),
76 forEach(InterestingField.bind(
"field")))
82 const MatchFinder::MatchResult &
Result) {
83 const auto *Field = Result.Nodes.getNodeAs<FieldDecl>(
"field");
84 assert(Field &&
"We should have the field we are going to complain about");
86 diag(Field->getLocation(),
"member variable %0 has %1 visibility")
87 << Field << Field->getAccess();
AST_MATCHER(BinaryOperator, isAssignmentOperator)
LangOptions getLangOpts() const
Returns the language options from the context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Base class for all clang-tidy checks.
static constexpr llvm::StringLiteral Name
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
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.