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