Coverage Report

Created: 2020-02-25 14:32

/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.18k
    : Listeners(L) {
26
4.18k
}
27
28
void MultiplexASTDeserializationListener::ReaderInitialized(
29
3.45k
    ASTReader *Reader) {
30
6.90k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.45k
)
31
3.45k
    Listeners[i]->ReaderInitialized(Reader);
32
3.45k
}
33
34
void MultiplexASTDeserializationListener::IdentifierRead(
35
1.98M
    serialization::IdentID ID, IdentifierInfo *II) {
36
3.96M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.98M
)
37
1.98M
    Listeners[i]->IdentifierRead(ID, II);
38
1.98M
}
39
40
void MultiplexASTDeserializationListener::MacroRead(
41
17.8k
    serialization::MacroID ID, MacroInfo *MI) {
42
17.8k
  for (auto &Listener : Listeners)
43
17.8k
    Listener->MacroRead(ID, MI);
44
17.8k
}
45
46
void MultiplexASTDeserializationListener::TypeRead(
47
83.8k
    serialization::TypeIdx Idx, QualType T) {
48
167k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i83.8k
)
49
83.8k
    Listeners[i]->TypeRead(Idx, T);
50
83.8k
}
51
52
void MultiplexASTDeserializationListener::DeclRead(
53
286k
    serialization::DeclID ID, const Decl *D) {
54
572k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i286k
)
55
286k
    Listeners[i]->DeclRead(ID, D);
56
286k
}
57
58
void MultiplexASTDeserializationListener::SelectorRead(
59
3.58k
    serialization::SelectorID ID, Selector Sel) {
60
7.17k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.58k
)
61
3.58k
    Listeners[i]->SelectorRead(ID, Sel);
62
3.58k
}
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
131k
    serialization::SubmoduleID ID, Module *Mod) {
72
131k
  for (auto &Listener : Listeners)
73
131k
    Listener->ModuleRead(ID, Mod);
74
131k
}
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.18k
    : Listeners(L.begin(), L.end()) {
120
4.18k
}
121
122
200k
void MultiplexASTMutationListener::CompletedTagDefinition(const TagDecl *D) {
123
401k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i200k
)
124
200k
    Listeners[i]->CompletedTagDefinition(D);
125
200k
}
126
127
void MultiplexASTMutationListener::AddedVisibleDecl(
128
1.03M
    const DeclContext *DC, const Decl *D) {
129
2.07M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.03M
)
130
1.03M
    Listeners[i]->AddedVisibleDecl(DC, D);
131
1.03M
}
132
133
void MultiplexASTMutationListener::AddedCXXImplicitMember(
134
21.7k
    const CXXRecordDecl *RD, const Decl *D) {
135
43.4k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i21.7k
)
136
21.7k
    Listeners[i]->AddedCXXImplicitMember(RD, D);
137
21.7k
}
138
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
139
85.8k
    const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) {
140
171k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i85.8k
)
141
85.8k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
142
85.8k
}
143
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
144
118
    const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) {
145
236
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i118
)
146
118
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
147
118
}
148
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
149
20.3k
    const FunctionTemplateDecl *TD, const FunctionDecl *D) {
150
40.7k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i20.3k
)
151
20.3k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
152
20.3k
}
153
void MultiplexASTMutationListener::ResolvedExceptionSpec(
154
54.3k
    const FunctionDecl *FD) {
155
54.3k
  for (auto &Listener : Listeners)
156
54.3k
    Listener->ResolvedExceptionSpec(FD);
157
54.3k
}
158
void MultiplexASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
159
52
                                                     QualType ReturnType) {
160
104
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i52
)
161
52
    Listeners[i]->DeducedReturnType(FD, ReturnType);
162
52
}
163
void MultiplexASTMutationListener::ResolvedOperatorDelete(
164
71
    const CXXDestructorDecl *DD, const FunctionDecl *Delete, Expr *ThisArg) {
165
71
  for (auto *L : Listeners)
166
71
    L->ResolvedOperatorDelete(DD, Delete, ThisArg);
167
71
}
168
void MultiplexASTMutationListener::CompletedImplicitDefinition(
169
5.15k
                                                        const FunctionDecl *D) {
170
10.3k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i5.15k
)
171
5.15k
    Listeners[i]->CompletedImplicitDefinition(D);
172
5.15k
}
173
26.6k
void MultiplexASTMutationListener::InstantiationRequested(const ValueDecl *D) {
174
53.2k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i26.6k
)
175
26.6k
    Listeners[i]->InstantiationRequested(D);
176
26.6k
}
177
void MultiplexASTMutationListener::VariableDefinitionInstantiated(
178
18.4k
    const VarDecl *D) {
179
36.9k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i18.4k
)
180
18.4k
    Listeners[i]->VariableDefinitionInstantiated(D);
181
18.4k
}
182
void MultiplexASTMutationListener::FunctionDefinitionInstantiated(
183
13.6k
    const FunctionDecl *D) {
184
13.6k
  for (auto &Listener : Listeners)
185
13.6k
    Listener->FunctionDefinitionInstantiated(D);
186
13.6k
}
187
void MultiplexASTMutationListener::DefaultArgumentInstantiated(
188
925
                                                         const ParmVarDecl *D) {
189
1.85k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i925
)
190
925
    Listeners[i]->DefaultArgumentInstantiated(D);
191
925
}
192
void MultiplexASTMutationListener::DefaultMemberInitializerInstantiated(
193
1
                                                           const FieldDecl *D) {
194
2
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1
)
195
1
    Listeners[i]->DefaultMemberInitializerInstantiated(D);
196
1
}
197
void MultiplexASTMutationListener::AddedObjCCategoryToInterface(
198
                                                 const ObjCCategoryDecl *CatD,
199
1.71k
                                                 const ObjCInterfaceDecl *IFD) {
200
3.42k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.71k
)
201
1.71k
    Listeners[i]->AddedObjCCategoryToInterface(CatD, IFD);
202
1.71k
}
203
344k
void MultiplexASTMutationListener::DeclarationMarkedUsed(const Decl *D) {
204
688k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i344k
)
205
344k
    Listeners[i]->DeclarationMarkedUsed(D);
206
344k
}
207
void MultiplexASTMutationListener::DeclarationMarkedOpenMPThreadPrivate(
208
185
    const Decl *D) {
209
370
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i185
)
210
185
    Listeners[i]->DeclarationMarkedOpenMPThreadPrivate(D);
211
185
}
212
void MultiplexASTMutationListener::DeclarationMarkedOpenMPAllocate(
213
168
    const Decl *D, const Attr *A) {
214
168
  for (ASTMutationListener *L : Listeners)
215
168
    L->DeclarationMarkedOpenMPAllocate(D, A);
216
168
}
217
void MultiplexASTMutationListener::DeclarationMarkedOpenMPDeclareTarget(
218
624
    const Decl *D, const Attr *Attr) {
219
624
  for (auto *L : Listeners)
220
624
    L->DeclarationMarkedOpenMPDeclareTarget(D, Attr);
221
624
}
222
void MultiplexASTMutationListener::RedefinedHiddenDefinition(const NamedDecl *D,
223
2.55k
                                                             Module *M) {
224
2.55k
  for (auto *L : Listeners)
225
2.55k
    L->RedefinedHiddenDefinition(D, M);
226
2.55k
}
227
228
void MultiplexASTMutationListener::AddedAttributeToRecord(
229
                                                    const Attr *Attr,
230
31
                                                    const RecordDecl *Record) {
231
31
  for (auto *L : Listeners)
232
31
    L->AddedAttributeToRecord(Attr, Record);
233
31
}
234
235
}  // end namespace clang
236
237
MultiplexConsumer::MultiplexConsumer(
238
    std::vector<std::unique_ptr<ASTConsumer>> C)
239
4.46k
    : Consumers(std::move(C)), MutationListener(), DeserializationListener() {
240
4.46k
  // Collect the mutation listeners and deserialization listeners of all
241
4.46k
  // children, and create a multiplex listener each if so.
242
4.46k
  std::vector<ASTMutationListener*> mutationListeners;
243
4.46k
  std::vector<ASTDeserializationListener*> serializationListeners;
244
8.83k
  for (auto &Consumer : Consumers) {
245
8.83k
    if (auto *mutationListener = Consumer->GetASTMutationListener())
246
4.18k
      mutationListeners.push_back(mutationListener);
247
8.83k
    if (auto *serializationListener = Consumer->GetASTDeserializationListener())
248
4.18k
      serializationListeners.push_back(serializationListener);
249
8.83k
  }
250
4.46k
  if (!mutationListeners.empty()) {
251
4.18k
    MutationListener =
252
4.18k
        std::make_unique<MultiplexASTMutationListener>(mutationListeners);
253
4.18k
  }
254
4.46k
  if (!serializationListeners.empty()) {
255
4.18k
    DeserializationListener =
256
4.18k
        std::make_unique<MultiplexASTDeserializationListener>(
257
4.18k
            serializationListeners);
258
4.18k
  }
259
4.46k
}
260
261
4.46k
MultiplexConsumer::~MultiplexConsumer() {}
262
263
4.46k
void MultiplexConsumer::Initialize(ASTContext &Context) {
264
4.46k
  for (auto &Consumer : Consumers)
265
8.83k
    Consumer->Initialize(Context);
266
4.46k
}
267
268
279k
bool MultiplexConsumer::HandleTopLevelDecl(DeclGroupRef D) {
269
279k
  bool Continue = true;
270
279k
  for (auto &Consumer : Consumers)
271
559k
    Continue = Continue && Consumer->HandleTopLevelDecl(D);
272
279k
  return Continue;
273
279k
}
274
275
66.1k
void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
276
66.1k
  for (auto &Consumer : Consumers)
277
132k
    Consumer->HandleInlineFunctionDefinition(D);
278
66.1k
}
279
280
66.1k
void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
281
66.1k
  for (auto &Consumer : Consumers)
282
132k
    Consumer->HandleCXXStaticMemberVarInstantiation(VD);
283
66.1k
}
284
285
4.07k
void MultiplexConsumer::HandleInterestingDecl(DeclGroupRef D) {
286
4.07k
  for (auto &Consumer : Consumers)
287
8.15k
    Consumer->HandleInterestingDecl(D);
288
4.07k
}
289
290
4.45k
void MultiplexConsumer::HandleTranslationUnit(ASTContext &Ctx) {
291
4.45k
  for (auto &Consumer : Consumers)
292
8.82k
    Consumer->HandleTranslationUnit(Ctx);
293
4.45k
}
294
295
169k
void MultiplexConsumer::HandleTagDeclDefinition(TagDecl *D) {
296
169k
  for (auto &Consumer : Consumers)
297
338k
    Consumer->HandleTagDeclDefinition(D);
298
169k
}
299
300
100k
void MultiplexConsumer::HandleTagDeclRequiredDefinition(const TagDecl *D) {
301
100k
  for (auto &Consumer : Consumers)
302
201k
    Consumer->HandleTagDeclRequiredDefinition(D);
303
100k
}
304
305
12.3k
void MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D){
306
12.3k
  for (auto &Consumer : Consumers)
307
24.6k
    Consumer->HandleCXXImplicitFunctionInstantiation(D);
308
12.3k
}
309
310
1.44k
void MultiplexConsumer::HandleTopLevelDeclInObjCContainer(DeclGroupRef D) {
311
1.44k
  for (auto &Consumer : Consumers)
312
2.89k
    Consumer->HandleTopLevelDeclInObjCContainer(D);
313
1.44k
}
314
315
96.5k
void MultiplexConsumer::HandleImplicitImportDecl(ImportDecl *D) {
316
96.5k
  for (auto &Consumer : Consumers)
317
193k
    Consumer->HandleImplicitImportDecl(D);
318
96.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
2
void MultiplexConsumer::AssignInheritanceModel(CXXRecordDecl *RD) {
331
2
  for (auto &Consumer : Consumers)
332
4
    Consumer->AssignInheritanceModel(RD);
333
2
}
334
335
3
void MultiplexConsumer::HandleVTable(CXXRecordDecl *RD) {
336
3
  for (auto &Consumer : Consumers)
337
6
    Consumer->HandleVTable(RD);
338
3
}
339
340
78.4k
ASTMutationListener *MultiplexConsumer::GetASTMutationListener() {
341
78.4k
  return MutationListener.get();
342
78.4k
}
343
344
1.98k
ASTDeserializationListener *MultiplexConsumer::GetASTDeserializationListener() {
345
1.98k
  return DeserializationListener.get();
346
1.98k
}
347
348
0
void MultiplexConsumer::PrintStats() {
349
0
  for (auto &Consumer : Consumers)
350
0
    Consumer->PrintStats();
351
0
}
352
353
30
bool MultiplexConsumer::shouldSkipFunctionBody(Decl *D) {
354
30
  bool Skip = true;
355
30
  for (auto &Consumer : Consumers)
356
60
    Skip = Skip && Consumer->shouldSkipFunctionBody(D);
357
30
  return Skip;
358
30
}
359
360
4.46k
void MultiplexConsumer::InitializeSema(Sema &S) {
361
4.46k
  for (auto &Consumer : Consumers)
362
8.83k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
363
4.18k
      SC->InitializeSema(S);
364
4.46k
}
365
366
4.43k
void MultiplexConsumer::ForgetSema() {
367
4.43k
  for (auto &Consumer : Consumers)
368
8.77k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
369
4.16k
      SC->ForgetSema();
370
4.43k
}