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.push_back(E->cleanupsHaveSideEffects()); 1435 Record.AddStmt(E->getSubExpr()); 1436 Code = serialization::EXPR_EXPR_WITH_CLEANUPS; 1437 } 1438 1439 void 1440 ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){ 1441 VisitExpr(E); 1442 1443 // Don't emit anything here, HasTemplateKWAndArgsInfo must be 1444 // emitted first. 1445 1446 Record.push_back(E->HasTemplateKWAndArgsInfo); 1447 if (E->HasTemplateKWAndArgsInfo) { 1448 const ASTTemplateKWAndArgsInfo &ArgInfo = 1449 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); 1450 Record.push_back(ArgInfo.NumTemplateArgs); 1451 AddTemplateKWAndArgsInfo(ArgInfo, 1452 E->getTrailingObjects<TemplateArgumentLoc>()); 1453 } 1454 1455 if (!E->isImplicitAccess()) 1456 Record.AddStmt(E->getBase()); 1457 else 1458 Record.AddStmt(nullptr); 1459 Record.AddTypeRef(E->getBaseType()); 1460 Record.push_back(E->isArrow()); 1461 Record.AddSourceLocation(E->getOperatorLoc()); 1462 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 1463 Record.AddDeclRef(E->getFirstQualifierFoundInScope()); 1464 Record.AddDeclarationNameInfo(E->MemberNameInfo); 1465 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER; 1466 } 1467 1468 void 1469 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { 1470 VisitExpr(E); 1471 1472 // Don't emit anything here, HasTemplateKWAndArgsInfo must be 1473 // emitted first. 1474 1475 Record.push_back(E->HasTemplateKWAndArgsInfo); 1476 if (E->HasTemplateKWAndArgsInfo) { 1477 const ASTTemplateKWAndArgsInfo &ArgInfo = 1478 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); 1479 Record.push_back(ArgInfo.NumTemplateArgs); 1480 AddTemplateKWAndArgsInfo(ArgInfo, 1481 E->getTrailingObjects<TemplateArgumentLoc>()); 1482 } 1483 1484 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 1485 Record.AddDeclarationNameInfo(E->NameInfo); 1486 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF; 1487 } 1488 1489 void 1490 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) { 1491 VisitExpr(E); 1492 Record.push_back(E->arg_size()); 1493 for (CXXUnresolvedConstructExpr::arg_iterator 1494 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI) 1495 Record.AddStmt(*ArgI); 1496 Record.AddTypeSourceInfo(E->getTypeSourceInfo()); 1497 Record.AddSourceLocation(E->getLParenLoc()); 1498 Record.AddSourceLocation(E->getRParenLoc()); 1499 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT; 1500 } 1501 1502 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) { 1503 VisitExpr(E); 1504 1505 // Don't emit anything here, HasTemplateKWAndArgsInfo must be 1506 // emitted first. 1507 1508 Record.push_back(E->HasTemplateKWAndArgsInfo); 1509 if (E->HasTemplateKWAndArgsInfo) { 1510 const ASTTemplateKWAndArgsInfo &ArgInfo = 1511 *E->getTrailingASTTemplateKWAndArgsInfo(); 1512 Record.push_back(ArgInfo.NumTemplateArgs); 1513 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc()); 1514 } 1515 1516 Record.push_back(E->getNumDecls()); 1517 for (OverloadExpr::decls_iterator 1518 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) { 1519 Record.AddDeclRef(OvI.getDecl()); 1520 Record.push_back(OvI.getAccess()); 1521 } 1522 1523 Record.AddDeclarationNameInfo(E->NameInfo); 1524 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 1525 } 1526 1527 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { 1528 VisitOverloadExpr(E); 1529 Record.push_back(E->isArrow()); 1530 Record.push_back(E->hasUnresolvedUsing()); 1531 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr); 1532 Record.AddTypeRef(E->getBaseType()); 1533 Record.AddSourceLocation(E->getOperatorLoc()); 1534 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER; 1535 } 1536 1537 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { 1538 VisitOverloadExpr(E); 1539 Record.push_back(E->requiresADL()); 1540 Record.push_back(E->isOverloaded()); 1541 Record.AddDeclRef(E->getNamingClass()); 1542 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP; 1543 } 1544 1545 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) { 1546 VisitExpr(E); 1547 Record.push_back(E->TypeTraitExprBits.NumArgs); 1548 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding 1549 Record.push_back(E->TypeTraitExprBits.Value); 1550 Record.AddSourceRange(E->getSourceRange()); 1551 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 1552 Record.AddTypeSourceInfo(E->getArg(I)); 1553 Code = serialization::EXPR_TYPE_TRAIT; 1554 } 1555 1556 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 1557 VisitExpr(E); 1558 Record.push_back(E->getTrait()); 1559 Record.push_back(E->getValue()); 1560 Record.AddSourceRange(E->getSourceRange()); 1561 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo()); 1562 Code = serialization::EXPR_ARRAY_TYPE_TRAIT; 1563 } 1564 1565 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { 1566 VisitExpr(E); 1567 Record.push_back(E->getTrait()); 1568 Record.push_back(E->getValue()); 1569 Record.AddSourceRange(E->getSourceRange()); 1570 Record.AddStmt(E->getQueriedExpression()); 1571 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT; 1572 } 1573 1574 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { 1575 VisitExpr(E); 1576 Record.push_back(E->getValue()); 1577 Record.AddSourceRange(E->getSourceRange()); 1578 Record.AddStmt(E->getOperand()); 1579 Code = serialization::EXPR_CXX_NOEXCEPT; 1580 } 1581 1582 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) { 1583 VisitExpr(E); 1584 Record.AddSourceLocation(E->getEllipsisLoc()); 1585 Record.push_back(E->NumExpansions); 1586 Record.AddStmt(E->getPattern()); 1587 Code = serialization::EXPR_PACK_EXPANSION; 1588 } 1589 1590 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { 1591 VisitExpr(E); 1592 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size() 1593 : 0); 1594 Record.AddSourceLocation(E->OperatorLoc); 1595 Record.AddSourceLocation(E->PackLoc); 1596 Record.AddSourceLocation(E->RParenLoc); 1597 Record.AddDeclRef(E->Pack); 1598 if (E->isPartiallySubstituted()) { 1599 for (const auto &TA : E->getPartialArguments()) 1600 Record.AddTemplateArgument(TA); 1601 } else if (!E->isValueDependent()) { 1602 Record.push_back(E->getPackLength()); 1603 } 1604 Code = serialization::EXPR_SIZEOF_PACK; 1605 } 1606 1607 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr( 1608 SubstNonTypeTemplateParmExpr *E) { 1609 VisitExpr(E); 1610 Record.AddDeclRef(E->getParameter()); 1611 Record.AddSourceLocation(E->getNameLoc()); 1612 Record.AddStmt(E->getReplacement()); 1613 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM; 1614 } 1615 1616 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr( 1617 SubstNonTypeTemplateParmPackExpr *E) { 1618 VisitExpr(E); 1619 Record.AddDeclRef(E->getParameterPack()); 1620 Record.AddTemplateArgument(E->getArgumentPack()); 1621 Record.AddSourceLocation(E->getParameterPackLocation()); 1622 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK; 1623 } 1624 1625 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) { 1626 VisitExpr(E); 1627 Record.push_back(E->getNumExpansions()); 1628 Record.AddDeclRef(E->getParameterPack()); 1629 Record.AddSourceLocation(E->getParameterPackLocation()); 1630 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end(); 1631 I != End; ++I) 1632 Record.AddDeclRef(*I); 1633 Code = serialization::EXPR_FUNCTION_PARM_PACK; 1634 } 1635 1636 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { 1637 VisitExpr(E); 1638 Record.AddStmt(E->getTemporary()); 1639 Record.AddDeclRef(E->getExtendingDecl()); 1640 Record.push_back(E->getManglingNumber()); 1641 Code = serialization::EXPR_MATERIALIZE_TEMPORARY; 1642 } 1643 1644 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) { 1645 VisitExpr(E); 1646 Record.AddSourceLocation(E->LParenLoc); 1647 Record.AddSourceLocation(E->EllipsisLoc); 1648 Record.AddSourceLocation(E->RParenLoc); 1649 Record.AddStmt(E->SubExprs[0]); 1650 Record.AddStmt(E->SubExprs[1]); 1651 Record.push_back(E->Opcode); 1652 Code = serialization::EXPR_CXX_FOLD; 1653 } 1654 1655 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { 1656 VisitExpr(E); 1657 Record.AddStmt(E->getSourceExpr()); 1658 Record.AddSourceLocation(E->getLocation()); 1659 Code = serialization::EXPR_OPAQUE_VALUE; 1660 } 1661 1662 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) { 1663 VisitExpr(E); 1664 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary 1665 llvm_unreachable("Cannot write TypoExpr nodes"); 1666 } 1667 1668 //===----------------------------------------------------------------------===// 1669 // CUDA Expressions and Statements. 1670 //===----------------------------------------------------------------------===// 1671 1672 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 1673 VisitCallExpr(E); 1674 Record.AddStmt(E->getConfig()); 1675 Code = serialization::EXPR_CUDA_KERNEL_CALL; 1676 } 1677 1678 //===----------------------------------------------------------------------===// 1679 // OpenCL Expressions and Statements. 1680 //===----------------------------------------------------------------------===// 1681 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) { 1682 VisitExpr(E); 1683 Record.AddSourceLocation(E->getBuiltinLoc()); 1684 Record.AddSourceLocation(E->getRParenLoc()); 1685 Record.AddStmt(E->getSrcExpr()); 1686 Code = serialization::EXPR_ASTYPE; 1687 } 1688 1689 //===----------------------------------------------------------------------===// 1690 // Microsoft Expressions and Statements. 1691 //===----------------------------------------------------------------------===// 1692 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) { 1693 VisitExpr(E); 1694 Record.push_back(E->isArrow()); 1695 Record.AddStmt(E->getBaseExpr()); 1696 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc()); 1697 Record.AddSourceLocation(E->getMemberLoc()); 1698 Record.AddDeclRef(E->getPropertyDecl()); 1699 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR; 1700 } 1701 1702 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) { 1703 VisitExpr(E); 1704 Record.AddStmt(E->getBase()); 1705 Record.AddStmt(E->getIdx()); 1706 Record.AddSourceLocation(E->getRBracketLoc()); 1707 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR; 1708 } 1709 1710 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) { 1711 VisitExpr(E); 1712 Record.AddSourceRange(E->getSourceRange()); 1713 Record.AddString(E->getUuidStr()); 1714 if (E->isTypeOperand()) { 1715 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo()); 1716 Code = serialization::EXPR_CXX_UUIDOF_TYPE; 1717 } else { 1718 Record.AddStmt(E->getExprOperand()); 1719 Code = serialization::EXPR_CXX_UUIDOF_EXPR; 1720 } 1721 } 1722 1723 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) { 1724 VisitStmt(S); 1725 Record.AddSourceLocation(S->getExceptLoc()); 1726 Record.AddStmt(S->getFilterExpr()); 1727 Record.AddStmt(S->getBlock()); 1728 Code = serialization::STMT_SEH_EXCEPT; 1729 } 1730 1731 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) { 1732 VisitStmt(S); 1733 Record.AddSourceLocation(S->getFinallyLoc()); 1734 Record.AddStmt(S->getBlock()); 1735 Code = serialization::STMT_SEH_FINALLY; 1736 } 1737 1738 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) { 1739 VisitStmt(S); 1740 Record.push_back(S->getIsCXXTry()); 1741 Record.AddSourceLocation(S->getTryLoc()); 1742 Record.AddStmt(S->getTryBlock()); 1743 Record.AddStmt(S->getHandler()); 1744 Code = serialization::STMT_SEH_TRY; 1745 } 1746 1747 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) { 1748 VisitStmt(S); 1749 Record.AddSourceLocation(S->getLeaveLoc()); 1750 Code = serialization::STMT_SEH_LEAVE; 1751 } 1752 1753 //===----------------------------------------------------------------------===// 1754 // OpenMP Clauses. 1755 //===----------------------------------------------------------------------===// 1756 1757 namespace clang { 1758 class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> { 1759 ASTRecordWriter &Record; 1760 public: 1761 OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {} 1762 #define OPENMP_CLAUSE(Name, Class) \ 1763 void Visit##Class(Class *S); 1764 #include "clang/Basic/OpenMPKinds.def" 1765 void writeClause(OMPClause *C); 1766 void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); 1767 void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); 1768 }; 1769 } 1770 1771 void OMPClauseWriter::writeClause(OMPClause *C) { 1772 Record.push_back(C->getClauseKind()); 1773 Visit(C); 1774 Record.AddSourceLocation(C->getLocStart()); 1775 Record.AddSourceLocation(C->getLocEnd()); 1776 } 1777 1778 void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) { 1779 Record.AddStmt(C->getPreInitStmt()); 1780 } 1781 1782 void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) { 1783 VisitOMPClauseWithPreInit(C); 1784 Record.AddStmt(C->getPostUpdateExpr()); 1785 } 1786 1787 void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) { 1788 Record.push_back(C->getNameModifier()); 1789 Record.AddSourceLocation(C->getNameModifierLoc()); 1790 Record.AddSourceLocation(C->getColonLoc()); 1791 Record.AddStmt(C->getCondition()); 1792 Record.AddSourceLocation(C->getLParenLoc()); 1793 } 1794 1795 void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) { 1796 Record.AddStmt(C->getCondition()); 1797 Record.AddSourceLocation(C->getLParenLoc()); 1798 } 1799 1800 void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { 1801 Record.AddStmt(C->getNumThreads()); 1802 Record.AddSourceLocation(C->getLParenLoc()); 1803 } 1804 1805 void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) { 1806 Record.AddStmt(C->getSafelen()); 1807 Record.AddSourceLocation(C->getLParenLoc()); 1808 } 1809 1810 void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) { 1811 Record.AddStmt(C->getSimdlen()); 1812 Record.AddSourceLocation(C->getLParenLoc()); 1813 } 1814 1815 void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) { 1816 Record.AddStmt(C->getNumForLoops()); 1817 Record.AddSourceLocation(C->getLParenLoc()); 1818 } 1819 1820 void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) { 1821 Record.push_back(C->getDefaultKind()); 1822 Record.AddSourceLocation(C->getLParenLoc()); 1823 Record.AddSourceLocation(C->getDefaultKindKwLoc()); 1824 } 1825 1826 void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) { 1827 Record.push_back(C->getProcBindKind()); 1828 Record.AddSourceLocation(C->getLParenLoc()); 1829 Record.AddSourceLocation(C->getProcBindKindKwLoc()); 1830 } 1831 1832 void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) { 1833 VisitOMPClauseWithPreInit(C); 1834 Record.push_back(C->getScheduleKind()); 1835 Record.push_back(C->getFirstScheduleModifier()); 1836 Record.push_back(C->getSecondScheduleModifier()); 1837 Record.AddStmt(C->getChunkSize()); 1838 Record.AddSourceLocation(C->getLParenLoc()); 1839 Record.AddSourceLocation(C->getFirstScheduleModifierLoc()); 1840 Record.AddSourceLocation(C->getSecondScheduleModifierLoc()); 1841 Record.AddSourceLocation(C->getScheduleKindLoc()); 1842 Record.AddSourceLocation(C->getCommaLoc()); 1843 } 1844 1845 void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) { 1846 Record.AddStmt(C->getNumForLoops()); 1847 Record.AddSourceLocation(C->getLParenLoc()); 1848 } 1849 1850 void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {} 1851 1852 void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {} 1853 1854 void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {} 1855 1856 void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {} 1857 1858 void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {} 1859 1860 void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {} 1861 1862 void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {} 1863 1864 void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {} 1865 1866 void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {} 1867 1868 void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {} 1869 1870 void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {} 1871 1872 void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) { 1873 Record.push_back(C->varlist_size()); 1874 Record.AddSourceLocation(C->getLParenLoc()); 1875 for (auto *VE : C->varlists()) { 1876 Record.AddStmt(VE); 1877 } 1878 for (auto *VE : C->private_copies()) { 1879 Record.AddStmt(VE); 1880 } 1881 } 1882 1883 void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) { 1884 Record.push_back(C->varlist_size()); 1885 VisitOMPClauseWithPreInit(C); 1886 Record.AddSourceLocation(C->getLParenLoc()); 1887 for (auto *VE : C->varlists()) { 1888 Record.AddStmt(VE); 1889 } 1890 for (auto *VE : C->private_copies()) { 1891 Record.AddStmt(VE); 1892 } 1893 for (auto *VE : C->inits()) { 1894 Record.AddStmt(VE); 1895 } 1896 } 1897 1898 void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) { 1899 Record.push_back(C->varlist_size()); 1900 VisitOMPClauseWithPostUpdate(C); 1901 Record.AddSourceLocation(C->getLParenLoc()); 1902 for (auto *VE : C->varlists()) 1903 Record.AddStmt(VE); 1904 for (auto *E : C->private_copies()) 1905 Record.AddStmt(E); 1906 for (auto *E : C->source_exprs()) 1907 Record.AddStmt(E); 1908 for (auto *E : C->destination_exprs()) 1909 Record.AddStmt(E); 1910 for (auto *E : C->assignment_ops()) 1911 Record.AddStmt(E); 1912 } 1913 1914 void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) { 1915 Record.push_back(C->varlist_size()); 1916 Record.AddSourceLocation(C->getLParenLoc()); 1917 for (auto *VE : C->varlists()) 1918 Record.AddStmt(VE); 1919 } 1920 1921 void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) { 1922 Record.push_back(C->varlist_size()); 1923 VisitOMPClauseWithPostUpdate(C); 1924 Record.AddSourceLocation(C->getLParenLoc()); 1925 Record.AddSourceLocation(C->getColonLoc()); 1926 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); 1927 Record.AddDeclarationNameInfo(C->getNameInfo()); 1928 for (auto *VE : C->varlists()) 1929 Record.AddStmt(VE); 1930 for (auto *VE : C->privates()) 1931 Record.AddStmt(VE); 1932 for (auto *E : C->lhs_exprs()) 1933 Record.AddStmt(E); 1934 for (auto *E : C->rhs_exprs()) 1935 Record.AddStmt(E); 1936 for (auto *E : C->reduction_ops()) 1937 Record.AddStmt(E); 1938 } 1939 1940 void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) { 1941 Record.push_back(C->varlist_size()); 1942 VisitOMPClauseWithPostUpdate(C); 1943 Record.AddSourceLocation(C->getLParenLoc()); 1944 Record.AddSourceLocation(C->getColonLoc()); 1945 Record.push_back(C->getModifier()); 1946 Record.AddSourceLocation(C->getModifierLoc()); 1947 for (auto *VE : C->varlists()) { 1948 Record.AddStmt(VE); 1949 } 1950 for (auto *VE : C->privates()) { 1951 Record.AddStmt(VE); 1952 } 1953 for (auto *VE : C->inits()) { 1954 Record.AddStmt(VE); 1955 } 1956 for (auto *VE : C->updates()) { 1957 Record.AddStmt(VE); 1958 } 1959 for (auto *VE : C->finals()) { 1960 Record.AddStmt(VE); 1961 } 1962 Record.AddStmt(C->getStep()); 1963 Record.AddStmt(C->getCalcStep()); 1964 } 1965 1966 void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) { 1967 Record.push_back(C->varlist_size()); 1968 Record.AddSourceLocation(C->getLParenLoc()); 1969 Record.AddSourceLocation(C->getColonLoc()); 1970 for (auto *VE : C->varlists()) 1971 Record.AddStmt(VE); 1972 Record.AddStmt(C->getAlignment()); 1973 } 1974 1975 void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) { 1976 Record.push_back(C->varlist_size()); 1977 Record.AddSourceLocation(C->getLParenLoc()); 1978 for (auto *VE : C->varlists()) 1979 Record.AddStmt(VE); 1980 for (auto *E : C->source_exprs()) 1981 Record.AddStmt(E); 1982 for (auto *E : C->destination_exprs()) 1983 Record.AddStmt(E); 1984 for (auto *E : C->assignment_ops()) 1985 Record.AddStmt(E); 1986 } 1987 1988 void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) { 1989 Record.push_back(C->varlist_size()); 1990 Record.AddSourceLocation(C->getLParenLoc()); 1991 for (auto *VE : C->varlists()) 1992 Record.AddStmt(VE); 1993 for (auto *E : C->source_exprs()) 1994 Record.AddStmt(E); 1995 for (auto *E : C->destination_exprs()) 1996 Record.AddStmt(E); 1997 for (auto *E : C->assignment_ops()) 1998 Record.AddStmt(E); 1999 } 2000 2001 void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) { 2002 Record.push_back(C->varlist_size()); 2003 Record.AddSourceLocation(C->getLParenLoc()); 2004 for (auto *VE : C->varlists()) 2005 Record.AddStmt(VE); 2006 } 2007 2008 void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) { 2009 Record.push_back(C->varlist_size()); 2010 Record.AddSourceLocation(C->getLParenLoc()); 2011 Record.push_back(C->getDependencyKind()); 2012 Record.AddSourceLocation(C->getDependencyLoc()); 2013 Record.AddSourceLocation(C->getColonLoc()); 2014 for (auto *VE : C->varlists()) 2015 Record.AddStmt(VE); 2016 Record.AddStmt(C->getCounterValue()); 2017 } 2018 2019 void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) { 2020 Record.AddStmt(C->getDevice()); 2021 Record.AddSourceLocation(C->getLParenLoc()); 2022 } 2023 2024 void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) { 2025 Record.push_back(C->varlist_size()); 2026 Record.push_back(C->getUniqueDeclarationsNum()); 2027 Record.push_back(C->getTotalComponentListNum()); 2028 Record.push_back(C->getTotalComponentsNum()); 2029 Record.AddSourceLocation(C->getLParenLoc()); 2030 Record.push_back(C->getMapTypeModifier()); 2031 Record.push_back(C->getMapType()); 2032 Record.AddSourceLocation(C->getMapLoc()); 2033 Record.AddSourceLocation(C->getColonLoc()); 2034 for (auto *E : C->varlists()) 2035 Record.AddStmt(E); 2036 for (auto *D : C->all_decls()) 2037 Record.AddDeclRef(D); 2038 for (auto N : C->all_num_lists()) 2039 Record.push_back(N); 2040 for (auto N : C->all_lists_sizes()) 2041 Record.push_back(N); 2042 for (auto &M : C->all_components()) { 2043 Record.AddStmt(M.getAssociatedExpression()); 2044 Record.AddDeclRef(M.getAssociatedDeclaration()); 2045 } 2046 } 2047 2048 void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { 2049 Record.AddStmt(C->getNumTeams()); 2050 Record.AddSourceLocation(C->getLParenLoc()); 2051 } 2052 2053 void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) { 2054 Record.AddStmt(C->getThreadLimit()); 2055 Record.AddSourceLocation(C->getLParenLoc()); 2056 } 2057 2058 void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) { 2059 Record.AddStmt(C->getPriority()); 2060 Record.AddSourceLocation(C->getLParenLoc()); 2061 } 2062 2063 void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) { 2064 Record.AddStmt(C->getGrainsize()); 2065 Record.AddSourceLocation(C->getLParenLoc()); 2066 } 2067 2068 void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) { 2069 Record.AddStmt(C->getNumTasks()); 2070 Record.AddSourceLocation(C->getLParenLoc()); 2071 } 2072 2073 void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) { 2074 Record.AddStmt(C->getHint()); 2075 Record.AddSourceLocation(C->getLParenLoc()); 2076 } 2077 2078 void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) { 2079 VisitOMPClauseWithPreInit(C); 2080 Record.push_back(C->getDistScheduleKind()); 2081 Record.AddStmt(C->getChunkSize()); 2082 Record.AddSourceLocation(C->getLParenLoc()); 2083 Record.AddSourceLocation(C->getDistScheduleKindLoc()); 2084 Record.AddSourceLocation(C->getCommaLoc()); 2085 } 2086 2087 void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) { 2088 Record.push_back(C->getDefaultmapKind()); 2089 Record.push_back(C->getDefaultmapModifier()); 2090 Record.AddSourceLocation(C->getLParenLoc()); 2091 Record.AddSourceLocation(C->getDefaultmapModifierLoc()); 2092 Record.AddSourceLocation(C->getDefaultmapKindLoc()); 2093 } 2094 2095 void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) { 2096 Record.push_back(C->varlist_size()); 2097 Record.push_back(C->getUniqueDeclarationsNum()); 2098 Record.push_back(C->getTotalComponentListNum()); 2099 Record.push_back(C->getTotalComponentsNum()); 2100 Record.AddSourceLocation(C->getLParenLoc()); 2101 for (auto *E : C->varlists()) 2102 Record.AddStmt(E); 2103 for (auto *D : C->all_decls()) 2104 Record.AddDeclRef(D); 2105 for (auto N : C->all_num_lists()) 2106 Record.push_back(N); 2107 for (auto N : C->all_lists_sizes()) 2108 Record.push_back(N); 2109 for (auto &M : C->all_components()) { 2110 Record.AddStmt(M.getAssociatedExpression()); 2111 Record.AddDeclRef(M.getAssociatedDeclaration()); 2112 } 2113 } 2114 2115 void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) { 2116 Record.push_back(C->varlist_size()); 2117 Record.push_back(C->getUniqueDeclarationsNum()); 2118 Record.push_back(C->getTotalComponentListNum()); 2119 Record.push_back(C->getTotalComponentsNum()); 2120 Record.AddSourceLocation(C->getLParenLoc()); 2121 for (auto *E : C->varlists()) 2122 Record.AddStmt(E); 2123 for (auto *D : C->all_decls()) 2124 Record.AddDeclRef(D); 2125 for (auto N : C->all_num_lists()) 2126 Record.push_back(N); 2127 for (auto N : C->all_lists_sizes()) 2128 Record.push_back(N); 2129 for (auto &M : C->all_components()) { 2130 Record.AddStmt(M.getAssociatedExpression()); 2131 Record.AddDeclRef(M.getAssociatedDeclaration()); 2132 } 2133 } 2134 2135 //===----------------------------------------------------------------------===// 2136 // OpenMP Directives. 2137 //===----------------------------------------------------------------------===// 2138 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) { 2139 Record.AddSourceLocation(E->getLocStart()); 2140 Record.AddSourceLocation(E->getLocEnd()); 2141 OMPClauseWriter ClauseWriter(Record); 2142 for (unsigned i = 0; i < E->getNumClauses(); ++i) { 2143 ClauseWriter.writeClause(E->getClause(i)); 2144 } 2145 if (E->hasAssociatedStmt()) 2146 Record.AddStmt(E->getAssociatedStmt()); 2147 } 2148 2149 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) { 2150 VisitStmt(D); 2151 Record.push_back(D->getNumClauses()); 2152 Record.push_back(D->getCollapsedNumber()); 2153 VisitOMPExecutableDirective(D); 2154 Record.AddStmt(D->getIterationVariable()); 2155 Record.AddStmt(D->getLastIteration()); 2156 Record.AddStmt(D->getCalcLastIteration()); 2157 Record.AddStmt(D->getPreCond()); 2158 Record.AddStmt(D->getCond()); 2159 Record.AddStmt(D->getInit()); 2160 Record.AddStmt(D->getInc()); 2161 Record.AddStmt(D->getPreInits()); 2162 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) || 2163 isOpenMPTaskLoopDirective(D->getDirectiveKind()) || 2164 isOpenMPDistributeDirective(D->getDirectiveKind())) { 2165 Record.AddStmt(D->getIsLastIterVariable()); 2166 Record.AddStmt(D->getLowerBoundVariable()); 2167 Record.AddStmt(D->getUpperBoundVariable()); 2168 Record.AddStmt(D->getStrideVariable()); 2169 Record.AddStmt(D->getEnsureUpperBound()); 2170 Record.AddStmt(D->getNextLowerBound()); 2171 Record.AddStmt(D->getNextUpperBound()); 2172 Record.AddStmt(D->getNumIterations()); 2173 } 2174 for (auto I : D->counters()) { 2175 Record.AddStmt(I); 2176 } 2177 for (auto I : D->private_counters()) { 2178 Record.AddStmt(I); 2179 } 2180 for (auto I : D->inits()) { 2181 Record.AddStmt(I); 2182 } 2183 for (auto I : D->updates()) { 2184 Record.AddStmt(I); 2185 } 2186 for (auto I : D->finals()) { 2187 Record.AddStmt(I); 2188 } 2189 } 2190 2191 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) { 2192 VisitStmt(D); 2193 Record.push_back(D->getNumClauses()); 2194 VisitOMPExecutableDirective(D); 2195 Record.push_back(D->hasCancel() ? 1 : 0); 2196 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE; 2197 } 2198 2199 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) { 2200 VisitOMPLoopDirective(D); 2201 Code = serialization::STMT_OMP_SIMD_DIRECTIVE; 2202 } 2203 2204 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) { 2205 VisitOMPLoopDirective(D); 2206 Record.push_back(D->hasCancel() ? 1 : 0); 2207 Code = serialization::STMT_OMP_FOR_DIRECTIVE; 2208 } 2209 2210 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) { 2211 VisitOMPLoopDirective(D); 2212 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE; 2213 } 2214 2215 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) { 2216 VisitStmt(D); 2217 Record.push_back(D->getNumClauses()); 2218 VisitOMPExecutableDirective(D); 2219 Record.push_back(D->hasCancel() ? 1 : 0); 2220 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE; 2221 } 2222 2223 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) { 2224 VisitStmt(D); 2225 VisitOMPExecutableDirective(D); 2226 Record.push_back(D->hasCancel() ? 1 : 0); 2227 Code = serialization::STMT_OMP_SECTION_DIRECTIVE; 2228 } 2229 2230 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) { 2231 VisitStmt(D); 2232 Record.push_back(D->getNumClauses()); 2233 VisitOMPExecutableDirective(D); 2234 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE; 2235 } 2236 2237 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) { 2238 VisitStmt(D); 2239 VisitOMPExecutableDirective(D); 2240 Code = serialization::STMT_OMP_MASTER_DIRECTIVE; 2241 } 2242 2243 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) { 2244 VisitStmt(D); 2245 Record.push_back(D->getNumClauses()); 2246 VisitOMPExecutableDirective(D); 2247 Record.AddDeclarationNameInfo(D->getDirectiveName()); 2248 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE; 2249 } 2250 2251 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) { 2252 VisitOMPLoopDirective(D); 2253 Record.push_back(D->hasCancel() ? 1 : 0); 2254 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE; 2255 } 2256 2257 void ASTStmtWriter::VisitOMPParallelForSimdDirective( 2258 OMPParallelForSimdDirective *D) { 2259 VisitOMPLoopDirective(D); 2260 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE; 2261 } 2262 2263 void ASTStmtWriter::VisitOMPParallelSectionsDirective( 2264 OMPParallelSectionsDirective *D) { 2265 VisitStmt(D); 2266 Record.push_back(D->getNumClauses()); 2267 VisitOMPExecutableDirective(D); 2268 Record.push_back(D->hasCancel() ? 1 : 0); 2269 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE; 2270 } 2271 2272 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) { 2273 VisitStmt(D); 2274 Record.push_back(D->getNumClauses()); 2275 VisitOMPExecutableDirective(D); 2276 Record.push_back(D->hasCancel() ? 1 : 0); 2277 Code = serialization::STMT_OMP_TASK_DIRECTIVE; 2278 } 2279 2280 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) { 2281 VisitStmt(D); 2282 Record.push_back(D->getNumClauses()); 2283 VisitOMPExecutableDirective(D); 2284 Record.AddStmt(D->getX()); 2285 Record.AddStmt(D->getV()); 2286 Record.AddStmt(D->getExpr()); 2287 Record.AddStmt(D->getUpdateExpr()); 2288 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0); 2289 Record.push_back(D->isPostfixUpdate() ? 1 : 0); 2290 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE; 2291 } 2292 2293 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) { 2294 VisitStmt(D); 2295 Record.push_back(D->getNumClauses()); 2296 VisitOMPExecutableDirective(D); 2297 Code = serialization::STMT_OMP_TARGET_DIRECTIVE; 2298 } 2299 2300 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) { 2301 VisitStmt(D); 2302 Record.push_back(D->getNumClauses()); 2303 VisitOMPExecutableDirective(D); 2304 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE; 2305 } 2306 2307 void ASTStmtWriter::VisitOMPTargetEnterDataDirective( 2308 OMPTargetEnterDataDirective *D) { 2309 VisitStmt(D); 2310 Record.push_back(D->getNumClauses()); 2311 VisitOMPExecutableDirective(D); 2312 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE; 2313 } 2314 2315 void ASTStmtWriter::VisitOMPTargetExitDataDirective( 2316 OMPTargetExitDataDirective *D) { 2317 VisitStmt(D); 2318 Record.push_back(D->getNumClauses()); 2319 VisitOMPExecutableDirective(D); 2320 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE; 2321 } 2322 2323 void ASTStmtWriter::VisitOMPTargetParallelDirective( 2324 OMPTargetParallelDirective *D) { 2325 VisitStmt(D); 2326 Record.push_back(D->getNumClauses()); 2327 VisitOMPExecutableDirective(D); 2328 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE; 2329 } 2330 2331 void ASTStmtWriter::VisitOMPTargetParallelForDirective( 2332 OMPTargetParallelForDirective *D) { 2333 VisitOMPLoopDirective(D); 2334 Record.push_back(D->hasCancel() ? 1 : 0); 2335 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE; 2336 } 2337 2338 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) { 2339 VisitStmt(D); 2340 VisitOMPExecutableDirective(D); 2341 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE; 2342 } 2343 2344 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) { 2345 VisitStmt(D); 2346 VisitOMPExecutableDirective(D); 2347 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE; 2348 } 2349 2350 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) { 2351 VisitStmt(D); 2352 VisitOMPExecutableDirective(D); 2353 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE; 2354 } 2355 2356 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) { 2357 VisitStmt(D); 2358 VisitOMPExecutableDirective(D); 2359 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE; 2360 } 2361 2362 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) { 2363 VisitStmt(D); 2364 Record.push_back(D->getNumClauses()); 2365 VisitOMPExecutableDirective(D); 2366 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE; 2367 } 2368 2369 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) { 2370 VisitStmt(D); 2371 Record.push_back(D->getNumClauses()); 2372 VisitOMPExecutableDirective(D); 2373 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE; 2374 } 2375 2376 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) { 2377 VisitStmt(D); 2378 Record.push_back(D->getNumClauses()); 2379 VisitOMPExecutableDirective(D); 2380 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE; 2381 } 2382 2383 void ASTStmtWriter::VisitOMPCancellationPointDirective( 2384 OMPCancellationPointDirective *D) { 2385 VisitStmt(D); 2386 VisitOMPExecutableDirective(D); 2387 Record.push_back(D->getCancelRegion()); 2388 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE; 2389 } 2390 2391 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) { 2392 VisitStmt(D); 2393 Record.push_back(D->getNumClauses()); 2394 VisitOMPExecutableDirective(D); 2395 Record.push_back(D->getCancelRegion()); 2396 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE; 2397 } 2398 2399 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) { 2400 VisitOMPLoopDirective(D); 2401 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE; 2402 } 2403 2404 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) { 2405 VisitOMPLoopDirective(D); 2406 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE; 2407 } 2408 2409 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) { 2410 VisitOMPLoopDirective(D); 2411 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE; 2412 } 2413 2414 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) { 2415 VisitStmt(D); 2416 Record.push_back(D->getNumClauses()); 2417 VisitOMPExecutableDirective(D); 2418 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE; 2419 } 2420 2421 //===----------------------------------------------------------------------===// 2422 // ASTWriter Implementation 2423 //===----------------------------------------------------------------------===// 2424 2425 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) { 2426 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() && 2427 "SwitchCase recorded twice"); 2428 unsigned NextID = SwitchCaseIDs.size(); 2429 SwitchCaseIDs[S] = NextID; 2430 return NextID; 2431 } 2432 2433 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) { 2434 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() && 2435 "SwitchCase hasn't been seen yet"); 2436 return SwitchCaseIDs[S]; 2437 } 2438 2439 void ASTWriter::ClearSwitchCaseIDs() { 2440 SwitchCaseIDs.clear(); 2441 } 2442 2443 /// \brief Write the given substatement or subexpression to the 2444 /// bitstream. 2445 void ASTWriter::WriteSubStmt(Stmt *S) { 2446 RecordData Record; 2447 ASTStmtWriter Writer(*this, Record); 2448 ++NumStatements; 2449 2450 if (!S) { 2451 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record); 2452 return; 2453 } 2454 2455 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S); 2456 if (I != SubStmtEntries.end()) { 2457 Record.push_back(I->second); 2458 Stream.EmitRecord(serialization::STMT_REF_PTR, Record); 2459 return; 2460 } 2461 2462 #ifndef NDEBUG 2463 assert(!ParentStmts.count(S) && "There is a Stmt cycle!"); 2464 2465 struct ParentStmtInserterRAII { 2466 Stmt *S; 2467 llvm::DenseSet<Stmt *> &ParentStmts; 2468 2469 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts) 2470 : S(S), ParentStmts(ParentStmts) { 2471 ParentStmts.insert(S); 2472 } 2473 ~ParentStmtInserterRAII() { 2474 ParentStmts.erase(S); 2475 } 2476 }; 2477 2478 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts); 2479 #endif 2480 2481 Writer.Visit(S); 2482 2483 uint64_t Offset = Writer.Emit(); 2484 SubStmtEntries[S] = Offset; 2485 } 2486 2487 /// \brief Flush all of the statements that have been added to the 2488 /// queue via AddStmt(). 2489 void ASTRecordWriter::FlushStmts() { 2490 // We expect to be the only consumer of the two temporary statement maps, 2491 // assert that they are empty. 2492 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map"); 2493 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map"); 2494 2495 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) { 2496 Writer->WriteSubStmt(StmtsToEmit[I]); 2497 2498 assert(N == StmtsToEmit.size() && "record modified while being written!"); 2499 2500 // Note that we are at the end of a full expression. Any 2501 // expression records that follow this one are part of a different 2502 // expression. 2503 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>()); 2504 2505 Writer->SubStmtEntries.clear(); 2506 Writer->ParentStmts.clear(); 2507 } 2508 2509 StmtsToEmit.clear(); 2510 } 2511 2512 void ASTRecordWriter::FlushSubStmts() { 2513 // For a nested statement, write out the substatements in reverse order (so 2514 // that a simple stack machine can be used when loading), and don't emit a 2515 // STMT_STOP after each one. 2516 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) { 2517 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]); 2518 assert(N == StmtsToEmit.size() && "record modified while being written!"); 2519 } 2520 2521 StmtsToEmit.clear(); 2522 } 2523