1 //===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// 9 /// \file 10 /// Implements serialization for Statements and Expressions. 11 /// 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/AST/ASTConcept.h" 15 #include "clang/AST/ASTContext.h" 16 #include "clang/AST/DeclCXX.h" 17 #include "clang/AST/DeclObjC.h" 18 #include "clang/AST/DeclTemplate.h" 19 #include "clang/AST/ExprOpenMP.h" 20 #include "clang/AST/StmtVisitor.h" 21 #include "clang/Lex/Token.h" 22 #include "clang/Serialization/ASTReader.h" 23 #include "clang/Serialization/ASTRecordWriter.h" 24 #include "llvm/Bitstream/BitstreamWriter.h" 25 using namespace clang; 26 27 //===----------------------------------------------------------------------===// 28 // Statement/expression serialization 29 //===----------------------------------------------------------------------===// 30 31 namespace clang { 32 33 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> { 34 ASTWriter &Writer; 35 ASTRecordWriter Record; 36 37 serialization::StmtCode Code; 38 unsigned AbbrevToUse; 39 40 /// A helper that can help us to write a packed bit across function 41 /// calls. For example, we may write separate bits in separate functions: 42 /// 43 /// void VisitA(A* a) { 44 /// Record.push_back(a->isSomething()); 45 /// } 46 /// 47 /// void Visitb(B *b) { 48 /// VisitA(b); 49 /// Record.push_back(b->isAnother()); 50 /// } 51 /// 52 /// In such cases, it'll be better if we can pack these 2 bits. We achieve 53 /// this by writing a zero value in `VisitA` and recorded that first and add 54 /// the new bit to the recorded value. 55 class PakedBitsWriter { 56 public: 57 PakedBitsWriter(ASTRecordWriter &Record) : RecordRef(Record) {} 58 ~PakedBitsWriter() { assert(!CurrentIndex); } 59 60 void addBit(bool Value) { 61 assert(CurrentIndex && "Writing Bits without recording first!"); 62 PackingBits.addBit(Value); 63 } 64 void addBits(uint32_t Value, uint32_t BitsWidth) { 65 assert(CurrentIndex && "Writing Bits without recording first!"); 66 PackingBits.addBits(Value, BitsWidth); 67 } 68 69 void writeBits() { 70 if (!CurrentIndex) 71 return; 72 73 RecordRef[*CurrentIndex] = (uint32_t)PackingBits; 74 CurrentIndex = std::nullopt; 75 PackingBits.reset(0); 76 } 77 78 void updateBits() { 79 writeBits(); 80 81 CurrentIndex = RecordRef.size(); 82 RecordRef.push_back(0); 83 } 84 85 private: 86 BitsPacker PackingBits; 87 ASTRecordWriter &RecordRef; 88 std::optional<unsigned> CurrentIndex; 89 }; 90 91 PakedBitsWriter CurrentPackingBits; 92 93 public: 94 ASTStmtWriter(ASTContext &Context, ASTWriter &Writer, 95 ASTWriter::RecordData &Record) 96 : Writer(Writer), Record(Context, Writer, Record), 97 Code(serialization::STMT_NULL_PTR), AbbrevToUse(0), 98 CurrentPackingBits(this->Record) {} 99 100 ASTStmtWriter(const ASTStmtWriter&) = delete; 101 ASTStmtWriter &operator=(const ASTStmtWriter &) = delete; 102 103 uint64_t Emit() { 104 CurrentPackingBits.writeBits(); 105 assert(Code != serialization::STMT_NULL_PTR && 106 "unhandled sub-statement writing AST file"); 107 return Record.EmitStmt(Code, AbbrevToUse); 108 } 109 110 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo, 111 const TemplateArgumentLoc *Args); 112 113 void VisitStmt(Stmt *S); 114 #define STMT(Type, Base) \ 115 void Visit##Type(Type *); 116 #include "clang/AST/StmtNodes.inc" 117 }; 118 } 119 120 void ASTStmtWriter::AddTemplateKWAndArgsInfo( 121 const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) { 122 Record.AddSourceLocation(ArgInfo.TemplateKWLoc); 123 Record.AddSourceLocation(ArgInfo.LAngleLoc); 124 Record.AddSourceLocation(ArgInfo.RAngleLoc); 125 for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i) 126 Record.AddTemplateArgumentLoc(Args[i]); 127 } 128 129 void ASTStmtWriter::VisitStmt(Stmt *S) { 130 } 131 132 void ASTStmtWriter::VisitNullStmt(NullStmt *S) { 133 VisitStmt(S); 134 Record.AddSourceLocation(S->getSemiLoc()); 135 Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro); 136 Code = serialization::STMT_NULL; 137 } 138 139 void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) { 140 VisitStmt(S); 141 142 Record.push_back(S->size()); 143 Record.push_back(S->hasStoredFPFeatures()); 144 145 for (auto *CS : S->body()) 146 Record.AddStmt(CS); 147 if (S->hasStoredFPFeatures()) 148 Record.push_back(S->getStoredFPFeatures().getAsOpaqueInt()); 149 Record.AddSourceLocation(S->getLBracLoc()); 150 Record.AddSourceLocation(S->getRBracLoc()); 151 152 if (!S->hasStoredFPFeatures()) 153 AbbrevToUse = Writer.getCompoundStmtAbbrev(); 154 155 Code = serialization::STMT_COMPOUND; 156 } 157 158 void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) { 159 VisitStmt(S); 160 Record.push_back(Writer.getSwitchCaseID(S)); 161 Record.AddSourceLocation(S->getKeywordLoc()); 162 Record.AddSourceLocation(S->getColonLoc()); 163 } 164 165 void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) { 166 VisitSwitchCase(S); 167 Record.push_back(S->caseStmtIsGNURange()); 168 Record.AddStmt(S->getLHS()); 169 Record.AddStmt(S->getSubStmt()); 170 if (S->caseStmtIsGNURange()) { 171 Record.AddStmt(S->getRHS()); 172 Record.AddSourceLocation(S->getEllipsisLoc()); 173 } 174 Code = serialization::STMT_CASE; 175 } 176 177 void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) { 178 VisitSwitchCase(S); 179 Record.AddStmt(S->getSubStmt()); 180 Code = serialization::STMT_DEFAULT; 181 } 182 183 void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) { 184 VisitStmt(S); 185 Record.push_back(S->isSideEntry()); 186 Record.AddDeclRef(S->getDecl()); 187 Record.AddStmt(S->getSubStmt()); 188 Record.AddSourceLocation(S->getIdentLoc()); 189 Code = serialization::STMT_LABEL; 190 } 191 192 void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) { 193 VisitStmt(S); 194 Record.push_back(S->getAttrs().size()); 195 Record.AddAttributes(S->getAttrs()); 196 Record.AddStmt(S->getSubStmt()); 197 Record.AddSourceLocation(S->getAttrLoc()); 198 Code = serialization::STMT_ATTRIBUTED; 199 } 200 201 void ASTStmtWriter::VisitIfStmt(IfStmt *S) { 202 VisitStmt(S); 203 204 bool HasElse = S->getElse() != nullptr; 205 bool HasVar = S->getConditionVariableDeclStmt() != nullptr; 206 bool HasInit = S->getInit() != nullptr; 207 208 CurrentPackingBits.updateBits(); 209 210 CurrentPackingBits.addBit(HasElse); 211 CurrentPackingBits.addBit(HasVar); 212 CurrentPackingBits.addBit(HasInit); 213 Record.push_back(static_cast<uint64_t>(S->getStatementKind())); 214 Record.AddStmt(S->getCond()); 215 Record.AddStmt(S->getThen()); 216 if (HasElse) 217 Record.AddStmt(S->getElse()); 218 if (HasVar) 219 Record.AddStmt(S->getConditionVariableDeclStmt()); 220 if (HasInit) 221 Record.AddStmt(S->getInit()); 222 223 Record.AddSourceLocation(S->getIfLoc()); 224 Record.AddSourceLocation(S->getLParenLoc()); 225 Record.AddSourceLocation(S->getRParenLoc()); 226 if (HasElse) 227 Record.AddSourceLocation(S->getElseLoc()); 228 229 Code = serialization::STMT_IF; 230 } 231 232 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) { 233 VisitStmt(S); 234 235 bool HasInit = S->getInit() != nullptr; 236 bool HasVar = S->getConditionVariableDeclStmt() != nullptr; 237 Record.push_back(HasInit); 238 Record.push_back(HasVar); 239 Record.push_back(S->isAllEnumCasesCovered()); 240 241 Record.AddStmt(S->getCond()); 242 Record.AddStmt(S->getBody()); 243 if (HasInit) 244 Record.AddStmt(S->getInit()); 245 if (HasVar) 246 Record.AddStmt(S->getConditionVariableDeclStmt()); 247 248 Record.AddSourceLocation(S->getSwitchLoc()); 249 Record.AddSourceLocation(S->getLParenLoc()); 250 Record.AddSourceLocation(S->getRParenLoc()); 251 252 for (SwitchCase *SC = S->getSwitchCaseList(); SC; 253 SC = SC->getNextSwitchCase()) 254 Record.push_back(Writer.RecordSwitchCaseID(SC)); 255 Code = serialization::STMT_SWITCH; 256 } 257 258 void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) { 259 VisitStmt(S); 260 261 bool HasVar = S->getConditionVariableDeclStmt() != nullptr; 262 Record.push_back(HasVar); 263 264 Record.AddStmt(S->getCond()); 265 Record.AddStmt(S->getBody()); 266 if (HasVar) 267 Record.AddStmt(S->getConditionVariableDeclStmt()); 268 269 Record.AddSourceLocation(S->getWhileLoc()); 270 Record.AddSourceLocation(S->getLParenLoc()); 271 Record.AddSourceLocation(S->getRParenLoc()); 272 Code = serialization::STMT_WHILE; 273 } 274 275 void ASTStmtWriter::VisitDoStmt(DoStmt *S) { 276 VisitStmt(S); 277 Record.AddStmt(S->getCond()); 278 Record.AddStmt(S->getBody()); 279 Record.AddSourceLocation(S->getDoLoc()); 280 Record.AddSourceLocation(S->getWhileLoc()); 281 Record.AddSourceLocation(S->getRParenLoc()); 282 Code = serialization::STMT_DO; 283 } 284 285 void ASTStmtWriter::VisitForStmt(ForStmt *S) { 286 VisitStmt(S); 287 Record.AddStmt(S->getInit()); 288 Record.AddStmt(S->getCond()); 289 Record.AddStmt(S->getConditionVariableDeclStmt()); 290 Record.AddStmt(S->getInc()); 291 Record.AddStmt(S->getBody()); 292 Record.AddSourceLocation(S->getForLoc()); 293 Record.AddSourceLocation(S->getLParenLoc()); 294 Record.AddSourceLocation(S->getRParenLoc()); 295 Code = serialization::STMT_FOR; 296 } 297 298 void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) { 299 VisitStmt(S); 300 Record.AddDeclRef(S->getLabel()); 301 Record.AddSourceLocation(S->getGotoLoc()); 302 Record.AddSourceLocation(S->getLabelLoc()); 303 Code = serialization::STMT_GOTO; 304 } 305 306 void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { 307 VisitStmt(S); 308 Record.AddSourceLocation(S->getGotoLoc()); 309 Record.AddSourceLocation(S->getStarLoc()); 310 Record.AddStmt(S->getTarget()); 311 Code = serialization::STMT_INDIRECT_GOTO; 312 } 313 314 void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) { 315 VisitStmt(S); 316 Record.AddSourceLocation(S->getContinueLoc()); 317 Code = serialization::STMT_CONTINUE; 318 } 319 320 void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) { 321 VisitStmt(S); 322 Record.AddSourceLocation(S->getBreakLoc()); 323 Code = serialization::STMT_BREAK; 324 } 325 326 void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) { 327 VisitStmt(S); 328 329 bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr; 330 Record.push_back(HasNRVOCandidate); 331 332 Record.AddStmt(S->getRetValue()); 333 if (HasNRVOCandidate) 334 Record.AddDeclRef(S->getNRVOCandidate()); 335 336 Record.AddSourceLocation(S->getReturnLoc()); 337 Code = serialization::STMT_RETURN; 338 } 339 340 void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) { 341 VisitStmt(S); 342 Record.AddSourceLocation(S->getBeginLoc()); 343 Record.AddSourceLocation(S->getEndLoc()); 344 DeclGroupRef DG = S->getDeclGroup(); 345 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D) 346 Record.AddDeclRef(*D); 347 Code = serialization::STMT_DECL; 348 } 349 350 void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) { 351 VisitStmt(S); 352 Record.push_back(S->getNumOutputs()); 353 Record.push_back(S->getNumInputs()); 354 Record.push_back(S->getNumClobbers()); 355 Record.AddSourceLocation(S->getAsmLoc()); 356 Record.push_back(S->isVolatile()); 357 Record.push_back(S->isSimple()); 358 } 359 360 void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) { 361 VisitAsmStmt(S); 362 Record.push_back(S->getNumLabels()); 363 Record.AddSourceLocation(S->getRParenLoc()); 364 Record.AddStmt(S->getAsmString()); 365 366 // Outputs 367 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) { 368 Record.AddIdentifierRef(S->getOutputIdentifier(I)); 369 Record.AddStmt(S->getOutputConstraintLiteral(I)); 370 Record.AddStmt(S->getOutputExpr(I)); 371 } 372 373 // Inputs 374 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) { 375 Record.AddIdentifierRef(S->getInputIdentifier(I)); 376 Record.AddStmt(S->getInputConstraintLiteral(I)); 377 Record.AddStmt(S->getInputExpr(I)); 378 } 379 380 // Clobbers 381 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) 382 Record.AddStmt(S->getClobberStringLiteral(I)); 383 384 // Labels 385 for (unsigned I = 0, N = S->getNumLabels(); I != N; ++I) { 386 Record.AddIdentifierRef(S->getLabelIdentifier(I)); 387 Record.AddStmt(S->getLabelExpr(I)); 388 } 389 390 Code = serialization::STMT_GCCASM; 391 } 392 393 void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) { 394 VisitAsmStmt(S); 395 Record.AddSourceLocation(S->getLBraceLoc()); 396 Record.AddSourceLocation(S->getEndLoc()); 397 Record.push_back(S->getNumAsmToks()); 398 Record.AddString(S->getAsmString()); 399 400 // Tokens 401 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) { 402 // FIXME: Move this to ASTRecordWriter? 403 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData()); 404 } 405 406 // Clobbers 407 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) { 408 Record.AddString(S->getClobber(I)); 409 } 410 411 // Outputs 412 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) { 413 Record.AddStmt(S->getOutputExpr(I)); 414 Record.AddString(S->getOutputConstraint(I)); 415 } 416 417 // Inputs 418 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) { 419 Record.AddStmt(S->getInputExpr(I)); 420 Record.AddString(S->getInputConstraint(I)); 421 } 422 423 Code = serialization::STMT_MSASM; 424 } 425 426 void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) { 427 VisitStmt(CoroStmt); 428 Record.push_back(CoroStmt->getParamMoves().size()); 429 for (Stmt *S : CoroStmt->children()) 430 Record.AddStmt(S); 431 Code = serialization::STMT_COROUTINE_BODY; 432 } 433 434 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) { 435 VisitStmt(S); 436 Record.AddSourceLocation(S->getKeywordLoc()); 437 Record.AddStmt(S->getOperand()); 438 Record.AddStmt(S->getPromiseCall()); 439 Record.push_back(S->isImplicit()); 440 Code = serialization::STMT_CORETURN; 441 } 442 443 void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) { 444 VisitExpr(E); 445 Record.AddSourceLocation(E->getKeywordLoc()); 446 for (Stmt *S : E->children()) 447 Record.AddStmt(S); 448 Record.AddStmt(E->getOpaqueValue()); 449 } 450 451 void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) { 452 VisitCoroutineSuspendExpr(E); 453 Record.push_back(E->isImplicit()); 454 Code = serialization::EXPR_COAWAIT; 455 } 456 457 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) { 458 VisitCoroutineSuspendExpr(E); 459 Code = serialization::EXPR_COYIELD; 460 } 461 462 void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) { 463 VisitExpr(E); 464 Record.AddSourceLocation(E->getKeywordLoc()); 465 for (Stmt *S : E->children()) 466 Record.AddStmt(S); 467 Code = serialization::EXPR_DEPENDENT_COAWAIT; 468 } 469 470 static void 471 addConstraintSatisfaction(ASTRecordWriter &Record, 472 const ASTConstraintSatisfaction &Satisfaction) { 473 Record.push_back(Satisfaction.IsSatisfied); 474 Record.push_back(Satisfaction.ContainsErrors); 475 if (!Satisfaction.IsSatisfied) { 476 Record.push_back(Satisfaction.NumRecords); 477 for (const auto &DetailRecord : Satisfaction) { 478 auto *E = dyn_cast<Expr *>(DetailRecord); 479 Record.push_back(/* IsDiagnostic */ E == nullptr); 480 if (E) 481 Record.AddStmt(E); 482 else { 483 auto *Diag = cast<std::pair<SourceLocation, StringRef> *>(DetailRecord); 484 Record.AddSourceLocation(Diag->first); 485 Record.AddString(Diag->second); 486 } 487 } 488 } 489 } 490 491 static void 492 addSubstitutionDiagnostic( 493 ASTRecordWriter &Record, 494 const concepts::Requirement::SubstitutionDiagnostic *D) { 495 Record.AddString(D->SubstitutedEntity); 496 Record.AddSourceLocation(D->DiagLoc); 497 Record.AddString(D->DiagMessage); 498 } 499 500 void ASTStmtWriter::VisitConceptSpecializationExpr( 501 ConceptSpecializationExpr *E) { 502 VisitExpr(E); 503 Record.AddDeclRef(E->getSpecializationDecl()); 504 const ConceptReference *CR = E->getConceptReference(); 505 Record.push_back(CR != nullptr); 506 if (CR) 507 Record.AddConceptReference(CR); 508 if (!E->isValueDependent()) 509 addConstraintSatisfaction(Record, E->getSatisfaction()); 510 511 Code = serialization::EXPR_CONCEPT_SPECIALIZATION; 512 } 513 514 void ASTStmtWriter::VisitRequiresExpr(RequiresExpr *E) { 515 VisitExpr(E); 516 Record.push_back(E->getLocalParameters().size()); 517 Record.push_back(E->getRequirements().size()); 518 Record.AddSourceLocation(E->RequiresExprBits.RequiresKWLoc); 519 Record.push_back(E->RequiresExprBits.IsSatisfied); 520 Record.AddDeclRef(E->getBody()); 521 for (ParmVarDecl *P : E->getLocalParameters()) 522 Record.AddDeclRef(P); 523 for (concepts::Requirement *R : E->getRequirements()) { 524 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(R)) { 525 Record.push_back(concepts::Requirement::RK_Type); 526 Record.push_back(TypeReq->Status); 527 if (TypeReq->Status == concepts::TypeRequirement::SS_SubstitutionFailure) 528 addSubstitutionDiagnostic(Record, TypeReq->getSubstitutionDiagnostic()); 529 else 530 Record.AddTypeSourceInfo(TypeReq->getType()); 531 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(R)) { 532 Record.push_back(ExprReq->getKind()); 533 Record.push_back(ExprReq->Status); 534 if (ExprReq->isExprSubstitutionFailure()) { 535 addSubstitutionDiagnostic( 536 Record, cast<concepts::Requirement::SubstitutionDiagnostic *>( 537 ExprReq->Value)); 538 } else 539 Record.AddStmt(cast<Expr *>(ExprReq->Value)); 540 if (ExprReq->getKind() == concepts::Requirement::RK_Compound) { 541 Record.AddSourceLocation(ExprReq->NoexceptLoc); 542 const auto &RetReq = ExprReq->getReturnTypeRequirement(); 543 if (RetReq.isSubstitutionFailure()) { 544 Record.push_back(2); 545 addSubstitutionDiagnostic(Record, RetReq.getSubstitutionDiagnostic()); 546 } else if (RetReq.isTypeConstraint()) { 547 Record.push_back(1); 548 Record.AddTemplateParameterList( 549 RetReq.getTypeConstraintTemplateParameterList()); 550 if (ExprReq->Status >= 551 concepts::ExprRequirement::SS_ConstraintsNotSatisfied) 552 Record.AddStmt( 553 ExprReq->getReturnTypeRequirementSubstitutedConstraintExpr()); 554 } else { 555 assert(RetReq.isEmpty()); 556 Record.push_back(0); 557 } 558 } 559 } else { 560 auto *NestedReq = cast<concepts::NestedRequirement>(R); 561 Record.push_back(concepts::Requirement::RK_Nested); 562 Record.push_back(NestedReq->hasInvalidConstraint()); 563 if (NestedReq->hasInvalidConstraint()) { 564 Record.AddString(NestedReq->getInvalidConstraintEntity()); 565 addConstraintSatisfaction(Record, *NestedReq->Satisfaction); 566 } else { 567 Record.AddStmt(NestedReq->getConstraintExpr()); 568 if (!NestedReq->isDependent()) 569 addConstraintSatisfaction(Record, *NestedReq->Satisfaction); 570 } 571 } 572 } 573 Record.AddSourceLocation(E->getLParenLoc()); 574 Record.AddSourceLocation(E->getRParenLoc()); 575 Record.AddSourceLocation(E->getEndLoc()); 576 577 Code = serialization::EXPR_REQUIRES; 578 } 579 580 581 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) { 582 VisitStmt(S); 583 // NumCaptures 584 Record.push_back(std::distance(S->capture_begin(), S->capture_end())); 585 586 // CapturedDecl and captured region kind 587 Record.AddDeclRef(S->getCapturedDecl()); 588 Record.push_back(S->getCapturedRegionKind()); 589 590 Record.AddDeclRef(S->getCapturedRecordDecl()); 591 592 // Capture inits 593 for (auto *I : S->capture_inits()) 594 Record.AddStmt(I); 595 596 // Body 597 Record.AddStmt(S->getCapturedStmt()); 598 599 // Captures 600 for (const auto &I : S->captures()) { 601 if (I.capturesThis() || I.capturesVariableArrayType()) 602 Record.AddDeclRef(nullptr); 603 else 604 Record.AddDeclRef(I.getCapturedVar()); 605 Record.push_back(I.getCaptureKind()); 606 Record.AddSourceLocation(I.getLocation()); 607 } 608 609 Code = serialization::STMT_CAPTURED; 610 } 611 612 void ASTStmtWriter::VisitSYCLKernelCallStmt(SYCLKernelCallStmt *S) { 613 VisitStmt(S); 614 Record.AddStmt(S->getOriginalStmt()); 615 Record.AddDeclRef(S->getOutlinedFunctionDecl()); 616 617 Code = serialization::STMT_SYCLKERNELCALL; 618 } 619 620 void ASTStmtWriter::VisitExpr(Expr *E) { 621 VisitStmt(E); 622 623 CurrentPackingBits.updateBits(); 624 CurrentPackingBits.addBits(E->getDependence(), /*BitsWidth=*/5); 625 CurrentPackingBits.addBits(E->getValueKind(), /*BitsWidth=*/2); 626 CurrentPackingBits.addBits(E->getObjectKind(), /*BitsWidth=*/3); 627 628 Record.AddTypeRef(E->getType()); 629 } 630 631 void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) { 632 VisitExpr(E); 633 Record.push_back(E->ConstantExprBits.ResultKind); 634 635 Record.push_back(E->ConstantExprBits.APValueKind); 636 Record.push_back(E->ConstantExprBits.IsUnsigned); 637 Record.push_back(E->ConstantExprBits.BitWidth); 638 // HasCleanup not serialized since we can just query the APValue. 639 Record.push_back(E->ConstantExprBits.IsImmediateInvocation); 640 641 switch (E->getResultStorageKind()) { 642 case ConstantResultStorageKind::None: 643 break; 644 case ConstantResultStorageKind::Int64: 645 Record.push_back(E->Int64Result()); 646 break; 647 case ConstantResultStorageKind::APValue: 648 Record.AddAPValue(E->APValueResult()); 649 break; 650 } 651 652 Record.AddStmt(E->getSubExpr()); 653 Code = serialization::EXPR_CONSTANT; 654 } 655 656 void ASTStmtWriter::VisitOpenACCAsteriskSizeExpr(OpenACCAsteriskSizeExpr *E) { 657 VisitExpr(E); 658 Record.AddSourceLocation(E->getLocation()); 659 Code = serialization::EXPR_OPENACC_ASTERISK_SIZE; 660 } 661 662 void ASTStmtWriter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) { 663 VisitExpr(E); 664 665 Record.AddSourceLocation(E->getLocation()); 666 Record.AddSourceLocation(E->getLParenLocation()); 667 Record.AddSourceLocation(E->getRParenLocation()); 668 Record.AddTypeSourceInfo(E->getTypeSourceInfo()); 669 670 Code = serialization::EXPR_SYCL_UNIQUE_STABLE_NAME; 671 } 672 673 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) { 674 VisitExpr(E); 675 676 bool HasFunctionName = E->getFunctionName() != nullptr; 677 Record.push_back(HasFunctionName); 678 Record.push_back( 679 llvm::to_underlying(E->getIdentKind())); // FIXME: stable encoding 680 Record.push_back(E->isTransparent()); 681 Record.AddSourceLocation(E->getLocation()); 682 if (HasFunctionName) 683 Record.AddStmt(E->getFunctionName()); 684 Code = serialization::EXPR_PREDEFINED; 685 } 686 687 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) { 688 VisitExpr(E); 689 690 CurrentPackingBits.updateBits(); 691 692 CurrentPackingBits.addBit(E->hadMultipleCandidates()); 693 CurrentPackingBits.addBit(E->refersToEnclosingVariableOrCapture()); 694 CurrentPackingBits.addBits(E->isNonOdrUse(), /*Width=*/2); 695 CurrentPackingBits.addBit(E->isImmediateEscalating()); 696 CurrentPackingBits.addBit(E->getDecl() != E->getFoundDecl()); 697 CurrentPackingBits.addBit(E->hasQualifier()); 698 CurrentPackingBits.addBit(E->hasTemplateKWAndArgsInfo()); 699 700 if (E->hasTemplateKWAndArgsInfo()) { 701 unsigned NumTemplateArgs = E->getNumTemplateArgs(); 702 Record.push_back(NumTemplateArgs); 703 } 704 705 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind()); 706 707 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) && 708 (E->getDecl() == E->getFoundDecl()) && 709 nk == DeclarationName::Identifier && E->getObjectKind() == OK_Ordinary) { 710 AbbrevToUse = Writer.getDeclRefExprAbbrev(); 711 } 712 713 if (E->hasQualifier()) 714 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 715 716 if (E->getDecl() != E->getFoundDecl()) 717 Record.AddDeclRef(E->getFoundDecl()); 718 719 if (E->hasTemplateKWAndArgsInfo()) 720 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(), 721 E->getTrailingObjects<TemplateArgumentLoc>()); 722 723 Record.AddDeclRef(E->getDecl()); 724 Record.AddSourceLocation(E->getLocation()); 725 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName()); 726 Code = serialization::EXPR_DECL_REF; 727 } 728 729 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) { 730 VisitExpr(E); 731 Record.AddSourceLocation(E->getLocation()); 732 Record.AddAPInt(E->getValue()); 733 734 if (E->getValue().getBitWidth() == 32) { 735 AbbrevToUse = Writer.getIntegerLiteralAbbrev(); 736 } 737 738 Code = serialization::EXPR_INTEGER_LITERAL; 739 } 740 741 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) { 742 VisitExpr(E); 743 Record.AddSourceLocation(E->getLocation()); 744 Record.push_back(E->getScale()); 745 Record.AddAPInt(E->getValue()); 746 Code = serialization::EXPR_FIXEDPOINT_LITERAL; 747 } 748 749 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) { 750 VisitExpr(E); 751 Record.push_back(E->getRawSemantics()); 752 Record.push_back(E->isExact()); 753 Record.AddAPFloat(E->getValue()); 754 Record.AddSourceLocation(E->getLocation()); 755 Code = serialization::EXPR_FLOATING_LITERAL; 756 } 757 758 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) { 759 VisitExpr(E); 760 Record.AddStmt(E->getSubExpr()); 761 Code = serialization::EXPR_IMAGINARY_LITERAL; 762 } 763 764 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) { 765 VisitExpr(E); 766 767 // Store the various bits of data of StringLiteral. 768 Record.push_back(E->getNumConcatenated()); 769 Record.push_back(E->getLength()); 770 Record.push_back(E->getCharByteWidth()); 771 Record.push_back(llvm::to_underlying(E->getKind())); 772 Record.push_back(E->isPascal()); 773 774 // Store the trailing array of SourceLocation. 775 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) 776 Record.AddSourceLocation(E->getStrTokenLoc(I)); 777 778 // Store the trailing array of char holding the string data. 779 StringRef StrData = E->getBytes(); 780 for (unsigned I = 0, N = E->getByteLength(); I != N; ++I) 781 Record.push_back(StrData[I]); 782 783 Code = serialization::EXPR_STRING_LITERAL; 784 } 785 786 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) { 787 VisitExpr(E); 788 Record.push_back(E->getValue()); 789 Record.AddSourceLocation(E->getLocation()); 790 Record.push_back(llvm::to_underlying(E->getKind())); 791 792 AbbrevToUse = Writer.getCharacterLiteralAbbrev(); 793 794 Code = serialization::EXPR_CHARACTER_LITERAL; 795 } 796 797 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) { 798 VisitExpr(E); 799 Record.push_back(E->isProducedByFoldExpansion()); 800 Record.AddSourceLocation(E->getLParen()); 801 Record.AddSourceLocation(E->getRParen()); 802 Record.AddStmt(E->getSubExpr()); 803 Code = serialization::EXPR_PAREN; 804 } 805 806 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) { 807 VisitExpr(E); 808 Record.push_back(E->getNumExprs()); 809 for (auto *SubStmt : E->exprs()) 810 Record.AddStmt(SubStmt); 811 Record.AddSourceLocation(E->getLParenLoc()); 812 Record.AddSourceLocation(E->getRParenLoc()); 813 Code = serialization::EXPR_PAREN_LIST; 814 } 815 816 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) { 817 VisitExpr(E); 818 bool HasFPFeatures = E->hasStoredFPFeatures(); 819 // Write this first for easy access when deserializing, as they affect the 820 // size of the UnaryOperator. 821 CurrentPackingBits.addBit(HasFPFeatures); 822 Record.AddStmt(E->getSubExpr()); 823 CurrentPackingBits.addBits(E->getOpcode(), 824 /*Width=*/5); // FIXME: stable encoding 825 Record.AddSourceLocation(E->getOperatorLoc()); 826 CurrentPackingBits.addBit(E->canOverflow()); 827 828 if (HasFPFeatures) 829 Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt()); 830 Code = serialization::EXPR_UNARY_OPERATOR; 831 } 832 833 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) { 834 VisitExpr(E); 835 Record.push_back(E->getNumComponents()); 836 Record.push_back(E->getNumExpressions()); 837 Record.AddSourceLocation(E->getOperatorLoc()); 838 Record.AddSourceLocation(E->getRParenLoc()); 839 Record.AddTypeSourceInfo(E->getTypeSourceInfo()); 840 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 841 const OffsetOfNode &ON = E->getComponent(I); 842 Record.push_back(ON.getKind()); // FIXME: Stable encoding 843 Record.AddSourceLocation(ON.getSourceRange().getBegin()); 844 Record.AddSourceLocation(ON.getSourceRange().getEnd()); 845 switch (ON.getKind()) { 846 case OffsetOfNode::Array: 847 Record.push_back(ON.getArrayExprIndex()); 848 break; 849 850 case OffsetOfNode::Field: 851 Record.AddDeclRef(ON.getField()); 852 break; 853 854 case OffsetOfNode::Identifier: 855 Record.AddIdentifierRef(ON.getFieldName()); 856 break; 857 858 case OffsetOfNode::Base: 859 Record.AddCXXBaseSpecifier(*ON.getBase()); 860 break; 861 } 862 } 863 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I) 864 Record.AddStmt(E->getIndexExpr(I)); 865 Code = serialization::EXPR_OFFSETOF; 866 } 867 868 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { 869 VisitExpr(E); 870 Record.push_back(E->getKind()); 871 if (E->isArgumentType()) 872 Record.AddTypeSourceInfo(E->getArgumentTypeInfo()); 873 else { 874 Record.push_back(0); 875 Record.AddStmt(E->getArgumentExpr()); 876 } 877 Record.AddSourceLocation(E->getOperatorLoc()); 878 Record.AddSourceLocation(E->getRParenLoc()); 879 Code = serialization::EXPR_SIZEOF_ALIGN_OF; 880 } 881 882 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { 883 VisitExpr(E); 884 Record.AddStmt(E->getLHS()); 885 Record.AddStmt(E->getRHS()); 886 Record.AddSourceLocation(E->getRBracketLoc()); 887 Code = serialization::EXPR_ARRAY_SUBSCRIPT; 888 } 889 890 void ASTStmtWriter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) { 891 VisitExpr(E); 892 Record.AddStmt(E->getBase()); 893 Record.AddStmt(E->getRowIdx()); 894 Record.AddStmt(E->getColumnIdx()); 895 Record.AddSourceLocation(E->getRBracketLoc()); 896 Code = serialization::EXPR_ARRAY_SUBSCRIPT; 897 } 898 899 void ASTStmtWriter::VisitArraySectionExpr(ArraySectionExpr *E) { 900 VisitExpr(E); 901 Record.writeEnum(E->ASType); 902 Record.AddStmt(E->getBase()); 903 Record.AddStmt(E->getLowerBound()); 904 Record.AddStmt(E->getLength()); 905 if (E->isOMPArraySection()) 906 Record.AddStmt(E->getStride()); 907 Record.AddSourceLocation(E->getColonLocFirst()); 908 909 if (E->isOMPArraySection()) 910 Record.AddSourceLocation(E->getColonLocSecond()); 911 912 Record.AddSourceLocation(E->getRBracketLoc()); 913 Code = serialization::EXPR_ARRAY_SECTION; 914 } 915 916 void ASTStmtWriter::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *E) { 917 VisitExpr(E); 918 Record.push_back(E->getDimensions().size()); 919 Record.AddStmt(E->getBase()); 920 for (Expr *Dim : E->getDimensions()) 921 Record.AddStmt(Dim); 922 for (SourceRange SR : E->getBracketsRanges()) 923 Record.AddSourceRange(SR); 924 Record.AddSourceLocation(E->getLParenLoc()); 925 Record.AddSourceLocation(E->getRParenLoc()); 926 Code = serialization::EXPR_OMP_ARRAY_SHAPING; 927 } 928 929 void ASTStmtWriter::VisitOMPIteratorExpr(OMPIteratorExpr *E) { 930 VisitExpr(E); 931 Record.push_back(E->numOfIterators()); 932 Record.AddSourceLocation(E->getIteratorKwLoc()); 933 Record.AddSourceLocation(E->getLParenLoc()); 934 Record.AddSourceLocation(E->getRParenLoc()); 935 for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) { 936 Record.AddDeclRef(E->getIteratorDecl(I)); 937 Record.AddSourceLocation(E->getAssignLoc(I)); 938 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I); 939 Record.AddStmt(Range.Begin); 940 Record.AddStmt(Range.End); 941 Record.AddStmt(Range.Step); 942 Record.AddSourceLocation(E->getColonLoc(I)); 943 if (Range.Step) 944 Record.AddSourceLocation(E->getSecondColonLoc(I)); 945 // Serialize helpers 946 OMPIteratorHelperData &HD = E->getHelper(I); 947 Record.AddDeclRef(HD.CounterVD); 948 Record.AddStmt(HD.Upper); 949 Record.AddStmt(HD.Update); 950 Record.AddStmt(HD.CounterUpdate); 951 } 952 Code = serialization::EXPR_OMP_ITERATOR; 953 } 954 955 void ASTStmtWriter::VisitCallExpr(CallExpr *E) { 956 VisitExpr(E); 957 958 Record.push_back(E->getNumArgs()); 959 CurrentPackingBits.updateBits(); 960 CurrentPackingBits.addBit(static_cast<bool>(E->getADLCallKind())); 961 CurrentPackingBits.addBit(E->hasStoredFPFeatures()); 962 963 Record.AddSourceLocation(E->getRParenLoc()); 964 Record.AddStmt(E->getCallee()); 965 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); 966 Arg != ArgEnd; ++Arg) 967 Record.AddStmt(*Arg); 968 969 if (E->hasStoredFPFeatures()) 970 Record.push_back(E->getFPFeatures().getAsOpaqueInt()); 971 972 if (!E->hasStoredFPFeatures() && !static_cast<bool>(E->getADLCallKind()) && 973 E->getStmtClass() == Stmt::CallExprClass) 974 AbbrevToUse = Writer.getCallExprAbbrev(); 975 976 Code = serialization::EXPR_CALL; 977 } 978 979 void ASTStmtWriter::VisitRecoveryExpr(RecoveryExpr *E) { 980 VisitExpr(E); 981 Record.push_back(std::distance(E->children().begin(), E->children().end())); 982 Record.AddSourceLocation(E->getBeginLoc()); 983 Record.AddSourceLocation(E->getEndLoc()); 984 for (Stmt *Child : E->children()) 985 Record.AddStmt(Child); 986 Code = serialization::EXPR_RECOVERY; 987 } 988 989 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) { 990 VisitExpr(E); 991 992 bool HasQualifier = E->hasQualifier(); 993 bool HasFoundDecl = E->hasFoundDecl(); 994 bool HasTemplateInfo = E->hasTemplateKWAndArgsInfo(); 995 unsigned NumTemplateArgs = E->getNumTemplateArgs(); 996 997 // Write these first for easy access when deserializing, as they affect the 998 // size of the MemberExpr. 999 CurrentPackingBits.updateBits(); 1000 CurrentPackingBits.addBit(HasQualifier); 1001 CurrentPackingBits.addBit(HasFoundDecl); 1002 CurrentPackingBits.addBit(HasTemplateInfo); 1003 Record.push_back(NumTemplateArgs); 1004 1005 Record.AddStmt(E->getBase()); 1006 Record.AddDeclRef(E->getMemberDecl()); 1007 Record.AddDeclarationNameLoc(E->MemberDNLoc, 1008 E->getMemberDecl()->getDeclName()); 1009 Record.AddSourceLocation(E->getMemberLoc()); 1010 CurrentPackingBits.addBit(E->isArrow()); 1011 CurrentPackingBits.addBit(E->hadMultipleCandidates()); 1012 CurrentPackingBits.addBits(E->isNonOdrUse(), /*Width=*/2); 1013 Record.AddSourceLocation(E->getOperatorLoc()); 1014 1015 if (HasQualifier) 1016 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 1017 1018 if (HasFoundDecl) { 1019 DeclAccessPair FoundDecl = E->getFoundDecl(); 1020 Record.AddDeclRef(FoundDecl.getDecl()); 1021 CurrentPackingBits.addBits(FoundDecl.getAccess(), /*BitWidth=*/2); 1022 } 1023 1024 if (HasTemplateInfo) 1025 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(), 1026 E->getTrailingObjects<TemplateArgumentLoc>()); 1027 1028 Code = serialization::EXPR_MEMBER; 1029 } 1030 1031 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) { 1032 VisitExpr(E); 1033 Record.AddStmt(E->getBase()); 1034 Record.AddSourceLocation(E->getIsaMemberLoc()); 1035 Record.AddSourceLocation(E->getOpLoc()); 1036 Record.push_back(E->isArrow()); 1037 Code = serialization::EXPR_OBJC_ISA; 1038 } 1039 1040 void ASTStmtWriter:: 1041 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 1042 VisitExpr(E); 1043 Record.AddStmt(E->getSubExpr()); 1044 Record.push_back(E->shouldCopy()); 1045 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE; 1046 } 1047 1048 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 1049 VisitExplicitCastExpr(E); 1050 Record.AddSourceLocation(E->getLParenLoc()); 1051 Record.AddSourceLocation(E->getBridgeKeywordLoc()); 1052 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding 1053 Code = serialization::EXPR_OBJC_BRIDGED_CAST; 1054 } 1055 1056 void ASTStmtWriter::VisitCastExpr(CastExpr *E) { 1057 VisitExpr(E); 1058 1059 Record.push_back(E->path_size()); 1060 CurrentPackingBits.updateBits(); 1061 // 7 bits should be enough to store the casting kinds. 1062 CurrentPackingBits.addBits(E->getCastKind(), /*Width=*/7); 1063 CurrentPackingBits.addBit(E->hasStoredFPFeatures()); 1064 Record.AddStmt(E->getSubExpr()); 1065 1066 for (CastExpr::path_iterator 1067 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI) 1068 Record.AddCXXBaseSpecifier(**PI); 1069 1070 if (E->hasStoredFPFeatures()) 1071 Record.push_back(E->getFPFeatures().getAsOpaqueInt()); 1072 } 1073 1074 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) { 1075 VisitExpr(E); 1076 1077 // Write this first for easy access when deserializing, as they affect the 1078 // size of the UnaryOperator. 1079 CurrentPackingBits.updateBits(); 1080 CurrentPackingBits.addBits(E->getOpcode(), /*Width=*/6); 1081 bool HasFPFeatures = E->hasStoredFPFeatures(); 1082 CurrentPackingBits.addBit(HasFPFeatures); 1083 CurrentPackingBits.addBit(E->hasExcludedOverflowPattern()); 1084 Record.AddStmt(E->getLHS()); 1085 Record.AddStmt(E->getRHS()); 1086 Record.AddSourceLocation(E->getOperatorLoc()); 1087 if (HasFPFeatures) 1088 Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt()); 1089 1090 if (!HasFPFeatures && E->getValueKind() == VK_PRValue && 1091 E->getObjectKind() == OK_Ordinary) 1092 AbbrevToUse = Writer.getBinaryOperatorAbbrev(); 1093 1094 Code = serialization::EXPR_BINARY_OPERATOR; 1095 } 1096 1097 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { 1098 VisitBinaryOperator(E); 1099 Record.AddTypeRef(E->getComputationLHSType()); 1100 Record.AddTypeRef(E->getComputationResultType()); 1101 1102 if (!E->hasStoredFPFeatures() && E->getValueKind() == VK_PRValue && 1103 E->getObjectKind() == OK_Ordinary) 1104 AbbrevToUse = Writer.getCompoundAssignOperatorAbbrev(); 1105 1106 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR; 1107 } 1108 1109 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) { 1110 VisitExpr(E); 1111 Record.AddStmt(E->getCond()); 1112 Record.AddStmt(E->getLHS()); 1113 Record.AddStmt(E->getRHS()); 1114 Record.AddSourceLocation(E->getQuestionLoc()); 1115 Record.AddSourceLocation(E->getColonLoc()); 1116 Code = serialization::EXPR_CONDITIONAL_OPERATOR; 1117 } 1118 1119 void 1120 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { 1121 VisitExpr(E); 1122 Record.AddStmt(E->getOpaqueValue()); 1123 Record.AddStmt(E->getCommon()); 1124 Record.AddStmt(E->getCond()); 1125 Record.AddStmt(E->getTrueExpr()); 1126 Record.AddStmt(E->getFalseExpr()); 1127 Record.AddSourceLocation(E->getQuestionLoc()); 1128 Record.AddSourceLocation(E->getColonLoc()); 1129 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR; 1130 } 1131 1132 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) { 1133 VisitCastExpr(E); 1134 CurrentPackingBits.addBit(E->isPartOfExplicitCast()); 1135 1136 if (E->path_size() == 0 && !E->hasStoredFPFeatures()) 1137 AbbrevToUse = Writer.getExprImplicitCastAbbrev(); 1138 1139 Code = serialization::EXPR_IMPLICIT_CAST; 1140 } 1141 1142 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) { 1143 VisitCastExpr(E); 1144 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten()); 1145 } 1146 1147 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) { 1148 VisitExplicitCastExpr(E); 1149 Record.AddSourceLocation(E->getLParenLoc()); 1150 Record.AddSourceLocation(E->getRParenLoc()); 1151 Code = serialization::EXPR_CSTYLE_CAST; 1152 } 1153 1154 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { 1155 VisitExpr(E); 1156 Record.AddSourceLocation(E->getLParenLoc()); 1157 Record.AddTypeSourceInfo(E->getTypeSourceInfo()); 1158 Record.AddStmt(E->getInitializer()); 1159 Record.push_back(E->isFileScope()); 1160 Code = serialization::EXPR_COMPOUND_LITERAL; 1161 } 1162 1163 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { 1164 VisitExpr(E); 1165 Record.AddStmt(E->getBase()); 1166 Record.AddIdentifierRef(&E->getAccessor()); 1167 Record.AddSourceLocation(E->getAccessorLoc()); 1168 Code = serialization::EXPR_EXT_VECTOR_ELEMENT; 1169 } 1170 1171 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) { 1172 VisitExpr(E); 1173 // NOTE: only add the (possibly null) syntactic form. 1174 // No need to serialize the isSemanticForm flag and the semantic form. 1175 Record.AddStmt(E->getSyntacticForm()); 1176 Record.AddSourceLocation(E->getLBraceLoc()); 1177 Record.AddSourceLocation(E->getRBraceLoc()); 1178 bool isArrayFiller = isa<Expr *>(E->ArrayFillerOrUnionFieldInit); 1179 Record.push_back(isArrayFiller); 1180 if (isArrayFiller) 1181 Record.AddStmt(E->getArrayFiller()); 1182 else 1183 Record.AddDeclRef(E->getInitializedFieldInUnion()); 1184 Record.push_back(E->hadArrayRangeDesignator()); 1185 Record.push_back(E->getNumInits()); 1186 if (isArrayFiller) { 1187 // ArrayFiller may have filled "holes" due to designated initializer. 1188 // Replace them by 0 to indicate that the filler goes in that place. 1189 Expr *filler = E->getArrayFiller(); 1190 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) 1191 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr); 1192 } else { 1193 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) 1194 Record.AddStmt(E->getInit(I)); 1195 } 1196 Code = serialization::EXPR_INIT_LIST; 1197 } 1198 1199 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { 1200 VisitExpr(E); 1201 Record.push_back(E->getNumSubExprs()); 1202 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) 1203 Record.AddStmt(E->getSubExpr(I)); 1204 Record.AddSourceLocation(E->getEqualOrColonLoc()); 1205 Record.push_back(E->usesGNUSyntax()); 1206 for (const DesignatedInitExpr::Designator &D : E->designators()) { 1207 if (D.isFieldDesignator()) { 1208 if (FieldDecl *Field = D.getFieldDecl()) { 1209 Record.push_back(serialization::DESIG_FIELD_DECL); 1210 Record.AddDeclRef(Field); 1211 } else { 1212 Record.push_back(serialization::DESIG_FIELD_NAME); 1213 Record.AddIdentifierRef(D.getFieldName()); 1214 } 1215 Record.AddSourceLocation(D.getDotLoc()); 1216 Record.AddSourceLocation(D.getFieldLoc()); 1217 } else if (D.isArrayDesignator()) { 1218 Record.push_back(serialization::DESIG_ARRAY); 1219 Record.push_back(D.getArrayIndex()); 1220 Record.AddSourceLocation(D.getLBracketLoc()); 1221 Record.AddSourceLocation(D.getRBracketLoc()); 1222 } else { 1223 assert(D.isArrayRangeDesignator() && "Unknown designator"); 1224 Record.push_back(serialization::DESIG_ARRAY_RANGE); 1225 Record.push_back(D.getArrayIndex()); 1226 Record.AddSourceLocation(D.getLBracketLoc()); 1227 Record.AddSourceLocation(D.getEllipsisLoc()); 1228 Record.AddSourceLocation(D.getRBracketLoc()); 1229 } 1230 } 1231 Code = serialization::EXPR_DESIGNATED_INIT; 1232 } 1233 1234 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) { 1235 VisitExpr(E); 1236 Record.AddStmt(E->getBase()); 1237 Record.AddStmt(E->getUpdater()); 1238 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE; 1239 } 1240 1241 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) { 1242 VisitExpr(E); 1243 Code = serialization::EXPR_NO_INIT; 1244 } 1245 1246 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { 1247 VisitExpr(E); 1248 Record.AddStmt(E->SubExprs[0]); 1249 Record.AddStmt(E->SubExprs[1]); 1250 Code = serialization::EXPR_ARRAY_INIT_LOOP; 1251 } 1252 1253 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { 1254 VisitExpr(E); 1255 Code = serialization::EXPR_ARRAY_INIT_INDEX; 1256 } 1257 1258 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { 1259 VisitExpr(E); 1260 Code = serialization::EXPR_IMPLICIT_VALUE_INIT; 1261 } 1262 1263 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) { 1264 VisitExpr(E); 1265 Record.AddStmt(E->getSubExpr()); 1266 Record.AddTypeSourceInfo(E->getWrittenTypeInfo()); 1267 Record.AddSourceLocation(E->getBuiltinLoc()); 1268 Record.AddSourceLocation(E->getRParenLoc()); 1269 Record.push_back(E->isMicrosoftABI()); 1270 Code = serialization::EXPR_VA_ARG; 1271 } 1272 1273 void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) { 1274 VisitExpr(E); 1275 Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext())); 1276 Record.AddSourceLocation(E->getBeginLoc()); 1277 Record.AddSourceLocation(E->getEndLoc()); 1278 Record.push_back(llvm::to_underlying(E->getIdentKind())); 1279 Code = serialization::EXPR_SOURCE_LOC; 1280 } 1281 1282 void ASTStmtWriter::VisitEmbedExpr(EmbedExpr *E) { 1283 VisitExpr(E); 1284 Record.AddSourceLocation(E->getBeginLoc()); 1285 Record.AddSourceLocation(E->getEndLoc()); 1286 Record.AddStmt(E->getDataStringLiteral()); 1287 Record.writeUInt32(E->getStartingElementPos()); 1288 Record.writeUInt32(E->getDataElementCount()); 1289 Code = serialization::EXPR_BUILTIN_PP_EMBED; 1290 } 1291 1292 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) { 1293 VisitExpr(E); 1294 Record.AddSourceLocation(E->getAmpAmpLoc()); 1295 Record.AddSourceLocation(E->getLabelLoc()); 1296 Record.AddDeclRef(E->getLabel()); 1297 Code = serialization::EXPR_ADDR_LABEL; 1298 } 1299 1300 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) { 1301 VisitExpr(E); 1302 Record.AddStmt(E->getSubStmt()); 1303 Record.AddSourceLocation(E->getLParenLoc()); 1304 Record.AddSourceLocation(E->getRParenLoc()); 1305 Record.push_back(E->getTemplateDepth()); 1306 Code = serialization::EXPR_STMT; 1307 } 1308 1309 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) { 1310 VisitExpr(E); 1311 Record.AddStmt(E->getCond()); 1312 Record.AddStmt(E->getLHS()); 1313 Record.AddStmt(E->getRHS()); 1314 Record.AddSourceLocation(E->getBuiltinLoc()); 1315 Record.AddSourceLocation(E->getRParenLoc()); 1316 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue()); 1317 Code = serialization::EXPR_CHOOSE; 1318 } 1319 1320 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) { 1321 VisitExpr(E); 1322 Record.AddSourceLocation(E->getTokenLocation()); 1323 Code = serialization::EXPR_GNU_NULL; 1324 } 1325 1326 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { 1327 VisitExpr(E); 1328 Record.push_back(E->getNumSubExprs()); 1329 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) 1330 Record.AddStmt(E->getExpr(I)); 1331 Record.AddSourceLocation(E->getBuiltinLoc()); 1332 Record.AddSourceLocation(E->getRParenLoc()); 1333 Code = serialization::EXPR_SHUFFLE_VECTOR; 1334 } 1335 1336 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) { 1337 VisitExpr(E); 1338 Record.AddSourceLocation(E->getBuiltinLoc()); 1339 Record.AddSourceLocation(E->getRParenLoc()); 1340 Record.AddTypeSourceInfo(E->getTypeSourceInfo()); 1341 Record.AddStmt(E->getSrcExpr()); 1342 Code = serialization::EXPR_CONVERT_VECTOR; 1343 } 1344 1345 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) { 1346 VisitExpr(E); 1347 Record.AddDeclRef(E->getBlockDecl()); 1348 Code = serialization::EXPR_BLOCK; 1349 } 1350 1351 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) { 1352 VisitExpr(E); 1353 1354 Record.push_back(E->getNumAssocs()); 1355 Record.push_back(E->isExprPredicate()); 1356 Record.push_back(E->ResultIndex); 1357 Record.AddSourceLocation(E->getGenericLoc()); 1358 Record.AddSourceLocation(E->getDefaultLoc()); 1359 Record.AddSourceLocation(E->getRParenLoc()); 1360 1361 Stmt **Stmts = E->getTrailingObjects<Stmt *>(); 1362 // Add 1 to account for the controlling expression which is the first 1363 // expression in the trailing array of Stmt *. This is not needed for 1364 // the trailing array of TypeSourceInfo *. 1365 for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I) 1366 Record.AddStmt(Stmts[I]); 1367 1368 TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>(); 1369 for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I) 1370 Record.AddTypeSourceInfo(TSIs[I]); 1371 1372 Code = serialization::EXPR_GENERIC_SELECTION; 1373 } 1374 1375 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) { 1376 VisitExpr(E); 1377 Record.push_back(E->getNumSemanticExprs()); 1378 1379 // Push the result index. Currently, this needs to exactly match 1380 // the encoding used internally for ResultIndex. 1381 unsigned result = E->getResultExprIndex(); 1382 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1); 1383 Record.push_back(result); 1384 1385 Record.AddStmt(E->getSyntacticForm()); 1386 for (PseudoObjectExpr::semantics_iterator 1387 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) { 1388 Record.AddStmt(*i); 1389 } 1390 Code = serialization::EXPR_PSEUDO_OBJECT; 1391 } 1392 1393 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) { 1394 VisitExpr(E); 1395 Record.push_back(E->getOp()); 1396 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) 1397 Record.AddStmt(E->getSubExprs()[I]); 1398 Record.AddSourceLocation(E->getBuiltinLoc()); 1399 Record.AddSourceLocation(E->getRParenLoc()); 1400 Code = serialization::EXPR_ATOMIC; 1401 } 1402 1403 //===----------------------------------------------------------------------===// 1404 // Objective-C Expressions and Statements. 1405 //===----------------------------------------------------------------------===// 1406 1407 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) { 1408 VisitExpr(E); 1409 Record.AddStmt(E->getString()); 1410 Record.AddSourceLocation(E->getAtLoc()); 1411 Code = serialization::EXPR_OBJC_STRING_LITERAL; 1412 } 1413 1414 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) { 1415 VisitExpr(E); 1416 Record.AddStmt(E->getSubExpr()); 1417 Record.AddDeclRef(E->getBoxingMethod()); 1418 Record.AddSourceRange(E->getSourceRange()); 1419 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION; 1420 } 1421 1422 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) { 1423 VisitExpr(E); 1424 Record.push_back(E->getNumElements()); 1425 for (unsigned i = 0; i < E->getNumElements(); i++) 1426 Record.AddStmt(E->getElement(i)); 1427 Record.AddDeclRef(E->getArrayWithObjectsMethod()); 1428 Record.AddSourceRange(E->getSourceRange()); 1429 Code = serialization::EXPR_OBJC_ARRAY_LITERAL; 1430 } 1431 1432 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) { 1433 VisitExpr(E); 1434 Record.push_back(E->getNumElements()); 1435 Record.push_back(E->HasPackExpansions); 1436 for (unsigned i = 0; i < E->getNumElements(); i++) { 1437 ObjCDictionaryElement Element = E->getKeyValueElement(i); 1438 Record.AddStmt(Element.Key); 1439 Record.AddStmt(Element.Value); 1440 if (E->HasPackExpansions) { 1441 Record.AddSourceLocation(Element.EllipsisLoc); 1442 unsigned NumExpansions = 0; 1443 if (Element.NumExpansions) 1444 NumExpansions = *Element.NumExpansions + 1; 1445 Record.push_back(NumExpansions); 1446 } 1447 } 1448 1449 Record.AddDeclRef(E->getDictWithObjectsMethod()); 1450 Record.AddSourceRange(E->getSourceRange()); 1451 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL; 1452 } 1453 1454 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { 1455 VisitExpr(E); 1456 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo()); 1457 Record.AddSourceLocation(E->getAtLoc()); 1458 Record.AddSourceLocation(E->getRParenLoc()); 1459 Code = serialization::EXPR_OBJC_ENCODE; 1460 } 1461 1462 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { 1463 VisitExpr(E); 1464 Record.AddSelectorRef(E->getSelector()); 1465 Record.AddSourceLocation(E->getAtLoc()); 1466 Record.AddSourceLocation(E->getRParenLoc()); 1467 Code = serialization::EXPR_OBJC_SELECTOR_EXPR; 1468 } 1469 1470 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { 1471 VisitExpr(E); 1472 Record.AddDeclRef(E->getProtocol()); 1473 Record.AddSourceLocation(E->getAtLoc()); 1474 Record.AddSourceLocation(E->ProtoLoc); 1475 Record.AddSourceLocation(E->getRParenLoc()); 1476 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR; 1477 } 1478 1479 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { 1480 VisitExpr(E); 1481 Record.AddDeclRef(E->getDecl()); 1482 Record.AddSourceLocation(E->getLocation()); 1483 Record.AddSourceLocation(E->getOpLoc()); 1484 Record.AddStmt(E->getBase()); 1485 Record.push_back(E->isArrow()); 1486 Record.push_back(E->isFreeIvar()); 1487 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR; 1488 } 1489 1490 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 1491 VisitExpr(E); 1492 Record.push_back(E->SetterAndMethodRefFlags.getInt()); 1493 Record.push_back(E->isImplicitProperty()); 1494 if (E->isImplicitProperty()) { 1495 Record.AddDeclRef(E->getImplicitPropertyGetter()); 1496 Record.AddDeclRef(E->getImplicitPropertySetter()); 1497 } else { 1498 Record.AddDeclRef(E->getExplicitProperty()); 1499 } 1500 Record.AddSourceLocation(E->getLocation()); 1501 Record.AddSourceLocation(E->getReceiverLocation()); 1502 if (E->isObjectReceiver()) { 1503 Record.push_back(0); 1504 Record.AddStmt(E->getBase()); 1505 } else if (E->isSuperReceiver()) { 1506 Record.push_back(1); 1507 Record.AddTypeRef(E->getSuperReceiverType()); 1508 } else { 1509 Record.push_back(2); 1510 Record.AddDeclRef(E->getClassReceiver()); 1511 } 1512 1513 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR; 1514 } 1515 1516 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { 1517 VisitExpr(E); 1518 Record.AddSourceLocation(E->getRBracket()); 1519 Record.AddStmt(E->getBaseExpr()); 1520 Record.AddStmt(E->getKeyExpr()); 1521 Record.AddDeclRef(E->getAtIndexMethodDecl()); 1522 Record.AddDeclRef(E->setAtIndexMethodDecl()); 1523 1524 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR; 1525 } 1526 1527 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) { 1528 VisitExpr(E); 1529 Record.push_back(E->getNumArgs()); 1530 Record.push_back(E->getNumStoredSelLocs()); 1531 Record.push_back(E->SelLocsKind); 1532 Record.push_back(E->isDelegateInitCall()); 1533 Record.push_back(E->IsImplicit); 1534 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding 1535 switch (E->getReceiverKind()) { 1536 case ObjCMessageExpr::Instance: 1537 Record.AddStmt(E->getInstanceReceiver()); 1538 break; 1539 1540 case ObjCMessageExpr::Class: 1541 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo()); 1542 break; 1543 1544 case ObjCMessageExpr::SuperClass: 1545 case ObjCMessageExpr::SuperInstance: 1546 Record.AddTypeRef(E->getSuperType()); 1547 Record.AddSourceLocation(E->getSuperLoc()); 1548 break; 1549 } 1550 1551 if (E->getMethodDecl()) { 1552 Record.push_back(1); 1553 Record.AddDeclRef(E->getMethodDecl()); 1554 } else { 1555 Record.push_back(0); 1556 Record.AddSelectorRef(E->getSelector()); 1557 } 1558 1559 Record.AddSourceLocation(E->getLeftLoc()); 1560 Record.AddSourceLocation(E->getRightLoc()); 1561 1562 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); 1563 Arg != ArgEnd; ++Arg) 1564 Record.AddStmt(*Arg); 1565 1566 SourceLocation *Locs = E->getStoredSelLocs(); 1567 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i) 1568 Record.AddSourceLocation(Locs[i]); 1569 1570 Code = serialization::EXPR_OBJC_MESSAGE_EXPR; 1571 } 1572 1573 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { 1574 VisitStmt(S); 1575 Record.AddStmt(S->getElement()); 1576 Record.AddStmt(S->getCollection()); 1577 Record.AddStmt(S->getBody()); 1578 Record.AddSourceLocation(S->getForLoc()); 1579 Record.AddSourceLocation(S->getRParenLoc()); 1580 Code = serialization::STMT_OBJC_FOR_COLLECTION; 1581 } 1582 1583 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { 1584 VisitStmt(S); 1585 Record.AddStmt(S->getCatchBody()); 1586 Record.AddDeclRef(S->getCatchParamDecl()); 1587 Record.AddSourceLocation(S->getAtCatchLoc()); 1588 Record.AddSourceLocation(S->getRParenLoc()); 1589 Code = serialization::STMT_OBJC_CATCH; 1590 } 1591 1592 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 1593 VisitStmt(S); 1594 Record.AddStmt(S->getFinallyBody()); 1595 Record.AddSourceLocation(S->getAtFinallyLoc()); 1596 Code = serialization::STMT_OBJC_FINALLY; 1597 } 1598 1599 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) { 1600 VisitStmt(S); // FIXME: no test coverage. 1601 Record.AddStmt(S->getSubStmt()); 1602 Record.AddSourceLocation(S->getAtLoc()); 1603 Code = serialization::STMT_OBJC_AUTORELEASE_POOL; 1604 } 1605 1606 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { 1607 VisitStmt(S); 1608 Record.push_back(S->getNumCatchStmts()); 1609 Record.push_back(S->getFinallyStmt() != nullptr); 1610 Record.AddStmt(S->getTryBody()); 1611 for (ObjCAtCatchStmt *C : S->catch_stmts()) 1612 Record.AddStmt(C); 1613 if (S->getFinallyStmt()) 1614 Record.AddStmt(S->getFinallyStmt()); 1615 Record.AddSourceLocation(S->getAtTryLoc()); 1616 Code = serialization::STMT_OBJC_AT_TRY; 1617 } 1618 1619 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { 1620 VisitStmt(S); // FIXME: no test coverage. 1621 Record.AddStmt(S->getSynchExpr()); 1622 Record.AddStmt(S->getSynchBody()); 1623 Record.AddSourceLocation(S->getAtSynchronizedLoc()); 1624 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED; 1625 } 1626 1627 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { 1628 VisitStmt(S); // FIXME: no test coverage. 1629 Record.AddStmt(S->getThrowExpr()); 1630 Record.AddSourceLocation(S->getThrowLoc()); 1631 Code = serialization::STMT_OBJC_AT_THROW; 1632 } 1633 1634 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { 1635 VisitExpr(E); 1636 Record.push_back(E->getValue()); 1637 Record.AddSourceLocation(E->getLocation()); 1638 Code = serialization::EXPR_OBJC_BOOL_LITERAL; 1639 } 1640 1641 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) { 1642 VisitExpr(E); 1643 Record.AddSourceRange(E->getSourceRange()); 1644 Record.AddVersionTuple(E->getVersion()); 1645 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK; 1646 } 1647 1648 //===----------------------------------------------------------------------===// 1649 // C++ Expressions and Statements. 1650 //===----------------------------------------------------------------------===// 1651 1652 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) { 1653 VisitStmt(S); 1654 Record.AddSourceLocation(S->getCatchLoc()); 1655 Record.AddDeclRef(S->getExceptionDecl()); 1656 Record.AddStmt(S->getHandlerBlock()); 1657 Code = serialization::STMT_CXX_CATCH; 1658 } 1659 1660 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) { 1661 VisitStmt(S); 1662 Record.push_back(S->getNumHandlers()); 1663 Record.AddSourceLocation(S->getTryLoc()); 1664 Record.AddStmt(S->getTryBlock()); 1665 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i) 1666 Record.AddStmt(S->getHandler(i)); 1667 Code = serialization::STMT_CXX_TRY; 1668 } 1669 1670 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { 1671 VisitStmt(S); 1672 Record.AddSourceLocation(S->getForLoc()); 1673 Record.AddSourceLocation(S->getCoawaitLoc()); 1674 Record.AddSourceLocation(S->getColonLoc()); 1675 Record.AddSourceLocation(S->getRParenLoc()); 1676 Record.AddStmt(S->getInit()); 1677 Record.AddStmt(S->getRangeStmt()); 1678 Record.AddStmt(S->getBeginStmt()); 1679 Record.AddStmt(S->getEndStmt()); 1680 Record.AddStmt(S->getCond()); 1681 Record.AddStmt(S->getInc()); 1682 Record.AddStmt(S->getLoopVarStmt()); 1683 Record.AddStmt(S->getBody()); 1684 Code = serialization::STMT_CXX_FOR_RANGE; 1685 } 1686 1687 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) { 1688 VisitStmt(S); 1689 Record.AddSourceLocation(S->getKeywordLoc()); 1690 Record.push_back(S->isIfExists()); 1691 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc()); 1692 Record.AddDeclarationNameInfo(S->getNameInfo()); 1693 Record.AddStmt(S->getSubStmt()); 1694 Code = serialization::STMT_MS_DEPENDENT_EXISTS; 1695 } 1696 1697 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 1698 VisitCallExpr(E); 1699 Record.push_back(E->getOperator()); 1700 Record.AddSourceRange(E->Range); 1701 1702 if (!E->hasStoredFPFeatures() && !static_cast<bool>(E->getADLCallKind())) 1703 AbbrevToUse = Writer.getCXXOperatorCallExprAbbrev(); 1704 1705 Code = serialization::EXPR_CXX_OPERATOR_CALL; 1706 } 1707 1708 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { 1709 VisitCallExpr(E); 1710 1711 if (!E->hasStoredFPFeatures() && !static_cast<bool>(E->getADLCallKind())) 1712 AbbrevToUse = Writer.getCXXMemberCallExprAbbrev(); 1713 1714 Code = serialization::EXPR_CXX_MEMBER_CALL; 1715 } 1716 1717 void ASTStmtWriter::VisitCXXRewrittenBinaryOperator( 1718 CXXRewrittenBinaryOperator *E) { 1719 VisitExpr(E); 1720 Record.push_back(E->isReversed()); 1721 Record.AddStmt(E->getSemanticForm()); 1722 Code = serialization::EXPR_CXX_REWRITTEN_BINARY_OPERATOR; 1723 } 1724 1725 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) { 1726 VisitExpr(E); 1727 1728 Record.push_back(E->getNumArgs()); 1729 Record.push_back(E->isElidable()); 1730 Record.push_back(E->hadMultipleCandidates()); 1731 Record.push_back(E->isListInitialization()); 1732 Record.push_back(E->isStdInitListInitialization()); 1733 Record.push_back(E->requiresZeroInitialization()); 1734 Record.push_back( 1735 llvm::to_underlying(E->getConstructionKind())); // FIXME: stable encoding 1736 Record.push_back(E->isImmediateEscalating()); 1737 Record.AddSourceLocation(E->getLocation()); 1738 Record.AddDeclRef(E->getConstructor()); 1739 Record.AddSourceRange(E->getParenOrBraceRange()); 1740 1741 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 1742 Record.AddStmt(E->getArg(I)); 1743 1744 Code = serialization::EXPR_CXX_CONSTRUCT; 1745 } 1746 1747 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) { 1748 VisitExpr(E); 1749 Record.AddDeclRef(E->getConstructor()); 1750 Record.AddSourceLocation(E->getLocation()); 1751 Record.push_back(E->constructsVBase()); 1752 Record.push_back(E->inheritedFromVBase()); 1753 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT; 1754 } 1755 1756 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { 1757 VisitCXXConstructExpr(E); 1758 Record.AddTypeSourceInfo(E->getTypeSourceInfo()); 1759 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT; 1760 } 1761 1762 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) { 1763 VisitExpr(E); 1764 Record.push_back(E->LambdaExprBits.NumCaptures); 1765 Record.AddSourceRange(E->IntroducerRange); 1766 Record.push_back(E->LambdaExprBits.CaptureDefault); // FIXME: stable encoding 1767 Record.AddSourceLocation(E->CaptureDefaultLoc); 1768 Record.push_back(E->LambdaExprBits.ExplicitParams); 1769 Record.push_back(E->LambdaExprBits.ExplicitResultType); 1770 Record.AddSourceLocation(E->ClosingBrace); 1771 1772 // Add capture initializers. 1773 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(), 1774 CEnd = E->capture_init_end(); 1775 C != CEnd; ++C) { 1776 Record.AddStmt(*C); 1777 } 1778 1779 // Don't serialize the body. It belongs to the call operator declaration. 1780 // LambdaExpr only stores a copy of the Stmt *. 1781 1782 Code = serialization::EXPR_LAMBDA; 1783 } 1784 1785 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) { 1786 VisitExpr(E); 1787 Record.AddStmt(E->getSubExpr()); 1788 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST; 1789 } 1790 1791 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { 1792 VisitExplicitCastExpr(E); 1793 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc())); 1794 CurrentPackingBits.addBit(E->getAngleBrackets().isValid()); 1795 if (E->getAngleBrackets().isValid()) 1796 Record.AddSourceRange(E->getAngleBrackets()); 1797 } 1798 1799 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) { 1800 VisitCXXNamedCastExpr(E); 1801 Code = serialization::EXPR_CXX_STATIC_CAST; 1802 } 1803 1804 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 1805 VisitCXXNamedCastExpr(E); 1806 Code = serialization::EXPR_CXX_DYNAMIC_CAST; 1807 } 1808 1809 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) { 1810 VisitCXXNamedCastExpr(E); 1811 Code = serialization::EXPR_CXX_REINTERPRET_CAST; 1812 } 1813 1814 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) { 1815 VisitCXXNamedCastExpr(E); 1816 Code = serialization::EXPR_CXX_CONST_CAST; 1817 } 1818 1819 void ASTStmtWriter::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) { 1820 VisitCXXNamedCastExpr(E); 1821 Code = serialization::EXPR_CXX_ADDRSPACE_CAST; 1822 } 1823 1824 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { 1825 VisitExplicitCastExpr(E); 1826 Record.AddSourceLocation(E->getLParenLoc()); 1827 Record.AddSourceLocation(E->getRParenLoc()); 1828 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST; 1829 } 1830 1831 void ASTStmtWriter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) { 1832 VisitExplicitCastExpr(E); 1833 Record.AddSourceLocation(E->getBeginLoc()); 1834 Record.AddSourceLocation(E->getEndLoc()); 1835 Code = serialization::EXPR_BUILTIN_BIT_CAST; 1836 } 1837 1838 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) { 1839 VisitCallExpr(E); 1840 Record.AddSourceLocation(E->UDSuffixLoc); 1841 Code = serialization::EXPR_USER_DEFINED_LITERAL; 1842 } 1843 1844 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 1845 VisitExpr(E); 1846 Record.push_back(E->getValue()); 1847 Record.AddSourceLocation(E->getLocation()); 1848 Code = serialization::EXPR_CXX_BOOL_LITERAL; 1849 } 1850 1851 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { 1852 VisitExpr(E); 1853 Record.AddSourceLocation(E->getLocation()); 1854 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL; 1855 } 1856 1857 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { 1858 VisitExpr(E); 1859 Record.AddSourceRange(E->getSourceRange()); 1860 if (E->isTypeOperand()) { 1861 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo()); 1862 Code = serialization::EXPR_CXX_TYPEID_TYPE; 1863 } else { 1864 Record.AddStmt(E->getExprOperand()); 1865 Code = serialization::EXPR_CXX_TYPEID_EXPR; 1866 } 1867 } 1868 1869 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) { 1870 VisitExpr(E); 1871 Record.AddSourceLocation(E->getLocation()); 1872 Record.push_back(E->isImplicit()); 1873 Record.push_back(E->isCapturedByCopyInLambdaWithExplicitObjectParameter()); 1874 1875 Code = serialization::EXPR_CXX_THIS; 1876 } 1877 1878 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) { 1879 VisitExpr(E); 1880 Record.AddSourceLocation(E->getThrowLoc()); 1881 Record.AddStmt(E->getSubExpr()); 1882 Record.push_back(E->isThrownVariableInScope()); 1883 Code = serialization::EXPR_CXX_THROW; 1884 } 1885 1886 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 1887 VisitExpr(E); 1888 Record.AddDeclRef(E->getParam()); 1889 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext())); 1890 Record.AddSourceLocation(E->getUsedLocation()); 1891 Record.push_back(E->hasRewrittenInit()); 1892 if (E->hasRewrittenInit()) 1893 Record.AddStmt(E->getRewrittenExpr()); 1894 Code = serialization::EXPR_CXX_DEFAULT_ARG; 1895 } 1896 1897 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { 1898 VisitExpr(E); 1899 Record.push_back(E->hasRewrittenInit()); 1900 Record.AddDeclRef(E->getField()); 1901 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext())); 1902 Record.AddSourceLocation(E->getExprLoc()); 1903 if (E->hasRewrittenInit()) 1904 Record.AddStmt(E->getRewrittenExpr()); 1905 Code = serialization::EXPR_CXX_DEFAULT_INIT; 1906 } 1907 1908 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 1909 VisitExpr(E); 1910 Record.AddCXXTemporary(E->getTemporary()); 1911 Record.AddStmt(E->getSubExpr()); 1912 Code = serialization::EXPR_CXX_BIND_TEMPORARY; 1913 } 1914 1915 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { 1916 VisitExpr(E); 1917 Record.AddTypeSourceInfo(E->getTypeSourceInfo()); 1918 Record.AddSourceLocation(E->getRParenLoc()); 1919 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT; 1920 } 1921 1922 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) { 1923 VisitExpr(E); 1924 1925 Record.push_back(E->isArray()); 1926 Record.push_back(E->hasInitializer()); 1927 Record.push_back(E->getNumPlacementArgs()); 1928 Record.push_back(E->isParenTypeId()); 1929 1930 Record.push_back(E->isGlobalNew()); 1931 Record.push_back(E->passAlignment()); 1932 Record.push_back(E->doesUsualArrayDeleteWantSize()); 1933 Record.push_back(E->CXXNewExprBits.HasInitializer); 1934 Record.push_back(E->CXXNewExprBits.StoredInitializationStyle); 1935 1936 Record.AddDeclRef(E->getOperatorNew()); 1937 Record.AddDeclRef(E->getOperatorDelete()); 1938 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo()); 1939 if (E->isParenTypeId()) 1940 Record.AddSourceRange(E->getTypeIdParens()); 1941 Record.AddSourceRange(E->getSourceRange()); 1942 Record.AddSourceRange(E->getDirectInitRange()); 1943 1944 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end(); 1945 I != N; ++I) 1946 Record.AddStmt(*I); 1947 1948 Code = serialization::EXPR_CXX_NEW; 1949 } 1950 1951 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { 1952 VisitExpr(E); 1953 Record.push_back(E->isGlobalDelete()); 1954 Record.push_back(E->isArrayForm()); 1955 Record.push_back(E->isArrayFormAsWritten()); 1956 Record.push_back(E->doesUsualArrayDeleteWantSize()); 1957 Record.AddDeclRef(E->getOperatorDelete()); 1958 Record.AddStmt(E->getArgument()); 1959 Record.AddSourceLocation(E->getBeginLoc()); 1960 1961 Code = serialization::EXPR_CXX_DELETE; 1962 } 1963 1964 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { 1965 VisitExpr(E); 1966 1967 Record.AddStmt(E->getBase()); 1968 Record.push_back(E->isArrow()); 1969 Record.AddSourceLocation(E->getOperatorLoc()); 1970 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 1971 Record.AddTypeSourceInfo(E->getScopeTypeInfo()); 1972 Record.AddSourceLocation(E->getColonColonLoc()); 1973 Record.AddSourceLocation(E->getTildeLoc()); 1974 1975 // PseudoDestructorTypeStorage. 1976 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier()); 1977 if (E->getDestroyedTypeIdentifier()) 1978 Record.AddSourceLocation(E->getDestroyedTypeLoc()); 1979 else 1980 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo()); 1981 1982 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR; 1983 } 1984 1985 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) { 1986 VisitExpr(E); 1987 Record.push_back(E->getNumObjects()); 1988 for (auto &Obj : E->getObjects()) { 1989 if (auto *BD = Obj.dyn_cast<BlockDecl *>()) { 1990 Record.push_back(serialization::COK_Block); 1991 Record.AddDeclRef(BD); 1992 } else if (auto *CLE = Obj.dyn_cast<CompoundLiteralExpr *>()) { 1993 Record.push_back(serialization::COK_CompoundLiteral); 1994 Record.AddStmt(CLE); 1995 } 1996 } 1997 1998 Record.push_back(E->cleanupsHaveSideEffects()); 1999 Record.AddStmt(E->getSubExpr()); 2000 Code = serialization::EXPR_EXPR_WITH_CLEANUPS; 2001 } 2002 2003 void ASTStmtWriter::VisitCXXDependentScopeMemberExpr( 2004 CXXDependentScopeMemberExpr *E) { 2005 VisitExpr(E); 2006 2007 // Don't emit anything here (or if you do you will have to update 2008 // the corresponding deserialization function). 2009 Record.push_back(E->getNumTemplateArgs()); 2010 CurrentPackingBits.updateBits(); 2011 CurrentPackingBits.addBit(E->hasTemplateKWAndArgsInfo()); 2012 CurrentPackingBits.addBit(E->hasFirstQualifierFoundInScope()); 2013 2014 if (E->hasTemplateKWAndArgsInfo()) { 2015 const ASTTemplateKWAndArgsInfo &ArgInfo = 2016 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); 2017 AddTemplateKWAndArgsInfo(ArgInfo, 2018 E->getTrailingObjects<TemplateArgumentLoc>()); 2019 } 2020 2021 CurrentPackingBits.addBit(E->isArrow()); 2022 2023 Record.AddTypeRef(E->getBaseType()); 2024 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 2025 CurrentPackingBits.addBit(!E->isImplicitAccess()); 2026 if (!E->isImplicitAccess()) 2027 Record.AddStmt(E->getBase()); 2028 2029 Record.AddSourceLocation(E->getOperatorLoc()); 2030 2031 if (E->hasFirstQualifierFoundInScope()) 2032 Record.AddDeclRef(E->getFirstQualifierFoundInScope()); 2033 2034 Record.AddDeclarationNameInfo(E->MemberNameInfo); 2035 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER; 2036 } 2037 2038 void 2039 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { 2040 VisitExpr(E); 2041 2042 // Don't emit anything here, HasTemplateKWAndArgsInfo must be 2043 // emitted first. 2044 CurrentPackingBits.addBit( 2045 E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo); 2046 2047 if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) { 2048 const ASTTemplateKWAndArgsInfo &ArgInfo = 2049 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); 2050 // 16 bits should be enought to store the number of args 2051 CurrentPackingBits.addBits(ArgInfo.NumTemplateArgs, /*Width=*/16); 2052 AddTemplateKWAndArgsInfo(ArgInfo, 2053 E->getTrailingObjects<TemplateArgumentLoc>()); 2054 } 2055 2056 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 2057 Record.AddDeclarationNameInfo(E->NameInfo); 2058 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF; 2059 } 2060 2061 void 2062 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) { 2063 VisitExpr(E); 2064 Record.push_back(E->getNumArgs()); 2065 for (CXXUnresolvedConstructExpr::arg_iterator 2066 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI) 2067 Record.AddStmt(*ArgI); 2068 Record.AddTypeSourceInfo(E->getTypeSourceInfo()); 2069 Record.AddSourceLocation(E->getLParenLoc()); 2070 Record.AddSourceLocation(E->getRParenLoc()); 2071 Record.push_back(E->isListInitialization()); 2072 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT; 2073 } 2074 2075 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) { 2076 VisitExpr(E); 2077 2078 Record.push_back(E->getNumDecls()); 2079 2080 CurrentPackingBits.updateBits(); 2081 CurrentPackingBits.addBit(E->hasTemplateKWAndArgsInfo()); 2082 if (E->hasTemplateKWAndArgsInfo()) { 2083 const ASTTemplateKWAndArgsInfo &ArgInfo = 2084 *E->getTrailingASTTemplateKWAndArgsInfo(); 2085 Record.push_back(ArgInfo.NumTemplateArgs); 2086 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc()); 2087 } 2088 2089 for (OverloadExpr::decls_iterator OvI = E->decls_begin(), 2090 OvE = E->decls_end(); 2091 OvI != OvE; ++OvI) { 2092 Record.AddDeclRef(OvI.getDecl()); 2093 Record.push_back(OvI.getAccess()); 2094 } 2095 2096 Record.AddDeclarationNameInfo(E->getNameInfo()); 2097 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 2098 } 2099 2100 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { 2101 VisitOverloadExpr(E); 2102 CurrentPackingBits.addBit(E->isArrow()); 2103 CurrentPackingBits.addBit(E->hasUnresolvedUsing()); 2104 CurrentPackingBits.addBit(!E->isImplicitAccess()); 2105 if (!E->isImplicitAccess()) 2106 Record.AddStmt(E->getBase()); 2107 2108 Record.AddSourceLocation(E->getOperatorLoc()); 2109 2110 Record.AddTypeRef(E->getBaseType()); 2111 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER; 2112 } 2113 2114 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { 2115 VisitOverloadExpr(E); 2116 CurrentPackingBits.addBit(E->requiresADL()); 2117 Record.AddDeclRef(E->getNamingClass()); 2118 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP; 2119 2120 if (Writer.isWritingStdCXXNamedModules() && Writer.getChain()) { 2121 // Referencing all the possible declarations to make sure the change get 2122 // propagted. 2123 DeclarationName Name = E->getName(); 2124 for (auto *Found : 2125 Record.getASTContext().getTranslationUnitDecl()->lookup(Name)) 2126 if (Found->isFromASTFile()) 2127 Writer.GetDeclRef(Found); 2128 2129 llvm::SmallVector<NamespaceDecl *> ExternalNSs; 2130 Writer.getChain()->ReadKnownNamespaces(ExternalNSs); 2131 for (auto *NS : ExternalNSs) 2132 for (auto *Found : NS->lookup(Name)) 2133 Writer.GetDeclRef(Found); 2134 } 2135 } 2136 2137 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) { 2138 VisitExpr(E); 2139 Record.push_back(E->TypeTraitExprBits.NumArgs); 2140 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding 2141 Record.push_back(E->TypeTraitExprBits.Value); 2142 Record.AddSourceRange(E->getSourceRange()); 2143 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 2144 Record.AddTypeSourceInfo(E->getArg(I)); 2145 Code = serialization::EXPR_TYPE_TRAIT; 2146 } 2147 2148 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 2149 VisitExpr(E); 2150 Record.push_back(E->getTrait()); 2151 Record.push_back(E->getValue()); 2152 Record.AddSourceRange(E->getSourceRange()); 2153 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo()); 2154 Record.AddStmt(E->getDimensionExpression()); 2155 Code = serialization::EXPR_ARRAY_TYPE_TRAIT; 2156 } 2157 2158 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { 2159 VisitExpr(E); 2160 Record.push_back(E->getTrait()); 2161 Record.push_back(E->getValue()); 2162 Record.AddSourceRange(E->getSourceRange()); 2163 Record.AddStmt(E->getQueriedExpression()); 2164 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT; 2165 } 2166 2167 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { 2168 VisitExpr(E); 2169 Record.push_back(E->getValue()); 2170 Record.AddSourceRange(E->getSourceRange()); 2171 Record.AddStmt(E->getOperand()); 2172 Code = serialization::EXPR_CXX_NOEXCEPT; 2173 } 2174 2175 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) { 2176 VisitExpr(E); 2177 Record.AddSourceLocation(E->getEllipsisLoc()); 2178 Record.push_back(E->NumExpansions); 2179 Record.AddStmt(E->getPattern()); 2180 Code = serialization::EXPR_PACK_EXPANSION; 2181 } 2182 2183 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { 2184 VisitExpr(E); 2185 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size() 2186 : 0); 2187 Record.AddSourceLocation(E->OperatorLoc); 2188 Record.AddSourceLocation(E->PackLoc); 2189 Record.AddSourceLocation(E->RParenLoc); 2190 Record.AddDeclRef(E->Pack); 2191 if (E->isPartiallySubstituted()) { 2192 for (const auto &TA : E->getPartialArguments()) 2193 Record.AddTemplateArgument(TA); 2194 } else if (!E->isValueDependent()) { 2195 Record.push_back(E->getPackLength()); 2196 } 2197 Code = serialization::EXPR_SIZEOF_PACK; 2198 } 2199 2200 void ASTStmtWriter::VisitPackIndexingExpr(PackIndexingExpr *E) { 2201 VisitExpr(E); 2202 Record.push_back(E->TransformedExpressions); 2203 Record.push_back(E->FullySubstituted); 2204 Record.AddSourceLocation(E->getEllipsisLoc()); 2205 Record.AddSourceLocation(E->getRSquareLoc()); 2206 Record.AddStmt(E->getPackIdExpression()); 2207 Record.AddStmt(E->getIndexExpr()); 2208 for (Expr *Sub : E->getExpressions()) 2209 Record.AddStmt(Sub); 2210 Code = serialization::EXPR_PACK_INDEXING; 2211 } 2212 2213 void ASTStmtWriter::VisitResolvedUnexpandedPackExpr( 2214 ResolvedUnexpandedPackExpr *E) { 2215 VisitExpr(E); 2216 Record.push_back(E->getNumExprs()); 2217 Record.AddSourceLocation(E->getBeginLoc()); 2218 for (Expr *Sub : E->getExprs()) 2219 Record.AddStmt(Sub); 2220 Code = serialization::EXPR_RESOLVED_UNEXPANDED_PACK; 2221 } 2222 2223 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr( 2224 SubstNonTypeTemplateParmExpr *E) { 2225 VisitExpr(E); 2226 Record.AddDeclRef(E->getAssociatedDecl()); 2227 CurrentPackingBits.addBit(E->isReferenceParameter()); 2228 CurrentPackingBits.addBits(E->getIndex(), /*Width=*/12); 2229 CurrentPackingBits.addBit((bool)E->getPackIndex()); 2230 if (auto PackIndex = E->getPackIndex()) 2231 Record.push_back(*PackIndex + 1); 2232 2233 Record.AddSourceLocation(E->getNameLoc()); 2234 Record.AddStmt(E->getReplacement()); 2235 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM; 2236 } 2237 2238 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr( 2239 SubstNonTypeTemplateParmPackExpr *E) { 2240 VisitExpr(E); 2241 Record.AddDeclRef(E->getAssociatedDecl()); 2242 Record.push_back(E->getIndex()); 2243 Record.AddTemplateArgument(E->getArgumentPack()); 2244 Record.AddSourceLocation(E->getParameterPackLocation()); 2245 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK; 2246 } 2247 2248 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) { 2249 VisitExpr(E); 2250 Record.push_back(E->getNumExpansions()); 2251 Record.AddDeclRef(E->getParameterPack()); 2252 Record.AddSourceLocation(E->getParameterPackLocation()); 2253 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end(); 2254 I != End; ++I) 2255 Record.AddDeclRef(*I); 2256 Code = serialization::EXPR_FUNCTION_PARM_PACK; 2257 } 2258 2259 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { 2260 VisitExpr(E); 2261 Record.push_back(static_cast<bool>(E->getLifetimeExtendedTemporaryDecl())); 2262 if (E->getLifetimeExtendedTemporaryDecl()) 2263 Record.AddDeclRef(E->getLifetimeExtendedTemporaryDecl()); 2264 else 2265 Record.AddStmt(E->getSubExpr()); 2266 Code = serialization::EXPR_MATERIALIZE_TEMPORARY; 2267 } 2268 2269 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) { 2270 VisitExpr(E); 2271 Record.AddSourceLocation(E->LParenLoc); 2272 Record.AddSourceLocation(E->EllipsisLoc); 2273 Record.AddSourceLocation(E->RParenLoc); 2274 Record.push_back(E->NumExpansions); 2275 Record.AddStmt(E->SubExprs[0]); 2276 Record.AddStmt(E->SubExprs[1]); 2277 Record.AddStmt(E->SubExprs[2]); 2278 Record.push_back(E->Opcode); 2279 Code = serialization::EXPR_CXX_FOLD; 2280 } 2281 2282 void ASTStmtWriter::VisitCXXParenListInitExpr(CXXParenListInitExpr *E) { 2283 VisitExpr(E); 2284 ArrayRef<Expr *> InitExprs = E->getInitExprs(); 2285 Record.push_back(InitExprs.size()); 2286 Record.push_back(E->getUserSpecifiedInitExprs().size()); 2287 Record.AddSourceLocation(E->getInitLoc()); 2288 Record.AddSourceLocation(E->getBeginLoc()); 2289 Record.AddSourceLocation(E->getEndLoc()); 2290 for (Expr *InitExpr : E->getInitExprs()) 2291 Record.AddStmt(InitExpr); 2292 Expr *ArrayFiller = E->getArrayFiller(); 2293 FieldDecl *UnionField = E->getInitializedFieldInUnion(); 2294 bool HasArrayFillerOrUnionDecl = ArrayFiller || UnionField; 2295 Record.push_back(HasArrayFillerOrUnionDecl); 2296 if (HasArrayFillerOrUnionDecl) { 2297 Record.push_back(static_cast<bool>(ArrayFiller)); 2298 if (ArrayFiller) 2299 Record.AddStmt(ArrayFiller); 2300 else 2301 Record.AddDeclRef(UnionField); 2302 } 2303 Code = serialization::EXPR_CXX_PAREN_LIST_INIT; 2304 } 2305 2306 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { 2307 VisitExpr(E); 2308 Record.AddStmt(E->getSourceExpr()); 2309 Record.AddSourceLocation(E->getLocation()); 2310 Record.push_back(E->isUnique()); 2311 Code = serialization::EXPR_OPAQUE_VALUE; 2312 } 2313 2314 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) { 2315 VisitExpr(E); 2316 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary 2317 llvm_unreachable("Cannot write TypoExpr nodes"); 2318 } 2319 2320 //===----------------------------------------------------------------------===// 2321 // CUDA Expressions and Statements. 2322 //===----------------------------------------------------------------------===// 2323 2324 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 2325 VisitCallExpr(E); 2326 Record.AddStmt(E->getConfig()); 2327 Code = serialization::EXPR_CUDA_KERNEL_CALL; 2328 } 2329 2330 //===----------------------------------------------------------------------===// 2331 // OpenCL Expressions and Statements. 2332 //===----------------------------------------------------------------------===// 2333 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) { 2334 VisitExpr(E); 2335 Record.AddSourceLocation(E->getBuiltinLoc()); 2336 Record.AddSourceLocation(E->getRParenLoc()); 2337 Record.AddStmt(E->getSrcExpr()); 2338 Code = serialization::EXPR_ASTYPE; 2339 } 2340 2341 //===----------------------------------------------------------------------===// 2342 // Microsoft Expressions and Statements. 2343 //===----------------------------------------------------------------------===// 2344 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) { 2345 VisitExpr(E); 2346 Record.push_back(E->isArrow()); 2347 Record.AddStmt(E->getBaseExpr()); 2348 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 2349 Record.AddSourceLocation(E->getMemberLoc()); 2350 Record.AddDeclRef(E->getPropertyDecl()); 2351 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR; 2352 } 2353 2354 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) { 2355 VisitExpr(E); 2356 Record.AddStmt(E->getBase()); 2357 Record.AddStmt(E->getIdx()); 2358 Record.AddSourceLocation(E->getRBracketLoc()); 2359 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR; 2360 } 2361 2362 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) { 2363 VisitExpr(E); 2364 Record.AddSourceRange(E->getSourceRange()); 2365 Record.AddDeclRef(E->getGuidDecl()); 2366 if (E->isTypeOperand()) { 2367 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo()); 2368 Code = serialization::EXPR_CXX_UUIDOF_TYPE; 2369 } else { 2370 Record.AddStmt(E->getExprOperand()); 2371 Code = serialization::EXPR_CXX_UUIDOF_EXPR; 2372 } 2373 } 2374 2375 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) { 2376 VisitStmt(S); 2377 Record.AddSourceLocation(S->getExceptLoc()); 2378 Record.AddStmt(S->getFilterExpr()); 2379 Record.AddStmt(S->getBlock()); 2380 Code = serialization::STMT_SEH_EXCEPT; 2381 } 2382 2383 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) { 2384 VisitStmt(S); 2385 Record.AddSourceLocation(S->getFinallyLoc()); 2386 Record.AddStmt(S->getBlock()); 2387 Code = serialization::STMT_SEH_FINALLY; 2388 } 2389 2390 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) { 2391 VisitStmt(S); 2392 Record.push_back(S->getIsCXXTry()); 2393 Record.AddSourceLocation(S->getTryLoc()); 2394 Record.AddStmt(S->getTryBlock()); 2395 Record.AddStmt(S->getHandler()); 2396 Code = serialization::STMT_SEH_TRY; 2397 } 2398 2399 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) { 2400 VisitStmt(S); 2401 Record.AddSourceLocation(S->getLeaveLoc()); 2402 Code = serialization::STMT_SEH_LEAVE; 2403 } 2404 2405 //===----------------------------------------------------------------------===// 2406 // OpenMP Directives. 2407 //===----------------------------------------------------------------------===// 2408 2409 void ASTStmtWriter::VisitOMPCanonicalLoop(OMPCanonicalLoop *S) { 2410 VisitStmt(S); 2411 for (Stmt *SubStmt : S->SubStmts) 2412 Record.AddStmt(SubStmt); 2413 Code = serialization::STMT_OMP_CANONICAL_LOOP; 2414 } 2415 2416 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) { 2417 Record.writeOMPChildren(E->Data); 2418 Record.AddSourceLocation(E->getBeginLoc()); 2419 Record.AddSourceLocation(E->getEndLoc()); 2420 } 2421 2422 void ASTStmtWriter::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) { 2423 VisitStmt(D); 2424 Record.writeUInt32(D->getLoopsNumber()); 2425 VisitOMPExecutableDirective(D); 2426 } 2427 2428 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) { 2429 VisitOMPLoopBasedDirective(D); 2430 } 2431 2432 void ASTStmtWriter::VisitOMPMetaDirective(OMPMetaDirective *D) { 2433 VisitStmt(D); 2434 Record.push_back(D->getNumClauses()); 2435 VisitOMPExecutableDirective(D); 2436 Code = serialization::STMT_OMP_META_DIRECTIVE; 2437 } 2438 2439 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) { 2440 VisitStmt(D); 2441 VisitOMPExecutableDirective(D); 2442 Record.writeBool(D->hasCancel()); 2443 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE; 2444 } 2445 2446 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) { 2447 VisitOMPLoopDirective(D); 2448 Code = serialization::STMT_OMP_SIMD_DIRECTIVE; 2449 } 2450 2451 void ASTStmtWriter::VisitOMPLoopTransformationDirective( 2452 OMPLoopTransformationDirective *D) { 2453 VisitOMPLoopBasedDirective(D); 2454 Record.writeUInt32(D->getNumGeneratedLoops()); 2455 } 2456 2457 void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective *D) { 2458 VisitOMPLoopTransformationDirective(D); 2459 Code = serialization::STMT_OMP_TILE_DIRECTIVE; 2460 } 2461 2462 void ASTStmtWriter::VisitOMPUnrollDirective(OMPUnrollDirective *D) { 2463 VisitOMPLoopTransformationDirective(D); 2464 Code = serialization::STMT_OMP_UNROLL_DIRECTIVE; 2465 } 2466 2467 void ASTStmtWriter::VisitOMPReverseDirective(OMPReverseDirective *D) { 2468 VisitOMPLoopTransformationDirective(D); 2469 Code = serialization::STMT_OMP_REVERSE_DIRECTIVE; 2470 } 2471 2472 void ASTStmtWriter::VisitOMPInterchangeDirective(OMPInterchangeDirective *D) { 2473 VisitOMPLoopTransformationDirective(D); 2474 Code = serialization::STMT_OMP_INTERCHANGE_DIRECTIVE; 2475 } 2476 2477 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) { 2478 VisitOMPLoopDirective(D); 2479 Record.writeBool(D->hasCancel()); 2480 Code = serialization::STMT_OMP_FOR_DIRECTIVE; 2481 } 2482 2483 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) { 2484 VisitOMPLoopDirective(D); 2485 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE; 2486 } 2487 2488 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) { 2489 VisitStmt(D); 2490 VisitOMPExecutableDirective(D); 2491 Record.writeBool(D->hasCancel()); 2492 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE; 2493 } 2494 2495 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) { 2496 VisitStmt(D); 2497 VisitOMPExecutableDirective(D); 2498 Record.writeBool(D->hasCancel()); 2499 Code = serialization::STMT_OMP_SECTION_DIRECTIVE; 2500 } 2501 2502 void ASTStmtWriter::VisitOMPScopeDirective(OMPScopeDirective *D) { 2503 VisitStmt(D); 2504 VisitOMPExecutableDirective(D); 2505 Code = serialization::STMT_OMP_SCOPE_DIRECTIVE; 2506 } 2507 2508 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) { 2509 VisitStmt(D); 2510 VisitOMPExecutableDirective(D); 2511 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE; 2512 } 2513 2514 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) { 2515 VisitStmt(D); 2516 VisitOMPExecutableDirective(D); 2517 Code = serialization::STMT_OMP_MASTER_DIRECTIVE; 2518 } 2519 2520 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) { 2521 VisitStmt(D); 2522 VisitOMPExecutableDirective(D); 2523 Record.AddDeclarationNameInfo(D->getDirectiveName()); 2524 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE; 2525 } 2526 2527 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) { 2528 VisitOMPLoopDirective(D); 2529 Record.writeBool(D->hasCancel()); 2530 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE; 2531 } 2532 2533 void ASTStmtWriter::VisitOMPParallelForSimdDirective( 2534 OMPParallelForSimdDirective *D) { 2535 VisitOMPLoopDirective(D); 2536 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE; 2537 } 2538 2539 void ASTStmtWriter::VisitOMPParallelMasterDirective( 2540 OMPParallelMasterDirective *D) { 2541 VisitStmt(D); 2542 VisitOMPExecutableDirective(D); 2543 Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE; 2544 } 2545 2546 void ASTStmtWriter::VisitOMPParallelMaskedDirective( 2547 OMPParallelMaskedDirective *D) { 2548 VisitStmt(D); 2549 VisitOMPExecutableDirective(D); 2550 Code = serialization::STMT_OMP_PARALLEL_MASKED_DIRECTIVE; 2551 } 2552 2553 void ASTStmtWriter::VisitOMPParallelSectionsDirective( 2554 OMPParallelSectionsDirective *D) { 2555 VisitStmt(D); 2556 VisitOMPExecutableDirective(D); 2557 Record.writeBool(D->hasCancel()); 2558 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE; 2559 } 2560 2561 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) { 2562 VisitStmt(D); 2563 VisitOMPExecutableDirective(D); 2564 Record.writeBool(D->hasCancel()); 2565 Code = serialization::STMT_OMP_TASK_DIRECTIVE; 2566 } 2567 2568 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) { 2569 VisitStmt(D); 2570 VisitOMPExecutableDirective(D); 2571 Record.writeBool(D->isXLHSInRHSPart()); 2572 Record.writeBool(D->isPostfixUpdate()); 2573 Record.writeBool(D->isFailOnly()); 2574 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE; 2575 } 2576 2577 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) { 2578 VisitStmt(D); 2579 VisitOMPExecutableDirective(D); 2580 Code = serialization::STMT_OMP_TARGET_DIRECTIVE; 2581 } 2582 2583 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) { 2584 VisitStmt(D); 2585 VisitOMPExecutableDirective(D); 2586 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE; 2587 } 2588 2589 void ASTStmtWriter::VisitOMPTargetEnterDataDirective( 2590 OMPTargetEnterDataDirective *D) { 2591 VisitStmt(D); 2592 VisitOMPExecutableDirective(D); 2593 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE; 2594 } 2595 2596 void ASTStmtWriter::VisitOMPTargetExitDataDirective( 2597 OMPTargetExitDataDirective *D) { 2598 VisitStmt(D); 2599 VisitOMPExecutableDirective(D); 2600 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE; 2601 } 2602 2603 void ASTStmtWriter::VisitOMPTargetParallelDirective( 2604 OMPTargetParallelDirective *D) { 2605 VisitStmt(D); 2606 VisitOMPExecutableDirective(D); 2607 Record.writeBool(D->hasCancel()); 2608 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE; 2609 } 2610 2611 void ASTStmtWriter::VisitOMPTargetParallelForDirective( 2612 OMPTargetParallelForDirective *D) { 2613 VisitOMPLoopDirective(D); 2614 Record.writeBool(D->hasCancel()); 2615 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE; 2616 } 2617 2618 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) { 2619 VisitStmt(D); 2620 VisitOMPExecutableDirective(D); 2621 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE; 2622 } 2623 2624 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) { 2625 VisitStmt(D); 2626 VisitOMPExecutableDirective(D); 2627 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE; 2628 } 2629 2630 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) { 2631 VisitStmt(D); 2632 Record.push_back(D->getNumClauses()); 2633 VisitOMPExecutableDirective(D); 2634 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE; 2635 } 2636 2637 void ASTStmtWriter::VisitOMPAssumeDirective(OMPAssumeDirective *D) { 2638 VisitStmt(D); 2639 VisitOMPExecutableDirective(D); 2640 Code = serialization::STMT_OMP_ASSUME_DIRECTIVE; 2641 } 2642 2643 void ASTStmtWriter::VisitOMPErrorDirective(OMPErrorDirective *D) { 2644 VisitStmt(D); 2645 Record.push_back(D->getNumClauses()); 2646 VisitOMPExecutableDirective(D); 2647 Code = serialization::STMT_OMP_ERROR_DIRECTIVE; 2648 } 2649 2650 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) { 2651 VisitStmt(D); 2652 VisitOMPExecutableDirective(D); 2653 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE; 2654 } 2655 2656 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) { 2657 VisitStmt(D); 2658 VisitOMPExecutableDirective(D); 2659 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE; 2660 } 2661 2662 void ASTStmtWriter::VisitOMPDepobjDirective(OMPDepobjDirective *D) { 2663 VisitStmt(D); 2664 VisitOMPExecutableDirective(D); 2665 Code = serialization::STMT_OMP_DEPOBJ_DIRECTIVE; 2666 } 2667 2668 void ASTStmtWriter::VisitOMPScanDirective(OMPScanDirective *D) { 2669 VisitStmt(D); 2670 VisitOMPExecutableDirective(D); 2671 Code = serialization::STMT_OMP_SCAN_DIRECTIVE; 2672 } 2673 2674 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) { 2675 VisitStmt(D); 2676 VisitOMPExecutableDirective(D); 2677 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE; 2678 } 2679 2680 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) { 2681 VisitStmt(D); 2682 VisitOMPExecutableDirective(D); 2683 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE; 2684 } 2685 2686 void ASTStmtWriter::VisitOMPCancellationPointDirective( 2687 OMPCancellationPointDirective *D) { 2688 VisitStmt(D); 2689 VisitOMPExecutableDirective(D); 2690 Record.writeEnum(D->getCancelRegion()); 2691 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE; 2692 } 2693 2694 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) { 2695 VisitStmt(D); 2696 VisitOMPExecutableDirective(D); 2697 Record.writeEnum(D->getCancelRegion()); 2698 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE; 2699 } 2700 2701 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) { 2702 VisitOMPLoopDirective(D); 2703 Record.writeBool(D->hasCancel()); 2704 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE; 2705 } 2706 2707 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) { 2708 VisitOMPLoopDirective(D); 2709 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE; 2710 } 2711 2712 void ASTStmtWriter::VisitOMPMasterTaskLoopDirective( 2713 OMPMasterTaskLoopDirective *D) { 2714 VisitOMPLoopDirective(D); 2715 Record.writeBool(D->hasCancel()); 2716 Code = serialization::STMT_OMP_MASTER_TASKLOOP_DIRECTIVE; 2717 } 2718 2719 void ASTStmtWriter::VisitOMPMaskedTaskLoopDirective( 2720 OMPMaskedTaskLoopDirective *D) { 2721 VisitOMPLoopDirective(D); 2722 Record.writeBool(D->hasCancel()); 2723 Code = serialization::STMT_OMP_MASKED_TASKLOOP_DIRECTIVE; 2724 } 2725 2726 void ASTStmtWriter::VisitOMPMasterTaskLoopSimdDirective( 2727 OMPMasterTaskLoopSimdDirective *D) { 2728 VisitOMPLoopDirective(D); 2729 Code = serialization::STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE; 2730 } 2731 2732 void ASTStmtWriter::VisitOMPMaskedTaskLoopSimdDirective( 2733 OMPMaskedTaskLoopSimdDirective *D) { 2734 VisitOMPLoopDirective(D); 2735 Code = serialization::STMT_OMP_MASKED_TASKLOOP_SIMD_DIRECTIVE; 2736 } 2737 2738 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopDirective( 2739 OMPParallelMasterTaskLoopDirective *D) { 2740 VisitOMPLoopDirective(D); 2741 Record.writeBool(D->hasCancel()); 2742 Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE; 2743 } 2744 2745 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopDirective( 2746 OMPParallelMaskedTaskLoopDirective *D) { 2747 VisitOMPLoopDirective(D); 2748 Record.writeBool(D->hasCancel()); 2749 Code = serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_DIRECTIVE; 2750 } 2751 2752 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopSimdDirective( 2753 OMPParallelMasterTaskLoopSimdDirective *D) { 2754 VisitOMPLoopDirective(D); 2755 Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE; 2756 } 2757 2758 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopSimdDirective( 2759 OMPParallelMaskedTaskLoopSimdDirective *D) { 2760 VisitOMPLoopDirective(D); 2761 Code = serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_SIMD_DIRECTIVE; 2762 } 2763 2764 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) { 2765 VisitOMPLoopDirective(D); 2766 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE; 2767 } 2768 2769 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) { 2770 VisitStmt(D); 2771 VisitOMPExecutableDirective(D); 2772 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE; 2773 } 2774 2775 void ASTStmtWriter::VisitOMPDistributeParallelForDirective( 2776 OMPDistributeParallelForDirective *D) { 2777 VisitOMPLoopDirective(D); 2778 Record.writeBool(D->hasCancel()); 2779 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE; 2780 } 2781 2782 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective( 2783 OMPDistributeParallelForSimdDirective *D) { 2784 VisitOMPLoopDirective(D); 2785 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE; 2786 } 2787 2788 void ASTStmtWriter::VisitOMPDistributeSimdDirective( 2789 OMPDistributeSimdDirective *D) { 2790 VisitOMPLoopDirective(D); 2791 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE; 2792 } 2793 2794 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective( 2795 OMPTargetParallelForSimdDirective *D) { 2796 VisitOMPLoopDirective(D); 2797 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE; 2798 } 2799 2800 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) { 2801 VisitOMPLoopDirective(D); 2802 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE; 2803 } 2804 2805 void ASTStmtWriter::VisitOMPTeamsDistributeDirective( 2806 OMPTeamsDistributeDirective *D) { 2807 VisitOMPLoopDirective(D); 2808 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE; 2809 } 2810 2811 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective( 2812 OMPTeamsDistributeSimdDirective *D) { 2813 VisitOMPLoopDirective(D); 2814 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE; 2815 } 2816 2817 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective( 2818 OMPTeamsDistributeParallelForSimdDirective *D) { 2819 VisitOMPLoopDirective(D); 2820 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE; 2821 } 2822 2823 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective( 2824 OMPTeamsDistributeParallelForDirective *D) { 2825 VisitOMPLoopDirective(D); 2826 Record.writeBool(D->hasCancel()); 2827 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE; 2828 } 2829 2830 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) { 2831 VisitStmt(D); 2832 VisitOMPExecutableDirective(D); 2833 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE; 2834 } 2835 2836 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective( 2837 OMPTargetTeamsDistributeDirective *D) { 2838 VisitOMPLoopDirective(D); 2839 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE; 2840 } 2841 2842 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective( 2843 OMPTargetTeamsDistributeParallelForDirective *D) { 2844 VisitOMPLoopDirective(D); 2845 Record.writeBool(D->hasCancel()); 2846 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE; 2847 } 2848 2849 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective( 2850 OMPTargetTeamsDistributeParallelForSimdDirective *D) { 2851 VisitOMPLoopDirective(D); 2852 Code = serialization:: 2853 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE; 2854 } 2855 2856 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective( 2857 OMPTargetTeamsDistributeSimdDirective *D) { 2858 VisitOMPLoopDirective(D); 2859 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE; 2860 } 2861 2862 void ASTStmtWriter::VisitOMPInteropDirective(OMPInteropDirective *D) { 2863 VisitStmt(D); 2864 VisitOMPExecutableDirective(D); 2865 Code = serialization::STMT_OMP_INTEROP_DIRECTIVE; 2866 } 2867 2868 void ASTStmtWriter::VisitOMPDispatchDirective(OMPDispatchDirective *D) { 2869 VisitStmt(D); 2870 VisitOMPExecutableDirective(D); 2871 Record.AddSourceLocation(D->getTargetCallLoc()); 2872 Code = serialization::STMT_OMP_DISPATCH_DIRECTIVE; 2873 } 2874 2875 void ASTStmtWriter::VisitOMPMaskedDirective(OMPMaskedDirective *D) { 2876 VisitStmt(D); 2877 VisitOMPExecutableDirective(D); 2878 Code = serialization::STMT_OMP_MASKED_DIRECTIVE; 2879 } 2880 2881 void ASTStmtWriter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) { 2882 VisitOMPLoopDirective(D); 2883 Code = serialization::STMT_OMP_GENERIC_LOOP_DIRECTIVE; 2884 } 2885 2886 void ASTStmtWriter::VisitOMPTeamsGenericLoopDirective( 2887 OMPTeamsGenericLoopDirective *D) { 2888 VisitOMPLoopDirective(D); 2889 Code = serialization::STMT_OMP_TEAMS_GENERIC_LOOP_DIRECTIVE; 2890 } 2891 2892 void ASTStmtWriter::VisitOMPTargetTeamsGenericLoopDirective( 2893 OMPTargetTeamsGenericLoopDirective *D) { 2894 VisitOMPLoopDirective(D); 2895 Record.writeBool(D->canBeParallelFor()); 2896 Code = serialization::STMT_OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE; 2897 } 2898 2899 void ASTStmtWriter::VisitOMPParallelGenericLoopDirective( 2900 OMPParallelGenericLoopDirective *D) { 2901 VisitOMPLoopDirective(D); 2902 Code = serialization::STMT_OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE; 2903 } 2904 2905 void ASTStmtWriter::VisitOMPTargetParallelGenericLoopDirective( 2906 OMPTargetParallelGenericLoopDirective *D) { 2907 VisitOMPLoopDirective(D); 2908 Code = serialization::STMT_OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE; 2909 } 2910 2911 //===----------------------------------------------------------------------===// 2912 // OpenACC Constructs/Directives. 2913 //===----------------------------------------------------------------------===// 2914 void ASTStmtWriter::VisitOpenACCConstructStmt(OpenACCConstructStmt *S) { 2915 Record.push_back(S->clauses().size()); 2916 Record.writeEnum(S->Kind); 2917 Record.AddSourceRange(S->Range); 2918 Record.AddSourceLocation(S->DirectiveLoc); 2919 Record.writeOpenACCClauseList(S->clauses()); 2920 } 2921 2922 void ASTStmtWriter::VisitOpenACCAssociatedStmtConstruct( 2923 OpenACCAssociatedStmtConstruct *S) { 2924 VisitOpenACCConstructStmt(S); 2925 Record.AddStmt(S->getAssociatedStmt()); 2926 } 2927 2928 void ASTStmtWriter::VisitOpenACCComputeConstruct(OpenACCComputeConstruct *S) { 2929 VisitStmt(S); 2930 VisitOpenACCAssociatedStmtConstruct(S); 2931 Code = serialization::STMT_OPENACC_COMPUTE_CONSTRUCT; 2932 } 2933 2934 void ASTStmtWriter::VisitOpenACCLoopConstruct(OpenACCLoopConstruct *S) { 2935 VisitStmt(S); 2936 VisitOpenACCAssociatedStmtConstruct(S); 2937 Record.writeEnum(S->getParentComputeConstructKind()); 2938 Code = serialization::STMT_OPENACC_LOOP_CONSTRUCT; 2939 } 2940 2941 void ASTStmtWriter::VisitOpenACCCombinedConstruct(OpenACCCombinedConstruct *S) { 2942 VisitStmt(S); 2943 VisitOpenACCAssociatedStmtConstruct(S); 2944 Code = serialization::STMT_OPENACC_COMBINED_CONSTRUCT; 2945 } 2946 2947 void ASTStmtWriter::VisitOpenACCDataConstruct(OpenACCDataConstruct *S) { 2948 VisitStmt(S); 2949 VisitOpenACCAssociatedStmtConstruct(S); 2950 Code = serialization::STMT_OPENACC_DATA_CONSTRUCT; 2951 } 2952 2953 void ASTStmtWriter::VisitOpenACCEnterDataConstruct( 2954 OpenACCEnterDataConstruct *S) { 2955 VisitStmt(S); 2956 VisitOpenACCConstructStmt(S); 2957 Code = serialization::STMT_OPENACC_ENTER_DATA_CONSTRUCT; 2958 } 2959 2960 void ASTStmtWriter::VisitOpenACCExitDataConstruct(OpenACCExitDataConstruct *S) { 2961 VisitStmt(S); 2962 VisitOpenACCConstructStmt(S); 2963 Code = serialization::STMT_OPENACC_EXIT_DATA_CONSTRUCT; 2964 } 2965 2966 void ASTStmtWriter::VisitOpenACCInitConstruct(OpenACCInitConstruct *S) { 2967 VisitStmt(S); 2968 VisitOpenACCConstructStmt(S); 2969 Code = serialization::STMT_OPENACC_INIT_CONSTRUCT; 2970 } 2971 2972 void ASTStmtWriter::VisitOpenACCShutdownConstruct(OpenACCShutdownConstruct *S) { 2973 VisitStmt(S); 2974 VisitOpenACCConstructStmt(S); 2975 Code = serialization::STMT_OPENACC_SHUTDOWN_CONSTRUCT; 2976 } 2977 2978 void ASTStmtWriter::VisitOpenACCSetConstruct(OpenACCSetConstruct *S) { 2979 VisitStmt(S); 2980 VisitOpenACCConstructStmt(S); 2981 Code = serialization::STMT_OPENACC_SET_CONSTRUCT; 2982 } 2983 2984 void ASTStmtWriter::VisitOpenACCUpdateConstruct(OpenACCUpdateConstruct *S) { 2985 VisitStmt(S); 2986 VisitOpenACCConstructStmt(S); 2987 Code = serialization::STMT_OPENACC_UPDATE_CONSTRUCT; 2988 } 2989 2990 void ASTStmtWriter::VisitOpenACCHostDataConstruct(OpenACCHostDataConstruct *S) { 2991 VisitStmt(S); 2992 VisitOpenACCAssociatedStmtConstruct(S); 2993 Code = serialization::STMT_OPENACC_HOST_DATA_CONSTRUCT; 2994 } 2995 2996 void ASTStmtWriter::VisitOpenACCWaitConstruct(OpenACCWaitConstruct *S) { 2997 VisitStmt(S); 2998 Record.push_back(S->getExprs().size()); 2999 VisitOpenACCConstructStmt(S); 3000 Record.AddSourceLocation(S->LParenLoc); 3001 Record.AddSourceLocation(S->RParenLoc); 3002 Record.AddSourceLocation(S->QueuesLoc); 3003 3004 for(Expr *E : S->getExprs()) 3005 Record.AddStmt(E); 3006 3007 Code = serialization::STMT_OPENACC_WAIT_CONSTRUCT; 3008 } 3009 3010 //===----------------------------------------------------------------------===// 3011 // HLSL Constructs/Directives. 3012 //===----------------------------------------------------------------------===// 3013 3014 void ASTStmtWriter::VisitHLSLOutArgExpr(HLSLOutArgExpr *S) { 3015 VisitExpr(S); 3016 Record.AddStmt(S->getOpaqueArgLValue()); 3017 Record.AddStmt(S->getCastedTemporary()); 3018 Record.AddStmt(S->getWritebackCast()); 3019 Record.writeBool(S->isInOut()); 3020 Code = serialization::EXPR_HLSL_OUT_ARG; 3021 } 3022 3023 //===----------------------------------------------------------------------===// 3024 // ASTWriter Implementation 3025 //===----------------------------------------------------------------------===// 3026 3027 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) { 3028 assert(!SwitchCaseIDs.contains(S) && "SwitchCase recorded twice"); 3029 unsigned NextID = SwitchCaseIDs.size(); 3030 SwitchCaseIDs[S] = NextID; 3031 return NextID; 3032 } 3033 3034 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) { 3035 assert(SwitchCaseIDs.contains(S) && "SwitchCase hasn't been seen yet"); 3036 return SwitchCaseIDs[S]; 3037 } 3038 3039 void ASTWriter::ClearSwitchCaseIDs() { 3040 SwitchCaseIDs.clear(); 3041 } 3042 3043 /// Write the given substatement or subexpression to the 3044 /// bitstream. 3045 void ASTWriter::WriteSubStmt(ASTContext &Context, Stmt *S) { 3046 RecordData Record; 3047 ASTStmtWriter Writer(Context, *this, Record); 3048 ++NumStatements; 3049 3050 if (!S) { 3051 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record); 3052 return; 3053 } 3054 3055 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S); 3056 if (I != SubStmtEntries.end()) { 3057 Record.push_back(I->second); 3058 Stream.EmitRecord(serialization::STMT_REF_PTR, Record); 3059 return; 3060 } 3061 3062 #ifndef NDEBUG 3063 assert(!ParentStmts.count(S) && "There is a Stmt cycle!"); 3064 3065 struct ParentStmtInserterRAII { 3066 Stmt *S; 3067 llvm::DenseSet<Stmt *> &ParentStmts; 3068 3069 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts) 3070 : S(S), ParentStmts(ParentStmts) { 3071 ParentStmts.insert(S); 3072 } 3073 ~ParentStmtInserterRAII() { 3074 ParentStmts.erase(S); 3075 } 3076 }; 3077 3078 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts); 3079 #endif 3080 3081 Writer.Visit(S); 3082 3083 uint64_t Offset = Writer.Emit(); 3084 SubStmtEntries[S] = Offset; 3085 } 3086 3087 /// Flush all of the statements that have been added to the 3088 /// queue via AddStmt(). 3089 void ASTRecordWriter::FlushStmts() { 3090 // We expect to be the only consumer of the two temporary statement maps, 3091 // assert that they are empty. 3092 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map"); 3093 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map"); 3094 3095 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) { 3096 Writer->WriteSubStmt(getASTContext(), StmtsToEmit[I]); 3097 3098 assert(N == StmtsToEmit.size() && "record modified while being written!"); 3099 3100 // Note that we are at the end of a full expression. Any 3101 // expression records that follow this one are part of a different 3102 // expression. 3103 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>()); 3104 3105 Writer->SubStmtEntries.clear(); 3106 Writer->ParentStmts.clear(); 3107 } 3108 3109 StmtsToEmit.clear(); 3110 } 3111 3112 void ASTRecordWriter::FlushSubStmts() { 3113 // For a nested statement, write out the substatements in reverse order (so 3114 // that a simple stack machine can be used when loading), and don't emit a 3115 // STMT_STOP after each one. 3116 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) { 3117 Writer->WriteSubStmt(getASTContext(), StmtsToEmit[N - I - 1]); 3118 assert(N == StmtsToEmit.size() && "record modified while being written!"); 3119 } 3120 3121 StmtsToEmit.clear(); 3122 } 3123