forked from OSchip/llvm-project
Use the ASTMutationListener to track added template specializations in a chained PCH.
llvm-svn: 117533
This commit is contained in:
parent
2efaf11695
commit
402dbbbd66
|
@ -14,9 +14,11 @@
|
|||
#define LLVM_CLANG_AST_ASTMUTATIONLISTENER_H
|
||||
|
||||
namespace clang {
|
||||
class Decl;
|
||||
class TagDecl;
|
||||
class CXXRecordDecl;
|
||||
class CXXMethodDecl;
|
||||
class ClassTemplateDecl;
|
||||
class ClassTemplateSpecializationDecl;
|
||||
|
||||
/// \brief An abstract interface that should be implemented by listeners
|
||||
/// that want to be notified when an AST entity gets modified after its
|
||||
|
@ -30,6 +32,11 @@ public:
|
|||
|
||||
/// \brief An implicit member was added after the definition was completed.
|
||||
virtual void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) {}
|
||||
|
||||
/// \brief A template specialization (or partial one) was added to the
|
||||
/// template declaration.
|
||||
virtual void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
|
||||
const ClassTemplateSpecializationDecl *D) {}
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
|
|
|
@ -1697,9 +1697,7 @@ public:
|
|||
|
||||
/// \brief Insert the specified specialization knowing that it is not already
|
||||
/// in. InsertPos must be obtained from findSpecialization.
|
||||
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos) {
|
||||
getSpecializations().InsertNode(D, InsertPos);
|
||||
}
|
||||
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos);
|
||||
|
||||
ClassTemplateDecl *getCanonicalDecl() {
|
||||
return redeclarable_base::getCanonicalDecl();
|
||||
|
@ -1733,9 +1731,7 @@ public:
|
|||
/// \brief Insert the specified partial specialization knowing that it is not
|
||||
/// already in. InsertPos must be obtained from findPartialSpecialization.
|
||||
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D,
|
||||
void *InsertPos) {
|
||||
getPartialSpecializations().InsertNode(D, InsertPos);
|
||||
}
|
||||
void *InsertPos);
|
||||
|
||||
/// \brief Return the next partial specialization sequence number.
|
||||
unsigned getNextPartialSpecSequenceNumber() {
|
||||
|
|
|
@ -327,17 +327,13 @@ namespace clang {
|
|||
/// In practice, this should only be used for the TU and namespaces.
|
||||
UPDATE_VISIBLE = 34,
|
||||
|
||||
/// \brief Record code for template specializations introduced after
|
||||
/// serializations of the original template decl.
|
||||
ADDITIONAL_TEMPLATE_SPECIALIZATIONS = 35,
|
||||
|
||||
/// \brief Record for offsets of DECL_UPDATES records for declarations
|
||||
/// that were modified after being deserialized and need updates.
|
||||
DECL_UPDATE_OFFSETS = 36,
|
||||
DECL_UPDATE_OFFSETS = 35,
|
||||
|
||||
/// \brief Record of updates for a declaration that was modified after
|
||||
/// being deserialized.
|
||||
DECL_UPDATES = 37
|
||||
DECL_UPDATES = 36
|
||||
};
|
||||
|
||||
/// \brief Record types used within a source manager block.
|
||||
|
|
|
@ -458,16 +458,6 @@ private:
|
|||
/// most recent declarations in another AST file.
|
||||
FirstLatestDeclIDMap FirstLatestDeclIDs;
|
||||
|
||||
typedef llvm::SmallVector<serialization::DeclID, 4>
|
||||
AdditionalTemplateSpecializations;
|
||||
typedef llvm::DenseMap<serialization::DeclID,
|
||||
AdditionalTemplateSpecializations>
|
||||
AdditionalTemplateSpecializationsMap;
|
||||
|
||||
/// \brief Additional specializations (including partial) of templates that
|
||||
/// were introduced after the template was serialized.
|
||||
AdditionalTemplateSpecializationsMap AdditionalTemplateSpecializationsPending;
|
||||
|
||||
/// \brief Read the records that describe the contents of declcontexts.
|
||||
bool ReadDeclContextStorage(llvm::BitstreamCursor &Cursor,
|
||||
const std::pair<uint64_t, uint64_t> &Offsets,
|
||||
|
|
|
@ -236,16 +236,6 @@ private:
|
|||
llvm::SmallVector<std::pair<serialization::DeclID, uint64_t>, 16>
|
||||
ReplacedDecls;
|
||||
|
||||
typedef llvm::SmallVector<serialization::DeclID, 4>
|
||||
AdditionalTemplateSpecializationsList;
|
||||
typedef llvm::DenseMap<serialization::DeclID,
|
||||
AdditionalTemplateSpecializationsList>
|
||||
AdditionalTemplateSpecializationsMap;
|
||||
|
||||
/// \brief Additional specializations (including partial) of templates that
|
||||
/// were introduced after the template was serialized.
|
||||
AdditionalTemplateSpecializationsMap AdditionalTemplateSpecializations;
|
||||
|
||||
/// \brief Statements that we've encountered while serializing a
|
||||
/// declaration or type.
|
||||
llvm::SmallVector<Stmt *, 16> StmtsToEmit;
|
||||
|
@ -296,7 +286,6 @@ private:
|
|||
void WriteDeclUpdatesBlocks();
|
||||
void WriteDeclReplacementsBlock();
|
||||
void WriteDeclContextVisibleUpdate(const DeclContext *DC);
|
||||
void WriteAdditionalTemplateSpecializations();
|
||||
|
||||
unsigned ParmVarDeclAbbrev;
|
||||
unsigned DeclContextLexicalAbbrev;
|
||||
|
@ -459,13 +448,6 @@ public:
|
|||
UpdatedNamespaces.insert(NS);
|
||||
}
|
||||
|
||||
/// \brief Record a template specialization or partial specialization of
|
||||
/// a template from a previous PCH file.
|
||||
void AddAdditionalTemplateSpecialization(serialization::DeclID Templ,
|
||||
serialization::DeclID Spec) {
|
||||
AdditionalTemplateSpecializations[Templ].push_back(Spec);
|
||||
}
|
||||
|
||||
/// \brief Note that the identifier II occurs at the given offset
|
||||
/// within the identifier table.
|
||||
void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset);
|
||||
|
@ -515,6 +497,8 @@ public:
|
|||
// ASTMutationListener implementation.
|
||||
virtual void CompletedTagDefinition(const TagDecl *D);
|
||||
virtual void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D);
|
||||
virtual void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
|
||||
const ClassTemplateSpecializationDecl *D);
|
||||
};
|
||||
|
||||
/// \brief AST and semantic-analysis consumer that generates a
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "clang/AST/Expr.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/TypeLoc.h"
|
||||
#include "clang/AST/ASTMutationListener.h"
|
||||
#include "clang/Basic/IdentifierTable.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
using namespace clang;
|
||||
|
@ -225,6 +226,13 @@ ClassTemplateDecl::findSpecialization(const TemplateArgument *Args,
|
|||
return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
|
||||
}
|
||||
|
||||
void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D,
|
||||
void *InsertPos) {
|
||||
getSpecializations().InsertNode(D, InsertPos);
|
||||
if (ASTMutationListener *L = getASTMutationListener())
|
||||
L->AddedCXXTemplateSpecialization(this, D);
|
||||
}
|
||||
|
||||
ClassTemplatePartialSpecializationDecl *
|
||||
ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args,
|
||||
unsigned NumArgs,
|
||||
|
@ -233,6 +241,14 @@ ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args,
|
|||
InsertPos);
|
||||
}
|
||||
|
||||
void ClassTemplateDecl::AddPartialSpecialization(
|
||||
ClassTemplatePartialSpecializationDecl *D,
|
||||
void *InsertPos) {
|
||||
getPartialSpecializations().InsertNode(D, InsertPos);
|
||||
if (ASTMutationListener *L = getASTMutationListener())
|
||||
L->AddedCXXTemplateSpecialization(this, D);
|
||||
}
|
||||
|
||||
void ClassTemplateDecl::getPartialSpecializations(
|
||||
llvm::SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) {
|
||||
llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &PartialSpecs
|
||||
|
|
|
@ -22,7 +22,8 @@ namespace serialization {
|
|||
|
||||
enum DeclUpdateKind {
|
||||
UPD_CXX_SET_DEFINITIONDATA,
|
||||
UPD_CXX_ADDED_IMPLICIT_MEMBER
|
||||
UPD_CXX_ADDED_IMPLICIT_MEMBER,
|
||||
UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION
|
||||
};
|
||||
|
||||
TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);
|
||||
|
|
|
@ -2069,13 +2069,6 @@ ASTReader::ReadASTBlock(PerFileData &F) {
|
|||
std::make_pair(&F, Record[I+1]);
|
||||
break;
|
||||
}
|
||||
|
||||
case ADDITIONAL_TEMPLATE_SPECIALIZATIONS: {
|
||||
AdditionalTemplateSpecializations &ATS =
|
||||
AdditionalTemplateSpecializationsPending[Record[0]];
|
||||
ATS.insert(ATS.end(), Record.begin()+1, Record.end());
|
||||
break;
|
||||
}
|
||||
}
|
||||
First = false;
|
||||
}
|
||||
|
|
|
@ -1553,20 +1553,6 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If this is a template, read additional specializations that may be in a
|
||||
// different part of the chain.
|
||||
if (isa<RedeclarableTemplateDecl>(D)) {
|
||||
AdditionalTemplateSpecializationsMap::iterator F =
|
||||
AdditionalTemplateSpecializationsPending.find(ID);
|
||||
if (F != AdditionalTemplateSpecializationsPending.end()) {
|
||||
for (AdditionalTemplateSpecializations::iterator I = F->second.begin(),
|
||||
E = F->second.end();
|
||||
I != E; ++I)
|
||||
GetDecl(*I);
|
||||
AdditionalTemplateSpecializationsPending.erase(F);
|
||||
}
|
||||
}
|
||||
assert(Idx == Record.size());
|
||||
|
||||
// The declaration may have been modified by files later in the chain.
|
||||
|
@ -1617,6 +1603,10 @@ void ASTDeclReader::UpdateDecl(Decl *D, const RecordData &Record) {
|
|||
case UPD_CXX_ADDED_IMPLICIT_MEMBER:
|
||||
cast<CXXRecordDecl>(D)->addedMember(Reader.GetDecl(Record[Idx++]));
|
||||
break;
|
||||
|
||||
case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
|
||||
// It will be added to the template's specializations set when loaded.
|
||||
Reader.GetDecl(Record[Idx++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2181,21 +2181,6 @@ void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) {
|
|||
Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str());
|
||||
}
|
||||
|
||||
/// \brief Write ADDITIONAL_TEMPLATE_SPECIALIZATIONS blocks for all templates
|
||||
/// that have new specializations in the current AST file.
|
||||
void ASTWriter::WriteAdditionalTemplateSpecializations() {
|
||||
RecordData Record;
|
||||
for (AdditionalTemplateSpecializationsMap::iterator
|
||||
I = AdditionalTemplateSpecializations.begin(),
|
||||
E = AdditionalTemplateSpecializations.end();
|
||||
I != E; ++I) {
|
||||
Record.clear();
|
||||
Record.push_back(I->first);
|
||||
Record.insert(Record.end(), I->second.begin(), I->second.end());
|
||||
Stream.EmitRecord(ADDITIONAL_TEMPLATE_SPECIALIZATIONS, Record);
|
||||
}
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// General Serialization Routines
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -2697,10 +2682,6 @@ void ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls,
|
|||
I != E; ++I)
|
||||
WriteDeclContextVisibleUpdate(*I);
|
||||
|
||||
// Write the updates to C++ template specialization lists.
|
||||
if (!AdditionalTemplateSpecializations.empty())
|
||||
WriteAdditionalTemplateSpecializations();
|
||||
|
||||
WriteDeclUpdatesBlocks();
|
||||
|
||||
Record.clear();
|
||||
|
@ -3340,3 +3321,13 @@ void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) {
|
|||
Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER);
|
||||
AddDeclRef(D, Record);
|
||||
}
|
||||
|
||||
void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
|
||||
const ClassTemplateSpecializationDecl *D) {
|
||||
if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0))
|
||||
return; // Not a source specialization added to a template from PCH.
|
||||
|
||||
UpdateRecord &Record = DeclUpdates[TD];
|
||||
Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION);
|
||||
AddDeclRef(D, Record);
|
||||
}
|
||||
|
|
|
@ -905,10 +905,6 @@ void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
|
|||
InstFromD = cast<ClassTemplatePartialSpecializationDecl>(InstFromD)->
|
||||
getSpecializedTemplate();
|
||||
}
|
||||
// Is this a specialization of an already-serialized template?
|
||||
if (InstFromD->getCanonicalDecl()->getPCHLevel() != 0)
|
||||
Writer.AddAdditionalTemplateSpecialization(Writer.getDeclID(InstFromD),
|
||||
Writer.getDeclID(D));
|
||||
|
||||
// Explicit info.
|
||||
Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
|
||||
|
|
Loading…
Reference in New Issue