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