Coverage Report

Created: 2022-05-14 11:35

/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
15.5k
inline StringRef getLambdaStaticInvokerName() {
23
15.5k
  return "__invoke";
24
15.5k
}
25
// This function returns true if M is a specialization, a template,
26
// or a non-generic lambda call operator.
27
11.1M
inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
28
11.1M
  const CXXRecordDecl *LambdaClass = MD->getParent();
29
11.1M
  if (!LambdaClass || !LambdaClass->isLambda()) 
return false10.9M
;
30
165k
  return MD->getOverloadedOperator() == OO_Call;
31
11.1M
}
32
33
100M
inline bool isLambdaCallOperator(const DeclContext *DC) {
34
100M
  if (!DC || 
!isa<CXXMethodDecl>(DC)92.4M
)
return false89.3M
;
35
10.8M
  return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
36
100M
}
37
38
11.7M
inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
39
11.7M
  if (!MD) 
return false4.57M
;
40
7.18M
  const CXXRecordDecl *LambdaClass = MD->getParent();
41
7.18M
  if (LambdaClass && LambdaClass->isGenericLambda())
42
19.4k
    return isLambdaCallOperator(MD) &&
43
19.4k
                    
MD->isFunctionTemplateSpecialization()11.6k
;
44
7.16M
  return false;
45
7.18M
}
46
47
786
inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
48
786
  return C ? C->getParent()->isLambda() : 
false0
;
49
786
}
50
51
12.8k
inline bool isLambdaConversionOperator(Decl *D) {
52
12.8k
  if (!D) 
return false0
;
53
12.8k
  if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
54
786
    return isLambdaConversionOperator(Conv);
55
12.0k
  if (FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(D))
56
0
    if (CXXConversionDecl *Conv =
57
0
        dyn_cast_or_null<CXXConversionDecl>(F->getTemplatedDecl()))
58
0
      return isLambdaConversionOperator(Conv);
59
12.0k
  return false;
60
12.0k
}
61
62
5.15M
inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
63
5.15M
  return isGenericLambdaCallOperatorSpecialization(
64
5.15M
                                          dyn_cast<CXXMethodDecl>(DC));
65
5.15M
}
66
67
inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(
68
103k
    const DeclContext *DC) {
69
103k
  const auto *MD = dyn_cast<CXXMethodDecl>(DC);
70
103k
  if (!MD) 
return false65.2k
;
71
38.2k
  const CXXRecordDecl *LambdaClass = MD->getParent();
72
38.2k
  if (LambdaClass && LambdaClass->isGenericLambda())
73
2.57k
    return (isLambdaCallOperator(MD) || 
MD->isLambdaStaticInvoker()0
) &&
74
2.57k
                    MD->isFunctionTemplateSpecialization();
75
35.6k
  return false;
76
38.2k
}
77
78
// This returns the parent DeclContext ensuring that the correct
79
// parent DeclContext is returned for Lambdas
80
2.54M
inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) {
81
2.54M
  if (isLambdaCallOperator(DC))
82
32.2k
    return DC->getParent()->getParent();
83
2.51M
  else
84
2.51M
    return DC->getParent();
85
2.54M
}
86
87
} // clang
88
89
#endif