clang 23.0.0git
SSAFAnalysesCommon.h
Go to the documentation of this file.
1//===- SSAFAnalysesCommon.h -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Common code in SSAF analyses implementations
10//
11//===----------------------------------------------------------------------===//
12#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_SSAFANALYSESCOMMON_H
13#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_SSAFANALYSESCOMMON_H
14
17#include "clang/AST/Decl.h"
18#include "llvm/Support/JSON.h"
19
20namespace clang::ssaf {
21///\return a short descriptions of a json::Value
22std::string describeJSONValue(const llvm::json::Value &V);
23///\return a short descriptions of a json::Array
24std::string describeJSONValue(const llvm::json::Array &A);
25///\return a short descriptions of a json::Object
26std::string describeJSONValue(const llvm::json::Object &O);
27
28template <typename NodeTy, typename... Ts>
29llvm::Error makeErrAtNode(clang::ASTContext &Ctx, const NodeTy *N,
30 llvm::StringRef Fmt, const Ts &...Args) {
31 std::string LocStr = N->getBeginLoc().printToString(Ctx.getSourceManager());
32 return llvm::createStringError((Fmt + " at %s").str().c_str(), Args...,
33 LocStr.c_str());
34}
35
36template <typename JSONTy, typename... Ts>
37llvm::Error makeSawButExpectedError(const JSONTy &Saw, llvm::StringRef Expected,
38 const Ts &...ExpectedArgs) {
39 std::string Fmt = ("saw %s but expected " + Expected).str();
40 std::string SawStr = describeJSONValue(Saw);
41
42 return llvm::createStringError(Fmt.c_str(), SawStr.c_str(), ExpectedArgs...);
43}
44
45template <typename DeclOrExpr> bool hasPtrOrArrType(const DeclOrExpr *E) {
46 return llvm::isa<clang::PointerType, clang::ArrayType>(
47 E->getType().getCanonicalType());
48}
49
51 const clang::NamedDecl *D);
52
53/// Find all contributors in an AST.
55 std::vector<const NamedDecl *> &Contributors);
56
57/// Perform "MatchAction" on each Stmt and Decl belonging to the `Contributor`.
58/// \param Contributor
59/// \param MatchActionRef a reference (view) to a "MatchAction"
60void findMatchesIn(
61 const NamedDecl *Contributor,
62 llvm::function_ref<void(const DynTypedNode &)> MatchActionRef);
63
64} // namespace clang::ssaf
65
66#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_SSAFANALYSESCOMMON_H
Defines the clang::ASTContext interface.
#define V(N, I)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:227
SourceManager & getSourceManager()
Definition ASTContext.h:866
A dynamically typed AST node container.
This represents a decl that may have a name.
Definition Decl.h:274
llvm::Error makeErrAtNode(clang::ASTContext &Ctx, const NodeTy *N, llvm::StringRef Fmt, const Ts &...Args)
void findContributors(ASTContext &Ctx, std::vector< const NamedDecl * > &Contributors)
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.
llvm::Error makeSawButExpectedError(const JSONTy &Saw, llvm::StringRef Expected, const Ts &...ExpectedArgs)
std::string describeJSONValue(const llvm::json::Value &V)
bool hasPtrOrArrType(const DeclOrExpr *E)