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