1 //===- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Statement/expression deserialization. This implements the
10 // ASTReader::ReadStmt method.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/AST/ASTConcept.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/AttrIterator.h"
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/DeclAccessPair.h"
19 #include "clang/AST/DeclCXX.h"
20 #include "clang/AST/DeclGroup.h"
21 #include "clang/AST/DeclObjC.h"
22 #include "clang/AST/DeclTemplate.h"
23 #include "clang/AST/DeclarationName.h"
24 #include "clang/AST/DependenceFlags.h"
25 #include "clang/AST/Expr.h"
26 #include "clang/AST/ExprCXX.h"
27 #include "clang/AST/ExprObjC.h"
28 #include "clang/AST/ExprOpenMP.h"
29 #include "clang/AST/NestedNameSpecifier.h"
30 #include "clang/AST/OpenMPClause.h"
31 #include "clang/AST/OperationKinds.h"
32 #include "clang/AST/Stmt.h"
33 #include "clang/AST/StmtCXX.h"
34 #include "clang/AST/StmtObjC.h"
35 #include "clang/AST/StmtOpenMP.h"
36 #include "clang/AST/StmtVisitor.h"
37 #include "clang/AST/TemplateBase.h"
38 #include "clang/AST/Type.h"
39 #include "clang/AST/UnresolvedSet.h"
40 #include "clang/Basic/CapturedStmt.h"
41 #include "clang/Basic/ExpressionTraits.h"
42 #include "clang/Basic/LLVM.h"
43 #include "clang/Basic/Lambda.h"
44 #include "clang/Basic/LangOptions.h"
45 #include "clang/Basic/OpenMPKinds.h"
46 #include "clang/Basic/OperatorKinds.h"
47 #include "clang/Basic/SourceLocation.h"
48 #include "clang/Basic/Specifiers.h"
49 #include "clang/Basic/TypeTraits.h"
50 #include "clang/Lex/Token.h"
51 #include "clang/Serialization/ASTBitCodes.h"
52 #include "clang/Serialization/ASTRecordReader.h"
53 #include "llvm/ADT/BitmaskEnum.h"
54 #include "llvm/ADT/DenseMap.h"
55 #include "llvm/ADT/SmallString.h"
56 #include "llvm/ADT/SmallVector.h"
57 #include "llvm/ADT/StringRef.h"
58 #include "llvm/Bitstream/BitstreamReader.h"
59 #include "llvm/Support/Casting.h"
60 #include "llvm/Support/ErrorHandling.h"
61 #include <algorithm>
62 #include <cassert>
63 #include <cstdint>
64 #include <optional>
65 #include <string>
66
67 using namespace clang;
68 using namespace serialization;
69
70 namespace clang {
71
72 class ASTStmtReader : public StmtVisitor<ASTStmtReader> {
73 ASTRecordReader &Record;
74 llvm::BitstreamCursor &DeclsCursor;
75
76 std::optional<BitsUnpacker> CurrentUnpackingBits;
77
readSourceLocation()78 SourceLocation readSourceLocation() {
79 return Record.readSourceLocation();
80 }
81
readSourceRange()82 SourceRange readSourceRange() {
83 return Record.readSourceRange();
84 }
85
readString()86 std::string readString() {
87 return Record.readString();
88 }
89
readTypeSourceInfo()90 TypeSourceInfo *readTypeSourceInfo() {
91 return Record.readTypeSourceInfo();
92 }
93
readDecl()94 Decl *readDecl() {
95 return Record.readDecl();
96 }
97
98 template<typename T>
readDeclAs()99 T *readDeclAs() {
100 return Record.readDeclAs<T>();
101 }
102
103 public:
ASTStmtReader(ASTRecordReader & Record,llvm::BitstreamCursor & Cursor)104 ASTStmtReader(ASTRecordReader &Record, llvm::BitstreamCursor &Cursor)
105 : Record(Record), DeclsCursor(Cursor) {}
106
107 /// The number of record fields required for the Stmt class
108 /// itself.
109 static const unsigned NumStmtFields = 0;
110
111 /// The number of record fields required for the Expr class
112 /// itself.
113 static const unsigned NumExprFields = NumStmtFields + 2;
114
115 /// The number of bits required for the packing bits for the Expr class.
116 static const unsigned NumExprBits = 10;
117
118 /// Read and initialize a ExplicitTemplateArgumentList structure.
119 void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
120 TemplateArgumentLoc *ArgsLocArray,
121 unsigned NumTemplateArgs);
122
123 void VisitStmt(Stmt *S);
124 #define STMT(Type, Base) \
125 void Visit##Type(Type *);
126 #include "clang/AST/StmtNodes.inc"
127 };
128
129 } // namespace clang
130
ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo & Args,TemplateArgumentLoc * ArgsLocArray,unsigned NumTemplateArgs)131 void ASTStmtReader::ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
132 TemplateArgumentLoc *ArgsLocArray,
133 unsigned NumTemplateArgs) {
134 SourceLocation TemplateKWLoc = readSourceLocation();
135 TemplateArgumentListInfo ArgInfo;
136 ArgInfo.setLAngleLoc(readSourceLocation());
137 ArgInfo.setRAngleLoc(readSourceLocation());
138 for (unsigned i = 0; i != NumTemplateArgs; ++i)
139 ArgInfo.addArgument(Record.readTemplateArgumentLoc());
140 Args.initializeFrom(TemplateKWLoc, ArgInfo, ArgsLocArray);
141 }
142
VisitStmt(Stmt * S)143 void ASTStmtReader::VisitStmt(Stmt *S) {
144 assert(Record.getIdx() == NumStmtFields && "Incorrect statement field count");
145 }
146
VisitNullStmt(NullStmt * S)147 void ASTStmtReader::VisitNullStmt(NullStmt *S) {
148 VisitStmt(S);
149 S->setSemiLoc(readSourceLocation());
150 S->NullStmtBits.HasLeadingEmptyMacro = Record.readInt();
151 }
152
VisitCompoundStmt(CompoundStmt * S)153 void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
154 VisitStmt(S);
155 SmallVector<Stmt *, 16> Stmts;
156 unsigned NumStmts = Record.readInt();
157 unsigned HasFPFeatures = Record.readInt();
158 assert(S->hasStoredFPFeatures() == HasFPFeatures);
159 while (NumStmts--)
160 Stmts.push_back(Record.readSubStmt());
161 S->setStmts(Stmts);
162 if (HasFPFeatures)
163 S->setStoredFPFeatures(
164 FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
165 S->LBraceLoc = readSourceLocation();
166 S->RBraceLoc = readSourceLocation();
167 }
168
VisitSwitchCase(SwitchCase * S)169 void ASTStmtReader::VisitSwitchCase(SwitchCase *S) {
170 VisitStmt(S);
171 Record.recordSwitchCaseID(S, Record.readInt());
172 S->setKeywordLoc(readSourceLocation());
173 S->setColonLoc(readSourceLocation());
174 }
175
VisitCaseStmt(CaseStmt * S)176 void ASTStmtReader::VisitCaseStmt(CaseStmt *S) {
177 VisitSwitchCase(S);
178 bool CaseStmtIsGNURange = Record.readInt();
179 S->setLHS(Record.readSubExpr());
180 S->setSubStmt(Record.readSubStmt());
181 if (CaseStmtIsGNURange) {
182 S->setRHS(Record.readSubExpr());
183 S->setEllipsisLoc(readSourceLocation());
184 }
185 }
186
VisitDefaultStmt(DefaultStmt * S)187 void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) {
188 VisitSwitchCase(S);
189 S->setSubStmt(Record.readSubStmt());
190 }
191
VisitLabelStmt(LabelStmt * S)192 void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
193 VisitStmt(S);
194 bool IsSideEntry = Record.readInt();
195 auto *LD = readDeclAs<LabelDecl>();
196 LD->setStmt(S);
197 S->setDecl(LD);
198 S->setSubStmt(Record.readSubStmt());
199 S->setIdentLoc(readSourceLocation());
200 S->setSideEntry(IsSideEntry);
201 }
202
VisitAttributedStmt(AttributedStmt * S)203 void ASTStmtReader::VisitAttributedStmt(AttributedStmt *S) {
204 VisitStmt(S);
205 // NumAttrs in AttributedStmt is set when creating an empty
206 // AttributedStmt in AttributedStmt::CreateEmpty, since it is needed
207 // to allocate the right amount of space for the trailing Attr *.
208 uint64_t NumAttrs = Record.readInt();
209 AttrVec Attrs;
210 Record.readAttributes(Attrs);
211 (void)NumAttrs;
212 assert(NumAttrs == S->AttributedStmtBits.NumAttrs);
213 assert(NumAttrs == Attrs.size());
214 std::copy(Attrs.begin(), Attrs.end(), S->getAttrArrayPtr());
215 S->SubStmt = Record.readSubStmt();
216 S->AttributedStmtBits.AttrLoc = readSourceLocation();
217 }
218
VisitIfStmt(IfStmt * S)219 void ASTStmtReader::VisitIfStmt(IfStmt *S) {
220 VisitStmt(S);
221
222 CurrentUnpackingBits.emplace(Record.readInt());
223
224 bool HasElse = CurrentUnpackingBits->getNextBit();
225 bool HasVar = CurrentUnpackingBits->getNextBit();
226 bool HasInit = CurrentUnpackingBits->getNextBit();
227
228 S->setStatementKind(static_cast<IfStatementKind>(Record.readInt()));
229 S->setCond(Record.readSubExpr());
230 S->setThen(Record.readSubStmt());
231 if (HasElse)
232 S->setElse(Record.readSubStmt());
233 if (HasVar)
234 S->setConditionVariableDeclStmt(cast<DeclStmt>(Record.readSubStmt()));
235 if (HasInit)
236 S->setInit(Record.readSubStmt());
237
238 S->setIfLoc(readSourceLocation());
239 S->setLParenLoc(readSourceLocation());
240 S->setRParenLoc(readSourceLocation());
241 if (HasElse)
242 S->setElseLoc(readSourceLocation());
243 }
244
VisitSwitchStmt(SwitchStmt * S)245 void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) {
246 VisitStmt(S);
247
248 bool HasInit = Record.readInt();
249 bool HasVar = Record.readInt();
250 bool AllEnumCasesCovered = Record.readInt();
251 if (AllEnumCasesCovered)
252 S->setAllEnumCasesCovered();
253
254 S->setCond(Record.readSubExpr());
255 S->setBody(Record.readSubStmt());
256 if (HasInit)
257 S->setInit(Record.readSubStmt());
258 if (HasVar)
259 S->setConditionVariableDeclStmt(cast<DeclStmt>(Record.readSubStmt()));
260
261 S->setSwitchLoc(readSourceLocation());
262 S->setLParenLoc(readSourceLocation());
263 S->setRParenLoc(readSourceLocation());
264
265 SwitchCase *PrevSC = nullptr;
266 for (auto E = Record.size(); Record.getIdx() != E; ) {
267 SwitchCase *SC = Record.getSwitchCaseWithID(Record.readInt());
268 if (PrevSC)
269 PrevSC->setNextSwitchCase(SC);
270 else
271 S->setSwitchCaseList(SC);
272
273 PrevSC = SC;
274 }
275 }
276
VisitWhileStmt(WhileStmt * S)277 void ASTStmtReader::VisitWhileStmt(WhileStmt *S) {
278 VisitStmt(S);
279
280 bool HasVar = Record.readInt();
281
282 S->setCond(Record.readSubExpr());
283 S->setBody(Record.readSubStmt());
284 if (HasVar)
285 S->setConditionVariableDeclStmt(cast<DeclStmt>(Record.readSubStmt()));
286
287 S->setWhileLoc(readSourceLocation());
288 S->setLParenLoc(readSourceLocation());
289 S->setRParenLoc(readSourceLocation());
290 }
291
VisitDoStmt(DoStmt * S)292 void ASTStmtReader::VisitDoStmt(DoStmt *S) {
293 VisitStmt(S);
294 S->setCond(Record.readSubExpr());
295 S->setBody(Record.readSubStmt());
296 S->setDoLoc(readSourceLocation());
297 S->setWhileLoc(readSourceLocation());
298 S->setRParenLoc(readSourceLocation());
299 }
300
VisitForStmt(ForStmt * S)301 void ASTStmtReader::VisitForStmt(ForStmt *S) {
302 VisitStmt(S);
303 S->setInit(Record.readSubStmt());
304 S->setCond(Record.readSubExpr());
305 S->setConditionVariableDeclStmt(cast_or_null<DeclStmt>(Record.readSubStmt()));
306 S->setInc(Record.readSubExpr());
307 S->setBody(Record.readSubStmt());
308 S->setForLoc(readSourceLocation());
309 S->setLParenLoc(readSourceLocation());
310 S->setRParenLoc(readSourceLocation());
311 }
312
VisitGotoStmt(GotoStmt * S)313 void ASTStmtReader::VisitGotoStmt(GotoStmt *S) {
314 VisitStmt(S);
315 S->setLabel(readDeclAs<LabelDecl>());
316 S->setGotoLoc(readSourceLocation());
317 S->setLabelLoc(readSourceLocation());
318 }
319
VisitIndirectGotoStmt(IndirectGotoStmt * S)320 void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
321 VisitStmt(S);
322 S->setGotoLoc(readSourceLocation());
323 S->setStarLoc(readSourceLocation());
324 S->setTarget(Record.readSubExpr());
325 }
326
VisitContinueStmt(ContinueStmt * S)327 void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) {
328 VisitStmt(S);
329 S->setContinueLoc(readSourceLocation());
330 }
331
VisitBreakStmt(BreakStmt * S)332 void ASTStmtReader::VisitBreakStmt(BreakStmt *S) {
333 VisitStmt(S);
334 S->setBreakLoc(readSourceLocation());
335 }
336
VisitReturnStmt(ReturnStmt * S)337 void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) {
338 VisitStmt(S);
339
340 bool HasNRVOCandidate = Record.readInt();
341
342 S->setRetValue(Record.readSubExpr());
343 if (HasNRVOCandidate)
344 S->setNRVOCandidate(readDeclAs<VarDecl>());
345
346 S->setReturnLoc(readSourceLocation());
347 }
348
VisitDeclStmt(DeclStmt * S)349 void ASTStmtReader::VisitDeclStmt(DeclStmt *S) {
350 VisitStmt(S);
351 S->setStartLoc(readSourceLocation());
352 S->setEndLoc(readSourceLocation());
353
354 if (Record.size() - Record.getIdx() == 1) {
355 // Single declaration
356 S->setDeclGroup(DeclGroupRef(readDecl()));
357 } else {
358 SmallVector<Decl *, 16> Decls;
359 int N = Record.size() - Record.getIdx();
360 Decls.reserve(N);
361 for (int I = 0; I < N; ++I)
362 Decls.push_back(readDecl());
363 S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Record.getContext(),
364 Decls.data(),
365 Decls.size())));
366 }
367 }
368
VisitAsmStmt(AsmStmt * S)369 void ASTStmtReader::VisitAsmStmt(AsmStmt *S) {
370 VisitStmt(S);
371 S->NumOutputs = Record.readInt();
372 S->NumInputs = Record.readInt();
373 S->NumClobbers = Record.readInt();
374 S->setAsmLoc(readSourceLocation());
375 S->setVolatile(Record.readInt());
376 S->setSimple(Record.readInt());
377 }
378
VisitGCCAsmStmt(GCCAsmStmt * S)379 void ASTStmtReader::VisitGCCAsmStmt(GCCAsmStmt *S) {
380 VisitAsmStmt(S);
381 S->NumLabels = Record.readInt();
382 S->setRParenLoc(readSourceLocation());
383 S->setAsmString(cast_or_null<StringLiteral>(Record.readSubStmt()));
384
385 unsigned NumOutputs = S->getNumOutputs();
386 unsigned NumInputs = S->getNumInputs();
387 unsigned NumClobbers = S->getNumClobbers();
388 unsigned NumLabels = S->getNumLabels();
389
390 // Outputs and inputs
391 SmallVector<IdentifierInfo *, 16> Names;
392 SmallVector<StringLiteral*, 16> Constraints;
393 SmallVector<Stmt*, 16> Exprs;
394 for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
395 Names.push_back(Record.readIdentifier());
396 Constraints.push_back(cast_or_null<StringLiteral>(Record.readSubStmt()));
397 Exprs.push_back(Record.readSubStmt());
398 }
399
400 // Constraints
401 SmallVector<StringLiteral*, 16> Clobbers;
402 for (unsigned I = 0; I != NumClobbers; ++I)
403 Clobbers.push_back(cast_or_null<StringLiteral>(Record.readSubStmt()));
404
405 // Labels
406 for (unsigned I = 0, N = NumLabels; I != N; ++I) {
407 Names.push_back(Record.readIdentifier());
408 Exprs.push_back(Record.readSubStmt());
409 }
410
411 S->setOutputsAndInputsAndClobbers(Record.getContext(),
412 Names.data(), Constraints.data(),
413 Exprs.data(), NumOutputs, NumInputs,
414 NumLabels,
415 Clobbers.data(), NumClobbers);
416 }
417
VisitMSAsmStmt(MSAsmStmt * S)418 void ASTStmtReader::VisitMSAsmStmt(MSAsmStmt *S) {
419 VisitAsmStmt(S);
420 S->LBraceLoc = readSourceLocation();
421 S->EndLoc = readSourceLocation();
422 S->NumAsmToks = Record.readInt();
423 std::string AsmStr = readString();
424
425 // Read the tokens.
426 SmallVector<Token, 16> AsmToks;
427 AsmToks.reserve(S->NumAsmToks);
428 for (unsigned i = 0, e = S->NumAsmToks; i != e; ++i) {
429 AsmToks.push_back(Record.readToken());
430 }
431
432 // The calls to reserve() for the FooData vectors are mandatory to
433 // prevent dead StringRefs in the Foo vectors.
434
435 // Read the clobbers.
436 SmallVector<std::string, 16> ClobbersData;
437 SmallVector<StringRef, 16> Clobbers;
438 ClobbersData.reserve(S->NumClobbers);
439 Clobbers.reserve(S->NumClobbers);
440 for (unsigned i = 0, e = S->NumClobbers; i != e; ++i) {
441 ClobbersData.push_back(readString());
442 Clobbers.push_back(ClobbersData.back());
443 }
444
445 // Read the operands.
446 unsigned NumOperands = S->NumOutputs + S->NumInputs;
447 SmallVector<Expr*, 16> Exprs;
448 SmallVector<std::string, 16> ConstraintsData;
449 SmallVector<StringRef, 16> Constraints;
450 Exprs.reserve(NumOperands);
451 ConstraintsData.reserve(NumOperands);
452 Constraints.reserve(NumOperands);
453 for (unsigned i = 0; i != NumOperands; ++i) {
454 Exprs.push_back(cast<Expr>(Record.readSubStmt()));
455 ConstraintsData.push_back(readString());
456 Constraints.push_back(ConstraintsData.back());
457 }
458
459 S->initialize(Record.getContext(), AsmStr, AsmToks,
460 Constraints, Exprs, Clobbers);
461 }
462
VisitCoroutineBodyStmt(CoroutineBodyStmt * S)463 void ASTStmtReader::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
464 VisitStmt(S);
465 assert(Record.peekInt() == S->NumParams);
466 Record.skipInts(1);
467 auto *StoredStmts = S->getStoredStmts();
468 for (unsigned i = 0;
469 i < CoroutineBodyStmt::SubStmt::FirstParamMove + S->NumParams; ++i)
470 StoredStmts[i] = Record.readSubStmt();
471 }
472
VisitCoreturnStmt(CoreturnStmt * S)473 void ASTStmtReader::VisitCoreturnStmt(CoreturnStmt *S) {
474 VisitStmt(S);
475 S->CoreturnLoc = Record.readSourceLocation();
476 for (auto &SubStmt: S->SubStmts)
477 SubStmt = Record.readSubStmt();
478 S->IsImplicit = Record.readInt() != 0;
479 }
480
VisitCoawaitExpr(CoawaitExpr * E)481 void ASTStmtReader::VisitCoawaitExpr(CoawaitExpr *E) {
482 VisitExpr(E);
483 E->KeywordLoc = readSourceLocation();
484 for (auto &SubExpr: E->SubExprs)
485 SubExpr = Record.readSubStmt();
486 E->OpaqueValue = cast_or_null<OpaqueValueExpr>(Record.readSubStmt());
487 E->setIsImplicit(Record.readInt() != 0);
488 }
489
VisitCoyieldExpr(CoyieldExpr * E)490 void ASTStmtReader::VisitCoyieldExpr(CoyieldExpr *E) {
491 VisitExpr(E);
492 E->KeywordLoc = readSourceLocation();
493 for (auto &SubExpr: E->SubExprs)
494 SubExpr = Record.readSubStmt();
495 E->OpaqueValue = cast_or_null<OpaqueValueExpr>(Record.readSubStmt());
496 }
497
VisitDependentCoawaitExpr(DependentCoawaitExpr * E)498 void ASTStmtReader::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
499 VisitExpr(E);
500 E->KeywordLoc = readSourceLocation();
501 for (auto &SubExpr: E->SubExprs)
502 SubExpr = Record.readSubStmt();
503 }
504
VisitCapturedStmt(CapturedStmt * S)505 void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) {
506 VisitStmt(S);
507 Record.skipInts(1);
508 S->setCapturedDecl(readDeclAs<CapturedDecl>());
509 S->setCapturedRegionKind(static_cast<CapturedRegionKind>(Record.readInt()));
510 S->setCapturedRecordDecl(readDeclAs<RecordDecl>());
511
512 // Capture inits
513 for (CapturedStmt::capture_init_iterator I = S->capture_init_begin(),
514 E = S->capture_init_end();
515 I != E; ++I)
516 *I = Record.readSubExpr();
517
518 // Body
519 S->setCapturedStmt(Record.readSubStmt());
520 S->getCapturedDecl()->setBody(S->getCapturedStmt());
521
522 // Captures
523 for (auto &I : S->captures()) {
524 I.VarAndKind.setPointer(readDeclAs<VarDecl>());
525 I.VarAndKind.setInt(
526 static_cast<CapturedStmt::VariableCaptureKind>(Record.readInt()));
527 I.Loc = readSourceLocation();
528 }
529 }
530
VisitExpr(Expr * E)531 void ASTStmtReader::VisitExpr(Expr *E) {
532 VisitStmt(E);
533 CurrentUnpackingBits.emplace(Record.readInt());
534 E->setDependence(static_cast<ExprDependence>(
535 CurrentUnpackingBits->getNextBits(/*Width=*/5)));
536 E->setValueKind(static_cast<ExprValueKind>(
537 CurrentUnpackingBits->getNextBits(/*Width=*/2)));
538 E->setObjectKind(static_cast<ExprObjectKind>(
539 CurrentUnpackingBits->getNextBits(/*Width=*/3)));
540
541 E->setType(Record.readType());
542 assert(Record.getIdx() == NumExprFields &&
543 "Incorrect expression field count");
544 }
545
VisitConstantExpr(ConstantExpr * E)546 void ASTStmtReader::VisitConstantExpr(ConstantExpr *E) {
547 VisitExpr(E);
548
549 auto StorageKind = static_cast<ConstantResultStorageKind>(Record.readInt());
550 assert(E->getResultStorageKind() == StorageKind && "Wrong ResultKind!");
551
552 E->ConstantExprBits.APValueKind = Record.readInt();
553 E->ConstantExprBits.IsUnsigned = Record.readInt();
554 E->ConstantExprBits.BitWidth = Record.readInt();
555 E->ConstantExprBits.HasCleanup = false; // Not serialized, see below.
556 E->ConstantExprBits.IsImmediateInvocation = Record.readInt();
557
558 switch (StorageKind) {
559 case ConstantResultStorageKind::None:
560 break;
561
562 case ConstantResultStorageKind::Int64:
563 E->Int64Result() = Record.readInt();
564 break;
565
566 case ConstantResultStorageKind::APValue:
567 E->APValueResult() = Record.readAPValue();
568 if (E->APValueResult().needsCleanup()) {
569 E->ConstantExprBits.HasCleanup = true;
570 Record.getContext().addDestruction(&E->APValueResult());
571 }
572 break;
573 }
574
575 E->setSubExpr(Record.readSubExpr());
576 }
577
VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr * E)578 void ASTStmtReader::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
579 VisitExpr(E);
580
581 E->setLocation(readSourceLocation());
582 E->setLParenLocation(readSourceLocation());
583 E->setRParenLocation(readSourceLocation());
584
585 E->setTypeSourceInfo(Record.readTypeSourceInfo());
586 }
587
VisitPredefinedExpr(PredefinedExpr * E)588 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
589 VisitExpr(E);
590 bool HasFunctionName = Record.readInt();
591 E->PredefinedExprBits.HasFunctionName = HasFunctionName;
592 E->PredefinedExprBits.Kind = Record.readInt();
593 E->PredefinedExprBits.IsTransparent = Record.readInt();
594 E->setLocation(readSourceLocation());
595 if (HasFunctionName)
596 E->setFunctionName(cast<StringLiteral>(Record.readSubExpr()));
597 }
598
VisitDeclRefExpr(DeclRefExpr * E)599 void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
600 VisitExpr(E);
601
602 CurrentUnpackingBits.emplace(Record.readInt());
603 E->DeclRefExprBits.HadMultipleCandidates = CurrentUnpackingBits->getNextBit();
604 E->DeclRefExprBits.RefersToEnclosingVariableOrCapture =
605 CurrentUnpackingBits->getNextBit();
606 E->DeclRefExprBits.NonOdrUseReason =
607 CurrentUnpackingBits->getNextBits(/*Width=*/2);
608 E->DeclRefExprBits.IsImmediateEscalating = CurrentUnpackingBits->getNextBit();
609 E->DeclRefExprBits.HasFoundDecl = CurrentUnpackingBits->getNextBit();
610 E->DeclRefExprBits.HasQualifier = CurrentUnpackingBits->getNextBit();
611 E->DeclRefExprBits.HasTemplateKWAndArgsInfo =
612 CurrentUnpackingBits->getNextBit();
613 E->DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = false;
614 unsigned NumTemplateArgs = 0;
615 if (E->hasTemplateKWAndArgsInfo())
616 NumTemplateArgs = Record.readInt();
617
618 if (E->hasQualifier())
619 new (E->getTrailingObjects<NestedNameSpecifierLoc>())
620 NestedNameSpecifierLoc(Record.readNestedNameSpecifierLoc());
621
622 if (E->hasFoundDecl())
623 *E->getTrailingObjects<NamedDecl *>() = readDeclAs<NamedDecl>();
624
625 if (E->hasTemplateKWAndArgsInfo())
626 ReadTemplateKWAndArgsInfo(
627 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
628 E->getTrailingObjects<TemplateArgumentLoc>(), NumTemplateArgs);
629
630 E->D = readDeclAs<ValueDecl>();
631 E->setLocation(readSourceLocation());
632 E->DNLoc = Record.readDeclarationNameLoc(E->getDecl()->getDeclName());
633 }
634
VisitIntegerLiteral(IntegerLiteral * E)635 void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
636 VisitExpr(E);
637 E->setLocation(readSourceLocation());
638 E->setValue(Record.getContext(), Record.readAPInt());
639 }
640
VisitFixedPointLiteral(FixedPointLiteral * E)641 void ASTStmtReader::VisitFixedPointLiteral(FixedPointLiteral *E) {
642 VisitExpr(E);
643 E->setLocation(readSourceLocation());
644 E->setScale(Record.readInt());
645 E->setValue(Record.getContext(), Record.readAPInt());
646 }
647
VisitFloatingLiteral(FloatingLiteral * E)648 void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
649 VisitExpr(E);
650 E->setRawSemantics(
651 static_cast<llvm::APFloatBase::Semantics>(Record.readInt()));
652 E->setExact(Record.readInt());
653 E->setValue(Record.getContext(), Record.readAPFloat(E->getSemantics()));
654 E->setLocation(readSourceLocation());
655 }
656
VisitImaginaryLiteral(ImaginaryLiteral * E)657 void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
658 VisitExpr(E);
659 E->setSubExpr(Record.readSubExpr());
660 }
661
VisitStringLiteral(StringLiteral * E)662 void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
663 VisitExpr(E);
664
665 // NumConcatenated, Length and CharByteWidth are set by the empty
666 // ctor since they are needed to allocate storage for the trailing objects.
667 unsigned NumConcatenated = Record.readInt();
668 unsigned Length = Record.readInt();
669 unsigned CharByteWidth = Record.readInt();
670 assert((NumConcatenated == E->getNumConcatenated()) &&
671 "Wrong number of concatenated tokens!");
672 assert((Length == E->getLength()) && "Wrong Length!");
673 assert((CharByteWidth == E->getCharByteWidth()) && "Wrong character width!");
674 E->StringLiteralBits.Kind = Record.readInt();
675 E->StringLiteralBits.IsPascal = Record.readInt();
676
677 // The character width is originally computed via mapCharByteWidth.
678 // Check that the deserialized character width is consistant with the result
679 // of calling mapCharByteWidth.
680 assert((CharByteWidth ==
681 StringLiteral::mapCharByteWidth(Record.getContext().getTargetInfo(),
682 E->getKind())) &&
683 "Wrong character width!");
684
685 // Deserialize the trailing array of SourceLocation.
686 for (unsigned I = 0; I < NumConcatenated; ++I)
687 E->setStrTokenLoc(I, readSourceLocation());
688
689 // Deserialize the trailing array of char holding the string data.
690 char *StrData = E->getStrDataAsChar();
691 for (unsigned I = 0; I < Length * CharByteWidth; ++I)
692 StrData[I] = Record.readInt();
693 }
694
VisitCharacterLiteral(CharacterLiteral * E)695 void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
696 VisitExpr(E);
697 E->setValue(Record.readInt());
698 E->setLocation(readSourceLocation());
699 E->setKind(static_cast<CharacterLiteralKind>(Record.readInt()));
700 }
701
VisitParenExpr(ParenExpr * E)702 void ASTStmtReader::VisitParenExpr(ParenExpr *E) {
703 VisitExpr(E);
704 E->setLParen(readSourceLocation());
705 E->setRParen(readSourceLocation());
706 E->setSubExpr(Record.readSubExpr());
707 }
708
VisitParenListExpr(ParenListExpr * E)709 void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
710 VisitExpr(E);
711 unsigned NumExprs = Record.readInt();
712 assert((NumExprs == E->getNumExprs()) && "Wrong NumExprs!");
713 for (unsigned I = 0; I != NumExprs; ++I)
714 E->getTrailingObjects<Stmt *>()[I] = Record.readSubStmt();
715 E->LParenLoc = readSourceLocation();
716 E->RParenLoc = readSourceLocation();
717 }
718
VisitUnaryOperator(UnaryOperator * E)719 void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) {
720 VisitExpr(E);
721 bool hasFP_Features = CurrentUnpackingBits->getNextBit();
722 assert(hasFP_Features == E->hasStoredFPFeatures());
723 E->setSubExpr(Record.readSubExpr());
724 E->setOpcode(
725 (UnaryOperator::Opcode)CurrentUnpackingBits->getNextBits(/*Width=*/5));
726 E->setOperatorLoc(readSourceLocation());
727 E->setCanOverflow(CurrentUnpackingBits->getNextBit());
728 if (hasFP_Features)
729 E->setStoredFPFeatures(
730 FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
731 }
732
VisitOffsetOfExpr(OffsetOfExpr * E)733 void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
734 VisitExpr(E);
735 assert(E->getNumComponents() == Record.peekInt());
736 Record.skipInts(1);
737 assert(E->getNumExpressions() == Record.peekInt());
738 Record.skipInts(1);
739 E->setOperatorLoc(readSourceLocation());
740 E->setRParenLoc(readSourceLocation());
741 E->setTypeSourceInfo(readTypeSourceInfo());
742 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
743 auto Kind = static_cast<OffsetOfNode::Kind>(Record.readInt());
744 SourceLocation Start = readSourceLocation();
745 SourceLocation End = readSourceLocation();
746 switch (Kind) {
747 case OffsetOfNode::Array:
748 E->setComponent(I, OffsetOfNode(Start, Record.readInt(), End));
749 break;
750
751 case OffsetOfNode::Field:
752 E->setComponent(
753 I, OffsetOfNode(Start, readDeclAs<FieldDecl>(), End));
754 break;
755
756 case OffsetOfNode::Identifier:
757 E->setComponent(
758 I,
759 OffsetOfNode(Start, Record.readIdentifier(), End));
760 break;
761
762 case OffsetOfNode::Base: {
763 auto *Base = new (Record.getContext()) CXXBaseSpecifier();
764 *Base = Record.readCXXBaseSpecifier();
765 E->setComponent(I, OffsetOfNode(Base));
766 break;
767 }
768 }
769 }
770
771 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
772 E->setIndexExpr(I, Record.readSubExpr());
773 }
774
VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr * E)775 void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
776 VisitExpr(E);
777 E->setKind(static_cast<UnaryExprOrTypeTrait>(Record.readInt()));
778 if (Record.peekInt() == 0) {
779 E->setArgument(Record.readSubExpr());
780 Record.skipInts(1);
781 } else {
782 E->setArgument(readTypeSourceInfo());
783 }
784 E->setOperatorLoc(readSourceLocation());
785 E->setRParenLoc(readSourceLocation());
786 }
787
788 static ConstraintSatisfaction
readConstraintSatisfaction(ASTRecordReader & Record)789 readConstraintSatisfaction(ASTRecordReader &Record) {
790 ConstraintSatisfaction Satisfaction;
791 Satisfaction.IsSatisfied = Record.readInt();
792 Satisfaction.ContainsErrors = Record.readInt();
793 const ASTContext &C = Record.getContext();
794 if (!Satisfaction.IsSatisfied) {
795 unsigned NumDetailRecords = Record.readInt();
796 for (unsigned i = 0; i != NumDetailRecords; ++i) {
797 if (/* IsDiagnostic */Record.readInt()) {
798 SourceLocation DiagLocation = Record.readSourceLocation();
799 StringRef DiagMessage = C.backupStr(Record.readString());
800
801 Satisfaction.Details.emplace_back(
802 new (C) ConstraintSatisfaction::SubstitutionDiagnostic(
803 DiagLocation, DiagMessage));
804 } else
805 Satisfaction.Details.emplace_back(Record.readExpr());
806 }
807 }
808 return Satisfaction;
809 }
810
VisitConceptSpecializationExpr(ConceptSpecializationExpr * E)811 void ASTStmtReader::VisitConceptSpecializationExpr(
812 ConceptSpecializationExpr *E) {
813 VisitExpr(E);
814 E->SpecDecl = Record.readDeclAs<ImplicitConceptSpecializationDecl>();
815 if (Record.readBool())
816 E->ConceptRef = Record.readConceptReference();
817 E->Satisfaction = E->isValueDependent() ? nullptr :
818 ASTConstraintSatisfaction::Create(Record.getContext(),
819 readConstraintSatisfaction(Record));
820 }
821
822 static concepts::Requirement::SubstitutionDiagnostic *
readSubstitutionDiagnostic(ASTRecordReader & Record)823 readSubstitutionDiagnostic(ASTRecordReader &Record) {
824 const ASTContext &C = Record.getContext();
825 StringRef SubstitutedEntity = C.backupStr(Record.readString());
826 SourceLocation DiagLoc = Record.readSourceLocation();
827 StringRef DiagMessage = C.backupStr(Record.readString());
828
829 return new (Record.getContext())
830 concepts::Requirement::SubstitutionDiagnostic{SubstitutedEntity, DiagLoc,
831 DiagMessage};
832 }
833
VisitRequiresExpr(RequiresExpr * E)834 void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {
835 VisitExpr(E);
836 unsigned NumLocalParameters = Record.readInt();
837 unsigned NumRequirements = Record.readInt();
838 E->RequiresExprBits.RequiresKWLoc = Record.readSourceLocation();
839 E->RequiresExprBits.IsSatisfied = Record.readInt();
840 E->Body = Record.readDeclAs<RequiresExprBodyDecl>();
841 llvm::SmallVector<ParmVarDecl *, 4> LocalParameters;
842 for (unsigned i = 0; i < NumLocalParameters; ++i)
843 LocalParameters.push_back(cast<ParmVarDecl>(Record.readDecl()));
844 std::copy(LocalParameters.begin(), LocalParameters.end(),
845 E->getTrailingObjects<ParmVarDecl *>());
846 llvm::SmallVector<concepts::Requirement *, 4> Requirements;
847 for (unsigned i = 0; i < NumRequirements; ++i) {
848 auto RK =
849 static_cast<concepts::Requirement::RequirementKind>(Record.readInt());
850 concepts::Requirement *R = nullptr;
851 switch (RK) {
852 case concepts::Requirement::RK_Type: {
853 auto Status =
854 static_cast<concepts::TypeRequirement::SatisfactionStatus>(
855 Record.readInt());
856 if (Status == concepts::TypeRequirement::SS_SubstitutionFailure)
857 R = new (Record.getContext())
858 concepts::TypeRequirement(readSubstitutionDiagnostic(Record));
859 else
860 R = new (Record.getContext())
861 concepts::TypeRequirement(Record.readTypeSourceInfo());
862 } break;
863 case concepts::Requirement::RK_Simple:
864 case concepts::Requirement::RK_Compound: {
865 auto Status =
866 static_cast<concepts::ExprRequirement::SatisfactionStatus>(
867 Record.readInt());
868 llvm::PointerUnion<concepts::Requirement::SubstitutionDiagnostic *,
869 Expr *> E;
870 if (Status == concepts::ExprRequirement::SS_ExprSubstitutionFailure) {
871 E = readSubstitutionDiagnostic(Record);
872 } else
873 E = Record.readExpr();
874
875 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> Req;
876 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
877 SourceLocation NoexceptLoc;
878 if (RK == concepts::Requirement::RK_Simple) {
879 Req.emplace();
880 } else {
881 NoexceptLoc = Record.readSourceLocation();
882 switch (/* returnTypeRequirementKind */Record.readInt()) {
883 case 0:
884 // No return type requirement.
885 Req.emplace();
886 break;
887 case 1: {
888 // type-constraint
889 TemplateParameterList *TPL = Record.readTemplateParameterList();
890 if (Status >=
891 concepts::ExprRequirement::SS_ConstraintsNotSatisfied)
892 SubstitutedConstraintExpr =
893 cast<ConceptSpecializationExpr>(Record.readExpr());
894 Req.emplace(TPL);
895 } break;
896 case 2:
897 // Substitution failure
898 Req.emplace(readSubstitutionDiagnostic(Record));
899 break;
900 }
901 }
902 if (Expr *Ex = E.dyn_cast<Expr *>())
903 R = new (Record.getContext()) concepts::ExprRequirement(
904 Ex, RK == concepts::Requirement::RK_Simple, NoexceptLoc,
905 std::move(*Req), Status, SubstitutedConstraintExpr);
906 else
907 R = new (Record.getContext()) concepts::ExprRequirement(
908 E.get<concepts::Requirement::SubstitutionDiagnostic *>(),
909 RK == concepts::Requirement::RK_Simple, NoexceptLoc,
910 std::move(*Req));
911 } break;
912 case concepts::Requirement::RK_Nested: {
913 ASTContext &C = Record.getContext();
914 bool HasInvalidConstraint = Record.readInt();
915 if (HasInvalidConstraint) {
916 StringRef InvalidConstraint = C.backupStr(Record.readString());
917 R = new (C) concepts::NestedRequirement(
918 Record.getContext(), InvalidConstraint,
919 readConstraintSatisfaction(Record));
920 break;
921 }
922 Expr *E = Record.readExpr();
923 if (E->isInstantiationDependent())
924 R = new (C) concepts::NestedRequirement(E);
925 else
926 R = new (C) concepts::NestedRequirement(
927 C, E, readConstraintSatisfaction(Record));
928 } break;
929 }
930 if (!R)
931 continue;
932 Requirements.push_back(R);
933 }
934 std::copy(Requirements.begin(), Requirements.end(),
935 E->getTrailingObjects<concepts::Requirement *>());
936 E->LParenLoc = Record.readSourceLocation();
937 E->RParenLoc = Record.readSourceLocation();
938 E->RBraceLoc = Record.readSourceLocation();
939 }
940
VisitArraySubscriptExpr(ArraySubscriptExpr * E)941 void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
942 VisitExpr(E);
943 E->setLHS(Record.readSubExpr());
944 E->setRHS(Record.readSubExpr());
945 E->setRBracketLoc(readSourceLocation());
946 }
947
VisitMatrixSubscriptExpr(MatrixSubscriptExpr * E)948 void ASTStmtReader::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
949 VisitExpr(E);
950 E->setBase(Record.readSubExpr());
951 E->setRowIdx(Record.readSubExpr());
952 E->setColumnIdx(Record.readSubExpr());
953 E->setRBracketLoc(readSourceLocation());
954 }
955
VisitArraySectionExpr(ArraySectionExpr * E)956 void ASTStmtReader::VisitArraySectionExpr(ArraySectionExpr *E) {
957 VisitExpr(E);
958 E->ASType = Record.readEnum<ArraySectionExpr::ArraySectionType>();
959
960 E->setBase(Record.readSubExpr());
961 E->setLowerBound(Record.readSubExpr());
962 E->setLength(Record.readSubExpr());
963
964 if (E->isOMPArraySection())
965 E->setStride(Record.readSubExpr());
966
967 E->setColonLocFirst(readSourceLocation());
968
969 if (E->isOMPArraySection())
970 E->setColonLocSecond(readSourceLocation());
971
972 E->setRBracketLoc(readSourceLocation());
973 }
974
VisitOMPArrayShapingExpr(OMPArrayShapingExpr * E)975 void ASTStmtReader::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
976 VisitExpr(E);
977 unsigned NumDims = Record.readInt();
978 E->setBase(Record.readSubExpr());
979 SmallVector<Expr *, 4> Dims(NumDims);
980 for (unsigned I = 0; I < NumDims; ++I)
981 Dims[I] = Record.readSubExpr();
982 E->setDimensions(Dims);
983 SmallVector<SourceRange, 4> SRs(NumDims);
984 for (unsigned I = 0; I < NumDims; ++I)
985 SRs[I] = readSourceRange();
986 E->setBracketsRanges(SRs);
987 E->setLParenLoc(readSourceLocation());
988 E->setRParenLoc(readSourceLocation());
989 }
990
VisitOMPIteratorExpr(OMPIteratorExpr * E)991 void ASTStmtReader::VisitOMPIteratorExpr(OMPIteratorExpr *E) {
992 VisitExpr(E);
993 unsigned NumIters = Record.readInt();
994 E->setIteratorKwLoc(readSourceLocation());
995 E->setLParenLoc(readSourceLocation());
996 E->setRParenLoc(readSourceLocation());
997 for (unsigned I = 0; I < NumIters; ++I) {
998 E->setIteratorDeclaration(I, Record.readDeclRef());
999 E->setAssignmentLoc(I, readSourceLocation());
1000 Expr *Begin = Record.readSubExpr();
1001 Expr *End = Record.readSubExpr();
1002 Expr *Step = Record.readSubExpr();
1003 SourceLocation ColonLoc = readSourceLocation();
1004 SourceLocation SecColonLoc;
1005 if (Step)
1006 SecColonLoc = readSourceLocation();
1007 E->setIteratorRange(I, Begin, ColonLoc, End, SecColonLoc, Step);
1008 // Deserialize helpers
1009 OMPIteratorHelperData HD;
1010 HD.CounterVD = cast_or_null<VarDecl>(Record.readDeclRef());
1011 HD.Upper = Record.readSubExpr();
1012 HD.Update = Record.readSubExpr();
1013 HD.CounterUpdate = Record.readSubExpr();
1014 E->setHelper(I, HD);
1015 }
1016 }
1017
VisitCallExpr(CallExpr * E)1018 void ASTStmtReader::VisitCallExpr(CallExpr *E) {
1019 VisitExpr(E);
1020
1021 unsigned NumArgs = Record.readInt();
1022 CurrentUnpackingBits.emplace(Record.readInt());
1023 E->setADLCallKind(
1024 static_cast<CallExpr::ADLCallKind>(CurrentUnpackingBits->getNextBit()));
1025 bool HasFPFeatures = CurrentUnpackingBits->getNextBit();
1026 assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");
1027 E->setRParenLoc(readSourceLocation());
1028 E->setCallee(Record.readSubExpr());
1029 for (unsigned I = 0; I != NumArgs; ++I)
1030 E->setArg(I, Record.readSubExpr());
1031
1032 if (HasFPFeatures)
1033 E->setStoredFPFeatures(
1034 FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
1035 }
1036
VisitCXXMemberCallExpr(CXXMemberCallExpr * E)1037 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1038 VisitCallExpr(E);
1039 }
1040
VisitMemberExpr(MemberExpr * E)1041 void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
1042 VisitExpr(E);
1043
1044 CurrentUnpackingBits.emplace(Record.readInt());
1045 bool HasQualifier = CurrentUnpackingBits->getNextBit();
1046 bool HasFoundDecl = CurrentUnpackingBits->getNextBit();
1047 bool HasTemplateInfo = CurrentUnpackingBits->getNextBit();
1048 unsigned NumTemplateArgs = Record.readInt();
1049
1050 E->Base = Record.readSubExpr();
1051 E->MemberDecl = Record.readDeclAs<ValueDecl>();
1052 E->MemberDNLoc = Record.readDeclarationNameLoc(E->MemberDecl->getDeclName());
1053 E->MemberLoc = Record.readSourceLocation();
1054 E->MemberExprBits.IsArrow = CurrentUnpackingBits->getNextBit();
1055 E->MemberExprBits.HasQualifier = HasQualifier;
1056 E->MemberExprBits.HasFoundDecl = HasFoundDecl;
1057 E->MemberExprBits.HasTemplateKWAndArgsInfo = HasTemplateInfo;
1058 E->MemberExprBits.HadMultipleCandidates = CurrentUnpackingBits->getNextBit();
1059 E->MemberExprBits.NonOdrUseReason =
1060 CurrentUnpackingBits->getNextBits(/*Width=*/2);
1061 E->MemberExprBits.OperatorLoc = Record.readSourceLocation();
1062
1063 if (HasQualifier)
1064 new (E->getTrailingObjects<NestedNameSpecifierLoc>())
1065 NestedNameSpecifierLoc(Record.readNestedNameSpecifierLoc());
1066
1067 if (HasFoundDecl) {
1068 auto *FoundD = Record.readDeclAs<NamedDecl>();
1069 auto AS = (AccessSpecifier)CurrentUnpackingBits->getNextBits(/*Width=*/2);
1070 *E->getTrailingObjects<DeclAccessPair>() = DeclAccessPair::make(FoundD, AS);
1071 }
1072
1073 if (HasTemplateInfo)
1074 ReadTemplateKWAndArgsInfo(
1075 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
1076 E->getTrailingObjects<TemplateArgumentLoc>(), NumTemplateArgs);
1077 }
1078
VisitObjCIsaExpr(ObjCIsaExpr * E)1079 void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
1080 VisitExpr(E);
1081 E->setBase(Record.readSubExpr());
1082 E->setIsaMemberLoc(readSourceLocation());
1083 E->setOpLoc(readSourceLocation());
1084 E->setArrow(Record.readInt());
1085 }
1086
1087 void ASTStmtReader::
VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr * E)1088 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
1089 VisitExpr(E);
1090 E->Operand = Record.readSubExpr();
1091 E->setShouldCopy(Record.readInt());
1092 }
1093
VisitObjCBridgedCastExpr(ObjCBridgedCastExpr * E)1094 void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
1095 VisitExplicitCastExpr(E);
1096 E->LParenLoc = readSourceLocation();
1097 E->BridgeKeywordLoc = readSourceLocation();
1098 E->Kind = Record.readInt();
1099 }
1100
VisitCastExpr(CastExpr * E)1101 void ASTStmtReader::VisitCastExpr(CastExpr *E) {
1102 VisitExpr(E);
1103 unsigned NumBaseSpecs = Record.readInt();
1104 assert(NumBaseSpecs == E->path_size());
1105
1106 CurrentUnpackingBits.emplace(Record.readInt());
1107 E->setCastKind((CastKind)CurrentUnpackingBits->getNextBits(/*Width=*/7));
1108 unsigned HasFPFeatures = CurrentUnpackingBits->getNextBit();
1109 assert(E->hasStoredFPFeatures() == HasFPFeatures);
1110
1111 E->setSubExpr(Record.readSubExpr());
1112
1113 CastExpr::path_iterator BaseI = E->path_begin();
1114 while (NumBaseSpecs--) {
1115 auto *BaseSpec = new (Record.getContext()) CXXBaseSpecifier;
1116 *BaseSpec = Record.readCXXBaseSpecifier();
1117 *BaseI++ = BaseSpec;
1118 }
1119 if (HasFPFeatures)
1120 *E->getTrailingFPFeatures() =
1121 FPOptionsOverride::getFromOpaqueInt(Record.readInt());
1122 }
1123
VisitBinaryOperator(BinaryOperator * E)1124 void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
1125 VisitExpr(E);
1126 CurrentUnpackingBits.emplace(Record.readInt());
1127 E->setOpcode(
1128 (BinaryOperator::Opcode)CurrentUnpackingBits->getNextBits(/*Width=*/6));
1129 bool hasFP_Features = CurrentUnpackingBits->getNextBit();
1130 E->setHasStoredFPFeatures(hasFP_Features);
1131 E->setLHS(Record.readSubExpr());
1132 E->setRHS(Record.readSubExpr());
1133 E->setOperatorLoc(readSourceLocation());
1134 if (hasFP_Features)
1135 E->setStoredFPFeatures(
1136 FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
1137 }
1138
VisitCompoundAssignOperator(CompoundAssignOperator * E)1139 void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
1140 VisitBinaryOperator(E);
1141 E->setComputationLHSType(Record.readType());
1142 E->setComputationResultType(Record.readType());
1143 }
1144
VisitConditionalOperator(ConditionalOperator * E)1145 void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
1146 VisitExpr(E);
1147 E->SubExprs[ConditionalOperator::COND] = Record.readSubExpr();
1148 E->SubExprs[ConditionalOperator::LHS] = Record.readSubExpr();
1149 E->SubExprs[ConditionalOperator::RHS] = Record.readSubExpr();
1150 E->QuestionLoc = readSourceLocation();
1151 E->ColonLoc = readSourceLocation();
1152 }
1153
1154 void
VisitBinaryConditionalOperator(BinaryConditionalOperator * E)1155 ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
1156 VisitExpr(E);
1157 E->OpaqueValue = cast<OpaqueValueExpr>(Record.readSubExpr());
1158 E->SubExprs[BinaryConditionalOperator::COMMON] = Record.readSubExpr();
1159 E->SubExprs[BinaryConditionalOperator::COND] = Record.readSubExpr();
1160 E->SubExprs[BinaryConditionalOperator::LHS] = Record.readSubExpr();
1161 E->SubExprs[BinaryConditionalOperator::RHS] = Record.readSubExpr();
1162 E->QuestionLoc = readSourceLocation();
1163 E->ColonLoc = readSourceLocation();
1164 }
1165
VisitImplicitCastExpr(ImplicitCastExpr * E)1166 void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
1167 VisitCastExpr(E);
1168 E->setIsPartOfExplicitCast(CurrentUnpackingBits->getNextBit());
1169 }
1170
VisitExplicitCastExpr(ExplicitCastExpr * E)1171 void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
1172 VisitCastExpr(E);
1173 E->setTypeInfoAsWritten(readTypeSourceInfo());
1174 }
1175
VisitCStyleCastExpr(CStyleCastExpr * E)1176 void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
1177 VisitExplicitCastExpr(E);
1178 E->setLParenLoc(readSourceLocation());
1179 E->setRParenLoc(readSourceLocation());
1180 }
1181
VisitCompoundLiteralExpr(CompoundLiteralExpr * E)1182 void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
1183 VisitExpr(E);
1184 E->setLParenLoc(readSourceLocation());
1185 E->setTypeSourceInfo(readTypeSourceInfo());
1186 E->setInitializer(Record.readSubExpr());
1187 E->setFileScope(Record.readInt());
1188 }
1189
VisitExtVectorElementExpr(ExtVectorElementExpr * E)1190 void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
1191 VisitExpr(E);
1192 E->setBase(Record.readSubExpr());
1193 E->setAccessor(Record.readIdentifier());
1194 E->setAccessorLoc(readSourceLocation());
1195 }
1196
VisitInitListExpr(InitListExpr * E)1197 void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
1198 VisitExpr(E);
1199 if (auto *SyntForm = cast_or_null<InitListExpr>(Record.readSubStmt()))
1200 E->setSyntacticForm(SyntForm);
1201 E->setLBraceLoc(readSourceLocation());
1202 E->setRBraceLoc(readSourceLocation());
1203 bool isArrayFiller = Record.readInt();
1204 Expr *filler = nullptr;
1205 if (isArrayFiller) {
1206 filler = Record.readSubExpr();
1207 E->ArrayFillerOrUnionFieldInit = filler;
1208 } else
1209 E->ArrayFillerOrUnionFieldInit = readDeclAs<FieldDecl>();
1210 E->sawArrayRangeDesignator(Record.readInt());
1211 unsigned NumInits = Record.readInt();
1212 E->reserveInits(Record.getContext(), NumInits);
1213 if (isArrayFiller) {
1214 for (unsigned I = 0; I != NumInits; ++I) {
1215 Expr *init = Record.readSubExpr();
1216 E->updateInit(Record.getContext(), I, init ? init : filler);
1217 }
1218 } else {
1219 for (unsigned I = 0; I != NumInits; ++I)
1220 E->updateInit(Record.getContext(), I, Record.readSubExpr());
1221 }
1222 }
1223
VisitDesignatedInitExpr(DesignatedInitExpr * E)1224 void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
1225 using Designator = DesignatedInitExpr::Designator;
1226
1227 VisitExpr(E);
1228 unsigned NumSubExprs = Record.readInt();
1229 assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
1230 for (unsigned I = 0; I != NumSubExprs; ++I)
1231 E->setSubExpr(I, Record.readSubExpr());
1232 E->setEqualOrColonLoc(readSourceLocation());
1233 E->setGNUSyntax(Record.readInt());
1234
1235 SmallVector<Designator, 4> Designators;
1236 while (Record.getIdx() < Record.size()) {
1237 switch ((DesignatorTypes)Record.readInt()) {
1238 case DESIG_FIELD_DECL: {
1239 auto *Field = readDeclAs<FieldDecl>();
1240 SourceLocation DotLoc = readSourceLocation();
1241 SourceLocation FieldLoc = readSourceLocation();
1242 Designators.push_back(Designator::CreateFieldDesignator(
1243 Field->getIdentifier(), DotLoc, FieldLoc));
1244 Designators.back().setFieldDecl(Field);
1245 break;
1246 }
1247
1248 case DESIG_FIELD_NAME: {
1249 const IdentifierInfo *Name = Record.readIdentifier();
1250 SourceLocation DotLoc = readSourceLocation();
1251 SourceLocation FieldLoc = readSourceLocation();
1252 Designators.push_back(Designator::CreateFieldDesignator(Name, DotLoc,
1253 FieldLoc));
1254 break;
1255 }
1256
1257 case DESIG_ARRAY: {
1258 unsigned Index = Record.readInt();
1259 SourceLocation LBracketLoc = readSourceLocation();
1260 SourceLocation RBracketLoc = readSourceLocation();
1261 Designators.push_back(Designator::CreateArrayDesignator(Index,
1262 LBracketLoc,
1263 RBracketLoc));
1264 break;
1265 }
1266
1267 case DESIG_ARRAY_RANGE: {
1268 unsigned Index = Record.readInt();
1269 SourceLocation LBracketLoc = readSourceLocation();
1270 SourceLocation EllipsisLoc = readSourceLocation();
1271 SourceLocation RBracketLoc = readSourceLocation();
1272 Designators.push_back(Designator::CreateArrayRangeDesignator(
1273 Index, LBracketLoc, EllipsisLoc, RBracketLoc));
1274 break;
1275 }
1276 }
1277 }
1278 E->setDesignators(Record.getContext(),
1279 Designators.data(), Designators.size());
1280 }
1281
VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr * E)1282 void ASTStmtReader::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
1283 VisitExpr(E);
1284 E->setBase(Record.readSubExpr());
1285 E->setUpdater(Record.readSubExpr());
1286 }
1287
VisitNoInitExpr(NoInitExpr * E)1288 void ASTStmtReader::VisitNoInitExpr(NoInitExpr *E) {
1289 VisitExpr(E);
1290 }
1291
VisitArrayInitLoopExpr(ArrayInitLoopExpr * E)1292 void ASTStmtReader::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
1293 VisitExpr(E);
1294 E->SubExprs[0] = Record.readSubExpr();
1295 E->SubExprs[1] = Record.readSubExpr();
1296 }
1297
VisitArrayInitIndexExpr(ArrayInitIndexExpr * E)1298 void ASTStmtReader::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
1299 VisitExpr(E);
1300 }
1301
VisitImplicitValueInitExpr(ImplicitValueInitExpr * E)1302 void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
1303 VisitExpr(E);
1304 }
1305
VisitVAArgExpr(VAArgExpr * E)1306 void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
1307 VisitExpr(E);
1308 E->setSubExpr(Record.readSubExpr());
1309 E->setWrittenTypeInfo(readTypeSourceInfo());
1310 E->setBuiltinLoc(readSourceLocation());
1311 E->setRParenLoc(readSourceLocation());
1312 E->setIsMicrosoftABI(Record.readInt());
1313 }
1314
VisitSourceLocExpr(SourceLocExpr * E)1315 void ASTStmtReader::VisitSourceLocExpr(SourceLocExpr *E) {
1316 VisitExpr(E);
1317 E->ParentContext = readDeclAs<DeclContext>();
1318 E->BuiltinLoc = readSourceLocation();
1319 E->RParenLoc = readSourceLocation();
1320 E->SourceLocExprBits.Kind = Record.readInt();
1321 }
1322
VisitEmbedExpr(EmbedExpr * E)1323 void ASTStmtReader::VisitEmbedExpr(EmbedExpr *E) {
1324 VisitExpr(E);
1325 E->EmbedKeywordLoc = readSourceLocation();
1326 EmbedDataStorage *Data = new (Record.getContext()) EmbedDataStorage;
1327 Data->BinaryData = cast<StringLiteral>(Record.readSubStmt());
1328 E->Data = Data;
1329 E->Begin = Record.readInt();
1330 E->NumOfElements = Record.readInt();
1331 }
1332
VisitAddrLabelExpr(AddrLabelExpr * E)1333 void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
1334 VisitExpr(E);
1335 E->setAmpAmpLoc(readSourceLocation());
1336 E->setLabelLoc(readSourceLocation());
1337 E->setLabel(readDeclAs<LabelDecl>());
1338 }
1339
VisitStmtExpr(StmtExpr * E)1340 void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
1341 VisitExpr(E);
1342 E->setLParenLoc(readSourceLocation());
1343 E->setRParenLoc(readSourceLocation());
1344 E->setSubStmt(cast_or_null<CompoundStmt>(Record.readSubStmt()));
1345 E->StmtExprBits.TemplateDepth = Record.readInt();
1346 }
1347
VisitChooseExpr(ChooseExpr * E)1348 void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
1349 VisitExpr(E);
1350 E->setCond(Record.readSubExpr());
1351 E->setLHS(Record.readSubExpr());
1352 E->setRHS(Record.readSubExpr());
1353 E->setBuiltinLoc(readSourceLocation());
1354 E->setRParenLoc(readSourceLocation());
1355 E->setIsConditionTrue(Record.readInt());
1356 }
1357
VisitGNUNullExpr(GNUNullExpr * E)1358 void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
1359 VisitExpr(E);
1360 E->setTokenLocation(readSourceLocation());
1361 }
1362
VisitShuffleVectorExpr(ShuffleVectorExpr * E)1363 void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
1364 VisitExpr(E);
1365 SmallVector<Expr *, 16> Exprs;
1366 unsigned NumExprs = Record.readInt();
1367 while (NumExprs--)
1368 Exprs.push_back(Record.readSubExpr());
1369 E->setExprs(Record.getContext(), Exprs);
1370 E->setBuiltinLoc(readSourceLocation());
1371 E->setRParenLoc(readSourceLocation());
1372 }
1373
VisitConvertVectorExpr(ConvertVectorExpr * E)1374 void ASTStmtReader::VisitConvertVectorExpr(ConvertVectorExpr *E) {
1375 VisitExpr(E);
1376 E->BuiltinLoc = readSourceLocation();
1377 E->RParenLoc = readSourceLocation();
1378 E->TInfo = readTypeSourceInfo();
1379 E->SrcExpr = Record.readSubExpr();
1380 }
1381
VisitBlockExpr(BlockExpr * E)1382 void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
1383 VisitExpr(E);
1384 E->setBlockDecl(readDeclAs<BlockDecl>());
1385 }
1386
VisitGenericSelectionExpr(GenericSelectionExpr * E)1387 void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
1388 VisitExpr(E);
1389
1390 unsigned NumAssocs = Record.readInt();
1391 assert(NumAssocs == E->getNumAssocs() && "Wrong NumAssocs!");
1392 E->IsExprPredicate = Record.readInt();
1393 E->ResultIndex = Record.readInt();
1394 E->GenericSelectionExprBits.GenericLoc = readSourceLocation();
1395 E->DefaultLoc = readSourceLocation();
1396 E->RParenLoc = readSourceLocation();
1397
1398 Stmt **Stmts = E->getTrailingObjects<Stmt *>();
1399 // Add 1 to account for the controlling expression which is the first
1400 // expression in the trailing array of Stmt *. This is not needed for
1401 // the trailing array of TypeSourceInfo *.
1402 for (unsigned I = 0, N = NumAssocs + 1; I < N; ++I)
1403 Stmts[I] = Record.readSubExpr();
1404
1405 TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
1406 for (unsigned I = 0, N = NumAssocs; I < N; ++I)
1407 TSIs[I] = readTypeSourceInfo();
1408 }
1409
VisitPseudoObjectExpr(PseudoObjectExpr * E)1410 void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
1411 VisitExpr(E);
1412 unsigned numSemanticExprs = Record.readInt();
1413 assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs);
1414 E->PseudoObjectExprBits.ResultIndex = Record.readInt();
1415
1416 // Read the syntactic expression.
1417 E->getSubExprsBuffer()[0] = Record.readSubExpr();
1418
1419 // Read all the semantic expressions.
1420 for (unsigned i = 0; i != numSemanticExprs; ++i) {
1421 Expr *subExpr = Record.readSubExpr();
1422 E->getSubExprsBuffer()[i+1] = subExpr;
1423 }
1424 }
1425
VisitAtomicExpr(AtomicExpr * E)1426 void ASTStmtReader::VisitAtomicExpr(AtomicExpr *E) {
1427 VisitExpr(E);
1428 E->Op = AtomicExpr::AtomicOp(Record.readInt());
1429 E->NumSubExprs = AtomicExpr::getNumSubExprs(E->Op);
1430 for (unsigned I = 0; I != E->NumSubExprs; ++I)
1431 E->SubExprs[I] = Record.readSubExpr();
1432 E->BuiltinLoc = readSourceLocation();
1433 E->RParenLoc = readSourceLocation();
1434 }
1435
1436 //===----------------------------------------------------------------------===//
1437 // Objective-C Expressions and Statements
1438
VisitObjCStringLiteral(ObjCStringLiteral * E)1439 void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
1440 VisitExpr(E);
1441 E->setString(cast<StringLiteral>(Record.readSubStmt()));
1442 E->setAtLoc(readSourceLocation());
1443 }
1444
VisitObjCBoxedExpr(ObjCBoxedExpr * E)1445 void ASTStmtReader::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1446 VisitExpr(E);
1447 // could be one of several IntegerLiteral, FloatLiteral, etc.
1448 E->SubExpr = Record.readSubStmt();
1449 E->BoxingMethod = readDeclAs<ObjCMethodDecl>();
1450 E->Range = readSourceRange();
1451 }
1452
VisitObjCArrayLiteral(ObjCArrayLiteral * E)1453 void ASTStmtReader::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1454 VisitExpr(E);
1455 unsigned NumElements = Record.readInt();
1456 assert(NumElements == E->getNumElements() && "Wrong number of elements");
1457 Expr **Elements = E->getElements();
1458 for (unsigned I = 0, N = NumElements; I != N; ++I)
1459 Elements[I] = Record.readSubExpr();
1460 E->ArrayWithObjectsMethod = readDeclAs<ObjCMethodDecl>();
1461 E->Range = readSourceRange();
1462 }
1463
VisitObjCDictionaryLiteral(ObjCDictionaryLiteral * E)1464 void ASTStmtReader::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1465 VisitExpr(E);
1466 unsigned NumElements = Record.readInt();
1467 assert(NumElements == E->getNumElements() && "Wrong number of elements");
1468 bool HasPackExpansions = Record.readInt();
1469 assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch");
1470 auto *KeyValues =
1471 E->getTrailingObjects<ObjCDictionaryLiteral::KeyValuePair>();
1472 auto *Expansions =
1473 E->getTrailingObjects<ObjCDictionaryLiteral::ExpansionData>();
1474 for (unsigned I = 0; I != NumElements; ++I) {
1475 KeyValues[I].Key = Record.readSubExpr();
1476 KeyValues[I].Value = Record.readSubExpr();
1477 if (HasPackExpansions) {
1478 Expansions[I].EllipsisLoc = readSourceLocation();
1479 Expansions[I].NumExpansionsPlusOne = Record.readInt();
1480 }
1481 }
1482 E->DictWithObjectsMethod = readDeclAs<ObjCMethodDecl>();
1483 E->Range = readSourceRange();
1484 }
1485
VisitObjCEncodeExpr(ObjCEncodeExpr * E)1486 void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
1487 VisitExpr(E);
1488 E->setEncodedTypeSourceInfo(readTypeSourceInfo());
1489 E->setAtLoc(readSourceLocation());
1490 E->setRParenLoc(readSourceLocation());
1491 }
1492
VisitObjCSelectorExpr(ObjCSelectorExpr * E)1493 void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
1494 VisitExpr(E);
1495 E->setSelector(Record.readSelector());
1496 E->setAtLoc(readSourceLocation());
1497 E->setRParenLoc(readSourceLocation());
1498 }
1499
VisitObjCProtocolExpr(ObjCProtocolExpr * E)1500 void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
1501 VisitExpr(E);
1502 E->setProtocol(readDeclAs<ObjCProtocolDecl>());
1503 E->setAtLoc(readSourceLocation());
1504 E->ProtoLoc = readSourceLocation();
1505 E->setRParenLoc(readSourceLocation());
1506 }
1507
VisitObjCIvarRefExpr(ObjCIvarRefExpr * E)1508 void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1509 VisitExpr(E);
1510 E->setDecl(readDeclAs<ObjCIvarDecl>());
1511 E->setLocation(readSourceLocation());
1512 E->setOpLoc(readSourceLocation());
1513 E->setBase(Record.readSubExpr());
1514 E->setIsArrow(Record.readInt());
1515 E->setIsFreeIvar(Record.readInt());
1516 }
1517
VisitObjCPropertyRefExpr(ObjCPropertyRefExpr * E)1518 void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1519 VisitExpr(E);
1520 unsigned MethodRefFlags = Record.readInt();
1521 bool Implicit = Record.readInt() != 0;
1522 if (Implicit) {
1523 auto *Getter = readDeclAs<ObjCMethodDecl>();
1524 auto *Setter = readDeclAs<ObjCMethodDecl>();
1525 E->setImplicitProperty(Getter, Setter, MethodRefFlags);
1526 } else {
1527 E->setExplicitProperty(readDeclAs<ObjCPropertyDecl>(), MethodRefFlags);
1528 }
1529 E->setLocation(readSourceLocation());
1530 E->setReceiverLocation(readSourceLocation());
1531 switch (Record.readInt()) {
1532 case 0:
1533 E->setBase(Record.readSubExpr());
1534 break;
1535 case 1:
1536 E->setSuperReceiver(Record.readType());
1537 break;
1538 case 2:
1539 E->setClassReceiver(readDeclAs<ObjCInterfaceDecl>());
1540 break;
1541 }
1542 }
1543
VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr * E)1544 void ASTStmtReader::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1545 VisitExpr(E);
1546 E->setRBracket(readSourceLocation());
1547 E->setBaseExpr(Record.readSubExpr());
1548 E->setKeyExpr(Record.readSubExpr());
1549 E->GetAtIndexMethodDecl = readDeclAs<ObjCMethodDecl>();
1550 E->SetAtIndexMethodDecl = readDeclAs<ObjCMethodDecl>();
1551 }
1552
VisitObjCMessageExpr(ObjCMessageExpr * E)1553 void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1554 VisitExpr(E);
1555 assert(Record.peekInt() == E->getNumArgs());
1556 Record.skipInts(1);
1557 unsigned NumStoredSelLocs = Record.readInt();
1558 E->SelLocsKind = Record.readInt();
1559 E->setDelegateInitCall(Record.readInt());
1560 E->IsImplicit = Record.readInt();
1561 auto Kind = static_cast<ObjCMessageExpr::ReceiverKind>(Record.readInt());
1562 switch (Kind) {
1563 case ObjCMessageExpr::Instance:
1564 E->setInstanceReceiver(Record.readSubExpr());
1565 break;
1566
1567 case ObjCMessageExpr::Class:
1568 E->setClassReceiver(readTypeSourceInfo());
1569 break;
1570
1571 case ObjCMessageExpr::SuperClass:
1572 case ObjCMessageExpr::SuperInstance: {
1573 QualType T = Record.readType();
1574 SourceLocation SuperLoc = readSourceLocation();
1575 E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
1576 break;
1577 }
1578 }
1579
1580 assert(Kind == E->getReceiverKind());
1581
1582 if (Record.readInt())
1583 E->setMethodDecl(readDeclAs<ObjCMethodDecl>());
1584 else
1585 E->setSelector(Record.readSelector());
1586
1587 E->LBracLoc = readSourceLocation();
1588 E->RBracLoc = readSourceLocation();
1589
1590 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1591 E->setArg(I, Record.readSubExpr());
1592
1593 SourceLocation *Locs = E->getStoredSelLocs();
1594 for (unsigned I = 0; I != NumStoredSelLocs; ++I)
1595 Locs[I] = readSourceLocation();
1596 }
1597
VisitObjCForCollectionStmt(ObjCForCollectionStmt * S)1598 void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1599 VisitStmt(S);
1600 S->setElement(Record.readSubStmt());
1601 S->setCollection(Record.readSubExpr());
1602 S->setBody(Record.readSubStmt());
1603 S->setForLoc(readSourceLocation());
1604 S->setRParenLoc(readSourceLocation());
1605 }
1606
VisitObjCAtCatchStmt(ObjCAtCatchStmt * S)1607 void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1608 VisitStmt(S);
1609 S->setCatchBody(Record.readSubStmt());
1610 S->setCatchParamDecl(readDeclAs<VarDecl>());
1611 S->setAtCatchLoc(readSourceLocation());
1612 S->setRParenLoc(readSourceLocation());
1613 }
1614
VisitObjCAtFinallyStmt(ObjCAtFinallyStmt * S)1615 void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1616 VisitStmt(S);
1617 S->setFinallyBody(Record.readSubStmt());
1618 S->setAtFinallyLoc(readSourceLocation());
1619 }
1620
VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt * S)1621 void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1622 VisitStmt(S); // FIXME: no test coverage.
1623 S->setSubStmt(Record.readSubStmt());
1624 S->setAtLoc(readSourceLocation());
1625 }
1626
VisitObjCAtTryStmt(ObjCAtTryStmt * S)1627 void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1628 VisitStmt(S);
1629 assert(Record.peekInt() == S->getNumCatchStmts());
1630 Record.skipInts(1);
1631 bool HasFinally = Record.readInt();
1632 S->setTryBody(Record.readSubStmt());
1633 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1634 S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Record.readSubStmt()));
1635
1636 if (HasFinally)
1637 S->setFinallyStmt(Record.readSubStmt());
1638 S->setAtTryLoc(readSourceLocation());
1639 }
1640
VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt * S)1641 void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1642 VisitStmt(S); // FIXME: no test coverage.
1643 S->setSynchExpr(Record.readSubStmt());
1644 S->setSynchBody(Record.readSubStmt());
1645 S->setAtSynchronizedLoc(readSourceLocation());
1646 }
1647
VisitObjCAtThrowStmt(ObjCAtThrowStmt * S)1648 void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1649 VisitStmt(S); // FIXME: no test coverage.
1650 S->setThrowExpr(Record.readSubStmt());
1651 S->setThrowLoc(readSourceLocation());
1652 }
1653
VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr * E)1654 void ASTStmtReader::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1655 VisitExpr(E);
1656 E->setValue(Record.readInt());
1657 E->setLocation(readSourceLocation());
1658 }
1659
VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr * E)1660 void ASTStmtReader::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1661 VisitExpr(E);
1662 SourceRange R = Record.readSourceRange();
1663 E->AtLoc = R.getBegin();
1664 E->RParen = R.getEnd();
1665 E->VersionToCheck = Record.readVersionTuple();
1666 }
1667
1668 //===----------------------------------------------------------------------===//
1669 // C++ Expressions and Statements
1670 //===----------------------------------------------------------------------===//
1671
VisitCXXCatchStmt(CXXCatchStmt * S)1672 void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
1673 VisitStmt(S);
1674 S->CatchLoc = readSourceLocation();
1675 S->ExceptionDecl = readDeclAs<VarDecl>();
1676 S->HandlerBlock = Record.readSubStmt();
1677 }
1678
VisitCXXTryStmt(CXXTryStmt * S)1679 void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
1680 VisitStmt(S);
1681 assert(Record.peekInt() == S->getNumHandlers() && "NumStmtFields is wrong ?");
1682 Record.skipInts(1);
1683 S->TryLoc = readSourceLocation();
1684 S->getStmts()[0] = Record.readSubStmt();
1685 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1686 S->getStmts()[i + 1] = Record.readSubStmt();
1687 }
1688
VisitCXXForRangeStmt(CXXForRangeStmt * S)1689 void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1690 VisitStmt(S);
1691 S->ForLoc = readSourceLocation();
1692 S->CoawaitLoc = readSourceLocation();
1693 S->ColonLoc = readSourceLocation();
1694 S->RParenLoc = readSourceLocation();
1695 S->setInit(Record.readSubStmt());
1696 S->setRangeStmt(Record.readSubStmt());
1697 S->setBeginStmt(Record.readSubStmt());
1698 S->setEndStmt(Record.readSubStmt());
1699 S->setCond(Record.readSubExpr());
1700 S->setInc(Record.readSubExpr());
1701 S->setLoopVarStmt(Record.readSubStmt());
1702 S->setBody(Record.readSubStmt());
1703 }
1704
VisitMSDependentExistsStmt(MSDependentExistsStmt * S)1705 void ASTStmtReader::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1706 VisitStmt(S);
1707 S->KeywordLoc = readSourceLocation();
1708 S->IsIfExists = Record.readInt();
1709 S->QualifierLoc = Record.readNestedNameSpecifierLoc();
1710 S->NameInfo = Record.readDeclarationNameInfo();
1711 S->SubStmt = Record.readSubStmt();
1712 }
1713
VisitCXXOperatorCallExpr(CXXOperatorCallExpr * E)1714 void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1715 VisitCallExpr(E);
1716 E->CXXOperatorCallExprBits.OperatorKind = Record.readInt();
1717 E->Range = Record.readSourceRange();
1718 }
1719
VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator * E)1720 void ASTStmtReader::VisitCXXRewrittenBinaryOperator(
1721 CXXRewrittenBinaryOperator *E) {
1722 VisitExpr(E);
1723 E->CXXRewrittenBinaryOperatorBits.IsReversed = Record.readInt();
1724 E->SemanticForm = Record.readSubExpr();
1725 }
1726
VisitCXXConstructExpr(CXXConstructExpr * E)1727 void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
1728 VisitExpr(E);
1729
1730 unsigned NumArgs = Record.readInt();
1731 assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");
1732
1733 E->CXXConstructExprBits.Elidable = Record.readInt();
1734 E->CXXConstructExprBits.HadMultipleCandidates = Record.readInt();
1735 E->CXXConstructExprBits.ListInitialization = Record.readInt();
1736 E->CXXConstructExprBits.StdInitListInitialization = Record.readInt();
1737 E->CXXConstructExprBits.ZeroInitialization = Record.readInt();
1738 E->CXXConstructExprBits.ConstructionKind = Record.readInt();
1739 E->CXXConstructExprBits.IsImmediateEscalating = Record.readInt();
1740 E->CXXConstructExprBits.Loc = readSourceLocation();
1741 E->Constructor = readDeclAs<CXXConstructorDecl>();
1742 E->ParenOrBraceRange = readSourceRange();
1743
1744 for (unsigned I = 0; I != NumArgs; ++I)
1745 E->setArg(I, Record.readSubExpr());
1746 }
1747
VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr * E)1748 void ASTStmtReader::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1749 VisitExpr(E);
1750 E->Constructor = readDeclAs<CXXConstructorDecl>();
1751 E->Loc = readSourceLocation();
1752 E->ConstructsVirtualBase = Record.readInt();
1753 E->InheritedFromVirtualBase = Record.readInt();
1754 }
1755
VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr * E)1756 void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1757 VisitCXXConstructExpr(E);
1758 E->TSI = readTypeSourceInfo();
1759 }
1760
VisitLambdaExpr(LambdaExpr * E)1761 void ASTStmtReader::VisitLambdaExpr(LambdaExpr *E) {
1762 VisitExpr(E);
1763 unsigned NumCaptures = Record.readInt();
1764 (void)NumCaptures;
1765 assert(NumCaptures == E->LambdaExprBits.NumCaptures);
1766 E->IntroducerRange = readSourceRange();
1767 E->LambdaExprBits.CaptureDefault = Record.readInt();
1768 E->CaptureDefaultLoc = readSourceLocation();
1769 E->LambdaExprBits.ExplicitParams = Record.readInt();
1770 E->LambdaExprBits.ExplicitResultType = Record.readInt();
1771 E->ClosingBrace = readSourceLocation();
1772
1773 // Read capture initializers.
1774 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1775 CEnd = E->capture_init_end();
1776 C != CEnd; ++C)
1777 *C = Record.readSubExpr();
1778
1779 // The body will be lazily deserialized when needed from the call operator
1780 // declaration.
1781 }
1782
1783 void
VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr * E)1784 ASTStmtReader::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1785 VisitExpr(E);
1786 E->SubExpr = Record.readSubExpr();
1787 }
1788
VisitCXXNamedCastExpr(CXXNamedCastExpr * E)1789 void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1790 VisitExplicitCastExpr(E);
1791 SourceRange R = readSourceRange();
1792 E->Loc = R.getBegin();
1793 E->RParenLoc = R.getEnd();
1794 if (CurrentUnpackingBits->getNextBit())
1795 E->AngleBrackets = readSourceRange();
1796 }
1797
VisitCXXStaticCastExpr(CXXStaticCastExpr * E)1798 void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1799 return VisitCXXNamedCastExpr(E);
1800 }
1801
VisitCXXDynamicCastExpr(CXXDynamicCastExpr * E)1802 void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1803 return VisitCXXNamedCastExpr(E);
1804 }
1805
VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr * E)1806 void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1807 return VisitCXXNamedCastExpr(E);
1808 }
1809
VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr * E)1810 void ASTStmtReader::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
1811 return VisitCXXNamedCastExpr(E);
1812 }
1813
VisitCXXConstCastExpr(CXXConstCastExpr * E)1814 void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1815 return VisitCXXNamedCastExpr(E);
1816 }
1817
VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr * E)1818 void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1819 VisitExplicitCastExpr(E);
1820 E->setLParenLoc(readSourceLocation());
1821 E->setRParenLoc(readSourceLocation());
1822 }
1823
VisitBuiltinBitCastExpr(BuiltinBitCastExpr * E)1824 void ASTStmtReader::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
1825 VisitExplicitCastExpr(E);
1826 E->KWLoc = readSourceLocation();
1827 E->RParenLoc = readSourceLocation();
1828 }
1829
VisitUserDefinedLiteral(UserDefinedLiteral * E)1830 void ASTStmtReader::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1831 VisitCallExpr(E);
1832 E->UDSuffixLoc = readSourceLocation();
1833 }
1834
VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr * E)1835 void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1836 VisitExpr(E);
1837 E->setValue(Record.readInt());
1838 E->setLocation(readSourceLocation());
1839 }
1840
VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr * E)1841 void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1842 VisitExpr(E);
1843 E->setLocation(readSourceLocation());
1844 }
1845
VisitCXXTypeidExpr(CXXTypeidExpr * E)1846 void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1847 VisitExpr(E);
1848 E->setSourceRange(readSourceRange());
1849 if (E->isTypeOperand())
1850 E->Operand = readTypeSourceInfo();
1851 else
1852 E->Operand = Record.readSubExpr();
1853 }
1854
VisitCXXThisExpr(CXXThisExpr * E)1855 void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
1856 VisitExpr(E);
1857 E->setLocation(readSourceLocation());
1858 E->setImplicit(Record.readInt());
1859 E->setCapturedByCopyInLambdaWithExplicitObjectParameter(Record.readInt());
1860 }
1861
VisitCXXThrowExpr(CXXThrowExpr * E)1862 void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
1863 VisitExpr(E);
1864 E->CXXThrowExprBits.ThrowLoc = readSourceLocation();
1865 E->Operand = Record.readSubExpr();
1866 E->CXXThrowExprBits.IsThrownVariableInScope = Record.readInt();
1867 }
1868
VisitCXXDefaultArgExpr(CXXDefaultArgExpr * E)1869 void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1870 VisitExpr(E);
1871 E->Param = readDeclAs<ParmVarDecl>();
1872 E->UsedContext = readDeclAs<DeclContext>();
1873 E->CXXDefaultArgExprBits.Loc = readSourceLocation();
1874 E->CXXDefaultArgExprBits.HasRewrittenInit = Record.readInt();
1875 if (E->CXXDefaultArgExprBits.HasRewrittenInit)
1876 *E->getTrailingObjects<Expr *>() = Record.readSubExpr();
1877 }
1878
VisitCXXDefaultInitExpr(CXXDefaultInitExpr * E)1879 void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1880 VisitExpr(E);
1881 E->CXXDefaultInitExprBits.HasRewrittenInit = Record.readInt();
1882 E->Field = readDeclAs<FieldDecl>();
1883 E->UsedContext = readDeclAs<DeclContext>();
1884 E->CXXDefaultInitExprBits.Loc = readSourceLocation();
1885 if (E->CXXDefaultInitExprBits.HasRewrittenInit)
1886 *E->getTrailingObjects<Expr *>() = Record.readSubExpr();
1887 }
1888
VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr * E)1889 void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1890 VisitExpr(E);
1891 E->setTemporary(Record.readCXXTemporary());
1892 E->setSubExpr(Record.readSubExpr());
1893 }
1894
VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr * E)1895 void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1896 VisitExpr(E);
1897 E->TypeInfo = readTypeSourceInfo();
1898 E->CXXScalarValueInitExprBits.RParenLoc = readSourceLocation();
1899 }
1900
VisitCXXNewExpr(CXXNewExpr * E)1901 void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
1902 VisitExpr(E);
1903
1904 bool IsArray = Record.readInt();
1905 bool HasInit = Record.readInt();
1906 unsigned NumPlacementArgs = Record.readInt();
1907 bool IsParenTypeId = Record.readInt();
1908
1909 E->CXXNewExprBits.IsGlobalNew = Record.readInt();
1910 E->CXXNewExprBits.ShouldPassAlignment = Record.readInt();
1911 E->CXXNewExprBits.UsualArrayDeleteWantsSize = Record.readInt();
1912 E->CXXNewExprBits.HasInitializer = Record.readInt();
1913 E->CXXNewExprBits.StoredInitializationStyle = Record.readInt();
1914
1915 assert((IsArray == E->isArray()) && "Wrong IsArray!");
1916 assert((HasInit == E->hasInitializer()) && "Wrong HasInit!");
1917 assert((NumPlacementArgs == E->getNumPlacementArgs()) &&
1918 "Wrong NumPlacementArgs!");
1919 assert((IsParenTypeId == E->isParenTypeId()) && "Wrong IsParenTypeId!");
1920 (void)IsArray;
1921 (void)HasInit;
1922 (void)NumPlacementArgs;
1923
1924 E->setOperatorNew(readDeclAs<FunctionDecl>());
1925 E->setOperatorDelete(readDeclAs<FunctionDecl>());
1926 E->AllocatedTypeInfo = readTypeSourceInfo();
1927 if (IsParenTypeId)
1928 E->getTrailingObjects<SourceRange>()[0] = readSourceRange();
1929 E->Range = readSourceRange();
1930 E->DirectInitRange = readSourceRange();
1931
1932 // Install all the subexpressions.
1933 for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),
1934 N = E->raw_arg_end();
1935 I != N; ++I)
1936 *I = Record.readSubStmt();
1937 }
1938
VisitCXXDeleteExpr(CXXDeleteExpr * E)1939 void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1940 VisitExpr(E);
1941 E->CXXDeleteExprBits.GlobalDelete = Record.readInt();
1942 E->CXXDeleteExprBits.ArrayForm = Record.readInt();
1943 E->CXXDeleteExprBits.ArrayFormAsWritten = Record.readInt();
1944 E->CXXDeleteExprBits.UsualArrayDeleteWantsSize = Record.readInt();
1945 E->OperatorDelete = readDeclAs<FunctionDecl>();
1946 E->Argument = Record.readSubExpr();
1947 E->CXXDeleteExprBits.Loc = readSourceLocation();
1948 }
1949
VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr * E)1950 void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1951 VisitExpr(E);
1952
1953 E->Base = Record.readSubExpr();
1954 E->IsArrow = Record.readInt();
1955 E->OperatorLoc = readSourceLocation();
1956 E->QualifierLoc = Record.readNestedNameSpecifierLoc();
1957 E->ScopeType = readTypeSourceInfo();
1958 E->ColonColonLoc = readSourceLocation();
1959 E->TildeLoc = readSourceLocation();
1960
1961 IdentifierInfo *II = Record.readIdentifier();
1962 if (II)
1963 E->setDestroyedType(II, readSourceLocation());
1964 else
1965 E->setDestroyedType(readTypeSourceInfo());
1966 }
1967
VisitExprWithCleanups(ExprWithCleanups * E)1968 void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
1969 VisitExpr(E);
1970
1971 unsigned NumObjects = Record.readInt();
1972 assert(NumObjects == E->getNumObjects());
1973 for (unsigned i = 0; i != NumObjects; ++i) {
1974 unsigned CleanupKind = Record.readInt();
1975 ExprWithCleanups::CleanupObject Obj;
1976 if (CleanupKind == COK_Block)
1977 Obj = readDeclAs<BlockDecl>();
1978 else if (CleanupKind == COK_CompoundLiteral)
1979 Obj = cast<CompoundLiteralExpr>(Record.readSubExpr());
1980 else
1981 llvm_unreachable("unexpected cleanup object type");
1982 E->getTrailingObjects<ExprWithCleanups::CleanupObject>()[i] = Obj;
1983 }
1984
1985 E->ExprWithCleanupsBits.CleanupsHaveSideEffects = Record.readInt();
1986 E->SubExpr = Record.readSubExpr();
1987 }
1988
VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr * E)1989 void ASTStmtReader::VisitCXXDependentScopeMemberExpr(
1990 CXXDependentScopeMemberExpr *E) {
1991 VisitExpr(E);
1992
1993 unsigned NumTemplateArgs = Record.readInt();
1994 CurrentUnpackingBits.emplace(Record.readInt());
1995 bool HasTemplateKWAndArgsInfo = CurrentUnpackingBits->getNextBit();
1996 bool HasFirstQualifierFoundInScope = CurrentUnpackingBits->getNextBit();
1997
1998 assert((HasTemplateKWAndArgsInfo == E->hasTemplateKWAndArgsInfo()) &&
1999 "Wrong HasTemplateKWAndArgsInfo!");
2000 assert(
2001 (HasFirstQualifierFoundInScope == E->hasFirstQualifierFoundInScope()) &&
2002 "Wrong HasFirstQualifierFoundInScope!");
2003
2004 if (HasTemplateKWAndArgsInfo)
2005 ReadTemplateKWAndArgsInfo(
2006 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
2007 E->getTrailingObjects<TemplateArgumentLoc>(), NumTemplateArgs);
2008
2009 assert((NumTemplateArgs == E->getNumTemplateArgs()) &&
2010 "Wrong NumTemplateArgs!");
2011
2012 E->CXXDependentScopeMemberExprBits.IsArrow =
2013 CurrentUnpackingBits->getNextBit();
2014
2015 E->BaseType = Record.readType();
2016 E->QualifierLoc = Record.readNestedNameSpecifierLoc();
2017 // not ImplicitAccess
2018 if (CurrentUnpackingBits->getNextBit())
2019 E->Base = Record.readSubExpr();
2020 else
2021 E->Base = nullptr;
2022
2023 E->CXXDependentScopeMemberExprBits.OperatorLoc = readSourceLocation();
2024
2025 if (HasFirstQualifierFoundInScope)
2026 *E->getTrailingObjects<NamedDecl *>() = readDeclAs<NamedDecl>();
2027
2028 E->MemberNameInfo = Record.readDeclarationNameInfo();
2029 }
2030
2031 void
VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr * E)2032 ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
2033 VisitExpr(E);
2034
2035 if (CurrentUnpackingBits->getNextBit()) // HasTemplateKWAndArgsInfo
2036 ReadTemplateKWAndArgsInfo(
2037 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
2038 E->getTrailingObjects<TemplateArgumentLoc>(),
2039 /*NumTemplateArgs=*/CurrentUnpackingBits->getNextBits(/*Width=*/16));
2040
2041 E->QualifierLoc = Record.readNestedNameSpecifierLoc();
2042 E->NameInfo = Record.readDeclarationNameInfo();
2043 }
2044
2045 void
VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr * E)2046 ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
2047 VisitExpr(E);
2048 assert(Record.peekInt() == E->getNumArgs() &&
2049 "Read wrong record during creation ?");
2050 Record.skipInts(1);
2051 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
2052 E->setArg(I, Record.readSubExpr());
2053 E->TypeAndInitForm.setPointer(readTypeSourceInfo());
2054 E->setLParenLoc(readSourceLocation());
2055 E->setRParenLoc(readSourceLocation());
2056 E->TypeAndInitForm.setInt(Record.readInt());
2057 }
2058
VisitOverloadExpr(OverloadExpr * E)2059 void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
2060 VisitExpr(E);
2061
2062 unsigned NumResults = Record.readInt();
2063 CurrentUnpackingBits.emplace(Record.readInt());
2064 bool HasTemplateKWAndArgsInfo = CurrentUnpackingBits->getNextBit();
2065 assert((E->getNumDecls() == NumResults) && "Wrong NumResults!");
2066 assert((E->hasTemplateKWAndArgsInfo() == HasTemplateKWAndArgsInfo) &&
2067 "Wrong HasTemplateKWAndArgsInfo!");
2068
2069 if (HasTemplateKWAndArgsInfo) {
2070 unsigned NumTemplateArgs = Record.readInt();
2071 ReadTemplateKWAndArgsInfo(*E->getTrailingASTTemplateKWAndArgsInfo(),
2072 E->getTrailingTemplateArgumentLoc(),
2073 NumTemplateArgs);
2074 assert((E->getNumTemplateArgs() == NumTemplateArgs) &&
2075 "Wrong NumTemplateArgs!");
2076 }
2077
2078 UnresolvedSet<8> Decls;
2079 for (unsigned I = 0; I != NumResults; ++I) {
2080 auto *D = readDeclAs<NamedDecl>();
2081 auto AS = (AccessSpecifier)Record.readInt();
2082 Decls.addDecl(D, AS);
2083 }
2084
2085 DeclAccessPair *Results = E->getTrailingResults();
2086 UnresolvedSetIterator Iter = Decls.begin();
2087 for (unsigned I = 0; I != NumResults; ++I) {
2088 Results[I] = (Iter + I).getPair();
2089 }
2090
2091 E->NameInfo = Record.readDeclarationNameInfo();
2092 E->QualifierLoc = Record.readNestedNameSpecifierLoc();
2093 }
2094
VisitUnresolvedMemberExpr(UnresolvedMemberExpr * E)2095 void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
2096 VisitOverloadExpr(E);
2097 E->UnresolvedMemberExprBits.IsArrow = CurrentUnpackingBits->getNextBit();
2098 E->UnresolvedMemberExprBits.HasUnresolvedUsing =
2099 CurrentUnpackingBits->getNextBit();
2100
2101 if (/*!isImplicitAccess=*/CurrentUnpackingBits->getNextBit())
2102 E->Base = Record.readSubExpr();
2103 else
2104 E->Base = nullptr;
2105
2106 E->OperatorLoc = readSourceLocation();
2107
2108 E->BaseType = Record.readType();
2109 }
2110
VisitUnresolvedLookupExpr(UnresolvedLookupExpr * E)2111 void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
2112 VisitOverloadExpr(E);
2113 E->UnresolvedLookupExprBits.RequiresADL = CurrentUnpackingBits->getNextBit();
2114 E->NamingClass = readDeclAs<CXXRecordDecl>();
2115 }
2116
VisitTypeTraitExpr(TypeTraitExpr * E)2117 void ASTStmtReader::VisitTypeTraitExpr(TypeTraitExpr *E) {
2118 VisitExpr(E);
2119 E->TypeTraitExprBits.NumArgs = Record.readInt();
2120 E->TypeTraitExprBits.Kind = Record.readInt();
2121 E->TypeTraitExprBits.Value = Record.readInt();
2122 SourceRange Range = readSourceRange();
2123 E->Loc = Range.getBegin();
2124 E->RParenLoc = Range.getEnd();
2125
2126 auto **Args = E->getTrailingObjects<TypeSourceInfo *>();
2127 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
2128 Args[I] = readTypeSourceInfo();
2129 }
2130
VisitArrayTypeTraitExpr(ArrayTypeTraitExpr * E)2131 void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
2132 VisitExpr(E);
2133 E->ATT = (ArrayTypeTrait)Record.readInt();
2134 E->Value = (unsigned int)Record.readInt();
2135 SourceRange Range = readSourceRange();
2136 E->Loc = Range.getBegin();
2137 E->RParen = Range.getEnd();
2138 E->QueriedType = readTypeSourceInfo();
2139 E->Dimension = Record.readSubExpr();
2140 }
2141
VisitExpressionTraitExpr(ExpressionTraitExpr * E)2142 void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2143 VisitExpr(E);
2144 E->ET = (ExpressionTrait)Record.readInt();
2145 E->Value = (bool)Record.readInt();
2146 SourceRange Range = readSourceRange();
2147 E->QueriedExpression = Record.readSubExpr();
2148 E->Loc = Range.getBegin();
2149 E->RParen = Range.getEnd();
2150 }
2151
VisitCXXNoexceptExpr(CXXNoexceptExpr * E)2152 void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2153 VisitExpr(E);
2154 E->CXXNoexceptExprBits.Value = Record.readInt();
2155 E->Range = readSourceRange();
2156 E->Operand = Record.readSubExpr();
2157 }
2158
VisitPackExpansionExpr(PackExpansionExpr * E)2159 void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
2160 VisitExpr(E);
2161 E->EllipsisLoc = readSourceLocation();
2162 E->NumExpansions = Record.readInt();
2163 E->Pattern = Record.readSubExpr();
2164 }
2165
VisitSizeOfPackExpr(SizeOfPackExpr * E)2166 void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2167 VisitExpr(E);
2168 unsigned NumPartialArgs = Record.readInt();
2169 E->OperatorLoc = readSourceLocation();
2170 E->PackLoc = readSourceLocation();
2171 E->RParenLoc = readSourceLocation();
2172 E->Pack = Record.readDeclAs<NamedDecl>();
2173 if (E->isPartiallySubstituted()) {
2174 assert(E->Length == NumPartialArgs);
2175 for (auto *I = E->getTrailingObjects<TemplateArgument>(),
2176 *E = I + NumPartialArgs;
2177 I != E; ++I)
2178 new (I) TemplateArgument(Record.readTemplateArgument());
2179 } else if (!E->isValueDependent()) {
2180 E->Length = Record.readInt();
2181 }
2182 }
2183
VisitPackIndexingExpr(PackIndexingExpr * E)2184 void ASTStmtReader::VisitPackIndexingExpr(PackIndexingExpr *E) {
2185 VisitExpr(E);
2186 E->TransformedExpressions = Record.readInt();
2187 E->ExpandedToEmptyPack = Record.readInt();
2188 E->EllipsisLoc = readSourceLocation();
2189 E->RSquareLoc = readSourceLocation();
2190 E->SubExprs[0] = Record.readStmt();
2191 E->SubExprs[1] = Record.readStmt();
2192 auto **Exprs = E->getTrailingObjects<Expr *>();
2193 for (unsigned I = 0; I < E->TransformedExpressions; ++I)
2194 Exprs[I] = Record.readExpr();
2195 }
2196
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr * E)2197 void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
2198 SubstNonTypeTemplateParmExpr *E) {
2199 VisitExpr(E);
2200 E->AssociatedDeclAndRef.setPointer(readDeclAs<Decl>());
2201 E->AssociatedDeclAndRef.setInt(CurrentUnpackingBits->getNextBit());
2202 E->Index = CurrentUnpackingBits->getNextBits(/*Width=*/12);
2203 if (CurrentUnpackingBits->getNextBit())
2204 E->PackIndex = Record.readInt();
2205 else
2206 E->PackIndex = 0;
2207 E->SubstNonTypeTemplateParmExprBits.NameLoc = readSourceLocation();
2208 E->Replacement = Record.readSubExpr();
2209 }
2210
VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr * E)2211 void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
2212 SubstNonTypeTemplateParmPackExpr *E) {
2213 VisitExpr(E);
2214 E->AssociatedDecl = readDeclAs<Decl>();
2215 E->Index = Record.readInt();
2216 TemplateArgument ArgPack = Record.readTemplateArgument();
2217 if (ArgPack.getKind() != TemplateArgument::Pack)
2218 return;
2219
2220 E->Arguments = ArgPack.pack_begin();
2221 E->NumArguments = ArgPack.pack_size();
2222 E->NameLoc = readSourceLocation();
2223 }
2224
VisitFunctionParmPackExpr(FunctionParmPackExpr * E)2225 void ASTStmtReader::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2226 VisitExpr(E);
2227 E->NumParameters = Record.readInt();
2228 E->ParamPack = readDeclAs<ParmVarDecl>();
2229 E->NameLoc = readSourceLocation();
2230 auto **Parms = E->getTrailingObjects<VarDecl *>();
2231 for (unsigned i = 0, n = E->NumParameters; i != n; ++i)
2232 Parms[i] = readDeclAs<VarDecl>();
2233 }
2234
VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr * E)2235 void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
2236 VisitExpr(E);
2237 bool HasMaterialzedDecl = Record.readInt();
2238 if (HasMaterialzedDecl)
2239 E->State = cast<LifetimeExtendedTemporaryDecl>(Record.readDecl());
2240 else
2241 E->State = Record.readSubExpr();
2242 }
2243
VisitCXXFoldExpr(CXXFoldExpr * E)2244 void ASTStmtReader::VisitCXXFoldExpr(CXXFoldExpr *E) {
2245 VisitExpr(E);
2246 E->LParenLoc = readSourceLocation();
2247 E->EllipsisLoc = readSourceLocation();
2248 E->RParenLoc = readSourceLocation();
2249 E->NumExpansions = Record.readInt();
2250 E->SubExprs[0] = Record.readSubExpr();
2251 E->SubExprs[1] = Record.readSubExpr();
2252 E->SubExprs[2] = Record.readSubExpr();
2253 E->Opcode = (BinaryOperatorKind)Record.readInt();
2254 }
2255
VisitCXXParenListInitExpr(CXXParenListInitExpr * E)2256 void ASTStmtReader::VisitCXXParenListInitExpr(CXXParenListInitExpr *E) {
2257 VisitExpr(E);
2258 unsigned ExpectedNumExprs = Record.readInt();
2259 assert(E->NumExprs == ExpectedNumExprs &&
2260 "expected number of expressions does not equal the actual number of "
2261 "serialized expressions.");
2262 E->NumUserSpecifiedExprs = Record.readInt();
2263 E->InitLoc = readSourceLocation();
2264 E->LParenLoc = readSourceLocation();
2265 E->RParenLoc = readSourceLocation();
2266 for (unsigned I = 0; I < ExpectedNumExprs; I++)
2267 E->getTrailingObjects<Expr *>()[I] = Record.readSubExpr();
2268
2269 bool HasArrayFillerOrUnionDecl = Record.readBool();
2270 if (HasArrayFillerOrUnionDecl) {
2271 bool HasArrayFiller = Record.readBool();
2272 if (HasArrayFiller) {
2273 E->setArrayFiller(Record.readSubExpr());
2274 } else {
2275 E->setInitializedFieldInUnion(readDeclAs<FieldDecl>());
2276 }
2277 }
2278 E->updateDependence();
2279 }
2280
VisitOpaqueValueExpr(OpaqueValueExpr * E)2281 void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
2282 VisitExpr(E);
2283 E->SourceExpr = Record.readSubExpr();
2284 E->OpaqueValueExprBits.Loc = readSourceLocation();
2285 E->setIsUnique(Record.readInt());
2286 }
2287
VisitTypoExpr(TypoExpr * E)2288 void ASTStmtReader::VisitTypoExpr(TypoExpr *E) {
2289 llvm_unreachable("Cannot read TypoExpr nodes");
2290 }
2291
VisitRecoveryExpr(RecoveryExpr * E)2292 void ASTStmtReader::VisitRecoveryExpr(RecoveryExpr *E) {
2293 VisitExpr(E);
2294 unsigned NumArgs = Record.readInt();
2295 E->BeginLoc = readSourceLocation();
2296 E->EndLoc = readSourceLocation();
2297 assert((NumArgs + 0LL ==
2298 std::distance(E->children().begin(), E->children().end())) &&
2299 "Wrong NumArgs!");
2300 (void)NumArgs;
2301 for (Stmt *&Child : E->children())
2302 Child = Record.readSubStmt();
2303 }
2304
2305 //===----------------------------------------------------------------------===//
2306 // Microsoft Expressions and Statements
2307 //===----------------------------------------------------------------------===//
VisitMSPropertyRefExpr(MSPropertyRefExpr * E)2308 void ASTStmtReader::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
2309 VisitExpr(E);
2310 E->IsArrow = (Record.readInt() != 0);
2311 E->BaseExpr = Record.readSubExpr();
2312 E->QualifierLoc = Record.readNestedNameSpecifierLoc();
2313 E->MemberLoc = readSourceLocation();
2314 E->TheDecl = readDeclAs<MSPropertyDecl>();
2315 }
2316
VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr * E)2317 void ASTStmtReader::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
2318 VisitExpr(E);
2319 E->setBase(Record.readSubExpr());
2320 E->setIdx(Record.readSubExpr());
2321 E->setRBracketLoc(readSourceLocation());
2322 }
2323
VisitCXXUuidofExpr(CXXUuidofExpr * E)2324 void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
2325 VisitExpr(E);
2326 E->setSourceRange(readSourceRange());
2327 E->Guid = readDeclAs<MSGuidDecl>();
2328 if (E->isTypeOperand())
2329 E->Operand = readTypeSourceInfo();
2330 else
2331 E->Operand = Record.readSubExpr();
2332 }
2333
VisitSEHLeaveStmt(SEHLeaveStmt * S)2334 void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
2335 VisitStmt(S);
2336 S->setLeaveLoc(readSourceLocation());
2337 }
2338
VisitSEHExceptStmt(SEHExceptStmt * S)2339 void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
2340 VisitStmt(S);
2341 S->Loc = readSourceLocation();
2342 S->Children[SEHExceptStmt::FILTER_EXPR] = Record.readSubStmt();
2343 S->Children[SEHExceptStmt::BLOCK] = Record.readSubStmt();
2344 }
2345
VisitSEHFinallyStmt(SEHFinallyStmt * S)2346 void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
2347 VisitStmt(S);
2348 S->Loc = readSourceLocation();
2349 S->Block = Record.readSubStmt();
2350 }
2351
VisitSEHTryStmt(SEHTryStmt * S)2352 void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
2353 VisitStmt(S);
2354 S->IsCXXTry = Record.readInt();
2355 S->TryLoc = readSourceLocation();
2356 S->Children[SEHTryStmt::TRY] = Record.readSubStmt();
2357 S->Children[SEHTryStmt::HANDLER] = Record.readSubStmt();
2358 }
2359
2360 //===----------------------------------------------------------------------===//
2361 // CUDA Expressions and Statements
2362 //===----------------------------------------------------------------------===//
2363
VisitCUDAKernelCallExpr(CUDAKernelCallExpr * E)2364 void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
2365 VisitCallExpr(E);
2366 E->setPreArg(CUDAKernelCallExpr::CONFIG, Record.readSubExpr());
2367 }
2368
2369 //===----------------------------------------------------------------------===//
2370 // OpenCL Expressions and Statements.
2371 //===----------------------------------------------------------------------===//
VisitAsTypeExpr(AsTypeExpr * E)2372 void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
2373 VisitExpr(E);
2374 E->BuiltinLoc = readSourceLocation();
2375 E->RParenLoc = readSourceLocation();
2376 E->SrcExpr = Record.readSubExpr();
2377 }
2378
2379 //===----------------------------------------------------------------------===//
2380 // OpenMP Directives.
2381 //===----------------------------------------------------------------------===//
2382
VisitOMPCanonicalLoop(OMPCanonicalLoop * S)2383 void ASTStmtReader::VisitOMPCanonicalLoop(OMPCanonicalLoop *S) {
2384 VisitStmt(S);
2385 for (Stmt *&SubStmt : S->SubStmts)
2386 SubStmt = Record.readSubStmt();
2387 }
2388
VisitOMPExecutableDirective(OMPExecutableDirective * E)2389 void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2390 Record.readOMPChildren(E->Data);
2391 E->setLocStart(readSourceLocation());
2392 E->setLocEnd(readSourceLocation());
2393 E->setMappedDirective(Record.readEnum<OpenMPDirectiveKind>());
2394 }
2395
VisitOMPLoopBasedDirective(OMPLoopBasedDirective * D)2396 void ASTStmtReader::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {
2397 VisitStmt(D);
2398 // Field CollapsedNum was read in ReadStmtFromStream.
2399 Record.skipInts(1);
2400 VisitOMPExecutableDirective(D);
2401 }
2402
VisitOMPLoopDirective(OMPLoopDirective * D)2403 void ASTStmtReader::VisitOMPLoopDirective(OMPLoopDirective *D) {
2404 VisitOMPLoopBasedDirective(D);
2405 }
2406
VisitOMPMetaDirective(OMPMetaDirective * D)2407 void ASTStmtReader::VisitOMPMetaDirective(OMPMetaDirective *D) {
2408 VisitStmt(D);
2409 // The NumClauses field was read in ReadStmtFromStream.
2410 Record.skipInts(1);
2411 VisitOMPExecutableDirective(D);
2412 }
2413
VisitOMPParallelDirective(OMPParallelDirective * D)2414 void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) {
2415 VisitStmt(D);
2416 VisitOMPExecutableDirective(D);
2417 D->setHasCancel(Record.readBool());
2418 }
2419
VisitOMPSimdDirective(OMPSimdDirective * D)2420 void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) {
2421 VisitOMPLoopDirective(D);
2422 }
2423
VisitOMPLoopTransformationDirective(OMPLoopTransformationDirective * D)2424 void ASTStmtReader::VisitOMPLoopTransformationDirective(
2425 OMPLoopTransformationDirective *D) {
2426 VisitOMPLoopBasedDirective(D);
2427 D->setNumGeneratedLoops(Record.readUInt32());
2428 }
2429
VisitOMPTileDirective(OMPTileDirective * D)2430 void ASTStmtReader::VisitOMPTileDirective(OMPTileDirective *D) {
2431 VisitOMPLoopTransformationDirective(D);
2432 }
2433
VisitOMPUnrollDirective(OMPUnrollDirective * D)2434 void ASTStmtReader::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
2435 VisitOMPLoopTransformationDirective(D);
2436 }
2437
VisitOMPReverseDirective(OMPReverseDirective * D)2438 void ASTStmtReader::VisitOMPReverseDirective(OMPReverseDirective *D) {
2439 VisitOMPLoopTransformationDirective(D);
2440 }
2441
VisitOMPInterchangeDirective(OMPInterchangeDirective * D)2442 void ASTStmtReader::VisitOMPInterchangeDirective(OMPInterchangeDirective *D) {
2443 VisitOMPLoopTransformationDirective(D);
2444 }
2445
VisitOMPForDirective(OMPForDirective * D)2446 void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) {
2447 VisitOMPLoopDirective(D);
2448 D->setHasCancel(Record.readBool());
2449 }
2450
VisitOMPForSimdDirective(OMPForSimdDirective * D)2451 void ASTStmtReader::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2452 VisitOMPLoopDirective(D);
2453 }
2454
VisitOMPSectionsDirective(OMPSectionsDirective * D)2455 void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2456 VisitStmt(D);
2457 VisitOMPExecutableDirective(D);
2458 D->setHasCancel(Record.readBool());
2459 }
2460
VisitOMPSectionDirective(OMPSectionDirective * D)2461 void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) {
2462 VisitStmt(D);
2463 VisitOMPExecutableDirective(D);
2464 D->setHasCancel(Record.readBool());
2465 }
2466
VisitOMPScopeDirective(OMPScopeDirective * D)2467 void ASTStmtReader::VisitOMPScopeDirective(OMPScopeDirective *D) {
2468 VisitStmt(D);
2469 VisitOMPExecutableDirective(D);
2470 }
2471
VisitOMPSingleDirective(OMPSingleDirective * D)2472 void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) {
2473 VisitStmt(D);
2474 VisitOMPExecutableDirective(D);
2475 }
2476
VisitOMPMasterDirective(OMPMasterDirective * D)2477 void ASTStmtReader::VisitOMPMasterDirective(OMPMasterDirective *D) {
2478 VisitStmt(D);
2479 VisitOMPExecutableDirective(D);
2480 }
2481
VisitOMPCriticalDirective(OMPCriticalDirective * D)2482 void ASTStmtReader::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2483 VisitStmt(D);
2484 VisitOMPExecutableDirective(D);
2485 D->DirName = Record.readDeclarationNameInfo();
2486 }
2487
VisitOMPParallelForDirective(OMPParallelForDirective * D)2488 void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2489 VisitOMPLoopDirective(D);
2490 D->setHasCancel(Record.readBool());
2491 }
2492
VisitOMPParallelForSimdDirective(OMPParallelForSimdDirective * D)2493 void ASTStmtReader::VisitOMPParallelForSimdDirective(
2494 OMPParallelForSimdDirective *D) {
2495 VisitOMPLoopDirective(D);
2496 }
2497
VisitOMPParallelMasterDirective(OMPParallelMasterDirective * D)2498 void ASTStmtReader::VisitOMPParallelMasterDirective(
2499 OMPParallelMasterDirective *D) {
2500 VisitStmt(D);
2501 VisitOMPExecutableDirective(D);
2502 }
2503
VisitOMPParallelMaskedDirective(OMPParallelMaskedDirective * D)2504 void ASTStmtReader::VisitOMPParallelMaskedDirective(
2505 OMPParallelMaskedDirective *D) {
2506 VisitStmt(D);
2507 VisitOMPExecutableDirective(D);
2508 }
2509
VisitOMPParallelSectionsDirective(OMPParallelSectionsDirective * D)2510 void ASTStmtReader::VisitOMPParallelSectionsDirective(
2511 OMPParallelSectionsDirective *D) {
2512 VisitStmt(D);
2513 VisitOMPExecutableDirective(D);
2514 D->setHasCancel(Record.readBool());
2515 }
2516
VisitOMPTaskDirective(OMPTaskDirective * D)2517 void ASTStmtReader::VisitOMPTaskDirective(OMPTaskDirective *D) {
2518 VisitStmt(D);
2519 VisitOMPExecutableDirective(D);
2520 D->setHasCancel(Record.readBool());
2521 }
2522
VisitOMPTaskyieldDirective(OMPTaskyieldDirective * D)2523 void ASTStmtReader::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2524 VisitStmt(D);
2525 VisitOMPExecutableDirective(D);
2526 }
2527
VisitOMPBarrierDirective(OMPBarrierDirective * D)2528 void ASTStmtReader::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2529 VisitStmt(D);
2530 VisitOMPExecutableDirective(D);
2531 }
2532
VisitOMPTaskwaitDirective(OMPTaskwaitDirective * D)2533 void ASTStmtReader::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2534 VisitStmt(D);
2535 // The NumClauses field was read in ReadStmtFromStream.
2536 Record.skipInts(1);
2537 VisitOMPExecutableDirective(D);
2538 }
2539
VisitOMPErrorDirective(OMPErrorDirective * D)2540 void ASTStmtReader::VisitOMPErrorDirective(OMPErrorDirective *D) {
2541 VisitStmt(D);
2542 // The NumClauses field was read in ReadStmtFromStream.
2543 Record.skipInts(1);
2544 VisitOMPExecutableDirective(D);
2545 }
2546
VisitOMPTaskgroupDirective(OMPTaskgroupDirective * D)2547 void ASTStmtReader::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2548 VisitStmt(D);
2549 VisitOMPExecutableDirective(D);
2550 }
2551
VisitOMPFlushDirective(OMPFlushDirective * D)2552 void ASTStmtReader::VisitOMPFlushDirective(OMPFlushDirective *D) {
2553 VisitStmt(D);
2554 VisitOMPExecutableDirective(D);
2555 }
2556
VisitOMPDepobjDirective(OMPDepobjDirective * D)2557 void ASTStmtReader::VisitOMPDepobjDirective(OMPDepobjDirective *D) {
2558 VisitStmt(D);
2559 VisitOMPExecutableDirective(D);
2560 }
2561
VisitOMPScanDirective(OMPScanDirective * D)2562 void ASTStmtReader::VisitOMPScanDirective(OMPScanDirective *D) {
2563 VisitStmt(D);
2564 VisitOMPExecutableDirective(D);
2565 }
2566
VisitOMPOrderedDirective(OMPOrderedDirective * D)2567 void ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2568 VisitStmt(D);
2569 VisitOMPExecutableDirective(D);
2570 }
2571
VisitOMPAtomicDirective(OMPAtomicDirective * D)2572 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2573 VisitStmt(D);
2574 VisitOMPExecutableDirective(D);
2575 D->Flags.IsXLHSInRHSPart = Record.readBool() ? 1 : 0;
2576 D->Flags.IsPostfixUpdate = Record.readBool() ? 1 : 0;
2577 D->Flags.IsFailOnly = Record.readBool() ? 1 : 0;
2578 }
2579
VisitOMPTargetDirective(OMPTargetDirective * D)2580 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
2581 VisitStmt(D);
2582 VisitOMPExecutableDirective(D);
2583 }
2584
VisitOMPTargetDataDirective(OMPTargetDataDirective * D)2585 void ASTStmtReader::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2586 VisitStmt(D);
2587 VisitOMPExecutableDirective(D);
2588 }
2589
VisitOMPTargetEnterDataDirective(OMPTargetEnterDataDirective * D)2590 void ASTStmtReader::VisitOMPTargetEnterDataDirective(
2591 OMPTargetEnterDataDirective *D) {
2592 VisitStmt(D);
2593 VisitOMPExecutableDirective(D);
2594 }
2595
VisitOMPTargetExitDataDirective(OMPTargetExitDataDirective * D)2596 void ASTStmtReader::VisitOMPTargetExitDataDirective(
2597 OMPTargetExitDataDirective *D) {
2598 VisitStmt(D);
2599 VisitOMPExecutableDirective(D);
2600 }
2601
VisitOMPTargetParallelDirective(OMPTargetParallelDirective * D)2602 void ASTStmtReader::VisitOMPTargetParallelDirective(
2603 OMPTargetParallelDirective *D) {
2604 VisitStmt(D);
2605 VisitOMPExecutableDirective(D);
2606 D->setHasCancel(Record.readBool());
2607 }
2608
VisitOMPTargetParallelForDirective(OMPTargetParallelForDirective * D)2609 void ASTStmtReader::VisitOMPTargetParallelForDirective(
2610 OMPTargetParallelForDirective *D) {
2611 VisitOMPLoopDirective(D);
2612 D->setHasCancel(Record.readBool());
2613 }
2614
VisitOMPTeamsDirective(OMPTeamsDirective * D)2615 void ASTStmtReader::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2616 VisitStmt(D);
2617 VisitOMPExecutableDirective(D);
2618 }
2619
VisitOMPCancellationPointDirective(OMPCancellationPointDirective * D)2620 void ASTStmtReader::VisitOMPCancellationPointDirective(
2621 OMPCancellationPointDirective *D) {
2622 VisitStmt(D);
2623 VisitOMPExecutableDirective(D);
2624 D->setCancelRegion(Record.readEnum<OpenMPDirectiveKind>());
2625 }
2626
VisitOMPCancelDirective(OMPCancelDirective * D)2627 void ASTStmtReader::VisitOMPCancelDirective(OMPCancelDirective *D) {
2628 VisitStmt(D);
2629 VisitOMPExecutableDirective(D);
2630 D->setCancelRegion(Record.readEnum<OpenMPDirectiveKind>());
2631 }
2632
VisitOMPTaskLoopDirective(OMPTaskLoopDirective * D)2633 void ASTStmtReader::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2634 VisitOMPLoopDirective(D);
2635 D->setHasCancel(Record.readBool());
2636 }
2637
VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective * D)2638 void ASTStmtReader::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2639 VisitOMPLoopDirective(D);
2640 }
2641
VisitOMPMasterTaskLoopDirective(OMPMasterTaskLoopDirective * D)2642 void ASTStmtReader::VisitOMPMasterTaskLoopDirective(
2643 OMPMasterTaskLoopDirective *D) {
2644 VisitOMPLoopDirective(D);
2645 D->setHasCancel(Record.readBool());
2646 }
2647
VisitOMPMaskedTaskLoopDirective(OMPMaskedTaskLoopDirective * D)2648 void ASTStmtReader::VisitOMPMaskedTaskLoopDirective(
2649 OMPMaskedTaskLoopDirective *D) {
2650 VisitOMPLoopDirective(D);
2651 D->setHasCancel(Record.readBool());
2652 }
2653
VisitOMPMasterTaskLoopSimdDirective(OMPMasterTaskLoopSimdDirective * D)2654 void ASTStmtReader::VisitOMPMasterTaskLoopSimdDirective(
2655 OMPMasterTaskLoopSimdDirective *D) {
2656 VisitOMPLoopDirective(D);
2657 }
2658
VisitOMPMaskedTaskLoopSimdDirective(OMPMaskedTaskLoopSimdDirective * D)2659 void ASTStmtReader::VisitOMPMaskedTaskLoopSimdDirective(
2660 OMPMaskedTaskLoopSimdDirective *D) {
2661 VisitOMPLoopDirective(D);
2662 }
2663
VisitOMPParallelMasterTaskLoopDirective(OMPParallelMasterTaskLoopDirective * D)2664 void ASTStmtReader::VisitOMPParallelMasterTaskLoopDirective(
2665 OMPParallelMasterTaskLoopDirective *D) {
2666 VisitOMPLoopDirective(D);
2667 D->setHasCancel(Record.readBool());
2668 }
2669
VisitOMPParallelMaskedTaskLoopDirective(OMPParallelMaskedTaskLoopDirective * D)2670 void ASTStmtReader::VisitOMPParallelMaskedTaskLoopDirective(
2671 OMPParallelMaskedTaskLoopDirective *D) {
2672 VisitOMPLoopDirective(D);
2673 D->setHasCancel(Record.readBool());
2674 }
2675
VisitOMPParallelMasterTaskLoopSimdDirective(OMPParallelMasterTaskLoopSimdDirective * D)2676 void ASTStmtReader::VisitOMPParallelMasterTaskLoopSimdDirective(
2677 OMPParallelMasterTaskLoopSimdDirective *D) {
2678 VisitOMPLoopDirective(D);
2679 }
2680
VisitOMPParallelMaskedTaskLoopSimdDirective(OMPParallelMaskedTaskLoopSimdDirective * D)2681 void ASTStmtReader::VisitOMPParallelMaskedTaskLoopSimdDirective(
2682 OMPParallelMaskedTaskLoopSimdDirective *D) {
2683 VisitOMPLoopDirective(D);
2684 }
2685
VisitOMPDistributeDirective(OMPDistributeDirective * D)2686 void ASTStmtReader::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2687 VisitOMPLoopDirective(D);
2688 }
2689
VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective * D)2690 void ASTStmtReader::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2691 VisitStmt(D);
2692 VisitOMPExecutableDirective(D);
2693 }
2694
VisitOMPDistributeParallelForDirective(OMPDistributeParallelForDirective * D)2695 void ASTStmtReader::VisitOMPDistributeParallelForDirective(
2696 OMPDistributeParallelForDirective *D) {
2697 VisitOMPLoopDirective(D);
2698 D->setHasCancel(Record.readBool());
2699 }
2700
VisitOMPDistributeParallelForSimdDirective(OMPDistributeParallelForSimdDirective * D)2701 void ASTStmtReader::VisitOMPDistributeParallelForSimdDirective(
2702 OMPDistributeParallelForSimdDirective *D) {
2703 VisitOMPLoopDirective(D);
2704 }
2705
VisitOMPDistributeSimdDirective(OMPDistributeSimdDirective * D)2706 void ASTStmtReader::VisitOMPDistributeSimdDirective(
2707 OMPDistributeSimdDirective *D) {
2708 VisitOMPLoopDirective(D);
2709 }
2710
VisitOMPTargetParallelForSimdDirective(OMPTargetParallelForSimdDirective * D)2711 void ASTStmtReader::VisitOMPTargetParallelForSimdDirective(
2712 OMPTargetParallelForSimdDirective *D) {
2713 VisitOMPLoopDirective(D);
2714 }
2715
VisitOMPTargetSimdDirective(OMPTargetSimdDirective * D)2716 void ASTStmtReader::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2717 VisitOMPLoopDirective(D);
2718 }
2719
VisitOMPTeamsDistributeDirective(OMPTeamsDistributeDirective * D)2720 void ASTStmtReader::VisitOMPTeamsDistributeDirective(
2721 OMPTeamsDistributeDirective *D) {
2722 VisitOMPLoopDirective(D);
2723 }
2724
VisitOMPTeamsDistributeSimdDirective(OMPTeamsDistributeSimdDirective * D)2725 void ASTStmtReader::VisitOMPTeamsDistributeSimdDirective(
2726 OMPTeamsDistributeSimdDirective *D) {
2727 VisitOMPLoopDirective(D);
2728 }
2729
VisitOMPTeamsDistributeParallelForSimdDirective(OMPTeamsDistributeParallelForSimdDirective * D)2730 void ASTStmtReader::VisitOMPTeamsDistributeParallelForSimdDirective(
2731 OMPTeamsDistributeParallelForSimdDirective *D) {
2732 VisitOMPLoopDirective(D);
2733 }
2734
VisitOMPTeamsDistributeParallelForDirective(OMPTeamsDistributeParallelForDirective * D)2735 void ASTStmtReader::VisitOMPTeamsDistributeParallelForDirective(
2736 OMPTeamsDistributeParallelForDirective *D) {
2737 VisitOMPLoopDirective(D);
2738 D->setHasCancel(Record.readBool());
2739 }
2740
VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective * D)2741 void ASTStmtReader::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2742 VisitStmt(D);
2743 VisitOMPExecutableDirective(D);
2744 }
2745
VisitOMPTargetTeamsDistributeDirective(OMPTargetTeamsDistributeDirective * D)2746 void ASTStmtReader::VisitOMPTargetTeamsDistributeDirective(
2747 OMPTargetTeamsDistributeDirective *D) {
2748 VisitOMPLoopDirective(D);
2749 }
2750
VisitOMPTargetTeamsDistributeParallelForDirective(OMPTargetTeamsDistributeParallelForDirective * D)2751 void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForDirective(
2752 OMPTargetTeamsDistributeParallelForDirective *D) {
2753 VisitOMPLoopDirective(D);
2754 D->setHasCancel(Record.readBool());
2755 }
2756
VisitOMPTargetTeamsDistributeParallelForSimdDirective(OMPTargetTeamsDistributeParallelForSimdDirective * D)2757 void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2758 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2759 VisitOMPLoopDirective(D);
2760 }
2761
VisitOMPTargetTeamsDistributeSimdDirective(OMPTargetTeamsDistributeSimdDirective * D)2762 void ASTStmtReader::VisitOMPTargetTeamsDistributeSimdDirective(
2763 OMPTargetTeamsDistributeSimdDirective *D) {
2764 VisitOMPLoopDirective(D);
2765 }
2766
VisitOMPInteropDirective(OMPInteropDirective * D)2767 void ASTStmtReader::VisitOMPInteropDirective(OMPInteropDirective *D) {
2768 VisitStmt(D);
2769 VisitOMPExecutableDirective(D);
2770 }
2771
VisitOMPDispatchDirective(OMPDispatchDirective * D)2772 void ASTStmtReader::VisitOMPDispatchDirective(OMPDispatchDirective *D) {
2773 VisitStmt(D);
2774 VisitOMPExecutableDirective(D);
2775 D->setTargetCallLoc(Record.readSourceLocation());
2776 }
2777
VisitOMPMaskedDirective(OMPMaskedDirective * D)2778 void ASTStmtReader::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
2779 VisitStmt(D);
2780 VisitOMPExecutableDirective(D);
2781 }
2782
VisitOMPGenericLoopDirective(OMPGenericLoopDirective * D)2783 void ASTStmtReader::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
2784 VisitOMPLoopDirective(D);
2785 }
2786
VisitOMPTeamsGenericLoopDirective(OMPTeamsGenericLoopDirective * D)2787 void ASTStmtReader::VisitOMPTeamsGenericLoopDirective(
2788 OMPTeamsGenericLoopDirective *D) {
2789 VisitOMPLoopDirective(D);
2790 }
2791
VisitOMPTargetTeamsGenericLoopDirective(OMPTargetTeamsGenericLoopDirective * D)2792 void ASTStmtReader::VisitOMPTargetTeamsGenericLoopDirective(
2793 OMPTargetTeamsGenericLoopDirective *D) {
2794 VisitOMPLoopDirective(D);
2795 D->setCanBeParallelFor(Record.readBool());
2796 }
2797
VisitOMPParallelGenericLoopDirective(OMPParallelGenericLoopDirective * D)2798 void ASTStmtReader::VisitOMPParallelGenericLoopDirective(
2799 OMPParallelGenericLoopDirective *D) {
2800 VisitOMPLoopDirective(D);
2801 }
2802
VisitOMPTargetParallelGenericLoopDirective(OMPTargetParallelGenericLoopDirective * D)2803 void ASTStmtReader::VisitOMPTargetParallelGenericLoopDirective(
2804 OMPTargetParallelGenericLoopDirective *D) {
2805 VisitOMPLoopDirective(D);
2806 }
2807
2808 //===----------------------------------------------------------------------===//
2809 // OpenACC Constructs/Directives.
2810 //===----------------------------------------------------------------------===//
VisitOpenACCConstructStmt(OpenACCConstructStmt * S)2811 void ASTStmtReader::VisitOpenACCConstructStmt(OpenACCConstructStmt *S) {
2812 (void)Record.readInt();
2813 S->Kind = Record.readEnum<OpenACCDirectiveKind>();
2814 S->Range = Record.readSourceRange();
2815 S->DirectiveLoc = Record.readSourceLocation();
2816 Record.readOpenACCClauseList(S->Clauses);
2817 }
2818
VisitOpenACCAssociatedStmtConstruct(OpenACCAssociatedStmtConstruct * S)2819 void ASTStmtReader::VisitOpenACCAssociatedStmtConstruct(
2820 OpenACCAssociatedStmtConstruct *S) {
2821 VisitOpenACCConstructStmt(S);
2822 S->setAssociatedStmt(Record.readSubStmt());
2823 }
2824
VisitOpenACCComputeConstruct(OpenACCComputeConstruct * S)2825 void ASTStmtReader::VisitOpenACCComputeConstruct(OpenACCComputeConstruct *S) {
2826 VisitStmt(S);
2827 VisitOpenACCAssociatedStmtConstruct(S);
2828 S->findAndSetChildLoops();
2829 }
2830
VisitOpenACCLoopConstruct(OpenACCLoopConstruct * S)2831 void ASTStmtReader::VisitOpenACCLoopConstruct(OpenACCLoopConstruct *S) {
2832 VisitStmt(S);
2833 VisitOpenACCAssociatedStmtConstruct(S);
2834 }
2835
2836 //===----------------------------------------------------------------------===//
2837 // ASTReader Implementation
2838 //===----------------------------------------------------------------------===//
2839
ReadStmt(ModuleFile & F)2840 Stmt *ASTReader::ReadStmt(ModuleFile &F) {
2841 switch (ReadingKind) {
2842 case Read_None:
2843 llvm_unreachable("should not call this when not reading anything");
2844 case Read_Decl:
2845 case Read_Type:
2846 return ReadStmtFromStream(F);
2847 case Read_Stmt:
2848 return ReadSubStmt();
2849 }
2850
2851 llvm_unreachable("ReadingKind not set ?");
2852 }
2853
ReadExpr(ModuleFile & F)2854 Expr *ASTReader::ReadExpr(ModuleFile &F) {
2855 return cast_or_null<Expr>(ReadStmt(F));
2856 }
2857
ReadSubExpr()2858 Expr *ASTReader::ReadSubExpr() {
2859 return cast_or_null<Expr>(ReadSubStmt());
2860 }
2861
2862 // Within the bitstream, expressions are stored in Reverse Polish
2863 // Notation, with each of the subexpressions preceding the
2864 // expression they are stored in. Subexpressions are stored from last to first.
2865 // To evaluate expressions, we continue reading expressions and placing them on
2866 // the stack, with expressions having operands removing those operands from the
2867 // stack. Evaluation terminates when we see a STMT_STOP record, and
2868 // the single remaining expression on the stack is our result.
ReadStmtFromStream(ModuleFile & F)2869 Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
2870 ReadingKindTracker ReadingKind(Read_Stmt, *this);
2871 llvm::BitstreamCursor &Cursor = F.DeclsCursor;
2872
2873 // Map of offset to previously deserialized stmt. The offset points
2874 // just after the stmt record.
2875 llvm::DenseMap<uint64_t, Stmt *> StmtEntries;
2876
2877 #ifndef NDEBUG
2878 unsigned PrevNumStmts = StmtStack.size();
2879 #endif
2880
2881 ASTRecordReader Record(*this, F);
2882 ASTStmtReader Reader(Record, Cursor);
2883 Stmt::EmptyShell Empty;
2884
2885 while (true) {
2886 llvm::Expected<llvm::BitstreamEntry> MaybeEntry =
2887 Cursor.advanceSkippingSubblocks();
2888 if (!MaybeEntry) {
2889 Error(toString(MaybeEntry.takeError()));
2890 return nullptr;
2891 }
2892 llvm::BitstreamEntry Entry = MaybeEntry.get();
2893
2894 switch (Entry.Kind) {
2895 case llvm::BitstreamEntry::SubBlock: // Handled for us already.
2896 case llvm::BitstreamEntry::Error:
2897 Error("malformed block record in AST file");
2898 return nullptr;
2899 case llvm::BitstreamEntry::EndBlock:
2900 goto Done;
2901 case llvm::BitstreamEntry::Record:
2902 // The interesting case.
2903 break;
2904 }
2905
2906 ASTContext &Context = getContext();
2907 Stmt *S = nullptr;
2908 bool Finished = false;
2909 bool IsStmtReference = false;
2910 Expected<unsigned> MaybeStmtCode = Record.readRecord(Cursor, Entry.ID);
2911 if (!MaybeStmtCode) {
2912 Error(toString(MaybeStmtCode.takeError()));
2913 return nullptr;
2914 }
2915 switch ((StmtCode)MaybeStmtCode.get()) {
2916 case STMT_STOP:
2917 Finished = true;
2918 break;
2919
2920 case STMT_REF_PTR:
2921 IsStmtReference = true;
2922 assert(StmtEntries.contains(Record[0]) &&
2923 "No stmt was recorded for this offset reference!");
2924 S = StmtEntries[Record.readInt()];
2925 break;
2926
2927 case STMT_NULL_PTR:
2928 S = nullptr;
2929 break;
2930
2931 case STMT_NULL:
2932 S = new (Context) NullStmt(Empty);
2933 break;
2934
2935 case STMT_COMPOUND: {
2936 unsigned NumStmts = Record[ASTStmtReader::NumStmtFields];
2937 bool HasFPFeatures = Record[ASTStmtReader::NumStmtFields + 1];
2938 S = CompoundStmt::CreateEmpty(Context, NumStmts, HasFPFeatures);
2939 break;
2940 }
2941
2942 case STMT_CASE:
2943 S = CaseStmt::CreateEmpty(
2944 Context,
2945 /*CaseStmtIsGNURange*/ Record[ASTStmtReader::NumStmtFields + 3]);
2946 break;
2947
2948 case STMT_DEFAULT:
2949 S = new (Context) DefaultStmt(Empty);
2950 break;
2951
2952 case STMT_LABEL:
2953 S = new (Context) LabelStmt(Empty);
2954 break;
2955
2956 case STMT_ATTRIBUTED:
2957 S = AttributedStmt::CreateEmpty(
2958 Context,
2959 /*NumAttrs*/Record[ASTStmtReader::NumStmtFields]);
2960 break;
2961
2962 case STMT_IF: {
2963 BitsUnpacker IfStmtBits(Record[ASTStmtReader::NumStmtFields]);
2964 bool HasElse = IfStmtBits.getNextBit();
2965 bool HasVar = IfStmtBits.getNextBit();
2966 bool HasInit = IfStmtBits.getNextBit();
2967 S = IfStmt::CreateEmpty(Context, HasElse, HasVar, HasInit);
2968 break;
2969 }
2970
2971 case STMT_SWITCH:
2972 S = SwitchStmt::CreateEmpty(
2973 Context,
2974 /* HasInit=*/Record[ASTStmtReader::NumStmtFields],
2975 /* HasVar=*/Record[ASTStmtReader::NumStmtFields + 1]);
2976 break;
2977
2978 case STMT_WHILE:
2979 S = WhileStmt::CreateEmpty(
2980 Context,
2981 /* HasVar=*/Record[ASTStmtReader::NumStmtFields]);
2982 break;
2983
2984 case STMT_DO:
2985 S = new (Context) DoStmt(Empty);
2986 break;
2987
2988 case STMT_FOR:
2989 S = new (Context) ForStmt(Empty);
2990 break;
2991
2992 case STMT_GOTO:
2993 S = new (Context) GotoStmt(Empty);
2994 break;
2995
2996 case STMT_INDIRECT_GOTO:
2997 S = new (Context) IndirectGotoStmt(Empty);
2998 break;
2999
3000 case STMT_CONTINUE:
3001 S = new (Context) ContinueStmt(Empty);
3002 break;
3003
3004 case STMT_BREAK:
3005 S = new (Context) BreakStmt(Empty);
3006 break;
3007
3008 case STMT_RETURN:
3009 S = ReturnStmt::CreateEmpty(
3010 Context, /* HasNRVOCandidate=*/Record[ASTStmtReader::NumStmtFields]);
3011 break;
3012
3013 case STMT_DECL:
3014 S = new (Context) DeclStmt(Empty);
3015 break;
3016
3017 case STMT_GCCASM:
3018 S = new (Context) GCCAsmStmt(Empty);
3019 break;
3020
3021 case STMT_MSASM:
3022 S = new (Context) MSAsmStmt(Empty);
3023 break;
3024
3025 case STMT_CAPTURED:
3026 S = CapturedStmt::CreateDeserialized(
3027 Context, Record[ASTStmtReader::NumStmtFields]);
3028 break;
3029
3030 case EXPR_CONSTANT:
3031 S = ConstantExpr::CreateEmpty(
3032 Context, static_cast<ConstantResultStorageKind>(
3033 /*StorageKind=*/Record[ASTStmtReader::NumExprFields]));
3034 break;
3035
3036 case EXPR_SYCL_UNIQUE_STABLE_NAME:
3037 S = SYCLUniqueStableNameExpr::CreateEmpty(Context);
3038 break;
3039
3040 case EXPR_PREDEFINED:
3041 S = PredefinedExpr::CreateEmpty(
3042 Context,
3043 /*HasFunctionName*/ Record[ASTStmtReader::NumExprFields]);
3044 break;
3045
3046 case EXPR_DECL_REF: {
3047 BitsUnpacker DeclRefExprBits(Record[ASTStmtReader::NumExprFields]);
3048 DeclRefExprBits.advance(5);
3049 bool HasFoundDecl = DeclRefExprBits.getNextBit();
3050 bool HasQualifier = DeclRefExprBits.getNextBit();
3051 bool HasTemplateKWAndArgsInfo = DeclRefExprBits.getNextBit();
3052 unsigned NumTemplateArgs = HasTemplateKWAndArgsInfo
3053 ? Record[ASTStmtReader::NumExprFields + 1]
3054 : 0;
3055 S = DeclRefExpr::CreateEmpty(Context, HasQualifier, HasFoundDecl,
3056 HasTemplateKWAndArgsInfo, NumTemplateArgs);
3057 break;
3058 }
3059
3060 case EXPR_INTEGER_LITERAL:
3061 S = IntegerLiteral::Create(Context, Empty);
3062 break;
3063
3064 case EXPR_FIXEDPOINT_LITERAL:
3065 S = FixedPointLiteral::Create(Context, Empty);
3066 break;
3067
3068 case EXPR_FLOATING_LITERAL:
3069 S = FloatingLiteral::Create(Context, Empty);
3070 break;
3071
3072 case EXPR_IMAGINARY_LITERAL:
3073 S = new (Context) ImaginaryLiteral(Empty);
3074 break;
3075
3076 case EXPR_STRING_LITERAL:
3077 S = StringLiteral::CreateEmpty(
3078 Context,
3079 /* NumConcatenated=*/Record[ASTStmtReader::NumExprFields],
3080 /* Length=*/Record[ASTStmtReader::NumExprFields + 1],
3081 /* CharByteWidth=*/Record[ASTStmtReader::NumExprFields + 2]);
3082 break;
3083
3084 case EXPR_CHARACTER_LITERAL:
3085 S = new (Context) CharacterLiteral(Empty);
3086 break;
3087
3088 case EXPR_PAREN:
3089 S = new (Context) ParenExpr(Empty);
3090 break;
3091
3092 case EXPR_PAREN_LIST:
3093 S = ParenListExpr::CreateEmpty(
3094 Context,
3095 /* NumExprs=*/Record[ASTStmtReader::NumExprFields]);
3096 break;
3097
3098 case EXPR_UNARY_OPERATOR: {
3099 BitsUnpacker UnaryOperatorBits(Record[ASTStmtReader::NumStmtFields]);
3100 UnaryOperatorBits.advance(ASTStmtReader::NumExprBits);
3101 bool HasFPFeatures = UnaryOperatorBits.getNextBit();
3102 S = UnaryOperator::CreateEmpty(Context, HasFPFeatures);
3103 break;
3104 }
3105
3106 case EXPR_OFFSETOF:
3107 S = OffsetOfExpr::CreateEmpty(Context,
3108 Record[ASTStmtReader::NumExprFields],
3109 Record[ASTStmtReader::NumExprFields + 1]);
3110 break;
3111
3112 case EXPR_SIZEOF_ALIGN_OF:
3113 S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
3114 break;
3115
3116 case EXPR_ARRAY_SUBSCRIPT:
3117 S = new (Context) ArraySubscriptExpr(Empty);
3118 break;
3119
3120 case EXPR_MATRIX_SUBSCRIPT:
3121 S = new (Context) MatrixSubscriptExpr(Empty);
3122 break;
3123
3124 case EXPR_ARRAY_SECTION:
3125 S = new (Context) ArraySectionExpr(Empty);
3126 break;
3127
3128 case EXPR_OMP_ARRAY_SHAPING:
3129 S = OMPArrayShapingExpr::CreateEmpty(
3130 Context, Record[ASTStmtReader::NumExprFields]);
3131 break;
3132
3133 case EXPR_OMP_ITERATOR:
3134 S = OMPIteratorExpr::CreateEmpty(Context,
3135 Record[ASTStmtReader::NumExprFields]);
3136 break;
3137
3138 case EXPR_CALL: {
3139 auto NumArgs = Record[ASTStmtReader::NumExprFields];
3140 BitsUnpacker CallExprBits(Record[ASTStmtReader::NumExprFields + 1]);
3141 CallExprBits.advance(1);
3142 auto HasFPFeatures = CallExprBits.getNextBit();
3143 S = CallExpr::CreateEmpty(Context, NumArgs, HasFPFeatures, Empty);
3144 break;
3145 }
3146
3147 case EXPR_RECOVERY:
3148 S = RecoveryExpr::CreateEmpty(
3149 Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
3150 break;
3151
3152 case EXPR_MEMBER: {
3153 BitsUnpacker ExprMemberBits(Record[ASTStmtReader::NumExprFields]);
3154 bool HasQualifier = ExprMemberBits.getNextBit();
3155 bool HasFoundDecl = ExprMemberBits.getNextBit();
3156 bool HasTemplateInfo = ExprMemberBits.getNextBit();
3157 unsigned NumTemplateArgs = Record[ASTStmtReader::NumExprFields + 1];
3158 S = MemberExpr::CreateEmpty(Context, HasQualifier, HasFoundDecl,
3159 HasTemplateInfo, NumTemplateArgs);
3160 break;
3161 }
3162
3163 case EXPR_BINARY_OPERATOR: {
3164 BitsUnpacker BinaryOperatorBits(Record[ASTStmtReader::NumExprFields]);
3165 BinaryOperatorBits.advance(/*Size of opcode*/ 6);
3166 bool HasFPFeatures = BinaryOperatorBits.getNextBit();
3167 S = BinaryOperator::CreateEmpty(Context, HasFPFeatures);
3168 break;
3169 }
3170
3171 case EXPR_COMPOUND_ASSIGN_OPERATOR: {
3172 BitsUnpacker BinaryOperatorBits(Record[ASTStmtReader::NumExprFields]);
3173 BinaryOperatorBits.advance(/*Size of opcode*/ 6);
3174 bool HasFPFeatures = BinaryOperatorBits.getNextBit();
3175 S = CompoundAssignOperator::CreateEmpty(Context, HasFPFeatures);
3176 break;
3177 }
3178
3179 case EXPR_CONDITIONAL_OPERATOR:
3180 S = new (Context) ConditionalOperator(Empty);
3181 break;
3182
3183 case EXPR_BINARY_CONDITIONAL_OPERATOR:
3184 S = new (Context) BinaryConditionalOperator(Empty);
3185 break;
3186
3187 case EXPR_IMPLICIT_CAST: {
3188 unsigned PathSize = Record[ASTStmtReader::NumExprFields];
3189 BitsUnpacker CastExprBits(Record[ASTStmtReader::NumExprFields + 1]);
3190 CastExprBits.advance(7);
3191 bool HasFPFeatures = CastExprBits.getNextBit();
3192 S = ImplicitCastExpr::CreateEmpty(Context, PathSize, HasFPFeatures);
3193 break;
3194 }
3195
3196 case EXPR_CSTYLE_CAST: {
3197 unsigned PathSize = Record[ASTStmtReader::NumExprFields];
3198 BitsUnpacker CastExprBits(Record[ASTStmtReader::NumExprFields + 1]);
3199 CastExprBits.advance(7);
3200 bool HasFPFeatures = CastExprBits.getNextBit();
3201 S = CStyleCastExpr::CreateEmpty(Context, PathSize, HasFPFeatures);
3202 break;
3203 }
3204
3205 case EXPR_COMPOUND_LITERAL:
3206 S = new (Context) CompoundLiteralExpr(Empty);
3207 break;
3208
3209 case EXPR_EXT_VECTOR_ELEMENT:
3210 S = new (Context) ExtVectorElementExpr(Empty);
3211 break;
3212
3213 case EXPR_INIT_LIST:
3214 S = new (Context) InitListExpr(Empty);
3215 break;
3216
3217 case EXPR_DESIGNATED_INIT:
3218 S = DesignatedInitExpr::CreateEmpty(Context,
3219 Record[ASTStmtReader::NumExprFields] - 1);
3220
3221 break;
3222
3223 case EXPR_DESIGNATED_INIT_UPDATE:
3224 S = new (Context) DesignatedInitUpdateExpr(Empty);
3225 break;
3226
3227 case EXPR_IMPLICIT_VALUE_INIT:
3228 S = new (Context) ImplicitValueInitExpr(Empty);
3229 break;
3230
3231 case EXPR_NO_INIT:
3232 S = new (Context) NoInitExpr(Empty);
3233 break;
3234
3235 case EXPR_ARRAY_INIT_LOOP:
3236 S = new (Context) ArrayInitLoopExpr(Empty);
3237 break;
3238
3239 case EXPR_ARRAY_INIT_INDEX:
3240 S = new (Context) ArrayInitIndexExpr(Empty);
3241 break;
3242
3243 case EXPR_VA_ARG:
3244 S = new (Context) VAArgExpr(Empty);
3245 break;
3246
3247 case EXPR_SOURCE_LOC:
3248 S = new (Context) SourceLocExpr(Empty);
3249 break;
3250
3251 case EXPR_BUILTIN_PP_EMBED:
3252 S = new (Context) EmbedExpr(Empty);
3253 break;
3254
3255 case EXPR_ADDR_LABEL:
3256 S = new (Context) AddrLabelExpr(Empty);
3257 break;
3258
3259 case EXPR_STMT:
3260 S = new (Context) StmtExpr(Empty);
3261 break;
3262
3263 case EXPR_CHOOSE:
3264 S = new (Context) ChooseExpr(Empty);
3265 break;
3266
3267 case EXPR_GNU_NULL:
3268 S = new (Context) GNUNullExpr(Empty);
3269 break;
3270
3271 case EXPR_SHUFFLE_VECTOR:
3272 S = new (Context) ShuffleVectorExpr(Empty);
3273 break;
3274
3275 case EXPR_CONVERT_VECTOR:
3276 S = new (Context) ConvertVectorExpr(Empty);
3277 break;
3278
3279 case EXPR_BLOCK:
3280 S = new (Context) BlockExpr(Empty);
3281 break;
3282
3283 case EXPR_GENERIC_SELECTION:
3284 S = GenericSelectionExpr::CreateEmpty(
3285 Context,
3286 /*NumAssocs=*/Record[ASTStmtReader::NumExprFields]);
3287 break;
3288
3289 case EXPR_OBJC_STRING_LITERAL:
3290 S = new (Context) ObjCStringLiteral(Empty);
3291 break;
3292
3293 case EXPR_OBJC_BOXED_EXPRESSION:
3294 S = new (Context) ObjCBoxedExpr(Empty);
3295 break;
3296
3297 case EXPR_OBJC_ARRAY_LITERAL:
3298 S = ObjCArrayLiteral::CreateEmpty(Context,
3299 Record[ASTStmtReader::NumExprFields]);
3300 break;
3301
3302 case EXPR_OBJC_DICTIONARY_LITERAL:
3303 S = ObjCDictionaryLiteral::CreateEmpty(Context,
3304 Record[ASTStmtReader::NumExprFields],
3305 Record[ASTStmtReader::NumExprFields + 1]);
3306 break;
3307
3308 case EXPR_OBJC_ENCODE:
3309 S = new (Context) ObjCEncodeExpr(Empty);
3310 break;
3311
3312 case EXPR_OBJC_SELECTOR_EXPR:
3313 S = new (Context) ObjCSelectorExpr(Empty);
3314 break;
3315
3316 case EXPR_OBJC_PROTOCOL_EXPR:
3317 S = new (Context) ObjCProtocolExpr(Empty);
3318 break;
3319
3320 case EXPR_OBJC_IVAR_REF_EXPR:
3321 S = new (Context) ObjCIvarRefExpr(Empty);
3322 break;
3323
3324 case EXPR_OBJC_PROPERTY_REF_EXPR:
3325 S = new (Context) ObjCPropertyRefExpr(Empty);
3326 break;
3327
3328 case EXPR_OBJC_SUBSCRIPT_REF_EXPR:
3329 S = new (Context) ObjCSubscriptRefExpr(Empty);
3330 break;
3331
3332 case EXPR_OBJC_KVC_REF_EXPR:
3333 llvm_unreachable("mismatching AST file");
3334
3335 case EXPR_OBJC_MESSAGE_EXPR:
3336 S = ObjCMessageExpr::CreateEmpty(Context,
3337 Record[ASTStmtReader::NumExprFields],
3338 Record[ASTStmtReader::NumExprFields + 1]);
3339 break;
3340
3341 case EXPR_OBJC_ISA:
3342 S = new (Context) ObjCIsaExpr(Empty);
3343 break;
3344
3345 case EXPR_OBJC_INDIRECT_COPY_RESTORE:
3346 S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
3347 break;
3348
3349 case EXPR_OBJC_BRIDGED_CAST:
3350 S = new (Context) ObjCBridgedCastExpr(Empty);
3351 break;
3352
3353 case STMT_OBJC_FOR_COLLECTION:
3354 S = new (Context) ObjCForCollectionStmt(Empty);
3355 break;
3356
3357 case STMT_OBJC_CATCH:
3358 S = new (Context) ObjCAtCatchStmt(Empty);
3359 break;
3360
3361 case STMT_OBJC_FINALLY:
3362 S = new (Context) ObjCAtFinallyStmt(Empty);
3363 break;
3364
3365 case STMT_OBJC_AT_TRY:
3366 S = ObjCAtTryStmt::CreateEmpty(Context,
3367 Record[ASTStmtReader::NumStmtFields],
3368 Record[ASTStmtReader::NumStmtFields + 1]);
3369 break;
3370
3371 case STMT_OBJC_AT_SYNCHRONIZED:
3372 S = new (Context) ObjCAtSynchronizedStmt(Empty);
3373 break;
3374
3375 case STMT_OBJC_AT_THROW:
3376 S = new (Context) ObjCAtThrowStmt(Empty);
3377 break;
3378
3379 case STMT_OBJC_AUTORELEASE_POOL:
3380 S = new (Context) ObjCAutoreleasePoolStmt(Empty);
3381 break;
3382
3383 case EXPR_OBJC_BOOL_LITERAL:
3384 S = new (Context) ObjCBoolLiteralExpr(Empty);
3385 break;
3386
3387 case EXPR_OBJC_AVAILABILITY_CHECK:
3388 S = new (Context) ObjCAvailabilityCheckExpr(Empty);
3389 break;
3390
3391 case STMT_SEH_LEAVE:
3392 S = new (Context) SEHLeaveStmt(Empty);
3393 break;
3394
3395 case STMT_SEH_EXCEPT:
3396 S = new (Context) SEHExceptStmt(Empty);
3397 break;
3398
3399 case STMT_SEH_FINALLY:
3400 S = new (Context) SEHFinallyStmt(Empty);
3401 break;
3402
3403 case STMT_SEH_TRY:
3404 S = new (Context) SEHTryStmt(Empty);
3405 break;
3406
3407 case STMT_CXX_CATCH:
3408 S = new (Context) CXXCatchStmt(Empty);
3409 break;
3410
3411 case STMT_CXX_TRY:
3412 S = CXXTryStmt::Create(Context, Empty,
3413 /*numHandlers=*/Record[ASTStmtReader::NumStmtFields]);
3414 break;
3415
3416 case STMT_CXX_FOR_RANGE:
3417 S = new (Context) CXXForRangeStmt(Empty);
3418 break;
3419
3420 case STMT_MS_DEPENDENT_EXISTS:
3421 S = new (Context) MSDependentExistsStmt(SourceLocation(), true,
3422 NestedNameSpecifierLoc(),
3423 DeclarationNameInfo(),
3424 nullptr);
3425 break;
3426
3427 case STMT_OMP_CANONICAL_LOOP:
3428 S = OMPCanonicalLoop::createEmpty(Context);
3429 break;
3430
3431 case STMT_OMP_META_DIRECTIVE:
3432 S = OMPMetaDirective::CreateEmpty(
3433 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3434 break;
3435
3436 case STMT_OMP_PARALLEL_DIRECTIVE:
3437 S =
3438 OMPParallelDirective::CreateEmpty(Context,
3439 Record[ASTStmtReader::NumStmtFields],
3440 Empty);
3441 break;
3442
3443 case STMT_OMP_SIMD_DIRECTIVE: {
3444 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3445 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3446 S = OMPSimdDirective::CreateEmpty(Context, NumClauses,
3447 CollapsedNum, Empty);
3448 break;
3449 }
3450
3451 case STMT_OMP_TILE_DIRECTIVE: {
3452 unsigned NumLoops = Record[ASTStmtReader::NumStmtFields];
3453 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3454 S = OMPTileDirective::CreateEmpty(Context, NumClauses, NumLoops);
3455 break;
3456 }
3457
3458 case STMT_OMP_UNROLL_DIRECTIVE: {
3459 assert(Record[ASTStmtReader::NumStmtFields] == 1 && "Unroll directive accepts only a single loop");
3460 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3461 S = OMPUnrollDirective::CreateEmpty(Context, NumClauses);
3462 break;
3463 }
3464
3465 case STMT_OMP_REVERSE_DIRECTIVE: {
3466 assert(Record[ASTStmtReader::NumStmtFields] == 1 &&
3467 "Reverse directive accepts only a single loop");
3468 assert(Record[ASTStmtReader::NumStmtFields + 1] == 0 &&
3469 "Reverse directive has no clauses");
3470 S = OMPReverseDirective::CreateEmpty(Context);
3471 break;
3472 }
3473
3474 case STMT_OMP_INTERCHANGE_DIRECTIVE: {
3475 unsigned NumLoops = Record[ASTStmtReader::NumStmtFields];
3476 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3477 S = OMPInterchangeDirective::CreateEmpty(Context, NumClauses, NumLoops);
3478 break;
3479 }
3480
3481 case STMT_OMP_FOR_DIRECTIVE: {
3482 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3483 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3484 S = OMPForDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3485 Empty);
3486 break;
3487 }
3488
3489 case STMT_OMP_FOR_SIMD_DIRECTIVE: {
3490 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3491 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3492 S = OMPForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3493 Empty);
3494 break;
3495 }
3496
3497 case STMT_OMP_SECTIONS_DIRECTIVE:
3498 S = OMPSectionsDirective::CreateEmpty(
3499 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3500 break;
3501
3502 case STMT_OMP_SECTION_DIRECTIVE:
3503 S = OMPSectionDirective::CreateEmpty(Context, Empty);
3504 break;
3505
3506 case STMT_OMP_SCOPE_DIRECTIVE:
3507 S = OMPScopeDirective::CreateEmpty(
3508 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3509 break;
3510
3511 case STMT_OMP_SINGLE_DIRECTIVE:
3512 S = OMPSingleDirective::CreateEmpty(
3513 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3514 break;
3515
3516 case STMT_OMP_MASTER_DIRECTIVE:
3517 S = OMPMasterDirective::CreateEmpty(Context, Empty);
3518 break;
3519
3520 case STMT_OMP_CRITICAL_DIRECTIVE:
3521 S = OMPCriticalDirective::CreateEmpty(
3522 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3523 break;
3524
3525 case STMT_OMP_PARALLEL_FOR_DIRECTIVE: {
3526 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3527 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3528 S = OMPParallelForDirective::CreateEmpty(Context, NumClauses,
3529 CollapsedNum, Empty);
3530 break;
3531 }
3532
3533 case STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE: {
3534 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3535 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3536 S = OMPParallelForSimdDirective::CreateEmpty(Context, NumClauses,
3537 CollapsedNum, Empty);
3538 break;
3539 }
3540
3541 case STMT_OMP_PARALLEL_MASTER_DIRECTIVE:
3542 S = OMPParallelMasterDirective::CreateEmpty(
3543 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3544 break;
3545
3546 case STMT_OMP_PARALLEL_MASKED_DIRECTIVE:
3547 S = OMPParallelMaskedDirective::CreateEmpty(
3548 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3549 break;
3550
3551 case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
3552 S = OMPParallelSectionsDirective::CreateEmpty(
3553 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3554 break;
3555
3556 case STMT_OMP_TASK_DIRECTIVE:
3557 S = OMPTaskDirective::CreateEmpty(
3558 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3559 break;
3560
3561 case STMT_OMP_TASKYIELD_DIRECTIVE:
3562 S = OMPTaskyieldDirective::CreateEmpty(Context, Empty);
3563 break;
3564
3565 case STMT_OMP_BARRIER_DIRECTIVE:
3566 S = OMPBarrierDirective::CreateEmpty(Context, Empty);
3567 break;
3568
3569 case STMT_OMP_TASKWAIT_DIRECTIVE:
3570 S = OMPTaskwaitDirective::CreateEmpty(
3571 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3572 break;
3573
3574 case STMT_OMP_ERROR_DIRECTIVE:
3575 S = OMPErrorDirective::CreateEmpty(
3576 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3577 break;
3578
3579 case STMT_OMP_TASKGROUP_DIRECTIVE:
3580 S = OMPTaskgroupDirective::CreateEmpty(
3581 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3582 break;
3583
3584 case STMT_OMP_FLUSH_DIRECTIVE:
3585 S = OMPFlushDirective::CreateEmpty(
3586 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3587 break;
3588
3589 case STMT_OMP_DEPOBJ_DIRECTIVE:
3590 S = OMPDepobjDirective::CreateEmpty(
3591 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3592 break;
3593
3594 case STMT_OMP_SCAN_DIRECTIVE:
3595 S = OMPScanDirective::CreateEmpty(
3596 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3597 break;
3598
3599 case STMT_OMP_ORDERED_DIRECTIVE: {
3600 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
3601 bool HasAssociatedStmt = Record[ASTStmtReader::NumStmtFields + 2];
3602 S = OMPOrderedDirective::CreateEmpty(Context, NumClauses,
3603 !HasAssociatedStmt, Empty);
3604 break;
3605 }
3606
3607 case STMT_OMP_ATOMIC_DIRECTIVE:
3608 S = OMPAtomicDirective::CreateEmpty(
3609 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3610 break;
3611
3612 case STMT_OMP_TARGET_DIRECTIVE:
3613 S = OMPTargetDirective::CreateEmpty(
3614 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3615 break;
3616
3617 case STMT_OMP_TARGET_DATA_DIRECTIVE:
3618 S = OMPTargetDataDirective::CreateEmpty(
3619 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3620 break;
3621
3622 case STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE:
3623 S = OMPTargetEnterDataDirective::CreateEmpty(
3624 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3625 break;
3626
3627 case STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE:
3628 S = OMPTargetExitDataDirective::CreateEmpty(
3629 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3630 break;
3631
3632 case STMT_OMP_TARGET_PARALLEL_DIRECTIVE:
3633 S = OMPTargetParallelDirective::CreateEmpty(
3634 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3635 break;
3636
3637 case STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE: {
3638 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3639 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3640 S = OMPTargetParallelForDirective::CreateEmpty(Context, NumClauses,
3641 CollapsedNum, Empty);
3642 break;
3643 }
3644
3645 case STMT_OMP_TARGET_UPDATE_DIRECTIVE:
3646 S = OMPTargetUpdateDirective::CreateEmpty(
3647 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3648 break;
3649
3650 case STMT_OMP_TEAMS_DIRECTIVE:
3651 S = OMPTeamsDirective::CreateEmpty(
3652 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3653 break;
3654
3655 case STMT_OMP_CANCELLATION_POINT_DIRECTIVE:
3656 S = OMPCancellationPointDirective::CreateEmpty(Context, Empty);
3657 break;
3658
3659 case STMT_OMP_CANCEL_DIRECTIVE:
3660 S = OMPCancelDirective::CreateEmpty(
3661 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3662 break;
3663
3664 case STMT_OMP_TASKLOOP_DIRECTIVE: {
3665 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3666 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3667 S = OMPTaskLoopDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3668 Empty);
3669 break;
3670 }
3671
3672 case STMT_OMP_TASKLOOP_SIMD_DIRECTIVE: {
3673 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3674 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3675 S = OMPTaskLoopSimdDirective::CreateEmpty(Context, NumClauses,
3676 CollapsedNum, Empty);
3677 break;
3678 }
3679
3680 case STMT_OMP_MASTER_TASKLOOP_DIRECTIVE: {
3681 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3682 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3683 S = OMPMasterTaskLoopDirective::CreateEmpty(Context, NumClauses,
3684 CollapsedNum, Empty);
3685 break;
3686 }
3687
3688 case STMT_OMP_MASKED_TASKLOOP_DIRECTIVE: {
3689 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3690 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3691 S = OMPMaskedTaskLoopDirective::CreateEmpty(Context, NumClauses,
3692 CollapsedNum, Empty);
3693 break;
3694 }
3695
3696 case STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE: {
3697 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3698 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3699 S = OMPMasterTaskLoopSimdDirective::CreateEmpty(Context, NumClauses,
3700 CollapsedNum, Empty);
3701 break;
3702 }
3703
3704 case STMT_OMP_MASKED_TASKLOOP_SIMD_DIRECTIVE: {
3705 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3706 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3707 S = OMPMaskedTaskLoopSimdDirective::CreateEmpty(Context, NumClauses,
3708 CollapsedNum, Empty);
3709 break;
3710 }
3711
3712 case STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE: {
3713 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3714 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3715 S = OMPParallelMasterTaskLoopDirective::CreateEmpty(Context, NumClauses,
3716 CollapsedNum, Empty);
3717 break;
3718 }
3719
3720 case STMT_OMP_PARALLEL_MASKED_TASKLOOP_DIRECTIVE: {
3721 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3722 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3723 S = OMPParallelMaskedTaskLoopDirective::CreateEmpty(Context, NumClauses,
3724 CollapsedNum, Empty);
3725 break;
3726 }
3727
3728 case STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE: {
3729 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3730 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3731 S = OMPParallelMasterTaskLoopSimdDirective::CreateEmpty(
3732 Context, NumClauses, CollapsedNum, Empty);
3733 break;
3734 }
3735
3736 case STMT_OMP_PARALLEL_MASKED_TASKLOOP_SIMD_DIRECTIVE: {
3737 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3738 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3739 S = OMPParallelMaskedTaskLoopSimdDirective::CreateEmpty(
3740 Context, NumClauses, CollapsedNum, Empty);
3741 break;
3742 }
3743
3744 case STMT_OMP_DISTRIBUTE_DIRECTIVE: {
3745 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3746 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3747 S = OMPDistributeDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3748 Empty);
3749 break;
3750 }
3751
3752 case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
3753 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3754 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3755 S = OMPDistributeParallelForDirective::CreateEmpty(Context, NumClauses,
3756 CollapsedNum, Empty);
3757 break;
3758 }
3759
3760 case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
3761 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3762 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3763 S = OMPDistributeParallelForSimdDirective::CreateEmpty(Context, NumClauses,
3764 CollapsedNum,
3765 Empty);
3766 break;
3767 }
3768
3769 case STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE: {
3770 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3771 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3772 S = OMPDistributeSimdDirective::CreateEmpty(Context, NumClauses,
3773 CollapsedNum, Empty);
3774 break;
3775 }
3776
3777 case STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE: {
3778 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3779 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3780 S = OMPTargetParallelForSimdDirective::CreateEmpty(Context, NumClauses,
3781 CollapsedNum, Empty);
3782 break;
3783 }
3784
3785 case STMT_OMP_TARGET_SIMD_DIRECTIVE: {
3786 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3787 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3788 S = OMPTargetSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3789 Empty);
3790 break;
3791 }
3792
3793 case STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE: {
3794 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3795 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3796 S = OMPTeamsDistributeDirective::CreateEmpty(Context, NumClauses,
3797 CollapsedNum, Empty);
3798 break;
3799 }
3800
3801 case STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: {
3802 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3803 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3804 S = OMPTeamsDistributeSimdDirective::CreateEmpty(Context, NumClauses,
3805 CollapsedNum, Empty);
3806 break;
3807 }
3808
3809 case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
3810 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3811 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3812 S = OMPTeamsDistributeParallelForSimdDirective::CreateEmpty(
3813 Context, NumClauses, CollapsedNum, Empty);
3814 break;
3815 }
3816
3817 case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
3818 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3819 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3820 S = OMPTeamsDistributeParallelForDirective::CreateEmpty(
3821 Context, NumClauses, CollapsedNum, Empty);
3822 break;
3823 }
3824
3825 case STMT_OMP_TARGET_TEAMS_DIRECTIVE:
3826 S = OMPTargetTeamsDirective::CreateEmpty(
3827 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3828 break;
3829
3830 case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE: {
3831 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3832 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3833 S = OMPTargetTeamsDistributeDirective::CreateEmpty(Context, NumClauses,
3834 CollapsedNum, Empty);
3835 break;
3836 }
3837
3838 case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
3839 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3840 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3841 S = OMPTargetTeamsDistributeParallelForDirective::CreateEmpty(
3842 Context, NumClauses, CollapsedNum, Empty);
3843 break;
3844 }
3845
3846 case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
3847 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3848 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3849 S = OMPTargetTeamsDistributeParallelForSimdDirective::CreateEmpty(
3850 Context, NumClauses, CollapsedNum, Empty);
3851 break;
3852 }
3853
3854 case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: {
3855 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3856 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3857 S = OMPTargetTeamsDistributeSimdDirective::CreateEmpty(
3858 Context, NumClauses, CollapsedNum, Empty);
3859 break;
3860 }
3861
3862 case STMT_OMP_INTEROP_DIRECTIVE:
3863 S = OMPInteropDirective::CreateEmpty(
3864 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3865 break;
3866
3867 case STMT_OMP_DISPATCH_DIRECTIVE:
3868 S = OMPDispatchDirective::CreateEmpty(
3869 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3870 break;
3871
3872 case STMT_OMP_MASKED_DIRECTIVE:
3873 S = OMPMaskedDirective::CreateEmpty(
3874 Context, Record[ASTStmtReader::NumStmtFields], Empty);
3875 break;
3876
3877 case STMT_OMP_GENERIC_LOOP_DIRECTIVE: {
3878 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3879 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3880 S = OMPGenericLoopDirective::CreateEmpty(Context, NumClauses,
3881 CollapsedNum, Empty);
3882 break;
3883 }
3884
3885 case STMT_OMP_TEAMS_GENERIC_LOOP_DIRECTIVE: {
3886 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3887 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3888 S = OMPTeamsGenericLoopDirective::CreateEmpty(Context, NumClauses,
3889 CollapsedNum, Empty);
3890 break;
3891 }
3892
3893 case STMT_OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE: {
3894 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3895 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3896 S = OMPTargetTeamsGenericLoopDirective::CreateEmpty(Context, NumClauses,
3897 CollapsedNum, Empty);
3898 break;
3899 }
3900
3901 case STMT_OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE: {
3902 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3903 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3904 S = OMPParallelGenericLoopDirective::CreateEmpty(Context, NumClauses,
3905 CollapsedNum, Empty);
3906 break;
3907 }
3908
3909 case STMT_OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE: {
3910 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3911 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3912 S = OMPTargetParallelGenericLoopDirective::CreateEmpty(
3913 Context, NumClauses, CollapsedNum, Empty);
3914 break;
3915 }
3916
3917 case EXPR_CXX_OPERATOR_CALL: {
3918 auto NumArgs = Record[ASTStmtReader::NumExprFields];
3919 BitsUnpacker CallExprBits(Record[ASTStmtReader::NumExprFields + 1]);
3920 CallExprBits.advance(1);
3921 auto HasFPFeatures = CallExprBits.getNextBit();
3922 S = CXXOperatorCallExpr::CreateEmpty(Context, NumArgs, HasFPFeatures,
3923 Empty);
3924 break;
3925 }
3926
3927 case EXPR_CXX_MEMBER_CALL: {
3928 auto NumArgs = Record[ASTStmtReader::NumExprFields];
3929 BitsUnpacker CallExprBits(Record[ASTStmtReader::NumExprFields + 1]);
3930 CallExprBits.advance(1);
3931 auto HasFPFeatures = CallExprBits.getNextBit();
3932 S = CXXMemberCallExpr::CreateEmpty(Context, NumArgs, HasFPFeatures,
3933 Empty);
3934 break;
3935 }
3936
3937 case EXPR_CXX_REWRITTEN_BINARY_OPERATOR:
3938 S = new (Context) CXXRewrittenBinaryOperator(Empty);
3939 break;
3940
3941 case EXPR_CXX_CONSTRUCT:
3942 S = CXXConstructExpr::CreateEmpty(
3943 Context,
3944 /* NumArgs=*/Record[ASTStmtReader::NumExprFields]);
3945 break;
3946
3947 case EXPR_CXX_INHERITED_CTOR_INIT:
3948 S = new (Context) CXXInheritedCtorInitExpr(Empty);
3949 break;
3950
3951 case EXPR_CXX_TEMPORARY_OBJECT:
3952 S = CXXTemporaryObjectExpr::CreateEmpty(
3953 Context,
3954 /* NumArgs=*/Record[ASTStmtReader::NumExprFields]);
3955 break;
3956
3957 case EXPR_CXX_STATIC_CAST: {
3958 unsigned PathSize = Record[ASTStmtReader::NumExprFields];
3959 BitsUnpacker CastExprBits(Record[ASTStmtReader::NumExprFields + 1]);
3960 CastExprBits.advance(7);
3961 bool HasFPFeatures = CastExprBits.getNextBit();
3962 S = CXXStaticCastExpr::CreateEmpty(Context, PathSize, HasFPFeatures);
3963 break;
3964 }
3965
3966 case EXPR_CXX_DYNAMIC_CAST: {
3967 unsigned PathSize = Record[ASTStmtReader::NumExprFields];
3968 S = CXXDynamicCastExpr::CreateEmpty(Context, PathSize);
3969 break;
3970 }
3971
3972 case EXPR_CXX_REINTERPRET_CAST: {
3973 unsigned PathSize = Record[ASTStmtReader::NumExprFields];
3974 S = CXXReinterpretCastExpr::CreateEmpty(Context, PathSize);
3975 break;
3976 }
3977
3978 case EXPR_CXX_CONST_CAST:
3979 S = CXXConstCastExpr::CreateEmpty(Context);
3980 break;
3981
3982 case EXPR_CXX_ADDRSPACE_CAST:
3983 S = CXXAddrspaceCastExpr::CreateEmpty(Context);
3984 break;
3985
3986 case EXPR_CXX_FUNCTIONAL_CAST: {
3987 unsigned PathSize = Record[ASTStmtReader::NumExprFields];
3988 BitsUnpacker CastExprBits(Record[ASTStmtReader::NumExprFields + 1]);
3989 CastExprBits.advance(7);
3990 bool HasFPFeatures = CastExprBits.getNextBit();
3991 S = CXXFunctionalCastExpr::CreateEmpty(Context, PathSize, HasFPFeatures);
3992 break;
3993 }
3994
3995 case EXPR_BUILTIN_BIT_CAST: {
3996 #ifndef NDEBUG
3997 unsigned PathSize = Record[ASTStmtReader::NumExprFields];
3998 assert(PathSize == 0 && "Wrong PathSize!");
3999 #endif
4000 S = new (Context) BuiltinBitCastExpr(Empty);
4001 break;
4002 }
4003
4004 case EXPR_USER_DEFINED_LITERAL: {
4005 auto NumArgs = Record[ASTStmtReader::NumExprFields];
4006 BitsUnpacker CallExprBits(Record[ASTStmtReader::NumExprFields + 1]);
4007 CallExprBits.advance(1);
4008 auto HasFPFeatures = CallExprBits.getNextBit();
4009 S = UserDefinedLiteral::CreateEmpty(Context, NumArgs, HasFPFeatures,
4010 Empty);
4011 break;
4012 }
4013
4014 case EXPR_CXX_STD_INITIALIZER_LIST:
4015 S = new (Context) CXXStdInitializerListExpr(Empty);
4016 break;
4017
4018 case EXPR_CXX_BOOL_LITERAL:
4019 S = new (Context) CXXBoolLiteralExpr(Empty);
4020 break;
4021
4022 case EXPR_CXX_NULL_PTR_LITERAL:
4023 S = new (Context) CXXNullPtrLiteralExpr(Empty);
4024 break;
4025
4026 case EXPR_CXX_TYPEID_EXPR:
4027 S = new (Context) CXXTypeidExpr(Empty, true);
4028 break;
4029
4030 case EXPR_CXX_TYPEID_TYPE:
4031 S = new (Context) CXXTypeidExpr(Empty, false);
4032 break;
4033
4034 case EXPR_CXX_UUIDOF_EXPR:
4035 S = new (Context) CXXUuidofExpr(Empty, true);
4036 break;
4037
4038 case EXPR_CXX_PROPERTY_REF_EXPR:
4039 S = new (Context) MSPropertyRefExpr(Empty);
4040 break;
4041
4042 case EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR:
4043 S = new (Context) MSPropertySubscriptExpr(Empty);
4044 break;
4045
4046 case EXPR_CXX_UUIDOF_TYPE:
4047 S = new (Context) CXXUuidofExpr(Empty, false);
4048 break;
4049
4050 case EXPR_CXX_THIS:
4051 S = CXXThisExpr::CreateEmpty(Context);
4052 break;
4053
4054 case EXPR_CXX_THROW:
4055 S = new (Context) CXXThrowExpr(Empty);
4056 break;
4057
4058 case EXPR_CXX_DEFAULT_ARG:
4059 S = CXXDefaultArgExpr::CreateEmpty(
4060 Context, /*HasRewrittenInit=*/Record[ASTStmtReader::NumExprFields]);
4061 break;
4062
4063 case EXPR_CXX_DEFAULT_INIT:
4064 S = CXXDefaultInitExpr::CreateEmpty(
4065 Context, /*HasRewrittenInit=*/Record[ASTStmtReader::NumExprFields]);
4066 break;
4067
4068 case EXPR_CXX_BIND_TEMPORARY:
4069 S = new (Context) CXXBindTemporaryExpr(Empty);
4070 break;
4071
4072 case EXPR_CXX_SCALAR_VALUE_INIT:
4073 S = new (Context) CXXScalarValueInitExpr(Empty);
4074 break;
4075
4076 case EXPR_CXX_NEW:
4077 S = CXXNewExpr::CreateEmpty(
4078 Context,
4079 /*IsArray=*/Record[ASTStmtReader::NumExprFields],
4080 /*HasInit=*/Record[ASTStmtReader::NumExprFields + 1],
4081 /*NumPlacementArgs=*/Record[ASTStmtReader::NumExprFields + 2],
4082 /*IsParenTypeId=*/Record[ASTStmtReader::NumExprFields + 3]);
4083 break;
4084
4085 case EXPR_CXX_DELETE:
4086 S = new (Context) CXXDeleteExpr(Empty);
4087 break;
4088
4089 case EXPR_CXX_PSEUDO_DESTRUCTOR:
4090 S = new (Context) CXXPseudoDestructorExpr(Empty);
4091 break;
4092
4093 case EXPR_EXPR_WITH_CLEANUPS:
4094 S = ExprWithCleanups::Create(Context, Empty,
4095 Record[ASTStmtReader::NumExprFields]);
4096 break;
4097
4098 case EXPR_CXX_DEPENDENT_SCOPE_MEMBER: {
4099 unsigned NumTemplateArgs = Record[ASTStmtReader::NumExprFields];
4100 BitsUnpacker DependentScopeMemberBits(
4101 Record[ASTStmtReader::NumExprFields + 1]);
4102 bool HasTemplateKWAndArgsInfo = DependentScopeMemberBits.getNextBit();
4103
4104 bool HasFirstQualifierFoundInScope =
4105 DependentScopeMemberBits.getNextBit();
4106 S = CXXDependentScopeMemberExpr::CreateEmpty(
4107 Context, HasTemplateKWAndArgsInfo, NumTemplateArgs,
4108 HasFirstQualifierFoundInScope);
4109 break;
4110 }
4111
4112 case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF: {
4113 BitsUnpacker DependentScopeDeclRefBits(
4114 Record[ASTStmtReader::NumStmtFields]);
4115 DependentScopeDeclRefBits.advance(ASTStmtReader::NumExprBits);
4116 bool HasTemplateKWAndArgsInfo = DependentScopeDeclRefBits.getNextBit();
4117 unsigned NumTemplateArgs =
4118 HasTemplateKWAndArgsInfo
4119 ? DependentScopeDeclRefBits.getNextBits(/*Width=*/16)
4120 : 0;
4121 S = DependentScopeDeclRefExpr::CreateEmpty(
4122 Context, HasTemplateKWAndArgsInfo, NumTemplateArgs);
4123 break;
4124 }
4125
4126 case EXPR_CXX_UNRESOLVED_CONSTRUCT:
4127 S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
4128 /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
4129 break;
4130
4131 case EXPR_CXX_UNRESOLVED_MEMBER: {
4132 auto NumResults = Record[ASTStmtReader::NumExprFields];
4133 BitsUnpacker OverloadExprBits(Record[ASTStmtReader::NumExprFields + 1]);
4134 auto HasTemplateKWAndArgsInfo = OverloadExprBits.getNextBit();
4135 auto NumTemplateArgs = HasTemplateKWAndArgsInfo
4136 ? Record[ASTStmtReader::NumExprFields + 2]
4137 : 0;
4138 S = UnresolvedMemberExpr::CreateEmpty(
4139 Context, NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
4140 break;
4141 }
4142
4143 case EXPR_CXX_UNRESOLVED_LOOKUP: {
4144 auto NumResults = Record[ASTStmtReader::NumExprFields];
4145 BitsUnpacker OverloadExprBits(Record[ASTStmtReader::NumExprFields + 1]);
4146 auto HasTemplateKWAndArgsInfo = OverloadExprBits.getNextBit();
4147 auto NumTemplateArgs = HasTemplateKWAndArgsInfo
4148 ? Record[ASTStmtReader::NumExprFields + 2]
4149 : 0;
4150 S = UnresolvedLookupExpr::CreateEmpty(
4151 Context, NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
4152 break;
4153 }
4154
4155 case EXPR_TYPE_TRAIT:
4156 S = TypeTraitExpr::CreateDeserialized(Context,
4157 Record[ASTStmtReader::NumExprFields]);
4158 break;
4159
4160 case EXPR_ARRAY_TYPE_TRAIT:
4161 S = new (Context) ArrayTypeTraitExpr(Empty);
4162 break;
4163
4164 case EXPR_CXX_EXPRESSION_TRAIT:
4165 S = new (Context) ExpressionTraitExpr(Empty);
4166 break;
4167
4168 case EXPR_CXX_NOEXCEPT:
4169 S = new (Context) CXXNoexceptExpr(Empty);
4170 break;
4171
4172 case EXPR_PACK_EXPANSION:
4173 S = new (Context) PackExpansionExpr(Empty);
4174 break;
4175
4176 case EXPR_SIZEOF_PACK:
4177 S = SizeOfPackExpr::CreateDeserialized(
4178 Context,
4179 /*NumPartialArgs=*/Record[ASTStmtReader::NumExprFields]);
4180 break;
4181
4182 case EXPR_PACK_INDEXING:
4183 S = PackIndexingExpr::CreateDeserialized(
4184 Context,
4185 /*TransformedExprs=*/Record[ASTStmtReader::NumExprFields]);
4186 break;
4187
4188 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
4189 S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
4190 break;
4191
4192 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
4193 S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
4194 break;
4195
4196 case EXPR_FUNCTION_PARM_PACK:
4197 S = FunctionParmPackExpr::CreateEmpty(Context,
4198 Record[ASTStmtReader::NumExprFields]);
4199 break;
4200
4201 case EXPR_MATERIALIZE_TEMPORARY:
4202 S = new (Context) MaterializeTemporaryExpr(Empty);
4203 break;
4204
4205 case EXPR_CXX_FOLD:
4206 S = new (Context) CXXFoldExpr(Empty);
4207 break;
4208
4209 case EXPR_CXX_PAREN_LIST_INIT:
4210 S = CXXParenListInitExpr::CreateEmpty(
4211 Context, /*numExprs=*/Record[ASTStmtReader::NumExprFields], Empty);
4212 break;
4213
4214 case EXPR_OPAQUE_VALUE:
4215 S = new (Context) OpaqueValueExpr(Empty);
4216 break;
4217
4218 case EXPR_CUDA_KERNEL_CALL: {
4219 auto NumArgs = Record[ASTStmtReader::NumExprFields];
4220 BitsUnpacker CallExprBits(Record[ASTStmtReader::NumExprFields + 1]);
4221 CallExprBits.advance(1);
4222 auto HasFPFeatures = CallExprBits.getNextBit();
4223 S = CUDAKernelCallExpr::CreateEmpty(Context, NumArgs, HasFPFeatures,
4224 Empty);
4225 break;
4226 }
4227
4228 case EXPR_ASTYPE:
4229 S = new (Context) AsTypeExpr(Empty);
4230 break;
4231
4232 case EXPR_PSEUDO_OBJECT: {
4233 unsigned numSemanticExprs = Record[ASTStmtReader::NumExprFields];
4234 S = PseudoObjectExpr::Create(Context, Empty, numSemanticExprs);
4235 break;
4236 }
4237
4238 case EXPR_ATOMIC:
4239 S = new (Context) AtomicExpr(Empty);
4240 break;
4241
4242 case EXPR_LAMBDA: {
4243 unsigned NumCaptures = Record[ASTStmtReader::NumExprFields];
4244 S = LambdaExpr::CreateDeserialized(Context, NumCaptures);
4245 break;
4246 }
4247
4248 case STMT_COROUTINE_BODY: {
4249 unsigned NumParams = Record[ASTStmtReader::NumStmtFields];
4250 S = CoroutineBodyStmt::Create(Context, Empty, NumParams);
4251 break;
4252 }
4253
4254 case STMT_CORETURN:
4255 S = new (Context) CoreturnStmt(Empty);
4256 break;
4257
4258 case EXPR_COAWAIT:
4259 S = new (Context) CoawaitExpr(Empty);
4260 break;
4261
4262 case EXPR_COYIELD:
4263 S = new (Context) CoyieldExpr(Empty);
4264 break;
4265
4266 case EXPR_DEPENDENT_COAWAIT:
4267 S = new (Context) DependentCoawaitExpr(Empty);
4268 break;
4269
4270 case EXPR_CONCEPT_SPECIALIZATION: {
4271 S = new (Context) ConceptSpecializationExpr(Empty);
4272 break;
4273 }
4274 case STMT_OPENACC_COMPUTE_CONSTRUCT: {
4275 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
4276 S = OpenACCComputeConstruct::CreateEmpty(Context, NumClauses);
4277 break;
4278 }
4279 case STMT_OPENACC_LOOP_CONSTRUCT: {
4280 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
4281 S = OpenACCLoopConstruct::CreateEmpty(Context, NumClauses);
4282 break;
4283 }
4284 case EXPR_REQUIRES:
4285 unsigned numLocalParameters = Record[ASTStmtReader::NumExprFields];
4286 unsigned numRequirement = Record[ASTStmtReader::NumExprFields + 1];
4287 S = RequiresExpr::Create(Context, Empty, numLocalParameters,
4288 numRequirement);
4289 break;
4290 }
4291
4292 // We hit a STMT_STOP, so we're done with this expression.
4293 if (Finished)
4294 break;
4295
4296 ++NumStatementsRead;
4297
4298 if (S && !IsStmtReference) {
4299 Reader.Visit(S);
4300 StmtEntries[Cursor.GetCurrentBitNo()] = S;
4301 }
4302
4303 assert(Record.getIdx() == Record.size() &&
4304 "Invalid deserialization of statement");
4305 StmtStack.push_back(S);
4306 }
4307 Done:
4308 assert(StmtStack.size() > PrevNumStmts && "Read too many sub-stmts!");
4309 assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
4310 return StmtStack.pop_back_val();
4311 }
4312