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" 18 #include "clang/Sema/SemaConsumer.h" 19 #include "clang/Serialization/ASTDeserializationListener.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. 29 class MultiplexASTDeserializationListener : public ASTDeserializationListener { 30 public: 31 // Does NOT take ownership of the elements in L. 32 MultiplexASTDeserializationListener( 33 const std::vector<ASTDeserializationListener *> &L); 34 void ReaderInitialized(ASTReader *Reader) override; 35 void IdentifierRead(serialization::IdentifierID ID, IdentifierInfo *II) override; 36 void MacroRead(serialization::MacroID ID, MacroInfo *MI) override; 37 void TypeRead(serialization::TypeIdx Idx, QualType T) override; 38 void DeclRead(GlobalDeclID ID, const Decl *D) override; 39 void SelectorRead(serialization::SelectorID iD, Selector Sel) override; 40 void MacroDefinitionRead(serialization::PreprocessedEntityID, 41 MacroDefinitionRecord *MD) override; 42 void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override; 43 void ModuleImportRead(serialization::SubmoduleID ID, 44 SourceLocation ImportLoc) override; 45 46 private: 47 std::vector<ASTDeserializationListener *> Listeners; 48 }; 49 50 // Has a list of ASTConsumers and calls each of them. Owns its children. 51 class MultiplexConsumer : public SemaConsumer { 52 public: 53 // Takes ownership of the pointers in C. 54 MultiplexConsumer(std::vector<std::unique_ptr<ASTConsumer>> C); 55 ~MultiplexConsumer() override; 56 57 // ASTConsumer 58 void Initialize(ASTContext &Context) override; 59 void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override; 60 bool HandleTopLevelDecl(DeclGroupRef D) override; 61 void HandleInlineFunctionDefinition(FunctionDecl *D) override; 62 void HandleInterestingDecl(DeclGroupRef D) override; 63 void HandleTranslationUnit(ASTContext &Ctx) override; 64 void HandleTagDeclDefinition(TagDecl *D) override; 65 void HandleTagDeclRequiredDefinition(const TagDecl *D) override; 66 void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) override; 67 void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) override; 68 void HandleImplicitImportDecl(ImportDecl *D) override; 69 void CompleteTentativeDefinition(VarDecl *D) override; 70 void CompleteExternalDeclaration(DeclaratorDecl *D) override; 71 void AssignInheritanceModel(CXXRecordDecl *RD) override; 72 void HandleVTable(CXXRecordDecl *RD) override; 73 ASTMutationListener *GetASTMutationListener() override; 74 ASTDeserializationListener *GetASTDeserializationListener() override; 75 void PrintStats() override; 76 bool shouldSkipFunctionBody(Decl *D) override; 77 78 // SemaConsumer 79 void InitializeSema(Sema &S) override; 80 void ForgetSema() override; 81 82 private: 83 std::vector<std::unique_ptr<ASTConsumer>> Consumers; // Owns these. 84 std::unique_ptr<MultiplexASTMutationListener> MutationListener; 85 std::unique_ptr<MultiplexASTDeserializationListener> DeserializationListener; 86 }; 87 88 } // end namespace clang 89 90 #endif 91