Path: blob/main/contrib/llvm-project/clang/lib/AST/DeclFriend.cpp
35260 views
//===- DeclFriend.cpp - C++ Friend Declaration AST Node Implementation ----===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements the AST classes related to C++ friend9// declarations.10//11//===----------------------------------------------------------------------===//1213#include "clang/AST/DeclFriend.h"14#include "clang/AST/Decl.h"15#include "clang/AST/DeclBase.h"16#include "clang/AST/DeclCXX.h"17#include "clang/AST/ASTContext.h"18#include "clang/AST/DeclTemplate.h"19#include "clang/Basic/LLVM.h"20#include "llvm/Support/Casting.h"21#include <cassert>22#include <cstddef>2324using namespace clang;2526void FriendDecl::anchor() {}2728FriendDecl *FriendDecl::getNextFriendSlowCase() {29return cast_or_null<FriendDecl>(30NextFriend.get(getASTContext().getExternalSource()));31}3233FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,34SourceLocation L,35FriendUnion Friend,36SourceLocation FriendL,37ArrayRef<TemplateParameterList *> FriendTypeTPLists) {38#ifndef NDEBUG39if (Friend.is<NamedDecl *>()) {40const auto *D = Friend.get<NamedDecl*>();41assert(isa<FunctionDecl>(D) ||42isa<CXXRecordDecl>(D) ||43isa<FunctionTemplateDecl>(D) ||44isa<ClassTemplateDecl>(D));4546// As a temporary hack, we permit template instantiation to point47// to the original declaration when instantiating members.48assert(D->getFriendObjectKind() ||49(cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));50// These template parameters are for friend types only.51assert(FriendTypeTPLists.empty());52}53#endif5455std::size_t Extra =56FriendDecl::additionalSizeToAlloc<TemplateParameterList *>(57FriendTypeTPLists.size());58auto *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL,59FriendTypeTPLists);60cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);61return FD;62}6364FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID,65unsigned FriendTypeNumTPLists) {66std::size_t Extra =67additionalSizeToAlloc<TemplateParameterList *>(FriendTypeNumTPLists);68return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);69}7071FriendDecl *CXXRecordDecl::getFirstFriend() const {72ExternalASTSource *Source = getParentASTContext().getExternalSource();73Decl *First = data().FirstFriend.get(Source);74return First ? cast<FriendDecl>(First) : nullptr;75}767778