clang
20.0.0git
include
clang
Analysis
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
21
namespace
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.
26
class
AnyCall
{
27
public
:
28
enum
Kind
{
29
/// A function, function pointer, or a C++ method call
30
Function
,
31
32
/// A call to an Objective-C method
33
ObjCMethod
,
34
35
/// A call to an Objective-C block
36
Block
,
37
38
/// An implicit C++ destructor call (called implicitly
39
/// or by operator 'delete')
40
Destructor
,
41
42
/// An implicit or explicit C++ constructor call
43
Constructor
,
44
45
/// A C++ inherited constructor produced by a "using T::T" directive
46
InheritedConstructor
,
47
48
/// A C++ allocation function call (operator `new`), via C++ new-expression
49
Allocator
,
50
51
/// A C++ deallocation function call (operator `delete`), via C++
52
/// delete-expression
53
Deallocator
54
};
55
56
private
:
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
69
public
:
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
79
AnyCall
(
const
ObjCMessageExpr
*ME)
80
:
E
(ME),
D
(ME->getMethodDecl()), K(
ObjCMethod
) {}
81
82
AnyCall
(
const
CXXNewExpr
*NE)
83
:
E
(NE),
D
(NE->getOperatorNew()), K(
Allocator
) {}
84
85
AnyCall
(
const
CXXDeleteExpr
*NE)
86
:
E
(NE),
D
(NE->getOperatorDelete()), K(
Deallocator
) {}
87
88
AnyCall
(
const
CXXConstructExpr
*NE)
89
:
E
(NE),
D
(NE->getConstructor()), K(
Constructor
) {}
90
91
AnyCall
(
const
CXXInheritedCtorInitExpr
*CIE)
92
:
E
(CIE),
D
(CIE->getConstructor()), K(
InheritedConstructor
) {}
93