clang 19.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"
20
21namespace clang {
22inline 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.
27inline 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
33inline bool isLambdaCallOperator(const DeclContext *DC) {
34 if (!DC || !isa<CXXMethodDecl>(DC)) return false;
35 return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
36}
37
39 return isLambdaCallOperator(DC) &&
40 cast<CXXMethodDecl>(DC)->isExplicitObjectMemberFunction();
41}
42
44 return isLambdaCallOperator(DC) &&
45 // FIXME: Checking for a null type is not great
46 // but lambdas with invalid captures or whose closure parameter list
47 // have not fully been parsed may have a call operator whose type is
48 // null.
49 !cast<CXXMethodDecl>(DC)->getType().isNull() &&
50 !cast<CXXMethodDecl>(DC)->isExplicitObjectMemberFunction();
51}
52
54 if (!MD) return false;
55 const CXXRecordDecl *LambdaClass = MD->getParent();
56 if (LambdaClass && LambdaClass->isGenericLambda())
57 return isLambdaCallOperator(MD) &&
59 return false;
60}
61
63 return C ? C->getParent()->isLambda() : false;
64}
65
67 if (!D) return false;
68 if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
69 return isLambdaConversionOperator(Conv);
70 if (FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(D))
71 if (CXXConversionDecl *Conv =
72 dyn_cast_or_null<CXXConversionDecl>(F->getTemplatedDecl()))
73 return isLambdaConversionOperator(Conv);
74 return false;
75}
76
79 dyn_cast<CXXMethodDecl>(DC));
80}
81
83 const DeclContext *DC) {
84 const auto *MD = dyn_cast<CXXMethodDecl>(DC);
85 if (!MD) return false;
86 const CXXRecordDecl *LambdaClass = MD->getParent();
87 if (LambdaClass && LambdaClass->isGenericLambda())
88 return (isLambdaCallOperator(MD) || MD->isLambdaStaticInvoker()) &&
89 MD->isFunctionTemplateSpecialization();
90 return false;
91}
92
93// This returns the parent DeclContext ensuring that the correct
94// parent DeclContext is returned for Lambdas
97 return DC->getParent()->getParent();
98 else
99 return DC->getParent();
100}
101
102} // clang
103
104#endif
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2862
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition: DeclCXX.h:2186
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Definition: DeclCXX.cpp:1564
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1022
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2066
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.cpp:4054
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition: Decl.cpp:3979
Declaration of a template function.
Definition: DeclTemplate.h:958
The JSON file list parser is used to communicate input to InstallAPI.
bool isLambdaCallWithImplicitObjectParameter(const DeclContext *DC)
Definition: ASTLambda.h:43
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
Definition: ASTLambda.h:95
bool isLambdaCallWithExplicitObjectParameter(const DeclContext *DC)
Definition: ASTLambda.h:38
bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(const DeclContext *DC)
Definition: ASTLambda.h:82
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:27
bool isLambdaConversionOperator(CXXConversionDecl *C)
Definition: ASTLambda.h:62
StringRef getLambdaStaticInvokerName()
Definition: ASTLambda.h:22
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
Definition: ASTLambda.h:53