Modify the way sub-statements are stored and retrieved from PCH.
Before this commit, sub-stmts were stored as encountered and when they were placed in the Stmts stack we had to know what index
each stmt operand has. This complicated supporting variable sub-stmts and sub-stmts that were contained in TypeSourceInfos, e.g.
x = sizeof(int[1]);
would crash PCH.
Now, sub-stmts are stored in reverse order, from last to first, so that when reading them, in order to get the next sub-stmt we just
need to pop the last stmt from the stack. This greatly simplified the way stmts are written and read (just use PCHWriter::AddStmt and
PCHReader::ReadStmt accordingly) and allowed variable stmt operands and TypeSourceInfo exprs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107087 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 5628de3..a526fd6 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -321,18 +321,6 @@
// PCH reader implementation
//===----------------------------------------------------------------------===//
-// Give ExprReader's VTable a home.
-Expr *PCHReader::ExprReader::Read() { return 0; }
-
-namespace {
- class DeclExprReader : public PCHReader::ExprReader {
- PCHReader &Reader;
- public:
- DeclExprReader(PCHReader &reader) : Reader(reader) { }
- virtual Expr *Read() { return Reader.ReadDeclExpr(); }
- };
-} // anonymous namespace
-
PCHReader::PCHReader(Preprocessor &PP, ASTContext *Context,
const char *isysroot)
: Listener(new PCHValidator(PP, *this)), SourceMgr(PP.getSourceManager()),
@@ -372,14 +360,6 @@
PCHReader::~PCHReader() {}
-Expr *PCHReader::ReadDeclExpr() {
- return dyn_cast_or_null<Expr>(ReadStmt(DeclsCursor));
-}
-
-Expr *PCHReader::ReadTypeExpr() {
- return dyn_cast_or_null<Expr>(ReadStmt(DeclsCursor));
-}
-
namespace {
class PCHMethodPoolLookupTrait {
@@ -1969,6 +1949,8 @@
// after reading this type.
SavedStreamPosition SavedPosition(DeclsCursor);
+ ReadingKindTracker ReadingKind(Read_Type, *this);
+
// Note that we are loading a type record.
LoadingTypeOrDecl Loading(*this);
@@ -2064,7 +2046,7 @@
unsigned IndexTypeQuals = Record[2];
SourceLocation LBLoc = SourceLocation::getFromRawEncoding(Record[3]);
SourceLocation RBLoc = SourceLocation::getFromRawEncoding(Record[4]);
- return Context->getVariableArrayType(ElementType, ReadTypeExpr(),
+ return Context->getVariableArrayType(ElementType, ReadExpr(),
ASM, IndexTypeQuals,
SourceRange(LBLoc, RBLoc));
}
@@ -2141,7 +2123,7 @@
return Context->getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0])));
case pch::TYPE_TYPEOF_EXPR:
- return Context->getTypeOfExprType(ReadTypeExpr());
+ return Context->getTypeOfExprType(ReadExpr());
case pch::TYPE_TYPEOF: {
if (Record.size() != 1) {
@@ -2153,7 +2135,7 @@
}
case pch::TYPE_DECLTYPE:
- return Context->getDecltypeType(ReadTypeExpr());
+ return Context->getDecltypeType(ReadExpr());
case pch::TYPE_RECORD:
if (Record.size() != 1) {
@@ -2319,7 +2301,7 @@
TL.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
TL.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
if (Record[Idx++])
- TL.setSizeExpr(Reader.ReadDeclExpr());
+ TL.setSizeExpr(Reader.ReadExpr());
else
TL.setSizeExpr(0);
}
@@ -2511,10 +2493,10 @@
TemplateArgumentLocInfo
PCHReader::GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
const RecordData &Record,
- unsigned &Index, ExprReader &ExprRdr) {
+ unsigned &Index) {
switch (Kind) {
case TemplateArgument::Expression:
- return ExprRdr.Read();
+ return ReadExpr();
case TemplateArgument::Type:
return GetTypeSourceInfo(Record, Index);
case TemplateArgument::Template: {
@@ -2532,32 +2514,16 @@
return TemplateArgumentLocInfo();
}
-TemplateArgumentLocInfo
-PCHReader::GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
- const RecordData &Record,
- unsigned &Index) {
- DeclExprReader DeclExprReader(*this);
- return GetTemplateArgumentLocInfo(Kind, Record, Index, DeclExprReader);
-}
-
TemplateArgumentLoc
-PCHReader::ReadTemplateArgumentLoc(const RecordData &Record, unsigned &Index,
- ExprReader &ExprRdr) {
- TemplateArgument Arg = ReadTemplateArgument(Record, Index, ExprRdr);
+PCHReader::ReadTemplateArgumentLoc(const RecordData &Record, unsigned &Index) {
+ TemplateArgument Arg = ReadTemplateArgument(Record, Index);
if (Arg.getKind() == TemplateArgument::Expression) {
if (Record[Index++]) // bool InfoHasSameExpr.
return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr()));
}
return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(Arg.getKind(),
- Record, Index,
- ExprRdr));
-}
-
-TemplateArgumentLoc
-PCHReader::ReadTemplateArgumentLoc(const RecordData &Record, unsigned &Index) {
- DeclExprReader DeclExprReader(*this);
- return ReadTemplateArgumentLoc(Record, Index, DeclExprReader);
+ Record, Index));
}
Decl *PCHReader::GetExternalDecl(uint32_t ID) {
@@ -2589,7 +2555,7 @@
// 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);
+ return ReadStmtFromStream(DeclsCursor);
}
bool PCHReader::FindExternalLexicalDecls(const DeclContext *DC,
@@ -3034,8 +3000,7 @@
}
TemplateArgument
-PCHReader::ReadTemplateArgument(const RecordData &Record, unsigned &Idx,
- ExprReader &ExprRdr) {
+PCHReader::ReadTemplateArgument(const RecordData &Record, unsigned &Idx) {
switch ((TemplateArgument::ArgKind)Record[Idx++]) {
case TemplateArgument::Null:
return TemplateArgument();
@@ -3051,13 +3016,13 @@
case TemplateArgument::Template:
return TemplateArgument(ReadTemplateName(Record, Idx));
case TemplateArgument::Expression:
- return TemplateArgument(ExprRdr.Read());
+ return TemplateArgument(ReadExpr());
case TemplateArgument::Pack: {
unsigned NumArgs = Record[Idx++];
llvm::SmallVector<TemplateArgument, 8> Args;
Args.reserve(NumArgs);
while (NumArgs--)
- Args.push_back(ReadTemplateArgument(Record, Idx, ExprRdr));
+ Args.push_back(ReadTemplateArgument(Record, Idx));
TemplateArgument TemplArg;
TemplArg.setArgumentPack(Args.data(), Args.size(), /*CopyArgs=*/true);
return TemplArg;
@@ -3068,12 +3033,6 @@
return TemplateArgument();
}
-TemplateArgument
-PCHReader::ReadTemplateArgument(const RecordData &Record, unsigned &Idx) {
- DeclExprReader DeclExprReader(*this);
- return ReadTemplateArgument(Record, Idx, DeclExprReader);
-}
-
TemplateParameterList *
PCHReader::ReadTemplateParameterList(const RecordData &Record, unsigned &Idx) {
SourceLocation TemplateLoc = ReadSourceLocation(Record, Idx);