blob: 02a8c68028f29394f5e7eb017b280ce5ff88f6d7 [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 Kyrtzidise2ca8282011-09-01 21:53:45 +0000112 S->HasLeadingEmptyMacro = 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());
Douglas Gregor35942772011-09-09 21:34:22 +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 Gregor35942772011-09-09 21:34:22 +0000159 S->setConditionVariable(Reader.getContext(),
Douglas Gregor409448c2011-07-21 22:35:25 +0000160 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 Gregor35942772011-09-09 21:34:22 +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 Gregor35942772011-09-09 21:34:22 +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 Gregor35942772011-09-09 21:34:22 +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));
Douglas Gregor35942772011-09-09 21:34:22 +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) {
Douglas Gregor95eab172011-07-28 20:55:49 +0000290 Names.push_back(Reader.GetIdentifierInfo(F, 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
Douglas Gregor35942772011-09-09 21:34:22 +0000300 S->setOutputsAndInputsAndClobbers(Reader.getContext(),
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000301 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));
Douglas Gregor35942772011-09-09 21:34:22 +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);
Douglas Gregor35942772011-09-09 21:34:22 +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);
Douglas Gregor35942772011-09-09 21:34:22 +0000379 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++];
Douglas Gregor35942772011-09-09 21:34:22 +0000404 E->Exprs = new (Reader.getContext()) Stmt*[NumExprs];
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +0000405 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:
Douglas Gregor95eab172011-07-28 20:55:49 +0000443 E->setComponent(I,
444 Node(Start,
445 Reader.GetIdentifierInfo(F, Record, Idx),
446 End));
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000447 break;
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000448
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000449 case Node::Base: {
Douglas Gregor35942772011-09-09 21:34:22 +0000450 CXXBaseSpecifier *Base = new (Reader.getContext()) CXXBaseSpecifier();
Sebastian Redlc3632732010-10-05 15:59:54 +0000451 *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000452 E->setComponent(I, Node(Base));
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000453 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000454 }
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000455 }
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000456 }
457
458 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000459 E->setIndexExpr(I, Reader.ReadSubExpr());
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000460}
461
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000462void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000463 VisitExpr(E);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000464 E->setKind(static_cast<UnaryExprOrTypeTrait>(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000465 if (Record[Idx] == 0) {
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000466 E->setArgument(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000467 ++Idx;
468 } else {
Sebastian Redlc3632732010-10-05 15:59:54 +0000469 E->setArgument(GetTypeSourceInfo(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000470 }
Sebastian Redlc3632732010-10-05 15:59:54 +0000471 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
472 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000473}
474
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000475void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000476 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000477 E->setLHS(Reader.ReadSubExpr());
478 E->setRHS(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000479 E->setRBracketLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000480}
481
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000482void ASTStmtReader::VisitCallExpr(CallExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000483 VisitExpr(E);
Douglas Gregor35942772011-09-09 21:34:22 +0000484 E->setNumArgs(Reader.getContext(), Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000485 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000486 E->setCallee(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000487 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000488 E->setArg(I, Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000489}
490
John McCall7110fd62011-07-15 07:00:14 +0000491void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
492 VisitCallExpr(E);
493}
494
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000495void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000496 // Don't call VisitExpr, this is fully initialized at creation.
497 assert(E->getStmtClass() == Stmt::MemberExprClass &&
498 "It's a subclass, we must advance Idx!");
Chris Lattner4c6f9522009-04-27 05:14:47 +0000499}
500
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000501void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Narofff242b1b2009-07-24 17:54:45 +0000502 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000503 E->setBase(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000504 E->setIsaMemberLoc(ReadSourceLocation(Record, Idx));
Steve Narofff242b1b2009-07-24 17:54:45 +0000505 E->setArrow(Record[Idx++]);
Steve Narofff242b1b2009-07-24 17:54:45 +0000506}
507
John McCallf85e1932011-06-15 23:02:42 +0000508void ASTStmtReader::
509VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
510 VisitExpr(E);
511 E->Operand = Reader.ReadSubExpr();
512 E->setShouldCopy(Record[Idx++]);
513}
514
515void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
516 VisitExplicitCastExpr(E);
517 E->LParenLoc = ReadSourceLocation(Record, Idx);
518 E->BridgeKeywordLoc = ReadSourceLocation(Record, Idx);
519 E->Kind = Record[Idx++];
520}
521
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000522void ASTStmtReader::VisitCastExpr(CastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000523 VisitExpr(E);
John McCallf871d0c2010-08-07 06:22:56 +0000524 unsigned NumBaseSpecs = Record[Idx++];
525 assert(NumBaseSpecs == E->path_size());
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000526 E->setSubExpr(Reader.ReadSubExpr());
Anders Carlssoncdef2b72009-07-31 00:48:10 +0000527 E->setCastKind((CastExpr::CastKind)Record[Idx++]);
John McCallf871d0c2010-08-07 06:22:56 +0000528 CastExpr::path_iterator BaseI = E->path_begin();
Argyrios Kyrtzidis0745d0a2010-07-02 23:30:27 +0000529 while (NumBaseSpecs--) {
Douglas Gregor35942772011-09-09 21:34:22 +0000530 CXXBaseSpecifier *BaseSpec = new (Reader.getContext()) CXXBaseSpecifier;
Sebastian Redlc3632732010-10-05 15:59:54 +0000531 *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
John McCallf871d0c2010-08-07 06:22:56 +0000532 *BaseI++ = BaseSpec;
Argyrios Kyrtzidis0745d0a2010-07-02 23:30:27 +0000533 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000534}
535
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000536void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000537 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000538 E->setLHS(Reader.ReadSubExpr());
539 E->setRHS(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000540 E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000541 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000542}
543
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000544void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000545 VisitBinaryOperator(E);
Douglas Gregor393f2492011-07-22 00:38:23 +0000546 E->setComputationLHSType(Reader.readType(F, Record, Idx));
547 E->setComputationResultType(Reader.readType(F, Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000548}
549
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000550void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000551 VisitExpr(E);
John McCall56ca35d2011-02-17 10:25:35 +0000552 E->SubExprs[ConditionalOperator::COND] = Reader.ReadSubExpr();
553 E->SubExprs[ConditionalOperator::LHS] = Reader.ReadSubExpr();
554 E->SubExprs[ConditionalOperator::RHS] = Reader.ReadSubExpr();
555 E->QuestionLoc = ReadSourceLocation(Record, Idx);
556 E->ColonLoc = ReadSourceLocation(Record, Idx);
557}
558
559void
560ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
561 VisitExpr(E);
562 E->OpaqueValue = cast<OpaqueValueExpr>(Reader.ReadSubExpr());
563 E->SubExprs[BinaryConditionalOperator::COMMON] = Reader.ReadSubExpr();
564 E->SubExprs[BinaryConditionalOperator::COND] = Reader.ReadSubExpr();
565 E->SubExprs[BinaryConditionalOperator::LHS] = Reader.ReadSubExpr();
566 E->SubExprs[BinaryConditionalOperator::RHS] = Reader.ReadSubExpr();
567 E->QuestionLoc = ReadSourceLocation(Record, Idx);
568 E->ColonLoc = ReadSourceLocation(Record, Idx);
569
570 E->getOpaqueValue()->setSourceExpr(E->getCommon());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000571}
572
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000573void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000574 VisitCastExpr(E);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000575}
576
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000577void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000578 VisitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000579 E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000580}
581
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000582void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000583 VisitExplicitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000584 E->setLParenLoc(ReadSourceLocation(Record, Idx));
585 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000586}
587
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000588void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000589 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000590 E->setLParenLoc(ReadSourceLocation(Record, Idx));
591 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000592 E->setInitializer(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000593 E->setFileScope(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000594}
595
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000596void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000597 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000598 E->setBase(Reader.ReadSubExpr());
Douglas Gregor95eab172011-07-28 20:55:49 +0000599 E->setAccessor(Reader.GetIdentifierInfo(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000600 E->setAccessorLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000601}
602
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000603void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000604 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000605 E->setSyntacticForm(cast_or_null<InitListExpr>(Reader.ReadSubStmt()));
Sebastian Redlc3632732010-10-05 15:59:54 +0000606 E->setLBraceLoc(ReadSourceLocation(Record, Idx));
607 E->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000608 bool isArrayFiller = Record[Idx++];
609 Expr *filler = 0;
610 if (isArrayFiller) {
611 filler = Reader.ReadSubExpr();
612 E->ArrayFillerOrUnionFieldInit = filler;
613 } else
Douglas Gregor409448c2011-07-21 22:35:25 +0000614 E->ArrayFillerOrUnionFieldInit = ReadDeclAs<FieldDecl>(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000615 E->sawArrayRangeDesignator(Record[Idx++]);
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000616 unsigned NumInits = Record[Idx++];
Douglas Gregor35942772011-09-09 21:34:22 +0000617 E->reserveInits(Reader.getContext(), NumInits);
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000618 if (isArrayFiller) {
619 for (unsigned I = 0; I != NumInits; ++I) {
620 Expr *init = Reader.ReadSubExpr();
Douglas Gregor35942772011-09-09 21:34:22 +0000621 E->updateInit(Reader.getContext(), I, init ? init : filler);
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000622 }
623 } else {
624 for (unsigned I = 0; I != NumInits; ++I)
Douglas Gregor35942772011-09-09 21:34:22 +0000625 E->updateInit(Reader.getContext(), I, Reader.ReadSubExpr());
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000626 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000627}
628
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000629void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000630 typedef DesignatedInitExpr::Designator Designator;
631
632 VisitExpr(E);
633 unsigned NumSubExprs = Record[Idx++];
634 assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
635 for (unsigned I = 0; I != NumSubExprs; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000636 E->setSubExpr(I, Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000637 E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000638 E->setGNUSyntax(Record[Idx++]);
639
Chris Lattner5f9e2722011-07-23 10:55:15 +0000640 SmallVector<Designator, 4> Designators;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000641 while (Idx < Record.size()) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000642 switch ((DesignatorTypes)Record[Idx++]) {
643 case DESIG_FIELD_DECL: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000644 FieldDecl *Field = ReadDeclAs<FieldDecl>(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000645 SourceLocation DotLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000646 = ReadSourceLocation(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000647 SourceLocation FieldLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000648 = ReadSourceLocation(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000649 Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
Chris Lattner4c6f9522009-04-27 05:14:47 +0000650 FieldLoc));
651 Designators.back().setField(Field);
652 break;
653 }
654
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000655 case DESIG_FIELD_NAME: {
Douglas Gregor95eab172011-07-28 20:55:49 +0000656 const IdentifierInfo *Name = Reader.GetIdentifierInfo(F, Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000657 SourceLocation DotLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000658 = ReadSourceLocation(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000659 SourceLocation FieldLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000660 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000661 Designators.push_back(Designator(Name, DotLoc, FieldLoc));
662 break;
663 }
Mike Stump1eb44332009-09-09 15:08:12 +0000664
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000665 case DESIG_ARRAY: {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000666 unsigned Index = Record[Idx++];
667 SourceLocation LBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000668 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000669 SourceLocation RBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000670 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000671 Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
672 break;
673 }
674
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000675 case DESIG_ARRAY_RANGE: {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000676 unsigned Index = Record[Idx++];
677 SourceLocation LBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000678 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000679 SourceLocation EllipsisLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000680 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000681 SourceLocation RBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000682 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000683 Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
684 RBracketLoc));
685 break;
686 }
687 }
688 }
Douglas Gregor35942772011-09-09 21:34:22 +0000689 E->setDesignators(Reader.getContext(),
Douglas Gregor319d57f2010-01-06 23:17:19 +0000690 Designators.data(), Designators.size());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000691}
692
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000693void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000694 VisitExpr(E);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000695}
696
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000697void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000698 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000699 E->setSubExpr(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000700 E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx));
701 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
702 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000703}
704
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000705void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000706 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000707 E->setAmpAmpLoc(ReadSourceLocation(Record, Idx));
708 E->setLabelLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000709 E->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000710}
711
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000712void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000713 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000714 E->setLParenLoc(ReadSourceLocation(Record, Idx));
715 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000716 E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt()));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000717}
718
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000719void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000720 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000721 E->setCond(Reader.ReadSubExpr());
722 E->setLHS(Reader.ReadSubExpr());
723 E->setRHS(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000724 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
725 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000726}
727
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000728void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000729 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000730 E->setTokenLocation(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000731}
732
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000733void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000734 VisitExpr(E);
Chris Lattner5f9e2722011-07-23 10:55:15 +0000735 SmallVector<Expr *, 16> Exprs;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000736 unsigned NumExprs = Record[Idx++];
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000737 while (NumExprs--)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000738 Exprs.push_back(Reader.ReadSubExpr());
Douglas Gregor35942772011-09-09 21:34:22 +0000739 E->setExprs(Reader.getContext(), Exprs.data(), Exprs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +0000740 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
741 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000742}
743
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000744void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000745 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000746 E->setBlockDecl(ReadDeclAs<BlockDecl>(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000747}
748
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000749void ASTStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000750 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000751 E->setDecl(ReadDeclAs<VarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000752 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000753 E->setByRef(Record[Idx++]);
Fariborz Jahanian9b0b57c2009-06-20 00:02:26 +0000754 E->setConstQualAdded(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000755}
756
Peter Collingbournef111d932011-04-15 00:35:48 +0000757void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
758 VisitExpr(E);
759 E->NumAssocs = Record[Idx++];
Douglas Gregor35942772011-09-09 21:34:22 +0000760 E->AssocTypes = new (Reader.getContext()) TypeSourceInfo*[E->NumAssocs];
Peter Collingbournef111d932011-04-15 00:35:48 +0000761 E->SubExprs =
Douglas Gregor35942772011-09-09 21:34:22 +0000762 new(Reader.getContext()) Stmt*[GenericSelectionExpr::END_EXPR+E->NumAssocs];
Peter Collingbournef111d932011-04-15 00:35:48 +0000763
764 E->SubExprs[GenericSelectionExpr::CONTROLLING] = Reader.ReadSubExpr();
765 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
766 E->AssocTypes[I] = GetTypeSourceInfo(Record, Idx);
767 E->SubExprs[GenericSelectionExpr::END_EXPR+I] = Reader.ReadSubExpr();
768 }
769 E->ResultIndex = Record[Idx++];
770
771 E->GenericLoc = ReadSourceLocation(Record, Idx);
772 E->DefaultLoc = ReadSourceLocation(Record, Idx);
773 E->RParenLoc = ReadSourceLocation(Record, Idx);
774}
775
Chris Lattner4c6f9522009-04-27 05:14:47 +0000776//===----------------------------------------------------------------------===//
777// Objective-C Expressions and Statements
778
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000779void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000780 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000781 E->setString(cast<StringLiteral>(Reader.ReadSubStmt()));
Sebastian Redlc3632732010-10-05 15:59:54 +0000782 E->setAtLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000783}
784
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000785void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000786 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000787 E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
788 E->setAtLoc(ReadSourceLocation(Record, Idx));
789 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000790}
791
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000792void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000793 VisitExpr(E);
Douglas Gregor2d2689a2011-07-28 21:16:51 +0000794 E->setSelector(Reader.ReadSelector(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000795 E->setAtLoc(ReadSourceLocation(Record, Idx));
796 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000797}
798
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000799void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000800 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000801 E->setProtocol(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000802 E->setAtLoc(ReadSourceLocation(Record, Idx));
803 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000804}
805
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000806void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000807 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000808 E->setDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000809 E->setLocation(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000810 E->setBase(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000811 E->setIsArrow(Record[Idx++]);
812 E->setIsFreeIvar(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000813}
814
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000815void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000816 VisitExpr(E);
John McCall12f78a62010-12-02 01:19:52 +0000817 bool Implicit = Record[Idx++] != 0;
818 if (Implicit) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000819 ObjCMethodDecl *Getter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
820 ObjCMethodDecl *Setter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
John McCall12f78a62010-12-02 01:19:52 +0000821 E->setImplicitProperty(Getter, Setter);
822 } else {
Douglas Gregor409448c2011-07-21 22:35:25 +0000823 E->setExplicitProperty(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000824 }
Sebastian Redlc3632732010-10-05 15:59:54 +0000825 E->setLocation(ReadSourceLocation(Record, Idx));
John McCall12f78a62010-12-02 01:19:52 +0000826 E->setReceiverLocation(ReadSourceLocation(Record, Idx));
827 switch (Record[Idx++]) {
828 case 0:
829 E->setBase(Reader.ReadSubExpr());
830 break;
831 case 1:
Douglas Gregor393f2492011-07-22 00:38:23 +0000832 E->setSuperReceiver(Reader.readType(F, Record, Idx));
John McCall12f78a62010-12-02 01:19:52 +0000833 break;
834 case 2:
Douglas Gregor409448c2011-07-21 22:35:25 +0000835 E->setClassReceiver(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
John McCall12f78a62010-12-02 01:19:52 +0000836 break;
837 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000838}
839
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000840void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000841 VisitExpr(E);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000842 assert(Record[Idx] == E->getNumArgs());
843 ++Idx;
John McCallf85e1932011-06-15 23:02:42 +0000844 E->setDelegateInitCall(Record[Idx++]);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000845 ObjCMessageExpr::ReceiverKind Kind
846 = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
847 switch (Kind) {
848 case ObjCMessageExpr::Instance:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000849 E->setInstanceReceiver(Reader.ReadSubExpr());
Douglas Gregor04badcf2010-04-21 00:45:42 +0000850 break;
851
852 case ObjCMessageExpr::Class:
Sebastian Redlc3632732010-10-05 15:59:54 +0000853 E->setClassReceiver(GetTypeSourceInfo(Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000854 break;
855
856 case ObjCMessageExpr::SuperClass:
857 case ObjCMessageExpr::SuperInstance: {
Douglas Gregor393f2492011-07-22 00:38:23 +0000858 QualType T = Reader.readType(F, Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000859 SourceLocation SuperLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000860 E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
861 break;
862 }
863 }
864
865 assert(Kind == E->getReceiverKind());
866
867 if (Record[Idx++])
Douglas Gregor409448c2011-07-21 22:35:25 +0000868 E->setMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000869 else
Douglas Gregor2d2689a2011-07-28 21:16:51 +0000870 E->setSelector(Reader.ReadSelector(F, Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000871
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +0000872 E->LBracLoc = ReadSourceLocation(Record, Idx);
873 E->RBracLoc = ReadSourceLocation(Record, Idx);
874 E->SelectorLoc = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000875
876 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000877 E->setArg(I, Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000878}
879
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000880void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000881 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000882 S->setElement(Reader.ReadSubStmt());
883 S->setCollection(Reader.ReadSubExpr());
884 S->setBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000885 S->setForLoc(ReadSourceLocation(Record, Idx));
886 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000887}
888
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000889void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000890 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000891 S->setCatchBody(Reader.ReadSubStmt());
Douglas Gregor409448c2011-07-21 22:35:25 +0000892 S->setCatchParamDecl(ReadDeclAs<VarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000893 S->setAtCatchLoc(ReadSourceLocation(Record, Idx));
894 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000895}
896
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000897void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000898 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000899 S->setFinallyBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000900 S->setAtFinallyLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000901}
902
John McCallf85e1932011-06-15 23:02:42 +0000903void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
904 VisitStmt(S);
905 S->setSubStmt(Reader.ReadSubStmt());
906 S->setAtLoc(ReadSourceLocation(Record, Idx));
907}
908
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000909void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000910 VisitStmt(S);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000911 assert(Record[Idx] == S->getNumCatchStmts());
912 ++Idx;
913 bool HasFinally = Record[Idx++];
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000914 S->setTryBody(Reader.ReadSubStmt());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000915 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000916 S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt()));
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000917
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000918 if (HasFinally)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000919 S->setFinallyStmt(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000920 S->setAtTryLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000921}
922
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000923void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000924 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000925 S->setSynchExpr(Reader.ReadSubStmt());
926 S->setSynchBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000927 S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000928}
929
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000930void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000931 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000932 S->setThrowExpr(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000933 S->setThrowLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000934}
935
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000936//===----------------------------------------------------------------------===//
937// C++ Expressions and Statements
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000938//===----------------------------------------------------------------------===//
939
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000940void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000941 VisitStmt(S);
Sebastian Redlc3632732010-10-05 15:59:54 +0000942 S->CatchLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000943 S->ExceptionDecl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000944 S->HandlerBlock = Reader.ReadSubStmt();
945}
946
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000947void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000948 VisitStmt(S);
949 assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?");
950 ++Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +0000951 S->TryLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000952 S->getStmts()[0] = Reader.ReadSubStmt();
953 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
954 S->getStmts()[i + 1] = Reader.ReadSubStmt();
955}
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000956
Richard Smithad762fc2011-04-14 22:09:26 +0000957void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
958 VisitStmt(S);
959 S->setForLoc(ReadSourceLocation(Record, Idx));
960 S->setColonLoc(ReadSourceLocation(Record, Idx));
961 S->setRParenLoc(ReadSourceLocation(Record, Idx));
962 S->setRangeStmt(Reader.ReadSubStmt());
963 S->setBeginEndStmt(Reader.ReadSubStmt());
964 S->setCond(Reader.ReadSubExpr());
965 S->setInc(Reader.ReadSubExpr());
966 S->setLoopVarStmt(Reader.ReadSubStmt());
967 S->setBody(Reader.ReadSubStmt());
968}
969
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000970void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000971 VisitCallExpr(E);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000972 E->setOperator((OverloadedOperatorKind)Record[Idx++]);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000973}
974
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000975void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor39da0b82009-09-09 23:08:42 +0000976 VisitExpr(E);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000977 E->NumArgs = Record[Idx++];
978 if (E->NumArgs)
Douglas Gregor35942772011-09-09 21:34:22 +0000979 E->Args = new (Reader.getContext()) Stmt*[E->NumArgs];
Argyrios Kyrtzidis5e1b7c22010-06-24 08:57:09 +0000980 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000981 E->setArg(I, Reader.ReadSubExpr());
Douglas Gregor409448c2011-07-21 22:35:25 +0000982 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000983 E->setLocation(ReadSourceLocation(Record, Idx));
Douglas Gregor39da0b82009-09-09 23:08:42 +0000984 E->setElidable(Record[Idx++]);
Douglas Gregor16006c92009-12-16 18:50:27 +0000985 E->setRequiresZeroInitialization(Record[Idx++]);
Douglas Gregor3c9034c2010-05-15 00:13:29 +0000986 E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
Chandler Carruth428edaf2010-10-25 08:47:36 +0000987 E->ParenRange = ReadSourceRange(Record, Idx);
Douglas Gregor39da0b82009-09-09 23:08:42 +0000988}
Chris Lattner4c6f9522009-04-27 05:14:47 +0000989
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000990void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000991 VisitCXXConstructExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000992 E->Type = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000993}
994
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000995void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000996 VisitExplicitCastExpr(E);
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000997 SourceRange R = ReadSourceRange(Record, Idx);
998 E->Loc = R.getBegin();
999 E->RParenLoc = R.getEnd();
Sam Weinigce757a72010-01-16 21:21:01 +00001000}
1001
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001002void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001003 return VisitCXXNamedCastExpr(E);
1004}
1005
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001006void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001007 return VisitCXXNamedCastExpr(E);
1008}
1009
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001010void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001011 return VisitCXXNamedCastExpr(E);
1012}
1013
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001014void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001015 return VisitCXXNamedCastExpr(E);
1016}
1017
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001018void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001019 VisitExplicitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001020 E->setTypeBeginLoc(ReadSourceLocation(Record, Idx));
1021 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Sam Weinigce757a72010-01-16 21:21:01 +00001022}
1023
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001024void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001025 VisitExpr(E);
1026 E->setValue(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +00001027 E->setLocation(ReadSourceLocation(Record, Idx));
Sam Weinigeb7f9612010-02-07 06:32:43 +00001028}
1029
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001030void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001031 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001032 E->setLocation(ReadSourceLocation(Record, Idx));
Sam Weinigeb7f9612010-02-07 06:32:43 +00001033}
1034
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001035void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner14ab24f2010-05-09 06:03:39 +00001036 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001037 E->setSourceRange(ReadSourceRange(Record, Idx));
Chris Lattner14ab24f2010-05-09 06:03:39 +00001038 if (E->isTypeOperand()) { // typeid(int)
Sebastian Redl577d4792010-07-22 22:43:28 +00001039 E->setTypeOperandSourceInfo(
Sebastian Redlc3632732010-10-05 15:59:54 +00001040 GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001041 return;
Chris Lattner14ab24f2010-05-09 06:03:39 +00001042 }
1043
1044 // typeid(42+2)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001045 E->setExprOperand(Reader.ReadSubExpr());
Chris Lattner14ab24f2010-05-09 06:03:39 +00001046}
1047
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001048void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001049 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001050 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001051 E->setImplicit(Record[Idx++]);
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001052}
1053
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001054void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001055 VisitExpr(E);
Douglas Gregorbca01b42011-07-06 22:04:06 +00001056 E->ThrowLoc = ReadSourceLocation(Record, Idx);
1057 E->Op = Reader.ReadSubExpr();
1058 E->IsThrownVariableInScope = Record[Idx++];
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001059}
Chris Lattner14ab24f2010-05-09 06:03:39 +00001060
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001061void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattner030854b2010-05-09 06:40:08 +00001062 VisitExpr(E);
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001063
1064 assert(Record[Idx] == E->Param.getInt() && "We messed up at creation ?");
1065 ++Idx; // HasOtherExprStored and SubExpr was handled during creation.
Douglas Gregor409448c2011-07-21 22:35:25 +00001066 E->Param.setPointer(ReadDeclAs<ParmVarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +00001067 E->Loc = ReadSourceLocation(Record, Idx);
Chris Lattnerd2598362010-05-10 00:25:06 +00001068}
1069
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001070void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001071 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001072 E->setTemporary(Reader.ReadCXXTemporary(F, Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001073 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattnerd2598362010-05-10 00:25:06 +00001074}
1075
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001076void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001077 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001078 E->TypeInfo = GetTypeSourceInfo(Record, Idx);
1079 E->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner59218632010-05-10 01:22:27 +00001080}
1081
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001082void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001083 VisitExpr(E);
John McCall6ec278d2011-01-27 09:37:56 +00001084 E->GlobalNew = Record[Idx++];
1085 E->Initializer = Record[Idx++];
1086 E->UsualArrayDeleteWantsSize = Record[Idx++];
Chris Lattner59218632010-05-10 01:22:27 +00001087 bool isArray = Record[Idx++];
1088 unsigned NumPlacementArgs = Record[Idx++];
1089 unsigned NumCtorArgs = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001090 E->setOperatorNew(ReadDeclAs<FunctionDecl>(Record, Idx));
1091 E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx));
1092 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +00001093 E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
Douglas Gregor4bd40312010-07-13 15:54:32 +00001094 SourceRange TypeIdParens;
Sebastian Redlc3632732010-10-05 15:59:54 +00001095 TypeIdParens.setBegin(ReadSourceLocation(Record, Idx));
1096 TypeIdParens.setEnd(ReadSourceLocation(Record, Idx));
Douglas Gregor4bd40312010-07-13 15:54:32 +00001097 E->TypeIdParens = TypeIdParens;
Chandler Carruth428edaf2010-10-25 08:47:36 +00001098 E->StartLoc = ReadSourceLocation(Record, Idx);
1099 E->EndLoc = ReadSourceLocation(Record, Idx);
1100 E->ConstructorLParen = ReadSourceLocation(Record, Idx);
1101 E->ConstructorRParen = ReadSourceLocation(Record, Idx);
1102
Douglas Gregor35942772011-09-09 21:34:22 +00001103 E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs,
Chris Lattner59218632010-05-10 01:22:27 +00001104 NumCtorArgs);
1105
1106 // Install all the subexpressions.
Chris Lattner59218632010-05-10 01:22:27 +00001107 for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
1108 I != e; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001109 *I = Reader.ReadSubStmt();
Chris Lattner59218632010-05-10 01:22:27 +00001110}
1111
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001112void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001113 VisitExpr(E);
Argyrios Kyrtzidisf1b89112010-09-13 20:15:40 +00001114 E->GlobalDelete = Record[Idx++];
1115 E->ArrayForm = Record[Idx++];
Argyrios Kyrtzidis4076dac2010-09-13 20:15:54 +00001116 E->ArrayFormAsWritten = Record[Idx++];
John McCall6ec278d2011-01-27 09:37:56 +00001117 E->UsualArrayDeleteWantsSize = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001118 E->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf1b89112010-09-13 20:15:40 +00001119 E->Argument = Reader.ReadSubExpr();
Sebastian Redlc3632732010-10-05 15:59:54 +00001120 E->Loc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001121}
Chris Lattnerd2598362010-05-10 00:25:06 +00001122
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001123void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001124 VisitExpr(E);
1125
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001126 E->Base = Reader.ReadSubExpr();
1127 E->IsArrow = Record[Idx++];
1128 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1129 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1130 E->ScopeType = GetTypeSourceInfo(Record, Idx);
1131 E->ColonColonLoc = ReadSourceLocation(Record, Idx);
1132 E->TildeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001133
Douglas Gregor95eab172011-07-28 20:55:49 +00001134 IdentifierInfo *II = Reader.GetIdentifierInfo(F, Record, Idx);
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001135 if (II)
Sebastian Redlc3632732010-10-05 15:59:54 +00001136 E->setDestroyedType(II, ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001137 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001138 E->setDestroyedType(GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001139}
1140
John McCall4765fa02010-12-06 08:20:24 +00001141void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001142 VisitExpr(E);
1143 unsigned NumTemps = Record[Idx++];
1144 if (NumTemps) {
Douglas Gregor35942772011-09-09 21:34:22 +00001145 E->setNumTemporaries(Reader.getContext(), NumTemps);
Chris Lattnerd2598362010-05-10 00:25:06 +00001146 for (unsigned i = 0; i != NumTemps; ++i)
Douglas Gregor409448c2011-07-21 22:35:25 +00001147 E->setTemporary(i, Reader.ReadCXXTemporary(F, Record, Idx));
Chris Lattnerd2598362010-05-10 00:25:06 +00001148 }
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001149 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner030854b2010-05-09 06:40:08 +00001150}
1151
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001152void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001153ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001154 VisitExpr(E);
1155
Douglas Gregordef03542011-02-04 12:01:24 +00001156 if (Record[Idx++])
John McCall096832c2010-08-19 23:49:38 +00001157 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Douglas Gregordef03542011-02-04 12:01:24 +00001158 Record[Idx++]);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001159
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001160 E->Base = Reader.ReadSubExpr();
Douglas Gregor393f2492011-07-22 00:38:23 +00001161 E->BaseType = Reader.readType(F, Record, Idx);
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001162 E->IsArrow = Record[Idx++];
1163 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1164 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001165 E->FirstQualifierFoundInScope = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001166 ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001167}
1168
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001169void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001170ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001171 VisitExpr(E);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001172
Douglas Gregordef03542011-02-04 12:01:24 +00001173 if (Record[Idx++])
1174 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
1175 Record[Idx++]);
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001176
1177 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001178 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001179}
1180
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001181void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001182ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001183 VisitExpr(E);
1184 assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
1185 ++Idx; // NumArgs;
1186 for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001187 E->setArg(I, Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +00001188 E->Type = GetTypeSourceInfo(Record, Idx);
1189 E->setLParenLoc(ReadSourceLocation(Record, Idx));
1190 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001191}
1192
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001193void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001194 VisitExpr(E);
1195
Douglas Gregordef03542011-02-04 12:01:24 +00001196 // Read the explicit template argument list, if available.
1197 if (Record[Idx++])
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001198 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Douglas Gregordef03542011-02-04 12:01:24 +00001199 Record[Idx++]);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001200
1201 unsigned NumDecls = Record[Idx++];
1202 UnresolvedSet<8> Decls;
1203 for (unsigned i = 0; i != NumDecls; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +00001204 NamedDecl *D = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001205 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1206 Decls.addDecl(D, AS);
1207 }
Douglas Gregor35942772011-09-09 21:34:22 +00001208 E->initializeResults(Reader.getContext(), Decls.begin(), Decls.end());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001209
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001210 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001211 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001212}
1213
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001214void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001215 VisitOverloadExpr(E);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001216 E->IsArrow = Record[Idx++];
1217 E->HasUnresolvedUsing = Record[Idx++];
1218 E->Base = Reader.ReadSubExpr();
Douglas Gregor393f2492011-07-22 00:38:23 +00001219 E->BaseType = Reader.readType(F, Record, Idx);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001220 E->OperatorLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001221}
1222
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001223void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001224 VisitOverloadExpr(E);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001225 E->RequiresADL = Record[Idx++];
Richard Smithad762fc2011-04-14 22:09:26 +00001226 if (E->RequiresADL)
1227 E->StdIsAssociatedNamespace = Record[Idx++];
Douglas Gregor4c9be892011-02-28 20:01:57 +00001228 E->Overloaded = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001229 E->NamingClass = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001230}
1231
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001232void ASTStmtReader::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001233 VisitExpr(E);
1234 E->UTT = (UnaryTypeTrait)Record[Idx++];
Sebastian Redl0dfd8482010-09-13 20:56:31 +00001235 E->Value = (bool)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001236 SourceRange Range = ReadSourceRange(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001237 E->Loc = Range.getBegin();
1238 E->RParen = Range.getEnd();
Sebastian Redlc3632732010-10-05 15:59:54 +00001239 E->QueriedType = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001240}
1241
Francois Pichet6ad6f282010-12-07 00:08:36 +00001242void ASTStmtReader::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
1243 VisitExpr(E);
1244 E->BTT = (BinaryTypeTrait)Record[Idx++];
1245 E->Value = (bool)Record[Idx++];
1246 SourceRange Range = ReadSourceRange(Record, Idx);
1247 E->Loc = Range.getBegin();
1248 E->RParen = Range.getEnd();
1249 E->LhsType = GetTypeSourceInfo(Record, Idx);
1250 E->RhsType = GetTypeSourceInfo(Record, Idx);
1251}
1252
John Wiegley21ff2e52011-04-28 00:16:57 +00001253void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1254 VisitExpr(E);
1255 E->ATT = (ArrayTypeTrait)Record[Idx++];
1256 E->Value = (unsigned int)Record[Idx++];
1257 SourceRange Range = ReadSourceRange(Record, Idx);
1258 E->Loc = Range.getBegin();
1259 E->RParen = Range.getEnd();
1260 E->QueriedType = GetTypeSourceInfo(Record, Idx);
1261}
1262
John Wiegley55262202011-04-25 06:54:41 +00001263void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1264 VisitExpr(E);
1265 E->ET = (ExpressionTrait)Record[Idx++];
1266 E->Value = (bool)Record[Idx++];
1267 SourceRange Range = ReadSourceRange(Record, Idx);
1268 E->QueriedExpression = Reader.ReadSubExpr();
1269 E->Loc = Range.getBegin();
1270 E->RParen = Range.getEnd();
1271}
1272
Sebastian Redl6b219d02010-09-10 20:55:54 +00001273void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1274 VisitExpr(E);
Sebastian Redl5221d8f2010-09-10 22:34:40 +00001275 E->Value = (bool)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001276 E->Range = ReadSourceRange(Record, Idx);
Sebastian Redl5221d8f2010-09-10 22:34:40 +00001277 E->Operand = Reader.ReadSubExpr();
Sebastian Redl6b219d02010-09-10 20:55:54 +00001278}
1279
Douglas Gregorbe230c32011-01-03 17:17:50 +00001280void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
1281 VisitExpr(E);
1282 E->EllipsisLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor67fd1252011-01-14 21:20:45 +00001283 E->NumExpansions = Record[Idx++];
Douglas Gregorbe230c32011-01-03 17:17:50 +00001284 E->Pattern = Reader.ReadSubExpr();
1285}
1286
Douglas Gregoree8aff02011-01-04 17:33:58 +00001287void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1288 VisitExpr(E);
1289 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1290 E->PackLoc = ReadSourceLocation(Record, Idx);
1291 E->RParenLoc = ReadSourceLocation(Record, Idx);
1292 E->Length = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001293 E->Pack = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregoree8aff02011-01-04 17:33:58 +00001294}
1295
John McCall7110fd62011-07-15 07:00:14 +00001296void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
1297 SubstNonTypeTemplateParmExpr *E) {
1298 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001299 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
John McCall7110fd62011-07-15 07:00:14 +00001300 E->NameLoc = ReadSourceLocation(Record, Idx);
1301 E->Replacement = Reader.ReadSubExpr();
1302}
1303
Douglas Gregorc7793c72011-01-15 01:15:58 +00001304void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
1305 SubstNonTypeTemplateParmPackExpr *E) {
1306 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001307 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
Douglas Gregorc7793c72011-01-15 01:15:58 +00001308 TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx);
1309 if (ArgPack.getKind() != TemplateArgument::Pack)
1310 return;
1311
1312 E->Arguments = ArgPack.pack_begin();
1313 E->NumArguments = ArgPack.pack_size();
1314 E->NameLoc = ReadSourceLocation(Record, Idx);
1315}
1316
Douglas Gregor03e80032011-06-21 17:03:29 +00001317void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1318 VisitExpr(E);
1319 E->Temporary = Reader.ReadSubExpr();
1320}
1321
John McCall7cd7d1a2010-11-15 23:31:06 +00001322void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1323 VisitExpr(E);
John McCall56ca35d2011-02-17 10:25:35 +00001324 Idx++; // skip ID
Douglas Gregorb608b982011-01-28 02:26:04 +00001325 E->Loc = ReadSourceLocation(Record, Idx);
John McCall7cd7d1a2010-11-15 23:31:06 +00001326}
1327
Peter Collingbournee08ce652011-02-09 21:07:24 +00001328//===----------------------------------------------------------------------===//
John McCall7110fd62011-07-15 07:00:14 +00001329// Microsoft Expressions and Statements
1330//===----------------------------------------------------------------------===//
1331void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1332 VisitExpr(E);
1333 E->setSourceRange(ReadSourceRange(Record, Idx));
1334 if (E->isTypeOperand()) { // __uuidof(ComType)
1335 E->setTypeOperandSourceInfo(
1336 GetTypeSourceInfo(Record, Idx));
1337 return;
1338 }
1339
1340 // __uuidof(expr)
1341 E->setExprOperand(Reader.ReadSubExpr());
1342}
1343
1344void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
1345 VisitStmt(S);
1346 S->Loc = ReadSourceLocation(Record, Idx);
1347 S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt();
1348 S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt();
1349}
1350
1351void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1352 VisitStmt(S);
1353 S->Loc = ReadSourceLocation(Record, Idx);
1354 S->Block = Reader.ReadSubStmt();
1355}
1356
1357void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
1358 VisitStmt(S);
1359 S->IsCXXTry = Record[Idx++];
1360 S->TryLoc = ReadSourceLocation(Record, Idx);
1361 S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt();
1362 S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
1363}
1364
1365//===----------------------------------------------------------------------===//
Peter Collingbournee08ce652011-02-09 21:07:24 +00001366// CUDA Expressions and Statements
1367//===----------------------------------------------------------------------===//
1368
1369void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1370 VisitCallExpr(E);
1371 E->setConfig(cast<CallExpr>(Reader.ReadSubExpr()));
1372}
1373
John McCall7110fd62011-07-15 07:00:14 +00001374//===----------------------------------------------------------------------===//
1375// OpenCL Expressions and Statements.
1376//===----------------------------------------------------------------------===//
1377void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
1378 VisitExpr(E);
1379 E->BuiltinLoc = ReadSourceLocation(Record, Idx);
1380 E->RParenLoc = ReadSourceLocation(Record, Idx);
1381 E->SrcExpr = Reader.ReadSubExpr();
1382}
1383
1384//===----------------------------------------------------------------------===//
1385// ASTReader Implementation
1386//===----------------------------------------------------------------------===//
1387
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001388Stmt *ASTReader::ReadStmt(Module &F) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001389 switch (ReadingKind) {
1390 case Read_Decl:
1391 case Read_Type:
Sebastian Redlc3632732010-10-05 15:59:54 +00001392 return ReadStmtFromStream(F);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001393 case Read_Stmt:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001394 return ReadSubStmt();
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001395 }
1396
1397 llvm_unreachable("ReadingKind not set ?");
1398 return 0;
1399}
1400
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001401Expr *ASTReader::ReadExpr(Module &F) {
Sebastian Redlc3632732010-10-05 15:59:54 +00001402 return cast_or_null<Expr>(ReadStmt(F));
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001403}
Chris Lattner030854b2010-05-09 06:40:08 +00001404
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001405Expr *ASTReader::ReadSubExpr() {
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001406 return cast_or_null<Expr>(ReadSubStmt());
1407}
1408
Chris Lattner52e97d12009-04-27 05:41:06 +00001409// Within the bitstream, expressions are stored in Reverse Polish
1410// Notation, with each of the subexpressions preceding the
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001411// expression they are stored in. Subexpressions are stored from last to first.
1412// To evaluate expressions, we continue reading expressions and placing them on
1413// the stack, with expressions having operands removing those operands from the
Chris Lattner52e97d12009-04-27 05:41:06 +00001414// stack. Evaluation terminates when we see a STMT_STOP record, and
1415// the single remaining expression on the stack is our result.
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001416Stmt *ASTReader::ReadStmtFromStream(Module &F) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001417
1418 ReadingKindTracker ReadingKind(Read_Stmt, *this);
Sebastian Redlc3632732010-10-05 15:59:54 +00001419 llvm::BitstreamCursor &Cursor = F.DeclsCursor;
1420
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001421#ifndef NDEBUG
1422 unsigned PrevNumStmts = StmtStack.size();
1423#endif
1424
Chris Lattner4c6f9522009-04-27 05:14:47 +00001425 RecordData Record;
1426 unsigned Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +00001427 ASTStmtReader Reader(*this, F, Cursor, Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001428 Stmt::EmptyShell Empty;
1429
1430 while (true) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001431 unsigned Code = Cursor.ReadCode();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001432 if (Code == llvm::bitc::END_BLOCK) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001433 if (Cursor.ReadBlockEnd()) {
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001434 Error("error at end of block in AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001435 return 0;
1436 }
1437 break;
1438 }
1439
1440 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
1441 // No known subblocks, always skip them.
Chris Lattner52e97d12009-04-27 05:41:06 +00001442 Cursor.ReadSubBlockID();
1443 if (Cursor.SkipBlock()) {
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001444 Error("malformed block record in AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001445 return 0;
1446 }
1447 continue;
1448 }
1449
1450 if (Code == llvm::bitc::DEFINE_ABBREV) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001451 Cursor.ReadAbbrevRecord();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001452 continue;
1453 }
1454
1455 Stmt *S = 0;
1456 Idx = 0;
1457 Record.clear();
1458 bool Finished = false;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001459 switch ((StmtCode)Cursor.ReadRecord(Code, Record)) {
1460 case STMT_STOP:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001461 Finished = true;
1462 break;
1463
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001464 case STMT_NULL_PTR:
Mike Stump1eb44332009-09-09 15:08:12 +00001465 S = 0;
Chris Lattner4c6f9522009-04-27 05:14:47 +00001466 break;
1467
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001468 case STMT_NULL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001469 S = new (Context) NullStmt(Empty);
1470 break;
1471
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001472 case STMT_COMPOUND:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001473 S = new (Context) CompoundStmt(Empty);
1474 break;
1475
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001476 case STMT_CASE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001477 S = new (Context) CaseStmt(Empty);
1478 break;
1479
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001480 case STMT_DEFAULT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001481 S = new (Context) DefaultStmt(Empty);
1482 break;
1483
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001484 case STMT_LABEL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001485 S = new (Context) LabelStmt(Empty);
1486 break;
1487
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001488 case STMT_IF:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001489 S = new (Context) IfStmt(Empty);
1490 break;
1491
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001492 case STMT_SWITCH:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001493 S = new (Context) SwitchStmt(Empty);
1494 break;
1495
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001496 case STMT_WHILE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001497 S = new (Context) WhileStmt(Empty);
1498 break;
1499
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001500 case STMT_DO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001501 S = new (Context) DoStmt(Empty);
1502 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001503
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001504 case STMT_FOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001505 S = new (Context) ForStmt(Empty);
1506 break;
1507
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001508 case STMT_GOTO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001509 S = new (Context) GotoStmt(Empty);
1510 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001511
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001512 case STMT_INDIRECT_GOTO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001513 S = new (Context) IndirectGotoStmt(Empty);
1514 break;
1515
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001516 case STMT_CONTINUE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001517 S = new (Context) ContinueStmt(Empty);
1518 break;
1519
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001520 case STMT_BREAK:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001521 S = new (Context) BreakStmt(Empty);
1522 break;
1523
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001524 case STMT_RETURN:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001525 S = new (Context) ReturnStmt(Empty);
1526 break;
1527
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001528 case STMT_DECL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001529 S = new (Context) DeclStmt(Empty);
1530 break;
1531
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001532 case STMT_ASM:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001533 S = new (Context) AsmStmt(Empty);
1534 break;
1535
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001536 case EXPR_PREDEFINED:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001537 S = new (Context) PredefinedExpr(Empty);
1538 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001539
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001540 case EXPR_DECL_REF:
Chandler Carruth3aa81402011-05-01 23:48:14 +00001541 S = DeclRefExpr::CreateEmpty(
Douglas Gregor35942772011-09-09 21:34:22 +00001542 Context,
Chandler Carruth3aa81402011-05-01 23:48:14 +00001543 /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
1544 /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
1545 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2],
1546 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
1547 Record[ASTStmtReader::NumExprFields + 3] : 0);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001548 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001549
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001550 case EXPR_INTEGER_LITERAL:
Douglas Gregor35942772011-09-09 21:34:22 +00001551 S = IntegerLiteral::Create(Context, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001552 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001553
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001554 case EXPR_FLOATING_LITERAL:
Douglas Gregor35942772011-09-09 21:34:22 +00001555 S = FloatingLiteral::Create(Context, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001556 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001557
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001558 case EXPR_IMAGINARY_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001559 S = new (Context) ImaginaryLiteral(Empty);
1560 break;
1561
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001562 case EXPR_STRING_LITERAL:
Douglas Gregor35942772011-09-09 21:34:22 +00001563 S = StringLiteral::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001564 Record[ASTStmtReader::NumExprFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001565 break;
1566
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001567 case EXPR_CHARACTER_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001568 S = new (Context) CharacterLiteral(Empty);
1569 break;
1570
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001571 case EXPR_PAREN:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001572 S = new (Context) ParenExpr(Empty);
1573 break;
1574
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001575 case EXPR_PAREN_LIST:
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +00001576 S = new (Context) ParenListExpr(Empty);
1577 break;
1578
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001579 case EXPR_UNARY_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001580 S = new (Context) UnaryOperator(Empty);
1581 break;
1582
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001583 case EXPR_OFFSETOF:
Douglas Gregor35942772011-09-09 21:34:22 +00001584 S = OffsetOfExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001585 Record[ASTStmtReader::NumExprFields],
1586 Record[ASTStmtReader::NumExprFields + 1]);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001587 break;
1588
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001589 case EXPR_SIZEOF_ALIGN_OF:
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001590 S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001591 break;
1592
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001593 case EXPR_ARRAY_SUBSCRIPT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001594 S = new (Context) ArraySubscriptExpr(Empty);
1595 break;
1596
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001597 case EXPR_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001598 S = new (Context) CallExpr(Context, Stmt::CallExprClass, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001599 break;
1600
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001601 case EXPR_MEMBER: {
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001602 // We load everything here and fully initialize it at creation.
1603 // That way we can use MemberExpr::Create and don't have to duplicate its
1604 // logic with a MemberExpr::CreateEmpty.
1605
1606 assert(Idx == 0);
Douglas Gregor40d96a62011-02-28 21:54:11 +00001607 NestedNameSpecifierLoc QualifierLoc;
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001608 if (Record[Idx++]) { // HasQualifier.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001609 QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001610 }
1611
1612 TemplateArgumentListInfo ArgInfo;
Douglas Gregordef03542011-02-04 12:01:24 +00001613 bool HasExplicitTemplateArgs = Record[Idx++];
1614 if (HasExplicitTemplateArgs) {
1615 unsigned NumTemplateArgs = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001616 ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx));
1617 ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx));
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001618 for (unsigned i = 0; i != NumTemplateArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001619 ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001620 }
1621
Douglas Gregor409448c2011-07-21 22:35:25 +00001622 NamedDecl *FoundD = ReadDeclAs<NamedDecl>(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001623 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1624 DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS);
1625
Douglas Gregor393f2492011-07-22 00:38:23 +00001626 QualType T = readType(F, Record, Idx);
John McCallf89e55a2010-11-18 06:31:45 +00001627 ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]);
1628 ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001629 Expr *Base = ReadSubExpr();
Douglas Gregor409448c2011-07-21 22:35:25 +00001630 ValueDecl *MemberD = ReadDeclAs<ValueDecl>(F, Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +00001631 SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx);
Abramo Bagnara25777432010-08-11 22:01:17 +00001632 DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001633 bool IsArrow = Record[Idx++];
1634
Douglas Gregor35942772011-09-09 21:34:22 +00001635 S = MemberExpr::Create(Context, Base, IsArrow, QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001636 MemberD, FoundDecl, MemberNameInfo,
Douglas Gregordef03542011-02-04 12:01:24 +00001637 HasExplicitTemplateArgs ? &ArgInfo : 0, T, VK, OK);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001638 ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc,
1639 MemberD->getDeclName(), Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001640 break;
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001641 }
Chris Lattner4c6f9522009-04-27 05:14:47 +00001642
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001643 case EXPR_BINARY_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001644 S = new (Context) BinaryOperator(Empty);
1645 break;
1646
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001647 case EXPR_COMPOUND_ASSIGN_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001648 S = new (Context) CompoundAssignOperator(Empty);
1649 break;
1650
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001651 case EXPR_CONDITIONAL_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001652 S = new (Context) ConditionalOperator(Empty);
1653 break;
1654
John McCall56ca35d2011-02-17 10:25:35 +00001655 case EXPR_BINARY_CONDITIONAL_OPERATOR:
1656 S = new (Context) BinaryConditionalOperator(Empty);
1657 break;
1658
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001659 case EXPR_IMPLICIT_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001660 S = ImplicitCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001661 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001662 break;
1663
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001664 case EXPR_CSTYLE_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001665 S = CStyleCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001666 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001667 break;
1668
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001669 case EXPR_COMPOUND_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001670 S = new (Context) CompoundLiteralExpr(Empty);
1671 break;
1672
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001673 case EXPR_EXT_VECTOR_ELEMENT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001674 S = new (Context) ExtVectorElementExpr(Empty);
1675 break;
1676
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001677 case EXPR_INIT_LIST:
Douglas Gregor35942772011-09-09 21:34:22 +00001678 S = new (Context) InitListExpr(getContext(), Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001679 break;
1680
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001681 case EXPR_DESIGNATED_INIT:
Douglas Gregor35942772011-09-09 21:34:22 +00001682 S = DesignatedInitExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001683 Record[ASTStmtReader::NumExprFields] - 1);
Mike Stump1eb44332009-09-09 15:08:12 +00001684
Chris Lattner4c6f9522009-04-27 05:14:47 +00001685 break;
1686
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001687 case EXPR_IMPLICIT_VALUE_INIT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001688 S = new (Context) ImplicitValueInitExpr(Empty);
1689 break;
1690
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001691 case EXPR_VA_ARG:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001692 S = new (Context) VAArgExpr(Empty);
1693 break;
1694
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001695 case EXPR_ADDR_LABEL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001696 S = new (Context) AddrLabelExpr(Empty);
1697 break;
1698
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001699 case EXPR_STMT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001700 S = new (Context) StmtExpr(Empty);
1701 break;
1702
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001703 case EXPR_CHOOSE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001704 S = new (Context) ChooseExpr(Empty);
1705 break;
1706
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001707 case EXPR_GNU_NULL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001708 S = new (Context) GNUNullExpr(Empty);
1709 break;
1710
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001711 case EXPR_SHUFFLE_VECTOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001712 S = new (Context) ShuffleVectorExpr(Empty);
1713 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001714
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001715 case EXPR_BLOCK:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001716 S = new (Context) BlockExpr(Empty);
1717 break;
1718
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001719 case EXPR_BLOCK_DECL_REF:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001720 S = new (Context) BlockDeclRefExpr(Empty);
1721 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001722
Peter Collingbournef111d932011-04-15 00:35:48 +00001723 case EXPR_GENERIC_SELECTION:
1724 S = new (Context) GenericSelectionExpr(Empty);
1725 break;
1726
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001727 case EXPR_OBJC_STRING_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001728 S = new (Context) ObjCStringLiteral(Empty);
1729 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001730 case EXPR_OBJC_ENCODE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001731 S = new (Context) ObjCEncodeExpr(Empty);
1732 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001733 case EXPR_OBJC_SELECTOR_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001734 S = new (Context) ObjCSelectorExpr(Empty);
1735 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001736 case EXPR_OBJC_PROTOCOL_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001737 S = new (Context) ObjCProtocolExpr(Empty);
1738 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001739 case EXPR_OBJC_IVAR_REF_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001740 S = new (Context) ObjCIvarRefExpr(Empty);
1741 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001742 case EXPR_OBJC_PROPERTY_REF_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001743 S = new (Context) ObjCPropertyRefExpr(Empty);
1744 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001745 case EXPR_OBJC_KVC_REF_EXPR:
John McCall12f78a62010-12-02 01:19:52 +00001746 llvm_unreachable("mismatching AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001747 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001748 case EXPR_OBJC_MESSAGE_EXPR:
Douglas Gregor35942772011-09-09 21:34:22 +00001749 S = ObjCMessageExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001750 Record[ASTStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001751 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001752 case EXPR_OBJC_ISA:
Steve Narofff242b1b2009-07-24 17:54:45 +00001753 S = new (Context) ObjCIsaExpr(Empty);
1754 break;
John McCallf85e1932011-06-15 23:02:42 +00001755 case EXPR_OBJC_INDIRECT_COPY_RESTORE:
1756 S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
1757 break;
1758 case EXPR_OBJC_BRIDGED_CAST:
1759 S = new (Context) ObjCBridgedCastExpr(Empty);
1760 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001761 case STMT_OBJC_FOR_COLLECTION:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001762 S = new (Context) ObjCForCollectionStmt(Empty);
1763 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001764 case STMT_OBJC_CATCH:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001765 S = new (Context) ObjCAtCatchStmt(Empty);
1766 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001767 case STMT_OBJC_FINALLY:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001768 S = new (Context) ObjCAtFinallyStmt(Empty);
1769 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001770 case STMT_OBJC_AT_TRY:
Douglas Gregor35942772011-09-09 21:34:22 +00001771 S = ObjCAtTryStmt::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001772 Record[ASTStmtReader::NumStmtFields],
1773 Record[ASTStmtReader::NumStmtFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001774 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001775 case STMT_OBJC_AT_SYNCHRONIZED:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001776 S = new (Context) ObjCAtSynchronizedStmt(Empty);
1777 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001778 case STMT_OBJC_AT_THROW:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001779 S = new (Context) ObjCAtThrowStmt(Empty);
1780 break;
John McCallf85e1932011-06-15 23:02:42 +00001781 case STMT_OBJC_AUTORELEASE_POOL:
1782 S = new (Context) ObjCAutoreleasePoolStmt(Empty);
1783 break;
John McCall7110fd62011-07-15 07:00:14 +00001784 case STMT_SEH_EXCEPT:
1785 S = new (Context) SEHExceptStmt(Empty);
1786 break;
1787 case STMT_SEH_FINALLY:
1788 S = new (Context) SEHFinallyStmt(Empty);
1789 break;
1790 case STMT_SEH_TRY:
1791 S = new (Context) SEHTryStmt(Empty);
1792 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001793 case STMT_CXX_CATCH:
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +00001794 S = new (Context) CXXCatchStmt(Empty);
1795 break;
1796
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001797 case STMT_CXX_TRY:
Douglas Gregor35942772011-09-09 21:34:22 +00001798 S = CXXTryStmt::Create(Context, Empty,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001799 /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +00001800 break;
1801
Richard Smithad762fc2011-04-14 22:09:26 +00001802 case STMT_CXX_FOR_RANGE:
1803 S = new (Context) CXXForRangeStmt(Empty);
1804 break;
1805
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001806 case EXPR_CXX_OPERATOR_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001807 S = new (Context) CXXOperatorCallExpr(Context, Empty);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +00001808 break;
Chris Lattner1817bd42010-05-09 05:36:05 +00001809
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001810 case EXPR_CXX_MEMBER_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001811 S = new (Context) CXXMemberCallExpr(Context, Empty);
Chris Lattner1817bd42010-05-09 05:36:05 +00001812 break;
Douglas Gregor39da0b82009-09-09 23:08:42 +00001813
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001814 case EXPR_CXX_CONSTRUCT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001815 S = new (Context) CXXConstructExpr(Empty);
1816 break;
1817
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001818 case EXPR_CXX_TEMPORARY_OBJECT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001819 S = new (Context) CXXTemporaryObjectExpr(Empty);
Douglas Gregor39da0b82009-09-09 23:08:42 +00001820 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001821
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001822 case EXPR_CXX_STATIC_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001823 S = CXXStaticCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001824 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001825 break;
1826
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001827 case EXPR_CXX_DYNAMIC_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001828 S = CXXDynamicCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001829 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001830 break;
1831
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001832 case EXPR_CXX_REINTERPRET_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001833 S = CXXReinterpretCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001834 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001835 break;
1836
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001837 case EXPR_CXX_CONST_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001838 S = CXXConstCastExpr::CreateEmpty(Context);
Sam Weinigce757a72010-01-16 21:21:01 +00001839 break;
1840
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001841 case EXPR_CXX_FUNCTIONAL_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001842 S = CXXFunctionalCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001843 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001844 break;
1845
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001846 case EXPR_CXX_BOOL_LITERAL:
Sam Weinigeb7f9612010-02-07 06:32:43 +00001847 S = new (Context) CXXBoolLiteralExpr(Empty);
1848 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001849
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001850 case EXPR_CXX_NULL_PTR_LITERAL:
Sam Weinigeb7f9612010-02-07 06:32:43 +00001851 S = new (Context) CXXNullPtrLiteralExpr(Empty);
1852 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001853 case EXPR_CXX_TYPEID_EXPR:
Chris Lattner14ab24f2010-05-09 06:03:39 +00001854 S = new (Context) CXXTypeidExpr(Empty, true);
1855 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001856 case EXPR_CXX_TYPEID_TYPE:
Chris Lattner14ab24f2010-05-09 06:03:39 +00001857 S = new (Context) CXXTypeidExpr(Empty, false);
1858 break;
Francois Pichet01b7c302010-09-08 12:20:18 +00001859 case EXPR_CXX_UUIDOF_EXPR:
1860 S = new (Context) CXXUuidofExpr(Empty, true);
1861 break;
1862 case EXPR_CXX_UUIDOF_TYPE:
1863 S = new (Context) CXXUuidofExpr(Empty, false);
1864 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001865 case EXPR_CXX_THIS:
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001866 S = new (Context) CXXThisExpr(Empty);
1867 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001868 case EXPR_CXX_THROW:
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001869 S = new (Context) CXXThrowExpr(Empty);
1870 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001871 case EXPR_CXX_DEFAULT_ARG: {
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001872 bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields];
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001873 if (HasOtherExprStored) {
1874 Expr *SubExpr = ReadSubExpr();
Douglas Gregor35942772011-09-09 21:34:22 +00001875 S = CXXDefaultArgExpr::Create(Context, SourceLocation(), 0, SubExpr);
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001876 } else
1877 S = new (Context) CXXDefaultArgExpr(Empty);
Chris Lattner030854b2010-05-09 06:40:08 +00001878 break;
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001879 }
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001880 case EXPR_CXX_BIND_TEMPORARY:
Chris Lattnerd2598362010-05-10 00:25:06 +00001881 S = new (Context) CXXBindTemporaryExpr(Empty);
1882 break;
Douglas Gregore2ca6d42010-09-02 21:50:02 +00001883
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001884 case EXPR_CXX_SCALAR_VALUE_INIT:
Douglas Gregored8abf12010-07-08 06:14:04 +00001885 S = new (Context) CXXScalarValueInitExpr(Empty);
Chris Lattner59218632010-05-10 01:22:27 +00001886 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001887 case EXPR_CXX_NEW:
Chris Lattner59218632010-05-10 01:22:27 +00001888 S = new (Context) CXXNewExpr(Empty);
1889 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001890 case EXPR_CXX_DELETE:
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001891 S = new (Context) CXXDeleteExpr(Empty);
1892 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001893 case EXPR_CXX_PSEUDO_DESTRUCTOR:
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001894 S = new (Context) CXXPseudoDestructorExpr(Empty);
1895 break;
Chris Lattner59218632010-05-10 01:22:27 +00001896
John McCall4765fa02010-12-06 08:20:24 +00001897 case EXPR_EXPR_WITH_CLEANUPS:
1898 S = new (Context) ExprWithCleanups(Empty);
Chris Lattnerd2598362010-05-10 00:25:06 +00001899 break;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001900
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001901 case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
Douglas Gregor35942772011-09-09 21:34:22 +00001902 S = CXXDependentScopeMemberExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001903 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1904 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1905 ? Record[ASTStmtReader::NumExprFields + 1]
1906 : 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001907 break;
1908
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001909 case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
Douglas Gregor35942772011-09-09 21:34:22 +00001910 S = DependentScopeDeclRefExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001911 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1912 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1913 ? Record[ASTStmtReader::NumExprFields + 1]
1914 : 0);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001915 break;
1916
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001917 case EXPR_CXX_UNRESOLVED_CONSTRUCT:
Douglas Gregor35942772011-09-09 21:34:22 +00001918 S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001919 /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001920 break;
1921
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001922 case EXPR_CXX_UNRESOLVED_MEMBER:
Douglas Gregor35942772011-09-09 21:34:22 +00001923 S = UnresolvedMemberExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001924 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1925 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1926 ? Record[ASTStmtReader::NumExprFields + 1]
1927 : 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001928 break;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001929
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001930 case EXPR_CXX_UNRESOLVED_LOOKUP:
Douglas Gregor35942772011-09-09 21:34:22 +00001931 S = UnresolvedLookupExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001932 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1933 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1934 ? Record[ASTStmtReader::NumExprFields + 1]
1935 : 0);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001936 break;
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001937
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001938 case EXPR_CXX_UNARY_TYPE_TRAIT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001939 S = new (Context) UnaryTypeTraitExpr(Empty);
1940 break;
Sebastian Redl6b219d02010-09-10 20:55:54 +00001941
Francois Pichetf1872372010-12-08 22:35:30 +00001942 case EXPR_BINARY_TYPE_TRAIT:
Francois Pichet6ad6f282010-12-07 00:08:36 +00001943 S = new (Context) BinaryTypeTraitExpr(Empty);
1944 break;
1945
John Wiegley21ff2e52011-04-28 00:16:57 +00001946 case EXPR_ARRAY_TYPE_TRAIT:
1947 S = new (Context) ArrayTypeTraitExpr(Empty);
1948 break;
1949
John Wiegley55262202011-04-25 06:54:41 +00001950 case EXPR_CXX_EXPRESSION_TRAIT:
1951 S = new (Context) ExpressionTraitExpr(Empty);
1952 break;
1953
Sebastian Redl6b219d02010-09-10 20:55:54 +00001954 case EXPR_CXX_NOEXCEPT:
1955 S = new (Context) CXXNoexceptExpr(Empty);
1956 break;
John McCall7cd7d1a2010-11-15 23:31:06 +00001957
Douglas Gregorbe230c32011-01-03 17:17:50 +00001958 case EXPR_PACK_EXPANSION:
1959 S = new (Context) PackExpansionExpr(Empty);
1960 break;
1961
Douglas Gregoree8aff02011-01-04 17:33:58 +00001962 case EXPR_SIZEOF_PACK:
1963 S = new (Context) SizeOfPackExpr(Empty);
1964 break;
1965
John McCall7110fd62011-07-15 07:00:14 +00001966 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
1967 S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
1968 break;
1969
Douglas Gregorc7793c72011-01-15 01:15:58 +00001970 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
1971 S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
1972 break;
1973
Douglas Gregor03e80032011-06-21 17:03:29 +00001974 case EXPR_MATERIALIZE_TEMPORARY:
1975 S = new (Context) MaterializeTemporaryExpr(Empty);
1976 break;
1977
John McCall56ca35d2011-02-17 10:25:35 +00001978 case EXPR_OPAQUE_VALUE: {
1979 unsigned key = Record[ASTStmtReader::NumExprFields];
1980 OpaqueValueExpr *&expr = OpaqueValueExprs[key];
1981
1982 // If we already have an entry for this opaque value expression,
1983 // don't bother reading it again.
1984 if (expr) {
1985 StmtStack.push_back(expr);
1986 continue;
1987 }
1988
1989 S = expr = new (Context) OpaqueValueExpr(Empty);
John McCall7cd7d1a2010-11-15 23:31:06 +00001990 break;
John McCall56ca35d2011-02-17 10:25:35 +00001991 }
Peter Collingbournee08ce652011-02-09 21:07:24 +00001992
1993 case EXPR_CUDA_KERNEL_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001994 S = new (Context) CUDAKernelCallExpr(Context, Empty);
Peter Collingbournee08ce652011-02-09 21:07:24 +00001995 break;
Tanya Lattner61eee0c2011-06-04 00:47:47 +00001996
1997 case EXPR_ASTYPE:
1998 S = new (Context) AsTypeExpr(Empty);
1999 break;
Chris Lattner4c6f9522009-04-27 05:14:47 +00002000 }
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00002001
Chris Lattner4c6f9522009-04-27 05:14:47 +00002002 // We hit a STMT_STOP, so we're done with this expression.
2003 if (Finished)
2004 break;
2005
2006 ++NumStatementsRead;
2007
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00002008 if (S)
2009 Reader.Visit(S);
Chris Lattner4c6f9522009-04-27 05:14:47 +00002010
2011 assert(Idx == Record.size() && "Invalid deserialization of statement");
2012 StmtStack.push_back(S);
2013 }
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00002014
2015#ifndef NDEBUG
2016 assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!");
2017 assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
2018#endif
2019
2020 return StmtStack.pop_back_val();
Chris Lattner4c6f9522009-04-27 05:14:47 +00002021}