clang
23.0.0git
lib
ScalableStaticAnalysisFramework
Analyses
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
15
#include "
clang/AST/ASTContext.h
"
16
#include "
clang/AST/ASTTypeTraits.h
"
17
#include "
clang/AST/Decl.h
"
18
#include "llvm/Support/JSON.h"
19
20
namespace
clang::ssaf
{
21
template
<
typename
NodeTy,
typename
... Ts>
22
llvm::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
29
template
<
typename
... Ts>
30
llvm::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
39
template
<
typename
DeclOrExpr>
bool
hasPtrOrArrType
(
const
DeclOrExpr *E) {
40
return
llvm::isa<clang::PointerType, clang::ArrayType>(
41
E->getType().getCanonicalType());
42
}
43
44
llvm::Error
makeEntityNameErr
(
clang::ASTContext
&Ctx,
45
const
clang::NamedDecl
*D);
46
47
/// Find all contributors in an AST.
48
void
findContributors
(
ASTContext
&Ctx,
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"
54
void
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
ASTContext.h
Defines the clang::ASTContext interface.
ASTTypeTraits.h
Decl.h
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition
ASTContext.h:227
clang::ASTContext::getSourceManager
SourceManager & getSourceManager()
Definition
ASTContext.h:866
clang::DynTypedNode
A dynamically typed AST node container.
Definition
ASTTypeTraits.h:257
clang::NamedDecl
This represents a decl that may have a name.
Definition
Decl.h:274
llvm::Expected
Definition
LLVM.h:36
clang::ssaf
Definition
CallGraphSummary.h:17
clang::ssaf::makeErrAtNode
llvm::Error makeErrAtNode(clang::ASTContext &Ctx, const NodeTy *N, llvm::StringRef Fmt, const Ts &...Args)
Definition
SSAFAnalysesCommon.h:22
clang::ssaf::findContributors
void findContributors(ASTContext &Ctx, std::vector< const NamedDecl * > &Contributors)
Find all contributors in an AST.
Definition
SSAFAnalysesCommon.cpp:101
clang::ssaf::makeEntityNameErr
llvm::Error makeEntityNameErr(clang::ASTContext &Ctx, const clang::NamedDecl *D)
Definition
SSAFAnalysesCommon.cpp:115
clang::ssaf::findMatchesIn
void findMatchesIn(const NamedDecl *Contributor, llvm::function_ref< void(const DynTypedNode &)> MatchActionRef)
Perform "MatchAction" on each Stmt and Decl belonging to the Contributor.
Definition
SSAFAnalysesCommon.cpp:109
clang::ssaf::makeSawButExpectedError
llvm::Error makeSawButExpectedError(const llvm::json::Value &Saw, llvm::StringRef Expected, const Ts &...ExpectedArgs)
Definition
SSAFAnalysesCommon.h:30
clang::ssaf::hasPtrOrArrType
bool hasPtrOrArrType(const DeclOrExpr *E)
Definition
SSAFAnalysesCommon.h:39
Generated on
for clang by
1.14.0