blob: 6e3bd8d4225b88a383a4d5960a5d800dd42a0eb2 [file] [log] [blame]
John McCall92b7f702010-03-11 07:50:04 +00001//===--- 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"
17using namespace clang;
18
David Blaikie99ba9e32011-12-20 02:48:34 +000019void FriendDecl::anchor() { }
20
John McCall92b7f702010-03-11 07:50:04 +000021FriendDecl *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 McCalld60e22e2010-03-12 01:19:31 +000040 FriendDecl *FD = new (C) FriendDecl(DC, L, Friend, FriendL);
41 cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
42 return FD;
John McCall92b7f702010-03-11 07:50:04 +000043}
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000044
Douglas Gregor1e68ecc2012-01-05 21:55:30 +000045FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
46 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendDecl));
47 return new (Mem) FriendDecl(EmptyShell());
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000048}