blob: 7653d5f2906c4c876e05c3b6deb813cfd178bea5 [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++];
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000330 E->DeclRefExprBits.HadMultipleCandidates = Record[Idx++];
Anders Carlssonb0ca1372011-03-06 18:19:42 +0000331 unsigned NumTemplateArgs = 0;
Chandler Carruthcb66cff2011-05-01 21:29:53 +0000332 if (E->hasExplicitTemplateArgs())
Anders Carlssonb0ca1372011-03-06 18:19:42 +0000333 NumTemplateArgs = Record[Idx++];
334
Chandler Carruthcb66cff2011-05-01 21:29:53 +0000335 if (E->hasQualifier())
Chandler Carruth6857c3e2011-05-01 22:14:37 +0000336 E->getInternalQualifierLoc()
Douglas Gregor40d96a62011-02-28 21:54:11 +0000337 = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000338
Chandler Carruth3aa81402011-05-01 23:48:14 +0000339 if (E->hasFoundDecl())
Douglas Gregor409448c2011-07-21 22:35:25 +0000340 E->getInternalFoundDecl() = ReadDeclAs<NamedDecl>(Record, Idx);
Chandler Carruth3aa81402011-05-01 23:48:14 +0000341
Chandler Carruthcb66cff2011-05-01 21:29:53 +0000342 if (E->hasExplicitTemplateArgs())
John McCall096832c2010-08-19 23:49:38 +0000343 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000344 NumTemplateArgs);
345
Douglas Gregor409448c2011-07-21 22:35:25 +0000346 E->setDecl(ReadDeclAs<ValueDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000347 E->setLocation(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000348 ReadDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000349}
350
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000351void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000352 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000353 E->setLocation(ReadSourceLocation(Record, Idx));
Douglas Gregor35942772011-09-09 21:34:22 +0000354 E->setValue(Reader.getContext(), Reader.ReadAPInt(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000355}
356
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000357void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000358 VisitExpr(E);
Douglas Gregor35942772011-09-09 21:34:22 +0000359 E->setValue(Reader.getContext(), Reader.ReadAPFloat(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000360 E->setExact(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000361 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000362}
363
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000364void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000365 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000366 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000367}
368
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000369void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000370 VisitExpr(E);
371 unsigned Len = Record[Idx++];
Mike Stump1eb44332009-09-09 15:08:12 +0000372 assert(Record[Idx] == E->getNumConcatenated() &&
Chris Lattner4c6f9522009-04-27 05:14:47 +0000373 "Wrong number of concatenated tokens!");
374 ++Idx;
Douglas Gregor5cee1192011-07-27 05:40:30 +0000375 E->Kind = static_cast<StringLiteral::StringKind>(Record[Idx++]);
Anders Carlsson3e2193c2011-04-14 00:40:03 +0000376 E->IsPascal = Record[Idx++];
Chris Lattner4c6f9522009-04-27 05:14:47 +0000377
Mike Stump1eb44332009-09-09 15:08:12 +0000378 // Read string data
Daniel Dunbarb6480232009-09-22 03:27:33 +0000379 llvm::SmallString<16> Str(&Record[Idx], &Record[Idx] + Len);
Douglas Gregor35942772011-09-09 21:34:22 +0000380 E->setString(Reader.getContext(), Str.str());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000381 Idx += Len;
382
383 // Read source locations
384 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000385 E->setStrTokenLoc(I, ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000386}
387
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000388void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000389 VisitExpr(E);
390 E->setValue(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000391 E->setLocation(ReadSourceLocation(Record, Idx));
Douglas Gregor5cee1192011-07-27 05:40:30 +0000392 E->setKind(static_cast<CharacterLiteral::CharacterKind>(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000393}
394
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000395void ASTStmtReader::VisitParenExpr(ParenExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000396 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000397 E->setLParen(ReadSourceLocation(Record, Idx));
398 E->setRParen(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000399 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000400}
401
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000402void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +0000403 VisitExpr(E);
404 unsigned NumExprs = Record[Idx++];
Douglas Gregor35942772011-09-09 21:34:22 +0000405 E->Exprs = new (Reader.getContext()) Stmt*[NumExprs];
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +0000406 for (unsigned i = 0; i != NumExprs; ++i)
407 E->Exprs[i] = Reader.ReadSubStmt();
408 E->NumExprs = NumExprs;
Sebastian Redlc3632732010-10-05 15:59:54 +0000409 E->LParenLoc = ReadSourceLocation(Record, Idx);
410 E->RParenLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +0000411}
412
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000413void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000414 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000415 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000416 E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000417 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000418}
419
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000420void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000421 typedef OffsetOfExpr::OffsetOfNode Node;
422 VisitExpr(E);
423 assert(E->getNumComponents() == Record[Idx]);
424 ++Idx;
425 assert(E->getNumExpressions() == Record[Idx]);
426 ++Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +0000427 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
428 E->setRParenLoc(ReadSourceLocation(Record, Idx));
429 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000430 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
431 Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000432 SourceLocation Start = ReadSourceLocation(Record, Idx);
433 SourceLocation End = ReadSourceLocation(Record, Idx);
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000434 switch (Kind) {
435 case Node::Array:
436 E->setComponent(I, Node(Start, Record[Idx++], End));
437 break;
438
439 case Node::Field:
Douglas Gregor409448c2011-07-21 22:35:25 +0000440 E->setComponent(I, Node(Start, ReadDeclAs<FieldDecl>(Record, Idx), End));
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000441 break;
442
443 case Node::Identifier:
Douglas Gregor95eab172011-07-28 20:55:49 +0000444 E->setComponent(I,
445 Node(Start,
446 Reader.GetIdentifierInfo(F, Record, Idx),
447 End));
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000448 break;
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000449
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000450 case Node::Base: {
Douglas Gregor35942772011-09-09 21:34:22 +0000451 CXXBaseSpecifier *Base = new (Reader.getContext()) CXXBaseSpecifier();
Sebastian Redlc3632732010-10-05 15:59:54 +0000452 *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000453 E->setComponent(I, Node(Base));
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000454 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000455 }
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000456 }
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000457 }
458
459 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000460 E->setIndexExpr(I, Reader.ReadSubExpr());
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000461}
462
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000463void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000464 VisitExpr(E);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000465 E->setKind(static_cast<UnaryExprOrTypeTrait>(Record[Idx++]));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000466 if (Record[Idx] == 0) {
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000467 E->setArgument(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000468 ++Idx;
469 } else {
Sebastian Redlc3632732010-10-05 15:59:54 +0000470 E->setArgument(GetTypeSourceInfo(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000471 }
Sebastian Redlc3632732010-10-05 15:59:54 +0000472 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
473 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000474}
475
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000476void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000477 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000478 E->setLHS(Reader.ReadSubExpr());
479 E->setRHS(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000480 E->setRBracketLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000481}
482
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000483void ASTStmtReader::VisitCallExpr(CallExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000484 VisitExpr(E);
Douglas Gregor35942772011-09-09 21:34:22 +0000485 E->setNumArgs(Reader.getContext(), Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000486 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000487 E->setCallee(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000488 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000489 E->setArg(I, Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000490}
491
John McCall7110fd62011-07-15 07:00:14 +0000492void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
493 VisitCallExpr(E);
494}
495
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000496void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000497 // Don't call VisitExpr, this is fully initialized at creation.
498 assert(E->getStmtClass() == Stmt::MemberExprClass &&
499 "It's a subclass, we must advance Idx!");
Chris Lattner4c6f9522009-04-27 05:14:47 +0000500}
501
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000502void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Narofff242b1b2009-07-24 17:54:45 +0000503 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000504 E->setBase(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000505 E->setIsaMemberLoc(ReadSourceLocation(Record, Idx));
Steve Narofff242b1b2009-07-24 17:54:45 +0000506 E->setArrow(Record[Idx++]);
Steve Narofff242b1b2009-07-24 17:54:45 +0000507}
508
John McCallf85e1932011-06-15 23:02:42 +0000509void ASTStmtReader::
510VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
511 VisitExpr(E);
512 E->Operand = Reader.ReadSubExpr();
513 E->setShouldCopy(Record[Idx++]);
514}
515
516void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
517 VisitExplicitCastExpr(E);
518 E->LParenLoc = ReadSourceLocation(Record, Idx);
519 E->BridgeKeywordLoc = ReadSourceLocation(Record, Idx);
520 E->Kind = Record[Idx++];
521}
522
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000523void ASTStmtReader::VisitCastExpr(CastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000524 VisitExpr(E);
John McCallf871d0c2010-08-07 06:22:56 +0000525 unsigned NumBaseSpecs = Record[Idx++];
526 assert(NumBaseSpecs == E->path_size());
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000527 E->setSubExpr(Reader.ReadSubExpr());
Anders Carlssoncdef2b72009-07-31 00:48:10 +0000528 E->setCastKind((CastExpr::CastKind)Record[Idx++]);
John McCallf871d0c2010-08-07 06:22:56 +0000529 CastExpr::path_iterator BaseI = E->path_begin();
Argyrios Kyrtzidis0745d0a2010-07-02 23:30:27 +0000530 while (NumBaseSpecs--) {
Douglas Gregor35942772011-09-09 21:34:22 +0000531 CXXBaseSpecifier *BaseSpec = new (Reader.getContext()) CXXBaseSpecifier;
Sebastian Redlc3632732010-10-05 15:59:54 +0000532 *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
John McCallf871d0c2010-08-07 06:22:56 +0000533 *BaseI++ = BaseSpec;
Argyrios Kyrtzidis0745d0a2010-07-02 23:30:27 +0000534 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000535}
536
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000537void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000538 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000539 E->setLHS(Reader.ReadSubExpr());
540 E->setRHS(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000541 E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000542 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000543}
544
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000545void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000546 VisitBinaryOperator(E);
Douglas Gregor393f2492011-07-22 00:38:23 +0000547 E->setComputationLHSType(Reader.readType(F, Record, Idx));
548 E->setComputationResultType(Reader.readType(F, Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000549}
550
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000551void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000552 VisitExpr(E);
John McCall56ca35d2011-02-17 10:25:35 +0000553 E->SubExprs[ConditionalOperator::COND] = Reader.ReadSubExpr();
554 E->SubExprs[ConditionalOperator::LHS] = Reader.ReadSubExpr();
555 E->SubExprs[ConditionalOperator::RHS] = Reader.ReadSubExpr();
556 E->QuestionLoc = ReadSourceLocation(Record, Idx);
557 E->ColonLoc = ReadSourceLocation(Record, Idx);
558}
559
560void
561ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
562 VisitExpr(E);
563 E->OpaqueValue = cast<OpaqueValueExpr>(Reader.ReadSubExpr());
564 E->SubExprs[BinaryConditionalOperator::COMMON] = Reader.ReadSubExpr();
565 E->SubExprs[BinaryConditionalOperator::COND] = Reader.ReadSubExpr();
566 E->SubExprs[BinaryConditionalOperator::LHS] = Reader.ReadSubExpr();
567 E->SubExprs[BinaryConditionalOperator::RHS] = Reader.ReadSubExpr();
568 E->QuestionLoc = ReadSourceLocation(Record, Idx);
569 E->ColonLoc = ReadSourceLocation(Record, Idx);
570
571 E->getOpaqueValue()->setSourceExpr(E->getCommon());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000572}
573
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000574void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000575 VisitCastExpr(E);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000576}
577
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000578void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000579 VisitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000580 E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000581}
582
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000583void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000584 VisitExplicitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000585 E->setLParenLoc(ReadSourceLocation(Record, Idx));
586 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000587}
588
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000589void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000590 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000591 E->setLParenLoc(ReadSourceLocation(Record, Idx));
592 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000593 E->setInitializer(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000594 E->setFileScope(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000595}
596
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000597void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000598 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000599 E->setBase(Reader.ReadSubExpr());
Douglas Gregor95eab172011-07-28 20:55:49 +0000600 E->setAccessor(Reader.GetIdentifierInfo(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000601 E->setAccessorLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000602}
603
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000604void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000605 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000606 E->setSyntacticForm(cast_or_null<InitListExpr>(Reader.ReadSubStmt()));
Sebastian Redlc3632732010-10-05 15:59:54 +0000607 E->setLBraceLoc(ReadSourceLocation(Record, Idx));
608 E->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000609 bool isArrayFiller = Record[Idx++];
610 Expr *filler = 0;
611 if (isArrayFiller) {
612 filler = Reader.ReadSubExpr();
613 E->ArrayFillerOrUnionFieldInit = filler;
614 } else
Douglas Gregor409448c2011-07-21 22:35:25 +0000615 E->ArrayFillerOrUnionFieldInit = ReadDeclAs<FieldDecl>(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000616 E->sawArrayRangeDesignator(Record[Idx++]);
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000617 unsigned NumInits = Record[Idx++];
Douglas Gregor35942772011-09-09 21:34:22 +0000618 E->reserveInits(Reader.getContext(), NumInits);
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000619 if (isArrayFiller) {
620 for (unsigned I = 0; I != NumInits; ++I) {
621 Expr *init = Reader.ReadSubExpr();
Douglas Gregor35942772011-09-09 21:34:22 +0000622 E->updateInit(Reader.getContext(), I, init ? init : filler);
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000623 }
624 } else {
625 for (unsigned I = 0; I != NumInits; ++I)
Douglas Gregor35942772011-09-09 21:34:22 +0000626 E->updateInit(Reader.getContext(), I, Reader.ReadSubExpr());
Argyrios Kyrtzidis2ac0b7a2011-04-22 05:29:30 +0000627 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000628}
629
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000630void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000631 typedef DesignatedInitExpr::Designator Designator;
632
633 VisitExpr(E);
634 unsigned NumSubExprs = Record[Idx++];
635 assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
636 for (unsigned I = 0; I != NumSubExprs; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000637 E->setSubExpr(I, Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000638 E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000639 E->setGNUSyntax(Record[Idx++]);
640
Chris Lattner5f9e2722011-07-23 10:55:15 +0000641 SmallVector<Designator, 4> Designators;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000642 while (Idx < Record.size()) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000643 switch ((DesignatorTypes)Record[Idx++]) {
644 case DESIG_FIELD_DECL: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000645 FieldDecl *Field = ReadDeclAs<FieldDecl>(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000646 SourceLocation DotLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000647 = ReadSourceLocation(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000648 SourceLocation FieldLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000649 = ReadSourceLocation(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000650 Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
Chris Lattner4c6f9522009-04-27 05:14:47 +0000651 FieldLoc));
652 Designators.back().setField(Field);
653 break;
654 }
655
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000656 case DESIG_FIELD_NAME: {
Douglas Gregor95eab172011-07-28 20:55:49 +0000657 const IdentifierInfo *Name = Reader.GetIdentifierInfo(F, Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000658 SourceLocation DotLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000659 = ReadSourceLocation(Record, Idx);
Mike Stump1eb44332009-09-09 15:08:12 +0000660 SourceLocation FieldLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000661 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000662 Designators.push_back(Designator(Name, DotLoc, FieldLoc));
663 break;
664 }
Mike Stump1eb44332009-09-09 15:08:12 +0000665
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000666 case DESIG_ARRAY: {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000667 unsigned Index = Record[Idx++];
668 SourceLocation LBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000669 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000670 SourceLocation RBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000671 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000672 Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
673 break;
674 }
675
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000676 case DESIG_ARRAY_RANGE: {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000677 unsigned Index = Record[Idx++];
678 SourceLocation LBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000679 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000680 SourceLocation EllipsisLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000681 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000682 SourceLocation RBracketLoc
Sebastian Redlc3632732010-10-05 15:59:54 +0000683 = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000684 Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
685 RBracketLoc));
686 break;
687 }
688 }
689 }
Douglas Gregor35942772011-09-09 21:34:22 +0000690 E->setDesignators(Reader.getContext(),
Douglas Gregor319d57f2010-01-06 23:17:19 +0000691 Designators.data(), Designators.size());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000692}
693
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000694void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000695 VisitExpr(E);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000696}
697
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000698void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000699 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000700 E->setSubExpr(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000701 E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx));
702 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
703 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000704}
705
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000706void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000707 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000708 E->setAmpAmpLoc(ReadSourceLocation(Record, Idx));
709 E->setLabelLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000710 E->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000711}
712
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000713void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000714 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000715 E->setLParenLoc(ReadSourceLocation(Record, Idx));
716 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000717 E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt()));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000718}
719
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000720void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000721 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000722 E->setCond(Reader.ReadSubExpr());
723 E->setLHS(Reader.ReadSubExpr());
724 E->setRHS(Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +0000725 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
726 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000727}
728
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000729void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000730 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000731 E->setTokenLocation(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000732}
733
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000734void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000735 VisitExpr(E);
Chris Lattner5f9e2722011-07-23 10:55:15 +0000736 SmallVector<Expr *, 16> Exprs;
Chris Lattner4c6f9522009-04-27 05:14:47 +0000737 unsigned NumExprs = Record[Idx++];
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000738 while (NumExprs--)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000739 Exprs.push_back(Reader.ReadSubExpr());
Douglas Gregor35942772011-09-09 21:34:22 +0000740 E->setExprs(Reader.getContext(), Exprs.data(), Exprs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +0000741 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
742 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000743}
744
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000745void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000746 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000747 E->setBlockDecl(ReadDeclAs<BlockDecl>(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000748}
749
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000750void ASTStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000751 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000752 E->setDecl(ReadDeclAs<VarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000753 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000754 E->setByRef(Record[Idx++]);
Fariborz Jahanian9b0b57c2009-06-20 00:02:26 +0000755 E->setConstQualAdded(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000756}
757
Peter Collingbournef111d932011-04-15 00:35:48 +0000758void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
759 VisitExpr(E);
760 E->NumAssocs = Record[Idx++];
Douglas Gregor35942772011-09-09 21:34:22 +0000761 E->AssocTypes = new (Reader.getContext()) TypeSourceInfo*[E->NumAssocs];
Peter Collingbournef111d932011-04-15 00:35:48 +0000762 E->SubExprs =
Douglas Gregor35942772011-09-09 21:34:22 +0000763 new(Reader.getContext()) Stmt*[GenericSelectionExpr::END_EXPR+E->NumAssocs];
Peter Collingbournef111d932011-04-15 00:35:48 +0000764
765 E->SubExprs[GenericSelectionExpr::CONTROLLING] = Reader.ReadSubExpr();
766 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
767 E->AssocTypes[I] = GetTypeSourceInfo(Record, Idx);
768 E->SubExprs[GenericSelectionExpr::END_EXPR+I] = Reader.ReadSubExpr();
769 }
770 E->ResultIndex = Record[Idx++];
771
772 E->GenericLoc = ReadSourceLocation(Record, Idx);
773 E->DefaultLoc = ReadSourceLocation(Record, Idx);
774 E->RParenLoc = ReadSourceLocation(Record, Idx);
775}
776
Chris Lattner4c6f9522009-04-27 05:14:47 +0000777//===----------------------------------------------------------------------===//
778// Objective-C Expressions and Statements
779
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000780void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000781 VisitExpr(E);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000782 E->setString(cast<StringLiteral>(Reader.ReadSubStmt()));
Sebastian Redlc3632732010-10-05 15:59:54 +0000783 E->setAtLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000784}
785
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000786void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000787 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000788 E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
789 E->setAtLoc(ReadSourceLocation(Record, Idx));
790 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000791}
792
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000793void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000794 VisitExpr(E);
Douglas Gregor2d2689a2011-07-28 21:16:51 +0000795 E->setSelector(Reader.ReadSelector(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000796 E->setAtLoc(ReadSourceLocation(Record, Idx));
797 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000798}
799
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000800void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000801 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000802 E->setProtocol(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000803 E->setAtLoc(ReadSourceLocation(Record, Idx));
804 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000805}
806
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000807void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000808 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +0000809 E->setDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000810 E->setLocation(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000811 E->setBase(Reader.ReadSubExpr());
Chris Lattner4c6f9522009-04-27 05:14:47 +0000812 E->setIsArrow(Record[Idx++]);
813 E->setIsFreeIvar(Record[Idx++]);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000814}
815
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000816void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000817 VisitExpr(E);
John McCall12f78a62010-12-02 01:19:52 +0000818 bool Implicit = Record[Idx++] != 0;
819 if (Implicit) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000820 ObjCMethodDecl *Getter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
821 ObjCMethodDecl *Setter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
John McCall12f78a62010-12-02 01:19:52 +0000822 E->setImplicitProperty(Getter, Setter);
823 } else {
Douglas Gregor409448c2011-07-21 22:35:25 +0000824 E->setExplicitProperty(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000825 }
Sebastian Redlc3632732010-10-05 15:59:54 +0000826 E->setLocation(ReadSourceLocation(Record, Idx));
John McCall12f78a62010-12-02 01:19:52 +0000827 E->setReceiverLocation(ReadSourceLocation(Record, Idx));
828 switch (Record[Idx++]) {
829 case 0:
830 E->setBase(Reader.ReadSubExpr());
831 break;
832 case 1:
Douglas Gregor393f2492011-07-22 00:38:23 +0000833 E->setSuperReceiver(Reader.readType(F, Record, Idx));
John McCall12f78a62010-12-02 01:19:52 +0000834 break;
835 case 2:
Douglas Gregor409448c2011-07-21 22:35:25 +0000836 E->setClassReceiver(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
John McCall12f78a62010-12-02 01:19:52 +0000837 break;
838 }
Chris Lattner4c6f9522009-04-27 05:14:47 +0000839}
840
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000841void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000842 VisitExpr(E);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000843 assert(Record[Idx] == E->getNumArgs());
844 ++Idx;
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +0000845 unsigned NumStoredSelLocs = Record[Idx++];
846 E->SelLocsKind = Record[Idx++];
John McCallf85e1932011-06-15 23:02:42 +0000847 E->setDelegateInitCall(Record[Idx++]);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000848 ObjCMessageExpr::ReceiverKind Kind
849 = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
850 switch (Kind) {
851 case ObjCMessageExpr::Instance:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000852 E->setInstanceReceiver(Reader.ReadSubExpr());
Douglas Gregor04badcf2010-04-21 00:45:42 +0000853 break;
854
855 case ObjCMessageExpr::Class:
Sebastian Redlc3632732010-10-05 15:59:54 +0000856 E->setClassReceiver(GetTypeSourceInfo(Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000857 break;
858
859 case ObjCMessageExpr::SuperClass:
860 case ObjCMessageExpr::SuperInstance: {
Douglas Gregor393f2492011-07-22 00:38:23 +0000861 QualType T = Reader.readType(F, Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000862 SourceLocation SuperLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor04badcf2010-04-21 00:45:42 +0000863 E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
864 break;
865 }
866 }
867
868 assert(Kind == E->getReceiverKind());
869
870 if (Record[Idx++])
Douglas Gregor409448c2011-07-21 22:35:25 +0000871 E->setMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000872 else
Douglas Gregor2d2689a2011-07-28 21:16:51 +0000873 E->setSelector(Reader.ReadSelector(F, Record, Idx));
Douglas Gregor04badcf2010-04-21 00:45:42 +0000874
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +0000875 E->LBracLoc = ReadSourceLocation(Record, Idx);
876 E->RBracLoc = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000877
878 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000879 E->setArg(I, Reader.ReadSubExpr());
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +0000880
881 SourceLocation *Locs = E->getStoredSelLocs();
882 for (unsigned I = 0; I != NumStoredSelLocs; ++I)
883 Locs[I] = ReadSourceLocation(Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +0000884}
885
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000886void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000887 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000888 S->setElement(Reader.ReadSubStmt());
889 S->setCollection(Reader.ReadSubExpr());
890 S->setBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000891 S->setForLoc(ReadSourceLocation(Record, Idx));
892 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000893}
894
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000895void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000896 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000897 S->setCatchBody(Reader.ReadSubStmt());
Douglas Gregor409448c2011-07-21 22:35:25 +0000898 S->setCatchParamDecl(ReadDeclAs<VarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000899 S->setAtCatchLoc(ReadSourceLocation(Record, Idx));
900 S->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000901}
902
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000903void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000904 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000905 S->setFinallyBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000906 S->setAtFinallyLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000907}
908
John McCallf85e1932011-06-15 23:02:42 +0000909void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
910 VisitStmt(S);
911 S->setSubStmt(Reader.ReadSubStmt());
912 S->setAtLoc(ReadSourceLocation(Record, Idx));
913}
914
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000915void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000916 VisitStmt(S);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000917 assert(Record[Idx] == S->getNumCatchStmts());
918 ++Idx;
919 bool HasFinally = Record[Idx++];
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000920 S->setTryBody(Reader.ReadSubStmt());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000921 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000922 S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt()));
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000923
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000924 if (HasFinally)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000925 S->setFinallyStmt(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000926 S->setAtTryLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000927}
928
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000929void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000930 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000931 S->setSynchExpr(Reader.ReadSubStmt());
932 S->setSynchBody(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000933 S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000934}
935
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000936void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Chris Lattner4c6f9522009-04-27 05:14:47 +0000937 VisitStmt(S);
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000938 S->setThrowExpr(Reader.ReadSubStmt());
Sebastian Redlc3632732010-10-05 15:59:54 +0000939 S->setThrowLoc(ReadSourceLocation(Record, Idx));
Chris Lattner4c6f9522009-04-27 05:14:47 +0000940}
941
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000942//===----------------------------------------------------------------------===//
943// C++ Expressions and Statements
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000944//===----------------------------------------------------------------------===//
945
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000946void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000947 VisitStmt(S);
Sebastian Redlc3632732010-10-05 15:59:54 +0000948 S->CatchLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000949 S->ExceptionDecl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000950 S->HandlerBlock = Reader.ReadSubStmt();
951}
952
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000953void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000954 VisitStmt(S);
955 assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?");
956 ++Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +0000957 S->TryLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000958 S->getStmts()[0] = Reader.ReadSubStmt();
959 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
960 S->getStmts()[i + 1] = Reader.ReadSubStmt();
961}
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000962
Richard Smithad762fc2011-04-14 22:09:26 +0000963void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
964 VisitStmt(S);
965 S->setForLoc(ReadSourceLocation(Record, Idx));
966 S->setColonLoc(ReadSourceLocation(Record, Idx));
967 S->setRParenLoc(ReadSourceLocation(Record, Idx));
968 S->setRangeStmt(Reader.ReadSubStmt());
969 S->setBeginEndStmt(Reader.ReadSubStmt());
970 S->setCond(Reader.ReadSubExpr());
971 S->setInc(Reader.ReadSubExpr());
972 S->setLoopVarStmt(Reader.ReadSubStmt());
973 S->setBody(Reader.ReadSubStmt());
974}
975
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000976void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000977 VisitCallExpr(E);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000978 E->setOperator((OverloadedOperatorKind)Record[Idx++]);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000979}
980
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000981void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor39da0b82009-09-09 23:08:42 +0000982 VisitExpr(E);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000983 E->NumArgs = Record[Idx++];
984 if (E->NumArgs)
Douglas Gregor35942772011-09-09 21:34:22 +0000985 E->Args = new (Reader.getContext()) Stmt*[E->NumArgs];
Argyrios Kyrtzidis5e1b7c22010-06-24 08:57:09 +0000986 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +0000987 E->setArg(I, Reader.ReadSubExpr());
Douglas Gregor409448c2011-07-21 22:35:25 +0000988 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000989 E->setLocation(ReadSourceLocation(Record, Idx));
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000990 E->setElidable(Record[Idx++]);
991 E->setHadMultipleCandidates(Record[Idx++]);
Douglas Gregor16006c92009-12-16 18:50:27 +0000992 E->setRequiresZeroInitialization(Record[Idx++]);
Douglas Gregor3c9034c2010-05-15 00:13:29 +0000993 E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
Chandler Carruth428edaf2010-10-25 08:47:36 +0000994 E->ParenRange = ReadSourceRange(Record, Idx);
Douglas Gregor39da0b82009-09-09 23:08:42 +0000995}
Chris Lattner4c6f9522009-04-27 05:14:47 +0000996
Sebastian Redl60adf4a2010-08-18 23:56:52 +0000997void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000998 VisitCXXConstructExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +0000999 E->Type = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001000}
1001
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001002void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001003 VisitExplicitCastExpr(E);
Douglas Gregor1d5d0b92011-01-12 22:41:29 +00001004 SourceRange R = ReadSourceRange(Record, Idx);
1005 E->Loc = R.getBegin();
1006 E->RParenLoc = R.getEnd();
Sam Weinigce757a72010-01-16 21:21:01 +00001007}
1008
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001009void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001010 return VisitCXXNamedCastExpr(E);
1011}
1012
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001013void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001014 return VisitCXXNamedCastExpr(E);
1015}
1016
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001017void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001018 return VisitCXXNamedCastExpr(E);
1019}
1020
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001021void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001022 return VisitCXXNamedCastExpr(E);
1023}
1024
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001025void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001026 VisitExplicitCastExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001027 E->setTypeBeginLoc(ReadSourceLocation(Record, Idx));
1028 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Sam Weinigce757a72010-01-16 21:21:01 +00001029}
1030
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001031void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001032 VisitExpr(E);
1033 E->setValue(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +00001034 E->setLocation(ReadSourceLocation(Record, Idx));
Sam Weinigeb7f9612010-02-07 06:32:43 +00001035}
1036
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001037void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001038 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001039 E->setLocation(ReadSourceLocation(Record, Idx));
Sam Weinigeb7f9612010-02-07 06:32:43 +00001040}
1041
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001042void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner14ab24f2010-05-09 06:03:39 +00001043 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001044 E->setSourceRange(ReadSourceRange(Record, Idx));
Chris Lattner14ab24f2010-05-09 06:03:39 +00001045 if (E->isTypeOperand()) { // typeid(int)
Sebastian Redl577d4792010-07-22 22:43:28 +00001046 E->setTypeOperandSourceInfo(
Sebastian Redlc3632732010-10-05 15:59:54 +00001047 GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001048 return;
Chris Lattner14ab24f2010-05-09 06:03:39 +00001049 }
1050
1051 // typeid(42+2)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001052 E->setExprOperand(Reader.ReadSubExpr());
Chris Lattner14ab24f2010-05-09 06:03:39 +00001053}
1054
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001055void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001056 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001057 E->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001058 E->setImplicit(Record[Idx++]);
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001059}
1060
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001061void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001062 VisitExpr(E);
Douglas Gregorbca01b42011-07-06 22:04:06 +00001063 E->ThrowLoc = ReadSourceLocation(Record, Idx);
1064 E->Op = Reader.ReadSubExpr();
1065 E->IsThrownVariableInScope = Record[Idx++];
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001066}
Chris Lattner14ab24f2010-05-09 06:03:39 +00001067
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001068void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattner030854b2010-05-09 06:40:08 +00001069 VisitExpr(E);
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001070
Douglas Gregordf226552011-09-23 22:07:41 +00001071 assert((bool)Record[Idx] == E->Param.getInt() && "We messed up at creation ?");
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001072 ++Idx; // HasOtherExprStored and SubExpr was handled during creation.
Douglas Gregor409448c2011-07-21 22:35:25 +00001073 E->Param.setPointer(ReadDeclAs<ParmVarDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +00001074 E->Loc = ReadSourceLocation(Record, Idx);
Chris Lattnerd2598362010-05-10 00:25:06 +00001075}
1076
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001077void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001078 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001079 E->setTemporary(Reader.ReadCXXTemporary(F, Record, Idx));
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001080 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattnerd2598362010-05-10 00:25:06 +00001081}
1082
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001083void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001084 VisitExpr(E);
Sebastian Redlc3632732010-10-05 15:59:54 +00001085 E->TypeInfo = GetTypeSourceInfo(Record, Idx);
1086 E->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner59218632010-05-10 01:22:27 +00001087}
1088
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001089void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001090 VisitExpr(E);
John McCall6ec278d2011-01-27 09:37:56 +00001091 E->GlobalNew = Record[Idx++];
1092 E->Initializer = Record[Idx++];
1093 E->UsualArrayDeleteWantsSize = Record[Idx++];
Chris Lattner59218632010-05-10 01:22:27 +00001094 bool isArray = Record[Idx++];
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00001095 E->setHadMultipleCandidates(Record[Idx++]);
Chris Lattner59218632010-05-10 01:22:27 +00001096 unsigned NumPlacementArgs = Record[Idx++];
1097 unsigned NumCtorArgs = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001098 E->setOperatorNew(ReadDeclAs<FunctionDecl>(Record, Idx));
1099 E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx));
1100 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +00001101 E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
Douglas Gregor4bd40312010-07-13 15:54:32 +00001102 SourceRange TypeIdParens;
Sebastian Redlc3632732010-10-05 15:59:54 +00001103 TypeIdParens.setBegin(ReadSourceLocation(Record, Idx));
1104 TypeIdParens.setEnd(ReadSourceLocation(Record, Idx));
Douglas Gregor4bd40312010-07-13 15:54:32 +00001105 E->TypeIdParens = TypeIdParens;
Chandler Carruth428edaf2010-10-25 08:47:36 +00001106 E->StartLoc = ReadSourceLocation(Record, Idx);
1107 E->EndLoc = ReadSourceLocation(Record, Idx);
1108 E->ConstructorLParen = ReadSourceLocation(Record, Idx);
1109 E->ConstructorRParen = ReadSourceLocation(Record, Idx);
1110
Douglas Gregor35942772011-09-09 21:34:22 +00001111 E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs,
Chris Lattner59218632010-05-10 01:22:27 +00001112 NumCtorArgs);
1113
1114 // Install all the subexpressions.
Chris Lattner59218632010-05-10 01:22:27 +00001115 for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
1116 I != e; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001117 *I = Reader.ReadSubStmt();
Chris Lattner59218632010-05-10 01:22:27 +00001118}
1119
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001120void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001121 VisitExpr(E);
Argyrios Kyrtzidisf1b89112010-09-13 20:15:40 +00001122 E->GlobalDelete = Record[Idx++];
1123 E->ArrayForm = Record[Idx++];
Argyrios Kyrtzidis4076dac2010-09-13 20:15:54 +00001124 E->ArrayFormAsWritten = Record[Idx++];
John McCall6ec278d2011-01-27 09:37:56 +00001125 E->UsualArrayDeleteWantsSize = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001126 E->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf1b89112010-09-13 20:15:40 +00001127 E->Argument = Reader.ReadSubExpr();
Sebastian Redlc3632732010-10-05 15:59:54 +00001128 E->Loc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001129}
Chris Lattnerd2598362010-05-10 00:25:06 +00001130
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001131void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001132 VisitExpr(E);
1133
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001134 E->Base = Reader.ReadSubExpr();
1135 E->IsArrow = Record[Idx++];
1136 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1137 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1138 E->ScopeType = GetTypeSourceInfo(Record, Idx);
1139 E->ColonColonLoc = ReadSourceLocation(Record, Idx);
1140 E->TildeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001141
Douglas Gregor95eab172011-07-28 20:55:49 +00001142 IdentifierInfo *II = Reader.GetIdentifierInfo(F, Record, Idx);
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001143 if (II)
Sebastian Redlc3632732010-10-05 15:59:54 +00001144 E->setDestroyedType(II, ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001145 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001146 E->setDestroyedType(GetTypeSourceInfo(Record, Idx));
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001147}
1148
John McCall4765fa02010-12-06 08:20:24 +00001149void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001150 VisitExpr(E);
1151 unsigned NumTemps = Record[Idx++];
1152 if (NumTemps) {
Douglas Gregor35942772011-09-09 21:34:22 +00001153 E->setNumTemporaries(Reader.getContext(), NumTemps);
Chris Lattnerd2598362010-05-10 00:25:06 +00001154 for (unsigned i = 0; i != NumTemps; ++i)
Douglas Gregor409448c2011-07-21 22:35:25 +00001155 E->setTemporary(i, Reader.ReadCXXTemporary(F, Record, Idx));
Chris Lattnerd2598362010-05-10 00:25:06 +00001156 }
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001157 E->setSubExpr(Reader.ReadSubExpr());
Chris Lattner030854b2010-05-09 06:40:08 +00001158}
1159
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001160void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001161ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001162 VisitExpr(E);
1163
Douglas Gregordef03542011-02-04 12:01:24 +00001164 if (Record[Idx++])
John McCall096832c2010-08-19 23:49:38 +00001165 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Douglas Gregordef03542011-02-04 12:01:24 +00001166 Record[Idx++]);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001167
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001168 E->Base = Reader.ReadSubExpr();
Douglas Gregor393f2492011-07-22 00:38:23 +00001169 E->BaseType = Reader.readType(F, Record, Idx);
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001170 E->IsArrow = Record[Idx++];
1171 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1172 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001173 E->FirstQualifierFoundInScope = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001174 ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001175}
1176
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001177void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001178ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001179 VisitExpr(E);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001180
Douglas Gregordef03542011-02-04 12:01:24 +00001181 if (Record[Idx++])
1182 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
1183 Record[Idx++]);
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001184
1185 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001186 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001187}
1188
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001189void
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001190ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001191 VisitExpr(E);
1192 assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
1193 ++Idx; // NumArgs;
1194 for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001195 E->setArg(I, Reader.ReadSubExpr());
Sebastian Redlc3632732010-10-05 15:59:54 +00001196 E->Type = GetTypeSourceInfo(Record, Idx);
1197 E->setLParenLoc(ReadSourceLocation(Record, Idx));
1198 E->setRParenLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001199}
1200
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001201void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001202 VisitExpr(E);
1203
Douglas Gregordef03542011-02-04 12:01:24 +00001204 // Read the explicit template argument list, if available.
1205 if (Record[Idx++])
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001206 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Douglas Gregordef03542011-02-04 12:01:24 +00001207 Record[Idx++]);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001208
1209 unsigned NumDecls = Record[Idx++];
1210 UnresolvedSet<8> Decls;
1211 for (unsigned i = 0; i != NumDecls; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +00001212 NamedDecl *D = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001213 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1214 Decls.addDecl(D, AS);
1215 }
Douglas Gregor35942772011-09-09 21:34:22 +00001216 E->initializeResults(Reader.getContext(), Decls.begin(), Decls.end());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001217
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001218 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001219 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001220}
1221
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001222void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001223 VisitOverloadExpr(E);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001224 E->IsArrow = Record[Idx++];
1225 E->HasUnresolvedUsing = Record[Idx++];
1226 E->Base = Reader.ReadSubExpr();
Douglas Gregor393f2492011-07-22 00:38:23 +00001227 E->BaseType = Reader.readType(F, Record, Idx);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001228 E->OperatorLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001229}
1230
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001231void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001232 VisitOverloadExpr(E);
Douglas Gregor4c9be892011-02-28 20:01:57 +00001233 E->RequiresADL = Record[Idx++];
Richard Smithad762fc2011-04-14 22:09:26 +00001234 if (E->RequiresADL)
1235 E->StdIsAssociatedNamespace = Record[Idx++];
Douglas Gregor4c9be892011-02-28 20:01:57 +00001236 E->Overloaded = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001237 E->NamingClass = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001238}
1239
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001240void ASTStmtReader::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001241 VisitExpr(E);
1242 E->UTT = (UnaryTypeTrait)Record[Idx++];
Sebastian Redl0dfd8482010-09-13 20:56:31 +00001243 E->Value = (bool)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001244 SourceRange Range = ReadSourceRange(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001245 E->Loc = Range.getBegin();
1246 E->RParen = Range.getEnd();
Sebastian Redlc3632732010-10-05 15:59:54 +00001247 E->QueriedType = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001248}
1249
Francois Pichet6ad6f282010-12-07 00:08:36 +00001250void ASTStmtReader::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
1251 VisitExpr(E);
1252 E->BTT = (BinaryTypeTrait)Record[Idx++];
1253 E->Value = (bool)Record[Idx++];
1254 SourceRange Range = ReadSourceRange(Record, Idx);
1255 E->Loc = Range.getBegin();
1256 E->RParen = Range.getEnd();
1257 E->LhsType = GetTypeSourceInfo(Record, Idx);
1258 E->RhsType = GetTypeSourceInfo(Record, Idx);
1259}
1260
John Wiegley21ff2e52011-04-28 00:16:57 +00001261void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1262 VisitExpr(E);
1263 E->ATT = (ArrayTypeTrait)Record[Idx++];
1264 E->Value = (unsigned int)Record[Idx++];
1265 SourceRange Range = ReadSourceRange(Record, Idx);
1266 E->Loc = Range.getBegin();
1267 E->RParen = Range.getEnd();
1268 E->QueriedType = GetTypeSourceInfo(Record, Idx);
1269}
1270
John Wiegley55262202011-04-25 06:54:41 +00001271void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1272 VisitExpr(E);
1273 E->ET = (ExpressionTrait)Record[Idx++];
1274 E->Value = (bool)Record[Idx++];
1275 SourceRange Range = ReadSourceRange(Record, Idx);
1276 E->QueriedExpression = Reader.ReadSubExpr();
1277 E->Loc = Range.getBegin();
1278 E->RParen = Range.getEnd();
1279}
1280
Sebastian Redl6b219d02010-09-10 20:55:54 +00001281void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1282 VisitExpr(E);
Sebastian Redl5221d8f2010-09-10 22:34:40 +00001283 E->Value = (bool)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001284 E->Range = ReadSourceRange(Record, Idx);
Sebastian Redl5221d8f2010-09-10 22:34:40 +00001285 E->Operand = Reader.ReadSubExpr();
Sebastian Redl6b219d02010-09-10 20:55:54 +00001286}
1287
Douglas Gregorbe230c32011-01-03 17:17:50 +00001288void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
1289 VisitExpr(E);
1290 E->EllipsisLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor67fd1252011-01-14 21:20:45 +00001291 E->NumExpansions = Record[Idx++];
Douglas Gregorbe230c32011-01-03 17:17:50 +00001292 E->Pattern = Reader.ReadSubExpr();
1293}
1294
Douglas Gregoree8aff02011-01-04 17:33:58 +00001295void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1296 VisitExpr(E);
1297 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1298 E->PackLoc = ReadSourceLocation(Record, Idx);
1299 E->RParenLoc = ReadSourceLocation(Record, Idx);
1300 E->Length = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001301 E->Pack = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregoree8aff02011-01-04 17:33:58 +00001302}
1303
John McCall7110fd62011-07-15 07:00:14 +00001304void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
1305 SubstNonTypeTemplateParmExpr *E) {
1306 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001307 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
John McCall7110fd62011-07-15 07:00:14 +00001308 E->NameLoc = ReadSourceLocation(Record, Idx);
1309 E->Replacement = Reader.ReadSubExpr();
1310}
1311
Douglas Gregorc7793c72011-01-15 01:15:58 +00001312void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
1313 SubstNonTypeTemplateParmPackExpr *E) {
1314 VisitExpr(E);
Douglas Gregor409448c2011-07-21 22:35:25 +00001315 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
Douglas Gregorc7793c72011-01-15 01:15:58 +00001316 TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx);
1317 if (ArgPack.getKind() != TemplateArgument::Pack)
1318 return;
1319
1320 E->Arguments = ArgPack.pack_begin();
1321 E->NumArguments = ArgPack.pack_size();
1322 E->NameLoc = ReadSourceLocation(Record, Idx);
1323}
1324
Douglas Gregor03e80032011-06-21 17:03:29 +00001325void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1326 VisitExpr(E);
1327 E->Temporary = Reader.ReadSubExpr();
1328}
1329
John McCall7cd7d1a2010-11-15 23:31:06 +00001330void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1331 VisitExpr(E);
John McCall56ca35d2011-02-17 10:25:35 +00001332 Idx++; // skip ID
Douglas Gregorb608b982011-01-28 02:26:04 +00001333 E->Loc = ReadSourceLocation(Record, Idx);
John McCall7cd7d1a2010-11-15 23:31:06 +00001334}
1335
Peter Collingbournee08ce652011-02-09 21:07:24 +00001336//===----------------------------------------------------------------------===//
John McCall7110fd62011-07-15 07:00:14 +00001337// Microsoft Expressions and Statements
1338//===----------------------------------------------------------------------===//
1339void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1340 VisitExpr(E);
1341 E->setSourceRange(ReadSourceRange(Record, Idx));
1342 if (E->isTypeOperand()) { // __uuidof(ComType)
1343 E->setTypeOperandSourceInfo(
1344 GetTypeSourceInfo(Record, Idx));
1345 return;
1346 }
1347
1348 // __uuidof(expr)
1349 E->setExprOperand(Reader.ReadSubExpr());
1350}
1351
1352void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
1353 VisitStmt(S);
1354 S->Loc = ReadSourceLocation(Record, Idx);
1355 S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt();
1356 S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt();
1357}
1358
1359void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1360 VisitStmt(S);
1361 S->Loc = ReadSourceLocation(Record, Idx);
1362 S->Block = Reader.ReadSubStmt();
1363}
1364
1365void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
1366 VisitStmt(S);
1367 S->IsCXXTry = Record[Idx++];
1368 S->TryLoc = ReadSourceLocation(Record, Idx);
1369 S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt();
1370 S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
1371}
1372
1373//===----------------------------------------------------------------------===//
Peter Collingbournee08ce652011-02-09 21:07:24 +00001374// CUDA Expressions and Statements
1375//===----------------------------------------------------------------------===//
1376
1377void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1378 VisitCallExpr(E);
1379 E->setConfig(cast<CallExpr>(Reader.ReadSubExpr()));
1380}
1381
John McCall7110fd62011-07-15 07:00:14 +00001382//===----------------------------------------------------------------------===//
1383// OpenCL Expressions and Statements.
1384//===----------------------------------------------------------------------===//
1385void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
1386 VisitExpr(E);
1387 E->BuiltinLoc = ReadSourceLocation(Record, Idx);
1388 E->RParenLoc = ReadSourceLocation(Record, Idx);
1389 E->SrcExpr = Reader.ReadSubExpr();
1390}
1391
1392//===----------------------------------------------------------------------===//
1393// ASTReader Implementation
1394//===----------------------------------------------------------------------===//
1395
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001396Stmt *ASTReader::ReadStmt(Module &F) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001397 switch (ReadingKind) {
1398 case Read_Decl:
1399 case Read_Type:
Sebastian Redlc3632732010-10-05 15:59:54 +00001400 return ReadStmtFromStream(F);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001401 case Read_Stmt:
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001402 return ReadSubStmt();
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001403 }
1404
1405 llvm_unreachable("ReadingKind not set ?");
1406 return 0;
1407}
1408
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001409Expr *ASTReader::ReadExpr(Module &F) {
Sebastian Redlc3632732010-10-05 15:59:54 +00001410 return cast_or_null<Expr>(ReadStmt(F));
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001411}
Chris Lattner030854b2010-05-09 06:40:08 +00001412
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001413Expr *ASTReader::ReadSubExpr() {
Argyrios Kyrtzidisd98a2ab2010-06-29 22:46:25 +00001414 return cast_or_null<Expr>(ReadSubStmt());
1415}
1416
Chris Lattner52e97d12009-04-27 05:41:06 +00001417// Within the bitstream, expressions are stored in Reverse Polish
1418// Notation, with each of the subexpressions preceding the
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001419// expression they are stored in. Subexpressions are stored from last to first.
1420// To evaluate expressions, we continue reading expressions and placing them on
1421// the stack, with expressions having operands removing those operands from the
Chris Lattner52e97d12009-04-27 05:41:06 +00001422// stack. Evaluation terminates when we see a STMT_STOP record, and
1423// the single remaining expression on the stack is our result.
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001424Stmt *ASTReader::ReadStmtFromStream(Module &F) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001425
1426 ReadingKindTracker ReadingKind(Read_Stmt, *this);
Sebastian Redlc3632732010-10-05 15:59:54 +00001427 llvm::BitstreamCursor &Cursor = F.DeclsCursor;
1428
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001429#ifndef NDEBUG
1430 unsigned PrevNumStmts = StmtStack.size();
1431#endif
1432
Chris Lattner4c6f9522009-04-27 05:14:47 +00001433 RecordData Record;
1434 unsigned Idx;
Sebastian Redlc3632732010-10-05 15:59:54 +00001435 ASTStmtReader Reader(*this, F, Cursor, Record, Idx);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001436 Stmt::EmptyShell Empty;
1437
1438 while (true) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001439 unsigned Code = Cursor.ReadCode();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001440 if (Code == llvm::bitc::END_BLOCK) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001441 if (Cursor.ReadBlockEnd()) {
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001442 Error("error at end of block in AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001443 return 0;
1444 }
1445 break;
1446 }
1447
1448 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
1449 // No known subblocks, always skip them.
Chris Lattner52e97d12009-04-27 05:41:06 +00001450 Cursor.ReadSubBlockID();
1451 if (Cursor.SkipBlock()) {
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001452 Error("malformed block record in AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001453 return 0;
1454 }
1455 continue;
1456 }
1457
1458 if (Code == llvm::bitc::DEFINE_ABBREV) {
Chris Lattner52e97d12009-04-27 05:41:06 +00001459 Cursor.ReadAbbrevRecord();
Chris Lattner4c6f9522009-04-27 05:14:47 +00001460 continue;
1461 }
1462
1463 Stmt *S = 0;
1464 Idx = 0;
1465 Record.clear();
1466 bool Finished = false;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001467 switch ((StmtCode)Cursor.ReadRecord(Code, Record)) {
1468 case STMT_STOP:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001469 Finished = true;
1470 break;
1471
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001472 case STMT_NULL_PTR:
Mike Stump1eb44332009-09-09 15:08:12 +00001473 S = 0;
Chris Lattner4c6f9522009-04-27 05:14:47 +00001474 break;
1475
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001476 case STMT_NULL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001477 S = new (Context) NullStmt(Empty);
1478 break;
1479
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001480 case STMT_COMPOUND:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001481 S = new (Context) CompoundStmt(Empty);
1482 break;
1483
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001484 case STMT_CASE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001485 S = new (Context) CaseStmt(Empty);
1486 break;
1487
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001488 case STMT_DEFAULT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001489 S = new (Context) DefaultStmt(Empty);
1490 break;
1491
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001492 case STMT_LABEL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001493 S = new (Context) LabelStmt(Empty);
1494 break;
1495
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001496 case STMT_IF:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001497 S = new (Context) IfStmt(Empty);
1498 break;
1499
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001500 case STMT_SWITCH:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001501 S = new (Context) SwitchStmt(Empty);
1502 break;
1503
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001504 case STMT_WHILE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001505 S = new (Context) WhileStmt(Empty);
1506 break;
1507
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001508 case STMT_DO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001509 S = new (Context) DoStmt(Empty);
1510 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001511
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001512 case STMT_FOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001513 S = new (Context) ForStmt(Empty);
1514 break;
1515
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001516 case STMT_GOTO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001517 S = new (Context) GotoStmt(Empty);
1518 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001519
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001520 case STMT_INDIRECT_GOTO:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001521 S = new (Context) IndirectGotoStmt(Empty);
1522 break;
1523
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001524 case STMT_CONTINUE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001525 S = new (Context) ContinueStmt(Empty);
1526 break;
1527
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001528 case STMT_BREAK:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001529 S = new (Context) BreakStmt(Empty);
1530 break;
1531
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001532 case STMT_RETURN:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001533 S = new (Context) ReturnStmt(Empty);
1534 break;
1535
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001536 case STMT_DECL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001537 S = new (Context) DeclStmt(Empty);
1538 break;
1539
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001540 case STMT_ASM:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001541 S = new (Context) AsmStmt(Empty);
1542 break;
1543
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001544 case EXPR_PREDEFINED:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001545 S = new (Context) PredefinedExpr(Empty);
1546 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001547
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001548 case EXPR_DECL_REF:
Chandler Carruth3aa81402011-05-01 23:48:14 +00001549 S = DeclRefExpr::CreateEmpty(
Douglas Gregor35942772011-09-09 21:34:22 +00001550 Context,
Chandler Carruth3aa81402011-05-01 23:48:14 +00001551 /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
1552 /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
1553 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2],
1554 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00001555 Record[ASTStmtReader::NumExprFields + 4] : 0);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001556 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001557
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001558 case EXPR_INTEGER_LITERAL:
Douglas Gregor35942772011-09-09 21:34:22 +00001559 S = IntegerLiteral::Create(Context, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001560 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001561
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001562 case EXPR_FLOATING_LITERAL:
Douglas Gregor35942772011-09-09 21:34:22 +00001563 S = FloatingLiteral::Create(Context, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001564 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001565
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001566 case EXPR_IMAGINARY_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001567 S = new (Context) ImaginaryLiteral(Empty);
1568 break;
1569
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001570 case EXPR_STRING_LITERAL:
Douglas Gregor35942772011-09-09 21:34:22 +00001571 S = StringLiteral::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001572 Record[ASTStmtReader::NumExprFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001573 break;
1574
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001575 case EXPR_CHARACTER_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001576 S = new (Context) CharacterLiteral(Empty);
1577 break;
1578
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001579 case EXPR_PAREN:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001580 S = new (Context) ParenExpr(Empty);
1581 break;
1582
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001583 case EXPR_PAREN_LIST:
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +00001584 S = new (Context) ParenListExpr(Empty);
1585 break;
1586
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001587 case EXPR_UNARY_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001588 S = new (Context) UnaryOperator(Empty);
1589 break;
1590
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001591 case EXPR_OFFSETOF:
Douglas Gregor35942772011-09-09 21:34:22 +00001592 S = OffsetOfExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001593 Record[ASTStmtReader::NumExprFields],
1594 Record[ASTStmtReader::NumExprFields + 1]);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001595 break;
1596
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001597 case EXPR_SIZEOF_ALIGN_OF:
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001598 S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001599 break;
1600
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001601 case EXPR_ARRAY_SUBSCRIPT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001602 S = new (Context) ArraySubscriptExpr(Empty);
1603 break;
1604
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001605 case EXPR_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001606 S = new (Context) CallExpr(Context, Stmt::CallExprClass, Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001607 break;
1608
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001609 case EXPR_MEMBER: {
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001610 // We load everything here and fully initialize it at creation.
1611 // That way we can use MemberExpr::Create and don't have to duplicate its
1612 // logic with a MemberExpr::CreateEmpty.
1613
1614 assert(Idx == 0);
Douglas Gregor40d96a62011-02-28 21:54:11 +00001615 NestedNameSpecifierLoc QualifierLoc;
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001616 if (Record[Idx++]) { // HasQualifier.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001617 QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001618 }
1619
1620 TemplateArgumentListInfo ArgInfo;
Douglas Gregordef03542011-02-04 12:01:24 +00001621 bool HasExplicitTemplateArgs = Record[Idx++];
1622 if (HasExplicitTemplateArgs) {
1623 unsigned NumTemplateArgs = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001624 ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx));
1625 ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx));
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001626 for (unsigned i = 0; i != NumTemplateArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001627 ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001628 }
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00001629
1630 bool HadMultipleCandidates = Record[Idx++];
1631
Douglas Gregor409448c2011-07-21 22:35:25 +00001632 NamedDecl *FoundD = ReadDeclAs<NamedDecl>(F, Record, Idx);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001633 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1634 DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS);
1635
Douglas Gregor393f2492011-07-22 00:38:23 +00001636 QualType T = readType(F, Record, Idx);
John McCallf89e55a2010-11-18 06:31:45 +00001637 ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]);
1638 ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001639 Expr *Base = ReadSubExpr();
Douglas Gregor409448c2011-07-21 22:35:25 +00001640 ValueDecl *MemberD = ReadDeclAs<ValueDecl>(F, Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +00001641 SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx);
Abramo Bagnara25777432010-08-11 22:01:17 +00001642 DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001643 bool IsArrow = Record[Idx++];
1644
Douglas Gregor35942772011-09-09 21:34:22 +00001645 S = MemberExpr::Create(Context, Base, IsArrow, QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001646 MemberD, FoundDecl, MemberNameInfo,
Douglas Gregordef03542011-02-04 12:01:24 +00001647 HasExplicitTemplateArgs ? &ArgInfo : 0, T, VK, OK);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001648 ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc,
1649 MemberD->getDeclName(), Record, Idx);
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00001650 if (HadMultipleCandidates)
1651 cast<MemberExpr>(S)->setHadMultipleCandidates(true);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001652 break;
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +00001653 }
Chris Lattner4c6f9522009-04-27 05:14:47 +00001654
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001655 case EXPR_BINARY_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001656 S = new (Context) BinaryOperator(Empty);
1657 break;
1658
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001659 case EXPR_COMPOUND_ASSIGN_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001660 S = new (Context) CompoundAssignOperator(Empty);
1661 break;
1662
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001663 case EXPR_CONDITIONAL_OPERATOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001664 S = new (Context) ConditionalOperator(Empty);
1665 break;
1666
John McCall56ca35d2011-02-17 10:25:35 +00001667 case EXPR_BINARY_CONDITIONAL_OPERATOR:
1668 S = new (Context) BinaryConditionalOperator(Empty);
1669 break;
1670
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001671 case EXPR_IMPLICIT_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001672 S = ImplicitCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001673 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001674 break;
1675
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001676 case EXPR_CSTYLE_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001677 S = CStyleCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001678 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001679 break;
1680
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001681 case EXPR_COMPOUND_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001682 S = new (Context) CompoundLiteralExpr(Empty);
1683 break;
1684
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001685 case EXPR_EXT_VECTOR_ELEMENT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001686 S = new (Context) ExtVectorElementExpr(Empty);
1687 break;
1688
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001689 case EXPR_INIT_LIST:
Douglas Gregor35942772011-09-09 21:34:22 +00001690 S = new (Context) InitListExpr(getContext(), Empty);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001691 break;
1692
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001693 case EXPR_DESIGNATED_INIT:
Douglas Gregor35942772011-09-09 21:34:22 +00001694 S = DesignatedInitExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001695 Record[ASTStmtReader::NumExprFields] - 1);
Mike Stump1eb44332009-09-09 15:08:12 +00001696
Chris Lattner4c6f9522009-04-27 05:14:47 +00001697 break;
1698
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001699 case EXPR_IMPLICIT_VALUE_INIT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001700 S = new (Context) ImplicitValueInitExpr(Empty);
1701 break;
1702
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001703 case EXPR_VA_ARG:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001704 S = new (Context) VAArgExpr(Empty);
1705 break;
1706
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001707 case EXPR_ADDR_LABEL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001708 S = new (Context) AddrLabelExpr(Empty);
1709 break;
1710
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001711 case EXPR_STMT:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001712 S = new (Context) StmtExpr(Empty);
1713 break;
1714
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001715 case EXPR_CHOOSE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001716 S = new (Context) ChooseExpr(Empty);
1717 break;
1718
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001719 case EXPR_GNU_NULL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001720 S = new (Context) GNUNullExpr(Empty);
1721 break;
1722
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001723 case EXPR_SHUFFLE_VECTOR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001724 S = new (Context) ShuffleVectorExpr(Empty);
1725 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001726
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001727 case EXPR_BLOCK:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001728 S = new (Context) BlockExpr(Empty);
1729 break;
1730
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001731 case EXPR_BLOCK_DECL_REF:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001732 S = new (Context) BlockDeclRefExpr(Empty);
1733 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001734
Peter Collingbournef111d932011-04-15 00:35:48 +00001735 case EXPR_GENERIC_SELECTION:
1736 S = new (Context) GenericSelectionExpr(Empty);
1737 break;
1738
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001739 case EXPR_OBJC_STRING_LITERAL:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001740 S = new (Context) ObjCStringLiteral(Empty);
1741 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001742 case EXPR_OBJC_ENCODE:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001743 S = new (Context) ObjCEncodeExpr(Empty);
1744 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001745 case EXPR_OBJC_SELECTOR_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001746 S = new (Context) ObjCSelectorExpr(Empty);
1747 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001748 case EXPR_OBJC_PROTOCOL_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001749 S = new (Context) ObjCProtocolExpr(Empty);
1750 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001751 case EXPR_OBJC_IVAR_REF_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001752 S = new (Context) ObjCIvarRefExpr(Empty);
1753 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001754 case EXPR_OBJC_PROPERTY_REF_EXPR:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001755 S = new (Context) ObjCPropertyRefExpr(Empty);
1756 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001757 case EXPR_OBJC_KVC_REF_EXPR:
John McCall12f78a62010-12-02 01:19:52 +00001758 llvm_unreachable("mismatching AST file");
Chris Lattner4c6f9522009-04-27 05:14:47 +00001759 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001760 case EXPR_OBJC_MESSAGE_EXPR:
Douglas Gregor35942772011-09-09 21:34:22 +00001761 S = ObjCMessageExpr::CreateEmpty(Context,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00001762 Record[ASTStmtReader::NumExprFields],
1763 Record[ASTStmtReader::NumExprFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001764 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001765 case EXPR_OBJC_ISA:
Steve Narofff242b1b2009-07-24 17:54:45 +00001766 S = new (Context) ObjCIsaExpr(Empty);
1767 break;
John McCallf85e1932011-06-15 23:02:42 +00001768 case EXPR_OBJC_INDIRECT_COPY_RESTORE:
1769 S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
1770 break;
1771 case EXPR_OBJC_BRIDGED_CAST:
1772 S = new (Context) ObjCBridgedCastExpr(Empty);
1773 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001774 case STMT_OBJC_FOR_COLLECTION:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001775 S = new (Context) ObjCForCollectionStmt(Empty);
1776 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001777 case STMT_OBJC_CATCH:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001778 S = new (Context) ObjCAtCatchStmt(Empty);
1779 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001780 case STMT_OBJC_FINALLY:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001781 S = new (Context) ObjCAtFinallyStmt(Empty);
1782 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001783 case STMT_OBJC_AT_TRY:
Douglas Gregor35942772011-09-09 21:34:22 +00001784 S = ObjCAtTryStmt::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001785 Record[ASTStmtReader::NumStmtFields],
1786 Record[ASTStmtReader::NumStmtFields + 1]);
Chris Lattner4c6f9522009-04-27 05:14:47 +00001787 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001788 case STMT_OBJC_AT_SYNCHRONIZED:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001789 S = new (Context) ObjCAtSynchronizedStmt(Empty);
1790 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001791 case STMT_OBJC_AT_THROW:
Chris Lattner4c6f9522009-04-27 05:14:47 +00001792 S = new (Context) ObjCAtThrowStmt(Empty);
1793 break;
John McCallf85e1932011-06-15 23:02:42 +00001794 case STMT_OBJC_AUTORELEASE_POOL:
1795 S = new (Context) ObjCAutoreleasePoolStmt(Empty);
1796 break;
John McCall7110fd62011-07-15 07:00:14 +00001797 case STMT_SEH_EXCEPT:
1798 S = new (Context) SEHExceptStmt(Empty);
1799 break;
1800 case STMT_SEH_FINALLY:
1801 S = new (Context) SEHFinallyStmt(Empty);
1802 break;
1803 case STMT_SEH_TRY:
1804 S = new (Context) SEHTryStmt(Empty);
1805 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001806 case STMT_CXX_CATCH:
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +00001807 S = new (Context) CXXCatchStmt(Empty);
1808 break;
1809
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001810 case STMT_CXX_TRY:
Douglas Gregor35942772011-09-09 21:34:22 +00001811 S = CXXTryStmt::Create(Context, Empty,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001812 /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]);
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +00001813 break;
1814
Richard Smithad762fc2011-04-14 22:09:26 +00001815 case STMT_CXX_FOR_RANGE:
1816 S = new (Context) CXXForRangeStmt(Empty);
1817 break;
1818
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001819 case EXPR_CXX_OPERATOR_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001820 S = new (Context) CXXOperatorCallExpr(Context, Empty);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +00001821 break;
Chris Lattner1817bd42010-05-09 05:36:05 +00001822
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001823 case EXPR_CXX_MEMBER_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00001824 S = new (Context) CXXMemberCallExpr(Context, Empty);
Chris Lattner1817bd42010-05-09 05:36:05 +00001825 break;
Douglas Gregor39da0b82009-09-09 23:08:42 +00001826
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001827 case EXPR_CXX_CONSTRUCT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001828 S = new (Context) CXXConstructExpr(Empty);
1829 break;
1830
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001831 case EXPR_CXX_TEMPORARY_OBJECT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001832 S = new (Context) CXXTemporaryObjectExpr(Empty);
Douglas Gregor39da0b82009-09-09 23:08:42 +00001833 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001834
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001835 case EXPR_CXX_STATIC_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001836 S = CXXStaticCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001837 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001838 break;
1839
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001840 case EXPR_CXX_DYNAMIC_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001841 S = CXXDynamicCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001842 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001843 break;
1844
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001845 case EXPR_CXX_REINTERPRET_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001846 S = CXXReinterpretCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001847 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001848 break;
1849
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001850 case EXPR_CXX_CONST_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001851 S = CXXConstCastExpr::CreateEmpty(Context);
Sam Weinigce757a72010-01-16 21:21:01 +00001852 break;
1853
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001854 case EXPR_CXX_FUNCTIONAL_CAST:
Douglas Gregor35942772011-09-09 21:34:22 +00001855 S = CXXFunctionalCastExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001856 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
Sam Weinigce757a72010-01-16 21:21:01 +00001857 break;
1858
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001859 case EXPR_CXX_BOOL_LITERAL:
Sam Weinigeb7f9612010-02-07 06:32:43 +00001860 S = new (Context) CXXBoolLiteralExpr(Empty);
1861 break;
Sam Weinigce757a72010-01-16 21:21:01 +00001862
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001863 case EXPR_CXX_NULL_PTR_LITERAL:
Sam Weinigeb7f9612010-02-07 06:32:43 +00001864 S = new (Context) CXXNullPtrLiteralExpr(Empty);
1865 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001866 case EXPR_CXX_TYPEID_EXPR:
Chris Lattner14ab24f2010-05-09 06:03:39 +00001867 S = new (Context) CXXTypeidExpr(Empty, true);
1868 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001869 case EXPR_CXX_TYPEID_TYPE:
Chris Lattner14ab24f2010-05-09 06:03:39 +00001870 S = new (Context) CXXTypeidExpr(Empty, false);
1871 break;
Francois Pichet01b7c302010-09-08 12:20:18 +00001872 case EXPR_CXX_UUIDOF_EXPR:
1873 S = new (Context) CXXUuidofExpr(Empty, true);
1874 break;
1875 case EXPR_CXX_UUIDOF_TYPE:
1876 S = new (Context) CXXUuidofExpr(Empty, false);
1877 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001878 case EXPR_CXX_THIS:
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001879 S = new (Context) CXXThisExpr(Empty);
1880 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001881 case EXPR_CXX_THROW:
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001882 S = new (Context) CXXThrowExpr(Empty);
1883 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001884 case EXPR_CXX_DEFAULT_ARG: {
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001885 bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields];
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001886 if (HasOtherExprStored) {
1887 Expr *SubExpr = ReadSubExpr();
Douglas Gregor35942772011-09-09 21:34:22 +00001888 S = CXXDefaultArgExpr::Create(Context, SourceLocation(), 0, SubExpr);
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001889 } else
1890 S = new (Context) CXXDefaultArgExpr(Empty);
Chris Lattner030854b2010-05-09 06:40:08 +00001891 break;
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001892 }
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001893 case EXPR_CXX_BIND_TEMPORARY:
Chris Lattnerd2598362010-05-10 00:25:06 +00001894 S = new (Context) CXXBindTemporaryExpr(Empty);
1895 break;
Douglas Gregore2ca6d42010-09-02 21:50:02 +00001896
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001897 case EXPR_CXX_SCALAR_VALUE_INIT:
Douglas Gregored8abf12010-07-08 06:14:04 +00001898 S = new (Context) CXXScalarValueInitExpr(Empty);
Chris Lattner59218632010-05-10 01:22:27 +00001899 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001900 case EXPR_CXX_NEW:
Chris Lattner59218632010-05-10 01:22:27 +00001901 S = new (Context) CXXNewExpr(Empty);
1902 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001903 case EXPR_CXX_DELETE:
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001904 S = new (Context) CXXDeleteExpr(Empty);
1905 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001906 case EXPR_CXX_PSEUDO_DESTRUCTOR:
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001907 S = new (Context) CXXPseudoDestructorExpr(Empty);
1908 break;
Chris Lattner59218632010-05-10 01:22:27 +00001909
John McCall4765fa02010-12-06 08:20:24 +00001910 case EXPR_EXPR_WITH_CLEANUPS:
1911 S = new (Context) ExprWithCleanups(Empty);
Chris Lattnerd2598362010-05-10 00:25:06 +00001912 break;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001913
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001914 case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
Douglas Gregor35942772011-09-09 21:34:22 +00001915 S = CXXDependentScopeMemberExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001916 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1917 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1918 ? Record[ASTStmtReader::NumExprFields + 1]
1919 : 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001920 break;
1921
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001922 case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
Douglas Gregor35942772011-09-09 21:34:22 +00001923 S = DependentScopeDeclRefExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001924 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1925 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1926 ? Record[ASTStmtReader::NumExprFields + 1]
1927 : 0);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001928 break;
1929
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001930 case EXPR_CXX_UNRESOLVED_CONSTRUCT:
Douglas Gregor35942772011-09-09 21:34:22 +00001931 S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
Sebastian Redl60adf4a2010-08-18 23:56:52 +00001932 /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001933 break;
1934
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001935 case EXPR_CXX_UNRESOLVED_MEMBER:
Douglas Gregor35942772011-09-09 21:34:22 +00001936 S = UnresolvedMemberExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001937 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1938 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1939 ? Record[ASTStmtReader::NumExprFields + 1]
1940 : 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001941 break;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001942
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001943 case EXPR_CXX_UNRESOLVED_LOOKUP:
Douglas Gregor35942772011-09-09 21:34:22 +00001944 S = UnresolvedLookupExpr::CreateEmpty(Context,
Douglas Gregordef03542011-02-04 12:01:24 +00001945 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1946 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1947 ? Record[ASTStmtReader::NumExprFields + 1]
1948 : 0);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001949 break;
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001950
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001951 case EXPR_CXX_UNARY_TYPE_TRAIT:
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001952 S = new (Context) UnaryTypeTraitExpr(Empty);
1953 break;
Sebastian Redl6b219d02010-09-10 20:55:54 +00001954
Francois Pichetf1872372010-12-08 22:35:30 +00001955 case EXPR_BINARY_TYPE_TRAIT:
Francois Pichet6ad6f282010-12-07 00:08:36 +00001956 S = new (Context) BinaryTypeTraitExpr(Empty);
1957 break;
1958
John Wiegley21ff2e52011-04-28 00:16:57 +00001959 case EXPR_ARRAY_TYPE_TRAIT:
1960 S = new (Context) ArrayTypeTraitExpr(Empty);
1961 break;
1962
John Wiegley55262202011-04-25 06:54:41 +00001963 case EXPR_CXX_EXPRESSION_TRAIT:
1964 S = new (Context) ExpressionTraitExpr(Empty);
1965 break;
1966
Sebastian Redl6b219d02010-09-10 20:55:54 +00001967 case EXPR_CXX_NOEXCEPT:
1968 S = new (Context) CXXNoexceptExpr(Empty);
1969 break;
John McCall7cd7d1a2010-11-15 23:31:06 +00001970
Douglas Gregorbe230c32011-01-03 17:17:50 +00001971 case EXPR_PACK_EXPANSION:
1972 S = new (Context) PackExpansionExpr(Empty);
1973 break;
1974
Douglas Gregoree8aff02011-01-04 17:33:58 +00001975 case EXPR_SIZEOF_PACK:
1976 S = new (Context) SizeOfPackExpr(Empty);
1977 break;
1978
John McCall7110fd62011-07-15 07:00:14 +00001979 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
1980 S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
1981 break;
1982
Douglas Gregorc7793c72011-01-15 01:15:58 +00001983 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
1984 S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
1985 break;
1986
Douglas Gregor03e80032011-06-21 17:03:29 +00001987 case EXPR_MATERIALIZE_TEMPORARY:
1988 S = new (Context) MaterializeTemporaryExpr(Empty);
1989 break;
1990
John McCall56ca35d2011-02-17 10:25:35 +00001991 case EXPR_OPAQUE_VALUE: {
1992 unsigned key = Record[ASTStmtReader::NumExprFields];
1993 OpaqueValueExpr *&expr = OpaqueValueExprs[key];
1994
1995 // If we already have an entry for this opaque value expression,
1996 // don't bother reading it again.
1997 if (expr) {
1998 StmtStack.push_back(expr);
1999 continue;
2000 }
2001
2002 S = expr = new (Context) OpaqueValueExpr(Empty);
John McCall7cd7d1a2010-11-15 23:31:06 +00002003 break;
John McCall56ca35d2011-02-17 10:25:35 +00002004 }
Peter Collingbournee08ce652011-02-09 21:07:24 +00002005
2006 case EXPR_CUDA_KERNEL_CALL:
Douglas Gregor35942772011-09-09 21:34:22 +00002007 S = new (Context) CUDAKernelCallExpr(Context, Empty);
Peter Collingbournee08ce652011-02-09 21:07:24 +00002008 break;
Tanya Lattner61eee0c2011-06-04 00:47:47 +00002009
2010 case EXPR_ASTYPE:
2011 S = new (Context) AsTypeExpr(Empty);
2012 break;
Chris Lattner4c6f9522009-04-27 05:14:47 +00002013 }
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00002014
Chris Lattner4c6f9522009-04-27 05:14:47 +00002015 // We hit a STMT_STOP, so we're done with this expression.
2016 if (Finished)
2017 break;
2018
2019 ++NumStatementsRead;
2020
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00002021 if (S)
2022 Reader.Visit(S);
Chris Lattner4c6f9522009-04-27 05:14:47 +00002023
2024 assert(Idx == Record.size() && "Invalid deserialization of statement");
2025 StmtStack.push_back(S);
2026 }
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00002027
2028#ifndef NDEBUG
2029 assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!");
2030 assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
2031#endif
2032
2033 return StmtStack.pop_back_val();
Chris Lattner4c6f9522009-04-27 05:14:47 +00002034}