1 //===--- DeclFriend.cpp - C++ Friend Declaration AST Node Implementation --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the AST classes related to C++ friend
13 //===----------------------------------------------------------------------===//
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/DeclFriend.h"
17 #include "clang/AST/DeclTemplate.h"
18 using namespace clang;
20 void FriendDecl::anchor() { }
22 FriendDecl *FriendDecl::getNextFriendSlowCase() {
23 return cast_or_null<FriendDecl>(
24 NextFriend.get(getASTContext().getExternalSource()));
27 FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
30 SourceLocation FriendL) {
32 if (Friend.is<NamedDecl*>()) {
33 NamedDecl *D = Friend.get<NamedDecl*>();
34 assert(isa<FunctionDecl>(D) ||
35 isa<CXXRecordDecl>(D) ||
36 isa<FunctionTemplateDecl>(D) ||
37 isa<ClassTemplateDecl>(D));
39 // As a temporary hack, we permit template instantiation to point
40 // to the original declaration when instantiating members.
41 assert(D->getFriendObjectKind() ||
42 (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
46 FriendDecl *FD = new (C) FriendDecl(DC, L, Friend, FriendL);
47 cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
51 FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
52 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendDecl));
53 return new (Mem) FriendDecl(EmptyShell());