clang  3.7.0
MultiplexConsumer.cpp
Go to the documentation of this file.
1 //===- MultiplexConsumer.cpp - AST Consumer for PCH Generation --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the MultiplexConsumer class. It also declares and defines
11 // MultiplexASTDeserializationListener and MultiplexASTMutationListener, which
12 // are implementation details of MultiplexConsumer.
13 //
14 //===----------------------------------------------------------------------===//
15 
18 #include "clang/AST/DeclGroup.h"
20 
21 using namespace clang;
22 
23 namespace clang {
24 
25 // This ASTDeserializationListener forwards its notifications to a set of
26 // child listeners.
29 public:
30  // Does NOT take ownership of the elements in L.
32  const std::vector<ASTDeserializationListener*>& L);
33  void ReaderInitialized(ASTReader *Reader) override;
35  IdentifierInfo *II) override;
36  void MacroRead(serialization::MacroID ID, MacroInfo *MI) override;
37  void TypeRead(serialization::TypeIdx Idx, QualType T) override;
38  void DeclRead(serialization::DeclID ID, const Decl *D) override;
39  void SelectorRead(serialization::SelectorID iD, Selector Sel) override;
41  MacroDefinitionRecord *MD) override;
42  void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
43 
44 private:
45  std::vector<ASTDeserializationListener *> Listeners;
46 };
47 
49  const std::vector<ASTDeserializationListener*>& L)
50  : Listeners(L) {
51 }
52 
54  ASTReader *Reader) {
55  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
56  Listeners[i]->ReaderInitialized(Reader);
57 }
58 
61  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
62  Listeners[i]->IdentifierRead(ID, II);
63 }
64 
67  for (auto &Listener : Listeners)
68  Listener->MacroRead(ID, MI);
69 }
70 
73  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
74  Listeners[i]->TypeRead(Idx, T);
75 }
76 
78  serialization::DeclID ID, const Decl *D) {
79  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
80  Listeners[i]->DeclRead(ID, D);
81 }
82 
85  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
86  Listeners[i]->SelectorRead(ID, Sel);
87 }
88 
91  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
92  Listeners[i]->MacroDefinitionRead(ID, MD);
93 }
94 
97  for (auto &Listener : Listeners)
98  Listener->ModuleRead(ID, Mod);
99 }
100 
101 // This ASTMutationListener forwards its notifications to a set of
102 // child listeners.
104 public:
105  // Does NOT take ownership of the elements in L.
107  void CompletedTagDefinition(const TagDecl *D) override;
108  void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override;
109  void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override;
111  const ClassTemplateSpecializationDecl *D) override;
113  const VarTemplateSpecializationDecl *D) override;
115  const FunctionDecl *D) override;
116  void ResolvedExceptionSpec(const FunctionDecl *FD) override;
117  void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override;
119  const FunctionDecl *Delete) override;
120  void CompletedImplicitDefinition(const FunctionDecl *D) override;
121  void StaticDataMemberInstantiated(const VarDecl *D) override;
123  const ObjCInterfaceDecl *IFD) override;
124  void FunctionDefinitionInstantiated(const FunctionDecl *D) override;
126  const ObjCPropertyDecl *OrigProp,
127  const ObjCCategoryDecl *ClassExt) override;
128  void DeclarationMarkedUsed(const Decl *D) override;
129  void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
130  void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
131  void AddedAttributeToRecord(const Attr *Attr,
132  const RecordDecl *Record) override;
133 
134 private:
135  std::vector<ASTMutationListener*> Listeners;
136 };
137 
140  : Listeners(L.begin(), L.end()) {
141 }
142 
144  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
145  Listeners[i]->CompletedTagDefinition(D);
146 }
147 
149  const DeclContext *DC, const Decl *D) {
150  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
151  Listeners[i]->AddedVisibleDecl(DC, D);
152 }
153 
155  const CXXRecordDecl *RD, const Decl *D) {
156  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
157  Listeners[i]->AddedCXXImplicitMember(RD, D);
158 }
161  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
162  Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
163 }
165  const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) {
166  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
167  Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
168 }
170  const FunctionTemplateDecl *TD, const FunctionDecl *D) {
171  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
172  Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
173 }
175  const FunctionDecl *FD) {
176  for (auto &Listener : Listeners)
177  Listener->ResolvedExceptionSpec(FD);
178 }
180  QualType ReturnType) {
181  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
182  Listeners[i]->DeducedReturnType(FD, ReturnType);
183 }
185  const CXXDestructorDecl *DD, const FunctionDecl *Delete) {
186  for (auto *L : Listeners)
187  L->ResolvedOperatorDelete(DD, Delete);
188 }
190  const FunctionDecl *D) {
191  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
192  Listeners[i]->CompletedImplicitDefinition(D);
193 }
195  const VarDecl *D) {
196  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
197  Listeners[i]->StaticDataMemberInstantiated(D);
198 }
200  const ObjCCategoryDecl *CatD,
201  const ObjCInterfaceDecl *IFD) {
202  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
203  Listeners[i]->AddedObjCCategoryToInterface(CatD, IFD);
204 }
206  const FunctionDecl *D) {
207  for (auto &Listener : Listeners)
208  Listener->FunctionDefinitionInstantiated(D);
209 }
211  const ObjCPropertyDecl *Prop,
212  const ObjCPropertyDecl *OrigProp,
213  const ObjCCategoryDecl *ClassExt) {
214  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
215  Listeners[i]->AddedObjCPropertyInClassExtension(Prop, OrigProp, ClassExt);
216 }
218  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
219  Listeners[i]->DeclarationMarkedUsed(D);
220 }
222  const Decl *D) {
223  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
224  Listeners[i]->DeclarationMarkedOpenMPThreadPrivate(D);
225 }
227  Module *M) {
228  for (auto *L : Listeners)
229  L->RedefinedHiddenDefinition(D, M);
230 }
231 
233  const Attr *Attr,
234  const RecordDecl *Record) {
235  for (auto *L : Listeners)
236  L->AddedAttributeToRecord(Attr, Record);
237 }
238 
239 } // end namespace clang
240 
241 MultiplexConsumer::MultiplexConsumer(
242  std::vector<std::unique_ptr<ASTConsumer>> C)
243  : Consumers(std::move(C)), MutationListener(), DeserializationListener() {
244  // Collect the mutation listeners and deserialization listeners of all
245  // children, and create a multiplex listener each if so.
246  std::vector<ASTMutationListener*> mutationListeners;
247  std::vector<ASTDeserializationListener*> serializationListeners;
248  for (auto &Consumer : Consumers) {
249  if (auto *mutationListener = Consumer->GetASTMutationListener())
250  mutationListeners.push_back(mutationListener);
251  if (auto *serializationListener = Consumer->GetASTDeserializationListener())
252  serializationListeners.push_back(serializationListener);
253  }
254  if (!mutationListeners.empty()) {
255  MutationListener =
256  llvm::make_unique<MultiplexASTMutationListener>(mutationListeners);
257  }
258  if (!serializationListeners.empty()) {
259  DeserializationListener =
260  llvm::make_unique<MultiplexASTDeserializationListener>(
261  serializationListeners);
262  }
263 }
264 
266 
268  for (auto &Consumer : Consumers)
269  Consumer->Initialize(Context);
270 }
271 
273  bool Continue = true;
274  for (auto &Consumer : Consumers)
275  Continue = Continue && Consumer->HandleTopLevelDecl(D);
276  return Continue;
277 }
278 
280  for (auto &Consumer : Consumers)
281  Consumer->HandleInlineMethodDefinition(D);
282 }
283 
285  for (auto &Consumer : Consumers)
286  Consumer->HandleCXXStaticMemberVarInstantiation(VD);
287 }
288 
290  for (auto &Consumer : Consumers)
291  Consumer->HandleInterestingDecl(D);
292 }
293 
295  for (auto &Consumer : Consumers)
296  Consumer->HandleTranslationUnit(Ctx);
297 }
298 
300  for (auto &Consumer : Consumers)
301  Consumer->HandleTagDeclDefinition(D);
302 }
303 
305  for (auto &Consumer : Consumers)
306  Consumer->HandleTagDeclRequiredDefinition(D);
307 }
308 
310  for (auto &Consumer : Consumers)
311  Consumer->HandleCXXImplicitFunctionInstantiation(D);
312 }
313 
315  for (auto &Consumer : Consumers)
316  Consumer->HandleTopLevelDeclInObjCContainer(D);
317 }
318 
320  for (auto &Consumer : Consumers)
321  Consumer->HandleImplicitImportDecl(D);
322 }
323 
325  for (auto &Consumer : Consumers)
326  Consumer->HandleLinkerOptionPragma(Opts);
327 }
328 
329 void MultiplexConsumer::HandleDetectMismatch(llvm::StringRef Name, llvm::StringRef Value) {
330  for (auto &Consumer : Consumers)
331  Consumer->HandleDetectMismatch(Name, Value);
332 }
333 
334 void MultiplexConsumer::HandleDependentLibrary(llvm::StringRef Lib) {
335  for (auto &Consumer : Consumers)
336  Consumer->HandleDependentLibrary(Lib);
337 }
338 
340  for (auto &Consumer : Consumers)
341  Consumer->CompleteTentativeDefinition(D);
342 }
343 
345  for (auto &Consumer : Consumers)
346  Consumer->HandleVTable(RD);
347 }
348 
350  return MutationListener.get();
351 }
352 
354  return DeserializationListener.get();
355 }
356 
358  for (auto &Consumer : Consumers)
359  Consumer->PrintStats();
360 }
361 
363  for (auto &Consumer : Consumers)
364  if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
365  SC->InitializeSema(S);
366 }
367 
369  for (auto &Consumer : Consumers)
370  if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer.get()))
371  SC->ForgetSema();
372 }
void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override
An implicit member was added after the definition was completed.
void DeclarationMarkedUsed(const Decl *D) override
A declaration is marked used which was not previously marked used.
ASTMutationListener * GetASTMutationListener() override
If the consumer is interested in entities getting modified after their initial creation, it should return a pointer to an ASTMutationListener here.
void CompletedImplicitDefinition(const FunctionDecl *D) override
An implicit member got a definition.
Smart pointer class that efficiently represents Objective-C method names.
void SelectorRead(serialization::SelectorID iD, Selector Sel) override
A selector was read from the AST file.
void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) override
Handle the specified top-level declaration that occurred inside and ObjC container. The default implementation ignored them.
void TypeRead(serialization::TypeIdx Idx, QualType T) override
A type was deserialized from the AST file. The ID here has the qualifier bits already removed...
void ResolvedOperatorDelete(const CXXDestructorDecl *DD, const FunctionDecl *Delete) override
A virtual destructor's operator delete has been resolved.
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:125
void ResolvedExceptionSpec(const FunctionDecl *FD) override
A function's exception specification has been evaluated or instantiated.
void HandleDependentLibrary(llvm::StringRef Lib) override
Handle a dependent library created by a pragma in the source. Currently this only exists to support M...
void HandleVTable(CXXRecordDecl *RD) override
Callback involved at the end of a translation unit to notify the consumer that a vtable for the given...
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:62
Declaration of a variable template.
MultiplexASTDeserializationListener(const std::vector< ASTDeserializationListener * > &L)
void DeclRead(serialization::DeclID ID, const Decl *D) override
A decl was deserialized from the AST file.
Represents a variable template specialization, which refers to a variable template with a given set o...
MultiplexASTMutationListener(ArrayRef< ASTMutationListener * > L)
void MacroDefinitionRead(serialization::PreprocessedEntityID, MacroDefinitionRecord *MD) override
A macro definition was read from the AST file.
void CompleteTentativeDefinition(VarDecl *D) override
void AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop, const ObjCPropertyDecl *OrigProp, const ObjCCategoryDecl *ClassExt) override
A objc class extension redeclared or introduced a property.
Represents a class template specialization, which refers to a class template with a given set of temp...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
Record the location of a macro definition.
void StaticDataMemberInstantiated(const VarDecl *D) override
A static data member was implicitly instantiated.
void PrintStats() override
PrintStats - If desired, print any statistics.
void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override
A declaration is marked as OpenMP threadprivate which was not previously marked as threadprivate...
Describes a module or submodule.
Definition: Basic/Module.h:49
An abstract interface that should be implemented by clients that read ASTs and then require further s...
Definition: SemaConsumer.h:26
bool HandleTopLevelDecl(DeclGroupRef D) override
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:162
void AddedAttributeToRecord(const Attr *Attr, const RecordDecl *Record) override
An attribute was added to a RecordDecl.
void HandleTagDeclRequiredDefinition(const TagDecl *D) override
This callback is invoked the first time each TagDecl is required to be complete.
Represents an ObjC class declaration.
Definition: DeclObjC.h:851
void ReaderInitialized(ASTReader *Reader) override
The ASTReader was initialized.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:258
ASTContext * Context
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
void Initialize(ASTContext &Context) override
void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) override
A template specialization (or partial one) was added to the template declaration. ...
void FunctionDefinitionInstantiated(const FunctionDecl *D) override
A function template's definition was instantiated.
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2358
void HandleTagDeclDefinition(TagDecl *D) override
void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override
A function's return type has been deduced.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
void HandleInterestingDecl(DeclGroupRef D) override
void HandleLinkerOptionPragma(llvm::StringRef Opts) override
Handle a pragma that appends to Linker Options. Currently this only exists to support Microsoft's #pr...
void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II) override
An identifier was deserialized from the AST file.
void CompletedTagDefinition(const TagDecl *D) override
A new TagDecl definition was completed.
void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) override
Invoked when a function is implicitly instantiated. Note that at this point point it does not have a ...
void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override
A module definition was read from the AST file.
void HandleDetectMismatch(llvm::StringRef Name, llvm::StringRef Value) override
Handle a pragma that emits a mismatch identifier and value to the object file for the linker to work ...
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2694
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1717
void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override
A new declaration with name has been added to a DeclContext.
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:131
void HandleImplicitImportDecl(ImportDecl *D) override
Handle an ImportDecl that was implicitly created due to an inclusion directive. The default implement...
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:2424
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:3704
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:302
void HandleInlineMethodDefinition(CXXMethodDecl *D) override
This callback is invoked each time an inline method definition is completed.
Encapsulates the data about a macro definition (e.g. its tokens).
Definition: MacroInfo.h:34
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:159
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:144
void MacroRead(serialization::MacroID ID, MacroInfo *MI) override
A macro was read from the AST file.
Declaration of a class template.
void HandleTranslationUnit(ASTContext &Ctx) override
ASTDeserializationListener * GetASTDeserializationListener() override
If the consumer is interested in entities being deserialized from AST files, it should return a point...
void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, const ObjCInterfaceDecl *IFD) override
A new objc category class was added for an interface.
Declaration of a template function.
Definition: DeclTemplate.h:821
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:85
Attr - This represents one attribute.
Definition: Attr.h:44
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override
A definition has been made visible by being redefined locally.