[cfe-commits] r107475 - in /cfe/trunk: include/clang/AST/DeclCXX.h include/clang/AST/Redeclarable.h include/clang/Frontend/PCHReader.h include/clang/Frontend/PCHWriter.h lib/AST/ASTContext.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriter.cpp lib/Frontend/PCHWriterDecl.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Jul 2 04:55:32 PDT 2010


Author: akirtzidis
Date: Fri Jul  2 06:55:32 2010
New Revision: 107475

URL: http://llvm.org/viewvc/llvm-project?rev=107475&view=rev
Log:
Fully read/write CXXRecordDecl for PCH.

Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/include/clang/AST/Redeclarable.h
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/include/clang/Frontend/PCHWriter.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/lib/Frontend/PCHWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=107475&r1=107474&r2=107475&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Jul  2 06:55:32 2010
@@ -414,6 +414,13 @@
   virtual const CXXRecordDecl *getCanonicalDecl() const {
     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
   }
+  
+  const CXXRecordDecl *getPreviousDeclaration() const {
+    return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration());
+  }
+  CXXRecordDecl *getPreviousDeclaration() {
+    return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration());
+  }
 
   CXXRecordDecl *getDefinition() const {
     if (!DefinitionData) return 0;

Modified: cfe/trunk/include/clang/AST/Redeclarable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Redeclarable.h?rev=107475&r1=107474&r2=107475&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Redeclarable.h (original)
+++ cfe/trunk/include/clang/AST/Redeclarable.h Fri Jul  2 06:55:32 2010
@@ -92,6 +92,11 @@
     return D;
   }
 
+  /// \brief Returns true if this is the first declaration.
+  bool isFirstDeclaration() const {
+    return RedeclLink.NextIsLatest();
+  }
+
   /// \brief Returns the most recent (re)declaration of this declaration.
   decl_type *getMostRecentDeclaration() {
     return getFirstDeclaration()->RedeclLink.getNext();

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=107475&r1=107474&r2=107475&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Fri Jul  2 06:55:32 2010
@@ -743,6 +743,10 @@
   ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs,
                            const RecordData &Record, unsigned &Idx);
 
+  /// \brief Read a UnresolvedSet structure.
+  void ReadUnresolvedSet(UnresolvedSetImpl &Set,
+                         const RecordData &Record, unsigned &Idx);
+
   /// \brief Read a source location.
   SourceLocation ReadSourceLocation(const RecordData &Record, unsigned& Idx) {
     return SourceLocation::getFromRawEncoding(Record[Idx++]);

Modified: cfe/trunk/include/clang/Frontend/PCHWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHWriter.h?rev=107475&r1=107474&r2=107475&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHWriter.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHWriter.h Fri Jul  2 06:55:32 2010
@@ -343,6 +343,9 @@
   void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs,
                                 RecordData &Record);
 
+  /// \brief Emit a UnresolvedSet structure.
+  void AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordData &Record);
+
   /// \brief Add a string to the given record.
   void AddString(const std::string &Str, RecordData &Record);
 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=107475&r1=107474&r2=107475&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jul  2 06:55:32 2010
@@ -1741,8 +1741,7 @@
   assert(NeedsInjectedClassNameType(Decl));
   if (Decl->TypeForDecl) {
     assert(isa<InjectedClassNameType>(Decl->TypeForDecl));
-  } else if (CXXRecordDecl *PrevDecl
-               = cast_or_null<CXXRecordDecl>(Decl->getPreviousDeclaration())) {
+  } else if (CXXRecordDecl *PrevDecl = Decl->getPreviousDeclaration()) {
     assert(PrevDecl->TypeForDecl && "previous declaration has no type");
     Decl->TypeForDecl = PrevDecl->TypeForDecl;
     assert(isa<InjectedClassNameType>(Decl->TypeForDecl));

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=107475&r1=107474&r2=107475&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Jul  2 06:55:32 2010
@@ -3090,6 +3090,17 @@
     TemplArgs.push_back(ReadTemplateArgument(Record, Idx));
 }
 
+/// \brief Read a UnresolvedSet structure.
+void PCHReader::ReadUnresolvedSet(UnresolvedSetImpl &Set,
+                                  const RecordData &Record, unsigned &Idx) {
+  unsigned NumDecls = Record[Idx++];
+  while (NumDecls--) {
+    NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++]));
+    AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
+    Set.addDecl(D, AS);
+  }
+}
+
 NestedNameSpecifier *
 PCHReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) {
   unsigned N = Record[Idx++];

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=107475&r1=107474&r2=107475&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Fri Jul  2 06:55:32 2010
@@ -39,7 +39,7 @@
                   unsigned &Idx)
       : Reader(Reader), Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
 
-    CXXBaseSpecifier *ReadCXXBaseSpecifier();
+    CXXBaseSpecifier ReadCXXBaseSpecifier();
 
     void Visit(Decl *D);
 
@@ -628,20 +628,63 @@
   D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
 }
 
-CXXBaseSpecifier *PCHDeclReader::ReadCXXBaseSpecifier() {
+CXXBaseSpecifier PCHDeclReader::ReadCXXBaseSpecifier() {
   bool isVirtual = static_cast<bool>(Record[Idx++]);
   bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
   AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
   QualType T = Reader.GetType(Record[Idx++]);
   SourceRange Range = Reader.ReadSourceRange(Record, Idx);
-  return new (*Reader.getContext())
-    CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, T);
+  return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, T);
 }
 
 void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
-  // assert(false && "cannot read CXXRecordDecl");
   VisitRecordDecl(D);
-  
+
+  ASTContext &C = *Reader.getContext();
+
+  if (D->isFirstDeclaration()) {
+    if (Record[Idx++]) { // DefinitionData != 0
+      D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(0);
+      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++];
+
+      // setBases() is unsuitable since it may try to iterate the bases of an
+      // unitialized base.
+      Data.NumBases = Record[Idx++];
+      Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
+      for (unsigned i = 0; i != Data.NumBases; ++i)
+        Data.Bases[i] = ReadCXXBaseSpecifier();
+
+      // 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] = ReadCXXBaseSpecifier();
+
+      Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
+      Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
+      Data.Definition = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
+      Data.FirstFriend
+          = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
+    }
+  } else {
+    D->DefinitionData = D->getPreviousDeclaration()->DefinitionData;
+  }
+
   enum CXXRecKind {
     CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
   };
@@ -663,31 +706,6 @@
     break;
   }
   }
-
-  // FIXME: Hack. See PCHDeclWriter::VisitTypeDecl.
-  D->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
-
-  // FIXME: this is far from complete
-
-  if (D->isDefinition()) {
-    D->setDefinition(false); // make peace with an assertion
-    D->startDefinition();
-
-    unsigned NumBases = Record[Idx++];
-
-    llvm::SmallVector<CXXBaseSpecifier*, 4> Bases;
-    Bases.reserve(NumBases);
-    for (unsigned I = 0; I != NumBases; ++I)
-      Bases.push_back(ReadCXXBaseSpecifier());
-    D->setBases(Bases.begin(), NumBases);
-
-    D->data().FirstFriend
-        = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
-
-    // FIXME: there's a lot of stuff we do here that's kindof sketchy
-    // if we're leaving the context incomplete.
-    D->completeDefinition();
-  }
 }
 
 void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=107475&r1=107474&r2=107475&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Jul  2 06:55:32 2010
@@ -2621,3 +2621,14 @@
   for (int i=0, e = TemplateArgs->flat_size(); i != e; ++i)
     AddTemplateArgument(TemplateArgs->get(i), Record);
 }
+
+
+void
+PCHWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordData &Record) {
+  Record.push_back(Set.size());
+  for (UnresolvedSetImpl::const_iterator
+         I = Set.begin(), E = Set.end(); I != E; ++I) {
+    AddDeclRef(I.getDecl(), Record);
+    Record.push_back(I.getAccess());
+  }
+}

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=107475&r1=107474&r2=107475&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Fri Jul  2 06:55:32 2010
@@ -632,6 +632,44 @@
 void PCHDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
   VisitRecordDecl(D);
 
+  if (D->isFirstDeclaration()) {
+    Record.push_back(D->DefinitionData != 0);
+    if (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(D->getNumBases());
+      for (CXXRecordDecl::base_class_iterator I = D->bases_begin(),
+             E = D->bases_end(); I != E; ++I)
+        WriteCXXBaseSpecifier(&*I);
+
+      // 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)
+        WriteCXXBaseSpecifier(&*I);
+
+      Writer.AddUnresolvedSet(Data.Conversions, Record);
+      Writer.AddUnresolvedSet(Data.VisibleConversions, Record);
+      Writer.AddDeclRef(Data.Definition, Record);
+      Writer.AddDeclRef(Data.FirstFriend, Record);
+    }
+  }
+
   enum {
     CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
   };
@@ -648,18 +686,6 @@
     Record.push_back(CXXRecNotTemplate);
   }
 
-  // FIXME: Hack. See PCHDeclWriter::VisitTypeDecl.
-  Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
-
-  if (D->isDefinition()) {
-    unsigned NumBases = D->getNumBases();
-    Record.push_back(NumBases);
-    for (CXXRecordDecl::base_class_iterator I = D->bases_begin(),
-           E = D->bases_end(); I != E; ++I)
-      WriteCXXBaseSpecifier(&*I);
-    
-    Writer.AddDeclRef(D->data().FirstFriend, Record);
-  }
   Code = pch::DECL_CXX_RECORD;
 }
 





More information about the cfe-commits mailing list