clang 8.0.0

DeclAccessPair.h
Go to the documentation of this file.
1 //===--- DeclAccessPair.h - A decl bundled with its path access -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_CLANG_AST_DECLACCESSPAIR_H
19 #define LLVM_CLANG_AST_DECLACCESSPAIR_H
20
21 #include "clang/Basic/Specifiers.h"
22 #include "llvm/Support/DataTypes.h"
23
24 namespace clang {
25
26 class NamedDecl;
27
28 /// A POD class for pairing a NamedDecl* with an access specifier.
29 /// Can be put into unions.
30 class DeclAccessPair {
31 uintptr_t Ptr; // we'd use llvm::PointerUnion, but it isn't trivial
32
33 enum { Mask = 0x3 };
34
35 public:
36 static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS) {
37 DeclAccessPair p;
38 p.set(D, AS);
39 return p;
40 }
41
42 NamedDecl *getDecl() const {
43 return reinterpret_cast<NamedDecl*>(~Mask & Ptr);
44 }
45 AccessSpecifier getAccess() const {
46 return AccessSpecifier(Mask & Ptr);
47 }
48
49 void setDecl(NamedDecl *D) {
50 set(D, getAccess());
51 }
52 void setAccess(AccessSpecifier AS) {
53 set(getDecl(), AS);
54 }
55 void set(NamedDecl *D, AccessSpecifier AS) {
56 Ptr = uintptr_t(AS) | reinterpret_cast<uintptr_t>(D);
57 }
58
59 operator NamedDecl*() const { return getDecl(); }
60 NamedDecl *operator->() const { return getDecl(); }
61 };
62 }
63
64 // Take a moment to tell SmallVector that DeclAccessPair is POD.
65 namespace llvm {
66 template<typename> struct isPodLike;
67 template<> struct isPodLike<clang::DeclAccessPair> {
68 static const bool value = true;
69 };
70 }
71
72 #endif
llvm
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
clang::DeclAccessPair::getDecl
NamedDecl * getDecl() const
Definition: DeclAccessPair.h:42
clang::AccessSpecifier
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:98
clang::DeclAccessPair::operator->
NamedDecl * operator->() const
Definition: DeclAccessPair.h:60
clang::DeclAccessPair::make
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Definition: DeclAccessPair.h:36
uintptr_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c.h:90
clang::DeclAccessPair::set
void set(NamedDecl *D, AccessSpecifier AS)
Definition: DeclAccessPair.h:55
llvm::isPodLike
Definition: DeclAccessPair.h:66
clang::DeclAccessPair::getAccess
AccessSpecifier getAccess() const
Definition: DeclAccessPair.h:45
clang::DeclAccessPair::setAccess
void setAccess(AccessSpecifier AS)
Definition: DeclAccessPair.h:52
Specifiers.h
Defines various enumerations that describe declaration and type specifiers.
clang::DeclAccessPair
A POD class for pairing a NamedDecl* with an access specifier.
Definition: DeclAccessPair.h:30
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::DeclAccessPair::setDecl
void setDecl(NamedDecl *D)
Definition: DeclAccessPair.h:49
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249