clang  6.0.0svn
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 /// \brief 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 
40  if (!MD) return false;
41  const CXXRecordDecl *LambdaClass = MD->getParent();
42  if (LambdaClass && LambdaClass->isGenericLambda())
43  return isLambdaCallOperator(MD) &&
45  return false;
46 }
47 
49  return C ? C->getParent()->isLambda() : false;
50 }
51 
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 
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
72  if (isLambdaCallOperator(DC))
73  return DC->getParent()->getParent();
74  else
75  return DC->getParent();
76 }
77 
78 } // clang
79 
80 #endif
bool isLambdaConversionOperator(CXXConversionDecl *C)
Definition: ASTLambda.h:48
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
Definition: ASTLambda.h:39
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Defines the C++ template declaration subclasses.
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1152
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
Definition: ASTLambda.h:71
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:28
StringRef getLambdaStaticInvokerName()
Definition: ASTLambda.h:23
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...
Definition: Decl.cpp:3168
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.h:2329
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1331
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2682
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1964
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Definition: DeclCXX.cpp:1116
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
Definition: DeclCXX.h:2085
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
Declaration of a template function.
Definition: DeclTemplate.h:967