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