Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
3.62k
    : Listeners(L) {
26
3.62k
}
27
28
void MultiplexASTDeserializationListener::ReaderInitialized(
29
2.42k
    ASTReader *Reader) {
30
4.85k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i2.42k
)
31
2.42k
    Listeners[i]->ReaderInitialized(Reader);
32
2.42k
}
33
34
void MultiplexASTDeserializationListener::IdentifierRead(
35
31.2k
    serialization::IdentID ID, IdentifierInfo *II) {
36
62.5k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i31.2k
)
37
31.2k
    Listeners[i]->IdentifierRead(ID, II);
38
31.2k
}
39
40
void MultiplexASTDeserializationListener::MacroRead(
41
359
    serialization::MacroID ID, MacroInfo *MI) {
42
359
  for (auto &Listener : Listeners)
43
359
    Listener->MacroRead(ID, MI);
44
359
}
45
46
void MultiplexASTDeserializationListener::TypeRead(
47
13.0k
    serialization::TypeIdx Idx, QualType T) {
48
26.0k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i13.0k
)
49
13.0k
    Listeners[i]->TypeRead(Idx, T);
50
13.0k
}
51
52
void MultiplexASTDeserializationListener::DeclRead(
53
14.9k
    serialization::DeclID ID, const Decl *D) {
54
29.8k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i14.9k
)
55
14.9k
    Listeners[i]->DeclRead(ID, D);
56
14.9k
}
57
58
void MultiplexASTDeserializationListener::SelectorRead(
59
16
    serialization::SelectorID ID, Selector Sel) {
60
32
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i16
)
61
16
    Listeners[i]->SelectorRead(ID, Sel);
62
16
}
63
64
void MultiplexASTDeserializationListener::MacroDefinitionRead(
65
35
    serialization::PreprocessedEntityID ID, MacroDefinitionRecord *MD) {
66
70
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i35
)
67
35
    Listeners[i]->MacroDefinitionRead(ID, MD);
68
35
}
69
70
void MultiplexASTDeserializationListener::ModuleRead(
71
2.51k
    serialization::SubmoduleID ID, Module *Mod) {
72
2.51k
  for (auto &Listener : Listeners)
73
2.51k
    Listener->ModuleRead(ID, Mod);
74
2.51k
}
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
3.62k
    : Listeners(L.begin(), L.end()) {
120
3.62k
}
121
122
33.4k
void MultiplexASTMutationListener::CompletedTagDefinition(const TagDecl *D) {
123
66.8k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i33.4k
)
124
33.4k
    Listeners[i]->CompletedTagDefinition(D);
125
33.4k
}
126
127
void MultiplexASTMutationListener::AddedVisibleDecl(
128
138k
    const DeclContext *DC, const Decl *D) {
129
276k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i138k
)
130
138k
    Listeners[i]->AddedVisibleDecl(DC, D);
131
138k
}
132
133
void MultiplexASTMutationListener::AddedCXXImplicitMember(
134
4.68k
    const CXXRecordDecl *RD, const Decl *D) {
135
9.36k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i4.68k
)
136
4.68k
    Listeners[i]->AddedCXXImplicitMember(RD, D);
137
4.68k
}
138
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
139
3.57k
    const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) {
140
7.14k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i3.57k
)
141
3.57k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
142
3.57k
}
143
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
144
114
    const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) {
145
228
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i114
)
146
114
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
147
114
}
148
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
149
1.04k
    const FunctionTemplateDecl *TD, const FunctionDecl *D) {
150
2.09k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.04k
)
151
1.04k
    Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
152
1.04k
}
153
void MultiplexASTMutationListener::ResolvedExceptionSpec(
154
3.04k
    const FunctionDecl *FD) {
155
3.04k
  for (auto &Listener : Listeners)
156
3.04k
    Listener->ResolvedExceptionSpec(FD);
157
3.04k
}
158
void MultiplexASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
159
49
                                                     QualType ReturnType) {
160
98
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i49
)
161
49
    Listeners[i]->DeducedReturnType(FD, ReturnType);
162
49
}
163
void MultiplexASTMutationListener::ResolvedOperatorDelete(
164
16
    const CXXDestructorDecl *DD, const FunctionDecl *Delete, Expr *ThisArg) {
165
16
  for (auto *L : Listeners)
166
16
    L->ResolvedOperatorDelete(DD, Delete, ThisArg);
167
16
}
168
void MultiplexASTMutationListener::CompletedImplicitDefinition(
169
1.29k
                                                        const FunctionDecl *D) {
170
2.58k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i1.29k
)
171
1.29k
    Listeners[i]->CompletedImplicitDefinition(D);
172
1.29k
}
173
2.71k
void MultiplexASTMutationListener::InstantiationRequested(const ValueDecl *D) {
174
5.42k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i2.71k
)
175
2.71k
    Listeners[i]->InstantiationRequested(D);
176
2.71k
}
177
void MultiplexASTMutationListener::VariableDefinitionInstantiated(
178
183
    const VarDecl *D) {
179
366
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i183
)
180
183
    Listeners[i]->VariableDefinitionInstantiated(D);
181
183
}
182
void MultiplexASTMutationListener::FunctionDefinitionInstantiated(
183
106
    const FunctionDecl *D) {
184
106
  for (auto &Listener : Listeners)
185
106
    Listener->FunctionDefinitionInstantiated(D);
186
106
}
187
void MultiplexASTMutationListener::DefaultArgumentInstantiated(
188
143
                                                         const ParmVarDecl *D) {
189
286
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i143
)
190
143
    Listeners[i]->DefaultArgumentInstantiated(D);
191
143
}
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
102
                                                 const ObjCInterfaceDecl *IFD) {
200
204
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i102
)
201
102
    Listeners[i]->AddedObjCCategoryToInterface(CatD, IFD);
202
102
}
203
147k
void MultiplexASTMutationListener::DeclarationMarkedUsed(const Decl *D) {
204
294k
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i147k
)
205
147k
    Listeners[i]->DeclarationMarkedUsed(D);
206
147k
}
207
void MultiplexASTMutationListener::DeclarationMarkedOpenMPThreadPrivate(
208
162
    const Decl *D) {
209
324
  for (size_t i = 0, e = Listeners.size(); i != e; 
++i162
)
210
162
    Listeners[i]->DeclarationMarkedOpenMPThreadPrivate(D);
211
162
}
212
void MultiplexASTMutationListener::DeclarationMarkedOpenMPAllocate(
213
158
    const Decl *D, const Attr *A) {
214
158
  for (ASTMutationListener *L : Listeners)
215
158
    L->DeclarationMarkedOpenMPAllocate(D, A);
216
158
}
217
void MultiplexASTMutationListener::DeclarationMarkedOpenMPDeclareTarget(
218
96
    const Decl *D, const Attr *Attr) {
219
96
  for (auto *L : Listeners)
220
96
    L->DeclarationMarkedOpenMPDeclareTarget(D, Attr);
221
96
}
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
1
                                                    const RecordDecl *Record) {
231
1
  for (auto *L : Listeners)
232
1
    L->AddedAttributeToRecord(Attr, Record);
233
1
}
234
235
}  // end namespace clang
236
237
MultiplexConsumer::MultiplexConsumer(
238
    std::vector<std::unique_ptr<ASTConsumer>> C)
239
5.63k
    : Consumers(std::move(C)), MutationListener(), DeserializationListener() {
240
5.63k
  // Collect the mutation listeners and deserialization listeners of all
241
5.63k
  // children, and create a multiplex listener each if so.
242
5.63k
  std::vector<ASTMutationListener*> mutationListeners;
243
5.63k
  std::vector<ASTDeserializationListener*> serializationListeners;
244
9.27k
  for (auto &Consumer : Consumers) {
245
9.27k
    if (auto *mutationListener = Consumer->GetASTMutationListener())
246
3.62k
      mutationListeners.push_back(mutationListener);
247
9.27k
    if (auto *serializationListener = Consumer->GetASTDeserializationListener())
248
3.62k
      serializationListeners.push_back(serializationListener);
249
9.27k
  }
250
5.63k
  if (!mutationListeners.empty()) {
251
3.62k
    MutationListener =
252
3.62k
        llvm::make_unique<MultiplexASTMutationListener>(mutationListeners);
253
3.62k
  }
254
5.63k
  if (!serializationListeners.empty()) {
255
3.62k
    DeserializationListener =
256
3.62k
        llvm::make_unique<MultiplexASTDeserializationListener>(
257
3.62k
            serializationListeners);
258
3.62k
  }
259
5.63k
}
260
261
5.63k
MultiplexConsumer::~MultiplexConsumer() {}
262
263
5.63k
void MultiplexConsumer::Initialize(ASTContext &Context) {
264
5.63k
  for (auto &Consumer : Consumers)
265
9.26k
    Consumer->Initialize(Context);
266
5.63k
}
267
268
117k
bool MultiplexConsumer::HandleTopLevelDecl(DeclGroupRef D) {
269
117k
  bool Continue = true;
270
117k
  for (auto &Consumer : Consumers)
271
216k
    Continue = Continue && Consumer->HandleTopLevelDecl(D);
272
117k
  return Continue;
273
117k
}
274
275
6.00k
void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
276
6.00k
  for (auto &Consumer : Consumers)
277
11.0k
    Consumer->HandleInlineFunctionDefinition(D);
278
6.00k
}
279
280
88
void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
281
88
  for (auto &Consumer : Consumers)
282
176
    Consumer->HandleCXXStaticMemberVarInstantiation(VD);
283
88
}
284
285
663
void MultiplexConsumer::HandleInterestingDecl(DeclGroupRef D) {
286
663
  for (auto &Consumer : Consumers)
287
1.25k
    Consumer->HandleInterestingDecl(D);
288
663
}
289
290
5.62k
void MultiplexConsumer::HandleTranslationUnit(ASTContext &Ctx) {
291
5.62k
  for (auto &Consumer : Consumers)
292
9.25k
    Consumer->HandleTranslationUnit(Ctx);
293
5.62k
}
294
295
10.2k
void MultiplexConsumer::HandleTagDeclDefinition(TagDecl *D) {
296
10.2k
  for (auto &Consumer : Consumers)
297
17.4k
    Consumer->HandleTagDeclDefinition(D);
298
10.2k
}
299
300
5.70k
void MultiplexConsumer::HandleTagDeclRequiredDefinition(const TagDecl *D) {
301
5.70k
  for (auto &Consumer : Consumers)
302
9.72k
    Consumer->HandleTagDeclRequiredDefinition(D);
303
5.70k
}
304
305
6.32k
void MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D){
306
6.32k
  for (auto &Consumer : Consumers)
307
8.90k
    Consumer->HandleCXXImplicitFunctionInstantiation(D);
308
6.32k
}
309
310
26
void MultiplexConsumer::HandleTopLevelDeclInObjCContainer(DeclGroupRef D) {
311
26
  for (auto &Consumer : Consumers)
312
34
    Consumer->HandleTopLevelDeclInObjCContainer(D);
313
26
}
314
315
3.07k
void MultiplexConsumer::HandleImplicitImportDecl(ImportDecl *D) {
316
3.07k
  for (auto &Consumer : Consumers)
317
6.03k
    Consumer->HandleImplicitImportDecl(D);
318
3.07k
}
319
320
1.05k
void MultiplexConsumer::CompleteTentativeDefinition(VarDecl *D) {
321
1.05k
  for (auto &Consumer : Consumers)
322
1.56k
    Consumer->CompleteTentativeDefinition(D);
323
1.05k
}
324
325
3
void MultiplexConsumer::AssignInheritanceModel(CXXRecordDecl *RD) {
326
3
  for (auto &Consumer : Consumers)
327
5
    Consumer->AssignInheritanceModel(RD);
328
3
}
329
330
17
void MultiplexConsumer::HandleVTable(CXXRecordDecl *RD) {
331
17
  for (auto &Consumer : Consumers)
332
20
    Consumer->HandleVTable(RD);
333
17
}
334
335
12.1k
ASTMutationListener *MultiplexConsumer::GetASTMutationListener() {
336
12.1k
  return MutationListener.get();
337
12.1k
}
338
339
2.07k
ASTDeserializationListener *MultiplexConsumer::GetASTDeserializationListener() {
340
2.07k
  return DeserializationListener.get();
341
2.07k
}
342
343
0
void MultiplexConsumer::PrintStats() {
344
0
  for (auto &Consumer : Consumers)
345
0
    Consumer->PrintStats();
346
0
}
347
348
70
bool MultiplexConsumer::shouldSkipFunctionBody(Decl *D) {
349
70
  bool Skip = true;
350
70
  for (auto &Consumer : Consumers)
351
100
    Skip = Skip && 
Consumer->shouldSkipFunctionBody(D)79
;
352
70
  return Skip;
353
70
}
354
355
5.63k
void MultiplexConsumer::InitializeSema(Sema &S) {
356
5.63k
  for (auto &Consumer : Consumers)
357
9.26k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
358
3.60k
      SC->InitializeSema(S);
359
5.63k
}
360
361
5.60k
void MultiplexConsumer::ForgetSema() {
362
5.60k
  for (auto &Consumer : Consumers)
363
9.20k
    if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
364
3.57k
      SC->ForgetSema();
365
5.60k
}