17#include "llvm/ADT/SetVector.h"
23 return llvm::formatv(
"{0:2}",
V).str();
27 return llvm::formatv(
"array of size {0}", A.size()).str();
31 return llvm::formatv(
"an object of {0} key(s)", O.size()).str();
38 llvm::SetVector<const NamedDecl *> Contributors;
42 bool ExtractFromSystemHeaders)
43 : Opts(Opts), Ctx(Ctx),
44 ExtractFromSystemHeaders(ExtractFromSystemHeaders) {
45 ShouldVisitTemplateInstantiations =
true;
46 ShouldVisitImplicitCode =
false;
50 if (!skipForSystemHeader(D))
51 Contributors.insert(D);
55 bool VisitRecordDecl(RecordDecl *D)
override {
56 if (skipForSystemHeader(D))
58 Contributors.insert(D);
62 bool VisitVarDecl(VarDecl *D)
override {
63 if (skipForSystemHeader(D))
69 Contributors.insert(D);
85 Contributors.insert(D);
94 bool skipForSystemHeader(
const Decl *D)
const {
95 if (ExtractFromSystemHeaders)
98 return Loc.
isValid() && Ctx.getSourceManager().isInSystemHeader(Loc);
102 bool ExtractFromSystemHeaders;
114 llvm::function_ref<void(
const DynTypedNode &)> MatchActionRef;
115 const NamedDecl *RootDecl =
nullptr;
117 template <
typename NodeTy>
void match(
const NodeTy &Node) {
118 MatchActionRef(DynTypedNode::create(Node));
122 ContributorFactFinder(
123 llvm::function_ref<
void(
const DynTypedNode &)> MatchActionRef)
124 : MatchActionRef(MatchActionRef) {
125 ShouldVisitTemplateInstantiations =
true;
126 ShouldVisitImplicitCode =
false;
130 void findMatches(
const NamedDecl *Contributor) {
131 RootDecl = Contributor;
132 TraverseDecl(
const_cast<NamedDecl *
>(Contributor));
135 bool TraverseDecl(Decl *Node)
override {
139 if (Node != RootDecl &&
146 bool TraverseStmt(Stmt *Node)
override {
153 bool TraverseLambdaExpr(
LambdaExpr *L)
override {
165 llvm::DenseMap<
const NamedDecl *, std::vector<const NamedDecl *>>
167 bool ExtractFromSystemHeaders) {
168 ContributorFinder Finder{Ctx, Options, ExtractFromSystemHeaders};
169 Finder.TraverseAST(Ctx);
170 for (
const NamedDecl *
C : Finder.Contributors)
176 llvm::function_ref<
void(
const DynTypedNode &)> MatchActionRef) {
177 ContributorFactFinder{MatchActionRef}.findMatches(Contributor);
182 return makeErrAtNode(Ctx, D,
"failed to create entity name for %s",
Defines the clang::ASTContext interface.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isFileContext() const
bool isFunctionOrMethod() const
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
SourceLocation getLocation() const
DeclContext * getDeclContext()
A dynamically typed AST node container.
virtual bool TraverseDecl(MaybeConst< Decl > *D)
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Represents a function declaration or definition.
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
This represents a decl that may have a name.
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isStaticDataMember() const
Determines whether this is a static data member.
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
llvm::Error makeErrAtNode(clang::ASTContext &Ctx, const NodeTy *N, llvm::StringRef Fmt, const Ts &...Args)
void findContributors(ASTContext &Ctx, const SSAFOptions &Options, llvm::DenseMap< const NamedDecl *, std::vector< const NamedDecl * > > &Contributors, bool ExtractFromSystemHeaders=true)
Find all contributors in an AST.
llvm::Error makeEntityNameErr(clang::ASTContext &Ctx, const clang::NamedDecl *D)
void findMatchesIn(const NamedDecl *Contributor, llvm::function_ref< void(const DynTypedNode &)> MatchActionRef)
Perform "MatchAction" on each Stmt and Decl belonging to the Contributor.
std::string describeJSONValue(const llvm::json::Value &V)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
U cast(CodeGen::Address addr)