clang API Documentation

ASTLambda.h
Go to the documentation of this file.
00001 //===--- ASTLambda.h - Lambda Helper Functions --------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief This file provides some common utility functions for processing
00012 /// Lambda related AST Constructs.
00013 ///
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_CLANG_AST_ASTLAMBDA_H
00017 #define LLVM_CLANG_AST_ASTLAMBDA_H
00018 
00019 #include "clang/AST/DeclCXX.h"
00020 #include "clang/AST/DeclTemplate.h"
00021 
00022 namespace clang {
00023 inline StringRef getLambdaStaticInvokerName() {
00024   return "__invoke";
00025 }
00026 // This function returns true if M is a specialization, a template,
00027 // or a non-generic lambda call operator.
00028 inline bool isLambdaCallOperator(const CXXMethodDecl *MD) {
00029   const CXXRecordDecl *LambdaClass = MD->getParent();
00030   if (!LambdaClass || !LambdaClass->isLambda()) return false;
00031   return MD->getOverloadedOperator() == OO_Call;
00032 }
00033 
00034 inline bool isLambdaCallOperator(const DeclContext *DC) {
00035   if (!DC || !isa<CXXMethodDecl>(DC)) return false;
00036   return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
00037 }
00038 
00039 inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
00040   if (!MD) return false;
00041   const CXXRecordDecl *LambdaClass = MD->getParent();
00042   if (LambdaClass && LambdaClass->isGenericLambda())
00043     return isLambdaCallOperator(MD) && 
00044                     MD->isFunctionTemplateSpecialization();
00045   return false;
00046 }
00047 
00048 inline bool isLambdaConversionOperator(CXXConversionDecl *C) {
00049   return C ? C->getParent()->isLambda() : false;
00050 }
00051 
00052 inline bool isLambdaConversionOperator(Decl *D) {
00053   if (!D) return false;
00054   if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D)) 
00055     return isLambdaConversionOperator(Conv);  
00056   if (FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(D)) 
00057     if (CXXConversionDecl *Conv = 
00058         dyn_cast_or_null<CXXConversionDecl>(F->getTemplatedDecl())) 
00059       return isLambdaConversionOperator(Conv);
00060   return false;
00061 }
00062 
00063 inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
00064   return isGenericLambdaCallOperatorSpecialization(
00065                                           dyn_cast<CXXMethodDecl>(DC));
00066 }
00067 
00068 
00069 // This returns the parent DeclContext ensuring that the correct
00070 // parent DeclContext is returned for Lambdas
00071 inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) {
00072   if (isLambdaCallOperator(DC))
00073     return DC->getParent()->getParent();
00074   else 
00075     return DC->getParent();
00076 }
00077 
00078 } // clang
00079 
00080 #endif