/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/ASTUnresolvedSet.h
Line | Count | Source (jump to first uncovered line) |
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 | 5.39M | DeclsTy() = default; |
34 | 0 | DeclsTy(ASTContext &C, unsigned N) : ASTVector<DeclAccessPair>(C, N) {} |
35 | | |
36 | 12.8M | bool isLazy() const { return getTag(); } |
37 | 21.9k | void setLazy(bool Lazy) { setTag(Lazy); } |
38 | | }; |
39 | | |
40 | | DeclsTy Decls; |
41 | | |
42 | | public: |
43 | 5.39M | ASTUnresolvedSet() = default; |
44 | 0 | ASTUnresolvedSet(ASTContext &C, unsigned N) : Decls(C, N) {} |
45 | | |
46 | | using iterator = UnresolvedSetIterator; |
47 | | using const_iterator = UnresolvedSetIterator; |
48 | | |
49 | 8.82M | iterator begin() { return iterator(Decls.begin()); } |
50 | 8.82M | iterator end() { return iterator(Decls.end()); } |
51 | | |
52 | 70.1k | const_iterator begin() const { return const_iterator(Decls.begin()); } |
53 | 70.1k | const_iterator end() const { return const_iterator(Decls.end()); } |
54 | | |
55 | 64.0k | void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS) { |
56 | 64.0k | Decls.push_back(DeclAccessPair::make(D, AS), C); |
57 | 64.0k | } |
58 | | |
59 | | /// Replaces the given declaration with the new one, once. |
60 | | /// |
61 | | /// \return true if the set changed |
62 | 0 | bool replace(const NamedDecl *Old, NamedDecl *New, AccessSpecifier AS) { |
63 | 0 | for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
64 | 0 | if (I->getDecl() == Old) { |
65 | 0 | I->set(New, AS); |
66 | 0 | return true; |
67 | 0 | } |
68 | 0 | } |
69 | 0 | return false; |
70 | 0 | } |
71 | | |
72 | 1 | void erase(unsigned I) { |
73 | 1 | if (I == Decls.size() - 1) |
74 | 1 | Decls.pop_back(); |
75 | 0 | else |
76 | 0 | Decls[I] = Decls.pop_back_val(); |
77 | 1 | } |
78 | | |
79 | 0 | void clear() { Decls.clear(); } |
80 | | |
81 | 21.8k | bool empty() const { return Decls.empty(); } |
82 | 70.1k | unsigned size() const { return Decls.size(); } |
83 | | |
84 | 268k | void reserve(ASTContext &C, unsigned N) { |
85 | 268k | Decls.reserve(C, N); |
86 | 268k | } |
87 | | |
88 | 7.47k | void append(ASTContext &C, iterator I, iterator E) { |
89 | 7.47k | Decls.append(C, I.I, E.I); |
90 | 7.47k | } |
91 | | |
92 | 1 | DeclAccessPair &operator[](unsigned I) { return Decls[I]; } |
93 | 0 | const DeclAccessPair &operator[](unsigned I) const { return Decls[I]; } |
94 | | }; |
95 | | |
96 | | /// An UnresolvedSet-like class that might not have been loaded from the |
97 | | /// external AST source yet. |
98 | | class LazyASTUnresolvedSet { |
99 | | mutable ASTUnresolvedSet Impl; |
100 | | |
101 | | void getFromExternalSource(ASTContext &C) const; |
102 | | |
103 | | public: |
104 | 12.8M | ASTUnresolvedSet &get(ASTContext &C) const { |
105 | 12.8M | if (Impl.Decls.isLazy()) |
106 | 89 | getFromExternalSource(C); |
107 | 12.8M | return Impl; |
108 | 12.8M | } |
109 | | |
110 | 268k | void reserve(ASTContext &C, unsigned N) { Impl.reserve(C, N); } |
111 | | |
112 | 21.8k | void addLazyDecl(ASTContext &C, uintptr_t ID, AccessSpecifier AS) { |
113 | 21.8k | assert(Impl.empty() || Impl.Decls.isLazy()); |
114 | 21.8k | Impl.Decls.setLazy(true); |
115 | 21.8k | Impl.addDecl(C, reinterpret_cast<NamedDecl *>(ID << 2), AS); |
116 | 21.8k | } |
117 | | }; |
118 | | |
119 | | } // namespace clang |
120 | | |
121 | | #endif // LLVM_CLANG_AST_ASTUNRESOLVEDSET_H |