Coverage Report

Created: 2020-09-19 12:23

/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.6k
inline StringRef getLambdaStaticInvokerName() {
23
15.6k
  return "__invoke";
24
15.6k
}
25
// This function returns true if M is a specialization, a template,
26
// or a non-generic lambda call operator.
27
10.7M
inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
28
10.7M
  const CXXRecordDecl *LambdaClass = MD->getParent();
29
10.7M
  if (!LambdaClass || !LambdaClass->isLambda()) 
return false10.5M
;
30
123k
  return MD->getOverloadedOperator() == OO_Call;
31
123k
}
32
33
60.4M
inline bool isLambdaCallOperator(const DeclContext *DC) {
34
60.4M
  if (!DC || 
!isa<CXXMethodDecl>(DC)53.4M
)
return false49.9M
;
35
10.5M
  return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
36
10.5M
}
37
38
10.5M
inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
39
10.5M
  if (!MD) 
return false4.19M
;
40
6.33M
  const CXXRecordDecl *LambdaClass = MD->getParent();
41
6.33M
  if (LambdaClass && LambdaClass->isGenericLambda())
42
10.5k
    return isLambdaCallOperator(MD) &&
43
6.28k
                    MD->isFunctionTemplateSpecialization();
44
6.32M
  return false;
45
6.32M
}
46
47
295
inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
48
295
  return C ? C->getParent()->isLambda() : 
false0
;
49
295
}
50
51
5.70k
inline bool isLambdaConversionOperator(Decl *D) {
52
5.70k
  if (!D) 
return false0
;
53
5.70k
  if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
54
295
    return isLambdaConversionOperator(Conv);
55
5.40k
  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
5.40k
  return false;
60
5.40k
}
61
62
4.81M
inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
63
4.81M
  return isGenericLambdaCallOperatorSpecialization(
64
4.81M
                                          dyn_cast<CXXMethodDecl>(DC));
65
4.81M
}
66
67
inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(
68
92.5k
    DeclContext *DC) {
69
92.5k
  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
70
92.5k
  if (!MD) 
return false53.7k
;
71
38.8k
  const CXXRecordDecl *LambdaClass = MD->getParent();
72
38.8k
  if (LambdaClass && LambdaClass->isGenericLambda())
73
1.36k
    return (isLambdaCallOperator(MD) || 
MD->isLambdaStaticInvoker()0
) &&
74
1.36k
                    MD->isFunctionTemplateSpecialization();
75
37.4k
  return false;
76
37.4k
}
77
78
79
// This returns the parent DeclContext ensuring that the correct
80
// parent DeclContext is returned for Lambdas
81
2.47M
inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) {
82
2.47M
  if (isLambdaCallOperator(DC))
83
26.2k
    return DC->getParent()->getParent();
84
2.44M
  else
85
2.44M
    return DC->getParent();
86
2.47M
}
87
88
} // clang
89
90
#endif