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