[cfe-commits] r117533 - in /cfe/trunk: include/clang/AST/ASTMutationListener.h include/clang/AST/DeclTemplate.h include/clang/Serialization/ASTBitCodes.h include/clang/Serialization/ASTReader.h include/clang/Serialization/ASTWriter.h lib/AST/DeclTemplate.cpp lib/Serialization/ASTCommon.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriter.cpp lib/Serialization/ASTWriterDecl.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Oct 28 00:38:42 PDT 2010
Author: akirtzidis
Date: Thu Oct 28 02:38:42 2010
New Revision: 117533
URL: http://llvm.org/viewvc/llvm-project?rev=117533&view=rev
Log:
Use the ASTMutationListener to track added template specializations in a chained PCH.
Modified:
cfe/trunk/include/clang/AST/ASTMutationListener.h
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/AST/DeclTemplate.cpp
cfe/trunk/lib/Serialization/ASTCommon.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTMutationListener.h (original)
+++ cfe/trunk/include/clang/AST/ASTMutationListener.h Thu Oct 28 02:38:42 2010
@@ -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 @@
/// \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
Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Thu Oct 28 02:38:42 2010
@@ -1697,9 +1697,7 @@
/// \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 @@
/// \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() {
Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Thu Oct 28 02:38:42 2010
@@ -327,17 +327,13 @@
/// 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.
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Oct 28 02:38:42 2010
@@ -458,16 +458,6 @@
/// 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,
Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Thu Oct 28 02:38:42 2010
@@ -236,16 +236,6 @@
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 @@
void WriteDeclUpdatesBlocks();
void WriteDeclReplacementsBlock();
void WriteDeclContextVisibleUpdate(const DeclContext *DC);
- void WriteAdditionalTemplateSpecializations();
unsigned ParmVarDeclAbbrev;
unsigned DeclContextLexicalAbbrev;
@@ -459,13 +448,6 @@
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 @@
// 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
Modified: cfe/trunk/lib/AST/DeclTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclTemplate.cpp?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclTemplate.cpp (original)
+++ cfe/trunk/lib/AST/DeclTemplate.cpp Thu Oct 28 02:38:42 2010
@@ -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 @@
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 @@
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
Modified: cfe/trunk/lib/Serialization/ASTCommon.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTCommon.h?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTCommon.h (original)
+++ cfe/trunk/lib/Serialization/ASTCommon.h Thu Oct 28 02:38:42 2010
@@ -22,7 +22,8 @@
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);
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Oct 28 02:38:42 2010
@@ -2069,13 +2069,6 @@
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;
}
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Oct 28 02:38:42 2010
@@ -1553,20 +1553,6 @@
}
}
}
-
- // 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 @@
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++]);
}
}
}
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Oct 28 02:38:42 2010
@@ -2181,21 +2181,6 @@
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 @@
I != E; ++I)
WriteDeclContextVisibleUpdate(*I);
- // Write the updates to C++ template specialization lists.
- if (!AdditionalTemplateSpecializations.empty())
- WriteAdditionalTemplateSpecializations();
-
WriteDeclUpdatesBlocks();
Record.clear();
@@ -3340,3 +3321,13 @@
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);
+}
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=117533&r1=117532&r2=117533&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Thu Oct 28 02:38:42 2010
@@ -905,10 +905,6 @@
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);
More information about the cfe-commits
mailing list