John McCall | 92b7f70 | 2010-03-11 07:50:04 +0000 | [diff] [blame] | 1 | //===--- DeclFriend.cpp - C++ Friend Declaration AST Node Implementation --===// |
| 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 | // This file implements the AST classes related to C++ friend |
| 11 | // declarations. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/AST/DeclFriend.h" |
| 16 | #include "clang/AST/DeclTemplate.h" |
| 17 | using namespace clang; |
| 18 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 19 | void FriendDecl::anchor() { } |
| 20 | |
John McCall | 92b7f70 | 2010-03-11 07:50:04 +0000 | [diff] [blame] | 21 | FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC, |
| 22 | SourceLocation L, |
| 23 | FriendUnion Friend, |
| 24 | SourceLocation FriendL) { |
| 25 | #ifndef NDEBUG |
| 26 | if (Friend.is<NamedDecl*>()) { |
| 27 | NamedDecl *D = Friend.get<NamedDecl*>(); |
| 28 | assert(isa<FunctionDecl>(D) || |
| 29 | isa<CXXRecordDecl>(D) || |
| 30 | isa<FunctionTemplateDecl>(D) || |
| 31 | isa<ClassTemplateDecl>(D)); |
| 32 | |
| 33 | // As a temporary hack, we permit template instantiation to point |
| 34 | // to the original declaration when instantiating members. |
| 35 | assert(D->getFriendObjectKind() || |
| 36 | (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind())); |
| 37 | } |
| 38 | #endif |
| 39 | |
John McCall | d60e22e | 2010-03-12 01:19:31 +0000 | [diff] [blame] | 40 | FriendDecl *FD = new (C) FriendDecl(DC, L, Friend, FriendL); |
| 41 | cast<CXXRecordDecl>(DC)->pushFriendDecl(FD); |
| 42 | return FD; |
John McCall | 92b7f70 | 2010-03-11 07:50:04 +0000 | [diff] [blame] | 43 | } |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 44 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 45 | FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 46 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendDecl)); |
| 47 | return new (Mem) FriendDecl(EmptyShell()); |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 48 | } |