clang  3.7.0
DeclFriend.cpp
Go to the documentation of this file.
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/ASTContext.h"
16 #include "clang/AST/DeclFriend.h"
17 #include "clang/AST/DeclTemplate.h"
18 using namespace clang;
19 
20 void FriendDecl::anchor() { }
21 
22 FriendDecl *FriendDecl::getNextFriendSlowCase() {
23  return cast_or_null<FriendDecl>(
24  NextFriend.get(getASTContext().getExternalSource()));
25 }
26 
29  FriendUnion Friend,
30  SourceLocation FriendL,
31  ArrayRef<TemplateParameterList*> FriendTypeTPLists) {
32 #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()));
44  // These template parameters are for friend types only.
45  assert(FriendTypeTPLists.size() == 0);
46  }
47 #endif
48 
49  std::size_t Extra = FriendTypeTPLists.size() * sizeof(TemplateParameterList*);
50  FriendDecl *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL,
51  FriendTypeTPLists);
52  cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
53  return FD;
54 }
55 
57  unsigned FriendTypeNumTPLists) {
58  std::size_t Extra = FriendTypeNumTPLists * sizeof(TemplateParameterList*);
59  return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
60 }
61 
62 FriendDecl *CXXRecordDecl::getFirstFriend() const {
64  Decl *First = data().FirstFriend.get(Source);
65  return First ? cast<FriendDecl>(First) : nullptr;
66 }
Defines the clang::ASTContext interface.
static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D)
Determine what kind of template specialization the given declaration is.
Defines the C++ template declaration subclasses.
static FriendDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned FriendTypeNumTPLists)
Definition: DeclFriend.cpp:56
static FriendDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_, SourceLocation FriendL, ArrayRef< TemplateParameterList * > FriendTypeTPLists=None)
Definition: DeclFriend.cpp:27
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:46
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition: DeclFriend.h:43
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:89
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1203
Abstract interface for external sources of AST nodes.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:864
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:284
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer.
__SIZE_TYPE__ size_t
Definition: stddef.h:62
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
Definition: DeclBase.h:958