From c01dc6fb5bae1ac60910e8fbf1d22a8fa1e691f7 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sun, 24 Oct 2010 17:26:27 +0000 Subject: [PATCH] Minor refactoring; Pull reading/writing DefinitionData out into a function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117233 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReaderDecl.cpp | 103 +++++++++++++++------------- lib/Serialization/ASTWriterDecl.cpp | 82 +++++++++++----------- 2 files changed, 96 insertions(+), 89 deletions(-) diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 119dbc3914..16fb2e0800 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -33,39 +33,39 @@ namespace clang { ASTReader::PerFileData &F; llvm::BitstreamCursor &Cursor; const DeclID ThisDeclID; - const ASTReader::RecordData &Record; + typedef ASTReader::RecordData RecordData; + const RecordData &Record; unsigned &Idx; TypeID TypeIDForTypeDecl; uint64_t GetCurrentCursorOffset(); - SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, - unsigned &I) { + SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) { return Reader.ReadSourceLocation(F, R, I); } - SourceRange ReadSourceRange(const ASTReader::RecordData &R, unsigned &I) { + SourceRange ReadSourceRange(const RecordData &R, unsigned &I) { return Reader.ReadSourceRange(F, R, I); } - TypeSourceInfo *GetTypeSourceInfo(const ASTReader::RecordData &R, - unsigned &I) { + TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) { return Reader.GetTypeSourceInfo(F, R, I); } void ReadQualifierInfo(QualifierInfo &Info, - const ASTReader::RecordData &R, unsigned &I) { + const RecordData &R, unsigned &I) { Reader.ReadQualifierInfo(F, Info, R, I); } void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name, - const ASTReader::RecordData &R, unsigned &I) { + const RecordData &R, unsigned &I) { Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I); } void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo, - const ASTReader::RecordData &R, unsigned &I) { + const RecordData &R, unsigned &I) { Reader.ReadDeclarationNameInfo(F, NameInfo, R, I); } + void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data); public: ASTDeclReader(ASTReader &Reader, ASTReader::PerFileData &F, llvm::BitstreamCursor &Cursor, DeclID thisDeclID, - const ASTReader::RecordData &Record, unsigned &Idx) + const RecordData &Record, unsigned &Idx) : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID), Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { } @@ -763,6 +763,49 @@ void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( D->TargetNestedNameSpecifier = Reader.ReadNestedNameSpecifier(Record, Idx); } +void ASTDeclReader::ReadCXXDefinitionData( + struct CXXRecordDecl::DefinitionData &Data) { + ASTContext &C = *Reader.getContext(); + + Data.UserDeclaredConstructor = Record[Idx++]; + Data.UserDeclaredCopyConstructor = Record[Idx++]; + Data.UserDeclaredCopyAssignment = Record[Idx++]; + Data.UserDeclaredDestructor = Record[Idx++]; + Data.Aggregate = Record[Idx++]; + Data.PlainOldData = Record[Idx++]; + Data.Empty = Record[Idx++]; + Data.Polymorphic = Record[Idx++]; + Data.Abstract = Record[Idx++]; + Data.HasTrivialConstructor = Record[Idx++]; + Data.HasTrivialCopyConstructor = Record[Idx++]; + Data.HasTrivialCopyAssignment = Record[Idx++]; + Data.HasTrivialDestructor = Record[Idx++]; + Data.ComputedVisibleConversions = Record[Idx++]; + Data.DeclaredDefaultConstructor = Record[Idx++]; + Data.DeclaredCopyConstructor = Record[Idx++]; + Data.DeclaredCopyAssignment = Record[Idx++]; + Data.DeclaredDestructor = Record[Idx++]; + + // setBases() is unsuitable since it may try to iterate the bases of an + // uninitialized base. + Data.NumBases = Record[Idx++]; + Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases]; + for (unsigned i = 0; i != Data.NumBases; ++i) + Data.Bases[i] = Reader.ReadCXXBaseSpecifier(F, Record, Idx); + + // FIXME: Make VBases lazily computed when needed to avoid storing them. + Data.NumVBases = Record[Idx++]; + Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases]; + for (unsigned i = 0; i != Data.NumVBases; ++i) + Data.VBases[i] = Reader.ReadCXXBaseSpecifier(F, Record, Idx); + + Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx); + Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx); + assert(Data.Definition && "Data.Definition should be already set!"); + Data.FirstFriend + = cast_or_null(Reader.GetDecl(Record[Idx++])); +} + void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { ASTContext &C = *Reader.getContext(); @@ -807,45 +850,7 @@ void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { if (DefOwnership == Data_Owner) { assert(D->DefinitionData); - struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; - - Data.UserDeclaredConstructor = Record[Idx++]; - Data.UserDeclaredCopyConstructor = Record[Idx++]; - Data.UserDeclaredCopyAssignment = Record[Idx++]; - Data.UserDeclaredDestructor = Record[Idx++]; - Data.Aggregate = Record[Idx++]; - Data.PlainOldData = Record[Idx++]; - Data.Empty = Record[Idx++]; - Data.Polymorphic = Record[Idx++]; - Data.Abstract = Record[Idx++]; - Data.HasTrivialConstructor = Record[Idx++]; - Data.HasTrivialCopyConstructor = Record[Idx++]; - Data.HasTrivialCopyAssignment = Record[Idx++]; - Data.HasTrivialDestructor = Record[Idx++]; - Data.ComputedVisibleConversions = Record[Idx++]; - Data.DeclaredDefaultConstructor = Record[Idx++]; - Data.DeclaredCopyConstructor = Record[Idx++]; - Data.DeclaredCopyAssignment = Record[Idx++]; - Data.DeclaredDestructor = Record[Idx++]; - - // setBases() is unsuitable since it may try to iterate the bases of an - // uninitialized base. - Data.NumBases = Record[Idx++]; - Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases]; - for (unsigned i = 0; i != Data.NumBases; ++i) - Data.Bases[i] = Reader.ReadCXXBaseSpecifier(F, Record, Idx); - - // FIXME: Make VBases lazily computed when needed to avoid storing them. - Data.NumVBases = Record[Idx++]; - Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases]; - for (unsigned i = 0; i != Data.NumVBases; ++i) - Data.VBases[i] = Reader.ReadCXXBaseSpecifier(F, Record, Idx); - - Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx); - Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx); - assert(Data.Definition && "Data.Definition should be already set!"); - Data.FirstFriend - = cast_or_null(Reader.GetDecl(Record[Idx++])); + ReadCXXDefinitionData(*D->DefinitionData); } enum CXXRecKind { diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 73a71e9701..19f198cb65 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -31,17 +31,18 @@ namespace clang { ASTWriter &Writer; ASTContext &Context; - ASTWriter::RecordData &Record; + typedef ASTWriter::RecordData RecordData; + RecordData &Record; + void WriteCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data); public: serialization::DeclCode Code; unsigned AbbrevToUse; - ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, - ASTWriter::RecordData &Record) + ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, RecordData &Record) : Writer(Writer), Context(Context), Record(Record) { } - + void Visit(Decl *D); void VisitDecl(Decl *D); @@ -720,6 +721,42 @@ void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl( Code = serialization::DECL_UNRESOLVED_USING_TYPENAME; } +void ASTDeclWriter::WriteCXXDefinitionData( + struct CXXRecordDecl::DefinitionData &Data) { + Record.push_back(Data.UserDeclaredConstructor); + Record.push_back(Data.UserDeclaredCopyConstructor); + Record.push_back(Data.UserDeclaredCopyAssignment); + Record.push_back(Data.UserDeclaredDestructor); + Record.push_back(Data.Aggregate); + Record.push_back(Data.PlainOldData); + Record.push_back(Data.Empty); + Record.push_back(Data.Polymorphic); + Record.push_back(Data.Abstract); + Record.push_back(Data.HasTrivialConstructor); + Record.push_back(Data.HasTrivialCopyConstructor); + Record.push_back(Data.HasTrivialCopyAssignment); + Record.push_back(Data.HasTrivialDestructor); + Record.push_back(Data.ComputedVisibleConversions); + Record.push_back(Data.DeclaredDefaultConstructor); + Record.push_back(Data.DeclaredCopyConstructor); + Record.push_back(Data.DeclaredCopyAssignment); + Record.push_back(Data.DeclaredDestructor); + + Record.push_back(Data.NumBases); + for (unsigned i = 0; i != Data.NumBases; ++i) + Writer.AddCXXBaseSpecifier(Data.Bases[i], Record); + + // FIXME: Make VBases lazily computed when needed to avoid storing them. + Record.push_back(Data.NumVBases); + for (unsigned i = 0; i != Data.NumVBases; ++i) + Writer.AddCXXBaseSpecifier(Data.VBases[i], Record); + + Writer.AddUnresolvedSet(Data.Conversions, Record); + Writer.AddUnresolvedSet(Data.VisibleConversions, Record); + // Data.Definition is the owning decl, no need to write it. + Writer.AddDeclRef(Data.FirstFriend, Record); +} + void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { // See comments at ASTDeclReader::VisitCXXRecordDecl about why this happens // before VisitRecordDecl. @@ -742,42 +779,7 @@ void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { if (OwnsDefinitionData) { assert(D->DefinitionData); - struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; - - Record.push_back(Data.UserDeclaredConstructor); - Record.push_back(Data.UserDeclaredCopyConstructor); - Record.push_back(Data.UserDeclaredCopyAssignment); - Record.push_back(Data.UserDeclaredDestructor); - Record.push_back(Data.Aggregate); - Record.push_back(Data.PlainOldData); - Record.push_back(Data.Empty); - Record.push_back(Data.Polymorphic); - Record.push_back(Data.Abstract); - Record.push_back(Data.HasTrivialConstructor); - Record.push_back(Data.HasTrivialCopyConstructor); - Record.push_back(Data.HasTrivialCopyAssignment); - Record.push_back(Data.HasTrivialDestructor); - Record.push_back(Data.ComputedVisibleConversions); - Record.push_back(Data.DeclaredDefaultConstructor); - Record.push_back(Data.DeclaredCopyConstructor); - Record.push_back(Data.DeclaredCopyAssignment); - Record.push_back(Data.DeclaredDestructor); - - Record.push_back(D->getNumBases()); - for (CXXRecordDecl::base_class_iterator I = D->bases_begin(), - E = D->bases_end(); I != E; ++I) - Writer.AddCXXBaseSpecifier(*I, Record); - - // FIXME: Make VBases lazily computed when needed to avoid storing them. - Record.push_back(D->getNumVBases()); - for (CXXRecordDecl::base_class_iterator I = D->vbases_begin(), - E = D->vbases_end(); I != E; ++I) - Writer.AddCXXBaseSpecifier(*I, Record); - - Writer.AddUnresolvedSet(Data.Conversions, Record); - Writer.AddUnresolvedSet(Data.VisibleConversions, Record); - // Data.Definition is written at the top. - Writer.AddDeclRef(Data.FirstFriend, Record); + WriteCXXDefinitionData(*D->DefinitionData); } enum { -- 2.40.0