blob: e2a78e9d1eaf481d28096ac70b911cc17bec6801 [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 Kyrtzidisb0c3e092011-09-22 20:07:03 +000083 void ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &ArgList,
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +000084 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 Kyrtzidisb0c3e092011-09-22 20:07:03 +000094ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &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;
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +0000844 unsigned NumStoredSelLocs = Record[Idx++];
845 E->SelLocsKind = Record[Idx++];
John McCallf85e1932011-06-15 23:02:42 +0000846 E->setDelegateInitCall(Record[Idx++]);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000847 ObjCMessageExpr::ReceiverKind Kind
848 = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
849 switch (Kind) {
850 case ObjCMessageExpr::Instance:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000851 E->setInstanceReceiver(Reader.ReadSubExpr());
Douglas Gregor04badcf2010-04-21 00:45:42 +0000852 break;
853
854 case ObjCMessageExpr::Class:
Sebastian Redlc3632732010-10-05 15:59:54 +0000855 E->setClassReceiver(GetTypeSourceInfo(Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000856 break;
857
858 case ObjCMessageExpr::SuperClass:
859 case ObjCMessageExpr::SuperInstance: {
Douglas Gregor393f2492011-07-22 00:38:23 +0000860 QualType T = Reader.readType(F, Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000861 SourceLocation SuperLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000862 E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
863 break;
864 }
865 }
866
867 assert(Kind == E->getReceiverKind());
868
869 if (Record[Idx++])
Douglas Gregor409448c2011-07-21 22:35:25 +0000870 E->setMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000871 else
Douglas Gregor2d2689a2011-07-28 21:16:51 +0000872 E->setSelector(Reader.ReadSelector(F, Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000873
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +0000874 E->LBracLoc = ReadSourceLocation(Record, Idx);
875 E->RBracLoc = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000876
877 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000878 E->setArg(I, Reader.ReadSubExpr());
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +0000879
880 SourceLocation *Locs = E->getStoredSelLocs();
881 for (unsigned I = 0; I != NumStoredSelLocs; ++I)
882 Locs[I] = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000883}
884
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000885void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000886 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000887 S->setElement(Reader.ReadSubStmt());
888 S->setCollection(Reader.ReadSubExpr());
889 S->setBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000890 S->setForLoc(ReadSourceLocation(Record, Idx));
891 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000892}
893
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000894void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000895 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000896 S->setCatchBody(Reader.ReadSubStmt());
Douglas Gregor409448c2011-07-21 22:35:25 +0000897 S->setCatchParamDecl(ReadDeclAs<VarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000898 S->setAtCatchLoc(ReadSourceLocation(Record, Idx));
899 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000900}
901
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000902void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000903 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000904 S->setFinallyBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000905 S->setAtFinallyLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000906}
907
John McCallf85e1932011-06-15 23:02:42 +0000908void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
909 VisitStmt(S);
910 S->setSubStmt(Reader.ReadSubStmt());
911 S->setAtLoc(ReadSourceLocation(Record, Idx));
912}
913
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000914void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000915 VisitStmt(S);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000916 assert(Record[Idx] == S->getNumCatchStmts());
917 ++Idx;
918 bool HasFinally = Record[Idx++];
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000919 S->setTryBody(Reader.ReadSubStmt());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000920 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000921 S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt()));
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000922
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000923 if (HasFinally)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000924 S->setFinallyStmt(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000925 S->setAtTryLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000926}
927
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000928void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000929 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000930 S->setSynchExpr(Reader.ReadSubStmt());
931 S->setSynchBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000932 S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000933}
934
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000935void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000936 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000937 S->setThrowExpr(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000938 S->setThrowLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000939}
940
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000941//===----------------------------------------------------------------------===//
942// C++ Expressions and Statements
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000943//===----------------------------------------------------------------------===//
944
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000945void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000946 VisitStmt(S);
Sebastian Redlc3632732010-10-05 15:59:54 +0000947 S->CatchLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000948 S->ExceptionDecl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000949 S->HandlerBlock = Reader.ReadSubStmt();
950}
951
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000952void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000953 VisitStmt(S);
954 assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?");
955 ++Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +0000956 S->TryLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000957 S->getStmts()[0] = Reader.ReadSubStmt();
958 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
959 S->getStmts()[i + 1] = Reader.ReadSubStmt();
960}
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000961
Richard Smithad762fc2011-04-14 22:09:26 +0000962void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
963 VisitStmt(S);
964 S->setForLoc(ReadSourceLocation(Record, Idx));
965 S->setColonLoc(ReadSourceLocation(Record, Idx));
966 S->setRParenLoc(ReadSourceLocation(Record, Idx));
967 S->setRangeStmt(Reader.ReadSubStmt());
968 S->setBeginEndStmt(Reader.ReadSubStmt());
969 S->setCond(Reader.ReadSubExpr());
970 S->setInc(Reader.ReadSubExpr());
971 S->setLoopVarStmt(Reader.ReadSubStmt());
972 S->setBody(Reader.ReadSubStmt());
973}
974
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000975void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000976 VisitCallExpr(E);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000977 E->setOperator((OverloadedOperatorKind)Record[Idx++]);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000978}
979
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000980void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor39da0b82009-09-09 23:08:42 +0000981 VisitExpr(E);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000982 E->NumArgs = Record[Idx++];
983 if (E->NumArgs)
Douglas Gregor35942772011-09-09 21:34:22 +0000984 E->Args = new (Reader.getContext()) Stmt*[E->NumArgs];
Argyrios Kyrtzidis5e1b7c22010-06-24 08:57:09 +0000985 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000986 E->setArg(I, Reader.ReadSubExpr());
Douglas Gregor409448c2011-07-21 22:35:25 +0000987 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000988 E->setLocation(ReadSourceLocation(Record, Idx));
Douglas Gregor39da0b82009-09-09 23:08:42 +0000989 E->setElidable(Record[Idx++]);
Douglas Gregor16006c92009-12-16 18:50:27 +0000990 E->setRequiresZeroInitialization(Record[Idx++]);
Douglas Gregor3c9034c2010-05-15 00:13:29 +0000991 E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
Chandler Carruth428edaf2010-10-25 08:47:36 +0000992 E->ParenRange = ReadSourceRange(Record, Idx);
Douglas Gregor39da0b82009-09-09 23:08:42 +0000993}
Chris Lattner4c6f9522009-04-27 05:14:47 +0000994
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000995void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000996 VisitCXXConstructExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000997 E->Type = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000998}
999
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001000void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001001 VisitExplicitCastExpr(E);
Douglas Gregor1d5d0b92011-01-12 22:41:29 +00001002 SourceRange R = ReadSourceRange(Record, Idx);
1003 E->Loc = R.getBegin();
1004 E->RParenLoc = R.getEnd();
Sam Weinigce757a72010-01-16 21:21:01 +00001005}
1006
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001007void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001008 return VisitCXXNamedCastExpr(E);
1009}
1010
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001011void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001012 return VisitCXXNamedCastExpr(E);
1013}
1014
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001015void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001016 return VisitCXXNamedCastExpr(E);
1017}
1018
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001019void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001020 return VisitCXXNamedCastExpr(E);
1021}
1022
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001023void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001024 VisitExplicitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001025 E->setTypeBeginLoc(ReadSourceLocation(Record, Idx));
1026 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Sam Weinigce757a72010-01-16 21:21:01 +00001027}
1028
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001029void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001030 VisitExpr(E);
1031 E->setValue(Record[Idx++]);
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::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001036 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001037 E->setLocation(ReadSourceLocation(Record, Idx));
Sam Weinigeb7f9612010-02-07 06:32:43 +00001038}
1039
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001040void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner14ab24f2010-05-09 06:03:39 +00001041 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001042 E->setSourceRange(ReadSourceRange(Record, Idx));
Chris Lattner14ab24f2010-05-09 06:03:39 +00001043 if (E->isTypeOperand()) { // typeid(int)
Sebastian Redl577d4792010-07-22 22:43:28 +00001044 E->setTypeOperandSourceInfo(
Sebastian Redlc3632732010-10-05 15:59:54 +00001045 GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001046 return;
Chris Lattner14ab24f2010-05-09 06:03:39 +00001047 }
1048
1049 // typeid(42+2)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001050 E->setExprOperand(Reader.ReadSubExpr());
Chris Lattner14ab24f2010-05-09 06:03:39 +00001051}
1052
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001053void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001054 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001055 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001056 E->setImplicit(Record[Idx++]);
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001057}
1058
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001059void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001060 VisitExpr(E);
Douglas Gregorbca01b42011-07-06 22:04:06 +00001061 E->ThrowLoc = ReadSourceLocation(Record, Idx);
1062 E->Op = Reader.ReadSubExpr();
1063 E->IsThrownVariableInScope = Record[Idx++];
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001064}
Chris Lattner14ab24f2010-05-09 06:03:39 +00001065
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001066void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattner030854b2010-05-09 06:40:08 +00001067 VisitExpr(E);
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001068
Douglas Gregordf226552011-09-23 22:07:41 +00001069 assert((bool)Record[Idx] == E->Param.getInt() && "We messed up at creation ?");
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001070 ++Idx; // HasOtherExprStored and SubExpr was handled during creation.
Douglas Gregor409448c2011-07-21 22:35:25 +00001071 E->Param.setPointer(ReadDeclAs<ParmVarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +00001072 E->Loc = ReadSourceLocation(Record, Idx);
Chris Lattnerd2598362010-05-10 00:25:06 +00001073}
1074
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001075void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001076 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001077 E->setTemporary(Reader.ReadCXXTemporary(F, Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001078 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattnerd2598362010-05-10 00:25:06 +00001079}
1080
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001081void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001082 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001083 E->TypeInfo = GetTypeSourceInfo(Record, Idx);
1084 E->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner59218632010-05-10 01:22:27 +00001085}
1086
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001087void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001088 VisitExpr(E);
John McCall6ec278d2011-01-27 09:37:56 +00001089 E->GlobalNew = Record[Idx++];
1090 E->Initializer = Record[Idx++];
1091 E->UsualArrayDeleteWantsSize = Record[Idx++];
Chris Lattner59218632010-05-10 01:22:27 +00001092 bool isArray = Record[Idx++];
1093 unsigned NumPlacementArgs = Record[Idx++];
1094 unsigned NumCtorArgs = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001095 E->setOperatorNew(ReadDeclAs<FunctionDecl>(Record, Idx));
1096 E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx));
1097 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +00001098 E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
Douglas Gregor4bd40312010-07-13 15:54:32 +00001099 SourceRange TypeIdParens;
Sebastian Redlc3632732010-10-05 15:59:54 +00001100 TypeIdParens.setBegin(ReadSourceLocation(Record, Idx));
1101 TypeIdParens.setEnd(ReadSourceLocation(Record, Idx));
Douglas Gregor4bd40312010-07-13 15:54:32 +00001102 E->TypeIdParens = TypeIdParens;
Chandler Carruth428edaf2010-10-25 08:47:36 +00001103 E->StartLoc = ReadSourceLocation(Record, Idx);
1104 E->EndLoc = ReadSourceLocation(Record, Idx);
1105 E->ConstructorLParen = ReadSourceLocation(Record, Idx);
1106 E->ConstructorRParen = ReadSourceLocation(Record, Idx);
1107
Douglas Gregor35942772011-09-09 21:34:22 +00001108 E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs,
Chris Lattner59218632010-05-10 01:22:27 +00001109 NumCtorArgs);
1110
1111 // Install all the subexpressions.
Chris Lattner59218632010-05-10 01:22:27 +00001112 for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
1113 I != e; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001114 *I = Reader.ReadSubStmt();
Chris Lattner59218632010-05-10 01:22:27 +00001115}
1116
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001117void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001118 VisitExpr(E);
Argyrios Kyrtzidisf1b89112010-09-13 20:15:40 +00001119 E->GlobalDelete = Record[Idx++];
1120 E->ArrayForm = Record[Idx++];
Argyrios Kyrtzidis4076dac2010-09-13 20:15:54 +00001121 E->ArrayFormAsWritten = Record[Idx++];
John McCall6ec278d2011-01-27 09:37:56 +00001122 E->UsualArrayDeleteWantsSize = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001123 E->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf1b89112010-09-13 20:15:40 +00001124 E->Argument = Reader.ReadSubExpr();
Sebastian Redlc3632732010-10-05 15:59:54 +00001125 E->Loc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001126}
Chris Lattnerd2598362010-05-10 00:25:06 +00001127
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001128void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001129 VisitExpr(E);
1130
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001131 E->Base = Reader.ReadSubExpr();
1132 E->IsArrow = Record[Idx++];
1133 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1134 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1135 E->ScopeType = GetTypeSourceInfo(Record, Idx);
1136 E->ColonColonLoc = ReadSourceLocation(Record, Idx);
1137 E->TildeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001138
Douglas Gregor95eab172011-07-28 20:55:49 +00001139 IdentifierInfo *II = Reader.GetIdentifierInfo(F, Record, Idx);
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001140 if (II)
Sebastian Redlc3632732010-10-05 15:59:54 +00001141 E->setDestroyedType(II, ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001142 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001143 E->setDestroyedType(GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001144}
1145
John McCall4765fa02010-12-06 08:20:24 +00001146void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001147 VisitExpr(E);
1148 unsigned NumTemps = Record[Idx++];
1149 if (NumTemps) {
Douglas Gregor35942772011-09-09 21:34:22 +00001150 E->setNumTemporaries(Reader.getContext(), NumTemps);
Chris Lattnerd2598362010-05-10 00:25:06 +00001151 for (unsigned i = 0; i != NumTemps; ++i)
Douglas Gregor409448c2011-07-21 22:35:25 +00001152 E->setTemporary(i, Reader.ReadCXXTemporary(F, Record, Idx));
Chris Lattnerd2598362010-05-10 00:25:06 +00001153 }
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001154 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner030854b2010-05-09 06:40:08 +00001155}
1156
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001157void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001158ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001159 VisitExpr(E);
1160
Douglas Gregordef03542011-02-04 12:01:24 +00001161 if (Record[Idx++])
John McCall096832c2010-08-19 23:49:38 +00001162 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Douglas Gregordef03542011-02-04 12:01:24 +00001163 Record[Idx++]);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001164
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001165 E->Base = Reader.ReadSubExpr();
Douglas Gregor393f2492011-07-22 00:38:23 +00001166 E->BaseType = Reader.readType(F, Record, Idx);
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001167 E->IsArrow = Record[Idx++];
1168 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1169 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001170 E->FirstQualifierFoundInScope = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001171 ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001172}
1173
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001174void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001175ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001176 VisitExpr(E);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001177
Douglas Gregordef03542011-02-04 12:01:24 +00001178 if (Record[Idx++])
1179 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
1180 Record[Idx++]);
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001181
1182 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001183 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001184}
1185
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001186void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001187ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001188 VisitExpr(E);
1189 assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
1190 ++Idx; // NumArgs;
1191 for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001192 E->setArg(I, Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +00001193 E->Type = GetTypeSourceInfo(Record, Idx);
1194 E->setLParenLoc(ReadSourceLocation(Record, Idx));
1195 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001196}
1197
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001198void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001199 VisitExpr(E);
1200
Douglas Gregordef03542011-02-04 12:01:24 +00001201 // Read the explicit template argument list, if available.
1202 if (Record[Idx++])
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001203 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Douglas Gregordef03542011-02-04 12:01:24 +00001204 Record[Idx++]);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001205
1206 unsigned NumDecls = Record[Idx++];
1207 UnresolvedSet<8> Decls;
1208 for (unsigned i = 0; i != NumDecls; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +00001209 NamedDecl *D = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001210 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1211 Decls.addDecl(D, AS);
1212 }
Douglas Gregor35942772011-09-09 21:34:22 +00001213 E->initializeResults(Reader.getContext(), Decls.begin(), Decls.end());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001214
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001215 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001216 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001217}
1218
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001219void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001220 VisitOverloadExpr(E);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001221 E->IsArrow = Record[Idx++];
1222 E->HasUnresolvedUsing = Record[Idx++];
1223 E->Base = Reader.ReadSubExpr();
Douglas Gregor393f2492011-07-22 00:38:23 +00001224 E->BaseType = Reader.readType(F, Record, Idx);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001225 E->OperatorLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001226}
1227
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001228void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001229 VisitOverloadExpr(E);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001230 E->RequiresADL = Record[Idx++];
Richard Smithad762fc2011-04-14 22:09:26 +00001231 if (E->RequiresADL)
1232 E->StdIsAssociatedNamespace = Record[Idx++];
Douglas Gregor4c9be892011-02-28 20:01:57 +00001233 E->Overloaded = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001234 E->NamingClass = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001235}
1236
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001237void ASTStmtReader::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001238 VisitExpr(E);
1239 E->UTT = (UnaryTypeTrait)Record[Idx++];
Sebastian Redl0dfd8482010-09-13 20:56:31 +00001240 E->Value = (bool)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001241 SourceRange Range = ReadSourceRange(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001242 E->Loc = Range.getBegin();
1243 E->RParen = Range.getEnd();
Sebastian Redlc3632732010-10-05 15:59:54 +00001244 E->QueriedType = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001245}
1246
Francois Pichet6ad6f282010-12-07 00:08:36 +00001247void ASTStmtReader::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
1248 VisitExpr(E);
1249 E->BTT = (BinaryTypeTrait)Record[Idx++];
1250 E->Value = (bool)Record[Idx++];
1251 SourceRange Range = ReadSourceRange(Record, Idx);
1252 E->Loc = Range.getBegin();
1253 E->RParen = Range.getEnd();
1254 E->LhsType = GetTypeSourceInfo(Record, Idx);
1255 E->RhsType = GetTypeSourceInfo(Record, Idx);
1256}
1257
John Wiegley21ff2e52011-04-28 00:16:57 +00001258void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1259 VisitExpr(E);
1260 E->ATT = (ArrayTypeTrait)Record[Idx++];
1261 E->Value = (unsigned int)Record[Idx++];
1262 SourceRange Range = ReadSourceRange(Record, Idx);
1263 E->Loc = Range.getBegin();
1264 E->RParen = Range.getEnd();
1265 E->QueriedType = GetTypeSourceInfo(Record, Idx);
1266}
1267
John Wiegley55262202011-04-25 06:54:41 +00001268void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1269 VisitExpr(E);
1270 E->ET = (ExpressionTrait)Record[Idx++];
1271 E->Value = (bool)Record[Idx++];
1272 SourceRange Range = ReadSourceRange(Record, Idx);
1273 E->QueriedExpression = Reader.ReadSubExpr();
1274 E->Loc = Range.getBegin();
1275 E->RParen = Range.getEnd();
1276}
1277
Sebastian Redl6b219d02010-09-10 20:55:54 +00001278void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1279 VisitExpr(E);
Sebastian Redl5221d8f2010-09-10 22:34:40 +00001280 E->Value = (bool)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001281 E->Range = ReadSourceRange(Record, Idx);
Sebastian Redl5221d8f2010-09-10 22:34:40 +00001282 E->Operand = Reader.ReadSubExpr();
Sebastian Redl6b219d02010-09-10 20:55:54 +00001283}
1284
Douglas Gregorbe230c32011-01-03 17:17:50 +00001285void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
1286 VisitExpr(E);
1287 E->EllipsisLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor67fd1252011-01-14 21:20:45 +00001288 E->NumExpansions = Record[Idx++];
Douglas Gregorbe230c32011-01-03 17:17:50 +00001289 E->Pattern = Reader.ReadSubExpr();
1290}
1291
Douglas Gregoree8aff02011-01-04 17:33:58 +00001292void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1293 VisitExpr(E);
1294 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1295 E->PackLoc = ReadSourceLocation(Record, Idx);
1296 E->RParenLoc = ReadSourceLocation(Record, Idx);
1297 E->Length = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001298 E->Pack = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregoree8aff02011-01-04 17:33:58 +00001299}
1300
John McCall7110fd62011-07-15 07:00:14 +00001301void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
1302 SubstNonTypeTemplateParmExpr *E) {
1303 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001304 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
John McCall7110fd62011-07-15 07:00:14 +00001305 E->NameLoc = ReadSourceLocation(Record, Idx);
1306 E->Replacement = Reader.ReadSubExpr();
1307}
1308
Douglas Gregorc7793c72011-01-15 01:15:58 +00001309void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
1310 SubstNonTypeTemplateParmPackExpr *E) {
1311 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001312 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
Douglas Gregorc7793c72011-01-15 01:15:58 +00001313 TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx);
1314 if (ArgPack.getKind() != TemplateArgument::Pack)
1315 return;
1316
1317 E->Arguments = ArgPack.pack_begin();
1318 E->NumArguments = ArgPack.pack_size();
1319 E->NameLoc = ReadSourceLocation(Record, Idx);
1320}
1321
Douglas Gregor03e80032011-06-21 17:03:29 +00001322void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1323 VisitExpr(E);
1324 E->Temporary = Reader.ReadSubExpr();
1325}
1326
John McCall7cd7d1a2010-11-15 23:31:06 +00001327void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1328 VisitExpr(E);
John McCall56ca35d2011-02-17 10:25:35 +00001329 Idx++; // skip ID
Douglas Gregorb608b982011-01-28 02:26:04 +00001330 E->Loc = ReadSourceLocation(Record, Idx);
John McCall7cd7d1a2010-11-15 23:31:06 +00001331}
1332
Peter Collingbournee08ce652011-02-09 21:07:24 +00001333//===----------------------------------------------------------------------===//
John McCall7110fd62011-07-15 07:00:14 +00001334// Microsoft Expressions and Statements
1335//===----------------------------------------------------------------------===//
1336void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1337 VisitExpr(E);
1338 E->setSourceRange(ReadSourceRange(Record, Idx));
1339 if (E->isTypeOperand()) { // __uuidof(ComType)
1340 E->setTypeOperandSourceInfo(
1341 GetTypeSourceInfo(Record, Idx));
1342 return;
1343 }
1344
1345 // __uuidof(expr)
1346 E->setExprOperand(Reader.ReadSubExpr());
1347}
1348
1349void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
1350 VisitStmt(S);
1351 S->Loc = ReadSourceLocation(Record, Idx);
1352 S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt();
1353 S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt();
1354}
1355
1356void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1357 VisitStmt(S);
1358 S->Loc = ReadSourceLocation(Record, Idx);
1359 S->Block = Reader.ReadSubStmt();
1360}
1361
1362void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
1363 VisitStmt(S);
1364 S->IsCXXTry = Record[Idx++];
1365 S->TryLoc = ReadSourceLocation(Record, Idx);
1366 S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt();
1367 S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
1368}
1369
1370//===----------------------------------------------------------------------===//
Peter Collingbournee08ce652011-02-09 21:07:24 +00001371// CUDA Expressions and Statements
1372//===----------------------------------------------------------------------===//
1373
1374void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1375 VisitCallExpr(E);
1376 E->setConfig(cast<CallExpr>(Reader.ReadSubExpr()));
1377}
1378
John McCall7110fd62011-07-15 07:00:14 +00001379//===----------------------------------------------------------------------===//
1380// OpenCL Expressions and Statements.
1381//===----------------------------------------------------------------------===//
1382void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
1383 VisitExpr(E);
1384 E->BuiltinLoc = ReadSourceLocation(Record, Idx);
1385 E->RParenLoc = ReadSourceLocation(Record, Idx);
1386 E->SrcExpr = Reader.ReadSubExpr();
1387}
1388
1389//===----------------------------------------------------------------------===//
1390// ASTReader Implementation
1391//===----------------------------------------------------------------------===//
1392
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001393Stmt *ASTReader::ReadStmt(Module &F) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001394 switch (ReadingKind) {
1395 case Read_Decl:
1396 case Read_Type:
Sebastian Redlc3632732010-10-05 15:59:54 +00001397 return ReadStmtFromStream(F);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001398 case Read_Stmt:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001399 return ReadSubStmt();
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001400 }
1401
1402 llvm_unreachable("ReadingKind not set ?");
1403 return 0;
1404}
1405
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001406Expr *ASTReader::ReadExpr(Module &F) {
Sebastian Redlc3632732010-10-05 15:59:54 +00001407 return cast_or_null<Expr>(ReadStmt(F));
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001408}
Chris Lattner030854b2010-05-09 06:40:08 +00001409
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001410Expr *ASTReader::ReadSubExpr() {
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001411 return cast_or_null<Expr>(ReadSubStmt());
1412}
1413
Chris Lattner52e97d12009-04-27 05:41:06 +00001414// Within the bitstream, expressions are stored in Reverse Polish
1415// Notation, with each of the subexpressions preceding the
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001416// expression they are stored in. Subexpressions are stored from last to first.
1417// To evaluate expressions, we continue reading expressions and placing them on
1418// the stack, with expressions having operands removing those operands from the
Chris Lattner52e97d12009-04-27 05:41:06 +00001419// stack. Evaluation terminates when we see a STMT_STOP record, and
1420// the single remaining expression on the stack is our result.
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001421Stmt *ASTReader::ReadStmtFromStream(Module &F) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001422
1423 ReadingKindTracker ReadingKind(Read_Stmt, *this);
Sebastian Redlc3632732010-10-05 15:59:54 +00001424 llvm::BitstreamCursor &Cursor = F.DeclsCursor;
1425
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001426#ifndef NDEBUG
1427 unsigned PrevNumStmts = StmtStack.size();
1428#endif
1429
Chris Lattner4c6f9522009-04-27 05:14:47 +00001430 RecordData Record;
1431 unsigned Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +00001432 ASTStmtReader Reader(*this, F, Cursor, Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001433 Stmt::EmptyShell Empty;
1434
1435 while (true) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001436 unsigned Code = Cursor.ReadCode();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001437 if (Code == llvm::bitc::END_BLOCK) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001438 if (Cursor.ReadBlockEnd()) {
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001439 Error("error at end of block in AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001440 return 0;
1441 }
1442 break;
1443 }
1444
1445 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
1446 // No known subblocks, always skip them.
Chris Lattner52e97d12009-04-27 05:41:06 +00001447 Cursor.ReadSubBlockID();
1448 if (Cursor.SkipBlock()) {
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001449 Error("malformed block record in AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001450 return 0;
1451 }
1452 continue;
1453 }
1454
1455 if (Code == llvm::bitc::DEFINE_ABBREV) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001456 Cursor.ReadAbbrevRecord();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001457 continue;
1458 }
1459
1460 Stmt *S = 0;
1461 Idx = 0;
1462 Record.clear();
1463 bool Finished = false;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001464 switch ((StmtCode)Cursor.ReadRecord(Code, Record)) {
1465 case STMT_STOP:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001466 Finished = true;
1467 break;
1468
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001469 case STMT_NULL_PTR:
Mike Stump1eb44332009-09-09 15:08:12 +00001470 S = 0;
Chris Lattner4c6f9522009-04-27 05:14:47 +00001471 break;
1472
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001473 case STMT_NULL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001474 S = new (Context) NullStmt(Empty);
1475 break;
1476
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001477 case STMT_COMPOUND:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001478 S = new (Context) CompoundStmt(Empty);
1479 break;
1480
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001481 case STMT_CASE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001482 S = new (Context) CaseStmt(Empty);
1483 break;
1484
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001485 case STMT_DEFAULT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001486 S = new (Context) DefaultStmt(Empty);
1487 break;
1488
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001489 case STMT_LABEL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001490 S = new (Context) LabelStmt(Empty);
1491 break;
1492
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001493 case STMT_IF:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001494 S = new (Context) IfStmt(Empty);
1495 break;
1496
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001497 case STMT_SWITCH:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001498 S = new (Context) SwitchStmt(Empty);
1499 break;
1500
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001501 case STMT_WHILE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001502 S = new (Context) WhileStmt(Empty);
1503 break;
1504
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001505 case STMT_DO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001506 S = new (Context) DoStmt(Empty);
1507 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001508
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001509 case STMT_FOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001510 S = new (Context) ForStmt(Empty);
1511 break;
1512
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001513 case STMT_GOTO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001514 S = new (Context) GotoStmt(Empty);
1515 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001516
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001517 case STMT_INDIRECT_GOTO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001518 S = new (Context) IndirectGotoStmt(Empty);
1519 break;
1520
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001521 case STMT_CONTINUE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001522 S = new (Context) ContinueStmt(Empty);
1523 break;
1524
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001525 case STMT_BREAK:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001526 S = new (Context) BreakStmt(Empty);
1527 break;
1528
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001529 case STMT_RETURN:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001530 S = new (Context) ReturnStmt(Empty);
1531 break;
1532
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001533 case STMT_DECL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001534 S = new (Context) DeclStmt(Empty);
1535 break;
1536
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001537 case STMT_ASM:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001538 S = new (Context) AsmStmt(Empty);
1539 break;
1540
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001541 case EXPR_PREDEFINED:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001542 S = new (Context) PredefinedExpr(Empty);
1543 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001544
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001545 case EXPR_DECL_REF:
Chandler Carruth3aa81402011-05-01 23:48:14 +00001546 S = DeclRefExpr::CreateEmpty(
Douglas Gregor35942772011-09-09 21:34:22 +00001547 Context,
Chandler Carruth3aa81402011-05-01 23:48:14 +00001548 /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
1549 /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
1550 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2],
1551 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
1552 Record[ASTStmtReader::NumExprFields + 3] : 0);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001553 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001554
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001555 case EXPR_INTEGER_LITERAL:
Douglas Gregor35942772011-09-09 21:34:22 +00001556 S = IntegerLiteral::Create(Context, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001557 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001558
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001559 case EXPR_FLOATING_LITERAL:
Douglas Gregor35942772011-09-09 21:34:22 +00001560 S = FloatingLiteral::Create(Context, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001561 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001562
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001563 case EXPR_IMAGINARY_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001564 S = new (Context) ImaginaryLiteral(Empty);
1565 break;
1566
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001567 case EXPR_STRING_LITERAL:
Douglas Gregor35942772011-09-09 21:34:22 +00001568 S = StringLiteral::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001569 Record[ASTStmtReader::NumExprFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001570 break;
1571
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001572 case EXPR_CHARACTER_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001573 S = new (Context) CharacterLiteral(Empty);
1574 break;
1575
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001576 case EXPR_PAREN:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001577 S = new (Context) ParenExpr(Empty);
1578 break;
1579
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001580 case EXPR_PAREN_LIST:
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +00001581 S = new (Context) ParenListExpr(Empty);
1582 break;
1583
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001584 case EXPR_UNARY_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001585 S = new (Context) UnaryOperator(Empty);
1586 break;
1587
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001588 case EXPR_OFFSETOF:
Douglas Gregor35942772011-09-09 21:34:22 +00001589 S = OffsetOfExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001590 Record[ASTStmtReader::NumExprFields],
1591 Record[ASTStmtReader::NumExprFields + 1]);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001592 break;
1593
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001594 case EXPR_SIZEOF_ALIGN_OF:
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001595 S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001596 break;
1597
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001598 case EXPR_ARRAY_SUBSCRIPT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001599 S = new (Context) ArraySubscriptExpr(Empty);
1600 break;
1601
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001602 case EXPR_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001603 S = new (Context) CallExpr(Context, Stmt::CallExprClass, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001604 break;
1605
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001606 case EXPR_MEMBER: {
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001607 // We load everything here and fully initialize it at creation.
1608 // That way we can use MemberExpr::Create and don't have to duplicate its
1609 // logic with a MemberExpr::CreateEmpty.
1610
1611 assert(Idx == 0);
Douglas Gregor40d96a62011-02-28 21:54:11 +00001612 NestedNameSpecifierLoc QualifierLoc;
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001613 if (Record[Idx++]) { // HasQualifier.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001614 QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001615 }
1616
1617 TemplateArgumentListInfo ArgInfo;
Douglas Gregordef03542011-02-04 12:01:24 +00001618 bool HasExplicitTemplateArgs = Record[Idx++];
1619 if (HasExplicitTemplateArgs) {
1620 unsigned NumTemplateArgs = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001621 ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx));
1622 ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx));
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001623 for (unsigned i = 0; i != NumTemplateArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001624 ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001625 }
1626
Douglas Gregor409448c2011-07-21 22:35:25 +00001627 NamedDecl *FoundD = ReadDeclAs<NamedDecl>(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001628 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1629 DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS);
1630
Douglas Gregor393f2492011-07-22 00:38:23 +00001631 QualType T = readType(F, Record, Idx);
John McCallf89e55a2010-11-18 06:31:45 +00001632 ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]);
1633 ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001634 Expr *Base = ReadSubExpr();
Douglas Gregor409448c2011-07-21 22:35:25 +00001635 ValueDecl *MemberD = ReadDeclAs<ValueDecl>(F, Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +00001636 SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx);
Abramo Bagnara25777432010-08-11 22:01:17 +00001637 DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001638 bool IsArrow = Record[Idx++];
1639
Douglas Gregor35942772011-09-09 21:34:22 +00001640 S = MemberExpr::Create(Context, Base, IsArrow, QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001641 MemberD, FoundDecl, MemberNameInfo,
Douglas Gregordef03542011-02-04 12:01:24 +00001642 HasExplicitTemplateArgs ? &ArgInfo : 0, T, VK, OK);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001643 ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc,
1644 MemberD->getDeclName(), Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001645 break;
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001646 }
Chris Lattner4c6f9522009-04-27 05:14:47 +00001647
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001648 case EXPR_BINARY_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001649 S = new (Context) BinaryOperator(Empty);
1650 break;
1651
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001652 case EXPR_COMPOUND_ASSIGN_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001653 S = new (Context) CompoundAssignOperator(Empty);
1654 break;
1655
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001656 case EXPR_CONDITIONAL_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001657 S = new (Context) ConditionalOperator(Empty);
1658 break;
1659
John McCall56ca35d2011-02-17 10:25:35 +00001660 case EXPR_BINARY_CONDITIONAL_OPERATOR:
1661 S = new (Context) BinaryConditionalOperator(Empty);
1662 break;
1663
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001664 case EXPR_IMPLICIT_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001665 S = ImplicitCastExpr::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_CSTYLE_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001670 S = CStyleCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001671 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001672 break;
1673
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001674 case EXPR_COMPOUND_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001675 S = new (Context) CompoundLiteralExpr(Empty);
1676 break;
1677
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001678 case EXPR_EXT_VECTOR_ELEMENT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001679 S = new (Context) ExtVectorElementExpr(Empty);
1680 break;
1681
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001682 case EXPR_INIT_LIST:
Douglas Gregor35942772011-09-09 21:34:22 +00001683 S = new (Context) InitListExpr(getContext(), Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001684 break;
1685
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001686 case EXPR_DESIGNATED_INIT:
Douglas Gregor35942772011-09-09 21:34:22 +00001687 S = DesignatedInitExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001688 Record[ASTStmtReader::NumExprFields] - 1);
Mike Stump1eb44332009-09-09 15:08:12 +00001689
Chris Lattner4c6f9522009-04-27 05:14:47 +00001690 break;
1691
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001692 case EXPR_IMPLICIT_VALUE_INIT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001693 S = new (Context) ImplicitValueInitExpr(Empty);
1694 break;
1695
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001696 case EXPR_VA_ARG:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001697 S = new (Context) VAArgExpr(Empty);
1698 break;
1699
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001700 case EXPR_ADDR_LABEL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001701 S = new (Context) AddrLabelExpr(Empty);
1702 break;
1703
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001704 case EXPR_STMT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001705 S = new (Context) StmtExpr(Empty);
1706 break;
1707
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001708 case EXPR_CHOOSE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001709 S = new (Context) ChooseExpr(Empty);
1710 break;
1711
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001712 case EXPR_GNU_NULL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001713 S = new (Context) GNUNullExpr(Empty);
1714 break;
1715
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001716 case EXPR_SHUFFLE_VECTOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001717 S = new (Context) ShuffleVectorExpr(Empty);
1718 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001719
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001720 case EXPR_BLOCK:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001721 S = new (Context) BlockExpr(Empty);
1722 break;
1723
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001724 case EXPR_BLOCK_DECL_REF:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001725 S = new (Context) BlockDeclRefExpr(Empty);
1726 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001727
Peter Collingbournef111d932011-04-15 00:35:48 +00001728 case EXPR_GENERIC_SELECTION:
1729 S = new (Context) GenericSelectionExpr(Empty);
1730 break;
1731
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001732 case EXPR_OBJC_STRING_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001733 S = new (Context) ObjCStringLiteral(Empty);
1734 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001735 case EXPR_OBJC_ENCODE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001736 S = new (Context) ObjCEncodeExpr(Empty);
1737 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001738 case EXPR_OBJC_SELECTOR_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001739 S = new (Context) ObjCSelectorExpr(Empty);
1740 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001741 case EXPR_OBJC_PROTOCOL_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001742 S = new (Context) ObjCProtocolExpr(Empty);
1743 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001744 case EXPR_OBJC_IVAR_REF_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001745 S = new (Context) ObjCIvarRefExpr(Empty);
1746 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001747 case EXPR_OBJC_PROPERTY_REF_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001748 S = new (Context) ObjCPropertyRefExpr(Empty);
1749 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001750 case EXPR_OBJC_KVC_REF_EXPR:
John McCall12f78a62010-12-02 01:19:52 +00001751 llvm_unreachable("mismatching AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001752 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001753 case EXPR_OBJC_MESSAGE_EXPR:
Douglas Gregor35942772011-09-09 21:34:22 +00001754 S = ObjCMessageExpr::CreateEmpty(Context,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00001755 Record[ASTStmtReader::NumExprFields],
1756 Record[ASTStmtReader::NumExprFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001757 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001758 case EXPR_OBJC_ISA:
Steve Narofff242b1b2009-07-24 17:54:45 +00001759 S = new (Context) ObjCIsaExpr(Empty);
1760 break;
John McCallf85e1932011-06-15 23:02:42 +00001761 case EXPR_OBJC_INDIRECT_COPY_RESTORE:
1762 S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
1763 break;
1764 case EXPR_OBJC_BRIDGED_CAST:
1765 S = new (Context) ObjCBridgedCastExpr(Empty);
1766 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001767 case STMT_OBJC_FOR_COLLECTION:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001768 S = new (Context) ObjCForCollectionStmt(Empty);
1769 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001770 case STMT_OBJC_CATCH:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001771 S = new (Context) ObjCAtCatchStmt(Empty);
1772 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001773 case STMT_OBJC_FINALLY:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001774 S = new (Context) ObjCAtFinallyStmt(Empty);
1775 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001776 case STMT_OBJC_AT_TRY:
Douglas Gregor35942772011-09-09 21:34:22 +00001777 S = ObjCAtTryStmt::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001778 Record[ASTStmtReader::NumStmtFields],
1779 Record[ASTStmtReader::NumStmtFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001780 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001781 case STMT_OBJC_AT_SYNCHRONIZED:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001782 S = new (Context) ObjCAtSynchronizedStmt(Empty);
1783 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001784 case STMT_OBJC_AT_THROW:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001785 S = new (Context) ObjCAtThrowStmt(Empty);
1786 break;
John McCallf85e1932011-06-15 23:02:42 +00001787 case STMT_OBJC_AUTORELEASE_POOL:
1788 S = new (Context) ObjCAutoreleasePoolStmt(Empty);
1789 break;
John McCall7110fd62011-07-15 07:00:14 +00001790 case STMT_SEH_EXCEPT:
1791 S = new (Context) SEHExceptStmt(Empty);
1792 break;
1793 case STMT_SEH_FINALLY:
1794 S = new (Context) SEHFinallyStmt(Empty);
1795 break;
1796 case STMT_SEH_TRY:
1797 S = new (Context) SEHTryStmt(Empty);
1798 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001799 case STMT_CXX_CATCH:
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +00001800 S = new (Context) CXXCatchStmt(Empty);
1801 break;
1802
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001803 case STMT_CXX_TRY:
Douglas Gregor35942772011-09-09 21:34:22 +00001804 S = CXXTryStmt::Create(Context, Empty,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001805 /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +00001806 break;
1807
Richard Smithad762fc2011-04-14 22:09:26 +00001808 case STMT_CXX_FOR_RANGE:
1809 S = new (Context) CXXForRangeStmt(Empty);
1810 break;
1811
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001812 case EXPR_CXX_OPERATOR_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001813 S = new (Context) CXXOperatorCallExpr(Context, Empty);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +00001814 break;
Chris Lattner1817bd42010-05-09 05:36:05 +00001815
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001816 case EXPR_CXX_MEMBER_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001817 S = new (Context) CXXMemberCallExpr(Context, Empty);
Chris Lattner1817bd42010-05-09 05:36:05 +00001818 break;
Douglas Gregor39da0b82009-09-09 23:08:42 +00001819
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001820 case EXPR_CXX_CONSTRUCT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001821 S = new (Context) CXXConstructExpr(Empty);
1822 break;
1823
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001824 case EXPR_CXX_TEMPORARY_OBJECT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001825 S = new (Context) CXXTemporaryObjectExpr(Empty);
Douglas Gregor39da0b82009-09-09 23:08:42 +00001826 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001827
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001828 case EXPR_CXX_STATIC_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001829 S = CXXStaticCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001830 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001831 break;
1832
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001833 case EXPR_CXX_DYNAMIC_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001834 S = CXXDynamicCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001835 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001836 break;
1837
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001838 case EXPR_CXX_REINTERPRET_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001839 S = CXXReinterpretCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001840 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001841 break;
1842
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001843 case EXPR_CXX_CONST_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001844 S = CXXConstCastExpr::CreateEmpty(Context);
Sam Weinigce757a72010-01-16 21:21:01 +00001845 break;
1846
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001847 case EXPR_CXX_FUNCTIONAL_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001848 S = CXXFunctionalCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001849 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001850 break;
1851
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001852 case EXPR_CXX_BOOL_LITERAL:
Sam Weinigeb7f9612010-02-07 06:32:43 +00001853 S = new (Context) CXXBoolLiteralExpr(Empty);
1854 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001855
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001856 case EXPR_CXX_NULL_PTR_LITERAL:
Sam Weinigeb7f9612010-02-07 06:32:43 +00001857 S = new (Context) CXXNullPtrLiteralExpr(Empty);
1858 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001859 case EXPR_CXX_TYPEID_EXPR:
Chris Lattner14ab24f2010-05-09 06:03:39 +00001860 S = new (Context) CXXTypeidExpr(Empty, true);
1861 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001862 case EXPR_CXX_TYPEID_TYPE:
Chris Lattner14ab24f2010-05-09 06:03:39 +00001863 S = new (Context) CXXTypeidExpr(Empty, false);
1864 break;
Francois Pichet01b7c302010-09-08 12:20:18 +00001865 case EXPR_CXX_UUIDOF_EXPR:
1866 S = new (Context) CXXUuidofExpr(Empty, true);
1867 break;
1868 case EXPR_CXX_UUIDOF_TYPE:
1869 S = new (Context) CXXUuidofExpr(Empty, false);
1870 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001871 case EXPR_CXX_THIS:
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001872 S = new (Context) CXXThisExpr(Empty);
1873 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001874 case EXPR_CXX_THROW:
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001875 S = new (Context) CXXThrowExpr(Empty);
1876 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001877 case EXPR_CXX_DEFAULT_ARG: {
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001878 bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields];
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001879 if (HasOtherExprStored) {
1880 Expr *SubExpr = ReadSubExpr();
Douglas Gregor35942772011-09-09 21:34:22 +00001881 S = CXXDefaultArgExpr::Create(Context, SourceLocation(), 0, SubExpr);
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001882 } else
1883 S = new (Context) CXXDefaultArgExpr(Empty);
Chris Lattner030854b2010-05-09 06:40:08 +00001884 break;
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001885 }
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001886 case EXPR_CXX_BIND_TEMPORARY:
Chris Lattnerd2598362010-05-10 00:25:06 +00001887 S = new (Context) CXXBindTemporaryExpr(Empty);
1888 break;
Douglas Gregore2ca6d42010-09-02 21:50:02 +00001889
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001890 case EXPR_CXX_SCALAR_VALUE_INIT:
Douglas Gregored8abf12010-07-08 06:14:04 +00001891 S = new (Context) CXXScalarValueInitExpr(Empty);
Chris Lattner59218632010-05-10 01:22:27 +00001892 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001893 case EXPR_CXX_NEW:
Chris Lattner59218632010-05-10 01:22:27 +00001894 S = new (Context) CXXNewExpr(Empty);
1895 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001896 case EXPR_CXX_DELETE:
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001897 S = new (Context) CXXDeleteExpr(Empty);
1898 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001899 case EXPR_CXX_PSEUDO_DESTRUCTOR:
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001900 S = new (Context) CXXPseudoDestructorExpr(Empty);
1901 break;
Chris Lattner59218632010-05-10 01:22:27 +00001902
John McCall4765fa02010-12-06 08:20:24 +00001903 case EXPR_EXPR_WITH_CLEANUPS:
1904 S = new (Context) ExprWithCleanups(Empty);
Chris Lattnerd2598362010-05-10 00:25:06 +00001905 break;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001906
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001907 case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
Douglas Gregor35942772011-09-09 21:34:22 +00001908 S = CXXDependentScopeMemberExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001909 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1910 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1911 ? Record[ASTStmtReader::NumExprFields + 1]
1912 : 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001913 break;
1914
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001915 case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
Douglas Gregor35942772011-09-09 21:34:22 +00001916 S = DependentScopeDeclRefExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001917 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1918 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1919 ? Record[ASTStmtReader::NumExprFields + 1]
1920 : 0);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001921 break;
1922
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001923 case EXPR_CXX_UNRESOLVED_CONSTRUCT:
Douglas Gregor35942772011-09-09 21:34:22 +00001924 S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001925 /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001926 break;
1927
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001928 case EXPR_CXX_UNRESOLVED_MEMBER:
Douglas Gregor35942772011-09-09 21:34:22 +00001929 S = UnresolvedMemberExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001930 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1931 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1932 ? Record[ASTStmtReader::NumExprFields + 1]
1933 : 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001934 break;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001935
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001936 case EXPR_CXX_UNRESOLVED_LOOKUP:
Douglas Gregor35942772011-09-09 21:34:22 +00001937 S = UnresolvedLookupExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001938 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1939 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1940 ? Record[ASTStmtReader::NumExprFields + 1]
1941 : 0);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001942 break;
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001943
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001944 case EXPR_CXX_UNARY_TYPE_TRAIT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001945 S = new (Context) UnaryTypeTraitExpr(Empty);
1946 break;
Sebastian Redl6b219d02010-09-10 20:55:54 +00001947
Francois Pichetf1872372010-12-08 22:35:30 +00001948 case EXPR_BINARY_TYPE_TRAIT:
Francois Pichet6ad6f282010-12-07 00:08:36 +00001949 S = new (Context) BinaryTypeTraitExpr(Empty);
1950 break;
1951
John Wiegley21ff2e52011-04-28 00:16:57 +00001952 case EXPR_ARRAY_TYPE_TRAIT:
1953 S = new (Context) ArrayTypeTraitExpr(Empty);
1954 break;
1955
John Wiegley55262202011-04-25 06:54:41 +00001956 case EXPR_CXX_EXPRESSION_TRAIT:
1957 S = new (Context) ExpressionTraitExpr(Empty);
1958 break;
1959
Sebastian Redl6b219d02010-09-10 20:55:54 +00001960 case EXPR_CXX_NOEXCEPT:
1961 S = new (Context) CXXNoexceptExpr(Empty);
1962 break;
John McCall7cd7d1a2010-11-15 23:31:06 +00001963
Douglas Gregorbe230c32011-01-03 17:17:50 +00001964 case EXPR_PACK_EXPANSION:
1965 S = new (Context) PackExpansionExpr(Empty);
1966 break;
1967
Douglas Gregoree8aff02011-01-04 17:33:58 +00001968 case EXPR_SIZEOF_PACK:
1969 S = new (Context) SizeOfPackExpr(Empty);
1970 break;
1971
John McCall7110fd62011-07-15 07:00:14 +00001972 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
1973 S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
1974 break;
1975
Douglas Gregorc7793c72011-01-15 01:15:58 +00001976 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
1977 S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
1978 break;
1979
Douglas Gregor03e80032011-06-21 17:03:29 +00001980 case EXPR_MATERIALIZE_TEMPORARY:
1981 S = new (Context) MaterializeTemporaryExpr(Empty);
1982 break;
1983
John McCall56ca35d2011-02-17 10:25:35 +00001984 case EXPR_OPAQUE_VALUE: {
1985 unsigned key = Record[ASTStmtReader::NumExprFields];
1986 OpaqueValueExpr *&expr = OpaqueValueExprs[key];
1987
1988 // If we already have an entry for this opaque value expression,
1989 // don't bother reading it again.
1990 if (expr) {
1991 StmtStack.push_back(expr);
1992 continue;
1993 }
1994
1995 S = expr = new (Context) OpaqueValueExpr(Empty);
John McCall7cd7d1a2010-11-15 23:31:06 +00001996 break;
John McCall56ca35d2011-02-17 10:25:35 +00001997 }
Peter Collingbournee08ce652011-02-09 21:07:24 +00001998
1999 case EXPR_CUDA_KERNEL_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00002000 S = new (Context) CUDAKernelCallExpr(Context, Empty);
Peter Collingbournee08ce652011-02-09 21:07:24 +00002001 break;
Tanya Lattner61eee0c2011-06-04 00:47:47 +00002002
2003 case EXPR_ASTYPE:
2004 S = new (Context) AsTypeExpr(Empty);
2005 break;
Chris Lattner4c6f9522009-04-27 05:14:47 +00002006 }
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00002007
Chris Lattner4c6f9522009-04-27 05:14:47 +00002008 // We hit a STMT_STOP, so we're done with this expression.
2009 if (Finished)
2010 break;
2011
2012 ++NumStatementsRead;
2013
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00002014 if (S)
2015 Reader.Visit(S);
Chris Lattner4c6f9522009-04-27 05:14:47 +00002016
2017 assert(Idx == Record.size() && "Invalid deserialization of statement");
2018 StmtStack.push_back(S);
2019 }
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00002020
2021#ifndef NDEBUG
2022 assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!");
2023 assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
2024#endif
2025
2026 return StmtStack.pop_back_val();
Chris Lattner4c6f9522009-04-27 05:14:47 +00002027}