1 //===--- DeclAccessPair.h - A decl bundled with its path access -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the DeclAccessPair class, which provides an
11 // efficient representation of a pair of a NamedDecl* and an
12 // AccessSpecifier. Generally the access specifier gives the
13 // natural access of a declaration when named in a class, as
14 // defined in C++ [class.access.base]p1.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_CLANG_AST_DECLACCESSPAIR_H
19 #define LLVM_CLANG_AST_DECLACCESSPAIR_H
21 #include "clang/Basic/Specifiers.h"
27 /// A POD class for pairing a NamedDecl* with an access specifier.
28 /// Can be put into unions.
29 class DeclAccessPair {
30 NamedDecl *Ptr; // we'd use llvm::PointerUnion, but it isn't trivial
35 static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS) {
41 NamedDecl *getDecl() const {
42 return (NamedDecl*) (~Mask & (uintptr_t) Ptr);
44 AccessSpecifier getAccess() const {
45 return AccessSpecifier(Mask & (uintptr_t) Ptr);
48 void setDecl(NamedDecl *D) {
51 void setAccess(AccessSpecifier AS) {
54 void set(NamedDecl *D, AccessSpecifier AS) {
55 Ptr = reinterpret_cast<NamedDecl*>(uintptr_t(AS) |
56 reinterpret_cast<uintptr_t>(D));
59 operator NamedDecl*() const { return getDecl(); }
60 NamedDecl *operator->() const { return getDecl(); }
64 // Take a moment to tell SmallVector that DeclAccessPair is POD.
66 template<typename> struct isPodLike;
67 template<> struct isPodLike<clang::DeclAccessPair> {
68 static const bool value = true;