clang 8.0.0

ASTUnresolvedSet.h
Go to the documentation of this file.
1 //===- ASTUnresolvedSet.h - Unresolved sets of declarations -----*- 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 provides an UnresolvedSet-like class, whose contents are
11 // allocated using the allocator associated with an ASTContext.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
16 #define LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
17
18 #include "clang/AST/ASTVector.h"
19 #include "clang/AST/DeclAccessPair.h"
20 #include "clang/AST/UnresolvedSet.h"
21 #include "clang/Basic/Specifiers.h"
22 #include <cassert>
23 #include <cstdint>
24
25 namespace clang {
26
27 class NamedDecl;
28
29 /// An UnresolvedSet-like class which uses the ASTContext's allocator.
30 class ASTUnresolvedSet {
31 friend class LazyASTUnresolvedSet;
32
33 struct DeclsTy : ASTVector<DeclAccessPair> {
34 DeclsTy() = default;
35 DeclsTy(ASTContext &C, unsigned N) : ASTVector<DeclAccessPair>(C, N) {}
36
37 bool isLazy() const { return getTag(); }
38 void setLazy(bool Lazy) { setTag(Lazy); }
39 };
40
41 DeclsTy Decls;
42
43 public:
44 ASTUnresolvedSet() = default;
45 ASTUnresolvedSet(ASTContext &C, unsigned N) : Decls(C, N) {}
46
47 using iterator = UnresolvedSetIterator;
48 using const_iterator = UnresolvedSetIterator;
49
50 iterator begin() { return iterator(Decls.begin()); }
51 iterator end() { return iterator(Decls.end()); }
52
53 const_iterator begin() const { return const_iterator(Decls.begin()); }
54 const_iterator end() const { return const_iterator(Decls.end()); }
55
56 void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS) {
57 Decls.push_back(DeclAccessPair::make(D, AS), C);
58 }
59
60 /// Replaces the given declaration with the new one, once.
61 ///
62 /// \return true if the set changed
63 bool replace(const NamedDecl *Old, NamedDecl *New, AccessSpecifier AS) {
64 for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
65 if (I->getDecl() == Old) {
66 I->set(New, AS);
67 return true;
68 }
69 }
70 return false;
71 }
72
73 void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
74
75 void clear() { Decls.clear(); }
76
77 bool empty() const { return Decls.empty(); }
78 unsigned size() const { return Decls.size(); }
79
80 void reserve(ASTContext &C, unsigned N) {
81 Decls.reserve(C, N);
82 }
83
84 void append(ASTContext &C, iterator I, iterator E) {
85 Decls.append(C, I.I, E.I);
86 }
87
88 DeclAccessPair &operator[](unsigned I) { return Decls[I]; }
89 const DeclAccessPair &operator[](unsigned I) const { return Decls[I]; }
90 };
91
92 /// An UnresolvedSet-like class that might not have been loaded from the
93 /// external AST source yet.
94 class LazyASTUnresolvedSet {
95 mutable ASTUnresolvedSet Impl;
96
97 void getFromExternalSource(ASTContext &C) const;
98
99 public:
100 ASTUnresolvedSet &get(ASTContext &C) const {
101 if (Impl.Decls.isLazy())
102 getFromExternalSource(C);
103 return Impl;
104 }
105
106 void reserve(ASTContext &C, unsigned N) { Impl.reserve(C, N); }
107
108 void addLazyDecl(ASTContext &C, uintptr_t ID, AccessSpecifier AS) {
109 assert(Impl.empty() || Impl.Decls.isLazy());
110 Impl.Decls.setLazy(true);
111 Impl.addDecl(C, reinterpret_cast<NamedDecl *>(ID << 2), AS);
112 }
113 };
114
115 } // namespace clang
116
117 #endif // LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
clang::Builtin::ID
ID
Definition: Builtins.h:49
clang::ASTUnresolvedSet::replace
bool replace(const NamedDecl *Old, NamedDecl *New, AccessSpecifier AS)
Replaces the given declaration with the new one, once.
Definition: ASTUnresolvedSet.h:63
clang::ASTUnresolvedSet::erase
void erase(unsigned I)
Definition: ASTUnresolvedSet.h:73
clang::ASTUnresolvedSet::clear
void clear()
Definition: ASTUnresolvedSet.h:75
clang::ASTUnresolvedSet::append
void append(ASTContext &C, iterator I, iterator E)
Definition: ASTUnresolvedSet.h:84
clang::ASTUnresolvedSet::iterator
UnresolvedSetIterator iterator
Definition: ASTUnresolvedSet.h:47
clang::ASTUnresolvedSet::begin
iterator begin()
Definition: ASTUnresolvedSet.h:50
clang::AccessSpecifier
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:98
clang::LazyASTUnresolvedSet
An UnresolvedSet-like class that might not have been loaded from the external AST source yet...
Definition: ASTUnresolvedSet.h:94
clang::LazyASTUnresolvedSet::addLazyDecl
void addLazyDecl(ASTContext &C, uintptr_t ID, AccessSpecifier AS)
Definition: ASTUnresolvedSet.h:108
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
clang::ASTUnresolvedSet::ASTUnresolvedSet
ASTUnresolvedSet()=default
clang::ASTUnresolvedSet::begin
const_iterator begin() const
Definition: ASTUnresolvedSet.h:53
clang::UnresolvedSetIterator
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:32
clang::ASTUnresolvedSet::addDecl
void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS)
Definition: ASTUnresolvedSet.h:56
clang::DeclAccessPair::make
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Definition: DeclAccessPair.h:36
clang::ASTUnresolvedSet::size
unsigned size() const
Definition: ASTUnresolvedSet.h:78
DeclAccessPair.h
clang::ASTUnresolvedSet::reserve
void reserve(ASTContext &C, unsigned N)
Definition: ASTUnresolvedSet.h:80
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::ASTUnresolvedSet::end
const_iterator end() const
Definition: ASTUnresolvedSet.h:54
UnresolvedSet.h
clang::ASTUnresolvedSet::ASTUnresolvedSet
ASTUnresolvedSet(ASTContext &C, unsigned N)
Definition: ASTUnresolvedSet.h:45
clang::ASTUnresolvedSet::empty
bool empty() const
Definition: ASTUnresolvedSet.h:77
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::LazyASTUnresolvedSet::reserve
void reserve(ASTContext &C, unsigned N)
Definition: ASTUnresolvedSet.h:106
clang::ASTUnresolvedSet
An UnresolvedSet-like class which uses the ASTContext&#39;s allocator.
Definition: ASTUnresolvedSet.h:30
clang::ASTUnresolvedSet::end
iterator end()
Definition: ASTUnresolvedSet.h:51
ASTVector.h
clang::AttrSyntax::C
clang::ASTUnresolvedSet::operator[]
DeclAccessPair & operator[](unsigned I)
Definition: ASTUnresolvedSet.h:88
clang::ASTUnresolvedSet::const_iterator
UnresolvedSetIterator const_iterator
Definition: ASTUnresolvedSet.h:48
clang::ASTUnresolvedSet::operator[]
const DeclAccessPair & operator[](unsigned I) const
Definition: ASTUnresolvedSet.h:89
clang::ASTVector
Definition: ASTVector.h:37
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249