Coverage Report

Created: 2021-08-24 07:12

/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.11k
    : Listeners(L) {
26
5.11k
}
27
28
void MultiplexASTDeserializationListener::ReaderInitialized(
29
3.44k
    ASTReader *Reader) {
30
6.88k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.44k
)
31
3.44k
    Listeners[i]->ReaderInitialized(Reader);
32
3.44k
}
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.8k
    serialization::MacroID ID, MacroInfo *MI) {
42
13.8k
  for (auto &Listener : Listeners)
43
13.8k
    Listener->MacroRead(ID, MI);
44
13.8k
}
45
46
void MultiplexASTDeserializationListener::TypeRead(
47
73.1k
    serialization::TypeIdx Idx, QualType T) {
48
146k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i73.1k
)
49
73.1k
    Listeners[i]->TypeRead(Idx, T);
50
73.1k
}
51
52
void MultiplexASTDeserializationListener::DeclRead(
53
251k
    serialization::DeclID ID, const Decl *D) {
54
502k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i251k
)
55
251k
    Listeners[i]->DeclRead(ID, D);
56
251k
}
57
58
void MultiplexASTDeserializationListener::SelectorRead(
59
3.52k
    serialization::SelectorID ID, Selector Sel) {
60
7.04k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.52k
)
61
3.52k
    Listeners[i]->SelectorRead(ID, Sel);
62
3.52k
}
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
115k
    serialization::SubmoduleID ID, Module *Mod) {
72
115k
  for (auto &Listener : Listeners)
73
115k
    Listener->ModuleRead(ID, Mod);
74
115k
}
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.11k
    : Listeners(L.begin(), L.end()) {
120
5.11k
}
121
122
151k
void MultiplexASTMutationListener::CompletedTagDefinition(const TagDecl *D) {
123
303k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i151k
)
124
151k
    Listeners[i]->CompletedTagDefinition(D);
125
151k
}
126
127
void MultiplexASTMutationListener::AddedVisibleDecl(
128
842k
    const DeclContext *DC, const Decl *D) {
129
1.68M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i842k
)
130
842k
    Listeners[i]->AddedVisibleDecl(DC, D);
131
842k
}
132
133
void MultiplexASTMutationListener::AddedCXXImplicitMember(
134
17.4k
    const CXXRecordDecl *RD, const Decl *D) {
135
34.9k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i17.4k
)
136
17.4k
    Listeners[i]->AddedCXXImplicitMember(RD, D);
137
17.4k
}
138
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
139
45.8k
    const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) {
140
91.7k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i45.8k
)
141
45.8k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
142
45.8k
}
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
10.2k
    const FunctionTemplateDecl *TD, const FunctionDecl *D) {
150
20.4k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i10.2k
)
151
10.2k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
152
10.2k
}
153
void MultiplexASTMutationListener::ResolvedExceptionSpec(
154
34.7k
    const FunctionDecl *FD) {
155
34.7k
  for (auto &Listener : Listeners)
156
34.7k
    Listener->ResolvedExceptionSpec(FD);
157
34.7k
}
158
void MultiplexASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
159
61
                                                     QualType ReturnType) {
160
122
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i61
)
161
61
    Listeners[i]->DeducedReturnType(FD, ReturnType);
162
61
}
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
4.09k
                                                        const FunctionDecl *D) {
170
8.19k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i4.09k
)
171
4.09k
    Listeners[i]->CompletedImplicitDefinition(D);
172
4.09k
}
173
10.2k
void MultiplexASTMutationListener::InstantiationRequested(const ValueDecl *D) {
174
20.4k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i10.2k
)
175
10.2k
    Listeners[i]->InstantiationRequested(D);
176
10.2k
}
177
void MultiplexASTMutationListener::VariableDefinitionInstantiated(
178
11.1k
    const VarDecl *D) {
179
22.3k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i11.1k
)
180
11.1k
    Listeners[i]->VariableDefinitionInstantiated(D);
181
11.1k
}
182
void MultiplexASTMutationListener::FunctionDefinitionInstantiated(
183
7.65k
    const FunctionDecl *D) {
184
7.65k
  for (auto &Listener : Listeners)
185
7.65k
    Listener->FunctionDefinitionInstantiated(D);
186
7.65k
}
187
void MultiplexASTMutationListener::DefaultArgumentInstantiated(
188
483
                                                         const ParmVarDecl *D) {
189
966
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i483
)
190
483
    Listeners[i]->DefaultArgumentInstantiated(D);
191
483
}
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
304k
void MultiplexASTMutationListener::DeclarationMarkedUsed(const Decl *D) {
204
608k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i304k
)
205
304k
    Listeners[i]->DeclarationMarkedUsed(D);
206
304k
}
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
228
    const Decl *D, const Attr *A) {
214
228
  for (ASTMutationListener *L : Listeners)
215
228
    L->DeclarationMarkedOpenMPAllocate(D, A);
216
228
}
217
void MultiplexASTMutationListener::DeclarationMarkedOpenMPDeclareTarget(
218
1.13k
    const Decl *D, const Attr *Attr) {
219
1.13k
  for (auto *L : Listeners)
220
1.13k
    L->DeclarationMarkedOpenMPDeclareTarget(D, Attr);
221
1.13k
}
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.39k
    : Consumers(std::move(C)), MutationListener(), DeserializationListener() {
240
  // Collect the mutation listeners and deserialization listeners of all
241
  // children, and create a multiplex listener each if so.
242
5.39k
  std::vector<ASTMutationListener*> mutationListeners;
243
5.39k
  std::vector<ASTDeserializationListener*> serializationListeners;
244
10.6k
  for (auto &Consumer : Consumers) {
245
10.6k
    if (auto *mutationListener = Consumer->GetASTMutationListener())
246
5.11k
      mutationListeners.push_back(mutationListener);
247
10.6k
    if (auto *serializationListener = Consumer->GetASTDeserializationListener())
248
5.11k
      serializationListeners.push_back(serializationListener);
249
10.6k
  }
250
5.39k
  if (!mutationListeners.empty()) {
251
5.11k
    MutationListener =
252
5.11k
        std::make_unique<MultiplexASTMutationListener>(mutationListeners);
253
5.11k
  }
254
5.39k
  if (!serializationListeners.empty()) {
255
5.11k
    DeserializationListener =
256
5.11k
        std::make_unique<MultiplexASTDeserializationListener>(
257
5.11k
            serializationListeners);
258
5.11k
  }
259
5.39k
}
260
261
5.39k
MultiplexConsumer::~MultiplexConsumer() {}
262
263
5.39k
void MultiplexConsumer::Initialize(ASTContext &Context) {
264
5.39k
  for (auto &Consumer : Consumers)
265
10.6k
    Consumer->Initialize(Context);
266
5.39k
}
267
268
253k
bool MultiplexConsumer::HandleTopLevelDecl(DeclGroupRef D) {
269
253k
  bool Continue = true;
270
253k
  for (auto &Consumer : Consumers)
271
506k
    Continue = Continue && Consumer->HandleTopLevelDecl(D);
272
253k
  return Continue;
273
253k
}
274
275
45.3k
void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
276
45.3k
  for (auto &Consumer : Consumers)
277
90.7k
    Consumer->HandleInlineFunctionDefinition(D);
278
45.3k
}
279
280
31.7k
void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
281
31.7k
  for (auto &Consumer : Consumers)
282
63.5k
    Consumer->HandleCXXStaticMemberVarInstantiation(VD);
283
31.7k
}
284
285
3.93k
void MultiplexConsumer::HandleInterestingDecl(DeclGroupRef D) {
286
3.93k
  for (auto &Consumer : Consumers)
287
7.87k
    Consumer->HandleInterestingDecl(D);
288
3.93k
}
289
290
5.39k
void MultiplexConsumer::HandleTranslationUnit(ASTContext &Ctx) {
291
5.39k
  for (auto &Consumer : Consumers)
292
10.6k
    Consumer->HandleTranslationUnit(Ctx);
293
5.39k
}
294
295
110k
void MultiplexConsumer::HandleTagDeclDefinition(TagDecl *D) {
296
110k
  for (auto &Consumer : Consumers)
297
221k
    Consumer->HandleTagDeclDefinition(D);
298
110k
}
299
300
59.7k
void MultiplexConsumer::HandleTagDeclRequiredDefinition(const TagDecl *D) {
301
59.7k
  for (auto &Consumer : Consumers)
302
119k
    Consumer->HandleTagDeclRequiredDefinition(D);
303
59.7k
}
304
305
8.93k
void MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D){
306
8.93k
  for (auto &Consumer : Consumers)
307
17.8k
    Consumer->HandleCXXImplicitFunctionInstantiation(D);
308
8.93k
}
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
93.4k
void MultiplexConsumer::HandleImplicitImportDecl(ImportDecl *D) {
316
93.4k
  for (auto &Consumer : Consumers)
317
186k
    Consumer->HandleImplicitImportDecl(D);
318
93.4k
}
319
320
550
void MultiplexConsumer::CompleteTentativeDefinition(VarDecl *D) {
321
550
  for (auto &Consumer : Consumers)
322
1.10k
    Consumer->CompleteTentativeDefinition(D);
323
550
}
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
52.2k
ASTMutationListener *MultiplexConsumer::GetASTMutationListener() {
341
52.2k
  return MutationListener.get();
342
52.2k
}
343
344
2.05k
ASTDeserializationListener *MultiplexConsumer::GetASTDeserializationListener() {
345
2.05k
  return DeserializationListener.get();
346
2.05k
}
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.39k
void MultiplexConsumer::InitializeSema(Sema &S) {
361
5.39k
  for (auto &Consumer : Consumers)
362
10.6k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
363
5.11k
      SC->InitializeSema(S);
364
5.39k
}
365
366
5.36k
void MultiplexConsumer::ForgetSema() {
367
5.36k
  for (auto &Consumer : Consumers)
368
10.6k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
369
5.08k
      SC->ForgetSema();
370
5.36k
}