Coverage Report

Created: 2020-02-25 14:32

/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.0k
inline StringRef getLambdaStaticInvokerName() {
23
15.0k
  return "__invoke";
24
15.0k
}
25
// This function returns true if M is a specialization, a template,
26
// or a non-generic lambda call operator.
27
11.8M
inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
28
11.8M
  const CXXRecordDecl *LambdaClass = MD->getParent();
29
11.8M
  if (!LambdaClass || !LambdaClass->isLambda()) 
return false11.7M
;
30
131k
  return MD->getOverloadedOperator() == OO_Call;
31
131k
}
32
33
61.4M
inline bool isLambdaCallOperator(const DeclContext *DC) {
34
61.4M
  if (!DC || 
!isa<CXXMethodDecl>(DC)56.1M
)
return false49.7M
;
35
11.6M
  return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
36
11.6M
}
37
38
9.56M
inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
39
9.56M
  if (!MD) 
return false3.50M
;
40
6.06M
  const CXXRecordDecl *LambdaClass = MD->getParent();
41
6.06M
  if (LambdaClass && LambdaClass->isGenericLambda())
42
10.1k
    return isLambdaCallOperator(MD) &&
43
10.1k
                    
MD->isFunctionTemplateSpecialization()6.12k
;
44
6.05M
  return false;
45
6.05M
}
46
47
295
inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
48
295
  return C ? C->getParent()->isLambda() : 
false0
;
49
295
}
50
51
5.43k
inline bool isLambdaConversionOperator(Decl *D) {
52
5.43k
  if (!D) 
return false0
;
53
5.43k
  if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
54
295
    return isLambdaConversionOperator(Conv);
55
5.14k
  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.14k
  return false;
60
5.14k
}
61
62
4.16M
inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
63
4.16M
  return isGenericLambdaCallOperatorSpecialization(
64
4.16M
                                          dyn_cast<CXXMethodDecl>(DC));
65
4.16M
}
66
67
inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(
68
92.0k
    DeclContext *DC) {
69
92.0k
  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
70
92.0k
  if (!MD) 
return false53.8k
;
71
38.1k
  const CXXRecordDecl *LambdaClass = MD->getParent();
72
38.1k
  if (LambdaClass && LambdaClass->isGenericLambda())
73
1.30k
    return (isLambdaCallOperator(MD) || 
MD->isLambdaStaticInvoker()0
) &&
74
1.30k
                    MD->isFunctionTemplateSpecialization();
75
36.8k
  return false;
76
36.8k
}
77
78
79
// This returns the parent DeclContext ensuring that the correct
80
// parent DeclContext is returned for Lambdas
81
2.05M
inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) {
82
2.05M
  if (isLambdaCallOperator(DC))
83
25.1k
    return DC->getParent()->getParent();
84
2.02M
  else
85
2.02M
    return DC->getParent();
86
2.05M
}
87
88
} // clang
89
90
#endif