1 //===--- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Statement/expression deserialization. This implements the
11 // ASTReader::ReadStmt method.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "clang/Serialization/ASTReader.h"
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/DeclTemplate.h"
19 #include "clang/AST/StmtVisitor.h"
20 #include "clang/Lex/Token.h"
21 #include "llvm/ADT/SmallString.h"
22 using namespace clang;
23 using namespace clang::serialization;
24
25 namespace clang {
26
27 class ASTStmtReader : public StmtVisitor<ASTStmtReader> {
28 friend class OMPClauseReader;
29 typedef ASTReader::RecordData RecordData;
30
31 ASTReader &Reader;
32 ModuleFile &F;
33 llvm::BitstreamCursor &DeclsCursor;
34 const ASTReader::RecordData &Record;
35 unsigned &Idx;
36
ReadToken(const RecordData & R,unsigned & I)37 Token ReadToken(const RecordData &R, unsigned &I) {
38 return Reader.ReadToken(F, R, I);
39 }
40
ReadSourceLocation(const RecordData & R,unsigned & I)41 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
42 return Reader.ReadSourceLocation(F, R, I);
43 }
44
ReadSourceRange(const RecordData & R,unsigned & I)45 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
46 return Reader.ReadSourceRange(F, R, I);
47 }
48
ReadString(const RecordData & R,unsigned & I)49 std::string ReadString(const RecordData &R, unsigned &I) {
50 return Reader.ReadString(R, I);
51 }
52
GetTypeSourceInfo(const RecordData & R,unsigned & I)53 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
54 return Reader.GetTypeSourceInfo(F, R, I);
55 }
56
ReadDeclID(const RecordData & R,unsigned & I)57 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
58 return Reader.ReadDeclID(F, R, I);
59 }
60
ReadDecl(const RecordData & R,unsigned & I)61 Decl *ReadDecl(const RecordData &R, unsigned &I) {
62 return Reader.ReadDecl(F, R, I);
63 }
64
65 template<typename T>
ReadDeclAs(const RecordData & R,unsigned & I)66 T *ReadDeclAs(const RecordData &R, unsigned &I) {
67 return Reader.ReadDeclAs<T>(F, R, I);
68 }
69
ReadDeclarationNameLoc(DeclarationNameLoc & DNLoc,DeclarationName Name,const ASTReader::RecordData & R,unsigned & I)70 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
71 const ASTReader::RecordData &R, unsigned &I) {
72 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
73 }
74
ReadDeclarationNameInfo(DeclarationNameInfo & NameInfo,const ASTReader::RecordData & R,unsigned & I)75 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
76 const ASTReader::RecordData &R, unsigned &I) {
77 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
78 }
79
80 public:
ASTStmtReader(ASTReader & Reader,ModuleFile & F,llvm::BitstreamCursor & Cursor,const ASTReader::RecordData & Record,unsigned & Idx)81 ASTStmtReader(ASTReader &Reader, ModuleFile &F,
82 llvm::BitstreamCursor &Cursor,
83 const ASTReader::RecordData &Record, unsigned &Idx)
84 : Reader(Reader), F(F), DeclsCursor(Cursor), Record(Record), Idx(Idx) { }
85
86 /// \brief The number of record fields required for the Stmt class
87 /// itself.
88 static const unsigned NumStmtFields = 0;
89
90 /// \brief The number of record fields required for the Expr class
91 /// itself.
92 static const unsigned NumExprFields = NumStmtFields + 7;
93
94 /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
95 void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
96 unsigned NumTemplateArgs);
97 /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
98 void ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &ArgList,
99 unsigned NumTemplateArgs);
100
101 void VisitStmt(Stmt *S);
102 #define STMT(Type, Base) \
103 void Visit##Type(Type *);
104 #include "clang/AST/StmtNodes.inc"
105 };
106 }
107
108 void ASTStmtReader::
ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo & Args,unsigned NumTemplateArgs)109 ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
110 unsigned NumTemplateArgs) {
111 SourceLocation TemplateKWLoc = ReadSourceLocation(Record, Idx);
112 TemplateArgumentListInfo ArgInfo;
113 ArgInfo.setLAngleLoc(ReadSourceLocation(Record, Idx));
114 ArgInfo.setRAngleLoc(ReadSourceLocation(Record, Idx));
115 for (unsigned i = 0; i != NumTemplateArgs; ++i)
116 ArgInfo.addArgument(
117 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
118 Args.initializeFrom(TemplateKWLoc, ArgInfo);
119 }
120
VisitStmt(Stmt * S)121 void ASTStmtReader::VisitStmt(Stmt *S) {
122 assert(Idx == NumStmtFields && "Incorrect statement field count");
123 }
124
VisitNullStmt(NullStmt * S)125 void ASTStmtReader::VisitNullStmt(NullStmt *S) {
126 VisitStmt(S);
127 S->setSemiLoc(ReadSourceLocation(Record, Idx));
128 S->HasLeadingEmptyMacro = Record[Idx++];
129 }
130
VisitCompoundStmt(CompoundStmt * S)131 void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
132 VisitStmt(S);
133 SmallVector<Stmt *, 16> Stmts;
134 unsigned NumStmts = Record[Idx++];
135 while (NumStmts--)
136 Stmts.push_back(Reader.ReadSubStmt());
137 S->setStmts(Reader.getContext(), Stmts.data(), Stmts.size());
138 S->LBraceLoc = ReadSourceLocation(Record, Idx);
139 S->RBraceLoc = ReadSourceLocation(Record, Idx);
140 }
141
VisitSwitchCase(SwitchCase * S)142 void ASTStmtReader::VisitSwitchCase(SwitchCase *S) {
143 VisitStmt(S);
144 Reader.RecordSwitchCaseID(S, Record[Idx++]);
145 S->setKeywordLoc(ReadSourceLocation(Record, Idx));
146 S->setColonLoc(ReadSourceLocation(Record, Idx));
147 }
148
VisitCaseStmt(CaseStmt * S)149 void ASTStmtReader::VisitCaseStmt(CaseStmt *S) {
150 VisitSwitchCase(S);
151 S->setLHS(Reader.ReadSubExpr());
152 S->setRHS(Reader.ReadSubExpr());
153 S->setSubStmt(Reader.ReadSubStmt());
154 S->setEllipsisLoc(ReadSourceLocation(Record, Idx));
155 }
156
VisitDefaultStmt(DefaultStmt * S)157 void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) {
158 VisitSwitchCase(S);
159 S->setSubStmt(Reader.ReadSubStmt());
160 }
161
VisitLabelStmt(LabelStmt * S)162 void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
163 VisitStmt(S);
164 LabelDecl *LD = ReadDeclAs<LabelDecl>(Record, Idx);
165 LD->setStmt(S);
166 S->setDecl(LD);
167 S->setSubStmt(Reader.ReadSubStmt());
168 S->setIdentLoc(ReadSourceLocation(Record, Idx));
169 }
170
VisitAttributedStmt(AttributedStmt * S)171 void ASTStmtReader::VisitAttributedStmt(AttributedStmt *S) {
172 VisitStmt(S);
173 uint64_t NumAttrs = Record[Idx++];
174 AttrVec Attrs;
175 Reader.ReadAttributes(F, Attrs, Record, Idx);
176 (void)NumAttrs;
177 assert(NumAttrs == S->NumAttrs);
178 assert(NumAttrs == Attrs.size());
179 std::copy(Attrs.begin(), Attrs.end(), S->getAttrArrayPtr());
180 S->SubStmt = Reader.ReadSubStmt();
181 S->AttrLoc = ReadSourceLocation(Record, Idx);
182 }
183
VisitIfStmt(IfStmt * S)184 void ASTStmtReader::VisitIfStmt(IfStmt *S) {
185 VisitStmt(S);
186 S->setConditionVariable(Reader.getContext(),
187 ReadDeclAs<VarDecl>(Record, Idx));
188 S->setCond(Reader.ReadSubExpr());
189 S->setThen(Reader.ReadSubStmt());
190 S->setElse(Reader.ReadSubStmt());
191 S->setIfLoc(ReadSourceLocation(Record, Idx));
192 S->setElseLoc(ReadSourceLocation(Record, Idx));
193 }
194
VisitSwitchStmt(SwitchStmt * S)195 void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) {
196 VisitStmt(S);
197 S->setConditionVariable(Reader.getContext(),
198 ReadDeclAs<VarDecl>(Record, Idx));
199 S->setCond(Reader.ReadSubExpr());
200 S->setBody(Reader.ReadSubStmt());
201 S->setSwitchLoc(ReadSourceLocation(Record, Idx));
202 if (Record[Idx++])
203 S->setAllEnumCasesCovered();
204
205 SwitchCase *PrevSC = nullptr;
206 for (unsigned N = Record.size(); Idx != N; ++Idx) {
207 SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]);
208 if (PrevSC)
209 PrevSC->setNextSwitchCase(SC);
210 else
211 S->setSwitchCaseList(SC);
212
213 PrevSC = SC;
214 }
215 }
216
VisitWhileStmt(WhileStmt * S)217 void ASTStmtReader::VisitWhileStmt(WhileStmt *S) {
218 VisitStmt(S);
219 S->setConditionVariable(Reader.getContext(),
220 ReadDeclAs<VarDecl>(Record, Idx));
221
222 S->setCond(Reader.ReadSubExpr());
223 S->setBody(Reader.ReadSubStmt());
224 S->setWhileLoc(ReadSourceLocation(Record, Idx));
225 }
226
VisitDoStmt(DoStmt * S)227 void ASTStmtReader::VisitDoStmt(DoStmt *S) {
228 VisitStmt(S);
229 S->setCond(Reader.ReadSubExpr());
230 S->setBody(Reader.ReadSubStmt());
231 S->setDoLoc(ReadSourceLocation(Record, Idx));
232 S->setWhileLoc(ReadSourceLocation(Record, Idx));
233 S->setRParenLoc(ReadSourceLocation(Record, Idx));
234 }
235
VisitForStmt(ForStmt * S)236 void ASTStmtReader::VisitForStmt(ForStmt *S) {
237 VisitStmt(S);
238 S->setInit(Reader.ReadSubStmt());
239 S->setCond(Reader.ReadSubExpr());
240 S->setConditionVariable(Reader.getContext(),
241 ReadDeclAs<VarDecl>(Record, Idx));
242 S->setInc(Reader.ReadSubExpr());
243 S->setBody(Reader.ReadSubStmt());
244 S->setForLoc(ReadSourceLocation(Record, Idx));
245 S->setLParenLoc(ReadSourceLocation(Record, Idx));
246 S->setRParenLoc(ReadSourceLocation(Record, Idx));
247 }
248
VisitGotoStmt(GotoStmt * S)249 void ASTStmtReader::VisitGotoStmt(GotoStmt *S) {
250 VisitStmt(S);
251 S->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
252 S->setGotoLoc(ReadSourceLocation(Record, Idx));
253 S->setLabelLoc(ReadSourceLocation(Record, Idx));
254 }
255
VisitIndirectGotoStmt(IndirectGotoStmt * S)256 void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
257 VisitStmt(S);
258 S->setGotoLoc(ReadSourceLocation(Record, Idx));
259 S->setStarLoc(ReadSourceLocation(Record, Idx));
260 S->setTarget(Reader.ReadSubExpr());
261 }
262
VisitContinueStmt(ContinueStmt * S)263 void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) {
264 VisitStmt(S);
265 S->setContinueLoc(ReadSourceLocation(Record, Idx));
266 }
267
VisitBreakStmt(BreakStmt * S)268 void ASTStmtReader::VisitBreakStmt(BreakStmt *S) {
269 VisitStmt(S);
270 S->setBreakLoc(ReadSourceLocation(Record, Idx));
271 }
272
VisitReturnStmt(ReturnStmt * S)273 void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) {
274 VisitStmt(S);
275 S->setRetValue(Reader.ReadSubExpr());
276 S->setReturnLoc(ReadSourceLocation(Record, Idx));
277 S->setNRVOCandidate(ReadDeclAs<VarDecl>(Record, Idx));
278 }
279
VisitDeclStmt(DeclStmt * S)280 void ASTStmtReader::VisitDeclStmt(DeclStmt *S) {
281 VisitStmt(S);
282 S->setStartLoc(ReadSourceLocation(Record, Idx));
283 S->setEndLoc(ReadSourceLocation(Record, Idx));
284
285 if (Idx + 1 == Record.size()) {
286 // Single declaration
287 S->setDeclGroup(DeclGroupRef(ReadDecl(Record, Idx)));
288 } else {
289 SmallVector<Decl *, 16> Decls;
290 Decls.reserve(Record.size() - Idx);
291 for (unsigned N = Record.size(); Idx != N; )
292 Decls.push_back(ReadDecl(Record, Idx));
293 S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(),
294 Decls.data(),
295 Decls.size())));
296 }
297 }
298
VisitAsmStmt(AsmStmt * S)299 void ASTStmtReader::VisitAsmStmt(AsmStmt *S) {
300 VisitStmt(S);
301 S->NumOutputs = Record[Idx++];
302 S->NumInputs = Record[Idx++];
303 S->NumClobbers = Record[Idx++];
304 S->setAsmLoc(ReadSourceLocation(Record, Idx));
305 S->setVolatile(Record[Idx++]);
306 S->setSimple(Record[Idx++]);
307 }
308
VisitGCCAsmStmt(GCCAsmStmt * S)309 void ASTStmtReader::VisitGCCAsmStmt(GCCAsmStmt *S) {
310 VisitAsmStmt(S);
311 S->setRParenLoc(ReadSourceLocation(Record, Idx));
312 S->setAsmString(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
313
314 unsigned NumOutputs = S->getNumOutputs();
315 unsigned NumInputs = S->getNumInputs();
316 unsigned NumClobbers = S->getNumClobbers();
317
318 // Outputs and inputs
319 SmallVector<IdentifierInfo *, 16> Names;
320 SmallVector<StringLiteral*, 16> Constraints;
321 SmallVector<Stmt*, 16> Exprs;
322 for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
323 Names.push_back(Reader.GetIdentifierInfo(F, Record, Idx));
324 Constraints.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
325 Exprs.push_back(Reader.ReadSubStmt());
326 }
327
328 // Constraints
329 SmallVector<StringLiteral*, 16> Clobbers;
330 for (unsigned I = 0; I != NumClobbers; ++I)
331 Clobbers.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
332
333 S->setOutputsAndInputsAndClobbers(Reader.getContext(),
334 Names.data(), Constraints.data(),
335 Exprs.data(), NumOutputs, NumInputs,
336 Clobbers.data(), NumClobbers);
337 }
338
VisitMSAsmStmt(MSAsmStmt * S)339 void ASTStmtReader::VisitMSAsmStmt(MSAsmStmt *S) {
340 VisitAsmStmt(S);
341 S->LBraceLoc = ReadSourceLocation(Record, Idx);
342 S->EndLoc = ReadSourceLocation(Record, Idx);
343 S->NumAsmToks = Record[Idx++];
344 std::string AsmStr = ReadString(Record, Idx);
345
346 // Read the tokens.
347 SmallVector<Token, 16> AsmToks;
348 AsmToks.reserve(S->NumAsmToks);
349 for (unsigned i = 0, e = S->NumAsmToks; i != e; ++i) {
350 AsmToks.push_back(ReadToken(Record, Idx));
351 }
352
353 // The calls to reserve() for the FooData vectors are mandatory to
354 // prevent dead StringRefs in the Foo vectors.
355
356 // Read the clobbers.
357 SmallVector<std::string, 16> ClobbersData;
358 SmallVector<StringRef, 16> Clobbers;
359 ClobbersData.reserve(S->NumClobbers);
360 Clobbers.reserve(S->NumClobbers);
361 for (unsigned i = 0, e = S->NumClobbers; i != e; ++i) {
362 ClobbersData.push_back(ReadString(Record, Idx));
363 Clobbers.push_back(ClobbersData.back());
364 }
365
366 // Read the operands.
367 unsigned NumOperands = S->NumOutputs + S->NumInputs;
368 SmallVector<Expr*, 16> Exprs;
369 SmallVector<std::string, 16> ConstraintsData;
370 SmallVector<StringRef, 16> Constraints;
371 Exprs.reserve(NumOperands);
372 ConstraintsData.reserve(NumOperands);
373 Constraints.reserve(NumOperands);
374 for (unsigned i = 0; i != NumOperands; ++i) {
375 Exprs.push_back(cast<Expr>(Reader.ReadSubStmt()));
376 ConstraintsData.push_back(ReadString(Record, Idx));
377 Constraints.push_back(ConstraintsData.back());
378 }
379
380 S->initialize(Reader.getContext(), AsmStr, AsmToks,
381 Constraints, Exprs, Clobbers);
382 }
383
VisitCapturedStmt(CapturedStmt * S)384 void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) {
385 VisitStmt(S);
386 ++Idx;
387 S->setCapturedDecl(ReadDeclAs<CapturedDecl>(Record, Idx));
388 S->setCapturedRegionKind(static_cast<CapturedRegionKind>(Record[Idx++]));
389 S->setCapturedRecordDecl(ReadDeclAs<RecordDecl>(Record, Idx));
390
391 // Capture inits
392 for (CapturedStmt::capture_init_iterator I = S->capture_init_begin(),
393 E = S->capture_init_end();
394 I != E; ++I)
395 *I = Reader.ReadSubExpr();
396
397 // Body
398 S->setCapturedStmt(Reader.ReadSubStmt());
399 S->getCapturedDecl()->setBody(S->getCapturedStmt());
400
401 // Captures
402 for (auto &I : S->captures()) {
403 I.VarAndKind.setPointer(ReadDeclAs<VarDecl>(Record, Idx));
404 I.VarAndKind
405 .setInt(static_cast<CapturedStmt::VariableCaptureKind>(Record[Idx++]));
406 I.Loc = ReadSourceLocation(Record, Idx);
407 }
408 }
409
VisitExpr(Expr * E)410 void ASTStmtReader::VisitExpr(Expr *E) {
411 VisitStmt(E);
412 E->setType(Reader.readType(F, Record, Idx));
413 E->setTypeDependent(Record[Idx++]);
414 E->setValueDependent(Record[Idx++]);
415 E->setInstantiationDependent(Record[Idx++]);
416 E->ExprBits.ContainsUnexpandedParameterPack = Record[Idx++];
417 E->setValueKind(static_cast<ExprValueKind>(Record[Idx++]));
418 E->setObjectKind(static_cast<ExprObjectKind>(Record[Idx++]));
419 assert(Idx == NumExprFields && "Incorrect expression field count");
420 }
421
VisitPredefinedExpr(PredefinedExpr * E)422 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
423 VisitExpr(E);
424 E->setLocation(ReadSourceLocation(Record, Idx));
425 E->Type = (PredefinedExpr::IdentType)Record[Idx++];
426 E->FnName = cast_or_null<StringLiteral>(Reader.ReadSubExpr());
427 }
428
VisitDeclRefExpr(DeclRefExpr * E)429 void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
430 VisitExpr(E);
431
432 E->DeclRefExprBits.HasQualifier = Record[Idx++];
433 E->DeclRefExprBits.HasFoundDecl = Record[Idx++];
434 E->DeclRefExprBits.HasTemplateKWAndArgsInfo = Record[Idx++];
435 E->DeclRefExprBits.HadMultipleCandidates = Record[Idx++];
436 E->DeclRefExprBits.RefersToEnclosingVariableOrCapture = Record[Idx++];
437 unsigned NumTemplateArgs = 0;
438 if (E->hasTemplateKWAndArgsInfo())
439 NumTemplateArgs = Record[Idx++];
440
441 if (E->hasQualifier())
442 E->getInternalQualifierLoc()
443 = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
444
445 if (E->hasFoundDecl())
446 E->getInternalFoundDecl() = ReadDeclAs<NamedDecl>(Record, Idx);
447
448 if (E->hasTemplateKWAndArgsInfo())
449 ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
450 NumTemplateArgs);
451
452 E->setDecl(ReadDeclAs<ValueDecl>(Record, Idx));
453 E->setLocation(ReadSourceLocation(Record, Idx));
454 ReadDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record, Idx);
455 }
456
VisitIntegerLiteral(IntegerLiteral * E)457 void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
458 VisitExpr(E);
459 E->setLocation(ReadSourceLocation(Record, Idx));
460 E->setValue(Reader.getContext(), Reader.ReadAPInt(Record, Idx));
461 }
462
VisitFloatingLiteral(FloatingLiteral * E)463 void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
464 VisitExpr(E);
465 E->setRawSemantics(static_cast<Stmt::APFloatSemantics>(Record[Idx++]));
466 E->setExact(Record[Idx++]);
467 E->setValue(Reader.getContext(),
468 Reader.ReadAPFloat(Record, E->getSemantics(), Idx));
469 E->setLocation(ReadSourceLocation(Record, Idx));
470 }
471
VisitImaginaryLiteral(ImaginaryLiteral * E)472 void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
473 VisitExpr(E);
474 E->setSubExpr(Reader.ReadSubExpr());
475 }
476
VisitStringLiteral(StringLiteral * E)477 void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
478 VisitExpr(E);
479 unsigned Len = Record[Idx++];
480 assert(Record[Idx] == E->getNumConcatenated() &&
481 "Wrong number of concatenated tokens!");
482 ++Idx;
483 StringLiteral::StringKind kind =
484 static_cast<StringLiteral::StringKind>(Record[Idx++]);
485 bool isPascal = Record[Idx++];
486
487 // Read string data
488 SmallString<16> Str(&Record[Idx], &Record[Idx] + Len);
489 E->setString(Reader.getContext(), Str, kind, isPascal);
490 Idx += Len;
491
492 // Read source locations
493 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
494 E->setStrTokenLoc(I, ReadSourceLocation(Record, Idx));
495 }
496
VisitCharacterLiteral(CharacterLiteral * E)497 void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
498 VisitExpr(E);
499 E->setValue(Record[Idx++]);
500 E->setLocation(ReadSourceLocation(Record, Idx));
501 E->setKind(static_cast<CharacterLiteral::CharacterKind>(Record[Idx++]));
502 }
503
VisitParenExpr(ParenExpr * E)504 void ASTStmtReader::VisitParenExpr(ParenExpr *E) {
505 VisitExpr(E);
506 E->setLParen(ReadSourceLocation(Record, Idx));
507 E->setRParen(ReadSourceLocation(Record, Idx));
508 E->setSubExpr(Reader.ReadSubExpr());
509 }
510
VisitParenListExpr(ParenListExpr * E)511 void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
512 VisitExpr(E);
513 unsigned NumExprs = Record[Idx++];
514 E->Exprs = new (Reader.getContext()) Stmt*[NumExprs];
515 for (unsigned i = 0; i != NumExprs; ++i)
516 E->Exprs[i] = Reader.ReadSubStmt();
517 E->NumExprs = NumExprs;
518 E->LParenLoc = ReadSourceLocation(Record, Idx);
519 E->RParenLoc = ReadSourceLocation(Record, Idx);
520 }
521
VisitUnaryOperator(UnaryOperator * E)522 void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) {
523 VisitExpr(E);
524 E->setSubExpr(Reader.ReadSubExpr());
525 E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
526 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
527 }
528
VisitOffsetOfExpr(OffsetOfExpr * E)529 void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
530 typedef OffsetOfExpr::OffsetOfNode Node;
531 VisitExpr(E);
532 assert(E->getNumComponents() == Record[Idx]);
533 ++Idx;
534 assert(E->getNumExpressions() == Record[Idx]);
535 ++Idx;
536 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
537 E->setRParenLoc(ReadSourceLocation(Record, Idx));
538 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
539 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
540 Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]);
541 SourceLocation Start = ReadSourceLocation(Record, Idx);
542 SourceLocation End = ReadSourceLocation(Record, Idx);
543 switch (Kind) {
544 case Node::Array:
545 E->setComponent(I, Node(Start, Record[Idx++], End));
546 break;
547
548 case Node::Field:
549 E->setComponent(I, Node(Start, ReadDeclAs<FieldDecl>(Record, Idx), End));
550 break;
551
552 case Node::Identifier:
553 E->setComponent(I,
554 Node(Start,
555 Reader.GetIdentifierInfo(F, Record, Idx),
556 End));
557 break;
558
559 case Node::Base: {
560 CXXBaseSpecifier *Base = new (Reader.getContext()) CXXBaseSpecifier();
561 *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
562 E->setComponent(I, Node(Base));
563 break;
564 }
565 }
566 }
567
568 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
569 E->setIndexExpr(I, Reader.ReadSubExpr());
570 }
571
VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr * E)572 void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
573 VisitExpr(E);
574 E->setKind(static_cast<UnaryExprOrTypeTrait>(Record[Idx++]));
575 if (Record[Idx] == 0) {
576 E->setArgument(Reader.ReadSubExpr());
577 ++Idx;
578 } else {
579 E->setArgument(GetTypeSourceInfo(Record, Idx));
580 }
581 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
582 E->setRParenLoc(ReadSourceLocation(Record, Idx));
583 }
584
VisitArraySubscriptExpr(ArraySubscriptExpr * E)585 void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
586 VisitExpr(E);
587 E->setLHS(Reader.ReadSubExpr());
588 E->setRHS(Reader.ReadSubExpr());
589 E->setRBracketLoc(ReadSourceLocation(Record, Idx));
590 }
591
VisitCallExpr(CallExpr * E)592 void ASTStmtReader::VisitCallExpr(CallExpr *E) {
593 VisitExpr(E);
594 E->setNumArgs(Reader.getContext(), Record[Idx++]);
595 E->setRParenLoc(ReadSourceLocation(Record, Idx));
596 E->setCallee(Reader.ReadSubExpr());
597 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
598 E->setArg(I, Reader.ReadSubExpr());
599 }
600
VisitCXXMemberCallExpr(CXXMemberCallExpr * E)601 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
602 VisitCallExpr(E);
603 }
604
VisitMemberExpr(MemberExpr * E)605 void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
606 // Don't call VisitExpr, this is fully initialized at creation.
607 assert(E->getStmtClass() == Stmt::MemberExprClass &&
608 "It's a subclass, we must advance Idx!");
609 }
610
VisitObjCIsaExpr(ObjCIsaExpr * E)611 void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
612 VisitExpr(E);
613 E->setBase(Reader.ReadSubExpr());
614 E->setIsaMemberLoc(ReadSourceLocation(Record, Idx));
615 E->setOpLoc(ReadSourceLocation(Record, Idx));
616 E->setArrow(Record[Idx++]);
617 }
618
619 void ASTStmtReader::
VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr * E)620 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
621 VisitExpr(E);
622 E->Operand = Reader.ReadSubExpr();
623 E->setShouldCopy(Record[Idx++]);
624 }
625
VisitObjCBridgedCastExpr(ObjCBridgedCastExpr * E)626 void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
627 VisitExplicitCastExpr(E);
628 E->LParenLoc = ReadSourceLocation(Record, Idx);
629 E->BridgeKeywordLoc = ReadSourceLocation(Record, Idx);
630 E->Kind = Record[Idx++];
631 }
632
VisitCastExpr(CastExpr * E)633 void ASTStmtReader::VisitCastExpr(CastExpr *E) {
634 VisitExpr(E);
635 unsigned NumBaseSpecs = Record[Idx++];
636 assert(NumBaseSpecs == E->path_size());
637 E->setSubExpr(Reader.ReadSubExpr());
638 E->setCastKind((CastKind)Record[Idx++]);
639 CastExpr::path_iterator BaseI = E->path_begin();
640 while (NumBaseSpecs--) {
641 CXXBaseSpecifier *BaseSpec = new (Reader.getContext()) CXXBaseSpecifier;
642 *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
643 *BaseI++ = BaseSpec;
644 }
645 }
646
VisitBinaryOperator(BinaryOperator * E)647 void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
648 VisitExpr(E);
649 E->setLHS(Reader.ReadSubExpr());
650 E->setRHS(Reader.ReadSubExpr());
651 E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
652 E->setOperatorLoc(ReadSourceLocation(Record, Idx));
653 E->setFPContractable((bool)Record[Idx++]);
654 }
655
VisitCompoundAssignOperator(CompoundAssignOperator * E)656 void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
657 VisitBinaryOperator(E);
658 E->setComputationLHSType(Reader.readType(F, Record, Idx));
659 E->setComputationResultType(Reader.readType(F, Record, Idx));
660 }
661
VisitConditionalOperator(ConditionalOperator * E)662 void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
663 VisitExpr(E);
664 E->SubExprs[ConditionalOperator::COND] = Reader.ReadSubExpr();
665 E->SubExprs[ConditionalOperator::LHS] = Reader.ReadSubExpr();
666 E->SubExprs[ConditionalOperator::RHS] = Reader.ReadSubExpr();
667 E->QuestionLoc = ReadSourceLocation(Record, Idx);
668 E->ColonLoc = ReadSourceLocation(Record, Idx);
669 }
670
671 void
VisitBinaryConditionalOperator(BinaryConditionalOperator * E)672 ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
673 VisitExpr(E);
674 E->OpaqueValue = cast<OpaqueValueExpr>(Reader.ReadSubExpr());
675 E->SubExprs[BinaryConditionalOperator::COMMON] = Reader.ReadSubExpr();
676 E->SubExprs[BinaryConditionalOperator::COND] = Reader.ReadSubExpr();
677 E->SubExprs[BinaryConditionalOperator::LHS] = Reader.ReadSubExpr();
678 E->SubExprs[BinaryConditionalOperator::RHS] = Reader.ReadSubExpr();
679 E->QuestionLoc = ReadSourceLocation(Record, Idx);
680 E->ColonLoc = ReadSourceLocation(Record, Idx);
681 }
682
VisitImplicitCastExpr(ImplicitCastExpr * E)683 void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
684 VisitCastExpr(E);
685 }
686
VisitExplicitCastExpr(ExplicitCastExpr * E)687 void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
688 VisitCastExpr(E);
689 E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx));
690 }
691
VisitCStyleCastExpr(CStyleCastExpr * E)692 void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
693 VisitExplicitCastExpr(E);
694 E->setLParenLoc(ReadSourceLocation(Record, Idx));
695 E->setRParenLoc(ReadSourceLocation(Record, Idx));
696 }
697
VisitCompoundLiteralExpr(CompoundLiteralExpr * E)698 void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
699 VisitExpr(E);
700 E->setLParenLoc(ReadSourceLocation(Record, Idx));
701 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
702 E->setInitializer(Reader.ReadSubExpr());
703 E->setFileScope(Record[Idx++]);
704 }
705
VisitExtVectorElementExpr(ExtVectorElementExpr * E)706 void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
707 VisitExpr(E);
708 E->setBase(Reader.ReadSubExpr());
709 E->setAccessor(Reader.GetIdentifierInfo(F, Record, Idx));
710 E->setAccessorLoc(ReadSourceLocation(Record, Idx));
711 }
712
VisitInitListExpr(InitListExpr * E)713 void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
714 VisitExpr(E);
715 if (InitListExpr *SyntForm = cast_or_null<InitListExpr>(Reader.ReadSubStmt()))
716 E->setSyntacticForm(SyntForm);
717 E->setLBraceLoc(ReadSourceLocation(Record, Idx));
718 E->setRBraceLoc(ReadSourceLocation(Record, Idx));
719 bool isArrayFiller = Record[Idx++];
720 Expr *filler = nullptr;
721 if (isArrayFiller) {
722 filler = Reader.ReadSubExpr();
723 E->ArrayFillerOrUnionFieldInit = filler;
724 } else
725 E->ArrayFillerOrUnionFieldInit = ReadDeclAs<FieldDecl>(Record, Idx);
726 E->sawArrayRangeDesignator(Record[Idx++]);
727 unsigned NumInits = Record[Idx++];
728 E->reserveInits(Reader.getContext(), NumInits);
729 if (isArrayFiller) {
730 for (unsigned I = 0; I != NumInits; ++I) {
731 Expr *init = Reader.ReadSubExpr();
732 E->updateInit(Reader.getContext(), I, init ? init : filler);
733 }
734 } else {
735 for (unsigned I = 0; I != NumInits; ++I)
736 E->updateInit(Reader.getContext(), I, Reader.ReadSubExpr());
737 }
738 }
739
VisitDesignatedInitExpr(DesignatedInitExpr * E)740 void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
741 typedef DesignatedInitExpr::Designator Designator;
742
743 VisitExpr(E);
744 unsigned NumSubExprs = Record[Idx++];
745 assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
746 for (unsigned I = 0; I != NumSubExprs; ++I)
747 E->setSubExpr(I, Reader.ReadSubExpr());
748 E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx));
749 E->setGNUSyntax(Record[Idx++]);
750
751 SmallVector<Designator, 4> Designators;
752 while (Idx < Record.size()) {
753 switch ((DesignatorTypes)Record[Idx++]) {
754 case DESIG_FIELD_DECL: {
755 FieldDecl *Field = ReadDeclAs<FieldDecl>(Record, Idx);
756 SourceLocation DotLoc
757 = ReadSourceLocation(Record, Idx);
758 SourceLocation FieldLoc
759 = ReadSourceLocation(Record, Idx);
760 Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
761 FieldLoc));
762 Designators.back().setField(Field);
763 break;
764 }
765
766 case DESIG_FIELD_NAME: {
767 const IdentifierInfo *Name = Reader.GetIdentifierInfo(F, Record, Idx);
768 SourceLocation DotLoc
769 = ReadSourceLocation(Record, Idx);
770 SourceLocation FieldLoc
771 = ReadSourceLocation(Record, Idx);
772 Designators.push_back(Designator(Name, DotLoc, FieldLoc));
773 break;
774 }
775
776 case DESIG_ARRAY: {
777 unsigned Index = Record[Idx++];
778 SourceLocation LBracketLoc
779 = ReadSourceLocation(Record, Idx);
780 SourceLocation RBracketLoc
781 = ReadSourceLocation(Record, Idx);
782 Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
783 break;
784 }
785
786 case DESIG_ARRAY_RANGE: {
787 unsigned Index = Record[Idx++];
788 SourceLocation LBracketLoc
789 = ReadSourceLocation(Record, Idx);
790 SourceLocation EllipsisLoc
791 = ReadSourceLocation(Record, Idx);
792 SourceLocation RBracketLoc
793 = ReadSourceLocation(Record, Idx);
794 Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
795 RBracketLoc));
796 break;
797 }
798 }
799 }
800 E->setDesignators(Reader.getContext(),
801 Designators.data(), Designators.size());
802 }
803
VisitImplicitValueInitExpr(ImplicitValueInitExpr * E)804 void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
805 VisitExpr(E);
806 }
807
VisitVAArgExpr(VAArgExpr * E)808 void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
809 VisitExpr(E);
810 E->setSubExpr(Reader.ReadSubExpr());
811 E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx));
812 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
813 E->setRParenLoc(ReadSourceLocation(Record, Idx));
814 }
815
VisitAddrLabelExpr(AddrLabelExpr * E)816 void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
817 VisitExpr(E);
818 E->setAmpAmpLoc(ReadSourceLocation(Record, Idx));
819 E->setLabelLoc(ReadSourceLocation(Record, Idx));
820 E->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
821 }
822
VisitStmtExpr(StmtExpr * E)823 void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
824 VisitExpr(E);
825 E->setLParenLoc(ReadSourceLocation(Record, Idx));
826 E->setRParenLoc(ReadSourceLocation(Record, Idx));
827 E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt()));
828 }
829
VisitChooseExpr(ChooseExpr * E)830 void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
831 VisitExpr(E);
832 E->setCond(Reader.ReadSubExpr());
833 E->setLHS(Reader.ReadSubExpr());
834 E->setRHS(Reader.ReadSubExpr());
835 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
836 E->setRParenLoc(ReadSourceLocation(Record, Idx));
837 E->setIsConditionTrue(Record[Idx++]);
838 }
839
VisitGNUNullExpr(GNUNullExpr * E)840 void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
841 VisitExpr(E);
842 E->setTokenLocation(ReadSourceLocation(Record, Idx));
843 }
844
VisitShuffleVectorExpr(ShuffleVectorExpr * E)845 void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
846 VisitExpr(E);
847 SmallVector<Expr *, 16> Exprs;
848 unsigned NumExprs = Record[Idx++];
849 while (NumExprs--)
850 Exprs.push_back(Reader.ReadSubExpr());
851 E->setExprs(Reader.getContext(), Exprs);
852 E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
853 E->setRParenLoc(ReadSourceLocation(Record, Idx));
854 }
855
VisitConvertVectorExpr(ConvertVectorExpr * E)856 void ASTStmtReader::VisitConvertVectorExpr(ConvertVectorExpr *E) {
857 VisitExpr(E);
858 E->BuiltinLoc = ReadSourceLocation(Record, Idx);
859 E->RParenLoc = ReadSourceLocation(Record, Idx);
860 E->TInfo = GetTypeSourceInfo(Record, Idx);
861 E->SrcExpr = Reader.ReadSubExpr();
862 }
863
VisitBlockExpr(BlockExpr * E)864 void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
865 VisitExpr(E);
866 E->setBlockDecl(ReadDeclAs<BlockDecl>(Record, Idx));
867 }
868
VisitGenericSelectionExpr(GenericSelectionExpr * E)869 void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
870 VisitExpr(E);
871 E->NumAssocs = Record[Idx++];
872 E->AssocTypes = new (Reader.getContext()) TypeSourceInfo*[E->NumAssocs];
873 E->SubExprs =
874 new(Reader.getContext()) Stmt*[GenericSelectionExpr::END_EXPR+E->NumAssocs];
875
876 E->SubExprs[GenericSelectionExpr::CONTROLLING] = Reader.ReadSubExpr();
877 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
878 E->AssocTypes[I] = GetTypeSourceInfo(Record, Idx);
879 E->SubExprs[GenericSelectionExpr::END_EXPR+I] = Reader.ReadSubExpr();
880 }
881 E->ResultIndex = Record[Idx++];
882
883 E->GenericLoc = ReadSourceLocation(Record, Idx);
884 E->DefaultLoc = ReadSourceLocation(Record, Idx);
885 E->RParenLoc = ReadSourceLocation(Record, Idx);
886 }
887
VisitPseudoObjectExpr(PseudoObjectExpr * E)888 void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
889 VisitExpr(E);
890 unsigned numSemanticExprs = Record[Idx++];
891 assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs);
892 E->PseudoObjectExprBits.ResultIndex = Record[Idx++];
893
894 // Read the syntactic expression.
895 E->getSubExprsBuffer()[0] = Reader.ReadSubExpr();
896
897 // Read all the semantic expressions.
898 for (unsigned i = 0; i != numSemanticExprs; ++i) {
899 Expr *subExpr = Reader.ReadSubExpr();
900 E->getSubExprsBuffer()[i+1] = subExpr;
901 }
902 }
903
VisitAtomicExpr(AtomicExpr * E)904 void ASTStmtReader::VisitAtomicExpr(AtomicExpr *E) {
905 VisitExpr(E);
906 E->Op = AtomicExpr::AtomicOp(Record[Idx++]);
907 E->NumSubExprs = AtomicExpr::getNumSubExprs(E->Op);
908 for (unsigned I = 0; I != E->NumSubExprs; ++I)
909 E->SubExprs[I] = Reader.ReadSubExpr();
910 E->BuiltinLoc = ReadSourceLocation(Record, Idx);
911 E->RParenLoc = ReadSourceLocation(Record, Idx);
912 }
913
914 //===----------------------------------------------------------------------===//
915 // Objective-C Expressions and Statements
916
VisitObjCStringLiteral(ObjCStringLiteral * E)917 void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
918 VisitExpr(E);
919 E->setString(cast<StringLiteral>(Reader.ReadSubStmt()));
920 E->setAtLoc(ReadSourceLocation(Record, Idx));
921 }
922
VisitObjCBoxedExpr(ObjCBoxedExpr * E)923 void ASTStmtReader::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
924 VisitExpr(E);
925 // could be one of several IntegerLiteral, FloatLiteral, etc.
926 E->SubExpr = Reader.ReadSubStmt();
927 E->BoxingMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
928 E->Range = ReadSourceRange(Record, Idx);
929 }
930
VisitObjCArrayLiteral(ObjCArrayLiteral * E)931 void ASTStmtReader::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
932 VisitExpr(E);
933 unsigned NumElements = Record[Idx++];
934 assert(NumElements == E->getNumElements() && "Wrong number of elements");
935 Expr **Elements = E->getElements();
936 for (unsigned I = 0, N = NumElements; I != N; ++I)
937 Elements[I] = Reader.ReadSubExpr();
938 E->ArrayWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
939 E->Range = ReadSourceRange(Record, Idx);
940 }
941
VisitObjCDictionaryLiteral(ObjCDictionaryLiteral * E)942 void ASTStmtReader::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
943 VisitExpr(E);
944 unsigned NumElements = Record[Idx++];
945 assert(NumElements == E->getNumElements() && "Wrong number of elements");
946 bool HasPackExpansions = Record[Idx++];
947 assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch");
948 ObjCDictionaryLiteral::KeyValuePair *KeyValues = E->getKeyValues();
949 ObjCDictionaryLiteral::ExpansionData *Expansions = E->getExpansionData();
950 for (unsigned I = 0; I != NumElements; ++I) {
951 KeyValues[I].Key = Reader.ReadSubExpr();
952 KeyValues[I].Value = Reader.ReadSubExpr();
953 if (HasPackExpansions) {
954 Expansions[I].EllipsisLoc = ReadSourceLocation(Record, Idx);
955 Expansions[I].NumExpansionsPlusOne = Record[Idx++];
956 }
957 }
958 E->DictWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
959 E->Range = ReadSourceRange(Record, Idx);
960 }
961
VisitObjCEncodeExpr(ObjCEncodeExpr * E)962 void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
963 VisitExpr(E);
964 E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
965 E->setAtLoc(ReadSourceLocation(Record, Idx));
966 E->setRParenLoc(ReadSourceLocation(Record, Idx));
967 }
968
VisitObjCSelectorExpr(ObjCSelectorExpr * E)969 void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
970 VisitExpr(E);
971 E->setSelector(Reader.ReadSelector(F, Record, Idx));
972 E->setAtLoc(ReadSourceLocation(Record, Idx));
973 E->setRParenLoc(ReadSourceLocation(Record, Idx));
974 }
975
VisitObjCProtocolExpr(ObjCProtocolExpr * E)976 void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
977 VisitExpr(E);
978 E->setProtocol(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
979 E->setAtLoc(ReadSourceLocation(Record, Idx));
980 E->ProtoLoc = ReadSourceLocation(Record, Idx);
981 E->setRParenLoc(ReadSourceLocation(Record, Idx));
982 }
983
VisitObjCIvarRefExpr(ObjCIvarRefExpr * E)984 void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
985 VisitExpr(E);
986 E->setDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
987 E->setLocation(ReadSourceLocation(Record, Idx));
988 E->setOpLoc(ReadSourceLocation(Record, Idx));
989 E->setBase(Reader.ReadSubExpr());
990 E->setIsArrow(Record[Idx++]);
991 E->setIsFreeIvar(Record[Idx++]);
992 }
993
VisitObjCPropertyRefExpr(ObjCPropertyRefExpr * E)994 void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
995 VisitExpr(E);
996 unsigned MethodRefFlags = Record[Idx++];
997 bool Implicit = Record[Idx++] != 0;
998 if (Implicit) {
999 ObjCMethodDecl *Getter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
1000 ObjCMethodDecl *Setter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
1001 E->setImplicitProperty(Getter, Setter, MethodRefFlags);
1002 } else {
1003 E->setExplicitProperty(ReadDeclAs<ObjCPropertyDecl>(Record, Idx),
1004 MethodRefFlags);
1005 }
1006 E->setLocation(ReadSourceLocation(Record, Idx));
1007 E->setReceiverLocation(ReadSourceLocation(Record, Idx));
1008 switch (Record[Idx++]) {
1009 case 0:
1010 E->setBase(Reader.ReadSubExpr());
1011 break;
1012 case 1:
1013 E->setSuperReceiver(Reader.readType(F, Record, Idx));
1014 break;
1015 case 2:
1016 E->setClassReceiver(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
1017 break;
1018 }
1019 }
1020
VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr * E)1021 void ASTStmtReader::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1022 VisitExpr(E);
1023 E->setRBracket(ReadSourceLocation(Record, Idx));
1024 E->setBaseExpr(Reader.ReadSubExpr());
1025 E->setKeyExpr(Reader.ReadSubExpr());
1026 E->GetAtIndexMethodDecl = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
1027 E->SetAtIndexMethodDecl = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
1028 }
1029
VisitObjCMessageExpr(ObjCMessageExpr * E)1030 void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1031 VisitExpr(E);
1032 assert(Record[Idx] == E->getNumArgs());
1033 ++Idx;
1034 unsigned NumStoredSelLocs = Record[Idx++];
1035 E->SelLocsKind = Record[Idx++];
1036 E->setDelegateInitCall(Record[Idx++]);
1037 E->IsImplicit = Record[Idx++];
1038 ObjCMessageExpr::ReceiverKind Kind
1039 = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
1040 switch (Kind) {
1041 case ObjCMessageExpr::Instance:
1042 E->setInstanceReceiver(Reader.ReadSubExpr());
1043 break;
1044
1045 case ObjCMessageExpr::Class:
1046 E->setClassReceiver(GetTypeSourceInfo(Record, Idx));
1047 break;
1048
1049 case ObjCMessageExpr::SuperClass:
1050 case ObjCMessageExpr::SuperInstance: {
1051 QualType T = Reader.readType(F, Record, Idx);
1052 SourceLocation SuperLoc = ReadSourceLocation(Record, Idx);
1053 E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
1054 break;
1055 }
1056 }
1057
1058 assert(Kind == E->getReceiverKind());
1059
1060 if (Record[Idx++])
1061 E->setMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
1062 else
1063 E->setSelector(Reader.ReadSelector(F, Record, Idx));
1064
1065 E->LBracLoc = ReadSourceLocation(Record, Idx);
1066 E->RBracLoc = ReadSourceLocation(Record, Idx);
1067
1068 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1069 E->setArg(I, Reader.ReadSubExpr());
1070
1071 SourceLocation *Locs = E->getStoredSelLocs();
1072 for (unsigned I = 0; I != NumStoredSelLocs; ++I)
1073 Locs[I] = ReadSourceLocation(Record, Idx);
1074 }
1075
VisitObjCForCollectionStmt(ObjCForCollectionStmt * S)1076 void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1077 VisitStmt(S);
1078 S->setElement(Reader.ReadSubStmt());
1079 S->setCollection(Reader.ReadSubExpr());
1080 S->setBody(Reader.ReadSubStmt());
1081 S->setForLoc(ReadSourceLocation(Record, Idx));
1082 S->setRParenLoc(ReadSourceLocation(Record, Idx));
1083 }
1084
VisitObjCAtCatchStmt(ObjCAtCatchStmt * S)1085 void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1086 VisitStmt(S);
1087 S->setCatchBody(Reader.ReadSubStmt());
1088 S->setCatchParamDecl(ReadDeclAs<VarDecl>(Record, Idx));
1089 S->setAtCatchLoc(ReadSourceLocation(Record, Idx));
1090 S->setRParenLoc(ReadSourceLocation(Record, Idx));
1091 }
1092
VisitObjCAtFinallyStmt(ObjCAtFinallyStmt * S)1093 void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1094 VisitStmt(S);
1095 S->setFinallyBody(Reader.ReadSubStmt());
1096 S->setAtFinallyLoc(ReadSourceLocation(Record, Idx));
1097 }
1098
VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt * S)1099 void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1100 VisitStmt(S);
1101 S->setSubStmt(Reader.ReadSubStmt());
1102 S->setAtLoc(ReadSourceLocation(Record, Idx));
1103 }
1104
VisitObjCAtTryStmt(ObjCAtTryStmt * S)1105 void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1106 VisitStmt(S);
1107 assert(Record[Idx] == S->getNumCatchStmts());
1108 ++Idx;
1109 bool HasFinally = Record[Idx++];
1110 S->setTryBody(Reader.ReadSubStmt());
1111 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1112 S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt()));
1113
1114 if (HasFinally)
1115 S->setFinallyStmt(Reader.ReadSubStmt());
1116 S->setAtTryLoc(ReadSourceLocation(Record, Idx));
1117 }
1118
VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt * S)1119 void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1120 VisitStmt(S);
1121 S->setSynchExpr(Reader.ReadSubStmt());
1122 S->setSynchBody(Reader.ReadSubStmt());
1123 S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx));
1124 }
1125
VisitObjCAtThrowStmt(ObjCAtThrowStmt * S)1126 void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1127 VisitStmt(S);
1128 S->setThrowExpr(Reader.ReadSubStmt());
1129 S->setThrowLoc(ReadSourceLocation(Record, Idx));
1130 }
1131
VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr * E)1132 void ASTStmtReader::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1133 VisitExpr(E);
1134 E->setValue(Record[Idx++]);
1135 E->setLocation(ReadSourceLocation(Record, Idx));
1136 }
1137
1138 //===----------------------------------------------------------------------===//
1139 // C++ Expressions and Statements
1140 //===----------------------------------------------------------------------===//
1141
VisitCXXCatchStmt(CXXCatchStmt * S)1142 void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
1143 VisitStmt(S);
1144 S->CatchLoc = ReadSourceLocation(Record, Idx);
1145 S->ExceptionDecl = ReadDeclAs<VarDecl>(Record, Idx);
1146 S->HandlerBlock = Reader.ReadSubStmt();
1147 }
1148
VisitCXXTryStmt(CXXTryStmt * S)1149 void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
1150 VisitStmt(S);
1151 assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?");
1152 ++Idx;
1153 S->TryLoc = ReadSourceLocation(Record, Idx);
1154 S->getStmts()[0] = Reader.ReadSubStmt();
1155 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1156 S->getStmts()[i + 1] = Reader.ReadSubStmt();
1157 }
1158
VisitCXXForRangeStmt(CXXForRangeStmt * S)1159 void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1160 VisitStmt(S);
1161 S->setForLoc(ReadSourceLocation(Record, Idx));
1162 S->setColonLoc(ReadSourceLocation(Record, Idx));
1163 S->setRParenLoc(ReadSourceLocation(Record, Idx));
1164 S->setRangeStmt(Reader.ReadSubStmt());
1165 S->setBeginEndStmt(Reader.ReadSubStmt());
1166 S->setCond(Reader.ReadSubExpr());
1167 S->setInc(Reader.ReadSubExpr());
1168 S->setLoopVarStmt(Reader.ReadSubStmt());
1169 S->setBody(Reader.ReadSubStmt());
1170 }
1171
VisitMSDependentExistsStmt(MSDependentExistsStmt * S)1172 void ASTStmtReader::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1173 VisitStmt(S);
1174 S->KeywordLoc = ReadSourceLocation(Record, Idx);
1175 S->IsIfExists = Record[Idx++];
1176 S->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1177 ReadDeclarationNameInfo(S->NameInfo, Record, Idx);
1178 S->SubStmt = Reader.ReadSubStmt();
1179 }
1180
VisitCXXOperatorCallExpr(CXXOperatorCallExpr * E)1181 void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1182 VisitCallExpr(E);
1183 E->Operator = (OverloadedOperatorKind)Record[Idx++];
1184 E->Range = Reader.ReadSourceRange(F, Record, Idx);
1185 E->setFPContractable((bool)Record[Idx++]);
1186 }
1187
VisitCXXConstructExpr(CXXConstructExpr * E)1188 void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
1189 VisitExpr(E);
1190 E->NumArgs = Record[Idx++];
1191 if (E->NumArgs)
1192 E->Args = new (Reader.getContext()) Stmt*[E->NumArgs];
1193 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1194 E->setArg(I, Reader.ReadSubExpr());
1195 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
1196 E->setLocation(ReadSourceLocation(Record, Idx));
1197 E->setElidable(Record[Idx++]);
1198 E->setHadMultipleCandidates(Record[Idx++]);
1199 E->setListInitialization(Record[Idx++]);
1200 E->setStdInitListInitialization(Record[Idx++]);
1201 E->setRequiresZeroInitialization(Record[Idx++]);
1202 E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
1203 E->ParenOrBraceRange = ReadSourceRange(Record, Idx);
1204 }
1205
VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr * E)1206 void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1207 VisitCXXConstructExpr(E);
1208 E->Type = GetTypeSourceInfo(Record, Idx);
1209 }
1210
VisitLambdaExpr(LambdaExpr * E)1211 void ASTStmtReader::VisitLambdaExpr(LambdaExpr *E) {
1212 VisitExpr(E);
1213 unsigned NumCaptures = Record[Idx++];
1214 assert(NumCaptures == E->NumCaptures);(void)NumCaptures;
1215 unsigned NumArrayIndexVars = Record[Idx++];
1216 E->IntroducerRange = ReadSourceRange(Record, Idx);
1217 E->CaptureDefault = static_cast<LambdaCaptureDefault>(Record[Idx++]);
1218 E->CaptureDefaultLoc = ReadSourceLocation(Record, Idx);
1219 E->ExplicitParams = Record[Idx++];
1220 E->ExplicitResultType = Record[Idx++];
1221 E->ClosingBrace = ReadSourceLocation(Record, Idx);
1222
1223 // Read capture initializers.
1224 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1225 CEnd = E->capture_init_end();
1226 C != CEnd; ++C)
1227 *C = Reader.ReadSubExpr();
1228
1229 // Read array capture index variables.
1230 if (NumArrayIndexVars > 0) {
1231 unsigned *ArrayIndexStarts = E->getArrayIndexStarts();
1232 for (unsigned I = 0; I != NumCaptures + 1; ++I)
1233 ArrayIndexStarts[I] = Record[Idx++];
1234
1235 VarDecl **ArrayIndexVars = E->getArrayIndexVars();
1236 for (unsigned I = 0; I != NumArrayIndexVars; ++I)
1237 ArrayIndexVars[I] = ReadDeclAs<VarDecl>(Record, Idx);
1238 }
1239 }
1240
1241 void
VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr * E)1242 ASTStmtReader::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1243 VisitExpr(E);
1244 E->SubExpr = Reader.ReadSubExpr();
1245 }
1246
VisitCXXNamedCastExpr(CXXNamedCastExpr * E)1247 void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1248 VisitExplicitCastExpr(E);
1249 SourceRange R = ReadSourceRange(Record, Idx);
1250 E->Loc = R.getBegin();
1251 E->RParenLoc = R.getEnd();
1252 R = ReadSourceRange(Record, Idx);
1253 E->AngleBrackets = R;
1254 }
1255
VisitCXXStaticCastExpr(CXXStaticCastExpr * E)1256 void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1257 return VisitCXXNamedCastExpr(E);
1258 }
1259
VisitCXXDynamicCastExpr(CXXDynamicCastExpr * E)1260 void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1261 return VisitCXXNamedCastExpr(E);
1262 }
1263
VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr * E)1264 void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1265 return VisitCXXNamedCastExpr(E);
1266 }
1267
VisitCXXConstCastExpr(CXXConstCastExpr * E)1268 void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1269 return VisitCXXNamedCastExpr(E);
1270 }
1271
VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr * E)1272 void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1273 VisitExplicitCastExpr(E);
1274 E->setLParenLoc(ReadSourceLocation(Record, Idx));
1275 E->setRParenLoc(ReadSourceLocation(Record, Idx));
1276 }
1277
VisitUserDefinedLiteral(UserDefinedLiteral * E)1278 void ASTStmtReader::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1279 VisitCallExpr(E);
1280 E->UDSuffixLoc = ReadSourceLocation(Record, Idx);
1281 }
1282
VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr * E)1283 void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1284 VisitExpr(E);
1285 E->setValue(Record[Idx++]);
1286 E->setLocation(ReadSourceLocation(Record, Idx));
1287 }
1288
VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr * E)1289 void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1290 VisitExpr(E);
1291 E->setLocation(ReadSourceLocation(Record, Idx));
1292 }
1293
VisitCXXTypeidExpr(CXXTypeidExpr * E)1294 void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1295 VisitExpr(E);
1296 E->setSourceRange(ReadSourceRange(Record, Idx));
1297 if (E->isTypeOperand()) { // typeid(int)
1298 E->setTypeOperandSourceInfo(
1299 GetTypeSourceInfo(Record, Idx));
1300 return;
1301 }
1302
1303 // typeid(42+2)
1304 E->setExprOperand(Reader.ReadSubExpr());
1305 }
1306
VisitCXXThisExpr(CXXThisExpr * E)1307 void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
1308 VisitExpr(E);
1309 E->setLocation(ReadSourceLocation(Record, Idx));
1310 E->setImplicit(Record[Idx++]);
1311 }
1312
VisitCXXThrowExpr(CXXThrowExpr * E)1313 void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
1314 VisitExpr(E);
1315 E->ThrowLoc = ReadSourceLocation(Record, Idx);
1316 E->Op = Reader.ReadSubExpr();
1317 E->IsThrownVariableInScope = Record[Idx++];
1318 }
1319
VisitCXXDefaultArgExpr(CXXDefaultArgExpr * E)1320 void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1321 VisitExpr(E);
1322
1323 assert((bool)Record[Idx] == E->Param.getInt() && "We messed up at creation ?");
1324 ++Idx; // HasOtherExprStored and SubExpr was handled during creation.
1325 E->Param.setPointer(ReadDeclAs<ParmVarDecl>(Record, Idx));
1326 E->Loc = ReadSourceLocation(Record, Idx);
1327 }
1328
VisitCXXDefaultInitExpr(CXXDefaultInitExpr * E)1329 void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1330 VisitExpr(E);
1331 E->Field = ReadDeclAs<FieldDecl>(Record, Idx);
1332 E->Loc = ReadSourceLocation(Record, Idx);
1333 }
1334
VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr * E)1335 void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1336 VisitExpr(E);
1337 E->setTemporary(Reader.ReadCXXTemporary(F, Record, Idx));
1338 E->setSubExpr(Reader.ReadSubExpr());
1339 }
1340
VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr * E)1341 void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1342 VisitExpr(E);
1343 E->TypeInfo = GetTypeSourceInfo(Record, Idx);
1344 E->RParenLoc = ReadSourceLocation(Record, Idx);
1345 }
1346
VisitCXXNewExpr(CXXNewExpr * E)1347 void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
1348 VisitExpr(E);
1349 E->GlobalNew = Record[Idx++];
1350 bool isArray = Record[Idx++];
1351 E->UsualArrayDeleteWantsSize = Record[Idx++];
1352 unsigned NumPlacementArgs = Record[Idx++];
1353 E->StoredInitializationStyle = Record[Idx++];
1354 E->setOperatorNew(ReadDeclAs<FunctionDecl>(Record, Idx));
1355 E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx));
1356 E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
1357 E->TypeIdParens = ReadSourceRange(Record, Idx);
1358 E->Range = ReadSourceRange(Record, Idx);
1359 E->DirectInitRange = ReadSourceRange(Record, Idx);
1360
1361 E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs,
1362 E->StoredInitializationStyle != 0);
1363
1364 // Install all the subexpressions.
1365 for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
1366 I != e; ++I)
1367 *I = Reader.ReadSubStmt();
1368 }
1369
VisitCXXDeleteExpr(CXXDeleteExpr * E)1370 void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1371 VisitExpr(E);
1372 E->GlobalDelete = Record[Idx++];
1373 E->ArrayForm = Record[Idx++];
1374 E->ArrayFormAsWritten = Record[Idx++];
1375 E->UsualArrayDeleteWantsSize = Record[Idx++];
1376 E->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
1377 E->Argument = Reader.ReadSubExpr();
1378 E->Loc = ReadSourceLocation(Record, Idx);
1379 }
1380
VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr * E)1381 void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1382 VisitExpr(E);
1383
1384 E->Base = Reader.ReadSubExpr();
1385 E->IsArrow = Record[Idx++];
1386 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1387 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1388 E->ScopeType = GetTypeSourceInfo(Record, Idx);
1389 E->ColonColonLoc = ReadSourceLocation(Record, Idx);
1390 E->TildeLoc = ReadSourceLocation(Record, Idx);
1391
1392 IdentifierInfo *II = Reader.GetIdentifierInfo(F, Record, Idx);
1393 if (II)
1394 E->setDestroyedType(II, ReadSourceLocation(Record, Idx));
1395 else
1396 E->setDestroyedType(GetTypeSourceInfo(Record, Idx));
1397 }
1398
VisitExprWithCleanups(ExprWithCleanups * E)1399 void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
1400 VisitExpr(E);
1401
1402 unsigned NumObjects = Record[Idx++];
1403 assert(NumObjects == E->getNumObjects());
1404 for (unsigned i = 0; i != NumObjects; ++i)
1405 E->getObjectsBuffer()[i] = ReadDeclAs<BlockDecl>(Record, Idx);
1406
1407 E->SubExpr = Reader.ReadSubExpr();
1408 }
1409
1410 void
VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr * E)1411 ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
1412 VisitExpr(E);
1413
1414 if (Record[Idx++]) // HasTemplateKWAndArgsInfo
1415 ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
1416 /*NumTemplateArgs=*/Record[Idx++]);
1417
1418 E->Base = Reader.ReadSubExpr();
1419 E->BaseType = Reader.readType(F, Record, Idx);
1420 E->IsArrow = Record[Idx++];
1421 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1422 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1423 E->FirstQualifierFoundInScope = ReadDeclAs<NamedDecl>(Record, Idx);
1424 ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx);
1425 }
1426
1427 void
VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr * E)1428 ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1429 VisitExpr(E);
1430
1431 if (Record[Idx++]) // HasTemplateKWAndArgsInfo
1432 ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
1433 /*NumTemplateArgs=*/Record[Idx++]);
1434
1435 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1436 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
1437 }
1438
1439 void
VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr * E)1440 ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1441 VisitExpr(E);
1442 assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
1443 ++Idx; // NumArgs;
1444 for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
1445 E->setArg(I, Reader.ReadSubExpr());
1446 E->Type = GetTypeSourceInfo(Record, Idx);
1447 E->setLParenLoc(ReadSourceLocation(Record, Idx));
1448 E->setRParenLoc(ReadSourceLocation(Record, Idx));
1449 }
1450
VisitOverloadExpr(OverloadExpr * E)1451 void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
1452 VisitExpr(E);
1453
1454 if (Record[Idx++]) // HasTemplateKWAndArgsInfo
1455 ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
1456 /*NumTemplateArgs=*/Record[Idx++]);
1457
1458 unsigned NumDecls = Record[Idx++];
1459 UnresolvedSet<8> Decls;
1460 for (unsigned i = 0; i != NumDecls; ++i) {
1461 NamedDecl *D = ReadDeclAs<NamedDecl>(Record, Idx);
1462 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1463 Decls.addDecl(D, AS);
1464 }
1465 E->initializeResults(Reader.getContext(), Decls.begin(), Decls.end());
1466
1467 ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
1468 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1469 }
1470
VisitUnresolvedMemberExpr(UnresolvedMemberExpr * E)1471 void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1472 VisitOverloadExpr(E);
1473 E->IsArrow = Record[Idx++];
1474 E->HasUnresolvedUsing = Record[Idx++];
1475 E->Base = Reader.ReadSubExpr();
1476 E->BaseType = Reader.readType(F, Record, Idx);
1477 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1478 }
1479
VisitUnresolvedLookupExpr(UnresolvedLookupExpr * E)1480 void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1481 VisitOverloadExpr(E);
1482 E->RequiresADL = Record[Idx++];
1483 E->Overloaded = Record[Idx++];
1484 E->NamingClass = ReadDeclAs<CXXRecordDecl>(Record, Idx);
1485 }
1486
VisitTypeTraitExpr(TypeTraitExpr * E)1487 void ASTStmtReader::VisitTypeTraitExpr(TypeTraitExpr *E) {
1488 VisitExpr(E);
1489 E->TypeTraitExprBits.NumArgs = Record[Idx++];
1490 E->TypeTraitExprBits.Kind = Record[Idx++];
1491 E->TypeTraitExprBits.Value = Record[Idx++];
1492 SourceRange Range = ReadSourceRange(Record, Idx);
1493 E->Loc = Range.getBegin();
1494 E->RParenLoc = Range.getEnd();
1495
1496 TypeSourceInfo **Args = E->getTypeSourceInfos();
1497 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1498 Args[I] = GetTypeSourceInfo(Record, Idx);
1499 }
1500
VisitArrayTypeTraitExpr(ArrayTypeTraitExpr * E)1501 void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1502 VisitExpr(E);
1503 E->ATT = (ArrayTypeTrait)Record[Idx++];
1504 E->Value = (unsigned int)Record[Idx++];
1505 SourceRange Range = ReadSourceRange(Record, Idx);
1506 E->Loc = Range.getBegin();
1507 E->RParen = Range.getEnd();
1508 E->QueriedType = GetTypeSourceInfo(Record, Idx);
1509 }
1510
VisitExpressionTraitExpr(ExpressionTraitExpr * E)1511 void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1512 VisitExpr(E);
1513 E->ET = (ExpressionTrait)Record[Idx++];
1514 E->Value = (bool)Record[Idx++];
1515 SourceRange Range = ReadSourceRange(Record, Idx);
1516 E->QueriedExpression = Reader.ReadSubExpr();
1517 E->Loc = Range.getBegin();
1518 E->RParen = Range.getEnd();
1519 }
1520
VisitCXXNoexceptExpr(CXXNoexceptExpr * E)1521 void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1522 VisitExpr(E);
1523 E->Value = (bool)Record[Idx++];
1524 E->Range = ReadSourceRange(Record, Idx);
1525 E->Operand = Reader.ReadSubExpr();
1526 }
1527
VisitPackExpansionExpr(PackExpansionExpr * E)1528 void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
1529 VisitExpr(E);
1530 E->EllipsisLoc = ReadSourceLocation(Record, Idx);
1531 E->NumExpansions = Record[Idx++];
1532 E->Pattern = Reader.ReadSubExpr();
1533 }
1534
VisitSizeOfPackExpr(SizeOfPackExpr * E)1535 void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1536 VisitExpr(E);
1537 E->OperatorLoc = ReadSourceLocation(Record, Idx);
1538 E->PackLoc = ReadSourceLocation(Record, Idx);
1539 E->RParenLoc = ReadSourceLocation(Record, Idx);
1540 E->Length = Record[Idx++];
1541 E->Pack = ReadDeclAs<NamedDecl>(Record, Idx);
1542 }
1543
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr * E)1544 void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
1545 SubstNonTypeTemplateParmExpr *E) {
1546 VisitExpr(E);
1547 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
1548 E->NameLoc = ReadSourceLocation(Record, Idx);
1549 E->Replacement = Reader.ReadSubExpr();
1550 }
1551
VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr * E)1552 void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
1553 SubstNonTypeTemplateParmPackExpr *E) {
1554 VisitExpr(E);
1555 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
1556 TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx);
1557 if (ArgPack.getKind() != TemplateArgument::Pack)
1558 return;
1559
1560 E->Arguments = ArgPack.pack_begin();
1561 E->NumArguments = ArgPack.pack_size();
1562 E->NameLoc = ReadSourceLocation(Record, Idx);
1563 }
1564
VisitFunctionParmPackExpr(FunctionParmPackExpr * E)1565 void ASTStmtReader::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1566 VisitExpr(E);
1567 E->NumParameters = Record[Idx++];
1568 E->ParamPack = ReadDeclAs<ParmVarDecl>(Record, Idx);
1569 E->NameLoc = ReadSourceLocation(Record, Idx);
1570 ParmVarDecl **Parms = reinterpret_cast<ParmVarDecl**>(E+1);
1571 for (unsigned i = 0, n = E->NumParameters; i != n; ++i)
1572 Parms[i] = ReadDeclAs<ParmVarDecl>(Record, Idx);
1573 }
1574
VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr * E)1575 void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1576 VisitExpr(E);
1577 E->State = Reader.ReadSubExpr();
1578 auto VD = ReadDeclAs<ValueDecl>(Record, Idx);
1579 unsigned ManglingNumber = Record[Idx++];
1580 E->setExtendingDecl(VD, ManglingNumber);
1581 }
1582
VisitCXXFoldExpr(CXXFoldExpr * E)1583 void ASTStmtReader::VisitCXXFoldExpr(CXXFoldExpr *E) {
1584 VisitExpr(E);
1585 E->LParenLoc = ReadSourceLocation(Record, Idx);
1586 E->EllipsisLoc = ReadSourceLocation(Record, Idx);
1587 E->RParenLoc = ReadSourceLocation(Record, Idx);
1588 E->SubExprs[0] = Reader.ReadSubExpr();
1589 E->SubExprs[1] = Reader.ReadSubExpr();
1590 E->Opcode = (BinaryOperatorKind)Record[Idx++];
1591 }
1592
VisitOpaqueValueExpr(OpaqueValueExpr * E)1593 void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1594 VisitExpr(E);
1595 E->SourceExpr = Reader.ReadSubExpr();
1596 E->Loc = ReadSourceLocation(Record, Idx);
1597 }
1598
VisitTypoExpr(TypoExpr * E)1599 void ASTStmtReader::VisitTypoExpr(TypoExpr *E) {
1600 llvm_unreachable("Cannot read TypoExpr nodes");
1601 }
1602
1603 //===----------------------------------------------------------------------===//
1604 // Microsoft Expressions and Statements
1605 //===----------------------------------------------------------------------===//
VisitMSPropertyRefExpr(MSPropertyRefExpr * E)1606 void ASTStmtReader::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1607 VisitExpr(E);
1608 E->IsArrow = (Record[Idx++] != 0);
1609 E->BaseExpr = Reader.ReadSubExpr();
1610 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1611 E->MemberLoc = ReadSourceLocation(Record, Idx);
1612 E->TheDecl = ReadDeclAs<MSPropertyDecl>(Record, Idx);
1613 }
1614
VisitCXXUuidofExpr(CXXUuidofExpr * E)1615 void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1616 VisitExpr(E);
1617 E->setSourceRange(ReadSourceRange(Record, Idx));
1618 if (E->isTypeOperand()) { // __uuidof(ComType)
1619 E->setTypeOperandSourceInfo(
1620 GetTypeSourceInfo(Record, Idx));
1621 return;
1622 }
1623
1624 // __uuidof(expr)
1625 E->setExprOperand(Reader.ReadSubExpr());
1626 }
1627
VisitSEHLeaveStmt(SEHLeaveStmt * S)1628 void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1629 VisitStmt(S);
1630 S->setLeaveLoc(ReadSourceLocation(Record, Idx));
1631 }
1632
VisitSEHExceptStmt(SEHExceptStmt * S)1633 void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
1634 VisitStmt(S);
1635 S->Loc = ReadSourceLocation(Record, Idx);
1636 S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt();
1637 S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt();
1638 }
1639
VisitSEHFinallyStmt(SEHFinallyStmt * S)1640 void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1641 VisitStmt(S);
1642 S->Loc = ReadSourceLocation(Record, Idx);
1643 S->Block = Reader.ReadSubStmt();
1644 }
1645
VisitSEHTryStmt(SEHTryStmt * S)1646 void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
1647 VisitStmt(S);
1648 S->IsCXXTry = Record[Idx++];
1649 S->TryLoc = ReadSourceLocation(Record, Idx);
1650 S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt();
1651 S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
1652 }
1653
1654 //===----------------------------------------------------------------------===//
1655 // CUDA Expressions and Statements
1656 //===----------------------------------------------------------------------===//
1657
VisitCUDAKernelCallExpr(CUDAKernelCallExpr * E)1658 void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1659 VisitCallExpr(E);
1660 E->setConfig(cast<CallExpr>(Reader.ReadSubExpr()));
1661 }
1662
1663 //===----------------------------------------------------------------------===//
1664 // OpenCL Expressions and Statements.
1665 //===----------------------------------------------------------------------===//
VisitAsTypeExpr(AsTypeExpr * E)1666 void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
1667 VisitExpr(E);
1668 E->BuiltinLoc = ReadSourceLocation(Record, Idx);
1669 E->RParenLoc = ReadSourceLocation(Record, Idx);
1670 E->SrcExpr = Reader.ReadSubExpr();
1671 }
1672
1673 //===----------------------------------------------------------------------===//
1674 // OpenMP Clauses.
1675 //===----------------------------------------------------------------------===//
1676
1677 namespace clang {
1678 class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> {
1679 ASTStmtReader *Reader;
1680 ASTContext &Context;
1681 const ASTReader::RecordData &Record;
1682 unsigned &Idx;
1683 public:
OMPClauseReader(ASTStmtReader * R,ASTContext & C,const ASTReader::RecordData & Record,unsigned & Idx)1684 OMPClauseReader(ASTStmtReader *R, ASTContext &C,
1685 const ASTReader::RecordData &Record, unsigned &Idx)
1686 : Reader(R), Context(C), Record(Record), Idx(Idx) { }
1687 #define OPENMP_CLAUSE(Name, Class) \
1688 void Visit##Class(Class *S);
1689 #include "clang/Basic/OpenMPKinds.def"
1690 OMPClause *readClause();
1691 };
1692 }
1693
readClause()1694 OMPClause *OMPClauseReader::readClause() {
1695 OMPClause *C;
1696 switch (Record[Idx++]) {
1697 case OMPC_if:
1698 C = new (Context) OMPIfClause();
1699 break;
1700 case OMPC_final:
1701 C = new (Context) OMPFinalClause();
1702 break;
1703 case OMPC_num_threads:
1704 C = new (Context) OMPNumThreadsClause();
1705 break;
1706 case OMPC_safelen:
1707 C = new (Context) OMPSafelenClause();
1708 break;
1709 case OMPC_collapse:
1710 C = new (Context) OMPCollapseClause();
1711 break;
1712 case OMPC_default:
1713 C = new (Context) OMPDefaultClause();
1714 break;
1715 case OMPC_proc_bind:
1716 C = new (Context) OMPProcBindClause();
1717 break;
1718 case OMPC_schedule:
1719 C = new (Context) OMPScheduleClause();
1720 break;
1721 case OMPC_ordered:
1722 C = new (Context) OMPOrderedClause();
1723 break;
1724 case OMPC_nowait:
1725 C = new (Context) OMPNowaitClause();
1726 break;
1727 case OMPC_untied:
1728 C = new (Context) OMPUntiedClause();
1729 break;
1730 case OMPC_mergeable:
1731 C = new (Context) OMPMergeableClause();
1732 break;
1733 case OMPC_read:
1734 C = new (Context) OMPReadClause();
1735 break;
1736 case OMPC_write:
1737 C = new (Context) OMPWriteClause();
1738 break;
1739 case OMPC_update:
1740 C = new (Context) OMPUpdateClause();
1741 break;
1742 case OMPC_capture:
1743 C = new (Context) OMPCaptureClause();
1744 break;
1745 case OMPC_seq_cst:
1746 C = new (Context) OMPSeqCstClause();
1747 break;
1748 case OMPC_private:
1749 C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
1750 break;
1751 case OMPC_firstprivate:
1752 C = OMPFirstprivateClause::CreateEmpty(Context, Record[Idx++]);
1753 break;
1754 case OMPC_lastprivate:
1755 C = OMPLastprivateClause::CreateEmpty(Context, Record[Idx++]);
1756 break;
1757 case OMPC_shared:
1758 C = OMPSharedClause::CreateEmpty(Context, Record[Idx++]);
1759 break;
1760 case OMPC_reduction:
1761 C = OMPReductionClause::CreateEmpty(Context, Record[Idx++]);
1762 break;
1763 case OMPC_linear:
1764 C = OMPLinearClause::CreateEmpty(Context, Record[Idx++]);
1765 break;
1766 case OMPC_aligned:
1767 C = OMPAlignedClause::CreateEmpty(Context, Record[Idx++]);
1768 break;
1769 case OMPC_copyin:
1770 C = OMPCopyinClause::CreateEmpty(Context, Record[Idx++]);
1771 break;
1772 case OMPC_copyprivate:
1773 C = OMPCopyprivateClause::CreateEmpty(Context, Record[Idx++]);
1774 break;
1775 case OMPC_flush:
1776 C = OMPFlushClause::CreateEmpty(Context, Record[Idx++]);
1777 break;
1778 }
1779 Visit(C);
1780 C->setLocStart(Reader->ReadSourceLocation(Record, Idx));
1781 C->setLocEnd(Reader->ReadSourceLocation(Record, Idx));
1782
1783 return C;
1784 }
1785
VisitOMPIfClause(OMPIfClause * C)1786 void OMPClauseReader::VisitOMPIfClause(OMPIfClause *C) {
1787 C->setCondition(Reader->Reader.ReadSubExpr());
1788 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1789 }
1790
VisitOMPFinalClause(OMPFinalClause * C)1791 void OMPClauseReader::VisitOMPFinalClause(OMPFinalClause *C) {
1792 C->setCondition(Reader->Reader.ReadSubExpr());
1793 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1794 }
1795
VisitOMPNumThreadsClause(OMPNumThreadsClause * C)1796 void OMPClauseReader::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
1797 C->setNumThreads(Reader->Reader.ReadSubExpr());
1798 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1799 }
1800
VisitOMPSafelenClause(OMPSafelenClause * C)1801 void OMPClauseReader::VisitOMPSafelenClause(OMPSafelenClause *C) {
1802 C->setSafelen(Reader->Reader.ReadSubExpr());
1803 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1804 }
1805
VisitOMPCollapseClause(OMPCollapseClause * C)1806 void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) {
1807 C->setNumForLoops(Reader->Reader.ReadSubExpr());
1808 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1809 }
1810
VisitOMPDefaultClause(OMPDefaultClause * C)1811 void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) {
1812 C->setDefaultKind(
1813 static_cast<OpenMPDefaultClauseKind>(Record[Idx++]));
1814 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1815 C->setDefaultKindKwLoc(Reader->ReadSourceLocation(Record, Idx));
1816 }
1817
VisitOMPProcBindClause(OMPProcBindClause * C)1818 void OMPClauseReader::VisitOMPProcBindClause(OMPProcBindClause *C) {
1819 C->setProcBindKind(
1820 static_cast<OpenMPProcBindClauseKind>(Record[Idx++]));
1821 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1822 C->setProcBindKindKwLoc(Reader->ReadSourceLocation(Record, Idx));
1823 }
1824
VisitOMPScheduleClause(OMPScheduleClause * C)1825 void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) {
1826 C->setScheduleKind(
1827 static_cast<OpenMPScheduleClauseKind>(Record[Idx++]));
1828 C->setChunkSize(Reader->Reader.ReadSubExpr());
1829 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1830 C->setScheduleKindLoc(Reader->ReadSourceLocation(Record, Idx));
1831 C->setCommaLoc(Reader->ReadSourceLocation(Record, Idx));
1832 }
1833
VisitOMPOrderedClause(OMPOrderedClause *)1834 void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *) {}
1835
VisitOMPNowaitClause(OMPNowaitClause *)1836 void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {}
1837
VisitOMPUntiedClause(OMPUntiedClause *)1838 void OMPClauseReader::VisitOMPUntiedClause(OMPUntiedClause *) {}
1839
VisitOMPMergeableClause(OMPMergeableClause *)1840 void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {}
1841
VisitOMPReadClause(OMPReadClause *)1842 void OMPClauseReader::VisitOMPReadClause(OMPReadClause *) {}
1843
VisitOMPWriteClause(OMPWriteClause *)1844 void OMPClauseReader::VisitOMPWriteClause(OMPWriteClause *) {}
1845
VisitOMPUpdateClause(OMPUpdateClause *)1846 void OMPClauseReader::VisitOMPUpdateClause(OMPUpdateClause *) {}
1847
VisitOMPCaptureClause(OMPCaptureClause *)1848 void OMPClauseReader::VisitOMPCaptureClause(OMPCaptureClause *) {}
1849
VisitOMPSeqCstClause(OMPSeqCstClause *)1850 void OMPClauseReader::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
1851
VisitOMPPrivateClause(OMPPrivateClause * C)1852 void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
1853 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1854 unsigned NumVars = C->varlist_size();
1855 SmallVector<Expr *, 16> Vars;
1856 Vars.reserve(NumVars);
1857 for (unsigned i = 0; i != NumVars; ++i)
1858 Vars.push_back(Reader->Reader.ReadSubExpr());
1859 C->setVarRefs(Vars);
1860 Vars.clear();
1861 for (unsigned i = 0; i != NumVars; ++i)
1862 Vars.push_back(Reader->Reader.ReadSubExpr());
1863 C->setPrivateCopies(Vars);
1864 }
1865
VisitOMPFirstprivateClause(OMPFirstprivateClause * C)1866 void OMPClauseReader::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
1867 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1868 unsigned NumVars = C->varlist_size();
1869 SmallVector<Expr *, 16> Vars;
1870 Vars.reserve(NumVars);
1871 for (unsigned i = 0; i != NumVars; ++i)
1872 Vars.push_back(Reader->Reader.ReadSubExpr());
1873 C->setVarRefs(Vars);
1874 Vars.clear();
1875 for (unsigned i = 0; i != NumVars; ++i)
1876 Vars.push_back(Reader->Reader.ReadSubExpr());
1877 C->setPrivateCopies(Vars);
1878 Vars.clear();
1879 for (unsigned i = 0; i != NumVars; ++i)
1880 Vars.push_back(Reader->Reader.ReadSubExpr());
1881 C->setInits(Vars);
1882 }
1883
VisitOMPLastprivateClause(OMPLastprivateClause * C)1884 void OMPClauseReader::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
1885 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1886 unsigned NumVars = C->varlist_size();
1887 SmallVector<Expr *, 16> Vars;
1888 Vars.reserve(NumVars);
1889 for (unsigned i = 0; i != NumVars; ++i)
1890 Vars.push_back(Reader->Reader.ReadSubExpr());
1891 C->setVarRefs(Vars);
1892 Vars.clear();
1893 for (unsigned i = 0; i != NumVars; ++i)
1894 Vars.push_back(Reader->Reader.ReadSubExpr());
1895 C->setPrivateCopies(Vars);
1896 Vars.clear();
1897 for (unsigned i = 0; i != NumVars; ++i)
1898 Vars.push_back(Reader->Reader.ReadSubExpr());
1899 C->setSourceExprs(Vars);
1900 Vars.clear();
1901 for (unsigned i = 0; i != NumVars; ++i)
1902 Vars.push_back(Reader->Reader.ReadSubExpr());
1903 C->setDestinationExprs(Vars);
1904 Vars.clear();
1905 for (unsigned i = 0; i != NumVars; ++i)
1906 Vars.push_back(Reader->Reader.ReadSubExpr());
1907 C->setAssignmentOps(Vars);
1908 }
1909
VisitOMPSharedClause(OMPSharedClause * C)1910 void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) {
1911 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1912 unsigned NumVars = C->varlist_size();
1913 SmallVector<Expr *, 16> Vars;
1914 Vars.reserve(NumVars);
1915 for (unsigned i = 0; i != NumVars; ++i)
1916 Vars.push_back(Reader->Reader.ReadSubExpr());
1917 C->setVarRefs(Vars);
1918 }
1919
VisitOMPReductionClause(OMPReductionClause * C)1920 void OMPClauseReader::VisitOMPReductionClause(OMPReductionClause *C) {
1921 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1922 C->setColonLoc(Reader->ReadSourceLocation(Record, Idx));
1923 NestedNameSpecifierLoc NNSL =
1924 Reader->Reader.ReadNestedNameSpecifierLoc(Reader->F, Record, Idx);
1925 DeclarationNameInfo DNI;
1926 Reader->ReadDeclarationNameInfo(DNI, Record, Idx);
1927 C->setQualifierLoc(NNSL);
1928 C->setNameInfo(DNI);
1929
1930 unsigned NumVars = C->varlist_size();
1931 SmallVector<Expr *, 16> Vars;
1932 Vars.reserve(NumVars);
1933 for (unsigned i = 0; i != NumVars; ++i)
1934 Vars.push_back(Reader->Reader.ReadSubExpr());
1935 C->setVarRefs(Vars);
1936 Vars.clear();
1937 for (unsigned i = 0; i != NumVars; ++i)
1938 Vars.push_back(Reader->Reader.ReadSubExpr());
1939 C->setLHSExprs(Vars);
1940 Vars.clear();
1941 for (unsigned i = 0; i != NumVars; ++i)
1942 Vars.push_back(Reader->Reader.ReadSubExpr());
1943 C->setRHSExprs(Vars);
1944 Vars.clear();
1945 for (unsigned i = 0; i != NumVars; ++i)
1946 Vars.push_back(Reader->Reader.ReadSubExpr());
1947 C->setReductionOps(Vars);
1948 }
1949
VisitOMPLinearClause(OMPLinearClause * C)1950 void OMPClauseReader::VisitOMPLinearClause(OMPLinearClause *C) {
1951 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1952 C->setColonLoc(Reader->ReadSourceLocation(Record, Idx));
1953 unsigned NumVars = C->varlist_size();
1954 SmallVector<Expr *, 16> Vars;
1955 Vars.reserve(NumVars);
1956 for (unsigned i = 0; i != NumVars; ++i)
1957 Vars.push_back(Reader->Reader.ReadSubExpr());
1958 C->setVarRefs(Vars);
1959 Vars.clear();
1960 for (unsigned i = 0; i != NumVars; ++i)
1961 Vars.push_back(Reader->Reader.ReadSubExpr());
1962 C->setInits(Vars);
1963 Vars.clear();
1964 for (unsigned i = 0; i != NumVars; ++i)
1965 Vars.push_back(Reader->Reader.ReadSubExpr());
1966 C->setUpdates(Vars);
1967 Vars.clear();
1968 for (unsigned i = 0; i != NumVars; ++i)
1969 Vars.push_back(Reader->Reader.ReadSubExpr());
1970 C->setFinals(Vars);
1971 C->setStep(Reader->Reader.ReadSubExpr());
1972 C->setCalcStep(Reader->Reader.ReadSubExpr());
1973 }
1974
VisitOMPAlignedClause(OMPAlignedClause * C)1975 void OMPClauseReader::VisitOMPAlignedClause(OMPAlignedClause *C) {
1976 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1977 C->setColonLoc(Reader->ReadSourceLocation(Record, Idx));
1978 unsigned NumVars = C->varlist_size();
1979 SmallVector<Expr *, 16> Vars;
1980 Vars.reserve(NumVars);
1981 for (unsigned i = 0; i != NumVars; ++i)
1982 Vars.push_back(Reader->Reader.ReadSubExpr());
1983 C->setVarRefs(Vars);
1984 C->setAlignment(Reader->Reader.ReadSubExpr());
1985 }
1986
VisitOMPCopyinClause(OMPCopyinClause * C)1987 void OMPClauseReader::VisitOMPCopyinClause(OMPCopyinClause *C) {
1988 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1989 unsigned NumVars = C->varlist_size();
1990 SmallVector<Expr *, 16> Exprs;
1991 Exprs.reserve(NumVars);
1992 for (unsigned i = 0; i != NumVars; ++i)
1993 Exprs.push_back(Reader->Reader.ReadSubExpr());
1994 C->setVarRefs(Exprs);
1995 Exprs.clear();
1996 for (unsigned i = 0; i != NumVars; ++i)
1997 Exprs.push_back(Reader->Reader.ReadSubExpr());
1998 C->setSourceExprs(Exprs);
1999 Exprs.clear();
2000 for (unsigned i = 0; i != NumVars; ++i)
2001 Exprs.push_back(Reader->Reader.ReadSubExpr());
2002 C->setDestinationExprs(Exprs);
2003 Exprs.clear();
2004 for (unsigned i = 0; i != NumVars; ++i)
2005 Exprs.push_back(Reader->Reader.ReadSubExpr());
2006 C->setAssignmentOps(Exprs);
2007 }
2008
VisitOMPCopyprivateClause(OMPCopyprivateClause * C)2009 void OMPClauseReader::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
2010 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
2011 unsigned NumVars = C->varlist_size();
2012 SmallVector<Expr *, 16> Exprs;
2013 Exprs.reserve(NumVars);
2014 for (unsigned i = 0; i != NumVars; ++i)
2015 Exprs.push_back(Reader->Reader.ReadSubExpr());
2016 C->setVarRefs(Exprs);
2017 Exprs.clear();
2018 for (unsigned i = 0; i != NumVars; ++i)
2019 Exprs.push_back(Reader->Reader.ReadSubExpr());
2020 C->setSourceExprs(Exprs);
2021 Exprs.clear();
2022 for (unsigned i = 0; i != NumVars; ++i)
2023 Exprs.push_back(Reader->Reader.ReadSubExpr());
2024 C->setDestinationExprs(Exprs);
2025 Exprs.clear();
2026 for (unsigned i = 0; i != NumVars; ++i)
2027 Exprs.push_back(Reader->Reader.ReadSubExpr());
2028 C->setAssignmentOps(Exprs);
2029 }
2030
VisitOMPFlushClause(OMPFlushClause * C)2031 void OMPClauseReader::VisitOMPFlushClause(OMPFlushClause *C) {
2032 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
2033 unsigned NumVars = C->varlist_size();
2034 SmallVector<Expr *, 16> Vars;
2035 Vars.reserve(NumVars);
2036 for (unsigned i = 0; i != NumVars; ++i)
2037 Vars.push_back(Reader->Reader.ReadSubExpr());
2038 C->setVarRefs(Vars);
2039 }
2040
2041 //===----------------------------------------------------------------------===//
2042 // OpenMP Directives.
2043 //===----------------------------------------------------------------------===//
VisitOMPExecutableDirective(OMPExecutableDirective * E)2044 void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2045 E->setLocStart(ReadSourceLocation(Record, Idx));
2046 E->setLocEnd(ReadSourceLocation(Record, Idx));
2047 OMPClauseReader ClauseReader(this, Reader.getContext(), Record, Idx);
2048 SmallVector<OMPClause *, 5> Clauses;
2049 for (unsigned i = 0; i < E->getNumClauses(); ++i)
2050 Clauses.push_back(ClauseReader.readClause());
2051 E->setClauses(Clauses);
2052 if (E->hasAssociatedStmt())
2053 E->setAssociatedStmt(Reader.ReadSubStmt());
2054 }
2055
VisitOMPLoopDirective(OMPLoopDirective * D)2056 void ASTStmtReader::VisitOMPLoopDirective(OMPLoopDirective *D) {
2057 VisitStmt(D);
2058 // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream.
2059 Idx += 2;
2060 VisitOMPExecutableDirective(D);
2061 D->setIterationVariable(Reader.ReadSubExpr());
2062 D->setLastIteration(Reader.ReadSubExpr());
2063 D->setCalcLastIteration(Reader.ReadSubExpr());
2064 D->setPreCond(Reader.ReadSubExpr());
2065 auto Fst = Reader.ReadSubExpr();
2066 auto Snd = Reader.ReadSubExpr();
2067 D->setCond(Fst, Snd);
2068 D->setInit(Reader.ReadSubExpr());
2069 D->setInc(Reader.ReadSubExpr());
2070 if (isOpenMPWorksharingDirective(D->getDirectiveKind())) {
2071 D->setIsLastIterVariable(Reader.ReadSubExpr());
2072 D->setLowerBoundVariable(Reader.ReadSubExpr());
2073 D->setUpperBoundVariable(Reader.ReadSubExpr());
2074 D->setStrideVariable(Reader.ReadSubExpr());
2075 D->setEnsureUpperBound(Reader.ReadSubExpr());
2076 D->setNextLowerBound(Reader.ReadSubExpr());
2077 D->setNextUpperBound(Reader.ReadSubExpr());
2078 }
2079 SmallVector<Expr *, 4> Sub;
2080 unsigned CollapsedNum = D->getCollapsedNumber();
2081 Sub.reserve(CollapsedNum);
2082 for (unsigned i = 0; i < CollapsedNum; ++i)
2083 Sub.push_back(Reader.ReadSubExpr());
2084 D->setCounters(Sub);
2085 Sub.clear();
2086 for (unsigned i = 0; i < CollapsedNum; ++i)
2087 Sub.push_back(Reader.ReadSubExpr());
2088 D->setUpdates(Sub);
2089 Sub.clear();
2090 for (unsigned i = 0; i < CollapsedNum; ++i)
2091 Sub.push_back(Reader.ReadSubExpr());
2092 D->setFinals(Sub);
2093 }
2094
VisitOMPParallelDirective(OMPParallelDirective * D)2095 void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) {
2096 VisitStmt(D);
2097 // The NumClauses field was read in ReadStmtFromStream.
2098 ++Idx;
2099 VisitOMPExecutableDirective(D);
2100 }
2101
VisitOMPSimdDirective(OMPSimdDirective * D)2102 void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) {
2103 VisitOMPLoopDirective(D);
2104 }
2105
VisitOMPForDirective(OMPForDirective * D)2106 void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) {
2107 VisitOMPLoopDirective(D);
2108 }
2109
VisitOMPForSimdDirective(OMPForSimdDirective * D)2110 void ASTStmtReader::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2111 VisitOMPLoopDirective(D);
2112 }
2113
VisitOMPSectionsDirective(OMPSectionsDirective * D)2114 void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2115 VisitStmt(D);
2116 // The NumClauses field was read in ReadStmtFromStream.
2117 ++Idx;
2118 VisitOMPExecutableDirective(D);
2119 }
2120
VisitOMPSectionDirective(OMPSectionDirective * D)2121 void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) {
2122 VisitStmt(D);
2123 VisitOMPExecutableDirective(D);
2124 }
2125
VisitOMPSingleDirective(OMPSingleDirective * D)2126 void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) {
2127 VisitStmt(D);
2128 // The NumClauses field was read in ReadStmtFromStream.
2129 ++Idx;
2130 VisitOMPExecutableDirective(D);
2131 }
2132
VisitOMPMasterDirective(OMPMasterDirective * D)2133 void ASTStmtReader::VisitOMPMasterDirective(OMPMasterDirective *D) {
2134 VisitStmt(D);
2135 VisitOMPExecutableDirective(D);
2136 }
2137
VisitOMPCriticalDirective(OMPCriticalDirective * D)2138 void ASTStmtReader::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2139 VisitStmt(D);
2140 VisitOMPExecutableDirective(D);
2141 ReadDeclarationNameInfo(D->DirName, Record, Idx);
2142 }
2143
VisitOMPParallelForDirective(OMPParallelForDirective * D)2144 void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2145 VisitOMPLoopDirective(D);
2146 }
2147
VisitOMPParallelForSimdDirective(OMPParallelForSimdDirective * D)2148 void ASTStmtReader::VisitOMPParallelForSimdDirective(
2149 OMPParallelForSimdDirective *D) {
2150 VisitOMPLoopDirective(D);
2151 }
2152
VisitOMPParallelSectionsDirective(OMPParallelSectionsDirective * D)2153 void ASTStmtReader::VisitOMPParallelSectionsDirective(
2154 OMPParallelSectionsDirective *D) {
2155 VisitStmt(D);
2156 // The NumClauses field was read in ReadStmtFromStream.
2157 ++Idx;
2158 VisitOMPExecutableDirective(D);
2159 }
2160
VisitOMPTaskDirective(OMPTaskDirective * D)2161 void ASTStmtReader::VisitOMPTaskDirective(OMPTaskDirective *D) {
2162 VisitStmt(D);
2163 // The NumClauses field was read in ReadStmtFromStream.
2164 ++Idx;
2165 VisitOMPExecutableDirective(D);
2166 }
2167
VisitOMPTaskyieldDirective(OMPTaskyieldDirective * D)2168 void ASTStmtReader::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2169 VisitStmt(D);
2170 VisitOMPExecutableDirective(D);
2171 }
2172
VisitOMPBarrierDirective(OMPBarrierDirective * D)2173 void ASTStmtReader::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2174 VisitStmt(D);
2175 VisitOMPExecutableDirective(D);
2176 }
2177
VisitOMPTaskwaitDirective(OMPTaskwaitDirective * D)2178 void ASTStmtReader::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2179 VisitStmt(D);
2180 VisitOMPExecutableDirective(D);
2181 }
2182
VisitOMPFlushDirective(OMPFlushDirective * D)2183 void ASTStmtReader::VisitOMPFlushDirective(OMPFlushDirective *D) {
2184 VisitStmt(D);
2185 // The NumClauses field was read in ReadStmtFromStream.
2186 ++Idx;
2187 VisitOMPExecutableDirective(D);
2188 }
2189
VisitOMPOrderedDirective(OMPOrderedDirective * D)2190 void ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2191 VisitStmt(D);
2192 VisitOMPExecutableDirective(D);
2193 }
2194
VisitOMPAtomicDirective(OMPAtomicDirective * D)2195 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2196 VisitStmt(D);
2197 // The NumClauses field was read in ReadStmtFromStream.
2198 ++Idx;
2199 VisitOMPExecutableDirective(D);
2200 D->setX(Reader.ReadSubExpr());
2201 D->setV(Reader.ReadSubExpr());
2202 D->setExpr(Reader.ReadSubExpr());
2203 D->setUpdateExpr(Reader.ReadSubExpr());
2204 D->IsXLHSInRHSPart = Record[Idx++] != 0;
2205 D->IsPostfixUpdate = Record[Idx++] != 0;
2206 }
2207
VisitOMPTargetDirective(OMPTargetDirective * D)2208 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
2209 VisitStmt(D);
2210 // The NumClauses field was read in ReadStmtFromStream.
2211 ++Idx;
2212 VisitOMPExecutableDirective(D);
2213 }
2214
VisitOMPTeamsDirective(OMPTeamsDirective * D)2215 void ASTStmtReader::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2216 VisitStmt(D);
2217 // The NumClauses field was read in ReadStmtFromStream.
2218 ++Idx;
2219 VisitOMPExecutableDirective(D);
2220 }
2221
2222 //===----------------------------------------------------------------------===//
2223 // ASTReader Implementation
2224 //===----------------------------------------------------------------------===//
2225
ReadStmt(ModuleFile & F)2226 Stmt *ASTReader::ReadStmt(ModuleFile &F) {
2227 switch (ReadingKind) {
2228 case Read_None:
2229 llvm_unreachable("should not call this when not reading anything");
2230 case Read_Decl:
2231 case Read_Type:
2232 return ReadStmtFromStream(F);
2233 case Read_Stmt:
2234 return ReadSubStmt();
2235 }
2236
2237 llvm_unreachable("ReadingKind not set ?");
2238 }
2239
ReadExpr(ModuleFile & F)2240 Expr *ASTReader::ReadExpr(ModuleFile &F) {
2241 return cast_or_null<Expr>(ReadStmt(F));
2242 }
2243
ReadSubExpr()2244 Expr *ASTReader::ReadSubExpr() {
2245 return cast_or_null<Expr>(ReadSubStmt());
2246 }
2247
2248 // Within the bitstream, expressions are stored in Reverse Polish
2249 // Notation, with each of the subexpressions preceding the
2250 // expression they are stored in. Subexpressions are stored from last to first.
2251 // To evaluate expressions, we continue reading expressions and placing them on
2252 // the stack, with expressions having operands removing those operands from the
2253 // stack. Evaluation terminates when we see a STMT_STOP record, and
2254 // the single remaining expression on the stack is our result.
ReadStmtFromStream(ModuleFile & F)2255 Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
2256
2257 ReadingKindTracker ReadingKind(Read_Stmt, *this);
2258 llvm::BitstreamCursor &Cursor = F.DeclsCursor;
2259
2260 // Map of offset to previously deserialized stmt. The offset points
2261 /// just after the stmt record.
2262 llvm::DenseMap<uint64_t, Stmt *> StmtEntries;
2263
2264 #ifndef NDEBUG
2265 unsigned PrevNumStmts = StmtStack.size();
2266 #endif
2267
2268 RecordData Record;
2269 unsigned Idx;
2270 ASTStmtReader Reader(*this, F, Cursor, Record, Idx);
2271 Stmt::EmptyShell Empty;
2272
2273 while (true) {
2274 llvm::BitstreamEntry Entry = Cursor.advanceSkippingSubblocks();
2275
2276 switch (Entry.Kind) {
2277 case llvm::BitstreamEntry::SubBlock: // Handled for us already.
2278 case llvm::BitstreamEntry::Error:
2279 Error("malformed block record in AST file");
2280 return nullptr;
2281 case llvm::BitstreamEntry::EndBlock:
2282 goto Done;
2283 case llvm::BitstreamEntry::Record:
2284 // The interesting case.
2285 break;
2286 }
2287
2288 Stmt *S = nullptr;
2289 Idx = 0;
2290 Record.clear();
2291 bool Finished = false;
2292 bool IsStmtReference = false;
2293 switch ((StmtCode)Cursor.readRecord(Entry.ID, Record)) {
2294 case STMT_STOP:
2295 Finished = true;
2296 break;
2297
2298 case STMT_REF_PTR:
2299 IsStmtReference = true;
2300 assert(StmtEntries.find(Record[0]) != StmtEntries.end() &&
2301 "No stmt was recorded for this offset reference!");
2302 S = StmtEntries[Record[Idx++]];
2303 break;
2304
2305 case STMT_NULL_PTR:
2306 S = nullptr;
2307 break;
2308
2309 case STMT_NULL:
2310 S = new (Context) NullStmt(Empty);
2311 break;
2312
2313 case STMT_COMPOUND:
2314 S = new (Context) CompoundStmt(Empty);
2315 break;
2316
2317 case STMT_CASE:
2318 S = new (Context) CaseStmt(Empty);
2319 break;
2320
2321 case STMT_DEFAULT:
2322 S = new (Context) DefaultStmt(Empty);
2323 break;
2324
2325 case STMT_LABEL:
2326 S = new (Context) LabelStmt(Empty);
2327 break;
2328
2329 case STMT_ATTRIBUTED:
2330 S = AttributedStmt::CreateEmpty(
2331 Context,
2332 /*NumAttrs*/Record[ASTStmtReader::NumStmtFields]);
2333 break;
2334
2335 case STMT_IF:
2336 S = new (Context) IfStmt(Empty);
2337 break;
2338
2339 case STMT_SWITCH:
2340 S = new (Context) SwitchStmt(Empty);
2341 break;
2342
2343 case STMT_WHILE:
2344 S = new (Context) WhileStmt(Empty);
2345 break;
2346
2347 case STMT_DO:
2348 S = new (Context) DoStmt(Empty);
2349 break;
2350
2351 case STMT_FOR:
2352 S = new (Context) ForStmt(Empty);
2353 break;
2354
2355 case STMT_GOTO:
2356 S = new (Context) GotoStmt(Empty);
2357 break;
2358
2359 case STMT_INDIRECT_GOTO:
2360 S = new (Context) IndirectGotoStmt(Empty);
2361 break;
2362
2363 case STMT_CONTINUE:
2364 S = new (Context) ContinueStmt(Empty);
2365 break;
2366
2367 case STMT_BREAK:
2368 S = new (Context) BreakStmt(Empty);
2369 break;
2370
2371 case STMT_RETURN:
2372 S = new (Context) ReturnStmt(Empty);
2373 break;
2374
2375 case STMT_DECL:
2376 S = new (Context) DeclStmt(Empty);
2377 break;
2378
2379 case STMT_GCCASM:
2380 S = new (Context) GCCAsmStmt(Empty);
2381 break;
2382
2383 case STMT_MSASM:
2384 S = new (Context) MSAsmStmt(Empty);
2385 break;
2386
2387 case STMT_CAPTURED:
2388 S = CapturedStmt::CreateDeserialized(Context,
2389 Record[ASTStmtReader::NumStmtFields]);
2390 break;
2391
2392 case EXPR_PREDEFINED:
2393 S = new (Context) PredefinedExpr(Empty);
2394 break;
2395
2396 case EXPR_DECL_REF:
2397 S = DeclRefExpr::CreateEmpty(
2398 Context,
2399 /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
2400 /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
2401 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 2],
2402 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
2403 Record[ASTStmtReader::NumExprFields + 5] : 0);
2404 break;
2405
2406 case EXPR_INTEGER_LITERAL:
2407 S = IntegerLiteral::Create(Context, Empty);
2408 break;
2409
2410 case EXPR_FLOATING_LITERAL:
2411 S = FloatingLiteral::Create(Context, Empty);
2412 break;
2413
2414 case EXPR_IMAGINARY_LITERAL:
2415 S = new (Context) ImaginaryLiteral(Empty);
2416 break;
2417
2418 case EXPR_STRING_LITERAL:
2419 S = StringLiteral::CreateEmpty(Context,
2420 Record[ASTStmtReader::NumExprFields + 1]);
2421 break;
2422
2423 case EXPR_CHARACTER_LITERAL:
2424 S = new (Context) CharacterLiteral(Empty);
2425 break;
2426
2427 case EXPR_PAREN:
2428 S = new (Context) ParenExpr(Empty);
2429 break;
2430
2431 case EXPR_PAREN_LIST:
2432 S = new (Context) ParenListExpr(Empty);
2433 break;
2434
2435 case EXPR_UNARY_OPERATOR:
2436 S = new (Context) UnaryOperator(Empty);
2437 break;
2438
2439 case EXPR_OFFSETOF:
2440 S = OffsetOfExpr::CreateEmpty(Context,
2441 Record[ASTStmtReader::NumExprFields],
2442 Record[ASTStmtReader::NumExprFields + 1]);
2443 break;
2444
2445 case EXPR_SIZEOF_ALIGN_OF:
2446 S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
2447 break;
2448
2449 case EXPR_ARRAY_SUBSCRIPT:
2450 S = new (Context) ArraySubscriptExpr(Empty);
2451 break;
2452
2453 case EXPR_CALL:
2454 S = new (Context) CallExpr(Context, Stmt::CallExprClass, Empty);
2455 break;
2456
2457 case EXPR_MEMBER: {
2458 // We load everything here and fully initialize it at creation.
2459 // That way we can use MemberExpr::Create and don't have to duplicate its
2460 // logic with a MemberExpr::CreateEmpty.
2461
2462 assert(Idx == 0);
2463 NestedNameSpecifierLoc QualifierLoc;
2464 if (Record[Idx++]) { // HasQualifier.
2465 QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
2466 }
2467
2468 SourceLocation TemplateKWLoc;
2469 TemplateArgumentListInfo ArgInfo;
2470 bool HasTemplateKWAndArgsInfo = Record[Idx++];
2471 if (HasTemplateKWAndArgsInfo) {
2472 TemplateKWLoc = ReadSourceLocation(F, Record, Idx);
2473 unsigned NumTemplateArgs = Record[Idx++];
2474 ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx));
2475 ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx));
2476 for (unsigned i = 0; i != NumTemplateArgs; ++i)
2477 ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx));
2478 }
2479
2480 bool HadMultipleCandidates = Record[Idx++];
2481
2482 NamedDecl *FoundD = ReadDeclAs<NamedDecl>(F, Record, Idx);
2483 AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
2484 DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS);
2485
2486 QualType T = readType(F, Record, Idx);
2487 ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]);
2488 ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]);
2489 Expr *Base = ReadSubExpr();
2490 ValueDecl *MemberD = ReadDeclAs<ValueDecl>(F, Record, Idx);
2491 SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx);
2492 DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc);
2493 bool IsArrow = Record[Idx++];
2494 SourceLocation OperatorLoc = ReadSourceLocation(F, Record, Idx);
2495
2496 S = MemberExpr::Create(Context, Base, IsArrow, OperatorLoc, QualifierLoc,
2497 TemplateKWLoc, MemberD, FoundDecl, MemberNameInfo,
2498 HasTemplateKWAndArgsInfo ? &ArgInfo : nullptr, T,
2499 VK, OK);
2500 ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc,
2501 MemberD->getDeclName(), Record, Idx);
2502 if (HadMultipleCandidates)
2503 cast<MemberExpr>(S)->setHadMultipleCandidates(true);
2504 break;
2505 }
2506
2507 case EXPR_BINARY_OPERATOR:
2508 S = new (Context) BinaryOperator(Empty);
2509 break;
2510
2511 case EXPR_COMPOUND_ASSIGN_OPERATOR:
2512 S = new (Context) CompoundAssignOperator(Empty);
2513 break;
2514
2515 case EXPR_CONDITIONAL_OPERATOR:
2516 S = new (Context) ConditionalOperator(Empty);
2517 break;
2518
2519 case EXPR_BINARY_CONDITIONAL_OPERATOR:
2520 S = new (Context) BinaryConditionalOperator(Empty);
2521 break;
2522
2523 case EXPR_IMPLICIT_CAST:
2524 S = ImplicitCastExpr::CreateEmpty(Context,
2525 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2526 break;
2527
2528 case EXPR_CSTYLE_CAST:
2529 S = CStyleCastExpr::CreateEmpty(Context,
2530 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2531 break;
2532
2533 case EXPR_COMPOUND_LITERAL:
2534 S = new (Context) CompoundLiteralExpr(Empty);
2535 break;
2536
2537 case EXPR_EXT_VECTOR_ELEMENT:
2538 S = new (Context) ExtVectorElementExpr(Empty);
2539 break;
2540
2541 case EXPR_INIT_LIST:
2542 S = new (Context) InitListExpr(Empty);
2543 break;
2544
2545 case EXPR_DESIGNATED_INIT:
2546 S = DesignatedInitExpr::CreateEmpty(Context,
2547 Record[ASTStmtReader::NumExprFields] - 1);
2548
2549 break;
2550
2551 case EXPR_IMPLICIT_VALUE_INIT:
2552 S = new (Context) ImplicitValueInitExpr(Empty);
2553 break;
2554
2555 case EXPR_VA_ARG:
2556 S = new (Context) VAArgExpr(Empty);
2557 break;
2558
2559 case EXPR_ADDR_LABEL:
2560 S = new (Context) AddrLabelExpr(Empty);
2561 break;
2562
2563 case EXPR_STMT:
2564 S = new (Context) StmtExpr(Empty);
2565 break;
2566
2567 case EXPR_CHOOSE:
2568 S = new (Context) ChooseExpr(Empty);
2569 break;
2570
2571 case EXPR_GNU_NULL:
2572 S = new (Context) GNUNullExpr(Empty);
2573 break;
2574
2575 case EXPR_SHUFFLE_VECTOR:
2576 S = new (Context) ShuffleVectorExpr(Empty);
2577 break;
2578
2579 case EXPR_CONVERT_VECTOR:
2580 S = new (Context) ConvertVectorExpr(Empty);
2581 break;
2582
2583 case EXPR_BLOCK:
2584 S = new (Context) BlockExpr(Empty);
2585 break;
2586
2587 case EXPR_GENERIC_SELECTION:
2588 S = new (Context) GenericSelectionExpr(Empty);
2589 break;
2590
2591 case EXPR_OBJC_STRING_LITERAL:
2592 S = new (Context) ObjCStringLiteral(Empty);
2593 break;
2594 case EXPR_OBJC_BOXED_EXPRESSION:
2595 S = new (Context) ObjCBoxedExpr(Empty);
2596 break;
2597 case EXPR_OBJC_ARRAY_LITERAL:
2598 S = ObjCArrayLiteral::CreateEmpty(Context,
2599 Record[ASTStmtReader::NumExprFields]);
2600 break;
2601 case EXPR_OBJC_DICTIONARY_LITERAL:
2602 S = ObjCDictionaryLiteral::CreateEmpty(Context,
2603 Record[ASTStmtReader::NumExprFields],
2604 Record[ASTStmtReader::NumExprFields + 1]);
2605 break;
2606 case EXPR_OBJC_ENCODE:
2607 S = new (Context) ObjCEncodeExpr(Empty);
2608 break;
2609 case EXPR_OBJC_SELECTOR_EXPR:
2610 S = new (Context) ObjCSelectorExpr(Empty);
2611 break;
2612 case EXPR_OBJC_PROTOCOL_EXPR:
2613 S = new (Context) ObjCProtocolExpr(Empty);
2614 break;
2615 case EXPR_OBJC_IVAR_REF_EXPR:
2616 S = new (Context) ObjCIvarRefExpr(Empty);
2617 break;
2618 case EXPR_OBJC_PROPERTY_REF_EXPR:
2619 S = new (Context) ObjCPropertyRefExpr(Empty);
2620 break;
2621 case EXPR_OBJC_SUBSCRIPT_REF_EXPR:
2622 S = new (Context) ObjCSubscriptRefExpr(Empty);
2623 break;
2624 case EXPR_OBJC_KVC_REF_EXPR:
2625 llvm_unreachable("mismatching AST file");
2626 case EXPR_OBJC_MESSAGE_EXPR:
2627 S = ObjCMessageExpr::CreateEmpty(Context,
2628 Record[ASTStmtReader::NumExprFields],
2629 Record[ASTStmtReader::NumExprFields + 1]);
2630 break;
2631 case EXPR_OBJC_ISA:
2632 S = new (Context) ObjCIsaExpr(Empty);
2633 break;
2634 case EXPR_OBJC_INDIRECT_COPY_RESTORE:
2635 S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
2636 break;
2637 case EXPR_OBJC_BRIDGED_CAST:
2638 S = new (Context) ObjCBridgedCastExpr(Empty);
2639 break;
2640 case STMT_OBJC_FOR_COLLECTION:
2641 S = new (Context) ObjCForCollectionStmt(Empty);
2642 break;
2643 case STMT_OBJC_CATCH:
2644 S = new (Context) ObjCAtCatchStmt(Empty);
2645 break;
2646 case STMT_OBJC_FINALLY:
2647 S = new (Context) ObjCAtFinallyStmt(Empty);
2648 break;
2649 case STMT_OBJC_AT_TRY:
2650 S = ObjCAtTryStmt::CreateEmpty(Context,
2651 Record[ASTStmtReader::NumStmtFields],
2652 Record[ASTStmtReader::NumStmtFields + 1]);
2653 break;
2654 case STMT_OBJC_AT_SYNCHRONIZED:
2655 S = new (Context) ObjCAtSynchronizedStmt(Empty);
2656 break;
2657 case STMT_OBJC_AT_THROW:
2658 S = new (Context) ObjCAtThrowStmt(Empty);
2659 break;
2660 case STMT_OBJC_AUTORELEASE_POOL:
2661 S = new (Context) ObjCAutoreleasePoolStmt(Empty);
2662 break;
2663 case EXPR_OBJC_BOOL_LITERAL:
2664 S = new (Context) ObjCBoolLiteralExpr(Empty);
2665 break;
2666 case STMT_SEH_LEAVE:
2667 S = new (Context) SEHLeaveStmt(Empty);
2668 break;
2669 case STMT_SEH_EXCEPT:
2670 S = new (Context) SEHExceptStmt(Empty);
2671 break;
2672 case STMT_SEH_FINALLY:
2673 S = new (Context) SEHFinallyStmt(Empty);
2674 break;
2675 case STMT_SEH_TRY:
2676 S = new (Context) SEHTryStmt(Empty);
2677 break;
2678 case STMT_CXX_CATCH:
2679 S = new (Context) CXXCatchStmt(Empty);
2680 break;
2681
2682 case STMT_CXX_TRY:
2683 S = CXXTryStmt::Create(Context, Empty,
2684 /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]);
2685 break;
2686
2687 case STMT_CXX_FOR_RANGE:
2688 S = new (Context) CXXForRangeStmt(Empty);
2689 break;
2690
2691 case STMT_MS_DEPENDENT_EXISTS:
2692 S = new (Context) MSDependentExistsStmt(SourceLocation(), true,
2693 NestedNameSpecifierLoc(),
2694 DeclarationNameInfo(),
2695 nullptr);
2696 break;
2697
2698 case STMT_OMP_PARALLEL_DIRECTIVE:
2699 S =
2700 OMPParallelDirective::CreateEmpty(Context,
2701 Record[ASTStmtReader::NumStmtFields],
2702 Empty);
2703 break;
2704
2705 case STMT_OMP_SIMD_DIRECTIVE: {
2706 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
2707 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
2708 S = OMPSimdDirective::CreateEmpty(Context, NumClauses,
2709 CollapsedNum, Empty);
2710 break;
2711 }
2712
2713 case STMT_OMP_FOR_DIRECTIVE: {
2714 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
2715 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
2716 S = OMPForDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
2717 Empty);
2718 break;
2719 }
2720
2721 case STMT_OMP_FOR_SIMD_DIRECTIVE: {
2722 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
2723 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
2724 S = OMPForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
2725 Empty);
2726 break;
2727 }
2728
2729 case STMT_OMP_SECTIONS_DIRECTIVE:
2730 S = OMPSectionsDirective::CreateEmpty(
2731 Context, Record[ASTStmtReader::NumStmtFields], Empty);
2732 break;
2733
2734 case STMT_OMP_SECTION_DIRECTIVE:
2735 S = OMPSectionDirective::CreateEmpty(Context, Empty);
2736 break;
2737
2738 case STMT_OMP_SINGLE_DIRECTIVE:
2739 S = OMPSingleDirective::CreateEmpty(
2740 Context, Record[ASTStmtReader::NumStmtFields], Empty);
2741 break;
2742
2743 case STMT_OMP_MASTER_DIRECTIVE:
2744 S = OMPMasterDirective::CreateEmpty(Context, Empty);
2745 break;
2746
2747 case STMT_OMP_CRITICAL_DIRECTIVE:
2748 S = OMPCriticalDirective::CreateEmpty(Context, Empty);
2749 break;
2750
2751 case STMT_OMP_PARALLEL_FOR_DIRECTIVE: {
2752 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
2753 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
2754 S = OMPParallelForDirective::CreateEmpty(Context, NumClauses,
2755 CollapsedNum, Empty);
2756 break;
2757 }
2758
2759 case STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE: {
2760 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
2761 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
2762 S = OMPParallelForSimdDirective::CreateEmpty(Context, NumClauses,
2763 CollapsedNum, Empty);
2764 break;
2765 }
2766
2767 case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
2768 S = OMPParallelSectionsDirective::CreateEmpty(
2769 Context, Record[ASTStmtReader::NumStmtFields], Empty);
2770 break;
2771
2772 case STMT_OMP_TASK_DIRECTIVE:
2773 S = OMPTaskDirective::CreateEmpty(
2774 Context, Record[ASTStmtReader::NumStmtFields], Empty);
2775 break;
2776
2777 case STMT_OMP_TASKYIELD_DIRECTIVE:
2778 S = OMPTaskyieldDirective::CreateEmpty(Context, Empty);
2779 break;
2780
2781 case STMT_OMP_BARRIER_DIRECTIVE:
2782 S = OMPBarrierDirective::CreateEmpty(Context, Empty);
2783 break;
2784
2785 case STMT_OMP_TASKWAIT_DIRECTIVE:
2786 S = OMPTaskwaitDirective::CreateEmpty(Context, Empty);
2787 break;
2788
2789 case STMT_OMP_FLUSH_DIRECTIVE:
2790 S = OMPFlushDirective::CreateEmpty(
2791 Context, Record[ASTStmtReader::NumStmtFields], Empty);
2792 break;
2793
2794 case STMT_OMP_ORDERED_DIRECTIVE:
2795 S = OMPOrderedDirective::CreateEmpty(Context, Empty);
2796 break;
2797
2798 case STMT_OMP_ATOMIC_DIRECTIVE:
2799 S = OMPAtomicDirective::CreateEmpty(
2800 Context, Record[ASTStmtReader::NumStmtFields], Empty);
2801 break;
2802
2803 case STMT_OMP_TARGET_DIRECTIVE:
2804 S = OMPTargetDirective::CreateEmpty(
2805 Context, Record[ASTStmtReader::NumStmtFields], Empty);
2806 break;
2807
2808 case STMT_OMP_TEAMS_DIRECTIVE:
2809 S = OMPTeamsDirective::CreateEmpty(
2810 Context, Record[ASTStmtReader::NumStmtFields], Empty);
2811 break;
2812
2813 case EXPR_CXX_OPERATOR_CALL:
2814 S = new (Context) CXXOperatorCallExpr(Context, Empty);
2815 break;
2816
2817 case EXPR_CXX_MEMBER_CALL:
2818 S = new (Context) CXXMemberCallExpr(Context, Empty);
2819 break;
2820
2821 case EXPR_CXX_CONSTRUCT:
2822 S = new (Context) CXXConstructExpr(Empty);
2823 break;
2824
2825 case EXPR_CXX_TEMPORARY_OBJECT:
2826 S = new (Context) CXXTemporaryObjectExpr(Empty);
2827 break;
2828
2829 case EXPR_CXX_STATIC_CAST:
2830 S = CXXStaticCastExpr::CreateEmpty(Context,
2831 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2832 break;
2833
2834 case EXPR_CXX_DYNAMIC_CAST:
2835 S = CXXDynamicCastExpr::CreateEmpty(Context,
2836 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2837 break;
2838
2839 case EXPR_CXX_REINTERPRET_CAST:
2840 S = CXXReinterpretCastExpr::CreateEmpty(Context,
2841 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2842 break;
2843
2844 case EXPR_CXX_CONST_CAST:
2845 S = CXXConstCastExpr::CreateEmpty(Context);
2846 break;
2847
2848 case EXPR_CXX_FUNCTIONAL_CAST:
2849 S = CXXFunctionalCastExpr::CreateEmpty(Context,
2850 /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2851 break;
2852
2853 case EXPR_USER_DEFINED_LITERAL:
2854 S = new (Context) UserDefinedLiteral(Context, Empty);
2855 break;
2856
2857 case EXPR_CXX_STD_INITIALIZER_LIST:
2858 S = new (Context) CXXStdInitializerListExpr(Empty);
2859 break;
2860
2861 case EXPR_CXX_BOOL_LITERAL:
2862 S = new (Context) CXXBoolLiteralExpr(Empty);
2863 break;
2864
2865 case EXPR_CXX_NULL_PTR_LITERAL:
2866 S = new (Context) CXXNullPtrLiteralExpr(Empty);
2867 break;
2868 case EXPR_CXX_TYPEID_EXPR:
2869 S = new (Context) CXXTypeidExpr(Empty, true);
2870 break;
2871 case EXPR_CXX_TYPEID_TYPE:
2872 S = new (Context) CXXTypeidExpr(Empty, false);
2873 break;
2874 case EXPR_CXX_UUIDOF_EXPR:
2875 S = new (Context) CXXUuidofExpr(Empty, true);
2876 break;
2877 case EXPR_CXX_PROPERTY_REF_EXPR:
2878 S = new (Context) MSPropertyRefExpr(Empty);
2879 break;
2880 case EXPR_CXX_UUIDOF_TYPE:
2881 S = new (Context) CXXUuidofExpr(Empty, false);
2882 break;
2883 case EXPR_CXX_THIS:
2884 S = new (Context) CXXThisExpr(Empty);
2885 break;
2886 case EXPR_CXX_THROW:
2887 S = new (Context) CXXThrowExpr(Empty);
2888 break;
2889 case EXPR_CXX_DEFAULT_ARG: {
2890 bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields];
2891 if (HasOtherExprStored) {
2892 Expr *SubExpr = ReadSubExpr();
2893 S = CXXDefaultArgExpr::Create(Context, SourceLocation(), nullptr,
2894 SubExpr);
2895 } else
2896 S = new (Context) CXXDefaultArgExpr(Empty);
2897 break;
2898 }
2899 case EXPR_CXX_DEFAULT_INIT:
2900 S = new (Context) CXXDefaultInitExpr(Empty);
2901 break;
2902 case EXPR_CXX_BIND_TEMPORARY:
2903 S = new (Context) CXXBindTemporaryExpr(Empty);
2904 break;
2905
2906 case EXPR_CXX_SCALAR_VALUE_INIT:
2907 S = new (Context) CXXScalarValueInitExpr(Empty);
2908 break;
2909 case EXPR_CXX_NEW:
2910 S = new (Context) CXXNewExpr(Empty);
2911 break;
2912 case EXPR_CXX_DELETE:
2913 S = new (Context) CXXDeleteExpr(Empty);
2914 break;
2915 case EXPR_CXX_PSEUDO_DESTRUCTOR:
2916 S = new (Context) CXXPseudoDestructorExpr(Empty);
2917 break;
2918
2919 case EXPR_EXPR_WITH_CLEANUPS:
2920 S = ExprWithCleanups::Create(Context, Empty,
2921 Record[ASTStmtReader::NumExprFields]);
2922 break;
2923
2924 case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
2925 S = CXXDependentScopeMemberExpr::CreateEmpty(Context,
2926 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
2927 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
2928 ? Record[ASTStmtReader::NumExprFields + 1]
2929 : 0);
2930 break;
2931
2932 case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
2933 S = DependentScopeDeclRefExpr::CreateEmpty(Context,
2934 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
2935 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
2936 ? Record[ASTStmtReader::NumExprFields + 1]
2937 : 0);
2938 break;
2939
2940 case EXPR_CXX_UNRESOLVED_CONSTRUCT:
2941 S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
2942 /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
2943 break;
2944
2945 case EXPR_CXX_UNRESOLVED_MEMBER:
2946 S = UnresolvedMemberExpr::CreateEmpty(Context,
2947 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
2948 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
2949 ? Record[ASTStmtReader::NumExprFields + 1]
2950 : 0);
2951 break;
2952
2953 case EXPR_CXX_UNRESOLVED_LOOKUP:
2954 S = UnresolvedLookupExpr::CreateEmpty(Context,
2955 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
2956 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
2957 ? Record[ASTStmtReader::NumExprFields + 1]
2958 : 0);
2959 break;
2960
2961 case EXPR_TYPE_TRAIT:
2962 S = TypeTraitExpr::CreateDeserialized(Context,
2963 Record[ASTStmtReader::NumExprFields]);
2964 break;
2965
2966 case EXPR_ARRAY_TYPE_TRAIT:
2967 S = new (Context) ArrayTypeTraitExpr(Empty);
2968 break;
2969
2970 case EXPR_CXX_EXPRESSION_TRAIT:
2971 S = new (Context) ExpressionTraitExpr(Empty);
2972 break;
2973
2974 case EXPR_CXX_NOEXCEPT:
2975 S = new (Context) CXXNoexceptExpr(Empty);
2976 break;
2977
2978 case EXPR_PACK_EXPANSION:
2979 S = new (Context) PackExpansionExpr(Empty);
2980 break;
2981
2982 case EXPR_SIZEOF_PACK:
2983 S = new (Context) SizeOfPackExpr(Empty);
2984 break;
2985
2986 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
2987 S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
2988 break;
2989
2990 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
2991 S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
2992 break;
2993
2994 case EXPR_FUNCTION_PARM_PACK:
2995 S = FunctionParmPackExpr::CreateEmpty(Context,
2996 Record[ASTStmtReader::NumExprFields]);
2997 break;
2998
2999 case EXPR_MATERIALIZE_TEMPORARY:
3000 S = new (Context) MaterializeTemporaryExpr(Empty);
3001 break;
3002
3003 case EXPR_CXX_FOLD:
3004 S = new (Context) CXXFoldExpr(Empty);
3005 break;
3006
3007 case EXPR_OPAQUE_VALUE:
3008 S = new (Context) OpaqueValueExpr(Empty);
3009 break;
3010
3011 case EXPR_CUDA_KERNEL_CALL:
3012 S = new (Context) CUDAKernelCallExpr(Context, Empty);
3013 break;
3014
3015 case EXPR_ASTYPE:
3016 S = new (Context) AsTypeExpr(Empty);
3017 break;
3018
3019 case EXPR_PSEUDO_OBJECT: {
3020 unsigned numSemanticExprs = Record[ASTStmtReader::NumExprFields];
3021 S = PseudoObjectExpr::Create(Context, Empty, numSemanticExprs);
3022 break;
3023 }
3024
3025 case EXPR_ATOMIC:
3026 S = new (Context) AtomicExpr(Empty);
3027 break;
3028
3029 case EXPR_LAMBDA: {
3030 unsigned NumCaptures = Record[ASTStmtReader::NumExprFields];
3031 unsigned NumArrayIndexVars = Record[ASTStmtReader::NumExprFields + 1];
3032 S = LambdaExpr::CreateDeserialized(Context, NumCaptures,
3033 NumArrayIndexVars);
3034 break;
3035 }
3036 }
3037
3038 // We hit a STMT_STOP, so we're done with this expression.
3039 if (Finished)
3040 break;
3041
3042 ++NumStatementsRead;
3043
3044 if (S && !IsStmtReference) {
3045 Reader.Visit(S);
3046 StmtEntries[Cursor.GetCurrentBitNo()] = S;
3047 }
3048
3049
3050 assert(Idx == Record.size() && "Invalid deserialization of statement");
3051 StmtStack.push_back(S);
3052 }
3053 Done:
3054 assert(StmtStack.size() > PrevNumStmts && "Read too many sub-stmts!");
3055 assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
3056 return StmtStack.pop_back_val();
3057 }
3058