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