Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Frontend/MultiplexConsumer.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- MultiplexConsumer.cpp - AST Consumer for PCH Generation --*- 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 defines the MultiplexConsumer class. It also declares and defines
10
//  MultiplexASTDeserializationListener and  MultiplexASTMutationListener, which
11
//  are implementation details of MultiplexConsumer.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#include "clang/Frontend/MultiplexConsumer.h"
16
#include "clang/AST/ASTMutationListener.h"
17
#include "clang/AST/DeclGroup.h"
18
19
using namespace clang;
20
21
namespace clang {
22
23
MultiplexASTDeserializationListener::MultiplexASTDeserializationListener(
24
      const std::vector<ASTDeserializationListener*>& L)
25
5.49k
    : Listeners(L) {
26
5.49k
}
27
28
void MultiplexASTDeserializationListener::ReaderInitialized(
29
3.90k
    ASTReader *Reader) {
30
7.81k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.90k
)
31
3.90k
    Listeners[i]->ReaderInitialized(Reader);
32
3.90k
}
33
34
void MultiplexASTDeserializationListener::IdentifierRead(
35
1.97M
    serialization::IdentID ID, IdentifierInfo *II) {
36
3.95M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.97M
)
37
1.97M
    Listeners[i]->IdentifierRead(ID, II);
38
1.97M
}
39
40
void MultiplexASTDeserializationListener::MacroRead(
41
16.2k
    serialization::MacroID ID, MacroInfo *MI) {
42
16.2k
  for (auto &Listener : Listeners)
43
16.2k
    Listener->MacroRead(ID, MI);
44
16.2k
}
45
46
void MultiplexASTDeserializationListener::TypeRead(
47
93.1k
    serialization::TypeIdx Idx, QualType T) {
48
186k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i93.1k
)
49
93.1k
    Listeners[i]->TypeRead(Idx, T);
50
93.1k
}
51
52
void MultiplexASTDeserializationListener::DeclRead(
53
405k
    serialization::DeclID ID, const Decl *D) {
54
810k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i405k
)
55
405k
    Listeners[i]->DeclRead(ID, D);
56
405k
}
57
58
void MultiplexASTDeserializationListener::SelectorRead(
59
3.74k
    serialization::SelectorID ID, Selector Sel) {
60
7.49k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.74k
)
61
3.74k
    Listeners[i]->SelectorRead(ID, Sel);
62
3.74k
}
63
64
void MultiplexASTDeserializationListener::MacroDefinitionRead(
65
16
    serialization::PreprocessedEntityID ID, MacroDefinitionRecord *MD) {
66
32
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i16
)
67
16
    Listeners[i]->MacroDefinitionRead(ID, MD);
68
16
}
69
70
void MultiplexASTDeserializationListener::ModuleRead(
71
135k
    serialization::SubmoduleID ID, Module *Mod) {
72
135k
  for (auto &Listener : Listeners)
73
135k
    Listener->ModuleRead(ID, Mod);
74
135k
}
75
76
void MultiplexASTDeserializationListener::ModuleImportRead(
77
2
    serialization::SubmoduleID ID, SourceLocation ImportLoc) {
78
2
  for (auto &Listener : Listeners)
79
2
    Listener->ModuleImportRead(ID, ImportLoc);
80
2
}
81
82
// This ASTMutationListener forwards its notifications to a set of
83
// child listeners.
84
class MultiplexASTMutationListener : public ASTMutationListener {
85
public:
86
  // Does NOT take ownership of the elements in L.
87
  MultiplexASTMutationListener(ArrayRef<ASTMutationListener*> L);
88
  void CompletedTagDefinition(const TagDecl *D) override;
89
  void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override;
90
  void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override;
91
  void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
92
                            const ClassTemplateSpecializationDecl *D) override;
93
  void AddedCXXTemplateSpecialization(const VarTemplateDecl *TD,
94
                               const VarTemplateSpecializationDecl *D) override;
95
  void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
96
                                      const FunctionDecl *D) override;
97
  void ResolvedExceptionSpec(const FunctionDecl *FD) override;
98
  void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override;
99
  void ResolvedOperatorDelete(const CXXDestructorDecl *DD,
100
                              const FunctionDecl *Delete,
101
                              Expr *ThisArg) override;
102
  void CompletedImplicitDefinition(const FunctionDecl *D) override;
103
  void InstantiationRequested(const ValueDecl *D) override;
104
  void VariableDefinitionInstantiated(const VarDecl *D) override;
105
  void FunctionDefinitionInstantiated(const FunctionDecl *D) override;
106
  void DefaultArgumentInstantiated(const ParmVarDecl *D) override;
107
  void DefaultMemberInitializerInstantiated(const FieldDecl *D) override;
108
  void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
109
                                    const ObjCInterfaceDecl *IFD) override;
110
  void DeclarationMarkedUsed(const Decl *D) override;
111
  void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
112
  void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) override;
113
  void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
114
                                            const Attr *Attr) override;
115
  void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
116
  void AddedAttributeToRecord(const Attr *Attr,
117
                              const RecordDecl *Record) override;
118
119
private:
120
  std::vector<ASTMutationListener*> Listeners;
121
};
122
123
MultiplexASTMutationListener::MultiplexASTMutationListener(
124
    ArrayRef<ASTMutationListener*> L)
125
5.49k
    : Listeners(L.begin(), L.end()) {
126
5.49k
}
127
128
169k
void MultiplexASTMutationListener::CompletedTagDefinition(const TagDecl *D) {
129
338k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i169k
)
130
169k
    Listeners[i]->CompletedTagDefinition(D);
131
169k
}
132
133
void MultiplexASTMutationListener::AddedVisibleDecl(
134
932k
    const DeclContext *DC, const Decl *D) {
135
1.86M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i932k
)
136
932k
    Listeners[i]->AddedVisibleDecl(DC, D);
137
932k
}
138
139
void MultiplexASTMutationListener::AddedCXXImplicitMember(
140
19.3k
    const CXXRecordDecl *RD, const Decl *D) {
141
38.7k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i19.3k
)
142
19.3k
    Listeners[i]->AddedCXXImplicitMember(RD, D);
143
19.3k
}
144
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
145
54.9k
    const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) {
146
109k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i54.9k
)
147
54.9k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
148
54.9k
}
149
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
150
603
    const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) {
151
1.20k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i603
)
152
603
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
153
603
}
154
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
155
13.8k
    const FunctionTemplateDecl *TD, const FunctionDecl *D) {
156
27.6k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i13.8k
)
157
13.8k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
158
13.8k
}
159
void MultiplexASTMutationListener::ResolvedExceptionSpec(
160
38.0k
    const FunctionDecl *FD) {
161
38.0k
  for (auto &Listener : Listeners)
162
38.0k
    Listener->ResolvedExceptionSpec(FD);
163
38.0k
}
164
void MultiplexASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
165
121
                                                     QualType ReturnType) {
166
242
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i121
)
167
121
    Listeners[i]->DeducedReturnType(FD, ReturnType);
168
121
}
169
void MultiplexASTMutationListener::ResolvedOperatorDelete(
170
58
    const CXXDestructorDecl *DD, const FunctionDecl *Delete, Expr *ThisArg) {
171
58
  for (auto *L : Listeners)
172
58
    L->ResolvedOperatorDelete(DD, Delete, ThisArg);
173
58
}
174
void MultiplexASTMutationListener::CompletedImplicitDefinition(
175
4.41k
                                                        const FunctionDecl *D) {
176
8.83k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i4.41k
)
177
4.41k
    Listeners[i]->CompletedImplicitDefinition(D);
178
4.41k
}
179
12.4k
void MultiplexASTMutationListener::InstantiationRequested(const ValueDecl *D) {
180
24.8k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i12.4k
)
181
12.4k
    Listeners[i]->InstantiationRequested(D);
182
12.4k
}
183
void MultiplexASTMutationListener::VariableDefinitionInstantiated(
184
12.2k
    const VarDecl *D) {
185
24.5k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i12.2k
)
186
12.2k
    Listeners[i]->VariableDefinitionInstantiated(D);
187
12.2k
}
188
void MultiplexASTMutationListener::FunctionDefinitionInstantiated(
189
9.36k
    const FunctionDecl *D) {
190
9.36k
  for (auto &Listener : Listeners)
191
9.36k
    Listener->FunctionDefinitionInstantiated(D);
192
9.36k
}
193
void MultiplexASTMutationListener::DefaultArgumentInstantiated(
194
496
                                                         const ParmVarDecl *D) {
195
992
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i496
)
196
496
    Listeners[i]->DefaultArgumentInstantiated(D);
197
496
}
198
void MultiplexASTMutationListener::DefaultMemberInitializerInstantiated(
199
70
                                                           const FieldDecl *D) {
200
140
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i70
)
201
70
    Listeners[i]->DefaultMemberInitializerInstantiated(D);
202
70
}
203
void MultiplexASTMutationListener::AddedObjCCategoryToInterface(
204
                                                 const ObjCCategoryDecl *CatD,
205
1.58k
                                                 const ObjCInterfaceDecl *IFD) {
206
3.17k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.58k
)
207
1.58k
    Listeners[i]->AddedObjCCategoryToInterface(CatD, IFD);
208
1.58k
}
209
327k
void MultiplexASTMutationListener::DeclarationMarkedUsed(const Decl *D) {
210
655k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i327k
)
211
327k
    Listeners[i]->DeclarationMarkedUsed(D);
212
327k
}
213
void MultiplexASTMutationListener::DeclarationMarkedOpenMPThreadPrivate(
214
215
    const Decl *D) {
215
430
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i215
)
216
215
    Listeners[i]->DeclarationMarkedOpenMPThreadPrivate(D);
217
215
}
218
void MultiplexASTMutationListener::DeclarationMarkedOpenMPAllocate(
219
265
    const Decl *D, const Attr *A) {
220
265
  for (ASTMutationListener *L : Listeners)
221
265
    L->DeclarationMarkedOpenMPAllocate(D, A);
222
265
}
223
void MultiplexASTMutationListener::DeclarationMarkedOpenMPDeclareTarget(
224
1.19k
    const Decl *D, const Attr *Attr) {
225
1.19k
  for (auto *L : Listeners)
226
1.19k
    L->DeclarationMarkedOpenMPDeclareTarget(D, Attr);
227
1.19k
}
228
void MultiplexASTMutationListener::RedefinedHiddenDefinition(const NamedDecl *D,
229
2.59k
                                                             Module *M) {
230
2.59k
  for (auto *L : Listeners)
231
2.59k
    L->RedefinedHiddenDefinition(D, M);
232
2.59k
}
233
234
void MultiplexASTMutationListener::AddedAttributeToRecord(
235
                                                    const Attr *Attr,
236
28
                                                    const RecordDecl *Record) {
237
28
  for (auto *L : Listeners)
238
28
    L->AddedAttributeToRecord(Attr, Record);
239
28
}
240
241
}  // end namespace clang
242
243
MultiplexConsumer::MultiplexConsumer(
244
    std::vector<std::unique_ptr<ASTConsumer>> C)
245
5.77k
    : Consumers(std::move(C)) {
246
  // Collect the mutation listeners and deserialization listeners of all
247
  // children, and create a multiplex listener each if so.
248
5.77k
  std::vector<ASTMutationListener *> mutationListeners;
249
5.77k
  std::vector<ASTDeserializationListener*> serializationListeners;
250
11.4k
  for (auto &Consumer : Consumers) {
251
11.4k
    if (auto *mutationListener = Consumer->GetASTMutationListener())
252
5.49k
      mutationListeners.push_back(mutationListener);
253
11.4k
    if (auto *serializationListener = Consumer->GetASTDeserializationListener())
254
5.48k
      serializationListeners.push_back(serializationListener);
255
11.4k
  }
256
5.77k
  if (!mutationListeners.empty()) {
257
5.49k
    MutationListener =
258
5.49k
        std::make_unique<MultiplexASTMutationListener>(mutationListeners);
259
5.49k
  }
260
5.77k
  if (!serializationListeners.empty()) {
261
5.48k
    DeserializationListener =
262
5.48k
        std::make_unique<MultiplexASTDeserializationListener>(
263
5.48k
            serializationListeners);
264
5.48k
  }
265
5.77k
}
266
267
5.77k
MultiplexConsumer::~MultiplexConsumer() {}
268
269
5.77k
void MultiplexConsumer::Initialize(ASTContext &Context) {
270
5.77k
  for (auto &Consumer : Consumers)
271
11.4k
    Consumer->Initialize(Context);
272
5.77k
}
273
274
278k
bool MultiplexConsumer::HandleTopLevelDecl(DeclGroupRef D) {
275
278k
  bool Continue = true;
276
278k
  for (auto &Consumer : Consumers)
277
556k
    Continue = Continue && Consumer->HandleTopLevelDecl(D);
278
278k
  return Continue;
279
278k
}
280
281
47.5k
void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
282
47.5k
  for (auto &Consumer : Consumers)
283
95.0k
    Consumer->HandleInlineFunctionDefinition(D);
284
47.5k
}
285
286
41.7k
void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
287
41.7k
  for (auto &Consumer : Consumers)
288
83.4k
    Consumer->HandleCXXStaticMemberVarInstantiation(VD);
289
41.7k
}
290
291
7.82k
void MultiplexConsumer::HandleInterestingDecl(DeclGroupRef D) {
292
7.82k
  for (auto &Consumer : Consumers)
293
15.6k
    Consumer->HandleInterestingDecl(D);
294
7.82k
}
295
296
5.76k
void MultiplexConsumer::HandleTranslationUnit(ASTContext &Ctx) {
297
5.76k
  for (auto &Consumer : Consumers)
298
11.4k
    Consumer->HandleTranslationUnit(Ctx);
299
5.76k
}
300
301
126k
void MultiplexConsumer::HandleTagDeclDefinition(TagDecl *D) {
302
126k
  for (auto &Consumer : Consumers)
303
252k
    Consumer->HandleTagDeclDefinition(D);
304
126k
}
305
306
68.9k
void MultiplexConsumer::HandleTagDeclRequiredDefinition(const TagDecl *D) {
307
68.9k
  for (auto &Consumer : Consumers)
308
137k
    Consumer->HandleTagDeclRequiredDefinition(D);
309
68.9k
}
310
311
9.10k
void MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D){
312
9.10k
  for (auto &Consumer : Consumers)
313
18.1k
    Consumer->HandleCXXImplicitFunctionInstantiation(D);
314
9.10k
}
315
316
1.27k
void MultiplexConsumer::HandleTopLevelDeclInObjCContainer(DeclGroupRef D) {
317
1.27k
  for (auto &Consumer : Consumers)
318
2.54k
    Consumer->HandleTopLevelDeclInObjCContainer(D);
319
1.27k
}
320
321
135k
void MultiplexConsumer::HandleImplicitImportDecl(ImportDecl *D) {
322
135k
  for (auto &Consumer : Consumers)
323
271k
    Consumer->HandleImplicitImportDecl(D);
324
135k
}
325
326
566
void MultiplexConsumer::CompleteTentativeDefinition(VarDecl *D) {
327
566
  for (auto &Consumer : Consumers)
328
1.13k
    Consumer->CompleteTentativeDefinition(D);
329
566
}
330
331
0
void MultiplexConsumer::CompleteExternalDeclaration(VarDecl *D) {
332
0
  for (auto &Consumer : Consumers)
333
0
    Consumer->CompleteExternalDeclaration(D);
334
0
}
335
336
3
void MultiplexConsumer::AssignInheritanceModel(CXXRecordDecl *RD) {
337
3
  for (auto &Consumer : Consumers)
338
6
    Consumer->AssignInheritanceModel(RD);
339
3
}
340
341
3
void MultiplexConsumer::HandleVTable(CXXRecordDecl *RD) {
342
3
  for (auto &Consumer : Consumers)
343
6
    Consumer->HandleVTable(RD);
344
3
}
345
346
58.0k
ASTMutationListener *MultiplexConsumer::GetASTMutationListener() {
347
58.0k
  return MutationListener.get();
348
58.0k
}
349
350
2.35k
ASTDeserializationListener *MultiplexConsumer::GetASTDeserializationListener() {
351
2.35k
  return DeserializationListener.get();
352
2.35k
}
353
354
0
void MultiplexConsumer::PrintStats() {
355
0
  for (auto &Consumer : Consumers)
356
0
    Consumer->PrintStats();
357
0
}
358
359
32
bool MultiplexConsumer::shouldSkipFunctionBody(Decl *D) {
360
32
  bool Skip = true;
361
32
  for (auto &Consumer : Consumers)
362
64
    Skip = Skip && Consumer->shouldSkipFunctionBody(D);
363
32
  return Skip;
364
32
}
365
366
5.76k
void MultiplexConsumer::InitializeSema(Sema &S) {
367
5.76k
  for (auto &Consumer : Consumers)
368
11.4k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
369
5.48k
      SC->InitializeSema(S);
370
5.76k
}
371
372
5.70k
void MultiplexConsumer::ForgetSema() {
373
5.70k
  for (auto &Consumer : Consumers)
374
11.3k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
375
5.42k
      SC->ForgetSema();
376
5.70k
}