clang 10.0.0git

DeclAccessPair.h
Go to the documentation of this file.
1 //===--- DeclAccessPair.h - A decl bundled with its path access -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the DeclAccessPair class, which provides an
10 // efficient representation of a pair of a NamedDecl* and an
11 // AccessSpecifier. Generally the access specifier gives the
12 // natural access of a declaration when named in a class, as
13 // defined in C++ [class.access.base]p1.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_CLANG_AST_DECLACCESSPAIR_H
18 #define LLVM_CLANG_AST_DECLACCESSPAIR_H
19
20 #include "clang/Basic/Specifiers.h"
21 #include "llvm/Support/DataTypes.h"
22
23 namespace clang {
24
25 class NamedDecl;
26
27 /// A POD class for pairing a NamedDecl* with an access specifier.
28 /// Can be put into unions.
29 class DeclAccessPair {
30 uintptr_t Ptr; // we'd use llvm::PointerUnion, but it isn't trivial
31
32 enum { Mask = 0x3 };
33
34 public:
35 static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS) {
36 DeclAccessPair p;
37 p.set(D, AS);
38 return p;
39 }
40
41 NamedDecl *getDecl() const {
42 return reinterpret_cast<NamedDecl*>(~Mask & Ptr);
43 }
44 AccessSpecifier getAccess() const {
45 return AccessSpecifier(Mask & Ptr);
46 }
47
48 void setDecl(NamedDecl *D) {
49 set(D, getAccess());
50 }
51 void setAccess(AccessSpecifier AS) {
52 set(getDecl(), AS);
53 }
54 void set(NamedDecl *D, AccessSpecifier AS) {
55 Ptr = uintptr_t(AS) | reinterpret_cast<uintptr_t>(D);
56 }
57
58 operator NamedDecl*() const { return getDecl(); }
59 NamedDecl *operator->() const { return getDecl(); }
60 };
61 }
62
63 #endif
clang::DeclAccessPair::getDecl
NamedDecl * getDecl() const
Definition: DeclAccessPair.h:41
clang::AccessSpecifier
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:113
clang::DeclAccessPair::operator->
NamedDecl * operator->() const
Definition: DeclAccessPair.h:59
clang::DeclAccessPair::make
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Definition: DeclAccessPair.h:35
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-base.h:62
clang::DeclAccessPair::set
void set(NamedDecl *D, AccessSpecifier AS)
Definition: DeclAccessPair.h:54
clang::DeclAccessPair::getAccess
AccessSpecifier getAccess() const
Definition: DeclAccessPair.h:44
clang::DeclAccessPair::setAccess
void setAccess(AccessSpecifier AS)
Definition: DeclAccessPair.h:51
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:29
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::DeclAccessPair::setDecl
void setDecl(NamedDecl *D)
Definition: DeclAccessPair.h:48
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:223