2017-11-10 08:59:22 +08:00
|
|
|
//===- DeclFriend.cpp - C++ Friend Declaration AST Node Implementation ----===//
|
2010-03-11 15:50:04 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-03-11 15:50:04 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the AST classes related to C++ friend
|
|
|
|
// declarations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/DeclFriend.h"
|
2017-11-10 08:59:22 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
#include "clang/AST/DeclBase.h"
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2010-03-11 15:50:04 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2017-11-10 08:59:22 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
|
2010-03-11 15:50:04 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2017-11-10 08:59:22 +08:00
|
|
|
void FriendDecl::anchor() {}
|
2011-12-20 10:48:34 +08:00
|
|
|
|
2012-07-05 04:19:54 +08:00
|
|
|
FriendDecl *FriendDecl::getNextFriendSlowCase() {
|
|
|
|
return cast_or_null<FriendDecl>(
|
|
|
|
NextFriend.get(getASTContext().getExternalSource()));
|
|
|
|
}
|
|
|
|
|
2010-03-11 15:50:04 +08:00
|
|
|
FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L,
|
|
|
|
FriendUnion Friend,
|
2013-01-31 17:54:08 +08:00
|
|
|
SourceLocation FriendL,
|
2017-11-10 08:59:22 +08:00
|
|
|
ArrayRef<TemplateParameterList *> FriendTypeTPLists) {
|
2010-03-11 15:50:04 +08:00
|
|
|
#ifndef NDEBUG
|
2017-11-10 08:59:22 +08:00
|
|
|
if (Friend.is<NamedDecl *>()) {
|
2018-04-03 08:11:50 +08:00
|
|
|
const auto *D = Friend.get<NamedDecl*>();
|
2010-03-11 15:50:04 +08:00
|
|
|
assert(isa<FunctionDecl>(D) ||
|
|
|
|
isa<CXXRecordDecl>(D) ||
|
|
|
|
isa<FunctionTemplateDecl>(D) ||
|
|
|
|
isa<ClassTemplateDecl>(D));
|
|
|
|
|
|
|
|
// As a temporary hack, we permit template instantiation to point
|
|
|
|
// to the original declaration when instantiating members.
|
|
|
|
assert(D->getFriendObjectKind() ||
|
|
|
|
(cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
|
2013-01-31 17:54:08 +08:00
|
|
|
// These template parameters are for friend types only.
|
2017-11-10 08:59:22 +08:00
|
|
|
assert(FriendTypeTPLists.empty());
|
2010-03-11 15:50:04 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-30 06:13:13 +08:00
|
|
|
std::size_t Extra =
|
|
|
|
FriendDecl::additionalSizeToAlloc<TemplateParameterList *>(
|
|
|
|
FriendTypeTPLists.size());
|
2018-04-03 08:11:50 +08:00
|
|
|
auto *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL,
|
|
|
|
FriendTypeTPLists);
|
2010-03-12 09:19:31 +08:00
|
|
|
cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
|
|
|
|
return FD;
|
2010-03-11 15:50:04 +08:00
|
|
|
}
|
2010-06-30 06:47:00 +08:00
|
|
|
|
2013-01-31 17:54:08 +08:00
|
|
|
FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID,
|
|
|
|
unsigned FriendTypeNumTPLists) {
|
2015-12-30 06:13:13 +08:00
|
|
|
std::size_t Extra =
|
|
|
|
additionalSizeToAlloc<TemplateParameterList *>(FriendTypeNumTPLists);
|
2013-11-22 17:01:48 +08:00
|
|
|
return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
|
2010-06-30 06:47:00 +08:00
|
|
|
}
|
2013-01-31 17:54:08 +08:00
|
|
|
|
2013-06-26 10:41:25 +08:00
|
|
|
FriendDecl *CXXRecordDecl::getFirstFriend() const {
|
|
|
|
ExternalASTSource *Source = getParentASTContext().getExternalSource();
|
|
|
|
Decl *First = data().FirstFriend.get(Source);
|
2014-05-12 13:36:57 +08:00
|
|
|
return First ? cast<FriendDecl>(First) : nullptr;
|
2013-06-26 10:41:25 +08:00
|
|
|
}
|