Skip to content

Commit 1de76db

Browse files
committed
read all decls (and attributes and stmts/exprs referenced by the decl)
from the DeclsCursor. llvm-svn: 70190
1 parent 9c28af0 commit 1de76db

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

clang/include/clang/Frontend/PCHReader.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ class PCHReader
8888

8989
/// \brief The bitstream reader from which we'll read the PCH file.
9090
llvm::BitstreamReader StreamFile;
91-
public:
9291
llvm::BitstreamCursor Stream;
93-
private:
9492

9593
/// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It
9694
/// has read all the abbreviations at the start of the block and is ready to
@@ -404,11 +402,19 @@ class PCHReader
404402
/// \brief Reads attributes from the current stream position.
405403
Attr *ReadAttributes();
406404

407-
/// \brief Reads an expression from the current stream position.
408-
Expr *ReadExpr();
405+
/// \brief ReadDeclExpr - Reads an expression from the current decl cursor.
406+
Expr *ReadDeclExpr();
407+
408+
/// \brief ReadTypeExpr - Reads an expression from the current type cursor.
409+
Expr *ReadTypeExpr();
409410

410411
/// \brief Reads a statement from the specified cursor.
411412
Stmt *ReadStmt(llvm::BitstreamCursor &Cursor);
413+
414+
/// \brief Read a statement from the current DeclCursor.
415+
Stmt *ReadDeclStmt() {
416+
return ReadStmt(DeclsCursor);
417+
}
412418

413419
/// \brief Reads the macro record located at the given offset.
414420
void ReadMacroRecord(uint64_t Offset);
@@ -428,6 +434,7 @@ class PCHReader
428434

429435
/// \brief Retrieve the stream that this PCH reader is reading from.
430436
llvm::BitstreamCursor &getStream() { return Stream; }
437+
llvm::BitstreamCursor &getDeclsCursor() { return DeclsCursor; }
431438

432439
/// \brief Retrieve the identifier table associated with the
433440
/// preprocessor.

clang/lib/Frontend/PCHReader.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ PCHReader::PCHReader(Preprocessor &PP, ASTContext &Context)
6666

6767
PCHReader::~PCHReader() {}
6868

69-
Expr *PCHReader::ReadExpr() {
69+
Expr *PCHReader::ReadDeclExpr() {
70+
return dyn_cast_or_null<Expr>(ReadStmt(DeclsCursor));
71+
}
72+
73+
Expr *PCHReader::ReadTypeExpr() {
7074
return dyn_cast_or_null<Expr>(ReadStmt(Stream));
7175
}
7276

@@ -1167,7 +1171,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
11671171
QualType ElementType = GetType(Record[0]);
11681172
ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
11691173
unsigned IndexTypeQuals = Record[2];
1170-
return Context.getVariableArrayType(ElementType, ReadExpr(),
1174+
return Context.getVariableArrayType(ElementType, ReadTypeExpr(),
11711175
ASM, IndexTypeQuals);
11721176
}
11731177

@@ -1220,7 +1224,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
12201224
return Context.getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0])));
12211225

12221226
case pch::TYPE_TYPEOF_EXPR:
1223-
return Context.getTypeOfExprType(ReadExpr());
1227+
return Context.getTypeOfExprType(ReadTypeExpr());
12241228

12251229
case pch::TYPE_TYPEOF: {
12261230
if (Record.size() != 1) {
@@ -1337,12 +1341,10 @@ Decl *PCHReader::GetDecl(pch::DeclID ID) {
13371341
/// source each time it is called, and is meant to be used via a
13381342
/// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
13391343
Stmt *PCHReader::GetDeclStmt(uint64_t Offset) {
1340-
// Keep track of where we are in the stream, then jump back there
1341-
// after reading this declaration.
1342-
SavedStreamPosition SavedPosition(Stream);
1343-
1344-
Stream.JumpToBit(Offset);
1345-
return ReadStmt(Stream);
1344+
// Since we know tha this statement is part of a decl, make sure to use the
1345+
// decl cursor to read it.
1346+
DeclsCursor.JumpToBit(Offset);
1347+
return ReadStmt(DeclsCursor);
13461348
}
13471349

13481350
bool PCHReader::ReadDeclsLexicallyInContext(DeclContext *DC,
@@ -1711,13 +1713,13 @@ std::string PCHReader::ReadString(const RecordData &Record, unsigned &Idx) {
17111713

17121714
/// \brief Reads attributes from the current stream position.
17131715
Attr *PCHReader::ReadAttributes() {
1714-
unsigned Code = Stream.ReadCode();
1716+
unsigned Code = DeclsCursor.ReadCode();
17151717
assert(Code == llvm::bitc::UNABBREV_RECORD &&
17161718
"Expected unabbreviated record"); (void)Code;
17171719

17181720
RecordData Record;
17191721
unsigned Idx = 0;
1720-
unsigned RecCode = Stream.ReadRecord(Code, Record);
1722+
unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
17211723
assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
17221724
(void)RecCode;
17231725

clang/lib/Frontend/PCHReaderDecl.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
154154
void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
155155
VisitValueDecl(ECD);
156156
if (Record[Idx++])
157-
ECD->setInitExpr(Reader.ReadExpr());
157+
ECD->setInitExpr(Reader.ReadDeclExpr());
158158
ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
159159
}
160160

161161
void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
162162
VisitValueDecl(FD);
163163
if (Record[Idx++])
164-
FD->setLazyBody(Reader.getStream().GetCurrentBitNo());
164+
FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
165165
FD->setPreviousDeclaration(
166166
cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
167167
FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
@@ -186,7 +186,7 @@ void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
186186
if (Record[Idx++]) {
187187
// In practice, this won't be executed (since method definitions
188188
// don't occur in header files).
189-
MD->setBody(Reader.ReadStmt(Reader.Stream));
189+
MD->setBody(Reader.ReadDeclStmt());
190190
MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
191191
MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
192192
}
@@ -346,7 +346,7 @@ void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
346346
VisitValueDecl(FD);
347347
FD->setMutable(Record[Idx++]);
348348
if (Record[Idx++])
349-
FD->setBitWidth(Reader.ReadExpr());
349+
FD->setBitWidth(Reader.ReadDeclExpr());
350350
}
351351

352352
void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
@@ -359,7 +359,7 @@ void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
359359
cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
360360
VD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
361361
if (Record[Idx++])
362-
VD->setInit(Reader.ReadExpr());
362+
VD->setInit(Reader.ReadDeclExpr());
363363
}
364364

365365
void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
@@ -379,12 +379,12 @@ void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) {
379379

380380
void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
381381
VisitDecl(AD);
382-
AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
382+
AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
383383
}
384384

385385
void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
386386
VisitDecl(BD);
387-
BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Reader.Stream)));
387+
BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
388388
unsigned NumParams = Record[Idx++];
389389
llvm::SmallVector<ParmVarDecl *, 16> Params;
390390
Params.reserve(NumParams);
@@ -435,16 +435,16 @@ static bool isConsumerInterestedIn(Decl *D) {
435435
Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
436436
// Keep track of where we are in the stream, then jump back there
437437
// after reading this declaration.
438-
SavedStreamPosition SavedPosition(Stream);
438+
SavedStreamPosition SavedPosition(DeclsCursor);
439439

440-
Decl *D = 0;
441-
Stream.JumpToBit(Offset);
440+
DeclsCursor.JumpToBit(Offset);
442441
RecordData Record;
443-
unsigned Code = Stream.ReadCode();
442+
unsigned Code = DeclsCursor.ReadCode();
444443
unsigned Idx = 0;
445444
PCHDeclReader Reader(*this, Record, Idx);
446445

447-
switch ((pch::DeclCode)Stream.ReadRecord(Code, Record)) {
446+
Decl *D = 0;
447+
switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
448448
case pch::DECL_ATTR:
449449
case pch::DECL_CONTEXT_LEXICAL:
450450
case pch::DECL_CONTEXT_VISIBLE:

clang/lib/Frontend/PCHReaderStmt.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,4 +1131,3 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
11311131
SwitchCaseStmts.clear();
11321132
return StmtStack.back();
11331133
}
1134-

0 commit comments

Comments
 (0)