Coverage Report

Created: 2021-01-19 06:58

/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
17.4k
inline StringRef getLambdaStaticInvokerName() {
23
17.4k
  return "__invoke";
24
17.4k
}
25
// This function returns true if M is a specialization, a template,
26
// or a non-generic lambda call operator.
27
10.8M
inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
28
10.8M
  const CXXRecordDecl *LambdaClass = MD->getParent();
29
10.8M
  if (!LambdaClass || !LambdaClass->isLambda()) 
return false10.7M
;
30
155k
  return MD->getOverloadedOperator() == OO_Call;
31
155k
}
32
33
62.1M
inline bool isLambdaCallOperator(const DeclContext *DC) {
34
62.1M
  if (!DC || 
!isa<CXXMethodDecl>(DC)54.7M
)
return false51.4M
;
35
10.6M
  return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
36
10.6M
}
37
38
10.9M
inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
39
10.9M
  if (!MD) 
return false4.30M
;
40
6.60M
  const CXXRecordDecl *LambdaClass = MD->getParent();
41
6.60M
  if (LambdaClass && 
LambdaClass->isGenericLambda()6.60M
)
42
18.6k
    return isLambdaCallOperator(MD) &&
43
11.1k
                    MD->isFunctionTemplateSpecialization();
44
6.58M
  return false;
45
6.58M
}
46
47
733
inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
48
733
  return C ? C->getParent()->isLambda() : 
false0
;
49
733
}
50
51
8.77k
inline bool isLambdaConversionOperator(Decl *D) {
52
8.77k
  if (!D) 
return false0
;
53
8.77k
  if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
54
733
    return isLambdaConversionOperator(Conv);
55
8.03k
  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
8.03k
  return false;
60
8.03k
}
61
62
4.93M
inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
63
4.93M
  return isGenericLambdaCallOperatorSpecialization(
64
4.93M
                                          dyn_cast<CXXMethodDecl>(DC));
65
4.93M
}
66
67
inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(
68
94.4k
    DeclContext *DC) {
69
94.4k
  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
70
94.4k
  if (!MD) 
return false56.2k
;
71
38.2k
  const CXXRecordDecl *LambdaClass = MD->getParent();
72
38.2k
  if (LambdaClass && LambdaClass->isGenericLambda())
73
2.46k
    return (isLambdaCallOperator(MD) || 
MD->isLambdaStaticInvoker()0
) &&
74
2.46k
                    MD->isFunctionTemplateSpecialization();
75
35.7k
  return false;
76
35.7k
}
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
30.2k
    return DC->getParent()->getParent();
84
2.46M
  else
85
2.46M
    return DC->getParent();
86
2.49M
}
87
88
} // clang
89
90
#endif