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 // This file implements serialization for Statements and Expressions. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/Serialization/ASTWriter.h" 15 #include "clang/AST/ASTContext.h" 16 #include "clang/AST/DeclCXX.h" 17 #include "clang/AST/DeclObjC.h" 18 #include "clang/AST/DeclTemplate.h" 19 #include "clang/AST/StmtVisitor.h" 20 #include "llvm/Bitcode/BitstreamWriter.h" 21 using namespace clang; 22 23 //===----------------------------------------------------------------------===// 24 // Statement/expression serialization 25 //===----------------------------------------------------------------------===// 26 27 namespace clang { 28 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> { 29 ASTWriter &Writer; 30 ASTWriter::RecordData &Record; 31 32 public: 33 serialization::StmtCode Code; 34 unsigned AbbrevToUse; 35 36 ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record) 37 : Writer(Writer), Record(Record) { } 38 39 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &Args); 40 41 void VisitStmt(Stmt *S); 42 #define STMT(Type, Base) \ 43 void Visit##Type(Type *); 44 #include "clang/AST/StmtNodes.inc" 45 }; 46 } 47 48 void ASTStmtWriter:: 49 AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &Args) { 50 Writer.AddSourceLocation(Args.getTemplateKeywordLoc(), Record); 51 Writer.AddSourceLocation(Args.LAngleLoc, Record); 52 Writer.AddSourceLocation(Args.RAngleLoc, Record); 53 for (unsigned i=0; i != Args.NumTemplateArgs; ++i) 54 Writer.AddTemplateArgumentLoc(Args.getTemplateArgs()[i], Record); 55 } 56 57 void ASTStmtWriter::VisitStmt(Stmt *S) { 58 } 59 60 void ASTStmtWriter::VisitNullStmt(NullStmt *S) { 61 VisitStmt(S); 62 Writer.AddSourceLocation(S->getSemiLoc(), Record); 63 Record.push_back(S->HasLeadingEmptyMacro); 64 Code = serialization::STMT_NULL; 65 } 66 67 void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) { 68 VisitStmt(S); 69 Record.push_back(S->size()); 70 for (CompoundStmt::body_iterator CS = S->body_begin(), CSEnd = S->body_end(); 71 CS != CSEnd; ++CS) 72 Writer.AddStmt(*CS); 73 Writer.AddSourceLocation(S->getLBracLoc(), Record); 74 Writer.AddSourceLocation(S->getRBracLoc(), Record); 75 Code = serialization::STMT_COMPOUND; 76 } 77 78 void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) { 79 VisitStmt(S); 80 Record.push_back(Writer.getSwitchCaseID(S)); 81 Writer.AddSourceLocation(S->getKeywordLoc(), Record); 82 Writer.AddSourceLocation(S->getColonLoc(), Record); 83 } 84 85 void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) { 86 VisitSwitchCase(S); 87 Writer.AddStmt(S->getLHS()); 88 Writer.AddStmt(S->getRHS()); 89 Writer.AddStmt(S->getSubStmt()); 90 Writer.AddSourceLocation(S->getEllipsisLoc(), Record); 91 Code = serialization::STMT_CASE; 92 } 93 94 void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) { 95 VisitSwitchCase(S); 96 Writer.AddStmt(S->getSubStmt()); 97 Code = serialization::STMT_DEFAULT; 98 } 99 100 void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) { 101 VisitStmt(S); 102 Writer.AddDeclRef(S->getDecl(), Record); 103 Writer.AddStmt(S->getSubStmt()); 104 Writer.AddSourceLocation(S->getIdentLoc(), Record); 105 Code = serialization::STMT_LABEL; 106 } 107 108 void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) { 109 VisitStmt(S); 110 Record.push_back(S->getAttrs().size()); 111 Writer.WriteAttributes(S->getAttrs(), Record); 112 Writer.AddStmt(S->getSubStmt()); 113 Writer.AddSourceLocation(S->getAttrLoc(), Record); 114 Code = serialization::STMT_ATTRIBUTED; 115 } 116 117 void ASTStmtWriter::VisitIfStmt(IfStmt *S) { 118 VisitStmt(S); 119 Writer.AddDeclRef(S->getConditionVariable(), Record); 120 Writer.AddStmt(S->getCond()); 121 Writer.AddStmt(S->getThen()); 122 Writer.AddStmt(S->getElse()); 123 Writer.AddSourceLocation(S->getIfLoc(), Record); 124 Writer.AddSourceLocation(S->getElseLoc(), Record); 125 Code = serialization::STMT_IF; 126 } 127 128 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) { 129 VisitStmt(S); 130 Writer.AddDeclRef(S->getConditionVariable(), Record); 131 Writer.AddStmt(S->getCond()); 132 Writer.AddStmt(S->getBody()); 133 Writer.AddSourceLocation(S->getSwitchLoc(), Record); 134 Record.push_back(S->isAllEnumCasesCovered()); 135 for (SwitchCase *SC = S->getSwitchCaseList(); SC; 136 SC = SC->getNextSwitchCase()) 137 Record.push_back(Writer.RecordSwitchCaseID(SC)); 138 Code = serialization::STMT_SWITCH; 139 } 140 141 void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) { 142 VisitStmt(S); 143 Writer.AddDeclRef(S->getConditionVariable(), Record); 144 Writer.AddStmt(S->getCond()); 145 Writer.AddStmt(S->getBody()); 146 Writer.AddSourceLocation(S->getWhileLoc(), Record); 147 Code = serialization::STMT_WHILE; 148 } 149 150 void ASTStmtWriter::VisitDoStmt(DoStmt *S) { 151 VisitStmt(S); 152 Writer.AddStmt(S->getCond()); 153 Writer.AddStmt(S->getBody()); 154 Writer.AddSourceLocation(S->getDoLoc(), Record); 155 Writer.AddSourceLocation(S->getWhileLoc(), Record); 156 Writer.AddSourceLocation(S->getRParenLoc(), Record); 157 Code = serialization::STMT_DO; 158 } 159 160 void ASTStmtWriter::VisitForStmt(ForStmt *S) { 161 VisitStmt(S); 162 Writer.AddStmt(S->getInit()); 163 Writer.AddStmt(S->getCond()); 164 Writer.AddDeclRef(S->getConditionVariable(), Record); 165 Writer.AddStmt(S->getInc()); 166 Writer.AddStmt(S->getBody()); 167 Writer.AddSourceLocation(S->getForLoc(), Record); 168 Writer.AddSourceLocation(S->getLParenLoc(), Record); 169 Writer.AddSourceLocation(S->getRParenLoc(), Record); 170 Code = serialization::STMT_FOR; 171 } 172 173 void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) { 174 VisitStmt(S); 175 Writer.AddDeclRef(S->getLabel(), Record); 176 Writer.AddSourceLocation(S->getGotoLoc(), Record); 177 Writer.AddSourceLocation(S->getLabelLoc(), Record); 178 Code = serialization::STMT_GOTO; 179 } 180 181 void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { 182 VisitStmt(S); 183 Writer.AddSourceLocation(S->getGotoLoc(), Record); 184 Writer.AddSourceLocation(S->getStarLoc(), Record); 185 Writer.AddStmt(S->getTarget()); 186 Code = serialization::STMT_INDIRECT_GOTO; 187 } 188 189 void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) { 190 VisitStmt(S); 191 Writer.AddSourceLocation(S->getContinueLoc(), Record); 192 Code = serialization::STMT_CONTINUE; 193 } 194 195 void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) { 196 VisitStmt(S); 197 Writer.AddSourceLocation(S->getBreakLoc(), Record); 198 Code = serialization::STMT_BREAK; 199 } 200 201 void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) { 202 VisitStmt(S); 203 Writer.AddStmt(S->getRetValue()); 204 Writer.AddSourceLocation(S->getReturnLoc(), Record); 205 Writer.AddDeclRef(S->getNRVOCandidate(), Record); 206 Code = serialization::STMT_RETURN; 207 } 208 209 void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) { 210 VisitStmt(S); 211 Writer.AddSourceLocation(S->getStartLoc(), Record); 212 Writer.AddSourceLocation(S->getEndLoc(), Record); 213 DeclGroupRef DG = S->getDeclGroup(); 214 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D) 215 Writer.AddDeclRef(*D, Record); 216 Code = serialization::STMT_DECL; 217 } 218 219 void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) { 220 VisitStmt(S); 221 Record.push_back(S->getNumOutputs()); 222 Record.push_back(S->getNumInputs()); 223 Record.push_back(S->getNumClobbers()); 224 Writer.AddSourceLocation(S->getAsmLoc(), Record); 225 Writer.AddSourceLocation(S->getRParenLoc(), Record); 226 Record.push_back(S->isVolatile()); 227 Record.push_back(S->isSimple()); 228 Writer.AddStmt(S->getAsmString()); 229 230 // Outputs 231 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) { 232 Writer.AddIdentifierRef(S->getOutputIdentifier(I), Record); 233 Writer.AddStmt(S->getOutputConstraintLiteral(I)); 234 Writer.AddStmt(S->getOutputExpr(I)); 235 } 236 237 // Inputs 238 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) { 239 Writer.AddIdentifierRef(S->getInputIdentifier(I), Record); 240 Writer.AddStmt(S->getInputConstraintLiteral(I)); 241 Writer.AddStmt(S->getInputExpr(I)); 242 } 243 244 // Clobbers 245 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) 246 Writer.AddStmt(S->getClobberStringLiteral(I)); 247 248 Code = serialization::STMT_GCCASM; 249 } 250 251 void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) { 252 // FIXME: Statement writer not yet implemented for MS style inline asm. 253 VisitStmt(S); 254 255 Code = serialization::STMT_MSASM; 256 } 257 258 void ASTStmtWriter::VisitExpr(Expr *E) { 259 VisitStmt(E); 260 Writer.AddTypeRef(E->getType(), Record); 261 Record.push_back(E->isTypeDependent()); 262 Record.push_back(E->isValueDependent()); 263 Record.push_back(E->isInstantiationDependent()); 264 Record.push_back(E->containsUnexpandedParameterPack()); 265 Record.push_back(E->getValueKind()); 266 Record.push_back(E->getObjectKind()); 267 } 268 269 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) { 270 VisitExpr(E); 271 Writer.AddSourceLocation(E->getLocation(), Record); 272 Record.push_back(E->getIdentType()); // FIXME: stable encoding 273 Code = serialization::EXPR_PREDEFINED; 274 } 275 276 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) { 277 VisitExpr(E); 278 279 Record.push_back(E->hasQualifier()); 280 Record.push_back(E->getDecl() != E->getFoundDecl()); 281 Record.push_back(E->hasTemplateKWAndArgsInfo()); 282 Record.push_back(E->hadMultipleCandidates()); 283 Record.push_back(E->refersToEnclosingLocal()); 284 285 if (E->hasTemplateKWAndArgsInfo()) { 286 unsigned NumTemplateArgs = E->getNumTemplateArgs(); 287 Record.push_back(NumTemplateArgs); 288 } 289 290 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind()); 291 292 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) && 293 (E->getDecl() == E->getFoundDecl()) && 294 nk == DeclarationName::Identifier) { 295 AbbrevToUse = Writer.getDeclRefExprAbbrev(); 296 } 297 298 if (E->hasQualifier()) 299 Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record); 300 301 if (E->getDecl() != E->getFoundDecl()) 302 Writer.AddDeclRef(E->getFoundDecl(), Record); 303 304 if (E->hasTemplateKWAndArgsInfo()) 305 AddTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo()); 306 307 Writer.AddDeclRef(E->getDecl(), Record); 308 Writer.AddSourceLocation(E->getLocation(), Record); 309 Writer.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record); 310 Code = serialization::EXPR_DECL_REF; 311 } 312 313 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) { 314 VisitExpr(E); 315 Writer.AddSourceLocation(E->getLocation(), Record); 316 Writer.AddAPInt(E->getValue(), Record); 317 318 if (E->getValue().getBitWidth() == 32) { 319 AbbrevToUse = Writer.getIntegerLiteralAbbrev(); 320 } 321 322 Code = serialization::EXPR_INTEGER_LITERAL; 323 } 324 325 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) { 326 VisitExpr(E); 327 Record.push_back(E->getRawSemantics()); 328 Record.push_back(E->isExact()); 329 Writer.AddAPFloat(E->getValue(), Record); 330 Writer.AddSourceLocation(E->getLocation(), Record); 331 Code = serialization::EXPR_FLOATING_LITERAL; 332 } 333 334 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) { 335 VisitExpr(E); 336 Writer.AddStmt(E->getSubExpr()); 337 Code = serialization::EXPR_IMAGINARY_LITERAL; 338 } 339 340 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) { 341 VisitExpr(E); 342 Record.push_back(E->getByteLength()); 343 Record.push_back(E->getNumConcatenated()); 344 Record.push_back(E->getKind()); 345 Record.push_back(E->isPascal()); 346 // FIXME: String data should be stored as a blob at the end of the 347 // StringLiteral. However, we can't do so now because we have no 348 // provision for coping with abbreviations when we're jumping around 349 // the AST file during deserialization. 350 Record.append(E->getBytes().begin(), E->getBytes().end()); 351 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) 352 Writer.AddSourceLocation(E->getStrTokenLoc(I), Record); 353 Code = serialization::EXPR_STRING_LITERAL; 354 } 355 356 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) { 357 VisitExpr(E); 358 Record.push_back(E->getValue()); 359 Writer.AddSourceLocation(E->getLocation(), Record); 360 Record.push_back(E->getKind()); 361 362 AbbrevToUse = Writer.getCharacterLiteralAbbrev(); 363 364 Code = serialization::EXPR_CHARACTER_LITERAL; 365 } 366 367 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) { 368 VisitExpr(E); 369 Writer.AddSourceLocation(E->getLParen(), Record); 370 Writer.AddSourceLocation(E->getRParen(), Record); 371 Writer.AddStmt(E->getSubExpr()); 372 Code = serialization::EXPR_PAREN; 373 } 374 375 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) { 376 VisitExpr(E); 377 Record.push_back(E->NumExprs); 378 for (unsigned i=0; i != E->NumExprs; ++i) 379 Writer.AddStmt(E->Exprs[i]); 380 Writer.AddSourceLocation(E->LParenLoc, Record); 381 Writer.AddSourceLocation(E->RParenLoc, Record); 382 Code = serialization::EXPR_PAREN_LIST; 383 } 384 385 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) { 386 VisitExpr(E); 387 Writer.AddStmt(E->getSubExpr()); 388 Record.push_back(E->getOpcode()); // FIXME: stable encoding 389 Writer.AddSourceLocation(E->getOperatorLoc(), Record); 390 Code = serialization::EXPR_UNARY_OPERATOR; 391 } 392 393 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) { 394 VisitExpr(E); 395 Record.push_back(E->getNumComponents()); 396 Record.push_back(E->getNumExpressions()); 397 Writer.AddSourceLocation(E->getOperatorLoc(), Record); 398 Writer.AddSourceLocation(E->getRParenLoc(), Record); 399 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record); 400 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 401 const OffsetOfExpr::OffsetOfNode &ON = E->getComponent(I); 402 Record.push_back(ON.getKind()); // FIXME: Stable encoding 403 Writer.AddSourceLocation(ON.getSourceRange().getBegin(), Record); 404 Writer.AddSourceLocation(ON.getSourceRange().getEnd(), Record); 405 switch (ON.getKind()) { 406 case OffsetOfExpr::OffsetOfNode::Array: 407 Record.push_back(ON.getArrayExprIndex()); 408 break; 409 410 case OffsetOfExpr::OffsetOfNode::Field: 411 Writer.AddDeclRef(ON.getField(), Record); 412 break; 413 414 case OffsetOfExpr::OffsetOfNode::Identifier: 415 Writer.AddIdentifierRef(ON.getFieldName(), Record); 416 break; 417 418 case OffsetOfExpr::OffsetOfNode::Base: 419 Writer.AddCXXBaseSpecifier(*ON.getBase(), Record); 420 break; 421 } 422 } 423 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I) 424 Writer.AddStmt(E->getIndexExpr(I)); 425 Code = serialization::EXPR_OFFSETOF; 426 } 427 428 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { 429 VisitExpr(E); 430 Record.push_back(E->getKind()); 431 if (E->isArgumentType()) 432 Writer.AddTypeSourceInfo(E->getArgumentTypeInfo(), Record); 433 else { 434 Record.push_back(0); 435 Writer.AddStmt(E->getArgumentExpr()); 436 } 437 Writer.AddSourceLocation(E->getOperatorLoc(), Record); 438 Writer.AddSourceLocation(E->getRParenLoc(), Record); 439 Code = serialization::EXPR_SIZEOF_ALIGN_OF; 440 } 441 442 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { 443 VisitExpr(E); 444 Writer.AddStmt(E->getLHS()); 445 Writer.AddStmt(E->getRHS()); 446 Writer.AddSourceLocation(E->getRBracketLoc(), Record); 447 Code = serialization::EXPR_ARRAY_SUBSCRIPT; 448 } 449 450 void ASTStmtWriter::VisitCallExpr(CallExpr *E) { 451 VisitExpr(E); 452 Record.push_back(E->getNumArgs()); 453 Writer.AddSourceLocation(E->getRParenLoc(), Record); 454 Writer.AddStmt(E->getCallee()); 455 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); 456 Arg != ArgEnd; ++Arg) 457 Writer.AddStmt(*Arg); 458 Code = serialization::EXPR_CALL; 459 } 460 461 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) { 462 // Don't call VisitExpr, we'll write everything here. 463 464 Record.push_back(E->hasQualifier()); 465 if (E->hasQualifier()) 466 Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record); 467 468 Record.push_back(E->HasTemplateKWAndArgsInfo); 469 if (E->HasTemplateKWAndArgsInfo) { 470 Writer.AddSourceLocation(E->getTemplateKeywordLoc(), Record); 471 unsigned NumTemplateArgs = E->getNumTemplateArgs(); 472 Record.push_back(NumTemplateArgs); 473 Writer.AddSourceLocation(E->getLAngleLoc(), Record); 474 Writer.AddSourceLocation(E->getRAngleLoc(), Record); 475 for (unsigned i=0; i != NumTemplateArgs; ++i) 476 Writer.AddTemplateArgumentLoc(E->getTemplateArgs()[i], Record); 477 } 478 479 Record.push_back(E->hadMultipleCandidates()); 480 481 DeclAccessPair FoundDecl = E->getFoundDecl(); 482 Writer.AddDeclRef(FoundDecl.getDecl(), Record); 483 Record.push_back(FoundDecl.getAccess()); 484 485 Writer.AddTypeRef(E->getType(), Record); 486 Record.push_back(E->getValueKind()); 487 Record.push_back(E->getObjectKind()); 488 Writer.AddStmt(E->getBase()); 489 Writer.AddDeclRef(E->getMemberDecl(), Record); 490 Writer.AddSourceLocation(E->getMemberLoc(), Record); 491 Record.push_back(E->isArrow()); 492 Writer.AddDeclarationNameLoc(E->MemberDNLoc, 493 E->getMemberDecl()->getDeclName(), Record); 494 Code = serialization::EXPR_MEMBER; 495 } 496 497 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) { 498 VisitExpr(E); 499 Writer.AddStmt(E->getBase()); 500 Writer.AddSourceLocation(E->getIsaMemberLoc(), Record); 501 Record.push_back(E->isArrow()); 502 Code = serialization::EXPR_OBJC_ISA; 503 } 504 505 void ASTStmtWriter:: 506 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 507 VisitExpr(E); 508 Writer.AddStmt(E->getSubExpr()); 509 Record.push_back(E->shouldCopy()); 510 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE; 511 } 512 513 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 514 VisitExplicitCastExpr(E); 515 Writer.AddSourceLocation(E->getLParenLoc(), Record); 516 Writer.AddSourceLocation(E->getBridgeKeywordLoc(), Record); 517 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding 518 Code = serialization::EXPR_OBJC_BRIDGED_CAST; 519 } 520 521 void ASTStmtWriter::VisitCastExpr(CastExpr *E) { 522 VisitExpr(E); 523 Record.push_back(E->path_size()); 524 Writer.AddStmt(E->getSubExpr()); 525 Record.push_back(E->getCastKind()); // FIXME: stable encoding 526 527 for (CastExpr::path_iterator 528 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI) 529 Writer.AddCXXBaseSpecifier(**PI, Record); 530 } 531 532 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) { 533 VisitExpr(E); 534 Writer.AddStmt(E->getLHS()); 535 Writer.AddStmt(E->getRHS()); 536 Record.push_back(E->getOpcode()); // FIXME: stable encoding 537 Writer.AddSourceLocation(E->getOperatorLoc(), Record); 538 Record.push_back(E->isFPContractable()); 539 Code = serialization::EXPR_BINARY_OPERATOR; 540 } 541 542 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { 543 VisitBinaryOperator(E); 544 Writer.AddTypeRef(E->getComputationLHSType(), Record); 545 Writer.AddTypeRef(E->getComputationResultType(), Record); 546 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR; 547 } 548 549 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) { 550 VisitExpr(E); 551 Writer.AddStmt(E->getCond()); 552 Writer.AddStmt(E->getLHS()); 553 Writer.AddStmt(E->getRHS()); 554 Writer.AddSourceLocation(E->getQuestionLoc(), Record); 555 Writer.AddSourceLocation(E->getColonLoc(), Record); 556 Code = serialization::EXPR_CONDITIONAL_OPERATOR; 557 } 558 559 void 560 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { 561 VisitExpr(E); 562 Writer.AddStmt(E->getOpaqueValue()); 563 Writer.AddStmt(E->getCommon()); 564 Writer.AddStmt(E->getCond()); 565 Writer.AddStmt(E->getTrueExpr()); 566 Writer.AddStmt(E->getFalseExpr()); 567 Writer.AddSourceLocation(E->getQuestionLoc(), Record); 568 Writer.AddSourceLocation(E->getColonLoc(), Record); 569 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR; 570 } 571 572 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) { 573 VisitCastExpr(E); 574 Code = serialization::EXPR_IMPLICIT_CAST; 575 } 576 577 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) { 578 VisitCastExpr(E); 579 Writer.AddTypeSourceInfo(E->getTypeInfoAsWritten(), Record); 580 } 581 582 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) { 583 VisitExplicitCastExpr(E); 584 Writer.AddSourceLocation(E->getLParenLoc(), Record); 585 Writer.AddSourceLocation(E->getRParenLoc(), Record); 586 Code = serialization::EXPR_CSTYLE_CAST; 587 } 588 589 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { 590 VisitExpr(E); 591 Writer.AddSourceLocation(E->getLParenLoc(), Record); 592 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record); 593 Writer.AddStmt(E->getInitializer()); 594 Record.push_back(E->isFileScope()); 595 Code = serialization::EXPR_COMPOUND_LITERAL; 596 } 597 598 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { 599 VisitExpr(E); 600 Writer.AddStmt(E->getBase()); 601 Writer.AddIdentifierRef(&E->getAccessor(), Record); 602 Writer.AddSourceLocation(E->getAccessorLoc(), Record); 603 Code = serialization::EXPR_EXT_VECTOR_ELEMENT; 604 } 605 606 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) { 607 VisitExpr(E); 608 // NOTE: only add the (possibly null) syntactic form. 609 // No need to serialize the isSemanticForm flag and the semantic form. 610 Writer.AddStmt(E->getSyntacticForm()); 611 Writer.AddSourceLocation(E->getLBraceLoc(), Record); 612 Writer.AddSourceLocation(E->getRBraceLoc(), Record); 613 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>(); 614 Record.push_back(isArrayFiller); 615 if (isArrayFiller) 616 Writer.AddStmt(E->getArrayFiller()); 617 else 618 Writer.AddDeclRef(E->getInitializedFieldInUnion(), Record); 619 Record.push_back(E->hadArrayRangeDesignator()); 620 Record.push_back(E->initializesStdInitializerList()); 621 Record.push_back(E->getNumInits()); 622 if (isArrayFiller) { 623 // ArrayFiller may have filled "holes" due to designated initializer. 624 // Replace them by 0 to indicate that the filler goes in that place. 625 Expr *filler = E->getArrayFiller(); 626 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) 627 Writer.AddStmt(E->getInit(I) != filler ? E->getInit(I) : 0); 628 } else { 629 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) 630 Writer.AddStmt(E->getInit(I)); 631 } 632 Code = serialization::EXPR_INIT_LIST; 633 } 634 635 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { 636 VisitExpr(E); 637 Record.push_back(E->getNumSubExprs()); 638 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) 639 Writer.AddStmt(E->getSubExpr(I)); 640 Writer.AddSourceLocation(E->getEqualOrColonLoc(), Record); 641 Record.push_back(E->usesGNUSyntax()); 642 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), 643 DEnd = E->designators_end(); 644 D != DEnd; ++D) { 645 if (D->isFieldDesignator()) { 646 if (FieldDecl *Field = D->getField()) { 647 Record.push_back(serialization::DESIG_FIELD_DECL); 648 Writer.AddDeclRef(Field, Record); 649 } else { 650 Record.push_back(serialization::DESIG_FIELD_NAME); 651 Writer.AddIdentifierRef(D->getFieldName(), Record); 652 } 653 Writer.AddSourceLocation(D->getDotLoc(), Record); 654 Writer.AddSourceLocation(D->getFieldLoc(), Record); 655 } else if (D->isArrayDesignator()) { 656 Record.push_back(serialization::DESIG_ARRAY); 657 Record.push_back(D->getFirstExprIndex()); 658 Writer.AddSourceLocation(D->getLBracketLoc(), Record); 659 Writer.AddSourceLocation(D->getRBracketLoc(), Record); 660 } else { 661 assert(D->isArrayRangeDesignator() && "Unknown designator"); 662 Record.push_back(serialization::DESIG_ARRAY_RANGE); 663 Record.push_back(D->getFirstExprIndex()); 664 Writer.AddSourceLocation(D->getLBracketLoc(), Record); 665 Writer.AddSourceLocation(D->getEllipsisLoc(), Record); 666 Writer.AddSourceLocation(D->getRBracketLoc(), Record); 667 } 668 } 669 Code = serialization::EXPR_DESIGNATED_INIT; 670 } 671 672 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { 673 VisitExpr(E); 674 Code = serialization::EXPR_IMPLICIT_VALUE_INIT; 675 } 676 677 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) { 678 VisitExpr(E); 679 Writer.AddStmt(E->getSubExpr()); 680 Writer.AddTypeSourceInfo(E->getWrittenTypeInfo(), Record); 681 Writer.AddSourceLocation(E->getBuiltinLoc(), Record); 682 Writer.AddSourceLocation(E->getRParenLoc(), Record); 683 Code = serialization::EXPR_VA_ARG; 684 } 685 686 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) { 687 VisitExpr(E); 688 Writer.AddSourceLocation(E->getAmpAmpLoc(), Record); 689 Writer.AddSourceLocation(E->getLabelLoc(), Record); 690 Writer.AddDeclRef(E->getLabel(), Record); 691 Code = serialization::EXPR_ADDR_LABEL; 692 } 693 694 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) { 695 VisitExpr(E); 696 Writer.AddStmt(E->getSubStmt()); 697 Writer.AddSourceLocation(E->getLParenLoc(), Record); 698 Writer.AddSourceLocation(E->getRParenLoc(), Record); 699 Code = serialization::EXPR_STMT; 700 } 701 702 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) { 703 VisitExpr(E); 704 Writer.AddStmt(E->getCond()); 705 Writer.AddStmt(E->getLHS()); 706 Writer.AddStmt(E->getRHS()); 707 Writer.AddSourceLocation(E->getBuiltinLoc(), Record); 708 Writer.AddSourceLocation(E->getRParenLoc(), Record); 709 Code = serialization::EXPR_CHOOSE; 710 } 711 712 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) { 713 VisitExpr(E); 714 Writer.AddSourceLocation(E->getTokenLocation(), Record); 715 Code = serialization::EXPR_GNU_NULL; 716 } 717 718 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { 719 VisitExpr(E); 720 Record.push_back(E->getNumSubExprs()); 721 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) 722 Writer.AddStmt(E->getExpr(I)); 723 Writer.AddSourceLocation(E->getBuiltinLoc(), Record); 724 Writer.AddSourceLocation(E->getRParenLoc(), Record); 725 Code = serialization::EXPR_SHUFFLE_VECTOR; 726 } 727 728 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) { 729 VisitExpr(E); 730 Writer.AddDeclRef(E->getBlockDecl(), Record); 731 Code = serialization::EXPR_BLOCK; 732 } 733 734 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) { 735 VisitExpr(E); 736 Record.push_back(E->getNumAssocs()); 737 738 Writer.AddStmt(E->getControllingExpr()); 739 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) { 740 Writer.AddTypeSourceInfo(E->getAssocTypeSourceInfo(I), Record); 741 Writer.AddStmt(E->getAssocExpr(I)); 742 } 743 Record.push_back(E->isResultDependent() ? -1U : E->getResultIndex()); 744 745 Writer.AddSourceLocation(E->getGenericLoc(), Record); 746 Writer.AddSourceLocation(E->getDefaultLoc(), Record); 747 Writer.AddSourceLocation(E->getRParenLoc(), Record); 748 Code = serialization::EXPR_GENERIC_SELECTION; 749 } 750 751 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) { 752 VisitExpr(E); 753 Record.push_back(E->getNumSemanticExprs()); 754 755 // Push the result index. Currently, this needs to exactly match 756 // the encoding used internally for ResultIndex. 757 unsigned result = E->getResultExprIndex(); 758 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1); 759 Record.push_back(result); 760 761 Writer.AddStmt(E->getSyntacticForm()); 762 for (PseudoObjectExpr::semantics_iterator 763 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) { 764 Writer.AddStmt(*i); 765 } 766 Code = serialization::EXPR_PSEUDO_OBJECT; 767 } 768 769 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) { 770 VisitExpr(E); 771 Record.push_back(E->getOp()); 772 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) 773 Writer.AddStmt(E->getSubExprs()[I]); 774 Writer.AddSourceLocation(E->getBuiltinLoc(), Record); 775 Writer.AddSourceLocation(E->getRParenLoc(), Record); 776 Code = serialization::EXPR_ATOMIC; 777 } 778 779 //===----------------------------------------------------------------------===// 780 // Objective-C Expressions and Statements. 781 //===----------------------------------------------------------------------===// 782 783 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) { 784 VisitExpr(E); 785 Writer.AddStmt(E->getString()); 786 Writer.AddSourceLocation(E->getAtLoc(), Record); 787 Code = serialization::EXPR_OBJC_STRING_LITERAL; 788 } 789 790 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) { 791 VisitExpr(E); 792 Writer.AddStmt(E->getSubExpr()); 793 Writer.AddDeclRef(E->getBoxingMethod(), Record); 794 Writer.AddSourceRange(E->getSourceRange(), Record); 795 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION; 796 } 797 798 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) { 799 VisitExpr(E); 800 Record.push_back(E->getNumElements()); 801 for (unsigned i = 0; i < E->getNumElements(); i++) 802 Writer.AddStmt(E->getElement(i)); 803 Writer.AddDeclRef(E->getArrayWithObjectsMethod(), Record); 804 Writer.AddSourceRange(E->getSourceRange(), Record); 805 Code = serialization::EXPR_OBJC_ARRAY_LITERAL; 806 } 807 808 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) { 809 VisitExpr(E); 810 Record.push_back(E->getNumElements()); 811 Record.push_back(E->HasPackExpansions); 812 for (unsigned i = 0; i < E->getNumElements(); i++) { 813 ObjCDictionaryElement Element = E->getKeyValueElement(i); 814 Writer.AddStmt(Element.Key); 815 Writer.AddStmt(Element.Value); 816 if (E->HasPackExpansions) { 817 Writer.AddSourceLocation(Element.EllipsisLoc, Record); 818 unsigned NumExpansions = 0; 819 if (Element.NumExpansions) 820 NumExpansions = *Element.NumExpansions + 1; 821 Record.push_back(NumExpansions); 822 } 823 } 824 825 Writer.AddDeclRef(E->getDictWithObjectsMethod(), Record); 826 Writer.AddSourceRange(E->getSourceRange(), Record); 827 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL; 828 } 829 830 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { 831 VisitExpr(E); 832 Writer.AddTypeSourceInfo(E->getEncodedTypeSourceInfo(), Record); 833 Writer.AddSourceLocation(E->getAtLoc(), Record); 834 Writer.AddSourceLocation(E->getRParenLoc(), Record); 835 Code = serialization::EXPR_OBJC_ENCODE; 836 } 837 838 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { 839 VisitExpr(E); 840 Writer.AddSelectorRef(E->getSelector(), Record); 841 Writer.AddSourceLocation(E->getAtLoc(), Record); 842 Writer.AddSourceLocation(E->getRParenLoc(), Record); 843 Code = serialization::EXPR_OBJC_SELECTOR_EXPR; 844 } 845 846 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { 847 VisitExpr(E); 848 Writer.AddDeclRef(E->getProtocol(), Record); 849 Writer.AddSourceLocation(E->getAtLoc(), Record); 850 Writer.AddSourceLocation(E->ProtoLoc, Record); 851 Writer.AddSourceLocation(E->getRParenLoc(), Record); 852 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR; 853 } 854 855 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { 856 VisitExpr(E); 857 Writer.AddDeclRef(E->getDecl(), Record); 858 Writer.AddSourceLocation(E->getLocation(), Record); 859 Writer.AddStmt(E->getBase()); 860 Record.push_back(E->isArrow()); 861 Record.push_back(E->isFreeIvar()); 862 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR; 863 } 864 865 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 866 VisitExpr(E); 867 Record.push_back(E->SetterAndMethodRefFlags.getInt()); 868 Record.push_back(E->isImplicitProperty()); 869 if (E->isImplicitProperty()) { 870 Writer.AddDeclRef(E->getImplicitPropertyGetter(), Record); 871 Writer.AddDeclRef(E->getImplicitPropertySetter(), Record); 872 } else { 873 Writer.AddDeclRef(E->getExplicitProperty(), Record); 874 } 875 Writer.AddSourceLocation(E->getLocation(), Record); 876 Writer.AddSourceLocation(E->getReceiverLocation(), Record); 877 if (E->isObjectReceiver()) { 878 Record.push_back(0); 879 Writer.AddStmt(E->getBase()); 880 } else if (E->isSuperReceiver()) { 881 Record.push_back(1); 882 Writer.AddTypeRef(E->getSuperReceiverType(), Record); 883 } else { 884 Record.push_back(2); 885 Writer.AddDeclRef(E->getClassReceiver(), Record); 886 } 887 888 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR; 889 } 890 891 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { 892 VisitExpr(E); 893 Writer.AddSourceLocation(E->getRBracket(), Record); 894 Writer.AddStmt(E->getBaseExpr()); 895 Writer.AddStmt(E->getKeyExpr()); 896 Writer.AddDeclRef(E->getAtIndexMethodDecl(), Record); 897 Writer.AddDeclRef(E->setAtIndexMethodDecl(), Record); 898 899 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR; 900 } 901 902 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) { 903 VisitExpr(E); 904 Record.push_back(E->getNumArgs()); 905 Record.push_back(E->getNumStoredSelLocs()); 906 Record.push_back(E->SelLocsKind); 907 Record.push_back(E->isDelegateInitCall()); 908 Record.push_back(E->IsImplicit); 909 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding 910 switch (E->getReceiverKind()) { 911 case ObjCMessageExpr::Instance: 912 Writer.AddStmt(E->getInstanceReceiver()); 913 break; 914 915 case ObjCMessageExpr::Class: 916 Writer.AddTypeSourceInfo(E->getClassReceiverTypeInfo(), Record); 917 break; 918 919 case ObjCMessageExpr::SuperClass: 920 case ObjCMessageExpr::SuperInstance: 921 Writer.AddTypeRef(E->getSuperType(), Record); 922 Writer.AddSourceLocation(E->getSuperLoc(), Record); 923 break; 924 } 925 926 if (E->getMethodDecl()) { 927 Record.push_back(1); 928 Writer.AddDeclRef(E->getMethodDecl(), Record); 929 } else { 930 Record.push_back(0); 931 Writer.AddSelectorRef(E->getSelector(), Record); 932 } 933 934 Writer.AddSourceLocation(E->getLeftLoc(), Record); 935 Writer.AddSourceLocation(E->getRightLoc(), Record); 936 937 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); 938 Arg != ArgEnd; ++Arg) 939 Writer.AddStmt(*Arg); 940 941 SourceLocation *Locs = E->getStoredSelLocs(); 942 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i) 943 Writer.AddSourceLocation(Locs[i], Record); 944 945 Code = serialization::EXPR_OBJC_MESSAGE_EXPR; 946 } 947 948 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { 949 VisitStmt(S); 950 Writer.AddStmt(S->getElement()); 951 Writer.AddStmt(S->getCollection()); 952 Writer.AddStmt(S->getBody()); 953 Writer.AddSourceLocation(S->getForLoc(), Record); 954 Writer.AddSourceLocation(S->getRParenLoc(), Record); 955 Code = serialization::STMT_OBJC_FOR_COLLECTION; 956 } 957 958 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { 959 Writer.AddStmt(S->getCatchBody()); 960 Writer.AddDeclRef(S->getCatchParamDecl(), Record); 961 Writer.AddSourceLocation(S->getAtCatchLoc(), Record); 962 Writer.AddSourceLocation(S->getRParenLoc(), Record); 963 Code = serialization::STMT_OBJC_CATCH; 964 } 965 966 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 967 Writer.AddStmt(S->getFinallyBody()); 968 Writer.AddSourceLocation(S->getAtFinallyLoc(), Record); 969 Code = serialization::STMT_OBJC_FINALLY; 970 } 971 972 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) { 973 Writer.AddStmt(S->getSubStmt()); 974 Writer.AddSourceLocation(S->getAtLoc(), Record); 975 Code = serialization::STMT_OBJC_AUTORELEASE_POOL; 976 } 977 978 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { 979 Record.push_back(S->getNumCatchStmts()); 980 Record.push_back(S->getFinallyStmt() != 0); 981 Writer.AddStmt(S->getTryBody()); 982 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) 983 Writer.AddStmt(S->getCatchStmt(I)); 984 if (S->getFinallyStmt()) 985 Writer.AddStmt(S->getFinallyStmt()); 986 Writer.AddSourceLocation(S->getAtTryLoc(), Record); 987 Code = serialization::STMT_OBJC_AT_TRY; 988 } 989 990 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { 991 Writer.AddStmt(S->getSynchExpr()); 992 Writer.AddStmt(S->getSynchBody()); 993 Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record); 994 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED; 995 } 996 997 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { 998 Writer.AddStmt(S->getThrowExpr()); 999 Writer.AddSourceLocation(S->getThrowLoc(), Record); 1000 Code = serialization::STMT_OBJC_AT_THROW; 1001 } 1002 1003 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { 1004 VisitExpr(E); 1005 Record.push_back(E->getValue()); 1006 Writer.AddSourceLocation(E->getLocation(), Record); 1007 Code = serialization::EXPR_OBJC_BOOL_LITERAL; 1008 } 1009 1010 //===----------------------------------------------------------------------===// 1011 // C++ Expressions and Statements. 1012 //===----------------------------------------------------------------------===// 1013 1014 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) { 1015 VisitStmt(S); 1016 Writer.AddSourceLocation(S->getCatchLoc(), Record); 1017 Writer.AddDeclRef(S->getExceptionDecl(), Record); 1018 Writer.AddStmt(S->getHandlerBlock()); 1019 Code = serialization::STMT_CXX_CATCH; 1020 } 1021 1022 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) { 1023 VisitStmt(S); 1024 Record.push_back(S->getNumHandlers()); 1025 Writer.AddSourceLocation(S->getTryLoc(), Record); 1026 Writer.AddStmt(S->getTryBlock()); 1027 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i) 1028 Writer.AddStmt(S->getHandler(i)); 1029 Code = serialization::STMT_CXX_TRY; 1030 } 1031 1032 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { 1033 VisitStmt(S); 1034 Writer.AddSourceLocation(S->getForLoc(), Record); 1035 Writer.AddSourceLocation(S->getColonLoc(), Record); 1036 Writer.AddSourceLocation(S->getRParenLoc(), Record); 1037 Writer.AddStmt(S->getRangeStmt()); 1038 Writer.AddStmt(S->getBeginEndStmt()); 1039 Writer.AddStmt(S->getCond()); 1040 Writer.AddStmt(S->getInc()); 1041 Writer.AddStmt(S->getLoopVarStmt()); 1042 Writer.AddStmt(S->getBody()); 1043 Code = serialization::STMT_CXX_FOR_RANGE; 1044 } 1045 1046 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) { 1047 VisitStmt(S); 1048 Writer.AddSourceLocation(S->getKeywordLoc(), Record); 1049 Record.push_back(S->isIfExists()); 1050 Writer.AddNestedNameSpecifierLoc(S->getQualifierLoc(), Record); 1051 Writer.AddDeclarationNameInfo(S->getNameInfo(), Record); 1052 Writer.AddStmt(S->getSubStmt()); 1053 Code = serialization::STMT_MS_DEPENDENT_EXISTS; 1054 } 1055 1056 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 1057 VisitCallExpr(E); 1058 Record.push_back(E->getOperator()); 1059 Writer.AddSourceRange(E->Range, Record); 1060 Record.push_back(E->isFPContractable()); 1061 Code = serialization::EXPR_CXX_OPERATOR_CALL; 1062 } 1063 1064 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { 1065 VisitCallExpr(E); 1066 Code = serialization::EXPR_CXX_MEMBER_CALL; 1067 } 1068 1069 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) { 1070 VisitExpr(E); 1071 Record.push_back(E->getNumArgs()); 1072 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 1073 Writer.AddStmt(E->getArg(I)); 1074 Writer.AddDeclRef(E->getConstructor(), Record); 1075 Writer.AddSourceLocation(E->getLocation(), Record); 1076 Record.push_back(E->isElidable()); 1077 Record.push_back(E->hadMultipleCandidates()); 1078 Record.push_back(E->isListInitialization()); 1079 Record.push_back(E->requiresZeroInitialization()); 1080 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding 1081 Writer.AddSourceRange(E->getParenRange(), Record); 1082 Code = serialization::EXPR_CXX_CONSTRUCT; 1083 } 1084 1085 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { 1086 VisitCXXConstructExpr(E); 1087 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record); 1088 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT; 1089 } 1090 1091 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) { 1092 VisitExpr(E); 1093 Record.push_back(E->NumCaptures); 1094 unsigned NumArrayIndexVars = 0; 1095 if (E->HasArrayIndexVars) 1096 NumArrayIndexVars = E->getArrayIndexStarts()[E->NumCaptures]; 1097 Record.push_back(NumArrayIndexVars); 1098 Writer.AddSourceRange(E->IntroducerRange, Record); 1099 Record.push_back(E->CaptureDefault); // FIXME: stable encoding 1100 Record.push_back(E->ExplicitParams); 1101 Record.push_back(E->ExplicitResultType); 1102 Writer.AddSourceLocation(E->ClosingBrace, Record); 1103 1104 // Add capture initializers. 1105 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(), 1106 CEnd = E->capture_init_end(); 1107 C != CEnd; ++C) { 1108 Writer.AddStmt(*C); 1109 } 1110 1111 // Add array index variables, if any. 1112 if (NumArrayIndexVars) { 1113 Record.append(E->getArrayIndexStarts(), 1114 E->getArrayIndexStarts() + E->NumCaptures + 1); 1115 VarDecl **ArrayIndexVars = E->getArrayIndexVars(); 1116 for (unsigned I = 0; I != NumArrayIndexVars; ++I) 1117 Writer.AddDeclRef(ArrayIndexVars[I], Record); 1118 } 1119 1120 Code = serialization::EXPR_LAMBDA; 1121 } 1122 1123 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { 1124 VisitExplicitCastExpr(E); 1125 Writer.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()), 1126 Record); 1127 Writer.AddSourceRange(E->getAngleBrackets(), Record); 1128 } 1129 1130 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) { 1131 VisitCXXNamedCastExpr(E); 1132 Code = serialization::EXPR_CXX_STATIC_CAST; 1133 } 1134 1135 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 1136 VisitCXXNamedCastExpr(E); 1137 Code = serialization::EXPR_CXX_DYNAMIC_CAST; 1138 } 1139 1140 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) { 1141 VisitCXXNamedCastExpr(E); 1142 Code = serialization::EXPR_CXX_REINTERPRET_CAST; 1143 } 1144 1145 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) { 1146 VisitCXXNamedCastExpr(E); 1147 Code = serialization::EXPR_CXX_CONST_CAST; 1148 } 1149 1150 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { 1151 VisitExplicitCastExpr(E); 1152 Writer.AddSourceLocation(E->getTypeBeginLoc(), Record); 1153 Writer.AddSourceLocation(E->getRParenLoc(), Record); 1154 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST; 1155 } 1156 1157 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) { 1158 VisitCallExpr(E); 1159 Writer.AddSourceLocation(E->UDSuffixLoc, Record); 1160 Code = serialization::EXPR_USER_DEFINED_LITERAL; 1161 } 1162 1163 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 1164 VisitExpr(E); 1165 Record.push_back(E->getValue()); 1166 Writer.AddSourceLocation(E->getLocation(), Record); 1167 Code = serialization::EXPR_CXX_BOOL_LITERAL; 1168 } 1169 1170 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { 1171 VisitExpr(E); 1172 Writer.AddSourceLocation(E->getLocation(), Record); 1173 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL; 1174 } 1175 1176 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { 1177 VisitExpr(E); 1178 Writer.AddSourceRange(E->getSourceRange(), Record); 1179 if (E->isTypeOperand()) { 1180 Writer.AddTypeSourceInfo(E->getTypeOperandSourceInfo(), Record); 1181 Code = serialization::EXPR_CXX_TYPEID_TYPE; 1182 } else { 1183 Writer.AddStmt(E->getExprOperand()); 1184 Code = serialization::EXPR_CXX_TYPEID_EXPR; 1185 } 1186 } 1187 1188 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) { 1189 VisitExpr(E); 1190 Writer.AddSourceLocation(E->getLocation(), Record); 1191 Record.push_back(E->isImplicit()); 1192 Code = serialization::EXPR_CXX_THIS; 1193 } 1194 1195 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) { 1196 VisitExpr(E); 1197 Writer.AddSourceLocation(E->getThrowLoc(), Record); 1198 Writer.AddStmt(E->getSubExpr()); 1199 Record.push_back(E->isThrownVariableInScope()); 1200 Code = serialization::EXPR_CXX_THROW; 1201 } 1202 1203 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 1204 VisitExpr(E); 1205 1206 bool HasOtherExprStored = E->Param.getInt(); 1207 // Store these first, the reader reads them before creation. 1208 Record.push_back(HasOtherExprStored); 1209 if (HasOtherExprStored) 1210 Writer.AddStmt(E->getExpr()); 1211 Writer.AddDeclRef(E->getParam(), Record); 1212 Writer.AddSourceLocation(E->getUsedLocation(), Record); 1213 1214 Code = serialization::EXPR_CXX_DEFAULT_ARG; 1215 } 1216 1217 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 1218 VisitExpr(E); 1219 Writer.AddCXXTemporary(E->getTemporary(), Record); 1220 Writer.AddStmt(E->getSubExpr()); 1221 Code = serialization::EXPR_CXX_BIND_TEMPORARY; 1222 } 1223 1224 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { 1225 VisitExpr(E); 1226 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record); 1227 Writer.AddSourceLocation(E->getRParenLoc(), Record); 1228 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT; 1229 } 1230 1231 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) { 1232 VisitExpr(E); 1233 Record.push_back(E->isGlobalNew()); 1234 Record.push_back(E->isArray()); 1235 Record.push_back(E->doesUsualArrayDeleteWantSize()); 1236 Record.push_back(E->getNumPlacementArgs()); 1237 Record.push_back(E->StoredInitializationStyle); 1238 Writer.AddDeclRef(E->getOperatorNew(), Record); 1239 Writer.AddDeclRef(E->getOperatorDelete(), Record); 1240 Writer.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo(), Record); 1241 Writer.AddSourceRange(E->getTypeIdParens(), Record); 1242 Writer.AddSourceRange(E->getSourceRange(), Record); 1243 Writer.AddSourceRange(E->getDirectInitRange(), Record); 1244 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end(); 1245 I != e; ++I) 1246 Writer.AddStmt(*I); 1247 1248 Code = serialization::EXPR_CXX_NEW; 1249 } 1250 1251 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { 1252 VisitExpr(E); 1253 Record.push_back(E->isGlobalDelete()); 1254 Record.push_back(E->isArrayForm()); 1255 Record.push_back(E->isArrayFormAsWritten()); 1256 Record.push_back(E->doesUsualArrayDeleteWantSize()); 1257 Writer.AddDeclRef(E->getOperatorDelete(), Record); 1258 Writer.AddStmt(E->getArgument()); 1259 Writer.AddSourceLocation(E->getSourceRange().getBegin(), Record); 1260 1261 Code = serialization::EXPR_CXX_DELETE; 1262 } 1263 1264 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { 1265 VisitExpr(E); 1266 1267 Writer.AddStmt(E->getBase()); 1268 Record.push_back(E->isArrow()); 1269 Writer.AddSourceLocation(E->getOperatorLoc(), Record); 1270 Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record); 1271 Writer.AddTypeSourceInfo(E->getScopeTypeInfo(), Record); 1272 Writer.AddSourceLocation(E->getColonColonLoc(), Record); 1273 Writer.AddSourceLocation(E->getTildeLoc(), Record); 1274 1275 // PseudoDestructorTypeStorage. 1276 Writer.AddIdentifierRef(E->getDestroyedTypeIdentifier(), Record); 1277 if (E->getDestroyedTypeIdentifier()) 1278 Writer.AddSourceLocation(E->getDestroyedTypeLoc(), Record); 1279 else 1280 Writer.AddTypeSourceInfo(E->getDestroyedTypeInfo(), Record); 1281 1282 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR; 1283 } 1284 1285 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) { 1286 VisitExpr(E); 1287 Record.push_back(E->getNumObjects()); 1288 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i) 1289 Writer.AddDeclRef(E->getObject(i), Record); 1290 1291 Writer.AddStmt(E->getSubExpr()); 1292 Code = serialization::EXPR_EXPR_WITH_CLEANUPS; 1293 } 1294 1295 void 1296 ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){ 1297 VisitExpr(E); 1298 1299 // Don't emit anything here, HasTemplateKWAndArgsInfo must be 1300 // emitted first. 1301 1302 Record.push_back(E->HasTemplateKWAndArgsInfo); 1303 if (E->HasTemplateKWAndArgsInfo) { 1304 const ASTTemplateKWAndArgsInfo &Args = *E->getTemplateKWAndArgsInfo(); 1305 Record.push_back(Args.NumTemplateArgs); 1306 AddTemplateKWAndArgsInfo(Args); 1307 } 1308 1309 if (!E->isImplicitAccess()) 1310 Writer.AddStmt(E->getBase()); 1311 else 1312 Writer.AddStmt(0); 1313 Writer.AddTypeRef(E->getBaseType(), Record); 1314 Record.push_back(E->isArrow()); 1315 Writer.AddSourceLocation(E->getOperatorLoc(), Record); 1316 Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record); 1317 Writer.AddDeclRef(E->getFirstQualifierFoundInScope(), Record); 1318 Writer.AddDeclarationNameInfo(E->MemberNameInfo, Record); 1319 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER; 1320 } 1321 1322 void 1323 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { 1324 VisitExpr(E); 1325 1326 // Don't emit anything here, HasTemplateKWAndArgsInfo must be 1327 // emitted first. 1328 1329 Record.push_back(E->HasTemplateKWAndArgsInfo); 1330 if (E->HasTemplateKWAndArgsInfo) { 1331 const ASTTemplateKWAndArgsInfo &Args = *E->getTemplateKWAndArgsInfo(); 1332 Record.push_back(Args.NumTemplateArgs); 1333 AddTemplateKWAndArgsInfo(Args); 1334 } 1335 1336 Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record); 1337 Writer.AddDeclarationNameInfo(E->NameInfo, Record); 1338 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF; 1339 } 1340 1341 void 1342 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) { 1343 VisitExpr(E); 1344 Record.push_back(E->arg_size()); 1345 for (CXXUnresolvedConstructExpr::arg_iterator 1346 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI) 1347 Writer.AddStmt(*ArgI); 1348 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record); 1349 Writer.AddSourceLocation(E->getLParenLoc(), Record); 1350 Writer.AddSourceLocation(E->getRParenLoc(), Record); 1351 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT; 1352 } 1353 1354 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) { 1355 VisitExpr(E); 1356 1357 // Don't emit anything here, HasTemplateKWAndArgsInfo must be 1358 // emitted first. 1359 1360 Record.push_back(E->HasTemplateKWAndArgsInfo); 1361 if (E->HasTemplateKWAndArgsInfo) { 1362 const ASTTemplateKWAndArgsInfo &Args = *E->getTemplateKWAndArgsInfo(); 1363 Record.push_back(Args.NumTemplateArgs); 1364 AddTemplateKWAndArgsInfo(Args); 1365 } 1366 1367 Record.push_back(E->getNumDecls()); 1368 for (OverloadExpr::decls_iterator 1369 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) { 1370 Writer.AddDeclRef(OvI.getDecl(), Record); 1371 Record.push_back(OvI.getAccess()); 1372 } 1373 1374 Writer.AddDeclarationNameInfo(E->NameInfo, Record); 1375 Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record); 1376 } 1377 1378 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { 1379 VisitOverloadExpr(E); 1380 Record.push_back(E->isArrow()); 1381 Record.push_back(E->hasUnresolvedUsing()); 1382 Writer.AddStmt(!E->isImplicitAccess() ? E->getBase() : 0); 1383 Writer.AddTypeRef(E->getBaseType(), Record); 1384 Writer.AddSourceLocation(E->getOperatorLoc(), Record); 1385 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER; 1386 } 1387 1388 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { 1389 VisitOverloadExpr(E); 1390 Record.push_back(E->requiresADL()); 1391 Record.push_back(E->isOverloaded()); 1392 Writer.AddDeclRef(E->getNamingClass(), Record); 1393 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP; 1394 } 1395 1396 void ASTStmtWriter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 1397 VisitExpr(E); 1398 Record.push_back(E->getTrait()); 1399 Record.push_back(E->getValue()); 1400 Writer.AddSourceRange(E->getSourceRange(), Record); 1401 Writer.AddTypeSourceInfo(E->getQueriedTypeSourceInfo(), Record); 1402 Code = serialization::EXPR_CXX_UNARY_TYPE_TRAIT; 1403 } 1404 1405 void ASTStmtWriter::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 1406 VisitExpr(E); 1407 Record.push_back(E->getTrait()); 1408 Record.push_back(E->getValue()); 1409 Writer.AddSourceRange(E->getSourceRange(), Record); 1410 Writer.AddTypeSourceInfo(E->getLhsTypeSourceInfo(), Record); 1411 Writer.AddTypeSourceInfo(E->getRhsTypeSourceInfo(), Record); 1412 Code = serialization::EXPR_BINARY_TYPE_TRAIT; 1413 } 1414 1415 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) { 1416 VisitExpr(E); 1417 Record.push_back(E->TypeTraitExprBits.NumArgs); 1418 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding 1419 Record.push_back(E->TypeTraitExprBits.Value); 1420 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 1421 Writer.AddTypeSourceInfo(E->getArg(I), Record); 1422 Code = serialization::EXPR_TYPE_TRAIT; 1423 } 1424 1425 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 1426 VisitExpr(E); 1427 Record.push_back(E->getTrait()); 1428 Record.push_back(E->getValue()); 1429 Writer.AddSourceRange(E->getSourceRange(), Record); 1430 Writer.AddTypeSourceInfo(E->getQueriedTypeSourceInfo(), Record); 1431 Code = serialization::EXPR_ARRAY_TYPE_TRAIT; 1432 } 1433 1434 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { 1435 VisitExpr(E); 1436 Record.push_back(E->getTrait()); 1437 Record.push_back(E->getValue()); 1438 Writer.AddSourceRange(E->getSourceRange(), Record); 1439 Writer.AddStmt(E->getQueriedExpression()); 1440 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT; 1441 } 1442 1443 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { 1444 VisitExpr(E); 1445 Record.push_back(E->getValue()); 1446 Writer.AddSourceRange(E->getSourceRange(), Record); 1447 Writer.AddStmt(E->getOperand()); 1448 Code = serialization::EXPR_CXX_NOEXCEPT; 1449 } 1450 1451 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) { 1452 VisitExpr(E); 1453 Writer.AddSourceLocation(E->getEllipsisLoc(), Record); 1454 Record.push_back(E->NumExpansions); 1455 Writer.AddStmt(E->getPattern()); 1456 Code = serialization::EXPR_PACK_EXPANSION; 1457 } 1458 1459 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { 1460 VisitExpr(E); 1461 Writer.AddSourceLocation(E->OperatorLoc, Record); 1462 Writer.AddSourceLocation(E->PackLoc, Record); 1463 Writer.AddSourceLocation(E->RParenLoc, Record); 1464 Record.push_back(E->Length); 1465 Writer.AddDeclRef(E->Pack, Record); 1466 Code = serialization::EXPR_SIZEOF_PACK; 1467 } 1468 1469 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr( 1470 SubstNonTypeTemplateParmExpr *E) { 1471 VisitExpr(E); 1472 Writer.AddDeclRef(E->getParameter(), Record); 1473 Writer.AddSourceLocation(E->getNameLoc(), Record); 1474 Writer.AddStmt(E->getReplacement()); 1475 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM; 1476 } 1477 1478 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr( 1479 SubstNonTypeTemplateParmPackExpr *E) { 1480 VisitExpr(E); 1481 Writer.AddDeclRef(E->getParameterPack(), Record); 1482 Writer.AddTemplateArgument(E->getArgumentPack(), Record); 1483 Writer.AddSourceLocation(E->getParameterPackLocation(), Record); 1484 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK; 1485 } 1486 1487 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) { 1488 VisitExpr(E); 1489 Record.push_back(E->getNumExpansions()); 1490 Writer.AddDeclRef(E->getParameterPack(), Record); 1491 Writer.AddSourceLocation(E->getParameterPackLocation(), Record); 1492 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end(); 1493 I != End; ++I) 1494 Writer.AddDeclRef(*I, Record); 1495 Code = serialization::EXPR_FUNCTION_PARM_PACK; 1496 } 1497 1498 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { 1499 VisitExpr(E); 1500 Writer.AddStmt(E->Temporary); 1501 Code = serialization::EXPR_MATERIALIZE_TEMPORARY; 1502 } 1503 1504 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { 1505 VisitExpr(E); 1506 Writer.AddStmt(E->getSourceExpr()); 1507 Writer.AddSourceLocation(E->getLocation(), Record); 1508 Code = serialization::EXPR_OPAQUE_VALUE; 1509 } 1510 1511 //===----------------------------------------------------------------------===// 1512 // CUDA Expressions and Statements. 1513 //===----------------------------------------------------------------------===// 1514 1515 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 1516 VisitCallExpr(E); 1517 Writer.AddStmt(E->getConfig()); 1518 Code = serialization::EXPR_CUDA_KERNEL_CALL; 1519 } 1520 1521 //===----------------------------------------------------------------------===// 1522 // OpenCL Expressions and Statements. 1523 //===----------------------------------------------------------------------===// 1524 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) { 1525 VisitExpr(E); 1526 Writer.AddSourceLocation(E->getBuiltinLoc(), Record); 1527 Writer.AddSourceLocation(E->getRParenLoc(), Record); 1528 Writer.AddStmt(E->getSrcExpr()); 1529 Code = serialization::EXPR_ASTYPE; 1530 } 1531 1532 //===----------------------------------------------------------------------===// 1533 // Microsoft Expressions and Statements. 1534 //===----------------------------------------------------------------------===// 1535 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) { 1536 VisitExpr(E); 1537 Writer.AddSourceRange(E->getSourceRange(), Record); 1538 if (E->isTypeOperand()) { 1539 Writer.AddTypeSourceInfo(E->getTypeOperandSourceInfo(), Record); 1540 Code = serialization::EXPR_CXX_UUIDOF_TYPE; 1541 } else { 1542 Writer.AddStmt(E->getExprOperand()); 1543 Code = serialization::EXPR_CXX_UUIDOF_EXPR; 1544 } 1545 } 1546 1547 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) { 1548 VisitStmt(S); 1549 Writer.AddSourceLocation(S->getExceptLoc(), Record); 1550 Writer.AddStmt(S->getFilterExpr()); 1551 Writer.AddStmt(S->getBlock()); 1552 Code = serialization::STMT_SEH_EXCEPT; 1553 } 1554 1555 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) { 1556 VisitStmt(S); 1557 Writer.AddSourceLocation(S->getFinallyLoc(), Record); 1558 Writer.AddStmt(S->getBlock()); 1559 Code = serialization::STMT_SEH_FINALLY; 1560 } 1561 1562 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) { 1563 VisitStmt(S); 1564 Record.push_back(S->getIsCXXTry()); 1565 Writer.AddSourceLocation(S->getTryLoc(), Record); 1566 Writer.AddStmt(S->getTryBlock()); 1567 Writer.AddStmt(S->getHandler()); 1568 Code = serialization::STMT_SEH_TRY; 1569 } 1570 1571 //===----------------------------------------------------------------------===// 1572 // ASTWriter Implementation 1573 //===----------------------------------------------------------------------===// 1574 1575 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) { 1576 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() && 1577 "SwitchCase recorded twice"); 1578 unsigned NextID = SwitchCaseIDs.size(); 1579 SwitchCaseIDs[S] = NextID; 1580 return NextID; 1581 } 1582 1583 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) { 1584 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() && 1585 "SwitchCase hasn't been seen yet"); 1586 return SwitchCaseIDs[S]; 1587 } 1588 1589 void ASTWriter::ClearSwitchCaseIDs() { 1590 SwitchCaseIDs.clear(); 1591 } 1592 1593 /// \brief Write the given substatement or subexpression to the 1594 /// bitstream. 1595 void ASTWriter::WriteSubStmt(Stmt *S, 1596 llvm::DenseMap<Stmt *, uint64_t> &SubStmtEntries, 1597 llvm::DenseSet<Stmt *> &ParentStmts) { 1598 RecordData Record; 1599 ASTStmtWriter Writer(*this, Record); 1600 ++NumStatements; 1601 1602 if (!S) { 1603 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record); 1604 return; 1605 } 1606 1607 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S); 1608 if (I != SubStmtEntries.end()) { 1609 Record.push_back(I->second); 1610 Stream.EmitRecord(serialization::STMT_REF_PTR, Record); 1611 return; 1612 } 1613 1614 #ifndef NDEBUG 1615 assert(!ParentStmts.count(S) && "There is a Stmt cycle!"); 1616 1617 struct ParentStmtInserterRAII { 1618 Stmt *S; 1619 llvm::DenseSet<Stmt *> &ParentStmts; 1620 1621 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts) 1622 : S(S), ParentStmts(ParentStmts) { 1623 ParentStmts.insert(S); 1624 } 1625 ~ParentStmtInserterRAII() { 1626 ParentStmts.erase(S); 1627 } 1628 }; 1629 1630 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts); 1631 #endif 1632 1633 // Redirect ASTWriter::AddStmt to collect sub stmts. 1634 SmallVector<Stmt *, 16> SubStmts; 1635 CollectedStmts = &SubStmts; 1636 1637 Writer.Code = serialization::STMT_NULL_PTR; 1638 Writer.AbbrevToUse = 0; 1639 Writer.Visit(S); 1640 1641 #ifndef NDEBUG 1642 if (Writer.Code == serialization::STMT_NULL_PTR) { 1643 SourceManager &SrcMgr 1644 = DeclIDs.begin()->first->getASTContext().getSourceManager(); 1645 S->dump(SrcMgr); 1646 llvm_unreachable("Unhandled sub statement writing AST file"); 1647 } 1648 #endif 1649 1650 // Revert ASTWriter::AddStmt. 1651 CollectedStmts = &StmtsToEmit; 1652 1653 // Write the sub stmts in reverse order, last to first. When reading them back 1654 // we will read them in correct order by "pop"ing them from the Stmts stack. 1655 // This simplifies reading and allows to store a variable number of sub stmts 1656 // without knowing it in advance. 1657 while (!SubStmts.empty()) 1658 WriteSubStmt(SubStmts.pop_back_val(), SubStmtEntries, ParentStmts); 1659 1660 Stream.EmitRecord(Writer.Code, Record, Writer.AbbrevToUse); 1661 1662 SubStmtEntries[S] = Stream.GetCurrentBitNo(); 1663 } 1664 1665 /// \brief Flush all of the statements that have been added to the 1666 /// queue via AddStmt(). 1667 void ASTWriter::FlushStmts() { 1668 RecordData Record; 1669 1670 // We expect to be the only consumer of the two temporary statement maps, 1671 // assert that they are empty. 1672 assert(SubStmtEntries.empty() && "unexpected entries in sub stmt map"); 1673 assert(ParentStmts.empty() && "unexpected entries in parent stmt map"); 1674 1675 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) { 1676 WriteSubStmt(StmtsToEmit[I], SubStmtEntries, ParentStmts); 1677 1678 assert(N == StmtsToEmit.size() && 1679 "Substatement written via AddStmt rather than WriteSubStmt!"); 1680 1681 // Note that we are at the end of a full expression. Any 1682 // expression records that follow this one are part of a different 1683 // expression. 1684 Stream.EmitRecord(serialization::STMT_STOP, Record); 1685 1686 SubStmtEntries.clear(); 1687 ParentStmts.clear(); 1688 } 1689 1690 StmtsToEmit.clear(); 1691 } 1692