Coverage Report

Created: 2022-01-22 13:19

/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.23k
    : Listeners(L) {
26
5.23k
}
27
28
void MultiplexASTDeserializationListener::ReaderInitialized(
29
3.54k
    ASTReader *Reader) {
30
7.09k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.54k
)
31
3.54k
    Listeners[i]->ReaderInitialized(Reader);
32
3.54k
}
33
34
void MultiplexASTDeserializationListener::IdentifierRead(
35
1.91M
    serialization::IdentID ID, IdentifierInfo *II) {
36
3.83M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.91M
)
37
1.91M
    Listeners[i]->IdentifierRead(ID, II);
38
1.91M
}
39
40
void MultiplexASTDeserializationListener::MacroRead(
41
13.3k
    serialization::MacroID ID, MacroInfo *MI) {
42
13.3k
  for (auto &Listener : Listeners)
43
13.3k
    Listener->MacroRead(ID, MI);
44
13.3k
}
45
46
void MultiplexASTDeserializationListener::TypeRead(
47
72.6k
    serialization::TypeIdx Idx, QualType T) {
48
145k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i72.6k
)
49
72.6k
    Listeners[i]->TypeRead(Idx, T);
50
72.6k
}
51
52
void MultiplexASTDeserializationListener::DeclRead(
53
269k
    serialization::DeclID ID, const Decl *D) {
54
538k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i269k
)
55
269k
    Listeners[i]->DeclRead(ID, D);
56
269k
}
57
58
void MultiplexASTDeserializationListener::SelectorRead(
59
3.67k
    serialization::SelectorID ID, Selector Sel) {
60
7.35k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.67k
)
61
3.67k
    Listeners[i]->SelectorRead(ID, Sel);
62
3.67k
}
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
120k
    serialization::SubmoduleID ID, Module *Mod) {
72
120k
  for (auto &Listener : Listeners)
73
120k
    Listener->ModuleRead(ID, Mod);
74
120k
}
75
76
// This ASTMutationListener forwards its notifications to a set of
77
// child listeners.
78
class MultiplexASTMutationListener : public ASTMutationListener {
79
public:
80
  // Does NOT take ownership of the elements in L.
81
  MultiplexASTMutationListener(ArrayRef<ASTMutationListener*> L);
82
  void CompletedTagDefinition(const TagDecl *D) override;
83
  void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override;
84
  void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override;
85
  void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
86
                            const ClassTemplateSpecializationDecl *D) override;
87
  void AddedCXXTemplateSpecialization(const VarTemplateDecl *TD,
88
                               const VarTemplateSpecializationDecl *D) override;
89
  void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
90
                                      const FunctionDecl *D) override;
91
  void ResolvedExceptionSpec(const FunctionDecl *FD) override;
92
  void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override;
93
  void ResolvedOperatorDelete(const CXXDestructorDecl *DD,
94
                              const FunctionDecl *Delete,
95
                              Expr *ThisArg) override;
96
  void CompletedImplicitDefinition(const FunctionDecl *D) override;
97
  void InstantiationRequested(const ValueDecl *D) override;
98
  void VariableDefinitionInstantiated(const VarDecl *D) override;
99
  void FunctionDefinitionInstantiated(const FunctionDecl *D) override;
100
  void DefaultArgumentInstantiated(const ParmVarDecl *D) override;
101
  void DefaultMemberInitializerInstantiated(const FieldDecl *D) override;
102
  void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
103
                                    const ObjCInterfaceDecl *IFD) override;
104
  void DeclarationMarkedUsed(const Decl *D) override;
105
  void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
106
  void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) override;
107
  void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
108
                                            const Attr *Attr) override;
109
  void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
110
  void AddedAttributeToRecord(const Attr *Attr,
111
                              const RecordDecl *Record) override;
112
113
private:
114
  std::vector<ASTMutationListener*> Listeners;
115
};
116
117
MultiplexASTMutationListener::MultiplexASTMutationListener(
118
    ArrayRef<ASTMutationListener*> L)
119
5.23k
    : Listeners(L.begin(), L.end()) {
120
5.23k
}
121
122
147k
void MultiplexASTMutationListener::CompletedTagDefinition(const TagDecl *D) {
123
295k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i147k
)
124
147k
    Listeners[i]->CompletedTagDefinition(D);
125
147k
}
126
127
void MultiplexASTMutationListener::AddedVisibleDecl(
128
835k
    const DeclContext *DC, const Decl *D) {
129
1.67M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i835k
)
130
835k
    Listeners[i]->AddedVisibleDecl(DC, D);
131
835k
}
132
133
void MultiplexASTMutationListener::AddedCXXImplicitMember(
134
16.6k
    const CXXRecordDecl *RD, const Decl *D) {
135
33.3k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i16.6k
)
136
16.6k
    Listeners[i]->AddedCXXImplicitMember(RD, D);
137
16.6k
}
138
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
139
42.3k
    const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) {
140
84.7k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i42.3k
)
141
42.3k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
142
42.3k
}
143
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
144
145
    const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) {
145
290
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i145
)
146
145
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
147
145
}
148
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
149
9.49k
    const FunctionTemplateDecl *TD, const FunctionDecl *D) {
150
18.9k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i9.49k
)
151
9.49k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
152
9.49k
}
153
void MultiplexASTMutationListener::ResolvedExceptionSpec(
154
32.0k
    const FunctionDecl *FD) {
155
32.0k
  for (auto &Listener : Listeners)
156
32.0k
    Listener->ResolvedExceptionSpec(FD);
157
32.0k
}
158
void MultiplexASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
159
62
                                                     QualType ReturnType) {
160
124
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i62
)
161
62
    Listeners[i]->DeducedReturnType(FD, ReturnType);
162
62
}
163
void MultiplexASTMutationListener::ResolvedOperatorDelete(
164
51
    const CXXDestructorDecl *DD, const FunctionDecl *Delete, Expr *ThisArg) {
165
51
  for (auto *L : Listeners)
166
51
    L->ResolvedOperatorDelete(DD, Delete, ThisArg);
167
51
}
168
void MultiplexASTMutationListener::CompletedImplicitDefinition(
169
3.94k
                                                        const FunctionDecl *D) {
170
7.88k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.94k
)
171
3.94k
    Listeners[i]->CompletedImplicitDefinition(D);
172
3.94k
}
173
9.36k
void MultiplexASTMutationListener::InstantiationRequested(const ValueDecl *D) {
174
18.7k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i9.36k
)
175
9.36k
    Listeners[i]->InstantiationRequested(D);
176
9.36k
}
177
void MultiplexASTMutationListener::VariableDefinitionInstantiated(
178
9.93k
    const VarDecl *D) {
179
19.8k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i9.93k
)
180
9.93k
    Listeners[i]->VariableDefinitionInstantiated(D);
181
9.93k
}
182
void MultiplexASTMutationListener::FunctionDefinitionInstantiated(
183
6.93k
    const FunctionDecl *D) {
184
6.93k
  for (auto &Listener : Listeners)
185
6.93k
    Listener->FunctionDefinitionInstantiated(D);
186
6.93k
}
187
void MultiplexASTMutationListener::DefaultArgumentInstantiated(
188
427
                                                         const ParmVarDecl *D) {
189
854
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i427
)
190
427
    Listeners[i]->DefaultArgumentInstantiated(D);
191
427
}
192
void MultiplexASTMutationListener::DefaultMemberInitializerInstantiated(
193
2
                                                           const FieldDecl *D) {
194
4
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i2
)
195
2
    Listeners[i]->DefaultMemberInitializerInstantiated(D);
196
2
}
197
void MultiplexASTMutationListener::AddedObjCCategoryToInterface(
198
                                                 const ObjCCategoryDecl *CatD,
199
1.40k
                                                 const ObjCInterfaceDecl *IFD) {
200
2.80k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.40k
)
201
1.40k
    Listeners[i]->AddedObjCCategoryToInterface(CatD, IFD);
202
1.40k
}
203
301k
void MultiplexASTMutationListener::DeclarationMarkedUsed(const Decl *D) {
204
602k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i301k
)
205
301k
    Listeners[i]->DeclarationMarkedUsed(D);
206
301k
}
207
void MultiplexASTMutationListener::DeclarationMarkedOpenMPThreadPrivate(
208
209
    const Decl *D) {
209
418
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i209
)
210
209
    Listeners[i]->DeclarationMarkedOpenMPThreadPrivate(D);
211
209
}
212
void MultiplexASTMutationListener::DeclarationMarkedOpenMPAllocate(
213
247
    const Decl *D, const Attr *A) {
214
247
  for (ASTMutationListener *L : Listeners)
215
247
    L->DeclarationMarkedOpenMPAllocate(D, A);
216
247
}
217
void MultiplexASTMutationListener::DeclarationMarkedOpenMPDeclareTarget(
218
1.19k
    const Decl *D, const Attr *Attr) {
219
1.19k
  for (auto *L : Listeners)
220
1.19k
    L->DeclarationMarkedOpenMPDeclareTarget(D, Attr);
221
1.19k
}
222
void MultiplexASTMutationListener::RedefinedHiddenDefinition(const NamedDecl *D,
223
2.57k
                                                             Module *M) {
224
2.57k
  for (auto *L : Listeners)
225
2.57k
    L->RedefinedHiddenDefinition(D, M);
226
2.57k
}
227
228
void MultiplexASTMutationListener::AddedAttributeToRecord(
229
                                                    const Attr *Attr,
230
24
                                                    const RecordDecl *Record) {
231
24
  for (auto *L : Listeners)
232
24
    L->AddedAttributeToRecord(Attr, Record);
233
24
}
234
235
}  // end namespace clang
236
237
MultiplexConsumer::MultiplexConsumer(
238
    std::vector<std::unique_ptr<ASTConsumer>> C)
239
5.51k
    : Consumers(std::move(C)) {
240
  // Collect the mutation listeners and deserialization listeners of all
241
  // children, and create a multiplex listener each if so.
242
5.51k
  std::vector<ASTMutationListener *> mutationListeners;
243
5.51k
  std::vector<ASTDeserializationListener*> serializationListeners;
244
10.9k
  for (auto &Consumer : Consumers) {
245
10.9k
    if (auto *mutationListener = Consumer->GetASTMutationListener())
246
5.23k
      mutationListeners.push_back(mutationListener);
247
10.9k
    if (auto *serializationListener = Consumer->GetASTDeserializationListener())
248
5.23k
      serializationListeners.push_back(serializationListener);
249
10.9k
  }
250
5.51k
  if (!mutationListeners.empty()) {
251
5.23k
    MutationListener =
252
5.23k
        std::make_unique<MultiplexASTMutationListener>(mutationListeners);
253
5.23k
  }
254
5.51k
  if (!serializationListeners.empty()) {
255
5.23k
    DeserializationListener =
256
5.23k
        std::make_unique<MultiplexASTDeserializationListener>(
257
5.23k
            serializationListeners);
258
5.23k
  }
259
5.51k
}
260
261
5.51k
MultiplexConsumer::~MultiplexConsumer() {}
262
263
5.51k
void MultiplexConsumer::Initialize(ASTContext &Context) {
264
5.51k
  for (auto &Consumer : Consumers)
265
10.9k
    Consumer->Initialize(Context);
266
5.51k
}
267
268
253k
bool MultiplexConsumer::HandleTopLevelDecl(DeclGroupRef D) {
269
253k
  bool Continue = true;
270
253k
  for (auto &Consumer : Consumers)
271
507k
    Continue = Continue && Consumer->HandleTopLevelDecl(D);
272
253k
  return Continue;
273
253k
}
274
275
42.2k
void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
276
42.2k
  for (auto &Consumer : Consumers)
277
84.4k
    Consumer->HandleInlineFunctionDefinition(D);
278
42.2k
}
279
280
29.5k
void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
281
29.5k
  for (auto &Consumer : Consumers)
282
59.0k
    Consumer->HandleCXXStaticMemberVarInstantiation(VD);
283
29.5k
}
284
285
3.90k
void MultiplexConsumer::HandleInterestingDecl(DeclGroupRef D) {
286
3.90k
  for (auto &Consumer : Consumers)
287
7.81k
    Consumer->HandleInterestingDecl(D);
288
3.90k
}
289
290
5.51k
void MultiplexConsumer::HandleTranslationUnit(ASTContext &Ctx) {
291
5.51k
  for (auto &Consumer : Consumers)
292
10.9k
    Consumer->HandleTranslationUnit(Ctx);
293
5.51k
}
294
295
106k
void MultiplexConsumer::HandleTagDeclDefinition(TagDecl *D) {
296
106k
  for (auto &Consumer : Consumers)
297
212k
    Consumer->HandleTagDeclDefinition(D);
298
106k
}
299
300
56.8k
void MultiplexConsumer::HandleTagDeclRequiredDefinition(const TagDecl *D) {
301
56.8k
  for (auto &Consumer : Consumers)
302
113k
    Consumer->HandleTagDeclRequiredDefinition(D);
303
56.8k
}
304
305
8.20k
void MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D){
306
8.20k
  for (auto &Consumer : Consumers)
307
16.4k
    Consumer->HandleCXXImplicitFunctionInstantiation(D);
308
8.20k
}
309
310
1.06k
void MultiplexConsumer::HandleTopLevelDeclInObjCContainer(DeclGroupRef D) {
311
1.06k
  for (auto &Consumer : Consumers)
312
2.13k
    Consumer->HandleTopLevelDeclInObjCContainer(D);
313
1.06k
}
314
315
97.9k
void MultiplexConsumer::HandleImplicitImportDecl(ImportDecl *D) {
316
97.9k
  for (auto &Consumer : Consumers)
317
195k
    Consumer->HandleImplicitImportDecl(D);
318
97.9k
}
319
320
562
void MultiplexConsumer::CompleteTentativeDefinition(VarDecl *D) {
321
562
  for (auto &Consumer : Consumers)
322
1.12k
    Consumer->CompleteTentativeDefinition(D);
323
562
}
324
325
0
void MultiplexConsumer::CompleteExternalDeclaration(VarDecl *D) {
326
0
  for (auto &Consumer : Consumers)
327
0
    Consumer->CompleteExternalDeclaration(D);
328
0
}
329
330
3
void MultiplexConsumer::AssignInheritanceModel(CXXRecordDecl *RD) {
331
3
  for (auto &Consumer : Consumers)
332
6
    Consumer->AssignInheritanceModel(RD);
333
3
}
334
335
3
void MultiplexConsumer::HandleVTable(CXXRecordDecl *RD) {
336
3
  for (auto &Consumer : Consumers)
337
6
    Consumer->HandleVTable(RD);
338
3
}
339
340
48.8k
ASTMutationListener *MultiplexConsumer::GetASTMutationListener() {
341
48.8k
  return MutationListener.get();
342
48.8k
}
343
344
2.14k
ASTDeserializationListener *MultiplexConsumer::GetASTDeserializationListener() {
345
2.14k
  return DeserializationListener.get();
346
2.14k
}
347
348
0
void MultiplexConsumer::PrintStats() {
349
0
  for (auto &Consumer : Consumers)
350
0
    Consumer->PrintStats();
351
0
}
352
353
32
bool MultiplexConsumer::shouldSkipFunctionBody(Decl *D) {
354
32
  bool Skip = true;
355
32
  for (auto &Consumer : Consumers)
356
64
    Skip = Skip && Consumer->shouldSkipFunctionBody(D);
357
32
  return Skip;
358
32
}
359
360
5.51k
void MultiplexConsumer::InitializeSema(Sema &S) {
361
5.51k
  for (auto &Consumer : Consumers)
362
10.9k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
363
5.23k
      SC->InitializeSema(S);
364
5.51k
}
365
366
5.48k
void MultiplexConsumer::ForgetSema() {
367
5.48k
  for (auto &Consumer : Consumers)
368
10.8k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
369
5.20k
      SC->ForgetSema();
370
5.48k
}