1 //===--- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------*- C++ -*-===// 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 // Statement/expression deserialization. This implements the 11 // ASTReader::ReadStmt method. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "clang/Serialization/ASTReader.h" 16 #include "clang/AST/DeclCXX.h" 17 #include "clang/AST/DeclTemplate.h" 18 #include "clang/AST/StmtVisitor.h" 19 using namespace clang; 20 using namespace clang::serialization; 21 22 namespace clang { 23 24 class ASTStmtReader : public StmtVisitor<ASTStmtReader> { 25 typedef ASTReader::RecordData RecordData; 26 27 ASTReader &Reader; 28 Module &F; 29 llvm::BitstreamCursor &DeclsCursor; 30 const ASTReader::RecordData &Record; 31 unsigned &Idx; 32 33 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) { 34 return Reader.ReadSourceLocation(F, R, I); 35 } 36 37 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) { 38 return Reader.ReadSourceRange(F, R, I); 39 } 40 41 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) { 42 return Reader.GetTypeSourceInfo(F, R, I); 43 } 44 45 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) { 46 return Reader.ReadDeclID(F, R, I); 47 } 48 49 Decl *ReadDecl(const RecordData &R, unsigned &I) { 50 return Reader.ReadDecl(F, R, I); 51 } 52 53 template<typename T> 54 T *ReadDeclAs(const RecordData &R, unsigned &I) { 55 return Reader.ReadDeclAs<T>(F, R, I); 56 } 57 58 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name, 59 const ASTReader::RecordData &R, unsigned &I) { 60 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I); 61 } 62 63 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo, 64 const ASTReader::RecordData &R, unsigned &I) { 65 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I); 66 } 67 68 public: 69 ASTStmtReader(ASTReader &Reader, Module &F, 70 llvm::BitstreamCursor &Cursor, 71 const ASTReader::RecordData &Record, unsigned &Idx) 72 : Reader(Reader), F(F), DeclsCursor(Cursor), Record(Record), Idx(Idx) { } 73 74 /// \brief The number of record fields required for the Stmt class 75 /// itself. 76 static const unsigned NumStmtFields = 0; 77 78 /// \brief The number of record fields required for the Expr class 79 /// itself. 80 static const unsigned NumExprFields = NumStmtFields + 7; 81 82 /// \brief Read and initialize a ExplicitTemplateArgumentList structure. 83 void ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &ArgList, 84 unsigned NumTemplateArgs); 85 86 void VisitStmt(Stmt *S); 87 #define STMT(Type, Base) \ 88 void Visit##Type(Type *); 89 #include "clang/AST/StmtNodes.inc" 90 }; 91 } 92 93 void ASTStmtReader:: 94 ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &ArgList, 95 unsigned NumTemplateArgs) { 96 TemplateArgumentListInfo ArgInfo; 97 ArgInfo.setLAngleLoc(ReadSourceLocation(Record, Idx)); 98 ArgInfo.setRAngleLoc(ReadSourceLocation(Record, Idx)); 99 for (unsigned i = 0; i != NumTemplateArgs; ++i) 100 ArgInfo.addArgument( 101 Reader.ReadTemplateArgumentLoc(F, Record, Idx)); 102 ArgList.initializeFrom(ArgInfo); 103 } 104 105 void ASTStmtReader::VisitStmt(Stmt *S) { 106 assert(Idx == NumStmtFields && "Incorrect statement field count"); 107 } 108 109 void ASTStmtReader::VisitNullStmt(NullStmt *S) { 110 VisitStmt(S); 111 S->setSemiLoc(ReadSourceLocation(Record, Idx)); 112 S->HasLeadingEmptyMacro = Record[Idx++]; 113 } 114 115 void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) { 116 VisitStmt(S); 117 SmallVector<Stmt *, 16> Stmts; 118 unsigned NumStmts = Record[Idx++]; 119 while (NumStmts--) 120 Stmts.push_back(Reader.ReadSubStmt()); 121 S->setStmts(Reader.getContext(), Stmts.data(), Stmts.size()); 122 S->setLBracLoc(ReadSourceLocation(Record, Idx)); 123 S->setRBracLoc(ReadSourceLocation(Record, Idx)); 124 } 125 126 void ASTStmtReader::VisitSwitchCase(SwitchCase *S) { 127 VisitStmt(S); 128 Reader.RecordSwitchCaseID(S, Record[Idx++]); 129 } 130 131 void ASTStmtReader::VisitCaseStmt(CaseStmt *S) { 132 VisitSwitchCase(S); 133 S->setLHS(Reader.ReadSubExpr()); 134 S->setRHS(Reader.ReadSubExpr()); 135 S->setSubStmt(Reader.ReadSubStmt()); 136 S->setCaseLoc(ReadSourceLocation(Record, Idx)); 137 S->setEllipsisLoc(ReadSourceLocation(Record, Idx)); 138 S->setColonLoc(ReadSourceLocation(Record, Idx)); 139 } 140 141 void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) { 142 VisitSwitchCase(S); 143 S->setSubStmt(Reader.ReadSubStmt()); 144 S->setDefaultLoc(ReadSourceLocation(Record, Idx)); 145 S->setColonLoc(ReadSourceLocation(Record, Idx)); 146 } 147 148 void ASTStmtReader::VisitLabelStmt(LabelStmt *S) { 149 VisitStmt(S); 150 LabelDecl *LD = ReadDeclAs<LabelDecl>(Record, Idx); 151 LD->setStmt(S); 152 S->setDecl(LD); 153 S->setSubStmt(Reader.ReadSubStmt()); 154 S->setIdentLoc(ReadSourceLocation(Record, Idx)); 155 } 156 157 void ASTStmtReader::VisitIfStmt(IfStmt *S) { 158 VisitStmt(S); 159 S->setConditionVariable(Reader.getContext(), 160 ReadDeclAs<VarDecl>(Record, Idx)); 161 S->setCond(Reader.ReadSubExpr()); 162 S->setThen(Reader.ReadSubStmt()); 163 S->setElse(Reader.ReadSubStmt()); 164 S->setIfLoc(ReadSourceLocation(Record, Idx)); 165 S->setElseLoc(ReadSourceLocation(Record, Idx)); 166 } 167 168 void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) { 169 VisitStmt(S); 170 S->setConditionVariable(Reader.getContext(), 171 ReadDeclAs<VarDecl>(Record, Idx)); 172 S->setCond(Reader.ReadSubExpr()); 173 S->setBody(Reader.ReadSubStmt()); 174 S->setSwitchLoc(ReadSourceLocation(Record, Idx)); 175 if (Record[Idx++]) 176 S->setAllEnumCasesCovered(); 177 178 SwitchCase *PrevSC = 0; 179 for (unsigned N = Record.size(); Idx != N; ++Idx) { 180 SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]); 181 if (PrevSC) 182 PrevSC->setNextSwitchCase(SC); 183 else 184 S->setSwitchCaseList(SC); 185 186 PrevSC = SC; 187 } 188 } 189 190 void ASTStmtReader::VisitWhileStmt(WhileStmt *S) { 191 VisitStmt(S); 192 S->setConditionVariable(Reader.getContext(), 193 ReadDeclAs<VarDecl>(Record, Idx)); 194 195 S->setCond(Reader.ReadSubExpr()); 196 S->setBody(Reader.ReadSubStmt()); 197 S->setWhileLoc(ReadSourceLocation(Record, Idx)); 198 } 199 200 void ASTStmtReader::VisitDoStmt(DoStmt *S) { 201 VisitStmt(S); 202 S->setCond(Reader.ReadSubExpr()); 203 S->setBody(Reader.ReadSubStmt()); 204 S->setDoLoc(ReadSourceLocation(Record, Idx)); 205 S->setWhileLoc(ReadSourceLocation(Record, Idx)); 206 S->setRParenLoc(ReadSourceLocation(Record, Idx)); 207 } 208 209 void ASTStmtReader::VisitForStmt(ForStmt *S) { 210 VisitStmt(S); 211 S->setInit(Reader.ReadSubStmt()); 212 S->setCond(Reader.ReadSubExpr()); 213 S->setConditionVariable(Reader.getContext(), 214 ReadDeclAs<VarDecl>(Record, Idx)); 215 S->setInc(Reader.ReadSubExpr()); 216 S->setBody(Reader.ReadSubStmt()); 217 S->setForLoc(ReadSourceLocation(Record, Idx)); 218 S->setLParenLoc(ReadSourceLocation(Record, Idx)); 219 S->setRParenLoc(ReadSourceLocation(Record, Idx)); 220 } 221 222 void ASTStmtReader::VisitGotoStmt(GotoStmt *S) { 223 VisitStmt(S); 224 S->setLabel(ReadDeclAs<LabelDecl>(Record, Idx)); 225 S->setGotoLoc(ReadSourceLocation(Record, Idx)); 226 S->setLabelLoc(ReadSourceLocation(Record, Idx)); 227 } 228 229 void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) { 230 VisitStmt(S); 231 S->setGotoLoc(ReadSourceLocation(Record, Idx)); 232 S->setStarLoc(ReadSourceLocation(Record, Idx)); 233 S->setTarget(Reader.ReadSubExpr()); 234 } 235 236 void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) { 237 VisitStmt(S); 238 S->setContinueLoc(ReadSourceLocation(Record, Idx)); 239 } 240 241 void ASTStmtReader::VisitBreakStmt(BreakStmt *S) { 242 VisitStmt(S); 243 S->setBreakLoc(ReadSourceLocation(Record, Idx)); 244 } 245 246 void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) { 247 VisitStmt(S); 248 S->setRetValue(Reader.ReadSubExpr()); 249 S->setReturnLoc(ReadSourceLocation(Record, Idx)); 250 S->setNRVOCandidate(ReadDeclAs<VarDecl>(Record, Idx)); 251 } 252 253 void ASTStmtReader::VisitDeclStmt(DeclStmt *S) { 254 VisitStmt(S); 255 S->setStartLoc(ReadSourceLocation(Record, Idx)); 256 S->setEndLoc(ReadSourceLocation(Record, Idx)); 257 258 if (Idx + 1 == Record.size()) { 259 // Single declaration 260 S->setDeclGroup(DeclGroupRef(ReadDecl(Record, Idx))); 261 } else { 262 SmallVector<Decl *, 16> Decls; 263 Decls.reserve(Record.size() - Idx); 264 for (unsigned N = Record.size(); Idx != N; ) 265 Decls.push_back(ReadDecl(Record, Idx)); 266 S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(), 267 Decls.data(), 268 Decls.size()))); 269 } 270 } 271 272 void ASTStmtReader::VisitAsmStmt(AsmStmt *S) { 273 VisitStmt(S); 274 unsigned NumOutputs = Record[Idx++]; 275 unsigned NumInputs = Record[Idx++]; 276 unsigned NumClobbers = Record[Idx++]; 277 S->setAsmLoc(ReadSourceLocation(Record, Idx)); 278 S->setRParenLoc(ReadSourceLocation(Record, Idx)); 279 S->setVolatile(Record[Idx++]); 280 S->setSimple(Record[Idx++]); 281 S->setMSAsm(Record[Idx++]); 282 283 S->setAsmString(cast_or_null<StringLiteral>(Reader.ReadSubStmt())); 284 285 // Outputs and inputs 286 SmallVector<IdentifierInfo *, 16> Names; 287 SmallVector<StringLiteral*, 16> Constraints; 288 SmallVector<Stmt*, 16> Exprs; 289 for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) { 290 Names.push_back(Reader.GetIdentifierInfo(F, Record, Idx)); 291 Constraints.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt())); 292 Exprs.push_back(Reader.ReadSubStmt()); 293 } 294 295 // Constraints 296 SmallVector<StringLiteral*, 16> Clobbers; 297 for (unsigned I = 0; I != NumClobbers; ++I) 298 Clobbers.push_back(cast_or_null<StringLiteral>(Reader.ReadSubStmt())); 299 300 S->setOutputsAndInputsAndClobbers(Reader.getContext(), 301 Names.data(), Constraints.data(), 302 Exprs.data(), NumOutputs, NumInputs, 303 Clobbers.data(), NumClobbers); 304 } 305 306 void ASTStmtReader::VisitExpr(Expr *E) { 307 VisitStmt(E); 308 E->setType(Reader.readType(F, Record, Idx)); 309 E->setTypeDependent(Record[Idx++]); 310 E->setValueDependent(Record[Idx++]); 311 E->setInstantiationDependent(Record[Idx++]); 312 E->ExprBits.ContainsUnexpandedParameterPack = Record[Idx++]; 313 E->setValueKind(static_cast<ExprValueKind>(Record[Idx++])); 314 E->setObjectKind(static_cast<ExprObjectKind>(Record[Idx++])); 315 assert(Idx == NumExprFields && "Incorrect expression field count"); 316 } 317 318 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) { 319 VisitExpr(E); 320 E->setLocation(ReadSourceLocation(Record, Idx)); 321 E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]); 322 } 323 324 void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) { 325 VisitExpr(E); 326 327 E->DeclRefExprBits.HasQualifier = Record[Idx++]; 328 E->DeclRefExprBits.HasFoundDecl = Record[Idx++]; 329 E->DeclRefExprBits.HasExplicitTemplateArgs = Record[Idx++]; 330 E->DeclRefExprBits.HadMultipleCandidates = Record[Idx++]; 331 unsigned NumTemplateArgs = 0; 332 if (E->hasExplicitTemplateArgs()) 333 NumTemplateArgs = Record[Idx++]; 334 335 if (E->hasQualifier()) 336 E->getInternalQualifierLoc() 337 = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 338 339 if (E->hasFoundDecl()) 340 E->getInternalFoundDecl() = ReadDeclAs<NamedDecl>(Record, Idx); 341 342 if (E->hasExplicitTemplateArgs()) 343 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(), 344 NumTemplateArgs); 345 346 E->setDecl(ReadDeclAs<ValueDecl>(Record, Idx)); 347 E->setLocation(ReadSourceLocation(Record, Idx)); 348 ReadDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record, Idx); 349 } 350 351 void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) { 352 VisitExpr(E); 353 E->setLocation(ReadSourceLocation(Record, Idx)); 354 E->setValue(Reader.getContext(), Reader.ReadAPInt(Record, Idx)); 355 } 356 357 void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) { 358 VisitExpr(E); 359 E->setValue(Reader.getContext(), Reader.ReadAPFloat(Record, Idx)); 360 E->setExact(Record[Idx++]); 361 E->setLocation(ReadSourceLocation(Record, Idx)); 362 } 363 364 void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) { 365 VisitExpr(E); 366 E->setSubExpr(Reader.ReadSubExpr()); 367 } 368 369 void ASTStmtReader::VisitStringLiteral(StringLiteral *E) { 370 VisitExpr(E); 371 unsigned Len = Record[Idx++]; 372 assert(Record[Idx] == E->getNumConcatenated() && 373 "Wrong number of concatenated tokens!"); 374 ++Idx; 375 E->Kind = static_cast<StringLiteral::StringKind>(Record[Idx++]); 376 E->IsPascal = Record[Idx++]; 377 378 // Read string data 379 llvm::SmallString<16> Str(&Record[Idx], &Record[Idx] + Len); 380 E->setString(Reader.getContext(), Str.str()); 381 Idx += Len; 382 383 // Read source locations 384 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) 385 E->setStrTokenLoc(I, ReadSourceLocation(Record, Idx)); 386 } 387 388 void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) { 389 VisitExpr(E); 390 E->setValue(Record[Idx++]); 391 E->setLocation(ReadSourceLocation(Record, Idx)); 392 E->setKind(static_cast<CharacterLiteral::CharacterKind>(Record[Idx++])); 393 } 394 395 void ASTStmtReader::VisitParenExpr(ParenExpr *E) { 396 VisitExpr(E); 397 E->setLParen(ReadSourceLocation(Record, Idx)); 398 E->setRParen(ReadSourceLocation(Record, Idx)); 399 E->setSubExpr(Reader.ReadSubExpr()); 400 } 401 402 void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) { 403 VisitExpr(E); 404 unsigned NumExprs = Record[Idx++]; 405 E->Exprs = new (Reader.getContext()) Stmt*[NumExprs]; 406 for (unsigned i = 0; i != NumExprs; ++i) 407 E->Exprs[i] = Reader.ReadSubStmt(); 408 E->NumExprs = NumExprs; 409 E->LParenLoc = ReadSourceLocation(Record, Idx); 410 E->RParenLoc = ReadSourceLocation(Record, Idx); 411 } 412 413 void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) { 414 VisitExpr(E); 415 E->setSubExpr(Reader.ReadSubExpr()); 416 E->setOpcode((UnaryOperator::Opcode)Record[Idx++]); 417 E->setOperatorLoc(ReadSourceLocation(Record, Idx)); 418 } 419 420 void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { 421 typedef OffsetOfExpr::OffsetOfNode Node; 422 VisitExpr(E); 423 assert(E->getNumComponents() == Record[Idx]); 424 ++Idx; 425 assert(E->getNumExpressions() == Record[Idx]); 426 ++Idx; 427 E->setOperatorLoc(ReadSourceLocation(Record, Idx)); 428 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 429 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); 430 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 431 Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]); 432 SourceLocation Start = ReadSourceLocation(Record, Idx); 433 SourceLocation End = ReadSourceLocation(Record, Idx); 434 switch (Kind) { 435 case Node::Array: 436 E->setComponent(I, Node(Start, Record[Idx++], End)); 437 break; 438 439 case Node::Field: 440 E->setComponent(I, Node(Start, ReadDeclAs<FieldDecl>(Record, Idx), End)); 441 break; 442 443 case Node::Identifier: 444 E->setComponent(I, 445 Node(Start, 446 Reader.GetIdentifierInfo(F, Record, Idx), 447 End)); 448 break; 449 450 case Node::Base: { 451 CXXBaseSpecifier *Base = new (Reader.getContext()) CXXBaseSpecifier(); 452 *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx); 453 E->setComponent(I, Node(Base)); 454 break; 455 } 456 } 457 } 458 459 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I) 460 E->setIndexExpr(I, Reader.ReadSubExpr()); 461 } 462 463 void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { 464 VisitExpr(E); 465 E->setKind(static_cast<UnaryExprOrTypeTrait>(Record[Idx++])); 466 if (Record[Idx] == 0) { 467 E->setArgument(Reader.ReadSubExpr()); 468 ++Idx; 469 } else { 470 E->setArgument(GetTypeSourceInfo(Record, Idx)); 471 } 472 E->setOperatorLoc(ReadSourceLocation(Record, Idx)); 473 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 474 } 475 476 void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { 477 VisitExpr(E); 478 E->setLHS(Reader.ReadSubExpr()); 479 E->setRHS(Reader.ReadSubExpr()); 480 E->setRBracketLoc(ReadSourceLocation(Record, Idx)); 481 } 482 483 void ASTStmtReader::VisitCallExpr(CallExpr *E) { 484 VisitExpr(E); 485 E->setNumArgs(Reader.getContext(), Record[Idx++]); 486 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 487 E->setCallee(Reader.ReadSubExpr()); 488 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 489 E->setArg(I, Reader.ReadSubExpr()); 490 } 491 492 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { 493 VisitCallExpr(E); 494 } 495 496 void ASTStmtReader::VisitMemberExpr(MemberExpr *E) { 497 // Don't call VisitExpr, this is fully initialized at creation. 498 assert(E->getStmtClass() == Stmt::MemberExprClass && 499 "It's a subclass, we must advance Idx!"); 500 } 501 502 void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) { 503 VisitExpr(E); 504 E->setBase(Reader.ReadSubExpr()); 505 E->setIsaMemberLoc(ReadSourceLocation(Record, Idx)); 506 E->setArrow(Record[Idx++]); 507 } 508 509 void ASTStmtReader:: 510 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 511 VisitExpr(E); 512 E->Operand = Reader.ReadSubExpr(); 513 E->setShouldCopy(Record[Idx++]); 514 } 515 516 void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 517 VisitExplicitCastExpr(E); 518 E->LParenLoc = ReadSourceLocation(Record, Idx); 519 E->BridgeKeywordLoc = ReadSourceLocation(Record, Idx); 520 E->Kind = Record[Idx++]; 521 } 522 523 void ASTStmtReader::VisitCastExpr(CastExpr *E) { 524 VisitExpr(E); 525 unsigned NumBaseSpecs = Record[Idx++]; 526 assert(NumBaseSpecs == E->path_size()); 527 E->setSubExpr(Reader.ReadSubExpr()); 528 E->setCastKind((CastExpr::CastKind)Record[Idx++]); 529 CastExpr::path_iterator BaseI = E->path_begin(); 530 while (NumBaseSpecs--) { 531 CXXBaseSpecifier *BaseSpec = new (Reader.getContext()) CXXBaseSpecifier; 532 *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx); 533 *BaseI++ = BaseSpec; 534 } 535 } 536 537 void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) { 538 VisitExpr(E); 539 E->setLHS(Reader.ReadSubExpr()); 540 E->setRHS(Reader.ReadSubExpr()); 541 E->setOpcode((BinaryOperator::Opcode)Record[Idx++]); 542 E->setOperatorLoc(ReadSourceLocation(Record, Idx)); 543 } 544 545 void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) { 546 VisitBinaryOperator(E); 547 E->setComputationLHSType(Reader.readType(F, Record, Idx)); 548 E->setComputationResultType(Reader.readType(F, Record, Idx)); 549 } 550 551 void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) { 552 VisitExpr(E); 553 E->SubExprs[ConditionalOperator::COND] = Reader.ReadSubExpr(); 554 E->SubExprs[ConditionalOperator::LHS] = Reader.ReadSubExpr(); 555 E->SubExprs[ConditionalOperator::RHS] = Reader.ReadSubExpr(); 556 E->QuestionLoc = ReadSourceLocation(Record, Idx); 557 E->ColonLoc = ReadSourceLocation(Record, Idx); 558 } 559 560 void 561 ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { 562 VisitExpr(E); 563 E->OpaqueValue = cast<OpaqueValueExpr>(Reader.ReadSubExpr()); 564 E->SubExprs[BinaryConditionalOperator::COMMON] = Reader.ReadSubExpr(); 565 E->SubExprs[BinaryConditionalOperator::COND] = Reader.ReadSubExpr(); 566 E->SubExprs[BinaryConditionalOperator::LHS] = Reader.ReadSubExpr(); 567 E->SubExprs[BinaryConditionalOperator::RHS] = Reader.ReadSubExpr(); 568 E->QuestionLoc = ReadSourceLocation(Record, Idx); 569 E->ColonLoc = ReadSourceLocation(Record, Idx); 570 571 E->getOpaqueValue()->setSourceExpr(E->getCommon()); 572 } 573 574 void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) { 575 VisitCastExpr(E); 576 } 577 578 void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) { 579 VisitCastExpr(E); 580 E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx)); 581 } 582 583 void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) { 584 VisitExplicitCastExpr(E); 585 E->setLParenLoc(ReadSourceLocation(Record, Idx)); 586 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 587 } 588 589 void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { 590 VisitExpr(E); 591 E->setLParenLoc(ReadSourceLocation(Record, Idx)); 592 E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); 593 E->setInitializer(Reader.ReadSubExpr()); 594 E->setFileScope(Record[Idx++]); 595 } 596 597 void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { 598 VisitExpr(E); 599 E->setBase(Reader.ReadSubExpr()); 600 E->setAccessor(Reader.GetIdentifierInfo(F, Record, Idx)); 601 E->setAccessorLoc(ReadSourceLocation(Record, Idx)); 602 } 603 604 void ASTStmtReader::VisitInitListExpr(InitListExpr *E) { 605 VisitExpr(E); 606 E->setSyntacticForm(cast_or_null<InitListExpr>(Reader.ReadSubStmt())); 607 E->setLBraceLoc(ReadSourceLocation(Record, Idx)); 608 E->setRBraceLoc(ReadSourceLocation(Record, Idx)); 609 bool isArrayFiller = Record[Idx++]; 610 Expr *filler = 0; 611 if (isArrayFiller) { 612 filler = Reader.ReadSubExpr(); 613 E->ArrayFillerOrUnionFieldInit = filler; 614 } else 615 E->ArrayFillerOrUnionFieldInit = ReadDeclAs<FieldDecl>(Record, Idx); 616 E->sawArrayRangeDesignator(Record[Idx++]); 617 unsigned NumInits = Record[Idx++]; 618 E->reserveInits(Reader.getContext(), NumInits); 619 if (isArrayFiller) { 620 for (unsigned I = 0; I != NumInits; ++I) { 621 Expr *init = Reader.ReadSubExpr(); 622 E->updateInit(Reader.getContext(), I, init ? init : filler); 623 } 624 } else { 625 for (unsigned I = 0; I != NumInits; ++I) 626 E->updateInit(Reader.getContext(), I, Reader.ReadSubExpr()); 627 } 628 } 629 630 void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { 631 typedef DesignatedInitExpr::Designator Designator; 632 633 VisitExpr(E); 634 unsigned NumSubExprs = Record[Idx++]; 635 assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs"); 636 for (unsigned I = 0; I != NumSubExprs; ++I) 637 E->setSubExpr(I, Reader.ReadSubExpr()); 638 E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx)); 639 E->setGNUSyntax(Record[Idx++]); 640 641 SmallVector<Designator, 4> Designators; 642 while (Idx < Record.size()) { 643 switch ((DesignatorTypes)Record[Idx++]) { 644 case DESIG_FIELD_DECL: { 645 FieldDecl *Field = ReadDeclAs<FieldDecl>(Record, Idx); 646 SourceLocation DotLoc 647 = ReadSourceLocation(Record, Idx); 648 SourceLocation FieldLoc 649 = ReadSourceLocation(Record, Idx); 650 Designators.push_back(Designator(Field->getIdentifier(), DotLoc, 651 FieldLoc)); 652 Designators.back().setField(Field); 653 break; 654 } 655 656 case DESIG_FIELD_NAME: { 657 const IdentifierInfo *Name = Reader.GetIdentifierInfo(F, Record, Idx); 658 SourceLocation DotLoc 659 = ReadSourceLocation(Record, Idx); 660 SourceLocation FieldLoc 661 = ReadSourceLocation(Record, Idx); 662 Designators.push_back(Designator(Name, DotLoc, FieldLoc)); 663 break; 664 } 665 666 case DESIG_ARRAY: { 667 unsigned Index = Record[Idx++]; 668 SourceLocation LBracketLoc 669 = ReadSourceLocation(Record, Idx); 670 SourceLocation RBracketLoc 671 = ReadSourceLocation(Record, Idx); 672 Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc)); 673 break; 674 } 675 676 case DESIG_ARRAY_RANGE: { 677 unsigned Index = Record[Idx++]; 678 SourceLocation LBracketLoc 679 = ReadSourceLocation(Record, Idx); 680 SourceLocation EllipsisLoc 681 = ReadSourceLocation(Record, Idx); 682 SourceLocation RBracketLoc 683 = ReadSourceLocation(Record, Idx); 684 Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc, 685 RBracketLoc)); 686 break; 687 } 688 } 689 } 690 E->setDesignators(Reader.getContext(), 691 Designators.data(), Designators.size()); 692 } 693 694 void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { 695 VisitExpr(E); 696 } 697 698 void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) { 699 VisitExpr(E); 700 E->setSubExpr(Reader.ReadSubExpr()); 701 E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx)); 702 E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); 703 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 704 } 705 706 void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) { 707 VisitExpr(E); 708 E->setAmpAmpLoc(ReadSourceLocation(Record, Idx)); 709 E->setLabelLoc(ReadSourceLocation(Record, Idx)); 710 E->setLabel(ReadDeclAs<LabelDecl>(Record, Idx)); 711 } 712 713 void ASTStmtReader::VisitStmtExpr(StmtExpr *E) { 714 VisitExpr(E); 715 E->setLParenLoc(ReadSourceLocation(Record, Idx)); 716 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 717 E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadSubStmt())); 718 } 719 720 void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) { 721 VisitExpr(E); 722 E->setCond(Reader.ReadSubExpr()); 723 E->setLHS(Reader.ReadSubExpr()); 724 E->setRHS(Reader.ReadSubExpr()); 725 E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); 726 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 727 } 728 729 void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) { 730 VisitExpr(E); 731 E->setTokenLocation(ReadSourceLocation(Record, Idx)); 732 } 733 734 void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { 735 VisitExpr(E); 736 SmallVector<Expr *, 16> Exprs; 737 unsigned NumExprs = Record[Idx++]; 738 while (NumExprs--) 739 Exprs.push_back(Reader.ReadSubExpr()); 740 E->setExprs(Reader.getContext(), Exprs.data(), Exprs.size()); 741 E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); 742 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 743 } 744 745 void ASTStmtReader::VisitBlockExpr(BlockExpr *E) { 746 VisitExpr(E); 747 E->setBlockDecl(ReadDeclAs<BlockDecl>(Record, Idx)); 748 } 749 750 void ASTStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { 751 VisitExpr(E); 752 E->setDecl(ReadDeclAs<VarDecl>(Record, Idx)); 753 E->setLocation(ReadSourceLocation(Record, Idx)); 754 E->setByRef(Record[Idx++]); 755 E->setConstQualAdded(Record[Idx++]); 756 } 757 758 void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) { 759 VisitExpr(E); 760 E->NumAssocs = Record[Idx++]; 761 E->AssocTypes = new (Reader.getContext()) TypeSourceInfo*[E->NumAssocs]; 762 E->SubExprs = 763 new(Reader.getContext()) Stmt*[GenericSelectionExpr::END_EXPR+E->NumAssocs]; 764 765 E->SubExprs[GenericSelectionExpr::CONTROLLING] = Reader.ReadSubExpr(); 766 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) { 767 E->AssocTypes[I] = GetTypeSourceInfo(Record, Idx); 768 E->SubExprs[GenericSelectionExpr::END_EXPR+I] = Reader.ReadSubExpr(); 769 } 770 E->ResultIndex = Record[Idx++]; 771 772 E->GenericLoc = ReadSourceLocation(Record, Idx); 773 E->DefaultLoc = ReadSourceLocation(Record, Idx); 774 E->RParenLoc = ReadSourceLocation(Record, Idx); 775 } 776 777 void ASTStmtReader::VisitAtomicExpr(AtomicExpr *E) { 778 VisitExpr(E); 779 E->setOp(AtomicExpr::AtomicOp(Record[Idx++])); 780 E->setPtr(Reader.ReadSubExpr()); 781 E->setOrder(Reader.ReadSubExpr()); 782 E->setNumSubExprs(2); 783 if (E->getOp() != AtomicExpr::Load) { 784 E->setVal1(Reader.ReadSubExpr()); 785 E->setNumSubExprs(3); 786 } 787 if (E->isCmpXChg()) { 788 E->setOrderFail(Reader.ReadSubExpr()); 789 E->setVal2(Reader.ReadSubExpr()); 790 E->setNumSubExprs(5); 791 } 792 E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); 793 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 794 } 795 796 //===----------------------------------------------------------------------===// 797 // Objective-C Expressions and Statements 798 799 void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) { 800 VisitExpr(E); 801 E->setString(cast<StringLiteral>(Reader.ReadSubStmt())); 802 E->setAtLoc(ReadSourceLocation(Record, Idx)); 803 } 804 805 void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { 806 VisitExpr(E); 807 E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); 808 E->setAtLoc(ReadSourceLocation(Record, Idx)); 809 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 810 } 811 812 void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { 813 VisitExpr(E); 814 E->setSelector(Reader.ReadSelector(F, Record, Idx)); 815 E->setAtLoc(ReadSourceLocation(Record, Idx)); 816 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 817 } 818 819 void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { 820 VisitExpr(E); 821 E->setProtocol(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 822 E->setAtLoc(ReadSourceLocation(Record, Idx)); 823 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 824 } 825 826 void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { 827 VisitExpr(E); 828 E->setDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx)); 829 E->setLocation(ReadSourceLocation(Record, Idx)); 830 E->setBase(Reader.ReadSubExpr()); 831 E->setIsArrow(Record[Idx++]); 832 E->setIsFreeIvar(Record[Idx++]); 833 } 834 835 void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 836 VisitExpr(E); 837 bool Implicit = Record[Idx++] != 0; 838 if (Implicit) { 839 ObjCMethodDecl *Getter = ReadDeclAs<ObjCMethodDecl>(Record, Idx); 840 ObjCMethodDecl *Setter = ReadDeclAs<ObjCMethodDecl>(Record, Idx); 841 E->setImplicitProperty(Getter, Setter); 842 } else { 843 E->setExplicitProperty(ReadDeclAs<ObjCPropertyDecl>(Record, Idx)); 844 } 845 E->setLocation(ReadSourceLocation(Record, Idx)); 846 E->setReceiverLocation(ReadSourceLocation(Record, Idx)); 847 switch (Record[Idx++]) { 848 case 0: 849 E->setBase(Reader.ReadSubExpr()); 850 break; 851 case 1: 852 E->setSuperReceiver(Reader.readType(F, Record, Idx)); 853 break; 854 case 2: 855 E->setClassReceiver(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx)); 856 break; 857 } 858 } 859 860 void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { 861 VisitExpr(E); 862 assert(Record[Idx] == E->getNumArgs()); 863 ++Idx; 864 unsigned NumStoredSelLocs = Record[Idx++]; 865 E->SelLocsKind = Record[Idx++]; 866 E->setDelegateInitCall(Record[Idx++]); 867 ObjCMessageExpr::ReceiverKind Kind 868 = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]); 869 switch (Kind) { 870 case ObjCMessageExpr::Instance: 871 E->setInstanceReceiver(Reader.ReadSubExpr()); 872 break; 873 874 case ObjCMessageExpr::Class: 875 E->setClassReceiver(GetTypeSourceInfo(Record, Idx)); 876 break; 877 878 case ObjCMessageExpr::SuperClass: 879 case ObjCMessageExpr::SuperInstance: { 880 QualType T = Reader.readType(F, Record, Idx); 881 SourceLocation SuperLoc = ReadSourceLocation(Record, Idx); 882 E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance); 883 break; 884 } 885 } 886 887 assert(Kind == E->getReceiverKind()); 888 889 if (Record[Idx++]) 890 E->setMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx)); 891 else 892 E->setSelector(Reader.ReadSelector(F, Record, Idx)); 893 894 E->LBracLoc = ReadSourceLocation(Record, Idx); 895 E->RBracLoc = ReadSourceLocation(Record, Idx); 896 897 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 898 E->setArg(I, Reader.ReadSubExpr()); 899 900 SourceLocation *Locs = E->getStoredSelLocs(); 901 for (unsigned I = 0; I != NumStoredSelLocs; ++I) 902 Locs[I] = ReadSourceLocation(Record, Idx); 903 } 904 905 void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { 906 VisitStmt(S); 907 S->setElement(Reader.ReadSubStmt()); 908 S->setCollection(Reader.ReadSubExpr()); 909 S->setBody(Reader.ReadSubStmt()); 910 S->setForLoc(ReadSourceLocation(Record, Idx)); 911 S->setRParenLoc(ReadSourceLocation(Record, Idx)); 912 } 913 914 void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { 915 VisitStmt(S); 916 S->setCatchBody(Reader.ReadSubStmt()); 917 S->setCatchParamDecl(ReadDeclAs<VarDecl>(Record, Idx)); 918 S->setAtCatchLoc(ReadSourceLocation(Record, Idx)); 919 S->setRParenLoc(ReadSourceLocation(Record, Idx)); 920 } 921 922 void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 923 VisitStmt(S); 924 S->setFinallyBody(Reader.ReadSubStmt()); 925 S->setAtFinallyLoc(ReadSourceLocation(Record, Idx)); 926 } 927 928 void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) { 929 VisitStmt(S); 930 S->setSubStmt(Reader.ReadSubStmt()); 931 S->setAtLoc(ReadSourceLocation(Record, Idx)); 932 } 933 934 void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { 935 VisitStmt(S); 936 assert(Record[Idx] == S->getNumCatchStmts()); 937 ++Idx; 938 bool HasFinally = Record[Idx++]; 939 S->setTryBody(Reader.ReadSubStmt()); 940 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) 941 S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadSubStmt())); 942 943 if (HasFinally) 944 S->setFinallyStmt(Reader.ReadSubStmt()); 945 S->setAtTryLoc(ReadSourceLocation(Record, Idx)); 946 } 947 948 void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { 949 VisitStmt(S); 950 S->setSynchExpr(Reader.ReadSubStmt()); 951 S->setSynchBody(Reader.ReadSubStmt()); 952 S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx)); 953 } 954 955 void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { 956 VisitStmt(S); 957 S->setThrowExpr(Reader.ReadSubStmt()); 958 S->setThrowLoc(ReadSourceLocation(Record, Idx)); 959 } 960 961 //===----------------------------------------------------------------------===// 962 // C++ Expressions and Statements 963 //===----------------------------------------------------------------------===// 964 965 void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) { 966 VisitStmt(S); 967 S->CatchLoc = ReadSourceLocation(Record, Idx); 968 S->ExceptionDecl = ReadDeclAs<VarDecl>(Record, Idx); 969 S->HandlerBlock = Reader.ReadSubStmt(); 970 } 971 972 void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) { 973 VisitStmt(S); 974 assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?"); 975 ++Idx; 976 S->TryLoc = ReadSourceLocation(Record, Idx); 977 S->getStmts()[0] = Reader.ReadSubStmt(); 978 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i) 979 S->getStmts()[i + 1] = Reader.ReadSubStmt(); 980 } 981 982 void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) { 983 VisitStmt(S); 984 S->setForLoc(ReadSourceLocation(Record, Idx)); 985 S->setColonLoc(ReadSourceLocation(Record, Idx)); 986 S->setRParenLoc(ReadSourceLocation(Record, Idx)); 987 S->setRangeStmt(Reader.ReadSubStmt()); 988 S->setBeginEndStmt(Reader.ReadSubStmt()); 989 S->setCond(Reader.ReadSubExpr()); 990 S->setInc(Reader.ReadSubExpr()); 991 S->setLoopVarStmt(Reader.ReadSubStmt()); 992 S->setBody(Reader.ReadSubStmt()); 993 } 994 995 void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 996 VisitCallExpr(E); 997 E->setOperator((OverloadedOperatorKind)Record[Idx++]); 998 } 999 1000 void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) { 1001 VisitExpr(E); 1002 E->NumArgs = Record[Idx++]; 1003 if (E->NumArgs) 1004 E->Args = new (Reader.getContext()) Stmt*[E->NumArgs]; 1005 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) 1006 E->setArg(I, Reader.ReadSubExpr()); 1007 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx)); 1008 E->setLocation(ReadSourceLocation(Record, Idx)); 1009 E->setElidable(Record[Idx++]); 1010 E->setHadMultipleCandidates(Record[Idx++]); 1011 E->setRequiresZeroInitialization(Record[Idx++]); 1012 E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]); 1013 E->ParenRange = ReadSourceRange(Record, Idx); 1014 } 1015 1016 void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { 1017 VisitCXXConstructExpr(E); 1018 E->Type = GetTypeSourceInfo(Record, Idx); 1019 } 1020 1021 void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { 1022 VisitExplicitCastExpr(E); 1023 SourceRange R = ReadSourceRange(Record, Idx); 1024 E->Loc = R.getBegin(); 1025 E->RParenLoc = R.getEnd(); 1026 } 1027 1028 void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) { 1029 return VisitCXXNamedCastExpr(E); 1030 } 1031 1032 void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 1033 return VisitCXXNamedCastExpr(E); 1034 } 1035 1036 void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) { 1037 return VisitCXXNamedCastExpr(E); 1038 } 1039 1040 void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) { 1041 return VisitCXXNamedCastExpr(E); 1042 } 1043 1044 void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { 1045 VisitExplicitCastExpr(E); 1046 E->setTypeBeginLoc(ReadSourceLocation(Record, Idx)); 1047 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 1048 } 1049 1050 void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 1051 VisitExpr(E); 1052 E->setValue(Record[Idx++]); 1053 E->setLocation(ReadSourceLocation(Record, Idx)); 1054 } 1055 1056 void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { 1057 VisitExpr(E); 1058 E->setLocation(ReadSourceLocation(Record, Idx)); 1059 } 1060 1061 void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) { 1062 VisitExpr(E); 1063 E->setSourceRange(ReadSourceRange(Record, Idx)); 1064 if (E->isTypeOperand()) { // typeid(int) 1065 E->setTypeOperandSourceInfo( 1066 GetTypeSourceInfo(Record, Idx)); 1067 return; 1068 } 1069 1070 // typeid(42+2) 1071 E->setExprOperand(Reader.ReadSubExpr()); 1072 } 1073 1074 void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) { 1075 VisitExpr(E); 1076 E->setLocation(ReadSourceLocation(Record, Idx)); 1077 E->setImplicit(Record[Idx++]); 1078 } 1079 1080 void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) { 1081 VisitExpr(E); 1082 E->ThrowLoc = ReadSourceLocation(Record, Idx); 1083 E->Op = Reader.ReadSubExpr(); 1084 E->IsThrownVariableInScope = Record[Idx++]; 1085 } 1086 1087 void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 1088 VisitExpr(E); 1089 1090 assert((bool)Record[Idx] == E->Param.getInt() && "We messed up at creation ?"); 1091 ++Idx; // HasOtherExprStored and SubExpr was handled during creation. 1092 E->Param.setPointer(ReadDeclAs<ParmVarDecl>(Record, Idx)); 1093 E->Loc = ReadSourceLocation(Record, Idx); 1094 } 1095 1096 void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 1097 VisitExpr(E); 1098 E->setTemporary(Reader.ReadCXXTemporary(F, Record, Idx)); 1099 E->setSubExpr(Reader.ReadSubExpr()); 1100 } 1101 1102 void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { 1103 VisitExpr(E); 1104 E->TypeInfo = GetTypeSourceInfo(Record, Idx); 1105 E->RParenLoc = ReadSourceLocation(Record, Idx); 1106 } 1107 1108 void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) { 1109 VisitExpr(E); 1110 E->GlobalNew = Record[Idx++]; 1111 E->Initializer = Record[Idx++]; 1112 E->UsualArrayDeleteWantsSize = Record[Idx++]; 1113 bool isArray = Record[Idx++]; 1114 E->setHadMultipleCandidates(Record[Idx++]); 1115 unsigned NumPlacementArgs = Record[Idx++]; 1116 unsigned NumCtorArgs = Record[Idx++]; 1117 E->setOperatorNew(ReadDeclAs<FunctionDecl>(Record, Idx)); 1118 E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx)); 1119 E->setConstructor(ReadDeclAs<CXXConstructorDecl>(Record, Idx)); 1120 E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx); 1121 SourceRange TypeIdParens; 1122 TypeIdParens.setBegin(ReadSourceLocation(Record, Idx)); 1123 TypeIdParens.setEnd(ReadSourceLocation(Record, Idx)); 1124 E->TypeIdParens = TypeIdParens; 1125 E->StartLoc = ReadSourceLocation(Record, Idx); 1126 E->EndLoc = ReadSourceLocation(Record, Idx); 1127 E->ConstructorLParen = ReadSourceLocation(Record, Idx); 1128 E->ConstructorRParen = ReadSourceLocation(Record, Idx); 1129 1130 E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs, 1131 NumCtorArgs); 1132 1133 // Install all the subexpressions. 1134 for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end(); 1135 I != e; ++I) 1136 *I = Reader.ReadSubStmt(); 1137 } 1138 1139 void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) { 1140 VisitExpr(E); 1141 E->GlobalDelete = Record[Idx++]; 1142 E->ArrayForm = Record[Idx++]; 1143 E->ArrayFormAsWritten = Record[Idx++]; 1144 E->UsualArrayDeleteWantsSize = Record[Idx++]; 1145 E->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx); 1146 E->Argument = Reader.ReadSubExpr(); 1147 E->Loc = ReadSourceLocation(Record, Idx); 1148 } 1149 1150 void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { 1151 VisitExpr(E); 1152 1153 E->Base = Reader.ReadSubExpr(); 1154 E->IsArrow = Record[Idx++]; 1155 E->OperatorLoc = ReadSourceLocation(Record, Idx); 1156 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1157 E->ScopeType = GetTypeSourceInfo(Record, Idx); 1158 E->ColonColonLoc = ReadSourceLocation(Record, Idx); 1159 E->TildeLoc = ReadSourceLocation(Record, Idx); 1160 1161 IdentifierInfo *II = Reader.GetIdentifierInfo(F, Record, Idx); 1162 if (II) 1163 E->setDestroyedType(II, ReadSourceLocation(Record, Idx)); 1164 else 1165 E->setDestroyedType(GetTypeSourceInfo(Record, Idx)); 1166 } 1167 1168 void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) { 1169 VisitExpr(E); 1170 unsigned NumTemps = Record[Idx++]; 1171 if (NumTemps) { 1172 E->setNumTemporaries(Reader.getContext(), NumTemps); 1173 for (unsigned i = 0; i != NumTemps; ++i) 1174 E->setTemporary(i, Reader.ReadCXXTemporary(F, Record, Idx)); 1175 } 1176 E->setSubExpr(Reader.ReadSubExpr()); 1177 } 1178 1179 void 1180 ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){ 1181 VisitExpr(E); 1182 1183 if (Record[Idx++]) 1184 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(), 1185 Record[Idx++]); 1186 1187 E->Base = Reader.ReadSubExpr(); 1188 E->BaseType = Reader.readType(F, Record, Idx); 1189 E->IsArrow = Record[Idx++]; 1190 E->OperatorLoc = ReadSourceLocation(Record, Idx); 1191 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1192 E->FirstQualifierFoundInScope = ReadDeclAs<NamedDecl>(Record, Idx); 1193 ReadDeclarationNameInfo(E->MemberNameInfo, Record, Idx); 1194 } 1195 1196 void 1197 ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { 1198 VisitExpr(E); 1199 1200 if (Record[Idx++]) 1201 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(), 1202 Record[Idx++]); 1203 1204 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1205 ReadDeclarationNameInfo(E->NameInfo, Record, Idx); 1206 } 1207 1208 void 1209 ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) { 1210 VisitExpr(E); 1211 assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?"); 1212 ++Idx; // NumArgs; 1213 for (unsigned I = 0, N = E->arg_size(); I != N; ++I) 1214 E->setArg(I, Reader.ReadSubExpr()); 1215 E->Type = GetTypeSourceInfo(Record, Idx); 1216 E->setLParenLoc(ReadSourceLocation(Record, Idx)); 1217 E->setRParenLoc(ReadSourceLocation(Record, Idx)); 1218 } 1219 1220 void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) { 1221 VisitExpr(E); 1222 1223 // Read the explicit template argument list, if available. 1224 if (Record[Idx++]) 1225 ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(), 1226 Record[Idx++]); 1227 1228 unsigned NumDecls = Record[Idx++]; 1229 UnresolvedSet<8> Decls; 1230 for (unsigned i = 0; i != NumDecls; ++i) { 1231 NamedDecl *D = ReadDeclAs<NamedDecl>(Record, Idx); 1232 AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; 1233 Decls.addDecl(D, AS); 1234 } 1235 E->initializeResults(Reader.getContext(), Decls.begin(), Decls.end()); 1236 1237 ReadDeclarationNameInfo(E->NameInfo, Record, Idx); 1238 E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1239 } 1240 1241 void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { 1242 VisitOverloadExpr(E); 1243 E->IsArrow = Record[Idx++]; 1244 E->HasUnresolvedUsing = Record[Idx++]; 1245 E->Base = Reader.ReadSubExpr(); 1246 E->BaseType = Reader.readType(F, Record, Idx); 1247 E->OperatorLoc = ReadSourceLocation(Record, Idx); 1248 } 1249 1250 void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { 1251 VisitOverloadExpr(E); 1252 E->RequiresADL = Record[Idx++]; 1253 if (E->RequiresADL) 1254 E->StdIsAssociatedNamespace = Record[Idx++]; 1255 E->Overloaded = Record[Idx++]; 1256 E->NamingClass = ReadDeclAs<CXXRecordDecl>(Record, Idx); 1257 } 1258 1259 void ASTStmtReader::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 1260 VisitExpr(E); 1261 E->UTT = (UnaryTypeTrait)Record[Idx++]; 1262 E->Value = (bool)Record[Idx++]; 1263 SourceRange Range = ReadSourceRange(Record, Idx); 1264 E->Loc = Range.getBegin(); 1265 E->RParen = Range.getEnd(); 1266 E->QueriedType = GetTypeSourceInfo(Record, Idx); 1267 } 1268 1269 void ASTStmtReader::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 1270 VisitExpr(E); 1271 E->BTT = (BinaryTypeTrait)Record[Idx++]; 1272 E->Value = (bool)Record[Idx++]; 1273 SourceRange Range = ReadSourceRange(Record, Idx); 1274 E->Loc = Range.getBegin(); 1275 E->RParen = Range.getEnd(); 1276 E->LhsType = GetTypeSourceInfo(Record, Idx); 1277 E->RhsType = GetTypeSourceInfo(Record, Idx); 1278 } 1279 1280 void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 1281 VisitExpr(E); 1282 E->ATT = (ArrayTypeTrait)Record[Idx++]; 1283 E->Value = (unsigned int)Record[Idx++]; 1284 SourceRange Range = ReadSourceRange(Record, Idx); 1285 E->Loc = Range.getBegin(); 1286 E->RParen = Range.getEnd(); 1287 E->QueriedType = GetTypeSourceInfo(Record, Idx); 1288 } 1289 1290 void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { 1291 VisitExpr(E); 1292 E->ET = (ExpressionTrait)Record[Idx++]; 1293 E->Value = (bool)Record[Idx++]; 1294 SourceRange Range = ReadSourceRange(Record, Idx); 1295 E->QueriedExpression = Reader.ReadSubExpr(); 1296 E->Loc = Range.getBegin(); 1297 E->RParen = Range.getEnd(); 1298 } 1299 1300 void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { 1301 VisitExpr(E); 1302 E->Value = (bool)Record[Idx++]; 1303 E->Range = ReadSourceRange(Record, Idx); 1304 E->Operand = Reader.ReadSubExpr(); 1305 } 1306 1307 void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) { 1308 VisitExpr(E); 1309 E->EllipsisLoc = ReadSourceLocation(Record, Idx); 1310 E->NumExpansions = Record[Idx++]; 1311 E->Pattern = Reader.ReadSubExpr(); 1312 } 1313 1314 void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) { 1315 VisitExpr(E); 1316 E->OperatorLoc = ReadSourceLocation(Record, Idx); 1317 E->PackLoc = ReadSourceLocation(Record, Idx); 1318 E->RParenLoc = ReadSourceLocation(Record, Idx); 1319 E->Length = Record[Idx++]; 1320 E->Pack = ReadDeclAs<NamedDecl>(Record, Idx); 1321 } 1322 1323 void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr( 1324 SubstNonTypeTemplateParmExpr *E) { 1325 VisitExpr(E); 1326 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx); 1327 E->NameLoc = ReadSourceLocation(Record, Idx); 1328 E->Replacement = Reader.ReadSubExpr(); 1329 } 1330 1331 void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr( 1332 SubstNonTypeTemplateParmPackExpr *E) { 1333 VisitExpr(E); 1334 E->Param = ReadDeclAs<NonTypeTemplateParmDecl>(Record, Idx); 1335 TemplateArgument ArgPack = Reader.ReadTemplateArgument(F, Record, Idx); 1336 if (ArgPack.getKind() != TemplateArgument::Pack) 1337 return; 1338 1339 E->Arguments = ArgPack.pack_begin(); 1340 E->NumArguments = ArgPack.pack_size(); 1341 E->NameLoc = ReadSourceLocation(Record, Idx); 1342 } 1343 1344 void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { 1345 VisitExpr(E); 1346 E->Temporary = Reader.ReadSubExpr(); 1347 } 1348 1349 void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) { 1350 VisitExpr(E); 1351 Idx++; // skip ID 1352 E->Loc = ReadSourceLocation(Record, Idx); 1353 } 1354 1355 //===----------------------------------------------------------------------===// 1356 // Microsoft Expressions and Statements 1357 //===----------------------------------------------------------------------===// 1358 void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) { 1359 VisitExpr(E); 1360 E->setSourceRange(ReadSourceRange(Record, Idx)); 1361 if (E->isTypeOperand()) { // __uuidof(ComType) 1362 E->setTypeOperandSourceInfo( 1363 GetTypeSourceInfo(Record, Idx)); 1364 return; 1365 } 1366 1367 // __uuidof(expr) 1368 E->setExprOperand(Reader.ReadSubExpr()); 1369 } 1370 1371 void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) { 1372 VisitStmt(S); 1373 S->Loc = ReadSourceLocation(Record, Idx); 1374 S->Children[SEHExceptStmt::FILTER_EXPR] = Reader.ReadSubStmt(); 1375 S->Children[SEHExceptStmt::BLOCK] = Reader.ReadSubStmt(); 1376 } 1377 1378 void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) { 1379 VisitStmt(S); 1380 S->Loc = ReadSourceLocation(Record, Idx); 1381 S->Block = Reader.ReadSubStmt(); 1382 } 1383 1384 void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) { 1385 VisitStmt(S); 1386 S->IsCXXTry = Record[Idx++]; 1387 S->TryLoc = ReadSourceLocation(Record, Idx); 1388 S->Children[SEHTryStmt::TRY] = Reader.ReadSubStmt(); 1389 S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt(); 1390 } 1391 1392 //===----------------------------------------------------------------------===// 1393 // CUDA Expressions and Statements 1394 //===----------------------------------------------------------------------===// 1395 1396 void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 1397 VisitCallExpr(E); 1398 E->setConfig(cast<CallExpr>(Reader.ReadSubExpr())); 1399 } 1400 1401 //===----------------------------------------------------------------------===// 1402 // OpenCL Expressions and Statements. 1403 //===----------------------------------------------------------------------===// 1404 void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) { 1405 VisitExpr(E); 1406 E->BuiltinLoc = ReadSourceLocation(Record, Idx); 1407 E->RParenLoc = ReadSourceLocation(Record, Idx); 1408 E->SrcExpr = Reader.ReadSubExpr(); 1409 } 1410 1411 //===----------------------------------------------------------------------===// 1412 // ASTReader Implementation 1413 //===----------------------------------------------------------------------===// 1414 1415 Stmt *ASTReader::ReadStmt(Module &F) { 1416 switch (ReadingKind) { 1417 case Read_Decl: 1418 case Read_Type: 1419 return ReadStmtFromStream(F); 1420 case Read_Stmt: 1421 return ReadSubStmt(); 1422 } 1423 1424 llvm_unreachable("ReadingKind not set ?"); 1425 return 0; 1426 } 1427 1428 Expr *ASTReader::ReadExpr(Module &F) { 1429 return cast_or_null<Expr>(ReadStmt(F)); 1430 } 1431 1432 Expr *ASTReader::ReadSubExpr() { 1433 return cast_or_null<Expr>(ReadSubStmt()); 1434 } 1435 1436 // Within the bitstream, expressions are stored in Reverse Polish 1437 // Notation, with each of the subexpressions preceding the 1438 // expression they are stored in. Subexpressions are stored from last to first. 1439 // To evaluate expressions, we continue reading expressions and placing them on 1440 // the stack, with expressions having operands removing those operands from the 1441 // stack. Evaluation terminates when we see a STMT_STOP record, and 1442 // the single remaining expression on the stack is our result. 1443 Stmt *ASTReader::ReadStmtFromStream(Module &F) { 1444 1445 ReadingKindTracker ReadingKind(Read_Stmt, *this); 1446 llvm::BitstreamCursor &Cursor = F.DeclsCursor; 1447 1448 #ifndef NDEBUG 1449 unsigned PrevNumStmts = StmtStack.size(); 1450 #endif 1451 1452 RecordData Record; 1453 unsigned Idx; 1454 ASTStmtReader Reader(*this, F, Cursor, Record, Idx); 1455 Stmt::EmptyShell Empty; 1456 1457 while (true) { 1458 unsigned Code = Cursor.ReadCode(); 1459 if (Code == llvm::bitc::END_BLOCK) { 1460 if (Cursor.ReadBlockEnd()) { 1461 Error("error at end of block in AST file"); 1462 return 0; 1463 } 1464 break; 1465 } 1466 1467 if (Code == llvm::bitc::ENTER_SUBBLOCK) { 1468 // No known subblocks, always skip them. 1469 Cursor.ReadSubBlockID(); 1470 if (Cursor.SkipBlock()) { 1471 Error("malformed block record in AST file"); 1472 return 0; 1473 } 1474 continue; 1475 } 1476 1477 if (Code == llvm::bitc::DEFINE_ABBREV) { 1478 Cursor.ReadAbbrevRecord(); 1479 continue; 1480 } 1481 1482 Stmt *S = 0; 1483 Idx = 0; 1484 Record.clear(); 1485 bool Finished = false; 1486 switch ((StmtCode)Cursor.ReadRecord(Code, Record)) { 1487 case STMT_STOP: 1488 Finished = true; 1489 break; 1490 1491 case STMT_NULL_PTR: 1492 S = 0; 1493 break; 1494 1495 case STMT_NULL: 1496 S = new (Context) NullStmt(Empty); 1497 break; 1498 1499 case STMT_COMPOUND: 1500 S = new (Context) CompoundStmt(Empty); 1501 break; 1502 1503 case STMT_CASE: 1504 S = new (Context) CaseStmt(Empty); 1505 break; 1506 1507 case STMT_DEFAULT: 1508 S = new (Context) DefaultStmt(Empty); 1509 break; 1510 1511 case STMT_LABEL: 1512 S = new (Context) LabelStmt(Empty); 1513 break; 1514 1515 case STMT_IF: 1516 S = new (Context) IfStmt(Empty); 1517 break; 1518 1519 case STMT_SWITCH: 1520 S = new (Context) SwitchStmt(Empty); 1521 break; 1522 1523 case STMT_WHILE: 1524 S = new (Context) WhileStmt(Empty); 1525 break; 1526 1527 case STMT_DO: 1528 S = new (Context) DoStmt(Empty); 1529 break; 1530 1531 case STMT_FOR: 1532 S = new (Context) ForStmt(Empty); 1533 break; 1534 1535 case STMT_GOTO: 1536 S = new (Context) GotoStmt(Empty); 1537 break; 1538 1539 case STMT_INDIRECT_GOTO: 1540 S = new (Context) IndirectGotoStmt(Empty); 1541 break; 1542 1543 case STMT_CONTINUE: 1544 S = new (Context) ContinueStmt(Empty); 1545 break; 1546 1547 case STMT_BREAK: 1548 S = new (Context) BreakStmt(Empty); 1549 break; 1550 1551 case STMT_RETURN: 1552 S = new (Context) ReturnStmt(Empty); 1553 break; 1554 1555 case STMT_DECL: 1556 S = new (Context) DeclStmt(Empty); 1557 break; 1558 1559 case STMT_ASM: 1560 S = new (Context) AsmStmt(Empty); 1561 break; 1562 1563 case EXPR_PREDEFINED: 1564 S = new (Context) PredefinedExpr(Empty); 1565 break; 1566 1567 case EXPR_DECL_REF: 1568 S = DeclRefExpr::CreateEmpty( 1569 Context, 1570 /*HasQualifier=*/Record[ASTStmtReader::NumExprFields], 1571 /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1], 1572 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2], 1573 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ? 1574 Record[ASTStmtReader::NumExprFields + 4] : 0); 1575 break; 1576 1577 case EXPR_INTEGER_LITERAL: 1578 S = IntegerLiteral::Create(Context, Empty); 1579 break; 1580 1581 case EXPR_FLOATING_LITERAL: 1582 S = FloatingLiteral::Create(Context, Empty); 1583 break; 1584 1585 case EXPR_IMAGINARY_LITERAL: 1586 S = new (Context) ImaginaryLiteral(Empty); 1587 break; 1588 1589 case EXPR_STRING_LITERAL: 1590 S = StringLiteral::CreateEmpty(Context, 1591 Record[ASTStmtReader::NumExprFields + 1]); 1592 break; 1593 1594 case EXPR_CHARACTER_LITERAL: 1595 S = new (Context) CharacterLiteral(Empty); 1596 break; 1597 1598 case EXPR_PAREN: 1599 S = new (Context) ParenExpr(Empty); 1600 break; 1601 1602 case EXPR_PAREN_LIST: 1603 S = new (Context) ParenListExpr(Empty); 1604 break; 1605 1606 case EXPR_UNARY_OPERATOR: 1607 S = new (Context) UnaryOperator(Empty); 1608 break; 1609 1610 case EXPR_OFFSETOF: 1611 S = OffsetOfExpr::CreateEmpty(Context, 1612 Record[ASTStmtReader::NumExprFields], 1613 Record[ASTStmtReader::NumExprFields + 1]); 1614 break; 1615 1616 case EXPR_SIZEOF_ALIGN_OF: 1617 S = new (Context) UnaryExprOrTypeTraitExpr(Empty); 1618 break; 1619 1620 case EXPR_ARRAY_SUBSCRIPT: 1621 S = new (Context) ArraySubscriptExpr(Empty); 1622 break; 1623 1624 case EXPR_CALL: 1625 S = new (Context) CallExpr(Context, Stmt::CallExprClass, Empty); 1626 break; 1627 1628 case EXPR_MEMBER: { 1629 // We load everything here and fully initialize it at creation. 1630 // That way we can use MemberExpr::Create and don't have to duplicate its 1631 // logic with a MemberExpr::CreateEmpty. 1632 1633 assert(Idx == 0); 1634 NestedNameSpecifierLoc QualifierLoc; 1635 if (Record[Idx++]) { // HasQualifier. 1636 QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); 1637 } 1638 1639 TemplateArgumentListInfo ArgInfo; 1640 bool HasExplicitTemplateArgs = Record[Idx++]; 1641 if (HasExplicitTemplateArgs) { 1642 unsigned NumTemplateArgs = Record[Idx++]; 1643 ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx)); 1644 ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx)); 1645 for (unsigned i = 0; i != NumTemplateArgs; ++i) 1646 ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx)); 1647 } 1648 1649 bool HadMultipleCandidates = Record[Idx++]; 1650 1651 NamedDecl *FoundD = ReadDeclAs<NamedDecl>(F, Record, Idx); 1652 AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; 1653 DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS); 1654 1655 QualType T = readType(F, Record, Idx); 1656 ExprValueKind VK = static_cast<ExprValueKind>(Record[Idx++]); 1657 ExprObjectKind OK = static_cast<ExprObjectKind>(Record[Idx++]); 1658 Expr *Base = ReadSubExpr(); 1659 ValueDecl *MemberD = ReadDeclAs<ValueDecl>(F, Record, Idx); 1660 SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx); 1661 DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc); 1662 bool IsArrow = Record[Idx++]; 1663 1664 S = MemberExpr::Create(Context, Base, IsArrow, QualifierLoc, 1665 MemberD, FoundDecl, MemberNameInfo, 1666 HasExplicitTemplateArgs ? &ArgInfo : 0, T, VK, OK); 1667 ReadDeclarationNameLoc(F, cast<MemberExpr>(S)->MemberDNLoc, 1668 MemberD->getDeclName(), Record, Idx); 1669 if (HadMultipleCandidates) 1670 cast<MemberExpr>(S)->setHadMultipleCandidates(true); 1671 break; 1672 } 1673 1674 case EXPR_BINARY_OPERATOR: 1675 S = new (Context) BinaryOperator(Empty); 1676 break; 1677 1678 case EXPR_COMPOUND_ASSIGN_OPERATOR: 1679 S = new (Context) CompoundAssignOperator(Empty); 1680 break; 1681 1682 case EXPR_CONDITIONAL_OPERATOR: 1683 S = new (Context) ConditionalOperator(Empty); 1684 break; 1685 1686 case EXPR_BINARY_CONDITIONAL_OPERATOR: 1687 S = new (Context) BinaryConditionalOperator(Empty); 1688 break; 1689 1690 case EXPR_IMPLICIT_CAST: 1691 S = ImplicitCastExpr::CreateEmpty(Context, 1692 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 1693 break; 1694 1695 case EXPR_CSTYLE_CAST: 1696 S = CStyleCastExpr::CreateEmpty(Context, 1697 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 1698 break; 1699 1700 case EXPR_COMPOUND_LITERAL: 1701 S = new (Context) CompoundLiteralExpr(Empty); 1702 break; 1703 1704 case EXPR_EXT_VECTOR_ELEMENT: 1705 S = new (Context) ExtVectorElementExpr(Empty); 1706 break; 1707 1708 case EXPR_INIT_LIST: 1709 S = new (Context) InitListExpr(getContext(), Empty); 1710 break; 1711 1712 case EXPR_DESIGNATED_INIT: 1713 S = DesignatedInitExpr::CreateEmpty(Context, 1714 Record[ASTStmtReader::NumExprFields] - 1); 1715 1716 break; 1717 1718 case EXPR_IMPLICIT_VALUE_INIT: 1719 S = new (Context) ImplicitValueInitExpr(Empty); 1720 break; 1721 1722 case EXPR_VA_ARG: 1723 S = new (Context) VAArgExpr(Empty); 1724 break; 1725 1726 case EXPR_ADDR_LABEL: 1727 S = new (Context) AddrLabelExpr(Empty); 1728 break; 1729 1730 case EXPR_STMT: 1731 S = new (Context) StmtExpr(Empty); 1732 break; 1733 1734 case EXPR_CHOOSE: 1735 S = new (Context) ChooseExpr(Empty); 1736 break; 1737 1738 case EXPR_GNU_NULL: 1739 S = new (Context) GNUNullExpr(Empty); 1740 break; 1741 1742 case EXPR_SHUFFLE_VECTOR: 1743 S = new (Context) ShuffleVectorExpr(Empty); 1744 break; 1745 1746 case EXPR_BLOCK: 1747 S = new (Context) BlockExpr(Empty); 1748 break; 1749 1750 case EXPR_BLOCK_DECL_REF: 1751 S = new (Context) BlockDeclRefExpr(Empty); 1752 break; 1753 1754 case EXPR_GENERIC_SELECTION: 1755 S = new (Context) GenericSelectionExpr(Empty); 1756 break; 1757 1758 case EXPR_OBJC_STRING_LITERAL: 1759 S = new (Context) ObjCStringLiteral(Empty); 1760 break; 1761 case EXPR_OBJC_ENCODE: 1762 S = new (Context) ObjCEncodeExpr(Empty); 1763 break; 1764 case EXPR_OBJC_SELECTOR_EXPR: 1765 S = new (Context) ObjCSelectorExpr(Empty); 1766 break; 1767 case EXPR_OBJC_PROTOCOL_EXPR: 1768 S = new (Context) ObjCProtocolExpr(Empty); 1769 break; 1770 case EXPR_OBJC_IVAR_REF_EXPR: 1771 S = new (Context) ObjCIvarRefExpr(Empty); 1772 break; 1773 case EXPR_OBJC_PROPERTY_REF_EXPR: 1774 S = new (Context) ObjCPropertyRefExpr(Empty); 1775 break; 1776 case EXPR_OBJC_KVC_REF_EXPR: 1777 llvm_unreachable("mismatching AST file"); 1778 break; 1779 case EXPR_OBJC_MESSAGE_EXPR: 1780 S = ObjCMessageExpr::CreateEmpty(Context, 1781 Record[ASTStmtReader::NumExprFields], 1782 Record[ASTStmtReader::NumExprFields + 1]); 1783 break; 1784 case EXPR_OBJC_ISA: 1785 S = new (Context) ObjCIsaExpr(Empty); 1786 break; 1787 case EXPR_OBJC_INDIRECT_COPY_RESTORE: 1788 S = new (Context) ObjCIndirectCopyRestoreExpr(Empty); 1789 break; 1790 case EXPR_OBJC_BRIDGED_CAST: 1791 S = new (Context) ObjCBridgedCastExpr(Empty); 1792 break; 1793 case STMT_OBJC_FOR_COLLECTION: 1794 S = new (Context) ObjCForCollectionStmt(Empty); 1795 break; 1796 case STMT_OBJC_CATCH: 1797 S = new (Context) ObjCAtCatchStmt(Empty); 1798 break; 1799 case STMT_OBJC_FINALLY: 1800 S = new (Context) ObjCAtFinallyStmt(Empty); 1801 break; 1802 case STMT_OBJC_AT_TRY: 1803 S = ObjCAtTryStmt::CreateEmpty(Context, 1804 Record[ASTStmtReader::NumStmtFields], 1805 Record[ASTStmtReader::NumStmtFields + 1]); 1806 break; 1807 case STMT_OBJC_AT_SYNCHRONIZED: 1808 S = new (Context) ObjCAtSynchronizedStmt(Empty); 1809 break; 1810 case STMT_OBJC_AT_THROW: 1811 S = new (Context) ObjCAtThrowStmt(Empty); 1812 break; 1813 case STMT_OBJC_AUTORELEASE_POOL: 1814 S = new (Context) ObjCAutoreleasePoolStmt(Empty); 1815 break; 1816 case STMT_SEH_EXCEPT: 1817 S = new (Context) SEHExceptStmt(Empty); 1818 break; 1819 case STMT_SEH_FINALLY: 1820 S = new (Context) SEHFinallyStmt(Empty); 1821 break; 1822 case STMT_SEH_TRY: 1823 S = new (Context) SEHTryStmt(Empty); 1824 break; 1825 case STMT_CXX_CATCH: 1826 S = new (Context) CXXCatchStmt(Empty); 1827 break; 1828 1829 case STMT_CXX_TRY: 1830 S = CXXTryStmt::Create(Context, Empty, 1831 /*NumHandlers=*/Record[ASTStmtReader::NumStmtFields]); 1832 break; 1833 1834 case STMT_CXX_FOR_RANGE: 1835 S = new (Context) CXXForRangeStmt(Empty); 1836 break; 1837 1838 case EXPR_CXX_OPERATOR_CALL: 1839 S = new (Context) CXXOperatorCallExpr(Context, Empty); 1840 break; 1841 1842 case EXPR_CXX_MEMBER_CALL: 1843 S = new (Context) CXXMemberCallExpr(Context, Empty); 1844 break; 1845 1846 case EXPR_CXX_CONSTRUCT: 1847 S = new (Context) CXXConstructExpr(Empty); 1848 break; 1849 1850 case EXPR_CXX_TEMPORARY_OBJECT: 1851 S = new (Context) CXXTemporaryObjectExpr(Empty); 1852 break; 1853 1854 case EXPR_CXX_STATIC_CAST: 1855 S = CXXStaticCastExpr::CreateEmpty(Context, 1856 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 1857 break; 1858 1859 case EXPR_CXX_DYNAMIC_CAST: 1860 S = CXXDynamicCastExpr::CreateEmpty(Context, 1861 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 1862 break; 1863 1864 case EXPR_CXX_REINTERPRET_CAST: 1865 S = CXXReinterpretCastExpr::CreateEmpty(Context, 1866 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 1867 break; 1868 1869 case EXPR_CXX_CONST_CAST: 1870 S = CXXConstCastExpr::CreateEmpty(Context); 1871 break; 1872 1873 case EXPR_CXX_FUNCTIONAL_CAST: 1874 S = CXXFunctionalCastExpr::CreateEmpty(Context, 1875 /*PathSize*/ Record[ASTStmtReader::NumExprFields]); 1876 break; 1877 1878 case EXPR_CXX_BOOL_LITERAL: 1879 S = new (Context) CXXBoolLiteralExpr(Empty); 1880 break; 1881 1882 case EXPR_CXX_NULL_PTR_LITERAL: 1883 S = new (Context) CXXNullPtrLiteralExpr(Empty); 1884 break; 1885 case EXPR_CXX_TYPEID_EXPR: 1886 S = new (Context) CXXTypeidExpr(Empty, true); 1887 break; 1888 case EXPR_CXX_TYPEID_TYPE: 1889 S = new (Context) CXXTypeidExpr(Empty, false); 1890 break; 1891 case EXPR_CXX_UUIDOF_EXPR: 1892 S = new (Context) CXXUuidofExpr(Empty, true); 1893 break; 1894 case EXPR_CXX_UUIDOF_TYPE: 1895 S = new (Context) CXXUuidofExpr(Empty, false); 1896 break; 1897 case EXPR_CXX_THIS: 1898 S = new (Context) CXXThisExpr(Empty); 1899 break; 1900 case EXPR_CXX_THROW: 1901 S = new (Context) CXXThrowExpr(Empty); 1902 break; 1903 case EXPR_CXX_DEFAULT_ARG: { 1904 bool HasOtherExprStored = Record[ASTStmtReader::NumExprFields]; 1905 if (HasOtherExprStored) { 1906 Expr *SubExpr = ReadSubExpr(); 1907 S = CXXDefaultArgExpr::Create(Context, SourceLocation(), 0, SubExpr); 1908 } else 1909 S = new (Context) CXXDefaultArgExpr(Empty); 1910 break; 1911 } 1912 case EXPR_CXX_BIND_TEMPORARY: 1913 S = new (Context) CXXBindTemporaryExpr(Empty); 1914 break; 1915 1916 case EXPR_CXX_SCALAR_VALUE_INIT: 1917 S = new (Context) CXXScalarValueInitExpr(Empty); 1918 break; 1919 case EXPR_CXX_NEW: 1920 S = new (Context) CXXNewExpr(Empty); 1921 break; 1922 case EXPR_CXX_DELETE: 1923 S = new (Context) CXXDeleteExpr(Empty); 1924 break; 1925 case EXPR_CXX_PSEUDO_DESTRUCTOR: 1926 S = new (Context) CXXPseudoDestructorExpr(Empty); 1927 break; 1928 1929 case EXPR_EXPR_WITH_CLEANUPS: 1930 S = new (Context) ExprWithCleanups(Empty); 1931 break; 1932 1933 case EXPR_CXX_DEPENDENT_SCOPE_MEMBER: 1934 S = CXXDependentScopeMemberExpr::CreateEmpty(Context, 1935 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields], 1936 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields] 1937 ? Record[ASTStmtReader::NumExprFields + 1] 1938 : 0); 1939 break; 1940 1941 case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF: 1942 S = DependentScopeDeclRefExpr::CreateEmpty(Context, 1943 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields], 1944 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields] 1945 ? Record[ASTStmtReader::NumExprFields + 1] 1946 : 0); 1947 break; 1948 1949 case EXPR_CXX_UNRESOLVED_CONSTRUCT: 1950 S = CXXUnresolvedConstructExpr::CreateEmpty(Context, 1951 /*NumArgs=*/Record[ASTStmtReader::NumExprFields]); 1952 break; 1953 1954 case EXPR_CXX_UNRESOLVED_MEMBER: 1955 S = UnresolvedMemberExpr::CreateEmpty(Context, 1956 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields], 1957 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields] 1958 ? Record[ASTStmtReader::NumExprFields + 1] 1959 : 0); 1960 break; 1961 1962 case EXPR_CXX_UNRESOLVED_LOOKUP: 1963 S = UnresolvedLookupExpr::CreateEmpty(Context, 1964 /*HasExplicitTemplateArgs=*/Record[ASTStmtReader::NumExprFields], 1965 /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields] 1966 ? Record[ASTStmtReader::NumExprFields + 1] 1967 : 0); 1968 break; 1969 1970 case EXPR_CXX_UNARY_TYPE_TRAIT: 1971 S = new (Context) UnaryTypeTraitExpr(Empty); 1972 break; 1973 1974 case EXPR_BINARY_TYPE_TRAIT: 1975 S = new (Context) BinaryTypeTraitExpr(Empty); 1976 break; 1977 1978 case EXPR_ARRAY_TYPE_TRAIT: 1979 S = new (Context) ArrayTypeTraitExpr(Empty); 1980 break; 1981 1982 case EXPR_CXX_EXPRESSION_TRAIT: 1983 S = new (Context) ExpressionTraitExpr(Empty); 1984 break; 1985 1986 case EXPR_CXX_NOEXCEPT: 1987 S = new (Context) CXXNoexceptExpr(Empty); 1988 break; 1989 1990 case EXPR_PACK_EXPANSION: 1991 S = new (Context) PackExpansionExpr(Empty); 1992 break; 1993 1994 case EXPR_SIZEOF_PACK: 1995 S = new (Context) SizeOfPackExpr(Empty); 1996 break; 1997 1998 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM: 1999 S = new (Context) SubstNonTypeTemplateParmExpr(Empty); 2000 break; 2001 2002 case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK: 2003 S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty); 2004 break; 2005 2006 case EXPR_MATERIALIZE_TEMPORARY: 2007 S = new (Context) MaterializeTemporaryExpr(Empty); 2008 break; 2009 2010 case EXPR_OPAQUE_VALUE: { 2011 unsigned key = Record[ASTStmtReader::NumExprFields]; 2012 OpaqueValueExpr *&expr = OpaqueValueExprs[key]; 2013 2014 // If we already have an entry for this opaque value expression, 2015 // don't bother reading it again. 2016 if (expr) { 2017 StmtStack.push_back(expr); 2018 continue; 2019 } 2020 2021 S = expr = new (Context) OpaqueValueExpr(Empty); 2022 break; 2023 } 2024 2025 case EXPR_CUDA_KERNEL_CALL: 2026 S = new (Context) CUDAKernelCallExpr(Context, Empty); 2027 break; 2028 2029 case EXPR_ASTYPE: 2030 S = new (Context) AsTypeExpr(Empty); 2031 break; 2032 2033 case EXPR_ATOMIC: 2034 S = new (Context) AtomicExpr(Empty); 2035 break; 2036 } 2037 2038 // We hit a STMT_STOP, so we're done with this expression. 2039 if (Finished) 2040 break; 2041 2042 ++NumStatementsRead; 2043 2044 if (S) 2045 Reader.Visit(S); 2046 2047 assert(Idx == Record.size() && "Invalid deserialization of statement"); 2048 StmtStack.push_back(S); 2049 } 2050 2051 #ifndef NDEBUG 2052 assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!"); 2053 assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!"); 2054 #endif 2055 2056 return StmtStack.pop_back_val(); 2057 } 2058