/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/Interp/FunctionPointer.h
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | |
3 | | #ifndef LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H |
4 | | #define LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H |
5 | | |
6 | | #include "Function.h" |
7 | | #include "Primitives.h" |
8 | | #include "clang/AST/APValue.h" |
9 | | |
10 | | namespace clang { |
11 | | class ASTContext; |
12 | | namespace interp { |
13 | | |
14 | | class FunctionPointer final { |
15 | | private: |
16 | | const Function *Func; |
17 | | |
18 | | public: |
19 | 5 | FunctionPointer() : Func(nullptr) {} |
20 | 19 | FunctionPointer(const Function *Func) : Func(Func) { assert(Func); } |
21 | | |
22 | 12 | const Function *getFunction() const { return Func; } |
23 | | |
24 | 9 | APValue toAPValue() const { |
25 | 9 | if (!Func) |
26 | 1 | return APValue(static_cast<Expr *>(nullptr), CharUnits::Zero(), {}, |
27 | 1 | /*OnePastTheEnd=*/false, /*IsNull=*/true); |
28 | | |
29 | 8 | return APValue(Func->getDecl(), CharUnits::Zero(), {}, |
30 | 8 | /*OnePastTheEnd=*/false, /*IsNull=*/false); |
31 | 9 | } |
32 | | |
33 | 0 | void print(llvm::raw_ostream &OS) const { |
34 | 0 | OS << "FnPtr("; |
35 | 0 | if (Func) |
36 | 0 | OS << Func->getName(); |
37 | 0 | else |
38 | 0 | OS << "nullptr"; |
39 | 0 | OS << ")"; |
40 | 0 | } |
41 | | |
42 | 4 | std::string toDiagnosticString(const ASTContext &Ctx) const { |
43 | 4 | if (!Func) |
44 | 1 | return "nullptr"; |
45 | | |
46 | 3 | return toAPValue().getAsString(Ctx, Func->getDecl()->getType()); |
47 | 4 | } |
48 | | |
49 | 6 | ComparisonCategoryResult compare(const FunctionPointer &RHS) const { |
50 | 6 | if (Func == RHS.Func) |
51 | 3 | return ComparisonCategoryResult::Equal; |
52 | 3 | return ComparisonCategoryResult::Unordered; |
53 | 6 | } |
54 | | }; |
55 | | |
56 | | inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, |
57 | 0 | FunctionPointer FP) { |
58 | 0 | FP.print(OS); |
59 | 0 | return OS; |
60 | 0 | } |
61 | | |
62 | | } // namespace interp |
63 | | } // namespace clang |
64 | | |
65 | | #endif |