blob: 553d170fc3d5112b4bed98c60b420c596cb72ff5 [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
Benjamin Kramer471c8b42012-07-04 20:19:54 +000015#include "clang/AST/ASTContext.h"
John McCall92b7f702010-03-11 07:50:04 +000016#include "clang/AST/DeclFriend.h"
17#include "clang/AST/DeclTemplate.h"
18using namespace clang;
19
David Blaikie99ba9e32011-12-20 02:48:34 +000020void FriendDecl::anchor() { }
21
Benjamin Kramer471c8b42012-07-04 20:19:54 +000022FriendDecl *FriendDecl::getNextFriendSlowCase() {
23 return cast_or_null<FriendDecl>(
24 NextFriend.get(getASTContext().getExternalSource()));
25}
26
John McCall92b7f702010-03-11 07:50:04 +000027FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
28 SourceLocation L,
29 FriendUnion Friend,
30 SourceLocation FriendL) {
31#ifndef NDEBUG
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));
38
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()));
43 }
44#endif
45
John McCalld60e22e2010-03-12 01:19:31 +000046 FriendDecl *FD = new (C) FriendDecl(DC, L, Friend, FriendL);
47 cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
48 return FD;
John McCall92b7f702010-03-11 07:50:04 +000049}
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000050
Douglas Gregor1e68ecc2012-01-05 21:55:30 +000051FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
52 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendDecl));
53 return new (Mem) FriendDecl(EmptyShell());
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000054}