/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/ASTLambda.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- ASTLambda.h - Lambda Helper Functions --------------*- 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 | | /// \file |
10 | | /// This file provides some common utility functions for processing |
11 | | /// Lambda related AST Constructs. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #ifndef LLVM_CLANG_AST_ASTLAMBDA_H |
16 | | #define LLVM_CLANG_AST_ASTLAMBDA_H |
17 | | |
18 | | #include "clang/AST/DeclCXX.h" |
19 | | #include "clang/AST/DeclTemplate.h" |
20 | | |
21 | | namespace clang { |
22 | 20.0k | inline StringRef getLambdaStaticInvokerName() { |
23 | 20.0k | return "__invoke"; |
24 | 20.0k | } |
25 | | // This function returns true if M is a specialization, a template, |
26 | | // or a non-generic lambda call operator. |
27 | 24.0M | inline bool isLambdaCallOperator(const CXXMethodDecl *MD) { |
28 | 24.0M | const CXXRecordDecl *LambdaClass = MD->getParent(); |
29 | 24.0M | if (!LambdaClass || !LambdaClass->isLambda()) return false23.7M ; |
30 | 237k | return MD->getOverloadedOperator() == OO_Call; |
31 | 24.0M | } |
32 | | |
33 | 212M | inline bool isLambdaCallOperator(const DeclContext *DC) { |
34 | 212M | if (!DC || !isa<CXXMethodDecl>(DC)201M ) return false189M ; |
35 | 23.4M | return isLambdaCallOperator(cast<CXXMethodDecl>(DC)); |
36 | 212M | } |
37 | | |
38 | 102 | inline bool isLambdaCallWithExplicitObjectParameter(const DeclContext *DC) { |
39 | 102 | return isLambdaCallOperator(DC) && |
40 | 102 | cast<CXXMethodDecl>(DC)->isExplicitObjectMemberFunction()20 ; |
41 | 102 | } |
42 | | |
43 | 16.2k | inline bool isLambdaCallWithImplicitObjectParameter(const DeclContext *DC) { |
44 | 16.2k | return isLambdaCallOperator(DC) && |
45 | | // FIXME: Checking for a null type is not great |
46 | | // but lambdas with invalid captures or whose closure parameter list |
47 | | // have not fully been parsed may have a call operator whose type is |
48 | | // null. |
49 | 16.2k | !cast<CXXMethodDecl>(DC)->getType().isNull()43 && |
50 | 16.2k | !cast<CXXMethodDecl>(DC)->isExplicitObjectMemberFunction()30 ; |
51 | 16.2k | } |
52 | | |
53 | 18.5M | inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) { |
54 | 18.5M | if (!MD) return false7.95M ; |
55 | 10.5M | const CXXRecordDecl *LambdaClass = MD->getParent(); |
56 | 10.5M | if (LambdaClass && LambdaClass->isGenericLambda()) |
57 | 20.6k | return isLambdaCallOperator(MD) && |
58 | 20.6k | MD->isFunctionTemplateSpecialization()12.5k ; |
59 | 10.5M | return false; |
60 | 10.5M | } |
61 | | |
62 | 842 | inline bool isLambdaConversionOperator(CXXConversionDecl *C) { |
63 | 842 | return C ? C->getParent()->isLambda() : false0 ; |
64 | 842 | } |
65 | | |
66 | 17.1k | inline bool isLambdaConversionOperator(Decl *D) { |
67 | 17.1k | if (!D) return false0 ; |
68 | 17.1k | if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D)) |
69 | 801 | return isLambdaConversionOperator(Conv); |
70 | 16.3k | if (FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(D)) |
71 | 0 | if (CXXConversionDecl *Conv = |
72 | 0 | dyn_cast_or_null<CXXConversionDecl>(F->getTemplatedDecl())) |
73 | 0 | return isLambdaConversionOperator(Conv); |
74 | 16.3k | return false; |
75 | 16.3k | } |
76 | | |
77 | 7.90M | inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) { |
78 | 7.90M | return isGenericLambdaCallOperatorSpecialization( |
79 | 7.90M | dyn_cast<CXXMethodDecl>(DC)); |
80 | 7.90M | } |
81 | | |
82 | | inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization( |
83 | 170k | const DeclContext *DC) { |
84 | 170k | const auto *MD = dyn_cast<CXXMethodDecl>(DC); |
85 | 170k | if (!MD) return false87.1k ; |
86 | 82.9k | const CXXRecordDecl *LambdaClass = MD->getParent(); |
87 | 82.9k | if (LambdaClass && LambdaClass->isGenericLambda()) |
88 | 2.69k | return (isLambdaCallOperator(MD) || MD->isLambdaStaticInvoker()0 ) && |
89 | 2.69k | MD->isFunctionTemplateSpecialization(); |
90 | 80.2k | return false; |
91 | 82.9k | } |
92 | | |
93 | | // This returns the parent DeclContext ensuring that the correct |
94 | | // parent DeclContext is returned for Lambdas |
95 | 3.22M | inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) { |
96 | 3.22M | if (isLambdaCallOperator(DC)) |
97 | 37.8k | return DC->getParent()->getParent(); |
98 | 3.19M | else |
99 | 3.19M | return DC->getParent(); |
100 | 3.22M | } |
101 | | |
102 | | } // clang |
103 | | |
104 | | #endif |