clang  14.0.0git
MultiplexConsumer.h
Go to the documentation of this file.
1 //===-- MultiplexConsumer.h - 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 declares the MultiplexConsumer class, which can be used to
10 // multiplex ASTConsumer and SemaConsumer messages to many consumers.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_FRONTEND_MULTIPLEXCONSUMER_H
15 #define LLVM_CLANG_FRONTEND_MULTIPLEXCONSUMER_H
16 
17 #include "clang/Basic/LLVM.h"
20 #include <memory>
21 #include <vector>
22 
23 namespace clang {
24 
25 class MultiplexASTMutationListener;
26 
27 // This ASTDeserializationListener forwards its notifications to a set of
28 // child listeners.
30 public:
31  // Does NOT take ownership of the elements in L.
33  const std::vector<ASTDeserializationListener *> &L);
34  void ReaderInitialized(ASTReader *Reader) 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 
48 // Has a list of ASTConsumers and calls each of them. Owns its children.
50 public:
51  // Takes ownership of the pointers in C.
52  MultiplexConsumer(std::vector<std::unique_ptr<ASTConsumer>> C);
53  ~MultiplexConsumer() override;
54 
55  // ASTConsumer
56  void Initialize(ASTContext &Context) override;
58  bool HandleTopLevelDecl(DeclGroupRef D) override;
60  void HandleInterestingDecl(DeclGroupRef D) override;
61  void HandleTranslationUnit(ASTContext &Ctx) override;
62  void HandleTagDeclDefinition(TagDecl *D) override;
63  void HandleTagDeclRequiredDefinition(const TagDecl *D) override;
66  void HandleImplicitImportDecl(ImportDecl *D) override;
67  void CompleteTentativeDefinition(VarDecl *D) override;
68  void CompleteExternalDeclaration(VarDecl *D) override;
69  void AssignInheritanceModel(CXXRecordDecl *RD) override;
70  void HandleVTable(CXXRecordDecl *RD) override;
73  void PrintStats() override;
74  bool shouldSkipFunctionBody(Decl *D) override;
75 
76  // SemaConsumer
77  void InitializeSema(Sema &S) override;
78  void ForgetSema() override;
79 
80 private:
81  std::vector<std::unique_ptr<ASTConsumer>> Consumers; // Owns these.
82  std::unique_ptr<MultiplexASTMutationListener> MutationListener;
83  std::unique_ptr<MultiplexASTDeserializationListener> DeserializationListener;
84 };
85 
86 } // end namespace clang
87 
88 #endif
clang::MultiplexConsumer::GetASTDeserializationListener
ASTDeserializationListener * GetASTDeserializationListener() override
If the consumer is interested in entities being deserialized from AST files, it should return a point...
Definition: MultiplexConsumer.cpp:344
clang::MultiplexASTDeserializationListener::SelectorRead
void SelectorRead(serialization::SelectorID iD, Selector Sel) override
A selector was read from the AST file.
Definition: MultiplexConsumer.cpp:58
clang::serialization::TypeIdx
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:88
clang::MultiplexConsumer::shouldSkipFunctionBody
bool shouldSkipFunctionBody(Decl *D) override
This callback is called for each function if the Parser was initialized with SkipFunctionBodies set t...
Definition: MultiplexConsumer.cpp:353
clang::MultiplexConsumer::HandleInterestingDecl
void HandleInterestingDecl(DeclGroupRef D) override
HandleInterestingDecl - Handle the specified interesting declaration.
Definition: MultiplexConsumer.cpp:285
clang::MultiplexConsumer::HandleTagDeclDefinition
void HandleTagDeclDefinition(TagDecl *D) override
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
Definition: MultiplexConsumer.cpp:295
clang::serialization::IdentID
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:134
clang::MultiplexConsumer::~MultiplexConsumer
~MultiplexConsumer() override
Definition: MultiplexConsumer.cpp:261
clang::MultiplexASTDeserializationListener::TypeRead
void TypeRead(serialization::TypeIdx Idx, QualType T) override
A type was deserialized from the AST file.
Definition: MultiplexConsumer.cpp:46
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::MultiplexConsumer::HandleImplicitImportDecl
void HandleImplicitImportDecl(ImportDecl *D) override
Handle an ImportDecl that was implicitly created due to an inclusion directive.
Definition: MultiplexConsumer.cpp:315
clang::MultiplexASTDeserializationListener::MacroDefinitionRead
void MacroDefinitionRead(serialization::PreprocessedEntityID, MacroDefinitionRecord *MD) override
A macro definition was read from the AST file.
Definition: MultiplexConsumer.cpp:64
clang::MultiplexConsumer::PrintStats
void PrintStats() override
PrintStats - If desired, print any statistics.
Definition: MultiplexConsumer.cpp:348
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
clang::MultiplexConsumer::CompleteTentativeDefinition
void CompleteTentativeDefinition(VarDecl *D) override
CompleteTentativeDefinition - Callback invoked at the end of a translation unit to notify the consume...
Definition: MultiplexConsumer.cpp:320
clang::MultiplexConsumer::InitializeSema
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
Definition: MultiplexConsumer.cpp:360
ASTDeserializationListener.h
clang::MultiplexASTDeserializationListener::DeclRead
void DeclRead(serialization::DeclID ID, const Decl *D) override
A decl was deserialized from the AST file.
Definition: MultiplexConsumer.cpp:52
clang::serialization::MacroID
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:140
clang::serialization::SubmoduleID
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:171
clang::MultiplexASTDeserializationListener::IdentifierRead
void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II) override
An identifier was deserialized from the AST file.
Definition: MultiplexConsumer.cpp:34
clang::SemaConsumer
An abstract interface that should be implemented by clients that read ASTs and then require further s...
Definition: SemaConsumer.h:25
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::ImportDecl
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4447
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
clang::MultiplexConsumer
Definition: MultiplexConsumer.h:49
clang::ASTMutationListener
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Definition: ASTMutationListener.h:46
clang::MultiplexConsumer::GetASTMutationListener
ASTMutationListener * GetASTMutationListener() override
If the consumer is interested in entities getting modified after their initial creation,...
Definition: MultiplexConsumer.cpp:340
clang::MultiplexConsumer::MultiplexConsumer
MultiplexConsumer(std::vector< std::unique_ptr< ASTConsumer >> C)
Definition: MultiplexConsumer.cpp:237
clang::MacroDefinitionRecord
Record the location of a macro definition.
Definition: PreprocessingRecord.h:148
clang::MultiplexConsumer::HandleCXXImplicitFunctionInstantiation
void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) override
Invoked when a function is implicitly instantiated.
Definition: MultiplexConsumer.cpp:305
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:876
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3328
clang::MultiplexASTDeserializationListener::ReaderInitialized
void ReaderInitialized(ASTReader *Reader) override
The ASTReader was initialized.
Definition: MultiplexConsumer.cpp:28
clang::MultiplexASTDeserializationListener
Definition: MultiplexConsumer.h:29
clang::MultiplexConsumer::HandleCXXStaticMemberVarInstantiation
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
Definition: MultiplexConsumer.cpp:280
clang::MultiplexConsumer::Initialize
void Initialize(ASTContext &Context) override
Initialize - This is called to initialize the consumer, providing the ASTContext.
Definition: MultiplexConsumer.cpp:263
clang::serialization::PreprocessedEntityID
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:168
clang::MultiplexConsumer::HandleVTable
void HandleVTable(CXXRecordDecl *RD) override
Callback involved at the end of a translation unit to notify the consumer that a vtable for the given...
Definition: MultiplexConsumer.cpp:335
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
clang::MultiplexASTDeserializationListener::MacroRead
void MacroRead(serialization::MacroID ID, MacroInfo *MI) override
A macro was read from the AST file.
Definition: MultiplexConsumer.cpp:40
clang::ASTDeserializationListener
Definition: ASTDeserializationListener.h:30
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::DeclGroupRef
Definition: DeclGroup.h:51
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:355
LLVM.h
clang::MultiplexConsumer::HandleTagDeclRequiredDefinition
void HandleTagDeclRequiredDefinition(const TagDecl *D) override
This callback is invoked the first time each TagDecl is required to be complete.
Definition: MultiplexConsumer.cpp:300
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::MultiplexConsumer::HandleInlineFunctionDefinition
void HandleInlineFunctionDefinition(FunctionDecl *D) override
This callback is invoked each time an inline (method or friend) function definition in a class is com...
Definition: MultiplexConsumer.cpp:275
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:342
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang::MultiplexASTDeserializationListener::ModuleRead
void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override
A module definition was read from the AST file.
Definition: MultiplexConsumer.cpp:70
clang
Definition: CalledOnceCheck.h:17
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:748
clang::MultiplexConsumer::HandleTopLevelDeclInObjCContainer
void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) override
Handle the specified top-level declaration that occurred inside and ObjC container.
Definition: MultiplexConsumer.cpp:310
clang::MultiplexConsumer::HandleTopLevelDecl
bool HandleTopLevelDecl(DeclGroupRef D) override
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: MultiplexConsumer.cpp:268
clang::MultiplexASTDeserializationListener::MultiplexASTDeserializationListener
MultiplexASTDeserializationListener(const std::vector< ASTDeserializationListener * > &L)
Definition: MultiplexConsumer.cpp:23
clang::serialization::DeclID
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:68
clang::MultiplexConsumer::HandleTranslationUnit
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Definition: MultiplexConsumer.cpp:290
clang::serialization::SelectorID
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:153
SemaConsumer.h
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1856
clang::MultiplexConsumer::CompleteExternalDeclaration
void CompleteExternalDeclaration(VarDecl *D) override
CompleteExternalDeclaration - Callback invoked at the end of a translation unit to notify the consume...
Definition: MultiplexConsumer.cpp:325
clang::MultiplexConsumer::AssignInheritanceModel
void AssignInheritanceModel(CXXRecordDecl *RD) override
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
Definition: MultiplexConsumer.cpp:330
clang::MultiplexConsumer::ForgetSema
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
Definition: MultiplexConsumer.cpp:366