Coverage Report

Created: 2021-08-24 07:12

/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
18.9k
inline StringRef getLambdaStaticInvokerName() {
23
18.9k
  return "__invoke";
24
18.9k
}
25
// This function returns true if M is a specialization, a template,
26
// or a non-generic lambda call operator.
27
11.2M
inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
28
11.2M
  const CXXRecordDecl *LambdaClass = MD->getParent();
29
11.2M
  if (!LambdaClass || !LambdaClass->isLambda()) 
return false11.0M
;
30
161k
  return MD->getOverloadedOperator() == OO_Call;
31
11.2M
}
32
33
100M
inline bool isLambdaCallOperator(const DeclContext *DC) {
34
100M
  if (!DC || 
!isa<CXXMethodDecl>(DC)92.8M
)
return false89.8M
;
35
11.0M
  return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
36
100M
}
37
38
11.5M
inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
39
11.5M
  if (!MD) 
return false4.68M
;
40
6.89M
  const CXXRecordDecl *LambdaClass = MD->getParent();
41
6.89M
  if (LambdaClass && LambdaClass->isGenericLambda())
42
19.2k
    return isLambdaCallOperator(MD) &&
43
19.2k
                    
MD->isFunctionTemplateSpecialization()11.4k
;
44
6.87M
  return false;
45
6.89M
}
46
47
786
inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
48
786
  return C ? C->getParent()->isLambda() : 
false0
;
49
786
}
50
51
9.95k
inline bool isLambdaConversionOperator(Decl *D) {
52
9.95k
  if (!D) 
return false0
;
53
9.95k
  if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
54
786
    return isLambdaConversionOperator(Conv);
55
9.16k
  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
9.16k
  return false;
60
9.16k
}
61
62
5.24M
inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
63
5.24M
  return isGenericLambdaCallOperatorSpecialization(
64
5.24M
                                          dyn_cast<CXXMethodDecl>(DC));
65
5.24M
}
66
67
inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(
68
97.4k
    DeclContext *DC) {
69
97.4k
  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
70
97.4k
  if (!MD) 
return false60.4k
;
71
36.9k
  const CXXRecordDecl *LambdaClass = MD->getParent();
72
36.9k
  if (LambdaClass && LambdaClass->isGenericLambda())
73
2.53k
    return (isLambdaCallOperator(MD) || 
MD->isLambdaStaticInvoker()0
) &&
74
2.53k
                    MD->isFunctionTemplateSpecialization();
75
34.4k
  return false;
76
36.9k
}
77
78
79
// This returns the parent DeclContext ensuring that the correct
80
// parent DeclContext is returned for Lambdas
81
2.49M
inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) {
82
2.49M
  if (isLambdaCallOperator(DC))
83
31.4k
    return DC->getParent()->getParent();
84
2.46M
  else
85
2.46M
    return DC->getParent();
86
2.49M
}
87
88
} // clang
89
90
#endif