clang  14.0.0git
ASTLambda.h
Go to the documentation of this file.
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 inline StringRef getLambdaStaticInvokerName() {
23  return "__invoke";
24 }
25 // This function returns true if M is a specialization, a template,
26 // or a non-generic lambda call operator.
27 inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
28  const CXXRecordDecl *LambdaClass = MD->getParent();
29  if (!LambdaClass || !LambdaClass->isLambda()) return false;
30  return MD->getOverloadedOperator() == OO_Call;
31 }
32 
33 inline bool isLambdaCallOperator(const DeclContext *DC) {
34  if (!DC || !isa<CXXMethodDecl>(DC)) return false;
35  return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
36 }
37 
39  if (!MD) return false;
40  const CXXRecordDecl *LambdaClass = MD->getParent();
41  if (LambdaClass && LambdaClass->isGenericLambda())
42  return isLambdaCallOperator(MD) &&
44  return false;
45 }
46 
48  return C ? C->getParent()->isLambda() : false;
49 }
50 
52  if (!D) return false;
53  if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
54  return isLambdaConversionOperator(Conv);
55  if (FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(D))
56  if (CXXConversionDecl *Conv =
57  dyn_cast_or_null<CXXConversionDecl>(F->getTemplatedDecl()))
58  return isLambdaConversionOperator(Conv);
59  return false;
60 }
61 
64  dyn_cast<CXXMethodDecl>(DC));
65 }
66 
68  DeclContext *DC) {
69  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
70  if (!MD) return false;
71  const CXXRecordDecl *LambdaClass = MD->getParent();
72  if (LambdaClass && LambdaClass->isGenericLambda())
73  return (isLambdaCallOperator(MD) || MD->isLambdaStaticInvoker()) &&
75  return false;
76 }
77 
78 
79 // This returns the parent DeclContext ensuring that the correct
80 // parent DeclContext is returned for Lambdas
82  if (isLambdaCallOperator(DC))
83  return DC->getParent()->getParent();
84  else
85  return DC->getParent();
86 }
87 
88 } // clang
89 
90 #endif
clang::isLambdaCallOperator
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:27
clang::isGenericLambdaCallOperatorSpecialization
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
Definition: ASTLambda.h:38
clang::CXXMethodDecl::isLambdaStaticInvoker
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Definition: DeclCXX.cpp:2484
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
clang::CXXConversionDecl
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2731
DeclCXX.h
clang::getLambdaAwareParentOfDeclContext
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
Definition: ASTLambda.h:81
clang::CXXRecordDecl::isGenericLambda
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Definition: DeclCXX.cpp:1479
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:974
DeclTemplate.h
clang::isGenericLambdaCallOperatorOrStaticInvokerSpecialization
bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(DeclContext *DC)
Definition: ASTLambda.h:67
clang::FunctionDecl::getOverloadedOperator
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition: Decl.cpp:3631
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1860
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang
Definition: CalledOnceCheck.h:17
clang::CXXRecordDecl::isLambda
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:992
clang::FunctionDecl::isFunctionTemplateSpecialization
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.h:2689
clang::getLambdaStaticInvokerName
StringRef getLambdaStaticInvokerName()
Definition: ASTLambda.h:22
clang::isLambdaConversionOperator
bool isLambdaConversionOperator(CXXConversionDecl *C)
Definition: ASTLambda.h:47
clang::CXXMethodDecl::getParent
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition: DeclCXX.h:2063
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1948