From da93061f56d5820725b01a140879d047554e7d32 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 27 Apr 2009 05:58:23 +0000 Subject: [PATCH] read all decls (and attributes and stmts/exprs referenced by the decl) 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 | 15 +++++++++++---- lib/Frontend/PCHReader.cpp | 24 +++++++++++++----------- lib/Frontend/PCHReaderDecl.cpp | 24 ++++++++++++------------ lib/Frontend/PCHReaderStmt.cpp | 1 - 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h index 5e75f72061..ecfc506169 100644 --- a/include/clang/Frontend/PCHReader.h +++ b/include/clang/Frontend/PCHReader.h @@ -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. diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 4ec2a3a18a..4f60db9e68 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -66,7 +66,11 @@ PCHReader::PCHReader(Preprocessor &PP, ASTContext &Context) PCHReader::~PCHReader() {} -Expr *PCHReader::ReadExpr() { +Expr *PCHReader::ReadDeclExpr() { + return dyn_cast_or_null(ReadStmt(DeclsCursor)); +} + +Expr *PCHReader::ReadTypeExpr() { return dyn_cast_or_null(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(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; diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index 74b489512d..2bf5a89058 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -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(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(Reader.GetDecl(Record[Idx++]))); MD->setCmdDecl(cast(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(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(Reader.ReadExpr())); + AD->setAsmString(cast(Reader.ReadDeclExpr())); } void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) { VisitDecl(BD); - BD->setBody(cast_or_null(Reader.ReadStmt(Reader.Stream))); + BD->setBody(cast_or_null(Reader.ReadDeclStmt())); unsigned NumParams = Record[Idx++]; llvm::SmallVector 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: diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index f38af9b3c8..af3e026b57 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -1131,4 +1131,3 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) { SwitchCaseStmts.clear(); return StmtStack.back(); } - -- 2.40.0