10 #include "../utils/LexerUtils.h" 11 #include "../utils/Matchers.h" 12 #include "clang/AST/ASTContext.h" 13 #include "clang/ASTMatchers/ASTMatchFinder.h" 21 namespace performance {
27 AST_MATCHER_P(CXXRecordDecl, hasBase, Matcher<QualType>, InnerMatcher) {
28 for (
const CXXBaseSpecifier &BaseSpec : Node.bases()) {
29 QualType BaseType = BaseSpec.getType();
30 if (InnerMatcher.matches(BaseType, Finder,
Builder))
38 void TriviallyDestructibleCheck::registerMatchers(MatchFinder *Finder) {
39 if (!getLangOpts().CPlusPlus11)
45 unless(anyOf(isFirstDecl(), isVirtual(),
46 ofClass(cxxRecordDecl(
54 void TriviallyDestructibleCheck::check(
const MatchFinder::MatchResult &Result) {
55 const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXDestructorDecl>(
"decl");
58 SourceManager &SM = *Result.SourceManager;
59 const auto *FirstDecl = cast<CXXMethodDecl>(MatchedDecl->getFirstDecl());
61 FirstDecl->getEndLoc(), SM, getLangOpts());
63 MatchedDecl->getBeginLoc(),
66 if (FirstDeclEnd.isInvalid() || SecondDeclRange.isInvalid())
70 diag(FirstDecl->getLocation(),
71 "class %0 can be made trivially destructible by defaulting the " 72 "destructor on its first declaration")
73 << FirstDecl->getParent()
74 << FixItHint::CreateInsertion(FirstDeclEnd,
" = default")
75 << FixItHint::CreateRemoval(SecondDeclRange);
76 diag(MatchedDecl->getLocation(),
"destructor definition is here",
const FunctionDecl * Decl
AST_MATCHER(Expr, isMacroID)
SourceLocation findNextTerminator(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
llvm::Optional< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
CodeCompletionBuilder Builder
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
bool isTriviallyDestructible(QualType Type)
Returns true if Type is trivially destructible.
AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl, ast_matchers::internal::Matcher< CXXMethodDecl >, InnerMatcher)