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