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