From: Douglas Gregor Date: Sun, 15 Jan 2012 18:17:48 +0000 (+0000) Subject: Now that deserializing a definition of a C++ class/Objective-C X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c23f8570d1fe934a99e6d2f4cd156ed5cc17f826;p=clang Now that deserializing a definition of a C++ class/Objective-C class/Objective-C protocol suffices get all of the redeclarations of that declaration wired to the definition, we no longer need to record the identity of the definition in every declaration. Instead, just record a bit to indicate whether a particular declaration is the definition. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148224 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 863aabb173..8becd35d54 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -103,10 +103,6 @@ namespace clang { void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, const RecordData &R, unsigned &I); - void InitializeCXXDefinitionData(CXXRecordDecl *D, - CXXRecordDecl *DefinitionDecl, - const RecordData &Record, unsigned &Idx); - /// \brief RAII class used to capture the first ID within a redeclaration /// chain and to introduce it into the list of pending redeclaration chains /// on destruction. @@ -672,8 +668,7 @@ void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]); mergeRedeclarable(ID, Redecl); - ObjCInterfaceDecl *Def = ReadDeclAs(Record, Idx); - if (ID == Def) { + if (Record[Idx++]) { // Read the definition. ID->allocateDefinitionData(); @@ -745,8 +740,7 @@ void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { VisitObjCContainerDecl(PD); mergeRedeclarable(PD, Redecl); - ObjCProtocolDecl *Def = ReadDeclAs(Record, Idx); - if (PD == Def) { + if (Record[Idx++]) { // Read the definition. PD->allocateDefinitionData(); @@ -1104,13 +1098,11 @@ void ASTDeclReader::ReadCXXDefinitionData( Data.FirstFriend = ReadDeclAs(Record, Idx); } -void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D, - CXXRecordDecl *DefinitionDecl, - const RecordData &Record, - unsigned &Idx) { - ASTContext &C = Reader.getContext(); +void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { + VisitRecordDecl(D); - if (D == DefinitionDecl) { + ASTContext &C = Reader.getContext(); + if (Record[Idx++]) { D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D); // Propagate the DefinitionData pointer to the canonical declaration, so @@ -1119,24 +1111,15 @@ void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D, D->getCanonicalDecl()->DefinitionData = D->DefinitionData; ReadCXXDefinitionData(*D->DefinitionData, Record, Idx); - + // Note that we have deserialized a definition. Any declarations // deserialized before this one will be be given the DefinitionData pointer // at the end. Reader.PendingDefinitions.insert(D); } else { // Propagate DefinitionData pointer from the canonical declaration. - D->DefinitionData = D->getCanonicalDecl()->DefinitionData; + D->DefinitionData = D->getCanonicalDecl()->DefinitionData; } -} - -void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { - VisitRecordDecl(D); - - CXXRecordDecl *DefinitionDecl = ReadDeclAs(Record, Idx); - InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx); - - ASTContext &C = Reader.getContext(); enum CXXRecKind { CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 0b55d73e45..8829dc630c 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -454,10 +454,8 @@ void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { VisitObjCContainerDecl(D); Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record); - ObjCInterfaceDecl *Def = D->getDefinition(); - Writer.AddDeclRef(Def, Record); - - if (D == Def) { + Record.push_back(D->isThisDeclarationADefinition()); + if (D->isThisDeclarationADefinition()) { // Write the DefinitionData ObjCInterfaceDecl::DefinitionData &Data = D->data(); @@ -520,10 +518,8 @@ void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { VisitRedeclarable(D); VisitObjCContainerDecl(D); - ObjCProtocolDecl *Def = D->getDefinition(); - Writer.AddDeclRef(Def, Record); - - if (D == Def) { + Record.push_back(D->isThisDeclarationADefinition()); + if (D->isThisDeclarationADefinition()) { Record.push_back(D->protocol_size()); for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I) @@ -905,12 +901,8 @@ void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl( void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { VisitRecordDecl(D); - - CXXRecordDecl *DefinitionDecl = 0; - if (D->DefinitionData) - DefinitionDecl = D->DefinitionData->Definition; - Writer.AddDeclRef(DefinitionDecl, Record); - if (D == DefinitionDecl) + Record.push_back(D->isThisDeclarationADefinition()); + if (D->isThisDeclarationADefinition()) Writer.AddCXXDefinitionData(D, Record); enum {