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
anchor()19 void FriendDecl::anchor() { }
20
Create(ASTContext & C,DeclContext * DC,SourceLocation L,FriendUnion Friend,SourceLocation FriendL)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
40 FriendDecl *FD = new (C) FriendDecl(DC, L, Friend, FriendL);
41 cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
42 return FD;
43 }
44
CreateDeserialized(ASTContext & C,unsigned ID)45 FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
46 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendDecl));
47 return new (Mem) FriendDecl(EmptyShell());
48 }
49