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