xref: /freebsd/contrib/llvm-project/clang/lib/Serialization/ASTWriterStmt.cpp (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1 //===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
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 /// \file
10 /// Implements serialization for Statements and Expressions.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ExprOpenMP.h"
15 #include "clang/Serialization/ASTRecordWriter.h"
16 #include "clang/Sema/DeclSpec.h"
17 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/StmtVisitor.h"
22 #include "clang/Lex/Token.h"
23 #include "llvm/Bitstream/BitstreamWriter.h"
24 using namespace clang;
25 
26 //===----------------------------------------------------------------------===//
27 // Statement/expression serialization
28 //===----------------------------------------------------------------------===//
29 
30 namespace clang {
31 
32   class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
33     ASTWriter &Writer;
34     ASTRecordWriter Record;
35 
36     serialization::StmtCode Code;
37     unsigned AbbrevToUse;
38 
39   public:
40     ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
41         : Writer(Writer), Record(Writer, Record),
42           Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
43 
44     ASTStmtWriter(const ASTStmtWriter&) = delete;
45     ASTStmtWriter &operator=(const ASTStmtWriter &) = delete;
46 
47     uint64_t Emit() {
48       assert(Code != serialization::STMT_NULL_PTR &&
49              "unhandled sub-statement writing AST file");
50       return Record.EmitStmt(Code, AbbrevToUse);
51     }
52 
53     void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo,
54                                   const TemplateArgumentLoc *Args);
55 
56     void VisitStmt(Stmt *S);
57 #define STMT(Type, Base) \
58     void Visit##Type(Type *);
59 #include "clang/AST/StmtNodes.inc"
60   };
61 }
62 
63 void ASTStmtWriter::AddTemplateKWAndArgsInfo(
64     const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) {
65   Record.AddSourceLocation(ArgInfo.TemplateKWLoc);
66   Record.AddSourceLocation(ArgInfo.LAngleLoc);
67   Record.AddSourceLocation(ArgInfo.RAngleLoc);
68   for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i)
69     Record.AddTemplateArgumentLoc(Args[i]);
70 }
71 
72 void ASTStmtWriter::VisitStmt(Stmt *S) {
73 }
74 
75 void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
76   VisitStmt(S);
77   Record.AddSourceLocation(S->getSemiLoc());
78   Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro);
79   Code = serialization::STMT_NULL;
80 }
81 
82 void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
83   VisitStmt(S);
84   Record.push_back(S->size());
85   Record.push_back(S->hasStoredFPFeatures());
86   for (auto *CS : S->body())
87     Record.AddStmt(CS);
88   if (S->hasStoredFPFeatures())
89     Record.push_back(S->getStoredFPFeatures().getAsOpaqueInt());
90   Record.AddSourceLocation(S->getLBracLoc());
91   Record.AddSourceLocation(S->getRBracLoc());
92   Code = serialization::STMT_COMPOUND;
93 }
94 
95 void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
96   VisitStmt(S);
97   Record.push_back(Writer.getSwitchCaseID(S));
98   Record.AddSourceLocation(S->getKeywordLoc());
99   Record.AddSourceLocation(S->getColonLoc());
100 }
101 
102 void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
103   VisitSwitchCase(S);
104   Record.push_back(S->caseStmtIsGNURange());
105   Record.AddStmt(S->getLHS());
106   Record.AddStmt(S->getSubStmt());
107   if (S->caseStmtIsGNURange()) {
108     Record.AddStmt(S->getRHS());
109     Record.AddSourceLocation(S->getEllipsisLoc());
110   }
111   Code = serialization::STMT_CASE;
112 }
113 
114 void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
115   VisitSwitchCase(S);
116   Record.AddStmt(S->getSubStmt());
117   Code = serialization::STMT_DEFAULT;
118 }
119 
120 void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
121   VisitStmt(S);
122   Record.push_back(S->isSideEntry());
123   Record.AddDeclRef(S->getDecl());
124   Record.AddStmt(S->getSubStmt());
125   Record.AddSourceLocation(S->getIdentLoc());
126   Code = serialization::STMT_LABEL;
127 }
128 
129 void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
130   VisitStmt(S);
131   Record.push_back(S->getAttrs().size());
132   Record.AddAttributes(S->getAttrs());
133   Record.AddStmt(S->getSubStmt());
134   Record.AddSourceLocation(S->getAttrLoc());
135   Code = serialization::STMT_ATTRIBUTED;
136 }
137 
138 void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
139   VisitStmt(S);
140 
141   bool HasElse = S->getElse() != nullptr;
142   bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
143   bool HasInit = S->getInit() != nullptr;
144 
145   Record.push_back(HasElse);
146   Record.push_back(HasVar);
147   Record.push_back(HasInit);
148   Record.push_back(static_cast<uint64_t>(S->getStatementKind()));
149   Record.AddStmt(S->getCond());
150   Record.AddStmt(S->getThen());
151   if (HasElse)
152     Record.AddStmt(S->getElse());
153   if (HasVar)
154     Record.AddStmt(S->getConditionVariableDeclStmt());
155   if (HasInit)
156     Record.AddStmt(S->getInit());
157 
158   Record.AddSourceLocation(S->getIfLoc());
159   Record.AddSourceLocation(S->getLParenLoc());
160   Record.AddSourceLocation(S->getRParenLoc());
161   if (HasElse)
162     Record.AddSourceLocation(S->getElseLoc());
163 
164   Code = serialization::STMT_IF;
165 }
166 
167 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
168   VisitStmt(S);
169 
170   bool HasInit = S->getInit() != nullptr;
171   bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
172   Record.push_back(HasInit);
173   Record.push_back(HasVar);
174   Record.push_back(S->isAllEnumCasesCovered());
175 
176   Record.AddStmt(S->getCond());
177   Record.AddStmt(S->getBody());
178   if (HasInit)
179     Record.AddStmt(S->getInit());
180   if (HasVar)
181     Record.AddStmt(S->getConditionVariableDeclStmt());
182 
183   Record.AddSourceLocation(S->getSwitchLoc());
184   Record.AddSourceLocation(S->getLParenLoc());
185   Record.AddSourceLocation(S->getRParenLoc());
186 
187   for (SwitchCase *SC = S->getSwitchCaseList(); SC;
188        SC = SC->getNextSwitchCase())
189     Record.push_back(Writer.RecordSwitchCaseID(SC));
190   Code = serialization::STMT_SWITCH;
191 }
192 
193 void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
194   VisitStmt(S);
195 
196   bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
197   Record.push_back(HasVar);
198 
199   Record.AddStmt(S->getCond());
200   Record.AddStmt(S->getBody());
201   if (HasVar)
202     Record.AddStmt(S->getConditionVariableDeclStmt());
203 
204   Record.AddSourceLocation(S->getWhileLoc());
205   Record.AddSourceLocation(S->getLParenLoc());
206   Record.AddSourceLocation(S->getRParenLoc());
207   Code = serialization::STMT_WHILE;
208 }
209 
210 void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
211   VisitStmt(S);
212   Record.AddStmt(S->getCond());
213   Record.AddStmt(S->getBody());
214   Record.AddSourceLocation(S->getDoLoc());
215   Record.AddSourceLocation(S->getWhileLoc());
216   Record.AddSourceLocation(S->getRParenLoc());
217   Code = serialization::STMT_DO;
218 }
219 
220 void ASTStmtWriter::VisitForStmt(ForStmt *S) {
221   VisitStmt(S);
222   Record.AddStmt(S->getInit());
223   Record.AddStmt(S->getCond());
224   Record.AddStmt(S->getConditionVariableDeclStmt());
225   Record.AddStmt(S->getInc());
226   Record.AddStmt(S->getBody());
227   Record.AddSourceLocation(S->getForLoc());
228   Record.AddSourceLocation(S->getLParenLoc());
229   Record.AddSourceLocation(S->getRParenLoc());
230   Code = serialization::STMT_FOR;
231 }
232 
233 void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
234   VisitStmt(S);
235   Record.AddDeclRef(S->getLabel());
236   Record.AddSourceLocation(S->getGotoLoc());
237   Record.AddSourceLocation(S->getLabelLoc());
238   Code = serialization::STMT_GOTO;
239 }
240 
241 void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
242   VisitStmt(S);
243   Record.AddSourceLocation(S->getGotoLoc());
244   Record.AddSourceLocation(S->getStarLoc());
245   Record.AddStmt(S->getTarget());
246   Code = serialization::STMT_INDIRECT_GOTO;
247 }
248 
249 void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
250   VisitStmt(S);
251   Record.AddSourceLocation(S->getContinueLoc());
252   Code = serialization::STMT_CONTINUE;
253 }
254 
255 void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
256   VisitStmt(S);
257   Record.AddSourceLocation(S->getBreakLoc());
258   Code = serialization::STMT_BREAK;
259 }
260 
261 void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
262   VisitStmt(S);
263 
264   bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr;
265   Record.push_back(HasNRVOCandidate);
266 
267   Record.AddStmt(S->getRetValue());
268   if (HasNRVOCandidate)
269     Record.AddDeclRef(S->getNRVOCandidate());
270 
271   Record.AddSourceLocation(S->getReturnLoc());
272   Code = serialization::STMT_RETURN;
273 }
274 
275 void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
276   VisitStmt(S);
277   Record.AddSourceLocation(S->getBeginLoc());
278   Record.AddSourceLocation(S->getEndLoc());
279   DeclGroupRef DG = S->getDeclGroup();
280   for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
281     Record.AddDeclRef(*D);
282   Code = serialization::STMT_DECL;
283 }
284 
285 void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
286   VisitStmt(S);
287   Record.push_back(S->getNumOutputs());
288   Record.push_back(S->getNumInputs());
289   Record.push_back(S->getNumClobbers());
290   Record.AddSourceLocation(S->getAsmLoc());
291   Record.push_back(S->isVolatile());
292   Record.push_back(S->isSimple());
293 }
294 
295 void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
296   VisitAsmStmt(S);
297   Record.push_back(S->getNumLabels());
298   Record.AddSourceLocation(S->getRParenLoc());
299   Record.AddStmt(S->getAsmString());
300 
301   // Outputs
302   for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
303     Record.AddIdentifierRef(S->getOutputIdentifier(I));
304     Record.AddStmt(S->getOutputConstraintLiteral(I));
305     Record.AddStmt(S->getOutputExpr(I));
306   }
307 
308   // Inputs
309   for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
310     Record.AddIdentifierRef(S->getInputIdentifier(I));
311     Record.AddStmt(S->getInputConstraintLiteral(I));
312     Record.AddStmt(S->getInputExpr(I));
313   }
314 
315   // Clobbers
316   for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
317     Record.AddStmt(S->getClobberStringLiteral(I));
318 
319   // Labels
320   for (unsigned I = 0, N = S->getNumLabels(); I != N; ++I) {
321     Record.AddIdentifierRef(S->getLabelIdentifier(I));
322     Record.AddStmt(S->getLabelExpr(I));
323   }
324 
325   Code = serialization::STMT_GCCASM;
326 }
327 
328 void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
329   VisitAsmStmt(S);
330   Record.AddSourceLocation(S->getLBraceLoc());
331   Record.AddSourceLocation(S->getEndLoc());
332   Record.push_back(S->getNumAsmToks());
333   Record.AddString(S->getAsmString());
334 
335   // Tokens
336   for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
337     // FIXME: Move this to ASTRecordWriter?
338     Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
339   }
340 
341   // Clobbers
342   for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
343     Record.AddString(S->getClobber(I));
344   }
345 
346   // Outputs
347   for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
348     Record.AddStmt(S->getOutputExpr(I));
349     Record.AddString(S->getOutputConstraint(I));
350   }
351 
352   // Inputs
353   for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
354     Record.AddStmt(S->getInputExpr(I));
355     Record.AddString(S->getInputConstraint(I));
356   }
357 
358   Code = serialization::STMT_MSASM;
359 }
360 
361 void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
362   VisitStmt(CoroStmt);
363   Record.push_back(CoroStmt->getParamMoves().size());
364   for (Stmt *S : CoroStmt->children())
365     Record.AddStmt(S);
366   Code = serialization::STMT_COROUTINE_BODY;
367 }
368 
369 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
370   VisitStmt(S);
371   Record.AddSourceLocation(S->getKeywordLoc());
372   Record.AddStmt(S->getOperand());
373   Record.AddStmt(S->getPromiseCall());
374   Record.push_back(S->isImplicit());
375   Code = serialization::STMT_CORETURN;
376 }
377 
378 void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
379   VisitExpr(E);
380   Record.AddSourceLocation(E->getKeywordLoc());
381   for (Stmt *S : E->children())
382     Record.AddStmt(S);
383   Record.AddStmt(E->getOpaqueValue());
384 }
385 
386 void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
387   VisitCoroutineSuspendExpr(E);
388   Record.push_back(E->isImplicit());
389   Code = serialization::EXPR_COAWAIT;
390 }
391 
392 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
393   VisitCoroutineSuspendExpr(E);
394   Code = serialization::EXPR_COYIELD;
395 }
396 
397 void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
398   VisitExpr(E);
399   Record.AddSourceLocation(E->getKeywordLoc());
400   for (Stmt *S : E->children())
401     Record.AddStmt(S);
402   Code = serialization::EXPR_DEPENDENT_COAWAIT;
403 }
404 
405 static void
406 addConstraintSatisfaction(ASTRecordWriter &Record,
407                           const ASTConstraintSatisfaction &Satisfaction) {
408   Record.push_back(Satisfaction.IsSatisfied);
409   Record.push_back(Satisfaction.ContainsErrors);
410   if (!Satisfaction.IsSatisfied) {
411     Record.push_back(Satisfaction.NumRecords);
412     for (const auto &DetailRecord : Satisfaction) {
413       Record.AddStmt(const_cast<Expr *>(DetailRecord.first));
414       auto *E = DetailRecord.second.dyn_cast<Expr *>();
415       Record.push_back(E == nullptr);
416       if (E)
417         Record.AddStmt(E);
418       else {
419         auto *Diag = DetailRecord.second.get<std::pair<SourceLocation,
420                                                        StringRef> *>();
421         Record.AddSourceLocation(Diag->first);
422         Record.AddString(Diag->second);
423       }
424     }
425   }
426 }
427 
428 static void
429 addSubstitutionDiagnostic(
430     ASTRecordWriter &Record,
431     const concepts::Requirement::SubstitutionDiagnostic *D) {
432   Record.AddString(D->SubstitutedEntity);
433   Record.AddSourceLocation(D->DiagLoc);
434   Record.AddString(D->DiagMessage);
435 }
436 
437 void ASTStmtWriter::VisitConceptSpecializationExpr(
438         ConceptSpecializationExpr *E) {
439   VisitExpr(E);
440   Record.AddNestedNameSpecifierLoc(E->getNestedNameSpecifierLoc());
441   Record.AddSourceLocation(E->getTemplateKWLoc());
442   Record.AddDeclarationNameInfo(E->getConceptNameInfo());
443   Record.AddDeclRef(E->getNamedConcept());
444   Record.AddDeclRef(E->getFoundDecl());
445   Record.AddDeclRef(E->getSpecializationDecl());
446   Record.AddASTTemplateArgumentListInfo(E->getTemplateArgsAsWritten());
447   if (!E->isValueDependent())
448     addConstraintSatisfaction(Record, E->getSatisfaction());
449 
450   Code = serialization::EXPR_CONCEPT_SPECIALIZATION;
451 }
452 
453 void ASTStmtWriter::VisitRequiresExpr(RequiresExpr *E) {
454   VisitExpr(E);
455   Record.push_back(E->getLocalParameters().size());
456   Record.push_back(E->getRequirements().size());
457   Record.AddSourceLocation(E->RequiresExprBits.RequiresKWLoc);
458   Record.push_back(E->RequiresExprBits.IsSatisfied);
459   Record.AddDeclRef(E->getBody());
460   for (ParmVarDecl *P : E->getLocalParameters())
461     Record.AddDeclRef(P);
462   for (concepts::Requirement *R : E->getRequirements()) {
463     if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(R)) {
464       Record.push_back(concepts::Requirement::RK_Type);
465       Record.push_back(TypeReq->Status);
466       if (TypeReq->Status == concepts::TypeRequirement::SS_SubstitutionFailure)
467         addSubstitutionDiagnostic(Record, TypeReq->getSubstitutionDiagnostic());
468       else
469         Record.AddTypeSourceInfo(TypeReq->getType());
470     } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(R)) {
471       Record.push_back(ExprReq->getKind());
472       Record.push_back(ExprReq->Status);
473       if (ExprReq->isExprSubstitutionFailure()) {
474         addSubstitutionDiagnostic(Record,
475          ExprReq->Value.get<concepts::Requirement::SubstitutionDiagnostic *>());
476       } else
477         Record.AddStmt(ExprReq->Value.get<Expr *>());
478       if (ExprReq->getKind() == concepts::Requirement::RK_Compound) {
479         Record.AddSourceLocation(ExprReq->NoexceptLoc);
480         const auto &RetReq = ExprReq->getReturnTypeRequirement();
481         if (RetReq.isSubstitutionFailure()) {
482           Record.push_back(2);
483           addSubstitutionDiagnostic(Record, RetReq.getSubstitutionDiagnostic());
484         } else if (RetReq.isTypeConstraint()) {
485           Record.push_back(1);
486           Record.AddTemplateParameterList(
487               RetReq.getTypeConstraintTemplateParameterList());
488           if (ExprReq->Status >=
489               concepts::ExprRequirement::SS_ConstraintsNotSatisfied)
490             Record.AddStmt(
491                 ExprReq->getReturnTypeRequirementSubstitutedConstraintExpr());
492         } else {
493           assert(RetReq.isEmpty());
494           Record.push_back(0);
495         }
496       }
497     } else {
498       auto *NestedReq = cast<concepts::NestedRequirement>(R);
499       Record.push_back(concepts::Requirement::RK_Nested);
500       Record.push_back(NestedReq->hasInvalidConstraint());
501       if (NestedReq->hasInvalidConstraint()) {
502         Record.AddString(NestedReq->getInvalidConstraintEntity());
503         addConstraintSatisfaction(Record, *NestedReq->Satisfaction);
504       } else {
505         Record.AddStmt(NestedReq->getConstraintExpr());
506         if (!NestedReq->isDependent())
507           addConstraintSatisfaction(Record, *NestedReq->Satisfaction);
508       }
509     }
510   }
511   Record.AddSourceLocation(E->getEndLoc());
512 
513   Code = serialization::EXPR_REQUIRES;
514 }
515 
516 
517 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
518   VisitStmt(S);
519   // NumCaptures
520   Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
521 
522   // CapturedDecl and captured region kind
523   Record.AddDeclRef(S->getCapturedDecl());
524   Record.push_back(S->getCapturedRegionKind());
525 
526   Record.AddDeclRef(S->getCapturedRecordDecl());
527 
528   // Capture inits
529   for (auto *I : S->capture_inits())
530     Record.AddStmt(I);
531 
532   // Body
533   Record.AddStmt(S->getCapturedStmt());
534 
535   // Captures
536   for (const auto &I : S->captures()) {
537     if (I.capturesThis() || I.capturesVariableArrayType())
538       Record.AddDeclRef(nullptr);
539     else
540       Record.AddDeclRef(I.getCapturedVar());
541     Record.push_back(I.getCaptureKind());
542     Record.AddSourceLocation(I.getLocation());
543   }
544 
545   Code = serialization::STMT_CAPTURED;
546 }
547 
548 void ASTStmtWriter::VisitExpr(Expr *E) {
549   VisitStmt(E);
550   Record.AddTypeRef(E->getType());
551   Record.push_back(E->getDependence());
552   Record.push_back(E->getValueKind());
553   Record.push_back(E->getObjectKind());
554 }
555 
556 void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
557   VisitExpr(E);
558   Record.push_back(E->ConstantExprBits.ResultKind);
559 
560   Record.push_back(E->ConstantExprBits.APValueKind);
561   Record.push_back(E->ConstantExprBits.IsUnsigned);
562   Record.push_back(E->ConstantExprBits.BitWidth);
563   // HasCleanup not serialized since we can just query the APValue.
564   Record.push_back(E->ConstantExprBits.IsImmediateInvocation);
565 
566   switch (E->ConstantExprBits.ResultKind) {
567   case ConstantExpr::RSK_None:
568     break;
569   case ConstantExpr::RSK_Int64:
570     Record.push_back(E->Int64Result());
571     break;
572   case ConstantExpr::RSK_APValue:
573     Record.AddAPValue(E->APValueResult());
574     break;
575   default:
576     llvm_unreachable("unexpected ResultKind!");
577   }
578 
579   Record.AddStmt(E->getSubExpr());
580   Code = serialization::EXPR_CONSTANT;
581 }
582 
583 void ASTStmtWriter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
584   VisitExpr(E);
585 
586   Record.AddSourceLocation(E->getLocation());
587   Record.AddSourceLocation(E->getLParenLocation());
588   Record.AddSourceLocation(E->getRParenLocation());
589   Record.AddTypeSourceInfo(E->getTypeSourceInfo());
590 
591   Code = serialization::EXPR_SYCL_UNIQUE_STABLE_NAME;
592 }
593 
594 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
595   VisitExpr(E);
596 
597   bool HasFunctionName = E->getFunctionName() != nullptr;
598   Record.push_back(HasFunctionName);
599   Record.push_back(E->getIdentKind()); // FIXME: stable encoding
600   Record.push_back(E->isTransparent());
601   Record.AddSourceLocation(E->getLocation());
602   if (HasFunctionName)
603     Record.AddStmt(E->getFunctionName());
604   Code = serialization::EXPR_PREDEFINED;
605 }
606 
607 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
608   VisitExpr(E);
609 
610   Record.push_back(E->hasQualifier());
611   Record.push_back(E->getDecl() != E->getFoundDecl());
612   Record.push_back(E->hasTemplateKWAndArgsInfo());
613   Record.push_back(E->hadMultipleCandidates());
614   Record.push_back(E->refersToEnclosingVariableOrCapture());
615   Record.push_back(E->isNonOdrUse());
616   Record.push_back(E->isImmediateEscalating());
617 
618   if (E->hasTemplateKWAndArgsInfo()) {
619     unsigned NumTemplateArgs = E->getNumTemplateArgs();
620     Record.push_back(NumTemplateArgs);
621   }
622 
623   DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
624 
625   if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
626       (E->getDecl() == E->getFoundDecl()) &&
627       nk == DeclarationName::Identifier &&
628       !E->refersToEnclosingVariableOrCapture() && !E->isNonOdrUse() &&
629       !E->isImmediateEscalating()) {
630     AbbrevToUse = Writer.getDeclRefExprAbbrev();
631   }
632 
633   if (E->hasQualifier())
634     Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
635 
636   if (E->getDecl() != E->getFoundDecl())
637     Record.AddDeclRef(E->getFoundDecl());
638 
639   if (E->hasTemplateKWAndArgsInfo())
640     AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
641                              E->getTrailingObjects<TemplateArgumentLoc>());
642 
643   Record.AddDeclRef(E->getDecl());
644   Record.AddSourceLocation(E->getLocation());
645   Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
646   Code = serialization::EXPR_DECL_REF;
647 }
648 
649 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
650   VisitExpr(E);
651   Record.AddSourceLocation(E->getLocation());
652   Record.AddAPInt(E->getValue());
653 
654   if (E->getValue().getBitWidth() == 32) {
655     AbbrevToUse = Writer.getIntegerLiteralAbbrev();
656   }
657 
658   Code = serialization::EXPR_INTEGER_LITERAL;
659 }
660 
661 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
662   VisitExpr(E);
663   Record.AddSourceLocation(E->getLocation());
664   Record.push_back(E->getScale());
665   Record.AddAPInt(E->getValue());
666   Code = serialization::EXPR_FIXEDPOINT_LITERAL;
667 }
668 
669 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
670   VisitExpr(E);
671   Record.push_back(E->getRawSemantics());
672   Record.push_back(E->isExact());
673   Record.AddAPFloat(E->getValue());
674   Record.AddSourceLocation(E->getLocation());
675   Code = serialization::EXPR_FLOATING_LITERAL;
676 }
677 
678 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
679   VisitExpr(E);
680   Record.AddStmt(E->getSubExpr());
681   Code = serialization::EXPR_IMAGINARY_LITERAL;
682 }
683 
684 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
685   VisitExpr(E);
686 
687   // Store the various bits of data of StringLiteral.
688   Record.push_back(E->getNumConcatenated());
689   Record.push_back(E->getLength());
690   Record.push_back(E->getCharByteWidth());
691   Record.push_back(E->getKind());
692   Record.push_back(E->isPascal());
693 
694   // Store the trailing array of SourceLocation.
695   for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
696     Record.AddSourceLocation(E->getStrTokenLoc(I));
697 
698   // Store the trailing array of char holding the string data.
699   StringRef StrData = E->getBytes();
700   for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
701     Record.push_back(StrData[I]);
702 
703   Code = serialization::EXPR_STRING_LITERAL;
704 }
705 
706 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
707   VisitExpr(E);
708   Record.push_back(E->getValue());
709   Record.AddSourceLocation(E->getLocation());
710   Record.push_back(E->getKind());
711 
712   AbbrevToUse = Writer.getCharacterLiteralAbbrev();
713 
714   Code = serialization::EXPR_CHARACTER_LITERAL;
715 }
716 
717 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
718   VisitExpr(E);
719   Record.AddSourceLocation(E->getLParen());
720   Record.AddSourceLocation(E->getRParen());
721   Record.AddStmt(E->getSubExpr());
722   Code = serialization::EXPR_PAREN;
723 }
724 
725 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
726   VisitExpr(E);
727   Record.push_back(E->getNumExprs());
728   for (auto *SubStmt : E->exprs())
729     Record.AddStmt(SubStmt);
730   Record.AddSourceLocation(E->getLParenLoc());
731   Record.AddSourceLocation(E->getRParenLoc());
732   Code = serialization::EXPR_PAREN_LIST;
733 }
734 
735 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
736   VisitExpr(E);
737   bool HasFPFeatures = E->hasStoredFPFeatures();
738   // Write this first for easy access when deserializing, as they affect the
739   // size of the UnaryOperator.
740   Record.push_back(HasFPFeatures);
741   Record.AddStmt(E->getSubExpr());
742   Record.push_back(E->getOpcode()); // FIXME: stable encoding
743   Record.AddSourceLocation(E->getOperatorLoc());
744   Record.push_back(E->canOverflow());
745   if (HasFPFeatures)
746     Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt());
747   Code = serialization::EXPR_UNARY_OPERATOR;
748 }
749 
750 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
751   VisitExpr(E);
752   Record.push_back(E->getNumComponents());
753   Record.push_back(E->getNumExpressions());
754   Record.AddSourceLocation(E->getOperatorLoc());
755   Record.AddSourceLocation(E->getRParenLoc());
756   Record.AddTypeSourceInfo(E->getTypeSourceInfo());
757   for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
758     const OffsetOfNode &ON = E->getComponent(I);
759     Record.push_back(ON.getKind()); // FIXME: Stable encoding
760     Record.AddSourceLocation(ON.getSourceRange().getBegin());
761     Record.AddSourceLocation(ON.getSourceRange().getEnd());
762     switch (ON.getKind()) {
763     case OffsetOfNode::Array:
764       Record.push_back(ON.getArrayExprIndex());
765       break;
766 
767     case OffsetOfNode::Field:
768       Record.AddDeclRef(ON.getField());
769       break;
770 
771     case OffsetOfNode::Identifier:
772       Record.AddIdentifierRef(ON.getFieldName());
773       break;
774 
775     case OffsetOfNode::Base:
776       Record.AddCXXBaseSpecifier(*ON.getBase());
777       break;
778     }
779   }
780   for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
781     Record.AddStmt(E->getIndexExpr(I));
782   Code = serialization::EXPR_OFFSETOF;
783 }
784 
785 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
786   VisitExpr(E);
787   Record.push_back(E->getKind());
788   if (E->isArgumentType())
789     Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
790   else {
791     Record.push_back(0);
792     Record.AddStmt(E->getArgumentExpr());
793   }
794   Record.AddSourceLocation(E->getOperatorLoc());
795   Record.AddSourceLocation(E->getRParenLoc());
796   Code = serialization::EXPR_SIZEOF_ALIGN_OF;
797 }
798 
799 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
800   VisitExpr(E);
801   Record.AddStmt(E->getLHS());
802   Record.AddStmt(E->getRHS());
803   Record.AddSourceLocation(E->getRBracketLoc());
804   Code = serialization::EXPR_ARRAY_SUBSCRIPT;
805 }
806 
807 void ASTStmtWriter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
808   VisitExpr(E);
809   Record.AddStmt(E->getBase());
810   Record.AddStmt(E->getRowIdx());
811   Record.AddStmt(E->getColumnIdx());
812   Record.AddSourceLocation(E->getRBracketLoc());
813   Code = serialization::EXPR_ARRAY_SUBSCRIPT;
814 }
815 
816 void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
817   VisitExpr(E);
818   Record.AddStmt(E->getBase());
819   Record.AddStmt(E->getLowerBound());
820   Record.AddStmt(E->getLength());
821   Record.AddStmt(E->getStride());
822   Record.AddSourceLocation(E->getColonLocFirst());
823   Record.AddSourceLocation(E->getColonLocSecond());
824   Record.AddSourceLocation(E->getRBracketLoc());
825   Code = serialization::EXPR_OMP_ARRAY_SECTION;
826 }
827 
828 void ASTStmtWriter::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
829   VisitExpr(E);
830   Record.push_back(E->getDimensions().size());
831   Record.AddStmt(E->getBase());
832   for (Expr *Dim : E->getDimensions())
833     Record.AddStmt(Dim);
834   for (SourceRange SR : E->getBracketsRanges())
835     Record.AddSourceRange(SR);
836   Record.AddSourceLocation(E->getLParenLoc());
837   Record.AddSourceLocation(E->getRParenLoc());
838   Code = serialization::EXPR_OMP_ARRAY_SHAPING;
839 }
840 
841 void ASTStmtWriter::VisitOMPIteratorExpr(OMPIteratorExpr *E) {
842   VisitExpr(E);
843   Record.push_back(E->numOfIterators());
844   Record.AddSourceLocation(E->getIteratorKwLoc());
845   Record.AddSourceLocation(E->getLParenLoc());
846   Record.AddSourceLocation(E->getRParenLoc());
847   for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) {
848     Record.AddDeclRef(E->getIteratorDecl(I));
849     Record.AddSourceLocation(E->getAssignLoc(I));
850     OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
851     Record.AddStmt(Range.Begin);
852     Record.AddStmt(Range.End);
853     Record.AddStmt(Range.Step);
854     Record.AddSourceLocation(E->getColonLoc(I));
855     if (Range.Step)
856       Record.AddSourceLocation(E->getSecondColonLoc(I));
857     // Serialize helpers
858     OMPIteratorHelperData &HD = E->getHelper(I);
859     Record.AddDeclRef(HD.CounterVD);
860     Record.AddStmt(HD.Upper);
861     Record.AddStmt(HD.Update);
862     Record.AddStmt(HD.CounterUpdate);
863   }
864   Code = serialization::EXPR_OMP_ITERATOR;
865 }
866 
867 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
868   VisitExpr(E);
869   Record.push_back(E->getNumArgs());
870   Record.push_back(E->hasStoredFPFeatures());
871   Record.AddSourceLocation(E->getRParenLoc());
872   Record.AddStmt(E->getCallee());
873   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
874        Arg != ArgEnd; ++Arg)
875     Record.AddStmt(*Arg);
876   Record.push_back(static_cast<unsigned>(E->getADLCallKind()));
877   if (E->hasStoredFPFeatures())
878     Record.push_back(E->getFPFeatures().getAsOpaqueInt());
879   Code = serialization::EXPR_CALL;
880 }
881 
882 void ASTStmtWriter::VisitRecoveryExpr(RecoveryExpr *E) {
883   VisitExpr(E);
884   Record.push_back(std::distance(E->children().begin(), E->children().end()));
885   Record.AddSourceLocation(E->getBeginLoc());
886   Record.AddSourceLocation(E->getEndLoc());
887   for (Stmt *Child : E->children())
888     Record.AddStmt(Child);
889   Code = serialization::EXPR_RECOVERY;
890 }
891 
892 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
893   VisitExpr(E);
894 
895   bool HasQualifier = E->hasQualifier();
896   bool HasFoundDecl =
897       E->hasQualifierOrFoundDecl() &&
898       (E->getFoundDecl().getDecl() != E->getMemberDecl() ||
899        E->getFoundDecl().getAccess() != E->getMemberDecl()->getAccess());
900   bool HasTemplateInfo = E->hasTemplateKWAndArgsInfo();
901   unsigned NumTemplateArgs = E->getNumTemplateArgs();
902 
903   // Write these first for easy access when deserializing, as they affect the
904   // size of the MemberExpr.
905   Record.push_back(HasQualifier);
906   Record.push_back(HasFoundDecl);
907   Record.push_back(HasTemplateInfo);
908   Record.push_back(NumTemplateArgs);
909 
910   Record.AddStmt(E->getBase());
911   Record.AddDeclRef(E->getMemberDecl());
912   Record.AddDeclarationNameLoc(E->MemberDNLoc,
913                                E->getMemberDecl()->getDeclName());
914   Record.AddSourceLocation(E->getMemberLoc());
915   Record.push_back(E->isArrow());
916   Record.push_back(E->hadMultipleCandidates());
917   Record.push_back(E->isNonOdrUse());
918   Record.AddSourceLocation(E->getOperatorLoc());
919 
920   if (HasFoundDecl) {
921     DeclAccessPair FoundDecl = E->getFoundDecl();
922     Record.AddDeclRef(FoundDecl.getDecl());
923     Record.push_back(FoundDecl.getAccess());
924   }
925 
926   if (HasQualifier)
927     Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
928 
929   if (HasTemplateInfo)
930     AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
931                              E->getTrailingObjects<TemplateArgumentLoc>());
932 
933   Code = serialization::EXPR_MEMBER;
934 }
935 
936 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
937   VisitExpr(E);
938   Record.AddStmt(E->getBase());
939   Record.AddSourceLocation(E->getIsaMemberLoc());
940   Record.AddSourceLocation(E->getOpLoc());
941   Record.push_back(E->isArrow());
942   Code = serialization::EXPR_OBJC_ISA;
943 }
944 
945 void ASTStmtWriter::
946 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
947   VisitExpr(E);
948   Record.AddStmt(E->getSubExpr());
949   Record.push_back(E->shouldCopy());
950   Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
951 }
952 
953 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
954   VisitExplicitCastExpr(E);
955   Record.AddSourceLocation(E->getLParenLoc());
956   Record.AddSourceLocation(E->getBridgeKeywordLoc());
957   Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
958   Code = serialization::EXPR_OBJC_BRIDGED_CAST;
959 }
960 
961 void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
962   VisitExpr(E);
963   Record.push_back(E->path_size());
964   Record.push_back(E->hasStoredFPFeatures());
965   Record.AddStmt(E->getSubExpr());
966   Record.push_back(E->getCastKind()); // FIXME: stable encoding
967 
968   for (CastExpr::path_iterator
969          PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
970     Record.AddCXXBaseSpecifier(**PI);
971 
972   if (E->hasStoredFPFeatures())
973     Record.push_back(E->getFPFeatures().getAsOpaqueInt());
974 }
975 
976 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
977   VisitExpr(E);
978   bool HasFPFeatures = E->hasStoredFPFeatures();
979   // Write this first for easy access when deserializing, as they affect the
980   // size of the UnaryOperator.
981   Record.push_back(HasFPFeatures);
982   Record.push_back(E->getOpcode()); // FIXME: stable encoding
983   Record.AddStmt(E->getLHS());
984   Record.AddStmt(E->getRHS());
985   Record.AddSourceLocation(E->getOperatorLoc());
986   if (HasFPFeatures)
987     Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt());
988   Code = serialization::EXPR_BINARY_OPERATOR;
989 }
990 
991 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
992   VisitBinaryOperator(E);
993   Record.AddTypeRef(E->getComputationLHSType());
994   Record.AddTypeRef(E->getComputationResultType());
995   Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
996 }
997 
998 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
999   VisitExpr(E);
1000   Record.AddStmt(E->getCond());
1001   Record.AddStmt(E->getLHS());
1002   Record.AddStmt(E->getRHS());
1003   Record.AddSourceLocation(E->getQuestionLoc());
1004   Record.AddSourceLocation(E->getColonLoc());
1005   Code = serialization::EXPR_CONDITIONAL_OPERATOR;
1006 }
1007 
1008 void
1009 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
1010   VisitExpr(E);
1011   Record.AddStmt(E->getOpaqueValue());
1012   Record.AddStmt(E->getCommon());
1013   Record.AddStmt(E->getCond());
1014   Record.AddStmt(E->getTrueExpr());
1015   Record.AddStmt(E->getFalseExpr());
1016   Record.AddSourceLocation(E->getQuestionLoc());
1017   Record.AddSourceLocation(E->getColonLoc());
1018   Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
1019 }
1020 
1021 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
1022   VisitCastExpr(E);
1023   Record.push_back(E->isPartOfExplicitCast());
1024 
1025   if (E->path_size() == 0 && !E->hasStoredFPFeatures())
1026     AbbrevToUse = Writer.getExprImplicitCastAbbrev();
1027 
1028   Code = serialization::EXPR_IMPLICIT_CAST;
1029 }
1030 
1031 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
1032   VisitCastExpr(E);
1033   Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
1034 }
1035 
1036 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
1037   VisitExplicitCastExpr(E);
1038   Record.AddSourceLocation(E->getLParenLoc());
1039   Record.AddSourceLocation(E->getRParenLoc());
1040   Code = serialization::EXPR_CSTYLE_CAST;
1041 }
1042 
1043 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
1044   VisitExpr(E);
1045   Record.AddSourceLocation(E->getLParenLoc());
1046   Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1047   Record.AddStmt(E->getInitializer());
1048   Record.push_back(E->isFileScope());
1049   Code = serialization::EXPR_COMPOUND_LITERAL;
1050 }
1051 
1052 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
1053   VisitExpr(E);
1054   Record.AddStmt(E->getBase());
1055   Record.AddIdentifierRef(&E->getAccessor());
1056   Record.AddSourceLocation(E->getAccessorLoc());
1057   Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
1058 }
1059 
1060 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
1061   VisitExpr(E);
1062   // NOTE: only add the (possibly null) syntactic form.
1063   // No need to serialize the isSemanticForm flag and the semantic form.
1064   Record.AddStmt(E->getSyntacticForm());
1065   Record.AddSourceLocation(E->getLBraceLoc());
1066   Record.AddSourceLocation(E->getRBraceLoc());
1067   bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
1068   Record.push_back(isArrayFiller);
1069   if (isArrayFiller)
1070     Record.AddStmt(E->getArrayFiller());
1071   else
1072     Record.AddDeclRef(E->getInitializedFieldInUnion());
1073   Record.push_back(E->hadArrayRangeDesignator());
1074   Record.push_back(E->getNumInits());
1075   if (isArrayFiller) {
1076     // ArrayFiller may have filled "holes" due to designated initializer.
1077     // Replace them by 0 to indicate that the filler goes in that place.
1078     Expr *filler = E->getArrayFiller();
1079     for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
1080       Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
1081   } else {
1082     for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
1083       Record.AddStmt(E->getInit(I));
1084   }
1085   Code = serialization::EXPR_INIT_LIST;
1086 }
1087 
1088 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
1089   VisitExpr(E);
1090   Record.push_back(E->getNumSubExprs());
1091   for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1092     Record.AddStmt(E->getSubExpr(I));
1093   Record.AddSourceLocation(E->getEqualOrColonLoc());
1094   Record.push_back(E->usesGNUSyntax());
1095   for (const DesignatedInitExpr::Designator &D : E->designators()) {
1096     if (D.isFieldDesignator()) {
1097       if (FieldDecl *Field = D.getFieldDecl()) {
1098         Record.push_back(serialization::DESIG_FIELD_DECL);
1099         Record.AddDeclRef(Field);
1100       } else {
1101         Record.push_back(serialization::DESIG_FIELD_NAME);
1102         Record.AddIdentifierRef(D.getFieldName());
1103       }
1104       Record.AddSourceLocation(D.getDotLoc());
1105       Record.AddSourceLocation(D.getFieldLoc());
1106     } else if (D.isArrayDesignator()) {
1107       Record.push_back(serialization::DESIG_ARRAY);
1108       Record.push_back(D.getArrayIndex());
1109       Record.AddSourceLocation(D.getLBracketLoc());
1110       Record.AddSourceLocation(D.getRBracketLoc());
1111     } else {
1112       assert(D.isArrayRangeDesignator() && "Unknown designator");
1113       Record.push_back(serialization::DESIG_ARRAY_RANGE);
1114       Record.push_back(D.getArrayIndex());
1115       Record.AddSourceLocation(D.getLBracketLoc());
1116       Record.AddSourceLocation(D.getEllipsisLoc());
1117       Record.AddSourceLocation(D.getRBracketLoc());
1118     }
1119   }
1120   Code = serialization::EXPR_DESIGNATED_INIT;
1121 }
1122 
1123 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
1124   VisitExpr(E);
1125   Record.AddStmt(E->getBase());
1126   Record.AddStmt(E->getUpdater());
1127   Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
1128 }
1129 
1130 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
1131   VisitExpr(E);
1132   Code = serialization::EXPR_NO_INIT;
1133 }
1134 
1135 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
1136   VisitExpr(E);
1137   Record.AddStmt(E->SubExprs[0]);
1138   Record.AddStmt(E->SubExprs[1]);
1139   Code = serialization::EXPR_ARRAY_INIT_LOOP;
1140 }
1141 
1142 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
1143   VisitExpr(E);
1144   Code = serialization::EXPR_ARRAY_INIT_INDEX;
1145 }
1146 
1147 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
1148   VisitExpr(E);
1149   Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
1150 }
1151 
1152 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
1153   VisitExpr(E);
1154   Record.AddStmt(E->getSubExpr());
1155   Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
1156   Record.AddSourceLocation(E->getBuiltinLoc());
1157   Record.AddSourceLocation(E->getRParenLoc());
1158   Record.push_back(E->isMicrosoftABI());
1159   Code = serialization::EXPR_VA_ARG;
1160 }
1161 
1162 void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) {
1163   VisitExpr(E);
1164   Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext()));
1165   Record.AddSourceLocation(E->getBeginLoc());
1166   Record.AddSourceLocation(E->getEndLoc());
1167   Record.push_back(E->getIdentKind());
1168   Code = serialization::EXPR_SOURCE_LOC;
1169 }
1170 
1171 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
1172   VisitExpr(E);
1173   Record.AddSourceLocation(E->getAmpAmpLoc());
1174   Record.AddSourceLocation(E->getLabelLoc());
1175   Record.AddDeclRef(E->getLabel());
1176   Code = serialization::EXPR_ADDR_LABEL;
1177 }
1178 
1179 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
1180   VisitExpr(E);
1181   Record.AddStmt(E->getSubStmt());
1182   Record.AddSourceLocation(E->getLParenLoc());
1183   Record.AddSourceLocation(E->getRParenLoc());
1184   Record.push_back(E->getTemplateDepth());
1185   Code = serialization::EXPR_STMT;
1186 }
1187 
1188 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
1189   VisitExpr(E);
1190   Record.AddStmt(E->getCond());
1191   Record.AddStmt(E->getLHS());
1192   Record.AddStmt(E->getRHS());
1193   Record.AddSourceLocation(E->getBuiltinLoc());
1194   Record.AddSourceLocation(E->getRParenLoc());
1195   Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
1196   Code = serialization::EXPR_CHOOSE;
1197 }
1198 
1199 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
1200   VisitExpr(E);
1201   Record.AddSourceLocation(E->getTokenLocation());
1202   Code = serialization::EXPR_GNU_NULL;
1203 }
1204 
1205 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
1206   VisitExpr(E);
1207   Record.push_back(E->getNumSubExprs());
1208   for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1209     Record.AddStmt(E->getExpr(I));
1210   Record.AddSourceLocation(E->getBuiltinLoc());
1211   Record.AddSourceLocation(E->getRParenLoc());
1212   Code = serialization::EXPR_SHUFFLE_VECTOR;
1213 }
1214 
1215 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
1216   VisitExpr(E);
1217   Record.AddSourceLocation(E->getBuiltinLoc());
1218   Record.AddSourceLocation(E->getRParenLoc());
1219   Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1220   Record.AddStmt(E->getSrcExpr());
1221   Code = serialization::EXPR_CONVERT_VECTOR;
1222 }
1223 
1224 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
1225   VisitExpr(E);
1226   Record.AddDeclRef(E->getBlockDecl());
1227   Code = serialization::EXPR_BLOCK;
1228 }
1229 
1230 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
1231   VisitExpr(E);
1232 
1233   Record.push_back(E->getNumAssocs());
1234   Record.push_back(E->isExprPredicate());
1235   Record.push_back(E->ResultIndex);
1236   Record.AddSourceLocation(E->getGenericLoc());
1237   Record.AddSourceLocation(E->getDefaultLoc());
1238   Record.AddSourceLocation(E->getRParenLoc());
1239 
1240   Stmt **Stmts = E->getTrailingObjects<Stmt *>();
1241   // Add 1 to account for the controlling expression which is the first
1242   // expression in the trailing array of Stmt *. This is not needed for
1243   // the trailing array of TypeSourceInfo *.
1244   for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I)
1245     Record.AddStmt(Stmts[I]);
1246 
1247   TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
1248   for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I)
1249     Record.AddTypeSourceInfo(TSIs[I]);
1250 
1251   Code = serialization::EXPR_GENERIC_SELECTION;
1252 }
1253 
1254 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
1255   VisitExpr(E);
1256   Record.push_back(E->getNumSemanticExprs());
1257 
1258   // Push the result index.  Currently, this needs to exactly match
1259   // the encoding used internally for ResultIndex.
1260   unsigned result = E->getResultExprIndex();
1261   result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
1262   Record.push_back(result);
1263 
1264   Record.AddStmt(E->getSyntacticForm());
1265   for (PseudoObjectExpr::semantics_iterator
1266          i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
1267     Record.AddStmt(*i);
1268   }
1269   Code = serialization::EXPR_PSEUDO_OBJECT;
1270 }
1271 
1272 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
1273   VisitExpr(E);
1274   Record.push_back(E->getOp());
1275   for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1276     Record.AddStmt(E->getSubExprs()[I]);
1277   Record.AddSourceLocation(E->getBuiltinLoc());
1278   Record.AddSourceLocation(E->getRParenLoc());
1279   Code = serialization::EXPR_ATOMIC;
1280 }
1281 
1282 //===----------------------------------------------------------------------===//
1283 // Objective-C Expressions and Statements.
1284 //===----------------------------------------------------------------------===//
1285 
1286 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
1287   VisitExpr(E);
1288   Record.AddStmt(E->getString());
1289   Record.AddSourceLocation(E->getAtLoc());
1290   Code = serialization::EXPR_OBJC_STRING_LITERAL;
1291 }
1292 
1293 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1294   VisitExpr(E);
1295   Record.AddStmt(E->getSubExpr());
1296   Record.AddDeclRef(E->getBoxingMethod());
1297   Record.AddSourceRange(E->getSourceRange());
1298   Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
1299 }
1300 
1301 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1302   VisitExpr(E);
1303   Record.push_back(E->getNumElements());
1304   for (unsigned i = 0; i < E->getNumElements(); i++)
1305     Record.AddStmt(E->getElement(i));
1306   Record.AddDeclRef(E->getArrayWithObjectsMethod());
1307   Record.AddSourceRange(E->getSourceRange());
1308   Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1309 }
1310 
1311 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1312   VisitExpr(E);
1313   Record.push_back(E->getNumElements());
1314   Record.push_back(E->HasPackExpansions);
1315   for (unsigned i = 0; i < E->getNumElements(); i++) {
1316     ObjCDictionaryElement Element = E->getKeyValueElement(i);
1317     Record.AddStmt(Element.Key);
1318     Record.AddStmt(Element.Value);
1319     if (E->HasPackExpansions) {
1320       Record.AddSourceLocation(Element.EllipsisLoc);
1321       unsigned NumExpansions = 0;
1322       if (Element.NumExpansions)
1323         NumExpansions = *Element.NumExpansions + 1;
1324       Record.push_back(NumExpansions);
1325     }
1326   }
1327 
1328   Record.AddDeclRef(E->getDictWithObjectsMethod());
1329   Record.AddSourceRange(E->getSourceRange());
1330   Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1331 }
1332 
1333 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
1334   VisitExpr(E);
1335   Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1336   Record.AddSourceLocation(E->getAtLoc());
1337   Record.AddSourceLocation(E->getRParenLoc());
1338   Code = serialization::EXPR_OBJC_ENCODE;
1339 }
1340 
1341 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
1342   VisitExpr(E);
1343   Record.AddSelectorRef(E->getSelector());
1344   Record.AddSourceLocation(E->getAtLoc());
1345   Record.AddSourceLocation(E->getRParenLoc());
1346   Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
1347 }
1348 
1349 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
1350   VisitExpr(E);
1351   Record.AddDeclRef(E->getProtocol());
1352   Record.AddSourceLocation(E->getAtLoc());
1353   Record.AddSourceLocation(E->ProtoLoc);
1354   Record.AddSourceLocation(E->getRParenLoc());
1355   Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
1356 }
1357 
1358 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1359   VisitExpr(E);
1360   Record.AddDeclRef(E->getDecl());
1361   Record.AddSourceLocation(E->getLocation());
1362   Record.AddSourceLocation(E->getOpLoc());
1363   Record.AddStmt(E->getBase());
1364   Record.push_back(E->isArrow());
1365   Record.push_back(E->isFreeIvar());
1366   Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
1367 }
1368 
1369 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1370   VisitExpr(E);
1371   Record.push_back(E->SetterAndMethodRefFlags.getInt());
1372   Record.push_back(E->isImplicitProperty());
1373   if (E->isImplicitProperty()) {
1374     Record.AddDeclRef(E->getImplicitPropertyGetter());
1375     Record.AddDeclRef(E->getImplicitPropertySetter());
1376   } else {
1377     Record.AddDeclRef(E->getExplicitProperty());
1378   }
1379   Record.AddSourceLocation(E->getLocation());
1380   Record.AddSourceLocation(E->getReceiverLocation());
1381   if (E->isObjectReceiver()) {
1382     Record.push_back(0);
1383     Record.AddStmt(E->getBase());
1384   } else if (E->isSuperReceiver()) {
1385     Record.push_back(1);
1386     Record.AddTypeRef(E->getSuperReceiverType());
1387   } else {
1388     Record.push_back(2);
1389     Record.AddDeclRef(E->getClassReceiver());
1390   }
1391 
1392   Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
1393 }
1394 
1395 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1396   VisitExpr(E);
1397   Record.AddSourceLocation(E->getRBracket());
1398   Record.AddStmt(E->getBaseExpr());
1399   Record.AddStmt(E->getKeyExpr());
1400   Record.AddDeclRef(E->getAtIndexMethodDecl());
1401   Record.AddDeclRef(E->setAtIndexMethodDecl());
1402 
1403   Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1404 }
1405 
1406 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1407   VisitExpr(E);
1408   Record.push_back(E->getNumArgs());
1409   Record.push_back(E->getNumStoredSelLocs());
1410   Record.push_back(E->SelLocsKind);
1411   Record.push_back(E->isDelegateInitCall());
1412   Record.push_back(E->IsImplicit);
1413   Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1414   switch (E->getReceiverKind()) {
1415   case ObjCMessageExpr::Instance:
1416     Record.AddStmt(E->getInstanceReceiver());
1417     break;
1418 
1419   case ObjCMessageExpr::Class:
1420     Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
1421     break;
1422 
1423   case ObjCMessageExpr::SuperClass:
1424   case ObjCMessageExpr::SuperInstance:
1425     Record.AddTypeRef(E->getSuperType());
1426     Record.AddSourceLocation(E->getSuperLoc());
1427     break;
1428   }
1429 
1430   if (E->getMethodDecl()) {
1431     Record.push_back(1);
1432     Record.AddDeclRef(E->getMethodDecl());
1433   } else {
1434     Record.push_back(0);
1435     Record.AddSelectorRef(E->getSelector());
1436   }
1437 
1438   Record.AddSourceLocation(E->getLeftLoc());
1439   Record.AddSourceLocation(E->getRightLoc());
1440 
1441   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1442        Arg != ArgEnd; ++Arg)
1443     Record.AddStmt(*Arg);
1444 
1445   SourceLocation *Locs = E->getStoredSelLocs();
1446   for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1447     Record.AddSourceLocation(Locs[i]);
1448 
1449   Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1450 }
1451 
1452 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1453   VisitStmt(S);
1454   Record.AddStmt(S->getElement());
1455   Record.AddStmt(S->getCollection());
1456   Record.AddStmt(S->getBody());
1457   Record.AddSourceLocation(S->getForLoc());
1458   Record.AddSourceLocation(S->getRParenLoc());
1459   Code = serialization::STMT_OBJC_FOR_COLLECTION;
1460 }
1461 
1462 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1463   VisitStmt(S);
1464   Record.AddStmt(S->getCatchBody());
1465   Record.AddDeclRef(S->getCatchParamDecl());
1466   Record.AddSourceLocation(S->getAtCatchLoc());
1467   Record.AddSourceLocation(S->getRParenLoc());
1468   Code = serialization::STMT_OBJC_CATCH;
1469 }
1470 
1471 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1472   VisitStmt(S);
1473   Record.AddStmt(S->getFinallyBody());
1474   Record.AddSourceLocation(S->getAtFinallyLoc());
1475   Code = serialization::STMT_OBJC_FINALLY;
1476 }
1477 
1478 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1479   VisitStmt(S); // FIXME: no test coverage.
1480   Record.AddStmt(S->getSubStmt());
1481   Record.AddSourceLocation(S->getAtLoc());
1482   Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1483 }
1484 
1485 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1486   VisitStmt(S);
1487   Record.push_back(S->getNumCatchStmts());
1488   Record.push_back(S->getFinallyStmt() != nullptr);
1489   Record.AddStmt(S->getTryBody());
1490   for (ObjCAtCatchStmt *C : S->catch_stmts())
1491     Record.AddStmt(C);
1492   if (S->getFinallyStmt())
1493     Record.AddStmt(S->getFinallyStmt());
1494   Record.AddSourceLocation(S->getAtTryLoc());
1495   Code = serialization::STMT_OBJC_AT_TRY;
1496 }
1497 
1498 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1499   VisitStmt(S); // FIXME: no test coverage.
1500   Record.AddStmt(S->getSynchExpr());
1501   Record.AddStmt(S->getSynchBody());
1502   Record.AddSourceLocation(S->getAtSynchronizedLoc());
1503   Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1504 }
1505 
1506 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1507   VisitStmt(S); // FIXME: no test coverage.
1508   Record.AddStmt(S->getThrowExpr());
1509   Record.AddSourceLocation(S->getThrowLoc());
1510   Code = serialization::STMT_OBJC_AT_THROW;
1511 }
1512 
1513 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1514   VisitExpr(E);
1515   Record.push_back(E->getValue());
1516   Record.AddSourceLocation(E->getLocation());
1517   Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1518 }
1519 
1520 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1521   VisitExpr(E);
1522   Record.AddSourceRange(E->getSourceRange());
1523   Record.AddVersionTuple(E->getVersion());
1524   Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1525 }
1526 
1527 //===----------------------------------------------------------------------===//
1528 // C++ Expressions and Statements.
1529 //===----------------------------------------------------------------------===//
1530 
1531 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1532   VisitStmt(S);
1533   Record.AddSourceLocation(S->getCatchLoc());
1534   Record.AddDeclRef(S->getExceptionDecl());
1535   Record.AddStmt(S->getHandlerBlock());
1536   Code = serialization::STMT_CXX_CATCH;
1537 }
1538 
1539 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1540   VisitStmt(S);
1541   Record.push_back(S->getNumHandlers());
1542   Record.AddSourceLocation(S->getTryLoc());
1543   Record.AddStmt(S->getTryBlock());
1544   for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1545     Record.AddStmt(S->getHandler(i));
1546   Code = serialization::STMT_CXX_TRY;
1547 }
1548 
1549 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1550   VisitStmt(S);
1551   Record.AddSourceLocation(S->getForLoc());
1552   Record.AddSourceLocation(S->getCoawaitLoc());
1553   Record.AddSourceLocation(S->getColonLoc());
1554   Record.AddSourceLocation(S->getRParenLoc());
1555   Record.AddStmt(S->getInit());
1556   Record.AddStmt(S->getRangeStmt());
1557   Record.AddStmt(S->getBeginStmt());
1558   Record.AddStmt(S->getEndStmt());
1559   Record.AddStmt(S->getCond());
1560   Record.AddStmt(S->getInc());
1561   Record.AddStmt(S->getLoopVarStmt());
1562   Record.AddStmt(S->getBody());
1563   Code = serialization::STMT_CXX_FOR_RANGE;
1564 }
1565 
1566 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1567   VisitStmt(S);
1568   Record.AddSourceLocation(S->getKeywordLoc());
1569   Record.push_back(S->isIfExists());
1570   Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1571   Record.AddDeclarationNameInfo(S->getNameInfo());
1572   Record.AddStmt(S->getSubStmt());
1573   Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1574 }
1575 
1576 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1577   VisitCallExpr(E);
1578   Record.push_back(E->getOperator());
1579   Record.AddSourceRange(E->Range);
1580   Code = serialization::EXPR_CXX_OPERATOR_CALL;
1581 }
1582 
1583 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1584   VisitCallExpr(E);
1585   Code = serialization::EXPR_CXX_MEMBER_CALL;
1586 }
1587 
1588 void ASTStmtWriter::VisitCXXRewrittenBinaryOperator(
1589     CXXRewrittenBinaryOperator *E) {
1590   VisitExpr(E);
1591   Record.push_back(E->isReversed());
1592   Record.AddStmt(E->getSemanticForm());
1593   Code = serialization::EXPR_CXX_REWRITTEN_BINARY_OPERATOR;
1594 }
1595 
1596 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1597   VisitExpr(E);
1598 
1599   Record.push_back(E->getNumArgs());
1600   Record.push_back(E->isElidable());
1601   Record.push_back(E->hadMultipleCandidates());
1602   Record.push_back(E->isListInitialization());
1603   Record.push_back(E->isStdInitListInitialization());
1604   Record.push_back(E->requiresZeroInitialization());
1605   Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
1606   Record.push_back(E->isImmediateEscalating());
1607   Record.AddSourceLocation(E->getLocation());
1608   Record.AddDeclRef(E->getConstructor());
1609   Record.AddSourceRange(E->getParenOrBraceRange());
1610 
1611   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1612     Record.AddStmt(E->getArg(I));
1613 
1614   Code = serialization::EXPR_CXX_CONSTRUCT;
1615 }
1616 
1617 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1618   VisitExpr(E);
1619   Record.AddDeclRef(E->getConstructor());
1620   Record.AddSourceLocation(E->getLocation());
1621   Record.push_back(E->constructsVBase());
1622   Record.push_back(E->inheritedFromVBase());
1623   Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1624 }
1625 
1626 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1627   VisitCXXConstructExpr(E);
1628   Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1629   Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1630 }
1631 
1632 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1633   VisitExpr(E);
1634   Record.push_back(E->LambdaExprBits.NumCaptures);
1635   Record.AddSourceRange(E->IntroducerRange);
1636   Record.push_back(E->LambdaExprBits.CaptureDefault); // FIXME: stable encoding
1637   Record.AddSourceLocation(E->CaptureDefaultLoc);
1638   Record.push_back(E->LambdaExprBits.ExplicitParams);
1639   Record.push_back(E->LambdaExprBits.ExplicitResultType);
1640   Record.AddSourceLocation(E->ClosingBrace);
1641 
1642   // Add capture initializers.
1643   for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1644                                       CEnd = E->capture_init_end();
1645        C != CEnd; ++C) {
1646     Record.AddStmt(*C);
1647   }
1648 
1649   // Don't serialize the body. It belongs to the call operator declaration.
1650   // LambdaExpr only stores a copy of the Stmt *.
1651 
1652   Code = serialization::EXPR_LAMBDA;
1653 }
1654 
1655 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1656   VisitExpr(E);
1657   Record.AddStmt(E->getSubExpr());
1658   Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1659 }
1660 
1661 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1662   VisitExplicitCastExpr(E);
1663   Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1664   Record.AddSourceRange(E->getAngleBrackets());
1665 }
1666 
1667 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1668   VisitCXXNamedCastExpr(E);
1669   Code = serialization::EXPR_CXX_STATIC_CAST;
1670 }
1671 
1672 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1673   VisitCXXNamedCastExpr(E);
1674   Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1675 }
1676 
1677 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1678   VisitCXXNamedCastExpr(E);
1679   Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1680 }
1681 
1682 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1683   VisitCXXNamedCastExpr(E);
1684   Code = serialization::EXPR_CXX_CONST_CAST;
1685 }
1686 
1687 void ASTStmtWriter::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
1688   VisitCXXNamedCastExpr(E);
1689   Code = serialization::EXPR_CXX_ADDRSPACE_CAST;
1690 }
1691 
1692 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1693   VisitExplicitCastExpr(E);
1694   Record.AddSourceLocation(E->getLParenLoc());
1695   Record.AddSourceLocation(E->getRParenLoc());
1696   Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1697 }
1698 
1699 void ASTStmtWriter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
1700   VisitExplicitCastExpr(E);
1701   Record.AddSourceLocation(E->getBeginLoc());
1702   Record.AddSourceLocation(E->getEndLoc());
1703   Code = serialization::EXPR_BUILTIN_BIT_CAST;
1704 }
1705 
1706 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1707   VisitCallExpr(E);
1708   Record.AddSourceLocation(E->UDSuffixLoc);
1709   Code = serialization::EXPR_USER_DEFINED_LITERAL;
1710 }
1711 
1712 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1713   VisitExpr(E);
1714   Record.push_back(E->getValue());
1715   Record.AddSourceLocation(E->getLocation());
1716   Code = serialization::EXPR_CXX_BOOL_LITERAL;
1717 }
1718 
1719 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1720   VisitExpr(E);
1721   Record.AddSourceLocation(E->getLocation());
1722   Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1723 }
1724 
1725 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1726   VisitExpr(E);
1727   Record.AddSourceRange(E->getSourceRange());
1728   if (E->isTypeOperand()) {
1729     Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1730     Code = serialization::EXPR_CXX_TYPEID_TYPE;
1731   } else {
1732     Record.AddStmt(E->getExprOperand());
1733     Code = serialization::EXPR_CXX_TYPEID_EXPR;
1734   }
1735 }
1736 
1737 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1738   VisitExpr(E);
1739   Record.AddSourceLocation(E->getLocation());
1740   Record.push_back(E->isImplicit());
1741   Code = serialization::EXPR_CXX_THIS;
1742 }
1743 
1744 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1745   VisitExpr(E);
1746   Record.AddSourceLocation(E->getThrowLoc());
1747   Record.AddStmt(E->getSubExpr());
1748   Record.push_back(E->isThrownVariableInScope());
1749   Code = serialization::EXPR_CXX_THROW;
1750 }
1751 
1752 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1753   VisitExpr(E);
1754   Record.AddDeclRef(E->getParam());
1755   Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1756   Record.AddSourceLocation(E->getUsedLocation());
1757   Record.push_back(E->hasRewrittenInit());
1758   if (E->hasRewrittenInit())
1759     Record.AddStmt(E->getRewrittenExpr());
1760   Code = serialization::EXPR_CXX_DEFAULT_ARG;
1761 }
1762 
1763 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1764   VisitExpr(E);
1765   Record.push_back(E->hasRewrittenInit());
1766   Record.AddDeclRef(E->getField());
1767   Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1768   Record.AddSourceLocation(E->getExprLoc());
1769   if (E->hasRewrittenInit())
1770     Record.AddStmt(E->getRewrittenExpr());
1771   Code = serialization::EXPR_CXX_DEFAULT_INIT;
1772 }
1773 
1774 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1775   VisitExpr(E);
1776   Record.AddCXXTemporary(E->getTemporary());
1777   Record.AddStmt(E->getSubExpr());
1778   Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1779 }
1780 
1781 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1782   VisitExpr(E);
1783   Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1784   Record.AddSourceLocation(E->getRParenLoc());
1785   Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1786 }
1787 
1788 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1789   VisitExpr(E);
1790 
1791   Record.push_back(E->isArray());
1792   Record.push_back(E->hasInitializer());
1793   Record.push_back(E->getNumPlacementArgs());
1794   Record.push_back(E->isParenTypeId());
1795 
1796   Record.push_back(E->isGlobalNew());
1797   Record.push_back(E->passAlignment());
1798   Record.push_back(E->doesUsualArrayDeleteWantSize());
1799   Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
1800 
1801   Record.AddDeclRef(E->getOperatorNew());
1802   Record.AddDeclRef(E->getOperatorDelete());
1803   Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1804   if (E->isParenTypeId())
1805     Record.AddSourceRange(E->getTypeIdParens());
1806   Record.AddSourceRange(E->getSourceRange());
1807   Record.AddSourceRange(E->getDirectInitRange());
1808 
1809   for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
1810        I != N; ++I)
1811     Record.AddStmt(*I);
1812 
1813   Code = serialization::EXPR_CXX_NEW;
1814 }
1815 
1816 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1817   VisitExpr(E);
1818   Record.push_back(E->isGlobalDelete());
1819   Record.push_back(E->isArrayForm());
1820   Record.push_back(E->isArrayFormAsWritten());
1821   Record.push_back(E->doesUsualArrayDeleteWantSize());
1822   Record.AddDeclRef(E->getOperatorDelete());
1823   Record.AddStmt(E->getArgument());
1824   Record.AddSourceLocation(E->getBeginLoc());
1825 
1826   Code = serialization::EXPR_CXX_DELETE;
1827 }
1828 
1829 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1830   VisitExpr(E);
1831 
1832   Record.AddStmt(E->getBase());
1833   Record.push_back(E->isArrow());
1834   Record.AddSourceLocation(E->getOperatorLoc());
1835   Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1836   Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1837   Record.AddSourceLocation(E->getColonColonLoc());
1838   Record.AddSourceLocation(E->getTildeLoc());
1839 
1840   // PseudoDestructorTypeStorage.
1841   Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
1842   if (E->getDestroyedTypeIdentifier())
1843     Record.AddSourceLocation(E->getDestroyedTypeLoc());
1844   else
1845     Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
1846 
1847   Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1848 }
1849 
1850 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1851   VisitExpr(E);
1852   Record.push_back(E->getNumObjects());
1853   for (auto &Obj : E->getObjects()) {
1854     if (auto *BD = Obj.dyn_cast<BlockDecl *>()) {
1855       Record.push_back(serialization::COK_Block);
1856       Record.AddDeclRef(BD);
1857     } else if (auto *CLE = Obj.dyn_cast<CompoundLiteralExpr *>()) {
1858       Record.push_back(serialization::COK_CompoundLiteral);
1859       Record.AddStmt(CLE);
1860     }
1861   }
1862 
1863   Record.push_back(E->cleanupsHaveSideEffects());
1864   Record.AddStmt(E->getSubExpr());
1865   Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1866 }
1867 
1868 void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
1869     CXXDependentScopeMemberExpr *E) {
1870   VisitExpr(E);
1871 
1872   // Don't emit anything here (or if you do you will have to update
1873   // the corresponding deserialization function).
1874 
1875   Record.push_back(E->hasTemplateKWAndArgsInfo());
1876   Record.push_back(E->getNumTemplateArgs());
1877   Record.push_back(E->hasFirstQualifierFoundInScope());
1878 
1879   if (E->hasTemplateKWAndArgsInfo()) {
1880     const ASTTemplateKWAndArgsInfo &ArgInfo =
1881         *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1882     AddTemplateKWAndArgsInfo(ArgInfo,
1883                              E->getTrailingObjects<TemplateArgumentLoc>());
1884   }
1885 
1886   Record.push_back(E->isArrow());
1887   Record.AddSourceLocation(E->getOperatorLoc());
1888   Record.AddTypeRef(E->getBaseType());
1889   Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1890   if (!E->isImplicitAccess())
1891     Record.AddStmt(E->getBase());
1892   else
1893     Record.AddStmt(nullptr);
1894 
1895   if (E->hasFirstQualifierFoundInScope())
1896     Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1897 
1898   Record.AddDeclarationNameInfo(E->MemberNameInfo);
1899   Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
1900 }
1901 
1902 void
1903 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1904   VisitExpr(E);
1905 
1906   // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1907   // emitted first.
1908 
1909   Record.push_back(E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
1910   if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
1911     const ASTTemplateKWAndArgsInfo &ArgInfo =
1912         *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1913     Record.push_back(ArgInfo.NumTemplateArgs);
1914     AddTemplateKWAndArgsInfo(ArgInfo,
1915                              E->getTrailingObjects<TemplateArgumentLoc>());
1916   }
1917 
1918   Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1919   Record.AddDeclarationNameInfo(E->NameInfo);
1920   Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
1921 }
1922 
1923 void
1924 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1925   VisitExpr(E);
1926   Record.push_back(E->getNumArgs());
1927   for (CXXUnresolvedConstructExpr::arg_iterator
1928          ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
1929     Record.AddStmt(*ArgI);
1930   Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1931   Record.AddSourceLocation(E->getLParenLoc());
1932   Record.AddSourceLocation(E->getRParenLoc());
1933   Record.push_back(E->isListInitialization());
1934   Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
1935 }
1936 
1937 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
1938   VisitExpr(E);
1939 
1940   Record.push_back(E->getNumDecls());
1941   Record.push_back(E->hasTemplateKWAndArgsInfo());
1942   if (E->hasTemplateKWAndArgsInfo()) {
1943     const ASTTemplateKWAndArgsInfo &ArgInfo =
1944         *E->getTrailingASTTemplateKWAndArgsInfo();
1945     Record.push_back(ArgInfo.NumTemplateArgs);
1946     AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
1947   }
1948 
1949   for (OverloadExpr::decls_iterator OvI = E->decls_begin(),
1950                                     OvE = E->decls_end();
1951        OvI != OvE; ++OvI) {
1952     Record.AddDeclRef(OvI.getDecl());
1953     Record.push_back(OvI.getAccess());
1954   }
1955 
1956   Record.AddDeclarationNameInfo(E->getNameInfo());
1957   Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1958 }
1959 
1960 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1961   VisitOverloadExpr(E);
1962   Record.push_back(E->isArrow());
1963   Record.push_back(E->hasUnresolvedUsing());
1964   Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1965   Record.AddTypeRef(E->getBaseType());
1966   Record.AddSourceLocation(E->getOperatorLoc());
1967   Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
1968 }
1969 
1970 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1971   VisitOverloadExpr(E);
1972   Record.push_back(E->requiresADL());
1973   Record.push_back(E->isOverloaded());
1974   Record.AddDeclRef(E->getNamingClass());
1975   Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
1976 }
1977 
1978 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1979   VisitExpr(E);
1980   Record.push_back(E->TypeTraitExprBits.NumArgs);
1981   Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1982   Record.push_back(E->TypeTraitExprBits.Value);
1983   Record.AddSourceRange(E->getSourceRange());
1984   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1985     Record.AddTypeSourceInfo(E->getArg(I));
1986   Code = serialization::EXPR_TYPE_TRAIT;
1987 }
1988 
1989 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1990   VisitExpr(E);
1991   Record.push_back(E->getTrait());
1992   Record.push_back(E->getValue());
1993   Record.AddSourceRange(E->getSourceRange());
1994   Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
1995   Record.AddStmt(E->getDimensionExpression());
1996   Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1997 }
1998 
1999 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2000   VisitExpr(E);
2001   Record.push_back(E->getTrait());
2002   Record.push_back(E->getValue());
2003   Record.AddSourceRange(E->getSourceRange());
2004   Record.AddStmt(E->getQueriedExpression());
2005   Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
2006 }
2007 
2008 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2009   VisitExpr(E);
2010   Record.push_back(E->getValue());
2011   Record.AddSourceRange(E->getSourceRange());
2012   Record.AddStmt(E->getOperand());
2013   Code = serialization::EXPR_CXX_NOEXCEPT;
2014 }
2015 
2016 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
2017   VisitExpr(E);
2018   Record.AddSourceLocation(E->getEllipsisLoc());
2019   Record.push_back(E->NumExpansions);
2020   Record.AddStmt(E->getPattern());
2021   Code = serialization::EXPR_PACK_EXPANSION;
2022 }
2023 
2024 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2025   VisitExpr(E);
2026   Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
2027                                                : 0);
2028   Record.AddSourceLocation(E->OperatorLoc);
2029   Record.AddSourceLocation(E->PackLoc);
2030   Record.AddSourceLocation(E->RParenLoc);
2031   Record.AddDeclRef(E->Pack);
2032   if (E->isPartiallySubstituted()) {
2033     for (const auto &TA : E->getPartialArguments())
2034       Record.AddTemplateArgument(TA);
2035   } else if (!E->isValueDependent()) {
2036     Record.push_back(E->getPackLength());
2037   }
2038   Code = serialization::EXPR_SIZEOF_PACK;
2039 }
2040 
2041 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
2042                                               SubstNonTypeTemplateParmExpr *E) {
2043   VisitExpr(E);
2044   Record.AddDeclRef(E->getAssociatedDecl());
2045   Record.push_back(E->isReferenceParameter());
2046   Record.push_back(E->getIndex());
2047   if (auto PackIndex = E->getPackIndex())
2048     Record.push_back(*PackIndex + 1);
2049   else
2050     Record.push_back(0);
2051   Record.AddSourceLocation(E->getNameLoc());
2052   Record.AddStmt(E->getReplacement());
2053   Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
2054 }
2055 
2056 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
2057                                           SubstNonTypeTemplateParmPackExpr *E) {
2058   VisitExpr(E);
2059   Record.AddDeclRef(E->getAssociatedDecl());
2060   Record.push_back(E->getIndex());
2061   Record.AddTemplateArgument(E->getArgumentPack());
2062   Record.AddSourceLocation(E->getParameterPackLocation());
2063   Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
2064 }
2065 
2066 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2067   VisitExpr(E);
2068   Record.push_back(E->getNumExpansions());
2069   Record.AddDeclRef(E->getParameterPack());
2070   Record.AddSourceLocation(E->getParameterPackLocation());
2071   for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
2072        I != End; ++I)
2073     Record.AddDeclRef(*I);
2074   Code = serialization::EXPR_FUNCTION_PARM_PACK;
2075 }
2076 
2077 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
2078   VisitExpr(E);
2079   Record.push_back(static_cast<bool>(E->getLifetimeExtendedTemporaryDecl()));
2080   if (E->getLifetimeExtendedTemporaryDecl())
2081     Record.AddDeclRef(E->getLifetimeExtendedTemporaryDecl());
2082   else
2083     Record.AddStmt(E->getSubExpr());
2084   Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
2085 }
2086 
2087 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
2088   VisitExpr(E);
2089   Record.AddSourceLocation(E->LParenLoc);
2090   Record.AddSourceLocation(E->EllipsisLoc);
2091   Record.AddSourceLocation(E->RParenLoc);
2092   Record.push_back(E->NumExpansions);
2093   Record.AddStmt(E->SubExprs[0]);
2094   Record.AddStmt(E->SubExprs[1]);
2095   Record.AddStmt(E->SubExprs[2]);
2096   Record.push_back(E->Opcode);
2097   Code = serialization::EXPR_CXX_FOLD;
2098 }
2099 
2100 void ASTStmtWriter::VisitCXXParenListInitExpr(CXXParenListInitExpr *E) {
2101   VisitExpr(E);
2102   ArrayRef<Expr *> InitExprs = E->getInitExprs();
2103   Record.push_back(InitExprs.size());
2104   Record.push_back(E->getUserSpecifiedInitExprs().size());
2105   Record.AddSourceLocation(E->getInitLoc());
2106   Record.AddSourceLocation(E->getBeginLoc());
2107   Record.AddSourceLocation(E->getEndLoc());
2108   for (Expr *InitExpr : E->getInitExprs())
2109     Record.AddStmt(InitExpr);
2110   Expr *ArrayFiller = E->getArrayFiller();
2111   FieldDecl *UnionField = E->getInitializedFieldInUnion();
2112   bool HasArrayFillerOrUnionDecl = ArrayFiller || UnionField;
2113   Record.push_back(HasArrayFillerOrUnionDecl);
2114   if (HasArrayFillerOrUnionDecl) {
2115     Record.push_back(static_cast<bool>(ArrayFiller));
2116     if (ArrayFiller)
2117       Record.AddStmt(ArrayFiller);
2118     else
2119       Record.AddDeclRef(UnionField);
2120   }
2121   Code = serialization::EXPR_CXX_PAREN_LIST_INIT;
2122 }
2123 
2124 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
2125   VisitExpr(E);
2126   Record.AddStmt(E->getSourceExpr());
2127   Record.AddSourceLocation(E->getLocation());
2128   Record.push_back(E->isUnique());
2129   Code = serialization::EXPR_OPAQUE_VALUE;
2130 }
2131 
2132 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
2133   VisitExpr(E);
2134   // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
2135   llvm_unreachable("Cannot write TypoExpr nodes");
2136 }
2137 
2138 //===----------------------------------------------------------------------===//
2139 // CUDA Expressions and Statements.
2140 //===----------------------------------------------------------------------===//
2141 
2142 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
2143   VisitCallExpr(E);
2144   Record.AddStmt(E->getConfig());
2145   Code = serialization::EXPR_CUDA_KERNEL_CALL;
2146 }
2147 
2148 //===----------------------------------------------------------------------===//
2149 // OpenCL Expressions and Statements.
2150 //===----------------------------------------------------------------------===//
2151 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
2152   VisitExpr(E);
2153   Record.AddSourceLocation(E->getBuiltinLoc());
2154   Record.AddSourceLocation(E->getRParenLoc());
2155   Record.AddStmt(E->getSrcExpr());
2156   Code = serialization::EXPR_ASTYPE;
2157 }
2158 
2159 //===----------------------------------------------------------------------===//
2160 // Microsoft Expressions and Statements.
2161 //===----------------------------------------------------------------------===//
2162 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
2163   VisitExpr(E);
2164   Record.push_back(E->isArrow());
2165   Record.AddStmt(E->getBaseExpr());
2166   Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
2167   Record.AddSourceLocation(E->getMemberLoc());
2168   Record.AddDeclRef(E->getPropertyDecl());
2169   Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
2170 }
2171 
2172 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
2173   VisitExpr(E);
2174   Record.AddStmt(E->getBase());
2175   Record.AddStmt(E->getIdx());
2176   Record.AddSourceLocation(E->getRBracketLoc());
2177   Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
2178 }
2179 
2180 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
2181   VisitExpr(E);
2182   Record.AddSourceRange(E->getSourceRange());
2183   Record.AddDeclRef(E->getGuidDecl());
2184   if (E->isTypeOperand()) {
2185     Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
2186     Code = serialization::EXPR_CXX_UUIDOF_TYPE;
2187   } else {
2188     Record.AddStmt(E->getExprOperand());
2189     Code = serialization::EXPR_CXX_UUIDOF_EXPR;
2190   }
2191 }
2192 
2193 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
2194   VisitStmt(S);
2195   Record.AddSourceLocation(S->getExceptLoc());
2196   Record.AddStmt(S->getFilterExpr());
2197   Record.AddStmt(S->getBlock());
2198   Code = serialization::STMT_SEH_EXCEPT;
2199 }
2200 
2201 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
2202   VisitStmt(S);
2203   Record.AddSourceLocation(S->getFinallyLoc());
2204   Record.AddStmt(S->getBlock());
2205   Code = serialization::STMT_SEH_FINALLY;
2206 }
2207 
2208 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
2209   VisitStmt(S);
2210   Record.push_back(S->getIsCXXTry());
2211   Record.AddSourceLocation(S->getTryLoc());
2212   Record.AddStmt(S->getTryBlock());
2213   Record.AddStmt(S->getHandler());
2214   Code = serialization::STMT_SEH_TRY;
2215 }
2216 
2217 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
2218   VisitStmt(S);
2219   Record.AddSourceLocation(S->getLeaveLoc());
2220   Code = serialization::STMT_SEH_LEAVE;
2221 }
2222 
2223 //===----------------------------------------------------------------------===//
2224 // OpenMP Directives.
2225 //===----------------------------------------------------------------------===//
2226 
2227 void ASTStmtWriter::VisitOMPCanonicalLoop(OMPCanonicalLoop *S) {
2228   VisitStmt(S);
2229   for (Stmt *SubStmt : S->SubStmts)
2230     Record.AddStmt(SubStmt);
2231   Code = serialization::STMT_OMP_CANONICAL_LOOP;
2232 }
2233 
2234 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2235   Record.writeOMPChildren(E->Data);
2236   Record.AddSourceLocation(E->getBeginLoc());
2237   Record.AddSourceLocation(E->getEndLoc());
2238 }
2239 
2240 void ASTStmtWriter::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {
2241   VisitStmt(D);
2242   Record.writeUInt32(D->getLoopsNumber());
2243   VisitOMPExecutableDirective(D);
2244 }
2245 
2246 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
2247   VisitOMPLoopBasedDirective(D);
2248 }
2249 
2250 void ASTStmtWriter::VisitOMPMetaDirective(OMPMetaDirective *D) {
2251   VisitStmt(D);
2252   Record.push_back(D->getNumClauses());
2253   VisitOMPExecutableDirective(D);
2254   Code = serialization::STMT_OMP_META_DIRECTIVE;
2255 }
2256 
2257 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2258   VisitStmt(D);
2259   VisitOMPExecutableDirective(D);
2260   Record.writeBool(D->hasCancel());
2261   Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2262 }
2263 
2264 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2265   VisitOMPLoopDirective(D);
2266   Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2267 }
2268 
2269 void ASTStmtWriter::VisitOMPLoopTransformationDirective(
2270     OMPLoopTransformationDirective *D) {
2271   VisitOMPLoopBasedDirective(D);
2272   Record.writeUInt32(D->getNumGeneratedLoops());
2273 }
2274 
2275 void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective *D) {
2276   VisitOMPLoopTransformationDirective(D);
2277   Code = serialization::STMT_OMP_TILE_DIRECTIVE;
2278 }
2279 
2280 void ASTStmtWriter::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
2281   VisitOMPLoopTransformationDirective(D);
2282   Code = serialization::STMT_OMP_UNROLL_DIRECTIVE;
2283 }
2284 
2285 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2286   VisitOMPLoopDirective(D);
2287   Record.writeBool(D->hasCancel());
2288   Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2289 }
2290 
2291 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2292   VisitOMPLoopDirective(D);
2293   Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2294 }
2295 
2296 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2297   VisitStmt(D);
2298   VisitOMPExecutableDirective(D);
2299   Record.writeBool(D->hasCancel());
2300   Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2301 }
2302 
2303 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2304   VisitStmt(D);
2305   VisitOMPExecutableDirective(D);
2306   Record.writeBool(D->hasCancel());
2307   Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2308 }
2309 
2310 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2311   VisitStmt(D);
2312   VisitOMPExecutableDirective(D);
2313   Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2314 }
2315 
2316 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2317   VisitStmt(D);
2318   VisitOMPExecutableDirective(D);
2319   Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2320 }
2321 
2322 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2323   VisitStmt(D);
2324   VisitOMPExecutableDirective(D);
2325   Record.AddDeclarationNameInfo(D->getDirectiveName());
2326   Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2327 }
2328 
2329 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2330   VisitOMPLoopDirective(D);
2331   Record.writeBool(D->hasCancel());
2332   Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2333 }
2334 
2335 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2336     OMPParallelForSimdDirective *D) {
2337   VisitOMPLoopDirective(D);
2338   Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2339 }
2340 
2341 void ASTStmtWriter::VisitOMPParallelMasterDirective(
2342     OMPParallelMasterDirective *D) {
2343   VisitStmt(D);
2344   VisitOMPExecutableDirective(D);
2345   Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE;
2346 }
2347 
2348 void ASTStmtWriter::VisitOMPParallelMaskedDirective(
2349     OMPParallelMaskedDirective *D) {
2350   VisitStmt(D);
2351   VisitOMPExecutableDirective(D);
2352   Code = serialization::STMT_OMP_PARALLEL_MASKED_DIRECTIVE;
2353 }
2354 
2355 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2356     OMPParallelSectionsDirective *D) {
2357   VisitStmt(D);
2358   VisitOMPExecutableDirective(D);
2359   Record.writeBool(D->hasCancel());
2360   Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2361 }
2362 
2363 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2364   VisitStmt(D);
2365   VisitOMPExecutableDirective(D);
2366   Record.writeBool(D->hasCancel());
2367   Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2368 }
2369 
2370 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2371   VisitStmt(D);
2372   VisitOMPExecutableDirective(D);
2373   Record.writeBool(D->isXLHSInRHSPart());
2374   Record.writeBool(D->isPostfixUpdate());
2375   Record.writeBool(D->isFailOnly());
2376   Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2377 }
2378 
2379 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2380   VisitStmt(D);
2381   VisitOMPExecutableDirective(D);
2382   Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2383 }
2384 
2385 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2386   VisitStmt(D);
2387   VisitOMPExecutableDirective(D);
2388   Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2389 }
2390 
2391 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2392     OMPTargetEnterDataDirective *D) {
2393   VisitStmt(D);
2394   VisitOMPExecutableDirective(D);
2395   Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2396 }
2397 
2398 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2399     OMPTargetExitDataDirective *D) {
2400   VisitStmt(D);
2401   VisitOMPExecutableDirective(D);
2402   Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2403 }
2404 
2405 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2406     OMPTargetParallelDirective *D) {
2407   VisitStmt(D);
2408   VisitOMPExecutableDirective(D);
2409   Record.writeBool(D->hasCancel());
2410   Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2411 }
2412 
2413 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2414     OMPTargetParallelForDirective *D) {
2415   VisitOMPLoopDirective(D);
2416   Record.writeBool(D->hasCancel());
2417   Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2418 }
2419 
2420 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2421   VisitStmt(D);
2422   VisitOMPExecutableDirective(D);
2423   Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2424 }
2425 
2426 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2427   VisitStmt(D);
2428   VisitOMPExecutableDirective(D);
2429   Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2430 }
2431 
2432 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2433   VisitStmt(D);
2434   Record.push_back(D->getNumClauses());
2435   VisitOMPExecutableDirective(D);
2436   Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2437 }
2438 
2439 void ASTStmtWriter::VisitOMPErrorDirective(OMPErrorDirective *D) {
2440   VisitStmt(D);
2441   Record.push_back(D->getNumClauses());
2442   VisitOMPExecutableDirective(D);
2443   Code = serialization::STMT_OMP_ERROR_DIRECTIVE;
2444 }
2445 
2446 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2447   VisitStmt(D);
2448   VisitOMPExecutableDirective(D);
2449   Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2450 }
2451 
2452 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2453   VisitStmt(D);
2454   VisitOMPExecutableDirective(D);
2455   Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2456 }
2457 
2458 void ASTStmtWriter::VisitOMPDepobjDirective(OMPDepobjDirective *D) {
2459   VisitStmt(D);
2460   VisitOMPExecutableDirective(D);
2461   Code = serialization::STMT_OMP_DEPOBJ_DIRECTIVE;
2462 }
2463 
2464 void ASTStmtWriter::VisitOMPScanDirective(OMPScanDirective *D) {
2465   VisitStmt(D);
2466   VisitOMPExecutableDirective(D);
2467   Code = serialization::STMT_OMP_SCAN_DIRECTIVE;
2468 }
2469 
2470 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2471   VisitStmt(D);
2472   VisitOMPExecutableDirective(D);
2473   Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2474 }
2475 
2476 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2477   VisitStmt(D);
2478   VisitOMPExecutableDirective(D);
2479   Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2480 }
2481 
2482 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2483     OMPCancellationPointDirective *D) {
2484   VisitStmt(D);
2485   VisitOMPExecutableDirective(D);
2486   Record.writeEnum(D->getCancelRegion());
2487   Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2488 }
2489 
2490 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2491   VisitStmt(D);
2492   VisitOMPExecutableDirective(D);
2493   Record.writeEnum(D->getCancelRegion());
2494   Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2495 }
2496 
2497 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2498   VisitOMPLoopDirective(D);
2499   Record.writeBool(D->hasCancel());
2500   Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2501 }
2502 
2503 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2504   VisitOMPLoopDirective(D);
2505   Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2506 }
2507 
2508 void ASTStmtWriter::VisitOMPMasterTaskLoopDirective(
2509     OMPMasterTaskLoopDirective *D) {
2510   VisitOMPLoopDirective(D);
2511   Record.writeBool(D->hasCancel());
2512   Code = serialization::STMT_OMP_MASTER_TASKLOOP_DIRECTIVE;
2513 }
2514 
2515 void ASTStmtWriter::VisitOMPMaskedTaskLoopDirective(
2516     OMPMaskedTaskLoopDirective *D) {
2517   VisitOMPLoopDirective(D);
2518   Record.writeBool(D->hasCancel());
2519   Code = serialization::STMT_OMP_MASKED_TASKLOOP_DIRECTIVE;
2520 }
2521 
2522 void ASTStmtWriter::VisitOMPMasterTaskLoopSimdDirective(
2523     OMPMasterTaskLoopSimdDirective *D) {
2524   VisitOMPLoopDirective(D);
2525   Code = serialization::STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE;
2526 }
2527 
2528 void ASTStmtWriter::VisitOMPMaskedTaskLoopSimdDirective(
2529     OMPMaskedTaskLoopSimdDirective *D) {
2530   VisitOMPLoopDirective(D);
2531   Code = serialization::STMT_OMP_MASKED_TASKLOOP_SIMD_DIRECTIVE;
2532 }
2533 
2534 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopDirective(
2535     OMPParallelMasterTaskLoopDirective *D) {
2536   VisitOMPLoopDirective(D);
2537   Record.writeBool(D->hasCancel());
2538   Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE;
2539 }
2540 
2541 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopDirective(
2542     OMPParallelMaskedTaskLoopDirective *D) {
2543   VisitOMPLoopDirective(D);
2544   Record.writeBool(D->hasCancel());
2545   Code = serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_DIRECTIVE;
2546 }
2547 
2548 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopSimdDirective(
2549     OMPParallelMasterTaskLoopSimdDirective *D) {
2550   VisitOMPLoopDirective(D);
2551   Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE;
2552 }
2553 
2554 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopSimdDirective(
2555     OMPParallelMaskedTaskLoopSimdDirective *D) {
2556   VisitOMPLoopDirective(D);
2557   Code = serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_SIMD_DIRECTIVE;
2558 }
2559 
2560 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2561   VisitOMPLoopDirective(D);
2562   Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2563 }
2564 
2565 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2566   VisitStmt(D);
2567   VisitOMPExecutableDirective(D);
2568   Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2569 }
2570 
2571 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2572     OMPDistributeParallelForDirective *D) {
2573   VisitOMPLoopDirective(D);
2574   Record.writeBool(D->hasCancel());
2575   Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2576 }
2577 
2578 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2579     OMPDistributeParallelForSimdDirective *D) {
2580   VisitOMPLoopDirective(D);
2581   Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2582 }
2583 
2584 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2585     OMPDistributeSimdDirective *D) {
2586   VisitOMPLoopDirective(D);
2587   Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2588 }
2589 
2590 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2591     OMPTargetParallelForSimdDirective *D) {
2592   VisitOMPLoopDirective(D);
2593   Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2594 }
2595 
2596 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2597   VisitOMPLoopDirective(D);
2598   Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2599 }
2600 
2601 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2602     OMPTeamsDistributeDirective *D) {
2603   VisitOMPLoopDirective(D);
2604   Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2605 }
2606 
2607 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2608     OMPTeamsDistributeSimdDirective *D) {
2609   VisitOMPLoopDirective(D);
2610   Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2611 }
2612 
2613 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2614     OMPTeamsDistributeParallelForSimdDirective *D) {
2615   VisitOMPLoopDirective(D);
2616   Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2617 }
2618 
2619 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2620     OMPTeamsDistributeParallelForDirective *D) {
2621   VisitOMPLoopDirective(D);
2622   Record.writeBool(D->hasCancel());
2623   Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2624 }
2625 
2626 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2627   VisitStmt(D);
2628   VisitOMPExecutableDirective(D);
2629   Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2630 }
2631 
2632 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2633     OMPTargetTeamsDistributeDirective *D) {
2634   VisitOMPLoopDirective(D);
2635   Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2636 }
2637 
2638 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2639     OMPTargetTeamsDistributeParallelForDirective *D) {
2640   VisitOMPLoopDirective(D);
2641   Record.writeBool(D->hasCancel());
2642   Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2643 }
2644 
2645 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2646     OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2647   VisitOMPLoopDirective(D);
2648   Code = serialization::
2649       STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2650 }
2651 
2652 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2653     OMPTargetTeamsDistributeSimdDirective *D) {
2654   VisitOMPLoopDirective(D);
2655   Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2656 }
2657 
2658 void ASTStmtWriter::VisitOMPInteropDirective(OMPInteropDirective *D) {
2659   VisitStmt(D);
2660   VisitOMPExecutableDirective(D);
2661   Code = serialization::STMT_OMP_INTEROP_DIRECTIVE;
2662 }
2663 
2664 void ASTStmtWriter::VisitOMPDispatchDirective(OMPDispatchDirective *D) {
2665   VisitStmt(D);
2666   VisitOMPExecutableDirective(D);
2667   Record.AddSourceLocation(D->getTargetCallLoc());
2668   Code = serialization::STMT_OMP_DISPATCH_DIRECTIVE;
2669 }
2670 
2671 void ASTStmtWriter::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
2672   VisitStmt(D);
2673   VisitOMPExecutableDirective(D);
2674   Code = serialization::STMT_OMP_MASKED_DIRECTIVE;
2675 }
2676 
2677 void ASTStmtWriter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
2678   VisitOMPLoopDirective(D);
2679   Code = serialization::STMT_OMP_GENERIC_LOOP_DIRECTIVE;
2680 }
2681 
2682 void ASTStmtWriter::VisitOMPTeamsGenericLoopDirective(
2683     OMPTeamsGenericLoopDirective *D) {
2684   VisitOMPLoopDirective(D);
2685   Code = serialization::STMT_OMP_TEAMS_GENERIC_LOOP_DIRECTIVE;
2686 }
2687 
2688 void ASTStmtWriter::VisitOMPTargetTeamsGenericLoopDirective(
2689     OMPTargetTeamsGenericLoopDirective *D) {
2690   VisitOMPLoopDirective(D);
2691   Code = serialization::STMT_OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE;
2692 }
2693 
2694 void ASTStmtWriter::VisitOMPParallelGenericLoopDirective(
2695     OMPParallelGenericLoopDirective *D) {
2696   VisitOMPLoopDirective(D);
2697   Code = serialization::STMT_OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE;
2698 }
2699 
2700 void ASTStmtWriter::VisitOMPTargetParallelGenericLoopDirective(
2701     OMPTargetParallelGenericLoopDirective *D) {
2702   VisitOMPLoopDirective(D);
2703   Code = serialization::STMT_OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE;
2704 }
2705 
2706 //===----------------------------------------------------------------------===//
2707 // ASTWriter Implementation
2708 //===----------------------------------------------------------------------===//
2709 
2710 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2711   assert(!SwitchCaseIDs.contains(S) && "SwitchCase recorded twice");
2712   unsigned NextID = SwitchCaseIDs.size();
2713   SwitchCaseIDs[S] = NextID;
2714   return NextID;
2715 }
2716 
2717 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2718   assert(SwitchCaseIDs.contains(S) && "SwitchCase hasn't been seen yet");
2719   return SwitchCaseIDs[S];
2720 }
2721 
2722 void ASTWriter::ClearSwitchCaseIDs() {
2723   SwitchCaseIDs.clear();
2724 }
2725 
2726 /// Write the given substatement or subexpression to the
2727 /// bitstream.
2728 void ASTWriter::WriteSubStmt(Stmt *S) {
2729   RecordData Record;
2730   ASTStmtWriter Writer(*this, Record);
2731   ++NumStatements;
2732 
2733   if (!S) {
2734     Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2735     return;
2736   }
2737 
2738   llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2739   if (I != SubStmtEntries.end()) {
2740     Record.push_back(I->second);
2741     Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2742     return;
2743   }
2744 
2745 #ifndef NDEBUG
2746   assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2747 
2748   struct ParentStmtInserterRAII {
2749     Stmt *S;
2750     llvm::DenseSet<Stmt *> &ParentStmts;
2751 
2752     ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2753       : S(S), ParentStmts(ParentStmts) {
2754       ParentStmts.insert(S);
2755     }
2756     ~ParentStmtInserterRAII() {
2757       ParentStmts.erase(S);
2758     }
2759   };
2760 
2761   ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2762 #endif
2763 
2764   Writer.Visit(S);
2765 
2766   uint64_t Offset = Writer.Emit();
2767   SubStmtEntries[S] = Offset;
2768 }
2769 
2770 /// Flush all of the statements that have been added to the
2771 /// queue via AddStmt().
2772 void ASTRecordWriter::FlushStmts() {
2773   // We expect to be the only consumer of the two temporary statement maps,
2774   // assert that they are empty.
2775   assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2776   assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2777 
2778   for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2779     Writer->WriteSubStmt(StmtsToEmit[I]);
2780 
2781     assert(N == StmtsToEmit.size() && "record modified while being written!");
2782 
2783     // Note that we are at the end of a full expression. Any
2784     // expression records that follow this one are part of a different
2785     // expression.
2786     Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2787 
2788     Writer->SubStmtEntries.clear();
2789     Writer->ParentStmts.clear();
2790   }
2791 
2792   StmtsToEmit.clear();
2793 }
2794 
2795 void ASTRecordWriter::FlushSubStmts() {
2796   // For a nested statement, write out the substatements in reverse order (so
2797   // that a simple stack machine can be used when loading), and don't emit a
2798   // STMT_STOP after each one.
2799   for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2800     Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
2801     assert(N == StmtsToEmit.size() && "record modified while being written!");
2802   }
2803 
2804   StmtsToEmit.clear();
2805 }
2806