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   Record.push_back(E->isUnique());
1703   Code = serialization::EXPR_OPAQUE_VALUE;
1704 }
1705 
1706 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1707   VisitExpr(E);
1708   // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
1709   llvm_unreachable("Cannot write TypoExpr nodes");
1710 }
1711 
1712 //===----------------------------------------------------------------------===//
1713 // CUDA Expressions and Statements.
1714 //===----------------------------------------------------------------------===//
1715 
1716 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1717   VisitCallExpr(E);
1718   Record.AddStmt(E->getConfig());
1719   Code = serialization::EXPR_CUDA_KERNEL_CALL;
1720 }
1721 
1722 //===----------------------------------------------------------------------===//
1723 // OpenCL Expressions and Statements.
1724 //===----------------------------------------------------------------------===//
1725 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1726   VisitExpr(E);
1727   Record.AddSourceLocation(E->getBuiltinLoc());
1728   Record.AddSourceLocation(E->getRParenLoc());
1729   Record.AddStmt(E->getSrcExpr());
1730   Code = serialization::EXPR_ASTYPE;
1731 }
1732 
1733 //===----------------------------------------------------------------------===//
1734 // Microsoft Expressions and Statements.
1735 //===----------------------------------------------------------------------===//
1736 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1737   VisitExpr(E);
1738   Record.push_back(E->isArrow());
1739   Record.AddStmt(E->getBaseExpr());
1740   Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1741   Record.AddSourceLocation(E->getMemberLoc());
1742   Record.AddDeclRef(E->getPropertyDecl());
1743   Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1744 }
1745 
1746 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1747   VisitExpr(E);
1748   Record.AddStmt(E->getBase());
1749   Record.AddStmt(E->getIdx());
1750   Record.AddSourceLocation(E->getRBracketLoc());
1751   Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1752 }
1753 
1754 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1755   VisitExpr(E);
1756   Record.AddSourceRange(E->getSourceRange());
1757   Record.AddString(E->getUuidStr());
1758   if (E->isTypeOperand()) {
1759     Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1760     Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1761   } else {
1762     Record.AddStmt(E->getExprOperand());
1763     Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1764   }
1765 }
1766 
1767 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1768   VisitStmt(S);
1769   Record.AddSourceLocation(S->getExceptLoc());
1770   Record.AddStmt(S->getFilterExpr());
1771   Record.AddStmt(S->getBlock());
1772   Code = serialization::STMT_SEH_EXCEPT;
1773 }
1774 
1775 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1776   VisitStmt(S);
1777   Record.AddSourceLocation(S->getFinallyLoc());
1778   Record.AddStmt(S->getBlock());
1779   Code = serialization::STMT_SEH_FINALLY;
1780 }
1781 
1782 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1783   VisitStmt(S);
1784   Record.push_back(S->getIsCXXTry());
1785   Record.AddSourceLocation(S->getTryLoc());
1786   Record.AddStmt(S->getTryBlock());
1787   Record.AddStmt(S->getHandler());
1788   Code = serialization::STMT_SEH_TRY;
1789 }
1790 
1791 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1792   VisitStmt(S);
1793   Record.AddSourceLocation(S->getLeaveLoc());
1794   Code = serialization::STMT_SEH_LEAVE;
1795 }
1796 
1797 //===----------------------------------------------------------------------===//
1798 // OpenMP Clauses.
1799 //===----------------------------------------------------------------------===//
1800 
1801 namespace clang {
1802 class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> {
1803   ASTRecordWriter &Record;
1804 public:
1805   OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {}
1806 #define OPENMP_CLAUSE(Name, Class)    \
1807   void Visit##Class(Class *S);
1808 #include "clang/Basic/OpenMPKinds.def"
1809   void writeClause(OMPClause *C);
1810   void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
1811   void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
1812 };
1813 }
1814 
1815 void OMPClauseWriter::writeClause(OMPClause *C) {
1816   Record.push_back(C->getClauseKind());
1817   Visit(C);
1818   Record.AddSourceLocation(C->getLocStart());
1819   Record.AddSourceLocation(C->getLocEnd());
1820 }
1821 
1822 void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) {
1823   Record.push_back(C->getCaptureRegion());
1824   Record.AddStmt(C->getPreInitStmt());
1825 }
1826 
1827 void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) {
1828   VisitOMPClauseWithPreInit(C);
1829   Record.AddStmt(C->getPostUpdateExpr());
1830 }
1831 
1832 void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) {
1833   VisitOMPClauseWithPreInit(C);
1834   Record.push_back(C->getNameModifier());
1835   Record.AddSourceLocation(C->getNameModifierLoc());
1836   Record.AddSourceLocation(C->getColonLoc());
1837   Record.AddStmt(C->getCondition());
1838   Record.AddSourceLocation(C->getLParenLoc());
1839 }
1840 
1841 void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) {
1842   Record.AddStmt(C->getCondition());
1843   Record.AddSourceLocation(C->getLParenLoc());
1844 }
1845 
1846 void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
1847   VisitOMPClauseWithPreInit(C);
1848   Record.AddStmt(C->getNumThreads());
1849   Record.AddSourceLocation(C->getLParenLoc());
1850 }
1851 
1852 void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) {
1853   Record.AddStmt(C->getSafelen());
1854   Record.AddSourceLocation(C->getLParenLoc());
1855 }
1856 
1857 void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
1858   Record.AddStmt(C->getSimdlen());
1859   Record.AddSourceLocation(C->getLParenLoc());
1860 }
1861 
1862 void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) {
1863   Record.AddStmt(C->getNumForLoops());
1864   Record.AddSourceLocation(C->getLParenLoc());
1865 }
1866 
1867 void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
1868   Record.push_back(C->getDefaultKind());
1869   Record.AddSourceLocation(C->getLParenLoc());
1870   Record.AddSourceLocation(C->getDefaultKindKwLoc());
1871 }
1872 
1873 void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
1874   Record.push_back(C->getProcBindKind());
1875   Record.AddSourceLocation(C->getLParenLoc());
1876   Record.AddSourceLocation(C->getProcBindKindKwLoc());
1877 }
1878 
1879 void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
1880   VisitOMPClauseWithPreInit(C);
1881   Record.push_back(C->getScheduleKind());
1882   Record.push_back(C->getFirstScheduleModifier());
1883   Record.push_back(C->getSecondScheduleModifier());
1884   Record.AddStmt(C->getChunkSize());
1885   Record.AddSourceLocation(C->getLParenLoc());
1886   Record.AddSourceLocation(C->getFirstScheduleModifierLoc());
1887   Record.AddSourceLocation(C->getSecondScheduleModifierLoc());
1888   Record.AddSourceLocation(C->getScheduleKindLoc());
1889   Record.AddSourceLocation(C->getCommaLoc());
1890 }
1891 
1892 void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) {
1893   Record.AddStmt(C->getNumForLoops());
1894   Record.AddSourceLocation(C->getLParenLoc());
1895 }
1896 
1897 void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {}
1898 
1899 void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}
1900 
1901 void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
1902 
1903 void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {}
1904 
1905 void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {}
1906 
1907 void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {}
1908 
1909 void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {}
1910 
1911 void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
1912 
1913 void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {}
1914 
1915 void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {}
1916 
1917 void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {}
1918 
1919 void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
1920   Record.push_back(C->varlist_size());
1921   Record.AddSourceLocation(C->getLParenLoc());
1922   for (auto *VE : C->varlists()) {
1923     Record.AddStmt(VE);
1924   }
1925   for (auto *VE : C->private_copies()) {
1926     Record.AddStmt(VE);
1927   }
1928 }
1929 
1930 void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
1931   Record.push_back(C->varlist_size());
1932   VisitOMPClauseWithPreInit(C);
1933   Record.AddSourceLocation(C->getLParenLoc());
1934   for (auto *VE : C->varlists()) {
1935     Record.AddStmt(VE);
1936   }
1937   for (auto *VE : C->private_copies()) {
1938     Record.AddStmt(VE);
1939   }
1940   for (auto *VE : C->inits()) {
1941     Record.AddStmt(VE);
1942   }
1943 }
1944 
1945 void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
1946   Record.push_back(C->varlist_size());
1947   VisitOMPClauseWithPostUpdate(C);
1948   Record.AddSourceLocation(C->getLParenLoc());
1949   for (auto *VE : C->varlists())
1950     Record.AddStmt(VE);
1951   for (auto *E : C->private_copies())
1952     Record.AddStmt(E);
1953   for (auto *E : C->source_exprs())
1954     Record.AddStmt(E);
1955   for (auto *E : C->destination_exprs())
1956     Record.AddStmt(E);
1957   for (auto *E : C->assignment_ops())
1958     Record.AddStmt(E);
1959 }
1960 
1961 void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {
1962   Record.push_back(C->varlist_size());
1963   Record.AddSourceLocation(C->getLParenLoc());
1964   for (auto *VE : C->varlists())
1965     Record.AddStmt(VE);
1966 }
1967 
1968 void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) {
1969   Record.push_back(C->varlist_size());
1970   VisitOMPClauseWithPostUpdate(C);
1971   Record.AddSourceLocation(C->getLParenLoc());
1972   Record.AddSourceLocation(C->getColonLoc());
1973   Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
1974   Record.AddDeclarationNameInfo(C->getNameInfo());
1975   for (auto *VE : C->varlists())
1976     Record.AddStmt(VE);
1977   for (auto *VE : C->privates())
1978     Record.AddStmt(VE);
1979   for (auto *E : C->lhs_exprs())
1980     Record.AddStmt(E);
1981   for (auto *E : C->rhs_exprs())
1982     Record.AddStmt(E);
1983   for (auto *E : C->reduction_ops())
1984     Record.AddStmt(E);
1985 }
1986 
1987 void OMPClauseWriter::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) {
1988   Record.push_back(C->varlist_size());
1989   VisitOMPClauseWithPostUpdate(C);
1990   Record.AddSourceLocation(C->getLParenLoc());
1991   Record.AddSourceLocation(C->getColonLoc());
1992   Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
1993   Record.AddDeclarationNameInfo(C->getNameInfo());
1994   for (auto *VE : C->varlists())
1995     Record.AddStmt(VE);
1996   for (auto *VE : C->privates())
1997     Record.AddStmt(VE);
1998   for (auto *E : C->lhs_exprs())
1999     Record.AddStmt(E);
2000   for (auto *E : C->rhs_exprs())
2001     Record.AddStmt(E);
2002   for (auto *E : C->reduction_ops())
2003     Record.AddStmt(E);
2004 }
2005 
2006 void OMPClauseWriter::VisitOMPInReductionClause(OMPInReductionClause *C) {
2007   Record.push_back(C->varlist_size());
2008   VisitOMPClauseWithPostUpdate(C);
2009   Record.AddSourceLocation(C->getLParenLoc());
2010   Record.AddSourceLocation(C->getColonLoc());
2011   Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
2012   Record.AddDeclarationNameInfo(C->getNameInfo());
2013   for (auto *VE : C->varlists())
2014     Record.AddStmt(VE);
2015   for (auto *VE : C->privates())
2016     Record.AddStmt(VE);
2017   for (auto *E : C->lhs_exprs())
2018     Record.AddStmt(E);
2019   for (auto *E : C->rhs_exprs())
2020     Record.AddStmt(E);
2021   for (auto *E : C->reduction_ops())
2022     Record.AddStmt(E);
2023   for (auto *E : C->taskgroup_descriptors())
2024     Record.AddStmt(E);
2025 }
2026 
2027 void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) {
2028   Record.push_back(C->varlist_size());
2029   VisitOMPClauseWithPostUpdate(C);
2030   Record.AddSourceLocation(C->getLParenLoc());
2031   Record.AddSourceLocation(C->getColonLoc());
2032   Record.push_back(C->getModifier());
2033   Record.AddSourceLocation(C->getModifierLoc());
2034   for (auto *VE : C->varlists()) {
2035     Record.AddStmt(VE);
2036   }
2037   for (auto *VE : C->privates()) {
2038     Record.AddStmt(VE);
2039   }
2040   for (auto *VE : C->inits()) {
2041     Record.AddStmt(VE);
2042   }
2043   for (auto *VE : C->updates()) {
2044     Record.AddStmt(VE);
2045   }
2046   for (auto *VE : C->finals()) {
2047     Record.AddStmt(VE);
2048   }
2049   Record.AddStmt(C->getStep());
2050   Record.AddStmt(C->getCalcStep());
2051 }
2052 
2053 void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) {
2054   Record.push_back(C->varlist_size());
2055   Record.AddSourceLocation(C->getLParenLoc());
2056   Record.AddSourceLocation(C->getColonLoc());
2057   for (auto *VE : C->varlists())
2058     Record.AddStmt(VE);
2059   Record.AddStmt(C->getAlignment());
2060 }
2061 
2062 void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) {
2063   Record.push_back(C->varlist_size());
2064   Record.AddSourceLocation(C->getLParenLoc());
2065   for (auto *VE : C->varlists())
2066     Record.AddStmt(VE);
2067   for (auto *E : C->source_exprs())
2068     Record.AddStmt(E);
2069   for (auto *E : C->destination_exprs())
2070     Record.AddStmt(E);
2071   for (auto *E : C->assignment_ops())
2072     Record.AddStmt(E);
2073 }
2074 
2075 void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
2076   Record.push_back(C->varlist_size());
2077   Record.AddSourceLocation(C->getLParenLoc());
2078   for (auto *VE : C->varlists())
2079     Record.AddStmt(VE);
2080   for (auto *E : C->source_exprs())
2081     Record.AddStmt(E);
2082   for (auto *E : C->destination_exprs())
2083     Record.AddStmt(E);
2084   for (auto *E : C->assignment_ops())
2085     Record.AddStmt(E);
2086 }
2087 
2088 void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) {
2089   Record.push_back(C->varlist_size());
2090   Record.AddSourceLocation(C->getLParenLoc());
2091   for (auto *VE : C->varlists())
2092     Record.AddStmt(VE);
2093 }
2094 
2095 void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) {
2096   Record.push_back(C->varlist_size());
2097   Record.AddSourceLocation(C->getLParenLoc());
2098   Record.push_back(C->getDependencyKind());
2099   Record.AddSourceLocation(C->getDependencyLoc());
2100   Record.AddSourceLocation(C->getColonLoc());
2101   for (auto *VE : C->varlists())
2102     Record.AddStmt(VE);
2103   Record.AddStmt(C->getCounterValue());
2104 }
2105 
2106 void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) {
2107   VisitOMPClauseWithPreInit(C);
2108   Record.AddStmt(C->getDevice());
2109   Record.AddSourceLocation(C->getLParenLoc());
2110 }
2111 
2112 void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) {
2113   Record.push_back(C->varlist_size());
2114   Record.push_back(C->getUniqueDeclarationsNum());
2115   Record.push_back(C->getTotalComponentListNum());
2116   Record.push_back(C->getTotalComponentsNum());
2117   Record.AddSourceLocation(C->getLParenLoc());
2118   Record.push_back(C->getMapTypeModifier());
2119   Record.push_back(C->getMapType());
2120   Record.AddSourceLocation(C->getMapLoc());
2121   Record.AddSourceLocation(C->getColonLoc());
2122   for (auto *E : C->varlists())
2123     Record.AddStmt(E);
2124   for (auto *D : C->all_decls())
2125     Record.AddDeclRef(D);
2126   for (auto N : C->all_num_lists())
2127     Record.push_back(N);
2128   for (auto N : C->all_lists_sizes())
2129     Record.push_back(N);
2130   for (auto &M : C->all_components()) {
2131     Record.AddStmt(M.getAssociatedExpression());
2132     Record.AddDeclRef(M.getAssociatedDeclaration());
2133   }
2134 }
2135 
2136 void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
2137   VisitOMPClauseWithPreInit(C);
2138   Record.AddStmt(C->getNumTeams());
2139   Record.AddSourceLocation(C->getLParenLoc());
2140 }
2141 
2142 void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
2143   VisitOMPClauseWithPreInit(C);
2144   Record.AddStmt(C->getThreadLimit());
2145   Record.AddSourceLocation(C->getLParenLoc());
2146 }
2147 
2148 void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) {
2149   Record.AddStmt(C->getPriority());
2150   Record.AddSourceLocation(C->getLParenLoc());
2151 }
2152 
2153 void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
2154   Record.AddStmt(C->getGrainsize());
2155   Record.AddSourceLocation(C->getLParenLoc());
2156 }
2157 
2158 void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
2159   Record.AddStmt(C->getNumTasks());
2160   Record.AddSourceLocation(C->getLParenLoc());
2161 }
2162 
2163 void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) {
2164   Record.AddStmt(C->getHint());
2165   Record.AddSourceLocation(C->getLParenLoc());
2166 }
2167 
2168 void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) {
2169   VisitOMPClauseWithPreInit(C);
2170   Record.push_back(C->getDistScheduleKind());
2171   Record.AddStmt(C->getChunkSize());
2172   Record.AddSourceLocation(C->getLParenLoc());
2173   Record.AddSourceLocation(C->getDistScheduleKindLoc());
2174   Record.AddSourceLocation(C->getCommaLoc());
2175 }
2176 
2177 void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
2178   Record.push_back(C->getDefaultmapKind());
2179   Record.push_back(C->getDefaultmapModifier());
2180   Record.AddSourceLocation(C->getLParenLoc());
2181   Record.AddSourceLocation(C->getDefaultmapModifierLoc());
2182   Record.AddSourceLocation(C->getDefaultmapKindLoc());
2183 }
2184 
2185 void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) {
2186   Record.push_back(C->varlist_size());
2187   Record.push_back(C->getUniqueDeclarationsNum());
2188   Record.push_back(C->getTotalComponentListNum());
2189   Record.push_back(C->getTotalComponentsNum());
2190   Record.AddSourceLocation(C->getLParenLoc());
2191   for (auto *E : C->varlists())
2192     Record.AddStmt(E);
2193   for (auto *D : C->all_decls())
2194     Record.AddDeclRef(D);
2195   for (auto N : C->all_num_lists())
2196     Record.push_back(N);
2197   for (auto N : C->all_lists_sizes())
2198     Record.push_back(N);
2199   for (auto &M : C->all_components()) {
2200     Record.AddStmt(M.getAssociatedExpression());
2201     Record.AddDeclRef(M.getAssociatedDeclaration());
2202   }
2203 }
2204 
2205 void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) {
2206   Record.push_back(C->varlist_size());
2207   Record.push_back(C->getUniqueDeclarationsNum());
2208   Record.push_back(C->getTotalComponentListNum());
2209   Record.push_back(C->getTotalComponentsNum());
2210   Record.AddSourceLocation(C->getLParenLoc());
2211   for (auto *E : C->varlists())
2212     Record.AddStmt(E);
2213   for (auto *D : C->all_decls())
2214     Record.AddDeclRef(D);
2215   for (auto N : C->all_num_lists())
2216     Record.push_back(N);
2217   for (auto N : C->all_lists_sizes())
2218     Record.push_back(N);
2219   for (auto &M : C->all_components()) {
2220     Record.AddStmt(M.getAssociatedExpression());
2221     Record.AddDeclRef(M.getAssociatedDeclaration());
2222   }
2223 }
2224 
2225 void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
2226   Record.push_back(C->varlist_size());
2227   Record.push_back(C->getUniqueDeclarationsNum());
2228   Record.push_back(C->getTotalComponentListNum());
2229   Record.push_back(C->getTotalComponentsNum());
2230   Record.AddSourceLocation(C->getLParenLoc());
2231   for (auto *E : C->varlists())
2232     Record.AddStmt(E);
2233   for (auto *VE : C->private_copies())
2234     Record.AddStmt(VE);
2235   for (auto *VE : C->inits())
2236     Record.AddStmt(VE);
2237   for (auto *D : C->all_decls())
2238     Record.AddDeclRef(D);
2239   for (auto N : C->all_num_lists())
2240     Record.push_back(N);
2241   for (auto N : C->all_lists_sizes())
2242     Record.push_back(N);
2243   for (auto &M : C->all_components()) {
2244     Record.AddStmt(M.getAssociatedExpression());
2245     Record.AddDeclRef(M.getAssociatedDeclaration());
2246   }
2247 }
2248 
2249 void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
2250   Record.push_back(C->varlist_size());
2251   Record.push_back(C->getUniqueDeclarationsNum());
2252   Record.push_back(C->getTotalComponentListNum());
2253   Record.push_back(C->getTotalComponentsNum());
2254   Record.AddSourceLocation(C->getLParenLoc());
2255   for (auto *E : C->varlists())
2256     Record.AddStmt(E);
2257   for (auto *D : C->all_decls())
2258     Record.AddDeclRef(D);
2259   for (auto N : C->all_num_lists())
2260     Record.push_back(N);
2261   for (auto N : C->all_lists_sizes())
2262     Record.push_back(N);
2263   for (auto &M : C->all_components()) {
2264     Record.AddStmt(M.getAssociatedExpression());
2265     Record.AddDeclRef(M.getAssociatedDeclaration());
2266   }
2267 }
2268 
2269 //===----------------------------------------------------------------------===//
2270 // OpenMP Directives.
2271 //===----------------------------------------------------------------------===//
2272 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2273   Record.AddSourceLocation(E->getLocStart());
2274   Record.AddSourceLocation(E->getLocEnd());
2275   OMPClauseWriter ClauseWriter(Record);
2276   for (unsigned i = 0; i < E->getNumClauses(); ++i) {
2277     ClauseWriter.writeClause(E->getClause(i));
2278   }
2279   if (E->hasAssociatedStmt())
2280     Record.AddStmt(E->getAssociatedStmt());
2281 }
2282 
2283 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
2284   VisitStmt(D);
2285   Record.push_back(D->getNumClauses());
2286   Record.push_back(D->getCollapsedNumber());
2287   VisitOMPExecutableDirective(D);
2288   Record.AddStmt(D->getIterationVariable());
2289   Record.AddStmt(D->getLastIteration());
2290   Record.AddStmt(D->getCalcLastIteration());
2291   Record.AddStmt(D->getPreCond());
2292   Record.AddStmt(D->getCond());
2293   Record.AddStmt(D->getInit());
2294   Record.AddStmt(D->getInc());
2295   Record.AddStmt(D->getPreInits());
2296   if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
2297       isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
2298       isOpenMPDistributeDirective(D->getDirectiveKind())) {
2299     Record.AddStmt(D->getIsLastIterVariable());
2300     Record.AddStmt(D->getLowerBoundVariable());
2301     Record.AddStmt(D->getUpperBoundVariable());
2302     Record.AddStmt(D->getStrideVariable());
2303     Record.AddStmt(D->getEnsureUpperBound());
2304     Record.AddStmt(D->getNextLowerBound());
2305     Record.AddStmt(D->getNextUpperBound());
2306     Record.AddStmt(D->getNumIterations());
2307   }
2308   if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
2309     Record.AddStmt(D->getPrevLowerBoundVariable());
2310     Record.AddStmt(D->getPrevUpperBoundVariable());
2311     Record.AddStmt(D->getDistInc());
2312     Record.AddStmt(D->getPrevEnsureUpperBound());
2313     Record.AddStmt(D->getCombinedLowerBoundVariable());
2314     Record.AddStmt(D->getCombinedUpperBoundVariable());
2315     Record.AddStmt(D->getCombinedEnsureUpperBound());
2316     Record.AddStmt(D->getCombinedInit());
2317     Record.AddStmt(D->getCombinedCond());
2318     Record.AddStmt(D->getCombinedNextLowerBound());
2319     Record.AddStmt(D->getCombinedNextUpperBound());
2320   }
2321   for (auto I : D->counters()) {
2322     Record.AddStmt(I);
2323   }
2324   for (auto I : D->private_counters()) {
2325     Record.AddStmt(I);
2326   }
2327   for (auto I : D->inits()) {
2328     Record.AddStmt(I);
2329   }
2330   for (auto I : D->updates()) {
2331     Record.AddStmt(I);
2332   }
2333   for (auto I : D->finals()) {
2334     Record.AddStmt(I);
2335   }
2336 }
2337 
2338 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2339   VisitStmt(D);
2340   Record.push_back(D->getNumClauses());
2341   VisitOMPExecutableDirective(D);
2342   Record.push_back(D->hasCancel() ? 1 : 0);
2343   Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2344 }
2345 
2346 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2347   VisitOMPLoopDirective(D);
2348   Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2349 }
2350 
2351 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2352   VisitOMPLoopDirective(D);
2353   Record.push_back(D->hasCancel() ? 1 : 0);
2354   Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2355 }
2356 
2357 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2358   VisitOMPLoopDirective(D);
2359   Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2360 }
2361 
2362 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2363   VisitStmt(D);
2364   Record.push_back(D->getNumClauses());
2365   VisitOMPExecutableDirective(D);
2366   Record.push_back(D->hasCancel() ? 1 : 0);
2367   Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2368 }
2369 
2370 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2371   VisitStmt(D);
2372   VisitOMPExecutableDirective(D);
2373   Record.push_back(D->hasCancel() ? 1 : 0);
2374   Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2375 }
2376 
2377 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2378   VisitStmt(D);
2379   Record.push_back(D->getNumClauses());
2380   VisitOMPExecutableDirective(D);
2381   Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2382 }
2383 
2384 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2385   VisitStmt(D);
2386   VisitOMPExecutableDirective(D);
2387   Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2388 }
2389 
2390 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2391   VisitStmt(D);
2392   Record.push_back(D->getNumClauses());
2393   VisitOMPExecutableDirective(D);
2394   Record.AddDeclarationNameInfo(D->getDirectiveName());
2395   Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2396 }
2397 
2398 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2399   VisitOMPLoopDirective(D);
2400   Record.push_back(D->hasCancel() ? 1 : 0);
2401   Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2402 }
2403 
2404 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2405     OMPParallelForSimdDirective *D) {
2406   VisitOMPLoopDirective(D);
2407   Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2408 }
2409 
2410 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2411     OMPParallelSectionsDirective *D) {
2412   VisitStmt(D);
2413   Record.push_back(D->getNumClauses());
2414   VisitOMPExecutableDirective(D);
2415   Record.push_back(D->hasCancel() ? 1 : 0);
2416   Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2417 }
2418 
2419 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2420   VisitStmt(D);
2421   Record.push_back(D->getNumClauses());
2422   VisitOMPExecutableDirective(D);
2423   Record.push_back(D->hasCancel() ? 1 : 0);
2424   Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2425 }
2426 
2427 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2428   VisitStmt(D);
2429   Record.push_back(D->getNumClauses());
2430   VisitOMPExecutableDirective(D);
2431   Record.AddStmt(D->getX());
2432   Record.AddStmt(D->getV());
2433   Record.AddStmt(D->getExpr());
2434   Record.AddStmt(D->getUpdateExpr());
2435   Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
2436   Record.push_back(D->isPostfixUpdate() ? 1 : 0);
2437   Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2438 }
2439 
2440 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2441   VisitStmt(D);
2442   Record.push_back(D->getNumClauses());
2443   VisitOMPExecutableDirective(D);
2444   Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2445 }
2446 
2447 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2448   VisitStmt(D);
2449   Record.push_back(D->getNumClauses());
2450   VisitOMPExecutableDirective(D);
2451   Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2452 }
2453 
2454 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2455     OMPTargetEnterDataDirective *D) {
2456   VisitStmt(D);
2457   Record.push_back(D->getNumClauses());
2458   VisitOMPExecutableDirective(D);
2459   Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2460 }
2461 
2462 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2463     OMPTargetExitDataDirective *D) {
2464   VisitStmt(D);
2465   Record.push_back(D->getNumClauses());
2466   VisitOMPExecutableDirective(D);
2467   Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2468 }
2469 
2470 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2471     OMPTargetParallelDirective *D) {
2472   VisitStmt(D);
2473   Record.push_back(D->getNumClauses());
2474   VisitOMPExecutableDirective(D);
2475   Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2476 }
2477 
2478 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2479     OMPTargetParallelForDirective *D) {
2480   VisitOMPLoopDirective(D);
2481   Record.push_back(D->hasCancel() ? 1 : 0);
2482   Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2483 }
2484 
2485 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2486   VisitStmt(D);
2487   VisitOMPExecutableDirective(D);
2488   Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2489 }
2490 
2491 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2492   VisitStmt(D);
2493   VisitOMPExecutableDirective(D);
2494   Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2495 }
2496 
2497 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2498   VisitStmt(D);
2499   VisitOMPExecutableDirective(D);
2500   Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2501 }
2502 
2503 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2504   VisitStmt(D);
2505   Record.push_back(D->getNumClauses());
2506   VisitOMPExecutableDirective(D);
2507   Record.AddStmt(D->getReductionRef());
2508   Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2509 }
2510 
2511 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2512   VisitStmt(D);
2513   Record.push_back(D->getNumClauses());
2514   VisitOMPExecutableDirective(D);
2515   Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2516 }
2517 
2518 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2519   VisitStmt(D);
2520   Record.push_back(D->getNumClauses());
2521   VisitOMPExecutableDirective(D);
2522   Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2523 }
2524 
2525 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2526   VisitStmt(D);
2527   Record.push_back(D->getNumClauses());
2528   VisitOMPExecutableDirective(D);
2529   Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2530 }
2531 
2532 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2533     OMPCancellationPointDirective *D) {
2534   VisitStmt(D);
2535   VisitOMPExecutableDirective(D);
2536   Record.push_back(D->getCancelRegion());
2537   Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2538 }
2539 
2540 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2541   VisitStmt(D);
2542   Record.push_back(D->getNumClauses());
2543   VisitOMPExecutableDirective(D);
2544   Record.push_back(D->getCancelRegion());
2545   Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2546 }
2547 
2548 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2549   VisitOMPLoopDirective(D);
2550   Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2551 }
2552 
2553 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2554   VisitOMPLoopDirective(D);
2555   Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2556 }
2557 
2558 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2559   VisitOMPLoopDirective(D);
2560   Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2561 }
2562 
2563 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2564   VisitStmt(D);
2565   Record.push_back(D->getNumClauses());
2566   VisitOMPExecutableDirective(D);
2567   Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2568 }
2569 
2570 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2571     OMPDistributeParallelForDirective *D) {
2572   VisitOMPLoopDirective(D);
2573   Record.push_back(D->hasCancel() ? 1 : 0);
2574   Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2575 }
2576 
2577 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2578     OMPDistributeParallelForSimdDirective *D) {
2579   VisitOMPLoopDirective(D);
2580   Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2581 }
2582 
2583 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2584     OMPDistributeSimdDirective *D) {
2585   VisitOMPLoopDirective(D);
2586   Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2587 }
2588 
2589 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2590     OMPTargetParallelForSimdDirective *D) {
2591   VisitOMPLoopDirective(D);
2592   Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2593 }
2594 
2595 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2596   VisitOMPLoopDirective(D);
2597   Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2598 }
2599 
2600 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2601     OMPTeamsDistributeDirective *D) {
2602   VisitOMPLoopDirective(D);
2603   Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2604 }
2605 
2606 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2607     OMPTeamsDistributeSimdDirective *D) {
2608   VisitOMPLoopDirective(D);
2609   Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2610 }
2611 
2612 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2613     OMPTeamsDistributeParallelForSimdDirective *D) {
2614   VisitOMPLoopDirective(D);
2615   Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2616 }
2617 
2618 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2619     OMPTeamsDistributeParallelForDirective *D) {
2620   VisitOMPLoopDirective(D);
2621   Record.push_back(D->hasCancel() ? 1 : 0);
2622   Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2623 }
2624 
2625 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2626   VisitStmt(D);
2627   Record.push_back(D->getNumClauses());
2628   VisitOMPExecutableDirective(D);
2629   Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2630 }
2631 
2632 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2633     OMPTargetTeamsDistributeDirective *D) {
2634   VisitOMPLoopDirective(D);
2635   Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2636 }
2637 
2638 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2639     OMPTargetTeamsDistributeParallelForDirective *D) {
2640   VisitOMPLoopDirective(D);
2641   Record.push_back(D->hasCancel() ? 1 : 0);
2642   Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2643 }
2644 
2645 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2646     OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2647   VisitOMPLoopDirective(D);
2648   Code = serialization::
2649       STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2650 }
2651 
2652 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2653     OMPTargetTeamsDistributeSimdDirective *D) {
2654   VisitOMPLoopDirective(D);
2655   Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2656 }
2657 
2658 //===----------------------------------------------------------------------===//
2659 // ASTWriter Implementation
2660 //===----------------------------------------------------------------------===//
2661 
2662 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2663   assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
2664          "SwitchCase recorded twice");
2665   unsigned NextID = SwitchCaseIDs.size();
2666   SwitchCaseIDs[S] = NextID;
2667   return NextID;
2668 }
2669 
2670 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2671   assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
2672          "SwitchCase hasn't been seen yet");
2673   return SwitchCaseIDs[S];
2674 }
2675 
2676 void ASTWriter::ClearSwitchCaseIDs() {
2677   SwitchCaseIDs.clear();
2678 }
2679 
2680 /// \brief Write the given substatement or subexpression to the
2681 /// bitstream.
2682 void ASTWriter::WriteSubStmt(Stmt *S) {
2683   RecordData Record;
2684   ASTStmtWriter Writer(*this, Record);
2685   ++NumStatements;
2686 
2687   if (!S) {
2688     Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2689     return;
2690   }
2691 
2692   llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2693   if (I != SubStmtEntries.end()) {
2694     Record.push_back(I->second);
2695     Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2696     return;
2697   }
2698 
2699 #ifndef NDEBUG
2700   assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2701 
2702   struct ParentStmtInserterRAII {
2703     Stmt *S;
2704     llvm::DenseSet<Stmt *> &ParentStmts;
2705 
2706     ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2707       : S(S), ParentStmts(ParentStmts) {
2708       ParentStmts.insert(S);
2709     }
2710     ~ParentStmtInserterRAII() {
2711       ParentStmts.erase(S);
2712     }
2713   };
2714 
2715   ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2716 #endif
2717 
2718   Writer.Visit(S);
2719 
2720   uint64_t Offset = Writer.Emit();
2721   SubStmtEntries[S] = Offset;
2722 }
2723 
2724 /// \brief Flush all of the statements that have been added to the
2725 /// queue via AddStmt().
2726 void ASTRecordWriter::FlushStmts() {
2727   // We expect to be the only consumer of the two temporary statement maps,
2728   // assert that they are empty.
2729   assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2730   assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2731 
2732   for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2733     Writer->WriteSubStmt(StmtsToEmit[I]);
2734 
2735     assert(N == StmtsToEmit.size() && "record modified while being written!");
2736 
2737     // Note that we are at the end of a full expression. Any
2738     // expression records that follow this one are part of a different
2739     // expression.
2740     Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2741 
2742     Writer->SubStmtEntries.clear();
2743     Writer->ParentStmts.clear();
2744   }
2745 
2746   StmtsToEmit.clear();
2747 }
2748 
2749 void ASTRecordWriter::FlushSubStmts() {
2750   // For a nested statement, write out the substatements in reverse order (so
2751   // that a simple stack machine can be used when loading), and don't emit a
2752   // STMT_STOP after each one.
2753   for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2754     Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
2755     assert(N == StmtsToEmit.size() && "record modified while being written!");
2756   }
2757 
2758   StmtsToEmit.clear();
2759 }
2760