DeclAccessPair.h revision 263509
182518Sgallatin//===--- DeclAccessPair.h - A decl bundled with its path access -*- C++ -*-===// 282518Sgallatin// 382518Sgallatin// The LLVM Compiler Infrastructure 482518Sgallatin// 582518Sgallatin// This file is distributed under the University of Illinois Open Source 682518Sgallatin// License. See LICENSE.TXT for details. 782518Sgallatin// 882518Sgallatin//===----------------------------------------------------------------------===// 982518Sgallatin// 1082518Sgallatin// This file defines the DeclAccessPair class, which provides an 1182518Sgallatin// efficient representation of a pair of a NamedDecl* and an 1282518Sgallatin// AccessSpecifier. Generally the access specifier gives the 1382518Sgallatin// natural access of a declaration when named in a class, as 1482518Sgallatin// defined in C++ [class.access.base]p1. 1582518Sgallatin// 1682518Sgallatin//===----------------------------------------------------------------------===// 1782518Sgallatin 1882518Sgallatin#ifndef LLVM_CLANG_AST_DECLACCESSPAIR_H 1982518Sgallatin#define LLVM_CLANG_AST_DECLACCESSPAIR_H 2082518Sgallatin 2182518Sgallatin#include "clang/Basic/Specifiers.h" 2282518Sgallatin#include "llvm/Support/DataTypes.h" 2382518Sgallatin 2482518Sgallatinnamespace clang { 2582518Sgallatin 2682518Sgallatinclass NamedDecl; 2782518Sgallatin 2882518Sgallatin/// A POD class for pairing a NamedDecl* with an access specifier. 2982518Sgallatin/// Can be put into unions. 3082518Sgallatinclass DeclAccessPair { 3182518Sgallatin uintptr_t Ptr; // we'd use llvm::PointerUnion, but it isn't trivial 3282518Sgallatin 3382518Sgallatin enum { Mask = 0x3 }; 3482518Sgallatin 3582518Sgallatinpublic: 3682518Sgallatin static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS) { 3782518Sgallatin DeclAccessPair p; 38116173Sobrien p.set(D, AS); 39116173Sobrien return p; 40116173Sobrien } 41116173Sobrien 42156874Sru NamedDecl *getDecl() const { 43112430Sphk return reinterpret_cast<NamedDecl*>(~Mask & Ptr); 4482518Sgallatin } 4582518Sgallatin AccessSpecifier getAccess() const { 4682518Sgallatin return AccessSpecifier(Mask & Ptr); 47112430Sphk } 48112430Sphk 49112430Sphk void setDecl(NamedDecl *D) { 50112430Sphk set(D, getAccess()); 51112430Sphk } 52102872Siedowse void setAccess(AccessSpecifier AS) { 53112430Sphk set(getDecl(), AS); 54112430Sphk } 5582518Sgallatin void set(NamedDecl *D, AccessSpecifier AS) { 56112430Sphk Ptr = uintptr_t(AS) | reinterpret_cast<uintptr_t>(D); 57112430Sphk } 58112430Sphk 59112430Sphk operator NamedDecl*() const { return getDecl(); } 6082518Sgallatin NamedDecl *operator->() const { return getDecl(); } 61140214Sobrien}; 62140214Sobrien} 63140214Sobrien 64140214Sobrien// Take a moment to tell SmallVector that DeclAccessPair is POD. 6582518Sgallatinnamespace llvm { 6682518Sgallatintemplate<typename> struct isPodLike; 67133816Stjrtemplate<> struct isPodLike<clang::DeclAccessPair> { 68112430Sphk static const bool value = true; 6982518Sgallatin}; 70163606Srwatson} 71163606Srwatson 72112430Sphk#endif 73112430Sphk