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