[cfe-commits] r70190 - in /cfe/trunk: include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHReaderStmt.cpp

Chris Lattner sabre at nondot.org
Sun Apr 26 22:58:24 PDT 2009


Author: lattner
Date: Mon Apr 27 00:58:23 2009
New Revision: 70190

URL: http://llvm.org/viewvc/llvm-project?rev=70190&view=rev
Log:
read all decls (and attributes and stmts/exprs referenced by the decl)
from the DeclsCursor.

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=70190&r1=70189&r2=70190&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Mon Apr 27 00:58:23 2009
@@ -88,9 +88,7 @@
 
   /// \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 @@
   /// \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 @@
 
   /// \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.

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=70190&r1=70189&r2=70190&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Mon Apr 27 00:58:23 2009
@@ -66,7 +66,11 @@
 
 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 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 @@
     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 @@
 /// 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 @@
 
 /// \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;
 

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=70190&r1=70189&r2=70190&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Mon Apr 27 00:58:23 2009
@@ -154,14 +154,14 @@
 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 @@
   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 @@
   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 @@
                          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::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 @@
 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:

Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=70190&r1=70189&r2=70190&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Mon Apr 27 00:58:23 2009
@@ -1131,4 +1131,3 @@
   SwitchCaseStmts.clear();
   return StmtStack.back();
 }
-





More information about the cfe-commits mailing list