Coverage Report

Created: 2022-05-17 06: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.42k
    : Listeners(L) {
26
5.42k
}
27
28
void MultiplexASTDeserializationListener::ReaderInitialized(
29
3.86k
    ASTReader *Reader) {
30
7.72k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.86k
)
31
3.86k
    Listeners[i]->ReaderInitialized(Reader);
32
3.86k
}
33
34
void MultiplexASTDeserializationListener::IdentifierRead(
35
1.93M
    serialization::IdentID ID, IdentifierInfo *II) {
36
3.87M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.93M
)
37
1.93M
    Listeners[i]->IdentifierRead(ID, II);
38
1.93M
}
39
40
void MultiplexASTDeserializationListener::MacroRead(
41
15.0k
    serialization::MacroID ID, MacroInfo *MI) {
42
15.0k
  for (auto &Listener : Listeners)
43
15.0k
    Listener->MacroRead(ID, MI);
44
15.0k
}
45
46
void MultiplexASTDeserializationListener::TypeRead(
47
78.4k
    serialization::TypeIdx Idx, QualType T) {
48
156k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i78.4k
)
49
78.4k
    Listeners[i]->TypeRead(Idx, T);
50
78.4k
}
51
52
void MultiplexASTDeserializationListener::DeclRead(
53
279k
    serialization::DeclID ID, const Decl *D) {
54
558k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i279k
)
55
279k
    Listeners[i]->DeclRead(ID, D);
56
279k
}
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
130k
    serialization::SubmoduleID ID, Module *Mod) {
72
130k
  for (auto &Listener : Listeners)
73
130k
    Listener->ModuleRead(ID, Mod);
74
130k
}
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.42k
    : Listeners(L.begin(), L.end()) {
126
5.42k
}
127
128
160k
void MultiplexASTMutationListener::CompletedTagDefinition(const TagDecl *D) {
129
321k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i160k
)
130
160k
    Listeners[i]->CompletedTagDefinition(D);
131
160k
}
132
133
void MultiplexASTMutationListener::AddedVisibleDecl(
134
910k
    const DeclContext *DC, const Decl *D) {
135
1.82M
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i910k
)
136
910k
    Listeners[i]->AddedVisibleDecl(DC, D);
137
910k
}
138
139
void MultiplexASTMutationListener::AddedCXXImplicitMember(
140
17.9k
    const CXXRecordDecl *RD, const Decl *D) {
141
35.8k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i17.9k
)
142
17.9k
    Listeners[i]->AddedCXXImplicitMember(RD, D);
143
17.9k
}
144
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
145
48.5k
    const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) {
146
97.1k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i48.5k
)
147
48.5k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
148
48.5k
}
149
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
150
150
    const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) {
151
300
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i150
)
152
150
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
153
150
}
154
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
155
10.8k
    const FunctionTemplateDecl *TD, const FunctionDecl *D) {
156
21.6k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i10.8k
)
157
10.8k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
158
10.8k
}
159
void MultiplexASTMutationListener::ResolvedExceptionSpec(
160
35.1k
    const FunctionDecl *FD) {
161
35.1k
  for (auto &Listener : Listeners)
162
35.1k
    Listener->ResolvedExceptionSpec(FD);
163
35.1k
}
164
void MultiplexASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
165
65
                                                     QualType ReturnType) {
166
130
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i65
)
167
65
    Listeners[i]->DeducedReturnType(FD, ReturnType);
168
65
}
169
void MultiplexASTMutationListener::ResolvedOperatorDelete(
170
56
    const CXXDestructorDecl *DD, const FunctionDecl *Delete, Expr *ThisArg) {
171
56
  for (auto *L : Listeners)
172
56
    L->ResolvedOperatorDelete(DD, Delete, ThisArg);
173
56
}
174
void MultiplexASTMutationListener::CompletedImplicitDefinition(
175
4.26k
                                                        const FunctionDecl *D) {
176
8.52k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i4.26k
)
177
4.26k
    Listeners[i]->CompletedImplicitDefinition(D);
178
4.26k
}
179
10.5k
void MultiplexASTMutationListener::InstantiationRequested(const ValueDecl *D) {
180
21.1k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i10.5k
)
181
10.5k
    Listeners[i]->InstantiationRequested(D);
182
10.5k
}
183
void MultiplexASTMutationListener::VariableDefinitionInstantiated(
184
10.5k
    const VarDecl *D) {
185
21.1k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i10.5k
)
186
10.5k
    Listeners[i]->VariableDefinitionInstantiated(D);
187
10.5k
}
188
void MultiplexASTMutationListener::FunctionDefinitionInstantiated(
189
8.05k
    const FunctionDecl *D) {
190
8.05k
  for (auto &Listener : Listeners)
191
8.05k
    Listener->FunctionDefinitionInstantiated(D);
192
8.05k
}
193
void MultiplexASTMutationListener::DefaultArgumentInstantiated(
194
461
                                                         const ParmVarDecl *D) {
195
922
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i461
)
196
461
    Listeners[i]->DefaultArgumentInstantiated(D);
197
461
}
198
void MultiplexASTMutationListener::DefaultMemberInitializerInstantiated(
199
36
                                                           const FieldDecl *D) {
200
72
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i36
)
201
36
    Listeners[i]->DefaultMemberInitializerInstantiated(D);
202
36
}
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
319k
void MultiplexASTMutationListener::DeclarationMarkedUsed(const Decl *D) {
210
638k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i319k
)
211
319k
    Listeners[i]->DeclarationMarkedUsed(D);
212
319k
}
213
void MultiplexASTMutationListener::DeclarationMarkedOpenMPThreadPrivate(
214
211
    const Decl *D) {
215
422
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i211
)
216
211
    Listeners[i]->DeclarationMarkedOpenMPThreadPrivate(D);
217
211
}
218
void MultiplexASTMutationListener::DeclarationMarkedOpenMPAllocate(
219
261
    const Decl *D, const Attr *A) {
220
261
  for (ASTMutationListener *L : Listeners)
221
261
    L->DeclarationMarkedOpenMPAllocate(D, A);
222
261
}
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.56k
                                                             Module *M) {
230
2.56k
  for (auto *L : Listeners)
231
2.56k
    L->RedefinedHiddenDefinition(D, M);
232
2.56k
}
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.70k
    : 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.70k
  std::vector<ASTMutationListener *> mutationListeners;
249
5.70k
  std::vector<ASTDeserializationListener*> serializationListeners;
250
11.3k
  for (auto &Consumer : Consumers) {
251
11.3k
    if (auto *mutationListener = Consumer->GetASTMutationListener())
252
5.42k
      mutationListeners.push_back(mutationListener);
253
11.3k
    if (auto *serializationListener = Consumer->GetASTDeserializationListener())
254
5.42k
      serializationListeners.push_back(serializationListener);
255
11.3k
  }
256
5.70k
  if (!mutationListeners.empty()) {
257
5.42k
    MutationListener =
258
5.42k
        std::make_unique<MultiplexASTMutationListener>(mutationListeners);
259
5.42k
  }
260
5.70k
  if (!serializationListeners.empty()) {
261
5.42k
    DeserializationListener =
262
5.42k
        std::make_unique<MultiplexASTDeserializationListener>(
263
5.42k
            serializationListeners);
264
5.42k
  }
265
5.70k
}
266
267
5.70k
MultiplexConsumer::~MultiplexConsumer() {}
268
269
5.70k
void MultiplexConsumer::Initialize(ASTContext &Context) {
270
5.70k
  for (auto &Consumer : Consumers)
271
11.3k
    Consumer->Initialize(Context);
272
5.70k
}
273
274
276k
bool MultiplexConsumer::HandleTopLevelDecl(DeclGroupRef D) {
275
276k
  bool Continue = true;
276
276k
  for (auto &Consumer : Consumers)
277
552k
    Continue = Continue && Consumer->HandleTopLevelDecl(D);
278
276k
  return Continue;
279
276k
}
280
281
46.0k
void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
282
46.0k
  for (auto &Consumer : Consumers)
283
92.0k
    Consumer->HandleInlineFunctionDefinition(D);
284
46.0k
}
285
286
34.2k
void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
287
34.2k
  for (auto &Consumer : Consumers)
288
68.4k
    Consumer->HandleCXXStaticMemberVarInstantiation(VD);
289
34.2k
}
290
291
4.02k
void MultiplexConsumer::HandleInterestingDecl(DeclGroupRef D) {
292
4.02k
  for (auto &Consumer : Consumers)
293
8.04k
    Consumer->HandleInterestingDecl(D);
294
4.02k
}
295
296
5.70k
void MultiplexConsumer::HandleTranslationUnit(ASTContext &Ctx) {
297
5.70k
  for (auto &Consumer : Consumers)
298
11.3k
    Consumer->HandleTranslationUnit(Ctx);
299
5.70k
}
300
301
118k
void MultiplexConsumer::HandleTagDeclDefinition(TagDecl *D) {
302
118k
  for (auto &Consumer : Consumers)
303
236k
    Consumer->HandleTagDeclDefinition(D);
304
118k
}
305
306
62.7k
void MultiplexConsumer::HandleTagDeclRequiredDefinition(const TagDecl *D) {
307
62.7k
  for (auto &Consumer : Consumers)
308
125k
    Consumer->HandleTagDeclRequiredDefinition(D);
309
62.7k
}
310
311
8.83k
void MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D){
312
8.83k
  for (auto &Consumer : Consumers)
313
17.6k
    Consumer->HandleCXXImplicitFunctionInstantiation(D);
314
8.83k
}
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
116k
void MultiplexConsumer::HandleImplicitImportDecl(ImportDecl *D) {
322
116k
  for (auto &Consumer : Consumers)
323
233k
    Consumer->HandleImplicitImportDecl(D);
324
116k
}
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
53.6k
ASTMutationListener *MultiplexConsumer::GetASTMutationListener() {
347
53.6k
  return MutationListener.get();
348
53.6k
}
349
350
2.31k
ASTDeserializationListener *MultiplexConsumer::GetASTDeserializationListener() {
351
2.31k
  return DeserializationListener.get();
352
2.31k
}
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.70k
void MultiplexConsumer::InitializeSema(Sema &S) {
367
5.70k
  for (auto &Consumer : Consumers)
368
11.3k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
369
5.42k
      SC->InitializeSema(S);
370
5.70k
}
371
372
5.67k
void MultiplexConsumer::ForgetSema() {
373
5.67k
  for (auto &Consumer : Consumers)
374
11.2k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
375
5.39k
      SC->ForgetSema();
376
5.67k
}