Coverage Report

Created: 2020-10-24 06:27

/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
4.93k
    : Listeners(L) {
26
4.93k
}
27
28
void MultiplexASTDeserializationListener::ReaderInitialized(
29
3.50k
    ASTReader *Reader) {
30
7.00k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.50k
)
31
3.50k
    Listeners[i]->ReaderInitialized(Reader);
32
3.50k
}
33
34
void MultiplexASTDeserializationListener::IdentifierRead(
35
1.94M
    serialization::IdentID ID, IdentifierInfo *II) {
36
3.88M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.94M
)
37
1.94M
    Listeners[i]->IdentifierRead(ID, II);
38
1.94M
}
39
40
void MultiplexASTDeserializationListener::MacroRead(
41
16.7k
    serialization::MacroID ID, MacroInfo *MI) {
42
16.7k
  for (auto &Listener : Listeners)
43
16.7k
    Listener->MacroRead(ID, MI);
44
16.7k
}
45
46
void MultiplexASTDeserializationListener::TypeRead(
47
86.2k
    serialization::TypeIdx Idx, QualType T) {
48
172k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i86.2k
)
49
86.2k
    Listeners[i]->TypeRead(Idx, T);
50
86.2k
}
51
52
void MultiplexASTDeserializationListener::DeclRead(
53
292k
    serialization::DeclID ID, const Decl *D) {
54
584k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i292k
)
55
292k
    Listeners[i]->DeclRead(ID, D);
56
292k
}
57
58
void MultiplexASTDeserializationListener::SelectorRead(
59
3.39k
    serialization::SelectorID ID, Selector Sel) {
60
6.78k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.39k
)
61
3.39k
    Listeners[i]->SelectorRead(ID, Sel);
62
3.39k
}
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
127k
    serialization::SubmoduleID ID, Module *Mod) {
72
127k
  for (auto &Listener : Listeners)
73
127k
    Listener->ModuleRead(ID, Mod);
74
127k
}
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
4.93k
    : Listeners(L.begin(), L.end()) {
120
4.93k
}
121
122
163k
void MultiplexASTMutationListener::CompletedTagDefinition(const TagDecl *D) {
123
327k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i163k
)
124
163k
    Listeners[i]->CompletedTagDefinition(D);
125
163k
}
126
127
void MultiplexASTMutationListener::AddedVisibleDecl(
128
942k
    const DeclContext *DC, const Decl *D) {
129
1.88M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i942k
)
130
942k
    Listeners[i]->AddedVisibleDecl(DC, D);
131
942k
}
132
133
void MultiplexASTMutationListener::AddedCXXImplicitMember(
134
17.9k
    const CXXRecordDecl *RD, const Decl *D) {
135
35.8k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i17.9k
)
136
17.9k
    Listeners[i]->AddedCXXImplicitMember(RD, D);
137
17.9k
}
138
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
139
52.9k
    const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) {
140
105k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i52.9k
)
141
52.9k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
142
52.9k
}
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
12.1k
    const FunctionTemplateDecl *TD, const FunctionDecl *D) {
150
24.3k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i12.1k
)
151
12.1k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
152
12.1k
}
153
void MultiplexASTMutationListener::ResolvedExceptionSpec(
154
35.8k
    const FunctionDecl *FD) {
155
35.8k
  for (auto &Listener : Listeners)
156
35.8k
    Listener->ResolvedExceptionSpec(FD);
157
35.8k
}
158
void MultiplexASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
159
60
                                                     QualType ReturnType) {
160
120
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i60
)
161
60
    Listeners[i]->DeducedReturnType(FD, ReturnType);
162
60
}
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.04k
                                                        const FunctionDecl *D) {
170
8.09k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i4.04k
)
171
4.04k
    Listeners[i]->CompletedImplicitDefinition(D);
172
4.04k
}
173
18.4k
void MultiplexASTMutationListener::InstantiationRequested(const ValueDecl *D) {
174
36.9k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i18.4k
)
175
18.4k
    Listeners[i]->InstantiationRequested(D);
176
18.4k
}
177
void MultiplexASTMutationListener::VariableDefinitionInstantiated(
178
11.2k
    const VarDecl *D) {
179
22.4k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i11.2k
)
180
11.2k
    Listeners[i]->VariableDefinitionInstantiated(D);
181
11.2k
}
182
void MultiplexASTMutationListener::FunctionDefinitionInstantiated(
183
8.74k
    const FunctionDecl *D) {
184
8.74k
  for (auto &Listener : Listeners)
185
8.74k
    Listener->FunctionDefinitionInstantiated(D);
186
8.74k
}
187
void MultiplexASTMutationListener::DefaultArgumentInstantiated(
188
593
                                                         const ParmVarDecl *D) {
189
1.18k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i593
)
190
593
    Listeners[i]->DefaultArgumentInstantiated(D);
191
593
}
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.75k
                                                 const ObjCInterfaceDecl *IFD) {
200
3.50k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.75k
)
201
1.75k
    Listeners[i]->AddedObjCCategoryToInterface(CatD, IFD);
202
1.75k
}
203
329k
void MultiplexASTMutationListener::DeclarationMarkedUsed(const Decl *D) {
204
658k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i329k
)
205
329k
    Listeners[i]->DeclarationMarkedUsed(D);
206
329k
}
207
void MultiplexASTMutationListener::DeclarationMarkedOpenMPThreadPrivate(
208
205
    const Decl *D) {
209
410
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i205
)
210
205
    Listeners[i]->DeclarationMarkedOpenMPThreadPrivate(D);
211
205
}
212
void MultiplexASTMutationListener::DeclarationMarkedOpenMPAllocate(
213
180
    const Decl *D, const Attr *A) {
214
180
  for (ASTMutationListener *L : Listeners)
215
180
    L->DeclarationMarkedOpenMPAllocate(D, A);
216
180
}
217
void MultiplexASTMutationListener::DeclarationMarkedOpenMPDeclareTarget(
218
1.12k
    const Decl *D, const Attr *Attr) {
219
1.12k
  for (auto *L : Listeners)
220
1.12k
    L->DeclarationMarkedOpenMPDeclareTarget(D, Attr);
221
1.12k
}
222
void MultiplexASTMutationListener::RedefinedHiddenDefinition(const NamedDecl *D,
223
2.56k
                                                             Module *M) {
224
2.56k
  for (auto *L : Listeners)
225
2.56k
    L->RedefinedHiddenDefinition(D, M);
226
2.56k
}
227
228
void MultiplexASTMutationListener::AddedAttributeToRecord(
229
                                                    const Attr *Attr,
230
32
                                                    const RecordDecl *Record) {
231
32
  for (auto *L : Listeners)
232
32
    L->AddedAttributeToRecord(Attr, Record);
233
32
}
234
235
}  // end namespace clang
236
237
MultiplexConsumer::MultiplexConsumer(
238
    std::vector<std::unique_ptr<ASTConsumer>> C)
239
5.20k
    : 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.20k
  std::vector<ASTMutationListener*> mutationListeners;
243
5.20k
  std::vector<ASTDeserializationListener*> serializationListeners;
244
10.3k
  for (auto &Consumer : Consumers) {
245
10.3k
    if (auto *mutationListener = Consumer->GetASTMutationListener())
246
4.93k
      mutationListeners.push_back(mutationListener);
247
10.3k
    if (auto *serializationListener = Consumer->GetASTDeserializationListener())
248
4.92k
      serializationListeners.push_back(serializationListener);
249
10.3k
  }
250
5.20k
  if (!mutationListeners.empty()) {
251
4.92k
    MutationListener =
252
4.92k
        std::make_unique<MultiplexASTMutationListener>(mutationListeners);
253
4.92k
  }
254
5.20k
  if (!serializationListeners.empty()) {
255
4.93k
    DeserializationListener =
256
4.93k
        std::make_unique<MultiplexASTDeserializationListener>(
257
4.93k
            serializationListeners);
258
4.93k
  }
259
5.20k
}
260
261
5.20k
MultiplexConsumer::~MultiplexConsumer() {}
262
263
5.20k
void MultiplexConsumer::Initialize(ASTContext &Context) {
264
5.20k
  for (auto &Consumer : Consumers)
265
10.3k
    Consumer->Initialize(Context);
266
5.20k
}
267
268
299k
bool MultiplexConsumer::HandleTopLevelDecl(DeclGroupRef D) {
269
299k
  bool Continue = true;
270
299k
  for (auto &Consumer : Consumers)
271
599k
    Continue = Continue && Consumer->HandleTopLevelDecl(D);
272
299k
  return Continue;
273
299k
}
274
275
44.9k
void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
276
44.9k
  for (auto &Consumer : Consumers)
277
89.8k
    Consumer->HandleInlineFunctionDefinition(D);
278
44.9k
}
279
280
40.4k
void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
281
40.4k
  for (auto &Consumer : Consumers)
282
80.9k
    Consumer->HandleCXXStaticMemberVarInstantiation(VD);
283
40.4k
}
284
285
4.22k
void MultiplexConsumer::HandleInterestingDecl(DeclGroupRef D) {
286
4.22k
  for (auto &Consumer : Consumers)
287
8.45k
    Consumer->HandleInterestingDecl(D);
288
4.22k
}
289
290
5.20k
void MultiplexConsumer::HandleTranslationUnit(ASTContext &Ctx) {
291
5.20k
  for (auto &Consumer : Consumers)
292
10.3k
    Consumer->HandleTranslationUnit(Ctx);
293
5.20k
}
294
295
124k
void MultiplexConsumer::HandleTagDeclDefinition(TagDecl *D) {
296
124k
  for (auto &Consumer : Consumers)
297
247k
    Consumer->HandleTagDeclDefinition(D);
298
124k
}
299
300
67.4k
void MultiplexConsumer::HandleTagDeclRequiredDefinition(const TagDecl *D) {
301
67.4k
  for (auto &Consumer : Consumers)
302
134k
    Consumer->HandleTagDeclRequiredDefinition(D);
303
67.4k
}
304
305
9.41k
void MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D){
306
9.41k
  for (auto &Consumer : Consumers)
307
18.8k
    Consumer->HandleCXXImplicitFunctionInstantiation(D);
308
9.41k
}
309
310
1.46k
void MultiplexConsumer::HandleTopLevelDeclInObjCContainer(DeclGroupRef D) {
311
1.46k
  for (auto &Consumer : Consumers)
312
2.92k
    Consumer->HandleTopLevelDeclInObjCContainer(D);
313
1.46k
}
314
315
77.5k
void MultiplexConsumer::HandleImplicitImportDecl(ImportDecl *D) {
316
77.5k
  for (auto &Consumer : Consumers)
317
155k
    Consumer->HandleImplicitImportDecl(D);
318
77.5k
}
319
320
514
void MultiplexConsumer::CompleteTentativeDefinition(VarDecl *D) {
321
514
  for (auto &Consumer : Consumers)
322
1.02k
    Consumer->CompleteTentativeDefinition(D);
323
514
}
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
54.3k
ASTMutationListener *MultiplexConsumer::GetASTMutationListener() {
341
54.3k
  return MutationListener.get();
342
54.3k
}
343
344
2.03k
ASTDeserializationListener *MultiplexConsumer::GetASTDeserializationListener() {
345
2.03k
  return DeserializationListener.get();
346
2.03k
}
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.20k
void MultiplexConsumer::InitializeSema(Sema &S) {
361
5.20k
  for (auto &Consumer : Consumers)
362
10.3k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
363
4.93k
      SC->InitializeSema(S);
364
5.20k
}
365
366
5.17k
void MultiplexConsumer::ForgetSema() {
367
5.17k
  for (auto &Consumer : Consumers)
368
10.2k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
369
4.90k
      SC->ForgetSema();
370
5.17k
}