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