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