]> granicus.if.org Git - clang/commitdiff
read all decls (and attributes and stmts/exprs referenced by the decl)
authorChris Lattner <sabre@nondot.org>
Mon, 27 Apr 2009 05:58:23 +0000 (05:58 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 27 Apr 2009 05:58:23 +0000 (05:58 +0000)
from the DeclsCursor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70190 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PCHReader.h
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHReaderDecl.cpp
lib/Frontend/PCHReaderStmt.cpp

index 5e75f720614d7973a1f8268a334304f69650361b..ecfc506169f0c3dbf1afce64dba71b02f74b2a08 100644 (file)
@@ -88,9 +88,7 @@ private:
 
   /// \brief The bitstream reader from which we'll read the PCH file.
   llvm::BitstreamReader StreamFile;
-public:
   llvm::BitstreamCursor Stream;
-private:
 
   /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block.  It
   /// has read all the abbreviations at the start of the block and is ready to
@@ -404,11 +402,19 @@ public:
   /// \brief Reads attributes from the current stream position.
   Attr *ReadAttributes();
 
-  /// \brief Reads an expression from the current stream position.
-  Expr *ReadExpr();
+  /// \brief ReadDeclExpr - Reads an expression from the current decl cursor.
+  Expr *ReadDeclExpr();
+      
+  /// \brief ReadTypeExpr - Reads an expression from the current type cursor.
+  Expr *ReadTypeExpr();
 
   /// \brief Reads a statement from the specified cursor.
   Stmt *ReadStmt(llvm::BitstreamCursor &Cursor);
+      
+  /// \brief Read a statement from the current DeclCursor.
+  Stmt *ReadDeclStmt() {
+    return ReadStmt(DeclsCursor);
+  }
 
   /// \brief Reads the macro record located at the given offset.
   void ReadMacroRecord(uint64_t Offset);
@@ -428,6 +434,7 @@ public:
 
   /// \brief Retrieve the stream that this PCH reader is reading from.
   llvm::BitstreamCursor &getStream() { return Stream; }
+  llvm::BitstreamCursor &getDeclsCursor() { return DeclsCursor; }
 
   /// \brief Retrieve the identifier table associated with the
   /// preprocessor.
index 4ec2a3a18aaf6d347c433c621f58898a1c48d80b..4f60db9e685b284ba0eebf5d1ed9a17cc7debd3a 100644 (file)
@@ -66,7 +66,11 @@ PCHReader::PCHReader(Preprocessor &PP, ASTContext &Context)
 
 PCHReader::~PCHReader() {}
 
-Expr *PCHReader::ReadExpr() {
+Expr *PCHReader::ReadDeclExpr() {
+  return dyn_cast_or_null<Expr>(ReadStmt(DeclsCursor));
+}
+
+Expr *PCHReader::ReadTypeExpr() {
   return dyn_cast_or_null<Expr>(ReadStmt(Stream));
 }
 
@@ -1167,7 +1171,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
     QualType ElementType = GetType(Record[0]);
     ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
     unsigned IndexTypeQuals = Record[2];
-    return Context.getVariableArrayType(ElementType, ReadExpr(),
+    return Context.getVariableArrayType(ElementType, ReadTypeExpr(),
                                         ASM, IndexTypeQuals);
   }
 
@@ -1220,7 +1224,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
     return Context.getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0])));
 
   case pch::TYPE_TYPEOF_EXPR:
-    return Context.getTypeOfExprType(ReadExpr());
+    return Context.getTypeOfExprType(ReadTypeExpr());
 
   case pch::TYPE_TYPEOF: {
     if (Record.size() != 1) {
@@ -1337,12 +1341,10 @@ Decl *PCHReader::GetDecl(pch::DeclID ID) {
 /// source each time it is called, and is meant to be used via a
 /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
 Stmt *PCHReader::GetDeclStmt(uint64_t Offset) {
-  // Keep track of where we are in the stream, then jump back there
-  // after reading this declaration.
-  SavedStreamPosition SavedPosition(Stream);
-
-  Stream.JumpToBit(Offset);
-  return ReadStmt(Stream);
+  // Since we know tha this statement is part of a decl, make sure to use the
+  // decl cursor to read it.
+  DeclsCursor.JumpToBit(Offset);
+  return ReadStmt(DeclsCursor);
 }
 
 bool PCHReader::ReadDeclsLexicallyInContext(DeclContext *DC,
@@ -1711,13 +1713,13 @@ std::string PCHReader::ReadString(const RecordData &Record, unsigned &Idx) {
 
 /// \brief Reads attributes from the current stream position.
 Attr *PCHReader::ReadAttributes() {
-  unsigned Code = Stream.ReadCode();
+  unsigned Code = DeclsCursor.ReadCode();
   assert(Code == llvm::bitc::UNABBREV_RECORD && 
          "Expected unabbreviated record"); (void)Code;
   
   RecordData Record;
   unsigned Idx = 0;
-  unsigned RecCode = Stream.ReadRecord(Code, Record);
+  unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
   assert(RecCode == pch::DECL_ATTR && "Expected attribute record"); 
   (void)RecCode;
 
index 74b489512d8b1f819014114a2e5e3822ae2300b2..2bf5a890580efbae78af85389f5a6c3415ecb120 100644 (file)
@@ -154,14 +154,14 @@ void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
 void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
   VisitValueDecl(ECD);
   if (Record[Idx++])
-    ECD->setInitExpr(Reader.ReadExpr());
+    ECD->setInitExpr(Reader.ReadDeclExpr());
   ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
 }
 
 void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
   VisitValueDecl(FD);
   if (Record[Idx++])
-    FD->setLazyBody(Reader.getStream().GetCurrentBitNo());
+    FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
   FD->setPreviousDeclaration(
                    cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
   FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
@@ -186,7 +186,7 @@ void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
   if (Record[Idx++]) {
     // In practice, this won't be executed (since method definitions
     // don't occur in header files).
-    MD->setBody(Reader.ReadStmt(Reader.Stream));
+    MD->setBody(Reader.ReadDeclStmt());
     MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
     MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
   }
@@ -346,7 +346,7 @@ void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
   VisitValueDecl(FD);
   FD->setMutable(Record[Idx++]);
   if (Record[Idx++])
-    FD->setBitWidth(Reader.ReadExpr());
+    FD->setBitWidth(Reader.ReadDeclExpr());
 }
 
 void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
@@ -359,7 +359,7 @@ void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
                          cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
   VD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   if (Record[Idx++])
-    VD->setInit(Reader.ReadExpr());
+    VD->setInit(Reader.ReadDeclExpr());
 }
 
 void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
@@ -379,12 +379,12 @@ void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) {
 
 void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
   VisitDecl(AD);
-  AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
+  AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
 }
 
 void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
   VisitDecl(BD);
-  BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Reader.Stream)));
+  BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
   unsigned NumParams = Record[Idx++];
   llvm::SmallVector<ParmVarDecl *, 16> Params;
   Params.reserve(NumParams);
@@ -435,16 +435,16 @@ static bool isConsumerInterestedIn(Decl *D) {
 Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
   // Keep track of where we are in the stream, then jump back there
   // after reading this declaration.
-  SavedStreamPosition SavedPosition(Stream);
+  SavedStreamPosition SavedPosition(DeclsCursor);
 
-  Decl *D = 0;
-  Stream.JumpToBit(Offset);
+  DeclsCursor.JumpToBit(Offset);
   RecordData Record;
-  unsigned Code = Stream.ReadCode();
+  unsigned Code = DeclsCursor.ReadCode();
   unsigned Idx = 0;
   PCHDeclReader Reader(*this, Record, Idx);
 
-  switch ((pch::DeclCode)Stream.ReadRecord(Code, Record)) {
+  Decl *D = 0;
+  switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
   case pch::DECL_ATTR:
   case pch::DECL_CONTEXT_LEXICAL:
   case pch::DECL_CONTEXT_VISIBLE:
index f38af9b3c80f15569e310fc5683daaa6b6c612a4..af3e026b575e4e1957f297d80f26e7f828b8ebb9 100644 (file)
@@ -1131,4 +1131,3 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
   SwitchCaseStmts.clear();
   return StmtStack.back();
 }
-