Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/clang/lib/Sema/MultiplexExternalSemaSource.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- MultiplexExternalSemaSource.cpp  ---------------------------------===//
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 implements the event dispatching to the subscribed clients.
10
//
11
//===----------------------------------------------------------------------===//
12
#include "clang/Sema/MultiplexExternalSemaSource.h"
13
#include "clang/Sema/Lookup.h"
14
15
using namespace clang;
16
17
char MultiplexExternalSemaSource::ID;
18
19
/// Constructs a new multiplexing external sema source and appends the
20
/// given element to it.
21
///
22
MultiplexExternalSemaSource::MultiplexExternalSemaSource(
23
0
    ExternalSemaSource *S1, ExternalSemaSource *S2) {
24
0
  S1->Retain();
25
0
  S2->Retain();
26
0
  Sources.push_back(S1);
27
0
  Sources.push_back(S2);
28
0
}
29
30
// pin the vtable here.
31
0
MultiplexExternalSemaSource::~MultiplexExternalSemaSource() {
32
0
  for (auto *S : Sources)
33
0
    S->Release();
34
0
}
35
36
/// Appends new source to the source list.
37
///
38
///\param[in] source - An ExternalSemaSource.
39
///
40
0
void MultiplexExternalSemaSource::AddSource(ExternalSemaSource *Source) {
41
0
  Source->Retain();
42
0
  Sources.push_back(Source);
43
0
}
44
45
//===----------------------------------------------------------------------===//
46
// ExternalASTSource.
47
//===----------------------------------------------------------------------===//
48
49
0
Decl *MultiplexExternalSemaSource::GetExternalDecl(uint32_t ID) {
50
0
  for(size_t i = 0; i < Sources.size(); ++i)
51
0
    if (Decl *Result = Sources[i]->GetExternalDecl(ID))
52
0
      return Result;
53
0
  return nullptr;
54
0
}
55
56
0
void MultiplexExternalSemaSource::CompleteRedeclChain(const Decl *D) {
57
0
  for (size_t i = 0; i < Sources.size(); ++i)
58
0
    Sources[i]->CompleteRedeclChain(D);
59
0
}
60
61
0
Selector MultiplexExternalSemaSource::GetExternalSelector(uint32_t ID) {
62
0
  Selector Sel;
63
0
  for(size_t i = 0; i < Sources.size(); ++i) {
64
0
    Sel = Sources[i]->GetExternalSelector(ID);
65
0
    if (!Sel.isNull())
66
0
      return Sel;
67
0
  }
68
0
  return Sel;
69
0
}
70
71
0
uint32_t MultiplexExternalSemaSource::GetNumExternalSelectors() {
72
0
  uint32_t total = 0;
73
0
  for(size_t i = 0; i < Sources.size(); ++i)
74
0
    total += Sources[i]->GetNumExternalSelectors();
75
0
  return total;
76
0
}
77
78
0
Stmt *MultiplexExternalSemaSource::GetExternalDeclStmt(uint64_t Offset) {
79
0
  for(size_t i = 0; i < Sources.size(); ++i)
80
0
    if (Stmt *Result = Sources[i]->GetExternalDeclStmt(Offset))
81
0
      return Result;
82
0
  return nullptr;
83
0
}
84
85
CXXBaseSpecifier *MultiplexExternalSemaSource::GetExternalCXXBaseSpecifiers(
86
0
                                                               uint64_t Offset){
87
0
  for(size_t i = 0; i < Sources.size(); ++i)
88
0
    if (CXXBaseSpecifier *R = Sources[i]->GetExternalCXXBaseSpecifiers(Offset))
89
0
      return R;
90
0
  return nullptr;
91
0
}
92
93
CXXCtorInitializer **
94
0
MultiplexExternalSemaSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
95
0
  for (auto *S : Sources)
96
0
    if (auto *R = S->GetExternalCXXCtorInitializers(Offset))
97
0
      return R;
98
0
  return nullptr;
99
0
}
100
101
ExternalASTSource::ExtKind
102
0
MultiplexExternalSemaSource::hasExternalDefinitions(const Decl *D) {
103
0
  for (const auto &S : Sources)
104
0
    if (auto EK = S->hasExternalDefinitions(D))
105
0
      if (EK != EK_ReplyHazy)
106
0
        return EK;
107
0
  return EK_ReplyHazy;
108
0
}
109
110
bool MultiplexExternalSemaSource::
111
0
FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
112
0
  bool AnyDeclsFound = false;
113
0
  for (size_t i = 0; i < Sources.size(); ++i)
114
0
    AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
115
0
  return AnyDeclsFound;
116
0
}
117
118
0
void MultiplexExternalSemaSource::completeVisibleDeclsMap(const DeclContext *DC){
119
0
  for(size_t i = 0; i < Sources.size(); ++i)
120
0
    Sources[i]->completeVisibleDeclsMap(DC);
121
0
}
122
123
void MultiplexExternalSemaSource::FindExternalLexicalDecls(
124
    const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
125
0
    SmallVectorImpl<Decl *> &Result) {
126
0
  for(size_t i = 0; i < Sources.size(); ++i)
127
0
    Sources[i]->FindExternalLexicalDecls(DC, IsKindWeWant, Result);
128
0
}
129
130
void MultiplexExternalSemaSource::FindFileRegionDecls(FileID File,
131
                                                      unsigned Offset,
132
                                                      unsigned Length,
133
0
                                                SmallVectorImpl<Decl *> &Decls){
134
0
  for(size_t i = 0; i < Sources.size(); ++i)
135
0
    Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls);
136
0
}
137
138
0
void MultiplexExternalSemaSource::CompleteType(TagDecl *Tag) {
139
0
  for(size_t i = 0; i < Sources.size(); ++i)
140
0
    Sources[i]->CompleteType(Tag);
141
0
}
142
143
0
void MultiplexExternalSemaSource::CompleteType(ObjCInterfaceDecl *Class) {
144
0
  for(size_t i = 0; i < Sources.size(); ++i)
145
0
    Sources[i]->CompleteType(Class);
146
0
}
147
148
0
void MultiplexExternalSemaSource::ReadComments() {
149
0
  for(size_t i = 0; i < Sources.size(); ++i)
150
0
    Sources[i]->ReadComments();
151
0
}
152
153
0
void MultiplexExternalSemaSource::StartedDeserializing() {
154
0
  for(size_t i = 0; i < Sources.size(); ++i)
155
0
    Sources[i]->StartedDeserializing();
156
0
}
157
158
0
void MultiplexExternalSemaSource::FinishedDeserializing() {
159
0
  for(size_t i = 0; i < Sources.size(); ++i)
160
0
    Sources[i]->FinishedDeserializing();
161
0
}
162
163
0
void MultiplexExternalSemaSource::StartTranslationUnit(ASTConsumer *Consumer) {
164
0
  for(size_t i = 0; i < Sources.size(); ++i)
165
0
    Sources[i]->StartTranslationUnit(Consumer);
166
0
}
167
168
0
void MultiplexExternalSemaSource::PrintStats() {
169
0
  for(size_t i = 0; i < Sources.size(); ++i)
170
0
    Sources[i]->PrintStats();
171
0
}
172
173
0
Module *MultiplexExternalSemaSource::getModule(unsigned ID) {
174
0
  for (size_t i = 0; i < Sources.size(); ++i)
175
0
    if (auto M = Sources[i]->getModule(ID))
176
0
      return M;
177
0
  return nullptr;
178
0
}
179
180
bool MultiplexExternalSemaSource::layoutRecordType(const RecordDecl *Record,
181
                                                   uint64_t &Size,
182
                                                   uint64_t &Alignment,
183
                      llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
184
                  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
185
0
          llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){
186
0
  for(size_t i = 0; i < Sources.size(); ++i)
187
0
    if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets,
188
0
                                     BaseOffsets, VirtualBaseOffsets))
189
0
      return true;
190
0
  return false;
191
0
}
192
193
void MultiplexExternalSemaSource::
194
0
getMemoryBufferSizes(MemoryBufferSizes &sizes) const {
195
0
  for(size_t i = 0; i < Sources.size(); ++i)
196
0
    Sources[i]->getMemoryBufferSizes(sizes);
197
198
0
}
199
200
//===----------------------------------------------------------------------===//
201
// ExternalSemaSource.
202
//===----------------------------------------------------------------------===//
203
204
205
0
void MultiplexExternalSemaSource::InitializeSema(Sema &S) {
206
0
  for(size_t i = 0; i < Sources.size(); ++i)
207
0
    Sources[i]->InitializeSema(S);
208
0
}
209
210
0
void MultiplexExternalSemaSource::ForgetSema() {
211
0
  for(size_t i = 0; i < Sources.size(); ++i)
212
0
    Sources[i]->ForgetSema();
213
0
}
214
215
0
void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) {
216
0
  for(size_t i = 0; i < Sources.size(); ++i)
217
0
    Sources[i]->ReadMethodPool(Sel);
218
0
}
219
220
0
void MultiplexExternalSemaSource::updateOutOfDateSelector(Selector Sel) {
221
0
  for(size_t i = 0; i < Sources.size(); ++i)
222
0
    Sources[i]->updateOutOfDateSelector(Sel);
223
0
}
224
225
void MultiplexExternalSemaSource::ReadKnownNamespaces(
226
0
                                   SmallVectorImpl<NamespaceDecl*> &Namespaces){
227
0
  for(size_t i = 0; i < Sources.size(); ++i)
228
0
    Sources[i]->ReadKnownNamespaces(Namespaces);
229
0
}
230
231
void MultiplexExternalSemaSource::ReadUndefinedButUsed(
232
0
    llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {
233
0
  for(size_t i = 0; i < Sources.size(); ++i)
234
0
    Sources[i]->ReadUndefinedButUsed(Undefined);
235
0
}
236
237
void MultiplexExternalSemaSource::ReadMismatchingDeleteExpressions(
238
    llvm::MapVector<FieldDecl *,
239
                    llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
240
0
        Exprs) {
241
0
  for (auto &Source : Sources)
242
0
    Source->ReadMismatchingDeleteExpressions(Exprs);
243
0
}
244
245
0
bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){
246
0
  for(size_t i = 0; i < Sources.size(); ++i)
247
0
    Sources[i]->LookupUnqualified(R, S);
248
249
0
  return !R.empty();
250
0
}
251
252
void MultiplexExternalSemaSource::ReadTentativeDefinitions(
253
0
                                     SmallVectorImpl<VarDecl*> &TentativeDefs) {
254
0
  for(size_t i = 0; i < Sources.size(); ++i)
255
0
    Sources[i]->ReadTentativeDefinitions(TentativeDefs);
256
0
}
257
258
void MultiplexExternalSemaSource::ReadUnusedFileScopedDecls(
259
0
                                SmallVectorImpl<const DeclaratorDecl*> &Decls) {
260
0
  for(size_t i = 0; i < Sources.size(); ++i)
261
0
    Sources[i]->ReadUnusedFileScopedDecls(Decls);
262
0
}
263
264
void MultiplexExternalSemaSource::ReadDelegatingConstructors(
265
0
                                  SmallVectorImpl<CXXConstructorDecl*> &Decls) {
266
0
  for(size_t i = 0; i < Sources.size(); ++i)
267
0
    Sources[i]->ReadDelegatingConstructors(Decls);
268
0
}
269
270
void MultiplexExternalSemaSource::ReadExtVectorDecls(
271
0
                                     SmallVectorImpl<TypedefNameDecl*> &Decls) {
272
0
  for(size_t i = 0; i < Sources.size(); ++i)
273
0
    Sources[i]->ReadExtVectorDecls(Decls);
274
0
}
275
276
void MultiplexExternalSemaSource::ReadDeclsToCheckForDeferredDiags(
277
0
    llvm::SmallSetVector<Decl *, 4> &Decls) {
278
0
  for(size_t i = 0; i < Sources.size(); ++i)
279
0
    Sources[i]->ReadDeclsToCheckForDeferredDiags(Decls);
280
0
}
281
282
void MultiplexExternalSemaSource::ReadUnusedLocalTypedefNameCandidates(
283
0
    llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {
284
0
  for(size_t i = 0; i < Sources.size(); ++i)
285
0
    Sources[i]->ReadUnusedLocalTypedefNameCandidates(Decls);
286
0
}
287
288
void MultiplexExternalSemaSource::ReadReferencedSelectors(
289
0
                  SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {
290
0
  for(size_t i = 0; i < Sources.size(); ++i)
291
0
    Sources[i]->ReadReferencedSelectors(Sels);
292
0
}
293
294
void MultiplexExternalSemaSource::ReadWeakUndeclaredIdentifiers(
295
0
                   SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) {
296
0
  for(size_t i = 0; i < Sources.size(); ++i)
297
0
    Sources[i]->ReadWeakUndeclaredIdentifiers(WI);
298
0
}
299
300
void MultiplexExternalSemaSource::ReadUsedVTables(
301
0
                                  SmallVectorImpl<ExternalVTableUse> &VTables) {
302
0
  for(size_t i = 0; i < Sources.size(); ++i)
303
0
    Sources[i]->ReadUsedVTables(VTables);
304
0
}
305
306
void MultiplexExternalSemaSource::ReadPendingInstantiations(
307
                                           SmallVectorImpl<std::pair<ValueDecl*,
308
0
                                                   SourceLocation> > &Pending) {
309
0
  for(size_t i = 0; i < Sources.size(); ++i)
310
0
    Sources[i]->ReadPendingInstantiations(Pending);
311
0
}
312
313
void MultiplexExternalSemaSource::ReadLateParsedTemplates(
314
    llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
315
0
        &LPTMap) {
316
0
  for (size_t i = 0; i < Sources.size(); ++i)
317
0
    Sources[i]->ReadLateParsedTemplates(LPTMap);
318
0
}
319
320
TypoCorrection MultiplexExternalSemaSource::CorrectTypo(
321
                                     const DeclarationNameInfo &Typo,
322
                                     int LookupKind, Scope *S, CXXScopeSpec *SS,
323
                                     CorrectionCandidateCallback &CCC,
324
                                     DeclContext *MemberContext,
325
                                     bool EnteringContext,
326
0
                                     const ObjCObjectPointerType *OPT) {
327
0
  for (size_t I = 0, E = Sources.size(); I < E; ++I) {
328
0
    if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC,
329
0
                                                   MemberContext,
330
0
                                                   EnteringContext, OPT))
331
0
      return C;
332
0
  }
333
0
  return TypoCorrection();
334
0
}
335
336
bool MultiplexExternalSemaSource::MaybeDiagnoseMissingCompleteType(
337
0
    SourceLocation Loc, QualType T) {
338
0
  for (size_t I = 0, E = Sources.size(); I < E; ++I) {
339
0
    if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T))
340
0
      return true;
341
0
  }
342
0
  return false;
343
0
}
344
345
void MultiplexExternalSemaSource::AssignedLambdaNumbering(
346
0
    const CXXRecordDecl *Lambda) {
347
0
  for (auto *Source : Sources)
348
0
    Source->AssignedLambdaNumbering(Lambda);
349
0
}