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