[cfe-commits] r117233 - in /cfe/trunk/lib/Serialization: ASTReaderDecl.cpp ASTWriterDecl.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Oct 24 10:26:27 PDT 2010


Author: akirtzidis
Date: Sun Oct 24 12:26:27 2010
New Revision: 117233

URL: http://llvm.org/viewvc/llvm-project?rev=117233&view=rev
Log:
Minor refactoring; Pull reading/writing DefinitionData out into a function.

Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=117233&r1=117232&r2=117233&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sun Oct 24 12:26:27 2010
@@ -33,39 +33,39 @@
     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 @@
   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<FriendDecl>(Reader.GetDecl(Record[Idx++]));
+}
+
 void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
   ASTContext &C = *Reader.getContext();
 
@@ -807,45 +850,7 @@
 
   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<FriendDecl>(Reader.GetDecl(Record[Idx++]));
+    ReadCXXDefinitionData(*D->DefinitionData);
   }
 
   enum CXXRecKind {

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=117233&r1=117232&r2=117233&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Sun Oct 24 12:26:27 2010
@@ -31,17 +31,18 @@
 
     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 @@
   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 @@
 
   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 {





More information about the cfe-commits mailing list