blob: 37a812e71aae0b1c4b098d69ee09275f141e90fe [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,
Enea Zaffanella8c840282013-01-31 09:54:08 +000030 SourceLocation FriendL,
31 ArrayRef<TemplateParameterList*> FriendTypeTPLists) {
John McCall92b7f702010-03-11 07:50:04 +000032#ifndef NDEBUG
33 if (Friend.is<NamedDecl*>()) {
34 NamedDecl *D = Friend.get<NamedDecl*>();
35 assert(isa<FunctionDecl>(D) ||
36 isa<CXXRecordDecl>(D) ||
37 isa<FunctionTemplateDecl>(D) ||
38 isa<ClassTemplateDecl>(D));
39
40 // As a temporary hack, we permit template instantiation to point
41 // to the original declaration when instantiating members.
42 assert(D->getFriendObjectKind() ||
43 (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
Enea Zaffanella8c840282013-01-31 09:54:08 +000044 // These template parameters are for friend types only.
45 assert(FriendTypeTPLists.size() == 0);
John McCall92b7f702010-03-11 07:50:04 +000046 }
47#endif
48
Enea Zaffanella8c840282013-01-31 09:54:08 +000049 std::size_t Size = sizeof(FriendDecl)
50 + FriendTypeTPLists.size() * sizeof(TemplateParameterList*);
51 void *Mem = C.Allocate(Size);
52 FriendDecl *FD = new (Mem) FriendDecl(DC, L, Friend, FriendL,
53 FriendTypeTPLists);
John McCalld60e22e2010-03-12 01:19:31 +000054 cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
55 return FD;
John McCall92b7f702010-03-11 07:50:04 +000056}
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000057
Enea Zaffanella8c840282013-01-31 09:54:08 +000058FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID,
59 unsigned FriendTypeNumTPLists) {
60 std::size_t Size = sizeof(FriendDecl)
61 + FriendTypeNumTPLists * sizeof(TemplateParameterList*);
62 void *Mem = AllocateDeserializedDecl(C, ID, Size);
63 return new (Mem) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000064}
Enea Zaffanella8c840282013-01-31 09:54:08 +000065