xref: /minix3/external/bsd/llvm/dist/clang/include/clang/AST/DeclAccessPair.h (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc //===--- DeclAccessPair.h - A decl bundled with its path access -*- C++ -*-===//
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7*f4a2713aSLionel Sambuc //
8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9*f4a2713aSLionel Sambuc //
10*f4a2713aSLionel Sambuc //  This file defines the DeclAccessPair class, which provides an
11*f4a2713aSLionel Sambuc //  efficient representation of a pair of a NamedDecl* and an
12*f4a2713aSLionel Sambuc //  AccessSpecifier.  Generally the access specifier gives the
13*f4a2713aSLionel Sambuc //  natural access of a declaration when named in a class, as
14*f4a2713aSLionel Sambuc //  defined in C++ [class.access.base]p1.
15*f4a2713aSLionel Sambuc //
16*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc #ifndef LLVM_CLANG_AST_DECLACCESSPAIR_H
19*f4a2713aSLionel Sambuc #define LLVM_CLANG_AST_DECLACCESSPAIR_H
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc #include "clang/Basic/Specifiers.h"
22*f4a2713aSLionel Sambuc #include "llvm/Support/DataTypes.h"
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc namespace clang {
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc class NamedDecl;
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc /// A POD class for pairing a NamedDecl* with an access specifier.
29*f4a2713aSLionel Sambuc /// Can be put into unions.
30*f4a2713aSLionel Sambuc class DeclAccessPair {
31*f4a2713aSLionel Sambuc   uintptr_t Ptr; // we'd use llvm::PointerUnion, but it isn't trivial
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc   enum { Mask = 0x3 };
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc public:
make(NamedDecl * D,AccessSpecifier AS)36*f4a2713aSLionel Sambuc   static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS) {
37*f4a2713aSLionel Sambuc     DeclAccessPair p;
38*f4a2713aSLionel Sambuc     p.set(D, AS);
39*f4a2713aSLionel Sambuc     return p;
40*f4a2713aSLionel Sambuc   }
41*f4a2713aSLionel Sambuc 
getDecl()42*f4a2713aSLionel Sambuc   NamedDecl *getDecl() const {
43*f4a2713aSLionel Sambuc     return reinterpret_cast<NamedDecl*>(~Mask & Ptr);
44*f4a2713aSLionel Sambuc   }
getAccess()45*f4a2713aSLionel Sambuc   AccessSpecifier getAccess() const {
46*f4a2713aSLionel Sambuc     return AccessSpecifier(Mask & Ptr);
47*f4a2713aSLionel Sambuc   }
48*f4a2713aSLionel Sambuc 
setDecl(NamedDecl * D)49*f4a2713aSLionel Sambuc   void setDecl(NamedDecl *D) {
50*f4a2713aSLionel Sambuc     set(D, getAccess());
51*f4a2713aSLionel Sambuc   }
setAccess(AccessSpecifier AS)52*f4a2713aSLionel Sambuc   void setAccess(AccessSpecifier AS) {
53*f4a2713aSLionel Sambuc     set(getDecl(), AS);
54*f4a2713aSLionel Sambuc   }
set(NamedDecl * D,AccessSpecifier AS)55*f4a2713aSLionel Sambuc   void set(NamedDecl *D, AccessSpecifier AS) {
56*f4a2713aSLionel Sambuc     Ptr = uintptr_t(AS) | reinterpret_cast<uintptr_t>(D);
57*f4a2713aSLionel Sambuc   }
58*f4a2713aSLionel Sambuc 
59*f4a2713aSLionel Sambuc   operator NamedDecl*() const { return getDecl(); }
60*f4a2713aSLionel Sambuc   NamedDecl *operator->() const { return getDecl(); }
61*f4a2713aSLionel Sambuc };
62*f4a2713aSLionel Sambuc }
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc // Take a moment to tell SmallVector that DeclAccessPair is POD.
65*f4a2713aSLionel Sambuc namespace llvm {
66*f4a2713aSLionel Sambuc template<typename> struct isPodLike;
67*f4a2713aSLionel Sambuc template<> struct isPodLike<clang::DeclAccessPair> {
68*f4a2713aSLionel Sambuc    static const bool value = true;
69*f4a2713aSLionel Sambuc };
70*f4a2713aSLionel Sambuc }
71*f4a2713aSLionel Sambuc 
72*f4a2713aSLionel Sambuc #endif
73