clang API Documentation

DeclAccessPair.h
Go to the documentation of this file.
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 
00023 namespace clang {
00024 
00025 class NamedDecl;
00026 
00027 /// A POD class for pairing a NamedDecl* with an access specifier.
00028 /// Can be put into unions.
00029 class DeclAccessPair {
00030   NamedDecl *Ptr; // we'd use llvm::PointerUnion, but it isn't trivial
00031 
00032   enum { Mask = 0x3 };
00033 
00034 public:
00035   static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS) {
00036     DeclAccessPair p;
00037     p.set(D, AS);
00038     return p;
00039   }
00040 
00041   NamedDecl *getDecl() const {
00042     return (NamedDecl*) (~Mask & (uintptr_t) Ptr);
00043   }
00044   AccessSpecifier getAccess() const {
00045     return AccessSpecifier(Mask & (uintptr_t) Ptr);
00046   }
00047 
00048   void setDecl(NamedDecl *D) {
00049     set(D, getAccess());
00050   }
00051   void setAccess(AccessSpecifier AS) {
00052     set(getDecl(), AS);
00053   }
00054   void set(NamedDecl *D, AccessSpecifier AS) {
00055     Ptr = reinterpret_cast<NamedDecl*>(uintptr_t(AS) |
00056                                        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