123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #pragma once
- #ifdef __GNUC__
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wunused-parameter"
- #endif
- //===--- ASTLambda.h - Lambda Helper Functions --------------*- C++ -*-===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- ///
- /// \file
- /// This file provides some common utility functions for processing
- /// Lambda related AST Constructs.
- ///
- //===----------------------------------------------------------------------===//
- #ifndef LLVM_CLANG_AST_ASTLAMBDA_H
- #define LLVM_CLANG_AST_ASTLAMBDA_H
- #include "clang/AST/DeclCXX.h"
- #include "clang/AST/DeclTemplate.h"
- namespace clang {
- inline StringRef getLambdaStaticInvokerName() {
- return "__invoke";
- }
- // This function returns true if M is a specialization, a template,
- // or a non-generic lambda call operator.
- inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
- const CXXRecordDecl *LambdaClass = MD->getParent();
- if (!LambdaClass || !LambdaClass->isLambda()) return false;
- return MD->getOverloadedOperator() == OO_Call;
- }
- inline bool isLambdaCallOperator(const DeclContext *DC) {
- if (!DC || !isa<CXXMethodDecl>(DC)) return false;
- return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
- }
- inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
- if (!MD) return false;
- const CXXRecordDecl *LambdaClass = MD->getParent();
- if (LambdaClass && LambdaClass->isGenericLambda())
- return isLambdaCallOperator(MD) &&
- MD->isFunctionTemplateSpecialization();
- return false;
- }
- inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
- return C ? C->getParent()->isLambda() : false;
- }
- inline bool isLambdaConversionOperator(Decl *D) {
- if (!D) return false;
- if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D))
- return isLambdaConversionOperator(Conv);
- if (FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(D))
- if (CXXConversionDecl *Conv =
- dyn_cast_or_null<CXXConversionDecl>(F->getTemplatedDecl()))
- return isLambdaConversionOperator(Conv);
- return false;
- }
- inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
- return isGenericLambdaCallOperatorSpecialization(
- dyn_cast<CXXMethodDecl>(DC));
- }
- inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(
- DeclContext *DC) {
- CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
- if (!MD) return false;
- const CXXRecordDecl *LambdaClass = MD->getParent();
- if (LambdaClass && LambdaClass->isGenericLambda())
- return (isLambdaCallOperator(MD) || MD->isLambdaStaticInvoker()) &&
- MD->isFunctionTemplateSpecialization();
- return false;
- }
- // This returns the parent DeclContext ensuring that the correct
- // parent DeclContext is returned for Lambdas
- inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) {
- if (isLambdaCallOperator(DC))
- return DC->getParent()->getParent();
- else
- return DC->getParent();
- }
- } // clang
- #endif
- #ifdef __GNUC__
- #pragma GCC diagnostic pop
- #endif
|