DeclFriend.h revision 92b7f70c924cbf4514e9e434cea7def51ab49860
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" 1992b7f70c924cbf4514e9e434cea7def51ab49860John McCall 2092b7f70c924cbf4514e9e434cea7def51ab49860John McCallnamespace clang { 2192b7f70c924cbf4514e9e434cea7def51ab49860John McCall 2292b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// FriendDecl - Represents the declaration of a friend entity, 2392b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// which can be a function, a type, or a templated function or type. 2492b7f70c924cbf4514e9e434cea7def51ab49860John McCall// For example: 2592b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// 2692b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// @code 2792b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// template <typename T> class A { 2892b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// friend int foo(T); 2992b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// friend class B; 3092b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// friend T; // only in C++0x 3192b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// template <typename U> friend class C; 3292b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// template <typename U> friend A& operator+=(A&, const U&) { ... } 3392b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// }; 3492b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// @endcode 3592b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// 3692b7f70c924cbf4514e9e434cea7def51ab49860John McCall/// The semantic context of a friend decl is its declaring class. 3792b7f70c924cbf4514e9e434cea7def51ab49860John McCallclass FriendDecl : public Decl { 3892b7f70c924cbf4514e9e434cea7def51ab49860John McCallpublic: 3992b7f70c924cbf4514e9e434cea7def51ab49860John McCall typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion; 4092b7f70c924cbf4514e9e434cea7def51ab49860John McCall 4192b7f70c924cbf4514e9e434cea7def51ab49860John McCallprivate: 4292b7f70c924cbf4514e9e434cea7def51ab49860John McCall // The declaration that's a friend of this class. 4392b7f70c924cbf4514e9e434cea7def51ab49860John McCall FriendUnion Friend; 4492b7f70c924cbf4514e9e434cea7def51ab49860John McCall 4592b7f70c924cbf4514e9e434cea7def51ab49860John McCall // Location of the 'friend' specifier. 4692b7f70c924cbf4514e9e434cea7def51ab49860John McCall SourceLocation FriendLoc; 4792b7f70c924cbf4514e9e434cea7def51ab49860John McCall 4892b7f70c924cbf4514e9e434cea7def51ab49860John McCall // FIXME: Hack to keep track of whether this was a friend function 4992b7f70c924cbf4514e9e434cea7def51ab49860John McCall // template specialization. 5092b7f70c924cbf4514e9e434cea7def51ab49860John McCall bool WasSpecialization; 5192b7f70c924cbf4514e9e434cea7def51ab49860John McCall 5292b7f70c924cbf4514e9e434cea7def51ab49860John McCall FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend, 5392b7f70c924cbf4514e9e434cea7def51ab49860John McCall SourceLocation FriendL) 5492b7f70c924cbf4514e9e434cea7def51ab49860John McCall : Decl(Decl::Friend, DC, L), 5592b7f70c924cbf4514e9e434cea7def51ab49860John McCall Friend(Friend), 5692b7f70c924cbf4514e9e434cea7def51ab49860John McCall FriendLoc(FriendL), 5792b7f70c924cbf4514e9e434cea7def51ab49860John McCall WasSpecialization(false) { 5892b7f70c924cbf4514e9e434cea7def51ab49860John McCall } 5992b7f70c924cbf4514e9e434cea7def51ab49860John McCall 6092b7f70c924cbf4514e9e434cea7def51ab49860John McCallpublic: 6192b7f70c924cbf4514e9e434cea7def51ab49860John McCall static FriendDecl *Create(ASTContext &C, DeclContext *DC, 6292b7f70c924cbf4514e9e434cea7def51ab49860John McCall SourceLocation L, FriendUnion Friend_, 6392b7f70c924cbf4514e9e434cea7def51ab49860John McCall SourceLocation FriendL); 6492b7f70c924cbf4514e9e434cea7def51ab49860John McCall 6592b7f70c924cbf4514e9e434cea7def51ab49860John McCall /// If this friend declaration names an (untemplated but 6692b7f70c924cbf4514e9e434cea7def51ab49860John McCall /// possibly dependent) type, return the type; otherwise 6792b7f70c924cbf4514e9e434cea7def51ab49860John McCall /// return null. This is used only for C++0x's unelaborated 6892b7f70c924cbf4514e9e434cea7def51ab49860John McCall /// friend type declarations. 6992b7f70c924cbf4514e9e434cea7def51ab49860John McCall Type *getFriendType() const { 7092b7f70c924cbf4514e9e434cea7def51ab49860John McCall return Friend.dyn_cast<Type*>(); 7192b7f70c924cbf4514e9e434cea7def51ab49860John McCall } 7292b7f70c924cbf4514e9e434cea7def51ab49860John McCall 7392b7f70c924cbf4514e9e434cea7def51ab49860John McCall /// If this friend declaration doesn't name an unelaborated 7492b7f70c924cbf4514e9e434cea7def51ab49860John McCall /// type, return the inner declaration. 7592b7f70c924cbf4514e9e434cea7def51ab49860John McCall NamedDecl *getFriendDecl() const { 7692b7f70c924cbf4514e9e434cea7def51ab49860John McCall return Friend.dyn_cast<NamedDecl*>(); 7792b7f70c924cbf4514e9e434cea7def51ab49860John McCall } 7892b7f70c924cbf4514e9e434cea7def51ab49860John McCall 7992b7f70c924cbf4514e9e434cea7def51ab49860John McCall /// Retrieves the location of the 'friend' keyword. 8092b7f70c924cbf4514e9e434cea7def51ab49860John McCall SourceLocation getFriendLoc() const { 8192b7f70c924cbf4514e9e434cea7def51ab49860John McCall return FriendLoc; 8292b7f70c924cbf4514e9e434cea7def51ab49860John McCall } 8392b7f70c924cbf4514e9e434cea7def51ab49860John McCall 8492b7f70c924cbf4514e9e434cea7def51ab49860John McCall bool wasSpecialization() const { return WasSpecialization; } 8592b7f70c924cbf4514e9e434cea7def51ab49860John McCall void setSpecialization(bool WS) { WasSpecialization = WS; } 8692b7f70c924cbf4514e9e434cea7def51ab49860John McCall 8792b7f70c924cbf4514e9e434cea7def51ab49860John McCall // Implement isa/cast/dyncast/etc. 8892b7f70c924cbf4514e9e434cea7def51ab49860John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 8992b7f70c924cbf4514e9e434cea7def51ab49860John McCall static bool classof(const FriendDecl *D) { return true; } 9092b7f70c924cbf4514e9e434cea7def51ab49860John McCall static bool classofKind(Kind K) { return K == Decl::Friend; } 9192b7f70c924cbf4514e9e434cea7def51ab49860John McCall}; 9292b7f70c924cbf4514e9e434cea7def51ab49860John McCall 9392b7f70c924cbf4514e9e434cea7def51ab49860John McCall} 9492b7f70c924cbf4514e9e434cea7def51ab49860John McCall 9592b7f70c924cbf4514e9e434cea7def51ab49860John McCall#endif 96