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); 138 S->LBraceLoc = ReadSourceLocation(Record, Idx); 139 S->RBraceLoc = 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->getAttrArrayPtr()); 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 = nullptr; 206 for (unsigned N = Record.size(); Idx != N; ++Idx) { 207 SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]); 208 if (PrevSC) 209 PrevSC->setNextSwitchCase(SC); 210 else 211 S->setSwitchCaseList(SC); 212 213 PrevSC = SC; 214 } 215 } 216 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::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) { 385 // FIXME: Implement coroutine serialization. 386 llvm_unreachable("unimplemented"); 387 } 388 389 void ASTStmtReader::VisitCoreturnStmt(CoreturnStmt *S) { 390 // FIXME: Implement coroutine serialization. 391 llvm_unreachable("unimplemented"); 392 } 393 394 void ASTStmtReader::VisitCoawaitExpr(CoawaitExpr *S) { 395 // FIXME: Implement coroutine serialization. 396 llvm_unreachable("unimplemented"); 397 } 398 399 void ASTStmtReader::VisitCoyieldExpr(CoyieldExpr *S) { 400 // FIXME: Implement coroutine serialization. 401 llvm_unreachable("unimplemented"); 402 } 403 404 void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) { 405 VisitStmt(S); 406 ++Idx; 407 S->setCapturedDecl(ReadDeclAs<CapturedDecl>(Record, Idx)); 408 S->setCapturedRegionKind(static_cast<CapturedRegionKind>(Record[Idx++])); 409 S->setCapturedRecordDecl(ReadDeclAs<RecordDecl>(Record, Idx)); 410 411 // Capture inits 412 for (CapturedStmt::capture_init_iterator I = S->capture_init_begin(), 413 E = S->capture_init_end(); 414 I != E; ++I) 415 *I = Reader.ReadSubExpr(); 416 417 // Body 418 S->setCapturedStmt(Reader.ReadSubStmt()); 419 S->getCapturedDecl()->setBody(S->getCapturedStmt()); 420 421 // Captures 422 for (auto &I : S->captures()) { 423 I.VarAndKind.setPointer(ReadDeclAs<VarDecl>(Record, Idx)); 424 I.VarAndKind 425 .setInt(static_cast<CapturedStmt::VariableCaptureKind>(Record[Idx++])); 426 I.Loc = ReadSourceLocation(Record, Idx); 427 } 428 } 429 430 void ASTStmtReader::VisitExpr(Expr *E) { 431 VisitStmt(E); 432 E->setType(Reader.readType(F, Record, Idx)); 433 E->setTypeDependent(Record[Idx++]); 434 E->setValueDependent(Record[Idx++]); 435 E->setInstantiationDependent(Record[Idx++]); 436 E->ExprBits.ContainsUnexpandedParameterPack = Record[Idx++]; 437 E->setValueKind(static_cast<ExprValueKind>(Record[Idx++])); 438 E->setObjectKind(static_cast<ExprObjectKind>(Record[Idx++])); 439 assert(Idx == NumExprFields && "Incorrect expression field count"); 440 } 441 442 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) { 443 VisitExpr(E); 444 E->setLocation(ReadSourceLocation(Record, Idx)); 445 E->Type = (PredefinedExpr::IdentType)Record[Idx++]; 446 E->FnName = cast_or_null<StringLiteral>(Reader.ReadSubExpr()); 447 } 448 449 void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) { 450 VisitExpr(E); 451 452 E->DeclRefExprBits.HasQualifier = Record[Idx++]; 453 E->DeclRefExprBits.HasFoundDecl = Record[Idx++]; 454 E->DeclRefExprBits.HasTemplateKWAndArgsInfo = Record[Idx++]; 455 E->DeclRefExprBits.HadMultipleCandidates = Record[Idx++]; 456 E->DeclRefExprBits.RefersToEnclosingVariableOrCapture = Record[Idx++]; 457 unsigned NumTemplateArgs = 0; 458 if (E->hasTemplateKWAndArgsInfo()) 459 NumTemplateArgs = Record[Idx++]; 460 461 if (E->hasQualifier()) 462 E->getInternalQualifierLoc() 463 = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 464 465 if (E->hasFoundDecl()) 466 E->getInternalFoundDecl() = ReadDeclAs<NamedDecl>(Record, Idx); 467 468 if (E->hasTemplateKWAndArgsInfo()) 469 ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(), 470 NumTemplateArgs); 471 472 E->setDecl(ReadDeclAs<ValueDecl>(Record, Idx)); 473 E->setLocation(ReadSourceLocation(Record, Idx)); 474 ReadDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record, Idx); 475 } 476 477 void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) { 478 VisitExpr(E); 479 E->setLocation(ReadSourceLocation(Record, Idx)); 480 E->setValue(Reader.getContext(), Reader.ReadAPInt(Record, Idx)); 481 } 482 483 void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) { 484 VisitExpr(E); 485 E->setRawSemantics(static_cast<Stmt::APFloatSemantics>(Record[Idx++])); 486 E->setExact(Record[Idx++]); 487 E->setValue(Reader.getContext(), 488 Reader.ReadAPFloat(Record, E->getSemantics(), Idx)); 489 E->setLocation(ReadSourceLocation(Record, Idx)); 490 } 491 492 void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) { 493 VisitExpr(E); 494 E->setSubExpr(Reader.ReadSubExpr()); 495 } 496 497 void ASTStmtReader::VisitStringLiteral(StringLiteral *E) { 498 VisitExpr(E); 499 unsigned Len = Record[Idx++]; 500 assert(Record[Idx] == E->getNumConcatenated() && 501 "Wrong number of concatenated tokens!"); 502 ++Idx; 503 StringLiteral::StringKind kind = 504 static_cast<StringLiteral::StringKind>(Record[Idx++]); 505 bool isPascal = Record[Idx++]; 506 507 // Read string data 508 SmallString<16> Str(&Record[Idx], &Record[Idx] + Len); 509 E->setString(Reader.getContext(), Str, kind, isPascal); 510 Idx += Len; 511 512 // Read source locations 513 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) 514 E->setStrTokenLoc(I, ReadSourceLocation(Record, Idx)); 515 } 516 517 void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) { 518 VisitExpr(E); 519 E->setValue(Record[Idx++]); 520 E->setLocation(ReadSourceLocation(Record, Idx)); 521 E->setKind(static_cast<CharacterLiteral::CharacterKind>(Record[Idx++])); 522 } 523 524 void ASTStmtReader::VisitParenExpr(ParenExpr *E) { 525 VisitExpr(E); 526 E->setLParen(ReadSourceLocation(Record, Idx)); 527 E->setRParen(ReadSourceLocation(Record, Idx)); 528 E->setSubExpr(Reader.ReadSubExpr()); 529 } 530 531 void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) { 532 VisitExpr(E); 533 unsigned NumExprs = Record[Idx++]; 534 E->Exprs = new (Reader.getContext()) Stmt*[NumExprs]; 535 for (unsigned i = 0; i != NumExprs; ++i) 536 E->Exprs[i] = Reader.ReadSubStmt(); 537 E->NumExprs = NumExprs; 538 E->LParenLoc = ReadSourceLocation(Record, Idx); 539 E->RParenLoc = ReadSourceLocation(Record, Idx); 540 } 541 542 void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) { 543 VisitExpr(E); 544 E->setSubExpr(Reader.ReadSubExpr()); 545 E->setOpcode((UnaryOperator::Opcode)Record[Idx++]); 546 E->setOperatorLoc(ReadSourceLocation(Record, Idx)); 547 } 548 549 void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { 550 typedef OffsetOfExpr::OffsetOfNode Node; 551 VisitExpr(E); 552 assert(E->getNumComponents() == Record[Idx]); 553 ++Idx; 554 assert(E->getNumExpressions() == Record[Idx]); 555 ++Idx; 556 E->setOperatorLoc(ReadSourceLocation(Record, Idx)); 557 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 558 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); 559 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 560 Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]); 561 SourceLocation Start = ReadSourceLocation(Record, Idx); 562 SourceLocation End = ReadSourceLocation(Record, Idx); 563 switch (Kind) { 564 case Node::Array: 565 E->setComponent(I, Node(Start, Record[Idx++], End)); 566 break; 567 568 case Node::Field: 569 E->setComponent(I, Node(Start, ReadDeclAs<FieldDecl>(Record, Idx), End)); 570 break; 571 572 case Node::Identifier: 573 E->setComponent(I, 574 Node(Start, 575 Reader.GetIdentifierInfo(F, Record, Idx), 576 End)); 577 break; 578 579 case Node::Base: { 580 CXXBaseSpecifier *Base = new (Reader.getContext()) CXXBaseSpecifier(); 581 *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx); 582 E->setComponent(I, Node(Base)); 583 break; 584 } 585 } 586 } 587 588 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I) 589 E->setIndexExpr(I, Reader.ReadSubExpr()); 590 } 591 592 void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { 593 VisitExpr(E); 594 E->setKind(static_cast<UnaryExprOrTypeTrait>(Record[Idx++])); 595 if (Record[Idx] == 0) { 596 E->setArgument(Reader.ReadSubExpr()); 597 ++Idx; 598 } else { 599 E->setArgument(GetTypeSourceInfo(Record, Idx)); 600 } 601 E->setOperatorLoc(ReadSourceLocation(Record, Idx)); 602 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 603 } 604 605 void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { 606 VisitExpr(E); 607 E->setLHS(Reader.ReadSubExpr()); 608 E->setRHS(Reader.ReadSubExpr()); 609 E->setRBracketLoc(ReadSourceLocation(Record, Idx)); 610 } 611 612 void ASTStmtReader::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) { 613 VisitExpr(E); 614 E->setBase(Reader.ReadSubExpr()); 615 E->setLowerBound(Reader.ReadSubExpr()); 616 E->setLength(Reader.ReadSubExpr()); 617 E->setColonLoc(ReadSourceLocation(Record, Idx)); 618 E->setRBracketLoc(ReadSourceLocation(Record, Idx)); 619 } 620 621 void ASTStmtReader::VisitCallExpr(CallExpr *E) { 622 VisitExpr(E); 623 E->setNumArgs(Reader.getContext(), Record[Idx++]); 624 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 625 E->setCallee(Reader.ReadSubExpr()); 626 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 627 E->setArg(I, Reader.ReadSubExpr()); 628 } 629 630 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { 631 VisitCallExpr(E); 632 } 633 634 void ASTStmtReader::VisitMemberExpr(MemberExpr *E) { 635 // Don't call VisitExpr, this is fully initialized at creation. 636 assert(E->getStmtClass() == Stmt::MemberExprClass && 637 "It's a subclass, we must advance Idx!"); 638 } 639 640 void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) { 641 VisitExpr(E); 642 E->setBase(Reader.ReadSubExpr()); 643 E->setIsaMemberLoc(ReadSourceLocation(Record, Idx)); 644 E->setOpLoc(ReadSourceLocation(Record, Idx)); 645 E->setArrow(Record[Idx++]); 646 } 647 648 void ASTStmtReader:: 649 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 650 VisitExpr(E); 651 E->Operand = Reader.ReadSubExpr(); 652 E->setShouldCopy(Record[Idx++]); 653 } 654 655 void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 656 VisitExplicitCastExpr(E); 657 E->LParenLoc = ReadSourceLocation(Record, Idx); 658 E->BridgeKeywordLoc = ReadSourceLocation(Record, Idx); 659 E->Kind = Record[Idx++]; 660 } 661 662 void ASTStmtReader::VisitCastExpr(CastExpr *E) { 663 VisitExpr(E); 664 unsigned NumBaseSpecs = Record[Idx++]; 665 assert(NumBaseSpecs == E->path_size()); 666 E->setSubExpr(Reader.ReadSubExpr()); 667 E->setCastKind((CastKind)Record[Idx++]); 668 CastExpr::path_iterator BaseI = E->path_begin(); 669 while (NumBaseSpecs--) { 670 CXXBaseSpecifier *BaseSpec = new (Reader.getContext()) CXXBaseSpecifier; 671 *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx); 672 *BaseI++ = BaseSpec; 673 } 674 } 675 676 void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) { 677 VisitExpr(E); 678 E->setLHS(Reader.ReadSubExpr()); 679 E->setRHS(Reader.ReadSubExpr()); 680 E->setOpcode((BinaryOperator::Opcode)Record[Idx++]); 681 E->setOperatorLoc(ReadSourceLocation(Record, Idx)); 682 E->setFPContractable((bool)Record[Idx++]); 683 } 684 685 void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) { 686 VisitBinaryOperator(E); 687 E->setComputationLHSType(Reader.readType(F, Record, Idx)); 688 E->setComputationResultType(Reader.readType(F, Record, Idx)); 689 } 690 691 void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) { 692 VisitExpr(E); 693 E->SubExprs[ConditionalOperator::COND] = Reader.ReadSubExpr(); 694 E->SubExprs[ConditionalOperator::LHS] = Reader.ReadSubExpr(); 695 E->SubExprs[ConditionalOperator::RHS] = Reader.ReadSubExpr(); 696 E->QuestionLoc = ReadSourceLocation(Record, Idx); 697 E->ColonLoc = ReadSourceLocation(Record, Idx); 698 } 699 700 void 701 ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { 702 VisitExpr(E); 703 E->OpaqueValue = cast<OpaqueValueExpr>(Reader.ReadSubExpr()); 704 E->SubExprs[BinaryConditionalOperator::COMMON] = Reader.ReadSubExpr(); 705 E->SubExprs[BinaryConditionalOperator::COND] = Reader.ReadSubExpr(); 706 E->SubExprs[BinaryConditionalOperator::LHS] = Reader.ReadSubExpr(); 707 E->SubExprs[BinaryConditionalOperator::RHS] = Reader.ReadSubExpr(); 708 E->QuestionLoc = ReadSourceLocation(Record, Idx); 709 E->ColonLoc = ReadSourceLocation(Record, Idx); 710 } 711 712 void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) { 713 VisitCastExpr(E); 714 } 715 716 void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) { 717 VisitCastExpr(E); 718 E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx)); 719 } 720 721 void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) { 722 VisitExplicitCastExpr(E); 723 E->setLParenLoc(ReadSourceLocation(Record, Idx)); 724 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 725 } 726 727 void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { 728 VisitExpr(E); 729 E->setLParenLoc(ReadSourceLocation(Record, Idx)); 730 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); 731 E->setInitializer(Reader.ReadSubExpr()); 732 E->setFileScope(Record[Idx++]); 733 } 734 735 void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { 736 VisitExpr(E); 737 E->setBase(Reader.ReadSubExpr()); 738 E->setAccessor(Reader.GetIdentifierInfo(F, Record, Idx)); 739 E->setAccessorLoc(ReadSourceLocation(Record, Idx)); 740 } 741 742 void ASTStmtReader::VisitInitListExpr(InitListExpr *E) { 743 VisitExpr(E); 744 if (InitListExpr *SyntForm = cast_or_null<InitListExpr>(Reader.ReadSubStmt())) 745 E->setSyntacticForm(SyntForm); 746 E->setLBraceLoc(ReadSourceLocation(Record, Idx)); 747 E->setRBraceLoc(ReadSourceLocation(Record, Idx)); 748 bool isArrayFiller = Record[Idx++]; 749 Expr *filler = nullptr; 750 if (isArrayFiller) { 751 filler = Reader.ReadSubExpr(); 752 E->ArrayFillerOrUnionFieldInit = filler; 753 } else 754 E->ArrayFillerOrUnionFieldInit = ReadDeclAs<FieldDecl>(Record, Idx); 755 E->sawArrayRangeDesignator(Record[Idx++]); 756 unsigned NumInits = Record[Idx++]; 757 E->reserveInits(Reader.getContext(), NumInits); 758 if (isArrayFiller) { 759 for (unsigned I = 0; I != NumInits; ++I) { 760 Expr *init = Reader.ReadSubExpr(); 761 E->updateInit(Reader.getContext(), I, init ? init : filler); 762 } 763 } else { 764 for (unsigned I = 0; I != NumInits; ++I) 765 E->updateInit(Reader.getContext(), I, Reader.ReadSubExpr()); 766 } 767 } 768 769 void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { 770 typedef DesignatedInitExpr::Designator Designator; 771 772 VisitExpr(E); 773 unsigned NumSubExprs = Record[Idx++]; 774 assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs"); 775 for (unsigned I = 0; I != NumSubExprs; ++I) 776 E->setSubExpr(I, Reader.ReadSubExpr()); 777 E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx)); 778 E->setGNUSyntax(Record[Idx++]); 779 780 SmallVector<Designator, 4> Designators; 781 while (Idx < Record.size()) { 782 switch ((DesignatorTypes)Record[Idx++]) { 783 case DESIG_FIELD_DECL: { 784 FieldDecl *Field = ReadDeclAs<FieldDecl>(Record, Idx); 785 SourceLocation DotLoc 786 = ReadSourceLocation(Record, Idx); 787 SourceLocation FieldLoc 788 = ReadSourceLocation(Record, Idx); 789 Designators.push_back(Designator(Field->getIdentifier(), DotLoc, 790 FieldLoc)); 791 Designators.back().setField(Field); 792 break; 793 } 794 795 case DESIG_FIELD_NAME: { 796 const IdentifierInfo *Name = Reader.GetIdentifierInfo(F, Record, Idx); 797 SourceLocation DotLoc 798 = ReadSourceLocation(Record, Idx); 799 SourceLocation FieldLoc 800 = ReadSourceLocation(Record, Idx); 801 Designators.push_back(Designator(Name, DotLoc, FieldLoc)); 802 break; 803 } 804 805 case DESIG_ARRAY: { 806 unsigned Index = Record[Idx++]; 807 SourceLocation LBracketLoc 808 = ReadSourceLocation(Record, Idx); 809 SourceLocation RBracketLoc 810 = ReadSourceLocation(Record, Idx); 811 Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc)); 812 break; 813 } 814 815 case DESIG_ARRAY_RANGE: { 816 unsigned Index = Record[Idx++]; 817 SourceLocation LBracketLoc 818 = ReadSourceLocation(Record, Idx); 819 SourceLocation EllipsisLoc 820 = ReadSourceLocation(Record, Idx); 821 SourceLocation RBracketLoc 822 = ReadSourceLocation(Record, Idx); 823 Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc, 824 RBracketLoc)); 825 break; 826 } 827 } 828 } 829 E->setDesignators(Reader.getContext(), 830 Designators.data(), Designators.size()); 831 } 832 833 void ASTStmtReader::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) { 834 VisitExpr(E); 835 E->setBase(Reader.ReadSubExpr()); 836 E->setUpdater(Reader.ReadSubExpr()); 837 } 838 839 void ASTStmtReader::VisitNoInitExpr(NoInitExpr *E) { 840 VisitExpr(E); 841 } 842 843 void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { 844 VisitExpr(E); 845 } 846 847 void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) { 848 VisitExpr(E); 849 E->setSubExpr(Reader.ReadSubExpr()); 850 E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx)); 851 E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); 852 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 853 E->setIsMicrosoftABI(Record[Idx++]); 854 } 855 856 void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) { 857 VisitExpr(E); 858 E->setAmpAmpLoc(ReadSourceLocation(Record, Idx)); 859 E->setLabelLoc(ReadSourceLocation(Record, Idx)); 860 E->setLabel(ReadDeclAs<LabelDecl>(Record, Idx)); 861 } 862 863 void ASTStmtReader::VisitStmtExpr(StmtExpr *E) { 864 VisitExpr(E); 865 E->setLParenLoc(ReadSourceLocation(Record, Idx)); 866 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 867 E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt())); 868 } 869 870 void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) { 871 VisitExpr(E); 872 E->setCond(Reader.ReadSubExpr()); 873 E->setLHS(Reader.ReadSubExpr()); 874 E->setRHS(Reader.ReadSubExpr()); 875 E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); 876 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 877 E->setIsConditionTrue(Record[Idx++]); 878 } 879 880 void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) { 881 VisitExpr(E); 882 E->setTokenLocation(ReadSourceLocation(Record, Idx)); 883 } 884 885 void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { 886 VisitExpr(E); 887 SmallVector<Expr *, 16> Exprs; 888 unsigned NumExprs = Record[Idx++]; 889 while (NumExprs--) 890 Exprs.push_back(Reader.ReadSubExpr()); 891 E->setExprs(Reader.getContext(), Exprs); 892 E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); 893 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 894 } 895 896 void ASTStmtReader::VisitConvertVectorExpr(ConvertVectorExpr *E) { 897 VisitExpr(E); 898 E->BuiltinLoc = ReadSourceLocation(Record, Idx); 899 E->RParenLoc = ReadSourceLocation(Record, Idx); 900 E->TInfo = GetTypeSourceInfo(Record, Idx); 901 E->SrcExpr = Reader.ReadSubExpr(); 902 } 903 904 void ASTStmtReader::VisitBlockExpr(BlockExpr *E) { 905 VisitExpr(E); 906 E->setBlockDecl(ReadDeclAs<BlockDecl>(Record, Idx)); 907 } 908 909 void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) { 910 VisitExpr(E); 911 E->NumAssocs = Record[Idx++]; 912 E->AssocTypes = new (Reader.getContext()) TypeSourceInfo*[E->NumAssocs]; 913 E->SubExprs = 914 new(Reader.getContext()) Stmt*[GenericSelectionExpr::END_EXPR+E->NumAssocs]; 915 916 E->SubExprs[GenericSelectionExpr::CONTROLLING] = Reader.ReadSubExpr(); 917 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) { 918 E->AssocTypes[I] = GetTypeSourceInfo(Record, Idx); 919 E->SubExprs[GenericSelectionExpr::END_EXPR+I] = Reader.ReadSubExpr(); 920 } 921 E->ResultIndex = Record[Idx++]; 922 923 E->GenericLoc = ReadSourceLocation(Record, Idx); 924 E->DefaultLoc = ReadSourceLocation(Record, Idx); 925 E->RParenLoc = ReadSourceLocation(Record, Idx); 926 } 927 928 void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) { 929 VisitExpr(E); 930 unsigned numSemanticExprs = Record[Idx++]; 931 assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs); 932 E->PseudoObjectExprBits.ResultIndex = Record[Idx++]; 933 934 // Read the syntactic expression. 935 E->getSubExprsBuffer()[0] = Reader.ReadSubExpr(); 936 937 // Read all the semantic expressions. 938 for (unsigned i = 0; i != numSemanticExprs; ++i) { 939 Expr *subExpr = Reader.ReadSubExpr(); 940 E->getSubExprsBuffer()[i+1] = subExpr; 941 } 942 } 943 944 void ASTStmtReader::VisitAtomicExpr(AtomicExpr *E) { 945 VisitExpr(E); 946 E->Op = AtomicExpr::AtomicOp(Record[Idx++]); 947 E->NumSubExprs = AtomicExpr::getNumSubExprs(E->Op); 948 for (unsigned I = 0; I != E->NumSubExprs; ++I) 949 E->SubExprs[I] = Reader.ReadSubExpr(); 950 E->BuiltinLoc = ReadSourceLocation(Record, Idx); 951 E->RParenLoc = ReadSourceLocation(Record, Idx); 952 } 953 954 //===----------------------------------------------------------------------===// 955 // Objective-C Expressions and Statements 956 957 void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) { 958 VisitExpr(E); 959 E->setString(cast<StringLiteral>(Reader.ReadSubStmt())); 960 E->setAtLoc(ReadSourceLocation(Record, Idx)); 961 } 962 963 void ASTStmtReader::VisitObjCBoxedExpr(ObjCBoxedExpr *E) { 964 VisitExpr(E); 965 // could be one of several IntegerLiteral, FloatLiteral, etc. 966 E->SubExpr = Reader.ReadSubStmt(); 967 E->BoxingMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx); 968 E->Range = ReadSourceRange(Record, Idx); 969 } 970 971 void ASTStmtReader::VisitObjCArrayLiteral(ObjCArrayLiteral *E) { 972 VisitExpr(E); 973 unsigned NumElements = Record[Idx++]; 974 assert(NumElements == E->getNumElements() && "Wrong number of elements"); 975 Expr **Elements = E->getElements(); 976 for (unsigned I = 0, N = NumElements; I != N; ++I) 977 Elements[I] = Reader.ReadSubExpr(); 978 E->ArrayWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx); 979 E->Range = ReadSourceRange(Record, Idx); 980 } 981 982 void ASTStmtReader::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) { 983 VisitExpr(E); 984 unsigned NumElements = Record[Idx++]; 985 assert(NumElements == E->getNumElements() && "Wrong number of elements"); 986 bool HasPackExpansions = Record[Idx++]; 987 assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch"); 988 ObjCDictionaryLiteral::KeyValuePair *KeyValues = E->getKeyValues(); 989 ObjCDictionaryLiteral::ExpansionData *Expansions = E->getExpansionData(); 990 for (unsigned I = 0; I != NumElements; ++I) { 991 KeyValues[I].Key = Reader.ReadSubExpr(); 992 KeyValues[I].Value = Reader.ReadSubExpr(); 993 if (HasPackExpansions) { 994 Expansions[I].EllipsisLoc = ReadSourceLocation(Record, Idx); 995 Expansions[I].NumExpansionsPlusOne = Record[Idx++]; 996 } 997 } 998 E->DictWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx); 999 E->Range = ReadSourceRange(Record, Idx); 1000 } 1001 1002 void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { 1003 VisitExpr(E); 1004 E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); 1005 E->setAtLoc(ReadSourceLocation(Record, Idx)); 1006 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 1007 } 1008 1009 void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { 1010 VisitExpr(E); 1011 E->setSelector(Reader.ReadSelector(F, Record, Idx)); 1012 E->setAtLoc(ReadSourceLocation(Record, Idx)); 1013 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 1014 } 1015 1016 void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { 1017 VisitExpr(E); 1018 E->setProtocol(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 1019 E->setAtLoc(ReadSourceLocation(Record, Idx)); 1020 E->ProtoLoc = ReadSourceLocation(Record, Idx); 1021 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 1022 } 1023 1024 void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { 1025 VisitExpr(E); 1026 E->setDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx)); 1027 E->setLocation(ReadSourceLocation(Record, Idx)); 1028 E->setOpLoc(ReadSourceLocation(Record, Idx)); 1029 E->setBase(Reader.ReadSubExpr()); 1030 E->setIsArrow(Record[Idx++]); 1031 E->setIsFreeIvar(Record[Idx++]); 1032 } 1033 1034 void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 1035 VisitExpr(E); 1036 unsigned MethodRefFlags = Record[Idx++]; 1037 bool Implicit = Record[Idx++] != 0; 1038 if (Implicit) { 1039 ObjCMethodDecl *Getter = ReadDeclAs<ObjCMethodDecl>(Record, Idx); 1040 ObjCMethodDecl *Setter = ReadDeclAs<ObjCMethodDecl>(Record, Idx); 1041 E->setImplicitProperty(Getter, Setter, MethodRefFlags); 1042 } else { 1043 E->setExplicitProperty(ReadDeclAs<ObjCPropertyDecl>(Record, Idx), 1044 MethodRefFlags); 1045 } 1046 E->setLocation(ReadSourceLocation(Record, Idx)); 1047 E->setReceiverLocation(ReadSourceLocation(Record, Idx)); 1048 switch (Record[Idx++]) { 1049 case 0: 1050 E->setBase(Reader.ReadSubExpr()); 1051 break; 1052 case 1: 1053 E->setSuperReceiver(Reader.readType(F, Record, Idx)); 1054 break; 1055 case 2: 1056 E->setClassReceiver(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx)); 1057 break; 1058 } 1059 } 1060 1061 void ASTStmtReader::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { 1062 VisitExpr(E); 1063 E->setRBracket(ReadSourceLocation(Record, Idx)); 1064 E->setBaseExpr(Reader.ReadSubExpr()); 1065 E->setKeyExpr(Reader.ReadSubExpr()); 1066 E->GetAtIndexMethodDecl = ReadDeclAs<ObjCMethodDecl>(Record, Idx); 1067 E->SetAtIndexMethodDecl = ReadDeclAs<ObjCMethodDecl>(Record, Idx); 1068 } 1069 1070 void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { 1071 VisitExpr(E); 1072 assert(Record[Idx] == E->getNumArgs()); 1073 ++Idx; 1074 unsigned NumStoredSelLocs = Record[Idx++]; 1075 E->SelLocsKind = Record[Idx++]; 1076 E->setDelegateInitCall(Record[Idx++]); 1077 E->IsImplicit = Record[Idx++]; 1078 ObjCMessageExpr::ReceiverKind Kind 1079 = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]); 1080 switch (Kind) { 1081 case ObjCMessageExpr::Instance: 1082 E->setInstanceReceiver(Reader.ReadSubExpr()); 1083 break; 1084 1085 case ObjCMessageExpr::Class: 1086 E->setClassReceiver(GetTypeSourceInfo(Record, Idx)); 1087 break; 1088 1089 case ObjCMessageExpr::SuperClass: 1090 case ObjCMessageExpr::SuperInstance: { 1091 QualType T = Reader.readType(F, Record, Idx); 1092 SourceLocation SuperLoc = ReadSourceLocation(Record, Idx); 1093 E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance); 1094 break; 1095 } 1096 } 1097 1098 assert(Kind == E->getReceiverKind()); 1099 1100 if (Record[Idx++]) 1101 E->setMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx)); 1102 else 1103 E->setSelector(Reader.ReadSelector(F, Record, Idx)); 1104 1105 E->LBracLoc = ReadSourceLocation(Record, Idx); 1106 E->RBracLoc = ReadSourceLocation(Record, Idx); 1107 1108 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 1109 E->setArg(I, Reader.ReadSubExpr()); 1110 1111 SourceLocation *Locs = E->getStoredSelLocs(); 1112 for (unsigned I = 0; I != NumStoredSelLocs; ++I) 1113 Locs[I] = ReadSourceLocation(Record, Idx); 1114 } 1115 1116 void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { 1117 VisitStmt(S); 1118 S->setElement(Reader.ReadSubStmt()); 1119 S->setCollection(Reader.ReadSubExpr()); 1120 S->setBody(Reader.ReadSubStmt()); 1121 S->setForLoc(ReadSourceLocation(Record, Idx)); 1122 S->setRParenLoc(ReadSourceLocation(Record, Idx)); 1123 } 1124 1125 void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { 1126 VisitStmt(S); 1127 S->setCatchBody(Reader.ReadSubStmt()); 1128 S->setCatchParamDecl(ReadDeclAs<VarDecl>(Record, Idx)); 1129 S->setAtCatchLoc(ReadSourceLocation(Record, Idx)); 1130 S->setRParenLoc(ReadSourceLocation(Record, Idx)); 1131 } 1132 1133 void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 1134 VisitStmt(S); 1135 S->setFinallyBody(Reader.ReadSubStmt()); 1136 S->setAtFinallyLoc(ReadSourceLocation(Record, Idx)); 1137 } 1138 1139 void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) { 1140 VisitStmt(S); 1141 S->setSubStmt(Reader.ReadSubStmt()); 1142 S->setAtLoc(ReadSourceLocation(Record, Idx)); 1143 } 1144 1145 void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { 1146 VisitStmt(S); 1147 assert(Record[Idx] == S->getNumCatchStmts()); 1148 ++Idx; 1149 bool HasFinally = Record[Idx++]; 1150 S->setTryBody(Reader.ReadSubStmt()); 1151 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) 1152 S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt())); 1153 1154 if (HasFinally) 1155 S->setFinallyStmt(Reader.ReadSubStmt()); 1156 S->setAtTryLoc(ReadSourceLocation(Record, Idx)); 1157 } 1158 1159 void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { 1160 VisitStmt(S); 1161 S->setSynchExpr(Reader.ReadSubStmt()); 1162 S->setSynchBody(Reader.ReadSubStmt()); 1163 S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx)); 1164 } 1165 1166 void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { 1167 VisitStmt(S); 1168 S->setThrowExpr(Reader.ReadSubStmt()); 1169 S->setThrowLoc(ReadSourceLocation(Record, Idx)); 1170 } 1171 1172 void ASTStmtReader::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { 1173 VisitExpr(E); 1174 E->setValue(Record[Idx++]); 1175 E->setLocation(ReadSourceLocation(Record, Idx)); 1176 } 1177 1178 //===----------------------------------------------------------------------===// 1179 // C++ Expressions and Statements 1180 //===----------------------------------------------------------------------===// 1181 1182 void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) { 1183 VisitStmt(S); 1184 S->CatchLoc = ReadSourceLocation(Record, Idx); 1185 S->ExceptionDecl = ReadDeclAs<VarDecl>(Record, Idx); 1186 S->HandlerBlock = Reader.ReadSubStmt(); 1187 } 1188 1189 void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) { 1190 VisitStmt(S); 1191 assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?"); 1192 ++Idx; 1193 S->TryLoc = ReadSourceLocation(Record, Idx); 1194 S->getStmts()[0] = Reader.ReadSubStmt(); 1195 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i) 1196 S->getStmts()[i + 1] = Reader.ReadSubStmt(); 1197 } 1198 1199 void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) { 1200 VisitStmt(S); 1201 S->ForLoc = ReadSourceLocation(Record, Idx); 1202 S->CoawaitLoc = ReadSourceLocation(Record, Idx); 1203 S->ColonLoc = ReadSourceLocation(Record, Idx); 1204 S->RParenLoc = ReadSourceLocation(Record, Idx); 1205 S->setRangeStmt(Reader.ReadSubStmt()); 1206 S->setBeginEndStmt(Reader.ReadSubStmt()); 1207 S->setCond(Reader.ReadSubExpr()); 1208 S->setInc(Reader.ReadSubExpr()); 1209 S->setLoopVarStmt(Reader.ReadSubStmt()); 1210 S->setBody(Reader.ReadSubStmt()); 1211 } 1212 1213 void ASTStmtReader::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) { 1214 VisitStmt(S); 1215 S->KeywordLoc = ReadSourceLocation(Record, Idx); 1216 S->IsIfExists = Record[Idx++]; 1217 S->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1218 ReadDeclarationNameInfo(S->NameInfo, Record, Idx); 1219 S->SubStmt = Reader.ReadSubStmt(); 1220 } 1221 1222 void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 1223 VisitCallExpr(E); 1224 E->Operator = (OverloadedOperatorKind)Record[Idx++]; 1225 E->Range = Reader.ReadSourceRange(F, Record, Idx); 1226 E->setFPContractable((bool)Record[Idx++]); 1227 } 1228 1229 void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) { 1230 VisitExpr(E); 1231 E->NumArgs = Record[Idx++]; 1232 if (E->NumArgs) 1233 E->Args = new (Reader.getContext()) Stmt*[E->NumArgs]; 1234 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 1235 E->setArg(I, Reader.ReadSubExpr()); 1236 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx)); 1237 E->setLocation(ReadSourceLocation(Record, Idx)); 1238 E->setElidable(Record[Idx++]); 1239 E->setHadMultipleCandidates(Record[Idx++]); 1240 E->setListInitialization(Record[Idx++]); 1241 E->setStdInitListInitialization(Record[Idx++]); 1242 E->setRequiresZeroInitialization(Record[Idx++]); 1243 E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]); 1244 E->ParenOrBraceRange = ReadSourceRange(Record, Idx); 1245 } 1246 1247 void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { 1248 VisitCXXConstructExpr(E); 1249 E->Type = GetTypeSourceInfo(Record, Idx); 1250 } 1251 1252 void ASTStmtReader::VisitLambdaExpr(LambdaExpr *E) { 1253 VisitExpr(E); 1254 unsigned NumCaptures = Record[Idx++]; 1255 assert(NumCaptures == E->NumCaptures);(void)NumCaptures; 1256 unsigned NumArrayIndexVars = Record[Idx++]; 1257 E->IntroducerRange = ReadSourceRange(Record, Idx); 1258 E->CaptureDefault = static_cast<LambdaCaptureDefault>(Record[Idx++]); 1259 E->CaptureDefaultLoc = ReadSourceLocation(Record, Idx); 1260 E->ExplicitParams = Record[Idx++]; 1261 E->ExplicitResultType = Record[Idx++]; 1262 E->ClosingBrace = ReadSourceLocation(Record, Idx); 1263 1264 // Read capture initializers. 1265 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(), 1266 CEnd = E->capture_init_end(); 1267 C != CEnd; ++C) 1268 *C = Reader.ReadSubExpr(); 1269 1270 // Read array capture index variables. 1271 if (NumArrayIndexVars > 0) { 1272 unsigned *ArrayIndexStarts = E->getArrayIndexStarts(); 1273 for (unsigned I = 0; I != NumCaptures + 1; ++I) 1274 ArrayIndexStarts[I] = Record[Idx++]; 1275 1276 VarDecl **ArrayIndexVars = E->getArrayIndexVars(); 1277 for (unsigned I = 0; I != NumArrayIndexVars; ++I) 1278 ArrayIndexVars[I] = ReadDeclAs<VarDecl>(Record, Idx); 1279 } 1280 } 1281 1282 void 1283 ASTStmtReader::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) { 1284 VisitExpr(E); 1285 E->SubExpr = Reader.ReadSubExpr(); 1286 } 1287 1288 void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { 1289 VisitExplicitCastExpr(E); 1290 SourceRange R = ReadSourceRange(Record, Idx); 1291 E->Loc = R.getBegin(); 1292 E->RParenLoc = R.getEnd(); 1293 R = ReadSourceRange(Record, Idx); 1294 E->AngleBrackets = R; 1295 } 1296 1297 void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) { 1298 return VisitCXXNamedCastExpr(E); 1299 } 1300 1301 void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 1302 return VisitCXXNamedCastExpr(E); 1303 } 1304 1305 void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) { 1306 return VisitCXXNamedCastExpr(E); 1307 } 1308 1309 void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) { 1310 return VisitCXXNamedCastExpr(E); 1311 } 1312 1313 void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { 1314 VisitExplicitCastExpr(E); 1315 E->setLParenLoc(ReadSourceLocation(Record, Idx)); 1316 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 1317 } 1318 1319 void ASTStmtReader::VisitUserDefinedLiteral(UserDefinedLiteral *E) { 1320 VisitCallExpr(E); 1321 E->UDSuffixLoc = ReadSourceLocation(Record, Idx); 1322 } 1323 1324 void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 1325 VisitExpr(E); 1326 E->setValue(Record[Idx++]); 1327 E->setLocation(ReadSourceLocation(Record, Idx)); 1328 } 1329 1330 void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { 1331 VisitExpr(E); 1332 E->setLocation(ReadSourceLocation(Record, Idx)); 1333 } 1334 1335 void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) { 1336 VisitExpr(E); 1337 E->setSourceRange(ReadSourceRange(Record, Idx)); 1338 if (E->isTypeOperand()) { // typeid(int) 1339 E->setTypeOperandSourceInfo( 1340 GetTypeSourceInfo(Record, Idx)); 1341 return; 1342 } 1343 1344 // typeid(42+2) 1345 E->setExprOperand(Reader.ReadSubExpr()); 1346 } 1347 1348 void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) { 1349 VisitExpr(E); 1350 E->setLocation(ReadSourceLocation(Record, Idx)); 1351 E->setImplicit(Record[Idx++]); 1352 } 1353 1354 void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) { 1355 VisitExpr(E); 1356 E->ThrowLoc = ReadSourceLocation(Record, Idx); 1357 E->Op = Reader.ReadSubExpr(); 1358 E->IsThrownVariableInScope = Record[Idx++]; 1359 } 1360 1361 void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 1362 VisitExpr(E); 1363 1364 assert((bool)Record[Idx] == E->Param.getInt() && "We messed up at creation ?"); 1365 ++Idx; // HasOtherExprStored and SubExpr was handled during creation. 1366 E->Param.setPointer(ReadDeclAs<ParmVarDecl>(Record, Idx)); 1367 E->Loc = ReadSourceLocation(Record, Idx); 1368 } 1369 1370 void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { 1371 VisitExpr(E); 1372 E->Field = ReadDeclAs<FieldDecl>(Record, Idx); 1373 E->Loc = ReadSourceLocation(Record, Idx); 1374 } 1375 1376 void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 1377 VisitExpr(E); 1378 E->setTemporary(Reader.ReadCXXTemporary(F, Record, Idx)); 1379 E->setSubExpr(Reader.ReadSubExpr()); 1380 } 1381 1382 void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { 1383 VisitExpr(E); 1384 E->TypeInfo = GetTypeSourceInfo(Record, Idx); 1385 E->RParenLoc = ReadSourceLocation(Record, Idx); 1386 } 1387 1388 void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) { 1389 VisitExpr(E); 1390 E->GlobalNew = Record[Idx++]; 1391 bool isArray = Record[Idx++]; 1392 E->UsualArrayDeleteWantsSize = Record[Idx++]; 1393 unsigned NumPlacementArgs = Record[Idx++]; 1394 E->StoredInitializationStyle = Record[Idx++]; 1395 E->setOperatorNew(ReadDeclAs<FunctionDecl>(Record, Idx)); 1396 E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx)); 1397 E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx); 1398 E->TypeIdParens = ReadSourceRange(Record, Idx); 1399 E->Range = ReadSourceRange(Record, Idx); 1400 E->DirectInitRange = ReadSourceRange(Record, Idx); 1401 1402 E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs, 1403 E->StoredInitializationStyle != 0); 1404 1405 // Install all the subexpressions. 1406 for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end(); 1407 I != e; ++I) 1408 *I = Reader.ReadSubStmt(); 1409 } 1410 1411 void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) { 1412 VisitExpr(E); 1413 E->GlobalDelete = Record[Idx++]; 1414 E->ArrayForm = Record[Idx++]; 1415 E->ArrayFormAsWritten = Record[Idx++]; 1416 E->UsualArrayDeleteWantsSize = Record[Idx++]; 1417 E->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx); 1418 E->Argument = Reader.ReadSubExpr(); 1419 E->Loc = ReadSourceLocation(Record, Idx); 1420 } 1421 1422 void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { 1423 VisitExpr(E); 1424 1425 E->Base = Reader.ReadSubExpr(); 1426 E->IsArrow = Record[Idx++]; 1427 E->OperatorLoc = ReadSourceLocation(Record, Idx); 1428 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1429 E->ScopeType = GetTypeSourceInfo(Record, Idx); 1430 E->ColonColonLoc = ReadSourceLocation(Record, Idx); 1431 E->TildeLoc = ReadSourceLocation(Record, Idx); 1432 1433 IdentifierInfo *II = Reader.GetIdentifierInfo(F, Record, Idx); 1434 if (II) 1435 E->setDestroyedType(II, ReadSourceLocation(Record, Idx)); 1436 else 1437 E->setDestroyedType(GetTypeSourceInfo(Record, Idx)); 1438 } 1439 1440 void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) { 1441 VisitExpr(E); 1442 1443 unsigned NumObjects = Record[Idx++]; 1444 assert(NumObjects == E->getNumObjects()); 1445 for (unsigned i = 0; i != NumObjects; ++i) 1446 E->getObjectsBuffer()[i] = ReadDeclAs<BlockDecl>(Record, Idx); 1447 1448 E->SubExpr = Reader.ReadSubExpr(); 1449 } 1450 1451 void 1452 ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){ 1453 VisitExpr(E); 1454 1455 if (Record[Idx++]) // HasTemplateKWAndArgsInfo 1456 ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(), 1457 /*NumTemplateArgs=*/Record[Idx++]); 1458 1459 E->Base = Reader.ReadSubExpr(); 1460 E->BaseType = Reader.readType(F, Record, Idx); 1461 E->IsArrow = Record[Idx++]; 1462 E->OperatorLoc = ReadSourceLocation(Record, Idx); 1463 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1464 E->FirstQualifierFoundInScope = ReadDeclAs<NamedDecl>(Record, Idx); 1465 ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx); 1466 } 1467 1468 void 1469 ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { 1470 VisitExpr(E); 1471 1472 if (Record[Idx++]) // HasTemplateKWAndArgsInfo 1473 ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(), 1474 /*NumTemplateArgs=*/Record[Idx++]); 1475 1476 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1477 ReadDeclarationNameInfo(E->NameInfo, Record, Idx); 1478 } 1479 1480 void 1481 ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) { 1482 VisitExpr(E); 1483 assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?"); 1484 ++Idx; // NumArgs; 1485 for (unsigned I = 0, N = E->arg_size(); I != N; ++I) 1486 E->setArg(I, Reader.ReadSubExpr()); 1487 E->Type = GetTypeSourceInfo(Record, Idx); 1488 E->setLParenLoc(ReadSourceLocation(Record, Idx)); 1489 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 1490 } 1491 1492 void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) { 1493 VisitExpr(E); 1494 1495 if (Record[Idx++]) // HasTemplateKWAndArgsInfo 1496 ReadTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo(), 1497 /*NumTemplateArgs=*/Record[Idx++]); 1498 1499 unsigned NumDecls = Record[Idx++]; 1500 UnresolvedSet<8> Decls; 1501 for (unsigned i = 0; i != NumDecls; ++i) { 1502 NamedDecl *D = ReadDeclAs<NamedDecl>(Record, Idx); 1503 AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; 1504 Decls.addDecl(D, AS); 1505 } 1506 E->initializeResults(Reader.getContext(), Decls.begin(), Decls.end()); 1507 1508 ReadDeclarationNameInfo(E->NameInfo, Record, Idx); 1509 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1510 } 1511 1512 void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { 1513 VisitOverloadExpr(E); 1514 E->IsArrow = Record[Idx++]; 1515 E->HasUnresolvedUsing = Record[Idx++]; 1516 E->Base = Reader.ReadSubExpr(); 1517 E->BaseType = Reader.readType(F, Record, Idx); 1518 E->OperatorLoc = ReadSourceLocation(Record, Idx); 1519 } 1520 1521 void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { 1522 VisitOverloadExpr(E); 1523 E->RequiresADL = Record[Idx++]; 1524 E->Overloaded = Record[Idx++]; 1525 E->NamingClass = ReadDeclAs<CXXRecordDecl>(Record, Idx); 1526 } 1527 1528 void ASTStmtReader::VisitTypeTraitExpr(TypeTraitExpr *E) { 1529 VisitExpr(E); 1530 E->TypeTraitExprBits.NumArgs = Record[Idx++]; 1531 E->TypeTraitExprBits.Kind = Record[Idx++]; 1532 E->TypeTraitExprBits.Value = Record[Idx++]; 1533 SourceRange Range = ReadSourceRange(Record, Idx); 1534 E->Loc = Range.getBegin(); 1535 E->RParenLoc = Range.getEnd(); 1536 1537 TypeSourceInfo **Args = E->getTypeSourceInfos(); 1538 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 1539 Args[I] = GetTypeSourceInfo(Record, Idx); 1540 } 1541 1542 void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 1543 VisitExpr(E); 1544 E->ATT = (ArrayTypeTrait)Record[Idx++]; 1545 E->Value = (unsigned int)Record[Idx++]; 1546 SourceRange Range = ReadSourceRange(Record, Idx); 1547 E->Loc = Range.getBegin(); 1548 E->RParen = Range.getEnd(); 1549 E->QueriedType = GetTypeSourceInfo(Record, Idx); 1550 } 1551 1552 void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { 1553 VisitExpr(E); 1554 E->ET = (ExpressionTrait)Record[Idx++]; 1555 E->Value = (bool)Record[Idx++]; 1556 SourceRange Range = ReadSourceRange(Record, Idx); 1557 E->QueriedExpression = Reader.ReadSubExpr(); 1558 E->Loc = Range.getBegin(); 1559 E->RParen = Range.getEnd(); 1560 } 1561 1562 void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { 1563 VisitExpr(E); 1564 E->Value = (bool)Record[Idx++]; 1565 E->Range = ReadSourceRange(Record, Idx); 1566 E->Operand = Reader.ReadSubExpr(); 1567 } 1568 1569 void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) { 1570 VisitExpr(E); 1571 E->EllipsisLoc = ReadSourceLocation(Record, Idx); 1572 E->NumExpansions = Record[Idx++]; 1573 E->Pattern = Reader.ReadSubExpr(); 1574 } 1575 1576 void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) { 1577 VisitExpr(E); 1578 unsigned NumPartialArgs = Record[Idx++]; 1579 E->OperatorLoc = ReadSourceLocation(Record, Idx); 1580 E->PackLoc = ReadSourceLocation(Record, Idx); 1581 E->RParenLoc = ReadSourceLocation(Record, Idx); 1582 E->Pack = Reader.ReadDeclAs<NamedDecl>(F, Record, Idx); 1583 if (E->isPartiallySubstituted()) { 1584 assert(E->Length == NumPartialArgs); 1585 for (auto *I = reinterpret_cast<TemplateArgument *>(E + 1), 1586 *E = I + NumPartialArgs; 1587 I != E; ++I) 1588 new (I) TemplateArgument(Reader.ReadTemplateArgument(F, Record, Idx)); 1589 } else if (!E->isValueDependent()) { 1590 E->Length = Record[Idx++]; 1591 } 1592 } 1593 1594 void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr( 1595 SubstNonTypeTemplateParmExpr *E) { 1596 VisitExpr(E); 1597 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx); 1598 E->NameLoc = ReadSourceLocation(Record, Idx); 1599 E->Replacement = Reader.ReadSubExpr(); 1600 } 1601 1602 void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr( 1603 SubstNonTypeTemplateParmPackExpr *E) { 1604 VisitExpr(E); 1605 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx); 1606 TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx); 1607 if (ArgPack.getKind() != TemplateArgument::Pack) 1608 return; 1609 1610 E->Arguments = ArgPack.pack_begin(); 1611 E->NumArguments = ArgPack.pack_size(); 1612 E->NameLoc = ReadSourceLocation(Record, Idx); 1613 } 1614 1615 void ASTStmtReader::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) { 1616 VisitExpr(E); 1617 E->NumParameters = Record[Idx++]; 1618 E->ParamPack = ReadDeclAs<ParmVarDecl>(Record, Idx); 1619 E->NameLoc = ReadSourceLocation(Record, Idx); 1620 ParmVarDecl **Parms = reinterpret_cast<ParmVarDecl**>(E+1); 1621 for (unsigned i = 0, n = E->NumParameters; i != n; ++i) 1622 Parms[i] = ReadDeclAs<ParmVarDecl>(Record, Idx); 1623 } 1624 1625 void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { 1626 VisitExpr(E); 1627 E->State = Reader.ReadSubExpr(); 1628 auto VD = ReadDeclAs<ValueDecl>(Record, Idx); 1629 unsigned ManglingNumber = Record[Idx++]; 1630 E->setExtendingDecl(VD, ManglingNumber); 1631 } 1632 1633 void ASTStmtReader::VisitCXXFoldExpr(CXXFoldExpr *E) { 1634 VisitExpr(E); 1635 E->LParenLoc = ReadSourceLocation(Record, Idx); 1636 E->EllipsisLoc = ReadSourceLocation(Record, Idx); 1637 E->RParenLoc = ReadSourceLocation(Record, Idx); 1638 E->SubExprs[0] = Reader.ReadSubExpr(); 1639 E->SubExprs[1] = Reader.ReadSubExpr(); 1640 E->Opcode = (BinaryOperatorKind)Record[Idx++]; 1641 } 1642 1643 void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) { 1644 VisitExpr(E); 1645 E->SourceExpr = Reader.ReadSubExpr(); 1646 E->Loc = ReadSourceLocation(Record, Idx); 1647 } 1648 1649 void ASTStmtReader::VisitTypoExpr(TypoExpr *E) { 1650 llvm_unreachable("Cannot read TypoExpr nodes"); 1651 } 1652 1653 //===----------------------------------------------------------------------===// 1654 // Microsoft Expressions and Statements 1655 //===----------------------------------------------------------------------===// 1656 void ASTStmtReader::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) { 1657 VisitExpr(E); 1658 E->IsArrow = (Record[Idx++] != 0); 1659 E->BaseExpr = Reader.ReadSubExpr(); 1660 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1661 E->MemberLoc = ReadSourceLocation(Record, Idx); 1662 E->TheDecl = ReadDeclAs<MSPropertyDecl>(Record, Idx); 1663 } 1664 1665 void ASTStmtReader::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) { 1666 VisitExpr(E); 1667 E->setBase(Reader.ReadSubExpr()); 1668 E->setIdx(Reader.ReadSubExpr()); 1669 E->setRBracketLoc(ReadSourceLocation(Record, Idx)); 1670 } 1671 1672 void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) { 1673 VisitExpr(E); 1674 E->setSourceRange(ReadSourceRange(Record, Idx)); 1675 if (E->isTypeOperand()) { // __uuidof(ComType) 1676 E->setTypeOperandSourceInfo( 1677 GetTypeSourceInfo(Record, Idx)); 1678 return; 1679 } 1680 1681 // __uuidof(expr) 1682 E->setExprOperand(Reader.ReadSubExpr()); 1683 } 1684 1685 void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) { 1686 VisitStmt(S); 1687 S->setLeaveLoc(ReadSourceLocation(Record, Idx)); 1688 } 1689 1690 void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) { 1691 VisitStmt(S); 1692 S->Loc = ReadSourceLocation(Record, Idx); 1693 S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt(); 1694 S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt(); 1695 } 1696 1697 void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) { 1698 VisitStmt(S); 1699 S->Loc = ReadSourceLocation(Record, Idx); 1700 S->Block = Reader.ReadSubStmt(); 1701 } 1702 1703 void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) { 1704 VisitStmt(S); 1705 S->IsCXXTry = Record[Idx++]; 1706 S->TryLoc = ReadSourceLocation(Record, Idx); 1707 S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt(); 1708 S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt(); 1709 } 1710 1711 //===----------------------------------------------------------------------===// 1712 // CUDA Expressions and Statements 1713 //===----------------------------------------------------------------------===// 1714 1715 void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 1716 VisitCallExpr(E); 1717 E->setConfig(cast<CallExpr>(Reader.ReadSubExpr())); 1718 } 1719 1720 //===----------------------------------------------------------------------===// 1721 // OpenCL Expressions and Statements. 1722 //===----------------------------------------------------------------------===// 1723 void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) { 1724 VisitExpr(E); 1725 E->BuiltinLoc = ReadSourceLocation(Record, Idx); 1726 E->RParenLoc = ReadSourceLocation(Record, Idx); 1727 E->SrcExpr = Reader.ReadSubExpr(); 1728 } 1729 1730 //===----------------------------------------------------------------------===// 1731 // OpenMP Clauses. 1732 //===----------------------------------------------------------------------===// 1733 1734 namespace clang { 1735 class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> { 1736 ASTStmtReader *Reader; 1737 ASTContext &Context; 1738 const ASTReader::RecordData &Record; 1739 unsigned &Idx; 1740 public: 1741 OMPClauseReader(ASTStmtReader *R, ASTContext &C, 1742 const ASTReader::RecordData &Record, unsigned &Idx) 1743 : Reader(R), Context(C), Record(Record), Idx(Idx) { } 1744 #define OPENMP_CLAUSE(Name, Class) \ 1745 void Visit##Class(Class *S); 1746 #include "clang/Basic/OpenMPKinds.def" 1747 OMPClause *readClause(); 1748 }; 1749 } 1750 1751 OMPClause *OMPClauseReader::readClause() { 1752 OMPClause *C; 1753 switch (Record[Idx++]) { 1754 case OMPC_if: 1755 C = new (Context) OMPIfClause(); 1756 break; 1757 case OMPC_final: 1758 C = new (Context) OMPFinalClause(); 1759 break; 1760 case OMPC_num_threads: 1761 C = new (Context) OMPNumThreadsClause(); 1762 break; 1763 case OMPC_safelen: 1764 C = new (Context) OMPSafelenClause(); 1765 break; 1766 case OMPC_simdlen: 1767 C = new (Context) OMPSimdlenClause(); 1768 break; 1769 case OMPC_collapse: 1770 C = new (Context) OMPCollapseClause(); 1771 break; 1772 case OMPC_default: 1773 C = new (Context) OMPDefaultClause(); 1774 break; 1775 case OMPC_proc_bind: 1776 C = new (Context) OMPProcBindClause(); 1777 break; 1778 case OMPC_schedule: 1779 C = new (Context) OMPScheduleClause(); 1780 break; 1781 case OMPC_ordered: 1782 C = new (Context) OMPOrderedClause(); 1783 break; 1784 case OMPC_nowait: 1785 C = new (Context) OMPNowaitClause(); 1786 break; 1787 case OMPC_untied: 1788 C = new (Context) OMPUntiedClause(); 1789 break; 1790 case OMPC_mergeable: 1791 C = new (Context) OMPMergeableClause(); 1792 break; 1793 case OMPC_read: 1794 C = new (Context) OMPReadClause(); 1795 break; 1796 case OMPC_write: 1797 C = new (Context) OMPWriteClause(); 1798 break; 1799 case OMPC_update: 1800 C = new (Context) OMPUpdateClause(); 1801 break; 1802 case OMPC_capture: 1803 C = new (Context) OMPCaptureClause(); 1804 break; 1805 case OMPC_seq_cst: 1806 C = new (Context) OMPSeqCstClause(); 1807 break; 1808 case OMPC_threads: 1809 C = new (Context) OMPThreadsClause(); 1810 break; 1811 case OMPC_simd: 1812 C = new (Context) OMPSIMDClause(); 1813 break; 1814 case OMPC_nogroup: 1815 C = new (Context) OMPNogroupClause(); 1816 break; 1817 case OMPC_private: 1818 C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]); 1819 break; 1820 case OMPC_firstprivate: 1821 C = OMPFirstprivateClause::CreateEmpty(Context, Record[Idx++]); 1822 break; 1823 case OMPC_lastprivate: 1824 C = OMPLastprivateClause::CreateEmpty(Context, Record[Idx++]); 1825 break; 1826 case OMPC_shared: 1827 C = OMPSharedClause::CreateEmpty(Context, Record[Idx++]); 1828 break; 1829 case OMPC_reduction: 1830 C = OMPReductionClause::CreateEmpty(Context, Record[Idx++]); 1831 break; 1832 case OMPC_linear: 1833 C = OMPLinearClause::CreateEmpty(Context, Record[Idx++]); 1834 break; 1835 case OMPC_aligned: 1836 C = OMPAlignedClause::CreateEmpty(Context, Record[Idx++]); 1837 break; 1838 case OMPC_copyin: 1839 C = OMPCopyinClause::CreateEmpty(Context, Record[Idx++]); 1840 break; 1841 case OMPC_copyprivate: 1842 C = OMPCopyprivateClause::CreateEmpty(Context, Record[Idx++]); 1843 break; 1844 case OMPC_flush: 1845 C = OMPFlushClause::CreateEmpty(Context, Record[Idx++]); 1846 break; 1847 case OMPC_depend: 1848 C = OMPDependClause::CreateEmpty(Context, Record[Idx++]); 1849 break; 1850 case OMPC_device: 1851 C = new (Context) OMPDeviceClause(); 1852 break; 1853 case OMPC_map: 1854 C = OMPMapClause::CreateEmpty(Context, Record[Idx++]); 1855 break; 1856 case OMPC_num_teams: 1857 C = new (Context) OMPNumTeamsClause(); 1858 break; 1859 case OMPC_thread_limit: 1860 C = new (Context) OMPThreadLimitClause(); 1861 break; 1862 case OMPC_priority: 1863 C = new (Context) OMPPriorityClause(); 1864 break; 1865 case OMPC_grainsize: 1866 C = new (Context) OMPGrainsizeClause(); 1867 break; 1868 case OMPC_num_tasks: 1869 C = new (Context) OMPNumTasksClause(); 1870 break; 1871 case OMPC_hint: 1872 C = new (Context) OMPHintClause(); 1873 break; 1874 } 1875 Visit(C); 1876 C->setLocStart(Reader->ReadSourceLocation(Record, Idx)); 1877 C->setLocEnd(Reader->ReadSourceLocation(Record, Idx)); 1878 1879 return C; 1880 } 1881 1882 void OMPClauseReader::VisitOMPIfClause(OMPIfClause *C) { 1883 C->setNameModifier(static_cast<OpenMPDirectiveKind>(Record[Idx++])); 1884 C->setNameModifierLoc(Reader->ReadSourceLocation(Record, Idx)); 1885 C->setColonLoc(Reader->ReadSourceLocation(Record, Idx)); 1886 C->setCondition(Reader->Reader.ReadSubExpr()); 1887 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1888 } 1889 1890 void OMPClauseReader::VisitOMPFinalClause(OMPFinalClause *C) { 1891 C->setCondition(Reader->Reader.ReadSubExpr()); 1892 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1893 } 1894 1895 void OMPClauseReader::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { 1896 C->setNumThreads(Reader->Reader.ReadSubExpr()); 1897 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1898 } 1899 1900 void OMPClauseReader::VisitOMPSafelenClause(OMPSafelenClause *C) { 1901 C->setSafelen(Reader->Reader.ReadSubExpr()); 1902 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1903 } 1904 1905 void OMPClauseReader::VisitOMPSimdlenClause(OMPSimdlenClause *C) { 1906 C->setSimdlen(Reader->Reader.ReadSubExpr()); 1907 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1908 } 1909 1910 void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) { 1911 C->setNumForLoops(Reader->Reader.ReadSubExpr()); 1912 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1913 } 1914 1915 void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) { 1916 C->setDefaultKind( 1917 static_cast<OpenMPDefaultClauseKind>(Record[Idx++])); 1918 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1919 C->setDefaultKindKwLoc(Reader->ReadSourceLocation(Record, Idx)); 1920 } 1921 1922 void OMPClauseReader::VisitOMPProcBindClause(OMPProcBindClause *C) { 1923 C->setProcBindKind( 1924 static_cast<OpenMPProcBindClauseKind>(Record[Idx++])); 1925 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1926 C->setProcBindKindKwLoc(Reader->ReadSourceLocation(Record, Idx)); 1927 } 1928 1929 void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) { 1930 C->setScheduleKind( 1931 static_cast<OpenMPScheduleClauseKind>(Record[Idx++])); 1932 C->setChunkSize(Reader->Reader.ReadSubExpr()); 1933 C->setHelperChunkSize(Reader->Reader.ReadSubExpr()); 1934 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1935 C->setScheduleKindLoc(Reader->ReadSourceLocation(Record, Idx)); 1936 C->setCommaLoc(Reader->ReadSourceLocation(Record, Idx)); 1937 } 1938 1939 void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *C) { 1940 C->setNumForLoops(Reader->Reader.ReadSubExpr()); 1941 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1942 } 1943 1944 void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {} 1945 1946 void OMPClauseReader::VisitOMPUntiedClause(OMPUntiedClause *) {} 1947 1948 void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {} 1949 1950 void OMPClauseReader::VisitOMPReadClause(OMPReadClause *) {} 1951 1952 void OMPClauseReader::VisitOMPWriteClause(OMPWriteClause *) {} 1953 1954 void OMPClauseReader::VisitOMPUpdateClause(OMPUpdateClause *) {} 1955 1956 void OMPClauseReader::VisitOMPCaptureClause(OMPCaptureClause *) {} 1957 1958 void OMPClauseReader::VisitOMPSeqCstClause(OMPSeqCstClause *) {} 1959 1960 void OMPClauseReader::VisitOMPThreadsClause(OMPThreadsClause *) {} 1961 1962 void OMPClauseReader::VisitOMPSIMDClause(OMPSIMDClause *) {} 1963 1964 void OMPClauseReader::VisitOMPNogroupClause(OMPNogroupClause *) {} 1965 1966 void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) { 1967 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1968 unsigned NumVars = C->varlist_size(); 1969 SmallVector<Expr *, 16> Vars; 1970 Vars.reserve(NumVars); 1971 for (unsigned i = 0; i != NumVars; ++i) 1972 Vars.push_back(Reader->Reader.ReadSubExpr()); 1973 C->setVarRefs(Vars); 1974 Vars.clear(); 1975 for (unsigned i = 0; i != NumVars; ++i) 1976 Vars.push_back(Reader->Reader.ReadSubExpr()); 1977 C->setPrivateCopies(Vars); 1978 } 1979 1980 void OMPClauseReader::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) { 1981 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 1982 unsigned NumVars = C->varlist_size(); 1983 SmallVector<Expr *, 16> Vars; 1984 Vars.reserve(NumVars); 1985 for (unsigned i = 0; i != NumVars; ++i) 1986 Vars.push_back(Reader->Reader.ReadSubExpr()); 1987 C->setVarRefs(Vars); 1988 Vars.clear(); 1989 for (unsigned i = 0; i != NumVars; ++i) 1990 Vars.push_back(Reader->Reader.ReadSubExpr()); 1991 C->setPrivateCopies(Vars); 1992 Vars.clear(); 1993 for (unsigned i = 0; i != NumVars; ++i) 1994 Vars.push_back(Reader->Reader.ReadSubExpr()); 1995 C->setInits(Vars); 1996 } 1997 1998 void OMPClauseReader::VisitOMPLastprivateClause(OMPLastprivateClause *C) { 1999 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2000 unsigned NumVars = C->varlist_size(); 2001 SmallVector<Expr *, 16> Vars; 2002 Vars.reserve(NumVars); 2003 for (unsigned i = 0; i != NumVars; ++i) 2004 Vars.push_back(Reader->Reader.ReadSubExpr()); 2005 C->setVarRefs(Vars); 2006 Vars.clear(); 2007 for (unsigned i = 0; i != NumVars; ++i) 2008 Vars.push_back(Reader->Reader.ReadSubExpr()); 2009 C->setPrivateCopies(Vars); 2010 Vars.clear(); 2011 for (unsigned i = 0; i != NumVars; ++i) 2012 Vars.push_back(Reader->Reader.ReadSubExpr()); 2013 C->setSourceExprs(Vars); 2014 Vars.clear(); 2015 for (unsigned i = 0; i != NumVars; ++i) 2016 Vars.push_back(Reader->Reader.ReadSubExpr()); 2017 C->setDestinationExprs(Vars); 2018 Vars.clear(); 2019 for (unsigned i = 0; i != NumVars; ++i) 2020 Vars.push_back(Reader->Reader.ReadSubExpr()); 2021 C->setAssignmentOps(Vars); 2022 } 2023 2024 void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) { 2025 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2026 unsigned NumVars = C->varlist_size(); 2027 SmallVector<Expr *, 16> Vars; 2028 Vars.reserve(NumVars); 2029 for (unsigned i = 0; i != NumVars; ++i) 2030 Vars.push_back(Reader->Reader.ReadSubExpr()); 2031 C->setVarRefs(Vars); 2032 } 2033 2034 void OMPClauseReader::VisitOMPReductionClause(OMPReductionClause *C) { 2035 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2036 C->setColonLoc(Reader->ReadSourceLocation(Record, Idx)); 2037 NestedNameSpecifierLoc NNSL = 2038 Reader->Reader.ReadNestedNameSpecifierLoc(Reader->F, Record, Idx); 2039 DeclarationNameInfo DNI; 2040 Reader->ReadDeclarationNameInfo(DNI, Record, Idx); 2041 C->setQualifierLoc(NNSL); 2042 C->setNameInfo(DNI); 2043 2044 unsigned NumVars = C->varlist_size(); 2045 SmallVector<Expr *, 16> Vars; 2046 Vars.reserve(NumVars); 2047 for (unsigned i = 0; i != NumVars; ++i) 2048 Vars.push_back(Reader->Reader.ReadSubExpr()); 2049 C->setVarRefs(Vars); 2050 Vars.clear(); 2051 for (unsigned i = 0; i != NumVars; ++i) 2052 Vars.push_back(Reader->Reader.ReadSubExpr()); 2053 C->setPrivates(Vars); 2054 Vars.clear(); 2055 for (unsigned i = 0; i != NumVars; ++i) 2056 Vars.push_back(Reader->Reader.ReadSubExpr()); 2057 C->setLHSExprs(Vars); 2058 Vars.clear(); 2059 for (unsigned i = 0; i != NumVars; ++i) 2060 Vars.push_back(Reader->Reader.ReadSubExpr()); 2061 C->setRHSExprs(Vars); 2062 Vars.clear(); 2063 for (unsigned i = 0; i != NumVars; ++i) 2064 Vars.push_back(Reader->Reader.ReadSubExpr()); 2065 C->setReductionOps(Vars); 2066 } 2067 2068 void OMPClauseReader::VisitOMPLinearClause(OMPLinearClause *C) { 2069 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2070 C->setColonLoc(Reader->ReadSourceLocation(Record, Idx)); 2071 C->setModifier(static_cast<OpenMPLinearClauseKind>(Record[Idx++])); 2072 C->setModifierLoc(Reader->ReadSourceLocation(Record, Idx)); 2073 unsigned NumVars = C->varlist_size(); 2074 SmallVector<Expr *, 16> Vars; 2075 Vars.reserve(NumVars); 2076 for (unsigned i = 0; i != NumVars; ++i) 2077 Vars.push_back(Reader->Reader.ReadSubExpr()); 2078 C->setVarRefs(Vars); 2079 Vars.clear(); 2080 for (unsigned i = 0; i != NumVars; ++i) 2081 Vars.push_back(Reader->Reader.ReadSubExpr()); 2082 C->setPrivates(Vars); 2083 Vars.clear(); 2084 for (unsigned i = 0; i != NumVars; ++i) 2085 Vars.push_back(Reader->Reader.ReadSubExpr()); 2086 C->setInits(Vars); 2087 Vars.clear(); 2088 for (unsigned i = 0; i != NumVars; ++i) 2089 Vars.push_back(Reader->Reader.ReadSubExpr()); 2090 C->setUpdates(Vars); 2091 Vars.clear(); 2092 for (unsigned i = 0; i != NumVars; ++i) 2093 Vars.push_back(Reader->Reader.ReadSubExpr()); 2094 C->setFinals(Vars); 2095 C->setStep(Reader->Reader.ReadSubExpr()); 2096 C->setCalcStep(Reader->Reader.ReadSubExpr()); 2097 } 2098 2099 void OMPClauseReader::VisitOMPAlignedClause(OMPAlignedClause *C) { 2100 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2101 C->setColonLoc(Reader->ReadSourceLocation(Record, Idx)); 2102 unsigned NumVars = C->varlist_size(); 2103 SmallVector<Expr *, 16> Vars; 2104 Vars.reserve(NumVars); 2105 for (unsigned i = 0; i != NumVars; ++i) 2106 Vars.push_back(Reader->Reader.ReadSubExpr()); 2107 C->setVarRefs(Vars); 2108 C->setAlignment(Reader->Reader.ReadSubExpr()); 2109 } 2110 2111 void OMPClauseReader::VisitOMPCopyinClause(OMPCopyinClause *C) { 2112 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2113 unsigned NumVars = C->varlist_size(); 2114 SmallVector<Expr *, 16> Exprs; 2115 Exprs.reserve(NumVars); 2116 for (unsigned i = 0; i != NumVars; ++i) 2117 Exprs.push_back(Reader->Reader.ReadSubExpr()); 2118 C->setVarRefs(Exprs); 2119 Exprs.clear(); 2120 for (unsigned i = 0; i != NumVars; ++i) 2121 Exprs.push_back(Reader->Reader.ReadSubExpr()); 2122 C->setSourceExprs(Exprs); 2123 Exprs.clear(); 2124 for (unsigned i = 0; i != NumVars; ++i) 2125 Exprs.push_back(Reader->Reader.ReadSubExpr()); 2126 C->setDestinationExprs(Exprs); 2127 Exprs.clear(); 2128 for (unsigned i = 0; i != NumVars; ++i) 2129 Exprs.push_back(Reader->Reader.ReadSubExpr()); 2130 C->setAssignmentOps(Exprs); 2131 } 2132 2133 void OMPClauseReader::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) { 2134 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2135 unsigned NumVars = C->varlist_size(); 2136 SmallVector<Expr *, 16> Exprs; 2137 Exprs.reserve(NumVars); 2138 for (unsigned i = 0; i != NumVars; ++i) 2139 Exprs.push_back(Reader->Reader.ReadSubExpr()); 2140 C->setVarRefs(Exprs); 2141 Exprs.clear(); 2142 for (unsigned i = 0; i != NumVars; ++i) 2143 Exprs.push_back(Reader->Reader.ReadSubExpr()); 2144 C->setSourceExprs(Exprs); 2145 Exprs.clear(); 2146 for (unsigned i = 0; i != NumVars; ++i) 2147 Exprs.push_back(Reader->Reader.ReadSubExpr()); 2148 C->setDestinationExprs(Exprs); 2149 Exprs.clear(); 2150 for (unsigned i = 0; i != NumVars; ++i) 2151 Exprs.push_back(Reader->Reader.ReadSubExpr()); 2152 C->setAssignmentOps(Exprs); 2153 } 2154 2155 void OMPClauseReader::VisitOMPFlushClause(OMPFlushClause *C) { 2156 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2157 unsigned NumVars = C->varlist_size(); 2158 SmallVector<Expr *, 16> Vars; 2159 Vars.reserve(NumVars); 2160 for (unsigned i = 0; i != NumVars; ++i) 2161 Vars.push_back(Reader->Reader.ReadSubExpr()); 2162 C->setVarRefs(Vars); 2163 } 2164 2165 void OMPClauseReader::VisitOMPDependClause(OMPDependClause *C) { 2166 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2167 C->setDependencyKind(static_cast<OpenMPDependClauseKind>(Record[Idx++])); 2168 C->setDependencyLoc(Reader->ReadSourceLocation(Record, Idx)); 2169 C->setColonLoc(Reader->ReadSourceLocation(Record, Idx)); 2170 unsigned NumVars = C->varlist_size(); 2171 SmallVector<Expr *, 16> Vars; 2172 Vars.reserve(NumVars); 2173 for (unsigned i = 0; i != NumVars; ++i) 2174 Vars.push_back(Reader->Reader.ReadSubExpr()); 2175 C->setVarRefs(Vars); 2176 } 2177 2178 void OMPClauseReader::VisitOMPDeviceClause(OMPDeviceClause *C) { 2179 C->setDevice(Reader->Reader.ReadSubExpr()); 2180 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2181 } 2182 2183 void OMPClauseReader::VisitOMPMapClause(OMPMapClause *C) { 2184 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2185 C->setMapTypeModifier( 2186 static_cast<OpenMPMapClauseKind>(Record[Idx++])); 2187 C->setMapType( 2188 static_cast<OpenMPMapClauseKind>(Record[Idx++])); 2189 C->setMapLoc(Reader->ReadSourceLocation(Record, Idx)); 2190 C->setColonLoc(Reader->ReadSourceLocation(Record, Idx)); 2191 auto NumVars = C->varlist_size(); 2192 SmallVector<Expr *, 16> Vars; 2193 Vars.reserve(NumVars); 2194 for (unsigned i = 0; i != NumVars; ++i) { 2195 Vars.push_back(Reader->Reader.ReadSubExpr()); 2196 } 2197 C->setVarRefs(Vars); 2198 } 2199 2200 void OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { 2201 C->setNumTeams(Reader->Reader.ReadSubExpr()); 2202 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2203 } 2204 2205 void OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) { 2206 C->setThreadLimit(Reader->Reader.ReadSubExpr()); 2207 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2208 } 2209 2210 void OMPClauseReader::VisitOMPPriorityClause(OMPPriorityClause *C) { 2211 C->setPriority(Reader->Reader.ReadSubExpr()); 2212 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2213 } 2214 2215 void OMPClauseReader::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) { 2216 C->setGrainsize(Reader->Reader.ReadSubExpr()); 2217 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2218 } 2219 2220 void OMPClauseReader::VisitOMPNumTasksClause(OMPNumTasksClause *C) { 2221 C->setNumTasks(Reader->Reader.ReadSubExpr()); 2222 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2223 } 2224 2225 void OMPClauseReader::VisitOMPHintClause(OMPHintClause *C) { 2226 C->setHint(Reader->Reader.ReadSubExpr()); 2227 C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); 2228 } 2229 2230 //===----------------------------------------------------------------------===// 2231 // OpenMP Directives. 2232 //===----------------------------------------------------------------------===// 2233 void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) { 2234 E->setLocStart(ReadSourceLocation(Record, Idx)); 2235 E->setLocEnd(ReadSourceLocation(Record, Idx)); 2236 OMPClauseReader ClauseReader(this, Reader.getContext(), Record, Idx); 2237 SmallVector<OMPClause *, 5> Clauses; 2238 for (unsigned i = 0; i < E->getNumClauses(); ++i) 2239 Clauses.push_back(ClauseReader.readClause()); 2240 E->setClauses(Clauses); 2241 if (E->hasAssociatedStmt()) 2242 E->setAssociatedStmt(Reader.ReadSubStmt()); 2243 } 2244 2245 void ASTStmtReader::VisitOMPLoopDirective(OMPLoopDirective *D) { 2246 VisitStmt(D); 2247 // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream. 2248 Idx += 2; 2249 VisitOMPExecutableDirective(D); 2250 D->setIterationVariable(Reader.ReadSubExpr()); 2251 D->setLastIteration(Reader.ReadSubExpr()); 2252 D->setCalcLastIteration(Reader.ReadSubExpr()); 2253 D->setPreCond(Reader.ReadSubExpr()); 2254 D->setCond(Reader.ReadSubExpr()); 2255 D->setInit(Reader.ReadSubExpr()); 2256 D->setInc(Reader.ReadSubExpr()); 2257 if (isOpenMPWorksharingDirective(D->getDirectiveKind())) { 2258 D->setIsLastIterVariable(Reader.ReadSubExpr()); 2259 D->setLowerBoundVariable(Reader.ReadSubExpr()); 2260 D->setUpperBoundVariable(Reader.ReadSubExpr()); 2261 D->setStrideVariable(Reader.ReadSubExpr()); 2262 D->setEnsureUpperBound(Reader.ReadSubExpr()); 2263 D->setNextLowerBound(Reader.ReadSubExpr()); 2264 D->setNextUpperBound(Reader.ReadSubExpr()); 2265 } 2266 SmallVector<Expr *, 4> Sub; 2267 unsigned CollapsedNum = D->getCollapsedNumber(); 2268 Sub.reserve(CollapsedNum); 2269 for (unsigned i = 0; i < CollapsedNum; ++i) 2270 Sub.push_back(Reader.ReadSubExpr()); 2271 D->setCounters(Sub); 2272 Sub.clear(); 2273 for (unsigned i = 0; i < CollapsedNum; ++i) 2274 Sub.push_back(Reader.ReadSubExpr()); 2275 D->setPrivateCounters(Sub); 2276 Sub.clear(); 2277 for (unsigned i = 0; i < CollapsedNum; ++i) 2278 Sub.push_back(Reader.ReadSubExpr()); 2279 D->setInits(Sub); 2280 Sub.clear(); 2281 for (unsigned i = 0; i < CollapsedNum; ++i) 2282 Sub.push_back(Reader.ReadSubExpr()); 2283 D->setUpdates(Sub); 2284 Sub.clear(); 2285 for (unsigned i = 0; i < CollapsedNum; ++i) 2286 Sub.push_back(Reader.ReadSubExpr()); 2287 D->setFinals(Sub); 2288 } 2289 2290 void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) { 2291 VisitStmt(D); 2292 // The NumClauses field was read in ReadStmtFromStream. 2293 ++Idx; 2294 VisitOMPExecutableDirective(D); 2295 D->setHasCancel(Record[Idx++]); 2296 } 2297 2298 void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) { 2299 VisitOMPLoopDirective(D); 2300 } 2301 2302 void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) { 2303 VisitOMPLoopDirective(D); 2304 D->setHasCancel(Record[Idx++]); 2305 } 2306 2307 void ASTStmtReader::VisitOMPForSimdDirective(OMPForSimdDirective *D) { 2308 VisitOMPLoopDirective(D); 2309 } 2310 2311 void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) { 2312 VisitStmt(D); 2313 // The NumClauses field was read in ReadStmtFromStream. 2314 ++Idx; 2315 VisitOMPExecutableDirective(D); 2316 D->setHasCancel(Record[Idx++]); 2317 } 2318 2319 void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) { 2320 VisitStmt(D); 2321 VisitOMPExecutableDirective(D); 2322 D->setHasCancel(Record[Idx++]); 2323 } 2324 2325 void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) { 2326 VisitStmt(D); 2327 // The NumClauses field was read in ReadStmtFromStream. 2328 ++Idx; 2329 VisitOMPExecutableDirective(D); 2330 } 2331 2332 void ASTStmtReader::VisitOMPMasterDirective(OMPMasterDirective *D) { 2333 VisitStmt(D); 2334 VisitOMPExecutableDirective(D); 2335 } 2336 2337 void ASTStmtReader::VisitOMPCriticalDirective(OMPCriticalDirective *D) { 2338 VisitStmt(D); 2339 // The NumClauses field was read in ReadStmtFromStream. 2340 ++Idx; 2341 VisitOMPExecutableDirective(D); 2342 ReadDeclarationNameInfo(D->DirName, Record, Idx); 2343 } 2344 2345 void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) { 2346 VisitOMPLoopDirective(D); 2347 D->setHasCancel(Record[Idx++]); 2348 } 2349 2350 void ASTStmtReader::VisitOMPParallelForSimdDirective( 2351 OMPParallelForSimdDirective *D) { 2352 VisitOMPLoopDirective(D); 2353 } 2354 2355 void ASTStmtReader::VisitOMPParallelSectionsDirective( 2356 OMPParallelSectionsDirective *D) { 2357 VisitStmt(D); 2358 // The NumClauses field was read in ReadStmtFromStream. 2359 ++Idx; 2360 VisitOMPExecutableDirective(D); 2361 D->setHasCancel(Record[Idx++]); 2362 } 2363 2364 void ASTStmtReader::VisitOMPTaskDirective(OMPTaskDirective *D) { 2365 VisitStmt(D); 2366 // The NumClauses field was read in ReadStmtFromStream. 2367 ++Idx; 2368 VisitOMPExecutableDirective(D); 2369 D->setHasCancel(Record[Idx++]); 2370 } 2371 2372 void ASTStmtReader::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) { 2373 VisitStmt(D); 2374 VisitOMPExecutableDirective(D); 2375 } 2376 2377 void ASTStmtReader::VisitOMPBarrierDirective(OMPBarrierDirective *D) { 2378 VisitStmt(D); 2379 VisitOMPExecutableDirective(D); 2380 } 2381 2382 void ASTStmtReader::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) { 2383 VisitStmt(D); 2384 VisitOMPExecutableDirective(D); 2385 } 2386 2387 void ASTStmtReader::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) { 2388 VisitStmt(D); 2389 VisitOMPExecutableDirective(D); 2390 } 2391 2392 void ASTStmtReader::VisitOMPFlushDirective(OMPFlushDirective *D) { 2393 VisitStmt(D); 2394 // The NumClauses field was read in ReadStmtFromStream. 2395 ++Idx; 2396 VisitOMPExecutableDirective(D); 2397 } 2398 2399 void ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) { 2400 VisitStmt(D); 2401 // The NumClauses field was read in ReadStmtFromStream. 2402 ++Idx; 2403 VisitOMPExecutableDirective(D); 2404 } 2405 2406 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) { 2407 VisitStmt(D); 2408 // The NumClauses field was read in ReadStmtFromStream. 2409 ++Idx; 2410 VisitOMPExecutableDirective(D); 2411 D->setX(Reader.ReadSubExpr()); 2412 D->setV(Reader.ReadSubExpr()); 2413 D->setExpr(Reader.ReadSubExpr()); 2414 D->setUpdateExpr(Reader.ReadSubExpr()); 2415 D->IsXLHSInRHSPart = Record[Idx++] != 0; 2416 D->IsPostfixUpdate = Record[Idx++] != 0; 2417 } 2418 2419 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) { 2420 VisitStmt(D); 2421 // The NumClauses field was read in ReadStmtFromStream. 2422 ++Idx; 2423 VisitOMPExecutableDirective(D); 2424 } 2425 2426 void ASTStmtReader::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) { 2427 VisitStmt(D); 2428 ++Idx; 2429 VisitOMPExecutableDirective(D); 2430 } 2431 2432 void ASTStmtReader::VisitOMPTeamsDirective(OMPTeamsDirective *D) { 2433 VisitStmt(D); 2434 // The NumClauses field was read in ReadStmtFromStream. 2435 ++Idx; 2436 VisitOMPExecutableDirective(D); 2437 } 2438 2439 void ASTStmtReader::VisitOMPCancellationPointDirective( 2440 OMPCancellationPointDirective *D) { 2441 VisitStmt(D); 2442 VisitOMPExecutableDirective(D); 2443 D->setCancelRegion(static_cast<OpenMPDirectiveKind>(Record[Idx++])); 2444 } 2445 2446 void ASTStmtReader::VisitOMPCancelDirective(OMPCancelDirective *D) { 2447 VisitStmt(D); 2448 // The NumClauses field was read in ReadStmtFromStream. 2449 ++Idx; 2450 VisitOMPExecutableDirective(D); 2451 D->setCancelRegion(static_cast<OpenMPDirectiveKind>(Record[Idx++])); 2452 } 2453 2454 void ASTStmtReader::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) { 2455 VisitOMPLoopDirective(D); 2456 } 2457 2458 void ASTStmtReader::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) { 2459 VisitOMPLoopDirective(D); 2460 } 2461 2462 void ASTStmtReader::VisitOMPDistributeDirective(OMPDistributeDirective *D) { 2463 VisitOMPLoopDirective(D); 2464 } 2465 2466 //===----------------------------------------------------------------------===// 2467 // ASTReader Implementation 2468 //===----------------------------------------------------------------------===// 2469 2470 Stmt *ASTReader::ReadStmt(ModuleFile &F) { 2471 switch (ReadingKind) { 2472 case Read_None: 2473 llvm_unreachable("should not call this when not reading anything"); 2474 case Read_Decl: 2475 case Read_Type: 2476 return ReadStmtFromStream(F); 2477 case Read_Stmt: 2478 return ReadSubStmt(); 2479 } 2480 2481 llvm_unreachable("ReadingKind not set ?"); 2482 } 2483 2484 Expr *ASTReader::ReadExpr(ModuleFile &F) { 2485 return cast_or_null<Expr>(ReadStmt(F)); 2486 } 2487 2488 Expr *ASTReader::ReadSubExpr() { 2489 return cast_or_null<Expr>(ReadSubStmt()); 2490 } 2491 2492 // Within the bitstream, expressions are stored in Reverse Polish 2493 // Notation, with each of the subexpressions preceding the 2494 // expression they are stored in. Subexpressions are stored from last to first. 2495 // To evaluate expressions, we continue reading expressions and placing them on 2496 // the stack, with expressions having operands removing those operands from the 2497 // stack. Evaluation terminates when we see a STMT_STOP record, and 2498 // the single remaining expression on the stack is our result. 2499 Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { 2500 2501 ReadingKindTracker ReadingKind(Read_Stmt, *this); 2502 llvm::BitstreamCursor &Cursor = F.DeclsCursor; 2503 2504 // Map of offset to previously deserialized stmt. The offset points 2505 /// just after the stmt record. 2506 llvm::DenseMap<uint64_t, Stmt *> StmtEntries; 2507 2508 #ifndef NDEBUG 2509 unsigned PrevNumStmts = StmtStack.size(); 2510 #endif 2511 2512 RecordData Record; 2513 unsigned Idx; 2514 ASTStmtReader Reader(*this, F, Cursor, Record, Idx); 2515 Stmt::EmptyShell Empty; 2516 2517 while (true) { 2518 llvm::BitstreamEntry Entry = Cursor.advanceSkippingSubblocks(); 2519 2520 switch (Entry.Kind) { 2521 case llvm::BitstreamEntry::SubBlock: // Handled for us already. 2522 case llvm::BitstreamEntry::Error: 2523 Error("malformed block record in AST file"); 2524 return nullptr; 2525 case llvm::BitstreamEntry::EndBlock: 2526 goto Done; 2527 case llvm::BitstreamEntry::Record: 2528 // The interesting case. 2529 break; 2530 } 2531 2532 Stmt *S = nullptr; 2533 Idx = 0; 2534 Record.clear(); 2535 bool Finished = false; 2536 bool IsStmtReference = false; 2537 switch ((StmtCode)Cursor.readRecord(Entry.ID, Record)) { 2538 case STMT_STOP: 2539 Finished = true; 2540 break; 2541 2542 case STMT_REF_PTR: 2543 IsStmtReference = true; 2544 assert(StmtEntries.find(Record[0]) != StmtEntries.end() && 2545 "No stmt was recorded for this offset reference!"); 2546 S = StmtEntries[Record[Idx++]]; 2547 break; 2548 2549 case STMT_NULL_PTR: 2550 S = nullptr; 2551 break; 2552 2553 case STMT_NULL: 2554 S = new (Context) NullStmt(Empty); 2555 break; 2556 2557 case STMT_COMPOUND: 2558 S = new (Context) CompoundStmt(Empty); 2559 break; 2560 2561 case STMT_CASE: 2562 S = new (Context) CaseStmt(Empty); 2563 break; 2564 2565 case STMT_DEFAULT: 2566 S = new (Context) DefaultStmt(Empty); 2567 break; 2568 2569 case STMT_LABEL: 2570 S = new (Context) LabelStmt(Empty); 2571 break; 2572 2573 case STMT_ATTRIBUTED: 2574 S = AttributedStmt::CreateEmpty( 2575 Context, 2576 /*NumAttrs*/Record[ASTStmtReader::NumStmtFields]); 2577 break; 2578 2579 case STMT_IF: 2580 S = new (Context) IfStmt(Empty); 2581 break; 2582 2583 case STMT_SWITCH: 2584 S = new (Context) SwitchStmt(Empty); 2585 break; 2586 2587 case STMT_WHILE: 2588 S = new (Context) WhileStmt(Empty); 2589 break; 2590 2591 case STMT_DO: 2592 S = new (Context) DoStmt(Empty); 2593 break; 2594 2595 case STMT_FOR: 2596 S = new (Context) ForStmt(Empty); 2597 break; 2598 2599 case STMT_GOTO: 2600 S = new (Context) GotoStmt(Empty); 2601 break; 2602 2603 case STMT_INDIRECT_GOTO: 2604 S = new (Context) IndirectGotoStmt(Empty); 2605 break; 2606 2607 case STMT_CONTINUE: 2608 S = new (Context) ContinueStmt(Empty); 2609 break; 2610 2611 case STMT_BREAK: 2612 S = new (Context) BreakStmt(Empty); 2613 break; 2614 2615 case STMT_RETURN: 2616 S = new (Context) ReturnStmt(Empty); 2617 break; 2618 2619 case STMT_DECL: 2620 S = new (Context) DeclStmt(Empty); 2621 break; 2622 2623 case STMT_GCCASM: 2624 S = new (Context) GCCAsmStmt(Empty); 2625 break; 2626 2627 case STMT_MSASM: 2628 S = new (Context) MSAsmStmt(Empty); 2629 break; 2630 2631 case STMT_CAPTURED: 2632 S = CapturedStmt::CreateDeserialized(Context, 2633 Record[ASTStmtReader::NumStmtFields]); 2634 break; 2635 2636 case EXPR_PREDEFINED: 2637 S = new (Context) PredefinedExpr(Empty); 2638 break; 2639 2640 case EXPR_DECL_REF: 2641 S = DeclRefExpr::CreateEmpty( 2642 Context, 2643 /*HasQualifier=*/Record[ASTStmtReader::NumExprFields], 2644 /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1], 2645 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 2], 2646 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ? 2647 Record[ASTStmtReader::NumExprFields + 5] : 0); 2648 break; 2649 2650 case EXPR_INTEGER_LITERAL: 2651 S = IntegerLiteral::Create(Context, Empty); 2652 break; 2653 2654 case EXPR_FLOATING_LITERAL: 2655 S = FloatingLiteral::Create(Context, Empty); 2656 break; 2657 2658 case EXPR_IMAGINARY_LITERAL: 2659 S = new (Context) ImaginaryLiteral(Empty); 2660 break; 2661 2662 case EXPR_STRING_LITERAL: 2663 S = StringLiteral::CreateEmpty(Context, 2664 Record[ASTStmtReader::NumExprFields + 1]); 2665 break; 2666 2667 case EXPR_CHARACTER_LITERAL: 2668 S = new (Context) CharacterLiteral(Empty); 2669 break; 2670 2671 case EXPR_PAREN: 2672 S = new (Context) ParenExpr(Empty); 2673 break; 2674 2675 case EXPR_PAREN_LIST: 2676 S = new (Context) ParenListExpr(Empty); 2677 break; 2678 2679 case EXPR_UNARY_OPERATOR: 2680 S = new (Context) UnaryOperator(Empty); 2681 break; 2682 2683 case EXPR_OFFSETOF: 2684 S = OffsetOfExpr::CreateEmpty(Context, 2685 Record[ASTStmtReader::NumExprFields], 2686 Record[ASTStmtReader::NumExprFields + 1]); 2687 break; 2688 2689 case EXPR_SIZEOF_ALIGN_OF: 2690 S = new (Context) UnaryExprOrTypeTraitExpr(Empty); 2691 break; 2692 2693 case EXPR_ARRAY_SUBSCRIPT: 2694 S = new (Context) ArraySubscriptExpr(Empty); 2695 break; 2696 2697 case EXPR_OMP_ARRAY_SECTION: 2698 S = new (Context) OMPArraySectionExpr(Empty); 2699 break; 2700 2701 case EXPR_CALL: 2702 S = new (Context) CallExpr(Context, Stmt::CallExprClass, Empty); 2703 break; 2704 2705 case EXPR_MEMBER: { 2706 // We load everything here and fully initialize it at creation. 2707 // That way we can use MemberExpr::Create and don't have to duplicate its 2708 // logic with a MemberExpr::CreateEmpty. 2709 2710 assert(Idx == 0); 2711 NestedNameSpecifierLoc QualifierLoc; 2712 if (Record[Idx++]) { // HasQualifier. 2713 QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); 2714 } 2715 2716 SourceLocation TemplateKWLoc; 2717 TemplateArgumentListInfo ArgInfo; 2718 bool HasTemplateKWAndArgsInfo = Record[Idx++]; 2719 if (HasTemplateKWAndArgsInfo) { 2720 TemplateKWLoc = ReadSourceLocation(F, Record, Idx); 2721 unsigned NumTemplateArgs = Record[Idx++]; 2722 ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx)); 2723 ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx)); 2724 for (unsigned i = 0; i != NumTemplateArgs; ++i) 2725 ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx)); 2726 } 2727 2728 bool HadMultipleCandidates = Record[Idx++]; 2729 2730 NamedDecl *FoundD = ReadDeclAs<NamedDecl>(F, Record, Idx); 2731 AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; 2732 DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS); 2733 2734 QualType T = readType(F, Record, Idx); 2735 ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]); 2736 ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]); 2737 Expr *Base = ReadSubExpr(); 2738 ValueDecl *MemberD = ReadDeclAs<ValueDecl>(F, Record, Idx); 2739 SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx); 2740 DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc); 2741 bool IsArrow = Record[Idx++]; 2742 SourceLocation OperatorLoc = ReadSourceLocation(F, Record, Idx); 2743 2744 S = MemberExpr::Create(Context, Base, IsArrow, OperatorLoc, QualifierLoc, 2745 TemplateKWLoc, MemberD, FoundDecl, MemberNameInfo, 2746 HasTemplateKWAndArgsInfo ? &ArgInfo : nullptr, T, 2747 VK, OK); 2748 ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc, 2749 MemberD->getDeclName(), Record, Idx); 2750 if (HadMultipleCandidates) 2751 cast<MemberExpr>(S)->setHadMultipleCandidates(true); 2752 break; 2753 } 2754 2755 case EXPR_BINARY_OPERATOR: 2756 S = new (Context) BinaryOperator(Empty); 2757 break; 2758 2759 case EXPR_COMPOUND_ASSIGN_OPERATOR: 2760 S = new (Context) CompoundAssignOperator(Empty); 2761 break; 2762 2763 case EXPR_CONDITIONAL_OPERATOR: 2764 S = new (Context) ConditionalOperator(Empty); 2765 break; 2766 2767 case EXPR_BINARY_CONDITIONAL_OPERATOR: 2768 S = new (Context) BinaryConditionalOperator(Empty); 2769 break; 2770 2771 case EXPR_IMPLICIT_CAST: 2772 S = ImplicitCastExpr::CreateEmpty(Context, 2773 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 2774 break; 2775 2776 case EXPR_CSTYLE_CAST: 2777 S = CStyleCastExpr::CreateEmpty(Context, 2778 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 2779 break; 2780 2781 case EXPR_COMPOUND_LITERAL: 2782 S = new (Context) CompoundLiteralExpr(Empty); 2783 break; 2784 2785 case EXPR_EXT_VECTOR_ELEMENT: 2786 S = new (Context) ExtVectorElementExpr(Empty); 2787 break; 2788 2789 case EXPR_INIT_LIST: 2790 S = new (Context) InitListExpr(Empty); 2791 break; 2792 2793 case EXPR_DESIGNATED_INIT: 2794 S = DesignatedInitExpr::CreateEmpty(Context, 2795 Record[ASTStmtReader::NumExprFields] - 1); 2796 2797 break; 2798 2799 case EXPR_DESIGNATED_INIT_UPDATE: 2800 S = new (Context) DesignatedInitUpdateExpr(Empty); 2801 break; 2802 2803 case EXPR_IMPLICIT_VALUE_INIT: 2804 S = new (Context) ImplicitValueInitExpr(Empty); 2805 break; 2806 2807 case EXPR_NO_INIT: 2808 S = new (Context) NoInitExpr(Empty); 2809 break; 2810 2811 case EXPR_VA_ARG: 2812 S = new (Context) VAArgExpr(Empty); 2813 break; 2814 2815 case EXPR_ADDR_LABEL: 2816 S = new (Context) AddrLabelExpr(Empty); 2817 break; 2818 2819 case EXPR_STMT: 2820 S = new (Context) StmtExpr(Empty); 2821 break; 2822 2823 case EXPR_CHOOSE: 2824 S = new (Context) ChooseExpr(Empty); 2825 break; 2826 2827 case EXPR_GNU_NULL: 2828 S = new (Context) GNUNullExpr(Empty); 2829 break; 2830 2831 case EXPR_SHUFFLE_VECTOR: 2832 S = new (Context) ShuffleVectorExpr(Empty); 2833 break; 2834 2835 case EXPR_CONVERT_VECTOR: 2836 S = new (Context) ConvertVectorExpr(Empty); 2837 break; 2838 2839 case EXPR_BLOCK: 2840 S = new (Context) BlockExpr(Empty); 2841 break; 2842 2843 case EXPR_GENERIC_SELECTION: 2844 S = new (Context) GenericSelectionExpr(Empty); 2845 break; 2846 2847 case EXPR_OBJC_STRING_LITERAL: 2848 S = new (Context) ObjCStringLiteral(Empty); 2849 break; 2850 case EXPR_OBJC_BOXED_EXPRESSION: 2851 S = new (Context) ObjCBoxedExpr(Empty); 2852 break; 2853 case EXPR_OBJC_ARRAY_LITERAL: 2854 S = ObjCArrayLiteral::CreateEmpty(Context, 2855 Record[ASTStmtReader::NumExprFields]); 2856 break; 2857 case EXPR_OBJC_DICTIONARY_LITERAL: 2858 S = ObjCDictionaryLiteral::CreateEmpty(Context, 2859 Record[ASTStmtReader::NumExprFields], 2860 Record[ASTStmtReader::NumExprFields + 1]); 2861 break; 2862 case EXPR_OBJC_ENCODE: 2863 S = new (Context) ObjCEncodeExpr(Empty); 2864 break; 2865 case EXPR_OBJC_SELECTOR_EXPR: 2866 S = new (Context) ObjCSelectorExpr(Empty); 2867 break; 2868 case EXPR_OBJC_PROTOCOL_EXPR: 2869 S = new (Context) ObjCProtocolExpr(Empty); 2870 break; 2871 case EXPR_OBJC_IVAR_REF_EXPR: 2872 S = new (Context) ObjCIvarRefExpr(Empty); 2873 break; 2874 case EXPR_OBJC_PROPERTY_REF_EXPR: 2875 S = new (Context) ObjCPropertyRefExpr(Empty); 2876 break; 2877 case EXPR_OBJC_SUBSCRIPT_REF_EXPR: 2878 S = new (Context) ObjCSubscriptRefExpr(Empty); 2879 break; 2880 case EXPR_OBJC_KVC_REF_EXPR: 2881 llvm_unreachable("mismatching AST file"); 2882 case EXPR_OBJC_MESSAGE_EXPR: 2883 S = ObjCMessageExpr::CreateEmpty(Context, 2884 Record[ASTStmtReader::NumExprFields], 2885 Record[ASTStmtReader::NumExprFields + 1]); 2886 break; 2887 case EXPR_OBJC_ISA: 2888 S = new (Context) ObjCIsaExpr(Empty); 2889 break; 2890 case EXPR_OBJC_INDIRECT_COPY_RESTORE: 2891 S = new (Context) ObjCIndirectCopyRestoreExpr(Empty); 2892 break; 2893 case EXPR_OBJC_BRIDGED_CAST: 2894 S = new (Context) ObjCBridgedCastExpr(Empty); 2895 break; 2896 case STMT_OBJC_FOR_COLLECTION: 2897 S = new (Context) ObjCForCollectionStmt(Empty); 2898 break; 2899 case STMT_OBJC_CATCH: 2900 S = new (Context) ObjCAtCatchStmt(Empty); 2901 break; 2902 case STMT_OBJC_FINALLY: 2903 S = new (Context) ObjCAtFinallyStmt(Empty); 2904 break; 2905 case STMT_OBJC_AT_TRY: 2906 S = ObjCAtTryStmt::CreateEmpty(Context, 2907 Record[ASTStmtReader::NumStmtFields], 2908 Record[ASTStmtReader::NumStmtFields + 1]); 2909 break; 2910 case STMT_OBJC_AT_SYNCHRONIZED: 2911 S = new (Context) ObjCAtSynchronizedStmt(Empty); 2912 break; 2913 case STMT_OBJC_AT_THROW: 2914 S = new (Context) ObjCAtThrowStmt(Empty); 2915 break; 2916 case STMT_OBJC_AUTORELEASE_POOL: 2917 S = new (Context) ObjCAutoreleasePoolStmt(Empty); 2918 break; 2919 case EXPR_OBJC_BOOL_LITERAL: 2920 S = new (Context) ObjCBoolLiteralExpr(Empty); 2921 break; 2922 case STMT_SEH_LEAVE: 2923 S = new (Context) SEHLeaveStmt(Empty); 2924 break; 2925 case STMT_SEH_EXCEPT: 2926 S = new (Context) SEHExceptStmt(Empty); 2927 break; 2928 case STMT_SEH_FINALLY: 2929 S = new (Context) SEHFinallyStmt(Empty); 2930 break; 2931 case STMT_SEH_TRY: 2932 S = new (Context) SEHTryStmt(Empty); 2933 break; 2934 case STMT_CXX_CATCH: 2935 S = new (Context) CXXCatchStmt(Empty); 2936 break; 2937 2938 case STMT_CXX_TRY: 2939 S = CXXTryStmt::Create(Context, Empty, 2940 /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]); 2941 break; 2942 2943 case STMT_CXX_FOR_RANGE: 2944 S = new (Context) CXXForRangeStmt(Empty); 2945 break; 2946 2947 case STMT_MS_DEPENDENT_EXISTS: 2948 S = new (Context) MSDependentExistsStmt(SourceLocation(), true, 2949 NestedNameSpecifierLoc(), 2950 DeclarationNameInfo(), 2951 nullptr); 2952 break; 2953 2954 case STMT_OMP_PARALLEL_DIRECTIVE: 2955 S = 2956 OMPParallelDirective::CreateEmpty(Context, 2957 Record[ASTStmtReader::NumStmtFields], 2958 Empty); 2959 break; 2960 2961 case STMT_OMP_SIMD_DIRECTIVE: { 2962 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; 2963 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; 2964 S = OMPSimdDirective::CreateEmpty(Context, NumClauses, 2965 CollapsedNum, Empty); 2966 break; 2967 } 2968 2969 case STMT_OMP_FOR_DIRECTIVE: { 2970 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; 2971 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; 2972 S = OMPForDirective::CreateEmpty(Context, NumClauses, CollapsedNum, 2973 Empty); 2974 break; 2975 } 2976 2977 case STMT_OMP_FOR_SIMD_DIRECTIVE: { 2978 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; 2979 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; 2980 S = OMPForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, 2981 Empty); 2982 break; 2983 } 2984 2985 case STMT_OMP_SECTIONS_DIRECTIVE: 2986 S = OMPSectionsDirective::CreateEmpty( 2987 Context, Record[ASTStmtReader::NumStmtFields], Empty); 2988 break; 2989 2990 case STMT_OMP_SECTION_DIRECTIVE: 2991 S = OMPSectionDirective::CreateEmpty(Context, Empty); 2992 break; 2993 2994 case STMT_OMP_SINGLE_DIRECTIVE: 2995 S = OMPSingleDirective::CreateEmpty( 2996 Context, Record[ASTStmtReader::NumStmtFields], Empty); 2997 break; 2998 2999 case STMT_OMP_MASTER_DIRECTIVE: 3000 S = OMPMasterDirective::CreateEmpty(Context, Empty); 3001 break; 3002 3003 case STMT_OMP_CRITICAL_DIRECTIVE: 3004 S = OMPCriticalDirective::CreateEmpty( 3005 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3006 break; 3007 3008 case STMT_OMP_PARALLEL_FOR_DIRECTIVE: { 3009 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; 3010 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; 3011 S = OMPParallelForDirective::CreateEmpty(Context, NumClauses, 3012 CollapsedNum, Empty); 3013 break; 3014 } 3015 3016 case STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE: { 3017 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; 3018 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; 3019 S = OMPParallelForSimdDirective::CreateEmpty(Context, NumClauses, 3020 CollapsedNum, Empty); 3021 break; 3022 } 3023 3024 case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE: 3025 S = OMPParallelSectionsDirective::CreateEmpty( 3026 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3027 break; 3028 3029 case STMT_OMP_TASK_DIRECTIVE: 3030 S = OMPTaskDirective::CreateEmpty( 3031 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3032 break; 3033 3034 case STMT_OMP_TASKYIELD_DIRECTIVE: 3035 S = OMPTaskyieldDirective::CreateEmpty(Context, Empty); 3036 break; 3037 3038 case STMT_OMP_BARRIER_DIRECTIVE: 3039 S = OMPBarrierDirective::CreateEmpty(Context, Empty); 3040 break; 3041 3042 case STMT_OMP_TASKWAIT_DIRECTIVE: 3043 S = OMPTaskwaitDirective::CreateEmpty(Context, Empty); 3044 break; 3045 3046 case STMT_OMP_TASKGROUP_DIRECTIVE: 3047 S = OMPTaskgroupDirective::CreateEmpty(Context, Empty); 3048 break; 3049 3050 case STMT_OMP_FLUSH_DIRECTIVE: 3051 S = OMPFlushDirective::CreateEmpty( 3052 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3053 break; 3054 3055 case STMT_OMP_ORDERED_DIRECTIVE: 3056 S = OMPOrderedDirective::CreateEmpty( 3057 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3058 break; 3059 3060 case STMT_OMP_ATOMIC_DIRECTIVE: 3061 S = OMPAtomicDirective::CreateEmpty( 3062 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3063 break; 3064 3065 case STMT_OMP_TARGET_DIRECTIVE: 3066 S = OMPTargetDirective::CreateEmpty( 3067 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3068 break; 3069 3070 case STMT_OMP_TARGET_DATA_DIRECTIVE: 3071 S = OMPTargetDataDirective::CreateEmpty( 3072 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3073 break; 3074 3075 case STMT_OMP_TEAMS_DIRECTIVE: 3076 S = OMPTeamsDirective::CreateEmpty( 3077 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3078 break; 3079 3080 case STMT_OMP_CANCELLATION_POINT_DIRECTIVE: 3081 S = OMPCancellationPointDirective::CreateEmpty(Context, Empty); 3082 break; 3083 3084 case STMT_OMP_CANCEL_DIRECTIVE: 3085 S = OMPCancelDirective::CreateEmpty( 3086 Context, Record[ASTStmtReader::NumStmtFields], Empty); 3087 break; 3088 3089 case STMT_OMP_TASKLOOP_DIRECTIVE: { 3090 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; 3091 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; 3092 S = OMPTaskLoopDirective::CreateEmpty(Context, NumClauses, CollapsedNum, 3093 Empty); 3094 break; 3095 } 3096 3097 case STMT_OMP_TASKLOOP_SIMD_DIRECTIVE: { 3098 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; 3099 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; 3100 S = OMPTaskLoopSimdDirective::CreateEmpty(Context, NumClauses, 3101 CollapsedNum, Empty); 3102 break; 3103 } 3104 3105 case STMT_OMP_DISTRIBUTE_DIRECTIVE: { 3106 unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; 3107 unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; 3108 S = OMPDistributeDirective::CreateEmpty(Context, NumClauses, CollapsedNum, 3109 Empty); 3110 break; 3111 } 3112 3113 case EXPR_CXX_OPERATOR_CALL: 3114 S = new (Context) CXXOperatorCallExpr(Context, Empty); 3115 break; 3116 3117 case EXPR_CXX_MEMBER_CALL: 3118 S = new (Context) CXXMemberCallExpr(Context, Empty); 3119 break; 3120 3121 case EXPR_CXX_CONSTRUCT: 3122 S = new (Context) CXXConstructExpr(Empty); 3123 break; 3124 3125 case EXPR_CXX_TEMPORARY_OBJECT: 3126 S = new (Context) CXXTemporaryObjectExpr(Empty); 3127 break; 3128 3129 case EXPR_CXX_STATIC_CAST: 3130 S = CXXStaticCastExpr::CreateEmpty(Context, 3131 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 3132 break; 3133 3134 case EXPR_CXX_DYNAMIC_CAST: 3135 S = CXXDynamicCastExpr::CreateEmpty(Context, 3136 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 3137 break; 3138 3139 case EXPR_CXX_REINTERPRET_CAST: 3140 S = CXXReinterpretCastExpr::CreateEmpty(Context, 3141 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 3142 break; 3143 3144 case EXPR_CXX_CONST_CAST: 3145 S = CXXConstCastExpr::CreateEmpty(Context); 3146 break; 3147 3148 case EXPR_CXX_FUNCTIONAL_CAST: 3149 S = CXXFunctionalCastExpr::CreateEmpty(Context, 3150 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 3151 break; 3152 3153 case EXPR_USER_DEFINED_LITERAL: 3154 S = new (Context) UserDefinedLiteral(Context, Empty); 3155 break; 3156 3157 case EXPR_CXX_STD_INITIALIZER_LIST: 3158 S = new (Context) CXXStdInitializerListExpr(Empty); 3159 break; 3160 3161 case EXPR_CXX_BOOL_LITERAL: 3162 S = new (Context) CXXBoolLiteralExpr(Empty); 3163 break; 3164 3165 case EXPR_CXX_NULL_PTR_LITERAL: 3166 S = new (Context) CXXNullPtrLiteralExpr(Empty); 3167 break; 3168 case EXPR_CXX_TYPEID_EXPR: 3169 S = new (Context) CXXTypeidExpr(Empty, true); 3170 break; 3171 case EXPR_CXX_TYPEID_TYPE: 3172 S = new (Context) CXXTypeidExpr(Empty, false); 3173 break; 3174 case EXPR_CXX_UUIDOF_EXPR: 3175 S = new (Context) CXXUuidofExpr(Empty, true); 3176 break; 3177 case EXPR_CXX_PROPERTY_REF_EXPR: 3178 S = new (Context) MSPropertyRefExpr(Empty); 3179 break; 3180 case EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR: 3181 S = new (Context) MSPropertySubscriptExpr(Empty); 3182 break; 3183 case EXPR_CXX_UUIDOF_TYPE: 3184 S = new (Context) CXXUuidofExpr(Empty, false); 3185 break; 3186 case EXPR_CXX_THIS: 3187 S = new (Context) CXXThisExpr(Empty); 3188 break; 3189 case EXPR_CXX_THROW: 3190 S = new (Context) CXXThrowExpr(Empty); 3191 break; 3192 case EXPR_CXX_DEFAULT_ARG: { 3193 bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields]; 3194 if (HasOtherExprStored) { 3195 Expr *SubExpr = ReadSubExpr(); 3196 S = CXXDefaultArgExpr::Create(Context, SourceLocation(), nullptr, 3197 SubExpr); 3198 } else 3199 S = new (Context) CXXDefaultArgExpr(Empty); 3200 break; 3201 } 3202 case EXPR_CXX_DEFAULT_INIT: 3203 S = new (Context) CXXDefaultInitExpr(Empty); 3204 break; 3205 case EXPR_CXX_BIND_TEMPORARY: 3206 S = new (Context) CXXBindTemporaryExpr(Empty); 3207 break; 3208 3209 case EXPR_CXX_SCALAR_VALUE_INIT: 3210 S = new (Context) CXXScalarValueInitExpr(Empty); 3211 break; 3212 case EXPR_CXX_NEW: 3213 S = new (Context) CXXNewExpr(Empty); 3214 break; 3215 case EXPR_CXX_DELETE: 3216 S = new (Context) CXXDeleteExpr(Empty); 3217 break; 3218 case EXPR_CXX_PSEUDO_DESTRUCTOR: 3219 S = new (Context) CXXPseudoDestructorExpr(Empty); 3220 break; 3221 3222 case EXPR_EXPR_WITH_CLEANUPS: 3223 S = ExprWithCleanups::Create(Context, Empty, 3224 Record[ASTStmtReader::NumExprFields]); 3225 break; 3226 3227 case EXPR_CXX_DEPENDENT_SCOPE_MEMBER: 3228 S = CXXDependentScopeMemberExpr::CreateEmpty(Context, 3229 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields], 3230 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields] 3231 ? Record[ASTStmtReader::NumExprFields + 1] 3232 : 0); 3233 break; 3234 3235 case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF: 3236 S = DependentScopeDeclRefExpr::CreateEmpty(Context, 3237 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields], 3238 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields] 3239 ? Record[ASTStmtReader::NumExprFields + 1] 3240 : 0); 3241 break; 3242 3243 case EXPR_CXX_UNRESOLVED_CONSTRUCT: 3244 S = CXXUnresolvedConstructExpr::CreateEmpty(Context, 3245 /*NumArgs=*/Record[ASTStmtReader::NumExprFields]); 3246 break; 3247 3248 case EXPR_CXX_UNRESOLVED_MEMBER: 3249 S = UnresolvedMemberExpr::CreateEmpty(Context, 3250 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields], 3251 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields] 3252 ? Record[ASTStmtReader::NumExprFields + 1] 3253 : 0); 3254 break; 3255 3256 case EXPR_CXX_UNRESOLVED_LOOKUP: 3257 S = UnresolvedLookupExpr::CreateEmpty(Context, 3258 /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields], 3259 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields] 3260 ? Record[ASTStmtReader::NumExprFields + 1] 3261 : 0); 3262 break; 3263 3264 case EXPR_TYPE_TRAIT: 3265 S = TypeTraitExpr::CreateDeserialized(Context, 3266 Record[ASTStmtReader::NumExprFields]); 3267 break; 3268 3269 case EXPR_ARRAY_TYPE_TRAIT: 3270 S = new (Context) ArrayTypeTraitExpr(Empty); 3271 break; 3272 3273 case EXPR_CXX_EXPRESSION_TRAIT: 3274 S = new (Context) ExpressionTraitExpr(Empty); 3275 break; 3276 3277 case EXPR_CXX_NOEXCEPT: 3278 S = new (Context) CXXNoexceptExpr(Empty); 3279 break; 3280 3281 case EXPR_PACK_EXPANSION: 3282 S = new (Context) PackExpansionExpr(Empty); 3283 break; 3284 3285 case EXPR_SIZEOF_PACK: 3286 S = SizeOfPackExpr::CreateDeserialized( 3287 Context, 3288 /*NumPartialArgs=*/Record[ASTStmtReader::NumExprFields]); 3289 break; 3290 3291 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM: 3292 S = new (Context) SubstNonTypeTemplateParmExpr(Empty); 3293 break; 3294 3295 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK: 3296 S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty); 3297 break; 3298 3299 case EXPR_FUNCTION_PARM_PACK: 3300 S = FunctionParmPackExpr::CreateEmpty(Context, 3301 Record[ASTStmtReader::NumExprFields]); 3302 break; 3303 3304 case EXPR_MATERIALIZE_TEMPORARY: 3305 S = new (Context) MaterializeTemporaryExpr(Empty); 3306 break; 3307 3308 case EXPR_CXX_FOLD: 3309 S = new (Context) CXXFoldExpr(Empty); 3310 break; 3311 3312 case EXPR_OPAQUE_VALUE: 3313 S = new (Context) OpaqueValueExpr(Empty); 3314 break; 3315 3316 case EXPR_CUDA_KERNEL_CALL: 3317 S = new (Context) CUDAKernelCallExpr(Context, Empty); 3318 break; 3319 3320 case EXPR_ASTYPE: 3321 S = new (Context) AsTypeExpr(Empty); 3322 break; 3323 3324 case EXPR_PSEUDO_OBJECT: { 3325 unsigned numSemanticExprs = Record[ASTStmtReader::NumExprFields]; 3326 S = PseudoObjectExpr::Create(Context, Empty, numSemanticExprs); 3327 break; 3328 } 3329 3330 case EXPR_ATOMIC: 3331 S = new (Context) AtomicExpr(Empty); 3332 break; 3333 3334 case EXPR_LAMBDA: { 3335 unsigned NumCaptures = Record[ASTStmtReader::NumExprFields]; 3336 unsigned NumArrayIndexVars = Record[ASTStmtReader::NumExprFields + 1]; 3337 S = LambdaExpr::CreateDeserialized(Context, NumCaptures, 3338 NumArrayIndexVars); 3339 break; 3340 } 3341 } 3342 3343 // We hit a STMT_STOP, so we're done with this expression. 3344 if (Finished) 3345 break; 3346 3347 ++NumStatementsRead; 3348 3349 if (S && !IsStmtReference) { 3350 Reader.Visit(S); 3351 StmtEntries[Cursor.GetCurrentBitNo()] = S; 3352 } 3353 3354 3355 assert(Idx == Record.size() && "Invalid deserialization of statement"); 3356 StmtStack.push_back(S); 3357 } 3358 Done: 3359 assert(StmtStack.size() > PrevNumStmts && "Read too many sub-stmts!"); 3360 assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!"); 3361 return StmtStack.pop_back_val(); 3362 } 3363