blob: 7a3c589c21158c9823f64fefb1bf41085ddf5b4d [file] [log] [blame]
Sebastian Redl904c9c82010-08-18 23:57:11 +00001//===--- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------*- C++ -*-===//
Chris Lattner4c6f9522009-04-27 05:14:47 +00002//
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
Sebastian Redlc43b54c2010-08-18 23:56:43 +000011// ASTReader::ReadStmt method.
Chris Lattner4c6f9522009-04-27 05:14:47 +000012//
13//===----------------------------------------------------------------------===//
14
Sebastian Redl6ab7cd82010-08-18 23:57:17 +000015#include "clang/Serialization/ASTReader.h"
Douglas Gregor39da0b82009-09-09 23:08:42 +000016#include "clang/AST/DeclCXX.h"
Douglas Gregorc7793c72011-01-15 01:15:58 +000017#include "clang/AST/DeclTemplate.h"
Chris Lattner4c6f9522009-04-27 05:14:47 +000018#include "clang/AST/StmtVisitor.h"
19using namespace clang;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000020using namespace clang::serialization;
Chris Lattner4c6f9522009-04-27 05:14:47 +000021
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +000022namespace clang {
Argyrios Kyrtzidis17cfded2010-06-28 09:31:42 +000023
Sebastian Redl60adf4a2010-08-18 23:56:52 +000024 class ASTStmtReader : public StmtVisitor<ASTStmtReader> {
Douglas Gregor409448c2011-07-21 22:35:25 +000025 typedef ASTReader::RecordData RecordData;
26
Sebastian Redlc43b54c2010-08-18 23:56:43 +000027 ASTReader &Reader;
Douglas Gregor72a9ae12011-07-22 16:00:58 +000028 Module &F;
Sebastian Redl577d4792010-07-22 22:43:28 +000029 llvm::BitstreamCursor &DeclsCursor;
Sebastian Redlc43b54c2010-08-18 23:56:43 +000030 const ASTReader::RecordData &Record;
Chris Lattner4c6f9522009-04-27 05:14:47 +000031 unsigned &Idx;
Chris Lattner4c6f9522009-04-27 05:14:47 +000032
Douglas Gregor409448c2011-07-21 22:35:25 +000033 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000034 return Reader.ReadSourceLocation(F, R, I);
35 }
Douglas Gregor409448c2011-07-21 22:35:25 +000036
37 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000038 return Reader.ReadSourceRange(F, R, I);
39 }
Douglas Gregor409448c2011-07-21 22:35:25 +000040
41 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000042 return Reader.GetTypeSourceInfo(F, R, I);
43 }
Douglas Gregor409448c2011-07-21 22:35:25 +000044
45 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
46 return Reader.ReadDeclID(F, R, I);
47 }
48
49 Decl *ReadDecl(const RecordData &R, unsigned &I) {
50 return Reader.ReadDecl(F, R, I);
51 }
52
53 template<typename T>
54 T *ReadDeclAs(const RecordData &R, unsigned &I) {
55 return Reader.ReadDeclAs<T>(F, R, I);
56 }
57
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000058 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
59 const ASTReader::RecordData &R, unsigned &I) {
60 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
61 }
Douglas Gregor409448c2011-07-21 22:35:25 +000062
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000063 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
64 const ASTReader::RecordData &R, unsigned &I) {
65 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
66 }
Sebastian Redlc3632732010-10-05 15:59:54 +000067
Chris Lattner4c6f9522009-04-27 05:14:47 +000068 public:
Douglas Gregor72a9ae12011-07-22 16:00:58 +000069 ASTStmtReader(ASTReader &Reader, Module &F,
Sebastian Redlc3632732010-10-05 15:59:54 +000070 llvm::BitstreamCursor &Cursor,
Sebastian Redlc43b54c2010-08-18 23:56:43 +000071 const ASTReader::RecordData &Record, unsigned &Idx)
Sebastian Redlc3632732010-10-05 15:59:54 +000072 : Reader(Reader), F(F), DeclsCursor(Cursor), Record(Record), Idx(Idx) { }
Chris Lattner4c6f9522009-04-27 05:14:47 +000073
74 /// \brief The number of record fields required for the Stmt class
75 /// itself.
76 static const unsigned NumStmtFields = 0;
77
78 /// \brief The number of record fields required for the Expr class
79 /// itself.
Douglas Gregor561f8122011-07-01 01:22:09 +000080 static const unsigned NumExprFields = NumStmtFields + 7;
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +000081
82 /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +000083 void ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
84 unsigned NumTemplateArgs);
Chris Lattner4c6f9522009-04-27 05:14:47 +000085
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +000086 void VisitStmt(Stmt *S);
John McCall7110fd62011-07-15 07:00:14 +000087#define STMT(Type, Base) \
88 void Visit##Type(Type *);
89#include "clang/AST/StmtNodes.inc"
Chris Lattner4c6f9522009-04-27 05:14:47 +000090 };
91}
92
Sebastian Redl60adf4a2010-08-18 23:56:52 +000093void ASTStmtReader::
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +000094ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +000095 unsigned NumTemplateArgs) {
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +000096 TemplateArgumentListInfo ArgInfo;
Sebastian Redlc3632732010-10-05 15:59:54 +000097 ArgInfo.setLAngleLoc(ReadSourceLocation(Record, Idx));
98 ArgInfo.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +000099 for (unsigned i = 0; i != NumTemplateArgs; ++i)
Sebastian Redl577d4792010-07-22 22:43:28 +0000100 ArgInfo.addArgument(
Sebastian Redlc3632732010-10-05 15:59:54 +0000101 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +0000102 ArgList.initializeFrom(ArgInfo);
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +0000103}
104
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000105void ASTStmtReader::VisitStmt(Stmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000106 assert(Idx == NumStmtFields && "Incorrect statement field count");
Chris Lattner4c6f9522009-04-27 05:14:47 +0000107}
108
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000109void ASTStmtReader::VisitNullStmt(NullStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000110 VisitStmt(S);
Sebastian Redlc3632732010-10-05 15:59:54 +0000111 S->setSemiLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisb7d98d32011-04-27 05:04:02 +0000112 S->LeadingEmptyMacro = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000113}
114
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000115void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000116 VisitStmt(S);
Chris Lattner5f9e2722011-07-23 10:55:15 +0000117 SmallVector<Stmt *, 16> Stmts;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000118 unsigned NumStmts = Record[Idx++];
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000119 while (NumStmts--)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000120 Stmts.push_back(Reader.ReadSubStmt());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000121 S->setStmts(*Reader.getContext(), Stmts.data(), Stmts.size());
Sebastian Redlc3632732010-10-05 15:59:54 +0000122 S->setLBracLoc(ReadSourceLocation(Record, Idx));
123 S->setRBracLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000124}
125
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000126void ASTStmtReader::VisitSwitchCase(SwitchCase *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000127 VisitStmt(S);
128 Reader.RecordSwitchCaseID(S, Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000129}
130
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000131void ASTStmtReader::VisitCaseStmt(CaseStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000132 VisitSwitchCase(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000133 S->setLHS(Reader.ReadSubExpr());
134 S->setRHS(Reader.ReadSubExpr());
135 S->setSubStmt(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000136 S->setCaseLoc(ReadSourceLocation(Record, Idx));
137 S->setEllipsisLoc(ReadSourceLocation(Record, Idx));
138 S->setColonLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000139}
140
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000141void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000142 VisitSwitchCase(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000143 S->setSubStmt(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000144 S->setDefaultLoc(ReadSourceLocation(Record, Idx));
145 S->setColonLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000146}
147
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000148void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000149 VisitStmt(S);
Douglas Gregor409448c2011-07-21 22:35:25 +0000150 LabelDecl *LD = ReadDeclAs<LabelDecl>(Record, Idx);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000151 LD->setStmt(S);
152 S->setDecl(LD);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000153 S->setSubStmt(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000154 S->setIdentLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000155}
156
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000157void ASTStmtReader::VisitIfStmt(IfStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000158 VisitStmt(S);
Douglas Gregor409448c2011-07-21 22:35:25 +0000159 S->setConditionVariable(*Reader.getContext(),
160 ReadDeclAs<VarDecl>(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000161 S->setCond(Reader.ReadSubExpr());
162 S->setThen(Reader.ReadSubStmt());
163 S->setElse(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000164 S->setIfLoc(ReadSourceLocation(Record, Idx));
165 S->setElseLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000166}
167
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000168void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000169 VisitStmt(S);
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000170 S->setConditionVariable(*Reader.getContext(),
Douglas Gregor409448c2011-07-21 22:35:25 +0000171 ReadDeclAs<VarDecl>(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000172 S->setCond(Reader.ReadSubExpr());
173 S->setBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000174 S->setSwitchLoc(ReadSourceLocation(Record, Idx));
Ted Kremenek559fb552010-09-09 00:05:53 +0000175 if (Record[Idx++])
176 S->setAllEnumCasesCovered();
177
Chris Lattner4c6f9522009-04-27 05:14:47 +0000178 SwitchCase *PrevSC = 0;
179 for (unsigned N = Record.size(); Idx != N; ++Idx) {
180 SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]);
181 if (PrevSC)
182 PrevSC->setNextSwitchCase(SC);
183 else
184 S->setSwitchCaseList(SC);
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Chris Lattner4c6f9522009-04-27 05:14:47 +0000186 PrevSC = SC;
187 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000188}
189
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000190void ASTStmtReader::VisitWhileStmt(WhileStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000191 VisitStmt(S);
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000192 S->setConditionVariable(*Reader.getContext(),
Douglas Gregor409448c2011-07-21 22:35:25 +0000193 ReadDeclAs<VarDecl>(Record, Idx));
194
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000195 S->setCond(Reader.ReadSubExpr());
196 S->setBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000197 S->setWhileLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000198}
199
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000200void ASTStmtReader::VisitDoStmt(DoStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000201 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000202 S->setCond(Reader.ReadSubExpr());
203 S->setBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000204 S->setDoLoc(ReadSourceLocation(Record, Idx));
205 S->setWhileLoc(ReadSourceLocation(Record, Idx));
206 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000207}
208
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000209void ASTStmtReader::VisitForStmt(ForStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000210 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000211 S->setInit(Reader.ReadSubStmt());
212 S->setCond(Reader.ReadSubExpr());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000213 S->setConditionVariable(*Reader.getContext(),
Douglas Gregor409448c2011-07-21 22:35:25 +0000214 ReadDeclAs<VarDecl>(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000215 S->setInc(Reader.ReadSubExpr());
216 S->setBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000217 S->setForLoc(ReadSourceLocation(Record, Idx));
218 S->setLParenLoc(ReadSourceLocation(Record, Idx));
219 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000220}
221
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000222void ASTStmtReader::VisitGotoStmt(GotoStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000223 VisitStmt(S);
Douglas Gregor409448c2011-07-21 22:35:25 +0000224 S->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000225 S->setGotoLoc(ReadSourceLocation(Record, Idx));
226 S->setLabelLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000227}
228
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000229void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000230 VisitStmt(S);
Sebastian Redlc3632732010-10-05 15:59:54 +0000231 S->setGotoLoc(ReadSourceLocation(Record, Idx));
232 S->setStarLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000233 S->setTarget(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000234}
235
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000236void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000237 VisitStmt(S);
Sebastian Redlc3632732010-10-05 15:59:54 +0000238 S->setContinueLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000239}
240
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000241void ASTStmtReader::VisitBreakStmt(BreakStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000242 VisitStmt(S);
Sebastian Redlc3632732010-10-05 15:59:54 +0000243 S->setBreakLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000244}
245
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000246void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000247 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000248 S->setRetValue(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000249 S->setReturnLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000250 S->setNRVOCandidate(ReadDeclAs<VarDecl>(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000251}
252
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000253void ASTStmtReader::VisitDeclStmt(DeclStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000254 VisitStmt(S);
Sebastian Redlc3632732010-10-05 15:59:54 +0000255 S->setStartLoc(ReadSourceLocation(Record, Idx));
256 S->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000257
258 if (Idx + 1 == Record.size()) {
259 // Single declaration
Douglas Gregor409448c2011-07-21 22:35:25 +0000260 S->setDeclGroup(DeclGroupRef(ReadDecl(Record, Idx)));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000261 } else {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000262 SmallVector<Decl *, 16> Decls;
Douglas Gregor409448c2011-07-21 22:35:25 +0000263 Decls.reserve(Record.size() - Idx);
264 for (unsigned N = Record.size(); Idx != N; )
265 Decls.push_back(ReadDecl(Record, Idx));
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000266 S->setDeclGroup(DeclGroupRef(DeclGroup::Create(*Reader.getContext(),
Douglas Gregor75fdb232009-05-22 22:45:36 +0000267 Decls.data(),
268 Decls.size())));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000269 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000270}
271
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000272void ASTStmtReader::VisitAsmStmt(AsmStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000273 VisitStmt(S);
274 unsigned NumOutputs = Record[Idx++];
275 unsigned NumInputs = Record[Idx++];
276 unsigned NumClobbers = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000277 S->setAsmLoc(ReadSourceLocation(Record, Idx));
278 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000279 S->setVolatile(Record[Idx++]);
280 S->setSimple(Record[Idx++]);
Mike Stump3b11fd32010-01-04 22:37:17 +0000281 S->setMSAsm(Record[Idx++]);
Mike Stump1eb44332009-09-09 15:08:12 +0000282
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000283 S->setAsmString(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000284
285 // Outputs and inputs
Chris Lattner5f9e2722011-07-23 10:55:15 +0000286 SmallVector<IdentifierInfo *, 16> Names;
287 SmallVector<StringLiteral*, 16> Constraints;
288 SmallVector<Stmt*, 16> Exprs;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000289 for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000290 Names.push_back(Reader.GetIdentifierInfo(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000291 Constraints.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
292 Exprs.push_back(Reader.ReadSubStmt());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000293 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000294
295 // Constraints
Chris Lattner5f9e2722011-07-23 10:55:15 +0000296 SmallVector<StringLiteral*, 16> Clobbers;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000297 for (unsigned I = 0; I != NumClobbers; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000298 Clobbers.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000299
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000300 S->setOutputsAndInputsAndClobbers(*Reader.getContext(),
301 Names.data(), Constraints.data(),
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000302 Exprs.data(), NumOutputs, NumInputs,
303 Clobbers.data(), NumClobbers);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000304}
305
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000306void ASTStmtReader::VisitExpr(Expr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000307 VisitStmt(E);
Douglas Gregor393f2492011-07-22 00:38:23 +0000308 E->setType(Reader.readType(F, Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000309 E->setTypeDependent(Record[Idx++]);
310 E->setValueDependent(Record[Idx++]);
Douglas Gregor561f8122011-07-01 01:22:09 +0000311 E->setInstantiationDependent(Record[Idx++]);
Douglas Gregord0937222010-12-13 22:49:22 +0000312 E->ExprBits.ContainsUnexpandedParameterPack = Record[Idx++];
John McCallf89e55a2010-11-18 06:31:45 +0000313 E->setValueKind(static_cast<ExprValueKind>(Record[Idx++]));
314 E->setObjectKind(static_cast<ExprObjectKind>(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000315 assert(Idx == NumExprFields && "Incorrect expression field count");
Chris Lattner4c6f9522009-04-27 05:14:47 +0000316}
317
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000318void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000319 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000320 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000321 E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000322}
323
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000324void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000325 VisitExpr(E);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000326
Chandler Carruthcb66cff2011-05-01 21:29:53 +0000327 E->DeclRefExprBits.HasQualifier = Record[Idx++];
Chandler Carruth3aa81402011-05-01 23:48:14 +0000328 E->DeclRefExprBits.HasFoundDecl = Record[Idx++];
Chandler Carruthcb66cff2011-05-01 21:29:53 +0000329 E->DeclRefExprBits.HasExplicitTemplateArgs = Record[Idx++];
Anders Carlssonb0ca1372011-03-06 18:19:42 +0000330 unsigned NumTemplateArgs = 0;
Chandler Carruthcb66cff2011-05-01 21:29:53 +0000331 if (E->hasExplicitTemplateArgs())
Anders Carlssonb0ca1372011-03-06 18:19:42 +0000332 NumTemplateArgs = Record[Idx++];
333
Chandler Carruthcb66cff2011-05-01 21:29:53 +0000334 if (E->hasQualifier())
Chandler Carruth6857c3e2011-05-01 22:14:37 +0000335 E->getInternalQualifierLoc()
Douglas Gregor40d96a62011-02-28 21:54:11 +0000336 = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000337
Chandler Carruth3aa81402011-05-01 23:48:14 +0000338 if (E->hasFoundDecl())
Douglas Gregor409448c2011-07-21 22:35:25 +0000339 E->getInternalFoundDecl() = ReadDeclAs<NamedDecl>(Record, Idx);
Chandler Carruth3aa81402011-05-01 23:48:14 +0000340
Chandler Carruthcb66cff2011-05-01 21:29:53 +0000341 if (E->hasExplicitTemplateArgs())
John McCall096832c2010-08-19 23:49:38 +0000342 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000343 NumTemplateArgs);
344
Douglas Gregor409448c2011-07-21 22:35:25 +0000345 E->setDecl(ReadDeclAs<ValueDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000346 E->setLocation(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000347 ReadDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000348}
349
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000350void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000351 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000352 E->setLocation(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +0000353 E->setValue(*Reader.getContext(), Reader.ReadAPInt(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000354}
355
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000356void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000357 VisitExpr(E);
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +0000358 E->setValue(*Reader.getContext(), Reader.ReadAPFloat(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000359 E->setExact(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000360 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000361}
362
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000363void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000364 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000365 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000366}
367
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000368void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000369 VisitExpr(E);
370 unsigned Len = Record[Idx++];
Mike Stump1eb44332009-09-09 15:08:12 +0000371 assert(Record[Idx] == E->getNumConcatenated() &&
Chris Lattner4c6f9522009-04-27 05:14:47 +0000372 "Wrong number of concatenated tokens!");
373 ++Idx;
Douglas Gregor5cee1192011-07-27 05:40:30 +0000374 E->Kind = static_cast<StringLiteral::StringKind>(Record[Idx++]);
Anders Carlsson3e2193c2011-04-14 00:40:03 +0000375 E->IsPascal = Record[Idx++];
Chris Lattner4c6f9522009-04-27 05:14:47 +0000376
Mike Stump1eb44332009-09-09 15:08:12 +0000377 // Read string data
Daniel Dunbarb6480232009-09-22 03:27:33 +0000378 llvm::SmallString<16> Str(&Record[Idx], &Record[Idx] + Len);
379 E->setString(*Reader.getContext(), Str.str());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000380 Idx += Len;
381
382 // Read source locations
383 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000384 E->setStrTokenLoc(I, ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000385}
386
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000387void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000388 VisitExpr(E);
389 E->setValue(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000390 E->setLocation(ReadSourceLocation(Record, Idx));
Douglas Gregor5cee1192011-07-27 05:40:30 +0000391 E->setKind(static_cast<CharacterLiteral::CharacterKind>(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000392}
393
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000394void ASTStmtReader::VisitParenExpr(ParenExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000395 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000396 E->setLParen(ReadSourceLocation(Record, Idx));
397 E->setRParen(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000398 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000399}
400
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000401void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +0000402 VisitExpr(E);
403 unsigned NumExprs = Record[Idx++];
404 E->Exprs = new (*Reader.getContext()) Stmt*[NumExprs];
405 for (unsigned i = 0; i != NumExprs; ++i)
406 E->Exprs[i] = Reader.ReadSubStmt();
407 E->NumExprs = NumExprs;
Sebastian Redlc3632732010-10-05 15:59:54 +0000408 E->LParenLoc = ReadSourceLocation(Record, Idx);
409 E->RParenLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +0000410}
411
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000412void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000413 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000414 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000415 E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000416 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000417}
418
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000419void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000420 typedef OffsetOfExpr::OffsetOfNode Node;
421 VisitExpr(E);
422 assert(E->getNumComponents() == Record[Idx]);
423 ++Idx;
424 assert(E->getNumExpressions() == Record[Idx]);
425 ++Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +0000426 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
427 E->setRParenLoc(ReadSourceLocation(Record, Idx));
428 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000429 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
430 Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000431 SourceLocation Start = ReadSourceLocation(Record, Idx);
432 SourceLocation End = ReadSourceLocation(Record, Idx);
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000433 switch (Kind) {
434 case Node::Array:
435 E->setComponent(I, Node(Start, Record[Idx++], End));
436 break;
437
438 case Node::Field:
Douglas Gregor409448c2011-07-21 22:35:25 +0000439 E->setComponent(I, Node(Start, ReadDeclAs<FieldDecl>(Record, Idx), End));
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000440 break;
441
442 case Node::Identifier:
443 E->setComponent(I, Node(Start, Reader.GetIdentifier(Record[Idx++]), End));
444 break;
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000445
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000446 case Node::Base: {
447 CXXBaseSpecifier *Base = new (*Reader.getContext()) CXXBaseSpecifier();
Sebastian Redlc3632732010-10-05 15:59:54 +0000448 *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000449 E->setComponent(I, Node(Base));
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000450 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000451 }
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000452 }
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000453 }
454
455 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000456 E->setIndexExpr(I, Reader.ReadSubExpr());
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000457}
458
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000459void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000460 VisitExpr(E);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000461 E->setKind(static_cast<UnaryExprOrTypeTrait>(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000462 if (Record[Idx] == 0) {
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000463 E->setArgument(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000464 ++Idx;
465 } else {
Sebastian Redlc3632732010-10-05 15:59:54 +0000466 E->setArgument(GetTypeSourceInfo(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000467 }
Sebastian Redlc3632732010-10-05 15:59:54 +0000468 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
469 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000470}
471
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000472void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000473 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000474 E->setLHS(Reader.ReadSubExpr());
475 E->setRHS(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000476 E->setRBracketLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000477}
478
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000479void ASTStmtReader::VisitCallExpr(CallExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000480 VisitExpr(E);
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000481 E->setNumArgs(*Reader.getContext(), Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000482 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000483 E->setCallee(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000484 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000485 E->setArg(I, Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000486}
487
John McCall7110fd62011-07-15 07:00:14 +0000488void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
489 VisitCallExpr(E);
490}
491
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000492void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000493 // Don't call VisitExpr, this is fully initialized at creation.
494 assert(E->getStmtClass() == Stmt::MemberExprClass &&
495 "It's a subclass, we must advance Idx!");
Chris Lattner4c6f9522009-04-27 05:14:47 +0000496}
497
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000498void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Narofff242b1b2009-07-24 17:54:45 +0000499 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000500 E->setBase(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000501 E->setIsaMemberLoc(ReadSourceLocation(Record, Idx));
Steve Narofff242b1b2009-07-24 17:54:45 +0000502 E->setArrow(Record[Idx++]);
Steve Narofff242b1b2009-07-24 17:54:45 +0000503}
504
John McCallf85e1932011-06-15 23:02:42 +0000505void ASTStmtReader::
506VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
507 VisitExpr(E);
508 E->Operand = Reader.ReadSubExpr();
509 E->setShouldCopy(Record[Idx++]);
510}
511
512void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
513 VisitExplicitCastExpr(E);
514 E->LParenLoc = ReadSourceLocation(Record, Idx);
515 E->BridgeKeywordLoc = ReadSourceLocation(Record, Idx);
516 E->Kind = Record[Idx++];
517}
518
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000519void ASTStmtReader::VisitCastExpr(CastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000520 VisitExpr(E);
John McCallf871d0c2010-08-07 06:22:56 +0000521 unsigned NumBaseSpecs = Record[Idx++];
522 assert(NumBaseSpecs == E->path_size());
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000523 E->setSubExpr(Reader.ReadSubExpr());
Anders Carlssoncdef2b72009-07-31 00:48:10 +0000524 E->setCastKind((CastExpr::CastKind)Record[Idx++]);
John McCallf871d0c2010-08-07 06:22:56 +0000525 CastExpr::path_iterator BaseI = E->path_begin();
Argyrios Kyrtzidis0745d0a2010-07-02 23:30:27 +0000526 while (NumBaseSpecs--) {
Argyrios Kyrtzidis0745d0a2010-07-02 23:30:27 +0000527 CXXBaseSpecifier *BaseSpec = new (*Reader.getContext()) CXXBaseSpecifier;
Sebastian Redlc3632732010-10-05 15:59:54 +0000528 *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
John McCallf871d0c2010-08-07 06:22:56 +0000529 *BaseI++ = BaseSpec;
Argyrios Kyrtzidis0745d0a2010-07-02 23:30:27 +0000530 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000531}
532
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000533void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000534 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000535 E->setLHS(Reader.ReadSubExpr());
536 E->setRHS(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000537 E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000538 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000539}
540
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000541void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000542 VisitBinaryOperator(E);
Douglas Gregor393f2492011-07-22 00:38:23 +0000543 E->setComputationLHSType(Reader.readType(F, Record, Idx));
544 E->setComputationResultType(Reader.readType(F, Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000545}
546
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000547void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000548 VisitExpr(E);
John McCall56ca35d2011-02-17 10:25:35 +0000549 E->SubExprs[ConditionalOperator::COND] = Reader.ReadSubExpr();
550 E->SubExprs[ConditionalOperator::LHS] = Reader.ReadSubExpr();
551 E->SubExprs[ConditionalOperator::RHS] = Reader.ReadSubExpr();
552 E->QuestionLoc = ReadSourceLocation(Record, Idx);
553 E->ColonLoc = ReadSourceLocation(Record, Idx);
554}
555
556void
557ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
558 VisitExpr(E);
559 E->OpaqueValue = cast<OpaqueValueExpr>(Reader.ReadSubExpr());
560 E->SubExprs[BinaryConditionalOperator::COMMON] = Reader.ReadSubExpr();
561 E->SubExprs[BinaryConditionalOperator::COND] = Reader.ReadSubExpr();
562 E->SubExprs[BinaryConditionalOperator::LHS] = Reader.ReadSubExpr();
563 E->SubExprs[BinaryConditionalOperator::RHS] = Reader.ReadSubExpr();
564 E->QuestionLoc = ReadSourceLocation(Record, Idx);
565 E->ColonLoc = ReadSourceLocation(Record, Idx);
566
567 E->getOpaqueValue()->setSourceExpr(E->getCommon());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000568}
569
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000570void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000571 VisitCastExpr(E);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000572}
573
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000574void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000575 VisitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000576 E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000577}
578
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000579void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000580 VisitExplicitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000581 E->setLParenLoc(ReadSourceLocation(Record, Idx));
582 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000583}
584
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000585void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000586 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000587 E->setLParenLoc(ReadSourceLocation(Record, Idx));
588 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000589 E->setInitializer(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000590 E->setFileScope(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000591}
592
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000593void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000594 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000595 E->setBase(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000596 E->setAccessor(Reader.GetIdentifierInfo(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000597 E->setAccessorLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000598}
599
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000600void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000601 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000602 E->setSyntacticForm(cast_or_null<InitListExpr>(Reader.ReadSubStmt()));
Sebastian Redlc3632732010-10-05 15:59:54 +0000603 E->setLBraceLoc(ReadSourceLocation(Record, Idx));
604 E->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000605 bool isArrayFiller = Record[Idx++];
606 Expr *filler = 0;
607 if (isArrayFiller) {
608 filler = Reader.ReadSubExpr();
609 E->ArrayFillerOrUnionFieldInit = filler;
610 } else
Douglas Gregor409448c2011-07-21 22:35:25 +0000611 E->ArrayFillerOrUnionFieldInit = ReadDeclAs<FieldDecl>(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000612 E->sawArrayRangeDesignator(Record[Idx++]);
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000613 unsigned NumInits = Record[Idx++];
614 E->reserveInits(*Reader.getContext(), NumInits);
615 if (isArrayFiller) {
616 for (unsigned I = 0; I != NumInits; ++I) {
617 Expr *init = Reader.ReadSubExpr();
618 E->updateInit(*Reader.getContext(), I, init ? init : filler);
619 }
620 } else {
621 for (unsigned I = 0; I != NumInits; ++I)
622 E->updateInit(*Reader.getContext(), I, Reader.ReadSubExpr());
623 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000624}
625
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000626void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000627 typedef DesignatedInitExpr::Designator Designator;
628
629 VisitExpr(E);
630 unsigned NumSubExprs = Record[Idx++];
631 assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
632 for (unsigned I = 0; I != NumSubExprs; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000633 E->setSubExpr(I, Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000634 E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000635 E->setGNUSyntax(Record[Idx++]);
636
Chris Lattner5f9e2722011-07-23 10:55:15 +0000637 SmallVector<Designator, 4> Designators;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000638 while (Idx < Record.size()) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000639 switch ((DesignatorTypes)Record[Idx++]) {
640 case DESIG_FIELD_DECL: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000641 FieldDecl *Field = ReadDeclAs<FieldDecl>(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000642 SourceLocation DotLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000643 = ReadSourceLocation(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000644 SourceLocation FieldLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000645 = ReadSourceLocation(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000646 Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
Chris Lattner4c6f9522009-04-27 05:14:47 +0000647 FieldLoc));
648 Designators.back().setField(Field);
649 break;
650 }
651
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000652 case DESIG_FIELD_NAME: {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000653 const IdentifierInfo *Name = Reader.GetIdentifierInfo(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000654 SourceLocation DotLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000655 = ReadSourceLocation(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000656 SourceLocation FieldLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000657 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000658 Designators.push_back(Designator(Name, DotLoc, FieldLoc));
659 break;
660 }
Mike Stump1eb44332009-09-09 15:08:12 +0000661
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000662 case DESIG_ARRAY: {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000663 unsigned Index = Record[Idx++];
664 SourceLocation LBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000665 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000666 SourceLocation RBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000667 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000668 Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
669 break;
670 }
671
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000672 case DESIG_ARRAY_RANGE: {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000673 unsigned Index = Record[Idx++];
674 SourceLocation LBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000675 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000676 SourceLocation EllipsisLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000677 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000678 SourceLocation RBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000679 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000680 Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
681 RBracketLoc));
682 break;
683 }
684 }
685 }
Douglas Gregor319d57f2010-01-06 23:17:19 +0000686 E->setDesignators(*Reader.getContext(),
687 Designators.data(), Designators.size());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000688}
689
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000690void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000691 VisitExpr(E);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000692}
693
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000694void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000695 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000696 E->setSubExpr(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000697 E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx));
698 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
699 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000700}
701
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000702void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000703 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000704 E->setAmpAmpLoc(ReadSourceLocation(Record, Idx));
705 E->setLabelLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000706 E->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000707}
708
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000709void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000710 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000711 E->setLParenLoc(ReadSourceLocation(Record, Idx));
712 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000713 E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt()));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000714}
715
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000716void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000717 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000718 E->setCond(Reader.ReadSubExpr());
719 E->setLHS(Reader.ReadSubExpr());
720 E->setRHS(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000721 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
722 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000723}
724
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000725void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000726 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000727 E->setTokenLocation(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000728}
729
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000730void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000731 VisitExpr(E);
Chris Lattner5f9e2722011-07-23 10:55:15 +0000732 SmallVector<Expr *, 16> Exprs;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000733 unsigned NumExprs = Record[Idx++];
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000734 while (NumExprs--)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000735 Exprs.push_back(Reader.ReadSubExpr());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000736 E->setExprs(*Reader.getContext(), Exprs.data(), Exprs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +0000737 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
738 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000739}
740
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000741void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000742 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000743 E->setBlockDecl(ReadDeclAs<BlockDecl>(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000744}
745
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000746void ASTStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000747 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000748 E->setDecl(ReadDeclAs<VarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000749 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000750 E->setByRef(Record[Idx++]);
Fariborz Jahanian9b0b57c2009-06-20 00:02:26 +0000751 E->setConstQualAdded(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000752}
753
Peter Collingbournef111d932011-04-15 00:35:48 +0000754void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
755 VisitExpr(E);
756 E->NumAssocs = Record[Idx++];
757 E->AssocTypes = new (*Reader.getContext()) TypeSourceInfo*[E->NumAssocs];
758 E->SubExprs =
759 new(*Reader.getContext()) Stmt*[GenericSelectionExpr::END_EXPR+E->NumAssocs];
760
761 E->SubExprs[GenericSelectionExpr::CONTROLLING] = Reader.ReadSubExpr();
762 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
763 E->AssocTypes[I] = GetTypeSourceInfo(Record, Idx);
764 E->SubExprs[GenericSelectionExpr::END_EXPR+I] = Reader.ReadSubExpr();
765 }
766 E->ResultIndex = Record[Idx++];
767
768 E->GenericLoc = ReadSourceLocation(Record, Idx);
769 E->DefaultLoc = ReadSourceLocation(Record, Idx);
770 E->RParenLoc = ReadSourceLocation(Record, Idx);
771}
772
Chris Lattner4c6f9522009-04-27 05:14:47 +0000773//===----------------------------------------------------------------------===//
774// Objective-C Expressions and Statements
775
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000776void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000777 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000778 E->setString(cast<StringLiteral>(Reader.ReadSubStmt()));
Sebastian Redlc3632732010-10-05 15:59:54 +0000779 E->setAtLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000780}
781
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000782void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000783 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000784 E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
785 E->setAtLoc(ReadSourceLocation(Record, Idx));
786 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000787}
788
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000789void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000790 VisitExpr(E);
791 E->setSelector(Reader.GetSelector(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000792 E->setAtLoc(ReadSourceLocation(Record, Idx));
793 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000794}
795
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000796void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000797 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000798 E->setProtocol(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000799 E->setAtLoc(ReadSourceLocation(Record, Idx));
800 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000801}
802
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000803void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000804 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000805 E->setDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000806 E->setLocation(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000807 E->setBase(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000808 E->setIsArrow(Record[Idx++]);
809 E->setIsFreeIvar(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000810}
811
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000812void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000813 VisitExpr(E);
John McCall12f78a62010-12-02 01:19:52 +0000814 bool Implicit = Record[Idx++] != 0;
815 if (Implicit) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000816 ObjCMethodDecl *Getter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
817 ObjCMethodDecl *Setter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
John McCall12f78a62010-12-02 01:19:52 +0000818 E->setImplicitProperty(Getter, Setter);
819 } else {
Douglas Gregor409448c2011-07-21 22:35:25 +0000820 E->setExplicitProperty(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000821 }
Sebastian Redlc3632732010-10-05 15:59:54 +0000822 E->setLocation(ReadSourceLocation(Record, Idx));
John McCall12f78a62010-12-02 01:19:52 +0000823 E->setReceiverLocation(ReadSourceLocation(Record, Idx));
824 switch (Record[Idx++]) {
825 case 0:
826 E->setBase(Reader.ReadSubExpr());
827 break;
828 case 1:
Douglas Gregor393f2492011-07-22 00:38:23 +0000829 E->setSuperReceiver(Reader.readType(F, Record, Idx));
John McCall12f78a62010-12-02 01:19:52 +0000830 break;
831 case 2:
Douglas Gregor409448c2011-07-21 22:35:25 +0000832 E->setClassReceiver(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
John McCall12f78a62010-12-02 01:19:52 +0000833 break;
834 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000835}
836
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000837void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000838 VisitExpr(E);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000839 assert(Record[Idx] == E->getNumArgs());
840 ++Idx;
John McCallf85e1932011-06-15 23:02:42 +0000841 E->setDelegateInitCall(Record[Idx++]);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000842 ObjCMessageExpr::ReceiverKind Kind
843 = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
844 switch (Kind) {
845 case ObjCMessageExpr::Instance:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000846 E->setInstanceReceiver(Reader.ReadSubExpr());
Douglas Gregor04badcf2010-04-21 00:45:42 +0000847 break;
848
849 case ObjCMessageExpr::Class:
Sebastian Redlc3632732010-10-05 15:59:54 +0000850 E->setClassReceiver(GetTypeSourceInfo(Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000851 break;
852
853 case ObjCMessageExpr::SuperClass:
854 case ObjCMessageExpr::SuperInstance: {
Douglas Gregor393f2492011-07-22 00:38:23 +0000855 QualType T = Reader.readType(F, Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000856 SourceLocation SuperLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000857 E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
858 break;
859 }
860 }
861
862 assert(Kind == E->getReceiverKind());
863
864 if (Record[Idx++])
Douglas Gregor409448c2011-07-21 22:35:25 +0000865 E->setMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000866 else
867 E->setSelector(Reader.GetSelector(Record, Idx));
868
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +0000869 E->LBracLoc = ReadSourceLocation(Record, Idx);
870 E->RBracLoc = ReadSourceLocation(Record, Idx);
871 E->SelectorLoc = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000872
873 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000874 E->setArg(I, Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000875}
876
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000877void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000878 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000879 S->setElement(Reader.ReadSubStmt());
880 S->setCollection(Reader.ReadSubExpr());
881 S->setBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000882 S->setForLoc(ReadSourceLocation(Record, Idx));
883 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000884}
885
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000886void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000887 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000888 S->setCatchBody(Reader.ReadSubStmt());
Douglas Gregor409448c2011-07-21 22:35:25 +0000889 S->setCatchParamDecl(ReadDeclAs<VarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000890 S->setAtCatchLoc(ReadSourceLocation(Record, Idx));
891 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000892}
893
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000894void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000895 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000896 S->setFinallyBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000897 S->setAtFinallyLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000898}
899
John McCallf85e1932011-06-15 23:02:42 +0000900void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
901 VisitStmt(S);
902 S->setSubStmt(Reader.ReadSubStmt());
903 S->setAtLoc(ReadSourceLocation(Record, Idx));
904}
905
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000906void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000907 VisitStmt(S);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000908 assert(Record[Idx] == S->getNumCatchStmts());
909 ++Idx;
910 bool HasFinally = Record[Idx++];
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000911 S->setTryBody(Reader.ReadSubStmt());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000912 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000913 S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt()));
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000914
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000915 if (HasFinally)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000916 S->setFinallyStmt(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000917 S->setAtTryLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000918}
919
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000920void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000921 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000922 S->setSynchExpr(Reader.ReadSubStmt());
923 S->setSynchBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000924 S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000925}
926
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000927void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000928 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000929 S->setThrowExpr(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000930 S->setThrowLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000931}
932
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000933//===----------------------------------------------------------------------===//
934// C++ Expressions and Statements
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000935//===----------------------------------------------------------------------===//
936
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000937void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000938 VisitStmt(S);
Sebastian Redlc3632732010-10-05 15:59:54 +0000939 S->CatchLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000940 S->ExceptionDecl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000941 S->HandlerBlock = Reader.ReadSubStmt();
942}
943
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000944void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000945 VisitStmt(S);
946 assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?");
947 ++Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +0000948 S->TryLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000949 S->getStmts()[0] = Reader.ReadSubStmt();
950 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
951 S->getStmts()[i + 1] = Reader.ReadSubStmt();
952}
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000953
Richard Smithad762fc2011-04-14 22:09:26 +0000954void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
955 VisitStmt(S);
956 S->setForLoc(ReadSourceLocation(Record, Idx));
957 S->setColonLoc(ReadSourceLocation(Record, Idx));
958 S->setRParenLoc(ReadSourceLocation(Record, Idx));
959 S->setRangeStmt(Reader.ReadSubStmt());
960 S->setBeginEndStmt(Reader.ReadSubStmt());
961 S->setCond(Reader.ReadSubExpr());
962 S->setInc(Reader.ReadSubExpr());
963 S->setLoopVarStmt(Reader.ReadSubStmt());
964 S->setBody(Reader.ReadSubStmt());
965}
966
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000967void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000968 VisitCallExpr(E);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000969 E->setOperator((OverloadedOperatorKind)Record[Idx++]);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000970}
971
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000972void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor39da0b82009-09-09 23:08:42 +0000973 VisitExpr(E);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000974 E->NumArgs = Record[Idx++];
975 if (E->NumArgs)
976 E->Args = new (*Reader.getContext()) Stmt*[E->NumArgs];
Argyrios Kyrtzidis5e1b7c22010-06-24 08:57:09 +0000977 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000978 E->setArg(I, Reader.ReadSubExpr());
Douglas Gregor409448c2011-07-21 22:35:25 +0000979 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000980 E->setLocation(ReadSourceLocation(Record, Idx));
Douglas Gregor39da0b82009-09-09 23:08:42 +0000981 E->setElidable(Record[Idx++]);
Douglas Gregor16006c92009-12-16 18:50:27 +0000982 E->setRequiresZeroInitialization(Record[Idx++]);
Douglas Gregor3c9034c2010-05-15 00:13:29 +0000983 E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
Chandler Carruth428edaf2010-10-25 08:47:36 +0000984 E->ParenRange = ReadSourceRange(Record, Idx);
Douglas Gregor39da0b82009-09-09 23:08:42 +0000985}
Chris Lattner4c6f9522009-04-27 05:14:47 +0000986
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000987void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000988 VisitCXXConstructExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000989 E->Type = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000990}
991
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000992void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000993 VisitExplicitCastExpr(E);
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000994 SourceRange R = ReadSourceRange(Record, Idx);
995 E->Loc = R.getBegin();
996 E->RParenLoc = R.getEnd();
Sam Weinigce757a72010-01-16 21:21:01 +0000997}
998
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000999void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001000 return VisitCXXNamedCastExpr(E);
1001}
1002
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001003void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001004 return VisitCXXNamedCastExpr(E);
1005}
1006
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001007void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001008 return VisitCXXNamedCastExpr(E);
1009}
1010
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001011void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001012 return VisitCXXNamedCastExpr(E);
1013}
1014
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001015void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001016 VisitExplicitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001017 E->setTypeBeginLoc(ReadSourceLocation(Record, Idx));
1018 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Sam Weinigce757a72010-01-16 21:21:01 +00001019}
1020
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001021void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001022 VisitExpr(E);
1023 E->setValue(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +00001024 E->setLocation(ReadSourceLocation(Record, Idx));
Sam Weinigeb7f9612010-02-07 06:32:43 +00001025}
1026
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001027void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001028 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001029 E->setLocation(ReadSourceLocation(Record, Idx));
Sam Weinigeb7f9612010-02-07 06:32:43 +00001030}
1031
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001032void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner14ab24f2010-05-09 06:03:39 +00001033 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001034 E->setSourceRange(ReadSourceRange(Record, Idx));
Chris Lattner14ab24f2010-05-09 06:03:39 +00001035 if (E->isTypeOperand()) { // typeid(int)
Sebastian Redl577d4792010-07-22 22:43:28 +00001036 E->setTypeOperandSourceInfo(
Sebastian Redlc3632732010-10-05 15:59:54 +00001037 GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001038 return;
Chris Lattner14ab24f2010-05-09 06:03:39 +00001039 }
1040
1041 // typeid(42+2)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001042 E->setExprOperand(Reader.ReadSubExpr());
Chris Lattner14ab24f2010-05-09 06:03:39 +00001043}
1044
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001045void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001046 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001047 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001048 E->setImplicit(Record[Idx++]);
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001049}
1050
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001051void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001052 VisitExpr(E);
Douglas Gregorbca01b42011-07-06 22:04:06 +00001053 E->ThrowLoc = ReadSourceLocation(Record, Idx);
1054 E->Op = Reader.ReadSubExpr();
1055 E->IsThrownVariableInScope = Record[Idx++];
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001056}
Chris Lattner14ab24f2010-05-09 06:03:39 +00001057
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001058void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattner030854b2010-05-09 06:40:08 +00001059 VisitExpr(E);
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001060
1061 assert(Record[Idx] == E->Param.getInt() && "We messed up at creation ?");
1062 ++Idx; // HasOtherExprStored and SubExpr was handled during creation.
Douglas Gregor409448c2011-07-21 22:35:25 +00001063 E->Param.setPointer(ReadDeclAs<ParmVarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +00001064 E->Loc = ReadSourceLocation(Record, Idx);
Chris Lattnerd2598362010-05-10 00:25:06 +00001065}
1066
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001067void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001068 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001069 E->setTemporary(Reader.ReadCXXTemporary(F, Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001070 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattnerd2598362010-05-10 00:25:06 +00001071}
1072
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001073void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001074 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001075 E->TypeInfo = GetTypeSourceInfo(Record, Idx);
1076 E->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner59218632010-05-10 01:22:27 +00001077}
1078
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001079void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001080 VisitExpr(E);
John McCall6ec278d2011-01-27 09:37:56 +00001081 E->GlobalNew = Record[Idx++];
1082 E->Initializer = Record[Idx++];
1083 E->UsualArrayDeleteWantsSize = Record[Idx++];
Chris Lattner59218632010-05-10 01:22:27 +00001084 bool isArray = Record[Idx++];
1085 unsigned NumPlacementArgs = Record[Idx++];
1086 unsigned NumCtorArgs = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001087 E->setOperatorNew(ReadDeclAs<FunctionDecl>(Record, Idx));
1088 E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx));
1089 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +00001090 E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
Douglas Gregor4bd40312010-07-13 15:54:32 +00001091 SourceRange TypeIdParens;
Sebastian Redlc3632732010-10-05 15:59:54 +00001092 TypeIdParens.setBegin(ReadSourceLocation(Record, Idx));
1093 TypeIdParens.setEnd(ReadSourceLocation(Record, Idx));
Douglas Gregor4bd40312010-07-13 15:54:32 +00001094 E->TypeIdParens = TypeIdParens;
Chandler Carruth428edaf2010-10-25 08:47:36 +00001095 E->StartLoc = ReadSourceLocation(Record, Idx);
1096 E->EndLoc = ReadSourceLocation(Record, Idx);
1097 E->ConstructorLParen = ReadSourceLocation(Record, Idx);
1098 E->ConstructorRParen = ReadSourceLocation(Record, Idx);
1099
Chris Lattner59218632010-05-10 01:22:27 +00001100 E->AllocateArgsArray(*Reader.getContext(), isArray, NumPlacementArgs,
1101 NumCtorArgs);
1102
1103 // Install all the subexpressions.
Chris Lattner59218632010-05-10 01:22:27 +00001104 for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
1105 I != e; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001106 *I = Reader.ReadSubStmt();
Chris Lattner59218632010-05-10 01:22:27 +00001107}
1108
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001109void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001110 VisitExpr(E);
Argyrios Kyrtzidisf1b89112010-09-13 20:15:40 +00001111 E->GlobalDelete = Record[Idx++];
1112 E->ArrayForm = Record[Idx++];
Argyrios Kyrtzidis4076dac2010-09-13 20:15:54 +00001113 E->ArrayFormAsWritten = Record[Idx++];
John McCall6ec278d2011-01-27 09:37:56 +00001114 E->UsualArrayDeleteWantsSize = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001115 E->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf1b89112010-09-13 20:15:40 +00001116 E->Argument = Reader.ReadSubExpr();
Sebastian Redlc3632732010-10-05 15:59:54 +00001117 E->Loc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001118}
Chris Lattnerd2598362010-05-10 00:25:06 +00001119
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001120void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001121 VisitExpr(E);
1122
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001123 E->Base = Reader.ReadSubExpr();
1124 E->IsArrow = Record[Idx++];
1125 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1126 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1127 E->ScopeType = GetTypeSourceInfo(Record, Idx);
1128 E->ColonColonLoc = ReadSourceLocation(Record, Idx);
1129 E->TildeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001130
1131 IdentifierInfo *II = Reader.GetIdentifierInfo(Record, Idx);
1132 if (II)
Sebastian Redlc3632732010-10-05 15:59:54 +00001133 E->setDestroyedType(II, ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001134 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001135 E->setDestroyedType(GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001136}
1137
John McCall4765fa02010-12-06 08:20:24 +00001138void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001139 VisitExpr(E);
1140 unsigned NumTemps = Record[Idx++];
1141 if (NumTemps) {
Ted Kremenekd04ed412010-05-10 20:06:30 +00001142 E->setNumTemporaries(*Reader.getContext(), NumTemps);
Chris Lattnerd2598362010-05-10 00:25:06 +00001143 for (unsigned i = 0; i != NumTemps; ++i)
Douglas Gregor409448c2011-07-21 22:35:25 +00001144 E->setTemporary(i, Reader.ReadCXXTemporary(F, Record, Idx));
Chris Lattnerd2598362010-05-10 00:25:06 +00001145 }
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001146 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner030854b2010-05-09 06:40:08 +00001147}
1148
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001149void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001150ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001151 VisitExpr(E);
1152
Douglas Gregordef03542011-02-04 12:01:24 +00001153 if (Record[Idx++])
John McCall096832c2010-08-19 23:49:38 +00001154 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Douglas Gregordef03542011-02-04 12:01:24 +00001155 Record[Idx++]);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001156
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001157 E->Base = Reader.ReadSubExpr();
Douglas Gregor393f2492011-07-22 00:38:23 +00001158 E->BaseType = Reader.readType(F, Record, Idx);
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001159 E->IsArrow = Record[Idx++];
1160 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1161 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001162 E->FirstQualifierFoundInScope = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001163 ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001164}
1165
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001166void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001167ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001168 VisitExpr(E);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001169
Douglas Gregordef03542011-02-04 12:01:24 +00001170 if (Record[Idx++])
1171 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
1172 Record[Idx++]);
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001173
1174 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001175 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001176}
1177
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001178void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001179ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001180 VisitExpr(E);
1181 assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
1182 ++Idx; // NumArgs;
1183 for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001184 E->setArg(I, Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +00001185 E->Type = GetTypeSourceInfo(Record, Idx);
1186 E->setLParenLoc(ReadSourceLocation(Record, Idx));
1187 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001188}
1189
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001190void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001191 VisitExpr(E);
1192
Douglas Gregordef03542011-02-04 12:01:24 +00001193 // Read the explicit template argument list, if available.
1194 if (Record[Idx++])
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001195 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Douglas Gregordef03542011-02-04 12:01:24 +00001196 Record[Idx++]);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001197
1198 unsigned NumDecls = Record[Idx++];
1199 UnresolvedSet<8> Decls;
1200 for (unsigned i = 0; i != NumDecls; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +00001201 NamedDecl *D = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001202 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1203 Decls.addDecl(D, AS);
1204 }
1205 E->initializeResults(*Reader.getContext(), Decls.begin(), Decls.end());
1206
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001207 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001208 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001209}
1210
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001211void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001212 VisitOverloadExpr(E);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001213 E->IsArrow = Record[Idx++];
1214 E->HasUnresolvedUsing = Record[Idx++];
1215 E->Base = Reader.ReadSubExpr();
Douglas Gregor393f2492011-07-22 00:38:23 +00001216 E->BaseType = Reader.readType(F, Record, Idx);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001217 E->OperatorLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001218}
1219
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001220void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001221 VisitOverloadExpr(E);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001222 E->RequiresADL = Record[Idx++];
Richard Smithad762fc2011-04-14 22:09:26 +00001223 if (E->RequiresADL)
1224 E->StdIsAssociatedNamespace = Record[Idx++];
Douglas Gregor4c9be892011-02-28 20:01:57 +00001225 E->Overloaded = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001226 E->NamingClass = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001227}
1228
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001229void ASTStmtReader::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001230 VisitExpr(E);
1231 E->UTT = (UnaryTypeTrait)Record[Idx++];
Sebastian Redl0dfd8482010-09-13 20:56:31 +00001232 E->Value = (bool)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001233 SourceRange Range = ReadSourceRange(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001234 E->Loc = Range.getBegin();
1235 E->RParen = Range.getEnd();
Sebastian Redlc3632732010-10-05 15:59:54 +00001236 E->QueriedType = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001237}
1238
Francois Pichet6ad6f282010-12-07 00:08:36 +00001239void ASTStmtReader::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
1240 VisitExpr(E);
1241 E->BTT = (BinaryTypeTrait)Record[Idx++];
1242 E->Value = (bool)Record[Idx++];
1243 SourceRange Range = ReadSourceRange(Record, Idx);
1244 E->Loc = Range.getBegin();
1245 E->RParen = Range.getEnd();
1246 E->LhsType = GetTypeSourceInfo(Record, Idx);
1247 E->RhsType = GetTypeSourceInfo(Record, Idx);
1248}
1249
John Wiegley21ff2e52011-04-28 00:16:57 +00001250void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1251 VisitExpr(E);
1252 E->ATT = (ArrayTypeTrait)Record[Idx++];
1253 E->Value = (unsigned int)Record[Idx++];
1254 SourceRange Range = ReadSourceRange(Record, Idx);
1255 E->Loc = Range.getBegin();
1256 E->RParen = Range.getEnd();
1257 E->QueriedType = GetTypeSourceInfo(Record, Idx);
1258}
1259
John Wiegley55262202011-04-25 06:54:41 +00001260void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1261 VisitExpr(E);
1262 E->ET = (ExpressionTrait)Record[Idx++];
1263 E->Value = (bool)Record[Idx++];
1264 SourceRange Range = ReadSourceRange(Record, Idx);
1265 E->QueriedExpression = Reader.ReadSubExpr();
1266 E->Loc = Range.getBegin();
1267 E->RParen = Range.getEnd();
1268}
1269
Sebastian Redl6b219d02010-09-10 20:55:54 +00001270void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1271 VisitExpr(E);
Sebastian Redl5221d8f2010-09-10 22:34:40 +00001272 E->Value = (bool)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001273 E->Range = ReadSourceRange(Record, Idx);
Sebastian Redl5221d8f2010-09-10 22:34:40 +00001274 E->Operand = Reader.ReadSubExpr();
Sebastian Redl6b219d02010-09-10 20:55:54 +00001275}
1276
Douglas Gregorbe230c32011-01-03 17:17:50 +00001277void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
1278 VisitExpr(E);
1279 E->EllipsisLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor67fd1252011-01-14 21:20:45 +00001280 E->NumExpansions = Record[Idx++];
Douglas Gregorbe230c32011-01-03 17:17:50 +00001281 E->Pattern = Reader.ReadSubExpr();
1282}
1283
Douglas Gregoree8aff02011-01-04 17:33:58 +00001284void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1285 VisitExpr(E);
1286 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1287 E->PackLoc = ReadSourceLocation(Record, Idx);
1288 E->RParenLoc = ReadSourceLocation(Record, Idx);
1289 E->Length = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001290 E->Pack = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregoree8aff02011-01-04 17:33:58 +00001291}
1292
John McCall7110fd62011-07-15 07:00:14 +00001293void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
1294 SubstNonTypeTemplateParmExpr *E) {
1295 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001296 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
John McCall7110fd62011-07-15 07:00:14 +00001297 E->NameLoc = ReadSourceLocation(Record, Idx);
1298 E->Replacement = Reader.ReadSubExpr();
1299}
1300
Douglas Gregorc7793c72011-01-15 01:15:58 +00001301void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
1302 SubstNonTypeTemplateParmPackExpr *E) {
1303 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001304 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
Douglas Gregorc7793c72011-01-15 01:15:58 +00001305 TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx);
1306 if (ArgPack.getKind() != TemplateArgument::Pack)
1307 return;
1308
1309 E->Arguments = ArgPack.pack_begin();
1310 E->NumArguments = ArgPack.pack_size();
1311 E->NameLoc = ReadSourceLocation(Record, Idx);
1312}
1313
Douglas Gregor03e80032011-06-21 17:03:29 +00001314void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1315 VisitExpr(E);
1316 E->Temporary = Reader.ReadSubExpr();
1317}
1318
John McCall7cd7d1a2010-11-15 23:31:06 +00001319void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1320 VisitExpr(E);
John McCall56ca35d2011-02-17 10:25:35 +00001321 Idx++; // skip ID
Douglas Gregorb608b982011-01-28 02:26:04 +00001322 E->Loc = ReadSourceLocation(Record, Idx);
John McCall7cd7d1a2010-11-15 23:31:06 +00001323}
1324
Peter Collingbournee08ce652011-02-09 21:07:24 +00001325//===----------------------------------------------------------------------===//
John McCall7110fd62011-07-15 07:00:14 +00001326// Microsoft Expressions and Statements
1327//===----------------------------------------------------------------------===//
1328void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1329 VisitExpr(E);
1330 E->setSourceRange(ReadSourceRange(Record, Idx));
1331 if (E->isTypeOperand()) { // __uuidof(ComType)
1332 E->setTypeOperandSourceInfo(
1333 GetTypeSourceInfo(Record, Idx));
1334 return;
1335 }
1336
1337 // __uuidof(expr)
1338 E->setExprOperand(Reader.ReadSubExpr());
1339}
1340
1341void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
1342 VisitStmt(S);
1343 S->Loc = ReadSourceLocation(Record, Idx);
1344 S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt();
1345 S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt();
1346}
1347
1348void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1349 VisitStmt(S);
1350 S->Loc = ReadSourceLocation(Record, Idx);
1351 S->Block = Reader.ReadSubStmt();
1352}
1353
1354void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
1355 VisitStmt(S);
1356 S->IsCXXTry = Record[Idx++];
1357 S->TryLoc = ReadSourceLocation(Record, Idx);
1358 S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt();
1359 S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
1360}
1361
1362//===----------------------------------------------------------------------===//
Peter Collingbournee08ce652011-02-09 21:07:24 +00001363// CUDA Expressions and Statements
1364//===----------------------------------------------------------------------===//
1365
1366void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1367 VisitCallExpr(E);
1368 E->setConfig(cast<CallExpr>(Reader.ReadSubExpr()));
1369}
1370
John McCall7110fd62011-07-15 07:00:14 +00001371//===----------------------------------------------------------------------===//
1372// OpenCL Expressions and Statements.
1373//===----------------------------------------------------------------------===//
1374void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
1375 VisitExpr(E);
1376 E->BuiltinLoc = ReadSourceLocation(Record, Idx);
1377 E->RParenLoc = ReadSourceLocation(Record, Idx);
1378 E->SrcExpr = Reader.ReadSubExpr();
1379}
1380
1381//===----------------------------------------------------------------------===//
1382// ASTReader Implementation
1383//===----------------------------------------------------------------------===//
1384
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001385Stmt *ASTReader::ReadStmt(Module &F) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001386 switch (ReadingKind) {
1387 case Read_Decl:
1388 case Read_Type:
Sebastian Redlc3632732010-10-05 15:59:54 +00001389 return ReadStmtFromStream(F);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001390 case Read_Stmt:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001391 return ReadSubStmt();
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001392 }
1393
1394 llvm_unreachable("ReadingKind not set ?");
1395 return 0;
1396}
1397
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001398Expr *ASTReader::ReadExpr(Module &F) {
Sebastian Redlc3632732010-10-05 15:59:54 +00001399 return cast_or_null<Expr>(ReadStmt(F));
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001400}
Chris Lattner030854b2010-05-09 06:40:08 +00001401
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001402Expr *ASTReader::ReadSubExpr() {
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001403 return cast_or_null<Expr>(ReadSubStmt());
1404}
1405
Chris Lattner52e97d12009-04-27 05:41:06 +00001406// Within the bitstream, expressions are stored in Reverse Polish
1407// Notation, with each of the subexpressions preceding the
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001408// expression they are stored in. Subexpressions are stored from last to first.
1409// To evaluate expressions, we continue reading expressions and placing them on
1410// the stack, with expressions having operands removing those operands from the
Chris Lattner52e97d12009-04-27 05:41:06 +00001411// stack. Evaluation terminates when we see a STMT_STOP record, and
1412// the single remaining expression on the stack is our result.
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001413Stmt *ASTReader::ReadStmtFromStream(Module &F) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001414
1415 ReadingKindTracker ReadingKind(Read_Stmt, *this);
Sebastian Redlc3632732010-10-05 15:59:54 +00001416 llvm::BitstreamCursor &Cursor = F.DeclsCursor;
1417
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001418#ifndef NDEBUG
1419 unsigned PrevNumStmts = StmtStack.size();
1420#endif
1421
Chris Lattner4c6f9522009-04-27 05:14:47 +00001422 RecordData Record;
1423 unsigned Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +00001424 ASTStmtReader Reader(*this, F, Cursor, Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001425 Stmt::EmptyShell Empty;
1426
1427 while (true) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001428 unsigned Code = Cursor.ReadCode();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001429 if (Code == llvm::bitc::END_BLOCK) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001430 if (Cursor.ReadBlockEnd()) {
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001431 Error("error at end of block in AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001432 return 0;
1433 }
1434 break;
1435 }
1436
1437 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
1438 // No known subblocks, always skip them.
Chris Lattner52e97d12009-04-27 05:41:06 +00001439 Cursor.ReadSubBlockID();
1440 if (Cursor.SkipBlock()) {
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001441 Error("malformed block record in AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001442 return 0;
1443 }
1444 continue;
1445 }
1446
1447 if (Code == llvm::bitc::DEFINE_ABBREV) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001448 Cursor.ReadAbbrevRecord();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001449 continue;
1450 }
1451
1452 Stmt *S = 0;
1453 Idx = 0;
1454 Record.clear();
1455 bool Finished = false;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001456 switch ((StmtCode)Cursor.ReadRecord(Code, Record)) {
1457 case STMT_STOP:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001458 Finished = true;
1459 break;
1460
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001461 case STMT_NULL_PTR:
Mike Stump1eb44332009-09-09 15:08:12 +00001462 S = 0;
Chris Lattner4c6f9522009-04-27 05:14:47 +00001463 break;
1464
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001465 case STMT_NULL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001466 S = new (Context) NullStmt(Empty);
1467 break;
1468
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001469 case STMT_COMPOUND:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001470 S = new (Context) CompoundStmt(Empty);
1471 break;
1472
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001473 case STMT_CASE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001474 S = new (Context) CaseStmt(Empty);
1475 break;
1476
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001477 case STMT_DEFAULT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001478 S = new (Context) DefaultStmt(Empty);
1479 break;
1480
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001481 case STMT_LABEL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001482 S = new (Context) LabelStmt(Empty);
1483 break;
1484
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001485 case STMT_IF:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001486 S = new (Context) IfStmt(Empty);
1487 break;
1488
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001489 case STMT_SWITCH:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001490 S = new (Context) SwitchStmt(Empty);
1491 break;
1492
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001493 case STMT_WHILE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001494 S = new (Context) WhileStmt(Empty);
1495 break;
1496
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001497 case STMT_DO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001498 S = new (Context) DoStmt(Empty);
1499 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001500
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001501 case STMT_FOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001502 S = new (Context) ForStmt(Empty);
1503 break;
1504
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001505 case STMT_GOTO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001506 S = new (Context) GotoStmt(Empty);
1507 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001508
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001509 case STMT_INDIRECT_GOTO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001510 S = new (Context) IndirectGotoStmt(Empty);
1511 break;
1512
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001513 case STMT_CONTINUE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001514 S = new (Context) ContinueStmt(Empty);
1515 break;
1516
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001517 case STMT_BREAK:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001518 S = new (Context) BreakStmt(Empty);
1519 break;
1520
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001521 case STMT_RETURN:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001522 S = new (Context) ReturnStmt(Empty);
1523 break;
1524
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001525 case STMT_DECL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001526 S = new (Context) DeclStmt(Empty);
1527 break;
1528
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001529 case STMT_ASM:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001530 S = new (Context) AsmStmt(Empty);
1531 break;
1532
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001533 case EXPR_PREDEFINED:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001534 S = new (Context) PredefinedExpr(Empty);
1535 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001536
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001537 case EXPR_DECL_REF:
Chandler Carruth3aa81402011-05-01 23:48:14 +00001538 S = DeclRefExpr::CreateEmpty(
1539 *Context,
1540 /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
1541 /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
1542 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2],
1543 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
1544 Record[ASTStmtReader::NumExprFields + 3] : 0);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001545 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001546
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001547 case EXPR_INTEGER_LITERAL:
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00001548 S = IntegerLiteral::Create(*Context, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001549 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001550
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001551 case EXPR_FLOATING_LITERAL:
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00001552 S = FloatingLiteral::Create(*Context, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001553 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001554
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001555 case EXPR_IMAGINARY_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001556 S = new (Context) ImaginaryLiteral(Empty);
1557 break;
1558
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001559 case EXPR_STRING_LITERAL:
Mike Stump1eb44332009-09-09 15:08:12 +00001560 S = StringLiteral::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001561 Record[ASTStmtReader::NumExprFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001562 break;
1563
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001564 case EXPR_CHARACTER_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001565 S = new (Context) CharacterLiteral(Empty);
1566 break;
1567
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001568 case EXPR_PAREN:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001569 S = new (Context) ParenExpr(Empty);
1570 break;
1571
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001572 case EXPR_PAREN_LIST:
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +00001573 S = new (Context) ParenListExpr(Empty);
1574 break;
1575
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001576 case EXPR_UNARY_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001577 S = new (Context) UnaryOperator(Empty);
1578 break;
1579
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001580 case EXPR_OFFSETOF:
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001581 S = OffsetOfExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001582 Record[ASTStmtReader::NumExprFields],
1583 Record[ASTStmtReader::NumExprFields + 1]);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001584 break;
1585
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001586 case EXPR_SIZEOF_ALIGN_OF:
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001587 S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001588 break;
1589
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001590 case EXPR_ARRAY_SUBSCRIPT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001591 S = new (Context) ArraySubscriptExpr(Empty);
1592 break;
1593
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001594 case EXPR_CALL:
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +00001595 S = new (Context) CallExpr(*Context, Stmt::CallExprClass, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001596 break;
1597
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001598 case EXPR_MEMBER: {
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001599 // We load everything here and fully initialize it at creation.
1600 // That way we can use MemberExpr::Create and don't have to duplicate its
1601 // logic with a MemberExpr::CreateEmpty.
1602
1603 assert(Idx == 0);
Douglas Gregor40d96a62011-02-28 21:54:11 +00001604 NestedNameSpecifierLoc QualifierLoc;
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001605 if (Record[Idx++]) { // HasQualifier.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001606 QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001607 }
1608
1609 TemplateArgumentListInfo ArgInfo;
Douglas Gregordef03542011-02-04 12:01:24 +00001610 bool HasExplicitTemplateArgs = Record[Idx++];
1611 if (HasExplicitTemplateArgs) {
1612 unsigned NumTemplateArgs = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001613 ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx));
1614 ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx));
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001615 for (unsigned i = 0; i != NumTemplateArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001616 ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001617 }
1618
Douglas Gregor409448c2011-07-21 22:35:25 +00001619 NamedDecl *FoundD = ReadDeclAs<NamedDecl>(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001620 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1621 DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS);
1622
Douglas Gregor393f2492011-07-22 00:38:23 +00001623 QualType T = readType(F, Record, Idx);
John McCallf89e55a2010-11-18 06:31:45 +00001624 ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]);
1625 ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001626 Expr *Base = ReadSubExpr();
Douglas Gregor409448c2011-07-21 22:35:25 +00001627 ValueDecl *MemberD = ReadDeclAs<ValueDecl>(F, Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +00001628 SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx);
Abramo Bagnara25777432010-08-11 22:01:17 +00001629 DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001630 bool IsArrow = Record[Idx++];
1631
Douglas Gregor40d96a62011-02-28 21:54:11 +00001632 S = MemberExpr::Create(*Context, Base, IsArrow, QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001633 MemberD, FoundDecl, MemberNameInfo,
Douglas Gregordef03542011-02-04 12:01:24 +00001634 HasExplicitTemplateArgs ? &ArgInfo : 0, T, VK, OK);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001635 ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc,
1636 MemberD->getDeclName(), Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001637 break;
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001638 }
Chris Lattner4c6f9522009-04-27 05:14:47 +00001639
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001640 case EXPR_BINARY_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001641 S = new (Context) BinaryOperator(Empty);
1642 break;
1643
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001644 case EXPR_COMPOUND_ASSIGN_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001645 S = new (Context) CompoundAssignOperator(Empty);
1646 break;
1647
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001648 case EXPR_CONDITIONAL_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001649 S = new (Context) ConditionalOperator(Empty);
1650 break;
1651
John McCall56ca35d2011-02-17 10:25:35 +00001652 case EXPR_BINARY_CONDITIONAL_OPERATOR:
1653 S = new (Context) BinaryConditionalOperator(Empty);
1654 break;
1655
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001656 case EXPR_IMPLICIT_CAST:
John McCallf871d0c2010-08-07 06:22:56 +00001657 S = ImplicitCastExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001658 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001659 break;
1660
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001661 case EXPR_CSTYLE_CAST:
John McCallf871d0c2010-08-07 06:22:56 +00001662 S = CStyleCastExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001663 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001664 break;
1665
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001666 case EXPR_COMPOUND_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001667 S = new (Context) CompoundLiteralExpr(Empty);
1668 break;
1669
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001670 case EXPR_EXT_VECTOR_ELEMENT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001671 S = new (Context) ExtVectorElementExpr(Empty);
1672 break;
1673
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001674 case EXPR_INIT_LIST:
Ted Kremenek709210f2010-04-13 23:39:13 +00001675 S = new (Context) InitListExpr(*getContext(), Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001676 break;
1677
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001678 case EXPR_DESIGNATED_INIT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001679 S = DesignatedInitExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001680 Record[ASTStmtReader::NumExprFields] - 1);
Mike Stump1eb44332009-09-09 15:08:12 +00001681
Chris Lattner4c6f9522009-04-27 05:14:47 +00001682 break;
1683
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001684 case EXPR_IMPLICIT_VALUE_INIT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001685 S = new (Context) ImplicitValueInitExpr(Empty);
1686 break;
1687
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001688 case EXPR_VA_ARG:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001689 S = new (Context) VAArgExpr(Empty);
1690 break;
1691
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001692 case EXPR_ADDR_LABEL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001693 S = new (Context) AddrLabelExpr(Empty);
1694 break;
1695
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001696 case EXPR_STMT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001697 S = new (Context) StmtExpr(Empty);
1698 break;
1699
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001700 case EXPR_CHOOSE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001701 S = new (Context) ChooseExpr(Empty);
1702 break;
1703
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001704 case EXPR_GNU_NULL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001705 S = new (Context) GNUNullExpr(Empty);
1706 break;
1707
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001708 case EXPR_SHUFFLE_VECTOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001709 S = new (Context) ShuffleVectorExpr(Empty);
1710 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001711
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001712 case EXPR_BLOCK:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001713 S = new (Context) BlockExpr(Empty);
1714 break;
1715
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001716 case EXPR_BLOCK_DECL_REF:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001717 S = new (Context) BlockDeclRefExpr(Empty);
1718 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001719
Peter Collingbournef111d932011-04-15 00:35:48 +00001720 case EXPR_GENERIC_SELECTION:
1721 S = new (Context) GenericSelectionExpr(Empty);
1722 break;
1723
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001724 case EXPR_OBJC_STRING_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001725 S = new (Context) ObjCStringLiteral(Empty);
1726 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001727 case EXPR_OBJC_ENCODE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001728 S = new (Context) ObjCEncodeExpr(Empty);
1729 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001730 case EXPR_OBJC_SELECTOR_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001731 S = new (Context) ObjCSelectorExpr(Empty);
1732 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001733 case EXPR_OBJC_PROTOCOL_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001734 S = new (Context) ObjCProtocolExpr(Empty);
1735 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001736 case EXPR_OBJC_IVAR_REF_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001737 S = new (Context) ObjCIvarRefExpr(Empty);
1738 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001739 case EXPR_OBJC_PROPERTY_REF_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001740 S = new (Context) ObjCPropertyRefExpr(Empty);
1741 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001742 case EXPR_OBJC_KVC_REF_EXPR:
John McCall12f78a62010-12-02 01:19:52 +00001743 llvm_unreachable("mismatching AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001744 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001745 case EXPR_OBJC_MESSAGE_EXPR:
Douglas Gregor04badcf2010-04-21 00:45:42 +00001746 S = ObjCMessageExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001747 Record[ASTStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001748 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001749 case EXPR_OBJC_ISA:
Steve Narofff242b1b2009-07-24 17:54:45 +00001750 S = new (Context) ObjCIsaExpr(Empty);
1751 break;
John McCallf85e1932011-06-15 23:02:42 +00001752 case EXPR_OBJC_INDIRECT_COPY_RESTORE:
1753 S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
1754 break;
1755 case EXPR_OBJC_BRIDGED_CAST:
1756 S = new (Context) ObjCBridgedCastExpr(Empty);
1757 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001758 case STMT_OBJC_FOR_COLLECTION:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001759 S = new (Context) ObjCForCollectionStmt(Empty);
1760 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001761 case STMT_OBJC_CATCH:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001762 S = new (Context) ObjCAtCatchStmt(Empty);
1763 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001764 case STMT_OBJC_FINALLY:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001765 S = new (Context) ObjCAtFinallyStmt(Empty);
1766 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001767 case STMT_OBJC_AT_TRY:
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001768 S = ObjCAtTryStmt::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001769 Record[ASTStmtReader::NumStmtFields],
1770 Record[ASTStmtReader::NumStmtFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001771 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001772 case STMT_OBJC_AT_SYNCHRONIZED:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001773 S = new (Context) ObjCAtSynchronizedStmt(Empty);
1774 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001775 case STMT_OBJC_AT_THROW:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001776 S = new (Context) ObjCAtThrowStmt(Empty);
1777 break;
John McCallf85e1932011-06-15 23:02:42 +00001778 case STMT_OBJC_AUTORELEASE_POOL:
1779 S = new (Context) ObjCAutoreleasePoolStmt(Empty);
1780 break;
John McCall7110fd62011-07-15 07:00:14 +00001781 case STMT_SEH_EXCEPT:
1782 S = new (Context) SEHExceptStmt(Empty);
1783 break;
1784 case STMT_SEH_FINALLY:
1785 S = new (Context) SEHFinallyStmt(Empty);
1786 break;
1787 case STMT_SEH_TRY:
1788 S = new (Context) SEHTryStmt(Empty);
1789 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001790 case STMT_CXX_CATCH:
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +00001791 S = new (Context) CXXCatchStmt(Empty);
1792 break;
1793
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001794 case STMT_CXX_TRY:
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +00001795 S = CXXTryStmt::Create(*Context, Empty,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001796 /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +00001797 break;
1798
Richard Smithad762fc2011-04-14 22:09:26 +00001799 case STMT_CXX_FOR_RANGE:
1800 S = new (Context) CXXForRangeStmt(Empty);
1801 break;
1802
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001803 case EXPR_CXX_OPERATOR_CALL:
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +00001804 S = new (Context) CXXOperatorCallExpr(*Context, Empty);
1805 break;
Chris Lattner1817bd42010-05-09 05:36:05 +00001806
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001807 case EXPR_CXX_MEMBER_CALL:
Chris Lattner1817bd42010-05-09 05:36:05 +00001808 S = new (Context) CXXMemberCallExpr(*Context, Empty);
1809 break;
Douglas Gregor39da0b82009-09-09 23:08:42 +00001810
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001811 case EXPR_CXX_CONSTRUCT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001812 S = new (Context) CXXConstructExpr(Empty);
1813 break;
1814
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001815 case EXPR_CXX_TEMPORARY_OBJECT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001816 S = new (Context) CXXTemporaryObjectExpr(Empty);
Douglas Gregor39da0b82009-09-09 23:08:42 +00001817 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001818
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001819 case EXPR_CXX_STATIC_CAST:
John McCallf871d0c2010-08-07 06:22:56 +00001820 S = CXXStaticCastExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001821 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001822 break;
1823
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001824 case EXPR_CXX_DYNAMIC_CAST:
John McCallf871d0c2010-08-07 06:22:56 +00001825 S = CXXDynamicCastExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001826 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001827 break;
1828
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001829 case EXPR_CXX_REINTERPRET_CAST:
John McCallf871d0c2010-08-07 06:22:56 +00001830 S = CXXReinterpretCastExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001831 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001832 break;
1833
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001834 case EXPR_CXX_CONST_CAST:
John McCallf871d0c2010-08-07 06:22:56 +00001835 S = CXXConstCastExpr::CreateEmpty(*Context);
Sam Weinigce757a72010-01-16 21:21:01 +00001836 break;
1837
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001838 case EXPR_CXX_FUNCTIONAL_CAST:
John McCallf871d0c2010-08-07 06:22:56 +00001839 S = CXXFunctionalCastExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001840 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001841 break;
1842
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001843 case EXPR_CXX_BOOL_LITERAL:
Sam Weinigeb7f9612010-02-07 06:32:43 +00001844 S = new (Context) CXXBoolLiteralExpr(Empty);
1845 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001846
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001847 case EXPR_CXX_NULL_PTR_LITERAL:
Sam Weinigeb7f9612010-02-07 06:32:43 +00001848 S = new (Context) CXXNullPtrLiteralExpr(Empty);
1849 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001850 case EXPR_CXX_TYPEID_EXPR:
Chris Lattner14ab24f2010-05-09 06:03:39 +00001851 S = new (Context) CXXTypeidExpr(Empty, true);
1852 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001853 case EXPR_CXX_TYPEID_TYPE:
Chris Lattner14ab24f2010-05-09 06:03:39 +00001854 S = new (Context) CXXTypeidExpr(Empty, false);
1855 break;
Francois Pichet01b7c302010-09-08 12:20:18 +00001856 case EXPR_CXX_UUIDOF_EXPR:
1857 S = new (Context) CXXUuidofExpr(Empty, true);
1858 break;
1859 case EXPR_CXX_UUIDOF_TYPE:
1860 S = new (Context) CXXUuidofExpr(Empty, false);
1861 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001862 case EXPR_CXX_THIS:
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001863 S = new (Context) CXXThisExpr(Empty);
1864 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001865 case EXPR_CXX_THROW:
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001866 S = new (Context) CXXThrowExpr(Empty);
1867 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001868 case EXPR_CXX_DEFAULT_ARG: {
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001869 bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields];
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001870 if (HasOtherExprStored) {
1871 Expr *SubExpr = ReadSubExpr();
1872 S = CXXDefaultArgExpr::Create(*Context, SourceLocation(), 0, SubExpr);
1873 } else
1874 S = new (Context) CXXDefaultArgExpr(Empty);
Chris Lattner030854b2010-05-09 06:40:08 +00001875 break;
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001876 }
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001877 case EXPR_CXX_BIND_TEMPORARY:
Chris Lattnerd2598362010-05-10 00:25:06 +00001878 S = new (Context) CXXBindTemporaryExpr(Empty);
1879 break;
Douglas Gregore2ca6d42010-09-02 21:50:02 +00001880
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001881 case EXPR_CXX_SCALAR_VALUE_INIT:
Douglas Gregored8abf12010-07-08 06:14:04 +00001882 S = new (Context) CXXScalarValueInitExpr(Empty);
Chris Lattner59218632010-05-10 01:22:27 +00001883 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001884 case EXPR_CXX_NEW:
Chris Lattner59218632010-05-10 01:22:27 +00001885 S = new (Context) CXXNewExpr(Empty);
1886 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001887 case EXPR_CXX_DELETE:
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001888 S = new (Context) CXXDeleteExpr(Empty);
1889 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001890 case EXPR_CXX_PSEUDO_DESTRUCTOR:
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001891 S = new (Context) CXXPseudoDestructorExpr(Empty);
1892 break;
Chris Lattner59218632010-05-10 01:22:27 +00001893
John McCall4765fa02010-12-06 08:20:24 +00001894 case EXPR_EXPR_WITH_CLEANUPS:
1895 S = new (Context) ExprWithCleanups(Empty);
Chris Lattnerd2598362010-05-10 00:25:06 +00001896 break;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001897
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001898 case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001899 S = CXXDependentScopeMemberExpr::CreateEmpty(*Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001900 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1901 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1902 ? Record[ASTStmtReader::NumExprFields + 1]
1903 : 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001904 break;
1905
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001906 case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001907 S = DependentScopeDeclRefExpr::CreateEmpty(*Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001908 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1909 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1910 ? Record[ASTStmtReader::NumExprFields + 1]
1911 : 0);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001912 break;
1913
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001914 case EXPR_CXX_UNRESOLVED_CONSTRUCT:
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001915 S = CXXUnresolvedConstructExpr::CreateEmpty(*Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001916 /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001917 break;
1918
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001919 case EXPR_CXX_UNRESOLVED_MEMBER:
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001920 S = UnresolvedMemberExpr::CreateEmpty(*Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001921 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1922 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1923 ? Record[ASTStmtReader::NumExprFields + 1]
1924 : 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001925 break;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001926
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001927 case EXPR_CXX_UNRESOLVED_LOOKUP:
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001928 S = UnresolvedLookupExpr::CreateEmpty(*Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001929 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1930 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1931 ? Record[ASTStmtReader::NumExprFields + 1]
1932 : 0);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001933 break;
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001934
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001935 case EXPR_CXX_UNARY_TYPE_TRAIT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001936 S = new (Context) UnaryTypeTraitExpr(Empty);
1937 break;
Sebastian Redl6b219d02010-09-10 20:55:54 +00001938
Francois Pichetf1872372010-12-08 22:35:30 +00001939 case EXPR_BINARY_TYPE_TRAIT:
Francois Pichet6ad6f282010-12-07 00:08:36 +00001940 S = new (Context) BinaryTypeTraitExpr(Empty);
1941 break;
1942
John Wiegley21ff2e52011-04-28 00:16:57 +00001943 case EXPR_ARRAY_TYPE_TRAIT:
1944 S = new (Context) ArrayTypeTraitExpr(Empty);
1945 break;
1946
John Wiegley55262202011-04-25 06:54:41 +00001947 case EXPR_CXX_EXPRESSION_TRAIT:
1948 S = new (Context) ExpressionTraitExpr(Empty);
1949 break;
1950
Sebastian Redl6b219d02010-09-10 20:55:54 +00001951 case EXPR_CXX_NOEXCEPT:
1952 S = new (Context) CXXNoexceptExpr(Empty);
1953 break;
John McCall7cd7d1a2010-11-15 23:31:06 +00001954
Douglas Gregorbe230c32011-01-03 17:17:50 +00001955 case EXPR_PACK_EXPANSION:
1956 S = new (Context) PackExpansionExpr(Empty);
1957 break;
1958
Douglas Gregoree8aff02011-01-04 17:33:58 +00001959 case EXPR_SIZEOF_PACK:
1960 S = new (Context) SizeOfPackExpr(Empty);
1961 break;
1962
John McCall7110fd62011-07-15 07:00:14 +00001963 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
1964 S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
1965 break;
1966
Douglas Gregorc7793c72011-01-15 01:15:58 +00001967 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
1968 S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
1969 break;
1970
Douglas Gregor03e80032011-06-21 17:03:29 +00001971 case EXPR_MATERIALIZE_TEMPORARY:
1972 S = new (Context) MaterializeTemporaryExpr(Empty);
1973 break;
1974
John McCall56ca35d2011-02-17 10:25:35 +00001975 case EXPR_OPAQUE_VALUE: {
1976 unsigned key = Record[ASTStmtReader::NumExprFields];
1977 OpaqueValueExpr *&expr = OpaqueValueExprs[key];
1978
1979 // If we already have an entry for this opaque value expression,
1980 // don't bother reading it again.
1981 if (expr) {
1982 StmtStack.push_back(expr);
1983 continue;
1984 }
1985
1986 S = expr = new (Context) OpaqueValueExpr(Empty);
John McCall7cd7d1a2010-11-15 23:31:06 +00001987 break;
John McCall56ca35d2011-02-17 10:25:35 +00001988 }
Peter Collingbournee08ce652011-02-09 21:07:24 +00001989
1990 case EXPR_CUDA_KERNEL_CALL:
1991 S = new (Context) CUDAKernelCallExpr(*Context, Empty);
1992 break;
Tanya Lattner61eee0c2011-06-04 00:47:47 +00001993
1994 case EXPR_ASTYPE:
1995 S = new (Context) AsTypeExpr(Empty);
1996 break;
Chris Lattner4c6f9522009-04-27 05:14:47 +00001997 }
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001998
Chris Lattner4c6f9522009-04-27 05:14:47 +00001999 // We hit a STMT_STOP, so we're done with this expression.
2000 if (Finished)
2001 break;
2002
2003 ++NumStatementsRead;
2004
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00002005 if (S)
2006 Reader.Visit(S);
Chris Lattner4c6f9522009-04-27 05:14:47 +00002007
2008 assert(Idx == Record.size() && "Invalid deserialization of statement");
2009 StmtStack.push_back(S);
2010 }
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00002011
2012#ifndef NDEBUG
2013 assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!");
2014 assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
2015#endif
2016
2017 return StmtStack.pop_back_val();
Chris Lattner4c6f9522009-04-27 05:14:47 +00002018}