• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/DeclCXX.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "clang/AST/StmtVisitor.h"
19 using namespace clang;
20 using namespace clang::serialization;
21 
22 namespace clang {
23 
24   class ASTStmtReader : public StmtVisitor<ASTStmtReader> {
25     ASTReader &Reader;
26     ASTReader::PerFileData &F;
27     llvm::BitstreamCursor &DeclsCursor;
28     const ASTReader::RecordData &Record;
29     unsigned &Idx;
30 
ReadSourceLocation(const ASTReader::RecordData & R,unsigned & I)31     SourceLocation ReadSourceLocation(const ASTReader::RecordData &R,
32                                       unsigned &I) {
33       return Reader.ReadSourceLocation(F, R, I);
34     }
ReadSourceRange(const ASTReader::RecordData & R,unsigned & I)35     SourceRange ReadSourceRange(const ASTReader::RecordData &R, unsigned &I) {
36       return Reader.ReadSourceRange(F, R, I);
37     }
GetTypeSourceInfo(const ASTReader::RecordData & R,unsigned & I)38     TypeSourceInfo *GetTypeSourceInfo(const ASTReader::RecordData &R,
39                                       unsigned &I) {
40       return Reader.GetTypeSourceInfo(F, R, I);
41     }
ReadDeclarationNameLoc(DeclarationNameLoc & DNLoc,DeclarationName Name,const ASTReader::RecordData & R,unsigned & I)42     void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
43                                 const ASTReader::RecordData &R, unsigned &I) {
44       Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
45     }
ReadDeclarationNameInfo(DeclarationNameInfo & NameInfo,const ASTReader::RecordData & R,unsigned & I)46     void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
47                                 const ASTReader::RecordData &R, unsigned &I) {
48       Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
49     }
50 
51   public:
ASTStmtReader(ASTReader & Reader,ASTReader::PerFileData & F,llvm::BitstreamCursor & Cursor,const ASTReader::RecordData & Record,unsigned & Idx)52     ASTStmtReader(ASTReader &Reader, ASTReader::PerFileData &F,
53                   llvm::BitstreamCursor &Cursor,
54                   const ASTReader::RecordData &Record, unsigned &Idx)
55       : Reader(Reader), F(F), DeclsCursor(Cursor), Record(Record), Idx(Idx) { }
56 
57     /// \brief The number of record fields required for the Stmt class
58     /// itself.
59     static const unsigned NumStmtFields = 0;
60 
61     /// \brief The number of record fields required for the Expr class
62     /// itself.
63     static const unsigned NumExprFields = NumStmtFields + 7;
64 
65     /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
66     void ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
67                                           unsigned NumTemplateArgs);
68 
69     void VisitStmt(Stmt *S);
70 #define STMT(Type, Base) \
71     void Visit##Type(Type *);
72 #include "clang/AST/StmtNodes.inc"
73   };
74 }
75 
76 void ASTStmtReader::
ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList & ArgList,unsigned NumTemplateArgs)77 ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
78                                  unsigned NumTemplateArgs) {
79   TemplateArgumentListInfo ArgInfo;
80   ArgInfo.setLAngleLoc(ReadSourceLocation(Record, Idx));
81   ArgInfo.setRAngleLoc(ReadSourceLocation(Record, Idx));
82   for (unsigned i = 0; i != NumTemplateArgs; ++i)
83     ArgInfo.addArgument(
84         Reader.ReadTemplateArgumentLoc(F, Record, Idx));
85   ArgList.initializeFrom(ArgInfo);
86 }
87 
VisitStmt(Stmt * S)88 void ASTStmtReader::VisitStmt(Stmt *S) {
89   assert(Idx == NumStmtFields && "Incorrect statement field count");
90 }
91 
VisitNullStmt(NullStmt * S)92 void ASTStmtReader::VisitNullStmt(NullStmt *S) {
93   VisitStmt(S);
94   S->setSemiLoc(ReadSourceLocation(Record, Idx));
95   S->LeadingEmptyMacro = ReadSourceLocation(Record, Idx);
96 }
97 
VisitCompoundStmt(CompoundStmt * S)98 void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
99   VisitStmt(S);
100   llvm::SmallVector<Stmt *, 16> Stmts;
101   unsigned NumStmts = Record[Idx++];
102   while (NumStmts--)
103     Stmts.push_back(Reader.ReadSubStmt());
104   S->setStmts(*Reader.getContext(), Stmts.data(), Stmts.size());
105   S->setLBracLoc(ReadSourceLocation(Record, Idx));
106   S->setRBracLoc(ReadSourceLocation(Record, Idx));
107 }
108 
VisitSwitchCase(SwitchCase * S)109 void ASTStmtReader::VisitSwitchCase(SwitchCase *S) {
110   VisitStmt(S);
111   Reader.RecordSwitchCaseID(S, Record[Idx++]);
112 }
113 
VisitCaseStmt(CaseStmt * S)114 void ASTStmtReader::VisitCaseStmt(CaseStmt *S) {
115   VisitSwitchCase(S);
116   S->setLHS(Reader.ReadSubExpr());
117   S->setRHS(Reader.ReadSubExpr());
118   S->setSubStmt(Reader.ReadSubStmt());
119   S->setCaseLoc(ReadSourceLocation(Record, Idx));
120   S->setEllipsisLoc(ReadSourceLocation(Record, Idx));
121   S->setColonLoc(ReadSourceLocation(Record, Idx));
122 }
123 
VisitDefaultStmt(DefaultStmt * S)124 void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) {
125   VisitSwitchCase(S);
126   S->setSubStmt(Reader.ReadSubStmt());
127   S->setDefaultLoc(ReadSourceLocation(Record, Idx));
128   S->setColonLoc(ReadSourceLocation(Record, Idx));
129 }
130 
VisitLabelStmt(LabelStmt * S)131 void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
132   VisitStmt(S);
133   LabelDecl *LD = cast<LabelDecl>(Reader.GetDecl(Record[Idx++]));
134   LD->setStmt(S);
135   S->setDecl(LD);
136   S->setSubStmt(Reader.ReadSubStmt());
137   S->setIdentLoc(ReadSourceLocation(Record, Idx));
138 }
139 
VisitIfStmt(IfStmt * S)140 void ASTStmtReader::VisitIfStmt(IfStmt *S) {
141   VisitStmt(S);
142   S->setConditionVariable(*Reader.getContext(),
143                           cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
144   S->setCond(Reader.ReadSubExpr());
145   S->setThen(Reader.ReadSubStmt());
146   S->setElse(Reader.ReadSubStmt());
147   S->setIfLoc(ReadSourceLocation(Record, Idx));
148   S->setElseLoc(ReadSourceLocation(Record, Idx));
149 }
150 
VisitSwitchStmt(SwitchStmt * S)151 void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) {
152   VisitStmt(S);
153   S->setConditionVariable(*Reader.getContext(),
154                           cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
155   S->setCond(Reader.ReadSubExpr());
156   S->setBody(Reader.ReadSubStmt());
157   S->setSwitchLoc(ReadSourceLocation(Record, Idx));
158   if (Record[Idx++])
159     S->setAllEnumCasesCovered();
160 
161   SwitchCase *PrevSC = 0;
162   for (unsigned N = Record.size(); Idx != N; ++Idx) {
163     SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]);
164     if (PrevSC)
165       PrevSC->setNextSwitchCase(SC);
166     else
167       S->setSwitchCaseList(SC);
168 
169     PrevSC = SC;
170   }
171 }
172 
VisitWhileStmt(WhileStmt * S)173 void ASTStmtReader::VisitWhileStmt(WhileStmt *S) {
174   VisitStmt(S);
175   S->setConditionVariable(*Reader.getContext(),
176                           cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
177   S->setCond(Reader.ReadSubExpr());
178   S->setBody(Reader.ReadSubStmt());
179   S->setWhileLoc(ReadSourceLocation(Record, Idx));
180 }
181 
VisitDoStmt(DoStmt * S)182 void ASTStmtReader::VisitDoStmt(DoStmt *S) {
183   VisitStmt(S);
184   S->setCond(Reader.ReadSubExpr());
185   S->setBody(Reader.ReadSubStmt());
186   S->setDoLoc(ReadSourceLocation(Record, Idx));
187   S->setWhileLoc(ReadSourceLocation(Record, Idx));
188   S->setRParenLoc(ReadSourceLocation(Record, Idx));
189 }
190 
VisitForStmt(ForStmt * S)191 void ASTStmtReader::VisitForStmt(ForStmt *S) {
192   VisitStmt(S);
193   S->setInit(Reader.ReadSubStmt());
194   S->setCond(Reader.ReadSubExpr());
195   S->setConditionVariable(*Reader.getContext(),
196                           cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
197   S->setInc(Reader.ReadSubExpr());
198   S->setBody(Reader.ReadSubStmt());
199   S->setForLoc(ReadSourceLocation(Record, Idx));
200   S->setLParenLoc(ReadSourceLocation(Record, Idx));
201   S->setRParenLoc(ReadSourceLocation(Record, Idx));
202 }
203 
VisitGotoStmt(GotoStmt * S)204 void ASTStmtReader::VisitGotoStmt(GotoStmt *S) {
205   VisitStmt(S);
206   S->setLabel(cast<LabelDecl>(Reader.GetDecl(Record[Idx++])));
207   S->setGotoLoc(ReadSourceLocation(Record, Idx));
208   S->setLabelLoc(ReadSourceLocation(Record, Idx));
209 }
210 
VisitIndirectGotoStmt(IndirectGotoStmt * S)211 void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
212   VisitStmt(S);
213   S->setGotoLoc(ReadSourceLocation(Record, Idx));
214   S->setStarLoc(ReadSourceLocation(Record, Idx));
215   S->setTarget(Reader.ReadSubExpr());
216 }
217 
VisitContinueStmt(ContinueStmt * S)218 void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) {
219   VisitStmt(S);
220   S->setContinueLoc(ReadSourceLocation(Record, Idx));
221 }
222 
VisitBreakStmt(BreakStmt * S)223 void ASTStmtReader::VisitBreakStmt(BreakStmt *S) {
224   VisitStmt(S);
225   S->setBreakLoc(ReadSourceLocation(Record, Idx));
226 }
227 
VisitReturnStmt(ReturnStmt * S)228 void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) {
229   VisitStmt(S);
230   S->setRetValue(Reader.ReadSubExpr());
231   S->setReturnLoc(ReadSourceLocation(Record, Idx));
232   S->setNRVOCandidate(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
233 }
234 
VisitDeclStmt(DeclStmt * S)235 void ASTStmtReader::VisitDeclStmt(DeclStmt *S) {
236   VisitStmt(S);
237   S->setStartLoc(ReadSourceLocation(Record, Idx));
238   S->setEndLoc(ReadSourceLocation(Record, Idx));
239 
240   if (Idx + 1 == Record.size()) {
241     // Single declaration
242     S->setDeclGroup(DeclGroupRef(Reader.GetDecl(Record[Idx++])));
243   } else {
244     llvm::SmallVector<Decl *, 16> Decls;
245     Decls.reserve(Record.size() - Idx);
246     for (unsigned N = Record.size(); Idx != N; ++Idx)
247       Decls.push_back(Reader.GetDecl(Record[Idx]));
248     S->setDeclGroup(DeclGroupRef(DeclGroup::Create(*Reader.getContext(),
249                                                    Decls.data(),
250                                                    Decls.size())));
251   }
252 }
253 
VisitAsmStmt(AsmStmt * S)254 void ASTStmtReader::VisitAsmStmt(AsmStmt *S) {
255   VisitStmt(S);
256   unsigned NumOutputs = Record[Idx++];
257   unsigned NumInputs = Record[Idx++];
258   unsigned NumClobbers = Record[Idx++];
259   S->setAsmLoc(ReadSourceLocation(Record, Idx));
260   S->setRParenLoc(ReadSourceLocation(Record, Idx));
261   S->setVolatile(Record[Idx++]);
262   S->setSimple(Record[Idx++]);
263   S->setMSAsm(Record[Idx++]);
264 
265   S->setAsmString(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
266 
267   // Outputs and inputs
268   llvm::SmallVector<IdentifierInfo *, 16> Names;
269   llvm::SmallVector<StringLiteral*, 16> Constraints;
270   llvm::SmallVector<Stmt*, 16> Exprs;
271   for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
272     Names.push_back(Reader.GetIdentifierInfo(Record, Idx));
273     Constraints.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
274     Exprs.push_back(Reader.ReadSubStmt());
275   }
276 
277   // Constraints
278   llvm::SmallVector<StringLiteral*, 16> Clobbers;
279   for (unsigned I = 0; I != NumClobbers; ++I)
280     Clobbers.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
281 
282   S->setOutputsAndInputsAndClobbers(*Reader.getContext(),
283                                     Names.data(), Constraints.data(),
284                                     Exprs.data(), NumOutputs, NumInputs,
285                                     Clobbers.data(), NumClobbers);
286 }
287 
VisitExpr(Expr * E)288 void ASTStmtReader::VisitExpr(Expr *E) {
289   VisitStmt(E);
290   E->setType(Reader.GetType(Record[Idx++]));
291   E->setTypeDependent(Record[Idx++]);
292   E->setValueDependent(Record[Idx++]);
293   E->setInstantiationDependent(Record[Idx++]);
294   E->ExprBits.ContainsUnexpandedParameterPack = Record[Idx++];
295   E->setValueKind(static_cast<ExprValueKind>(Record[Idx++]));
296   E->setObjectKind(static_cast<ExprObjectKind>(Record[Idx++]));
297   assert(Idx == NumExprFields && "Incorrect expression field count");
298 }
299 
VisitPredefinedExpr(PredefinedExpr * E)300 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
301   VisitExpr(E);
302   E->setLocation(ReadSourceLocation(Record, Idx));
303   E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]);
304 }
305 
VisitDeclRefExpr(DeclRefExpr * E)306 void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
307   VisitExpr(E);
308 
309   E->DeclRefExprBits.HasQualifier = Record[Idx++];
310   E->DeclRefExprBits.HasFoundDecl = Record[Idx++];
311   E->DeclRefExprBits.HasExplicitTemplateArgs = Record[Idx++];
312   unsigned NumTemplateArgs = 0;
313   if (E->hasExplicitTemplateArgs())
314     NumTemplateArgs = Record[Idx++];
315 
316   if (E->hasQualifier())
317     E->getInternalQualifierLoc()
318       = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
319 
320   if (E->hasFoundDecl())
321     E->getInternalFoundDecl() = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
322 
323   if (E->hasExplicitTemplateArgs())
324     ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
325                                      NumTemplateArgs);
326 
327   E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
328   E->setLocation(ReadSourceLocation(Record, Idx));
329   ReadDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record, Idx);
330 }
331 
VisitIntegerLiteral(IntegerLiteral * E)332 void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
333   VisitExpr(E);
334   E->setLocation(ReadSourceLocation(Record, Idx));
335   E->setValue(*Reader.getContext(), Reader.ReadAPInt(Record, Idx));
336 }
337 
VisitFloatingLiteral(FloatingLiteral * E)338 void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
339   VisitExpr(E);
340   E->setValue(*Reader.getContext(), Reader.ReadAPFloat(Record, Idx));
341   E->setExact(Record[Idx++]);
342   E->setLocation(ReadSourceLocation(Record, Idx));
343 }
344 
VisitImaginaryLiteral(ImaginaryLiteral * E)345 void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
346   VisitExpr(E);
347   E->setSubExpr(Reader.ReadSubExpr());
348 }
349 
VisitStringLiteral(StringLiteral * E)350 void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
351   VisitExpr(E);
352   unsigned Len = Record[Idx++];
353   assert(Record[Idx] == E->getNumConcatenated() &&
354          "Wrong number of concatenated tokens!");
355   ++Idx;
356   E->IsWide = Record[Idx++];
357   E->IsPascal = Record[Idx++];
358 
359   // Read string data
360   llvm::SmallString<16> Str(&Record[Idx], &Record[Idx] + Len);
361   E->setString(*Reader.getContext(), Str.str());
362   Idx += Len;
363 
364   // Read source locations
365   for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
366     E->setStrTokenLoc(I, ReadSourceLocation(Record, Idx));
367 }
368 
VisitCharacterLiteral(CharacterLiteral * E)369 void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
370   VisitExpr(E);
371   E->setValue(Record[Idx++]);
372   E->setLocation(ReadSourceLocation(Record, Idx));
373   E->setWide(Record[Idx++]);
374 }
375 
VisitParenExpr(ParenExpr * E)376 void ASTStmtReader::VisitParenExpr(ParenExpr *E) {
377   VisitExpr(E);
378   E->setLParen(ReadSourceLocation(Record, Idx));
379   E->setRParen(ReadSourceLocation(Record, Idx));
380   E->setSubExpr(Reader.ReadSubExpr());
381 }
382 
VisitParenListExpr(ParenListExpr * E)383 void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
384   VisitExpr(E);
385   unsigned NumExprs = Record[Idx++];
386   E->Exprs = new (*Reader.getContext()) Stmt*[NumExprs];
387   for (unsigned i = 0; i != NumExprs; ++i)
388     E->Exprs[i] = Reader.ReadSubStmt();
389   E->NumExprs = NumExprs;
390   E->LParenLoc = ReadSourceLocation(Record, Idx);
391   E->RParenLoc = ReadSourceLocation(Record, Idx);
392 }
393 
VisitUnaryOperator(UnaryOperator * E)394 void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) {
395   VisitExpr(E);
396   E->setSubExpr(Reader.ReadSubExpr());
397   E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
398   E->setOperatorLoc(ReadSourceLocation(Record, Idx));
399 }
400 
VisitOffsetOfExpr(OffsetOfExpr * E)401 void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
402   typedef OffsetOfExpr::OffsetOfNode Node;
403   VisitExpr(E);
404   assert(E->getNumComponents() == Record[Idx]);
405   ++Idx;
406   assert(E->getNumExpressions() == Record[Idx]);
407   ++Idx;
408   E->setOperatorLoc(ReadSourceLocation(Record, Idx));
409   E->setRParenLoc(ReadSourceLocation(Record, Idx));
410   E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
411   for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
412     Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]);
413     SourceLocation Start = ReadSourceLocation(Record, Idx);
414     SourceLocation End = ReadSourceLocation(Record, Idx);
415     switch (Kind) {
416     case Node::Array:
417       E->setComponent(I, Node(Start, Record[Idx++], End));
418       break;
419 
420     case Node::Field:
421       E->setComponent(I,
422              Node(Start,
423                   dyn_cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++])),
424                   End));
425       break;
426 
427     case Node::Identifier:
428       E->setComponent(I, Node(Start, Reader.GetIdentifier(Record[Idx++]), End));
429       break;
430 
431     case Node::Base: {
432       CXXBaseSpecifier *Base = new (*Reader.getContext()) CXXBaseSpecifier();
433       *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
434       E->setComponent(I, Node(Base));
435       break;
436     }
437     }
438   }
439 
440   for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
441     E->setIndexExpr(I, Reader.ReadSubExpr());
442 }
443 
VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr * E)444 void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
445   VisitExpr(E);
446   E->setKind(static_cast<UnaryExprOrTypeTrait>(Record[Idx++]));
447   if (Record[Idx] == 0) {
448     E->setArgument(Reader.ReadSubExpr());
449     ++Idx;
450   } else {
451     E->setArgument(GetTypeSourceInfo(Record, Idx));
452   }
453   E->setOperatorLoc(ReadSourceLocation(Record, Idx));
454   E->setRParenLoc(ReadSourceLocation(Record, Idx));
455 }
456 
VisitArraySubscriptExpr(ArraySubscriptExpr * E)457 void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
458   VisitExpr(E);
459   E->setLHS(Reader.ReadSubExpr());
460   E->setRHS(Reader.ReadSubExpr());
461   E->setRBracketLoc(ReadSourceLocation(Record, Idx));
462 }
463 
VisitCallExpr(CallExpr * E)464 void ASTStmtReader::VisitCallExpr(CallExpr *E) {
465   VisitExpr(E);
466   E->setNumArgs(*Reader.getContext(), Record[Idx++]);
467   E->setRParenLoc(ReadSourceLocation(Record, Idx));
468   E->setCallee(Reader.ReadSubExpr());
469   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
470     E->setArg(I, Reader.ReadSubExpr());
471 }
472 
VisitCXXMemberCallExpr(CXXMemberCallExpr * E)473 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
474   VisitCallExpr(E);
475 }
476 
VisitMemberExpr(MemberExpr * E)477 void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
478   // Don't call VisitExpr, this is fully initialized at creation.
479   assert(E->getStmtClass() == Stmt::MemberExprClass &&
480          "It's a subclass, we must advance Idx!");
481 }
482 
VisitObjCIsaExpr(ObjCIsaExpr * E)483 void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
484   VisitExpr(E);
485   E->setBase(Reader.ReadSubExpr());
486   E->setIsaMemberLoc(ReadSourceLocation(Record, Idx));
487   E->setArrow(Record[Idx++]);
488 }
489 
490 void ASTStmtReader::
VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr * E)491 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
492   VisitExpr(E);
493   E->Operand = Reader.ReadSubExpr();
494   E->setShouldCopy(Record[Idx++]);
495 }
496 
VisitObjCBridgedCastExpr(ObjCBridgedCastExpr * E)497 void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
498   VisitExplicitCastExpr(E);
499   E->LParenLoc = ReadSourceLocation(Record, Idx);
500   E->BridgeKeywordLoc = ReadSourceLocation(Record, Idx);
501   E->Kind = Record[Idx++];
502 }
503 
VisitCastExpr(CastExpr * E)504 void ASTStmtReader::VisitCastExpr(CastExpr *E) {
505   VisitExpr(E);
506   unsigned NumBaseSpecs = Record[Idx++];
507   assert(NumBaseSpecs == E->path_size());
508   E->setSubExpr(Reader.ReadSubExpr());
509   E->setCastKind((CastExpr::CastKind)Record[Idx++]);
510   CastExpr::path_iterator BaseI = E->path_begin();
511   while (NumBaseSpecs--) {
512     CXXBaseSpecifier *BaseSpec = new (*Reader.getContext()) CXXBaseSpecifier;
513     *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
514     *BaseI++ = BaseSpec;
515   }
516 }
517 
VisitBinaryOperator(BinaryOperator * E)518 void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
519   VisitExpr(E);
520   E->setLHS(Reader.ReadSubExpr());
521   E->setRHS(Reader.ReadSubExpr());
522   E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
523   E->setOperatorLoc(ReadSourceLocation(Record, Idx));
524 }
525 
VisitCompoundAssignOperator(CompoundAssignOperator * E)526 void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
527   VisitBinaryOperator(E);
528   E->setComputationLHSType(Reader.GetType(Record[Idx++]));
529   E->setComputationResultType(Reader.GetType(Record[Idx++]));
530 }
531 
VisitConditionalOperator(ConditionalOperator * E)532 void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
533   VisitExpr(E);
534   E->SubExprs[ConditionalOperator::COND] = Reader.ReadSubExpr();
535   E->SubExprs[ConditionalOperator::LHS] = Reader.ReadSubExpr();
536   E->SubExprs[ConditionalOperator::RHS] = Reader.ReadSubExpr();
537   E->QuestionLoc = ReadSourceLocation(Record, Idx);
538   E->ColonLoc = ReadSourceLocation(Record, Idx);
539 }
540 
541 void
VisitBinaryConditionalOperator(BinaryConditionalOperator * E)542 ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
543   VisitExpr(E);
544   E->OpaqueValue = cast<OpaqueValueExpr>(Reader.ReadSubExpr());
545   E->SubExprs[BinaryConditionalOperator::COMMON] = Reader.ReadSubExpr();
546   E->SubExprs[BinaryConditionalOperator::COND] = Reader.ReadSubExpr();
547   E->SubExprs[BinaryConditionalOperator::LHS] = Reader.ReadSubExpr();
548   E->SubExprs[BinaryConditionalOperator::RHS] = Reader.ReadSubExpr();
549   E->QuestionLoc = ReadSourceLocation(Record, Idx);
550   E->ColonLoc = ReadSourceLocation(Record, Idx);
551 
552   E->getOpaqueValue()->setSourceExpr(E->getCommon());
553 }
554 
VisitImplicitCastExpr(ImplicitCastExpr * E)555 void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
556   VisitCastExpr(E);
557 }
558 
VisitExplicitCastExpr(ExplicitCastExpr * E)559 void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
560   VisitCastExpr(E);
561   E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx));
562 }
563 
VisitCStyleCastExpr(CStyleCastExpr * E)564 void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
565   VisitExplicitCastExpr(E);
566   E->setLParenLoc(ReadSourceLocation(Record, Idx));
567   E->setRParenLoc(ReadSourceLocation(Record, Idx));
568 }
569 
VisitCompoundLiteralExpr(CompoundLiteralExpr * E)570 void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
571   VisitExpr(E);
572   E->setLParenLoc(ReadSourceLocation(Record, Idx));
573   E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
574   E->setInitializer(Reader.ReadSubExpr());
575   E->setFileScope(Record[Idx++]);
576 }
577 
VisitExtVectorElementExpr(ExtVectorElementExpr * E)578 void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
579   VisitExpr(E);
580   E->setBase(Reader.ReadSubExpr());
581   E->setAccessor(Reader.GetIdentifierInfo(Record, Idx));
582   E->setAccessorLoc(ReadSourceLocation(Record, Idx));
583 }
584 
VisitInitListExpr(InitListExpr * E)585 void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
586   VisitExpr(E);
587   E->setSyntacticForm(cast_or_null<InitListExpr>(Reader.ReadSubStmt()));
588   E->setLBraceLoc(ReadSourceLocation(Record, Idx));
589   E->setRBraceLoc(ReadSourceLocation(Record, Idx));
590   bool isArrayFiller = Record[Idx++];
591   Expr *filler = 0;
592   if (isArrayFiller) {
593     filler = Reader.ReadSubExpr();
594     E->ArrayFillerOrUnionFieldInit = filler;
595   } else
596     E->ArrayFillerOrUnionFieldInit
597         = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
598   E->sawArrayRangeDesignator(Record[Idx++]);
599   unsigned NumInits = Record[Idx++];
600   E->reserveInits(*Reader.getContext(), NumInits);
601   if (isArrayFiller) {
602     for (unsigned I = 0; I != NumInits; ++I) {
603       Expr *init = Reader.ReadSubExpr();
604       E->updateInit(*Reader.getContext(), I, init ? init : filler);
605     }
606   } else {
607     for (unsigned I = 0; I != NumInits; ++I)
608       E->updateInit(*Reader.getContext(), I, Reader.ReadSubExpr());
609   }
610 }
611 
VisitDesignatedInitExpr(DesignatedInitExpr * E)612 void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
613   typedef DesignatedInitExpr::Designator Designator;
614 
615   VisitExpr(E);
616   unsigned NumSubExprs = Record[Idx++];
617   assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
618   for (unsigned I = 0; I != NumSubExprs; ++I)
619     E->setSubExpr(I, Reader.ReadSubExpr());
620   E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx));
621   E->setGNUSyntax(Record[Idx++]);
622 
623   llvm::SmallVector<Designator, 4> Designators;
624   while (Idx < Record.size()) {
625     switch ((DesignatorTypes)Record[Idx++]) {
626     case DESIG_FIELD_DECL: {
627       FieldDecl *Field = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
628       SourceLocation DotLoc
629         = ReadSourceLocation(Record, Idx);
630       SourceLocation FieldLoc
631         = ReadSourceLocation(Record, Idx);
632       Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
633                                        FieldLoc));
634       Designators.back().setField(Field);
635       break;
636     }
637 
638     case DESIG_FIELD_NAME: {
639       const IdentifierInfo *Name = Reader.GetIdentifierInfo(Record, Idx);
640       SourceLocation DotLoc
641         = ReadSourceLocation(Record, Idx);
642       SourceLocation FieldLoc
643         = ReadSourceLocation(Record, Idx);
644       Designators.push_back(Designator(Name, DotLoc, FieldLoc));
645       break;
646     }
647 
648     case DESIG_ARRAY: {
649       unsigned Index = Record[Idx++];
650       SourceLocation LBracketLoc
651         = ReadSourceLocation(Record, Idx);
652       SourceLocation RBracketLoc
653         = ReadSourceLocation(Record, Idx);
654       Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
655       break;
656     }
657 
658     case DESIG_ARRAY_RANGE: {
659       unsigned Index = Record[Idx++];
660       SourceLocation LBracketLoc
661         = ReadSourceLocation(Record, Idx);
662       SourceLocation EllipsisLoc
663         = ReadSourceLocation(Record, Idx);
664       SourceLocation RBracketLoc
665         = ReadSourceLocation(Record, Idx);
666       Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
667                                        RBracketLoc));
668       break;
669     }
670     }
671   }
672   E->setDesignators(*Reader.getContext(),
673                     Designators.data(), Designators.size());
674 }
675 
VisitImplicitValueInitExpr(ImplicitValueInitExpr * E)676 void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
677   VisitExpr(E);
678 }
679 
VisitVAArgExpr(VAArgExpr * E)680 void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
681   VisitExpr(E);
682   E->setSubExpr(Reader.ReadSubExpr());
683   E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx));
684   E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
685   E->setRParenLoc(ReadSourceLocation(Record, Idx));
686 }
687 
VisitAddrLabelExpr(AddrLabelExpr * E)688 void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
689   VisitExpr(E);
690   E->setAmpAmpLoc(ReadSourceLocation(Record, Idx));
691   E->setLabelLoc(ReadSourceLocation(Record, Idx));
692   E->setLabel(cast<LabelDecl>(Reader.GetDecl(Record[Idx++])));
693 }
694 
VisitStmtExpr(StmtExpr * E)695 void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
696   VisitExpr(E);
697   E->setLParenLoc(ReadSourceLocation(Record, Idx));
698   E->setRParenLoc(ReadSourceLocation(Record, Idx));
699   E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt()));
700 }
701 
VisitChooseExpr(ChooseExpr * E)702 void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
703   VisitExpr(E);
704   E->setCond(Reader.ReadSubExpr());
705   E->setLHS(Reader.ReadSubExpr());
706   E->setRHS(Reader.ReadSubExpr());
707   E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
708   E->setRParenLoc(ReadSourceLocation(Record, Idx));
709 }
710 
VisitGNUNullExpr(GNUNullExpr * E)711 void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
712   VisitExpr(E);
713   E->setTokenLocation(ReadSourceLocation(Record, Idx));
714 }
715 
VisitShuffleVectorExpr(ShuffleVectorExpr * E)716 void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
717   VisitExpr(E);
718   llvm::SmallVector<Expr *, 16> Exprs;
719   unsigned NumExprs = Record[Idx++];
720   while (NumExprs--)
721     Exprs.push_back(Reader.ReadSubExpr());
722   E->setExprs(*Reader.getContext(), Exprs.data(), Exprs.size());
723   E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
724   E->setRParenLoc(ReadSourceLocation(Record, Idx));
725 }
726 
VisitBlockExpr(BlockExpr * E)727 void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
728   VisitExpr(E);
729   E->setBlockDecl(cast_or_null<BlockDecl>(Reader.GetDecl(Record[Idx++])));
730 }
731 
VisitBlockDeclRefExpr(BlockDeclRefExpr * E)732 void ASTStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
733   VisitExpr(E);
734   E->setDecl(cast<VarDecl>(Reader.GetDecl(Record[Idx++])));
735   E->setLocation(ReadSourceLocation(Record, Idx));
736   E->setByRef(Record[Idx++]);
737   E->setConstQualAdded(Record[Idx++]);
738 }
739 
VisitGenericSelectionExpr(GenericSelectionExpr * E)740 void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
741   VisitExpr(E);
742   E->NumAssocs = Record[Idx++];
743   E->AssocTypes = new (*Reader.getContext()) TypeSourceInfo*[E->NumAssocs];
744   E->SubExprs =
745    new(*Reader.getContext()) Stmt*[GenericSelectionExpr::END_EXPR+E->NumAssocs];
746 
747   E->SubExprs[GenericSelectionExpr::CONTROLLING] = Reader.ReadSubExpr();
748   for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
749     E->AssocTypes[I] = GetTypeSourceInfo(Record, Idx);
750     E->SubExprs[GenericSelectionExpr::END_EXPR+I] = Reader.ReadSubExpr();
751   }
752   E->ResultIndex = Record[Idx++];
753 
754   E->GenericLoc = ReadSourceLocation(Record, Idx);
755   E->DefaultLoc = ReadSourceLocation(Record, Idx);
756   E->RParenLoc = ReadSourceLocation(Record, Idx);
757 }
758 
759 //===----------------------------------------------------------------------===//
760 // Objective-C Expressions and Statements
761 
VisitObjCStringLiteral(ObjCStringLiteral * E)762 void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
763   VisitExpr(E);
764   E->setString(cast<StringLiteral>(Reader.ReadSubStmt()));
765   E->setAtLoc(ReadSourceLocation(Record, Idx));
766 }
767 
VisitObjCEncodeExpr(ObjCEncodeExpr * E)768 void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
769   VisitExpr(E);
770   E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
771   E->setAtLoc(ReadSourceLocation(Record, Idx));
772   E->setRParenLoc(ReadSourceLocation(Record, Idx));
773 }
774 
VisitObjCSelectorExpr(ObjCSelectorExpr * E)775 void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
776   VisitExpr(E);
777   E->setSelector(Reader.GetSelector(Record, Idx));
778   E->setAtLoc(ReadSourceLocation(Record, Idx));
779   E->setRParenLoc(ReadSourceLocation(Record, Idx));
780 }
781 
VisitObjCProtocolExpr(ObjCProtocolExpr * E)782 void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
783   VisitExpr(E);
784   E->setProtocol(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
785   E->setAtLoc(ReadSourceLocation(Record, Idx));
786   E->setRParenLoc(ReadSourceLocation(Record, Idx));
787 }
788 
VisitObjCIvarRefExpr(ObjCIvarRefExpr * E)789 void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
790   VisitExpr(E);
791   E->setDecl(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
792   E->setLocation(ReadSourceLocation(Record, Idx));
793   E->setBase(Reader.ReadSubExpr());
794   E->setIsArrow(Record[Idx++]);
795   E->setIsFreeIvar(Record[Idx++]);
796 }
797 
VisitObjCPropertyRefExpr(ObjCPropertyRefExpr * E)798 void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
799   VisitExpr(E);
800   bool Implicit = Record[Idx++] != 0;
801   if (Implicit) {
802     ObjCMethodDecl *Getter =
803       cast<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]));
804     ObjCMethodDecl *Setter =
805       cast<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]));
806     E->setImplicitProperty(Getter, Setter);
807   } else {
808     E->setExplicitProperty(
809                       cast<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
810   }
811   E->setLocation(ReadSourceLocation(Record, Idx));
812   E->setReceiverLocation(ReadSourceLocation(Record, Idx));
813   switch (Record[Idx++]) {
814   case 0:
815     E->setBase(Reader.ReadSubExpr());
816     break;
817   case 1:
818     E->setSuperReceiver(Reader.GetType(Record[Idx++]));
819     break;
820   case 2:
821     E->setClassReceiver(
822                      cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
823     break;
824   }
825 }
826 
VisitObjCMessageExpr(ObjCMessageExpr * E)827 void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
828   VisitExpr(E);
829   assert(Record[Idx] == E->getNumArgs());
830   ++Idx;
831   E->setDelegateInitCall(Record[Idx++]);
832   ObjCMessageExpr::ReceiverKind Kind
833     = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
834   switch (Kind) {
835   case ObjCMessageExpr::Instance:
836     E->setInstanceReceiver(Reader.ReadSubExpr());
837     break;
838 
839   case ObjCMessageExpr::Class:
840     E->setClassReceiver(GetTypeSourceInfo(Record, Idx));
841     break;
842 
843   case ObjCMessageExpr::SuperClass:
844   case ObjCMessageExpr::SuperInstance: {
845     QualType T = Reader.GetType(Record[Idx++]);
846     SourceLocation SuperLoc = ReadSourceLocation(Record, Idx);
847     E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
848     break;
849   }
850   }
851 
852   assert(Kind == E->getReceiverKind());
853 
854   if (Record[Idx++])
855     E->setMethodDecl(cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
856   else
857     E->setSelector(Reader.GetSelector(Record, Idx));
858 
859   E->LBracLoc = ReadSourceLocation(Record, Idx);
860   E->RBracLoc = ReadSourceLocation(Record, Idx);
861   E->SelectorLoc = ReadSourceLocation(Record, Idx);
862 
863   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
864     E->setArg(I, Reader.ReadSubExpr());
865 }
866 
VisitObjCForCollectionStmt(ObjCForCollectionStmt * S)867 void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
868   VisitStmt(S);
869   S->setElement(Reader.ReadSubStmt());
870   S->setCollection(Reader.ReadSubExpr());
871   S->setBody(Reader.ReadSubStmt());
872   S->setForLoc(ReadSourceLocation(Record, Idx));
873   S->setRParenLoc(ReadSourceLocation(Record, Idx));
874 }
875 
VisitObjCAtCatchStmt(ObjCAtCatchStmt * S)876 void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
877   VisitStmt(S);
878   S->setCatchBody(Reader.ReadSubStmt());
879   S->setCatchParamDecl(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
880   S->setAtCatchLoc(ReadSourceLocation(Record, Idx));
881   S->setRParenLoc(ReadSourceLocation(Record, Idx));
882 }
883 
VisitObjCAtFinallyStmt(ObjCAtFinallyStmt * S)884 void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
885   VisitStmt(S);
886   S->setFinallyBody(Reader.ReadSubStmt());
887   S->setAtFinallyLoc(ReadSourceLocation(Record, Idx));
888 }
889 
VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt * S)890 void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
891   VisitStmt(S);
892   S->setSubStmt(Reader.ReadSubStmt());
893   S->setAtLoc(ReadSourceLocation(Record, Idx));
894 }
895 
VisitObjCAtTryStmt(ObjCAtTryStmt * S)896 void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
897   VisitStmt(S);
898   assert(Record[Idx] == S->getNumCatchStmts());
899   ++Idx;
900   bool HasFinally = Record[Idx++];
901   S->setTryBody(Reader.ReadSubStmt());
902   for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
903     S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt()));
904 
905   if (HasFinally)
906     S->setFinallyStmt(Reader.ReadSubStmt());
907   S->setAtTryLoc(ReadSourceLocation(Record, Idx));
908 }
909 
VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt * S)910 void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
911   VisitStmt(S);
912   S->setSynchExpr(Reader.ReadSubStmt());
913   S->setSynchBody(Reader.ReadSubStmt());
914   S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx));
915 }
916 
VisitObjCAtThrowStmt(ObjCAtThrowStmt * S)917 void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
918   VisitStmt(S);
919   S->setThrowExpr(Reader.ReadSubStmt());
920   S->setThrowLoc(ReadSourceLocation(Record, Idx));
921 }
922 
923 //===----------------------------------------------------------------------===//
924 // C++ Expressions and Statements
925 //===----------------------------------------------------------------------===//
926 
VisitCXXCatchStmt(CXXCatchStmt * S)927 void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
928   VisitStmt(S);
929   S->CatchLoc = ReadSourceLocation(Record, Idx);
930   S->ExceptionDecl = cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]));
931   S->HandlerBlock = Reader.ReadSubStmt();
932 }
933 
VisitCXXTryStmt(CXXTryStmt * S)934 void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
935   VisitStmt(S);
936   assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?");
937   ++Idx;
938   S->TryLoc = ReadSourceLocation(Record, Idx);
939   S->getStmts()[0] = Reader.ReadSubStmt();
940   for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
941     S->getStmts()[i + 1] = Reader.ReadSubStmt();
942 }
943 
VisitCXXForRangeStmt(CXXForRangeStmt * S)944 void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
945   VisitStmt(S);
946   S->setForLoc(ReadSourceLocation(Record, Idx));
947   S->setColonLoc(ReadSourceLocation(Record, Idx));
948   S->setRParenLoc(ReadSourceLocation(Record, Idx));
949   S->setRangeStmt(Reader.ReadSubStmt());
950   S->setBeginEndStmt(Reader.ReadSubStmt());
951   S->setCond(Reader.ReadSubExpr());
952   S->setInc(Reader.ReadSubExpr());
953   S->setLoopVarStmt(Reader.ReadSubStmt());
954   S->setBody(Reader.ReadSubStmt());
955 }
956 
VisitCXXOperatorCallExpr(CXXOperatorCallExpr * E)957 void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
958   VisitCallExpr(E);
959   E->setOperator((OverloadedOperatorKind)Record[Idx++]);
960 }
961 
VisitCXXConstructExpr(CXXConstructExpr * E)962 void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
963   VisitExpr(E);
964   E->NumArgs = Record[Idx++];
965   if (E->NumArgs)
966     E->Args = new (*Reader.getContext()) Stmt*[E->NumArgs];
967   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
968     E->setArg(I, Reader.ReadSubExpr());
969   E->setConstructor(cast<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++])));
970   E->setLocation(ReadSourceLocation(Record, Idx));
971   E->setElidable(Record[Idx++]);
972   E->setRequiresZeroInitialization(Record[Idx++]);
973   E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
974   E->ParenRange = ReadSourceRange(Record, Idx);
975 }
976 
VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr * E)977 void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
978   VisitCXXConstructExpr(E);
979   E->Type = GetTypeSourceInfo(Record, Idx);
980 }
981 
VisitCXXNamedCastExpr(CXXNamedCastExpr * E)982 void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
983   VisitExplicitCastExpr(E);
984   SourceRange R = ReadSourceRange(Record, Idx);
985   E->Loc = R.getBegin();
986   E->RParenLoc = R.getEnd();
987 }
988 
VisitCXXStaticCastExpr(CXXStaticCastExpr * E)989 void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
990   return VisitCXXNamedCastExpr(E);
991 }
992 
VisitCXXDynamicCastExpr(CXXDynamicCastExpr * E)993 void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
994   return VisitCXXNamedCastExpr(E);
995 }
996 
VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr * E)997 void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
998   return VisitCXXNamedCastExpr(E);
999 }
1000 
VisitCXXConstCastExpr(CXXConstCastExpr * E)1001 void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1002   return VisitCXXNamedCastExpr(E);
1003 }
1004 
VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr * E)1005 void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1006   VisitExplicitCastExpr(E);
1007   E->setTypeBeginLoc(ReadSourceLocation(Record, Idx));
1008   E->setRParenLoc(ReadSourceLocation(Record, Idx));
1009 }
1010 
VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr * E)1011 void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1012   VisitExpr(E);
1013   E->setValue(Record[Idx++]);
1014   E->setLocation(ReadSourceLocation(Record, Idx));
1015 }
1016 
VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr * E)1017 void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1018   VisitExpr(E);
1019   E->setLocation(ReadSourceLocation(Record, Idx));
1020 }
1021 
VisitCXXTypeidExpr(CXXTypeidExpr * E)1022 void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1023   VisitExpr(E);
1024   E->setSourceRange(ReadSourceRange(Record, Idx));
1025   if (E->isTypeOperand()) { // typeid(int)
1026     E->setTypeOperandSourceInfo(
1027         GetTypeSourceInfo(Record, Idx));
1028     return;
1029   }
1030 
1031   // typeid(42+2)
1032   E->setExprOperand(Reader.ReadSubExpr());
1033 }
1034 
VisitCXXThisExpr(CXXThisExpr * E)1035 void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
1036   VisitExpr(E);
1037   E->setLocation(ReadSourceLocation(Record, Idx));
1038   E->setImplicit(Record[Idx++]);
1039 }
1040 
VisitCXXThrowExpr(CXXThrowExpr * E)1041 void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
1042   VisitExpr(E);
1043   E->ThrowLoc = ReadSourceLocation(Record, Idx);
1044   E->Op = Reader.ReadSubExpr();
1045   E->IsThrownVariableInScope = Record[Idx++];
1046 }
1047 
VisitCXXDefaultArgExpr(CXXDefaultArgExpr * E)1048 void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1049   VisitExpr(E);
1050 
1051   assert(Record[Idx] == E->Param.getInt() && "We messed up at creation ?");
1052   ++Idx; // HasOtherExprStored and SubExpr was handled during creation.
1053   E->Param.setPointer(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
1054   E->Loc = ReadSourceLocation(Record, Idx);
1055 }
1056 
VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr * E)1057 void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1058   VisitExpr(E);
1059   E->setTemporary(Reader.ReadCXXTemporary(Record, Idx));
1060   E->setSubExpr(Reader.ReadSubExpr());
1061 }
1062 
VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr * E)1063 void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1064   VisitExpr(E);
1065   E->TypeInfo = GetTypeSourceInfo(Record, Idx);
1066   E->RParenLoc = ReadSourceLocation(Record, Idx);
1067 }
1068 
VisitCXXNewExpr(CXXNewExpr * E)1069 void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
1070   VisitExpr(E);
1071   E->GlobalNew = Record[Idx++];
1072   E->Initializer = Record[Idx++];
1073   E->UsualArrayDeleteWantsSize = Record[Idx++];
1074   bool isArray = Record[Idx++];
1075   unsigned NumPlacementArgs = Record[Idx++];
1076   unsigned NumCtorArgs = Record[Idx++];
1077   E->setOperatorNew(cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
1078   E->setOperatorDelete(
1079                     cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
1080   E->setConstructor(
1081                cast_or_null<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++])));
1082   E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
1083   SourceRange TypeIdParens;
1084   TypeIdParens.setBegin(ReadSourceLocation(Record, Idx));
1085   TypeIdParens.setEnd(ReadSourceLocation(Record, Idx));
1086   E->TypeIdParens = TypeIdParens;
1087   E->StartLoc = ReadSourceLocation(Record, Idx);
1088   E->EndLoc = ReadSourceLocation(Record, Idx);
1089   E->ConstructorLParen = ReadSourceLocation(Record, Idx);
1090   E->ConstructorRParen = ReadSourceLocation(Record, Idx);
1091 
1092   E->AllocateArgsArray(*Reader.getContext(), isArray, NumPlacementArgs,
1093                        NumCtorArgs);
1094 
1095   // Install all the subexpressions.
1096   for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
1097        I != e; ++I)
1098     *I = Reader.ReadSubStmt();
1099 }
1100 
VisitCXXDeleteExpr(CXXDeleteExpr * E)1101 void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1102   VisitExpr(E);
1103   E->GlobalDelete = Record[Idx++];
1104   E->ArrayForm = Record[Idx++];
1105   E->ArrayFormAsWritten = Record[Idx++];
1106   E->UsualArrayDeleteWantsSize = Record[Idx++];
1107   E->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
1108   E->Argument = Reader.ReadSubExpr();
1109   E->Loc = ReadSourceLocation(Record, Idx);
1110 }
1111 
VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr * E)1112 void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1113   VisitExpr(E);
1114 
1115   E->Base = Reader.ReadSubExpr();
1116   E->IsArrow = Record[Idx++];
1117   E->OperatorLoc = ReadSourceLocation(Record, Idx);
1118   E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1119   E->ScopeType = GetTypeSourceInfo(Record, Idx);
1120   E->ColonColonLoc = ReadSourceLocation(Record, Idx);
1121   E->TildeLoc = ReadSourceLocation(Record, Idx);
1122 
1123   IdentifierInfo *II = Reader.GetIdentifierInfo(Record, Idx);
1124   if (II)
1125     E->setDestroyedType(II, ReadSourceLocation(Record, Idx));
1126   else
1127     E->setDestroyedType(GetTypeSourceInfo(Record, Idx));
1128 }
1129 
VisitExprWithCleanups(ExprWithCleanups * E)1130 void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
1131   VisitExpr(E);
1132   unsigned NumTemps = Record[Idx++];
1133   if (NumTemps) {
1134     E->setNumTemporaries(*Reader.getContext(), NumTemps);
1135     for (unsigned i = 0; i != NumTemps; ++i)
1136       E->setTemporary(i, Reader.ReadCXXTemporary(Record, Idx));
1137   }
1138   E->setSubExpr(Reader.ReadSubExpr());
1139 }
1140 
1141 void
VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr * E)1142 ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
1143   VisitExpr(E);
1144 
1145   if (Record[Idx++])
1146     ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
1147                                      Record[Idx++]);
1148 
1149   E->Base = Reader.ReadSubExpr();
1150   E->BaseType = Reader.GetType(Record[Idx++]);
1151   E->IsArrow = Record[Idx++];
1152   E->OperatorLoc = ReadSourceLocation(Record, Idx);
1153   E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1154   E->FirstQualifierFoundInScope
1155                       = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
1156   ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx);
1157 }
1158 
1159 void
VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr * E)1160 ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1161   VisitExpr(E);
1162 
1163   if (Record[Idx++])
1164     ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
1165                                      Record[Idx++]);
1166 
1167   E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1168   ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
1169 }
1170 
1171 void
VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr * E)1172 ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1173   VisitExpr(E);
1174   assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
1175   ++Idx; // NumArgs;
1176   for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
1177     E->setArg(I, Reader.ReadSubExpr());
1178   E->Type = GetTypeSourceInfo(Record, Idx);
1179   E->setLParenLoc(ReadSourceLocation(Record, Idx));
1180   E->setRParenLoc(ReadSourceLocation(Record, Idx));
1181 }
1182 
VisitOverloadExpr(OverloadExpr * E)1183 void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
1184   VisitExpr(E);
1185 
1186   // Read the explicit template argument list, if available.
1187   if (Record[Idx++])
1188     ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
1189                                      Record[Idx++]);
1190 
1191   unsigned NumDecls = Record[Idx++];
1192   UnresolvedSet<8> Decls;
1193   for (unsigned i = 0; i != NumDecls; ++i) {
1194     NamedDecl *D = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
1195     AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1196     Decls.addDecl(D, AS);
1197   }
1198   E->initializeResults(*Reader.getContext(), Decls.begin(), Decls.end());
1199 
1200   ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
1201   E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
1202 }
1203 
VisitUnresolvedMemberExpr(UnresolvedMemberExpr * E)1204 void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1205   VisitOverloadExpr(E);
1206   E->IsArrow = Record[Idx++];
1207   E->HasUnresolvedUsing = Record[Idx++];
1208   E->Base = Reader.ReadSubExpr();
1209   E->BaseType = Reader.GetType(Record[Idx++]);
1210   E->OperatorLoc = ReadSourceLocation(Record, Idx);
1211 }
1212 
VisitUnresolvedLookupExpr(UnresolvedLookupExpr * E)1213 void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1214   VisitOverloadExpr(E);
1215   E->RequiresADL = Record[Idx++];
1216   if (E->RequiresADL)
1217     E->StdIsAssociatedNamespace = Record[Idx++];
1218   E->Overloaded = Record[Idx++];
1219   E->NamingClass = cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
1220 }
1221 
VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr * E)1222 void ASTStmtReader::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
1223   VisitExpr(E);
1224   E->UTT = (UnaryTypeTrait)Record[Idx++];
1225   E->Value = (bool)Record[Idx++];
1226   SourceRange Range = ReadSourceRange(Record, Idx);
1227   E->Loc = Range.getBegin();
1228   E->RParen = Range.getEnd();
1229   E->QueriedType = GetTypeSourceInfo(Record, Idx);
1230 }
1231 
VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr * E)1232 void ASTStmtReader::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
1233   VisitExpr(E);
1234   E->BTT = (BinaryTypeTrait)Record[Idx++];
1235   E->Value = (bool)Record[Idx++];
1236   SourceRange Range = ReadSourceRange(Record, Idx);
1237   E->Loc = Range.getBegin();
1238   E->RParen = Range.getEnd();
1239   E->LhsType = GetTypeSourceInfo(Record, Idx);
1240   E->RhsType = GetTypeSourceInfo(Record, Idx);
1241 }
1242 
VisitArrayTypeTraitExpr(ArrayTypeTraitExpr * E)1243 void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1244   VisitExpr(E);
1245   E->ATT = (ArrayTypeTrait)Record[Idx++];
1246   E->Value = (unsigned int)Record[Idx++];
1247   SourceRange Range = ReadSourceRange(Record, Idx);
1248   E->Loc = Range.getBegin();
1249   E->RParen = Range.getEnd();
1250   E->QueriedType = GetTypeSourceInfo(Record, Idx);
1251 }
1252 
VisitExpressionTraitExpr(ExpressionTraitExpr * E)1253 void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1254   VisitExpr(E);
1255   E->ET = (ExpressionTrait)Record[Idx++];
1256   E->Value = (bool)Record[Idx++];
1257   SourceRange Range = ReadSourceRange(Record, Idx);
1258   E->QueriedExpression = Reader.ReadSubExpr();
1259   E->Loc = Range.getBegin();
1260   E->RParen = Range.getEnd();
1261 }
1262 
VisitCXXNoexceptExpr(CXXNoexceptExpr * E)1263 void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1264   VisitExpr(E);
1265   E->Value = (bool)Record[Idx++];
1266   E->Range = ReadSourceRange(Record, Idx);
1267   E->Operand = Reader.ReadSubExpr();
1268 }
1269 
VisitPackExpansionExpr(PackExpansionExpr * E)1270 void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
1271   VisitExpr(E);
1272   E->EllipsisLoc = ReadSourceLocation(Record, Idx);
1273   E->NumExpansions = Record[Idx++];
1274   E->Pattern = Reader.ReadSubExpr();
1275 }
1276 
VisitSizeOfPackExpr(SizeOfPackExpr * E)1277 void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1278   VisitExpr(E);
1279   E->OperatorLoc = ReadSourceLocation(Record, Idx);
1280   E->PackLoc = ReadSourceLocation(Record, Idx);
1281   E->RParenLoc = ReadSourceLocation(Record, Idx);
1282   E->Length = Record[Idx++];
1283   E->Pack = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
1284 }
1285 
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr * E)1286 void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
1287                                               SubstNonTypeTemplateParmExpr *E) {
1288   VisitExpr(E);
1289   E->Param
1290     = cast_or_null<NonTypeTemplateParmDecl>(Reader.GetDecl(Record[Idx++]));
1291   E->NameLoc = ReadSourceLocation(Record, Idx);
1292   E->Replacement = Reader.ReadSubExpr();
1293 }
1294 
VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr * E)1295 void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
1296                                           SubstNonTypeTemplateParmPackExpr *E) {
1297   VisitExpr(E);
1298   E->Param
1299     = cast_or_null<NonTypeTemplateParmDecl>(Reader.GetDecl(Record[Idx++]));
1300   TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx);
1301   if (ArgPack.getKind() != TemplateArgument::Pack)
1302     return;
1303 
1304   E->Arguments = ArgPack.pack_begin();
1305   E->NumArguments = ArgPack.pack_size();
1306   E->NameLoc = ReadSourceLocation(Record, Idx);
1307 }
1308 
VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr * E)1309 void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1310   VisitExpr(E);
1311   E->Temporary = Reader.ReadSubExpr();
1312 }
1313 
VisitOpaqueValueExpr(OpaqueValueExpr * E)1314 void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1315   VisitExpr(E);
1316   Idx++; // skip ID
1317   E->Loc = ReadSourceLocation(Record, Idx);
1318 }
1319 
1320 //===----------------------------------------------------------------------===//
1321 // Microsoft Expressions and Statements
1322 //===----------------------------------------------------------------------===//
VisitCXXUuidofExpr(CXXUuidofExpr * E)1323 void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1324   VisitExpr(E);
1325   E->setSourceRange(ReadSourceRange(Record, Idx));
1326   if (E->isTypeOperand()) { // __uuidof(ComType)
1327     E->setTypeOperandSourceInfo(
1328         GetTypeSourceInfo(Record, Idx));
1329     return;
1330   }
1331 
1332   // __uuidof(expr)
1333   E->setExprOperand(Reader.ReadSubExpr());
1334 }
1335 
VisitSEHExceptStmt(SEHExceptStmt * S)1336 void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
1337   VisitStmt(S);
1338   S->Loc = ReadSourceLocation(Record, Idx);
1339   S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt();
1340   S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt();
1341 }
1342 
VisitSEHFinallyStmt(SEHFinallyStmt * S)1343 void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1344   VisitStmt(S);
1345   S->Loc = ReadSourceLocation(Record, Idx);
1346   S->Block = Reader.ReadSubStmt();
1347 }
1348 
VisitSEHTryStmt(SEHTryStmt * S)1349 void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
1350   VisitStmt(S);
1351   S->IsCXXTry = Record[Idx++];
1352   S->TryLoc = ReadSourceLocation(Record, Idx);
1353   S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt();
1354   S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
1355 }
1356 
1357 //===----------------------------------------------------------------------===//
1358 // CUDA Expressions and Statements
1359 //===----------------------------------------------------------------------===//
1360 
VisitCUDAKernelCallExpr(CUDAKernelCallExpr * E)1361 void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1362   VisitCallExpr(E);
1363   E->setConfig(cast<CallExpr>(Reader.ReadSubExpr()));
1364 }
1365 
1366 //===----------------------------------------------------------------------===//
1367 // OpenCL Expressions and Statements.
1368 //===----------------------------------------------------------------------===//
VisitAsTypeExpr(AsTypeExpr * E)1369 void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
1370   VisitExpr(E);
1371   E->BuiltinLoc = ReadSourceLocation(Record, Idx);
1372   E->RParenLoc = ReadSourceLocation(Record, Idx);
1373   E->SrcExpr = Reader.ReadSubExpr();
1374 }
1375 
1376 //===----------------------------------------------------------------------===//
1377 // ASTReader Implementation
1378 //===----------------------------------------------------------------------===//
1379 
ReadStmt(PerFileData & F)1380 Stmt *ASTReader::ReadStmt(PerFileData &F) {
1381   switch (ReadingKind) {
1382   case Read_Decl:
1383   case Read_Type:
1384     return ReadStmtFromStream(F);
1385   case Read_Stmt:
1386     return ReadSubStmt();
1387   }
1388 
1389   llvm_unreachable("ReadingKind not set ?");
1390   return 0;
1391 }
1392 
ReadExpr(PerFileData & F)1393 Expr *ASTReader::ReadExpr(PerFileData &F) {
1394   return cast_or_null<Expr>(ReadStmt(F));
1395 }
1396 
ReadSubExpr()1397 Expr *ASTReader::ReadSubExpr() {
1398   return cast_or_null<Expr>(ReadSubStmt());
1399 }
1400 
1401 // Within the bitstream, expressions are stored in Reverse Polish
1402 // Notation, with each of the subexpressions preceding the
1403 // expression they are stored in. Subexpressions are stored from last to first.
1404 // To evaluate expressions, we continue reading expressions and placing them on
1405 // the stack, with expressions having operands removing those operands from the
1406 // stack. Evaluation terminates when we see a STMT_STOP record, and
1407 // the single remaining expression on the stack is our result.
ReadStmtFromStream(PerFileData & F)1408 Stmt *ASTReader::ReadStmtFromStream(PerFileData &F) {
1409 
1410   ReadingKindTracker ReadingKind(Read_Stmt, *this);
1411   llvm::BitstreamCursor &Cursor = F.DeclsCursor;
1412 
1413 #ifndef NDEBUG
1414   unsigned PrevNumStmts = StmtStack.size();
1415 #endif
1416 
1417   RecordData Record;
1418   unsigned Idx;
1419   ASTStmtReader Reader(*this, F, Cursor, Record, Idx);
1420   Stmt::EmptyShell Empty;
1421 
1422   while (true) {
1423     unsigned Code = Cursor.ReadCode();
1424     if (Code == llvm::bitc::END_BLOCK) {
1425       if (Cursor.ReadBlockEnd()) {
1426         Error("error at end of block in AST file");
1427         return 0;
1428       }
1429       break;
1430     }
1431 
1432     if (Code == llvm::bitc::ENTER_SUBBLOCK) {
1433       // No known subblocks, always skip them.
1434       Cursor.ReadSubBlockID();
1435       if (Cursor.SkipBlock()) {
1436         Error("malformed block record in AST file");
1437         return 0;
1438       }
1439       continue;
1440     }
1441 
1442     if (Code == llvm::bitc::DEFINE_ABBREV) {
1443       Cursor.ReadAbbrevRecord();
1444       continue;
1445     }
1446 
1447     Stmt *S = 0;
1448     Idx = 0;
1449     Record.clear();
1450     bool Finished = false;
1451     switch ((StmtCode)Cursor.ReadRecord(Code, Record)) {
1452     case STMT_STOP:
1453       Finished = true;
1454       break;
1455 
1456     case STMT_NULL_PTR:
1457       S = 0;
1458       break;
1459 
1460     case STMT_NULL:
1461       S = new (Context) NullStmt(Empty);
1462       break;
1463 
1464     case STMT_COMPOUND:
1465       S = new (Context) CompoundStmt(Empty);
1466       break;
1467 
1468     case STMT_CASE:
1469       S = new (Context) CaseStmt(Empty);
1470       break;
1471 
1472     case STMT_DEFAULT:
1473       S = new (Context) DefaultStmt(Empty);
1474       break;
1475 
1476     case STMT_LABEL:
1477       S = new (Context) LabelStmt(Empty);
1478       break;
1479 
1480     case STMT_IF:
1481       S = new (Context) IfStmt(Empty);
1482       break;
1483 
1484     case STMT_SWITCH:
1485       S = new (Context) SwitchStmt(Empty);
1486       break;
1487 
1488     case STMT_WHILE:
1489       S = new (Context) WhileStmt(Empty);
1490       break;
1491 
1492     case STMT_DO:
1493       S = new (Context) DoStmt(Empty);
1494       break;
1495 
1496     case STMT_FOR:
1497       S = new (Context) ForStmt(Empty);
1498       break;
1499 
1500     case STMT_GOTO:
1501       S = new (Context) GotoStmt(Empty);
1502       break;
1503 
1504     case STMT_INDIRECT_GOTO:
1505       S = new (Context) IndirectGotoStmt(Empty);
1506       break;
1507 
1508     case STMT_CONTINUE:
1509       S = new (Context) ContinueStmt(Empty);
1510       break;
1511 
1512     case STMT_BREAK:
1513       S = new (Context) BreakStmt(Empty);
1514       break;
1515 
1516     case STMT_RETURN:
1517       S = new (Context) ReturnStmt(Empty);
1518       break;
1519 
1520     case STMT_DECL:
1521       S = new (Context) DeclStmt(Empty);
1522       break;
1523 
1524     case STMT_ASM:
1525       S = new (Context) AsmStmt(Empty);
1526       break;
1527 
1528     case EXPR_PREDEFINED:
1529       S = new (Context) PredefinedExpr(Empty);
1530       break;
1531 
1532     case EXPR_DECL_REF:
1533       S = DeclRefExpr::CreateEmpty(
1534         *Context,
1535         /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
1536         /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
1537         /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2],
1538         /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
1539           Record[ASTStmtReader::NumExprFields + 3] : 0);
1540       break;
1541 
1542     case EXPR_INTEGER_LITERAL:
1543       S = IntegerLiteral::Create(*Context, Empty);
1544       break;
1545 
1546     case EXPR_FLOATING_LITERAL:
1547       S = FloatingLiteral::Create(*Context, Empty);
1548       break;
1549 
1550     case EXPR_IMAGINARY_LITERAL:
1551       S = new (Context) ImaginaryLiteral(Empty);
1552       break;
1553 
1554     case EXPR_STRING_LITERAL:
1555       S = StringLiteral::CreateEmpty(*Context,
1556                                      Record[ASTStmtReader::NumExprFields + 1]);
1557       break;
1558 
1559     case EXPR_CHARACTER_LITERAL:
1560       S = new (Context) CharacterLiteral(Empty);
1561       break;
1562 
1563     case EXPR_PAREN:
1564       S = new (Context) ParenExpr(Empty);
1565       break;
1566 
1567     case EXPR_PAREN_LIST:
1568       S = new (Context) ParenListExpr(Empty);
1569       break;
1570 
1571     case EXPR_UNARY_OPERATOR:
1572       S = new (Context) UnaryOperator(Empty);
1573       break;
1574 
1575     case EXPR_OFFSETOF:
1576       S = OffsetOfExpr::CreateEmpty(*Context,
1577                                     Record[ASTStmtReader::NumExprFields],
1578                                     Record[ASTStmtReader::NumExprFields + 1]);
1579       break;
1580 
1581     case EXPR_SIZEOF_ALIGN_OF:
1582       S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
1583       break;
1584 
1585     case EXPR_ARRAY_SUBSCRIPT:
1586       S = new (Context) ArraySubscriptExpr(Empty);
1587       break;
1588 
1589     case EXPR_CALL:
1590       S = new (Context) CallExpr(*Context, Stmt::CallExprClass, Empty);
1591       break;
1592 
1593     case EXPR_MEMBER: {
1594       // We load everything here and fully initialize it at creation.
1595       // That way we can use MemberExpr::Create and don't have to duplicate its
1596       // logic with a MemberExpr::CreateEmpty.
1597 
1598       assert(Idx == 0);
1599       NestedNameSpecifierLoc QualifierLoc;
1600       if (Record[Idx++]) { // HasQualifier.
1601         QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
1602       }
1603 
1604       TemplateArgumentListInfo ArgInfo;
1605       bool HasExplicitTemplateArgs = Record[Idx++];
1606       if (HasExplicitTemplateArgs) {
1607         unsigned NumTemplateArgs = Record[Idx++];
1608         ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx));
1609         ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx));
1610         for (unsigned i = 0; i != NumTemplateArgs; ++i)
1611           ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx));
1612       }
1613 
1614       NamedDecl *FoundD = cast_or_null<NamedDecl>(GetDecl(Record[Idx++]));
1615       AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
1616       DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS);
1617 
1618       QualType T = GetType(Record[Idx++]);
1619       ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]);
1620       ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]);
1621       Expr *Base = ReadSubExpr();
1622       ValueDecl *MemberD = cast<ValueDecl>(GetDecl(Record[Idx++]));
1623       SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx);
1624       DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc);
1625       bool IsArrow = Record[Idx++];
1626 
1627       S = MemberExpr::Create(*Context, Base, IsArrow, QualifierLoc,
1628                              MemberD, FoundDecl, MemberNameInfo,
1629                              HasExplicitTemplateArgs ? &ArgInfo : 0, T, VK, OK);
1630       ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc,
1631                              MemberD->getDeclName(), Record, Idx);
1632       break;
1633     }
1634 
1635     case EXPR_BINARY_OPERATOR:
1636       S = new (Context) BinaryOperator(Empty);
1637       break;
1638 
1639     case EXPR_COMPOUND_ASSIGN_OPERATOR:
1640       S = new (Context) CompoundAssignOperator(Empty);
1641       break;
1642 
1643     case EXPR_CONDITIONAL_OPERATOR:
1644       S = new (Context) ConditionalOperator(Empty);
1645       break;
1646 
1647     case EXPR_BINARY_CONDITIONAL_OPERATOR:
1648       S = new (Context) BinaryConditionalOperator(Empty);
1649       break;
1650 
1651     case EXPR_IMPLICIT_CAST:
1652       S = ImplicitCastExpr::CreateEmpty(*Context,
1653                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
1654       break;
1655 
1656     case EXPR_CSTYLE_CAST:
1657       S = CStyleCastExpr::CreateEmpty(*Context,
1658                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
1659       break;
1660 
1661     case EXPR_COMPOUND_LITERAL:
1662       S = new (Context) CompoundLiteralExpr(Empty);
1663       break;
1664 
1665     case EXPR_EXT_VECTOR_ELEMENT:
1666       S = new (Context) ExtVectorElementExpr(Empty);
1667       break;
1668 
1669     case EXPR_INIT_LIST:
1670       S = new (Context) InitListExpr(*getContext(), Empty);
1671       break;
1672 
1673     case EXPR_DESIGNATED_INIT:
1674       S = DesignatedInitExpr::CreateEmpty(*Context,
1675                                      Record[ASTStmtReader::NumExprFields] - 1);
1676 
1677       break;
1678 
1679     case EXPR_IMPLICIT_VALUE_INIT:
1680       S = new (Context) ImplicitValueInitExpr(Empty);
1681       break;
1682 
1683     case EXPR_VA_ARG:
1684       S = new (Context) VAArgExpr(Empty);
1685       break;
1686 
1687     case EXPR_ADDR_LABEL:
1688       S = new (Context) AddrLabelExpr(Empty);
1689       break;
1690 
1691     case EXPR_STMT:
1692       S = new (Context) StmtExpr(Empty);
1693       break;
1694 
1695     case EXPR_CHOOSE:
1696       S = new (Context) ChooseExpr(Empty);
1697       break;
1698 
1699     case EXPR_GNU_NULL:
1700       S = new (Context) GNUNullExpr(Empty);
1701       break;
1702 
1703     case EXPR_SHUFFLE_VECTOR:
1704       S = new (Context) ShuffleVectorExpr(Empty);
1705       break;
1706 
1707     case EXPR_BLOCK:
1708       S = new (Context) BlockExpr(Empty);
1709       break;
1710 
1711     case EXPR_BLOCK_DECL_REF:
1712       S = new (Context) BlockDeclRefExpr(Empty);
1713       break;
1714 
1715     case EXPR_GENERIC_SELECTION:
1716       S = new (Context) GenericSelectionExpr(Empty);
1717       break;
1718 
1719     case EXPR_OBJC_STRING_LITERAL:
1720       S = new (Context) ObjCStringLiteral(Empty);
1721       break;
1722     case EXPR_OBJC_ENCODE:
1723       S = new (Context) ObjCEncodeExpr(Empty);
1724       break;
1725     case EXPR_OBJC_SELECTOR_EXPR:
1726       S = new (Context) ObjCSelectorExpr(Empty);
1727       break;
1728     case EXPR_OBJC_PROTOCOL_EXPR:
1729       S = new (Context) ObjCProtocolExpr(Empty);
1730       break;
1731     case EXPR_OBJC_IVAR_REF_EXPR:
1732       S = new (Context) ObjCIvarRefExpr(Empty);
1733       break;
1734     case EXPR_OBJC_PROPERTY_REF_EXPR:
1735       S = new (Context) ObjCPropertyRefExpr(Empty);
1736       break;
1737     case EXPR_OBJC_KVC_REF_EXPR:
1738       llvm_unreachable("mismatching AST file");
1739       break;
1740     case EXPR_OBJC_MESSAGE_EXPR:
1741       S = ObjCMessageExpr::CreateEmpty(*Context,
1742                                      Record[ASTStmtReader::NumExprFields]);
1743       break;
1744     case EXPR_OBJC_ISA:
1745       S = new (Context) ObjCIsaExpr(Empty);
1746       break;
1747     case EXPR_OBJC_INDIRECT_COPY_RESTORE:
1748       S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
1749       break;
1750     case EXPR_OBJC_BRIDGED_CAST:
1751       S = new (Context) ObjCBridgedCastExpr(Empty);
1752       break;
1753     case STMT_OBJC_FOR_COLLECTION:
1754       S = new (Context) ObjCForCollectionStmt(Empty);
1755       break;
1756     case STMT_OBJC_CATCH:
1757       S = new (Context) ObjCAtCatchStmt(Empty);
1758       break;
1759     case STMT_OBJC_FINALLY:
1760       S = new (Context) ObjCAtFinallyStmt(Empty);
1761       break;
1762     case STMT_OBJC_AT_TRY:
1763       S = ObjCAtTryStmt::CreateEmpty(*Context,
1764                                      Record[ASTStmtReader::NumStmtFields],
1765                                      Record[ASTStmtReader::NumStmtFields + 1]);
1766       break;
1767     case STMT_OBJC_AT_SYNCHRONIZED:
1768       S = new (Context) ObjCAtSynchronizedStmt(Empty);
1769       break;
1770     case STMT_OBJC_AT_THROW:
1771       S = new (Context) ObjCAtThrowStmt(Empty);
1772       break;
1773     case STMT_OBJC_AUTORELEASE_POOL:
1774       S = new (Context) ObjCAutoreleasePoolStmt(Empty);
1775       break;
1776     case STMT_SEH_EXCEPT:
1777       S = new (Context) SEHExceptStmt(Empty);
1778       break;
1779     case STMT_SEH_FINALLY:
1780       S = new (Context) SEHFinallyStmt(Empty);
1781       break;
1782     case STMT_SEH_TRY:
1783       S = new (Context) SEHTryStmt(Empty);
1784       break;
1785     case STMT_CXX_CATCH:
1786       S = new (Context) CXXCatchStmt(Empty);
1787       break;
1788 
1789     case STMT_CXX_TRY:
1790       S = CXXTryStmt::Create(*Context, Empty,
1791              /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]);
1792       break;
1793 
1794     case STMT_CXX_FOR_RANGE:
1795       S = new (Context) CXXForRangeStmt(Empty);
1796       break;
1797 
1798     case EXPR_CXX_OPERATOR_CALL:
1799       S = new (Context) CXXOperatorCallExpr(*Context, Empty);
1800       break;
1801 
1802     case EXPR_CXX_MEMBER_CALL:
1803       S = new (Context) CXXMemberCallExpr(*Context, Empty);
1804       break;
1805 
1806     case EXPR_CXX_CONSTRUCT:
1807       S = new (Context) CXXConstructExpr(Empty);
1808       break;
1809 
1810     case EXPR_CXX_TEMPORARY_OBJECT:
1811       S = new (Context) CXXTemporaryObjectExpr(Empty);
1812       break;
1813 
1814     case EXPR_CXX_STATIC_CAST:
1815       S = CXXStaticCastExpr::CreateEmpty(*Context,
1816                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
1817       break;
1818 
1819     case EXPR_CXX_DYNAMIC_CAST:
1820       S = CXXDynamicCastExpr::CreateEmpty(*Context,
1821                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
1822       break;
1823 
1824     case EXPR_CXX_REINTERPRET_CAST:
1825       S = CXXReinterpretCastExpr::CreateEmpty(*Context,
1826                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
1827       break;
1828 
1829     case EXPR_CXX_CONST_CAST:
1830       S = CXXConstCastExpr::CreateEmpty(*Context);
1831       break;
1832 
1833     case EXPR_CXX_FUNCTIONAL_CAST:
1834       S = CXXFunctionalCastExpr::CreateEmpty(*Context,
1835                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
1836       break;
1837 
1838     case EXPR_CXX_BOOL_LITERAL:
1839       S = new (Context) CXXBoolLiteralExpr(Empty);
1840       break;
1841 
1842     case EXPR_CXX_NULL_PTR_LITERAL:
1843       S = new (Context) CXXNullPtrLiteralExpr(Empty);
1844       break;
1845     case EXPR_CXX_TYPEID_EXPR:
1846       S = new (Context) CXXTypeidExpr(Empty, true);
1847       break;
1848     case EXPR_CXX_TYPEID_TYPE:
1849       S = new (Context) CXXTypeidExpr(Empty, false);
1850       break;
1851     case EXPR_CXX_UUIDOF_EXPR:
1852       S = new (Context) CXXUuidofExpr(Empty, true);
1853       break;
1854     case EXPR_CXX_UUIDOF_TYPE:
1855       S = new (Context) CXXUuidofExpr(Empty, false);
1856       break;
1857     case EXPR_CXX_THIS:
1858       S = new (Context) CXXThisExpr(Empty);
1859       break;
1860     case EXPR_CXX_THROW:
1861       S = new (Context) CXXThrowExpr(Empty);
1862       break;
1863     case EXPR_CXX_DEFAULT_ARG: {
1864       bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields];
1865       if (HasOtherExprStored) {
1866         Expr *SubExpr = ReadSubExpr();
1867         S = CXXDefaultArgExpr::Create(*Context, SourceLocation(), 0, SubExpr);
1868       } else
1869         S = new (Context) CXXDefaultArgExpr(Empty);
1870       break;
1871     }
1872     case EXPR_CXX_BIND_TEMPORARY:
1873       S = new (Context) CXXBindTemporaryExpr(Empty);
1874       break;
1875 
1876     case EXPR_CXX_SCALAR_VALUE_INIT:
1877       S = new (Context) CXXScalarValueInitExpr(Empty);
1878       break;
1879     case EXPR_CXX_NEW:
1880       S = new (Context) CXXNewExpr(Empty);
1881       break;
1882     case EXPR_CXX_DELETE:
1883       S = new (Context) CXXDeleteExpr(Empty);
1884       break;
1885     case EXPR_CXX_PSEUDO_DESTRUCTOR:
1886       S = new (Context) CXXPseudoDestructorExpr(Empty);
1887       break;
1888 
1889     case EXPR_EXPR_WITH_CLEANUPS:
1890       S = new (Context) ExprWithCleanups(Empty);
1891       break;
1892 
1893     case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
1894       S = CXXDependentScopeMemberExpr::CreateEmpty(*Context,
1895           /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1896                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1897                                    ? Record[ASTStmtReader::NumExprFields + 1]
1898                                    : 0);
1899       break;
1900 
1901     case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
1902       S = DependentScopeDeclRefExpr::CreateEmpty(*Context,
1903           /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1904                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1905                                    ? Record[ASTStmtReader::NumExprFields + 1]
1906                                    : 0);
1907       break;
1908 
1909     case EXPR_CXX_UNRESOLVED_CONSTRUCT:
1910       S = CXXUnresolvedConstructExpr::CreateEmpty(*Context,
1911                               /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
1912       break;
1913 
1914     case EXPR_CXX_UNRESOLVED_MEMBER:
1915       S = UnresolvedMemberExpr::CreateEmpty(*Context,
1916           /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1917                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1918                                    ? Record[ASTStmtReader::NumExprFields + 1]
1919                                    : 0);
1920       break;
1921 
1922     case EXPR_CXX_UNRESOLVED_LOOKUP:
1923       S = UnresolvedLookupExpr::CreateEmpty(*Context,
1924           /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields],
1925                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
1926                                    ? Record[ASTStmtReader::NumExprFields + 1]
1927                                    : 0);
1928       break;
1929 
1930     case EXPR_CXX_UNARY_TYPE_TRAIT:
1931       S = new (Context) UnaryTypeTraitExpr(Empty);
1932       break;
1933 
1934     case EXPR_BINARY_TYPE_TRAIT:
1935       S = new (Context) BinaryTypeTraitExpr(Empty);
1936       break;
1937 
1938     case EXPR_ARRAY_TYPE_TRAIT:
1939       S = new (Context) ArrayTypeTraitExpr(Empty);
1940       break;
1941 
1942     case EXPR_CXX_EXPRESSION_TRAIT:
1943       S = new (Context) ExpressionTraitExpr(Empty);
1944       break;
1945 
1946     case EXPR_CXX_NOEXCEPT:
1947       S = new (Context) CXXNoexceptExpr(Empty);
1948       break;
1949 
1950     case EXPR_PACK_EXPANSION:
1951       S = new (Context) PackExpansionExpr(Empty);
1952       break;
1953 
1954     case EXPR_SIZEOF_PACK:
1955       S = new (Context) SizeOfPackExpr(Empty);
1956       break;
1957 
1958     case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
1959       S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
1960       break;
1961 
1962     case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
1963       S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
1964       break;
1965 
1966     case EXPR_MATERIALIZE_TEMPORARY:
1967       S = new (Context) MaterializeTemporaryExpr(Empty);
1968       break;
1969 
1970     case EXPR_OPAQUE_VALUE: {
1971       unsigned key = Record[ASTStmtReader::NumExprFields];
1972       OpaqueValueExpr *&expr = OpaqueValueExprs[key];
1973 
1974       // If we already have an entry for this opaque value expression,
1975       // don't bother reading it again.
1976       if (expr) {
1977         StmtStack.push_back(expr);
1978         continue;
1979       }
1980 
1981       S = expr = new (Context) OpaqueValueExpr(Empty);
1982       break;
1983     }
1984 
1985     case EXPR_CUDA_KERNEL_CALL:
1986       S = new (Context) CUDAKernelCallExpr(*Context, Empty);
1987       break;
1988 
1989     case EXPR_ASTYPE:
1990       S = new (Context) AsTypeExpr(Empty);
1991       break;
1992     }
1993 
1994     // We hit a STMT_STOP, so we're done with this expression.
1995     if (Finished)
1996       break;
1997 
1998     ++NumStatementsRead;
1999 
2000     if (S)
2001       Reader.Visit(S);
2002 
2003     assert(Idx == Record.size() && "Invalid deserialization of statement");
2004     StmtStack.push_back(S);
2005   }
2006 
2007 #ifndef NDEBUG
2008   assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!");
2009   assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
2010 #endif
2011 
2012   return StmtStack.pop_back_val();
2013 }
2014