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
///\return a short descriptions of a json::Value
22
std::string
describeJSONValue
(
const
llvm::json::Value &
V
);
23
///\return a short descriptions of a json::Array
24
std::string
describeJSONValue
(
const
llvm::json::Array &A);
25
///\return a short descriptions of a json::Object
26
std::string
describeJSONValue
(
const
llvm::json::Object &O);
27
28
template
<
typename
NodeTy,
typename
... Ts>
29
llvm::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
36
template
<
typename
JSONTy,
typename
... Ts>
37
llvm::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
45
template
<
typename
DeclOrExpr>
bool
hasPtrOrArrType
(
const
DeclOrExpr *E) {
46
return
llvm::isa<clang::PointerType, clang::ArrayType>(
47
E->getType().getCanonicalType());
48
}
49
50
llvm::Error
makeEntityNameErr
(
clang::ASTContext
&Ctx,
51
const
clang::NamedDecl
*D);
52
53
/// Find all contributors in an AST.
54
void
findContributors
(
ASTContext
&Ctx,
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"
60
void
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
ASTContext.h
Defines the clang::ASTContext interface.
V
#define V(N, I)
Definition
ASTContext.h:3718
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:259
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:29
clang::ssaf::findContributors
void findContributors(ASTContext &Ctx, std::vector< const NamedDecl * > &Contributors)
Find all contributors in an AST.
Definition
SSAFAnalysesCommon.cpp:122
clang::ssaf::makeEntityNameErr
llvm::Error makeEntityNameErr(clang::ASTContext &Ctx, const clang::NamedDecl *D)
Definition
SSAFAnalysesCommon.cpp:136
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:130
clang::ssaf::makeSawButExpectedError
llvm::Error makeSawButExpectedError(const JSONTy &Saw, llvm::StringRef Expected, const Ts &...ExpectedArgs)
Definition
SSAFAnalysesCommon.h:37
clang::ssaf::describeJSONValue
std::string describeJSONValue(const llvm::json::Value &V)
Definition
SSAFAnalysesCommon.cpp:19
clang::ssaf::hasPtrOrArrType
bool hasPtrOrArrType(const DeclOrExpr *E)
Definition
SSAFAnalysesCommon.h:45
Generated on
for clang by
1.14.0