Coverage Report

Created: 2022-07-16 07:03

/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
16.3k
inline StringRef getLambdaStaticInvokerName() {
23
16.3k
  return "__invoke";
24
16.3k
}
25
// This function returns true if M is a specialization, a template,
26
// or a non-generic lambda call operator.
27
15.7M
inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
28
15.7M
  const CXXRecordDecl *LambdaClass = MD->getParent();
29
15.7M
  if (!LambdaClass || !LambdaClass->isLambda()) 
return false15.5M
;
30
171k
  return MD->getOverloadedOperator() == OO_Call;
31
15.7M
}
32
33
115M
inline bool isLambdaCallOperator(const DeclContext *DC) {
34
115M
  if (!DC || 
!isa<CXXMethodDecl>(DC)106M
)
return false99.9M
;
35
15.4M
  return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
36
115M
}
37
38
13.2M
inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
39
13.2M
  if (!MD) 
return false4.85M
;
40
8.35M
  const CXXRecordDecl *LambdaClass = MD->getParent();
41
8.35M
  if (LambdaClass && LambdaClass->isGenericLambda())
42
20.2k
    return isLambdaCallOperator(MD) &&
43
20.2k
                    
MD->isFunctionTemplateSpecialization()12.3k
;
44
8.33M
  return false;
45
8.35M
}
46
47
788
inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
48
788
  return C ? C->getParent()->isLambda() : 
false0
;
49
788
}
50
51
14.0k
inline bool isLambdaConversionOperator(Decl *D) {
52
14.0k
  if (!D) 
return false0
;
53
14.0k
  if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
54
788
    return isLambdaConversionOperator(Conv);
55
13.3k
  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
13.3k
  return false;
60
13.3k
}
61
62
5.74M
inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
63
5.74M
  return isGenericLambdaCallOperatorSpecialization(
64
5.74M
                                          dyn_cast<CXXMethodDecl>(DC));
65
5.74M
}
66
67
inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(
68
113k
    const DeclContext *DC) {
69
113k
  const auto *MD = dyn_cast<CXXMethodDecl>(DC);
70
113k
  if (!MD) 
return false68.3k
;
71
45.2k
  const CXXRecordDecl *LambdaClass = MD->getParent();
72
45.2k
  if (LambdaClass && LambdaClass->isGenericLambda())
73
2.63k
    return (isLambdaCallOperator(MD) || 
MD->isLambdaStaticInvoker()0
) &&
74
2.63k
                    MD->isFunctionTemplateSpecialization();
75
42.6k
  return false;
76
45.2k
}
77
78
// This returns the parent DeclContext ensuring that the correct
79
// parent DeclContext is returned for Lambdas
80
2.70M
inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) {
81
2.70M
  if (isLambdaCallOperator(DC))
82
33.8k
    return DC->getParent()->getParent();
83
2.67M
  else
84
2.67M
    return DC->getParent();
85
2.70M
}
86
87
} // clang
88
89
#endif