clang API Documentation

ASTReaderStmt.cpp
Go to the documentation of this file.
00001 //===--- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Statement/expression deserialization.  This implements the
00011 // ASTReader::ReadStmt method.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "clang/Serialization/ASTReader.h"
00016 #include "clang/AST/ASTContext.h"
00017 #include "clang/AST/DeclCXX.h"
00018 #include "clang/AST/DeclTemplate.h"
00019 #include "clang/AST/StmtVisitor.h"
00020 #include "clang/Lex/Token.h"
00021 #include "llvm/ADT/SmallString.h"
00022 using namespace clang;
00023 using namespace clang::serialization;
00024 
00025 namespace clang {
00026 
00027   class ASTStmtReader : public StmtVisitor<ASTStmtReader> {
00028     friend class OMPClauseReader;
00029     typedef ASTReader::RecordData RecordData;
00030     
00031     ASTReader &Reader;
00032     ModuleFile &F;
00033     llvm::BitstreamCursor &DeclsCursor;
00034     const ASTReader::RecordData &Record;
00035     unsigned &Idx;
00036 
00037     Token ReadToken(const RecordData &R, unsigned &I) {
00038       return Reader.ReadToken(F, R, I);
00039     }
00040 
00041     SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
00042       return Reader.ReadSourceLocation(F, R, I);
00043     }
00044 
00045     SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
00046       return Reader.ReadSourceRange(F, R, I);
00047     }
00048 
00049     std::string ReadString(const RecordData &R, unsigned &I) {
00050       return Reader.ReadString(R, I);
00051     }
00052         
00053     TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
00054       return Reader.GetTypeSourceInfo(F, R, I);
00055     }
00056     
00057     serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
00058       return Reader.ReadDeclID(F, R, I);
00059     }
00060     
00061     Decl *ReadDecl(const RecordData &R, unsigned &I) {
00062       return Reader.ReadDecl(F, R, I);
00063     }
00064     
00065     template<typename T>
00066     T *ReadDeclAs(const RecordData &R, unsigned &I) {
00067       return Reader.ReadDeclAs<T>(F, R, I);
00068     }
00069 
00070     void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
00071                                 const ASTReader::RecordData &R, unsigned &I) {
00072       Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
00073     }
00074     
00075     void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
00076                                 const ASTReader::RecordData &R, unsigned &I) {
00077       Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
00078     }
00079 
00080   public:
00081     ASTStmtReader(ASTReader &Reader, ModuleFile &F,
00082                   llvm::BitstreamCursor &Cursor,
00083                   const ASTReader::RecordData &Record, unsigned &Idx)
00084       : Reader(Reader), F(F), DeclsCursor(Cursor), Record(Record), Idx(Idx) { }
00085 
00086     /// \brief The number of record fields required for the Stmt class
00087     /// itself.
00088     static const unsigned NumStmtFields = 0;
00089 
00090     /// \brief The number of record fields required for the Expr class
00091     /// itself.
00092     static const unsigned NumExprFields = NumStmtFields + 7;
00093 
00094     /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
00095     void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
00096                                    unsigned NumTemplateArgs);
00097     /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
00098     void ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &ArgList,
00099                                           unsigned NumTemplateArgs);
00100 
00101     void VisitStmt(Stmt *S);
00102 #define STMT(Type, Base) \
00103     void Visit##Type(Type *);
00104 #include "clang/AST/StmtNodes.inc"
00105   };
00106 }
00107 
00108 void ASTStmtReader::
00109 ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
00110                           unsigned NumTemplateArgs) {
00111   SourceLocation TemplateKWLoc = ReadSourceLocation(Record, Idx);
00112   TemplateArgumentListInfo ArgInfo;
00113   ArgInfo.setLAngleLoc(ReadSourceLocation(Record, Idx));
00114   ArgInfo.setRAngleLoc(ReadSourceLocation(Record, Idx));
00115   for (unsigned i = 0; i != NumTemplateArgs; ++i)
00116     ArgInfo.addArgument(
00117         Reader.ReadTemplateArgumentLoc(F, Record, Idx));
00118   Args.initializeFrom(TemplateKWLoc, ArgInfo);
00119 }
00120 
00121 void ASTStmtReader::VisitStmt(Stmt *S) {
00122   assert(Idx == NumStmtFields && "Incorrect statement field count");
00123 }
00124 
00125 void ASTStmtReader::VisitNullStmt(NullStmt *S) {
00126   VisitStmt(S);
00127   S->setSemiLoc(ReadSourceLocation(Record, Idx));
00128   S->HasLeadingEmptyMacro = Record[Idx++];
00129 }
00130 
00131 void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
00132   VisitStmt(S);
00133   SmallVector<Stmt *, 16> Stmts;
00134   unsigned NumStmts = Record[Idx++];
00135   while (NumStmts--)
00136     Stmts.push_back(Reader.ReadSubStmt());
00137   S->setStmts(Reader.getContext(), Stmts.data(), Stmts.size());
00138   S->LBraceLoc = ReadSourceLocation(Record, Idx);
00139   S->RBraceLoc = ReadSourceLocation(Record, Idx);
00140 }
00141 
00142 void ASTStmtReader::VisitSwitchCase(SwitchCase *S) {
00143   VisitStmt(S);
00144   Reader.RecordSwitchCaseID(S, Record[Idx++]);
00145   S->setKeywordLoc(ReadSourceLocation(Record, Idx));
00146   S->setColonLoc(ReadSourceLocation(Record, Idx));
00147 }
00148 
00149 void ASTStmtReader::VisitCaseStmt(CaseStmt *S) {
00150   VisitSwitchCase(S);
00151   S->setLHS(Reader.ReadSubExpr());
00152   S->setRHS(Reader.ReadSubExpr());
00153   S->setSubStmt(Reader.ReadSubStmt());
00154   S->setEllipsisLoc(ReadSourceLocation(Record, Idx));
00155 }
00156 
00157 void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) {
00158   VisitSwitchCase(S);
00159   S->setSubStmt(Reader.ReadSubStmt());
00160 }
00161 
00162 void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
00163   VisitStmt(S);
00164   LabelDecl *LD = ReadDeclAs<LabelDecl>(Record, Idx);
00165   LD->setStmt(S);
00166   S->setDecl(LD);
00167   S->setSubStmt(Reader.ReadSubStmt());
00168   S->setIdentLoc(ReadSourceLocation(Record, Idx));
00169 }
00170 
00171 void ASTStmtReader::VisitAttributedStmt(AttributedStmt *S) {
00172   VisitStmt(S);
00173   uint64_t NumAttrs = Record[Idx++];
00174   AttrVec Attrs;
00175   Reader.ReadAttributes(F, Attrs, Record, Idx);
00176   (void)NumAttrs;
00177   assert(NumAttrs == S->NumAttrs);
00178   assert(NumAttrs == Attrs.size());
00179   std::copy(Attrs.begin(), Attrs.end(), S->getAttrArrayPtr());
00180   S->SubStmt = Reader.ReadSubStmt();
00181   S->AttrLoc = ReadSourceLocation(Record, Idx);
00182 }
00183 
00184 void ASTStmtReader::VisitIfStmt(IfStmt *S) {
00185   VisitStmt(S);
00186   S->setConditionVariable(Reader.getContext(),
00187                           ReadDeclAs<VarDecl>(Record, Idx));
00188   S->setCond(Reader.ReadSubExpr());
00189   S->setThen(Reader.ReadSubStmt());
00190   S->setElse(Reader.ReadSubStmt());
00191   S->setIfLoc(ReadSourceLocation(Record, Idx));
00192   S->setElseLoc(ReadSourceLocation(Record, Idx));
00193 }
00194 
00195 void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) {
00196   VisitStmt(S);
00197   S->setConditionVariable(Reader.getContext(),
00198                           ReadDeclAs<VarDecl>(Record, Idx));
00199   S->setCond(Reader.ReadSubExpr());
00200   S->setBody(Reader.ReadSubStmt());
00201   S->setSwitchLoc(ReadSourceLocation(Record, Idx));
00202   if (Record[Idx++])
00203     S->setAllEnumCasesCovered();
00204 
00205   SwitchCase *PrevSC = nullptr;
00206   for (unsigned N = Record.size(); Idx != N; ++Idx) {
00207     SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]);
00208     if (PrevSC)
00209       PrevSC->setNextSwitchCase(SC);
00210     else
00211       S->setSwitchCaseList(SC);
00212 
00213     PrevSC = SC;
00214   }
00215 }
00216 
00217 void ASTStmtReader::VisitWhileStmt(WhileStmt *S) {
00218   VisitStmt(S);
00219   S->setConditionVariable(Reader.getContext(),
00220                           ReadDeclAs<VarDecl>(Record, Idx));
00221 
00222   S->setCond(Reader.ReadSubExpr());
00223   S->setBody(Reader.ReadSubStmt());
00224   S->setWhileLoc(ReadSourceLocation(Record, Idx));
00225 }
00226 
00227 void ASTStmtReader::VisitDoStmt(DoStmt *S) {
00228   VisitStmt(S);
00229   S->setCond(Reader.ReadSubExpr());
00230   S->setBody(Reader.ReadSubStmt());
00231   S->setDoLoc(ReadSourceLocation(Record, Idx));
00232   S->setWhileLoc(ReadSourceLocation(Record, Idx));
00233   S->setRParenLoc(ReadSourceLocation(Record, Idx));
00234 }
00235 
00236 void ASTStmtReader::VisitForStmt(ForStmt *S) {
00237   VisitStmt(S);
00238   S->setInit(Reader.ReadSubStmt());
00239   S->setCond(Reader.ReadSubExpr());
00240   S->setConditionVariable(Reader.getContext(),
00241                           ReadDeclAs<VarDecl>(Record, Idx));
00242   S->setInc(Reader.ReadSubExpr());
00243   S->setBody(Reader.ReadSubStmt());
00244   S->setForLoc(ReadSourceLocation(Record, Idx));
00245   S->setLParenLoc(ReadSourceLocation(Record, Idx));
00246   S->setRParenLoc(ReadSourceLocation(Record, Idx));
00247 }
00248 
00249 void ASTStmtReader::VisitGotoStmt(GotoStmt *S) {
00250   VisitStmt(S);
00251   S->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
00252   S->setGotoLoc(ReadSourceLocation(Record, Idx));
00253   S->setLabelLoc(ReadSourceLocation(Record, Idx));
00254 }
00255 
00256 void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
00257   VisitStmt(S);
00258   S->setGotoLoc(ReadSourceLocation(Record, Idx));
00259   S->setStarLoc(ReadSourceLocation(Record, Idx));
00260   S->setTarget(Reader.ReadSubExpr());
00261 }
00262 
00263 void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) {
00264   VisitStmt(S);
00265   S->setContinueLoc(ReadSourceLocation(Record, Idx));
00266 }
00267 
00268 void ASTStmtReader::VisitBreakStmt(BreakStmt *S) {
00269   VisitStmt(S);
00270   S->setBreakLoc(ReadSourceLocation(Record, Idx));
00271 }
00272 
00273 void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) {
00274   VisitStmt(S);
00275   S->setRetValue(Reader.ReadSubExpr());
00276   S->setReturnLoc(ReadSourceLocation(Record, Idx));
00277   S->setNRVOCandidate(ReadDeclAs<VarDecl>(Record, Idx));
00278 }
00279 
00280 void ASTStmtReader::VisitDeclStmt(DeclStmt *S) {
00281   VisitStmt(S);
00282   S->setStartLoc(ReadSourceLocation(Record, Idx));
00283   S->setEndLoc(ReadSourceLocation(Record, Idx));
00284 
00285   if (Idx + 1 == Record.size()) {
00286     // Single declaration
00287     S->setDeclGroup(DeclGroupRef(ReadDecl(Record, Idx)));
00288   } else {
00289     SmallVector<Decl *, 16> Decls;
00290     Decls.reserve(Record.size() - Idx);    
00291     for (unsigned N = Record.size(); Idx != N; )
00292       Decls.push_back(ReadDecl(Record, Idx));
00293     S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(),
00294                                                    Decls.data(),
00295                                                    Decls.size())));
00296   }
00297 }
00298 
00299 void ASTStmtReader::VisitAsmStmt(AsmStmt *S) {
00300   VisitStmt(S);
00301   S->NumOutputs = Record[Idx++];
00302   S->NumInputs = Record[Idx++];
00303   S->NumClobbers = Record[Idx++];
00304   S->setAsmLoc(ReadSourceLocation(Record, Idx));
00305   S->setVolatile(Record[Idx++]);
00306   S->setSimple(Record[Idx++]);
00307 }
00308 
00309 void ASTStmtReader::VisitGCCAsmStmt(GCCAsmStmt *S) {
00310   VisitAsmStmt(S);
00311   S->setRParenLoc(ReadSourceLocation(Record, Idx));
00312   S->setAsmString(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
00313 
00314   unsigned NumOutputs = S->getNumOutputs();
00315   unsigned NumInputs = S->getNumInputs();
00316   unsigned NumClobbers = S->getNumClobbers();
00317 
00318   // Outputs and inputs
00319   SmallVector<IdentifierInfo *, 16> Names;
00320   SmallVector<StringLiteral*, 16> Constraints;
00321   SmallVector<Stmt*, 16> Exprs;
00322   for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
00323     Names.push_back(Reader.GetIdentifierInfo(F, Record, Idx));
00324     Constraints.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
00325     Exprs.push_back(Reader.ReadSubStmt());
00326   }
00327 
00328   // Constraints
00329   SmallVector<StringLiteral*, 16> Clobbers;
00330   for (unsigned I = 0; I != NumClobbers; ++I)
00331     Clobbers.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt()));
00332 
00333   S->setOutputsAndInputsAndClobbers(Reader.getContext(),
00334                                     Names.data(), Constraints.data(), 
00335                                     Exprs.data(), NumOutputs, NumInputs, 
00336                                     Clobbers.data(), NumClobbers);
00337 }
00338 
00339 void ASTStmtReader::VisitMSAsmStmt(MSAsmStmt *S) {
00340   VisitAsmStmt(S);
00341   S->LBraceLoc = ReadSourceLocation(Record, Idx);
00342   S->EndLoc = ReadSourceLocation(Record, Idx);
00343   S->NumAsmToks = Record[Idx++];
00344   std::string AsmStr = ReadString(Record, Idx);
00345 
00346   // Read the tokens.
00347   SmallVector<Token, 16> AsmToks;
00348   AsmToks.reserve(S->NumAsmToks);
00349   for (unsigned i = 0, e = S->NumAsmToks; i != e; ++i) {
00350     AsmToks.push_back(ReadToken(Record, Idx));
00351   }
00352 
00353   // The calls to reserve() for the FooData vectors are mandatory to
00354   // prevent dead StringRefs in the Foo vectors.
00355 
00356   // Read the clobbers.
00357   SmallVector<std::string, 16> ClobbersData;
00358   SmallVector<StringRef, 16> Clobbers;
00359   ClobbersData.reserve(S->NumClobbers);
00360   Clobbers.reserve(S->NumClobbers);
00361   for (unsigned i = 0, e = S->NumClobbers; i != e; ++i) {
00362     ClobbersData.push_back(ReadString(Record, Idx));
00363     Clobbers.push_back(ClobbersData.back());
00364   }
00365 
00366   // Read the operands.
00367   unsigned NumOperands = S->NumOutputs + S->NumInputs;
00368   SmallVector<Expr*, 16> Exprs;
00369   SmallVector<std::string, 16> ConstraintsData;
00370   SmallVector<StringRef, 16> Constraints;
00371   Exprs.reserve(NumOperands);
00372   ConstraintsData.reserve(NumOperands);
00373   Constraints.reserve(NumOperands);
00374   for (unsigned i = 0; i != NumOperands; ++i) {
00375     Exprs.push_back(cast<Expr>(Reader.ReadSubStmt()));
00376     ConstraintsData.push_back(ReadString(Record, Idx));
00377     Constraints.push_back(ConstraintsData.back());
00378   }
00379 
00380   S->initialize(Reader.getContext(), AsmStr, AsmToks,
00381                 Constraints, Exprs, Clobbers);
00382 }
00383 
00384 void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) {
00385   VisitStmt(S);
00386   ++Idx;
00387   S->setCapturedDecl(ReadDeclAs<CapturedDecl>(Record, Idx));
00388   S->setCapturedRegionKind(static_cast<CapturedRegionKind>(Record[Idx++]));
00389   S->setCapturedRecordDecl(ReadDeclAs<RecordDecl>(Record, Idx));
00390 
00391   // Capture inits
00392   for (CapturedStmt::capture_init_iterator I = S->capture_init_begin(),
00393                                            E = S->capture_init_end();
00394        I != E; ++I)
00395     *I = Reader.ReadSubExpr();
00396 
00397   // Body
00398   S->setCapturedStmt(Reader.ReadSubStmt());
00399   S->getCapturedDecl()->setBody(S->getCapturedStmt());
00400 
00401   // Captures
00402   for (auto &I : S->captures()) {
00403     I.VarAndKind.setPointer(ReadDeclAs<VarDecl>(Record, Idx));
00404     I.VarAndKind
00405         .setInt(static_cast<CapturedStmt::VariableCaptureKind>(Record[Idx++]));
00406     I.Loc = ReadSourceLocation(Record, Idx);
00407   }
00408 }
00409 
00410 void ASTStmtReader::VisitExpr(Expr *E) {
00411   VisitStmt(E);
00412   E->setType(Reader.readType(F, Record, Idx));
00413   E->setTypeDependent(Record[Idx++]);
00414   E->setValueDependent(Record[Idx++]);
00415   E->setInstantiationDependent(Record[Idx++]);
00416   E->ExprBits.ContainsUnexpandedParameterPack = Record[Idx++];
00417   E->setValueKind(static_cast<ExprValueKind>(Record[Idx++]));
00418   E->setObjectKind(static_cast<ExprObjectKind>(Record[Idx++]));
00419   assert(Idx == NumExprFields && "Incorrect expression field count");
00420 }
00421 
00422 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
00423   VisitExpr(E);
00424   E->setLocation(ReadSourceLocation(Record, Idx));
00425   E->Type = (PredefinedExpr::IdentType)Record[Idx++];
00426   E->FnName = cast_or_null<StringLiteral>(Reader.ReadSubExpr());
00427 }
00428 
00429 void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
00430   VisitExpr(E);
00431 
00432   E->DeclRefExprBits.HasQualifier = Record[Idx++];
00433   E->DeclRefExprBits.HasFoundDecl = Record[Idx++];
00434   E->DeclRefExprBits.HasTemplateKWAndArgsInfo = Record[Idx++];
00435   E->DeclRefExprBits.HadMultipleCandidates = Record[Idx++];
00436   E->DeclRefExprBits.RefersToEnclosingLocal = Record[Idx++];
00437   unsigned NumTemplateArgs = 0;
00438   if (E->hasTemplateKWAndArgsInfo())
00439     NumTemplateArgs = Record[Idx++];
00440 
00441   if (E->hasQualifier())
00442     E->getInternalQualifierLoc()
00443       = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
00444 
00445   if (E->hasFoundDecl())
00446     E->getInternalFoundDecl() = ReadDeclAs<NamedDecl>(Record, Idx);
00447 
00448   if (E->hasTemplateKWAndArgsInfo())
00449     ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
00450                               NumTemplateArgs);
00451 
00452   E->setDecl(ReadDeclAs<ValueDecl>(Record, Idx));
00453   E->setLocation(ReadSourceLocation(Record, Idx));
00454   ReadDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record, Idx);
00455 }
00456 
00457 void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
00458   VisitExpr(E);
00459   E->setLocation(ReadSourceLocation(Record, Idx));
00460   E->setValue(Reader.getContext(), Reader.ReadAPInt(Record, Idx));
00461 }
00462 
00463 void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
00464   VisitExpr(E);
00465   E->setRawSemantics(static_cast<Stmt::APFloatSemantics>(Record[Idx++]));
00466   E->setExact(Record[Idx++]);
00467   E->setValue(Reader.getContext(),
00468               Reader.ReadAPFloat(Record, E->getSemantics(), Idx));
00469   E->setLocation(ReadSourceLocation(Record, Idx));
00470 }
00471 
00472 void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
00473   VisitExpr(E);
00474   E->setSubExpr(Reader.ReadSubExpr());
00475 }
00476 
00477 void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
00478   VisitExpr(E);
00479   unsigned Len = Record[Idx++];
00480   assert(Record[Idx] == E->getNumConcatenated() &&
00481          "Wrong number of concatenated tokens!");
00482   ++Idx;
00483   StringLiteral::StringKind kind =
00484         static_cast<StringLiteral::StringKind>(Record[Idx++]);
00485   bool isPascal = Record[Idx++];
00486 
00487   // Read string data
00488   SmallString<16> Str(&Record[Idx], &Record[Idx] + Len);
00489   E->setString(Reader.getContext(), Str.str(), kind, isPascal);
00490   Idx += Len;
00491 
00492   // Read source locations
00493   for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
00494     E->setStrTokenLoc(I, ReadSourceLocation(Record, Idx));
00495 }
00496 
00497 void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
00498   VisitExpr(E);
00499   E->setValue(Record[Idx++]);
00500   E->setLocation(ReadSourceLocation(Record, Idx));
00501   E->setKind(static_cast<CharacterLiteral::CharacterKind>(Record[Idx++]));
00502 }
00503 
00504 void ASTStmtReader::VisitParenExpr(ParenExpr *E) {
00505   VisitExpr(E);
00506   E->setLParen(ReadSourceLocation(Record, Idx));
00507   E->setRParen(ReadSourceLocation(Record, Idx));
00508   E->setSubExpr(Reader.ReadSubExpr());
00509 }
00510 
00511 void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
00512   VisitExpr(E);
00513   unsigned NumExprs = Record[Idx++];
00514   E->Exprs = new (Reader.getContext()) Stmt*[NumExprs];
00515   for (unsigned i = 0; i != NumExprs; ++i)
00516     E->Exprs[i] = Reader.ReadSubStmt();
00517   E->NumExprs = NumExprs;
00518   E->LParenLoc = ReadSourceLocation(Record, Idx);
00519   E->RParenLoc = ReadSourceLocation(Record, Idx);
00520 }
00521 
00522 void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) {
00523   VisitExpr(E);
00524   E->setSubExpr(Reader.ReadSubExpr());
00525   E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
00526   E->setOperatorLoc(ReadSourceLocation(Record, Idx));
00527 }
00528 
00529 void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
00530   typedef OffsetOfExpr::OffsetOfNode Node;
00531   VisitExpr(E);
00532   assert(E->getNumComponents() == Record[Idx]);
00533   ++Idx;
00534   assert(E->getNumExpressions() == Record[Idx]);
00535   ++Idx;
00536   E->setOperatorLoc(ReadSourceLocation(Record, Idx));
00537   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00538   E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
00539   for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
00540     Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]);
00541     SourceLocation Start = ReadSourceLocation(Record, Idx);
00542     SourceLocation End = ReadSourceLocation(Record, Idx);
00543     switch (Kind) {
00544     case Node::Array:
00545       E->setComponent(I, Node(Start, Record[Idx++], End));
00546       break;
00547         
00548     case Node::Field:
00549       E->setComponent(I, Node(Start, ReadDeclAs<FieldDecl>(Record, Idx), End));
00550       break;
00551 
00552     case Node::Identifier:
00553       E->setComponent(I, 
00554                       Node(Start, 
00555                            Reader.GetIdentifierInfo(F, Record, Idx),
00556                            End));
00557       break;
00558         
00559     case Node::Base: {
00560       CXXBaseSpecifier *Base = new (Reader.getContext()) CXXBaseSpecifier();
00561       *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
00562       E->setComponent(I, Node(Base));
00563       break;
00564     }
00565     }
00566   }
00567   
00568   for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
00569     E->setIndexExpr(I, Reader.ReadSubExpr());
00570 }
00571 
00572 void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
00573   VisitExpr(E);
00574   E->setKind(static_cast<UnaryExprOrTypeTrait>(Record[Idx++]));
00575   if (Record[Idx] == 0) {
00576     E->setArgument(Reader.ReadSubExpr());
00577     ++Idx;
00578   } else {
00579     E->setArgument(GetTypeSourceInfo(Record, Idx));
00580   }
00581   E->setOperatorLoc(ReadSourceLocation(Record, Idx));
00582   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00583 }
00584 
00585 void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
00586   VisitExpr(E);
00587   E->setLHS(Reader.ReadSubExpr());
00588   E->setRHS(Reader.ReadSubExpr());
00589   E->setRBracketLoc(ReadSourceLocation(Record, Idx));
00590 }
00591 
00592 void ASTStmtReader::VisitCallExpr(CallExpr *E) {
00593   VisitExpr(E);
00594   E->setNumArgs(Reader.getContext(), Record[Idx++]);
00595   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00596   E->setCallee(Reader.ReadSubExpr());
00597   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
00598     E->setArg(I, Reader.ReadSubExpr());
00599 }
00600 
00601 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
00602   VisitCallExpr(E);
00603 }
00604 
00605 void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
00606   // Don't call VisitExpr, this is fully initialized at creation.
00607   assert(E->getStmtClass() == Stmt::MemberExprClass &&
00608          "It's a subclass, we must advance Idx!");
00609 }
00610 
00611 void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
00612   VisitExpr(E);
00613   E->setBase(Reader.ReadSubExpr());
00614   E->setIsaMemberLoc(ReadSourceLocation(Record, Idx));
00615   E->setOpLoc(ReadSourceLocation(Record, Idx));
00616   E->setArrow(Record[Idx++]);
00617 }
00618 
00619 void ASTStmtReader::
00620 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
00621   VisitExpr(E);
00622   E->Operand = Reader.ReadSubExpr();
00623   E->setShouldCopy(Record[Idx++]);
00624 }
00625 
00626 void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
00627   VisitExplicitCastExpr(E);
00628   E->LParenLoc = ReadSourceLocation(Record, Idx);
00629   E->BridgeKeywordLoc = ReadSourceLocation(Record, Idx);
00630   E->Kind = Record[Idx++];
00631 }
00632 
00633 void ASTStmtReader::VisitCastExpr(CastExpr *E) {
00634   VisitExpr(E);
00635   unsigned NumBaseSpecs = Record[Idx++];
00636   assert(NumBaseSpecs == E->path_size());
00637   E->setSubExpr(Reader.ReadSubExpr());
00638   E->setCastKind((CastKind)Record[Idx++]);
00639   CastExpr::path_iterator BaseI = E->path_begin();
00640   while (NumBaseSpecs--) {
00641     CXXBaseSpecifier *BaseSpec = new (Reader.getContext()) CXXBaseSpecifier;
00642     *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx);
00643     *BaseI++ = BaseSpec;
00644   }
00645 }
00646 
00647 void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
00648   VisitExpr(E);
00649   E->setLHS(Reader.ReadSubExpr());
00650   E->setRHS(Reader.ReadSubExpr());
00651   E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
00652   E->setOperatorLoc(ReadSourceLocation(Record, Idx));
00653   E->setFPContractable((bool)Record[Idx++]);
00654 }
00655 
00656 void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
00657   VisitBinaryOperator(E);
00658   E->setComputationLHSType(Reader.readType(F, Record, Idx));
00659   E->setComputationResultType(Reader.readType(F, Record, Idx));
00660 }
00661 
00662 void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
00663   VisitExpr(E);
00664   E->SubExprs[ConditionalOperator::COND] = Reader.ReadSubExpr();
00665   E->SubExprs[ConditionalOperator::LHS] = Reader.ReadSubExpr();
00666   E->SubExprs[ConditionalOperator::RHS] = Reader.ReadSubExpr();
00667   E->QuestionLoc = ReadSourceLocation(Record, Idx);
00668   E->ColonLoc = ReadSourceLocation(Record, Idx);
00669 }
00670 
00671 void
00672 ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
00673   VisitExpr(E);
00674   E->OpaqueValue = cast<OpaqueValueExpr>(Reader.ReadSubExpr());
00675   E->SubExprs[BinaryConditionalOperator::COMMON] = Reader.ReadSubExpr();
00676   E->SubExprs[BinaryConditionalOperator::COND] = Reader.ReadSubExpr();
00677   E->SubExprs[BinaryConditionalOperator::LHS] = Reader.ReadSubExpr();
00678   E->SubExprs[BinaryConditionalOperator::RHS] = Reader.ReadSubExpr();
00679   E->QuestionLoc = ReadSourceLocation(Record, Idx);
00680   E->ColonLoc = ReadSourceLocation(Record, Idx);
00681 }
00682 
00683 void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
00684   VisitCastExpr(E);
00685 }
00686 
00687 void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
00688   VisitCastExpr(E);
00689   E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx));
00690 }
00691 
00692 void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
00693   VisitExplicitCastExpr(E);
00694   E->setLParenLoc(ReadSourceLocation(Record, Idx));
00695   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00696 }
00697 
00698 void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
00699   VisitExpr(E);
00700   E->setLParenLoc(ReadSourceLocation(Record, Idx));
00701   E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
00702   E->setInitializer(Reader.ReadSubExpr());
00703   E->setFileScope(Record[Idx++]);
00704 }
00705 
00706 void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
00707   VisitExpr(E);
00708   E->setBase(Reader.ReadSubExpr());
00709   E->setAccessor(Reader.GetIdentifierInfo(F, Record, Idx));
00710   E->setAccessorLoc(ReadSourceLocation(Record, Idx));
00711 }
00712 
00713 void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
00714   VisitExpr(E);
00715   if (InitListExpr *SyntForm = cast_or_null<InitListExpr>(Reader.ReadSubStmt()))
00716     E->setSyntacticForm(SyntForm);
00717   E->setLBraceLoc(ReadSourceLocation(Record, Idx));
00718   E->setRBraceLoc(ReadSourceLocation(Record, Idx));
00719   bool isArrayFiller = Record[Idx++];
00720   Expr *filler = nullptr;
00721   if (isArrayFiller) {
00722     filler = Reader.ReadSubExpr();
00723     E->ArrayFillerOrUnionFieldInit = filler;
00724   } else
00725     E->ArrayFillerOrUnionFieldInit = ReadDeclAs<FieldDecl>(Record, Idx);
00726   E->sawArrayRangeDesignator(Record[Idx++]);
00727   unsigned NumInits = Record[Idx++];
00728   E->reserveInits(Reader.getContext(), NumInits);
00729   if (isArrayFiller) {
00730     for (unsigned I = 0; I != NumInits; ++I) {
00731       Expr *init = Reader.ReadSubExpr();
00732       E->updateInit(Reader.getContext(), I, init ? init : filler);
00733     }
00734   } else {
00735     for (unsigned I = 0; I != NumInits; ++I)
00736       E->updateInit(Reader.getContext(), I, Reader.ReadSubExpr());
00737   }
00738 }
00739 
00740 void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
00741   typedef DesignatedInitExpr::Designator Designator;
00742 
00743   VisitExpr(E);
00744   unsigned NumSubExprs = Record[Idx++];
00745   assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
00746   for (unsigned I = 0; I != NumSubExprs; ++I)
00747     E->setSubExpr(I, Reader.ReadSubExpr());
00748   E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx));
00749   E->setGNUSyntax(Record[Idx++]);
00750 
00751   SmallVector<Designator, 4> Designators;
00752   while (Idx < Record.size()) {
00753     switch ((DesignatorTypes)Record[Idx++]) {
00754     case DESIG_FIELD_DECL: {
00755       FieldDecl *Field = ReadDeclAs<FieldDecl>(Record, Idx);
00756       SourceLocation DotLoc
00757         = ReadSourceLocation(Record, Idx);
00758       SourceLocation FieldLoc
00759         = ReadSourceLocation(Record, Idx);
00760       Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
00761                                        FieldLoc));
00762       Designators.back().setField(Field);
00763       break;
00764     }
00765 
00766     case DESIG_FIELD_NAME: {
00767       const IdentifierInfo *Name = Reader.GetIdentifierInfo(F, Record, Idx);
00768       SourceLocation DotLoc
00769         = ReadSourceLocation(Record, Idx);
00770       SourceLocation FieldLoc
00771         = ReadSourceLocation(Record, Idx);
00772       Designators.push_back(Designator(Name, DotLoc, FieldLoc));
00773       break;
00774     }
00775 
00776     case DESIG_ARRAY: {
00777       unsigned Index = Record[Idx++];
00778       SourceLocation LBracketLoc
00779         = ReadSourceLocation(Record, Idx);
00780       SourceLocation RBracketLoc
00781         = ReadSourceLocation(Record, Idx);
00782       Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
00783       break;
00784     }
00785 
00786     case DESIG_ARRAY_RANGE: {
00787       unsigned Index = Record[Idx++];
00788       SourceLocation LBracketLoc
00789         = ReadSourceLocation(Record, Idx);
00790       SourceLocation EllipsisLoc
00791         = ReadSourceLocation(Record, Idx);
00792       SourceLocation RBracketLoc
00793         = ReadSourceLocation(Record, Idx);
00794       Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
00795                                        RBracketLoc));
00796       break;
00797     }
00798     }
00799   }
00800   E->setDesignators(Reader.getContext(), 
00801                     Designators.data(), Designators.size());
00802 }
00803 
00804 void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
00805   VisitExpr(E);
00806 }
00807 
00808 void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
00809   VisitExpr(E);
00810   E->setSubExpr(Reader.ReadSubExpr());
00811   E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx));
00812   E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
00813   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00814 }
00815 
00816 void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
00817   VisitExpr(E);
00818   E->setAmpAmpLoc(ReadSourceLocation(Record, Idx));
00819   E->setLabelLoc(ReadSourceLocation(Record, Idx));
00820   E->setLabel(ReadDeclAs<LabelDecl>(Record, Idx));
00821 }
00822 
00823 void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
00824   VisitExpr(E);
00825   E->setLParenLoc(ReadSourceLocation(Record, Idx));
00826   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00827   E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt()));
00828 }
00829 
00830 void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
00831   VisitExpr(E);
00832   E->setCond(Reader.ReadSubExpr());
00833   E->setLHS(Reader.ReadSubExpr());
00834   E->setRHS(Reader.ReadSubExpr());
00835   E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
00836   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00837   E->setIsConditionTrue(Record[Idx++]);
00838 }
00839 
00840 void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
00841   VisitExpr(E);
00842   E->setTokenLocation(ReadSourceLocation(Record, Idx));
00843 }
00844 
00845 void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
00846   VisitExpr(E);
00847   SmallVector<Expr *, 16> Exprs;
00848   unsigned NumExprs = Record[Idx++];
00849   while (NumExprs--)
00850     Exprs.push_back(Reader.ReadSubExpr());
00851   E->setExprs(Reader.getContext(), Exprs);
00852   E->setBuiltinLoc(ReadSourceLocation(Record, Idx));
00853   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00854 }
00855 
00856 void ASTStmtReader::VisitConvertVectorExpr(ConvertVectorExpr *E) {
00857   VisitExpr(E);
00858   E->BuiltinLoc = ReadSourceLocation(Record, Idx);
00859   E->RParenLoc = ReadSourceLocation(Record, Idx);
00860   E->TInfo = GetTypeSourceInfo(Record, Idx);
00861   E->SrcExpr = Reader.ReadSubExpr();
00862 }
00863 
00864 void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
00865   VisitExpr(E);
00866   E->setBlockDecl(ReadDeclAs<BlockDecl>(Record, Idx));
00867 }
00868 
00869 void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
00870   VisitExpr(E);
00871   E->NumAssocs = Record[Idx++];
00872   E->AssocTypes = new (Reader.getContext()) TypeSourceInfo*[E->NumAssocs];
00873   E->SubExprs =
00874    new(Reader.getContext()) Stmt*[GenericSelectionExpr::END_EXPR+E->NumAssocs];
00875 
00876   E->SubExprs[GenericSelectionExpr::CONTROLLING] = Reader.ReadSubExpr();
00877   for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
00878     E->AssocTypes[I] = GetTypeSourceInfo(Record, Idx);
00879     E->SubExprs[GenericSelectionExpr::END_EXPR+I] = Reader.ReadSubExpr();
00880   }
00881   E->ResultIndex = Record[Idx++];
00882 
00883   E->GenericLoc = ReadSourceLocation(Record, Idx);
00884   E->DefaultLoc = ReadSourceLocation(Record, Idx);
00885   E->RParenLoc = ReadSourceLocation(Record, Idx);
00886 }
00887 
00888 void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
00889   VisitExpr(E);
00890   unsigned numSemanticExprs = Record[Idx++];
00891   assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs);
00892   E->PseudoObjectExprBits.ResultIndex = Record[Idx++];
00893 
00894   // Read the syntactic expression.
00895   E->getSubExprsBuffer()[0] = Reader.ReadSubExpr();
00896 
00897   // Read all the semantic expressions.
00898   for (unsigned i = 0; i != numSemanticExprs; ++i) {
00899     Expr *subExpr = Reader.ReadSubExpr();
00900     E->getSubExprsBuffer()[i+1] = subExpr;
00901   }
00902 }
00903 
00904 void ASTStmtReader::VisitAtomicExpr(AtomicExpr *E) {
00905   VisitExpr(E);
00906   E->Op = AtomicExpr::AtomicOp(Record[Idx++]);
00907   E->NumSubExprs = AtomicExpr::getNumSubExprs(E->Op);
00908   for (unsigned I = 0; I != E->NumSubExprs; ++I)
00909     E->SubExprs[I] = Reader.ReadSubExpr();
00910   E->BuiltinLoc = ReadSourceLocation(Record, Idx);
00911   E->RParenLoc = ReadSourceLocation(Record, Idx);
00912 }
00913 
00914 //===----------------------------------------------------------------------===//
00915 // Objective-C Expressions and Statements
00916 
00917 void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
00918   VisitExpr(E);
00919   E->setString(cast<StringLiteral>(Reader.ReadSubStmt()));
00920   E->setAtLoc(ReadSourceLocation(Record, Idx));
00921 }
00922 
00923 void ASTStmtReader::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
00924   VisitExpr(E);
00925   // could be one of several IntegerLiteral, FloatLiteral, etc.
00926   E->SubExpr = Reader.ReadSubStmt();
00927   E->BoxingMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
00928   E->Range = ReadSourceRange(Record, Idx);
00929 }
00930 
00931 void ASTStmtReader::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
00932   VisitExpr(E);
00933   unsigned NumElements = Record[Idx++];
00934   assert(NumElements == E->getNumElements() && "Wrong number of elements");
00935   Expr **Elements = E->getElements();
00936   for (unsigned I = 0, N = NumElements; I != N; ++I)
00937     Elements[I] = Reader.ReadSubExpr();
00938   E->ArrayWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
00939   E->Range = ReadSourceRange(Record, Idx);
00940 }
00941 
00942 void ASTStmtReader::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
00943   VisitExpr(E);
00944   unsigned NumElements = Record[Idx++];
00945   assert(NumElements == E->getNumElements() && "Wrong number of elements");
00946   bool HasPackExpansions = Record[Idx++];
00947   assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch");
00948   ObjCDictionaryLiteral::KeyValuePair *KeyValues = E->getKeyValues();
00949   ObjCDictionaryLiteral::ExpansionData *Expansions = E->getExpansionData();
00950   for (unsigned I = 0; I != NumElements; ++I) {
00951     KeyValues[I].Key = Reader.ReadSubExpr();
00952     KeyValues[I].Value = Reader.ReadSubExpr();
00953     if (HasPackExpansions) {
00954       Expansions[I].EllipsisLoc = ReadSourceLocation(Record, Idx);
00955       Expansions[I].NumExpansionsPlusOne = Record[Idx++];
00956     }
00957   }
00958   E->DictWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
00959   E->Range = ReadSourceRange(Record, Idx);
00960 }
00961 
00962 void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
00963   VisitExpr(E);
00964   E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
00965   E->setAtLoc(ReadSourceLocation(Record, Idx));
00966   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00967 }
00968 
00969 void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
00970   VisitExpr(E);
00971   E->setSelector(Reader.ReadSelector(F, Record, Idx));
00972   E->setAtLoc(ReadSourceLocation(Record, Idx));
00973   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00974 }
00975 
00976 void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
00977   VisitExpr(E);
00978   E->setProtocol(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
00979   E->setAtLoc(ReadSourceLocation(Record, Idx));
00980   E->ProtoLoc = ReadSourceLocation(Record, Idx);
00981   E->setRParenLoc(ReadSourceLocation(Record, Idx));
00982 }
00983 
00984 void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
00985   VisitExpr(E);
00986   E->setDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
00987   E->setLocation(ReadSourceLocation(Record, Idx));
00988   E->setOpLoc(ReadSourceLocation(Record, Idx));
00989   E->setBase(Reader.ReadSubExpr());
00990   E->setIsArrow(Record[Idx++]);
00991   E->setIsFreeIvar(Record[Idx++]);
00992 }
00993 
00994 void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
00995   VisitExpr(E);
00996   unsigned MethodRefFlags = Record[Idx++];
00997   bool Implicit = Record[Idx++] != 0;
00998   if (Implicit) {
00999     ObjCMethodDecl *Getter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
01000     ObjCMethodDecl *Setter = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
01001     E->setImplicitProperty(Getter, Setter, MethodRefFlags);
01002   } else {
01003     E->setExplicitProperty(ReadDeclAs<ObjCPropertyDecl>(Record, Idx),
01004                            MethodRefFlags);
01005   }
01006   E->setLocation(ReadSourceLocation(Record, Idx));
01007   E->setReceiverLocation(ReadSourceLocation(Record, Idx));
01008   switch (Record[Idx++]) {
01009   case 0:
01010     E->setBase(Reader.ReadSubExpr());
01011     break;
01012   case 1:
01013     E->setSuperReceiver(Reader.readType(F, Record, Idx));
01014     break;
01015   case 2:
01016     E->setClassReceiver(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
01017     break;
01018   }
01019 }
01020 
01021 void ASTStmtReader::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
01022   VisitExpr(E);
01023   E->setRBracket(ReadSourceLocation(Record, Idx));
01024   E->setBaseExpr(Reader.ReadSubExpr());
01025   E->setKeyExpr(Reader.ReadSubExpr());
01026   E->GetAtIndexMethodDecl = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
01027   E->SetAtIndexMethodDecl = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
01028 }
01029 
01030 void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
01031   VisitExpr(E);
01032   assert(Record[Idx] == E->getNumArgs());
01033   ++Idx;
01034   unsigned NumStoredSelLocs = Record[Idx++];
01035   E->SelLocsKind = Record[Idx++]; 
01036   E->setDelegateInitCall(Record[Idx++]);
01037   E->IsImplicit = Record[Idx++];
01038   ObjCMessageExpr::ReceiverKind Kind
01039     = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
01040   switch (Kind) {
01041   case ObjCMessageExpr::Instance:
01042     E->setInstanceReceiver(Reader.ReadSubExpr());
01043     break;
01044 
01045   case ObjCMessageExpr::Class:
01046     E->setClassReceiver(GetTypeSourceInfo(Record, Idx));
01047     break;
01048 
01049   case ObjCMessageExpr::SuperClass:
01050   case ObjCMessageExpr::SuperInstance: {
01051     QualType T = Reader.readType(F, Record, Idx);
01052     SourceLocation SuperLoc = ReadSourceLocation(Record, Idx);
01053     E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
01054     break;
01055   }
01056   }
01057 
01058   assert(Kind == E->getReceiverKind());
01059 
01060   if (Record[Idx++])
01061     E->setMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
01062   else
01063     E->setSelector(Reader.ReadSelector(F, Record, Idx));
01064 
01065   E->LBracLoc = ReadSourceLocation(Record, Idx);
01066   E->RBracLoc = ReadSourceLocation(Record, Idx);
01067 
01068   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
01069     E->setArg(I, Reader.ReadSubExpr());
01070 
01071   SourceLocation *Locs = E->getStoredSelLocs();
01072   for (unsigned I = 0; I != NumStoredSelLocs; ++I)
01073     Locs[I] = ReadSourceLocation(Record, Idx);
01074 }
01075 
01076 void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
01077   VisitStmt(S);
01078   S->setElement(Reader.ReadSubStmt());
01079   S->setCollection(Reader.ReadSubExpr());
01080   S->setBody(Reader.ReadSubStmt());
01081   S->setForLoc(ReadSourceLocation(Record, Idx));
01082   S->setRParenLoc(ReadSourceLocation(Record, Idx));
01083 }
01084 
01085 void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
01086   VisitStmt(S);
01087   S->setCatchBody(Reader.ReadSubStmt());
01088   S->setCatchParamDecl(ReadDeclAs<VarDecl>(Record, Idx));
01089   S->setAtCatchLoc(ReadSourceLocation(Record, Idx));
01090   S->setRParenLoc(ReadSourceLocation(Record, Idx));
01091 }
01092 
01093 void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
01094   VisitStmt(S);
01095   S->setFinallyBody(Reader.ReadSubStmt());
01096   S->setAtFinallyLoc(ReadSourceLocation(Record, Idx));
01097 }
01098 
01099 void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
01100   VisitStmt(S);
01101   S->setSubStmt(Reader.ReadSubStmt());
01102   S->setAtLoc(ReadSourceLocation(Record, Idx));
01103 }
01104 
01105 void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
01106   VisitStmt(S);
01107   assert(Record[Idx] == S->getNumCatchStmts());
01108   ++Idx;
01109   bool HasFinally = Record[Idx++];
01110   S->setTryBody(Reader.ReadSubStmt());
01111   for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
01112     S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt()));
01113 
01114   if (HasFinally)
01115     S->setFinallyStmt(Reader.ReadSubStmt());
01116   S->setAtTryLoc(ReadSourceLocation(Record, Idx));
01117 }
01118 
01119 void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
01120   VisitStmt(S);
01121   S->setSynchExpr(Reader.ReadSubStmt());
01122   S->setSynchBody(Reader.ReadSubStmt());
01123   S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx));
01124 }
01125 
01126 void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
01127   VisitStmt(S);
01128   S->setThrowExpr(Reader.ReadSubStmt());
01129   S->setThrowLoc(ReadSourceLocation(Record, Idx));
01130 }
01131 
01132 void ASTStmtReader::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
01133   VisitExpr(E);
01134   E->setValue(Record[Idx++]);
01135   E->setLocation(ReadSourceLocation(Record, Idx));
01136 }
01137 
01138 //===----------------------------------------------------------------------===//
01139 // C++ Expressions and Statements
01140 //===----------------------------------------------------------------------===//
01141 
01142 void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
01143   VisitStmt(S);
01144   S->CatchLoc = ReadSourceLocation(Record, Idx);
01145   S->ExceptionDecl = ReadDeclAs<VarDecl>(Record, Idx);
01146   S->HandlerBlock = Reader.ReadSubStmt();
01147 }
01148 
01149 void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
01150   VisitStmt(S);
01151   assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?");
01152   ++Idx;
01153   S->TryLoc = ReadSourceLocation(Record, Idx);
01154   S->getStmts()[0] = Reader.ReadSubStmt();
01155   for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
01156     S->getStmts()[i + 1] = Reader.ReadSubStmt();
01157 }
01158 
01159 void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
01160   VisitStmt(S);
01161   S->setForLoc(ReadSourceLocation(Record, Idx));
01162   S->setColonLoc(ReadSourceLocation(Record, Idx));
01163   S->setRParenLoc(ReadSourceLocation(Record, Idx));
01164   S->setRangeStmt(Reader.ReadSubStmt());
01165   S->setBeginEndStmt(Reader.ReadSubStmt());
01166   S->setCond(Reader.ReadSubExpr());
01167   S->setInc(Reader.ReadSubExpr());
01168   S->setLoopVarStmt(Reader.ReadSubStmt());
01169   S->setBody(Reader.ReadSubStmt());
01170 }
01171 
01172 void ASTStmtReader::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
01173   VisitStmt(S);
01174   S->KeywordLoc = ReadSourceLocation(Record, Idx);
01175   S->IsIfExists = Record[Idx++];
01176   S->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
01177   ReadDeclarationNameInfo(S->NameInfo, Record, Idx);
01178   S->SubStmt = Reader.ReadSubStmt();
01179 }
01180 
01181 void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
01182   VisitCallExpr(E);
01183   E->Operator = (OverloadedOperatorKind)Record[Idx++];
01184   E->Range = Reader.ReadSourceRange(F, Record, Idx);
01185   E->setFPContractable((bool)Record[Idx++]);
01186 }
01187 
01188 void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
01189   VisitExpr(E);
01190   E->NumArgs = Record[Idx++];
01191   if (E->NumArgs)
01192     E->Args = new (Reader.getContext()) Stmt*[E->NumArgs];
01193   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
01194     E->setArg(I, Reader.ReadSubExpr());
01195   E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx));
01196   E->setLocation(ReadSourceLocation(Record, Idx));
01197   E->setElidable(Record[Idx++]);
01198   E->setHadMultipleCandidates(Record[Idx++]);
01199   E->setListInitialization(Record[Idx++]);
01200   E->setStdInitListInitialization(Record[Idx++]);
01201   E->setRequiresZeroInitialization(Record[Idx++]);
01202   E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
01203   E->ParenOrBraceRange = ReadSourceRange(Record, Idx);
01204 }
01205 
01206 void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
01207   VisitCXXConstructExpr(E);
01208   E->Type = GetTypeSourceInfo(Record, Idx);
01209 }
01210 
01211 void ASTStmtReader::VisitLambdaExpr(LambdaExpr *E) {
01212   VisitExpr(E);
01213   unsigned NumCaptures = Record[Idx++];
01214   assert(NumCaptures == E->NumCaptures);(void)NumCaptures;
01215   unsigned NumArrayIndexVars = Record[Idx++];
01216   E->IntroducerRange = ReadSourceRange(Record, Idx);
01217   E->CaptureDefault = static_cast<LambdaCaptureDefault>(Record[Idx++]);
01218   E->CaptureDefaultLoc = ReadSourceLocation(Record, Idx);
01219   E->ExplicitParams = Record[Idx++];
01220   E->ExplicitResultType = Record[Idx++];
01221   E->ClosingBrace = ReadSourceLocation(Record, Idx);
01222   
01223   // Read capture initializers.
01224   for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
01225                                       CEnd = E->capture_init_end();
01226        C != CEnd; ++C)
01227     *C = Reader.ReadSubExpr();
01228   
01229   // Read array capture index variables.
01230   if (NumArrayIndexVars > 0) {
01231     unsigned *ArrayIndexStarts = E->getArrayIndexStarts();
01232     for (unsigned I = 0; I != NumCaptures + 1; ++I)
01233       ArrayIndexStarts[I] = Record[Idx++];
01234     
01235     VarDecl **ArrayIndexVars = E->getArrayIndexVars();
01236     for (unsigned I = 0; I != NumArrayIndexVars; ++I)
01237       ArrayIndexVars[I] = ReadDeclAs<VarDecl>(Record, Idx);
01238   }
01239 }
01240 
01241 void
01242 ASTStmtReader::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
01243   VisitExpr(E);
01244   E->SubExpr = Reader.ReadSubExpr();
01245 }
01246 
01247 void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
01248   VisitExplicitCastExpr(E);
01249   SourceRange R = ReadSourceRange(Record, Idx);
01250   E->Loc = R.getBegin();
01251   E->RParenLoc = R.getEnd();
01252   R = ReadSourceRange(Record, Idx);
01253   E->AngleBrackets = R;
01254 }
01255 
01256 void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
01257   return VisitCXXNamedCastExpr(E);
01258 }
01259 
01260 void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
01261   return VisitCXXNamedCastExpr(E);
01262 }
01263 
01264 void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
01265   return VisitCXXNamedCastExpr(E);
01266 }
01267 
01268 void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
01269   return VisitCXXNamedCastExpr(E);
01270 }
01271 
01272 void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
01273   VisitExplicitCastExpr(E);
01274   E->setLParenLoc(ReadSourceLocation(Record, Idx));
01275   E->setRParenLoc(ReadSourceLocation(Record, Idx));
01276 }
01277 
01278 void ASTStmtReader::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
01279   VisitCallExpr(E);
01280   E->UDSuffixLoc = ReadSourceLocation(Record, Idx);
01281 }
01282 
01283 void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
01284   VisitExpr(E);
01285   E->setValue(Record[Idx++]);
01286   E->setLocation(ReadSourceLocation(Record, Idx));
01287 }
01288 
01289 void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
01290   VisitExpr(E);
01291   E->setLocation(ReadSourceLocation(Record, Idx));
01292 }
01293 
01294 void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
01295   VisitExpr(E);
01296   E->setSourceRange(ReadSourceRange(Record, Idx));
01297   if (E->isTypeOperand()) { // typeid(int)
01298     E->setTypeOperandSourceInfo(
01299         GetTypeSourceInfo(Record, Idx));
01300     return;
01301   }
01302   
01303   // typeid(42+2)
01304   E->setExprOperand(Reader.ReadSubExpr());
01305 }
01306 
01307 void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
01308   VisitExpr(E);
01309   E->setLocation(ReadSourceLocation(Record, Idx));
01310   E->setImplicit(Record[Idx++]);
01311 }
01312 
01313 void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
01314   VisitExpr(E);
01315   E->ThrowLoc = ReadSourceLocation(Record, Idx);
01316   E->Op = Reader.ReadSubExpr();
01317   E->IsThrownVariableInScope = Record[Idx++];
01318 }
01319 
01320 void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
01321   VisitExpr(E);
01322 
01323   assert((bool)Record[Idx] == E->Param.getInt() && "We messed up at creation ?");
01324   ++Idx; // HasOtherExprStored and SubExpr was handled during creation.
01325   E->Param.setPointer(ReadDeclAs<ParmVarDecl>(Record, Idx));
01326   E->Loc = ReadSourceLocation(Record, Idx);
01327 }
01328 
01329 void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
01330   VisitExpr(E);
01331   E->Field = ReadDeclAs<FieldDecl>(Record, Idx);
01332   E->Loc = ReadSourceLocation(Record, Idx);
01333 }
01334 
01335 void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
01336   VisitExpr(E);
01337   E->setTemporary(Reader.ReadCXXTemporary(F, Record, Idx));
01338   E->setSubExpr(Reader.ReadSubExpr());
01339 }
01340 
01341 void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
01342   VisitExpr(E);
01343   E->TypeInfo = GetTypeSourceInfo(Record, Idx);
01344   E->RParenLoc = ReadSourceLocation(Record, Idx);
01345 }
01346 
01347 void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
01348   VisitExpr(E);
01349   E->GlobalNew = Record[Idx++];
01350   bool isArray = Record[Idx++];
01351   E->UsualArrayDeleteWantsSize = Record[Idx++];
01352   unsigned NumPlacementArgs = Record[Idx++];
01353   E->StoredInitializationStyle = Record[Idx++];
01354   E->setOperatorNew(ReadDeclAs<FunctionDecl>(Record, Idx));
01355   E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx));
01356   E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
01357   E->TypeIdParens = ReadSourceRange(Record, Idx);
01358   E->Range = ReadSourceRange(Record, Idx);
01359   E->DirectInitRange = ReadSourceRange(Record, Idx);
01360 
01361   E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs,
01362                        E->StoredInitializationStyle != 0);
01363 
01364   // Install all the subexpressions.
01365   for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
01366        I != e; ++I)
01367     *I = Reader.ReadSubStmt();
01368 }
01369 
01370 void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
01371   VisitExpr(E);
01372   E->GlobalDelete = Record[Idx++];
01373   E->ArrayForm = Record[Idx++];
01374   E->ArrayFormAsWritten = Record[Idx++];
01375   E->UsualArrayDeleteWantsSize = Record[Idx++];
01376   E->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
01377   E->Argument = Reader.ReadSubExpr();
01378   E->Loc = ReadSourceLocation(Record, Idx);
01379 }
01380 
01381 void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
01382   VisitExpr(E);
01383 
01384   E->Base = Reader.ReadSubExpr();
01385   E->IsArrow = Record[Idx++];
01386   E->OperatorLoc = ReadSourceLocation(Record, Idx);
01387   E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
01388   E->ScopeType = GetTypeSourceInfo(Record, Idx);
01389   E->ColonColonLoc = ReadSourceLocation(Record, Idx);
01390   E->TildeLoc = ReadSourceLocation(Record, Idx);
01391   
01392   IdentifierInfo *II = Reader.GetIdentifierInfo(F, Record, Idx);
01393   if (II)
01394     E->setDestroyedType(II, ReadSourceLocation(Record, Idx));
01395   else
01396     E->setDestroyedType(GetTypeSourceInfo(Record, Idx));
01397 }
01398 
01399 void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
01400   VisitExpr(E);
01401 
01402   unsigned NumObjects = Record[Idx++];
01403   assert(NumObjects == E->getNumObjects());
01404   for (unsigned i = 0; i != NumObjects; ++i)
01405     E->getObjectsBuffer()[i] = ReadDeclAs<BlockDecl>(Record, Idx);
01406 
01407   E->SubExpr = Reader.ReadSubExpr();
01408 }
01409 
01410 void
01411 ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
01412   VisitExpr(E);
01413 
01414   if (Record[Idx++]) // HasTemplateKWAndArgsInfo
01415     ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
01416                               /*NumTemplateArgs=*/Record[Idx++]);
01417 
01418   E->Base = Reader.ReadSubExpr();
01419   E->BaseType = Reader.readType(F, Record, Idx);
01420   E->IsArrow = Record[Idx++];
01421   E->OperatorLoc = ReadSourceLocation(Record, Idx);
01422   E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
01423   E->FirstQualifierFoundInScope = ReadDeclAs<NamedDecl>(Record, Idx);
01424   ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx);
01425 }
01426 
01427 void
01428 ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
01429   VisitExpr(E);
01430 
01431   if (Record[Idx++]) // HasTemplateKWAndArgsInfo
01432     ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
01433                               /*NumTemplateArgs=*/Record[Idx++]);
01434 
01435   E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
01436   ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
01437 }
01438 
01439 void
01440 ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
01441   VisitExpr(E);
01442   assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
01443   ++Idx; // NumArgs;
01444   for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
01445     E->setArg(I, Reader.ReadSubExpr());
01446   E->Type = GetTypeSourceInfo(Record, Idx);
01447   E->setLParenLoc(ReadSourceLocation(Record, Idx));
01448   E->setRParenLoc(ReadSourceLocation(Record, Idx));
01449 }
01450 
01451 void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
01452   VisitExpr(E);
01453 
01454   if (Record[Idx++]) // HasTemplateKWAndArgsInfo
01455     ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(),
01456                               /*NumTemplateArgs=*/Record[Idx++]);
01457 
01458   unsigned NumDecls = Record[Idx++];
01459   UnresolvedSet<8> Decls;
01460   for (unsigned i = 0; i != NumDecls; ++i) {
01461     NamedDecl *D = ReadDeclAs<NamedDecl>(Record, Idx);
01462     AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
01463     Decls.addDecl(D, AS);
01464   }
01465   E->initializeResults(Reader.getContext(), Decls.begin(), Decls.end());
01466 
01467   ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
01468   E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
01469 }
01470 
01471 void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
01472   VisitOverloadExpr(E);
01473   E->IsArrow = Record[Idx++];
01474   E->HasUnresolvedUsing = Record[Idx++];
01475   E->Base = Reader.ReadSubExpr();
01476   E->BaseType = Reader.readType(F, Record, Idx);
01477   E->OperatorLoc = ReadSourceLocation(Record, Idx);
01478 }
01479 
01480 void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
01481   VisitOverloadExpr(E);
01482   E->RequiresADL = Record[Idx++];
01483   E->Overloaded = Record[Idx++];
01484   E->NamingClass = ReadDeclAs<CXXRecordDecl>(Record, Idx);
01485 }
01486 
01487 void ASTStmtReader::VisitTypeTraitExpr(TypeTraitExpr *E) {
01488   VisitExpr(E);
01489   E->TypeTraitExprBits.NumArgs = Record[Idx++];
01490   E->TypeTraitExprBits.Kind = Record[Idx++];
01491   E->TypeTraitExprBits.Value = Record[Idx++];
01492   SourceRange Range = ReadSourceRange(Record, Idx);
01493   E->Loc = Range.getBegin();
01494   E->RParenLoc = Range.getEnd();
01495 
01496   TypeSourceInfo **Args = E->getTypeSourceInfos();
01497   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
01498     Args[I] = GetTypeSourceInfo(Record, Idx);
01499 }
01500 
01501 void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
01502   VisitExpr(E);
01503   E->ATT = (ArrayTypeTrait)Record[Idx++];
01504   E->Value = (unsigned int)Record[Idx++];
01505   SourceRange Range = ReadSourceRange(Record, Idx);
01506   E->Loc = Range.getBegin();
01507   E->RParen = Range.getEnd();
01508   E->QueriedType = GetTypeSourceInfo(Record, Idx);
01509 }
01510 
01511 void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
01512   VisitExpr(E);
01513   E->ET = (ExpressionTrait)Record[Idx++];
01514   E->Value = (bool)Record[Idx++];
01515   SourceRange Range = ReadSourceRange(Record, Idx);
01516   E->QueriedExpression = Reader.ReadSubExpr();
01517   E->Loc = Range.getBegin();
01518   E->RParen = Range.getEnd();
01519 }
01520 
01521 void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
01522   VisitExpr(E);
01523   E->Value = (bool)Record[Idx++];
01524   E->Range = ReadSourceRange(Record, Idx);
01525   E->Operand = Reader.ReadSubExpr();
01526 }
01527 
01528 void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
01529   VisitExpr(E);
01530   E->EllipsisLoc = ReadSourceLocation(Record, Idx);
01531   E->NumExpansions = Record[Idx++];
01532   E->Pattern = Reader.ReadSubExpr();  
01533 }
01534 
01535 void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
01536   VisitExpr(E);
01537   E->OperatorLoc = ReadSourceLocation(Record, Idx);
01538   E->PackLoc = ReadSourceLocation(Record, Idx);
01539   E->RParenLoc = ReadSourceLocation(Record, Idx);
01540   E->Length = Record[Idx++];
01541   E->Pack = ReadDeclAs<NamedDecl>(Record, Idx);
01542 }
01543 
01544 void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
01545                                               SubstNonTypeTemplateParmExpr *E) {
01546   VisitExpr(E);
01547   E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
01548   E->NameLoc = ReadSourceLocation(Record, Idx);
01549   E->Replacement = Reader.ReadSubExpr();
01550 }
01551 
01552 void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
01553                                           SubstNonTypeTemplateParmPackExpr *E) {
01554   VisitExpr(E);
01555   E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx);
01556   TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx);
01557   if (ArgPack.getKind() != TemplateArgument::Pack)
01558     return;
01559   
01560   E->Arguments = ArgPack.pack_begin();
01561   E->NumArguments = ArgPack.pack_size();
01562   E->NameLoc = ReadSourceLocation(Record, Idx);
01563 }
01564 
01565 void ASTStmtReader::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
01566   VisitExpr(E);
01567   E->NumParameters = Record[Idx++];
01568   E->ParamPack = ReadDeclAs<ParmVarDecl>(Record, Idx);
01569   E->NameLoc = ReadSourceLocation(Record, Idx);
01570   ParmVarDecl **Parms = reinterpret_cast<ParmVarDecl**>(E+1);
01571   for (unsigned i = 0, n = E->NumParameters; i != n; ++i)
01572     Parms[i] = ReadDeclAs<ParmVarDecl>(Record, Idx);
01573 }
01574 
01575 void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
01576   VisitExpr(E);
01577   E->State = Reader.ReadSubExpr();
01578   auto VD = ReadDeclAs<ValueDecl>(Record, Idx);
01579   unsigned ManglingNumber = Record[Idx++];
01580   E->setExtendingDecl(VD, ManglingNumber);
01581 }
01582 
01583 void ASTStmtReader::VisitCXXFoldExpr(CXXFoldExpr *E) {
01584   VisitExpr(E);
01585   E->LParenLoc = ReadSourceLocation(Record, Idx);
01586   E->EllipsisLoc = ReadSourceLocation(Record, Idx);
01587   E->RParenLoc = ReadSourceLocation(Record, Idx);
01588   E->SubExprs[0] = Reader.ReadSubExpr();
01589   E->SubExprs[1] = Reader.ReadSubExpr();
01590   E->Opcode = (BinaryOperatorKind)Record[Idx++];
01591 }
01592 
01593 void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
01594   VisitExpr(E);
01595   E->SourceExpr = Reader.ReadSubExpr();
01596   E->Loc = ReadSourceLocation(Record, Idx);
01597 }
01598 
01599 void ASTStmtReader::VisitTypoExpr(TypoExpr *E) {
01600   llvm_unreachable("Cannot read TypoExpr nodes");
01601 }
01602 
01603 //===----------------------------------------------------------------------===//
01604 // Microsoft Expressions and Statements
01605 //===----------------------------------------------------------------------===//
01606 void ASTStmtReader::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
01607   VisitExpr(E);
01608   E->IsArrow = (Record[Idx++] != 0);
01609   E->BaseExpr = Reader.ReadSubExpr();
01610   E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
01611   E->MemberLoc = ReadSourceLocation(Record, Idx);
01612   E->TheDecl = ReadDeclAs<MSPropertyDecl>(Record, Idx);
01613 }
01614 
01615 void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
01616   VisitExpr(E);
01617   E->setSourceRange(ReadSourceRange(Record, Idx));
01618   if (E->isTypeOperand()) { // __uuidof(ComType)
01619     E->setTypeOperandSourceInfo(
01620         GetTypeSourceInfo(Record, Idx));
01621     return;
01622   }
01623   
01624   // __uuidof(expr)
01625   E->setExprOperand(Reader.ReadSubExpr());
01626 }
01627 
01628 void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
01629   VisitStmt(S);
01630   S->setLeaveLoc(ReadSourceLocation(Record, Idx));
01631 }
01632 
01633 void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
01634   VisitStmt(S);
01635   S->Loc = ReadSourceLocation(Record, Idx);
01636   S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt();
01637   S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt();
01638 }
01639 
01640 void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
01641   VisitStmt(S);
01642   S->Loc = ReadSourceLocation(Record, Idx);
01643   S->Block = Reader.ReadSubStmt();
01644 }
01645 
01646 void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
01647   VisitStmt(S);
01648   S->IsCXXTry = Record[Idx++];
01649   S->TryLoc = ReadSourceLocation(Record, Idx);
01650   S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt();
01651   S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
01652 }
01653 
01654 //===----------------------------------------------------------------------===//
01655 // CUDA Expressions and Statements
01656 //===----------------------------------------------------------------------===//
01657 
01658 void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
01659   VisitCallExpr(E);
01660   E->setConfig(cast<CallExpr>(Reader.ReadSubExpr()));
01661 }
01662 
01663 //===----------------------------------------------------------------------===//
01664 // OpenCL Expressions and Statements.
01665 //===----------------------------------------------------------------------===//
01666 void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
01667   VisitExpr(E);
01668   E->BuiltinLoc = ReadSourceLocation(Record, Idx);
01669   E->RParenLoc = ReadSourceLocation(Record, Idx);
01670   E->SrcExpr = Reader.ReadSubExpr();
01671 }
01672 
01673 //===----------------------------------------------------------------------===//
01674 // OpenMP Clauses.
01675 //===----------------------------------------------------------------------===//
01676 
01677 namespace clang {
01678 class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> {
01679   ASTStmtReader *Reader;
01680   ASTContext &Context;
01681   const ASTReader::RecordData &Record;
01682   unsigned &Idx;
01683 public:
01684   OMPClauseReader(ASTStmtReader *R, ASTContext &C,
01685                   const ASTReader::RecordData &Record, unsigned &Idx)
01686     : Reader(R), Context(C), Record(Record), Idx(Idx) { }
01687 #define OPENMP_CLAUSE(Name, Class)    \
01688   void Visit##Class(Class *S);
01689 #include "clang/Basic/OpenMPKinds.def"
01690   OMPClause *readClause();
01691 };
01692 }
01693 
01694 OMPClause *OMPClauseReader::readClause() {
01695   OMPClause *C;
01696   switch (Record[Idx++]) {
01697   case OMPC_if:
01698     C = new (Context) OMPIfClause();
01699     break;
01700   case OMPC_final:
01701     C = new (Context) OMPFinalClause();
01702     break;
01703   case OMPC_num_threads:
01704     C = new (Context) OMPNumThreadsClause();
01705     break;
01706   case OMPC_safelen:
01707     C = new (Context) OMPSafelenClause();
01708     break;
01709   case OMPC_collapse:
01710     C = new (Context) OMPCollapseClause();
01711     break;
01712   case OMPC_default:
01713     C = new (Context) OMPDefaultClause();
01714     break;
01715   case OMPC_proc_bind:
01716     C = new (Context) OMPProcBindClause();
01717     break;
01718   case OMPC_schedule:
01719     C = new (Context) OMPScheduleClause();
01720     break;
01721   case OMPC_ordered:
01722     C = new (Context) OMPOrderedClause();
01723     break;
01724   case OMPC_nowait:
01725     C = new (Context) OMPNowaitClause();
01726     break;
01727   case OMPC_untied:
01728     C = new (Context) OMPUntiedClause();
01729     break;
01730   case OMPC_mergeable:
01731     C = new (Context) OMPMergeableClause();
01732     break;
01733   case OMPC_read:
01734     C = new (Context) OMPReadClause();
01735     break;
01736   case OMPC_write:
01737     C = new (Context) OMPWriteClause();
01738     break;
01739   case OMPC_update:
01740     C = new (Context) OMPUpdateClause();
01741     break;
01742   case OMPC_capture:
01743     C = new (Context) OMPCaptureClause();
01744     break;
01745   case OMPC_seq_cst:
01746     C = new (Context) OMPSeqCstClause();
01747     break;
01748   case OMPC_private:
01749     C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
01750     break;
01751   case OMPC_firstprivate:
01752     C = OMPFirstprivateClause::CreateEmpty(Context, Record[Idx++]);
01753     break;
01754   case OMPC_lastprivate:
01755     C = OMPLastprivateClause::CreateEmpty(Context, Record[Idx++]);
01756     break;
01757   case OMPC_shared:
01758     C = OMPSharedClause::CreateEmpty(Context, Record[Idx++]);
01759     break;
01760   case OMPC_reduction:
01761     C = OMPReductionClause::CreateEmpty(Context, Record[Idx++]);
01762     break;
01763   case OMPC_linear:
01764     C = OMPLinearClause::CreateEmpty(Context, Record[Idx++]);
01765     break;
01766   case OMPC_aligned:
01767     C = OMPAlignedClause::CreateEmpty(Context, Record[Idx++]);
01768     break;
01769   case OMPC_copyin:
01770     C = OMPCopyinClause::CreateEmpty(Context, Record[Idx++]);
01771     break;
01772   case OMPC_copyprivate:
01773     C = OMPCopyprivateClause::CreateEmpty(Context, Record[Idx++]);
01774     break;
01775   case OMPC_flush:
01776     C = OMPFlushClause::CreateEmpty(Context, Record[Idx++]);
01777     break;
01778   }
01779   Visit(C);
01780   C->setLocStart(Reader->ReadSourceLocation(Record, Idx));
01781   C->setLocEnd(Reader->ReadSourceLocation(Record, Idx));
01782 
01783   return C;
01784 }
01785 
01786 void OMPClauseReader::VisitOMPIfClause(OMPIfClause *C) {
01787   C->setCondition(Reader->Reader.ReadSubExpr());
01788   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01789 }
01790 
01791 void OMPClauseReader::VisitOMPFinalClause(OMPFinalClause *C) {
01792   C->setCondition(Reader->Reader.ReadSubExpr());
01793   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01794 }
01795 
01796 void OMPClauseReader::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
01797   C->setNumThreads(Reader->Reader.ReadSubExpr());
01798   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01799 }
01800 
01801 void OMPClauseReader::VisitOMPSafelenClause(OMPSafelenClause *C) {
01802   C->setSafelen(Reader->Reader.ReadSubExpr());
01803   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01804 }
01805 
01806 void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) {
01807   C->setNumForLoops(Reader->Reader.ReadSubExpr());
01808   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01809 }
01810 
01811 void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) {
01812   C->setDefaultKind(
01813        static_cast<OpenMPDefaultClauseKind>(Record[Idx++]));
01814   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01815   C->setDefaultKindKwLoc(Reader->ReadSourceLocation(Record, Idx));
01816 }
01817 
01818 void OMPClauseReader::VisitOMPProcBindClause(OMPProcBindClause *C) {
01819   C->setProcBindKind(
01820        static_cast<OpenMPProcBindClauseKind>(Record[Idx++]));
01821   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01822   C->setProcBindKindKwLoc(Reader->ReadSourceLocation(Record, Idx));
01823 }
01824 
01825 void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) {
01826   C->setScheduleKind(
01827        static_cast<OpenMPScheduleClauseKind>(Record[Idx++]));
01828   C->setChunkSize(Reader->Reader.ReadSubExpr());
01829   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01830   C->setScheduleKindLoc(Reader->ReadSourceLocation(Record, Idx));
01831   C->setCommaLoc(Reader->ReadSourceLocation(Record, Idx));
01832 }
01833 
01834 void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *) {}
01835 
01836 void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {}
01837 
01838 void OMPClauseReader::VisitOMPUntiedClause(OMPUntiedClause *) {}
01839 
01840 void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {}
01841 
01842 void OMPClauseReader::VisitOMPReadClause(OMPReadClause *) {}
01843 
01844 void OMPClauseReader::VisitOMPWriteClause(OMPWriteClause *) {}
01845 
01846 void OMPClauseReader::VisitOMPUpdateClause(OMPUpdateClause *) {}
01847 
01848 void OMPClauseReader::VisitOMPCaptureClause(OMPCaptureClause *) {}
01849 
01850 void OMPClauseReader::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
01851 
01852 void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
01853   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01854   unsigned NumVars = C->varlist_size();
01855   SmallVector<Expr *, 16> Vars;
01856   Vars.reserve(NumVars);
01857   for (unsigned i = 0; i != NumVars; ++i)
01858     Vars.push_back(Reader->Reader.ReadSubExpr());
01859   C->setVarRefs(Vars);
01860   Vars.clear();
01861   for (unsigned i = 0; i != NumVars; ++i)
01862     Vars.push_back(Reader->Reader.ReadSubExpr());
01863   C->setPrivateCopies(Vars);
01864 }
01865 
01866 void OMPClauseReader::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
01867   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01868   unsigned NumVars = C->varlist_size();
01869   SmallVector<Expr *, 16> Vars;
01870   Vars.reserve(NumVars);
01871   for (unsigned i = 0; i != NumVars; ++i)
01872     Vars.push_back(Reader->Reader.ReadSubExpr());
01873   C->setVarRefs(Vars);
01874   Vars.clear();
01875   for (unsigned i = 0; i != NumVars; ++i)
01876     Vars.push_back(Reader->Reader.ReadSubExpr());
01877   C->setPrivateCopies(Vars);
01878   Vars.clear();
01879   for (unsigned i = 0; i != NumVars; ++i)
01880     Vars.push_back(Reader->Reader.ReadSubExpr());
01881   C->setInits(Vars);
01882 }
01883 
01884 void OMPClauseReader::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
01885   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01886   unsigned NumVars = C->varlist_size();
01887   SmallVector<Expr *, 16> Vars;
01888   Vars.reserve(NumVars);
01889   for (unsigned i = 0; i != NumVars; ++i)
01890     Vars.push_back(Reader->Reader.ReadSubExpr());
01891   C->setVarRefs(Vars);
01892 }
01893 
01894 void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) {
01895   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01896   unsigned NumVars = C->varlist_size();
01897   SmallVector<Expr *, 16> Vars;
01898   Vars.reserve(NumVars);
01899   for (unsigned i = 0; i != NumVars; ++i)
01900     Vars.push_back(Reader->Reader.ReadSubExpr());
01901   C->setVarRefs(Vars);
01902 }
01903 
01904 void OMPClauseReader::VisitOMPReductionClause(OMPReductionClause *C) {
01905   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01906   C->setColonLoc(Reader->ReadSourceLocation(Record, Idx));
01907   NestedNameSpecifierLoc NNSL =
01908     Reader->Reader.ReadNestedNameSpecifierLoc(Reader->F, Record, Idx);
01909   DeclarationNameInfo DNI;
01910   Reader->ReadDeclarationNameInfo(DNI, Record, Idx);
01911   C->setQualifierLoc(NNSL);
01912   C->setNameInfo(DNI);
01913 
01914   unsigned NumVars = C->varlist_size();
01915   SmallVector<Expr *, 16> Vars;
01916   Vars.reserve(NumVars);
01917   for (unsigned i = 0; i != NumVars; ++i)
01918     Vars.push_back(Reader->Reader.ReadSubExpr());
01919   C->setVarRefs(Vars);
01920 }
01921 
01922 void OMPClauseReader::VisitOMPLinearClause(OMPLinearClause *C) {
01923   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01924   C->setColonLoc(Reader->ReadSourceLocation(Record, Idx));
01925   unsigned NumVars = C->varlist_size();
01926   SmallVector<Expr *, 16> Vars;
01927   Vars.reserve(NumVars);
01928   for (unsigned i = 0; i != NumVars; ++i)
01929     Vars.push_back(Reader->Reader.ReadSubExpr());
01930   C->setVarRefs(Vars);
01931   C->setStep(Reader->Reader.ReadSubExpr());
01932 }
01933 
01934 void OMPClauseReader::VisitOMPAlignedClause(OMPAlignedClause *C) {
01935   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01936   C->setColonLoc(Reader->ReadSourceLocation(Record, Idx));
01937   unsigned NumVars = C->varlist_size();
01938   SmallVector<Expr *, 16> Vars;
01939   Vars.reserve(NumVars);
01940   for (unsigned i = 0; i != NumVars; ++i)
01941     Vars.push_back(Reader->Reader.ReadSubExpr());
01942   C->setVarRefs(Vars);
01943   C->setAlignment(Reader->Reader.ReadSubExpr());
01944 }
01945 
01946 void OMPClauseReader::VisitOMPCopyinClause(OMPCopyinClause *C) {
01947   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01948   unsigned NumVars = C->varlist_size();
01949   SmallVector<Expr *, 16> Vars;
01950   Vars.reserve(NumVars);
01951   for (unsigned i = 0; i != NumVars; ++i)
01952     Vars.push_back(Reader->Reader.ReadSubExpr());
01953   C->setVarRefs(Vars);
01954 }
01955 
01956 void OMPClauseReader::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
01957   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01958   unsigned NumVars = C->varlist_size();
01959   SmallVector<Expr *, 16> Vars;
01960   Vars.reserve(NumVars);
01961   for (unsigned i = 0; i != NumVars; ++i)
01962     Vars.push_back(Reader->Reader.ReadSubExpr());
01963   C->setVarRefs(Vars);
01964 }
01965 
01966 void OMPClauseReader::VisitOMPFlushClause(OMPFlushClause *C) {
01967   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
01968   unsigned NumVars = C->varlist_size();
01969   SmallVector<Expr *, 16> Vars;
01970   Vars.reserve(NumVars);
01971   for (unsigned i = 0; i != NumVars; ++i)
01972     Vars.push_back(Reader->Reader.ReadSubExpr());
01973   C->setVarRefs(Vars);
01974 }
01975 
01976 //===----------------------------------------------------------------------===//
01977 // OpenMP Directives.
01978 //===----------------------------------------------------------------------===//
01979 void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
01980   E->setLocStart(ReadSourceLocation(Record, Idx));
01981   E->setLocEnd(ReadSourceLocation(Record, Idx));
01982   OMPClauseReader ClauseReader(this, Reader.getContext(), Record, Idx);
01983   SmallVector<OMPClause *, 5> Clauses;
01984   for (unsigned i = 0; i < E->getNumClauses(); ++i)
01985     Clauses.push_back(ClauseReader.readClause());
01986   E->setClauses(Clauses);
01987   if (E->hasAssociatedStmt())
01988     E->setAssociatedStmt(Reader.ReadSubStmt());
01989 }
01990 
01991 void ASTStmtReader::VisitOMPLoopDirective(OMPLoopDirective *D) {
01992   VisitStmt(D);
01993   // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream.
01994   Idx += 2;
01995   VisitOMPExecutableDirective(D);
01996   D->setIterationVariable(Reader.ReadSubExpr());
01997   D->setLastIteration(Reader.ReadSubExpr());
01998   D->setCalcLastIteration(Reader.ReadSubExpr());
01999   D->setPreCond(Reader.ReadSubExpr());
02000   auto Fst = Reader.ReadSubExpr();
02001   auto Snd = Reader.ReadSubExpr();
02002   D->setCond(Fst, Snd);
02003   D->setInit(Reader.ReadSubExpr());
02004   D->setInc(Reader.ReadSubExpr());
02005   SmallVector<Expr *, 4> Sub;
02006   unsigned CollapsedNum = D->getCollapsedNumber();
02007   Sub.reserve(CollapsedNum);
02008   for (unsigned i = 0; i < CollapsedNum; ++i)
02009     Sub.push_back(Reader.ReadSubExpr());
02010   D->setCounters(Sub);
02011   Sub.clear();
02012   for (unsigned i = 0; i < CollapsedNum; ++i)
02013     Sub.push_back(Reader.ReadSubExpr());
02014   D->setUpdates(Sub);
02015   Sub.clear();
02016   for (unsigned i = 0; i < CollapsedNum; ++i)
02017     Sub.push_back(Reader.ReadSubExpr());
02018   D->setFinals(Sub);
02019 }
02020 
02021 void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) {
02022   VisitStmt(D);
02023   // The NumClauses field was read in ReadStmtFromStream.
02024   ++Idx;
02025   VisitOMPExecutableDirective(D);
02026 }
02027 
02028 void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) {
02029   VisitOMPLoopDirective(D);
02030 }
02031 
02032 void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) {
02033   VisitOMPLoopDirective(D);
02034 }
02035 
02036 void ASTStmtReader::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
02037   VisitOMPLoopDirective(D);
02038 }
02039 
02040 void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
02041   VisitStmt(D);
02042   // The NumClauses field was read in ReadStmtFromStream.
02043   ++Idx;
02044   VisitOMPExecutableDirective(D);
02045 }
02046 
02047 void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) {
02048   VisitStmt(D);
02049   VisitOMPExecutableDirective(D);
02050 }
02051 
02052 void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) {
02053   VisitStmt(D);
02054   // The NumClauses field was read in ReadStmtFromStream.
02055   ++Idx;
02056   VisitOMPExecutableDirective(D);
02057 }
02058 
02059 void ASTStmtReader::VisitOMPMasterDirective(OMPMasterDirective *D) {
02060   VisitStmt(D);
02061   VisitOMPExecutableDirective(D);
02062 }
02063 
02064 void ASTStmtReader::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
02065   VisitStmt(D);
02066   VisitOMPExecutableDirective(D);
02067   ReadDeclarationNameInfo(D->DirName, Record, Idx);
02068 }
02069 
02070 void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
02071   VisitOMPLoopDirective(D);
02072 }
02073 
02074 void ASTStmtReader::VisitOMPParallelForSimdDirective(
02075     OMPParallelForSimdDirective *D) {
02076   VisitOMPLoopDirective(D);
02077 }
02078 
02079 void ASTStmtReader::VisitOMPParallelSectionsDirective(
02080     OMPParallelSectionsDirective *D) {
02081   VisitStmt(D);
02082   // The NumClauses field was read in ReadStmtFromStream.
02083   ++Idx;
02084   VisitOMPExecutableDirective(D);
02085 }
02086 
02087 void ASTStmtReader::VisitOMPTaskDirective(OMPTaskDirective *D) {
02088   VisitStmt(D);
02089   // The NumClauses field was read in ReadStmtFromStream.
02090   ++Idx;
02091   VisitOMPExecutableDirective(D);
02092 }
02093 
02094 void ASTStmtReader::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
02095   VisitStmt(D);
02096   VisitOMPExecutableDirective(D);
02097 }
02098 
02099 void ASTStmtReader::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
02100   VisitStmt(D);
02101   VisitOMPExecutableDirective(D);
02102 }
02103 
02104 void ASTStmtReader::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
02105   VisitStmt(D);
02106   VisitOMPExecutableDirective(D);
02107 }
02108 
02109 void ASTStmtReader::VisitOMPFlushDirective(OMPFlushDirective *D) {
02110   VisitStmt(D);
02111   // The NumClauses field was read in ReadStmtFromStream.
02112   ++Idx;
02113   VisitOMPExecutableDirective(D);
02114 }
02115 
02116 void ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
02117   VisitStmt(D);
02118   VisitOMPExecutableDirective(D);
02119 }
02120 
02121 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
02122   VisitStmt(D);
02123   // The NumClauses field was read in ReadStmtFromStream.
02124   ++Idx;
02125   VisitOMPExecutableDirective(D);
02126   D->setX(Reader.ReadSubExpr());
02127   D->setV(Reader.ReadSubExpr());
02128   D->setExpr(Reader.ReadSubExpr());
02129 }
02130 
02131 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
02132   VisitStmt(D);
02133   // The NumClauses field was read in ReadStmtFromStream.
02134   ++Idx;
02135   VisitOMPExecutableDirective(D);
02136 }
02137 
02138 void ASTStmtReader::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
02139   VisitStmt(D);
02140   // The NumClauses field was read in ReadStmtFromStream.
02141   ++Idx;
02142   VisitOMPExecutableDirective(D);
02143 }
02144 
02145 //===----------------------------------------------------------------------===//
02146 // ASTReader Implementation
02147 //===----------------------------------------------------------------------===//
02148 
02149 Stmt *ASTReader::ReadStmt(ModuleFile &F) {
02150   switch (ReadingKind) {
02151   case Read_None:
02152     llvm_unreachable("should not call this when not reading anything");
02153   case Read_Decl:
02154   case Read_Type:
02155     return ReadStmtFromStream(F);
02156   case Read_Stmt:
02157     return ReadSubStmt();
02158   }
02159 
02160   llvm_unreachable("ReadingKind not set ?");
02161 }
02162 
02163 Expr *ASTReader::ReadExpr(ModuleFile &F) {
02164   return cast_or_null<Expr>(ReadStmt(F));
02165 }
02166 
02167 Expr *ASTReader::ReadSubExpr() {
02168   return cast_or_null<Expr>(ReadSubStmt());
02169 }
02170 
02171 // Within the bitstream, expressions are stored in Reverse Polish
02172 // Notation, with each of the subexpressions preceding the
02173 // expression they are stored in. Subexpressions are stored from last to first.
02174 // To evaluate expressions, we continue reading expressions and placing them on
02175 // the stack, with expressions having operands removing those operands from the
02176 // stack. Evaluation terminates when we see a STMT_STOP record, and
02177 // the single remaining expression on the stack is our result.
02178 Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
02179 
02180   ReadingKindTracker ReadingKind(Read_Stmt, *this);
02181   llvm::BitstreamCursor &Cursor = F.DeclsCursor;
02182   
02183   // Map of offset to previously deserialized stmt. The offset points
02184   /// just after the stmt record.
02185   llvm::DenseMap<uint64_t, Stmt *> StmtEntries;
02186 
02187 #ifndef NDEBUG
02188   unsigned PrevNumStmts = StmtStack.size();
02189 #endif
02190 
02191   RecordData Record;
02192   unsigned Idx;
02193   ASTStmtReader Reader(*this, F, Cursor, Record, Idx);
02194   Stmt::EmptyShell Empty;
02195 
02196   while (true) {
02197     llvm::BitstreamEntry Entry = Cursor.advanceSkippingSubblocks();
02198     
02199     switch (Entry.Kind) {
02200     case llvm::BitstreamEntry::SubBlock: // Handled for us already.
02201     case llvm::BitstreamEntry::Error:
02202       Error("malformed block record in AST file");
02203       return nullptr;
02204     case llvm::BitstreamEntry::EndBlock:
02205       goto Done;
02206     case llvm::BitstreamEntry::Record:
02207       // The interesting case.
02208       break;
02209     }
02210 
02211     Stmt *S = nullptr;
02212     Idx = 0;
02213     Record.clear();
02214     bool Finished = false;
02215     bool IsStmtReference = false;
02216     switch ((StmtCode)Cursor.readRecord(Entry.ID, Record)) {
02217     case STMT_STOP:
02218       Finished = true;
02219       break;
02220 
02221     case STMT_REF_PTR:
02222       IsStmtReference = true;
02223       assert(StmtEntries.find(Record[0]) != StmtEntries.end() &&
02224              "No stmt was recorded for this offset reference!");
02225       S = StmtEntries[Record[Idx++]];
02226       break;
02227 
02228     case STMT_NULL_PTR:
02229       S = nullptr;
02230       break;
02231 
02232     case STMT_NULL:
02233       S = new (Context) NullStmt(Empty);
02234       break;
02235 
02236     case STMT_COMPOUND:
02237       S = new (Context) CompoundStmt(Empty);
02238       break;
02239 
02240     case STMT_CASE:
02241       S = new (Context) CaseStmt(Empty);
02242       break;
02243 
02244     case STMT_DEFAULT:
02245       S = new (Context) DefaultStmt(Empty);
02246       break;
02247 
02248     case STMT_LABEL:
02249       S = new (Context) LabelStmt(Empty);
02250       break;
02251 
02252     case STMT_ATTRIBUTED:
02253       S = AttributedStmt::CreateEmpty(
02254         Context,
02255         /*NumAttrs*/Record[ASTStmtReader::NumStmtFields]);
02256       break;
02257 
02258     case STMT_IF:
02259       S = new (Context) IfStmt(Empty);
02260       break;
02261 
02262     case STMT_SWITCH:
02263       S = new (Context) SwitchStmt(Empty);
02264       break;
02265 
02266     case STMT_WHILE:
02267       S = new (Context) WhileStmt(Empty);
02268       break;
02269 
02270     case STMT_DO:
02271       S = new (Context) DoStmt(Empty);
02272       break;
02273 
02274     case STMT_FOR:
02275       S = new (Context) ForStmt(Empty);
02276       break;
02277 
02278     case STMT_GOTO:
02279       S = new (Context) GotoStmt(Empty);
02280       break;
02281 
02282     case STMT_INDIRECT_GOTO:
02283       S = new (Context) IndirectGotoStmt(Empty);
02284       break;
02285 
02286     case STMT_CONTINUE:
02287       S = new (Context) ContinueStmt(Empty);
02288       break;
02289 
02290     case STMT_BREAK:
02291       S = new (Context) BreakStmt(Empty);
02292       break;
02293 
02294     case STMT_RETURN:
02295       S = new (Context) ReturnStmt(Empty);
02296       break;
02297 
02298     case STMT_DECL:
02299       S = new (Context) DeclStmt(Empty);
02300       break;
02301 
02302     case STMT_GCCASM:
02303       S = new (Context) GCCAsmStmt(Empty);
02304       break;
02305 
02306     case STMT_MSASM:
02307       S = new (Context) MSAsmStmt(Empty);
02308       break;
02309 
02310     case STMT_CAPTURED:
02311       S = CapturedStmt::CreateDeserialized(Context,
02312                                            Record[ASTStmtReader::NumStmtFields]);
02313       break;
02314 
02315     case EXPR_PREDEFINED:
02316       S = new (Context) PredefinedExpr(Empty);
02317       break;
02318 
02319     case EXPR_DECL_REF:
02320       S = DeclRefExpr::CreateEmpty(
02321         Context,
02322         /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
02323         /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
02324         /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 2],
02325         /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
02326           Record[ASTStmtReader::NumExprFields + 5] : 0);
02327       break;
02328 
02329     case EXPR_INTEGER_LITERAL:
02330       S = IntegerLiteral::Create(Context, Empty);
02331       break;
02332 
02333     case EXPR_FLOATING_LITERAL:
02334       S = FloatingLiteral::Create(Context, Empty);
02335       break;
02336 
02337     case EXPR_IMAGINARY_LITERAL:
02338       S = new (Context) ImaginaryLiteral(Empty);
02339       break;
02340 
02341     case EXPR_STRING_LITERAL:
02342       S = StringLiteral::CreateEmpty(Context,
02343                                      Record[ASTStmtReader::NumExprFields + 1]);
02344       break;
02345 
02346     case EXPR_CHARACTER_LITERAL:
02347       S = new (Context) CharacterLiteral(Empty);
02348       break;
02349 
02350     case EXPR_PAREN:
02351       S = new (Context) ParenExpr(Empty);
02352       break;
02353 
02354     case EXPR_PAREN_LIST:
02355       S = new (Context) ParenListExpr(Empty);
02356       break;
02357 
02358     case EXPR_UNARY_OPERATOR:
02359       S = new (Context) UnaryOperator(Empty);
02360       break;
02361 
02362     case EXPR_OFFSETOF:
02363       S = OffsetOfExpr::CreateEmpty(Context, 
02364                                     Record[ASTStmtReader::NumExprFields],
02365                                     Record[ASTStmtReader::NumExprFields + 1]);
02366       break;
02367         
02368     case EXPR_SIZEOF_ALIGN_OF:
02369       S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
02370       break;
02371 
02372     case EXPR_ARRAY_SUBSCRIPT:
02373       S = new (Context) ArraySubscriptExpr(Empty);
02374       break;
02375 
02376     case EXPR_CALL:
02377       S = new (Context) CallExpr(Context, Stmt::CallExprClass, Empty);
02378       break;
02379 
02380     case EXPR_MEMBER: {
02381       // We load everything here and fully initialize it at creation.
02382       // That way we can use MemberExpr::Create and don't have to duplicate its
02383       // logic with a MemberExpr::CreateEmpty.
02384 
02385       assert(Idx == 0);
02386       NestedNameSpecifierLoc QualifierLoc;
02387       if (Record[Idx++]) { // HasQualifier.
02388         QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
02389       }
02390 
02391       SourceLocation TemplateKWLoc;
02392       TemplateArgumentListInfo ArgInfo;
02393       bool HasTemplateKWAndArgsInfo = Record[Idx++];
02394       if (HasTemplateKWAndArgsInfo) {
02395         TemplateKWLoc = ReadSourceLocation(F, Record, Idx);
02396         unsigned NumTemplateArgs = Record[Idx++];
02397         ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx));
02398         ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx));
02399         for (unsigned i = 0; i != NumTemplateArgs; ++i)
02400           ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx));
02401       }
02402 
02403       bool HadMultipleCandidates = Record[Idx++];
02404 
02405       NamedDecl *FoundD = ReadDeclAs<NamedDecl>(F, Record, Idx);
02406       AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
02407       DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS);
02408 
02409       QualType T = readType(F, Record, Idx);
02410       ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]);
02411       ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]);
02412       Expr *Base = ReadSubExpr();
02413       ValueDecl *MemberD = ReadDeclAs<ValueDecl>(F, Record, Idx);
02414       SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx);
02415       DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc);
02416       bool IsArrow = Record[Idx++];
02417 
02418       S = MemberExpr::Create(Context, Base, IsArrow, QualifierLoc,
02419                              TemplateKWLoc, MemberD, FoundDecl, MemberNameInfo,
02420                              HasTemplateKWAndArgsInfo ? &ArgInfo : nullptr,
02421                              T, VK, OK);
02422       ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc,
02423                              MemberD->getDeclName(), Record, Idx);
02424       if (HadMultipleCandidates)
02425         cast<MemberExpr>(S)->setHadMultipleCandidates(true);
02426       break;
02427     }
02428 
02429     case EXPR_BINARY_OPERATOR:
02430       S = new (Context) BinaryOperator(Empty);
02431       break;
02432 
02433     case EXPR_COMPOUND_ASSIGN_OPERATOR:
02434       S = new (Context) CompoundAssignOperator(Empty);
02435       break;
02436 
02437     case EXPR_CONDITIONAL_OPERATOR:
02438       S = new (Context) ConditionalOperator(Empty);
02439       break;
02440 
02441     case EXPR_BINARY_CONDITIONAL_OPERATOR:
02442       S = new (Context) BinaryConditionalOperator(Empty);
02443       break;
02444 
02445     case EXPR_IMPLICIT_CAST:
02446       S = ImplicitCastExpr::CreateEmpty(Context,
02447                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
02448       break;
02449 
02450     case EXPR_CSTYLE_CAST:
02451       S = CStyleCastExpr::CreateEmpty(Context,
02452                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
02453       break;
02454 
02455     case EXPR_COMPOUND_LITERAL:
02456       S = new (Context) CompoundLiteralExpr(Empty);
02457       break;
02458 
02459     case EXPR_EXT_VECTOR_ELEMENT:
02460       S = new (Context) ExtVectorElementExpr(Empty);
02461       break;
02462 
02463     case EXPR_INIT_LIST:
02464       S = new (Context) InitListExpr(Empty);
02465       break;
02466 
02467     case EXPR_DESIGNATED_INIT:
02468       S = DesignatedInitExpr::CreateEmpty(Context,
02469                                      Record[ASTStmtReader::NumExprFields] - 1);
02470 
02471       break;
02472 
02473     case EXPR_IMPLICIT_VALUE_INIT:
02474       S = new (Context) ImplicitValueInitExpr(Empty);
02475       break;
02476 
02477     case EXPR_VA_ARG:
02478       S = new (Context) VAArgExpr(Empty);
02479       break;
02480 
02481     case EXPR_ADDR_LABEL:
02482       S = new (Context) AddrLabelExpr(Empty);
02483       break;
02484 
02485     case EXPR_STMT:
02486       S = new (Context) StmtExpr(Empty);
02487       break;
02488 
02489     case EXPR_CHOOSE:
02490       S = new (Context) ChooseExpr(Empty);
02491       break;
02492 
02493     case EXPR_GNU_NULL:
02494       S = new (Context) GNUNullExpr(Empty);
02495       break;
02496 
02497     case EXPR_SHUFFLE_VECTOR:
02498       S = new (Context) ShuffleVectorExpr(Empty);
02499       break;
02500 
02501     case EXPR_CONVERT_VECTOR:
02502       S = new (Context) ConvertVectorExpr(Empty);
02503       break;
02504 
02505     case EXPR_BLOCK:
02506       S = new (Context) BlockExpr(Empty);
02507       break;
02508 
02509     case EXPR_GENERIC_SELECTION:
02510       S = new (Context) GenericSelectionExpr(Empty);
02511       break;
02512 
02513     case EXPR_OBJC_STRING_LITERAL:
02514       S = new (Context) ObjCStringLiteral(Empty);
02515       break;
02516     case EXPR_OBJC_BOXED_EXPRESSION:
02517       S = new (Context) ObjCBoxedExpr(Empty);
02518       break;
02519     case EXPR_OBJC_ARRAY_LITERAL:
02520       S = ObjCArrayLiteral::CreateEmpty(Context,
02521                                         Record[ASTStmtReader::NumExprFields]);
02522       break;
02523     case EXPR_OBJC_DICTIONARY_LITERAL:
02524       S = ObjCDictionaryLiteral::CreateEmpty(Context,
02525             Record[ASTStmtReader::NumExprFields],
02526             Record[ASTStmtReader::NumExprFields + 1]);
02527       break;
02528     case EXPR_OBJC_ENCODE:
02529       S = new (Context) ObjCEncodeExpr(Empty);
02530       break;
02531     case EXPR_OBJC_SELECTOR_EXPR:
02532       S = new (Context) ObjCSelectorExpr(Empty);
02533       break;
02534     case EXPR_OBJC_PROTOCOL_EXPR:
02535       S = new (Context) ObjCProtocolExpr(Empty);
02536       break;
02537     case EXPR_OBJC_IVAR_REF_EXPR:
02538       S = new (Context) ObjCIvarRefExpr(Empty);
02539       break;
02540     case EXPR_OBJC_PROPERTY_REF_EXPR:
02541       S = new (Context) ObjCPropertyRefExpr(Empty);
02542       break;
02543     case EXPR_OBJC_SUBSCRIPT_REF_EXPR:
02544       S = new (Context) ObjCSubscriptRefExpr(Empty);
02545       break;
02546     case EXPR_OBJC_KVC_REF_EXPR:
02547       llvm_unreachable("mismatching AST file");
02548     case EXPR_OBJC_MESSAGE_EXPR:
02549       S = ObjCMessageExpr::CreateEmpty(Context,
02550                                      Record[ASTStmtReader::NumExprFields],
02551                                      Record[ASTStmtReader::NumExprFields + 1]);
02552       break;
02553     case EXPR_OBJC_ISA:
02554       S = new (Context) ObjCIsaExpr(Empty);
02555       break;
02556     case EXPR_OBJC_INDIRECT_COPY_RESTORE:
02557       S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
02558       break;
02559     case EXPR_OBJC_BRIDGED_CAST:
02560       S = new (Context) ObjCBridgedCastExpr(Empty);
02561       break;
02562     case STMT_OBJC_FOR_COLLECTION:
02563       S = new (Context) ObjCForCollectionStmt(Empty);
02564       break;
02565     case STMT_OBJC_CATCH:
02566       S = new (Context) ObjCAtCatchStmt(Empty);
02567       break;
02568     case STMT_OBJC_FINALLY:
02569       S = new (Context) ObjCAtFinallyStmt(Empty);
02570       break;
02571     case STMT_OBJC_AT_TRY:
02572       S = ObjCAtTryStmt::CreateEmpty(Context, 
02573                                      Record[ASTStmtReader::NumStmtFields],
02574                                      Record[ASTStmtReader::NumStmtFields + 1]);
02575       break;
02576     case STMT_OBJC_AT_SYNCHRONIZED:
02577       S = new (Context) ObjCAtSynchronizedStmt(Empty);
02578       break;
02579     case STMT_OBJC_AT_THROW:
02580       S = new (Context) ObjCAtThrowStmt(Empty);
02581       break;
02582     case STMT_OBJC_AUTORELEASE_POOL:
02583       S = new (Context) ObjCAutoreleasePoolStmt(Empty);
02584       break;
02585     case EXPR_OBJC_BOOL_LITERAL:
02586       S = new (Context) ObjCBoolLiteralExpr(Empty);
02587       break;
02588     case STMT_SEH_LEAVE:
02589       S = new (Context) SEHLeaveStmt(Empty);
02590       break;
02591     case STMT_SEH_EXCEPT:
02592       S = new (Context) SEHExceptStmt(Empty);
02593       break;
02594     case STMT_SEH_FINALLY:
02595       S = new (Context) SEHFinallyStmt(Empty);
02596       break;
02597     case STMT_SEH_TRY:
02598       S = new (Context) SEHTryStmt(Empty);
02599       break;
02600     case STMT_CXX_CATCH:
02601       S = new (Context) CXXCatchStmt(Empty);
02602       break;
02603 
02604     case STMT_CXX_TRY:
02605       S = CXXTryStmt::Create(Context, Empty,
02606              /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]);
02607       break;
02608 
02609     case STMT_CXX_FOR_RANGE:
02610       S = new (Context) CXXForRangeStmt(Empty);
02611       break;
02612 
02613     case STMT_MS_DEPENDENT_EXISTS:
02614       S = new (Context) MSDependentExistsStmt(SourceLocation(), true,
02615                                               NestedNameSpecifierLoc(),
02616                                               DeclarationNameInfo(),
02617                                               nullptr);
02618       break;
02619 
02620     case STMT_OMP_PARALLEL_DIRECTIVE:
02621       S =
02622         OMPParallelDirective::CreateEmpty(Context,
02623                                           Record[ASTStmtReader::NumStmtFields],
02624                                           Empty);
02625       break;
02626 
02627     case STMT_OMP_SIMD_DIRECTIVE: {
02628       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
02629       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
02630       S = OMPSimdDirective::CreateEmpty(Context, NumClauses,
02631                                         CollapsedNum, Empty);
02632       break;
02633     }
02634 
02635     case STMT_OMP_FOR_DIRECTIVE: {
02636       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
02637       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
02638       S = OMPForDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
02639                                        Empty);
02640       break;
02641     }
02642 
02643     case STMT_OMP_FOR_SIMD_DIRECTIVE: {
02644       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
02645       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
02646       S = OMPForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
02647                                            Empty);
02648       break;
02649     }
02650 
02651     case STMT_OMP_SECTIONS_DIRECTIVE:
02652       S = OMPSectionsDirective::CreateEmpty(
02653           Context, Record[ASTStmtReader::NumStmtFields], Empty);
02654       break;
02655 
02656     case STMT_OMP_SECTION_DIRECTIVE:
02657       S = OMPSectionDirective::CreateEmpty(Context, Empty);
02658       break;
02659 
02660     case STMT_OMP_SINGLE_DIRECTIVE:
02661       S = OMPSingleDirective::CreateEmpty(
02662           Context, Record[ASTStmtReader::NumStmtFields], Empty);
02663       break;
02664 
02665     case STMT_OMP_MASTER_DIRECTIVE:
02666       S = OMPMasterDirective::CreateEmpty(Context, Empty);
02667       break;
02668 
02669     case STMT_OMP_CRITICAL_DIRECTIVE:
02670       S = OMPCriticalDirective::CreateEmpty(Context, Empty);
02671       break;
02672 
02673     case STMT_OMP_PARALLEL_FOR_DIRECTIVE: {
02674       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
02675       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
02676       S = OMPParallelForDirective::CreateEmpty(Context, NumClauses,
02677                                                CollapsedNum, Empty);
02678       break;
02679     }
02680 
02681     case STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE: {
02682       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
02683       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1];
02684       S = OMPParallelForSimdDirective::CreateEmpty(Context, NumClauses,
02685                                                    CollapsedNum, Empty);
02686       break;
02687     }
02688 
02689     case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
02690       S = OMPParallelSectionsDirective::CreateEmpty(
02691           Context, Record[ASTStmtReader::NumStmtFields], Empty);
02692       break;
02693 
02694     case STMT_OMP_TASK_DIRECTIVE:
02695       S = OMPTaskDirective::CreateEmpty(
02696           Context, Record[ASTStmtReader::NumStmtFields], Empty);
02697       break;
02698 
02699     case STMT_OMP_TASKYIELD_DIRECTIVE:
02700       S = OMPTaskyieldDirective::CreateEmpty(Context, Empty);
02701       break;
02702 
02703     case STMT_OMP_BARRIER_DIRECTIVE:
02704       S = OMPBarrierDirective::CreateEmpty(Context, Empty);
02705       break;
02706 
02707     case STMT_OMP_TASKWAIT_DIRECTIVE:
02708       S = OMPTaskwaitDirective::CreateEmpty(Context, Empty);
02709       break;
02710 
02711     case STMT_OMP_FLUSH_DIRECTIVE:
02712       S = OMPFlushDirective::CreateEmpty(
02713           Context, Record[ASTStmtReader::NumStmtFields], Empty);
02714       break;
02715 
02716     case STMT_OMP_ORDERED_DIRECTIVE:
02717       S = OMPOrderedDirective::CreateEmpty(Context, Empty);
02718       break;
02719 
02720     case STMT_OMP_ATOMIC_DIRECTIVE:
02721       S = OMPAtomicDirective::CreateEmpty(
02722           Context, Record[ASTStmtReader::NumStmtFields], Empty);
02723       break;
02724 
02725     case STMT_OMP_TARGET_DIRECTIVE:
02726       S = OMPTargetDirective::CreateEmpty(
02727           Context, Record[ASTStmtReader::NumStmtFields], Empty);
02728       break;
02729 
02730     case STMT_OMP_TEAMS_DIRECTIVE:
02731       S = OMPTeamsDirective::CreateEmpty(
02732           Context, Record[ASTStmtReader::NumStmtFields], Empty);
02733       break;
02734 
02735     case EXPR_CXX_OPERATOR_CALL:
02736       S = new (Context) CXXOperatorCallExpr(Context, Empty);
02737       break;
02738 
02739     case EXPR_CXX_MEMBER_CALL:
02740       S = new (Context) CXXMemberCallExpr(Context, Empty);
02741       break;
02742 
02743     case EXPR_CXX_CONSTRUCT:
02744       S = new (Context) CXXConstructExpr(Empty);
02745       break;
02746 
02747     case EXPR_CXX_TEMPORARY_OBJECT:
02748       S = new (Context) CXXTemporaryObjectExpr(Empty);
02749       break;
02750 
02751     case EXPR_CXX_STATIC_CAST:
02752       S = CXXStaticCastExpr::CreateEmpty(Context,
02753                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
02754       break;
02755 
02756     case EXPR_CXX_DYNAMIC_CAST:
02757       S = CXXDynamicCastExpr::CreateEmpty(Context,
02758                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
02759       break;
02760 
02761     case EXPR_CXX_REINTERPRET_CAST:
02762       S = CXXReinterpretCastExpr::CreateEmpty(Context,
02763                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
02764       break;
02765 
02766     case EXPR_CXX_CONST_CAST:
02767       S = CXXConstCastExpr::CreateEmpty(Context);
02768       break;
02769 
02770     case EXPR_CXX_FUNCTIONAL_CAST:
02771       S = CXXFunctionalCastExpr::CreateEmpty(Context,
02772                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
02773       break;
02774 
02775     case EXPR_USER_DEFINED_LITERAL:
02776       S = new (Context) UserDefinedLiteral(Context, Empty);
02777       break;
02778 
02779     case EXPR_CXX_STD_INITIALIZER_LIST:
02780       S = new (Context) CXXStdInitializerListExpr(Empty);
02781       break;
02782 
02783     case EXPR_CXX_BOOL_LITERAL:
02784       S = new (Context) CXXBoolLiteralExpr(Empty);
02785       break;
02786 
02787     case EXPR_CXX_NULL_PTR_LITERAL:
02788       S = new (Context) CXXNullPtrLiteralExpr(Empty);
02789       break;
02790     case EXPR_CXX_TYPEID_EXPR:
02791       S = new (Context) CXXTypeidExpr(Empty, true);
02792       break;
02793     case EXPR_CXX_TYPEID_TYPE:
02794       S = new (Context) CXXTypeidExpr(Empty, false);
02795       break;
02796     case EXPR_CXX_UUIDOF_EXPR:
02797       S = new (Context) CXXUuidofExpr(Empty, true);
02798       break;
02799     case EXPR_CXX_PROPERTY_REF_EXPR:
02800       S = new (Context) MSPropertyRefExpr(Empty);
02801       break;
02802     case EXPR_CXX_UUIDOF_TYPE:
02803       S = new (Context) CXXUuidofExpr(Empty, false);
02804       break;
02805     case EXPR_CXX_THIS:
02806       S = new (Context) CXXThisExpr(Empty);
02807       break;
02808     case EXPR_CXX_THROW:
02809       S = new (Context) CXXThrowExpr(Empty);
02810       break;
02811     case EXPR_CXX_DEFAULT_ARG: {
02812       bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields];
02813       if (HasOtherExprStored) {
02814         Expr *SubExpr = ReadSubExpr();
02815         S = CXXDefaultArgExpr::Create(Context, SourceLocation(), nullptr,
02816                                       SubExpr);
02817       } else
02818         S = new (Context) CXXDefaultArgExpr(Empty);
02819       break;
02820     }
02821     case EXPR_CXX_DEFAULT_INIT:
02822       S = new (Context) CXXDefaultInitExpr(Empty);
02823       break;
02824     case EXPR_CXX_BIND_TEMPORARY:
02825       S = new (Context) CXXBindTemporaryExpr(Empty);
02826       break;
02827         
02828     case EXPR_CXX_SCALAR_VALUE_INIT:
02829       S = new (Context) CXXScalarValueInitExpr(Empty);
02830       break;
02831     case EXPR_CXX_NEW:
02832       S = new (Context) CXXNewExpr(Empty);
02833       break;
02834     case EXPR_CXX_DELETE:
02835       S = new (Context) CXXDeleteExpr(Empty);
02836       break;
02837     case EXPR_CXX_PSEUDO_DESTRUCTOR:
02838       S = new (Context) CXXPseudoDestructorExpr(Empty);
02839       break;
02840         
02841     case EXPR_EXPR_WITH_CLEANUPS:
02842       S = ExprWithCleanups::Create(Context, Empty,
02843                                    Record[ASTStmtReader::NumExprFields]);
02844       break;
02845       
02846     case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
02847       S = CXXDependentScopeMemberExpr::CreateEmpty(Context,
02848          /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
02849                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
02850                                    ? Record[ASTStmtReader::NumExprFields + 1] 
02851                                    : 0);
02852       break;
02853       
02854     case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
02855       S = DependentScopeDeclRefExpr::CreateEmpty(Context,
02856          /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
02857                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
02858                                    ? Record[ASTStmtReader::NumExprFields + 1] 
02859                                    : 0);
02860       break;
02861       
02862     case EXPR_CXX_UNRESOLVED_CONSTRUCT:
02863       S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
02864                               /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
02865       break;
02866       
02867     case EXPR_CXX_UNRESOLVED_MEMBER:
02868       S = UnresolvedMemberExpr::CreateEmpty(Context,
02869          /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
02870                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
02871                                    ? Record[ASTStmtReader::NumExprFields + 1] 
02872                                    : 0);
02873       break;
02874       
02875     case EXPR_CXX_UNRESOLVED_LOOKUP:
02876       S = UnresolvedLookupExpr::CreateEmpty(Context,
02877          /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
02878                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
02879                                    ? Record[ASTStmtReader::NumExprFields + 1] 
02880                                    : 0);
02881       break;
02882 
02883     case EXPR_TYPE_TRAIT:
02884       S = TypeTraitExpr::CreateDeserialized(Context, 
02885             Record[ASTStmtReader::NumExprFields]);
02886       break;
02887         
02888     case EXPR_ARRAY_TYPE_TRAIT:
02889       S = new (Context) ArrayTypeTraitExpr(Empty);
02890       break;
02891 
02892     case EXPR_CXX_EXPRESSION_TRAIT:
02893       S = new (Context) ExpressionTraitExpr(Empty);
02894       break;
02895 
02896     case EXPR_CXX_NOEXCEPT:
02897       S = new (Context) CXXNoexceptExpr(Empty);
02898       break;
02899 
02900     case EXPR_PACK_EXPANSION:
02901       S = new (Context) PackExpansionExpr(Empty);
02902       break;
02903         
02904     case EXPR_SIZEOF_PACK:
02905       S = new (Context) SizeOfPackExpr(Empty);
02906       break;
02907         
02908     case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
02909       S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
02910       break;
02911         
02912     case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
02913       S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
02914       break;
02915 
02916     case EXPR_FUNCTION_PARM_PACK:
02917       S = FunctionParmPackExpr::CreateEmpty(Context,
02918                                           Record[ASTStmtReader::NumExprFields]);
02919       break;
02920         
02921     case EXPR_MATERIALIZE_TEMPORARY:
02922       S = new (Context) MaterializeTemporaryExpr(Empty);
02923       break;
02924 
02925     case EXPR_CXX_FOLD:
02926       S = new (Context) CXXFoldExpr(Empty);
02927       break;
02928 
02929     case EXPR_OPAQUE_VALUE:
02930       S = new (Context) OpaqueValueExpr(Empty);
02931       break;
02932 
02933     case EXPR_CUDA_KERNEL_CALL:
02934       S = new (Context) CUDAKernelCallExpr(Context, Empty);
02935       break;
02936         
02937     case EXPR_ASTYPE:
02938       S = new (Context) AsTypeExpr(Empty);
02939       break;
02940 
02941     case EXPR_PSEUDO_OBJECT: {
02942       unsigned numSemanticExprs = Record[ASTStmtReader::NumExprFields];
02943       S = PseudoObjectExpr::Create(Context, Empty, numSemanticExprs);
02944       break;
02945     }
02946 
02947     case EXPR_ATOMIC:
02948       S = new (Context) AtomicExpr(Empty);
02949       break;
02950         
02951     case EXPR_LAMBDA: {
02952       unsigned NumCaptures = Record[ASTStmtReader::NumExprFields];
02953       unsigned NumArrayIndexVars = Record[ASTStmtReader::NumExprFields + 1];
02954       S = LambdaExpr::CreateDeserialized(Context, NumCaptures, 
02955                                          NumArrayIndexVars);
02956       break;
02957     }
02958     }
02959     
02960     // We hit a STMT_STOP, so we're done with this expression.
02961     if (Finished)
02962       break;
02963 
02964     ++NumStatementsRead;
02965 
02966     if (S && !IsStmtReference) {
02967       Reader.Visit(S);
02968       StmtEntries[Cursor.GetCurrentBitNo()] = S;
02969     }
02970 
02971 
02972     assert(Idx == Record.size() && "Invalid deserialization of statement");
02973     StmtStack.push_back(S);
02974   }
02975 Done:
02976   assert(StmtStack.size() > PrevNumStmts && "Read too many sub-stmts!");
02977   assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
02978   return StmtStack.pop_back_val();
02979 }