13 #ifndef LLVM_CLANG_ANALYSIS_ANY_CALL_H 14 #define LLVM_CLANG_ANALYSIS_ANY_CALL_H 58 const Expr *E =
nullptr;
62 const Decl *D =
nullptr;
66 AnyCall(
const CallExpr *CE) : E(CE) {
67 D = CE->getCalleeDecl();
68 K = (CE->getCallee()->getType()->getAs<BlockPointerType>()) ? Block
70 if (D && ((K == Function && !isa<FunctionDecl>(D)) ||
71 (K == Block && !isa<BlockDecl>(D))))
75 AnyCall(
const ObjCMessageExpr *ME)
76 : E(ME), D(ME->getMethodDecl()), K(ObjCMethod) {}
78 AnyCall(
const CXXNewExpr *NE)
79 : E(NE), D(NE->getOperatorNew()), K(Allocator) {}
81 AnyCall(
const CXXDeleteExpr *NE)
82 : E(NE), D(NE->getOperatorDelete()), K(Deallocator) {}
84 AnyCall(
const CXXConstructExpr *NE)
87 AnyCall(
const CXXDestructorDecl *D) : E(nullptr), D(D), K(
Destructor) {}
89 AnyCall(
const CXXConstructorDecl *D) : E(nullptr), D(D), K(
Constructor) {}
91 AnyCall(
const ObjCMethodDecl *D) : E(nullptr), D(D), K(ObjCMethod) {}
93 AnyCall(
const FunctionDecl *D) : E(nullptr), D(D) {
94 if (isa<CXXConstructorDecl>(D)) {
96 }
else if (isa <CXXDestructorDecl>(D)) {
106 static Optional<AnyCall> forExpr(
const Expr *E) {
107 if (
const auto *ME = dyn_cast<ObjCMessageExpr>(E)) {
109 }
else if (
const auto *CE = dyn_cast<CallExpr>(E)) {
111 }
else if (
const auto *CXNE = dyn_cast<CXXNewExpr>(E)) {
112 return AnyCall(CXNE);
113 }
else if (
const auto *CXDE = dyn_cast<CXXDeleteExpr>(E)) {
114 return AnyCall(CXDE);
115 }
else if (
const auto *CXCE = dyn_cast<CXXConstructExpr>(E)) {
116 return AnyCall(CXCE);
125 static Optional<AnyCall> forDecl(
const Decl *D) {
126 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
128 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
135 ArrayRef<ParmVarDecl *> parameters()
const {
139 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
140 return FD->parameters();
141 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
142 return MD->parameters();
143 }
else if (
const auto *BD = dyn_cast<BlockDecl>(D)) {
144 return BD->parameters();
150 using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator;
151 param_const_iterator param_begin()
const {
return parameters().begin(); }
152 param_const_iterator param_end()
const {
return parameters().end(); }
153 size_t param_size()
const {
return parameters().size(); }
154 bool param_empty()
const {
return parameters().empty(); }
156 QualType getReturnType(ASTContext &Ctx)
const {
160 return cast<CallExpr>(E)->getCallReturnType(Ctx);
161 return cast<FunctionDecl>(D)->getReturnType();
164 return cast<ObjCMessageExpr>(E)->getCallReturnType(Ctx);
165 return cast<ObjCMethodDecl>(D)->getReturnType();
169 return cast<CallExpr>(E)->getCallReturnType(Ctx);
174 return cast<FunctionDecl>(D)->getReturnType();
176 llvm_unreachable(
"Unknown AnyCall::Kind");
182 if (
const auto *ND = dyn_cast_or_null<NamedDecl>(D))
183 return ND->getIdentifier();
187 const Decl *getDecl()
const {
191 const Expr *getExpr()
const {
209 #endif // LLVM_CLANG_ANALYSIS_ANY_CALL_H The l-value was an access to a declared entity or something equivalently strong, like the address of ...
constexpr XRayInstrMask Function
Defines the clang::Expr interface and subclasses for C++ expressions.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
static StringRef getIdentifier(const Token &Tok)
Dataflow Directional Tag Classes.
static Decl::Kind getKind(const Decl *D)