clang 10.0.0git

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