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