clang  6.0.0svn
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/DeclFriend.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclBase.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/ASTContext.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/Basic/LLVM.h"
22 #include "llvm/Support/Casting.h"
23 #include <cassert>
24 #include <cstddef>
25 
26 using namespace clang;
27 
28 void FriendDecl::anchor() {}
29 
30 FriendDecl *FriendDecl::getNextFriendSlowCase() {
31  return cast_or_null<FriendDecl>(
32  NextFriend.get(getASTContext().getExternalSource()));
33 }
34 
37  FriendUnion Friend,
38  SourceLocation FriendL,
39  ArrayRef<TemplateParameterList *> FriendTypeTPLists) {
40 #ifndef NDEBUG
41  if (Friend.is<NamedDecl *>()) {
42  NamedDecl *D = Friend.get<NamedDecl*>();
43  assert(isa<FunctionDecl>(D) ||
44  isa<CXXRecordDecl>(D) ||
45  isa<FunctionTemplateDecl>(D) ||
46  isa<ClassTemplateDecl>(D));
47 
48  // As a temporary hack, we permit template instantiation to point
49  // to the original declaration when instantiating members.
50  assert(D->getFriendObjectKind() ||
51  (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
52  // These template parameters are for friend types only.
53  assert(FriendTypeTPLists.empty());
54  }
55 #endif
56 
57  std::size_t Extra =
58  FriendDecl::additionalSizeToAlloc<TemplateParameterList *>(
59  FriendTypeTPLists.size());
60  FriendDecl *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL,
61  FriendTypeTPLists);
62  cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
63  return FD;
64 }
65 
67  unsigned FriendTypeNumTPLists) {
68  std::size_t Extra =
69  additionalSizeToAlloc<TemplateParameterList *>(FriendTypeNumTPLists);
70  return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
71 }
72 
73 FriendDecl *CXXRecordDecl::getFirstFriend() const {
74  ExternalASTSource *Source = getParentASTContext().getExternalSource();
75  Decl *First = data().FirstFriend.get(Source);
76  return First ? cast<FriendDecl>(First) : nullptr;
77 }
Defines the clang::ASTContext interface.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c.h:60
static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D)
Determine what kind of template specialization the given declaration is.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Defines the C++ template declaration subclasses.
static FriendDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned FriendTypeNumTPLists)
Definition: DeclFriend.cpp:66
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Definition: DeclFriend.h:54
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition: DeclFriend.h:60
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:102
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
Definition: DeclBase.h:1098
Abstract interface for external sources of AST nodes.
static FriendDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_, SourceLocation FriendL, ArrayRef< TemplateParameterList *> FriendTypeTPLists=None)
Definition: DeclFriend.cpp:35
Encodes a location in the source.
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:365
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
NamedDecl - This represents a decl with a name.
Definition: Decl.h:245