11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 19 return Node.getBeginLoc().isValid();
23 clang::ast_matchers::internal::Matcher<clang::Type>,
25 const clang::Type *TypeNode = Node.getTypePtr();
26 return TypeNode !=
nullptr &&
27 InnerMatcher.matches(*TypeNode, Finder, Builder);
31 return Node.isExternCContext();
35 const clang::DeclContext *DC = Node.getDeclContext();
36 const auto *FD = llvm::dyn_cast<clang::FunctionDecl>(DC);
37 return FD ? FD->isMain() :
false;
46 void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
48 if (!getLangOpts().CPlusPlus11)
52 typeLoc(hasValidBeginLoc(), hasType(arrayType()),
53 unless(anyOf(hasParent(parmVarDecl(isArgvOfMain())),
54 hasParent(varDecl(isExternC())),
56 hasParent(recordDecl(isExternCContext())))),
57 hasAncestor(functionDecl(isExternC())))))
62 void AvoidCArraysCheck::check(
const MatchFinder::MatchResult &
Result) {
63 const auto *ArrayType = Result.Nodes.getNodeAs<TypeLoc>(
"typeloc");
65 static constexpr llvm::StringLiteral UseArray = llvm::StringLiteral(
66 "do not declare C-style arrays, use std::array<> instead");
67 static constexpr llvm::StringLiteral UseVector = llvm::StringLiteral(
68 "do not declare C VLA arrays, use std::vector<> instead");
70 diag(ArrayType->getBeginLoc(),
71 ArrayType->getTypePtr()->isVariableArrayType() ? UseVector : UseArray);
AST_MATCHER(BinaryOperator, isAssignmentOperator)
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
AST_MATCHER_P(FunctionDecl, throws, internal::Matcher< Type >, InnerMatcher)