clang 20.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"
19#include "clang/AST/DeclID.h"
22#include <cassert>
23#include <cstdint>
24
25namespace clang {
26
27class NamedDecl;
28
29/// An UnresolvedSet-like class which uses the ASTContext's allocator.
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
43public:
44 ASTUnresolvedSet() = default;
45 ASTUnresolvedSet(ASTContext &C, unsigned N) : Decls(C, N) {}
46
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
57 Decls.push_back(DeclAccessPair::make(D, AS), C);
58 }
59
61 Decls.push_back(DeclAccessPair::makeLazy(ID.getRawValue(), AS), C);
62 }
63
64 /// Replaces the given declaration with the new one, once.
65 ///
66 /// \return true if the set changed
67 bool replace(const NamedDecl *Old, NamedDecl *New, AccessSpecifier AS) {
68 for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
69 if (I->getDecl() == Old) {
70 I->set(New, AS);
71 return true;
72 }
73 }
74 return false;
75 }
76
77 void erase(unsigned I) {
78 if (I == Decls.size() - 1)
79 Decls.pop_back();
80 else
81 Decls[I] = Decls.pop_back_val();
82 }
83
84 void clear() { Decls.clear(); }
85
86 bool empty() const { return Decls.empty(); }
87 unsigned size() const { return Decls.size(); }
88
89 void reserve(ASTContext &C, unsigned N) {
90 Decls.reserve(C, N);
91 }
92
94 Decls.append(C, I.I, E.I);
95 }
96
97 DeclAccessPair &operator[](unsigned I) { return Decls[I]; }
98 const DeclAccessPair &operator[](unsigned I) const { return Decls[I]; }
99};
100
101/// An UnresolvedSet-like class that might not have been loaded from the
102/// external AST source yet.
104 mutable ASTUnresolvedSet Impl;
105
106 void getFromExternalSource(ASTContext &C) const;
107
108public:
110 if (Impl.Decls.isLazy())
111 getFromExternalSource(C);
112 return Impl;
113 }
114
115 void reserve(ASTContext &C, unsigned N) { Impl.reserve(C, N); }
116
118 assert(Impl.empty() || Impl.Decls.isLazy());
119 Impl.Decls.setLazy(true);
120 Impl.addLazyDecl(C, ID, AS);
121 }
122};
123
124} // namespace clang
125
126#endif // LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
static char ID
Definition: Arena.cpp:183
const Decl * D
Expr * E
Defines various enumerations that describe declaration and type specifiers.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
An UnresolvedSet-like class which uses the ASTContext's allocator.
void append(ASTContext &C, iterator I, iterator E)
const DeclAccessPair & operator[](unsigned I) const
bool replace(const NamedDecl *Old, NamedDecl *New, AccessSpecifier AS)
Replaces the given declaration with the new one, once.
UnresolvedSetIterator iterator
UnresolvedSetIterator const_iterator
const_iterator end() const
ASTUnresolvedSet(ASTContext &C, unsigned N)
void reserve(ASTContext &C, unsigned N)
void addLazyDecl(ASTContext &C, GlobalDeclID ID, AccessSpecifier AS)
const_iterator begin() const
void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS)
void erase(unsigned I)
DeclAccessPair & operator[](unsigned I)
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
static DeclAccessPair makeLazy(uint64_t ID, AccessSpecifier AS)
An UnresolvedSet-like class that might not have been loaded from the external AST source yet.
void reserve(ASTContext &C, unsigned N)
void addLazyDecl(ASTContext &C, GlobalDeclID ID, AccessSpecifier AS)
ASTUnresolvedSet & get(ASTContext &C) const
This represents a decl that may have a name.
Definition: Decl.h:249
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:35
The JSON file list parser is used to communicate input to InstallAPI.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:123