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