clang API Documentation
00001 //===--- DeclAccessPair.h - A decl bundled with its path access -*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the DeclAccessPair class, which provides an 00011 // efficient representation of a pair of a NamedDecl* and an 00012 // AccessSpecifier. Generally the access specifier gives the 00013 // natural access of a declaration when named in a class, as 00014 // defined in C++ [class.access.base]p1. 00015 // 00016 //===----------------------------------------------------------------------===// 00017 00018 #ifndef LLVM_CLANG_AST_DECLACCESSPAIR_H 00019 #define LLVM_CLANG_AST_DECLACCESSPAIR_H 00020 00021 #include "clang/Basic/Specifiers.h" 00022 #include "llvm/Support/DataTypes.h" 00023 00024 namespace clang { 00025 00026 class NamedDecl; 00027 00028 /// A POD class for pairing a NamedDecl* with an access specifier. 00029 /// Can be put into unions. 00030 class DeclAccessPair { 00031 uintptr_t Ptr; // we'd use llvm::PointerUnion, but it isn't trivial 00032 00033 enum { Mask = 0x3 }; 00034 00035 public: 00036 static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS) { 00037 DeclAccessPair p; 00038 p.set(D, AS); 00039 return p; 00040 } 00041 00042 NamedDecl *getDecl() const { 00043 return reinterpret_cast<NamedDecl*>(~Mask & Ptr); 00044 } 00045 AccessSpecifier getAccess() const { 00046 return AccessSpecifier(Mask & Ptr); 00047 } 00048 00049 void setDecl(NamedDecl *D) { 00050 set(D, getAccess()); 00051 } 00052 void setAccess(AccessSpecifier AS) { 00053 set(getDecl(), AS); 00054 } 00055 void set(NamedDecl *D, AccessSpecifier AS) { 00056 Ptr = uintptr_t(AS) | reinterpret_cast<uintptr_t>(D); 00057 } 00058 00059 operator NamedDecl*() const { return getDecl(); } 00060 NamedDecl *operator->() const { return getDecl(); } 00061 }; 00062 } 00063 00064 // Take a moment to tell SmallVector that DeclAccessPair is POD. 00065 namespace llvm { 00066 template<typename> struct isPodLike; 00067 template<> struct isPodLike<clang::DeclAccessPair> { 00068 static const bool value = true; 00069 }; 00070 } 00071 00072 #endif