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