clang 8.0.0

ASTLambda.h
Go to the documentation of this file.
1 //===--- ASTLambda.h - Lambda Helper Functions --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file provides some common utility functions for processing
12 /// Lambda related AST Constructs.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CLANG_AST_ASTLAMBDA_H
17 #define LLVM_CLANG_AST_ASTLAMBDA_H
18
19 #include "clang/AST/DeclCXX.h"
20 #include "clang/AST/DeclTemplate.h"
21
22 namespace clang {
23 inline StringRef getLambdaStaticInvokerName() {
24 return "__invoke";
25 }
26 // This function returns true if M is a specialization, a template,
27 // or a non-generic lambda call operator.
28 inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
29 const CXXRecordDecl *LambdaClass = MD->getParent();
30 if (!LambdaClass || !LambdaClass->isLambda()) return false;
31 return MD->getOverloadedOperator() == OO_Call;
32 }
33
34 inline bool isLambdaCallOperator(const DeclContext *DC) {
35 if (!DC || !isa<CXXMethodDecl>(DC)) return false;
36 return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
37 }
38
39 inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
40 if (!MD) return false;
41 const CXXRecordDecl *LambdaClass = MD->getParent();
42 if (LambdaClass && LambdaClass->isGenericLambda())
43 return isLambdaCallOperator(MD) &&
44 MD->isFunctionTemplateSpecialization();
45 return false;
46 }
47
48 inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
49 return C ? C->getParent()->isLambda() : false;
50 }
51
52 inline bool isLambdaConversionOperator(Decl *D) {
53 if (!D) return false;
54 if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
55 return isLambdaConversionOperator(Conv);
56 if (FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(D))
57 if (CXXConversionDecl *Conv =
58 dyn_cast_or_null<CXXConversionDecl>(F->getTemplatedDecl()))
59 return isLambdaConversionOperator(Conv);
60 return false;
61 }
62
63 inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
64 return isGenericLambdaCallOperatorSpecialization(
65 dyn_cast<CXXMethodDecl>(DC));
66 }
67
68
69 // This returns the parent DeclContext ensuring that the correct
70 // parent DeclContext is returned for Lambdas
71 inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) {
72 if (isLambdaCallOperator(DC))
73 return DC->getParent()->getParent();
74 else
75 return DC->getParent();
76 }
77
78 } // clang
79
80 #endif
clang::isLambdaConversionOperator
bool isLambdaConversionOperator(CXXConversionDecl *C)
Definition: ASTLambda.h:48
clang::isGenericLambdaCallOperatorSpecialization
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
Definition: ASTLambda.h:39
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
DeclTemplate.h
Defines the C++ template declaration subclasses.
clang::CXXRecordDecl::isLambda
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1196
clang::getLambdaAwareParentOfDeclContext
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
Definition: ASTLambda.h:71
clang::isLambdaCallOperator
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:28
clang::getLambdaStaticInvokerName
StringRef getLambdaStaticInvokerName()
Definition: ASTLambda.h:23
clang::FunctionDecl::getOverloadedOperator
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...
Definition: Decl.cpp:3300
clang::FunctionDecl::isFunctionTemplateSpecialization
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.h:2440
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1752
clang::CXXConversionDecl
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2768
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2041
clang::CXXRecordDecl::isGenericLambda
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Definition: DeclCXX.cpp:1348
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
clang::CXXMethodDecl::getParent
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
Definition: DeclCXX.h:2166
DeclCXX.h
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:969