[cfe-commits] r109191 - in /cfe/trunk: include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHReaderStmt.cpp test/PCH/Inputs/chain-trivial1.h test/PCH/Inputs/chain-trivial2.h test/PCH/chain-trivial.c

Sebastian Redl sebastian.redl at getdesigned.at
Thu Jul 22 15:43:28 PDT 2010


Author: cornedbee
Date: Thu Jul 22 17:43:28 2010
New Revision: 109191

URL: http://llvm.org/viewvc/llvm-project?rev=109191&view=rev
Log:
Thread bitstream cursors all the way through the AST reading stuff. This way, reading a trivial 2-element chained file actually works.

Added:
    cfe/trunk/test/PCH/Inputs/chain-trivial1.h
    cfe/trunk/test/PCH/Inputs/chain-trivial2.h
    cfe/trunk/test/PCH/chain-trivial.c
Modified:
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHReaderStmt.cpp

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=109191&r1=109190&r2=109191&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Thu Jul 22 17:43:28 2010
@@ -670,15 +670,17 @@
   /// given TemplateArgument kind.
   TemplateArgumentLocInfo
   GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
+                             llvm::BitstreamCursor &DeclsCursor,
                              const RecordData &Record, unsigned &Idx);
 
   /// \brief Reads a TemplateArgumentLoc.
-  TemplateArgumentLoc ReadTemplateArgumentLoc(const RecordData &Record,
-                                              unsigned &Idx);
+  TemplateArgumentLoc
+  ReadTemplateArgumentLoc(llvm::BitstreamCursor &DeclsCursor,
+                          const RecordData &Record, unsigned &Idx);
 
   /// \brief Reads a declarator info from the given record.
-  TypeSourceInfo *GetTypeSourceInfo(const RecordData &Record,
-                                    unsigned &Idx);
+  TypeSourceInfo *GetTypeSourceInfo(llvm::BitstreamCursor &DeclsCursor,
+                                    const RecordData &Record, unsigned &Idx);
 
   /// \brief Resolve and return the translation unit declaration.
   TranslationUnitDecl *GetTranslationUnitDecl();
@@ -807,7 +809,8 @@
   TemplateName ReadTemplateName(const RecordData &Record, unsigned &Idx);
 
   /// \brief Read a template argument.
-  TemplateArgument ReadTemplateArgument(const RecordData &Record,unsigned &Idx);
+  TemplateArgument ReadTemplateArgument(llvm::BitstreamCursor &DeclsCursor,
+                                        const RecordData &Record,unsigned &Idx);
   
   /// \brief Read a template parameter list.
   TemplateParameterList *ReadTemplateParameterList(const RecordData &Record,
@@ -816,6 +819,7 @@
   /// \brief Read a template argument array.
   void
   ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs,
+                           llvm::BitstreamCursor &DeclsCursor,
                            const RecordData &Record, unsigned &Idx);
 
   /// \brief Read a UnresolvedSet structure.
@@ -848,13 +852,13 @@
   CXXTemporary *ReadCXXTemporary(const RecordData &Record, unsigned &Idx);
       
   /// \brief Reads attributes from the current stream position.
-  Attr *ReadAttributes();
+  Attr *ReadAttributes(llvm::BitstreamCursor &DeclsCursor);
 
   /// \brief Reads a statement.
-  Stmt *ReadStmt();
+  Stmt *ReadStmt(llvm::BitstreamCursor &Cursor);
 
   /// \brief Reads an expression.
-  Expr *ReadExpr();
+  Expr *ReadExpr(llvm::BitstreamCursor &Cursor);
 
   /// \brief Reads a sub-statement operand during statement reading.
   Stmt *ReadSubStmt() {

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=109191&r1=109190&r2=109191&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Thu Jul 22 17:43:28 2010
@@ -2296,7 +2296,7 @@
     unsigned IndexTypeQuals = Record[2];
     SourceLocation LBLoc = SourceLocation::getFromRawEncoding(Record[3]);
     SourceLocation RBLoc = SourceLocation::getFromRawEncoding(Record[4]);
-    return Context->getVariableArrayType(ElementType, ReadExpr(),
+    return Context->getVariableArrayType(ElementType, ReadExpr(DeclsCursor),
                                          ASM, IndexTypeQuals,
                                          SourceRange(LBLoc, RBLoc));
   }
@@ -2376,7 +2376,7 @@
   }
 
   case pch::TYPE_TYPEOF_EXPR:
-    return Context->getTypeOfExprType(ReadExpr());
+    return Context->getTypeOfExprType(ReadExpr(DeclsCursor));
 
   case pch::TYPE_TYPEOF: {
     if (Record.size() != 1) {
@@ -2388,7 +2388,7 @@
   }
 
   case pch::TYPE_DECLTYPE:
-    return Context->getDecltypeType(ReadExpr());
+    return Context->getDecltypeType(ReadExpr(DeclsCursor));
 
   case pch::TYPE_RECORD: {
     if (Record.size() != 2) {
@@ -2487,7 +2487,7 @@
     llvm::SmallVector<TemplateArgument, 8> Args;
     Args.reserve(NumArgs);
     while (NumArgs--)
-      Args.push_back(ReadTemplateArgument(Record, Idx));
+      Args.push_back(ReadTemplateArgument(DeclsCursor, Record, Idx));
     return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name,
                                                       Args.size(), Args.data());
   }
@@ -2502,7 +2502,7 @@
     unsigned IndexTypeQuals = Record[Idx++];
 
     // DependentSizedArrayType
-    Expr *NumElts = ReadExpr();
+    Expr *NumElts = ReadExpr(DeclsCursor);
     SourceRange Brackets = ReadSourceRange(Record, Idx);
 
     return Context->getDependentSizedArrayType(ElementType, NumElts, ASM,
@@ -2514,7 +2514,7 @@
     bool IsDependent = Record[Idx++];
     TemplateName Name = ReadTemplateName(Record, Idx);
     llvm::SmallVector<TemplateArgument, 8> Args;
-    ReadTemplateArgumentList(Args, Record, Idx);
+    ReadTemplateArgumentList(Args, DeclsCursor, Record, Idx);
     QualType Canon = GetType(Record[Idx++]);
     QualType T;
     if (Canon.isNull())
@@ -2535,13 +2535,14 @@
 
 class TypeLocReader : public TypeLocVisitor<TypeLocReader> {
   PCHReader &Reader;
+  llvm::BitstreamCursor &DeclsCursor;
   const PCHReader::RecordData &Record;
   unsigned &Idx;
 
 public:
-  TypeLocReader(PCHReader &Reader, const PCHReader::RecordData &Record,
-                unsigned &Idx)
-    : Reader(Reader), Record(Record), Idx(Idx) { }
+  TypeLocReader(PCHReader &Reader, llvm::BitstreamCursor &Cursor,
+                const PCHReader::RecordData &Record, unsigned &Idx)
+    : Reader(Reader), DeclsCursor(Cursor), Record(Record), Idx(Idx) { }
 
   // We want compile-time assurance that we've enumerated all of
   // these, so unfortunately we have to declare them first, then
@@ -2591,7 +2592,7 @@
   TL.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   TL.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   if (Record[Idx++])
-    TL.setSizeExpr(Reader.ReadExpr());
+    TL.setSizeExpr(Reader.ReadExpr(DeclsCursor));
   else
     TL.setSizeExpr(0);
 }
@@ -2646,7 +2647,7 @@
   TL.setTypeofLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   TL.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   TL.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-  TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(Record, Idx));
+  TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
 }
 void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
   TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
@@ -2672,7 +2673,7 @@
   for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
     TL.setArgLocInfo(i,
         Reader.GetTemplateArgumentLocInfo(TL.getTypePtr()->getArg(i).getKind(),
-                                          Record, Idx));
+                                          DeclsCursor, Record, Idx));
 }
 void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
   TL.setKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
@@ -2696,7 +2697,7 @@
   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
     TL.setArgLocInfo(I,
         Reader.GetTemplateArgumentLocInfo(TL.getTypePtr()->getArg(I).getKind(),
-                                          Record, Idx));
+                                          DeclsCursor, Record, Idx));
 }
 void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
   TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
@@ -2712,14 +2713,15 @@
   TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
 
-TypeSourceInfo *PCHReader::GetTypeSourceInfo(const RecordData &Record,
+TypeSourceInfo *PCHReader::GetTypeSourceInfo(llvm::BitstreamCursor &DeclsCursor,
+                                             const RecordData &Record,
                                              unsigned &Idx) {
   QualType InfoTy = GetType(Record[Idx++]);
   if (InfoTy.isNull())
     return 0;
 
   TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy);
-  TypeLocReader TLR(*this, Record, Idx);
+  TypeLocReader TLR(*this, DeclsCursor, Record, Idx);
   for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
     TLR.Visit(TL);
   return TInfo;
@@ -2787,13 +2789,14 @@
 
 TemplateArgumentLocInfo
 PCHReader::GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
+                                      llvm::BitstreamCursor &DeclsCursor,
                                       const RecordData &Record,
                                       unsigned &Index) {
   switch (Kind) {
   case TemplateArgument::Expression:
-    return ReadExpr();
+    return ReadExpr(DeclsCursor);
   case TemplateArgument::Type:
-    return GetTypeSourceInfo(Record, Index);
+    return GetTypeSourceInfo(DeclsCursor, Record, Index);
   case TemplateArgument::Template: {
     SourceRange QualifierRange = ReadSourceRange(Record, Index);
     SourceLocation TemplateNameLoc = ReadSourceLocation(Record, Index);
@@ -2810,14 +2813,16 @@
 }
 
 TemplateArgumentLoc
-PCHReader::ReadTemplateArgumentLoc(const RecordData &Record, unsigned &Index) {
-  TemplateArgument Arg = ReadTemplateArgument(Record, Index);
+PCHReader::ReadTemplateArgumentLoc(llvm::BitstreamCursor &DeclsCursor,
+                                   const RecordData &Record, unsigned &Index) {
+  TemplateArgument Arg = ReadTemplateArgument(DeclsCursor, Record, Index);
 
   if (Arg.getKind() == TemplateArgument::Expression) {
     if (Record[Index++]) // bool InfoHasSameExpr.
       return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr()));
   }
   return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(Arg.getKind(),
+                                                             DeclsCursor,
                                                              Record, Index));
 }
 
@@ -3370,7 +3375,8 @@
 }
 
 TemplateArgument
-PCHReader::ReadTemplateArgument(const RecordData &Record, unsigned &Idx) {
+PCHReader::ReadTemplateArgument(llvm::BitstreamCursor &DeclsCursor,
+                                const RecordData &Record, unsigned &Idx) {
   switch ((TemplateArgument::ArgKind)Record[Idx++]) {
   case TemplateArgument::Null:
     return TemplateArgument();
@@ -3386,13 +3392,13 @@
   case TemplateArgument::Template:
     return TemplateArgument(ReadTemplateName(Record, Idx));
   case TemplateArgument::Expression:
-    return TemplateArgument(ReadExpr());
+    return TemplateArgument(ReadExpr(DeclsCursor));
   case TemplateArgument::Pack: {
     unsigned NumArgs = Record[Idx++];
     llvm::SmallVector<TemplateArgument, 8> Args;
     Args.reserve(NumArgs);
     while (NumArgs--)
-      Args.push_back(ReadTemplateArgument(Record, Idx));
+      Args.push_back(ReadTemplateArgument(DeclsCursor, Record, Idx));
     TemplateArgument TemplArg;
     TemplArg.setArgumentPack(Args.data(), Args.size(), /*CopyArgs=*/true);
     return TemplArg;
@@ -3424,11 +3430,12 @@
 void
 PCHReader::
 ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs,
+                         llvm::BitstreamCursor &DeclsCursor,
                          const RecordData &Record, unsigned &Idx) {
   unsigned NumTemplateArgs = Record[Idx++];
   TemplArgs.reserve(NumTemplateArgs);
   while (NumTemplateArgs--)
-    TemplArgs.push_back(ReadTemplateArgument(Record, Idx));
+    TemplArgs.push_back(ReadTemplateArgument(DeclsCursor, Record, Idx));
 }
 
 /// \brief Read a UnresolvedSet structure.

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=109191&r1=109190&r2=109191&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Thu Jul 22 17:43:28 2010
@@ -30,14 +30,18 @@
 namespace clang {
   class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
     PCHReader &Reader;
+    llvm::BitstreamCursor &Cursor;
     const PCHReader::RecordData &Record;
     unsigned &Idx;
     pch::TypeID TypeIDForTypeDecl;
 
+    uint64_t GetCurrentCursorOffset();
+
   public:
-    PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
-                  unsigned &Idx)
-      : Reader(Reader), Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
+    PCHDeclReader(PCHReader &Reader, llvm::BitstreamCursor &Cursor,
+                  const PCHReader::RecordData &Record, unsigned &Idx)
+      : Reader(Reader), Cursor(Cursor), Record(Record), Idx(Idx),
+        TypeIDForTypeDecl(0) { }
 
     void Visit(Decl *D);
 
@@ -108,6 +112,19 @@
   };
 }
 
+uint64_t PCHDeclReader::GetCurrentCursorOffset() {
+  uint64_t Off = 0;
+  for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
+    PCHReader::PerFileData &F = *Reader.Chain[N - I - 1];
+    if (&Cursor == &F.DeclsCursor) {
+      Off += F.DeclsCursor.GetCurrentBitNo();
+      break;
+    }
+    Off += F.SizeInBits;
+  }
+  return Off;
+}
+
 void PCHDeclReader::Visit(Decl *D) {
   DeclVisitor<PCHDeclReader, void>::Visit(D);
 
@@ -117,7 +134,7 @@
   } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     // FunctionDecl's body was written last after all other Stmts/Exprs.
     if (Record[Idx++])
-      FD->setLazyBody(Reader.Chain[0]->DeclsCursor.GetCurrentBitNo());
+      FD->setLazyBody(GetCurrentCursorOffset());
   }
 }
 
@@ -128,7 +145,7 @@
   D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
   D->setInvalidDecl(Record[Idx++]);
   if (Record[Idx++])
-    D->initAttrs(Reader.ReadAttributes());
+    D->initAttrs(Reader.ReadAttributes(Cursor));
   D->setImplicit(Record[Idx++]);
   D->setUsed(Record[Idx++]);
   D->setAccess((AccessSpecifier)Record[Idx++]);
@@ -154,7 +171,7 @@
 
 void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
   VisitTypeDecl(TD);
-  TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
+  TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
 }
 
 void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
@@ -197,13 +214,13 @@
 void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
   VisitValueDecl(ECD);
   if (Record[Idx++])
-    ECD->setInitExpr(Reader.ReadExpr());
+    ECD->setInitExpr(Reader.ReadExpr(Cursor));
   ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
 }
 
 void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
   VisitValueDecl(DD);
-  TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
+  TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
   if (TInfo)
     DD->setTypeSourceInfo(TInfo);
   // FIXME: read optional qualifier and its range.
@@ -237,7 +254,7 @@
     
     // Template arguments.
     llvm::SmallVector<TemplateArgument, 8> TemplArgs;
-    Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
+    Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
     
     // Template args as written.
     llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
@@ -246,7 +263,8 @@
       unsigned NumTemplateArgLocs = Record[Idx++];
       TemplArgLocs.reserve(NumTemplateArgLocs);
       for (unsigned i=0; i != NumTemplateArgLocs; ++i)
-        TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
+        TemplArgLocs.push_back(
+            Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
   
       LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
       RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
@@ -273,7 +291,7 @@
     TemplateArgumentListInfo TemplArgs;
     unsigned NumArgs = Record[Idx++];
     while (NumArgs--)
-      TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
+      TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx));
     TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
     TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
     
@@ -317,7 +335,7 @@
   if (Record[Idx++]) {
     // In practice, this won't be executed (since method definitions
     // don't occur in header files).
-    MD->setBody(Reader.ReadStmt());
+    MD->setBody(Reader.ReadStmt(Cursor));
     MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
     MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
   }
@@ -329,7 +347,7 @@
   MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
   MD->setNumSelectorArgs(unsigned(Record[Idx++]));
   MD->setResultType(Reader.GetType(Record[Idx++]));
-  MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
+  MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
   MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   unsigned NumParams = Record[Idx++];
   llvm::SmallVector<ParmVarDecl *, 16> Params;
@@ -462,7 +480,7 @@
 void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
   VisitNamedDecl(D);
   D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-  D->setType(Reader.GetTypeSourceInfo(Record, Idx));
+  D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
   // FIXME: stable encoding
   D->setPropertyAttributes(
                       (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
@@ -514,7 +532,7 @@
   VisitDeclaratorDecl(FD);
   FD->setMutable(Record[Idx++]);
   if (Record[Idx++])
-    FD->setBitWidth(Reader.ReadExpr());
+    FD->setBitWidth(Reader.ReadExpr(Cursor));
   if (!FD->getDeclName()) {
     FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
     if (Tmpl)
@@ -534,7 +552,7 @@
   VD->setPreviousDeclaration(
                          cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
   if (Record[Idx++])
-    VD->setInit(Reader.ReadExpr());
+    VD->setInit(Reader.ReadExpr(Cursor));
 
   if (Record[Idx++]) { // HasMemberSpecializationInfo.
     VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
@@ -553,18 +571,18 @@
   PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
   PD->setHasInheritedDefaultArg(Record[Idx++]);
   if (Record[Idx++]) // hasUninstantiatedDefaultArg.
-    PD->setUninstantiatedDefaultArg(Reader.ReadExpr());
+    PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor));
 }
 
 void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
   VisitDecl(AD);
-  AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
+  AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor)));
 }
 
 void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
   VisitDecl(BD);
-  BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
-  BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
+  BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor)));
+  BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
   unsigned NumParams = Record[Idx++];
   llvm::SmallVector<ParmVarDecl *, 16> Params;
   Params.reserve(NumParams);
@@ -782,13 +800,13 @@
   
       bool IsBaseInitializer = Record[Idx++];
       if (IsBaseInitializer) {
-        BaseClassInfo = Reader.GetTypeSourceInfo(Record, Idx);
+        BaseClassInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
         IsBaseVirtual = Record[Idx++];
       } else {
         Member = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
       }
       SourceLocation MemberLoc = Reader.ReadSourceLocation(Record, Idx);
-      Expr *Init = Reader.ReadExpr();
+      Expr *Init = Reader.ReadExpr(Cursor);
       FieldDecl *AnonUnionMember
           = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
       SourceLocation LParenLoc = Reader.ReadSourceLocation(Record, Idx);
@@ -846,7 +864,7 @@
 void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
   VisitDecl(D);
   if (Record[Idx++])
-    D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
+    D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
   else
     D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
   D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
@@ -863,7 +881,7 @@
   if (Record[Idx++]) // HasFriendDecl
     D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
   else
-    D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
+    D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
   D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
 }
 
@@ -917,21 +935,21 @@
       D->setInstantiationOf(CTD);
     } else {
       llvm::SmallVector<TemplateArgument, 8> TemplArgs;
-      Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
+      Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
       D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
                             TemplArgs.data(), TemplArgs.size());
     }
   }
 
   // Explicit info.
-  if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
+  if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) {
     D->setTypeAsWritten(TyInfo);
     D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
     D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
   }
 
   llvm::SmallVector<TemplateArgument, 8> TemplArgs;
-  Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
+  Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
   D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
   SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
   if (POI.isValid())
@@ -959,7 +977,7 @@
   TemplateArgumentListInfo ArgInfos;
   unsigned NumArgs = Record[Idx++];
   while (NumArgs--)
-    ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
+    ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
   D->initTemplateArgsAsWritten(ArgInfos);
   
   D->setSequenceNumber(Record[Idx++]);
@@ -1007,7 +1025,7 @@
   D->setParameterPack(Record[Idx++]);
 
   bool Inherited = Record[Idx++];
-  TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
+  TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
   D->setDefaultArgument(DefArg, Inherited);
 }
 
@@ -1018,7 +1036,7 @@
   D->setPosition(Record[Idx++]);
   // Rest of NonTypeTemplateParmDecl.
   if (Record[Idx++]) {
-    Expr *DefArg = Reader.ReadExpr();
+    Expr *DefArg = Reader.ReadExpr(Cursor);
     bool Inherited = Record[Idx++];
     D->setDefaultArgument(DefArg, Inherited);
  }
@@ -1030,15 +1048,15 @@
   D->setDepth(Record[Idx++]);
   D->setPosition(Record[Idx++]);
   // Rest of TemplateTemplateParmDecl.
-  TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Record, Idx);
+  TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx);
   bool IsInherited = Record[Idx++];
   D->setDefaultArgument(Arg, IsInherited);
 }
 
 void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
   VisitDecl(D);
-  D->AssertExpr = Reader.ReadExpr();
-  D->Message = cast<StringLiteral>(Reader.ReadExpr());
+  D->AssertExpr = Reader.ReadExpr(Cursor);
+  D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor));
 }
 
 std::pair<uint64_t, uint64_t>
@@ -1053,8 +1071,7 @@
 //===----------------------------------------------------------------------===//
 
 /// \brief Reads attributes from the current stream position.
-Attr *PCHReader::ReadAttributes() {
-  llvm::BitstreamCursor &DeclsCursor = Chain[0]->DeclsCursor;
+Attr *PCHReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor) {
   unsigned Code = DeclsCursor.ReadCode();
   assert(Code == llvm::bitc::UNABBREV_RECORD &&
          "Expected unabbreviated record"); (void)Code;
@@ -1297,7 +1314,7 @@
   RecordData Record;
   unsigned Code = DeclsCursor.ReadCode();
   unsigned Idx = 0;
-  PCHDeclReader Reader(*this, Record, Idx);
+  PCHDeclReader Reader(*this, DeclsCursor, Record, Idx);
 
   Decl *D = 0;
   switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {

Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=109191&r1=109190&r2=109191&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Thu Jul 22 17:43:28 2010
@@ -21,13 +21,14 @@
 
   class PCHStmtReader : public StmtVisitor<PCHStmtReader> {
     PCHReader &Reader;
+    llvm::BitstreamCursor &DeclsCursor;
     const PCHReader::RecordData &Record;
     unsigned &Idx;
 
   public:
-    PCHStmtReader(PCHReader &Reader, const PCHReader::RecordData &Record,
-                  unsigned &Idx)
-      : Reader(Reader), Record(Record), Idx(Idx) { }
+    PCHStmtReader(PCHReader &Reader, llvm::BitstreamCursor &Cursor,
+                  const PCHReader::RecordData &Record, unsigned &Idx)
+      : Reader(Reader), DeclsCursor(Cursor), Record(Record), Idx(Idx) { }
 
     /// \brief The number of record fields required for the Stmt class
     /// itself.
@@ -164,7 +165,8 @@
   ArgInfo.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
   ArgInfo.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
   for (unsigned i = 0; i != NumTemplateArgs; ++i)
-    ArgInfo.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
+    ArgInfo.addArgument(
+        Reader.ReadTemplateArgumentLoc(DeclsCursor, Record, Idx));
   ArgList.initializeFrom(ArgInfo);
 }
 
@@ -479,7 +481,7 @@
   ++Idx;
   E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-  E->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
+  E->setTypeSourceInfo(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
   for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
     Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]);
     SourceLocation Start = SourceLocation::getFromRawEncoding(Record[Idx++]);
@@ -518,7 +520,7 @@
     E->setArgument(Reader.ReadSubExpr());
     ++Idx;
   } else {
-    E->setArgument(Reader.GetTypeSourceInfo(Record, Idx));
+    E->setArgument(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
   }
   E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
@@ -597,7 +599,7 @@
 
 void PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
   VisitCastExpr(E);
-  E->setTypeInfoAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
+  E->setTypeInfoAsWritten(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
 }
 
 void PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
@@ -609,7 +611,7 @@
 void PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
   VisitExpr(E);
   E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-  E->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
+  E->setTypeSourceInfo(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
   E->setInitializer(Reader.ReadSubExpr());
   E->setFileScope(Record[Idx++]);
 }
@@ -783,7 +785,7 @@
 
 void PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
   VisitExpr(E);
-  E->setEncodedTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
+  E->setEncodedTypeSourceInfo(Reader.GetTypeSourceInfo(DeclsCursor,Record,Idx));
   E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
@@ -844,7 +846,7 @@
     break;
 
   case ObjCMessageExpr::Class:
-    E->setClassReceiver(Reader.GetTypeSourceInfo(Record, Idx));
+    E->setClassReceiver(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
     break;
 
   case ObjCMessageExpr::SuperClass:
@@ -1013,7 +1015,8 @@
   VisitExpr(E);
   E->setSourceRange(Reader.ReadSourceRange(Record, Idx));
   if (E->isTypeOperand()) { // typeid(int)
-    E->setTypeOperandSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
+    E->setTypeOperandSourceInfo(
+        Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
     return;
   }
   
@@ -1107,7 +1110,7 @@
   E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
   E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
   E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
-  E->setScopeTypeInfo(Reader.GetTypeSourceInfo(Record, Idx));
+  E->setScopeTypeInfo(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
   E->setColonColonLoc(Reader.ReadSourceLocation(Record, Idx));
   E->setTildeLoc(Reader.ReadSourceLocation(Record, Idx));
   
@@ -1115,7 +1118,7 @@
   if (II)
     E->setDestroyedType(II, Reader.ReadSourceLocation(Record, Idx));
   else
-    E->setDestroyedType(Reader.GetTypeSourceInfo(Record, Idx));
+    E->setDestroyedType(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
 }
 
 void PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
@@ -1232,12 +1235,11 @@
   E->QueriedType = Reader.GetType(Record[Idx++]);
 }
 
-Stmt *PCHReader::ReadStmt() {
+Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
   switch (ReadingKind) {
   case Read_Decl:
   case Read_Type:
-    // Read a statement from the current DeclCursor.
-    return ReadStmtFromStream(Chain[0]->DeclsCursor);
+    return ReadStmtFromStream(Cursor);
   case Read_Stmt:
     return ReadSubStmt();
   }
@@ -1246,8 +1248,8 @@
   return 0;
 }
 
-Expr *PCHReader::ReadExpr() {
-  return cast_or_null<Expr>(ReadStmt());
+Expr *PCHReader::ReadExpr(llvm::BitstreamCursor &Cursor) {
+  return cast_or_null<Expr>(ReadStmt(Cursor));
 }
 
 Expr *PCHReader::ReadSubExpr() {
@@ -1271,7 +1273,7 @@
 
   RecordData Record;
   unsigned Idx;
-  PCHStmtReader Reader(*this, Record, Idx);
+  PCHStmtReader Reader(*this, Cursor, Record, Idx);
   Stmt::EmptyShell Empty;
 
   while (true) {
@@ -1460,7 +1462,7 @@
         ArgInfo.setLAngleLoc(ReadSourceLocation(Record, Idx));
         ArgInfo.setRAngleLoc(ReadSourceLocation(Record, Idx));
         for (unsigned i = 0; i != NumTemplateArgs; ++i)
-          ArgInfo.addArgument(ReadTemplateArgumentLoc(Record, Idx));
+          ArgInfo.addArgument(ReadTemplateArgumentLoc(Cursor, Record, Idx));
       }
       
       NamedDecl *FoundD = cast_or_null<NamedDecl>(GetDecl(Record[Idx++]));

Added: cfe/trunk/test/PCH/Inputs/chain-trivial1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/chain-trivial1.h?rev=109191&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/PCH/Inputs/chain-trivial2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/chain-trivial2.h?rev=109191&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/PCH/chain-trivial.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-trivial.c?rev=109191&view=auto
==============================================================================
--- cfe/trunk/test/PCH/chain-trivial.c (added)
+++ cfe/trunk/test/PCH/chain-trivial.c Thu Jul 22 17:43:28 2010
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t1 %S/Inputs/chain-trivial1.h
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t2 -include-pch %t1 -chained-pch %S/Inputs/chain-trivial2.h
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-print -include-pch %t2 %s | FileCheck %s
+// CHECK: struct __va_list_tag {





More information about the cfe-commits mailing list