clang API Documentation
00001 //===--- DeclFriend.cpp - C++ Friend Declaration AST Node Implementation --===// 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 // This file implements the AST classes related to C++ friend 00011 // declarations. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "clang/AST/ASTContext.h" 00016 #include "clang/AST/DeclFriend.h" 00017 #include "clang/AST/DeclTemplate.h" 00018 using namespace clang; 00019 00020 void FriendDecl::anchor() { } 00021 00022 FriendDecl *FriendDecl::getNextFriendSlowCase() { 00023 return cast_or_null<FriendDecl>( 00024 NextFriend.get(getASTContext().getExternalSource())); 00025 } 00026 00027 FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC, 00028 SourceLocation L, 00029 FriendUnion Friend, 00030 SourceLocation FriendL, 00031 ArrayRef<TemplateParameterList*> FriendTypeTPLists) { 00032 #ifndef NDEBUG 00033 if (Friend.is<NamedDecl*>()) { 00034 NamedDecl *D = Friend.get<NamedDecl*>(); 00035 assert(isa<FunctionDecl>(D) || 00036 isa<CXXRecordDecl>(D) || 00037 isa<FunctionTemplateDecl>(D) || 00038 isa<ClassTemplateDecl>(D)); 00039 00040 // As a temporary hack, we permit template instantiation to point 00041 // to the original declaration when instantiating members. 00042 assert(D->getFriendObjectKind() || 00043 (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind())); 00044 // These template parameters are for friend types only. 00045 assert(FriendTypeTPLists.size() == 0); 00046 } 00047 #endif 00048 00049 std::size_t Extra = FriendTypeTPLists.size() * sizeof(TemplateParameterList*); 00050 FriendDecl *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL, 00051 FriendTypeTPLists); 00052 cast<CXXRecordDecl>(DC)->pushFriendDecl(FD); 00053 return FD; 00054 } 00055 00056 FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID, 00057 unsigned FriendTypeNumTPLists) { 00058 std::size_t Extra = FriendTypeNumTPLists * sizeof(TemplateParameterList*); 00059 return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists); 00060 } 00061 00062 FriendDecl *CXXRecordDecl::getFirstFriend() const { 00063 ExternalASTSource *Source = getParentASTContext().getExternalSource(); 00064 Decl *First = data().FirstFriend.get(Source); 00065 return First ? cast<FriendDecl>(First) : nullptr; 00066 }