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