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