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