namespace {
- class PCHStmtReader : public StmtVisitor<PCHStmtReader, unsigned> {
+ class PCHStmtReader : public StmtVisitor<PCHStmtReader> {
PCHReader &Reader;
const PCHReader::RecordData &Record;
unsigned &Idx;
- llvm::SmallVectorImpl<Stmt *> &StmtStack;
public:
PCHStmtReader(PCHReader &Reader, const PCHReader::RecordData &Record,
- unsigned &Idx, llvm::SmallVectorImpl<Stmt *> &StmtStack)
- : Reader(Reader), Record(Record), Idx(Idx), StmtStack(StmtStack) { }
+ unsigned &Idx)
+ : Reader(Reader), Record(Record), Idx(Idx) { }
/// \brief The number of record fields required for the Stmt class
/// itself.
static const unsigned NumExprFields = NumStmtFields + 3;
/// \brief Read and initialize a ExplicitTemplateArgumentList structure.
- /// \return the number of Exprs that were read.
- unsigned
- ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
- unsigned NumTemplateArgs,
- llvm::SmallVectorImpl<Stmt *>::iterator EndOfExprs);
-
- // Each of the Visit* functions reads in part of the expression
- // from the given record and the current expression stack, then
- // return the total number of operands that it read from the
- // expression stack.
-
- unsigned VisitStmt(Stmt *S);
- unsigned VisitNullStmt(NullStmt *S);
- unsigned VisitCompoundStmt(CompoundStmt *S);
- unsigned VisitSwitchCase(SwitchCase *S);
- unsigned VisitCaseStmt(CaseStmt *S);
- unsigned VisitDefaultStmt(DefaultStmt *S);
- unsigned VisitLabelStmt(LabelStmt *S);
- unsigned VisitIfStmt(IfStmt *S);
- unsigned VisitSwitchStmt(SwitchStmt *S);
- unsigned VisitWhileStmt(WhileStmt *S);
- unsigned VisitDoStmt(DoStmt *S);
- unsigned VisitForStmt(ForStmt *S);
- unsigned VisitGotoStmt(GotoStmt *S);
- unsigned VisitIndirectGotoStmt(IndirectGotoStmt *S);
- unsigned VisitContinueStmt(ContinueStmt *S);
- unsigned VisitBreakStmt(BreakStmt *S);
- unsigned VisitReturnStmt(ReturnStmt *S);
- unsigned VisitDeclStmt(DeclStmt *S);
- unsigned VisitAsmStmt(AsmStmt *S);
- unsigned VisitExpr(Expr *E);
- unsigned VisitPredefinedExpr(PredefinedExpr *E);
- unsigned VisitDeclRefExpr(DeclRefExpr *E);
- unsigned VisitIntegerLiteral(IntegerLiteral *E);
- unsigned VisitFloatingLiteral(FloatingLiteral *E);
- unsigned VisitImaginaryLiteral(ImaginaryLiteral *E);
- unsigned VisitStringLiteral(StringLiteral *E);
- unsigned VisitCharacterLiteral(CharacterLiteral *E);
- unsigned VisitParenExpr(ParenExpr *E);
- unsigned VisitUnaryOperator(UnaryOperator *E);
- unsigned VisitOffsetOfExpr(OffsetOfExpr *E);
- unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
- unsigned VisitArraySubscriptExpr(ArraySubscriptExpr *E);
- unsigned VisitCallExpr(CallExpr *E);
- unsigned VisitMemberExpr(MemberExpr *E);
- unsigned VisitCastExpr(CastExpr *E);
- unsigned VisitBinaryOperator(BinaryOperator *E);
- unsigned VisitCompoundAssignOperator(CompoundAssignOperator *E);
- unsigned VisitConditionalOperator(ConditionalOperator *E);
- unsigned VisitImplicitCastExpr(ImplicitCastExpr *E);
- unsigned VisitExplicitCastExpr(ExplicitCastExpr *E);
- unsigned VisitCStyleCastExpr(CStyleCastExpr *E);
- unsigned VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
- unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E);
- unsigned VisitInitListExpr(InitListExpr *E);
- unsigned VisitDesignatedInitExpr(DesignatedInitExpr *E);
- unsigned VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
- unsigned VisitVAArgExpr(VAArgExpr *E);
- unsigned VisitAddrLabelExpr(AddrLabelExpr *E);
- unsigned VisitStmtExpr(StmtExpr *E);
- unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
- unsigned VisitChooseExpr(ChooseExpr *E);
- unsigned VisitGNUNullExpr(GNUNullExpr *E);
- unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E);
- unsigned VisitBlockExpr(BlockExpr *E);
- unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
- unsigned VisitObjCStringLiteral(ObjCStringLiteral *E);
- unsigned VisitObjCEncodeExpr(ObjCEncodeExpr *E);
- unsigned VisitObjCSelectorExpr(ObjCSelectorExpr *E);
- unsigned VisitObjCProtocolExpr(ObjCProtocolExpr *E);
- unsigned VisitObjCIvarRefExpr(ObjCIvarRefExpr *E);
- unsigned VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E);
- unsigned VisitObjCImplicitSetterGetterRefExpr(
+ void ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
+ unsigned NumTemplateArgs);
+
+ void VisitStmt(Stmt *S);
+ void VisitNullStmt(NullStmt *S);
+ void VisitCompoundStmt(CompoundStmt *S);
+ void VisitSwitchCase(SwitchCase *S);
+ void VisitCaseStmt(CaseStmt *S);
+ void VisitDefaultStmt(DefaultStmt *S);
+ void VisitLabelStmt(LabelStmt *S);
+ void VisitIfStmt(IfStmt *S);
+ void VisitSwitchStmt(SwitchStmt *S);
+ void VisitWhileStmt(WhileStmt *S);
+ void VisitDoStmt(DoStmt *S);
+ void VisitForStmt(ForStmt *S);
+ void VisitGotoStmt(GotoStmt *S);
+ void VisitIndirectGotoStmt(IndirectGotoStmt *S);
+ void VisitContinueStmt(ContinueStmt *S);
+ void VisitBreakStmt(BreakStmt *S);
+ void VisitReturnStmt(ReturnStmt *S);
+ void VisitDeclStmt(DeclStmt *S);
+ void VisitAsmStmt(AsmStmt *S);
+ void VisitExpr(Expr *E);
+ void VisitPredefinedExpr(PredefinedExpr *E);
+ void VisitDeclRefExpr(DeclRefExpr *E);
+ void VisitIntegerLiteral(IntegerLiteral *E);
+ void VisitFloatingLiteral(FloatingLiteral *E);
+ void VisitImaginaryLiteral(ImaginaryLiteral *E);
+ void VisitStringLiteral(StringLiteral *E);
+ void VisitCharacterLiteral(CharacterLiteral *E);
+ void VisitParenExpr(ParenExpr *E);
+ void VisitUnaryOperator(UnaryOperator *E);
+ void VisitOffsetOfExpr(OffsetOfExpr *E);
+ void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
+ void VisitArraySubscriptExpr(ArraySubscriptExpr *E);
+ void VisitCallExpr(CallExpr *E);
+ void VisitMemberExpr(MemberExpr *E);
+ void VisitCastExpr(CastExpr *E);
+ void VisitBinaryOperator(BinaryOperator *E);
+ void VisitCompoundAssignOperator(CompoundAssignOperator *E);
+ void VisitConditionalOperator(ConditionalOperator *E);
+ void VisitImplicitCastExpr(ImplicitCastExpr *E);
+ void VisitExplicitCastExpr(ExplicitCastExpr *E);
+ void VisitCStyleCastExpr(CStyleCastExpr *E);
+ void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
+ void VisitExtVectorElementExpr(ExtVectorElementExpr *E);
+ void VisitInitListExpr(InitListExpr *E);
+ void VisitDesignatedInitExpr(DesignatedInitExpr *E);
+ void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
+ void VisitVAArgExpr(VAArgExpr *E);
+ void VisitAddrLabelExpr(AddrLabelExpr *E);
+ void VisitStmtExpr(StmtExpr *E);
+ void VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
+ void VisitChooseExpr(ChooseExpr *E);
+ void VisitGNUNullExpr(GNUNullExpr *E);
+ void VisitShuffleVectorExpr(ShuffleVectorExpr *E);
+ void VisitBlockExpr(BlockExpr *E);
+ void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
+ void VisitObjCStringLiteral(ObjCStringLiteral *E);
+ void VisitObjCEncodeExpr(ObjCEncodeExpr *E);
+ void VisitObjCSelectorExpr(ObjCSelectorExpr *E);
+ void VisitObjCProtocolExpr(ObjCProtocolExpr *E);
+ void VisitObjCIvarRefExpr(ObjCIvarRefExpr *E);
+ void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E);
+ void VisitObjCImplicitSetterGetterRefExpr(
ObjCImplicitSetterGetterRefExpr *E);
- unsigned VisitObjCMessageExpr(ObjCMessageExpr *E);
- unsigned VisitObjCSuperExpr(ObjCSuperExpr *E);
- unsigned VisitObjCIsaExpr(ObjCIsaExpr *E);
-
- unsigned VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
- unsigned VisitObjCAtCatchStmt(ObjCAtCatchStmt *);
- unsigned VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *);
- unsigned VisitObjCAtTryStmt(ObjCAtTryStmt *);
- unsigned VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
- unsigned VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
-
- unsigned VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
- unsigned VisitCXXConstructExpr(CXXConstructExpr *E);
- unsigned VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
- unsigned VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
- unsigned VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
- unsigned VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
- unsigned VisitCXXConstCastExpr(CXXConstCastExpr *E);
- unsigned VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
- unsigned VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
- unsigned VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
- unsigned VisitCXXTypeidExpr(CXXTypeidExpr *E);
- unsigned VisitCXXThisExpr(CXXThisExpr *E);
- unsigned VisitCXXThrowExpr(CXXThrowExpr *E);
- unsigned VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
- unsigned VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+ void VisitObjCMessageExpr(ObjCMessageExpr *E);
+ void VisitObjCSuperExpr(ObjCSuperExpr *E);
+ void VisitObjCIsaExpr(ObjCIsaExpr *E);
+
+ void VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
+ void VisitObjCAtCatchStmt(ObjCAtCatchStmt *);
+ void VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *);
+ void VisitObjCAtTryStmt(ObjCAtTryStmt *);
+ void VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
+ void VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
+
+ void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
+ void VisitCXXConstructExpr(CXXConstructExpr *E);
+ void VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
+ void VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
+ void VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
+ void VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
+ void VisitCXXConstCastExpr(CXXConstCastExpr *E);
+ void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
+ void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
+ void VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
+ void VisitCXXTypeidExpr(CXXTypeidExpr *E);
+ void VisitCXXThisExpr(CXXThisExpr *E);
+ void VisitCXXThrowExpr(CXXThrowExpr *E);
+ void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
+ void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
- unsigned VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
- unsigned VisitCXXNewExpr(CXXNewExpr *E);
- unsigned VisitCXXDeleteExpr(CXXDeleteExpr *E);
- unsigned VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
+ void VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
+ void VisitCXXNewExpr(CXXNewExpr *E);
+ void VisitCXXDeleteExpr(CXXDeleteExpr *E);
+ void VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
- unsigned VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
+ void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
- unsigned VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
- unsigned VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
- unsigned VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
+ void VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
+ void VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
+ void VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
- unsigned VisitOverloadExpr(OverloadExpr *E);
- unsigned VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
- unsigned VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
+ void VisitOverloadExpr(OverloadExpr *E);
+ void VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
+ void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
};
}
-unsigned PCHStmtReader::
+void PCHStmtReader::
ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
- unsigned NumTemplateArgs,
- llvm::SmallVectorImpl<Stmt *>::iterator EndOfExprs) {
-
- class StmtStackExprReader : public PCHReader::ExprReader {
- llvm::SmallVectorImpl<Stmt *>::iterator StmtI;
- public:
- StmtStackExprReader(const llvm::SmallVectorImpl<Stmt *>::iterator &stmtI)
- : StmtI(stmtI) { }
- virtual Expr *Read() { return cast_or_null<Expr>(*StmtI++); }
- };
-
- unsigned NumExprs = Record[Idx++];
-
+ unsigned NumTemplateArgs) {
TemplateArgumentListInfo ArgInfo;
ArgInfo.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
ArgInfo.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
-
- StmtStackExprReader ExprReader(EndOfExprs - NumExprs);
for (unsigned i = 0; i != NumTemplateArgs; ++i)
- ArgInfo.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx,
- ExprReader));
+ ArgInfo.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
ArgList.initializeFrom(ArgInfo);
-
- return NumExprs;
}
-unsigned PCHStmtReader::VisitStmt(Stmt *S) {
+void PCHStmtReader::VisitStmt(Stmt *S) {
assert(Idx == NumStmtFields && "Incorrect statement field count");
- return 0;
}
-unsigned PCHStmtReader::VisitNullStmt(NullStmt *S) {
+void PCHStmtReader::VisitNullStmt(NullStmt *S) {
VisitStmt(S);
S->setSemiLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) {
+void PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) {
VisitStmt(S);
+ llvm::SmallVector<Stmt *, 16> Stmts;
unsigned NumStmts = Record[Idx++];
- S->setStmts(*Reader.getContext(),
- StmtStack.data() + StmtStack.size() - NumStmts, NumStmts);
+ while (NumStmts--)
+ Stmts.push_back(Reader.ReadStmt());
+ S->setStmts(*Reader.getContext(), Stmts.data(), Stmts.size());
S->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return NumStmts;
}
-unsigned PCHStmtReader::VisitSwitchCase(SwitchCase *S) {
+void PCHStmtReader::VisitSwitchCase(SwitchCase *S) {
VisitStmt(S);
Reader.RecordSwitchCaseID(S, Record[Idx++]);
- return 0;
}
-unsigned PCHStmtReader::VisitCaseStmt(CaseStmt *S) {
+void PCHStmtReader::VisitCaseStmt(CaseStmt *S) {
VisitSwitchCase(S);
- S->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 3]));
- S->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
- S->setSubStmt(StmtStack.back());
+ S->setLHS(Reader.ReadExpr());
+ S->setRHS(Reader.ReadExpr());
+ S->setSubStmt(Reader.ReadStmt());
S->setCaseLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setEllipsisLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 3;
}
-unsigned PCHStmtReader::VisitDefaultStmt(DefaultStmt *S) {
+void PCHStmtReader::VisitDefaultStmt(DefaultStmt *S) {
VisitSwitchCase(S);
- S->setSubStmt(StmtStack.back());
+ S->setSubStmt(Reader.ReadStmt());
S->setDefaultLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned PCHStmtReader::VisitLabelStmt(LabelStmt *S) {
+void PCHStmtReader::VisitLabelStmt(LabelStmt *S) {
VisitStmt(S);
S->setID(Reader.GetIdentifierInfo(Record, Idx));
- S->setSubStmt(StmtStack.back());
+ S->setSubStmt(Reader.ReadStmt());
S->setIdentLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Reader.RecordLabelStmt(S, Record[Idx++]);
- return 1;
}
-unsigned PCHStmtReader::VisitIfStmt(IfStmt *S) {
+void PCHStmtReader::VisitIfStmt(IfStmt *S) {
VisitStmt(S);
S->setConditionVariable(*Reader.getContext(),
cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
- S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3]));
- S->setThen(StmtStack[StmtStack.size() - 2]);
- S->setElse(StmtStack[StmtStack.size() - 1]);
+ S->setCond(Reader.ReadExpr());
+ S->setThen(Reader.ReadStmt());
+ S->setElse(Reader.ReadStmt());
S->setIfLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setElseLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 3;
}
-unsigned PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) {
+void PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) {
VisitStmt(S);
S->setConditionVariable(*Reader.getContext(),
cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
- S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 2]));
- S->setBody(StmtStack.back());
+ S->setCond(Reader.ReadExpr());
+ S->setBody(Reader.ReadStmt());
S->setSwitchLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
SwitchCase *PrevSC = 0;
for (unsigned N = Record.size(); Idx != N; ++Idx) {
SC->Retain();
PrevSC = SC;
}
- return 2;
}
-unsigned PCHStmtReader::VisitWhileStmt(WhileStmt *S) {
+void PCHStmtReader::VisitWhileStmt(WhileStmt *S) {
VisitStmt(S);
S->setConditionVariable(*Reader.getContext(),
cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
- S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
- S->setBody(StmtStack.back());
+ S->setCond(Reader.ReadExpr());
+ S->setBody(Reader.ReadStmt());
S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 2;
}
-unsigned PCHStmtReader::VisitDoStmt(DoStmt *S) {
+void PCHStmtReader::VisitDoStmt(DoStmt *S) {
VisitStmt(S);
- S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
- S->setBody(StmtStack.back());
+ S->setCond(Reader.ReadExpr());
+ S->setBody(Reader.ReadStmt());
S->setDoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 2;
}
-unsigned PCHStmtReader::VisitForStmt(ForStmt *S) {
+void PCHStmtReader::VisitForStmt(ForStmt *S) {
VisitStmt(S);
- S->setInit(StmtStack[StmtStack.size() - 4]);
- S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 3]));
+ S->setInit(Reader.ReadStmt());
+ S->setCond(Reader.ReadExpr());
S->setConditionVariable(*Reader.getContext(),
cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
- S->setInc(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
- S->setBody(StmtStack.back());
+ S->setInc(Reader.ReadExpr());
+ S->setBody(Reader.ReadStmt());
S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 4;
}
-unsigned PCHStmtReader::VisitGotoStmt(GotoStmt *S) {
+void PCHStmtReader::VisitGotoStmt(GotoStmt *S) {
VisitStmt(S);
Reader.SetLabelOf(S, Record[Idx++]);
S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
+void PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
VisitStmt(S);
S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- S->setTarget(cast_or_null<Expr>(StmtStack.back()));
- return 1;
+ S->setTarget(Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitContinueStmt(ContinueStmt *S) {
+void PCHStmtReader::VisitContinueStmt(ContinueStmt *S) {
VisitStmt(S);
S->setContinueLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitBreakStmt(BreakStmt *S) {
+void PCHStmtReader::VisitBreakStmt(BreakStmt *S) {
VisitStmt(S);
S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) {
+void PCHStmtReader::VisitReturnStmt(ReturnStmt *S) {
VisitStmt(S);
- S->setRetValue(cast_or_null<Expr>(StmtStack.back()));
+ S->setRetValue(Reader.ReadExpr());
S->setReturnLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setNRVOCandidate(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
- return 1;
}
-unsigned PCHStmtReader::VisitDeclStmt(DeclStmt *S) {
+void PCHStmtReader::VisitDeclStmt(DeclStmt *S) {
VisitStmt(S);
S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Decls.data(),
Decls.size())));
}
- return 0;
}
-unsigned PCHStmtReader::VisitAsmStmt(AsmStmt *S) {
+void PCHStmtReader::VisitAsmStmt(AsmStmt *S) {
VisitStmt(S);
unsigned NumOutputs = Record[Idx++];
unsigned NumInputs = Record[Idx++];
S->setSimple(Record[Idx++]);
S->setMSAsm(Record[Idx++]);
- unsigned StackIdx
- = StmtStack.size() - (NumOutputs*2 + NumInputs*2 + NumClobbers + 1);
- S->setAsmString(cast_or_null<StringLiteral>(StmtStack[StackIdx++]));
+ S->setAsmString(cast_or_null<StringLiteral>(Reader.ReadStmt()));
// Outputs and inputs
llvm::SmallVector<IdentifierInfo *, 16> Names;
llvm::SmallVector<Stmt*, 16> Exprs;
for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
Names.push_back(Reader.GetIdentifierInfo(Record, Idx));
- Constraints.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++]));
- Exprs.push_back(StmtStack[StackIdx++]);
+ Constraints.push_back(cast_or_null<StringLiteral>(Reader.ReadStmt()));
+ Exprs.push_back(Reader.ReadStmt());
}
// Constraints
llvm::SmallVector<StringLiteral*, 16> Clobbers;
for (unsigned I = 0; I != NumClobbers; ++I)
- Clobbers.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++]));
+ Clobbers.push_back(cast_or_null<StringLiteral>(Reader.ReadStmt()));
S->setOutputsAndInputsAndClobbers(*Reader.getContext(),
Names.data(), Constraints.data(),
Exprs.data(), NumOutputs, NumInputs,
Clobbers.data(), NumClobbers);
-
- assert(StackIdx == StmtStack.size() && "Error deserializing AsmStmt");
- return NumOutputs*2 + NumInputs*2 + NumClobbers + 1;
}
-unsigned PCHStmtReader::VisitExpr(Expr *E) {
+void PCHStmtReader::VisitExpr(Expr *E) {
VisitStmt(E);
E->setType(Reader.GetType(Record[Idx++]));
E->setTypeDependent(Record[Idx++]);
E->setValueDependent(Record[Idx++]);
assert(Idx == NumExprFields && "Incorrect expression field count");
- return 0;
}
-unsigned PCHStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
+void PCHStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
VisitExpr(E);
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]);
- return 0;
}
-unsigned PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
+void PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
VisitExpr(E);
E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
// FIXME: read qualifier
// FIXME: read explicit template arguments
- return 0;
}
-unsigned PCHStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
+void PCHStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
VisitExpr(E);
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setValue(Reader.ReadAPInt(Record, Idx));
- return 0;
}
-unsigned PCHStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
+void PCHStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
VisitExpr(E);
E->setValue(Reader.ReadAPFloat(Record, Idx));
E->setExact(Record[Idx++]);
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
+void PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
VisitExpr(E);
- E->setSubExpr(cast<Expr>(StmtStack.back()));
- return 1;
+ E->setSubExpr(Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitStringLiteral(StringLiteral *E) {
+void PCHStmtReader::VisitStringLiteral(StringLiteral *E) {
VisitExpr(E);
unsigned Len = Record[Idx++];
assert(Record[Idx] == E->getNumConcatenated() &&
// Read source locations
for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
E->setStrTokenLoc(I, SourceLocation::getFromRawEncoding(Record[Idx++]));
-
- return 0;
}
-unsigned PCHStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
+void PCHStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
VisitExpr(E);
E->setValue(Record[Idx++]);
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setWide(Record[Idx++]);
- return 0;
}
-unsigned PCHStmtReader::VisitParenExpr(ParenExpr *E) {
+void PCHStmtReader::VisitParenExpr(ParenExpr *E) {
VisitExpr(E);
E->setLParen(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParen(SourceLocation::getFromRawEncoding(Record[Idx++]));
- E->setSubExpr(cast<Expr>(StmtStack.back()));
- return 1;
+ E->setSubExpr(Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) {
+void PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) {
VisitExpr(E);
- E->setSubExpr(cast<Expr>(StmtStack.back()));
+ E->setSubExpr(Reader.ReadExpr());
E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned PCHStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
+void PCHStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
typedef OffsetOfExpr::OffsetOfNode Node;
VisitExpr(E);
assert(E->getNumComponents() == Record[Idx]);
}
for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
- E->setIndexExpr(I, cast_or_null<Expr>(StmtStack[StmtStack.size() - N + I]));
-
- return E->getNumExpressions();
+ E->setIndexExpr(I, Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
+void PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
VisitExpr(E);
E->setSizeof(Record[Idx++]);
if (Record[Idx] == 0) {
- E->setArgument(cast<Expr>(StmtStack.back()));
+ E->setArgument(Reader.ReadExpr());
++Idx;
} else {
E->setArgument(Reader.GetTypeSourceInfo(Record, Idx));
}
E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return E->isArgumentType()? 0 : 1;
}
-unsigned PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
+void PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
VisitExpr(E);
- E->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 2]));
- E->setRHS(cast<Expr>(StmtStack[StmtStack.size() - 1]));
+ E->setLHS(Reader.ReadExpr());
+ E->setRHS(Reader.ReadExpr());
E->setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 2;
}
-unsigned PCHStmtReader::VisitCallExpr(CallExpr *E) {
+void PCHStmtReader::VisitCallExpr(CallExpr *E) {
VisitExpr(E);
E->setNumArgs(*Reader.getContext(), Record[Idx++]);
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- E->setCallee(cast<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1]));
+ E->setCallee(Reader.ReadExpr());
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
- E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I]));
- return E->getNumArgs() + 1;
+ E->setArg(I, Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitMemberExpr(MemberExpr *E) {
+void PCHStmtReader::VisitMemberExpr(MemberExpr *E) {
VisitExpr(E);
- E->setBase(cast<Expr>(StmtStack.back()));
+ E->setBase(Reader.ReadExpr());
E->setMemberDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
E->setMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setArrow(Record[Idx++]);
- return 1;
}
-unsigned PCHStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
+void PCHStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
VisitExpr(E);
- E->setBase(cast<Expr>(StmtStack.back()));
+ E->setBase(Reader.ReadExpr());
E->setIsaMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setArrow(Record[Idx++]);
- return 1;
}
-unsigned PCHStmtReader::VisitCastExpr(CastExpr *E) {
+void PCHStmtReader::VisitCastExpr(CastExpr *E) {
VisitExpr(E);
- E->setSubExpr(cast<Expr>(StmtStack.back()));
+ E->setSubExpr(Reader.ReadExpr());
E->setCastKind((CastExpr::CastKind)Record[Idx++]);
- return 1;
}
-unsigned PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) {
+void PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) {
VisitExpr(E);
- E->setLHS(cast<Expr>(StmtStack.end()[-2]));
- E->setRHS(cast<Expr>(StmtStack.end()[-1]));
+ E->setLHS(Reader.ReadExpr());
+ E->setRHS(Reader.ReadExpr());
E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 2;
}
-unsigned PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
+void PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
VisitBinaryOperator(E);
E->setComputationLHSType(Reader.GetType(Record[Idx++]));
E->setComputationResultType(Reader.GetType(Record[Idx++]));
- return 2;
}
-unsigned PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
+void PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
VisitExpr(E);
- E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3]));
- E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
- E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1]));
+ E->setCond(Reader.ReadExpr());
+ E->setLHS(Reader.ReadExpr());
+ E->setRHS(Reader.ReadExpr());
E->setQuestionLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 3;
}
-unsigned PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
+void PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
VisitCastExpr(E);
E->setLvalueCast(Record[Idx++]);
- return 1;
}
-unsigned PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
+void PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
VisitCastExpr(E);
E->setTypeInfoAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
- return 1;
}
-unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
+void PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
VisitExplicitCastExpr(E);
E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
+void PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
VisitExpr(E);
E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
- E->setInitializer(cast<Expr>(StmtStack.back()));
+ E->setInitializer(Reader.ReadExpr());
E->setFileScope(Record[Idx++]);
- return 1;
}
-unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
+void PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
VisitExpr(E);
- E->setBase(cast<Expr>(StmtStack.back()));
+ E->setBase(Reader.ReadExpr());
E->setAccessor(Reader.GetIdentifierInfo(Record, Idx));
E->setAccessorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned PCHStmtReader::VisitInitListExpr(InitListExpr *E) {
+void PCHStmtReader::VisitInitListExpr(InitListExpr *E) {
VisitExpr(E);
unsigned NumInits = Record[Idx++];
E->reserveInits(*Reader.getContext(), NumInits);
for (unsigned I = 0; I != NumInits; ++I)
- E->updateInit(*Reader.getContext(), I,
- cast<Expr>(StmtStack[StmtStack.size() - NumInits - 1 + I]));
- E->setSyntacticForm(cast_or_null<InitListExpr>(StmtStack.back()));
+ E->updateInit(*Reader.getContext(), I, Reader.ReadExpr());
+ E->setSyntacticForm(cast_or_null<InitListExpr>(Reader.ReadStmt()));
E->setLBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setInitializedFieldInUnion(
cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++])));
E->sawArrayRangeDesignator(Record[Idx++]);
- return NumInits + 1;
}
-unsigned PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
+void PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
typedef DesignatedInitExpr::Designator Designator;
VisitExpr(E);
unsigned NumSubExprs = Record[Idx++];
assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
for (unsigned I = 0; I != NumSubExprs; ++I)
- E->setSubExpr(I, cast<Expr>(StmtStack[StmtStack.size() - NumSubExprs + I]));
+ E->setSubExpr(I, Reader.ReadExpr());
E->setEqualOrColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setGNUSyntax(Record[Idx++]);
}
E->setDesignators(*Reader.getContext(),
Designators.data(), Designators.size());
-
- return NumSubExprs;
}
-unsigned PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
+void PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
VisitExpr(E);
- return 0;
}
-unsigned PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) {
+void PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) {
VisitExpr(E);
- E->setSubExpr(cast<Expr>(StmtStack.back()));
+ E->setSubExpr(Reader.ReadExpr());
E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
+void PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
VisitExpr(E);
E->setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Reader.SetLabelOf(E, Record[Idx++]);
- return 0;
}
-unsigned PCHStmtReader::VisitStmtExpr(StmtExpr *E) {
+void PCHStmtReader::VisitStmtExpr(StmtExpr *E) {
VisitExpr(E);
E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- E->setSubStmt(cast_or_null<CompoundStmt>(StmtStack.back()));
- return 1;
+ E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
}
-unsigned PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
+void PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
VisitExpr(E);
E->setArgType1(Reader.GetType(Record[Idx++]));
E->setArgType2(Reader.GetType(Record[Idx++]));
E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitChooseExpr(ChooseExpr *E) {
+void PCHStmtReader::VisitChooseExpr(ChooseExpr *E) {
VisitExpr(E);
- E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3]));
- E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
- E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1]));
+ E->setCond(Reader.ReadExpr());
+ E->setLHS(Reader.ReadExpr());
+ E->setRHS(Reader.ReadExpr());
E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 3;
}
-unsigned PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
+void PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
VisitExpr(E);
E->setTokenLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
+void PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
VisitExpr(E);
+ llvm::SmallVector<Expr *, 16> Exprs;
unsigned NumExprs = Record[Idx++];
- E->setExprs(*Reader.getContext(),
- (Expr **)&StmtStack[StmtStack.size() - NumExprs], NumExprs);
+ while (NumExprs--)
+ Exprs.push_back(Reader.ReadExpr());
+ E->setExprs(*Reader.getContext(), Exprs.data(), Exprs.size());
E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return NumExprs;
}
-unsigned PCHStmtReader::VisitBlockExpr(BlockExpr *E) {
+void PCHStmtReader::VisitBlockExpr(BlockExpr *E) {
VisitExpr(E);
E->setBlockDecl(cast_or_null<BlockDecl>(Reader.GetDecl(Record[Idx++])));
E->setHasBlockDeclRefExprs(Record[Idx++]);
- return 0;
}
-unsigned PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
+void PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
VisitExpr(E);
E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setByRef(Record[Idx++]);
E->setConstQualAdded(Record[Idx++]);
- E->setCopyConstructorExpr(cast_or_null<Expr>(StmtStack.back()));
- return 1;
+ E->setCopyConstructorExpr(Reader.ReadExpr());
}
//===----------------------------------------------------------------------===//
// Objective-C Expressions and Statements
-unsigned PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
+void PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
VisitExpr(E);
- E->setString(cast<StringLiteral>(StmtStack.back()));
+ E->setString(cast<StringLiteral>(Reader.ReadStmt()));
E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
+void PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
VisitExpr(E);
E->setEncodedTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
+void PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
VisitExpr(E);
E->setSelector(Reader.GetSelector(Record, Idx));
E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
+void PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
VisitExpr(E);
E->setProtocol(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
+void PCHStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
VisitExpr(E);
E->setDecl(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
- E->setBase(cast<Expr>(StmtStack.back()));
+ E->setBase(Reader.ReadExpr());
E->setIsArrow(Record[Idx++]);
E->setIsFreeIvar(Record[Idx++]);
- return 1;
}
-unsigned PCHStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
+void PCHStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
VisitExpr(E);
E->setProperty(cast<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
- E->setBase(cast<Expr>(StmtStack.back()));
- return 1;
+ E->setBase(Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitObjCImplicitSetterGetterRefExpr(
+void PCHStmtReader::VisitObjCImplicitSetterGetterRefExpr(
ObjCImplicitSetterGetterRefExpr *E) {
VisitExpr(E);
E->setGetterMethod(
cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
E->setInterfaceDecl(
cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
- E->setBase(cast_or_null<Expr>(StmtStack.back()));
+ E->setBase(Reader.ReadExpr());
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
+void PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
VisitExpr(E);
assert(Record[Idx] == E->getNumArgs());
++Idx;
= static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
switch (Kind) {
case ObjCMessageExpr::Instance:
- E->setInstanceReceiver(
- cast_or_null<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1]));
+ E->setInstanceReceiver(Reader.ReadExpr());
break;
case ObjCMessageExpr::Class:
E->setRightLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
- E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I]));
- return E->getNumArgs() + (Kind == ObjCMessageExpr::Instance);
+ E->setArg(I, Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) {
+void PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) {
VisitExpr(E);
E->setLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
+void PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
VisitStmt(S);
- S->setElement(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 3]));
- S->setCollection(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
- S->setBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
+ S->setElement(Reader.ReadStmt());
+ S->setCollection(Reader.ReadExpr());
+ S->setBody(Reader.ReadStmt());
S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 3;
}
-unsigned PCHStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
+void PCHStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
VisitStmt(S);
- S->setCatchBody(cast_or_null<Stmt>(StmtStack.back()));
+ S->setCatchBody(Reader.ReadStmt());
S->setCatchParamDecl(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
S->setAtCatchLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned PCHStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
+void PCHStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
VisitStmt(S);
- S->setFinallyBody(StmtStack.back());
+ S->setFinallyBody(Reader.ReadStmt());
S->setAtFinallyLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
+void PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
VisitStmt(S);
assert(Record[Idx] == S->getNumCatchStmts());
++Idx;
bool HasFinally = Record[Idx++];
- for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
- unsigned Offset = StmtStack.size() - N - HasFinally + I;
- S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(StmtStack[Offset]));
- }
+ S->setTryBody(Reader.ReadStmt());
+ for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
+ S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadStmt()));
- unsigned TryOffset
- = StmtStack.size() - S->getNumCatchStmts() - HasFinally - 1;
- S->setTryBody(cast_or_null<Stmt>(StmtStack[TryOffset]));
if (HasFinally)
- S->setFinallyStmt(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
+ S->setFinallyStmt(Reader.ReadStmt());
S->setAtTryLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1 + S->getNumCatchStmts() + HasFinally;
}
-unsigned PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
+void PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
VisitStmt(S);
- S->setSynchExpr(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 2]));
- S->setSynchBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
+ S->setSynchExpr(Reader.ReadStmt());
+ S->setSynchBody(Reader.ReadStmt());
S->setAtSynchronizedLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 2;
}
-unsigned PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
+void PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
VisitStmt(S);
- S->setThrowExpr(StmtStack.back());
+ S->setThrowExpr(Reader.ReadStmt());
S->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
//===----------------------------------------------------------------------===//
// C++ Expressions and Statements
-unsigned PCHStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
- unsigned num = VisitCallExpr(E);
+void PCHStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+ VisitCallExpr(E);
E->setOperator((OverloadedOperatorKind)Record[Idx++]);
- return num;
}
-unsigned PCHStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
+void PCHStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
VisitExpr(E);
- assert(Record[Idx] == E->getNumArgs() &&
- "Read wrong record during creation ?");
+ assert(Record[Idx] == E->getNumArgs() &&"Read wrong record during creation?");
++Idx; // NumArgs;
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
- E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I]));
+ E->setArg(I, Reader.ReadExpr());
E->setConstructor(cast<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++])));
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setElidable(Record[Idx++]);
E->setRequiresZeroInitialization(Record[Idx++]);
E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
- return E->getNumArgs();
}
-unsigned PCHStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
- unsigned num = VisitExplicitCastExpr(E);
+void PCHStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
+ VisitExplicitCastExpr(E);
E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return num;
}
-unsigned PCHStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
+void PCHStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
return VisitCXXNamedCastExpr(E);
}
-unsigned PCHStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
+void PCHStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
return VisitCXXNamedCastExpr(E);
}
-unsigned PCHStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
+void PCHStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
return VisitCXXNamedCastExpr(E);
}
-unsigned PCHStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
+void PCHStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
return VisitCXXNamedCastExpr(E);
}
-unsigned PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
- unsigned num = VisitExplicitCastExpr(E);
+void PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
+ VisitExplicitCastExpr(E);
E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return num;
}
-unsigned PCHStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
+void PCHStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
VisitExpr(E);
E->setValue(Record[Idx++]);
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
+void PCHStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
VisitExpr(E);
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
+void PCHStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
VisitExpr(E);
E->setSourceRange(Reader.ReadSourceRange(Record, Idx));
if (E->isTypeOperand()) { // typeid(int)
E->setTypeOperandSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
- return 0;
+ return;
}
// typeid(42+2)
- E->setExprOperand(cast<Expr>(StmtStack.back()));
- return 1;
+ E->setExprOperand(Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
+void PCHStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
VisitExpr(E);
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setImplicit(Record[Idx++]);
- return 0;
}
-unsigned PCHStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
+void PCHStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
VisitExpr(E);
E->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- E->setSubExpr(cast_or_null<Expr>(StmtStack.back()));
- return 1;
+ E->setSubExpr(Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
+void PCHStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
VisitExpr(E);
E->setUsedLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
bool HasStoredExpr = Record[Idx++];
- if (!HasStoredExpr) return 0;
- E->setExpr(cast<Expr>(StmtStack.back()));
- return 1;
+ if (!HasStoredExpr) return;
+ E->setExpr(Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+void PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
VisitExpr(E);
E->setTemporary(Reader.ReadCXXTemporary(Record, Idx));
- E->setSubExpr(cast<Expr>(StmtStack.back()));
- return 1;
+ E->setSubExpr(Reader.ReadExpr());
}
-unsigned PCHStmtReader::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+void PCHStmtReader::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
VisitExpr(E);
E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 0;
}
-unsigned PCHStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
+void PCHStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
VisitExpr(E);
E->setGlobalNew(Record[Idx++]);
E->setParenTypeId(Record[Idx++]);
NumCtorArgs);
// Install all the subexpressions.
- unsigned TotalSubExprs = E->raw_arg_end()-E->raw_arg_begin();
- unsigned SSIdx = StmtStack.size()-TotalSubExprs;
for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
I != e; ++I)
- *I = StmtStack[SSIdx++];
-
- return TotalSubExprs;
+ *I = Reader.ReadStmt();
}
-unsigned PCHStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+void PCHStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
VisitExpr(E);
E->setGlobalDelete(Record[Idx++]);
E->setArrayForm(Record[Idx++]);
E->setOperatorDelete(
cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
- E->setArgument(cast_or_null<Expr>(StmtStack.back()));
+ E->setArgument(Reader.ReadExpr());
E->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
- return 1;
}
-unsigned
-PCHStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
+void PCHStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
VisitExpr(E);
- E->setBase(cast_or_null<Expr>(StmtStack.back()));
+ E->setBase(Reader.ReadExpr());
E->setArrow(Record[Idx++]);
E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
E->setDestroyedType(II, Reader.ReadSourceLocation(Record, Idx));
else
E->setDestroyedType(Reader.GetTypeSourceInfo(Record, Idx));
-
- return 1;
}
-unsigned PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
+void PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
VisitExpr(E);
unsigned NumTemps = Record[Idx++];
if (NumTemps) {
for (unsigned i = 0; i != NumTemps; ++i)
E->setTemporary(i, Reader.ReadCXXTemporary(Record, Idx));
}
- E->setSubExpr(cast<Expr>(StmtStack.back()));
- return 1;
+ E->setSubExpr(Reader.ReadExpr());
}
-unsigned
+void
PCHStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
VisitExpr(E);
- unsigned NumExprs = 0;
unsigned NumTemplateArgs = Record[Idx++];
assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
"Read wrong record during creation ?");
if (E->hasExplicitTemplateArgs())
- NumExprs
- = ReadExplicitTemplateArgumentList(*E->getExplicitTemplateArgumentList(),
- NumTemplateArgs, StmtStack.end());
+ ReadExplicitTemplateArgumentList(*E->getExplicitTemplateArgumentList(),
+ NumTemplateArgs);
- E->setBase(cast_or_null<Expr>(StmtStack.back()));
+ E->setBase(Reader.ReadExpr());
E->setBaseType(Reader.GetType(Record[Idx++]));
E->setArrow(Record[Idx++]);
E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++])));
E->setMember(Reader.ReadDeclarationName(Record, Idx));
E->setMemberLoc(Reader.ReadSourceLocation(Record, Idx));
-
- return NumExprs + 1;
}
-unsigned
+void
PCHStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
VisitExpr(E);
- unsigned NumExprs = 0;
unsigned NumTemplateArgs = Record[Idx++];
assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
"Read wrong record during creation ?");
if (E->hasExplicitTemplateArgs())
- NumExprs
- = ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
- NumTemplateArgs, StmtStack.end());
+ ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
+ NumTemplateArgs);
E->setDeclName(Reader.ReadDeclarationName(Record, Idx));
E->setLocation(Reader.ReadSourceLocation(Record, Idx));
E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
- return NumExprs;
}
-unsigned
+void
PCHStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
VisitExpr(E);
assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
++Idx; // NumArgs;
for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
- E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I]));
+ E->setArg(I, Reader.ReadExpr());
E->setTypeBeginLoc(Reader.ReadSourceLocation(Record, Idx));
E->setTypeAsWritten(Reader.GetType(Record[Idx++]));
E->setLParenLoc(Reader.ReadSourceLocation(Record, Idx));
E->setRParenLoc(Reader.ReadSourceLocation(Record, Idx));
- return E->arg_size();
}
-unsigned PCHStmtReader::VisitOverloadExpr(OverloadExpr *E) {
+void PCHStmtReader::VisitOverloadExpr(OverloadExpr *E) {
VisitExpr(E);
- unsigned NumExprs = 0;
unsigned NumTemplateArgs = Record[Idx++];
assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
"Read wrong record during creation ?");
- if (E->hasExplicitTemplateArgs()) {
- llvm::SmallVectorImpl<Stmt *>::iterator EndOfExprs = StmtStack.end();
- if (isa<UnresolvedMemberExpr>(E))
- --EndOfExprs; // UnresolvedMemberExpr contains an Expr.
- NumExprs = ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
- NumTemplateArgs, EndOfExprs);
- }
+ if (E->hasExplicitTemplateArgs())
+ ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
+ NumTemplateArgs);
unsigned NumDecls = Record[Idx++];
UnresolvedSet<8> Decls;
E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
E->setNameLoc(Reader.ReadSourceLocation(Record, Idx));
- return NumExprs;
}
-unsigned PCHStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
- unsigned NumExprs = VisitOverloadExpr(E);
+void PCHStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
+ VisitOverloadExpr(E);
E->setArrow(Record[Idx++]);
E->setHasUnresolvedUsing(Record[Idx++]);
- E->setBase(cast_or_null<Expr>(StmtStack.back()));
+ E->setBase(Reader.ReadExpr());
E->setBaseType(Reader.GetType(Record[Idx++]));
E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
- return NumExprs + 1;
}
-unsigned PCHStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
- unsigned NumExprs = VisitOverloadExpr(E);
+void PCHStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
+ VisitOverloadExpr(E);
E->setRequiresADL(Record[Idx++]);
E->setOverloaded(Record[Idx++]);
E->setNamingClass(cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++])));
- return NumExprs;
}
+Stmt *PCHReader::ReadStmt() {
+ switch (ReadingKind) {
+ case Read_Decl:
+ case Read_Type:
+ // Read a statement from the current DeclCursor.
+ return ReadStmtFromStream(DeclsCursor);
+ case Read_Stmt:
+ // Subexpressions are stored from last to first, so the next Stmt we need
+ // will be at the back of the stack.
+ assert(!StmtStack.empty() && "Read too many sub statements!");
+ return StmtStack.pop_back_val();
+ }
+
+ llvm_unreachable("ReadingKind not set ?");
+ return 0;
+}
+
+Expr *PCHReader::ReadExpr() {
+ return cast_or_null<Expr>(ReadStmt());
+}
// Within the bitstream, expressions are stored in Reverse Polish
// Notation, with each of the subexpressions preceding the
-// expression they are stored in. To evaluate expressions, we
-// continue reading expressions and placing them on the stack, with
-// expressions having operands removing those operands from the
+// expression they are stored in. Subexpressions are stored from last to first.
+// To evaluate expressions, we continue reading expressions and placing them on
+// the stack, with expressions having operands removing those operands from the
// stack. Evaluation terminates when we see a STMT_STOP record, and
// the single remaining expression on the stack is our result.
-Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
+Stmt *PCHReader::ReadStmtFromStream(llvm::BitstreamCursor &Cursor) {
+
+ ReadingKindTracker ReadingKind(Read_Stmt, *this);
+
+#ifndef NDEBUG
+ unsigned PrevNumStmts = StmtStack.size();
+#endif
+
RecordData Record;
unsigned Idx;
- llvm::SmallVector<Stmt *, 16> StmtStack;
- PCHStmtReader Reader(*this, Record, Idx, StmtStack);
+ PCHStmtReader Reader(*this, Record, Idx);
Stmt::EmptyShell Empty;
while (true) {
++NumStatementsRead;
- if (S) {
- unsigned NumSubStmts = Reader.Visit(S);
- while (NumSubStmts > 0) {
- StmtStack.pop_back();
- --NumSubStmts;
- }
- }
+ if (S)
+ Reader.Visit(S);
assert(Idx == Record.size() && "Invalid deserialization of statement");
StmtStack.push_back(S);
}
- assert(StmtStack.size() == 1 && "Extra expressions on stack!");
- return StmtStack.back();
+
+#ifndef NDEBUG
+ assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!");
+ assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
+#endif
+
+ return StmtStack.pop_back_val();
}
};
}
-/// \brief Return the number of Exprs contained in the given TemplateArgument.
-static unsigned NumExprsContainedIn(const TemplateArgument &Arg) {
- switch (Arg.getKind()) {
- default: break;
- case TemplateArgument::Expression:
- return 1;
- case TemplateArgument::Pack: {
- unsigned Count = 0;
- for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end();
- I != E; ++I)
- Count += NumExprsContainedIn(*I);
- return Count;
- }
- }
-
- return 0;
-}
-
-/// \brief Return the number of Exprs contained in the given
-/// ExplicitTemplateArgumentList.
-static unsigned NumExprsContainedIn(const ExplicitTemplateArgumentList &Args) {
- unsigned Count = 0;
- for (unsigned i=0; i != Args.NumTemplateArgs; ++i) {
- const TemplateArgumentLoc &ArgLoc = Args.getTemplateArgs()[i];
- const TemplateArgument &TemplA = ArgLoc.getArgument();
- Count += NumExprsContainedIn(TemplA);
- if (TemplA.getKind() == TemplateArgument::Expression &&
- TemplA.getAsExpr() != ArgLoc.getLocInfo().getAsExpr())
- ++Count; // 1 in TemplateArgumentLocInfo.
- }
-
- return Count;
-}
-
void PCHStmtWriter::
AddExplicitTemplateArgumentList(const ExplicitTemplateArgumentList &Args) {
- Record.push_back(NumExprsContainedIn(Args));
Writer.AddSourceLocation(Args.LAngleLoc, Record);
Writer.AddSourceLocation(Args.RAngleLoc, Record);
for (unsigned i=0; i != Args.NumTemplateArgs; ++i)
Record.push_back(S->size());
for (CompoundStmt::body_iterator CS = S->body_begin(), CSEnd = S->body_end();
CS != CSEnd; ++CS)
- Writer.WriteSubStmt(*CS);
+ Writer.AddStmt(*CS);
Writer.AddSourceLocation(S->getLBracLoc(), Record);
Writer.AddSourceLocation(S->getRBracLoc(), Record);
Code = pch::STMT_COMPOUND;
void PCHStmtWriter::VisitSwitchCase(SwitchCase *S) {
VisitStmt(S);
- Record.push_back(Writer.RecordSwitchCaseID(S));
+ Record.push_back(Writer.getSwitchCaseID(S));
}
void PCHStmtWriter::VisitCaseStmt(CaseStmt *S) {
VisitSwitchCase(S);
- Writer.WriteSubStmt(S->getLHS());
- Writer.WriteSubStmt(S->getRHS());
- Writer.WriteSubStmt(S->getSubStmt());
+ Writer.AddStmt(S->getLHS());
+ Writer.AddStmt(S->getRHS());
+ Writer.AddStmt(S->getSubStmt());
Writer.AddSourceLocation(S->getCaseLoc(), Record);
Writer.AddSourceLocation(S->getEllipsisLoc(), Record);
Writer.AddSourceLocation(S->getColonLoc(), Record);
void PCHStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
VisitSwitchCase(S);
- Writer.WriteSubStmt(S->getSubStmt());
+ Writer.AddStmt(S->getSubStmt());
Writer.AddSourceLocation(S->getDefaultLoc(), Record);
Writer.AddSourceLocation(S->getColonLoc(), Record);
Code = pch::STMT_DEFAULT;
void PCHStmtWriter::VisitLabelStmt(LabelStmt *S) {
VisitStmt(S);
Writer.AddIdentifierRef(S->getID(), Record);
- Writer.WriteSubStmt(S->getSubStmt());
+ Writer.AddStmt(S->getSubStmt());
Writer.AddSourceLocation(S->getIdentLoc(), Record);
Record.push_back(Writer.GetLabelID(S));
Code = pch::STMT_LABEL;
void PCHStmtWriter::VisitIfStmt(IfStmt *S) {
VisitStmt(S);
Writer.AddDeclRef(S->getConditionVariable(), Record);
- Writer.WriteSubStmt(S->getCond());
- Writer.WriteSubStmt(S->getThen());
- Writer.WriteSubStmt(S->getElse());
+ Writer.AddStmt(S->getCond());
+ Writer.AddStmt(S->getThen());
+ Writer.AddStmt(S->getElse());
Writer.AddSourceLocation(S->getIfLoc(), Record);
Writer.AddSourceLocation(S->getElseLoc(), Record);
Code = pch::STMT_IF;
void PCHStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
VisitStmt(S);
Writer.AddDeclRef(S->getConditionVariable(), Record);
- Writer.WriteSubStmt(S->getCond());
- Writer.WriteSubStmt(S->getBody());
+ Writer.AddStmt(S->getCond());
+ Writer.AddStmt(S->getBody());
Writer.AddSourceLocation(S->getSwitchLoc(), Record);
for (SwitchCase *SC = S->getSwitchCaseList(); SC;
SC = SC->getNextSwitchCase())
- Record.push_back(Writer.getSwitchCaseID(SC));
+ Record.push_back(Writer.RecordSwitchCaseID(SC));
Code = pch::STMT_SWITCH;
}
void PCHStmtWriter::VisitWhileStmt(WhileStmt *S) {
VisitStmt(S);
Writer.AddDeclRef(S->getConditionVariable(), Record);
- Writer.WriteSubStmt(S->getCond());
- Writer.WriteSubStmt(S->getBody());
+ Writer.AddStmt(S->getCond());
+ Writer.AddStmt(S->getBody());
Writer.AddSourceLocation(S->getWhileLoc(), Record);
Code = pch::STMT_WHILE;
}
void PCHStmtWriter::VisitDoStmt(DoStmt *S) {
VisitStmt(S);
- Writer.WriteSubStmt(S->getCond());
- Writer.WriteSubStmt(S->getBody());
+ Writer.AddStmt(S->getCond());
+ Writer.AddStmt(S->getBody());
Writer.AddSourceLocation(S->getDoLoc(), Record);
Writer.AddSourceLocation(S->getWhileLoc(), Record);
Writer.AddSourceLocation(S->getRParenLoc(), Record);
void PCHStmtWriter::VisitForStmt(ForStmt *S) {
VisitStmt(S);
- Writer.WriteSubStmt(S->getInit());
- Writer.WriteSubStmt(S->getCond());
+ Writer.AddStmt(S->getInit());
+ Writer.AddStmt(S->getCond());
Writer.AddDeclRef(S->getConditionVariable(), Record);
- Writer.WriteSubStmt(S->getInc());
- Writer.WriteSubStmt(S->getBody());
+ Writer.AddStmt(S->getInc());
+ Writer.AddStmt(S->getBody());
Writer.AddSourceLocation(S->getForLoc(), Record);
Writer.AddSourceLocation(S->getLParenLoc(), Record);
Writer.AddSourceLocation(S->getRParenLoc(), Record);
VisitStmt(S);
Writer.AddSourceLocation(S->getGotoLoc(), Record);
Writer.AddSourceLocation(S->getStarLoc(), Record);
- Writer.WriteSubStmt(S->getTarget());
+ Writer.AddStmt(S->getTarget());
Code = pch::STMT_INDIRECT_GOTO;
}
void PCHStmtWriter::VisitReturnStmt(ReturnStmt *S) {
VisitStmt(S);
- Writer.WriteSubStmt(S->getRetValue());
+ Writer.AddStmt(S->getRetValue());
Writer.AddSourceLocation(S->getReturnLoc(), Record);
Writer.AddDeclRef(S->getNRVOCandidate(), Record);
Code = pch::STMT_RETURN;
Record.push_back(S->isVolatile());
Record.push_back(S->isSimple());
Record.push_back(S->isMSAsm());
- Writer.WriteSubStmt(S->getAsmString());
+ Writer.AddStmt(S->getAsmString());
// Outputs
for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Writer.AddIdentifierRef(S->getOutputIdentifier(I), Record);
- Writer.WriteSubStmt(S->getOutputConstraintLiteral(I));
- Writer.WriteSubStmt(S->getOutputExpr(I));
+ Writer.AddStmt(S->getOutputConstraintLiteral(I));
+ Writer.AddStmt(S->getOutputExpr(I));
}
// Inputs
for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Writer.AddIdentifierRef(S->getInputIdentifier(I), Record);
- Writer.WriteSubStmt(S->getInputConstraintLiteral(I));
- Writer.WriteSubStmt(S->getInputExpr(I));
+ Writer.AddStmt(S->getInputConstraintLiteral(I));
+ Writer.AddStmt(S->getInputExpr(I));
}
// Clobbers
for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
- Writer.WriteSubStmt(S->getClobber(I));
+ Writer.AddStmt(S->getClobber(I));
Code = pch::STMT_ASM;
}
void PCHStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getSubExpr());
+ Writer.AddStmt(E->getSubExpr());
Code = pch::EXPR_IMAGINARY_LITERAL;
}
VisitExpr(E);
Writer.AddSourceLocation(E->getLParen(), Record);
Writer.AddSourceLocation(E->getRParen(), Record);
- Writer.WriteSubStmt(E->getSubExpr());
+ Writer.AddStmt(E->getSubExpr());
Code = pch::EXPR_PAREN;
}
void PCHStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getSubExpr());
+ Writer.AddStmt(E->getSubExpr());
Record.push_back(E->getOpcode()); // FIXME: stable encoding
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
Code = pch::EXPR_UNARY_OPERATOR;
}
}
for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
- Writer.WriteSubStmt(E->getIndexExpr(I));
+ Writer.AddStmt(E->getIndexExpr(I));
Code = pch::EXPR_OFFSETOF;
}
Writer.AddTypeSourceInfo(E->getArgumentTypeInfo(), Record);
else {
Record.push_back(0);
- Writer.WriteSubStmt(E->getArgumentExpr());
+ Writer.AddStmt(E->getArgumentExpr());
}
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
Writer.AddSourceLocation(E->getRParenLoc(), Record);
void PCHStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getLHS());
- Writer.WriteSubStmt(E->getRHS());
+ Writer.AddStmt(E->getLHS());
+ Writer.AddStmt(E->getRHS());
Writer.AddSourceLocation(E->getRBracketLoc(), Record);
Code = pch::EXPR_ARRAY_SUBSCRIPT;
}
VisitExpr(E);
Record.push_back(E->getNumArgs());
Writer.AddSourceLocation(E->getRParenLoc(), Record);
- Writer.WriteSubStmt(E->getCallee());
+ Writer.AddStmt(E->getCallee());
for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
Arg != ArgEnd; ++Arg)
- Writer.WriteSubStmt(*Arg);
+ Writer.AddStmt(*Arg);
Code = pch::EXPR_CALL;
}
void PCHStmtWriter::VisitMemberExpr(MemberExpr *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getBase());
+ Writer.AddStmt(E->getBase());
Writer.AddDeclRef(E->getMemberDecl(), Record);
Writer.AddSourceLocation(E->getMemberLoc(), Record);
Record.push_back(E->isArrow());
void PCHStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getBase());
+ Writer.AddStmt(E->getBase());
Writer.AddSourceLocation(E->getIsaMemberLoc(), Record);
Record.push_back(E->isArrow());
Code = pch::EXPR_OBJC_ISA;
void PCHStmtWriter::VisitCastExpr(CastExpr *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getSubExpr());
+ Writer.AddStmt(E->getSubExpr());
Record.push_back(E->getCastKind()); // FIXME: stable encoding
}
void PCHStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getLHS());
- Writer.WriteSubStmt(E->getRHS());
+ Writer.AddStmt(E->getLHS());
+ Writer.AddStmt(E->getRHS());
Record.push_back(E->getOpcode()); // FIXME: stable encoding
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
Code = pch::EXPR_BINARY_OPERATOR;
void PCHStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getCond());
- Writer.WriteSubStmt(E->getLHS());
- Writer.WriteSubStmt(E->getRHS());
+ Writer.AddStmt(E->getCond());
+ Writer.AddStmt(E->getLHS());
+ Writer.AddStmt(E->getRHS());
Writer.AddSourceLocation(E->getQuestionLoc(), Record);
Writer.AddSourceLocation(E->getColonLoc(), Record);
Code = pch::EXPR_CONDITIONAL_OPERATOR;
VisitExpr(E);
Writer.AddSourceLocation(E->getLParenLoc(), Record);
Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
- Writer.WriteSubStmt(E->getInitializer());
+ Writer.AddStmt(E->getInitializer());
Record.push_back(E->isFileScope());
Code = pch::EXPR_COMPOUND_LITERAL;
}
void PCHStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getBase());
+ Writer.AddStmt(E->getBase());
Writer.AddIdentifierRef(&E->getAccessor(), Record);
Writer.AddSourceLocation(E->getAccessorLoc(), Record);
Code = pch::EXPR_EXT_VECTOR_ELEMENT;
VisitExpr(E);
Record.push_back(E->getNumInits());
for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
- Writer.WriteSubStmt(E->getInit(I));
- Writer.WriteSubStmt(E->getSyntacticForm());
+ Writer.AddStmt(E->getInit(I));
+ Writer.AddStmt(E->getSyntacticForm());
Writer.AddSourceLocation(E->getLBraceLoc(), Record);
Writer.AddSourceLocation(E->getRBraceLoc(), Record);
Writer.AddDeclRef(E->getInitializedFieldInUnion(), Record);
VisitExpr(E);
Record.push_back(E->getNumSubExprs());
for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
- Writer.WriteSubStmt(E->getSubExpr(I));
+ Writer.AddStmt(E->getSubExpr(I));
Writer.AddSourceLocation(E->getEqualOrColonLoc(), Record);
Record.push_back(E->usesGNUSyntax());
for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
void PCHStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getSubExpr());
+ Writer.AddStmt(E->getSubExpr());
Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
Writer.AddSourceLocation(E->getRParenLoc(), Record);
Code = pch::EXPR_VA_ARG;
void PCHStmtWriter::VisitStmtExpr(StmtExpr *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getSubStmt());
+ Writer.AddStmt(E->getSubStmt());
Writer.AddSourceLocation(E->getLParenLoc(), Record);
Writer.AddSourceLocation(E->getRParenLoc(), Record);
Code = pch::EXPR_STMT;
void PCHStmtWriter::VisitChooseExpr(ChooseExpr *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getCond());
- Writer.WriteSubStmt(E->getLHS());
- Writer.WriteSubStmt(E->getRHS());
+ Writer.AddStmt(E->getCond());
+ Writer.AddStmt(E->getLHS());
+ Writer.AddStmt(E->getRHS());
Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
Writer.AddSourceLocation(E->getRParenLoc(), Record);
Code = pch::EXPR_CHOOSE;
VisitExpr(E);
Record.push_back(E->getNumSubExprs());
for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
- Writer.WriteSubStmt(E->getExpr(I));
+ Writer.AddStmt(E->getExpr(I));
Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
Writer.AddSourceLocation(E->getRParenLoc(), Record);
Code = pch::EXPR_SHUFFLE_VECTOR;
Writer.AddSourceLocation(E->getLocation(), Record);
Record.push_back(E->isByRef());
Record.push_back(E->isConstQualAdded());
- Writer.WriteSubStmt(E->getCopyConstructorExpr());
+ Writer.AddStmt(E->getCopyConstructorExpr());
Code = pch::EXPR_BLOCK_DECL_REF;
}
void PCHStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
VisitExpr(E);
- Writer.WriteSubStmt(E->getString());
+ Writer.AddStmt(E->getString());
Writer.AddSourceLocation(E->getAtLoc(), Record);
Code = pch::EXPR_OBJC_STRING_LITERAL;
}
VisitExpr(E);
Writer.AddDeclRef(E->getDecl(), Record);
Writer.AddSourceLocation(E->getLocation(), Record);
- Writer.WriteSubStmt(E->getBase());
+ Writer.AddStmt(E->getBase());
Record.push_back(E->isArrow());
Record.push_back(E->isFreeIvar());
Code = pch::EXPR_OBJC_IVAR_REF_EXPR;
VisitExpr(E);
Writer.AddDeclRef(E->getProperty(), Record);
Writer.AddSourceLocation(E->getLocation(), Record);
- Writer.WriteSubStmt(E->getBase());
+ Writer.AddStmt(E->getBase());
Code = pch::EXPR_OBJC_PROPERTY_REF_EXPR;
}
// NOTE: InterfaceDecl and Base are mutually exclusive.
Writer.AddDeclRef(E->getInterfaceDecl(), Record);
- Writer.WriteSubStmt(E->getBase());
+ Writer.AddStmt(E->getBase());
Writer.AddSourceLocation(E->getLocation(), Record);
Writer.AddSourceLocation(E->getClassLoc(), Record);
Code = pch::EXPR_OBJC_KVC_REF_EXPR;
Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
switch (E->getReceiverKind()) {
case ObjCMessageExpr::Instance:
- Writer.WriteSubStmt(E->getInstanceReceiver());
+ Writer.AddStmt(E->getInstanceReceiver());
break;
case ObjCMessageExpr::Class:
for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
Arg != ArgEnd; ++Arg)
- Writer.WriteSubStmt(*Arg);
+ Writer.AddStmt(*Arg);
Code = pch::EXPR_OBJC_MESSAGE_EXPR;
}
void PCHStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
VisitStmt(S);
- Writer.WriteSubStmt(S->getElement());
- Writer.WriteSubStmt(S->getCollection());
- Writer.WriteSubStmt(S->getBody());
+ Writer.AddStmt(S->getElement());
+ Writer.AddStmt(S->getCollection());
+ Writer.AddStmt(S->getBody());
Writer.AddSourceLocation(S->getForLoc(), Record);
Writer.AddSourceLocation(S->getRParenLoc(), Record);
Code = pch::STMT_OBJC_FOR_COLLECTION;
}
void PCHStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
- Writer.WriteSubStmt(S->getCatchBody());
+ Writer.AddStmt(S->getCatchBody());
Writer.AddDeclRef(S->getCatchParamDecl(), Record);
Writer.AddSourceLocation(S->getAtCatchLoc(), Record);
Writer.AddSourceLocation(S->getRParenLoc(), Record);
}
void PCHStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
- Writer.WriteSubStmt(S->getFinallyBody());
+ Writer.AddStmt(S->getFinallyBody());
Writer.AddSourceLocation(S->getAtFinallyLoc(), Record);
Code = pch::STMT_OBJC_FINALLY;
}
void PCHStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Record.push_back(S->getNumCatchStmts());
Record.push_back(S->getFinallyStmt() != 0);
- Writer.WriteSubStmt(S->getTryBody());
+ Writer.AddStmt(S->getTryBody());
for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
- Writer.WriteSubStmt(S->getCatchStmt(I));
+ Writer.AddStmt(S->getCatchStmt(I));
if (S->getFinallyStmt())
- Writer.WriteSubStmt(S->getFinallyStmt());
+ Writer.AddStmt(S->getFinallyStmt());
Writer.AddSourceLocation(S->getAtTryLoc(), Record);
Code = pch::STMT_OBJC_AT_TRY;
}
void PCHStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
- Writer.WriteSubStmt(S->getSynchExpr());
- Writer.WriteSubStmt(S->getSynchBody());
+ Writer.AddStmt(S->getSynchExpr());
+ Writer.AddStmt(S->getSynchBody());
Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record);
Code = pch::STMT_OBJC_AT_SYNCHRONIZED;
}
void PCHStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
- Writer.WriteSubStmt(S->getThrowExpr());
+ Writer.AddStmt(S->getThrowExpr());
Writer.AddSourceLocation(S->getThrowLoc(), Record);
Code = pch::STMT_OBJC_AT_THROW;
}
VisitExpr(E);
Record.push_back(E->getNumArgs());
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
- Writer.WriteSubStmt(E->getArg(I));
+ Writer.AddStmt(E->getArg(I));
Writer.AddDeclRef(E->getConstructor(), Record);
Writer.AddSourceLocation(E->getLocation(), Record);
Record.push_back(E->isElidable());
Writer.AddTypeSourceInfo(E->getTypeOperandSourceInfo(), Record);
Code = pch::EXPR_CXX_TYPEID_TYPE;
} else {
- Writer.WriteSubStmt(E->getExprOperand());
+ Writer.AddStmt(E->getExprOperand());
Code = pch::EXPR_CXX_TYPEID_EXPR;
}
}
void PCHStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
VisitExpr(E);
Writer.AddSourceLocation(E->getThrowLoc(), Record);
- Writer.WriteSubStmt(E->getSubExpr());
+ Writer.AddStmt(E->getSubExpr());
Code = pch::EXPR_CXX_THROW;
}
Writer.AddSourceLocation(E->getUsedLocation(), Record);
if (E->isExprStored()) {
Record.push_back(1);
- Writer.WriteSubStmt(E->getExpr());
+ Writer.AddStmt(E->getExpr());
} else {
Record.push_back(0);
}
void PCHStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
VisitExpr(E);
Writer.AddCXXTemporary(E->getTemporary(), Record);
- Writer.WriteSubStmt(E->getSubExpr());
+ Writer.AddStmt(E->getSubExpr());
Code = pch::EXPR_CXX_BIND_TEMPORARY;
}
Writer.AddSourceLocation(E->getEndLoc(), Record);
for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
I != e; ++I)
- Writer.WriteSubStmt(*I);
+ Writer.AddStmt(*I);
Code = pch::EXPR_CXX_NEW;
}
Record.push_back(E->isGlobalDelete());
Record.push_back(E->isArrayForm());
Writer.AddDeclRef(E->getOperatorDelete(), Record);
- Writer.WriteSubStmt(E->getArgument());
+ Writer.AddStmt(E->getArgument());
Writer.AddSourceLocation(E->getSourceRange().getBegin(), Record);
Code = pch::EXPR_CXX_DELETE;
for (unsigned i = 0, e = E->getNumTemporaries(); i != e; ++i)
Writer.AddCXXTemporary(E->getTemporary(i), Record);
- Writer.WriteSubStmt(E->getSubExpr());
+ Writer.AddStmt(E->getSubExpr());
Code = pch::EXPR_CXX_EXPR_WITH_TEMPORARIES;
}
}
if (!E->isImplicitAccess())
- Writer.WriteSubStmt(E->getBase());
+ Writer.AddStmt(E->getBase());
else
- Writer.WriteSubStmt(0);
+ Writer.AddStmt(0);
Writer.AddTypeRef(E->getBaseType(), Record);
Record.push_back(E->isArrow());
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
Record.push_back(E->arg_size());
for (CXXUnresolvedConstructExpr::arg_iterator
ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
- Writer.WriteSubStmt(*ArgI);
+ Writer.AddStmt(*ArgI);
Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
Writer.AddTypeRef(E->getTypeAsWritten(), Record);
Writer.AddSourceLocation(E->getLParenLoc(), Record);
VisitOverloadExpr(E);
Record.push_back(E->isArrow());
Record.push_back(E->hasUnresolvedUsing());
- Writer.WriteSubStmt(!E->isImplicitAccess() ? E->getBase() : 0);
+ Writer.AddStmt(!E->isImplicitAccess() ? E->getBase() : 0);
Writer.AddTypeRef(E->getBaseType(), Record);
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
Code = pch::EXPR_CXX_UNRESOLVED_MEMBER;
RecordData Record;
PCHStmtWriter Writer(*this, Record);
++NumStatements;
-
+
if (!S) {
Stream.EmitRecord(pch::STMT_NULL_PTR, Record);
return;
}
+ // Redirect PCHWriter::AddStmt to collect sub stmts.
+ llvm::SmallVector<Stmt *, 16> SubStmts;
+ CollectedStmts = &SubStmts;
+
Writer.Code = pch::STMT_NULL_PTR;
Writer.Visit(S);
assert(0 && "Unhandled sub statement writing PCH file");
}
#endif
+
+ // Revert PCHWriter::AddStmt.
+ CollectedStmts = &StmtsToEmit;
+
+ // Write the sub stmts in reverse order, last to first. When reading them back
+ // we will read them in correct order by "pop"ing them from the Stmts stack.
+ // This simplifies reading and allows to store a variable number of sub stmts
+ // without knowing it in advance.
+ while (!SubStmts.empty())
+ WriteSubStmt(SubStmts.pop_back_val());
+
Stream.EmitRecord(Writer.Code, Record);
}
/// queue via AddStmt().
void PCHWriter::FlushStmts() {
RecordData Record;
- PCHStmtWriter Writer(*this, Record);
-
- EmittingStmts = true;
for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
- ++NumStatements;
- Stmt *S = StmtsToEmit[I];
-
- if (!S) {
- Stream.EmitRecord(pch::STMT_NULL_PTR, Record);
- Stream.EmitRecord(pch::STMT_STOP, Record);
- continue;
- }
-
- Writer.Code = pch::STMT_NULL_PTR;
- Writer.Visit(S);
-#ifndef NDEBUG
- if (Writer.Code == pch::STMT_NULL_PTR) {
- S->dump();
- assert(0 && "Unhandled expression writing PCH file");
- }
-#endif
- Stream.EmitRecord(Writer.Code, Record);
-
+ WriteSubStmt(StmtsToEmit[I]);
+
assert(N == StmtsToEmit.size() &&
"Substatement writen via AddStmt rather than WriteSubStmt!");
// Note that we are at the end of a full expression. Any
// expression records that follow this one are part of a different
// expression.
- Record.clear();
Stream.EmitRecord(pch::STMT_STOP, Record);
}
- EmittingStmts = false;
-
StmtsToEmit.clear();
}