clang 22.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
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclBase.h"
18#include "clang/AST/DeclCXX.h"
20#include "clang/Basic/LLVM.h"
21#include <cassert>
22#include <cstddef>
23
24using namespace clang;
25
26void FriendDecl::anchor() {}
27
28FriendDecl *FriendDecl::getNextFriendSlowCase() {
29 return cast_or_null<FriendDecl>(
30 NextFriend.get(getASTContext().getExternalSource()));
31}
32
35 FriendUnion Friend, SourceLocation FriendL,
36 SourceLocation EllipsisLoc,
37 ArrayRef<TemplateParameterList *> FriendTypeTPLists) {
38#ifndef NDEBUG
39 if (const auto *D = dyn_cast<NamedDecl *>(Friend)) {
40 assert(isa<FunctionDecl>(D) ||
44
45 // As a temporary hack, we permit template instantiation to point
46 // to the original declaration when instantiating members.
47 assert(D->getFriendObjectKind() ||
48 (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
49 // These template parameters are for friend types only.
50 assert(FriendTypeTPLists.empty());
51 }
52#endif
53
54 std::size_t Extra =
55 FriendDecl::additionalSizeToAlloc<TemplateParameterList *>(
56 FriendTypeTPLists.size());
57 auto *FD = new (C, DC, Extra)
58 FriendDecl(DC, L, Friend, FriendL, EllipsisLoc, FriendTypeTPLists);
59 cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
60 return FD;
61}
62
64 unsigned FriendTypeNumTPLists) {
65 std::size_t Extra =
66 additionalSizeToAlloc<TemplateParameterList *>(FriendTypeNumTPLists);
67 return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
68}
69
70FriendDecl *CXXRecordDecl::getFirstFriend() const {
72 Decl *First = data().FirstFriend.get(Source);
74}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:188
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
ASTContext & getParentASTContext() const
Definition DeclBase.h:2138
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:524
friend class DeclContext
Definition DeclBase.h:252
Abstract interface for external sources of AST nodes.
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition DeclFriend.h:54
static FriendDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_, SourceLocation FriendL, SourceLocation EllipsisLoc={}, ArrayRef< TemplateParameterList * > FriendTypeTPLists={})
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition DeclFriend.h:58
static FriendDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned FriendTypeNumTPLists)
Encodes a location in the source.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
nullptr
This class represents a compute construct, representing a 'Kind' of β€˜parallel’, 'serial',...
U cast(CodeGen::Address addr)
Definition Address.h:327
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition DeclBase.h:102
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.