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