blob: 9a29234d5a8543e325996483e0fe67799cf74067 [file] [log] [blame]
Chris Lattner4c6f9522009-04-27 05:14:47 +00001//===--- PCHReaderStmt.cpp - Stmt/Expr Deserialization ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Statement/expression deserialization. This implements the
11// PCHReader::ReadStmt method.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Frontend/PCHReader.h"
Douglas Gregor39da0b82009-09-09 23:08:42 +000016#include "clang/AST/DeclCXX.h"
Chris Lattner4c6f9522009-04-27 05:14:47 +000017#include "clang/AST/StmtVisitor.h"
18using namespace clang;
19
Chris Lattner4c6f9522009-04-27 05:14:47 +000020namespace {
Argyrios Kyrtzidis17cfded2010-06-28 09:31:42 +000021
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +000022 class PCHStmtReader : public StmtVisitor<PCHStmtReader> {
Chris Lattner4c6f9522009-04-27 05:14:47 +000023 PCHReader &Reader;
24 const PCHReader::RecordData &Record;
25 unsigned &Idx;
Chris Lattner4c6f9522009-04-27 05:14:47 +000026
27 public:
28 PCHStmtReader(PCHReader &Reader, const PCHReader::RecordData &Record,
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +000029 unsigned &Idx)
30 : Reader(Reader), Record(Record), Idx(Idx) { }
Chris Lattner4c6f9522009-04-27 05:14:47 +000031
32 /// \brief The number of record fields required for the Stmt class
33 /// itself.
34 static const unsigned NumStmtFields = 0;
35
36 /// \brief The number of record fields required for the Expr class
37 /// itself.
38 static const unsigned NumExprFields = NumStmtFields + 3;
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +000039
40 /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +000041 void ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
42 unsigned NumTemplateArgs);
Chris Lattner4c6f9522009-04-27 05:14:47 +000043
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +000044 void VisitStmt(Stmt *S);
45 void VisitNullStmt(NullStmt *S);
46 void VisitCompoundStmt(CompoundStmt *S);
47 void VisitSwitchCase(SwitchCase *S);
48 void VisitCaseStmt(CaseStmt *S);
49 void VisitDefaultStmt(DefaultStmt *S);
50 void VisitLabelStmt(LabelStmt *S);
51 void VisitIfStmt(IfStmt *S);
52 void VisitSwitchStmt(SwitchStmt *S);
53 void VisitWhileStmt(WhileStmt *S);
54 void VisitDoStmt(DoStmt *S);
55 void VisitForStmt(ForStmt *S);
56 void VisitGotoStmt(GotoStmt *S);
57 void VisitIndirectGotoStmt(IndirectGotoStmt *S);
58 void VisitContinueStmt(ContinueStmt *S);
59 void VisitBreakStmt(BreakStmt *S);
60 void VisitReturnStmt(ReturnStmt *S);
61 void VisitDeclStmt(DeclStmt *S);
62 void VisitAsmStmt(AsmStmt *S);
63 void VisitExpr(Expr *E);
64 void VisitPredefinedExpr(PredefinedExpr *E);
65 void VisitDeclRefExpr(DeclRefExpr *E);
66 void VisitIntegerLiteral(IntegerLiteral *E);
67 void VisitFloatingLiteral(FloatingLiteral *E);
68 void VisitImaginaryLiteral(ImaginaryLiteral *E);
69 void VisitStringLiteral(StringLiteral *E);
70 void VisitCharacterLiteral(CharacterLiteral *E);
71 void VisitParenExpr(ParenExpr *E);
72 void VisitUnaryOperator(UnaryOperator *E);
73 void VisitOffsetOfExpr(OffsetOfExpr *E);
74 void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
75 void VisitArraySubscriptExpr(ArraySubscriptExpr *E);
76 void VisitCallExpr(CallExpr *E);
77 void VisitMemberExpr(MemberExpr *E);
78 void VisitCastExpr(CastExpr *E);
79 void VisitBinaryOperator(BinaryOperator *E);
80 void VisitCompoundAssignOperator(CompoundAssignOperator *E);
81 void VisitConditionalOperator(ConditionalOperator *E);
82 void VisitImplicitCastExpr(ImplicitCastExpr *E);
83 void VisitExplicitCastExpr(ExplicitCastExpr *E);
84 void VisitCStyleCastExpr(CStyleCastExpr *E);
85 void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
86 void VisitExtVectorElementExpr(ExtVectorElementExpr *E);
87 void VisitInitListExpr(InitListExpr *E);
88 void VisitDesignatedInitExpr(DesignatedInitExpr *E);
89 void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
90 void VisitVAArgExpr(VAArgExpr *E);
91 void VisitAddrLabelExpr(AddrLabelExpr *E);
92 void VisitStmtExpr(StmtExpr *E);
93 void VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
94 void VisitChooseExpr(ChooseExpr *E);
95 void VisitGNUNullExpr(GNUNullExpr *E);
96 void VisitShuffleVectorExpr(ShuffleVectorExpr *E);
97 void VisitBlockExpr(BlockExpr *E);
98 void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
99 void VisitObjCStringLiteral(ObjCStringLiteral *E);
100 void VisitObjCEncodeExpr(ObjCEncodeExpr *E);
101 void VisitObjCSelectorExpr(ObjCSelectorExpr *E);
102 void VisitObjCProtocolExpr(ObjCProtocolExpr *E);
103 void VisitObjCIvarRefExpr(ObjCIvarRefExpr *E);
104 void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E);
105 void VisitObjCImplicitSetterGetterRefExpr(
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000106 ObjCImplicitSetterGetterRefExpr *E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000107 void VisitObjCMessageExpr(ObjCMessageExpr *E);
108 void VisitObjCSuperExpr(ObjCSuperExpr *E);
109 void VisitObjCIsaExpr(ObjCIsaExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000110
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000111 void VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
112 void VisitObjCAtCatchStmt(ObjCAtCatchStmt *);
113 void VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *);
114 void VisitObjCAtTryStmt(ObjCAtTryStmt *);
115 void VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
116 void VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000117
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000118 void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
119 void VisitCXXConstructExpr(CXXConstructExpr *E);
120 void VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
121 void VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
122 void VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
123 void VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
124 void VisitCXXConstCastExpr(CXXConstCastExpr *E);
125 void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
126 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
127 void VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
128 void VisitCXXTypeidExpr(CXXTypeidExpr *E);
129 void VisitCXXThisExpr(CXXThisExpr *E);
130 void VisitCXXThrowExpr(CXXThrowExpr *E);
131 void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
132 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
Chris Lattnerd2598362010-05-10 00:25:06 +0000133
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000134 void VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
135 void VisitCXXNewExpr(CXXNewExpr *E);
136 void VisitCXXDeleteExpr(CXXDeleteExpr *E);
137 void VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
Chris Lattner59218632010-05-10 01:22:27 +0000138
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000139 void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000140
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000141 void VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
142 void VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
143 void VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000144
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000145 void VisitOverloadExpr(OverloadExpr *E);
146 void VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
147 void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000148 };
149}
150
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000151void PCHStmtReader::
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +0000152ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000153 unsigned NumTemplateArgs) {
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +0000154 TemplateArgumentListInfo ArgInfo;
155 ArgInfo.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
156 ArgInfo.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +0000157 for (unsigned i = 0; i != NumTemplateArgs; ++i)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000158 ArgInfo.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +0000159 ArgList.initializeFrom(ArgInfo);
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +0000160}
161
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000162void PCHStmtReader::VisitStmt(Stmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000163 assert(Idx == NumStmtFields && "Incorrect statement field count");
Chris Lattner4c6f9522009-04-27 05:14:47 +0000164}
165
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000166void PCHStmtReader::VisitNullStmt(NullStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000167 VisitStmt(S);
168 S->setSemiLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000169}
170
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000171void PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000172 VisitStmt(S);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000173 llvm::SmallVector<Stmt *, 16> Stmts;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000174 unsigned NumStmts = Record[Idx++];
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000175 while (NumStmts--)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000176 Stmts.push_back(Reader.ReadSubStmt());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000177 S->setStmts(*Reader.getContext(), Stmts.data(), Stmts.size());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000178 S->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
179 S->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000180}
181
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000182void PCHStmtReader::VisitSwitchCase(SwitchCase *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000183 VisitStmt(S);
184 Reader.RecordSwitchCaseID(S, Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000185}
186
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000187void PCHStmtReader::VisitCaseStmt(CaseStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000188 VisitSwitchCase(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000189 S->setLHS(Reader.ReadSubExpr());
190 S->setRHS(Reader.ReadSubExpr());
191 S->setSubStmt(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000192 S->setCaseLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregordbb26db2009-05-15 23:57:33 +0000193 S->setEllipsisLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
194 S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000195}
196
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000197void PCHStmtReader::VisitDefaultStmt(DefaultStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000198 VisitSwitchCase(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000199 S->setSubStmt(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000200 S->setDefaultLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregordbb26db2009-05-15 23:57:33 +0000201 S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000202}
203
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000204void PCHStmtReader::VisitLabelStmt(LabelStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000205 VisitStmt(S);
206 S->setID(Reader.GetIdentifierInfo(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000207 S->setSubStmt(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000208 S->setIdentLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
209 Reader.RecordLabelStmt(S, Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000210}
211
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000212void PCHStmtReader::VisitIfStmt(IfStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000213 VisitStmt(S);
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000214 S->setConditionVariable(*Reader.getContext(),
215 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000216 S->setCond(Reader.ReadSubExpr());
217 S->setThen(Reader.ReadSubStmt());
218 S->setElse(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000219 S->setIfLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregord06f6ca2009-05-15 18:53:42 +0000220 S->setElseLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000221}
222
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000223void PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000224 VisitStmt(S);
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000225 S->setConditionVariable(*Reader.getContext(),
226 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000227 S->setCond(Reader.ReadSubExpr());
228 S->setBody(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000229 S->setSwitchLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
230 SwitchCase *PrevSC = 0;
231 for (unsigned N = Record.size(); Idx != N; ++Idx) {
232 SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]);
233 if (PrevSC)
234 PrevSC->setNextSwitchCase(SC);
235 else
236 S->setSwitchCaseList(SC);
Mike Stump1eb44332009-09-09 15:08:12 +0000237
Douglas Gregor43d9d922009-08-08 01:41:12 +0000238 // Retain this SwitchCase, since SwitchStmt::addSwitchCase() would
239 // normally retain it (but we aren't calling addSwitchCase).
240 SC->Retain();
Chris Lattner4c6f9522009-04-27 05:14:47 +0000241 PrevSC = SC;
242 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000243}
244
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000245void PCHStmtReader::VisitWhileStmt(WhileStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000246 VisitStmt(S);
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000247 S->setConditionVariable(*Reader.getContext(),
248 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000249 S->setCond(Reader.ReadSubExpr());
250 S->setBody(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000251 S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000252}
253
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000254void PCHStmtReader::VisitDoStmt(DoStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000255 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000256 S->setCond(Reader.ReadSubExpr());
257 S->setBody(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000258 S->setDoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor9f3ca2a2009-05-15 21:56:04 +0000259 S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner98913592009-06-12 23:04:47 +0000260 S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000261}
262
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000263void PCHStmtReader::VisitForStmt(ForStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000264 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000265 S->setInit(Reader.ReadSubStmt());
266 S->setCond(Reader.ReadSubExpr());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000267 S->setConditionVariable(*Reader.getContext(),
268 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000269 S->setInc(Reader.ReadSubExpr());
270 S->setBody(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000271 S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor5831c6a2009-05-15 22:12:32 +0000272 S->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
273 S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000274}
275
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000276void PCHStmtReader::VisitGotoStmt(GotoStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000277 VisitStmt(S);
278 Reader.SetLabelOf(S, Record[Idx++]);
279 S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
280 S->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000281}
282
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000283void PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000284 VisitStmt(S);
285 S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor5f1b9e62009-05-16 00:20:29 +0000286 S->setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000287 S->setTarget(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000288}
289
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000290void PCHStmtReader::VisitContinueStmt(ContinueStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000291 VisitStmt(S);
292 S->setContinueLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000293}
294
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000295void PCHStmtReader::VisitBreakStmt(BreakStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000296 VisitStmt(S);
297 S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000298}
299
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000300void PCHStmtReader::VisitReturnStmt(ReturnStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000301 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000302 S->setRetValue(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000303 S->setReturnLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor5077c382010-05-15 06:01:05 +0000304 S->setNRVOCandidate(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000305}
306
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000307void PCHStmtReader::VisitDeclStmt(DeclStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000308 VisitStmt(S);
309 S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
310 S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
311
312 if (Idx + 1 == Record.size()) {
313 // Single declaration
314 S->setDeclGroup(DeclGroupRef(Reader.GetDecl(Record[Idx++])));
315 } else {
316 llvm::SmallVector<Decl *, 16> Decls;
317 Decls.reserve(Record.size() - Idx);
318 for (unsigned N = Record.size(); Idx != N; ++Idx)
319 Decls.push_back(Reader.GetDecl(Record[Idx]));
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000320 S->setDeclGroup(DeclGroupRef(DeclGroup::Create(*Reader.getContext(),
Douglas Gregor75fdb232009-05-22 22:45:36 +0000321 Decls.data(),
322 Decls.size())));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000323 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000324}
325
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000326void PCHStmtReader::VisitAsmStmt(AsmStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000327 VisitStmt(S);
328 unsigned NumOutputs = Record[Idx++];
329 unsigned NumInputs = Record[Idx++];
330 unsigned NumClobbers = Record[Idx++];
331 S->setAsmLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
332 S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
333 S->setVolatile(Record[Idx++]);
334 S->setSimple(Record[Idx++]);
Mike Stump3b11fd32010-01-04 22:37:17 +0000335 S->setMSAsm(Record[Idx++]);
Mike Stump1eb44332009-09-09 15:08:12 +0000336
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000337 S->setAsmString(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000338
339 // Outputs and inputs
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000340 llvm::SmallVector<IdentifierInfo *, 16> Names;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000341 llvm::SmallVector<StringLiteral*, 16> Constraints;
342 llvm::SmallVector<Stmt*, 16> Exprs;
343 for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000344 Names.push_back(Reader.GetIdentifierInfo(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000345 Constraints.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
346 Exprs.push_back(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000347 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000348
349 // Constraints
350 llvm::SmallVector<StringLiteral*, 16> Clobbers;
351 for (unsigned I = 0; I != NumClobbers; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000352 Clobbers.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000353
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000354 S->setOutputsAndInputsAndClobbers(*Reader.getContext(),
355 Names.data(), Constraints.data(),
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000356 Exprs.data(), NumOutputs, NumInputs,
357 Clobbers.data(), NumClobbers);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000358}
359
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000360void PCHStmtReader::VisitExpr(Expr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000361 VisitStmt(E);
362 E->setType(Reader.GetType(Record[Idx++]));
363 E->setTypeDependent(Record[Idx++]);
364 E->setValueDependent(Record[Idx++]);
365 assert(Idx == NumExprFields && "Incorrect expression field count");
Chris Lattner4c6f9522009-04-27 05:14:47 +0000366}
367
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000368void PCHStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000369 VisitExpr(E);
370 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
371 E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000372}
373
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000374void PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000375 VisitExpr(E);
John McCalldbd872f2009-12-08 09:08:17 +0000376 E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000377 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregora2813ce2009-10-23 18:54:35 +0000378 // FIXME: read qualifier
379 // FIXME: read explicit template arguments
Chris Lattner4c6f9522009-04-27 05:14:47 +0000380}
381
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000382void PCHStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000383 VisitExpr(E);
384 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
385 E->setValue(Reader.ReadAPInt(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000386}
387
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000388void PCHStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000389 VisitExpr(E);
390 E->setValue(Reader.ReadAPFloat(Record, Idx));
391 E->setExact(Record[Idx++]);
392 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000393}
394
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000395void PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000396 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000397 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000398}
399
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000400void PCHStmtReader::VisitStringLiteral(StringLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000401 VisitExpr(E);
402 unsigned Len = Record[Idx++];
Mike Stump1eb44332009-09-09 15:08:12 +0000403 assert(Record[Idx] == E->getNumConcatenated() &&
Chris Lattner4c6f9522009-04-27 05:14:47 +0000404 "Wrong number of concatenated tokens!");
405 ++Idx;
406 E->setWide(Record[Idx++]);
407
Mike Stump1eb44332009-09-09 15:08:12 +0000408 // Read string data
Daniel Dunbarb6480232009-09-22 03:27:33 +0000409 llvm::SmallString<16> Str(&Record[Idx], &Record[Idx] + Len);
410 E->setString(*Reader.getContext(), Str.str());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000411 Idx += Len;
412
413 // Read source locations
414 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
415 E->setStrTokenLoc(I, SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000416}
417
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000418void PCHStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000419 VisitExpr(E);
420 E->setValue(Record[Idx++]);
421 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
422 E->setWide(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000423}
424
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000425void PCHStmtReader::VisitParenExpr(ParenExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000426 VisitExpr(E);
427 E->setLParen(SourceLocation::getFromRawEncoding(Record[Idx++]));
428 E->setRParen(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000429 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000430}
431
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000432void PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000433 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000434 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000435 E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
436 E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000437}
438
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000439void PCHStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000440 typedef OffsetOfExpr::OffsetOfNode Node;
441 VisitExpr(E);
442 assert(E->getNumComponents() == Record[Idx]);
443 ++Idx;
444 assert(E->getNumExpressions() == Record[Idx]);
445 ++Idx;
446 E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
447 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
448 E->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
449 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
450 Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]);
451 SourceLocation Start = SourceLocation::getFromRawEncoding(Record[Idx++]);
452 SourceLocation End = SourceLocation::getFromRawEncoding(Record[Idx++]);
453 switch (Kind) {
454 case Node::Array:
455 E->setComponent(I, Node(Start, Record[Idx++], End));
456 break;
457
458 case Node::Field:
459 E->setComponent(I,
460 Node(Start,
461 dyn_cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++])),
462 End));
463 break;
464
465 case Node::Identifier:
466 E->setComponent(I, Node(Start, Reader.GetIdentifier(Record[Idx++]), End));
467 break;
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000468
469 case Node::Base:
470 // FIXME: Implement this!
471 llvm_unreachable("PCH for offsetof(base-specifier) not implemented");
472 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000473 }
474 }
475
476 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000477 E->setIndexExpr(I, Reader.ReadSubExpr());
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000478}
479
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000480void PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000481 VisitExpr(E);
482 E->setSizeof(Record[Idx++]);
483 if (Record[Idx] == 0) {
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000484 E->setArgument(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000485 ++Idx;
486 } else {
John McCalla93c9342009-12-07 02:54:59 +0000487 E->setArgument(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000488 }
489 E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
490 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000491}
492
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000493void PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000494 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000495 E->setLHS(Reader.ReadSubExpr());
496 E->setRHS(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000497 E->setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000498}
499
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000500void PCHStmtReader::VisitCallExpr(CallExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000501 VisitExpr(E);
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000502 E->setNumArgs(*Reader.getContext(), Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000503 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000504 E->setCallee(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000505 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000506 E->setArg(I, Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000507}
508
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000509void PCHStmtReader::VisitMemberExpr(MemberExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000510 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000511 E->setBase(Reader.ReadSubExpr());
Eli Friedmandd27a2d2009-12-04 06:46:54 +0000512 E->setMemberDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000513 E->setMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
514 E->setArrow(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000515}
516
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000517void PCHStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Narofff242b1b2009-07-24 17:54:45 +0000518 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000519 E->setBase(Reader.ReadSubExpr());
Steve Narofff242b1b2009-07-24 17:54:45 +0000520 E->setIsaMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
521 E->setArrow(Record[Idx++]);
Steve Narofff242b1b2009-07-24 17:54:45 +0000522}
523
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000524void PCHStmtReader::VisitCastExpr(CastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000525 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000526 E->setSubExpr(Reader.ReadSubExpr());
Anders Carlssoncdef2b72009-07-31 00:48:10 +0000527 E->setCastKind((CastExpr::CastKind)Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000528}
529
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000530void PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000531 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000532 E->setLHS(Reader.ReadSubExpr());
533 E->setRHS(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000534 E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
535 E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000536}
537
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000538void PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000539 VisitBinaryOperator(E);
540 E->setComputationLHSType(Reader.GetType(Record[Idx++]));
541 E->setComputationResultType(Reader.GetType(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000542}
543
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000544void PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000545 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000546 E->setCond(Reader.ReadSubExpr());
547 E->setLHS(Reader.ReadSubExpr());
548 E->setRHS(Reader.ReadSubExpr());
Douglas Gregor47e1f7c2009-08-26 14:37:04 +0000549 E->setQuestionLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
550 E->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000551}
552
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000553void PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000554 VisitCastExpr(E);
555 E->setLvalueCast(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000556}
557
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000558void PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000559 VisitCastExpr(E);
John McCall9d125032010-01-15 18:39:57 +0000560 E->setTypeInfoAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000561}
562
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000563void PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000564 VisitExplicitCastExpr(E);
565 E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
566 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000567}
568
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000569void PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000570 VisitExpr(E);
571 E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall42f56b52010-01-18 19:35:47 +0000572 E->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000573 E->setInitializer(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000574 E->setFileScope(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000575}
576
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000577void PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000578 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000579 E->setBase(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000580 E->setAccessor(Reader.GetIdentifierInfo(Record, Idx));
581 E->setAccessorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000582}
583
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000584void PCHStmtReader::VisitInitListExpr(InitListExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000585 VisitExpr(E);
586 unsigned NumInits = Record[Idx++];
Ted Kremenek709210f2010-04-13 23:39:13 +0000587 E->reserveInits(*Reader.getContext(), NumInits);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000588 for (unsigned I = 0; I != NumInits; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000589 E->updateInit(*Reader.getContext(), I, Reader.ReadSubExpr());
590 E->setSyntacticForm(cast_or_null<InitListExpr>(Reader.ReadSubStmt()));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000591 E->setLBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
592 E->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
593 E->setInitializedFieldInUnion(
594 cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++])));
595 E->sawArrayRangeDesignator(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000596}
597
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000598void PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000599 typedef DesignatedInitExpr::Designator Designator;
600
601 VisitExpr(E);
602 unsigned NumSubExprs = Record[Idx++];
603 assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
604 for (unsigned I = 0; I != NumSubExprs; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000605 E->setSubExpr(I, Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000606 E->setEqualOrColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
607 E->setGNUSyntax(Record[Idx++]);
608
609 llvm::SmallVector<Designator, 4> Designators;
610 while (Idx < Record.size()) {
611 switch ((pch::DesignatorTypes)Record[Idx++]) {
612 case pch::DESIG_FIELD_DECL: {
613 FieldDecl *Field = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
Mike Stump1eb44332009-09-09 15:08:12 +0000614 SourceLocation DotLoc
Chris Lattner4c6f9522009-04-27 05:14:47 +0000615 = SourceLocation::getFromRawEncoding(Record[Idx++]);
Mike Stump1eb44332009-09-09 15:08:12 +0000616 SourceLocation FieldLoc
Chris Lattner4c6f9522009-04-27 05:14:47 +0000617 = SourceLocation::getFromRawEncoding(Record[Idx++]);
Mike Stump1eb44332009-09-09 15:08:12 +0000618 Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
Chris Lattner4c6f9522009-04-27 05:14:47 +0000619 FieldLoc));
620 Designators.back().setField(Field);
621 break;
622 }
623
624 case pch::DESIG_FIELD_NAME: {
625 const IdentifierInfo *Name = Reader.GetIdentifierInfo(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000626 SourceLocation DotLoc
Chris Lattner4c6f9522009-04-27 05:14:47 +0000627 = SourceLocation::getFromRawEncoding(Record[Idx++]);
Mike Stump1eb44332009-09-09 15:08:12 +0000628 SourceLocation FieldLoc
Chris Lattner4c6f9522009-04-27 05:14:47 +0000629 = SourceLocation::getFromRawEncoding(Record[Idx++]);
630 Designators.push_back(Designator(Name, DotLoc, FieldLoc));
631 break;
632 }
Mike Stump1eb44332009-09-09 15:08:12 +0000633
Chris Lattner4c6f9522009-04-27 05:14:47 +0000634 case pch::DESIG_ARRAY: {
635 unsigned Index = Record[Idx++];
636 SourceLocation LBracketLoc
637 = SourceLocation::getFromRawEncoding(Record[Idx++]);
638 SourceLocation RBracketLoc
639 = SourceLocation::getFromRawEncoding(Record[Idx++]);
640 Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
641 break;
642 }
643
644 case pch::DESIG_ARRAY_RANGE: {
645 unsigned Index = Record[Idx++];
646 SourceLocation LBracketLoc
647 = SourceLocation::getFromRawEncoding(Record[Idx++]);
648 SourceLocation EllipsisLoc
649 = SourceLocation::getFromRawEncoding(Record[Idx++]);
650 SourceLocation RBracketLoc
651 = SourceLocation::getFromRawEncoding(Record[Idx++]);
652 Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
653 RBracketLoc));
654 break;
655 }
656 }
657 }
Douglas Gregor319d57f2010-01-06 23:17:19 +0000658 E->setDesignators(*Reader.getContext(),
659 Designators.data(), Designators.size());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000660}
661
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000662void PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000663 VisitExpr(E);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000664}
665
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000666void PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000667 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000668 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000669 E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
670 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000671}
672
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000673void PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000674 VisitExpr(E);
675 E->setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
676 E->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
677 Reader.SetLabelOf(E, Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000678}
679
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000680void PCHStmtReader::VisitStmtExpr(StmtExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000681 VisitExpr(E);
682 E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
683 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000684 E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt()));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000685}
686
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000687void PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000688 VisitExpr(E);
689 E->setArgType1(Reader.GetType(Record[Idx++]));
690 E->setArgType2(Reader.GetType(Record[Idx++]));
691 E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
692 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000693}
694
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000695void PCHStmtReader::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000696 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000697 E->setCond(Reader.ReadSubExpr());
698 E->setLHS(Reader.ReadSubExpr());
699 E->setRHS(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000700 E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
701 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000702}
703
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000704void PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000705 VisitExpr(E);
706 E->setTokenLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000707}
708
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000709void PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000710 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000711 llvm::SmallVector<Expr *, 16> Exprs;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000712 unsigned NumExprs = Record[Idx++];
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000713 while (NumExprs--)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000714 Exprs.push_back(Reader.ReadSubExpr());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000715 E->setExprs(*Reader.getContext(), Exprs.data(), Exprs.size());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000716 E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
717 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000718}
719
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000720void PCHStmtReader::VisitBlockExpr(BlockExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000721 VisitExpr(E);
722 E->setBlockDecl(cast_or_null<BlockDecl>(Reader.GetDecl(Record[Idx++])));
723 E->setHasBlockDeclRefExprs(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000724}
725
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000726void PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000727 VisitExpr(E);
728 E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
729 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
730 E->setByRef(Record[Idx++]);
Fariborz Jahanian9b0b57c2009-06-20 00:02:26 +0000731 E->setConstQualAdded(Record[Idx++]);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000732 E->setCopyConstructorExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000733}
734
735//===----------------------------------------------------------------------===//
736// Objective-C Expressions and Statements
737
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000738void PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000739 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000740 E->setString(cast<StringLiteral>(Reader.ReadSubStmt()));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000741 E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000742}
743
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000744void PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000745 VisitExpr(E);
Douglas Gregor81d34662010-04-20 15:39:42 +0000746 E->setEncodedTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000747 E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
748 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000749}
750
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000751void PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000752 VisitExpr(E);
753 E->setSelector(Reader.GetSelector(Record, Idx));
754 E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
755 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000756}
757
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000758void PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000759 VisitExpr(E);
760 E->setProtocol(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
761 E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
762 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000763}
764
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000765void PCHStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000766 VisitExpr(E);
767 E->setDecl(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
768 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000769 E->setBase(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000770 E->setIsArrow(Record[Idx++]);
771 E->setIsFreeIvar(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000772}
773
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000774void PCHStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000775 VisitExpr(E);
776 E->setProperty(cast<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
777 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000778 E->setBase(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000779}
780
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000781void PCHStmtReader::VisitObjCImplicitSetterGetterRefExpr(
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000782 ObjCImplicitSetterGetterRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000783 VisitExpr(E);
784 E->setGetterMethod(
785 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
786 E->setSetterMethod(
787 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniand2ae5aa2009-08-18 21:37:33 +0000788 E->setInterfaceDecl(
Chris Lattner4c6f9522009-04-27 05:14:47 +0000789 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000790 E->setBase(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000791 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
792 E->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000793}
794
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000795void PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000796 VisitExpr(E);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000797 assert(Record[Idx] == E->getNumArgs());
798 ++Idx;
799 ObjCMessageExpr::ReceiverKind Kind
800 = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
801 switch (Kind) {
802 case ObjCMessageExpr::Instance:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000803 E->setInstanceReceiver(Reader.ReadSubExpr());
Douglas Gregor04badcf2010-04-21 00:45:42 +0000804 break;
805
806 case ObjCMessageExpr::Class:
807 E->setClassReceiver(Reader.GetTypeSourceInfo(Record, Idx));
808 break;
809
810 case ObjCMessageExpr::SuperClass:
811 case ObjCMessageExpr::SuperInstance: {
812 QualType T = Reader.GetType(Record[Idx++]);
813 SourceLocation SuperLoc = SourceLocation::getFromRawEncoding(Record[Idx++]);
814 E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
815 break;
816 }
817 }
818
819 assert(Kind == E->getReceiverKind());
820
821 if (Record[Idx++])
822 E->setMethodDecl(cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
823 else
824 E->setSelector(Reader.GetSelector(Record, Idx));
825
Chris Lattner4c6f9522009-04-27 05:14:47 +0000826 E->setLeftLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
827 E->setRightLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000828
829 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000830 E->setArg(I, Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000831}
832
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000833void PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000834 VisitExpr(E);
835 E->setLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000836}
837
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000838void PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000839 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000840 S->setElement(Reader.ReadSubStmt());
841 S->setCollection(Reader.ReadSubExpr());
842 S->setBody(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000843 S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
844 S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000845}
846
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000847void PCHStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000848 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000849 S->setCatchBody(Reader.ReadSubStmt());
Douglas Gregorc00d8e12010-04-26 16:46:50 +0000850 S->setCatchParamDecl(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000851 S->setAtCatchLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
852 S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000853}
854
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000855void PCHStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000856 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000857 S->setFinallyBody(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000858 S->setAtFinallyLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000859}
860
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000861void PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000862 VisitStmt(S);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000863 assert(Record[Idx] == S->getNumCatchStmts());
864 ++Idx;
865 bool HasFinally = Record[Idx++];
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000866 S->setTryBody(Reader.ReadSubStmt());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000867 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000868 S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt()));
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000869
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000870 if (HasFinally)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000871 S->setFinallyStmt(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000872 S->setAtTryLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000873}
874
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000875void PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000876 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000877 S->setSynchExpr(Reader.ReadSubStmt());
878 S->setSynchBody(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000879 S->setAtSynchronizedLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000880}
881
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000882void PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000883 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000884 S->setThrowExpr(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000885 S->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000886}
887
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000888//===----------------------------------------------------------------------===//
889// C++ Expressions and Statements
890
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000891void PCHStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
892 VisitCallExpr(E);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000893 E->setOperator((OverloadedOperatorKind)Record[Idx++]);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000894}
895
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000896void PCHStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor39da0b82009-09-09 23:08:42 +0000897 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000898 assert(Record[Idx] == E->getNumArgs() &&"Read wrong record during creation?");
Argyrios Kyrtzidis5e1b7c22010-06-24 08:57:09 +0000899 ++Idx; // NumArgs;
900 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000901 E->setArg(I, Reader.ReadSubExpr());
Douglas Gregor39da0b82009-09-09 23:08:42 +0000902 E->setConstructor(cast<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor99a2e602009-12-16 01:38:02 +0000903 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor39da0b82009-09-09 23:08:42 +0000904 E->setElidable(Record[Idx++]);
Douglas Gregor16006c92009-12-16 18:50:27 +0000905 E->setRequiresZeroInitialization(Record[Idx++]);
Douglas Gregor3c9034c2010-05-15 00:13:29 +0000906 E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
Douglas Gregor39da0b82009-09-09 23:08:42 +0000907}
Chris Lattner4c6f9522009-04-27 05:14:47 +0000908
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000909void PCHStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
910 VisitExplicitCastExpr(E);
Sam Weinigce757a72010-01-16 21:21:01 +0000911 E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sam Weinigce757a72010-01-16 21:21:01 +0000912}
913
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000914void PCHStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +0000915 return VisitCXXNamedCastExpr(E);
916}
917
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000918void PCHStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +0000919 return VisitCXXNamedCastExpr(E);
920}
921
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000922void PCHStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +0000923 return VisitCXXNamedCastExpr(E);
924}
925
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000926void PCHStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +0000927 return VisitCXXNamedCastExpr(E);
928}
929
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000930void PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
931 VisitExplicitCastExpr(E);
Sam Weinigce757a72010-01-16 21:21:01 +0000932 E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
933 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sam Weinigce757a72010-01-16 21:21:01 +0000934}
935
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000936void PCHStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +0000937 VisitExpr(E);
938 E->setValue(Record[Idx++]);
939 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sam Weinigeb7f9612010-02-07 06:32:43 +0000940}
941
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000942void PCHStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +0000943 VisitExpr(E);
944 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sam Weinigeb7f9612010-02-07 06:32:43 +0000945}
946
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000947void PCHStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner14ab24f2010-05-09 06:03:39 +0000948 VisitExpr(E);
949 E->setSourceRange(Reader.ReadSourceRange(Record, Idx));
950 if (E->isTypeOperand()) { // typeid(int)
951 E->setTypeOperandSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000952 return;
Chris Lattner14ab24f2010-05-09 06:03:39 +0000953 }
954
955 // typeid(42+2)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000956 E->setExprOperand(Reader.ReadSubExpr());
Chris Lattner14ab24f2010-05-09 06:03:39 +0000957}
958
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000959void PCHStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +0000960 VisitExpr(E);
961 E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
962 E->setImplicit(Record[Idx++]);
Chris Lattner2fbdfcd2010-05-09 06:15:05 +0000963}
964
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000965void PCHStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +0000966 VisitExpr(E);
967 E->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000968 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner2fbdfcd2010-05-09 06:15:05 +0000969}
Chris Lattner14ab24f2010-05-09 06:03:39 +0000970
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000971void PCHStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattner030854b2010-05-09 06:40:08 +0000972 VisitExpr(E);
973 E->setUsedLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
974 bool HasStoredExpr = Record[Idx++];
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000975 if (!HasStoredExpr) return;
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000976 E->setExpr(Reader.ReadSubExpr());
Chris Lattnerd2598362010-05-10 00:25:06 +0000977}
978
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000979void PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +0000980 VisitExpr(E);
981 E->setTemporary(Reader.ReadCXXTemporary(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000982 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattnerd2598362010-05-10 00:25:06 +0000983}
984
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000985void PCHStmtReader::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +0000986 VisitExpr(E);
987 E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
988 E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner59218632010-05-10 01:22:27 +0000989}
990
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000991void PCHStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +0000992 VisitExpr(E);
993 E->setGlobalNew(Record[Idx++]);
994 E->setParenTypeId(Record[Idx++]);
995 E->setHasInitializer(Record[Idx++]);
996 bool isArray = Record[Idx++];
997 unsigned NumPlacementArgs = Record[Idx++];
998 unsigned NumCtorArgs = Record[Idx++];
999 E->setOperatorNew(cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
1000 E->setOperatorDelete(
1001 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
1002 E->setConstructor(
1003 cast_or_null<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++])));
1004 E->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
1005 E->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
1006
1007 E->AllocateArgsArray(*Reader.getContext(), isArray, NumPlacementArgs,
1008 NumCtorArgs);
1009
1010 // Install all the subexpressions.
Chris Lattner59218632010-05-10 01:22:27 +00001011 for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
1012 I != e; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001013 *I = Reader.ReadSubStmt();
Chris Lattner59218632010-05-10 01:22:27 +00001014}
1015
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001016void PCHStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001017 VisitExpr(E);
1018 E->setGlobalDelete(Record[Idx++]);
1019 E->setArrayForm(Record[Idx++]);
1020 E->setOperatorDelete(
1021 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001022 E->setArgument(Reader.ReadSubExpr());
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001023 E->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001024}
Chris Lattnerd2598362010-05-10 00:25:06 +00001025
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001026void PCHStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001027 VisitExpr(E);
1028
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001029 E->setBase(Reader.ReadSubExpr());
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001030 E->setArrow(Record[Idx++]);
1031 E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
1032 E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
1033 E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
1034 E->setScopeTypeInfo(Reader.GetTypeSourceInfo(Record, Idx));
1035 E->setColonColonLoc(Reader.ReadSourceLocation(Record, Idx));
1036 E->setTildeLoc(Reader.ReadSourceLocation(Record, Idx));
1037
1038 IdentifierInfo *II = Reader.GetIdentifierInfo(Record, Idx);
1039 if (II)
1040 E->setDestroyedType(II, Reader.ReadSourceLocation(Record, Idx));
1041 else
1042 E->setDestroyedType(Reader.GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001043}
1044
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001045void PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001046 VisitExpr(E);
1047 unsigned NumTemps = Record[Idx++];
1048 if (NumTemps) {
Ted Kremenekd04ed412010-05-10 20:06:30 +00001049 E->setNumTemporaries(*Reader.getContext(), NumTemps);
Chris Lattnerd2598362010-05-10 00:25:06 +00001050 for (unsigned i = 0; i != NumTemps; ++i)
1051 E->setTemporary(i, Reader.ReadCXXTemporary(Record, Idx));
1052 }
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001053 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner030854b2010-05-09 06:40:08 +00001054}
1055
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001056void
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001057PCHStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
1058 VisitExpr(E);
1059
1060 unsigned NumTemplateArgs = Record[Idx++];
1061 assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
1062 "Read wrong record during creation ?");
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +00001063 if (E->hasExplicitTemplateArgs())
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001064 ReadExplicitTemplateArgumentList(*E->getExplicitTemplateArgumentList(),
1065 NumTemplateArgs);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001066
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001067 E->setBase(Reader.ReadSubExpr());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001068 E->setBaseType(Reader.GetType(Record[Idx++]));
1069 E->setArrow(Record[Idx++]);
1070 E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
1071 E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
1072 E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
1073 E->setFirstQualifierFoundInScope(
1074 cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++])));
1075 E->setMember(Reader.ReadDeclarationName(Record, Idx));
1076 E->setMemberLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001077}
1078
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001079void
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001080PCHStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1081 VisitExpr(E);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001082
1083 unsigned NumTemplateArgs = Record[Idx++];
1084 assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
1085 "Read wrong record during creation ?");
1086 if (E->hasExplicitTemplateArgs())
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001087 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
1088 NumTemplateArgs);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001089
1090 E->setDeclName(Reader.ReadDeclarationName(Record, Idx));
1091 E->setLocation(Reader.ReadSourceLocation(Record, Idx));
1092 E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
1093 E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001094}
1095
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001096void
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001097PCHStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1098 VisitExpr(E);
1099 assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
1100 ++Idx; // NumArgs;
1101 for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001102 E->setArg(I, Reader.ReadSubExpr());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001103 E->setTypeBeginLoc(Reader.ReadSourceLocation(Record, Idx));
1104 E->setTypeAsWritten(Reader.GetType(Record[Idx++]));
1105 E->setLParenLoc(Reader.ReadSourceLocation(Record, Idx));
1106 E->setRParenLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001107}
1108
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001109void PCHStmtReader::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001110 VisitExpr(E);
1111
1112 unsigned NumTemplateArgs = Record[Idx++];
1113 assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
1114 "Read wrong record during creation ?");
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001115 if (E->hasExplicitTemplateArgs())
1116 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
1117 NumTemplateArgs);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001118
1119 unsigned NumDecls = Record[Idx++];
1120 UnresolvedSet<8> Decls;
1121 for (unsigned i = 0; i != NumDecls; ++i) {
1122 NamedDecl *D = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
1123 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1124 Decls.addDecl(D, AS);
1125 }
1126 E->initializeResults(*Reader.getContext(), Decls.begin(), Decls.end());
1127
1128 E->setName(Reader.ReadDeclarationName(Record, Idx));
1129 E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
1130 E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
1131 E->setNameLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001132}
1133
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001134void PCHStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1135 VisitOverloadExpr(E);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001136 E->setArrow(Record[Idx++]);
1137 E->setHasUnresolvedUsing(Record[Idx++]);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001138 E->setBase(Reader.ReadSubExpr());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001139 E->setBaseType(Reader.GetType(Record[Idx++]));
1140 E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001141}
1142
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001143void PCHStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1144 VisitOverloadExpr(E);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001145 E->setRequiresADL(Record[Idx++]);
1146 E->setOverloaded(Record[Idx++]);
1147 E->setNamingClass(cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001148}
1149
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001150Stmt *PCHReader::ReadStmt() {
1151 switch (ReadingKind) {
1152 case Read_Decl:
1153 case Read_Type:
1154 // Read a statement from the current DeclCursor.
1155 return ReadStmtFromStream(DeclsCursor);
1156 case Read_Stmt:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001157 return ReadSubStmt();
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001158 }
1159
1160 llvm_unreachable("ReadingKind not set ?");
1161 return 0;
1162}
1163
1164Expr *PCHReader::ReadExpr() {
1165 return cast_or_null<Expr>(ReadStmt());
1166}
Chris Lattner030854b2010-05-09 06:40:08 +00001167
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001168Expr *PCHReader::ReadSubExpr() {
1169 return cast_or_null<Expr>(ReadSubStmt());
1170}
1171
Chris Lattner52e97d12009-04-27 05:41:06 +00001172// Within the bitstream, expressions are stored in Reverse Polish
1173// Notation, with each of the subexpressions preceding the
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001174// expression they are stored in. Subexpressions are stored from last to first.
1175// To evaluate expressions, we continue reading expressions and placing them on
1176// the stack, with expressions having operands removing those operands from the
Chris Lattner52e97d12009-04-27 05:41:06 +00001177// stack. Evaluation terminates when we see a STMT_STOP record, and
1178// the single remaining expression on the stack is our result.
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001179Stmt *PCHReader::ReadStmtFromStream(llvm::BitstreamCursor &Cursor) {
1180
1181 ReadingKindTracker ReadingKind(Read_Stmt, *this);
1182
1183#ifndef NDEBUG
1184 unsigned PrevNumStmts = StmtStack.size();
1185#endif
1186
Chris Lattner4c6f9522009-04-27 05:14:47 +00001187 RecordData Record;
1188 unsigned Idx;
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001189 PCHStmtReader Reader(*this, Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001190 Stmt::EmptyShell Empty;
1191
1192 while (true) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001193 unsigned Code = Cursor.ReadCode();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001194 if (Code == llvm::bitc::END_BLOCK) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001195 if (Cursor.ReadBlockEnd()) {
Douglas Gregora02b1472009-04-28 21:53:25 +00001196 Error("error at end of block in PCH file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001197 return 0;
1198 }
1199 break;
1200 }
1201
1202 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
1203 // No known subblocks, always skip them.
Chris Lattner52e97d12009-04-27 05:41:06 +00001204 Cursor.ReadSubBlockID();
1205 if (Cursor.SkipBlock()) {
Douglas Gregora02b1472009-04-28 21:53:25 +00001206 Error("malformed block record in PCH file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001207 return 0;
1208 }
1209 continue;
1210 }
1211
1212 if (Code == llvm::bitc::DEFINE_ABBREV) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001213 Cursor.ReadAbbrevRecord();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001214 continue;
1215 }
1216
1217 Stmt *S = 0;
1218 Idx = 0;
1219 Record.clear();
1220 bool Finished = false;
Chris Lattner52e97d12009-04-27 05:41:06 +00001221 switch ((pch::StmtCode)Cursor.ReadRecord(Code, Record)) {
Chris Lattner4c6f9522009-04-27 05:14:47 +00001222 case pch::STMT_STOP:
1223 Finished = true;
1224 break;
1225
Mike Stump1eb44332009-09-09 15:08:12 +00001226 case pch::STMT_NULL_PTR:
1227 S = 0;
Chris Lattner4c6f9522009-04-27 05:14:47 +00001228 break;
1229
1230 case pch::STMT_NULL:
1231 S = new (Context) NullStmt(Empty);
1232 break;
1233
1234 case pch::STMT_COMPOUND:
1235 S = new (Context) CompoundStmt(Empty);
1236 break;
1237
1238 case pch::STMT_CASE:
1239 S = new (Context) CaseStmt(Empty);
1240 break;
1241
1242 case pch::STMT_DEFAULT:
1243 S = new (Context) DefaultStmt(Empty);
1244 break;
1245
1246 case pch::STMT_LABEL:
1247 S = new (Context) LabelStmt(Empty);
1248 break;
1249
1250 case pch::STMT_IF:
1251 S = new (Context) IfStmt(Empty);
1252 break;
1253
1254 case pch::STMT_SWITCH:
1255 S = new (Context) SwitchStmt(Empty);
1256 break;
1257
1258 case pch::STMT_WHILE:
1259 S = new (Context) WhileStmt(Empty);
1260 break;
1261
1262 case pch::STMT_DO:
1263 S = new (Context) DoStmt(Empty);
1264 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001265
Chris Lattner4c6f9522009-04-27 05:14:47 +00001266 case pch::STMT_FOR:
1267 S = new (Context) ForStmt(Empty);
1268 break;
1269
1270 case pch::STMT_GOTO:
1271 S = new (Context) GotoStmt(Empty);
1272 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001273
Chris Lattner4c6f9522009-04-27 05:14:47 +00001274 case pch::STMT_INDIRECT_GOTO:
1275 S = new (Context) IndirectGotoStmt(Empty);
1276 break;
1277
1278 case pch::STMT_CONTINUE:
1279 S = new (Context) ContinueStmt(Empty);
1280 break;
1281
1282 case pch::STMT_BREAK:
1283 S = new (Context) BreakStmt(Empty);
1284 break;
1285
1286 case pch::STMT_RETURN:
1287 S = new (Context) ReturnStmt(Empty);
1288 break;
1289
1290 case pch::STMT_DECL:
1291 S = new (Context) DeclStmt(Empty);
1292 break;
1293
1294 case pch::STMT_ASM:
1295 S = new (Context) AsmStmt(Empty);
1296 break;
1297
1298 case pch::EXPR_PREDEFINED:
1299 S = new (Context) PredefinedExpr(Empty);
1300 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001301
1302 case pch::EXPR_DECL_REF:
1303 S = new (Context) DeclRefExpr(Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001304 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001305
1306 case pch::EXPR_INTEGER_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001307 S = new (Context) IntegerLiteral(Empty);
1308 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001309
Chris Lattner4c6f9522009-04-27 05:14:47 +00001310 case pch::EXPR_FLOATING_LITERAL:
1311 S = new (Context) FloatingLiteral(Empty);
1312 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001313
Chris Lattner4c6f9522009-04-27 05:14:47 +00001314 case pch::EXPR_IMAGINARY_LITERAL:
1315 S = new (Context) ImaginaryLiteral(Empty);
1316 break;
1317
1318 case pch::EXPR_STRING_LITERAL:
Mike Stump1eb44332009-09-09 15:08:12 +00001319 S = StringLiteral::CreateEmpty(*Context,
Chris Lattner4c6f9522009-04-27 05:14:47 +00001320 Record[PCHStmtReader::NumExprFields + 1]);
1321 break;
1322
1323 case pch::EXPR_CHARACTER_LITERAL:
1324 S = new (Context) CharacterLiteral(Empty);
1325 break;
1326
1327 case pch::EXPR_PAREN:
1328 S = new (Context) ParenExpr(Empty);
1329 break;
1330
1331 case pch::EXPR_UNARY_OPERATOR:
1332 S = new (Context) UnaryOperator(Empty);
1333 break;
1334
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001335 case pch::EXPR_OFFSETOF:
1336 S = OffsetOfExpr::CreateEmpty(*Context,
1337 Record[PCHStmtReader::NumExprFields],
1338 Record[PCHStmtReader::NumExprFields + 1]);
1339 break;
1340
Chris Lattner4c6f9522009-04-27 05:14:47 +00001341 case pch::EXPR_SIZEOF_ALIGN_OF:
1342 S = new (Context) SizeOfAlignOfExpr(Empty);
1343 break;
1344
1345 case pch::EXPR_ARRAY_SUBSCRIPT:
1346 S = new (Context) ArraySubscriptExpr(Empty);
1347 break;
1348
1349 case pch::EXPR_CALL:
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +00001350 S = new (Context) CallExpr(*Context, Stmt::CallExprClass, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001351 break;
1352
1353 case pch::EXPR_MEMBER:
1354 S = new (Context) MemberExpr(Empty);
1355 break;
1356
1357 case pch::EXPR_BINARY_OPERATOR:
1358 S = new (Context) BinaryOperator(Empty);
1359 break;
1360
1361 case pch::EXPR_COMPOUND_ASSIGN_OPERATOR:
1362 S = new (Context) CompoundAssignOperator(Empty);
1363 break;
1364
1365 case pch::EXPR_CONDITIONAL_OPERATOR:
1366 S = new (Context) ConditionalOperator(Empty);
1367 break;
1368
1369 case pch::EXPR_IMPLICIT_CAST:
1370 S = new (Context) ImplicitCastExpr(Empty);
1371 break;
1372
1373 case pch::EXPR_CSTYLE_CAST:
1374 S = new (Context) CStyleCastExpr(Empty);
1375 break;
1376
1377 case pch::EXPR_COMPOUND_LITERAL:
1378 S = new (Context) CompoundLiteralExpr(Empty);
1379 break;
1380
1381 case pch::EXPR_EXT_VECTOR_ELEMENT:
1382 S = new (Context) ExtVectorElementExpr(Empty);
1383 break;
1384
1385 case pch::EXPR_INIT_LIST:
Ted Kremenek709210f2010-04-13 23:39:13 +00001386 S = new (Context) InitListExpr(*getContext(), Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001387 break;
1388
1389 case pch::EXPR_DESIGNATED_INIT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001390 S = DesignatedInitExpr::CreateEmpty(*Context,
Chris Lattner4c6f9522009-04-27 05:14:47 +00001391 Record[PCHStmtReader::NumExprFields] - 1);
Mike Stump1eb44332009-09-09 15:08:12 +00001392
Chris Lattner4c6f9522009-04-27 05:14:47 +00001393 break;
1394
1395 case pch::EXPR_IMPLICIT_VALUE_INIT:
1396 S = new (Context) ImplicitValueInitExpr(Empty);
1397 break;
1398
1399 case pch::EXPR_VA_ARG:
1400 S = new (Context) VAArgExpr(Empty);
1401 break;
1402
1403 case pch::EXPR_ADDR_LABEL:
1404 S = new (Context) AddrLabelExpr(Empty);
1405 break;
1406
1407 case pch::EXPR_STMT:
1408 S = new (Context) StmtExpr(Empty);
1409 break;
1410
1411 case pch::EXPR_TYPES_COMPATIBLE:
1412 S = new (Context) TypesCompatibleExpr(Empty);
1413 break;
1414
1415 case pch::EXPR_CHOOSE:
1416 S = new (Context) ChooseExpr(Empty);
1417 break;
1418
1419 case pch::EXPR_GNU_NULL:
1420 S = new (Context) GNUNullExpr(Empty);
1421 break;
1422
1423 case pch::EXPR_SHUFFLE_VECTOR:
1424 S = new (Context) ShuffleVectorExpr(Empty);
1425 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001426
Chris Lattner4c6f9522009-04-27 05:14:47 +00001427 case pch::EXPR_BLOCK:
1428 S = new (Context) BlockExpr(Empty);
1429 break;
1430
1431 case pch::EXPR_BLOCK_DECL_REF:
1432 S = new (Context) BlockDeclRefExpr(Empty);
1433 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001434
Chris Lattner4c6f9522009-04-27 05:14:47 +00001435 case pch::EXPR_OBJC_STRING_LITERAL:
1436 S = new (Context) ObjCStringLiteral(Empty);
1437 break;
1438 case pch::EXPR_OBJC_ENCODE:
1439 S = new (Context) ObjCEncodeExpr(Empty);
1440 break;
1441 case pch::EXPR_OBJC_SELECTOR_EXPR:
1442 S = new (Context) ObjCSelectorExpr(Empty);
1443 break;
1444 case pch::EXPR_OBJC_PROTOCOL_EXPR:
1445 S = new (Context) ObjCProtocolExpr(Empty);
1446 break;
1447 case pch::EXPR_OBJC_IVAR_REF_EXPR:
1448 S = new (Context) ObjCIvarRefExpr(Empty);
1449 break;
1450 case pch::EXPR_OBJC_PROPERTY_REF_EXPR:
1451 S = new (Context) ObjCPropertyRefExpr(Empty);
1452 break;
1453 case pch::EXPR_OBJC_KVC_REF_EXPR:
Fariborz Jahanian09105f52009-08-20 17:02:02 +00001454 S = new (Context) ObjCImplicitSetterGetterRefExpr(Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001455 break;
1456 case pch::EXPR_OBJC_MESSAGE_EXPR:
Douglas Gregor04badcf2010-04-21 00:45:42 +00001457 S = ObjCMessageExpr::CreateEmpty(*Context,
1458 Record[PCHStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001459 break;
1460 case pch::EXPR_OBJC_SUPER_EXPR:
1461 S = new (Context) ObjCSuperExpr(Empty);
1462 break;
Steve Narofff242b1b2009-07-24 17:54:45 +00001463 case pch::EXPR_OBJC_ISA:
1464 S = new (Context) ObjCIsaExpr(Empty);
1465 break;
Chris Lattner4c6f9522009-04-27 05:14:47 +00001466 case pch::STMT_OBJC_FOR_COLLECTION:
1467 S = new (Context) ObjCForCollectionStmt(Empty);
1468 break;
1469 case pch::STMT_OBJC_CATCH:
1470 S = new (Context) ObjCAtCatchStmt(Empty);
1471 break;
1472 case pch::STMT_OBJC_FINALLY:
1473 S = new (Context) ObjCAtFinallyStmt(Empty);
1474 break;
1475 case pch::STMT_OBJC_AT_TRY:
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001476 S = ObjCAtTryStmt::CreateEmpty(*Context,
1477 Record[PCHStmtReader::NumStmtFields],
1478 Record[PCHStmtReader::NumStmtFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001479 break;
1480 case pch::STMT_OBJC_AT_SYNCHRONIZED:
1481 S = new (Context) ObjCAtSynchronizedStmt(Empty);
1482 break;
1483 case pch::STMT_OBJC_AT_THROW:
1484 S = new (Context) ObjCAtThrowStmt(Empty);
1485 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001486
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +00001487 case pch::EXPR_CXX_OPERATOR_CALL:
1488 S = new (Context) CXXOperatorCallExpr(*Context, Empty);
1489 break;
Chris Lattner1817bd42010-05-09 05:36:05 +00001490
1491 case pch::EXPR_CXX_MEMBER_CALL:
1492 S = new (Context) CXXMemberCallExpr(*Context, Empty);
1493 break;
Douglas Gregor39da0b82009-09-09 23:08:42 +00001494
1495 case pch::EXPR_CXX_CONSTRUCT:
1496 S = new (Context) CXXConstructExpr(Empty, *Context,
Argyrios Kyrtzidis5e1b7c22010-06-24 08:57:09 +00001497 Record[PCHStmtReader::NumExprFields]);
Douglas Gregor39da0b82009-09-09 23:08:42 +00001498 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001499
1500 case pch::EXPR_CXX_STATIC_CAST:
1501 S = new (Context) CXXStaticCastExpr(Empty);
1502 break;
1503
1504 case pch::EXPR_CXX_DYNAMIC_CAST:
1505 S = new (Context) CXXDynamicCastExpr(Empty);
1506 break;
1507
1508 case pch::EXPR_CXX_REINTERPRET_CAST:
1509 S = new (Context) CXXReinterpretCastExpr(Empty);
1510 break;
1511
1512 case pch::EXPR_CXX_CONST_CAST:
1513 S = new (Context) CXXConstCastExpr(Empty);
1514 break;
1515
1516 case pch::EXPR_CXX_FUNCTIONAL_CAST:
1517 S = new (Context) CXXFunctionalCastExpr(Empty);
1518 break;
1519
Sam Weinigeb7f9612010-02-07 06:32:43 +00001520 case pch::EXPR_CXX_BOOL_LITERAL:
1521 S = new (Context) CXXBoolLiteralExpr(Empty);
1522 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001523
Sam Weinigeb7f9612010-02-07 06:32:43 +00001524 case pch::EXPR_CXX_NULL_PTR_LITERAL:
1525 S = new (Context) CXXNullPtrLiteralExpr(Empty);
1526 break;
Chris Lattner14ab24f2010-05-09 06:03:39 +00001527 case pch::EXPR_CXX_TYPEID_EXPR:
1528 S = new (Context) CXXTypeidExpr(Empty, true);
1529 break;
1530 case pch::EXPR_CXX_TYPEID_TYPE:
1531 S = new (Context) CXXTypeidExpr(Empty, false);
1532 break;
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001533 case pch::EXPR_CXX_THIS:
1534 S = new (Context) CXXThisExpr(Empty);
1535 break;
1536 case pch::EXPR_CXX_THROW:
1537 S = new (Context) CXXThrowExpr(Empty);
1538 break;
Chris Lattner030854b2010-05-09 06:40:08 +00001539 case pch::EXPR_CXX_DEFAULT_ARG:
1540 S = new (Context) CXXDefaultArgExpr(Empty);
1541 break;
Chris Lattnerd2598362010-05-10 00:25:06 +00001542 case pch::EXPR_CXX_BIND_TEMPORARY:
1543 S = new (Context) CXXBindTemporaryExpr(Empty);
1544 break;
Chris Lattner59218632010-05-10 01:22:27 +00001545
1546 case pch::EXPR_CXX_ZERO_INIT_VALUE:
1547 S = new (Context) CXXZeroInitValueExpr(Empty);
1548 break;
1549 case pch::EXPR_CXX_NEW:
1550 S = new (Context) CXXNewExpr(Empty);
1551 break;
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001552 case pch::EXPR_CXX_DELETE:
1553 S = new (Context) CXXDeleteExpr(Empty);
1554 break;
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001555 case pch::EXPR_CXX_PSEUDO_DESTRUCTOR:
1556 S = new (Context) CXXPseudoDestructorExpr(Empty);
1557 break;
Chris Lattner59218632010-05-10 01:22:27 +00001558
Chris Lattnerd2598362010-05-10 00:25:06 +00001559 case pch::EXPR_CXX_EXPR_WITH_TEMPORARIES:
1560 S = new (Context) CXXExprWithTemporaries(Empty);
1561 break;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001562
1563 case pch::EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
1564 S = CXXDependentScopeMemberExpr::CreateEmpty(*Context,
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001565 /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001566 break;
1567
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001568 case pch::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
1569 S = DependentScopeDeclRefExpr::CreateEmpty(*Context,
1570 /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]);
1571 break;
1572
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001573 case pch::EXPR_CXX_UNRESOLVED_CONSTRUCT:
1574 S = CXXUnresolvedConstructExpr::CreateEmpty(*Context,
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001575 /*NumArgs=*/Record[PCHStmtReader::NumExprFields]);
1576 break;
1577
1578 case pch::EXPR_CXX_UNRESOLVED_MEMBER:
1579 S = UnresolvedMemberExpr::CreateEmpty(*Context,
1580 /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001581 break;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001582
1583 case pch::EXPR_CXX_UNRESOLVED_LOOKUP:
1584 S = UnresolvedLookupExpr::CreateEmpty(*Context,
1585 /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]);
1586 break;
Chris Lattner4c6f9522009-04-27 05:14:47 +00001587 }
1588
1589 // We hit a STMT_STOP, so we're done with this expression.
1590 if (Finished)
1591 break;
1592
1593 ++NumStatementsRead;
1594
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001595 if (S)
1596 Reader.Visit(S);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001597
1598 assert(Idx == Record.size() && "Invalid deserialization of statement");
1599 StmtStack.push_back(S);
1600 }
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001601
1602#ifndef NDEBUG
1603 assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!");
1604 assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
1605#endif
1606
1607 return StmtStack.pop_back_val();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001608}