2011-01-26 04:34:14 +08:00
|
|
|
//===- MultiplexConsumer.cpp - AST Consumer for PCH Generation --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the MultiplexConsumer class. It also declares and defines
|
|
|
|
// MultiplexASTDeserializationListener and MultiplexASTMutationListener, which
|
|
|
|
// are implementation details of MultiplexConsumer.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Frontend/MultiplexConsumer.h"
|
|
|
|
#include "clang/AST/ASTMutationListener.h"
|
|
|
|
#include "clang/AST/DeclGroup.h"
|
|
|
|
#include "clang/Serialization/ASTDeserializationListener.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
// This ASTDeserializationListener forwards its notifications to a set of
|
|
|
|
// child listeners.
|
|
|
|
class MultiplexASTDeserializationListener
|
|
|
|
: public ASTDeserializationListener {
|
|
|
|
public:
|
|
|
|
// Does NOT take ownership of the elements in L.
|
|
|
|
MultiplexASTDeserializationListener(
|
|
|
|
const std::vector<ASTDeserializationListener*>& L);
|
|
|
|
virtual void ReaderInitialized(ASTReader *Reader);
|
|
|
|
virtual void IdentifierRead(serialization::IdentID ID,
|
|
|
|
IdentifierInfo *II);
|
|
|
|
virtual void TypeRead(serialization::TypeIdx Idx, QualType T);
|
|
|
|
virtual void DeclRead(serialization::DeclID ID, const Decl *D);
|
|
|
|
virtual void SelectorRead(serialization::SelectorID iD, Selector Sel);
|
2011-09-16 02:02:56 +08:00
|
|
|
virtual void MacroDefinitionRead(serialization::PreprocessedEntityID,
|
2011-01-26 04:34:14 +08:00
|
|
|
MacroDefinition *MD);
|
|
|
|
private:
|
|
|
|
std::vector<ASTDeserializationListener*> Listeners;
|
|
|
|
};
|
|
|
|
|
|
|
|
MultiplexASTDeserializationListener::MultiplexASTDeserializationListener(
|
|
|
|
const std::vector<ASTDeserializationListener*>& L)
|
|
|
|
: Listeners(L) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexASTDeserializationListener::ReaderInitialized(
|
|
|
|
ASTReader *Reader) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->ReaderInitialized(Reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexASTDeserializationListener::IdentifierRead(
|
|
|
|
serialization::IdentID ID, IdentifierInfo *II) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->IdentifierRead(ID, II);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexASTDeserializationListener::TypeRead(
|
|
|
|
serialization::TypeIdx Idx, QualType T) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->TypeRead(Idx, T);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexASTDeserializationListener::DeclRead(
|
|
|
|
serialization::DeclID ID, const Decl *D) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->DeclRead(ID, D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexASTDeserializationListener::SelectorRead(
|
|
|
|
serialization::SelectorID ID, Selector Sel) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->SelectorRead(ID, Sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexASTDeserializationListener::MacroDefinitionRead(
|
2011-09-16 02:02:56 +08:00
|
|
|
serialization::PreprocessedEntityID ID, MacroDefinition *MD) {
|
2011-01-26 04:34:14 +08:00
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->MacroDefinitionRead(ID, MD);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This ASTMutationListener forwards its notifications to a set of
|
|
|
|
// child listeners.
|
|
|
|
class MultiplexASTMutationListener : public ASTMutationListener {
|
|
|
|
public:
|
|
|
|
// Does NOT take ownership of the elements in L.
|
2012-02-11 04:10:38 +08:00
|
|
|
MultiplexASTMutationListener(ArrayRef<ASTMutationListener*> L);
|
2011-01-26 04:34:14 +08:00
|
|
|
virtual void CompletedTagDefinition(const TagDecl *D);
|
|
|
|
virtual void AddedVisibleDecl(const DeclContext *DC, const Decl *D);
|
|
|
|
virtual void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D);
|
|
|
|
virtual void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
|
|
|
|
const ClassTemplateSpecializationDecl *D);
|
2011-04-14 22:07:59 +08:00
|
|
|
virtual void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
|
|
|
|
const FunctionDecl *D);
|
2013-05-11 13:45:24 +08:00
|
|
|
virtual void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType);
|
2011-04-25 00:28:06 +08:00
|
|
|
virtual void CompletedImplicitDefinition(const FunctionDecl *D);
|
2011-04-29 16:19:30 +08:00
|
|
|
virtual void StaticDataMemberInstantiated(const VarDecl *D);
|
2012-02-11 04:10:36 +08:00
|
|
|
virtual void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
|
|
|
|
const ObjCInterfaceDecl *IFD);
|
|
|
|
virtual void AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop,
|
|
|
|
const ObjCPropertyDecl *OrigProp,
|
|
|
|
const ObjCCategoryDecl *ClassExt);
|
2011-01-26 04:34:14 +08:00
|
|
|
private:
|
|
|
|
std::vector<ASTMutationListener*> Listeners;
|
|
|
|
};
|
|
|
|
|
|
|
|
MultiplexASTMutationListener::MultiplexASTMutationListener(
|
2012-02-11 04:10:38 +08:00
|
|
|
ArrayRef<ASTMutationListener*> L)
|
|
|
|
: Listeners(L.begin(), L.end()) {
|
2011-01-26 04:34:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexASTMutationListener::CompletedTagDefinition(const TagDecl *D) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->CompletedTagDefinition(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexASTMutationListener::AddedVisibleDecl(
|
|
|
|
const DeclContext *DC, const Decl *D) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->AddedVisibleDecl(DC, D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexASTMutationListener::AddedCXXImplicitMember(
|
|
|
|
const CXXRecordDecl *RD, const Decl *D) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->AddedCXXImplicitMember(RD, D);
|
|
|
|
}
|
|
|
|
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
|
|
|
|
const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
|
|
|
|
}
|
2011-04-14 22:07:59 +08:00
|
|
|
void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
|
|
|
|
const FunctionTemplateDecl *TD, const FunctionDecl *D) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
|
|
|
|
}
|
2013-05-11 13:45:24 +08:00
|
|
|
void MultiplexASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
|
|
|
|
QualType ReturnType) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->DeducedReturnType(FD, ReturnType);
|
|
|
|
}
|
2011-04-25 00:28:06 +08:00
|
|
|
void MultiplexASTMutationListener::CompletedImplicitDefinition(
|
|
|
|
const FunctionDecl *D) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->CompletedImplicitDefinition(D);
|
|
|
|
}
|
2011-04-29 16:19:30 +08:00
|
|
|
void MultiplexASTMutationListener::StaticDataMemberInstantiated(
|
|
|
|
const VarDecl *D) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->StaticDataMemberInstantiated(D);
|
|
|
|
}
|
2012-02-11 04:10:36 +08:00
|
|
|
void MultiplexASTMutationListener::AddedObjCCategoryToInterface(
|
|
|
|
const ObjCCategoryDecl *CatD,
|
|
|
|
const ObjCInterfaceDecl *IFD) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->AddedObjCCategoryToInterface(CatD, IFD);
|
|
|
|
}
|
|
|
|
void MultiplexASTMutationListener::AddedObjCPropertyInClassExtension(
|
|
|
|
const ObjCPropertyDecl *Prop,
|
|
|
|
const ObjCPropertyDecl *OrigProp,
|
|
|
|
const ObjCCategoryDecl *ClassExt) {
|
|
|
|
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
|
|
|
|
Listeners[i]->AddedObjCPropertyInClassExtension(Prop, OrigProp, ClassExt);
|
|
|
|
}
|
2011-01-26 04:34:14 +08:00
|
|
|
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
|
2012-02-04 13:23:00 +08:00
|
|
|
MultiplexConsumer::MultiplexConsumer(ArrayRef<ASTConsumer*> C)
|
|
|
|
: Consumers(C.begin(), C.end()),
|
|
|
|
MutationListener(0), DeserializationListener(0) {
|
2011-01-26 04:34:14 +08:00
|
|
|
// Collect the mutation listeners and deserialization listeners of all
|
|
|
|
// children, and create a multiplex listener each if so.
|
|
|
|
std::vector<ASTMutationListener*> mutationListeners;
|
|
|
|
std::vector<ASTDeserializationListener*> serializationListeners;
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i) {
|
|
|
|
ASTMutationListener* mutationListener =
|
|
|
|
Consumers[i]->GetASTMutationListener();
|
|
|
|
if (mutationListener)
|
|
|
|
mutationListeners.push_back(mutationListener);
|
|
|
|
ASTDeserializationListener* serializationListener =
|
|
|
|
Consumers[i]->GetASTDeserializationListener();
|
|
|
|
if (serializationListener)
|
|
|
|
serializationListeners.push_back(serializationListener);
|
|
|
|
}
|
|
|
|
if (mutationListeners.size()) {
|
|
|
|
MutationListener.reset(new MultiplexASTMutationListener(mutationListeners));
|
|
|
|
}
|
|
|
|
if (serializationListeners.size()) {
|
|
|
|
DeserializationListener.reset(
|
|
|
|
new MultiplexASTDeserializationListener(serializationListeners));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiplexConsumer::~MultiplexConsumer() {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
delete Consumers[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexConsumer::Initialize(ASTContext &Context) {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
Consumers[i]->Initialize(Context);
|
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:59 +08:00
|
|
|
bool MultiplexConsumer::HandleTopLevelDecl(DeclGroupRef D) {
|
2011-11-28 12:56:00 +08:00
|
|
|
bool Continue = true;
|
2011-01-26 04:34:14 +08:00
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
2011-11-28 12:56:00 +08:00
|
|
|
Continue = Continue && Consumers[i]->HandleTopLevelDecl(D);
|
|
|
|
return Continue;
|
2011-01-26 04:34:14 +08:00
|
|
|
}
|
|
|
|
|
2012-03-08 23:51:03 +08:00
|
|
|
void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
|
2012-03-05 18:54:55 +08:00
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
2012-03-08 23:51:03 +08:00
|
|
|
Consumers[i]->HandleCXXStaticMemberVarInstantiation(VD);
|
2012-03-05 18:54:55 +08:00
|
|
|
}
|
|
|
|
|
2011-01-26 04:34:14 +08:00
|
|
|
void MultiplexConsumer::HandleInterestingDecl(DeclGroupRef D) {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
Consumers[i]->HandleInterestingDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexConsumer::HandleTranslationUnit(ASTContext &Ctx) {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
Consumers[i]->HandleTranslationUnit(Ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexConsumer::HandleTagDeclDefinition(TagDecl *D) {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
Consumers[i]->HandleTagDeclDefinition(D);
|
|
|
|
}
|
|
|
|
|
2012-02-11 04:10:44 +08:00
|
|
|
void MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D){
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
Consumers[i]->HandleCXXImplicitFunctionInstantiation(D);
|
|
|
|
}
|
|
|
|
|
2011-11-28 12:56:00 +08:00
|
|
|
void MultiplexConsumer::HandleTopLevelDeclInObjCContainer(DeclGroupRef D) {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
Consumers[i]->HandleTopLevelDeclInObjCContainer(D);
|
|
|
|
}
|
|
|
|
|
2011-01-26 04:34:14 +08:00
|
|
|
void MultiplexConsumer::CompleteTentativeDefinition(VarDecl *D) {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
Consumers[i]->CompleteTentativeDefinition(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexConsumer::HandleVTable(
|
|
|
|
CXXRecordDecl *RD, bool DefinitionRequired) {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
Consumers[i]->HandleVTable(RD, DefinitionRequired);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTMutationListener *MultiplexConsumer::GetASTMutationListener() {
|
|
|
|
return MutationListener.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTDeserializationListener *MultiplexConsumer::GetASTDeserializationListener() {
|
|
|
|
return DeserializationListener.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexConsumer::PrintStats() {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
Consumers[i]->PrintStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexConsumer::InitializeSema(Sema &S) {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumers[i]))
|
|
|
|
SC->InitializeSema(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiplexConsumer::ForgetSema() {
|
|
|
|
for (size_t i = 0, e = Consumers.size(); i != e; ++i)
|
|
|
|
if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumers[i]))
|
|
|
|
SC->ForgetSema();
|
|
|
|
}
|