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