DeclFriend.cpp revision 99ba9e3bd70671f3441fb974895f226a83ce0e66
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"
17using namespace clang;
18
19void FriendDecl::anchor() { }
20
21FriendDecl *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
45FriendDecl *FriendDecl::Create(ASTContext &C, EmptyShell Empty) {
46  return new (C) FriendDecl(Empty);
47}
48