]> granicus.if.org Git - clang/blob - include/clang/AST/ASTLambda.h
Implement conversion to function pointer for generic lambdas without captures.
[clang] / include / clang / AST / ASTLambda.h
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 /// \brief This file provides some common utility functions for processing
12 /// Lambda related AST Constructs.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CLANG_AST_LAMBDA_H
17 #define LLVM_CLANG_AST_LAMBDA_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(CXXMethodDecl *MD) {
40   if (!MD) return false;
41   CXXRecordDecl *LambdaClass = MD->getParent();
42   if (LambdaClass && LambdaClass->isGenericLambda())
43     return isLambdaCallOperator(MD) && 
44                     MD->isFunctionTemplateSpecialization();
45   return false;
46 }
47
48 inline bool isGenericLambdaCallOperatorSpecialization(Decl *D) {
49   if (!D || !isa<CXXMethodDecl>(D)) return false;
50   return isGenericLambdaCallOperatorSpecialization(
51                                 cast<CXXMethodDecl>(D));
52 }
53
54 inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
55   return C ? C->getParent()->isLambda() : false;
56 }
57
58 inline bool isLambdaConversionOperator(Decl *D) {
59   if (!D) return false;
60   if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D)) 
61     return isLambdaConversionOperator(Conv);  
62   if (FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(D)) 
63     if (CXXConversionDecl *Conv = 
64         dyn_cast_or_null<CXXConversionDecl>(F->getTemplatedDecl())) 
65       return isLambdaConversionOperator(Conv);
66   return false;
67 }
68
69 inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
70   return isGenericLambdaCallOperatorSpecialization(
71                                           dyn_cast<CXXMethodDecl>(DC));
72 }
73
74 } // clang
75
76 #endif // LLVM_CLANG_AST_LAMBDA_H