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