DeclFriend.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //===--- DeclFriend.cpp - C++ Friend Declaration AST Node Implementation --===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the AST classes related to C++ friend
  11. // declarations.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "clang/AST/ASTContext.h"
  15. #include "clang/AST/DeclFriend.h"
  16. #include "clang/AST/DeclTemplate.h"
  17. using namespace clang;
  18. void FriendDecl::anchor() { }
  19. FriendDecl *FriendDecl::getNextFriendSlowCase() {
  20. return cast_or_null<FriendDecl>(
  21. NextFriend.get(getASTContext().getExternalSource()));
  22. }
  23. FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
  24. SourceLocation L,
  25. FriendUnion Friend,
  26. SourceLocation FriendL,
  27. ArrayRef<TemplateParameterList*> FriendTypeTPLists) {
  28. #ifndef NDEBUG
  29. if (Friend.is<NamedDecl*>()) {
  30. NamedDecl *D = Friend.get<NamedDecl*>();
  31. assert(isa<FunctionDecl>(D) ||
  32. isa<CXXRecordDecl>(D) ||
  33. isa<FunctionTemplateDecl>(D) ||
  34. isa<ClassTemplateDecl>(D));
  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. // These template parameters are for friend types only.
  40. assert(FriendTypeTPLists.size() == 0);
  41. }
  42. #endif
  43. std::size_t Extra = FriendTypeTPLists.size() * sizeof(TemplateParameterList*);
  44. FriendDecl *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL,
  45. FriendTypeTPLists);
  46. cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
  47. return FD;
  48. }
  49. FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID,
  50. unsigned FriendTypeNumTPLists) {
  51. std::size_t Extra = FriendTypeNumTPLists * sizeof(TemplateParameterList*);
  52. return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
  53. }
  54. FriendDecl *CXXRecordDecl::getFirstFriend() const {
  55. ExternalASTSource *Source = getParentASTContext().getExternalSource();
  56. Decl *First = data().FirstFriend.get(Source);
  57. return First ? cast<FriendDecl>(First) : nullptr;
  58. }