192b7f70c924cbf4514e9e434cea7def51ab49860John McCall//===-- DeclFriend.h - Classes for C++ friend declarations -*- C++ -*------===//
292b7f70c924cbf4514e9e434cea7def51ab49860John McCall//
392b7f70c924cbf4514e9e434cea7def51ab49860John McCall//                     The LLVM Compiler Infrastructure
492b7f70c924cbf4514e9e434cea7def51ab49860John McCall//
592b7f70c924cbf4514e9e434cea7def51ab49860John McCall// This file is distributed under the University of Illinois Open Source
692b7f70c924cbf4514e9e434cea7def51ab49860John McCall// License. See LICENSE.TXT for details.
792b7f70c924cbf4514e9e434cea7def51ab49860John McCall//
892b7f70c924cbf4514e9e434cea7def51ab49860John McCall//===----------------------------------------------------------------------===//
992b7f70c924cbf4514e9e434cea7def51ab49860John McCall//
1092b7f70c924cbf4514e9e434cea7def51ab49860John McCall// This file defines the section of the AST representing C++ friend
1192b7f70c924cbf4514e9e434cea7def51ab49860John McCall// declarations.
1292b7f70c924cbf4514e9e434cea7def51ab49860John McCall//
1392b7f70c924cbf4514e9e434cea7def51ab49860John McCall//===----------------------------------------------------------------------===//
1492b7f70c924cbf4514e9e434cea7def51ab49860John McCall
1592b7f70c924cbf4514e9e434cea7def51ab49860John McCall#ifndef LLVM_CLANG_AST_DECLFRIEND_H
1692b7f70c924cbf4514e9e434cea7def51ab49860John McCall#define LLVM_CLANG_AST_DECLFRIEND_H
1792b7f70c924cbf4514e9e434cea7def51ab49860John McCall
1892b7f70c924cbf4514e9e434cea7def51ab49860John McCall#include "clang/AST/DeclCXX.h"
1903a400510fb8ba2e88e27c95ec797d944d944c4bAbramo Bagnara#include "clang/AST/DeclTemplate.h"
206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "clang/AST/TypeLoc.h"
21aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
2292b7f70c924cbf4514e9e434cea7def51ab49860John McCall
2392b7f70c924cbf4514e9e434cea7def51ab49860John McCallnamespace clang {
2492b7f70c924cbf4514e9e434cea7def51ab49860John McCall
2592b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// FriendDecl - Represents the declaration of a friend entity,
2692b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// which can be a function, a type, or a templated function or type.
2792b7f70c924cbf4514e9e434cea7def51ab49860John McCall//  For example:
2892b7f70c924cbf4514e9e434cea7def51ab49860John McCall///
2992b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// @code
3092b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// template <typename T> class A {
3192b7f70c924cbf4514e9e434cea7def51ab49860John McCall///   friend int foo(T);
3292b7f70c924cbf4514e9e434cea7def51ab49860John McCall///   friend class B;
3392b7f70c924cbf4514e9e434cea7def51ab49860John McCall///   friend T; // only in C++0x
3492b7f70c924cbf4514e9e434cea7def51ab49860John McCall///   template <typename U> friend class C;
3592b7f70c924cbf4514e9e434cea7def51ab49860John McCall///   template <typename U> friend A& operator+=(A&, const U&) { ... }
3692b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// };
3792b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// @endcode
3892b7f70c924cbf4514e9e434cea7def51ab49860John McCall///
3992b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// The semantic context of a friend decl is its declaring class.
4092b7f70c924cbf4514e9e434cea7def51ab49860John McCallclass FriendDecl : public Decl {
4199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
4292b7f70c924cbf4514e9e434cea7def51ab49860John McCallpublic:
4332f2fb53d9d7c28c94d8569fd0fcf06cccee0c3dJohn McCall  typedef llvm::PointerUnion<NamedDecl*,TypeSourceInfo*> FriendUnion;
4492b7f70c924cbf4514e9e434cea7def51ab49860John McCall
4592b7f70c924cbf4514e9e434cea7def51ab49860John McCallprivate:
4692b7f70c924cbf4514e9e434cea7def51ab49860John McCall  // The declaration that's a friend of this class.
4792b7f70c924cbf4514e9e434cea7def51ab49860John McCall  FriendUnion Friend;
4892b7f70c924cbf4514e9e434cea7def51ab49860John McCall
49d60e22e601852ae1345f01514318a0951dc09f89John McCall  // A pointer to the next friend in the sequence.
5069aecc6252bf4a5ee59f9b51c3728ea07b6342bfDouglas Gregor  LazyDeclPtr NextFriend;
51d60e22e601852ae1345f01514318a0951dc09f89John McCall
5292b7f70c924cbf4514e9e434cea7def51ab49860John McCall  // Location of the 'friend' specifier.
5392b7f70c924cbf4514e9e434cea7def51ab49860John McCall  SourceLocation FriendLoc;
5492b7f70c924cbf4514e9e434cea7def51ab49860John McCall
556102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall  /// True if this 'friend' declaration is unsupported.  Eventually we
566102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall  /// will support every possible friend declaration, but for now we
576102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall  /// silently ignore some and set this flag to authorize all access.
588c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  bool UnsupportedFriend : 1;
598c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella
608c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  // The number of "outer" template parameter lists in non-templatic
618c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  // (currently unsupported) friend type declarations, such as
628c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  //     template <class T> friend class A<T>::B;
638c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  unsigned NumTPLists : 31;
648c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella
658c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  // The tail-allocated friend type template parameter lists (if any).
668c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  TemplateParameterList* const *getTPLists() const {
678c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella    return reinterpret_cast<TemplateParameterList* const *>(this + 1);
688c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  }
698c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  TemplateParameterList **getTPLists() {
708c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella    return reinterpret_cast<TemplateParameterList**>(this + 1);
718c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  }
726102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall
73d60e22e601852ae1345f01514318a0951dc09f89John McCall  friend class CXXRecordDecl::friend_iterator;
74d60e22e601852ae1345f01514318a0951dc09f89John McCall  friend class CXXRecordDecl;
75d60e22e601852ae1345f01514318a0951dc09f89John McCall
7692b7f70c924cbf4514e9e434cea7def51ab49860John McCall  FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend,
778c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella             SourceLocation FriendL,
788c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella             ArrayRef<TemplateParameterList*> FriendTypeTPLists)
7992b7f70c924cbf4514e9e434cea7def51ab49860John McCall    : Decl(Decl::Friend, DC, L),
8092b7f70c924cbf4514e9e434cea7def51ab49860John McCall      Friend(Friend),
8169aecc6252bf4a5ee59f9b51c3728ea07b6342bfDouglas Gregor      NextFriend(),
826102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall      FriendLoc(FriendL),
838c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella      UnsupportedFriend(false),
848c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella      NumTPLists(FriendTypeTPLists.size()) {
858c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella    for (unsigned i = 0; i < NumTPLists; ++i)
868c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella      getTPLists()[i] = FriendTypeTPLists[i];
8792b7f70c924cbf4514e9e434cea7def51ab49860John McCall  }
8892b7f70c924cbf4514e9e434cea7def51ab49860John McCall
898c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  FriendDecl(EmptyShell Empty, unsigned NumFriendTypeTPLists)
908c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella    : Decl(Decl::Friend, Empty), NextFriend(),
918c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella      NumTPLists(NumFriendTypeTPLists) { }
926764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis
9369aecc6252bf4a5ee59f9b51c3728ea07b6342bfDouglas Gregor  FriendDecl *getNextFriend() {
94471c8b49982d1132f30b0b0da27fef94fd6e4f67Benjamin Kramer    if (!NextFriend.isOffset())
956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines      return cast_or_null<FriendDecl>(NextFriend.get(nullptr));
96471c8b49982d1132f30b0b0da27fef94fd6e4f67Benjamin Kramer    return getNextFriendSlowCase();
9769aecc6252bf4a5ee59f9b51c3728ea07b6342bfDouglas Gregor  }
98471c8b49982d1132f30b0b0da27fef94fd6e4f67Benjamin Kramer  FriendDecl *getNextFriendSlowCase();
99471c8b49982d1132f30b0b0da27fef94fd6e4f67Benjamin Kramer
10092b7f70c924cbf4514e9e434cea7def51ab49860John McCallpublic:
10192b7f70c924cbf4514e9e434cea7def51ab49860John McCall  static FriendDecl *Create(ASTContext &C, DeclContext *DC,
10292b7f70c924cbf4514e9e434cea7def51ab49860John McCall                            SourceLocation L, FriendUnion Friend_,
1038c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella                            SourceLocation FriendL,
1048c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella                            ArrayRef<TemplateParameterList*> FriendTypeTPLists
1055543169296beeb183b9c9392debc774fcf493eebDmitri Gribenko                            = None);
1068c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  static FriendDecl *CreateDeserialized(ASTContext &C, unsigned ID,
1078c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella                                        unsigned FriendTypeNumTPLists);
10892b7f70c924cbf4514e9e434cea7def51ab49860John McCall
109710672485039d3dd355748876299fff88e8ad84cCraig Silverstein  /// If this friend declaration names an (untemplated but possibly
110710672485039d3dd355748876299fff88e8ad84cCraig Silverstein  /// dependent) type, return the type; otherwise return null.  This
111710672485039d3dd355748876299fff88e8ad84cCraig Silverstein  /// is used for elaborated-type-specifiers and, in C++0x, for
112710672485039d3dd355748876299fff88e8ad84cCraig Silverstein  /// arbitrary friend type declarations.
11332f2fb53d9d7c28c94d8569fd0fcf06cccee0c3dJohn McCall  TypeSourceInfo *getFriendType() const {
11432f2fb53d9d7c28c94d8569fd0fcf06cccee0c3dJohn McCall    return Friend.dyn_cast<TypeSourceInfo*>();
11592b7f70c924cbf4514e9e434cea7def51ab49860John McCall  }
1168c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  unsigned getFriendTypeNumTemplateParameterLists() const {
1178c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella    return NumTPLists;
1188c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  }
1198c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  TemplateParameterList *getFriendTypeTemplateParameterList(unsigned N) const {
1208c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella    assert(N < NumTPLists);
1218c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella    return getTPLists()[N];
1228c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella  }
12392b7f70c924cbf4514e9e434cea7def51ab49860John McCall
124710672485039d3dd355748876299fff88e8ad84cCraig Silverstein  /// If this friend declaration doesn't name a type, return the inner
125710672485039d3dd355748876299fff88e8ad84cCraig Silverstein  /// declaration.
12692b7f70c924cbf4514e9e434cea7def51ab49860John McCall  NamedDecl *getFriendDecl() const {
12792b7f70c924cbf4514e9e434cea7def51ab49860John McCall    return Friend.dyn_cast<NamedDecl*>();
12892b7f70c924cbf4514e9e434cea7def51ab49860John McCall  }
12992b7f70c924cbf4514e9e434cea7def51ab49860John McCall
13092b7f70c924cbf4514e9e434cea7def51ab49860John McCall  /// Retrieves the location of the 'friend' keyword.
13192b7f70c924cbf4514e9e434cea7def51ab49860John McCall  SourceLocation getFriendLoc() const {
13292b7f70c924cbf4514e9e434cea7def51ab49860John McCall    return FriendLoc;
13392b7f70c924cbf4514e9e434cea7def51ab49860John McCall  }
13492b7f70c924cbf4514e9e434cea7def51ab49860John McCall
1358fbb7628e9fc364bbfb65bdf2c2468b0d06a7e5bAbramo Bagnara  /// Retrieves the source range for the friend declaration.
136651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  SourceRange getSourceRange() const override LLVM_READONLY {
13703a400510fb8ba2e88e27c95ec797d944d944c4bAbramo Bagnara    if (NamedDecl *ND = getFriendDecl()) {
13803a400510fb8ba2e88e27c95ec797d944d944c4bAbramo Bagnara      if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(ND))
13903a400510fb8ba2e88e27c95ec797d944d944c4bAbramo Bagnara        return FTD->getSourceRange();
14003a400510fb8ba2e88e27c95ec797d944d944c4bAbramo Bagnara      if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(ND)) {
14103a400510fb8ba2e88e27c95ec797d944d944c4bAbramo Bagnara        if (DD->getOuterLocStart() != DD->getInnerLocStart())
14203a400510fb8ba2e88e27c95ec797d944d944c4bAbramo Bagnara          return DD->getSourceRange();
14303a400510fb8ba2e88e27c95ec797d944d944c4bAbramo Bagnara      }
1448fbb7628e9fc364bbfb65bdf2c2468b0d06a7e5bAbramo Bagnara      return SourceRange(getFriendLoc(), ND->getLocEnd());
14503a400510fb8ba2e88e27c95ec797d944d944c4bAbramo Bagnara    }
1468c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella    else if (TypeSourceInfo *TInfo = getFriendType()) {
1478c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella      SourceLocation StartL = (NumTPLists == 0)
1488c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella        ? getFriendLoc()
1498c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella        : getTPLists()[0]->getTemplateLoc();
1508c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella      return SourceRange(StartL, TInfo->getTypeLoc().getEndLoc());
1518c84028ed9aa0dfd54ab729dee78f29c961d7f37Enea Zaffanella    }
1528fbb7628e9fc364bbfb65bdf2c2468b0d06a7e5bAbramo Bagnara    else
1538fbb7628e9fc364bbfb65bdf2c2468b0d06a7e5bAbramo Bagnara      return SourceRange(getFriendLoc(), getLocation());
1548fbb7628e9fc364bbfb65bdf2c2468b0d06a7e5bAbramo Bagnara  }
1558fbb7628e9fc364bbfb65bdf2c2468b0d06a7e5bAbramo Bagnara
1566102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall  /// Determines if this friend kind is unsupported.
1576102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall  bool isUnsupportedFriend() const {
1586102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall    return UnsupportedFriend;
1596102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall  }
1606102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall  void setUnsupportedFriend(bool Unsupported) {
1616102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall    UnsupportedFriend = Unsupported;
1626102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall  }
1636102ca1d490836096678d7d934f0b2b78f9293ecJohn McCall
16492b7f70c924cbf4514e9e434cea7def51ab49860John McCall  // Implement isa/cast/dyncast/etc.
16592b7f70c924cbf4514e9e434cea7def51ab49860John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
16692b7f70c924cbf4514e9e434cea7def51ab49860John McCall  static bool classofKind(Kind K) { return K == Decl::Friend; }
1676764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis
168d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
1693397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTDeclWriter;
17092b7f70c924cbf4514e9e434cea7def51ab49860John McCall};
171d60e22e601852ae1345f01514318a0951dc09f89John McCall
172d60e22e601852ae1345f01514318a0951dc09f89John McCall/// An iterator over the friend declarations of a class.
173d60e22e601852ae1345f01514318a0951dc09f89John McCallclass CXXRecordDecl::friend_iterator {
174d60e22e601852ae1345f01514318a0951dc09f89John McCall  FriendDecl *Ptr;
175d60e22e601852ae1345f01514318a0951dc09f89John McCall
176d60e22e601852ae1345f01514318a0951dc09f89John McCall  friend class CXXRecordDecl;
177d60e22e601852ae1345f01514318a0951dc09f89John McCall  explicit friend_iterator(FriendDecl *Ptr) : Ptr(Ptr) {}
178d60e22e601852ae1345f01514318a0951dc09f89John McCallpublic:
179d60e22e601852ae1345f01514318a0951dc09f89John McCall  friend_iterator() {}
180d60e22e601852ae1345f01514318a0951dc09f89John McCall
181d60e22e601852ae1345f01514318a0951dc09f89John McCall  typedef FriendDecl *value_type;
182d60e22e601852ae1345f01514318a0951dc09f89John McCall  typedef FriendDecl *reference;
183d60e22e601852ae1345f01514318a0951dc09f89John McCall  typedef FriendDecl *pointer;
184d60e22e601852ae1345f01514318a0951dc09f89John McCall  typedef int difference_type;
185d60e22e601852ae1345f01514318a0951dc09f89John McCall  typedef std::forward_iterator_tag iterator_category;
186d60e22e601852ae1345f01514318a0951dc09f89John McCall
187d60e22e601852ae1345f01514318a0951dc09f89John McCall  reference operator*() const { return Ptr; }
188d60e22e601852ae1345f01514318a0951dc09f89John McCall
189d60e22e601852ae1345f01514318a0951dc09f89John McCall  friend_iterator &operator++() {
190d60e22e601852ae1345f01514318a0951dc09f89John McCall    assert(Ptr && "attempt to increment past end of friend list");
19169aecc6252bf4a5ee59f9b51c3728ea07b6342bfDouglas Gregor    Ptr = Ptr->getNextFriend();
192d60e22e601852ae1345f01514318a0951dc09f89John McCall    return *this;
193d60e22e601852ae1345f01514318a0951dc09f89John McCall  }
194d60e22e601852ae1345f01514318a0951dc09f89John McCall
195d60e22e601852ae1345f01514318a0951dc09f89John McCall  friend_iterator operator++(int) {
196d60e22e601852ae1345f01514318a0951dc09f89John McCall    friend_iterator tmp = *this;
197d60e22e601852ae1345f01514318a0951dc09f89John McCall    ++*this;
198d60e22e601852ae1345f01514318a0951dc09f89John McCall    return tmp;
199d60e22e601852ae1345f01514318a0951dc09f89John McCall  }
200d60e22e601852ae1345f01514318a0951dc09f89John McCall
201d60e22e601852ae1345f01514318a0951dc09f89John McCall  bool operator==(const friend_iterator &Other) const {
202d60e22e601852ae1345f01514318a0951dc09f89John McCall    return Ptr == Other.Ptr;
203d60e22e601852ae1345f01514318a0951dc09f89John McCall  }
204d60e22e601852ae1345f01514318a0951dc09f89John McCall
205d60e22e601852ae1345f01514318a0951dc09f89John McCall  bool operator!=(const friend_iterator &Other) const {
206d60e22e601852ae1345f01514318a0951dc09f89John McCall    return Ptr != Other.Ptr;
207d60e22e601852ae1345f01514318a0951dc09f89John McCall  }
208d60e22e601852ae1345f01514318a0951dc09f89John McCall
209d60e22e601852ae1345f01514318a0951dc09f89John McCall  friend_iterator &operator+=(difference_type N) {
210d60e22e601852ae1345f01514318a0951dc09f89John McCall    assert(N >= 0 && "cannot rewind a CXXRecordDecl::friend_iterator");
211d60e22e601852ae1345f01514318a0951dc09f89John McCall    while (N--)
212d60e22e601852ae1345f01514318a0951dc09f89John McCall      ++*this;
213d60e22e601852ae1345f01514318a0951dc09f89John McCall    return *this;
214d60e22e601852ae1345f01514318a0951dc09f89John McCall  }
215d60e22e601852ae1345f01514318a0951dc09f89John McCall
216d60e22e601852ae1345f01514318a0951dc09f89John McCall  friend_iterator operator+(difference_type N) const {
217d60e22e601852ae1345f01514318a0951dc09f89John McCall    friend_iterator tmp = *this;
218d60e22e601852ae1345f01514318a0951dc09f89John McCall    tmp += N;
219d60e22e601852ae1345f01514318a0951dc09f89John McCall    return tmp;
220d60e22e601852ae1345f01514318a0951dc09f89John McCall  }
221d60e22e601852ae1345f01514318a0951dc09f89John McCall};
222d60e22e601852ae1345f01514318a0951dc09f89John McCall
223d60e22e601852ae1345f01514318a0951dc09f89John McCallinline CXXRecordDecl::friend_iterator CXXRecordDecl::friend_begin() const {
2244fc5089e306fe606f2e3e4fa58063ebab35deb62Richard Smith  return friend_iterator(getFirstFriend());
225d60e22e601852ae1345f01514318a0951dc09f89John McCall}
226d60e22e601852ae1345f01514318a0951dc09f89John McCall
227d60e22e601852ae1345f01514318a0951dc09f89John McCallinline CXXRecordDecl::friend_iterator CXXRecordDecl::friend_end() const {
2286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  return friend_iterator(nullptr);
229d60e22e601852ae1345f01514318a0951dc09f89John McCall}
230d60e22e601852ae1345f01514318a0951dc09f89John McCall
231651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesinline CXXRecordDecl::friend_range CXXRecordDecl::friends() const {
232651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  return friend_range(friend_begin(), friend_end());
233651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines}
234651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
235d60e22e601852ae1345f01514318a0951dc09f89John McCallinline void CXXRecordDecl::pushFriendDecl(FriendDecl *FD) {
2367247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie  assert(!FD->NextFriend && "friend already has next friend?");
237d60e22e601852ae1345f01514318a0951dc09f89John McCall  FD->NextFriend = data().FirstFriend;
238d60e22e601852ae1345f01514318a0951dc09f89John McCall  data().FirstFriend = FD;
239d60e22e601852ae1345f01514318a0951dc09f89John McCall}
24092b7f70c924cbf4514e9e434cea7def51ab49860John McCall
24192b7f70c924cbf4514e9e434cea7def51ab49860John McCall}
24292b7f70c924cbf4514e9e434cea7def51ab49860John McCall
24392b7f70c924cbf4514e9e434cea7def51ab49860John McCall#endif
244