16#include "llvm/ADT/SetVector.h"
22 return llvm::formatv(
"{0:2}",
V).str();
26 return llvm::formatv(
"array of size {0}", A.size()).str();
30 return llvm::formatv(
"an object of {0} key(s)", O.size()).str();
37 llvm::SetVector<const NamedDecl *> Contributors;
40 ContributorFinder(
const SSAFOptions &Opts) : Opts(Opts) {
41 ShouldVisitTemplateInstantiations =
true;
42 ShouldVisitImplicitCode =
false;
46 Contributors.insert(D);
50 bool VisitRecordDecl(RecordDecl *D)
override {
51 Contributors.insert(D);
55 bool VisitVarDecl(VarDecl *D)
override {
60 Contributors.insert(D);
76 Contributors.insert(D);
97 llvm::function_ref<void(
const DynTypedNode &)> MatchActionRef;
98 const NamedDecl *RootDecl =
nullptr;
100 template <
typename NodeTy>
void match(
const NodeTy &Node) {
101 MatchActionRef(DynTypedNode::create(Node));
105 ContributorFactFinder(
106 llvm::function_ref<
void(
const DynTypedNode &)> MatchActionRef)
107 : MatchActionRef(MatchActionRef) {
108 ShouldVisitTemplateInstantiations =
true;
109 ShouldVisitImplicitCode =
false;
113 void findMatches(
const NamedDecl *Contributor) {
114 RootDecl = Contributor;
115 TraverseDecl(
const_cast<NamedDecl *
>(Contributor));
118 bool TraverseDecl(Decl *Node)
override {
122 if (Node != RootDecl &&
129 bool TraverseStmt(Stmt *Node)
override {
136 bool TraverseLambdaExpr(
LambdaExpr *L)
override {
148 llvm::DenseMap<
const NamedDecl *, std::vector<const NamedDecl *>>
150 ContributorFinder Finder{Options};
151 Finder.TraverseAST(Ctx);
152 for (
const NamedDecl *
C : Finder.Contributors)
158 llvm::function_ref<
void(
const DynTypedNode &)> MatchActionRef) {
159 ContributorFactFinder{MatchActionRef}.findMatches(Contributor);
164 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.
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.
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 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)
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)
void findContributors(ASTContext &Ctx, const SSAFOptions &Options, llvm::DenseMap< const NamedDecl *, std::vector< const NamedDecl * > > &Contributors)
Find all contributors in an AST.
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)