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