clang  13.0.0git
DeclFriend.cpp
Go to the documentation of this file.
1 //===- DeclFriend.cpp - C++ Friend Declaration AST Node Implementation ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the AST classes related to C++ friend
10 // declarations.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/DeclFriend.h"
15 #include "clang/AST/Decl.h"
16 #include "clang/AST/DeclBase.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/ASTContext.h"
19 #include "clang/AST/DeclTemplate.h"
20 #include "clang/Basic/LLVM.h"
21 #include "llvm/Support/Casting.h"
22 #include <cassert>
23 #include <cstddef>
24 
25 using namespace clang;
26 
27 void FriendDecl::anchor() {}
28 
29 FriendDecl *FriendDecl::getNextFriendSlowCase() {
30  return cast_or_null<FriendDecl>(
31  NextFriend.get(getASTContext().getExternalSource()));
32 }
33 
36  FriendUnion Friend,
37  SourceLocation FriendL,
38  ArrayRef<TemplateParameterList *> FriendTypeTPLists) {
39 #ifndef NDEBUG
40  if (Friend.is<NamedDecl *>()) {
41  const auto *D = Friend.get<NamedDecl*>();
42  assert(isa<FunctionDecl>(D) ||
43  isa<CXXRecordDecl>(D) ||
44  isa<FunctionTemplateDecl>(D) ||
45  isa<ClassTemplateDecl>(D));
46 
47  // As a temporary hack, we permit template instantiation to point
48  // to the original declaration when instantiating members.
49  assert(D->getFriendObjectKind() ||
50  (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
51  // These template parameters are for friend types only.
52  assert(FriendTypeTPLists.empty());
53  }
54 #endif
55 
56  std::size_t Extra =
57  FriendDecl::additionalSizeToAlloc<TemplateParameterList *>(
58  FriendTypeTPLists.size());
59  auto *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL,
60  FriendTypeTPLists);
61  cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
62  return FD;
63 }
64 
66  unsigned FriendTypeNumTPLists) {
67  std::size_t Extra =
68  additionalSizeToAlloc<TemplateParameterList *>(FriendTypeNumTPLists);
69  return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
70 }
71 
72 FriendDecl *CXXRecordDecl::getFirstFriend() const {
74  Decl *First = data().FirstFriend.get(Source);
75  return First ? cast<FriendDecl>(First) : nullptr;
76 }
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:414
clang::DeclContext::getParentASTContext
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1889
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:89
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:223
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:52
DeclCXX.h
clang::FriendDecl::CreateDeserialized
static FriendDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned FriendTypeNumTPLists)
Definition: DeclFriend.cpp:65
Decl.h
size_t
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:70
clang::ASTContext::getExternalSource
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1079
DeclTemplate.h
DeclFriend.h
DeclBase.h
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
clang::FriendDecl::Create
static FriendDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_, SourceLocation FriendL, ArrayRef< TemplateParameterList * > FriendTypeTPLists=None)
Definition: DeclFriend.cpp:34
clang::FriendDecl
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition: DeclFriend.h:53
ASTContext.h
clang::Redeclarable< TagDecl >::First
TagDecl * First
Definition: Redeclarable.h:187
clang::FriendDecl::FriendUnion
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition: DeclFriend.h:59
llvm::ArrayRef
Definition: LLVM.h:34
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
LLVM.h
clang::LazyOffsetPtr::get
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.
Definition: ExternalASTSource.h:376
clang::Builtin::ID
ID
Definition: Builtins.h:47
clang
Dataflow Directional Tag Classes.
Definition: CalledOnceCheck.h:17
clang::Decl::EmptyShell
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:105
clang::ExternalASTSource
Abstract interface for external sources of AST nodes.
Definition: ExternalASTSource.h:62