clang 20.0.0git
AnyCall.h
Go to the documentation of this file.
1//=== AnyCall.h - Abstraction over different callables --------*- 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// A utility class for performing generic operations over different callables.
10//
11//===----------------------------------------------------------------------===//
12//
13#ifndef LLVM_CLANG_ANALYSIS_ANYCALL_H
14#define LLVM_CLANG_ANALYSIS_ANYCALL_H
15
16#include "clang/AST/Decl.h"
17#include "clang/AST/ExprCXX.h"
18#include "clang/AST/ExprObjC.h"
19#include <optional>
20
21namespace clang {
22
23/// An instance of this class corresponds to a call.
24/// It might be a syntactically-concrete call, done as a part of evaluating an
25/// expression, or it may be an abstract callee with no associated expression.
26class AnyCall {
27public:
28 enum Kind {
29 /// A function, function pointer, or a C++ method call
31
32 /// A call to an Objective-C method
34
35 /// A call to an Objective-C block
37
38 /// An implicit C++ destructor call (called implicitly
39 /// or by operator 'delete')
41
42 /// An implicit or explicit C++ constructor call
44
45 /// A C++ inherited constructor produced by a "using T::T" directive
47
48 /// A C++ allocation function call (operator `new`), via C++ new-expression
50
51 /// A C++ deallocation function call (operator `delete`), via C++
52 /// delete-expression
54 };
55
56private:
57 /// Either expression or declaration (but not both at the same time)
58 /// can be null.
59
60 /// Call expression, is null when is not known (then declaration is non-null),
61 /// or for implicit destructor calls (when no expression exists.)
62 const Expr *E = nullptr;
63
64 /// Corresponds to a statically known declaration of the called function,
65 /// or null if it is not known (e.g. for a function pointer).
66 const Decl *D = nullptr;
67 Kind K;
68
69public:
70 AnyCall(const CallExpr *CE) : E(CE) {
71 D = CE->getCalleeDecl();
72 K = (CE->getCallee()->getType()->getAs<BlockPointerType>()) ? Block
73 : Function;
74 if (D && ((K == Function && !isa<FunctionDecl>(D)) ||
75 (K == Block && !isa<BlockDecl>(D))))
76 D = nullptr;
77 }
78
80 : E(ME), D(ME->getMethodDecl()), K(ObjCMethod) {}
81
83 : E(NE), D(NE->getOperatorNew()), K(Allocator) {}
84
86 : E(NE), D(NE->getOperatorDelete()), K(Deallocator) {}
87
89 : E(NE), D(NE->getConstructor()), K(Constructor) {}
90
92 : E(CIE), D(CIE->getConstructor()), K(InheritedConstructor) {}
93