12#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_SSAFANALYSESCOMMON_H
13#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_SSAFANALYSESCOMMON_H
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/STLFunctionalExtras.h"
23#include "llvm/Support/Debug.h"
24#include "llvm/Support/Error.h"
25#include "llvm/Support/JSON.h"
26#include "llvm/Support/raw_ostream.h"
37template <
typename NodeTy,
typename... Ts>
39 llvm::StringRef Fmt,
const Ts &...Args) {
41 return llvm::createStringError((Fmt +
" at %s").str().c_str(), Args...,
45template <
typename JSONTy,
typename... Ts>
47 const Ts &...ExpectedArgs) {
48 std::string Fmt = (
"saw %s but expected " +
Expected).str();
51 return llvm::createStringError(Fmt.c_str(), SawStr.c_str(), ExpectedArgs...);
56 return llvm::isa<clang::PointerType, clang::ArrayType>(
62 return llvm::isa<clang::PointerType, clang::ArrayType>(
71 DEBUG_WITH_TYPE(
"ssaf-analyses", llvm::errs() << Err);
72 llvm::consumeError(std::move(Err));
80 llvm::DenseMap<
const NamedDecl *, std::vector<const NamedDecl *>>
88 llvm::function_ref<
void(
const DynTypedNode &)> MatchActionRef);
103template <
typename ExtractorFnT>
106 ExtractorFnT ExtractFn,
107 const char *ExtractorName =
"") {
108 llvm::DenseMap<const NamedDecl *, std::vector<const NamedDecl *>>
111 for (
const auto &[Cano, Decls] : Contributors) {
115 if (Cano->isTemplated())
118 auto Summary = ExtractFn(Decls);
120 if (Summary->empty())
123 if (
auto Id = Extractor.
addEntity(Cano)) {
124 if (!Builder.addSummary(*Id, std::move(Summary)).second)
126 Ctx, Cano,
"dropping duplicate %s summary for entity %s",
127 ExtractorName, Cano->getNameAsString().c_str()));
Defines the clang::ASTContext interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
A dynamically typed AST node container.
This represents one expression.
This represents a decl that may have a name.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool hasPtrOrArrType(const Expr *E)
void findContributors(ASTContext &Ctx, llvm::DenseMap< const NamedDecl *, std::vector< const NamedDecl * > > &Contributors)
Find all contributors in an AST.
void logWarningFromError(llvm::Error Err)
Log a warning from an llvm::Error.
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.
llvm::Error makeSawButExpectedError(const JSONTy &Saw, llvm::StringRef Expected, const Ts &...ExpectedArgs)
std::string describeJSONValue(const llvm::json::Value &V)
void extractAndAddSummaries(TUSummaryExtractor &Extractor, TUSummaryBuilder &Builder, ASTContext &Ctx, ExtractorFnT ExtractFn, const char *ExtractorName="")
The standard contributor-summary extraction procedure: