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 {
21template <typename NodeTy, typename... Ts>
22llvm::Error makeErrAtNode(clang::ASTContext &Ctx, const NodeTy *N,
23 llvm::StringRef Fmt, const Ts &...Args) {
24 std::string LocStr = N->getBeginLoc().printToString(Ctx.getSourceManager());
25 return llvm::createStringError((Fmt + " at %s").str().c_str(), Args...,
26 LocStr.c_str());
27}
28
29template <typename... Ts>
30llvm::Error makeSawButExpectedError(const llvm::json::Value &Saw,
31 llvm::StringRef Expected,
32 const Ts &...ExpectedArgs) {
33 std::string Fmt = ("saw %s but expected " + Expected).str();
34 std::string SawStr = llvm::formatv("{0:2}", Saw).str();
35
36 return llvm::createStringError(Fmt.c_str(), SawStr.c_str(), ExpectedArgs...);
37}
38
39template <typename DeclOrExpr> bool hasPtrOrArrType(const DeclOrExpr *E) {
40 return llvm::isa<clang::PointerType, clang::ArrayType>(
41 E->getType().getCanonicalType());
42}
43
45 const clang::NamedDecl *D);
46
47/// Find all contributors in an AST.
49 std::vector<const NamedDecl *> &Contributors);
50
51/// Perform "MatchAction" on each Stmt and Decl belonging to the `Contributor`.
52/// \param Contributor
53/// \param MatchActionRef a reference (view) to a "MatchAction"
54void findMatchesIn(
55 const NamedDecl *Contributor,
56 llvm::function_ref<void(const DynTypedNode &)> MatchActionRef);
57
58} // namespace clang::ssaf
59
60#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_SSAFANALYSESCOMMON_H
Defines the clang::ASTContext interface.
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 llvm::json::Value &Saw, llvm::StringRef Expected, const Ts &...ExpectedArgs)
bool hasPtrOrArrType(const DeclOrExpr *E)