clang 24.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/DeclCXX.h"
19#include <cassert>
20
21using namespace clang;
22
23void FriendDecl::anchor() {}
24
27 SourceLocation EllipsisLoc) {
28#ifndef NDEBUG
29 if (const auto *D = dyn_cast<NamedDecl *>(Friend)) {
30 assert(isa<FunctionDecl>(D) ||
34
35 // As a temporary hack, we permit template instantiation to point
36 // to the original declaration when instantiating members.
37 assert(D->getFriendObjectKind() ||
38 (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
39 }
40#endif
41
42 auto *FD =
43 new (C, DC) FriendDecl(Decl::Friend, DC, L, Friend, FriendL, EllipsisLoc);
44 cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
45 return FD;
46}
47
49 return new (C, ID) FriendDecl(Decl::Friend, EmptyShell());
50}
51
53 return cast_or_null<FriendDecl>(
54 NextFriend.get(getASTContext().getExternalSource()));
55}
56
57FriendDecl *CXXRecordDecl::getFirstFriend() const {
59 Decl *First = data().FirstFriend.get(Source);
61}
62
64 if (TypeSourceInfo *TInfo = getFriendType()) {
65 SourceLocation EndL =
66 isPackExpansion() ? getEllipsisLoc() : TInfo->getTypeLoc().getEndLoc();
67 return SourceRange(getFriendLoc(), EndL);
68 }
69
70 if (isPackExpansion())
72
73 if (NamedDecl *ND = getFriendDecl()) {
74 if (const auto *FD = dyn_cast<FunctionDecl>(ND))
75 return FD->getSourceRange();
76 if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(ND))
77 return FTD->getSourceRange();
78 if (const auto *CTD = dyn_cast<ClassTemplateDecl>(ND))
79 return CTD->getSourceRange();
80 if (const auto *DD = dyn_cast<DeclaratorDecl>(ND)) {
81 if (DD->getOuterLocStart() != DD->getInnerLocStart())
82 return DD->getSourceRange();
83 }
84 return SourceRange(getFriendLoc(), ND->getEndLoc());
85 }
87}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
ASTContext & getParentASTContext() const
Definition DeclBase.h:2155
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
SourceLocation getLocation() const
Definition DeclBase.h:447
friend class DeclContext
Definition DeclBase.h:260
Abstract interface for external sources of AST nodes.
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition DeclFriend.h:46
LazyDeclPtr NextFriend
Definition DeclFriend.h:65
FriendDecl(Kind K, DeclContext *DC, SourceLocation L, FriendUnion Friend, SourceLocation FL, SourceLocation EllipsisLoc={})
Definition DeclFriend.h:67
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition DeclFriend.h:50
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
SourceLocation getFriendLoc() const
Definition DeclFriend.h:109
FriendUnion Friend
Definition DeclFriend.h:63
SourceLocation getEllipsisLoc() const
Retrieves the location of the '...', if present.
Definition DeclFriend.h:107
FriendDecl * getNextFriendSlowCase()
virtual NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition DeclFriend.h:102
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition DeclFriend.h:96
bool isPackExpansion() const
Definition DeclFriend.h:113
static FriendDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend, SourceLocation FriendL, SourceLocation EllipsisLoc={})
static FriendDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
This represents a decl that may have a name.
Definition Decl.h:274
Encodes a location in the source.
A trivial tuple used to represent a source range.
A container of type source information.
Definition TypeBase.h:8475
Top level wrappers for InstallAPI frontend operations.
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.