1//===--- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------*- C++ -*-===//
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// Statement/expression deserialization.  This implements the
11// ASTReader::ReadStmt method.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Serialization/ASTReader.h"
16#include "clang/AST/ASTContext.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/DeclTemplate.h"
19#include "clang/AST/StmtVisitor.h"
20#include "clang/Lex/Token.h"
21#include "llvm/ADT/SmallString.h"
22using namespace clang;
23using namespace clang::serialization;
24
25namespace clang {
26
27  class ASTStmtReader : public StmtVisitor<ASTStmtReader> {
28    friend class OMPClauseReader;
29    typedef ASTReader::RecordData RecordData;
30
31    ASTReader &Reader;
32    ModuleFile &F;
33    llvm::BitstreamCursor &DeclsCursor;
34    const ASTReader::RecordData &Record;
35    unsigned &Idx;
36
37    Token ReadToken(const RecordData &R, unsigned &I) {
38      return Reader.ReadToken(F, R, I);
39    }
40
41    SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
42      return Reader.ReadSourceLocation(F, R, I);
43    }
44
45    SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
46      return Reader.ReadSourceRange(F, R, I);
47    }
48
49    std::string ReadString(const RecordData &R, unsigned &I) {
50      return Reader.ReadString(R, I);
51    }
52
53    TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
54      return Reader.GetTypeSourceInfo(F, R, I);
55    }
56
57    serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
58      return Reader.ReadDeclID(F, R, I);
59    }
60
61    Decl *ReadDecl(const RecordData &R, unsigned &I) {
62      return Reader.ReadDecl(F, R, I);
63    }
64
65    template<typename T>
66    T *ReadDeclAs(const RecordData &R, unsigned &I) {
67      return Reader.ReadDeclAs<T>(F, R, I);
68    }
69
70    void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
71                                const ASTReader::RecordData &R, unsigned &I) {
72      Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
73    }
74
75    void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
76                                const ASTReader::RecordData &R, unsigned &I) {
77      Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
78    }
79
80  public:
81    ASTStmtReader(ASTReader &Reader, ModuleFile &F,
82                  llvm::BitstreamCursor &Cursor,
83                  const ASTReader::RecordData &Record, unsigned &Idx)
84      : Reader(Reader), F(F), DeclsCursor(Cursor), Record(Record), Idx(Idx) { }
85
86    /// \brief The number of record fields required for the Stmt class
87    /// itself.
88    static const unsigned NumStmtFields = 0;
89
90    /// \brief The number of record fields required for the Expr class
91    /// itself.
92    static const unsigned NumExprFields = NumStmtFields + 7;
93
94    /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
95    void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
96                                   unsigned NumTemplateArgs);
97    /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
98    void ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &ArgList,
99                                          unsigned NumTemplateArgs);
100
101    void VisitStmt(Stmt *S);
102#define STMT(Type, Base) \
103    void Visit##Type(Type *);
104#include "clang/AST/StmtNodes.inc"
105  };
106}
107
108void ASTStmtReader::
109ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
110                          unsigned NumTemplateArgs) {
111  SourceLocation TemplateKWLoc = ReadSourceLocation(Record, Idx);
112  TemplateArgumentListInfo ArgInfo;
113  ArgInfo.setLAngleLoc(ReadSourceLocation(Record, Idx));
114  ArgInfo.setRAngleLoc(ReadSourceLocation(Record, Idx));
115  for (unsigned i = 0; i != NumTemplateArgs; ++i)
116    ArgInfo.addArgument(
117        Reader.ReadTemplateArgumentLoc(F, Record, Idx));
118  Args.initializeFrom(TemplateKWLoc, ArgInfo);
119}
120
121void ASTStmtReader::VisitStmt(Stmt *S) {
122  assert(Idx == NumStmtFields && "Incorrect statement field count");
123}
124
125void ASTStmtReader::VisitNullStmt(NullStmt *S) {
126  VisitStmt(S);
127  S->setSemiLoc(ReadSourceLocation(Record, Idx));
128  S->HasLeadingEmptyMacro = Record[Idx++];
129}
130
131void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
132  VisitStmt(S);
133  SmallVector<Stmt *, 16> Stmts;
134  unsigned NumStmts = Record[Idx++];
135  while (NumStmts--)
136    Stmts.push_back(Reader.ReadSubStmt());
137  S->setStmts(Reader.getContext(), Stmts.data(), Stmts.size());
138  S->setLBracLoc(ReadSourceLocation(Record, Idx));
139  S->setRBracLoc(ReadSourceLocation(Record, Idx));
140}
141
142void ASTStmtReader::VisitSwitchCase(SwitchCase *S) {
143  VisitStmt(S);
144  Reader.RecordSwitchCaseID(S, Record[Idx++]);
145  S->setKeywordLoc(ReadSourceLocation(Record, Idx));
146  S->setColonLoc(ReadSourceLocation(Record, Idx));
147}
148
149void ASTStmtReader::VisitCaseStmt(CaseStmt *S) {
150  VisitSwitchCase(S);
151  S->setLHS(Reader.ReadSubExpr());
152  S->setRHS(Reader.ReadSubExpr());
153  S->setSubStmt(Reader.ReadSubStmt());
154  S->setEllipsisLoc(ReadSourceLocation(Record, Idx));
155}
156
157void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) {
158  VisitSwitchCase(S);
159  S->setSubStmt(Reader.ReadSubStmt());
160}
161
162void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
163  VisitStmt(S);
164  LabelDecl *LD = ReadDeclAs<LabelDecl>(Record, Idx);
165  LD->setStmt(S);
166  S->setDecl(LD);
167  S->setSubStmt(Reader.ReadSubStmt());
168  S->setIdentLoc(ReadSourceLocation(Record, Idx));
169}
170
171void ASTStmtReader::VisitAttributedStmt(AttributedStmt *S) {
172  VisitStmt(S);
173  uint64_t NumAttrs = Record[Idx++];
174  AttrVec Attrs;
175  Reader.ReadAttributes(F, Attrs, Record, Idx);
176  (void)NumAttrs;
177  assert(NumAttrs == S->NumAttrs);
178  assert(NumAttrs == Attrs.size());
179  std::copy(Attrs.begin(), Attrs.end(), S->getAttrArrayPtr());
180  S->SubStmt = Reader.ReadSubStmt();
181  S->AttrLoc = ReadSourceLocation(Record, Idx);
182}
183
184void ASTStmtReader::VisitIfStmt(IfStmt *S) {
185  VisitStmt(S);
186  S->setConditionVariable(Reader.getContext(),
187                          ReadDeclAs<VarDecl>(Record, Idx));
188  S->setCond(Reader.ReadSubExpr());
189  S->setThen(Reader.ReadSubStmt());
190  S->setElse(Reader.ReadSubStmt());
191  S->setIfLoc(ReadSourceLocation(Record, Idx));
192  S->setElseLoc(ReadSourceLocation(Record, Idx));
193}
194
195void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) {
196  VisitStmt(S);
197  S->setConditionVariable(Reader.getContext(),
198                          ReadDeclAs<VarDecl>(Record, Idx));
199  S->setCond(Reader.ReadSubExpr());
200  S->setBody(Reader.ReadSubStmt());
201  S->setSwitchLoc(ReadSourceLocation(Record, Idx));
202  if (Record[Idx++])
203    S->setAllEnumCasesCovered();
204
205  SwitchCase *PrevSC = nullptr;
206  for (unsigned N = Record.size(); Idx != N; ++Idx) {
207    SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]);
208    if (PrevSC)
209      PrevSC->setNextSwitchCase(SC);
210    else
211      S->setSwitchCaseList(SC);
212
213    PrevSC = SC;
214  }
215}
216
217void ASTStmtReader::VisitWhileStmt(WhileStmt *S) {
218  VisitStmt(S);
219  S->setConditionVariable(Reader.getContext(),
220                          ReadDeclAs<VarDecl>(Record, Idx));
221
222  S->setCond(Reader.ReadSubExpr());
223  S->setBody(Reader.ReadSubStmt());
224  S->setWhileLoc(ReadSourceLocation(Record, Idx));
225}
226
227void ASTStmtReader::VisitDoStmt(DoStmt *S) {
228  VisitStmt(S);
229  S->setCond(Reader.ReadSubExpr());
230  S->setBody(Reader.ReadSubStmt());
231  S->setDoLoc(ReadSourceLocation(Record, Idx));
232  S->setWhileLoc(ReadSourceLocation(Record, Idx));
233  S->setRParenLoc(ReadSourceLocation(Record, Idx));
234}
235
236void ASTStmtReader::VisitForStmt(ForStmt *S) {
237  VisitStmt(S);
238  S->setInit(Reader.ReadSubStmt());
239  S->setCond(Reader.ReadSubExpr());
240  S->setConditionVariable(Reader.getContext(),
241                          ReadDeclAs<VarDecl>(Record, Idx));
242  S->setInc(Reader.ReadSubExpr());
243  S->setBody(Reader.ReadSubStmt());
244  S->setForLoc(ReadSourceLocation(Record, Idx));
245  S->setLParenLoc(ReadSourceLocation(Record, Idx));
246  S->setRParenLoc(ReadSourceLocation(Record, Idx));
247}
248
249void ASTStmtReader::VisitGotoStmt(GotoStmt *S) {
250  VisitStmt(S);
251  S->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
252  S->setGotoLoc(ReadSourceLocation(Record, Idx));
253  S->setLabelLoc(ReadSourceLocation(Record, Idx));
254}
255
256void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
257  VisitStmt(S);
258  S->setGotoLoc(ReadSourceLocation(Record, Idx));
259  S->setStarLoc(ReadSourceLocation(Record, Idx));
260  S->setTarget(Reader.ReadSubExpr());
261}
262
263void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) {
264  VisitStmt(S);
265  S->setContinueLoc(ReadSourceLocation(Record, Idx));
266}
267
268void ASTStmtReader::VisitBreakStmt(BreakStmt *S) {
269  VisitStmt(S);
270  S->setBreakLoc(ReadSourceLocation(Record, Idx));
271}
272
273void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) {
274  VisitStmt(S);
275  S->setRetValue(Reader.ReadSubExpr());
276  S->setReturnLoc(ReadSourceLocation(Record, Idx));
277  S->setNRVOCandidate(ReadDeclAs<VarDecl>(Record, Idx));
278}
279
280void ASTStmtReader::VisitDeclStmt(DeclStmt *S) {
281  VisitStmt(S);
282  S->setStartLoc(ReadSourceLocation(Record, Idx));
283  S->setEndLoc(ReadSourceLocation(Record, Idx));
284
285  if (Idx + 1 == Record.size()) {
286    // Single declaration
287    S->setDeclGroup(DeclGroupRef(ReadDecl(Record, Idx)));
288  } else {
289    SmallVector<Decl *, 16> Decls;
290    Decls.reserve(Record.size() - Idx);
291    for (unsigned N = Record.size(); Idx != N; )
292      Decls.push_back(ReadDecl(Record, Idx));
293    S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(),
294                                                   Decls.data(),
295                                                   Decls.size())));
296  }
297}
298
299void ASTStmtReader::VisitAsmStmt(AsmStmt *S) {
300  VisitStmt(S);
301  S->NumOutputs = Record[Idx++];
302  S->NumInputs = Record[Idx++];
303  S->NumClobbers = Record[Idx++];
304  S->setAsmLoc(ReadSourceLocation(Record, Idx));
305  S->setVolatile(Record[Idx++]);
306  S->setSimple(Record[Idx++]);
307}
308
309void ASTStmtReader::VisitGCCAsmStmt(GCCAsmStmt *S) {
310  VisitAsmStmt(S);
311  S->setRParenLoc(ReadSourceLocation(Record, Idx));
312  S->setAsmString(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
313
314  unsigned NumOutputs = S->getNumOutputs();
315  unsigned NumInputs = S->getNumInputs();
316  unsigned NumClobbers = S->getNumClobbers();
317
318  // Outputs and inputs
319  SmallVector<IdentifierInfo *, 16> Names;
320  SmallVector<StringLiteral*, 16> Constraints;
321  SmallVector<Stmt*, 16> Exprs;
322  for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
323    Names.push_back(Reader.GetIdentifierInfo(F, Record, Idx));
324    Constraints.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
325    Exprs.push_back(Reader.ReadSubStmt());
326  }
327
328  // Constraints
329  SmallVector<StringLiteral*, 16> Clobbers;
330  for (unsigned I = 0; I != NumClobbers; ++I)
331    Clobbers.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
332
333  S->setOutputsAndInputsAndClobbers(Reader.getContext(),
334                                    Names.data(), Constraints.data(),
335                                    Exprs.data(), NumOutputs, NumInputs,
336                                    Clobbers.data(), NumClobbers);
337}
338
339void ASTStmtReader::VisitMSAsmStmt(MSAsmStmt *S) {
340  VisitAsmStmt(S);
341  S->LBraceLoc = ReadSourceLocation(Record, Idx);
342  S->EndLoc = ReadSourceLocation(Record, Idx);
343  S->NumAsmToks = Record[Idx++];
344  std::string AsmStr = ReadString(Record, Idx);
345
346  // Read the tokens.
347  SmallVector<Token, 16> AsmToks;
348  AsmToks.reserve(S->NumAsmToks);
349  for (unsigned i = 0, e = S->NumAsmToks; i != e; ++i) {
350    AsmToks.push_back(ReadToken(Record, Idx));
351  }
352
353  // The calls to reserve() for the FooData vectors are mandatory to
354  // prevent dead StringRefs in the Foo vectors.
355
356  // Read the clobbers.
357  SmallVector<std::string, 16> ClobbersData;
358  SmallVector<StringRef, 16> Clobbers;
359  ClobbersData.reserve(S->NumClobbers);
360  Clobbers.reserve(S->NumClobbers);
361  for (unsigned i = 0, e = S->NumClobbers; i != e; ++i) {
362    ClobbersData.push_back(ReadString(Record, Idx));
363    Clobbers.push_back(ClobbersData.back());
364  }
365
366  // Read the operands.
367  unsigned NumOperands = S->NumOutputs + S->NumInputs;
368  SmallVector<Expr*, 16> Exprs;
369  SmallVector<std::string, 16> ConstraintsData;
370  SmallVector<StringRef, 16> Constraints;
371  Exprs.reserve(NumOperands);
372  ConstraintsData.reserve(NumOperands);
373  Constraints.reserve(NumOperands);
374  for (unsigned i = 0; i != NumOperands; ++i) {
375    Exprs.push_back(cast<Expr>(Reader.ReadSubStmt()));
376    ConstraintsData.push_back(ReadString(Record, Idx));
377    Constraints.push_back(ConstraintsData.back());
378  }
379
380  S->initialize(Reader.getContext(), AsmStr, AsmToks,
381                Constraints, Exprs, Clobbers);
382}
383
384void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) {
385  VisitStmt(S);
386  ++Idx;
387  S->setCapturedDecl(ReadDeclAs<CapturedDecl>(Record, Idx));
388  S->setCapturedRegionKind(static_cast<CapturedRegionKind>(Record[Idx++]));
389  S->setCapturedRecordDecl(ReadDeclAs<RecordDecl>(Record, Idx));
390
391  // Capture inits
392  for (CapturedStmt::capture_init_iterator I = S->capture_init_begin(),
393                                           E = S->capture_init_end();
394       I != E; ++I)
395    *I = Reader.ReadSubExpr();
396
397  // Body
398  S->setCapturedStmt(Reader.ReadSubStmt());
399  S->getCapturedDecl()->setBody(S->getCapturedStmt());
400
401  // Captures
402  for (auto &I : S->captures()) {
403    I.VarAndKind.setPointer(ReadDeclAs<VarDecl>(Record, Idx));
404    I.VarAndKind
405        .setInt(static_cast<CapturedStmt::VariableCaptureKind>(Record[Idx++]));
406    I.Loc = ReadSourceLocation(Record, Idx);
407  }
408}
409
410void ASTStmtReader::VisitExpr(Expr *E) {
411  VisitStmt(E);
412  E->setType(Reader.readType(F, Record, Idx));
413  E->setTypeDependent(Record[Idx++]);
414  E->setValueDependent(Record[Idx++]);
415  E->setInstantiationDependent(Record[Idx++]);
416  E->ExprBits.ContainsUnexpandedParameterPack = Record[Idx++];
417  E->setValueKind(static_cast<ExprValueKind>(Record[Idx++]));
418  E->setObjectKind(static_cast<ExprObjectKind>(Record[Idx++]));
419  assert(Idx == NumExprFields && "Incorrect expression field count");
420}
421
422void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
423  VisitExpr(E);
424  E->setLocation(ReadSourceLocation(Record, Idx));
425  E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]);
426}
427
428void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
429  VisitExpr(E);
430
431  E->DeclRefExprBits.HasQualifier = Record[Idx++];
432  E->DeclRefExprBits.HasFoundDecl = Record[Idx++];
433  E->DeclRefExprBits.HasTemplateKWAndArgsInfo = Record[Idx++];
434  E->DeclRefExprBits.HadMultipleCandidates = Record[Idx++];
435  E->DeclRefExprBits.RefersToEnclosingLocal = Record[Idx++];
436  unsigned NumTemplateArgs = 0;
437  if (E->hasTemplateKWAndArgsInfo())
438    NumTemplateArgs = Record[Idx++];
439
440  if (E->hasQualifier())
441    E->getInternalQualifierLoc()
442      = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
443
444  if (E->hasFoundDecl())
445    E->getInternalFoundDecl() = ReadDeclAs<NamedDecl>(Record, Idx);
446
447  if (E->hasTemplateKWAndArgsInfo())
448    ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
449                              NumTemplateArgs);
450
451  E->setDecl(ReadDeclAs<ValueDecl>(Record, Idx));
452  E->setLocation(ReadSourceLocation(Record, Idx));
453  ReadDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record, Idx);
454}
455
456void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
457  VisitExpr(E);
458  E->setLocation(ReadSourceLocation(Record, Idx));
459  E->setValue(Reader.getContext(), Reader.ReadAPInt(Record, Idx));
460}
461
462void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
463  VisitExpr(E);
464  E->setRawSemantics(static_cast<Stmt::APFloatSemantics>(Record[Idx++]));
465  E->setExact(Record[Idx++]);
466  E->setValue(Reader.getContext(),
467              Reader.ReadAPFloat(Record, E->getSemantics(), Idx));
468  E->setLocation(ReadSourceLocation(Record, Idx));
469}
470
471void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
472  VisitExpr(E);
473  E->setSubExpr(Reader.ReadSubExpr());
474}
475
476void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
477  VisitExpr(E);
478  unsigned Len = Record[Idx++];
479  assert(Record[Idx] == E->getNumConcatenated() &&
480         "Wrong number of concatenated tokens!");
481  ++Idx;
482  StringLiteral::StringKind kind =
483        static_cast<StringLiteral::StringKind>(Record[Idx++]);
484  bool isPascal = Record[Idx++];
485
486  // Read string data
487  SmallString<16> Str(&Record[Idx], &Record[Idx] + Len);
488  E->setString(Reader.getContext(), Str.str(), kind, isPascal);
489  Idx += Len;
490
491  // Read source locations
492  for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
493    E->setStrTokenLoc(I, ReadSourceLocation(Record, Idx));
494}
495
496void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
497  VisitExpr(E);
498  E->setValue(Record[Idx++]);
499  E->setLocation(ReadSourceLocation(Record, Idx));
500  E->setKind(static_cast<CharacterLiteral::CharacterKind>(Record[Idx++]));
501}
502
503void ASTStmtReader::VisitParenExpr(ParenExpr *E) {
504  VisitExpr(E);
505  E->setLParen(ReadSourceLocation(Record, Idx));
506  E->setRParen(ReadSourceLocation(Record, Idx));
507  E->setSubExpr(Reader.ReadSubExpr());
508}
509
510void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
511  VisitExpr(E);
512  unsigned NumExprs = Record[Idx++];
513  E->Exprs = new (Reader.getContext()) Stmt*[NumExprs];
514  for (unsigned i = 0; i != NumExprs; ++i)
515    E->Exprs[i] = Reader.ReadSubStmt();
516  E->NumExprs = NumExprs;
517  E->LParenLoc = ReadSourceLocation(Record, Idx);
518  E->RParenLoc = ReadSourceLocation(Record, Idx);
519}
520
521void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) {
522  VisitExpr(E);
523  E->setSubExpr(Reader.ReadSubExpr());
524  E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
525  E->setOperatorLoc(ReadSourceLocation(Record, Idx));
526}
527
528void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
529  typedef OffsetOfExpr::OffsetOfNode Node;
530  VisitExpr(E);
531  assert(E->getNumComponents() == Record[Idx]);
532  ++Idx;
533  assert(E->getNumExpressions() == Record[Idx]);
534  ++Idx;
535  E->setOperatorLoc(ReadSourceLocation(Record, Idx));
536  E->setRParenLoc(ReadSourceLocation(Record, Idx));
537  E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
538  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
539    Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]);
540    SourceLocation Start = ReadSourceLocation(Record, Idx);
541    SourceLocation End = ReadSourceLocation(Record, Idx);
542    switch (Kind) {
543    case Node::Array:
544      E->setComponent(I, Node(Start, Record[Idx++], End));
545      break;
546
547    case Node::Field:
548      E->setComponent(I, Node(Start, ReadDeclAs<FieldDecl>(Record, Idx), End));
549      break;
550
551    case Node::Identifier:
552      E->setComponent(I,
553                      Node(Start,
554                           Reader.GetIdentifierInfo(F, Record, Idx),
555                           End));
556      break;
557
558    case Node::Base: {
559      CXXBaseSpecifier *Base = new (Reader.getContext()) CXXBaseSpecifier();
560      *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
561      E->setComponent(I, Node(Base));
562      break;
563    }
564    }
565  }
566
567  for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
568    E->setIndexExpr(I, Reader.ReadSubExpr());
569}
570
571void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
572  VisitExpr(E);
573  E->setKind(static_cast<UnaryExprOrTypeTrait>(Record[Idx++]));
574  if (Record[Idx] == 0) {
575    E->setArgument(Reader.ReadSubExpr());
576    ++Idx;
577  } else {
578    E->setArgument(GetTypeSourceInfo(Record, Idx));
579  }
580  E->setOperatorLoc(ReadSourceLocation(Record, Idx));
581  E->setRParenLoc(ReadSourceLocation(Record, Idx));
582}
583
584void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
585  VisitExpr(E);
586  E->setLHS(Reader.ReadSubExpr());
587  E->setRHS(Reader.ReadSubExpr());
588  E->setRBracketLoc(ReadSourceLocation(Record, Idx));
589}
590
591void ASTStmtReader::VisitCallExpr(CallExpr *E) {
592  VisitExpr(E);
593  E->setNumArgs(Reader.getContext(), Record[Idx++]);
594  E->setRParenLoc(ReadSourceLocation(Record, Idx));
595  E->setCallee(Reader.ReadSubExpr());
596  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
597    E->setArg(I, Reader.ReadSubExpr());
598}
599
600void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
601  VisitCallExpr(E);
602}
603
604void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
605  // Don't call VisitExpr, this is fully initialized at creation.
606  assert(E->getStmtClass() == Stmt::MemberExprClass &&
607         "It's a subclass, we must advance Idx!");
608}
609
610void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
611  VisitExpr(E);
612  E->setBase(Reader.ReadSubExpr());
613  E->setIsaMemberLoc(ReadSourceLocation(Record, Idx));
614  E->setOpLoc(ReadSourceLocation(Record, Idx));
615  E->setArrow(Record[Idx++]);
616}
617
618void ASTStmtReader::
619VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
620  VisitExpr(E);
621  E->Operand = Reader.ReadSubExpr();
622  E->setShouldCopy(Record[Idx++]);
623}
624
625void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
626  VisitExplicitCastExpr(E);
627  E->LParenLoc = ReadSourceLocation(Record, Idx);
628  E->BridgeKeywordLoc = ReadSourceLocation(Record, Idx);
629  E->Kind = Record[Idx++];
630}
631
632void ASTStmtReader::VisitCastExpr(CastExpr *E) {
633  VisitExpr(E);
634  unsigned NumBaseSpecs = Record[Idx++];
635  assert(NumBaseSpecs == E->path_size());
636  E->setSubExpr(Reader.ReadSubExpr());
637  E->setCastKind((CastExpr::CastKind)Record[Idx++]);
638  CastExpr::path_iterator BaseI = E->path_begin();
639  while (NumBaseSpecs--) {
640    CXXBaseSpecifier *BaseSpec = new (Reader.getContext()) CXXBaseSpecifier;
641    *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
642    *BaseI++ = BaseSpec;
643  }
644}
645
646void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
647  VisitExpr(E);
648  E->setLHS(Reader.ReadSubExpr());
649  E->setRHS(Reader.ReadSubExpr());
650  E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
651  E->setOperatorLoc(ReadSourceLocation(Record, Idx));
652  E->setFPContractable((bool)Record[Idx++]);
653}
654
655void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
656  VisitBinaryOperator(E);
657  E->setComputationLHSType(Reader.readType(F, Record, Idx));
658  E->setComputationResultType(Reader.readType(F, Record, Idx));
659}
660
661void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
662  VisitExpr(E);
663  E->SubExprs[ConditionalOperator::COND] = Reader.ReadSubExpr();
664  E->SubExprs[ConditionalOperator::LHS] = Reader.ReadSubExpr();
665  E->SubExprs[ConditionalOperator::RHS] = Reader.ReadSubExpr();
666  E->QuestionLoc = ReadSourceLocation(Record, Idx);
667  E->ColonLoc = ReadSourceLocation(Record, Idx);
668}
669
670void
671ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
672  VisitExpr(E);
673  E->OpaqueValue = cast<OpaqueValueExpr>(Reader.ReadSubExpr());
674  E->SubExprs[BinaryConditionalOperator::COMMON] = Reader.ReadSubExpr();
675  E->SubExprs[BinaryConditionalOperator::COND] = Reader.ReadSubExpr();
676  E->SubExprs[BinaryConditionalOperator::LHS] = Reader.ReadSubExpr();
677  E->SubExprs[BinaryConditionalOperator::RHS] = Reader.ReadSubExpr();
678  E->QuestionLoc = ReadSourceLocation(Record, Idx);
679  E->ColonLoc = ReadSourceLocation(Record, Idx);
680}
681
682void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
683  VisitCastExpr(E);
684}
685
686void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
687  VisitCastExpr(E);
688  E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx));
689}
690
691void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
692  VisitExplicitCastExpr(E);
693  E->setLParenLoc(ReadSourceLocation(Record, Idx));
694  E->setRParenLoc(ReadSourceLocation(Record, Idx));
695}
696
697void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
698  VisitExpr(E);
699  E->setLParenLoc(ReadSourceLocation(Record, Idx));
700  E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
701  E->setInitializer(Reader.ReadSubExpr());
702  E->setFileScope(Record[Idx++]);
703}
704
705void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
706  VisitExpr(E);
707  E->setBase(Reader.ReadSubExpr());
708  E->setAccessor(Reader.GetIdentifierInfo(F, Record, Idx));
709  E->setAccessorLoc(ReadSourceLocation(Record, Idx));
710}
711
712void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
713  VisitExpr(E);
714  if (InitListExpr *SyntForm = cast_or_null<InitListExpr>(Reader.ReadSubStmt()))
715    E->setSyntacticForm(SyntForm);
716  E->setLBraceLoc(ReadSourceLocation(Record, Idx));
717  E->setRBraceLoc(ReadSourceLocation(Record, Idx));
718  bool isArrayFiller = Record[Idx++];
719  Expr *filler = nullptr;
720  if (isArrayFiller) {
721    filler = Reader.ReadSubExpr();
722    E->ArrayFillerOrUnionFieldInit = filler;
723  } else
724    E->ArrayFillerOrUnionFieldInit = ReadDeclAs<FieldDecl>(Record, Idx);
725  E->sawArrayRangeDesignator(Record[Idx++]);
726  unsigned NumInits = Record[Idx++];
727  E->reserveInits(Reader.getContext(), NumInits);
728  if (isArrayFiller) {
729    for (unsigned I = 0; I != NumInits; ++I) {
730      Expr *init = Reader.ReadSubExpr();
731      E->updateInit(Reader.getContext(), I, init ? init : filler);
732    }
733  } else {
734    for (unsigned I = 0; I != NumInits; ++I)
735      E->updateInit(Reader.getContext(), I, Reader.ReadSubExpr());
736  }
737}
738
739void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
740  typedef DesignatedInitExpr::Designator Designator;
741
742  VisitExpr(E);
743  unsigned NumSubExprs = Record[Idx++];
744  assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
745  for (unsigned I = 0; I != NumSubExprs; ++I)
746    E->setSubExpr(I, Reader.ReadSubExpr());
747  E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx));
748  E->setGNUSyntax(Record[Idx++]);
749
750  SmallVector<Designator, 4> Designators;
751  while (Idx < Record.size()) {
752    switch ((DesignatorTypes)Record[Idx++]) {
753    case DESIG_FIELD_DECL: {
754      FieldDecl *Field = ReadDeclAs<FieldDecl>(Record, Idx);
755      SourceLocation DotLoc
756        = ReadSourceLocation(Record, Idx);
757      SourceLocation FieldLoc
758        = ReadSourceLocation(Record, Idx);
759      Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
760                                       FieldLoc));
761      Designators.back().setField(Field);
762      break;
763    }
764
765    case DESIG_FIELD_NAME: {
766      const IdentifierInfo *Name = Reader.GetIdentifierInfo(F, Record, Idx);
767      SourceLocation DotLoc
768        = ReadSourceLocation(Record, Idx);
769      SourceLocation FieldLoc
770        = ReadSourceLocation(Record, Idx);
771      Designators.push_back(Designator(Name, DotLoc, FieldLoc));
772      break;
773    }
774
775    case DESIG_ARRAY: {
776      unsigned Index = Record[Idx++];
777      SourceLocation LBracketLoc
778        = ReadSourceLocation(Record, Idx);
779      SourceLocation RBracketLoc
780        = ReadSourceLocation(Record, Idx);
781      Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
782      break;
783    }
784
785    case DESIG_ARRAY_RANGE: {
786      unsigned Index = Record[Idx++];
787      SourceLocation LBracketLoc
788        = ReadSourceLocation(Record, Idx);
789      SourceLocation EllipsisLoc
790        = ReadSourceLocation(Record, Idx);
791      SourceLocation RBracketLoc
792        = ReadSourceLocation(Record, Idx);
793      Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
794                                       RBracketLoc));
795      break;
796    }
797    }
798  }
799  E->setDesignators(Reader.getContext(),
800                    Designators.data(), Designators.size());
801}
802
803void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
804  VisitExpr(E);
805}
806
807void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
808  VisitExpr(E);
809  E->setSubExpr(Reader.ReadSubExpr());
810  E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx));
811  E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
812  E->setRParenLoc(ReadSourceLocation(Record, Idx));
813}
814
815void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
816  VisitExpr(E);
817  E->setAmpAmpLoc(ReadSourceLocation(Record, Idx));
818  E->setLabelLoc(ReadSourceLocation(Record, Idx));
819  E->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
820}
821
822void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
823  VisitExpr(E);
824  E->setLParenLoc(ReadSourceLocation(Record, Idx));
825  E->setRParenLoc(ReadSourceLocation(Record, Idx));
826  E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt()));
827}
828
829void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
830  VisitExpr(E);
831  E->setCond(Reader.ReadSubExpr());
832  E->setLHS(Reader.ReadSubExpr());
833  E->setRHS(Reader.ReadSubExpr());
834  E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
835  E->setRParenLoc(ReadSourceLocation(Record, Idx));
836  E->setIsConditionTrue(Record[Idx++]);
837}
838
839void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
840  VisitExpr(E);
841  E->setTokenLocation(ReadSourceLocation(Record, Idx));
842}
843
844void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
845  VisitExpr(E);
846  SmallVector<Expr *, 16> Exprs;
847  unsigned NumExprs = Record[Idx++];
848  while (NumExprs--)
849    Exprs.push_back(Reader.ReadSubExpr());
850  E->setExprs(Reader.getContext(), Exprs);
851  E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
852  E->setRParenLoc(ReadSourceLocation(Record, Idx));
853}
854
855void ASTStmtReader::VisitConvertVectorExpr(ConvertVectorExpr *E) {
856  VisitExpr(E);
857  E->BuiltinLoc = ReadSourceLocation(Record, Idx);
858  E->RParenLoc = ReadSourceLocation(Record, Idx);
859  E->TInfo = GetTypeSourceInfo(Record, Idx);
860  E->SrcExpr = Reader.ReadSubExpr();
861}
862
863void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
864  VisitExpr(E);
865  E->setBlockDecl(ReadDeclAs<BlockDecl>(Record, Idx));
866}
867
868void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
869  VisitExpr(E);
870  E->NumAssocs = Record[Idx++];
871  E->AssocTypes = new (Reader.getContext()) TypeSourceInfo*[E->NumAssocs];
872  E->SubExprs =
873   new(Reader.getContext()) Stmt*[GenericSelectionExpr::END_EXPR+E->NumAssocs];
874
875  E->SubExprs[GenericSelectionExpr::CONTROLLING] = Reader.ReadSubExpr();
876  for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
877    E->AssocTypes[I] = GetTypeSourceInfo(Record, Idx);
878    E->SubExprs[GenericSelectionExpr::END_EXPR+I] = Reader.ReadSubExpr();
879  }
880  E->ResultIndex = Record[Idx++];
881
882  E->GenericLoc = ReadSourceLocation(Record, Idx);
883  E->DefaultLoc = ReadSourceLocation(Record, Idx);
884  E->RParenLoc = ReadSourceLocation(Record, Idx);
885}
886
887void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
888  VisitExpr(E);
889  unsigned numSemanticExprs = Record[Idx++];
890  assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs);
891  E->PseudoObjectExprBits.ResultIndex = Record[Idx++];
892
893  // Read the syntactic expression.
894  E->getSubExprsBuffer()[0] = Reader.ReadSubExpr();
895
896  // Read all the semantic expressions.
897  for (unsigned i = 0; i != numSemanticExprs; ++i) {
898    Expr *subExpr = Reader.ReadSubExpr();
899    E->getSubExprsBuffer()[i+1] = subExpr;
900  }
901}
902
903void ASTStmtReader::VisitAtomicExpr(AtomicExpr *E) {
904  VisitExpr(E);
905  E->Op = AtomicExpr::AtomicOp(Record[Idx++]);
906  E->NumSubExprs = AtomicExpr::getNumSubExprs(E->Op);
907  for (unsigned I = 0; I != E->NumSubExprs; ++I)
908    E->SubExprs[I] = Reader.ReadSubExpr();
909  E->BuiltinLoc = ReadSourceLocation(Record, Idx);
910  E->RParenLoc = ReadSourceLocation(Record, Idx);
911}
912
913//===----------------------------------------------------------------------===//
914// Objective-C Expressions and Statements
915
916void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
917  VisitExpr(E);
918  E->setString(cast<StringLiteral>(Reader.ReadSubStmt()));
919  E->setAtLoc(ReadSourceLocation(Record, Idx));
920}
921
922void ASTStmtReader::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
923  VisitExpr(E);
924  // could be one of several IntegerLiteral, FloatLiteral, etc.
925  E->SubExpr = Reader.ReadSubStmt();
926  E->BoxingMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
927  E->Range = ReadSourceRange(Record, Idx);
928}
929
930void ASTStmtReader::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
931  VisitExpr(E);
932  unsigned NumElements = Record[Idx++];
933  assert(NumElements == E->getNumElements() && "Wrong number of elements");
934  Expr **Elements = E->getElements();
935  for (unsigned I = 0, N = NumElements; I != N; ++I)
936    Elements[I] = Reader.ReadSubExpr();
937  E->ArrayWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
938  E->Range = ReadSourceRange(Record, Idx);
939}
940
941void ASTStmtReader::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
942  VisitExpr(E);
943  unsigned NumElements = Record[Idx++];
944  assert(NumElements == E->getNumElements() && "Wrong number of elements");
945  bool HasPackExpansions = Record[Idx++];
946  assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch");
947  ObjCDictionaryLiteral::KeyValuePair *KeyValues = E->getKeyValues();
948  ObjCDictionaryLiteral::ExpansionData *Expansions = E->getExpansionData();
949  for (unsigned I = 0; I != NumElements; ++I) {
950    KeyValues[I].Key = Reader.ReadSubExpr();
951    KeyValues[I].Value = Reader.ReadSubExpr();
952    if (HasPackExpansions) {
953      Expansions[I].EllipsisLoc = ReadSourceLocation(Record, Idx);
954      Expansions[I].NumExpansionsPlusOne = Record[Idx++];
955    }
956  }
957  E->DictWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
958  E->Range = ReadSourceRange(Record, Idx);
959}
960
961void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
962  VisitExpr(E);
963  E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
964  E->setAtLoc(ReadSourceLocation(Record, Idx));
965  E->setRParenLoc(ReadSourceLocation(Record, Idx));
966}
967
968void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
969  VisitExpr(E);
970  E->setSelector(Reader.ReadSelector(F, Record, Idx));
971  E->setAtLoc(ReadSourceLocation(Record, Idx));
972  E->setRParenLoc(ReadSourceLocation(Record, Idx));
973}
974
975void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
976  VisitExpr(E);
977  E->setProtocol(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
978  E->setAtLoc(ReadSourceLocation(Record, Idx));
979  E->ProtoLoc = ReadSourceLocation(Record, Idx);
980  E->setRParenLoc(ReadSourceLocation(Record, Idx));
981}
982
983void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
984  VisitExpr(E);
985  E->setDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
986  E->setLocation(ReadSourceLocation(Record, Idx));
987  E->setOpLoc(ReadSourceLocation(Record, Idx));
988  E->setBase(Reader.ReadSubExpr());
989  E->setIsArrow(Record[Idx++]);
990  E->setIsFreeIvar(Record[Idx++]);
991}
992
993void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
994  VisitExpr(E);
995  unsigned MethodRefFlags = Record[Idx++];
996  bool Implicit = Record[Idx++] != 0;
997  if (Implicit) {
998    ObjCMethodDecl *Getter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
999    ObjCMethodDecl *Setter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
1000    E->setImplicitProperty(Getter, Setter, MethodRefFlags);
1001  } else {
1002    E->setExplicitProperty(ReadDeclAs<ObjCPropertyDecl>(Record, Idx),
1003                           MethodRefFlags);
1004  }
1005  E->setLocation(ReadSourceLocation(Record, Idx));
1006  E->setReceiverLocation(ReadSourceLocation(Record, Idx));
1007  switch (Record[Idx++]) {
1008  case 0:
1009    E->setBase(Reader.ReadSubExpr());
1010    break;
1011  case 1:
1012    E->setSuperReceiver(Reader.readType(F, Record, Idx));
1013    break;
1014  case 2:
1015    E->setClassReceiver(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
1016    break;
1017  }
1018}
1019
1020void ASTStmtReader::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1021  VisitExpr(E);
1022  E->setRBracket(ReadSourceLocation(Record, Idx));
1023  E->setBaseExpr(Reader.ReadSubExpr());
1024  E->setKeyExpr(Reader.ReadSubExpr());
1025  E->GetAtIndexMethodDecl = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
1026  E->SetAtIndexMethodDecl = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
1027}
1028
1029void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1030  VisitExpr(E);
1031  assert(Record[Idx] == E->getNumArgs());
1032  ++Idx;
1033  unsigned NumStoredSelLocs = Record[Idx++];
1034  E->SelLocsKind = Record[Idx++];
1035  E->setDelegateInitCall(Record[Idx++]);
1036  E->IsImplicit = Record[Idx++];
1037  ObjCMessageExpr::ReceiverKind Kind
1038    = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
1039  switch (Kind) {
1040  case ObjCMessageExpr::Instance:
1041    E->setInstanceReceiver(Reader.ReadSubExpr());
1042    break;
1043
1044  case ObjCMessageExpr::Class:
1045    E->setClassReceiver(GetTypeSourceInfo(Record, Idx));
1046    break;
1047
1048  case ObjCMessageExpr::SuperClass:
1049  case ObjCMessageExpr::SuperInstance: {
1050    QualType T = Reader.readType(F, Record, Idx);
1051    SourceLocation SuperLoc = ReadSourceLocation(Record, Idx);
1052    E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
1053    break;
1054  }
1055  }
1056
1057  assert(Kind == E->getReceiverKind());
1058
1059  if (Record[Idx++])
1060    E->setMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
1061  else
1062    E->setSelector(Reader.ReadSelector(F, Record, Idx));
1063
1064  E->LBracLoc = ReadSourceLocation(Record, Idx);
1065  E->RBracLoc = ReadSourceLocation(Record, Idx);
1066
1067  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1068    E->setArg(I, Reader.ReadSubExpr());
1069
1070  SourceLocation *Locs = E->getStoredSelLocs();
1071  for (unsigned I = 0; I != NumStoredSelLocs; ++I)
1072    Locs[I] = ReadSourceLocation(Record, Idx);
1073}
1074
1075void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1076  VisitStmt(S);
1077  S->setElement(Reader.ReadSubStmt());
1078  S->setCollection(Reader.ReadSubExpr());
1079  S->setBody(Reader.ReadSubStmt());
1080  S->setForLoc(ReadSourceLocation(Record, Idx));
1081  S->setRParenLoc(ReadSourceLocation(Record, Idx));
1082}
1083
1084void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1085  VisitStmt(S);
1086  S->setCatchBody(Reader.ReadSubStmt());
1087  S->setCatchParamDecl(ReadDeclAs<VarDecl>(Record, Idx));
1088  S->setAtCatchLoc(ReadSourceLocation(Record, Idx));
1089  S->setRParenLoc(ReadSourceLocation(Record, Idx));
1090}
1091
1092void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1093  VisitStmt(S);
1094  S->setFinallyBody(Reader.ReadSubStmt());
1095  S->setAtFinallyLoc(ReadSourceLocation(Record, Idx));
1096}
1097
1098void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1099  VisitStmt(S);
1100  S->setSubStmt(Reader.ReadSubStmt());
1101  S->setAtLoc(ReadSourceLocation(Record, Idx));
1102}
1103
1104void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1105  VisitStmt(S);
1106  assert(Record[Idx] == S->getNumCatchStmts());
1107  ++Idx;
1108  bool HasFinally = Record[Idx++];
1109  S->setTryBody(Reader.ReadSubStmt());
1110  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1111    S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt()));
1112
1113  if (HasFinally)
1114    S->setFinallyStmt(Reader.ReadSubStmt());
1115  S->setAtTryLoc(ReadSourceLocation(Record, Idx));
1116}
1117
1118void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1119  VisitStmt(S);
1120  S->setSynchExpr(Reader.ReadSubStmt());
1121  S->setSynchBody(Reader.ReadSubStmt());
1122  S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx));
1123}
1124
1125void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1126  VisitStmt(S);
1127  S->setThrowExpr(Reader.ReadSubStmt());
1128  S->setThrowLoc(ReadSourceLocation(Record, Idx));
1129}
1130
1131void ASTStmtReader::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1132  VisitExpr(E);
1133  E->setValue(Record[Idx++]);
1134  E->setLocation(ReadSourceLocation(Record, Idx));
1135}
1136
1137//===----------------------------------------------------------------------===//
1138// C++ Expressions and Statements
1139//===----------------------------------------------------------------------===//
1140
1141void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
1142  VisitStmt(S);
1143  S->CatchLoc = ReadSourceLocation(Record, Idx);
1144  S->ExceptionDecl = ReadDeclAs<VarDecl>(Record, Idx);
1145  S->HandlerBlock = Reader.ReadSubStmt();
1146}
1147
1148void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
1149  VisitStmt(S);
1150  assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?");
1151  ++Idx;
1152  S->TryLoc = ReadSourceLocation(Record, Idx);
1153  S->getStmts()[0] = Reader.ReadSubStmt();
1154  for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1155    S->getStmts()[i + 1] = Reader.ReadSubStmt();
1156}
1157
1158void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1159  VisitStmt(S);
1160  S->setForLoc(ReadSourceLocation(Record, Idx));
1161  S->setColonLoc(ReadSourceLocation(Record, Idx));
1162  S->setRParenLoc(ReadSourceLocation(Record, Idx));
1163  S->setRangeStmt(Reader.ReadSubStmt());
1164  S->setBeginEndStmt(Reader.ReadSubStmt());
1165  S->setCond(Reader.ReadSubExpr());
1166  S->setInc(Reader.ReadSubExpr());
1167  S->setLoopVarStmt(Reader.ReadSubStmt());
1168  S->setBody(Reader.ReadSubStmt());
1169}
1170
1171void ASTStmtReader::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1172  VisitStmt(S);
1173  S->KeywordLoc = ReadSourceLocation(Record, Idx);
1174  S->IsIfExists = Record[Idx++];
1175  S->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1176  ReadDeclarationNameInfo(S->NameInfo, Record, Idx);
1177  S->SubStmt = Reader.ReadSubStmt();
1178}
1179
1180void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1181  VisitCallExpr(E);
1182  E->Operator = (OverloadedOperatorKind)Record[Idx++];
1183  E->Range = Reader.ReadSourceRange(F, Record, Idx);
1184  E->setFPContractable((bool)Record[Idx++]);
1185}
1186
1187void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
1188  VisitExpr(E);
1189  E->NumArgs = Record[Idx++];
1190  if (E->NumArgs)
1191    E->Args = new (Reader.getContext()) Stmt*[E->NumArgs];
1192  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1193    E->setArg(I, Reader.ReadSubExpr());
1194  E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
1195  E->setLocation(ReadSourceLocation(Record, Idx));
1196  E->setElidable(Record[Idx++]);
1197  E->setHadMultipleCandidates(Record[Idx++]);
1198  E->setListInitialization(Record[Idx++]);
1199  E->setRequiresZeroInitialization(Record[Idx++]);
1200  E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
1201  E->ParenOrBraceRange = ReadSourceRange(Record, Idx);
1202}
1203
1204void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1205  VisitCXXConstructExpr(E);
1206  E->Type = GetTypeSourceInfo(Record, Idx);
1207}
1208
1209void ASTStmtReader::VisitLambdaExpr(LambdaExpr *E) {
1210  VisitExpr(E);
1211  unsigned NumCaptures = Record[Idx++];
1212  assert(NumCaptures == E->NumCaptures);(void)NumCaptures;
1213  unsigned NumArrayIndexVars = Record[Idx++];
1214  E->IntroducerRange = ReadSourceRange(Record, Idx);
1215  E->CaptureDefault = static_cast<LambdaCaptureDefault>(Record[Idx++]);
1216  E->CaptureDefaultLoc = ReadSourceLocation(Record, Idx);
1217  E->ExplicitParams = Record[Idx++];
1218  E->ExplicitResultType = Record[Idx++];
1219  E->ClosingBrace = ReadSourceLocation(Record, Idx);
1220
1221  // Read capture initializers.
1222  for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1223                                      CEnd = E->capture_init_end();
1224       C != CEnd; ++C)
1225    *C = Reader.ReadSubExpr();
1226
1227  // Read array capture index variables.
1228  if (NumArrayIndexVars > 0) {
1229    unsigned *ArrayIndexStarts = E->getArrayIndexStarts();
1230    for (unsigned I = 0; I != NumCaptures + 1; ++I)
1231      ArrayIndexStarts[I] = Record[Idx++];
1232
1233    VarDecl **ArrayIndexVars = E->getArrayIndexVars();
1234    for (unsigned I = 0; I != NumArrayIndexVars; ++I)
1235      ArrayIndexVars[I] = ReadDeclAs<VarDecl>(Record, Idx);
1236  }
1237}
1238
1239void
1240ASTStmtReader::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1241  VisitExpr(E);
1242  E->SubExpr = Reader.ReadSubExpr();
1243}
1244
1245void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1246  VisitExplicitCastExpr(E);
1247  SourceRange R = ReadSourceRange(Record, Idx);
1248  E->Loc = R.getBegin();
1249  E->RParenLoc = R.getEnd();
1250  R = ReadSourceRange(Record, Idx);
1251  E->AngleBrackets = R;
1252}
1253
1254void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1255  return VisitCXXNamedCastExpr(E);
1256}
1257
1258void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1259  return VisitCXXNamedCastExpr(E);
1260}
1261
1262void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1263  return VisitCXXNamedCastExpr(E);
1264}
1265
1266void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1267  return VisitCXXNamedCastExpr(E);
1268}
1269
1270void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1271  VisitExplicitCastExpr(E);
1272  E->setLParenLoc(ReadSourceLocation(Record, Idx));
1273  E->setRParenLoc(ReadSourceLocation(Record, Idx));
1274}
1275
1276void ASTStmtReader::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1277  VisitCallExpr(E);
1278  E->UDSuffixLoc = ReadSourceLocation(Record, Idx);
1279}
1280
1281void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1282  VisitExpr(E);
1283  E->setValue(Record[Idx++]);
1284  E->setLocation(ReadSourceLocation(Record, Idx));
1285}
1286
1287void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1288  VisitExpr(E);
1289  E->setLocation(ReadSourceLocation(Record, Idx));
1290}
1291
1292void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1293  VisitExpr(E);
1294  E->setSourceRange(ReadSourceRange(Record, Idx));
1295  if (E->isTypeOperand()) { // typeid(int)
1296    E->setTypeOperandSourceInfo(
1297        GetTypeSourceInfo(Record, Idx));
1298    return;
1299  }
1300
1301  // typeid(42+2)
1302  E->setExprOperand(Reader.ReadSubExpr());
1303}
1304
1305void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
1306  VisitExpr(E);
1307  E->setLocation(ReadSourceLocation(Record, Idx));
1308  E->setImplicit(Record[Idx++]);
1309}
1310
1311void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
1312  VisitExpr(E);
1313  E->ThrowLoc = ReadSourceLocation(Record, Idx);
1314  E->Op = Reader.ReadSubExpr();
1315  E->IsThrownVariableInScope = Record[Idx++];
1316}
1317
1318void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1319  VisitExpr(E);
1320
1321  assert((bool)Record[Idx] == E->Param.getInt() && "We messed up at creation ?");
1322  ++Idx; // HasOtherExprStored and SubExpr was handled during creation.
1323  E->Param.setPointer(ReadDeclAs<ParmVarDecl>(Record, Idx));
1324  E->Loc = ReadSourceLocation(Record, Idx);
1325}
1326
1327void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1328  VisitExpr(E);
1329  E->Field = ReadDeclAs<FieldDecl>(Record, Idx);
1330  E->Loc = ReadSourceLocation(Record, Idx);
1331}
1332
1333void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1334  VisitExpr(E);
1335  E->setTemporary(Reader.ReadCXXTemporary(F, Record, Idx));
1336  E->setSubExpr(Reader.ReadSubExpr());
1337}
1338
1339void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1340  VisitExpr(E);
1341  E->TypeInfo = GetTypeSourceInfo(Record, Idx);
1342  E->RParenLoc = ReadSourceLocation(Record, Idx);
1343}
1344
1345void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
1346  VisitExpr(E);
1347  E->GlobalNew = Record[Idx++];
1348  bool isArray = Record[Idx++];
1349  E->UsualArrayDeleteWantsSize = Record[Idx++];
1350  unsigned NumPlacementArgs = Record[Idx++];
1351  E->StoredInitializationStyle = Record[Idx++];
1352  E->setOperatorNew(ReadDeclAs<FunctionDecl>(Record, Idx));
1353  E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx));
1354  E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
1355  E->TypeIdParens = ReadSourceRange(Record, Idx);
1356  E->Range = ReadSourceRange(Record, Idx);
1357  E->DirectInitRange = ReadSourceRange(Record, Idx);
1358
1359  E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs,
1360                       E->StoredInitializationStyle != 0);
1361
1362  // Install all the subexpressions.
1363  for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
1364       I != e; ++I)
1365    *I = Reader.ReadSubStmt();
1366}
1367
1368void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1369  VisitExpr(E);
1370  E->GlobalDelete = Record[Idx++];
1371  E->ArrayForm = Record[Idx++];
1372  E->ArrayFormAsWritten = Record[Idx++];
1373  E->UsualArrayDeleteWantsSize = Record[Idx++];
1374  E->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
1375  E->Argument = Reader.ReadSubExpr();
1376  E->Loc = ReadSourceLocation(Record, Idx);
1377}
1378
1379void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1380  VisitExpr(E);
1381
1382  E->Base = Reader.ReadSubExpr();
1383  E->IsArrow = Record[Idx++];
1384  E->OperatorLoc = ReadSourceLocation(Record, Idx);
1385  E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1386  E->ScopeType = GetTypeSourceInfo(Record, Idx);
1387  E->ColonColonLoc = ReadSourceLocation(Record, Idx);
1388  E->TildeLoc = ReadSourceLocation(Record, Idx);
1389
1390  IdentifierInfo *II = Reader.GetIdentifierInfo(F, Record, Idx);
1391  if (II)
1392    E->setDestroyedType(II, ReadSourceLocation(Record, Idx));
1393  else
1394    E->setDestroyedType(GetTypeSourceInfo(Record, Idx));
1395}
1396
1397void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
1398  VisitExpr(E);
1399
1400  unsigned NumObjects = Record[Idx++];
1401  assert(NumObjects == E->getNumObjects());
1402  for (unsigned i = 0; i != NumObjects; ++i)
1403    E->getObjectsBuffer()[i] = ReadDeclAs<BlockDecl>(Record, Idx);
1404
1405  E->SubExpr = Reader.ReadSubExpr();
1406}
1407
1408void
1409ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
1410  VisitExpr(E);
1411
1412  if (Record[Idx++]) // HasTemplateKWAndArgsInfo
1413    ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
1414                              /*NumTemplateArgs=*/Record[Idx++]);
1415
1416  E->Base = Reader.ReadSubExpr();
1417  E->BaseType = Reader.readType(F, Record, Idx);
1418  E->IsArrow = Record[Idx++];
1419  E->OperatorLoc = ReadSourceLocation(Record, Idx);
1420  E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1421  E->FirstQualifierFoundInScope = ReadDeclAs<NamedDecl>(Record, Idx);
1422  ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx);
1423}
1424
1425void
1426ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1427  VisitExpr(E);
1428
1429  if (Record[Idx++]) // HasTemplateKWAndArgsInfo
1430    ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
1431                              /*NumTemplateArgs=*/Record[Idx++]);
1432
1433  E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1434  ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
1435}
1436
1437void
1438ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1439  VisitExpr(E);
1440  assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
1441  ++Idx; // NumArgs;
1442  for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
1443    E->setArg(I, Reader.ReadSubExpr());
1444  E->Type = GetTypeSourceInfo(Record, Idx);
1445  E->setLParenLoc(ReadSourceLocation(Record, Idx));
1446  E->setRParenLoc(ReadSourceLocation(Record, Idx));
1447}
1448
1449void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
1450  VisitExpr(E);
1451
1452  if (Record[Idx++]) // HasTemplateKWAndArgsInfo
1453    ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
1454                              /*NumTemplateArgs=*/Record[Idx++]);
1455
1456  unsigned NumDecls = Record[Idx++];
1457  UnresolvedSet<8> Decls;
1458  for (unsigned i = 0; i != NumDecls; ++i) {
1459    NamedDecl *D = ReadDeclAs<NamedDecl>(Record, Idx);
1460    AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1461    Decls.addDecl(D, AS);
1462  }
1463  E->initializeResults(Reader.getContext(), Decls.begin(), Decls.end());
1464
1465  ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
1466  E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1467}
1468
1469void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1470  VisitOverloadExpr(E);
1471  E->IsArrow = Record[Idx++];
1472  E->HasUnresolvedUsing = Record[Idx++];
1473  E->Base = Reader.ReadSubExpr();
1474  E->BaseType = Reader.readType(F, Record, Idx);
1475  E->OperatorLoc = ReadSourceLocation(Record, Idx);
1476}
1477
1478void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1479  VisitOverloadExpr(E);
1480  E->RequiresADL = Record[Idx++];
1481  E->Overloaded = Record[Idx++];
1482  E->NamingClass = ReadDeclAs<CXXRecordDecl>(Record, Idx);
1483}
1484
1485void ASTStmtReader::VisitTypeTraitExpr(TypeTraitExpr *E) {
1486  VisitExpr(E);
1487  E->TypeTraitExprBits.NumArgs = Record[Idx++];
1488  E->TypeTraitExprBits.Kind = Record[Idx++];
1489  E->TypeTraitExprBits.Value = Record[Idx++];
1490  SourceRange Range = ReadSourceRange(Record, Idx);
1491  E->Loc = Range.getBegin();
1492  E->RParenLoc = Range.getEnd();
1493
1494  TypeSourceInfo **Args = E->getTypeSourceInfos();
1495  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1496    Args[I] = GetTypeSourceInfo(Record, Idx);
1497}
1498
1499void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1500  VisitExpr(E);
1501  E->ATT = (ArrayTypeTrait)Record[Idx++];
1502  E->Value = (unsigned int)Record[Idx++];
1503  SourceRange Range = ReadSourceRange(Record, Idx);
1504  E->Loc = Range.getBegin();
1505  E->RParen = Range.getEnd();
1506  E->QueriedType = GetTypeSourceInfo(Record, Idx);
1507}
1508
1509void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1510  VisitExpr(E);
1511  E->ET = (ExpressionTrait)Record[Idx++];
1512  E->Value = (bool)Record[Idx++];
1513  SourceRange Range = ReadSourceRange(Record, Idx);
1514  E->QueriedExpression = Reader.ReadSubExpr();
1515  E->Loc = Range.getBegin();
1516  E->RParen = Range.getEnd();
1517}
1518
1519void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1520  VisitExpr(E);
1521  E->Value = (bool)Record[Idx++];
1522  E->Range = ReadSourceRange(Record, Idx);
1523  E->Operand = Reader.ReadSubExpr();
1524}
1525
1526void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
1527  VisitExpr(E);
1528  E->EllipsisLoc = ReadSourceLocation(Record, Idx);
1529  E->NumExpansions = Record[Idx++];
1530  E->Pattern = Reader.ReadSubExpr();
1531}
1532
1533void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1534  VisitExpr(E);
1535  E->OperatorLoc = ReadSourceLocation(Record, Idx);
1536  E->PackLoc = ReadSourceLocation(Record, Idx);
1537  E->RParenLoc = ReadSourceLocation(Record, Idx);
1538  E->Length = Record[Idx++];
1539  E->Pack = ReadDeclAs<NamedDecl>(Record, Idx);
1540}
1541
1542void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
1543                                              SubstNonTypeTemplateParmExpr *E) {
1544  VisitExpr(E);
1545  E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
1546  E->NameLoc = ReadSourceLocation(Record, Idx);
1547  E->Replacement = Reader.ReadSubExpr();
1548}
1549
1550void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
1551                                          SubstNonTypeTemplateParmPackExpr *E) {
1552  VisitExpr(E);
1553  E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
1554  TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx);
1555  if (ArgPack.getKind() != TemplateArgument::Pack)
1556    return;
1557
1558  E->Arguments = ArgPack.pack_begin();
1559  E->NumArguments = ArgPack.pack_size();
1560  E->NameLoc = ReadSourceLocation(Record, Idx);
1561}
1562
1563void ASTStmtReader::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1564  VisitExpr(E);
1565  E->NumParameters = Record[Idx++];
1566  E->ParamPack = ReadDeclAs<ParmVarDecl>(Record, Idx);
1567  E->NameLoc = ReadSourceLocation(Record, Idx);
1568  ParmVarDecl **Parms = reinterpret_cast<ParmVarDecl**>(E+1);
1569  for (unsigned i = 0, n = E->NumParameters; i != n; ++i)
1570    Parms[i] = ReadDeclAs<ParmVarDecl>(Record, Idx);
1571}
1572
1573void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1574  VisitExpr(E);
1575  E->State = Reader.ReadSubExpr();
1576  auto VD = ReadDeclAs<ValueDecl>(Record, Idx);
1577  unsigned ManglingNumber = Record[Idx++];
1578  E->setExtendingDecl(VD, ManglingNumber);
1579}
1580
1581void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1582  VisitExpr(E);
1583  E->SourceExpr = Reader.ReadSubExpr();
1584  E->Loc = ReadSourceLocation(Record, Idx);
1585}
1586
1587//===----------------------------------------------------------------------===//
1588// Microsoft Expressions and Statements
1589//===----------------------------------------------------------------------===//
1590void ASTStmtReader::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1591  VisitExpr(E);
1592  E->IsArrow = (Record[Idx++] != 0);
1593  E->BaseExpr = Reader.ReadSubExpr();
1594  E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1595  E->MemberLoc = ReadSourceLocation(Record, Idx);
1596  E->TheDecl = ReadDeclAs<MSPropertyDecl>(Record, Idx);
1597}
1598
1599void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1600  VisitExpr(E);
1601  E->setSourceRange(ReadSourceRange(Record, Idx));
1602  if (E->isTypeOperand()) { // __uuidof(ComType)
1603    E->setTypeOperandSourceInfo(
1604        GetTypeSourceInfo(Record, Idx));
1605    return;
1606  }
1607
1608  // __uuidof(expr)
1609  E->setExprOperand(Reader.ReadSubExpr());
1610}
1611
1612void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1613  VisitStmt(S);
1614  S->setLeaveLoc(ReadSourceLocation(Record, Idx));
1615}
1616
1617void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
1618  VisitStmt(S);
1619  S->Loc = ReadSourceLocation(Record, Idx);
1620  S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt();
1621  S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt();
1622}
1623
1624void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1625  VisitStmt(S);
1626  S->Loc = ReadSourceLocation(Record, Idx);
1627  S->Block = Reader.ReadSubStmt();
1628}
1629
1630void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
1631  VisitStmt(S);
1632  S->IsCXXTry = Record[Idx++];
1633  S->TryLoc = ReadSourceLocation(Record, Idx);
1634  S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt();
1635  S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
1636}
1637
1638//===----------------------------------------------------------------------===//
1639// CUDA Expressions and Statements
1640//===----------------------------------------------------------------------===//
1641
1642void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1643  VisitCallExpr(E);
1644  E->setConfig(cast<CallExpr>(Reader.ReadSubExpr()));
1645}
1646
1647//===----------------------------------------------------------------------===//
1648// OpenCL Expressions and Statements.
1649//===----------------------------------------------------------------------===//
1650void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
1651  VisitExpr(E);
1652  E->BuiltinLoc = ReadSourceLocation(Record, Idx);
1653  E->RParenLoc = ReadSourceLocation(Record, Idx);
1654  E->SrcExpr = Reader.ReadSubExpr();
1655}
1656
1657//===----------------------------------------------------------------------===//
1658// OpenMP Clauses.
1659//===----------------------------------------------------------------------===//
1660
1661namespace clang {
1662class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> {
1663  ASTStmtReader *Reader;
1664  ASTContext &Context;
1665  const ASTReader::RecordData &Record;
1666  unsigned &Idx;
1667public:
1668  OMPClauseReader(ASTStmtReader *R, ASTContext &C,
1669                  const ASTReader::RecordData &Record, unsigned &Idx)
1670    : Reader(R), Context(C), Record(Record), Idx(Idx) { }
1671#define OPENMP_CLAUSE(Name, Class)    \
1672  void Visit##Class(Class *S);
1673#include "clang/Basic/OpenMPKinds.def"
1674  OMPClause *readClause();
1675};
1676}
1677
1678OMPClause *OMPClauseReader::readClause() {
1679  OMPClause *C;
1680  switch (Record[Idx++]) {
1681  case OMPC_if:
1682    C = new (Context) OMPIfClause();
1683    break;
1684  case OMPC_num_threads:
1685    C = new (Context) OMPNumThreadsClause();
1686    break;
1687  case OMPC_safelen:
1688    C = new (Context) OMPSafelenClause();
1689    break;
1690  case OMPC_collapse:
1691    C = new (Context) OMPCollapseClause();
1692    break;
1693  case OMPC_default:
1694    C = new (Context) OMPDefaultClause();
1695    break;
1696  case OMPC_proc_bind:
1697    C = new (Context) OMPProcBindClause();
1698    break;
1699  case OMPC_schedule:
1700    C = new (Context) OMPScheduleClause();
1701    break;
1702  case OMPC_ordered:
1703    C = new (Context) OMPOrderedClause();
1704    break;
1705  case OMPC_nowait:
1706    C = new (Context) OMPNowaitClause();
1707    break;
1708  case OMPC_private:
1709    C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
1710    break;
1711  case OMPC_firstprivate:
1712    C = OMPFirstprivateClause::CreateEmpty(Context, Record[Idx++]);
1713    break;
1714  case OMPC_lastprivate:
1715    C = OMPLastprivateClause::CreateEmpty(Context, Record[Idx++]);
1716    break;
1717  case OMPC_shared:
1718    C = OMPSharedClause::CreateEmpty(Context, Record[Idx++]);
1719    break;
1720  case OMPC_reduction:
1721    C = OMPReductionClause::CreateEmpty(Context, Record[Idx++]);
1722    break;
1723  case OMPC_linear:
1724    C = OMPLinearClause::CreateEmpty(Context, Record[Idx++]);
1725    break;
1726  case OMPC_aligned:
1727    C = OMPAlignedClause::CreateEmpty(Context, Record[Idx++]);
1728    break;
1729  case OMPC_copyin:
1730    C = OMPCopyinClause::CreateEmpty(Context, Record[Idx++]);
1731    break;
1732  case OMPC_copyprivate:
1733    C = OMPCopyprivateClause::CreateEmpty(Context, Record[Idx++]);
1734    break;
1735  }
1736  Visit(C);
1737  C->setLocStart(Reader->ReadSourceLocation(Record, Idx));
1738  C->setLocEnd(Reader->ReadSourceLocation(Record, Idx));
1739
1740  return C;
1741}
1742
1743void OMPClauseReader::VisitOMPIfClause(OMPIfClause *C) {
1744  C->setCondition(Reader->Reader.ReadSubExpr());
1745  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1746}
1747
1748void OMPClauseReader::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
1749  C->setNumThreads(Reader->Reader.ReadSubExpr());
1750  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1751}
1752
1753void OMPClauseReader::VisitOMPSafelenClause(OMPSafelenClause *C) {
1754  C->setSafelen(Reader->Reader.ReadSubExpr());
1755  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1756}
1757
1758void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) {
1759  C->setNumForLoops(Reader->Reader.ReadSubExpr());
1760  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1761}
1762
1763void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) {
1764  C->setDefaultKind(
1765       static_cast<OpenMPDefaultClauseKind>(Record[Idx++]));
1766  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1767  C->setDefaultKindKwLoc(Reader->ReadSourceLocation(Record, Idx));
1768}
1769
1770void OMPClauseReader::VisitOMPProcBindClause(OMPProcBindClause *C) {
1771  C->setProcBindKind(
1772       static_cast<OpenMPProcBindClauseKind>(Record[Idx++]));
1773  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1774  C->setProcBindKindKwLoc(Reader->ReadSourceLocation(Record, Idx));
1775}
1776
1777void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) {
1778  C->setScheduleKind(
1779       static_cast<OpenMPScheduleClauseKind>(Record[Idx++]));
1780  C->setChunkSize(Reader->Reader.ReadSubExpr());
1781  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1782  C->setScheduleKindLoc(Reader->ReadSourceLocation(Record, Idx));
1783  C->setCommaLoc(Reader->ReadSourceLocation(Record, Idx));
1784}
1785
1786void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *) {}
1787
1788void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {}
1789
1790void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
1791  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1792  unsigned NumVars = C->varlist_size();
1793  SmallVector<Expr *, 16> Vars;
1794  Vars.reserve(NumVars);
1795  for (unsigned i = 0; i != NumVars; ++i)
1796    Vars.push_back(Reader->Reader.ReadSubExpr());
1797  C->setVarRefs(Vars);
1798}
1799
1800void OMPClauseReader::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
1801  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1802  unsigned NumVars = C->varlist_size();
1803  SmallVector<Expr *, 16> Vars;
1804  Vars.reserve(NumVars);
1805  for (unsigned i = 0; i != NumVars; ++i)
1806    Vars.push_back(Reader->Reader.ReadSubExpr());
1807  C->setVarRefs(Vars);
1808}
1809
1810void OMPClauseReader::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
1811  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1812  unsigned NumVars = C->varlist_size();
1813  SmallVector<Expr *, 16> Vars;
1814  Vars.reserve(NumVars);
1815  for (unsigned i = 0; i != NumVars; ++i)
1816    Vars.push_back(Reader->Reader.ReadSubExpr());
1817  C->setVarRefs(Vars);
1818}
1819
1820void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) {
1821  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1822  unsigned NumVars = C->varlist_size();
1823  SmallVector<Expr *, 16> Vars;
1824  Vars.reserve(NumVars);
1825  for (unsigned i = 0; i != NumVars; ++i)
1826    Vars.push_back(Reader->Reader.ReadSubExpr());
1827  C->setVarRefs(Vars);
1828}
1829
1830void OMPClauseReader::VisitOMPReductionClause(OMPReductionClause *C) {
1831  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1832  C->setColonLoc(Reader->ReadSourceLocation(Record, Idx));
1833  NestedNameSpecifierLoc NNSL =
1834    Reader->Reader.ReadNestedNameSpecifierLoc(Reader->F, Record, Idx);
1835  DeclarationNameInfo DNI;
1836  Reader->ReadDeclarationNameInfo(DNI, Record, Idx);
1837  C->setQualifierLoc(NNSL);
1838  C->setNameInfo(DNI);
1839
1840  unsigned NumVars = C->varlist_size();
1841  SmallVector<Expr *, 16> Vars;
1842  Vars.reserve(NumVars);
1843  for (unsigned i = 0; i != NumVars; ++i)
1844    Vars.push_back(Reader->Reader.ReadSubExpr());
1845  C->setVarRefs(Vars);
1846}
1847
1848void OMPClauseReader::VisitOMPLinearClause(OMPLinearClause *C) {
1849  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1850  C->setColonLoc(Reader->ReadSourceLocation(Record, Idx));
1851  unsigned NumVars = C->varlist_size();
1852  SmallVector<Expr *, 16> Vars;
1853  Vars.reserve(NumVars);
1854  for (unsigned i = 0; i != NumVars; ++i)
1855    Vars.push_back(Reader->Reader.ReadSubExpr());
1856  C->setVarRefs(Vars);
1857  C->setStep(Reader->Reader.ReadSubExpr());
1858}
1859
1860void OMPClauseReader::VisitOMPAlignedClause(OMPAlignedClause *C) {
1861  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1862  C->setColonLoc(Reader->ReadSourceLocation(Record, Idx));
1863  unsigned NumVars = C->varlist_size();
1864  SmallVector<Expr *, 16> Vars;
1865  Vars.reserve(NumVars);
1866  for (unsigned i = 0; i != NumVars; ++i)
1867    Vars.push_back(Reader->Reader.ReadSubExpr());
1868  C->setVarRefs(Vars);
1869  C->setAlignment(Reader->Reader.ReadSubExpr());
1870}
1871
1872void OMPClauseReader::VisitOMPCopyinClause(OMPCopyinClause *C) {
1873  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1874  unsigned NumVars = C->varlist_size();
1875  SmallVector<Expr *, 16> Vars;
1876  Vars.reserve(NumVars);
1877  for (unsigned i = 0; i != NumVars; ++i)
1878    Vars.push_back(Reader->Reader.ReadSubExpr());
1879  C->setVarRefs(Vars);
1880}
1881
1882void OMPClauseReader::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
1883  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
1884  unsigned NumVars = C->varlist_size();
1885  SmallVector<Expr *, 16> Vars;
1886  Vars.reserve(NumVars);
1887  for (unsigned i = 0; i != NumVars; ++i)
1888    Vars.push_back(Reader->Reader.ReadSubExpr());
1889  C->setVarRefs(Vars);
1890}
1891
1892//===----------------------------------------------------------------------===//
1893// OpenMP Directives.
1894//===----------------------------------------------------------------------===//
1895void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
1896  E->setLocStart(ReadSourceLocation(Record, Idx));
1897  E->setLocEnd(ReadSourceLocation(Record, Idx));
1898  OMPClauseReader ClauseReader(this, Reader.getContext(), Record, Idx);
1899  SmallVector<OMPClause *, 5> Clauses;
1900  for (unsigned i = 0; i < E->getNumClauses(); ++i)
1901    Clauses.push_back(ClauseReader.readClause());
1902  E->setClauses(Clauses);
1903  E->setAssociatedStmt(Reader.ReadSubStmt());
1904}
1905
1906void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) {
1907  VisitStmt(D);
1908  // The NumClauses field was read in ReadStmtFromStream.
1909  ++Idx;
1910  VisitOMPExecutableDirective(D);
1911}
1912
1913void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) {
1914  VisitStmt(D);
1915  // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream.
1916  Idx += 2;
1917  VisitOMPExecutableDirective(D);
1918}
1919
1920void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) {
1921  VisitStmt(D);
1922  // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream.
1923  Idx += 2;
1924  VisitOMPExecutableDirective(D);
1925}
1926
1927void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
1928  VisitStmt(D);
1929  // The NumClauses field was read in ReadStmtFromStream.
1930  ++Idx;
1931  VisitOMPExecutableDirective(D);
1932}
1933
1934void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) {
1935  VisitStmt(D);
1936  VisitOMPExecutableDirective(D);
1937}
1938
1939void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) {
1940  VisitStmt(D);
1941  // The NumClauses field was read in ReadStmtFromStream.
1942  ++Idx;
1943  VisitOMPExecutableDirective(D);
1944}
1945
1946void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
1947  VisitStmt(D);
1948  // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream.
1949  Idx += 2;
1950  VisitOMPExecutableDirective(D);
1951}
1952
1953void ASTStmtReader::VisitOMPParallelSectionsDirective(
1954    OMPParallelSectionsDirective *D) {
1955  VisitStmt(D);
1956  // The NumClauses field was read in ReadStmtFromStream.
1957  ++Idx;
1958  VisitOMPExecutableDirective(D);
1959}
1960
1961//===----------------------------------------------------------------------===//
1962// ASTReader Implementation
1963//===----------------------------------------------------------------------===//
1964
1965Stmt *ASTReader::ReadStmt(ModuleFile &F) {
1966  switch (ReadingKind) {
1967  case Read_None:
1968    llvm_unreachable("should not call this when not reading anything");
1969  case Read_Decl:
1970  case Read_Type:
1971    return ReadStmtFromStream(F);
1972  case Read_Stmt:
1973    return ReadSubStmt();
1974  }
1975
1976  llvm_unreachable("ReadingKind not set ?");
1977}
1978
1979Expr *ASTReader::ReadExpr(ModuleFile &F) {
1980  return cast_or_null<Expr>(ReadStmt(F));
1981}
1982
1983Expr *ASTReader::ReadSubExpr() {
1984  return cast_or_null<Expr>(ReadSubStmt());
1985}
1986
1987// Within the bitstream, expressions are stored in Reverse Polish
1988// Notation, with each of the subexpressions preceding the
1989// expression they are stored in. Subexpressions are stored from last to first.
1990// To evaluate expressions, we continue reading expressions and placing them on
1991// the stack, with expressions having operands removing those operands from the
1992// stack. Evaluation terminates when we see a STMT_STOP record, and
1993// the single remaining expression on the stack is our result.
1994Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
1995
1996  ReadingKindTracker ReadingKind(Read_Stmt, *this);
1997  llvm::BitstreamCursor &Cursor = F.DeclsCursor;
1998
1999  // Map of offset to previously deserialized stmt. The offset points
2000  /// just after the stmt record.
2001  llvm::DenseMap<uint64_t, Stmt *> StmtEntries;
2002
2003#ifndef NDEBUG
2004  unsigned PrevNumStmts = StmtStack.size();
2005#endif
2006
2007  RecordData Record;
2008  unsigned Idx;
2009  ASTStmtReader Reader(*this, F, Cursor, Record, Idx);
2010  Stmt::EmptyShell Empty;
2011
2012  while (true) {
2013    llvm::BitstreamEntry Entry = Cursor.advanceSkippingSubblocks();
2014
2015    switch (Entry.Kind) {
2016    case llvm::BitstreamEntry::SubBlock: // Handled for us already.
2017    case llvm::BitstreamEntry::Error:
2018      Error("malformed block record in AST file");
2019      return nullptr;
2020    case llvm::BitstreamEntry::EndBlock:
2021      goto Done;
2022    case llvm::BitstreamEntry::Record:
2023      // The interesting case.
2024      break;
2025    }
2026
2027    Stmt *S = nullptr;
2028    Idx = 0;
2029    Record.clear();
2030    bool Finished = false;
2031    bool IsStmtReference = false;
2032    switch ((StmtCode)Cursor.readRecord(Entry.ID, Record)) {
2033    case STMT_STOP:
2034      Finished = true;
2035      break;
2036
2037    case STMT_REF_PTR:
2038      IsStmtReference = true;
2039      assert(StmtEntries.find(Record[0]) != StmtEntries.end() &&
2040             "No stmt was recorded for this offset reference!");
2041      S = StmtEntries[Record[Idx++]];
2042      break;
2043
2044    case STMT_NULL_PTR:
2045      S = nullptr;
2046      break;
2047
2048    case STMT_NULL:
2049      S = new (Context) NullStmt(Empty);
2050      break;
2051
2052    case STMT_COMPOUND:
2053      S = new (Context) CompoundStmt(Empty);
2054      break;
2055
2056    case STMT_CASE:
2057      S = new (Context) CaseStmt(Empty);
2058      break;
2059
2060    case STMT_DEFAULT:
2061      S = new (Context) DefaultStmt(Empty);
2062      break;
2063
2064    case STMT_LABEL:
2065      S = new (Context) LabelStmt(Empty);
2066      break;
2067
2068    case STMT_ATTRIBUTED:
2069      S = AttributedStmt::CreateEmpty(
2070        Context,
2071        /*NumAttrs*/Record[ASTStmtReader::NumStmtFields]);
2072      break;
2073
2074    case STMT_IF:
2075      S = new (Context) IfStmt(Empty);
2076      break;
2077
2078    case STMT_SWITCH:
2079      S = new (Context) SwitchStmt(Empty);
2080      break;
2081
2082    case STMT_WHILE:
2083      S = new (Context) WhileStmt(Empty);
2084      break;
2085
2086    case STMT_DO:
2087      S = new (Context) DoStmt(Empty);
2088      break;
2089
2090    case STMT_FOR:
2091      S = new (Context) ForStmt(Empty);
2092      break;
2093
2094    case STMT_GOTO:
2095      S = new (Context) GotoStmt(Empty);
2096      break;
2097
2098    case STMT_INDIRECT_GOTO:
2099      S = new (Context) IndirectGotoStmt(Empty);
2100      break;
2101
2102    case STMT_CONTINUE:
2103      S = new (Context) ContinueStmt(Empty);
2104      break;
2105
2106    case STMT_BREAK:
2107      S = new (Context) BreakStmt(Empty);
2108      break;
2109
2110    case STMT_RETURN:
2111      S = new (Context) ReturnStmt(Empty);
2112      break;
2113
2114    case STMT_DECL:
2115      S = new (Context) DeclStmt(Empty);
2116      break;
2117
2118    case STMT_GCCASM:
2119      S = new (Context) GCCAsmStmt(Empty);
2120      break;
2121
2122    case STMT_MSASM:
2123      S = new (Context) MSAsmStmt(Empty);
2124      break;
2125
2126    case STMT_CAPTURED:
2127      S = CapturedStmt::CreateDeserialized(Context,
2128                                           Record[ASTStmtReader::NumStmtFields]);
2129      break;
2130
2131    case EXPR_PREDEFINED:
2132      S = new (Context) PredefinedExpr(Empty);
2133      break;
2134
2135    case EXPR_DECL_REF:
2136      S = DeclRefExpr::CreateEmpty(
2137        Context,
2138        /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
2139        /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
2140        /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 2],
2141        /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
2142          Record[ASTStmtReader::NumExprFields + 5] : 0);
2143      break;
2144
2145    case EXPR_INTEGER_LITERAL:
2146      S = IntegerLiteral::Create(Context, Empty);
2147      break;
2148
2149    case EXPR_FLOATING_LITERAL:
2150      S = FloatingLiteral::Create(Context, Empty);
2151      break;
2152
2153    case EXPR_IMAGINARY_LITERAL:
2154      S = new (Context) ImaginaryLiteral(Empty);
2155      break;
2156
2157    case EXPR_STRING_LITERAL:
2158      S = StringLiteral::CreateEmpty(Context,
2159                                     Record[ASTStmtReader::NumExprFields + 1]);
2160      break;
2161
2162    case EXPR_CHARACTER_LITERAL:
2163      S = new (Context) CharacterLiteral(Empty);
2164      break;
2165
2166    case EXPR_PAREN:
2167      S = new (Context) ParenExpr(Empty);
2168      break;
2169
2170    case EXPR_PAREN_LIST:
2171      S = new (Context) ParenListExpr(Empty);
2172      break;
2173
2174    case EXPR_UNARY_OPERATOR:
2175      S = new (Context) UnaryOperator(Empty);
2176      break;
2177
2178    case EXPR_OFFSETOF:
2179      S = OffsetOfExpr::CreateEmpty(Context,
2180                                    Record[ASTStmtReader::NumExprFields],
2181                                    Record[ASTStmtReader::NumExprFields + 1]);
2182      break;
2183
2184    case EXPR_SIZEOF_ALIGN_OF:
2185      S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
2186      break;
2187
2188    case EXPR_ARRAY_SUBSCRIPT:
2189      S = new (Context) ArraySubscriptExpr(Empty);
2190      break;
2191
2192    case EXPR_CALL:
2193      S = new (Context) CallExpr(Context, Stmt::CallExprClass, Empty);
2194      break;
2195
2196    case EXPR_MEMBER: {
2197      // We load everything here and fully initialize it at creation.
2198      // That way we can use MemberExpr::Create and don't have to duplicate its
2199      // logic with a MemberExpr::CreateEmpty.
2200
2201      assert(Idx == 0);
2202      NestedNameSpecifierLoc QualifierLoc;
2203      if (Record[Idx++]) { // HasQualifier.
2204        QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
2205      }
2206
2207      SourceLocation TemplateKWLoc;
2208      TemplateArgumentListInfo ArgInfo;
2209      bool HasTemplateKWAndArgsInfo = Record[Idx++];
2210      if (HasTemplateKWAndArgsInfo) {
2211        TemplateKWLoc = ReadSourceLocation(F, Record, Idx);
2212        unsigned NumTemplateArgs = Record[Idx++];
2213        ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx));
2214        ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx));
2215        for (unsigned i = 0; i != NumTemplateArgs; ++i)
2216          ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx));
2217      }
2218
2219      bool HadMultipleCandidates = Record[Idx++];
2220
2221      NamedDecl *FoundD = ReadDeclAs<NamedDecl>(F, Record, Idx);
2222      AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
2223      DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS);
2224
2225      QualType T = readType(F, Record, Idx);
2226      ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]);
2227      ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]);
2228      Expr *Base = ReadSubExpr();
2229      ValueDecl *MemberD = ReadDeclAs<ValueDecl>(F, Record, Idx);
2230      SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx);
2231      DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc);
2232      bool IsArrow = Record[Idx++];
2233
2234      S = MemberExpr::Create(Context, Base, IsArrow, QualifierLoc,
2235                             TemplateKWLoc, MemberD, FoundDecl, MemberNameInfo,
2236                             HasTemplateKWAndArgsInfo ? &ArgInfo : nullptr,
2237                             T, VK, OK);
2238      ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc,
2239                             MemberD->getDeclName(), Record, Idx);
2240      if (HadMultipleCandidates)
2241        cast<MemberExpr>(S)->setHadMultipleCandidates(true);
2242      break;
2243    }
2244
2245    case EXPR_BINARY_OPERATOR:
2246      S = new (Context) BinaryOperator(Empty);
2247      break;
2248
2249    case EXPR_COMPOUND_ASSIGN_OPERATOR:
2250      S = new (Context) CompoundAssignOperator(Empty);
2251      break;
2252
2253    case EXPR_CONDITIONAL_OPERATOR:
2254      S = new (Context) ConditionalOperator(Empty);
2255      break;
2256
2257    case EXPR_BINARY_CONDITIONAL_OPERATOR:
2258      S = new (Context) BinaryConditionalOperator(Empty);
2259      break;
2260
2261    case EXPR_IMPLICIT_CAST:
2262      S = ImplicitCastExpr::CreateEmpty(Context,
2263                       /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2264      break;
2265
2266    case EXPR_CSTYLE_CAST:
2267      S = CStyleCastExpr::CreateEmpty(Context,
2268                       /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2269      break;
2270
2271    case EXPR_COMPOUND_LITERAL:
2272      S = new (Context) CompoundLiteralExpr(Empty);
2273      break;
2274
2275    case EXPR_EXT_VECTOR_ELEMENT:
2276      S = new (Context) ExtVectorElementExpr(Empty);
2277      break;
2278
2279    case EXPR_INIT_LIST:
2280      S = new (Context) InitListExpr(Empty);
2281      break;
2282
2283    case EXPR_DESIGNATED_INIT:
2284      S = DesignatedInitExpr::CreateEmpty(Context,
2285                                     Record[ASTStmtReader::NumExprFields] - 1);
2286
2287      break;
2288
2289    case EXPR_IMPLICIT_VALUE_INIT:
2290      S = new (Context) ImplicitValueInitExpr(Empty);
2291      break;
2292
2293    case EXPR_VA_ARG:
2294      S = new (Context) VAArgExpr(Empty);
2295      break;
2296
2297    case EXPR_ADDR_LABEL:
2298      S = new (Context) AddrLabelExpr(Empty);
2299      break;
2300
2301    case EXPR_STMT:
2302      S = new (Context) StmtExpr(Empty);
2303      break;
2304
2305    case EXPR_CHOOSE:
2306      S = new (Context) ChooseExpr(Empty);
2307      break;
2308
2309    case EXPR_GNU_NULL:
2310      S = new (Context) GNUNullExpr(Empty);
2311      break;
2312
2313    case EXPR_SHUFFLE_VECTOR:
2314      S = new (Context) ShuffleVectorExpr(Empty);
2315      break;
2316
2317    case EXPR_CONVERT_VECTOR:
2318      S = new (Context) ConvertVectorExpr(Empty);
2319      break;
2320
2321    case EXPR_BLOCK:
2322      S = new (Context) BlockExpr(Empty);
2323      break;
2324
2325    case EXPR_GENERIC_SELECTION:
2326      S = new (Context) GenericSelectionExpr(Empty);
2327      break;
2328
2329    case EXPR_OBJC_STRING_LITERAL:
2330      S = new (Context) ObjCStringLiteral(Empty);
2331      break;
2332    case EXPR_OBJC_BOXED_EXPRESSION:
2333      S = new (Context) ObjCBoxedExpr(Empty);
2334      break;
2335    case EXPR_OBJC_ARRAY_LITERAL:
2336      S = ObjCArrayLiteral::CreateEmpty(Context,
2337                                        Record[ASTStmtReader::NumExprFields]);
2338      break;
2339    case EXPR_OBJC_DICTIONARY_LITERAL:
2340      S = ObjCDictionaryLiteral::CreateEmpty(Context,
2341            Record[ASTStmtReader::NumExprFields],
2342            Record[ASTStmtReader::NumExprFields + 1]);
2343      break;
2344    case EXPR_OBJC_ENCODE:
2345      S = new (Context) ObjCEncodeExpr(Empty);
2346      break;
2347    case EXPR_OBJC_SELECTOR_EXPR:
2348      S = new (Context) ObjCSelectorExpr(Empty);
2349      break;
2350    case EXPR_OBJC_PROTOCOL_EXPR:
2351      S = new (Context) ObjCProtocolExpr(Empty);
2352      break;
2353    case EXPR_OBJC_IVAR_REF_EXPR:
2354      S = new (Context) ObjCIvarRefExpr(Empty);
2355      break;
2356    case EXPR_OBJC_PROPERTY_REF_EXPR:
2357      S = new (Context) ObjCPropertyRefExpr(Empty);
2358      break;
2359    case EXPR_OBJC_SUBSCRIPT_REF_EXPR:
2360      S = new (Context) ObjCSubscriptRefExpr(Empty);
2361      break;
2362    case EXPR_OBJC_KVC_REF_EXPR:
2363      llvm_unreachable("mismatching AST file");
2364    case EXPR_OBJC_MESSAGE_EXPR:
2365      S = ObjCMessageExpr::CreateEmpty(Context,
2366                                     Record[ASTStmtReader::NumExprFields],
2367                                     Record[ASTStmtReader::NumExprFields + 1]);
2368      break;
2369    case EXPR_OBJC_ISA:
2370      S = new (Context) ObjCIsaExpr(Empty);
2371      break;
2372    case EXPR_OBJC_INDIRECT_COPY_RESTORE:
2373      S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
2374      break;
2375    case EXPR_OBJC_BRIDGED_CAST:
2376      S = new (Context) ObjCBridgedCastExpr(Empty);
2377      break;
2378    case STMT_OBJC_FOR_COLLECTION:
2379      S = new (Context) ObjCForCollectionStmt(Empty);
2380      break;
2381    case STMT_OBJC_CATCH:
2382      S = new (Context) ObjCAtCatchStmt(Empty);
2383      break;
2384    case STMT_OBJC_FINALLY:
2385      S = new (Context) ObjCAtFinallyStmt(Empty);
2386      break;
2387    case STMT_OBJC_AT_TRY:
2388      S = ObjCAtTryStmt::CreateEmpty(Context,
2389                                     Record[ASTStmtReader::NumStmtFields],
2390                                     Record[ASTStmtReader::NumStmtFields + 1]);
2391      break;
2392    case STMT_OBJC_AT_SYNCHRONIZED:
2393      S = new (Context) ObjCAtSynchronizedStmt(Empty);
2394      break;
2395    case STMT_OBJC_AT_THROW:
2396      S = new (Context) ObjCAtThrowStmt(Empty);
2397      break;
2398    case STMT_OBJC_AUTORELEASE_POOL:
2399      S = new (Context) ObjCAutoreleasePoolStmt(Empty);
2400      break;
2401    case EXPR_OBJC_BOOL_LITERAL:
2402      S = new (Context) ObjCBoolLiteralExpr(Empty);
2403      break;
2404    case STMT_SEH_LEAVE:
2405      S = new (Context) SEHLeaveStmt(Empty);
2406      break;
2407    case STMT_SEH_EXCEPT:
2408      S = new (Context) SEHExceptStmt(Empty);
2409      break;
2410    case STMT_SEH_FINALLY:
2411      S = new (Context) SEHFinallyStmt(Empty);
2412      break;
2413    case STMT_SEH_TRY:
2414      S = new (Context) SEHTryStmt(Empty);
2415      break;
2416    case STMT_CXX_CATCH:
2417      S = new (Context) CXXCatchStmt(Empty);
2418      break;
2419
2420    case STMT_CXX_TRY:
2421      S = CXXTryStmt::Create(Context, Empty,
2422             /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]);
2423      break;
2424
2425    case STMT_CXX_FOR_RANGE:
2426      S = new (Context) CXXForRangeStmt(Empty);
2427      break;
2428
2429    case STMT_MS_DEPENDENT_EXISTS:
2430      S = new (Context) MSDependentExistsStmt(SourceLocation(), true,
2431                                              NestedNameSpecifierLoc(),
2432                                              DeclarationNameInfo(),
2433                                              nullptr);
2434      break;
2435
2436    case STMT_OMP_PARALLEL_DIRECTIVE:
2437      S =
2438        OMPParallelDirective::CreateEmpty(Context,
2439                                          Record[ASTStmtReader::NumStmtFields],
2440                                          Empty);
2441      break;
2442
2443    case STMT_OMP_SIMD_DIRECTIVE: {
2444      unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
2445      unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
2446      S = OMPSimdDirective::CreateEmpty(Context, NumClauses,
2447                                        CollapsedNum, Empty);
2448      break;
2449    }
2450
2451    case STMT_OMP_FOR_DIRECTIVE: {
2452      unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
2453      unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
2454      S = OMPForDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
2455                                       Empty);
2456      break;
2457    }
2458
2459    case STMT_OMP_SECTIONS_DIRECTIVE:
2460      S = OMPSectionsDirective::CreateEmpty(
2461          Context, Record[ASTStmtReader::NumStmtFields], Empty);
2462      break;
2463
2464    case STMT_OMP_SECTION_DIRECTIVE:
2465      S = OMPSectionDirective::CreateEmpty(Context, Empty);
2466      break;
2467
2468    case STMT_OMP_SINGLE_DIRECTIVE:
2469      S = OMPSingleDirective::CreateEmpty(
2470          Context, Record[ASTStmtReader::NumStmtFields], Empty);
2471      break;
2472
2473    case STMT_OMP_PARALLEL_FOR_DIRECTIVE: {
2474      unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
2475      unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
2476      S = OMPParallelForDirective::CreateEmpty(Context, NumClauses,
2477                                               CollapsedNum, Empty);
2478      break;
2479    }
2480
2481    case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
2482      S = OMPParallelSectionsDirective::CreateEmpty(
2483          Context, Record[ASTStmtReader::NumStmtFields], Empty);
2484      break;
2485
2486    case EXPR_CXX_OPERATOR_CALL:
2487      S = new (Context) CXXOperatorCallExpr(Context, Empty);
2488      break;
2489
2490    case EXPR_CXX_MEMBER_CALL:
2491      S = new (Context) CXXMemberCallExpr(Context, Empty);
2492      break;
2493
2494    case EXPR_CXX_CONSTRUCT:
2495      S = new (Context) CXXConstructExpr(Empty);
2496      break;
2497
2498    case EXPR_CXX_TEMPORARY_OBJECT:
2499      S = new (Context) CXXTemporaryObjectExpr(Empty);
2500      break;
2501
2502    case EXPR_CXX_STATIC_CAST:
2503      S = CXXStaticCastExpr::CreateEmpty(Context,
2504                       /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2505      break;
2506
2507    case EXPR_CXX_DYNAMIC_CAST:
2508      S = CXXDynamicCastExpr::CreateEmpty(Context,
2509                       /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2510      break;
2511
2512    case EXPR_CXX_REINTERPRET_CAST:
2513      S = CXXReinterpretCastExpr::CreateEmpty(Context,
2514                       /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2515      break;
2516
2517    case EXPR_CXX_CONST_CAST:
2518      S = CXXConstCastExpr::CreateEmpty(Context);
2519      break;
2520
2521    case EXPR_CXX_FUNCTIONAL_CAST:
2522      S = CXXFunctionalCastExpr::CreateEmpty(Context,
2523                       /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
2524      break;
2525
2526    case EXPR_USER_DEFINED_LITERAL:
2527      S = new (Context) UserDefinedLiteral(Context, Empty);
2528      break;
2529
2530    case EXPR_CXX_STD_INITIALIZER_LIST:
2531      S = new (Context) CXXStdInitializerListExpr(Empty);
2532      break;
2533
2534    case EXPR_CXX_BOOL_LITERAL:
2535      S = new (Context) CXXBoolLiteralExpr(Empty);
2536      break;
2537
2538    case EXPR_CXX_NULL_PTR_LITERAL:
2539      S = new (Context) CXXNullPtrLiteralExpr(Empty);
2540      break;
2541    case EXPR_CXX_TYPEID_EXPR:
2542      S = new (Context) CXXTypeidExpr(Empty, true);
2543      break;
2544    case EXPR_CXX_TYPEID_TYPE:
2545      S = new (Context) CXXTypeidExpr(Empty, false);
2546      break;
2547    case EXPR_CXX_UUIDOF_EXPR:
2548      S = new (Context) CXXUuidofExpr(Empty, true);
2549      break;
2550    case EXPR_CXX_PROPERTY_REF_EXPR:
2551      S = new (Context) MSPropertyRefExpr(Empty);
2552      break;
2553    case EXPR_CXX_UUIDOF_TYPE:
2554      S = new (Context) CXXUuidofExpr(Empty, false);
2555      break;
2556    case EXPR_CXX_THIS:
2557      S = new (Context) CXXThisExpr(Empty);
2558      break;
2559    case EXPR_CXX_THROW:
2560      S = new (Context) CXXThrowExpr(Empty);
2561      break;
2562    case EXPR_CXX_DEFAULT_ARG: {
2563      bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields];
2564      if (HasOtherExprStored) {
2565        Expr *SubExpr = ReadSubExpr();
2566        S = CXXDefaultArgExpr::Create(Context, SourceLocation(), nullptr,
2567                                      SubExpr);
2568      } else
2569        S = new (Context) CXXDefaultArgExpr(Empty);
2570      break;
2571    }
2572    case EXPR_CXX_DEFAULT_INIT:
2573      S = new (Context) CXXDefaultInitExpr(Empty);
2574      break;
2575    case EXPR_CXX_BIND_TEMPORARY:
2576      S = new (Context) CXXBindTemporaryExpr(Empty);
2577      break;
2578
2579    case EXPR_CXX_SCALAR_VALUE_INIT:
2580      S = new (Context) CXXScalarValueInitExpr(Empty);
2581      break;
2582    case EXPR_CXX_NEW:
2583      S = new (Context) CXXNewExpr(Empty);
2584      break;
2585    case EXPR_CXX_DELETE:
2586      S = new (Context) CXXDeleteExpr(Empty);
2587      break;
2588    case EXPR_CXX_PSEUDO_DESTRUCTOR:
2589      S = new (Context) CXXPseudoDestructorExpr(Empty);
2590      break;
2591
2592    case EXPR_EXPR_WITH_CLEANUPS:
2593      S = ExprWithCleanups::Create(Context, Empty,
2594                                   Record[ASTStmtReader::NumExprFields]);
2595      break;
2596
2597    case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
2598      S = CXXDependentScopeMemberExpr::CreateEmpty(Context,
2599         /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
2600                  /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
2601                                   ? Record[ASTStmtReader::NumExprFields + 1]
2602                                   : 0);
2603      break;
2604
2605    case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
2606      S = DependentScopeDeclRefExpr::CreateEmpty(Context,
2607         /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
2608                  /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
2609                                   ? Record[ASTStmtReader::NumExprFields + 1]
2610                                   : 0);
2611      break;
2612
2613    case EXPR_CXX_UNRESOLVED_CONSTRUCT:
2614      S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
2615                              /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
2616      break;
2617
2618    case EXPR_CXX_UNRESOLVED_MEMBER:
2619      S = UnresolvedMemberExpr::CreateEmpty(Context,
2620         /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
2621                  /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
2622                                   ? Record[ASTStmtReader::NumExprFields + 1]
2623                                   : 0);
2624      break;
2625
2626    case EXPR_CXX_UNRESOLVED_LOOKUP:
2627      S = UnresolvedLookupExpr::CreateEmpty(Context,
2628         /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
2629                  /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
2630                                   ? Record[ASTStmtReader::NumExprFields + 1]
2631                                   : 0);
2632      break;
2633
2634    case EXPR_TYPE_TRAIT:
2635      S = TypeTraitExpr::CreateDeserialized(Context,
2636            Record[ASTStmtReader::NumExprFields]);
2637      break;
2638
2639    case EXPR_ARRAY_TYPE_TRAIT:
2640      S = new (Context) ArrayTypeTraitExpr(Empty);
2641      break;
2642
2643    case EXPR_CXX_EXPRESSION_TRAIT:
2644      S = new (Context) ExpressionTraitExpr(Empty);
2645      break;
2646
2647    case EXPR_CXX_NOEXCEPT:
2648      S = new (Context) CXXNoexceptExpr(Empty);
2649      break;
2650
2651    case EXPR_PACK_EXPANSION:
2652      S = new (Context) PackExpansionExpr(Empty);
2653      break;
2654
2655    case EXPR_SIZEOF_PACK:
2656      S = new (Context) SizeOfPackExpr(Empty);
2657      break;
2658
2659    case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
2660      S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
2661      break;
2662
2663    case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
2664      S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
2665      break;
2666
2667    case EXPR_FUNCTION_PARM_PACK:
2668      S = FunctionParmPackExpr::CreateEmpty(Context,
2669                                          Record[ASTStmtReader::NumExprFields]);
2670      break;
2671
2672    case EXPR_MATERIALIZE_TEMPORARY:
2673      S = new (Context) MaterializeTemporaryExpr(Empty);
2674      break;
2675
2676    case EXPR_OPAQUE_VALUE:
2677      S = new (Context) OpaqueValueExpr(Empty);
2678      break;
2679
2680    case EXPR_CUDA_KERNEL_CALL:
2681      S = new (Context) CUDAKernelCallExpr(Context, Empty);
2682      break;
2683
2684    case EXPR_ASTYPE:
2685      S = new (Context) AsTypeExpr(Empty);
2686      break;
2687
2688    case EXPR_PSEUDO_OBJECT: {
2689      unsigned numSemanticExprs = Record[ASTStmtReader::NumExprFields];
2690      S = PseudoObjectExpr::Create(Context, Empty, numSemanticExprs);
2691      break;
2692    }
2693
2694    case EXPR_ATOMIC:
2695      S = new (Context) AtomicExpr(Empty);
2696      break;
2697
2698    case EXPR_LAMBDA: {
2699      unsigned NumCaptures = Record[ASTStmtReader::NumExprFields];
2700      unsigned NumArrayIndexVars = Record[ASTStmtReader::NumExprFields + 1];
2701      S = LambdaExpr::CreateDeserialized(Context, NumCaptures,
2702                                         NumArrayIndexVars);
2703      break;
2704    }
2705    }
2706
2707    // We hit a STMT_STOP, so we're done with this expression.
2708    if (Finished)
2709      break;
2710
2711    ++NumStatementsRead;
2712
2713    if (S && !IsStmtReference) {
2714      Reader.Visit(S);
2715      StmtEntries[Cursor.GetCurrentBitNo()] = S;
2716    }
2717
2718
2719    assert(Idx == Record.size() && "Invalid deserialization of statement");
2720    StmtStack.push_back(S);
2721  }
2722Done:
2723  assert(StmtStack.size() > PrevNumStmts && "Read too many sub-stmts!");
2724  assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
2725  return StmtStack.pop_back_val();
2726}
2727