Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame^] | 1 | //===--- PCHReaderStmt.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 | // PCHReader::ReadStmt method. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Frontend/PCHReader.h" |
| 16 | #include "clang/AST/StmtVisitor.h" |
| 17 | using namespace clang; |
| 18 | |
| 19 | // FIXME: use the diagnostics machinery |
| 20 | static bool Error(const char *Str) { |
| 21 | std::fprintf(stderr, "%s\n", Str); |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | namespace { |
| 26 | class PCHStmtReader : public StmtVisitor<PCHStmtReader, unsigned> { |
| 27 | PCHReader &Reader; |
| 28 | const PCHReader::RecordData &Record; |
| 29 | unsigned &Idx; |
| 30 | llvm::SmallVectorImpl<Stmt *> &StmtStack; |
| 31 | |
| 32 | public: |
| 33 | PCHStmtReader(PCHReader &Reader, const PCHReader::RecordData &Record, |
| 34 | unsigned &Idx, llvm::SmallVectorImpl<Stmt *> &StmtStack) |
| 35 | : Reader(Reader), Record(Record), Idx(Idx), StmtStack(StmtStack) { } |
| 36 | |
| 37 | /// \brief The number of record fields required for the Stmt class |
| 38 | /// itself. |
| 39 | static const unsigned NumStmtFields = 0; |
| 40 | |
| 41 | /// \brief The number of record fields required for the Expr class |
| 42 | /// itself. |
| 43 | static const unsigned NumExprFields = NumStmtFields + 3; |
| 44 | |
| 45 | // Each of the Visit* functions reads in part of the expression |
| 46 | // from the given record and the current expression stack, then |
| 47 | // return the total number of operands that it read from the |
| 48 | // expression stack. |
| 49 | |
| 50 | unsigned VisitStmt(Stmt *S); |
| 51 | unsigned VisitNullStmt(NullStmt *S); |
| 52 | unsigned VisitCompoundStmt(CompoundStmt *S); |
| 53 | unsigned VisitSwitchCase(SwitchCase *S); |
| 54 | unsigned VisitCaseStmt(CaseStmt *S); |
| 55 | unsigned VisitDefaultStmt(DefaultStmt *S); |
| 56 | unsigned VisitLabelStmt(LabelStmt *S); |
| 57 | unsigned VisitIfStmt(IfStmt *S); |
| 58 | unsigned VisitSwitchStmt(SwitchStmt *S); |
| 59 | unsigned VisitWhileStmt(WhileStmt *S); |
| 60 | unsigned VisitDoStmt(DoStmt *S); |
| 61 | unsigned VisitForStmt(ForStmt *S); |
| 62 | unsigned VisitGotoStmt(GotoStmt *S); |
| 63 | unsigned VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 64 | unsigned VisitContinueStmt(ContinueStmt *S); |
| 65 | unsigned VisitBreakStmt(BreakStmt *S); |
| 66 | unsigned VisitReturnStmt(ReturnStmt *S); |
| 67 | unsigned VisitDeclStmt(DeclStmt *S); |
| 68 | unsigned VisitAsmStmt(AsmStmt *S); |
| 69 | unsigned VisitExpr(Expr *E); |
| 70 | unsigned VisitPredefinedExpr(PredefinedExpr *E); |
| 71 | unsigned VisitDeclRefExpr(DeclRefExpr *E); |
| 72 | unsigned VisitIntegerLiteral(IntegerLiteral *E); |
| 73 | unsigned VisitFloatingLiteral(FloatingLiteral *E); |
| 74 | unsigned VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 75 | unsigned VisitStringLiteral(StringLiteral *E); |
| 76 | unsigned VisitCharacterLiteral(CharacterLiteral *E); |
| 77 | unsigned VisitParenExpr(ParenExpr *E); |
| 78 | unsigned VisitUnaryOperator(UnaryOperator *E); |
| 79 | unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); |
| 80 | unsigned VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 81 | unsigned VisitCallExpr(CallExpr *E); |
| 82 | unsigned VisitMemberExpr(MemberExpr *E); |
| 83 | unsigned VisitCastExpr(CastExpr *E); |
| 84 | unsigned VisitBinaryOperator(BinaryOperator *E); |
| 85 | unsigned VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 86 | unsigned VisitConditionalOperator(ConditionalOperator *E); |
| 87 | unsigned VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 88 | unsigned VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 89 | unsigned VisitCStyleCastExpr(CStyleCastExpr *E); |
| 90 | unsigned VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 91 | unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E); |
| 92 | unsigned VisitInitListExpr(InitListExpr *E); |
| 93 | unsigned VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 94 | unsigned VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 95 | unsigned VisitVAArgExpr(VAArgExpr *E); |
| 96 | unsigned VisitAddrLabelExpr(AddrLabelExpr *E); |
| 97 | unsigned VisitStmtExpr(StmtExpr *E); |
| 98 | unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr *E); |
| 99 | unsigned VisitChooseExpr(ChooseExpr *E); |
| 100 | unsigned VisitGNUNullExpr(GNUNullExpr *E); |
| 101 | unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E); |
| 102 | unsigned VisitBlockExpr(BlockExpr *E); |
| 103 | unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E); |
| 104 | unsigned VisitObjCStringLiteral(ObjCStringLiteral *E); |
| 105 | unsigned VisitObjCEncodeExpr(ObjCEncodeExpr *E); |
| 106 | unsigned VisitObjCSelectorExpr(ObjCSelectorExpr *E); |
| 107 | unsigned VisitObjCProtocolExpr(ObjCProtocolExpr *E); |
| 108 | unsigned VisitObjCIvarRefExpr(ObjCIvarRefExpr *E); |
| 109 | unsigned VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E); |
| 110 | unsigned VisitObjCKVCRefExpr(ObjCKVCRefExpr *E); |
| 111 | unsigned VisitObjCMessageExpr(ObjCMessageExpr *E); |
| 112 | unsigned VisitObjCSuperExpr(ObjCSuperExpr *E); |
| 113 | |
| 114 | unsigned VisitObjCForCollectionStmt(ObjCForCollectionStmt *); |
| 115 | unsigned VisitObjCAtCatchStmt(ObjCAtCatchStmt *); |
| 116 | unsigned VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *); |
| 117 | unsigned VisitObjCAtTryStmt(ObjCAtTryStmt *); |
| 118 | unsigned VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *); |
| 119 | unsigned VisitObjCAtThrowStmt(ObjCAtThrowStmt *); |
| 120 | }; |
| 121 | } |
| 122 | |
| 123 | unsigned PCHStmtReader::VisitStmt(Stmt *S) { |
| 124 | assert(Idx == NumStmtFields && "Incorrect statement field count"); |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | unsigned PCHStmtReader::VisitNullStmt(NullStmt *S) { |
| 129 | VisitStmt(S); |
| 130 | S->setSemiLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | unsigned PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) { |
| 135 | VisitStmt(S); |
| 136 | unsigned NumStmts = Record[Idx++]; |
| 137 | S->setStmts(Reader.getContext(), |
| 138 | &StmtStack[StmtStack.size() - NumStmts], NumStmts); |
| 139 | S->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 140 | S->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 141 | return NumStmts; |
| 142 | } |
| 143 | |
| 144 | unsigned PCHStmtReader::VisitSwitchCase(SwitchCase *S) { |
| 145 | VisitStmt(S); |
| 146 | Reader.RecordSwitchCaseID(S, Record[Idx++]); |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | unsigned PCHStmtReader::VisitCaseStmt(CaseStmt *S) { |
| 151 | VisitSwitchCase(S); |
| 152 | S->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 153 | S->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 154 | S->setSubStmt(StmtStack.back()); |
| 155 | S->setCaseLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 156 | return 3; |
| 157 | } |
| 158 | |
| 159 | unsigned PCHStmtReader::VisitDefaultStmt(DefaultStmt *S) { |
| 160 | VisitSwitchCase(S); |
| 161 | S->setSubStmt(StmtStack.back()); |
| 162 | S->setDefaultLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | unsigned PCHStmtReader::VisitLabelStmt(LabelStmt *S) { |
| 167 | VisitStmt(S); |
| 168 | S->setID(Reader.GetIdentifierInfo(Record, Idx)); |
| 169 | S->setSubStmt(StmtStack.back()); |
| 170 | S->setIdentLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 171 | Reader.RecordLabelStmt(S, Record[Idx++]); |
| 172 | return 1; |
| 173 | } |
| 174 | |
| 175 | unsigned PCHStmtReader::VisitIfStmt(IfStmt *S) { |
| 176 | VisitStmt(S); |
| 177 | S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 178 | S->setThen(StmtStack[StmtStack.size() - 2]); |
| 179 | S->setElse(StmtStack[StmtStack.size() - 1]); |
| 180 | S->setIfLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 181 | return 3; |
| 182 | } |
| 183 | |
| 184 | unsigned PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) { |
| 185 | VisitStmt(S); |
| 186 | S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 2])); |
| 187 | S->setBody(StmtStack.back()); |
| 188 | S->setSwitchLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 189 | SwitchCase *PrevSC = 0; |
| 190 | for (unsigned N = Record.size(); Idx != N; ++Idx) { |
| 191 | SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]); |
| 192 | if (PrevSC) |
| 193 | PrevSC->setNextSwitchCase(SC); |
| 194 | else |
| 195 | S->setSwitchCaseList(SC); |
| 196 | PrevSC = SC; |
| 197 | } |
| 198 | return 2; |
| 199 | } |
| 200 | |
| 201 | unsigned PCHStmtReader::VisitWhileStmt(WhileStmt *S) { |
| 202 | VisitStmt(S); |
| 203 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 204 | S->setBody(StmtStack.back()); |
| 205 | S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 206 | return 2; |
| 207 | } |
| 208 | |
| 209 | unsigned PCHStmtReader::VisitDoStmt(DoStmt *S) { |
| 210 | VisitStmt(S); |
| 211 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 212 | S->setBody(StmtStack.back()); |
| 213 | S->setDoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 214 | return 2; |
| 215 | } |
| 216 | |
| 217 | unsigned PCHStmtReader::VisitForStmt(ForStmt *S) { |
| 218 | VisitStmt(S); |
| 219 | S->setInit(StmtStack[StmtStack.size() - 4]); |
| 220 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 3])); |
| 221 | S->setInc(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 222 | S->setBody(StmtStack.back()); |
| 223 | S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 224 | return 4; |
| 225 | } |
| 226 | |
| 227 | unsigned PCHStmtReader::VisitGotoStmt(GotoStmt *S) { |
| 228 | VisitStmt(S); |
| 229 | Reader.SetLabelOf(S, Record[Idx++]); |
| 230 | S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 231 | S->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 236 | VisitStmt(S); |
| 237 | S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 238 | S->setTarget(cast_or_null<Expr>(StmtStack.back())); |
| 239 | return 1; |
| 240 | } |
| 241 | |
| 242 | unsigned PCHStmtReader::VisitContinueStmt(ContinueStmt *S) { |
| 243 | VisitStmt(S); |
| 244 | S->setContinueLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | unsigned PCHStmtReader::VisitBreakStmt(BreakStmt *S) { |
| 249 | VisitStmt(S); |
| 250 | S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) { |
| 255 | VisitStmt(S); |
| 256 | S->setRetValue(cast_or_null<Expr>(StmtStack.back())); |
| 257 | S->setReturnLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 258 | return 1; |
| 259 | } |
| 260 | |
| 261 | unsigned PCHStmtReader::VisitDeclStmt(DeclStmt *S) { |
| 262 | VisitStmt(S); |
| 263 | S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 264 | S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 265 | |
| 266 | if (Idx + 1 == Record.size()) { |
| 267 | // Single declaration |
| 268 | S->setDeclGroup(DeclGroupRef(Reader.GetDecl(Record[Idx++]))); |
| 269 | } else { |
| 270 | llvm::SmallVector<Decl *, 16> Decls; |
| 271 | Decls.reserve(Record.size() - Idx); |
| 272 | for (unsigned N = Record.size(); Idx != N; ++Idx) |
| 273 | Decls.push_back(Reader.GetDecl(Record[Idx])); |
| 274 | S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(), |
| 275 | &Decls[0], Decls.size()))); |
| 276 | } |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | unsigned PCHStmtReader::VisitAsmStmt(AsmStmt *S) { |
| 281 | VisitStmt(S); |
| 282 | unsigned NumOutputs = Record[Idx++]; |
| 283 | unsigned NumInputs = Record[Idx++]; |
| 284 | unsigned NumClobbers = Record[Idx++]; |
| 285 | S->setAsmLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 286 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 287 | S->setVolatile(Record[Idx++]); |
| 288 | S->setSimple(Record[Idx++]); |
| 289 | |
| 290 | unsigned StackIdx |
| 291 | = StmtStack.size() - (NumOutputs*2 + NumInputs*2 + NumClobbers + 1); |
| 292 | S->setAsmString(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 293 | |
| 294 | // Outputs and inputs |
| 295 | llvm::SmallVector<std::string, 16> Names; |
| 296 | llvm::SmallVector<StringLiteral*, 16> Constraints; |
| 297 | llvm::SmallVector<Stmt*, 16> Exprs; |
| 298 | for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) { |
| 299 | Names.push_back(Reader.ReadString(Record, Idx)); |
| 300 | Constraints.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 301 | Exprs.push_back(StmtStack[StackIdx++]); |
| 302 | } |
| 303 | S->setOutputsAndInputs(NumOutputs, NumInputs, |
| 304 | &Names[0], &Constraints[0], &Exprs[0]); |
| 305 | |
| 306 | // Constraints |
| 307 | llvm::SmallVector<StringLiteral*, 16> Clobbers; |
| 308 | for (unsigned I = 0; I != NumClobbers; ++I) |
| 309 | Clobbers.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 310 | S->setClobbers(&Clobbers[0], NumClobbers); |
| 311 | |
| 312 | assert(StackIdx == StmtStack.size() && "Error deserializing AsmStmt"); |
| 313 | return NumOutputs*2 + NumInputs*2 + NumClobbers + 1; |
| 314 | } |
| 315 | |
| 316 | unsigned PCHStmtReader::VisitExpr(Expr *E) { |
| 317 | VisitStmt(E); |
| 318 | E->setType(Reader.GetType(Record[Idx++])); |
| 319 | E->setTypeDependent(Record[Idx++]); |
| 320 | E->setValueDependent(Record[Idx++]); |
| 321 | assert(Idx == NumExprFields && "Incorrect expression field count"); |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | unsigned PCHStmtReader::VisitPredefinedExpr(PredefinedExpr *E) { |
| 326 | VisitExpr(E); |
| 327 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 328 | E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]); |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | unsigned PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) { |
| 333 | VisitExpr(E); |
| 334 | E->setDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 335 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | unsigned PCHStmtReader::VisitIntegerLiteral(IntegerLiteral *E) { |
| 340 | VisitExpr(E); |
| 341 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 342 | E->setValue(Reader.ReadAPInt(Record, Idx)); |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | unsigned PCHStmtReader::VisitFloatingLiteral(FloatingLiteral *E) { |
| 347 | VisitExpr(E); |
| 348 | E->setValue(Reader.ReadAPFloat(Record, Idx)); |
| 349 | E->setExact(Record[Idx++]); |
| 350 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | unsigned PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 355 | VisitExpr(E); |
| 356 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 357 | return 1; |
| 358 | } |
| 359 | |
| 360 | unsigned PCHStmtReader::VisitStringLiteral(StringLiteral *E) { |
| 361 | VisitExpr(E); |
| 362 | unsigned Len = Record[Idx++]; |
| 363 | assert(Record[Idx] == E->getNumConcatenated() && |
| 364 | "Wrong number of concatenated tokens!"); |
| 365 | ++Idx; |
| 366 | E->setWide(Record[Idx++]); |
| 367 | |
| 368 | // Read string data |
| 369 | llvm::SmallVector<char, 16> Str(&Record[Idx], &Record[Idx] + Len); |
| 370 | E->setStrData(Reader.getContext(), &Str[0], Len); |
| 371 | Idx += Len; |
| 372 | |
| 373 | // Read source locations |
| 374 | for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) |
| 375 | E->setStrTokenLoc(I, SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | unsigned PCHStmtReader::VisitCharacterLiteral(CharacterLiteral *E) { |
| 381 | VisitExpr(E); |
| 382 | E->setValue(Record[Idx++]); |
| 383 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 384 | E->setWide(Record[Idx++]); |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | unsigned PCHStmtReader::VisitParenExpr(ParenExpr *E) { |
| 389 | VisitExpr(E); |
| 390 | E->setLParen(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 391 | E->setRParen(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 392 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 393 | return 1; |
| 394 | } |
| 395 | |
| 396 | unsigned PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) { |
| 397 | VisitExpr(E); |
| 398 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 399 | E->setOpcode((UnaryOperator::Opcode)Record[Idx++]); |
| 400 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 401 | return 1; |
| 402 | } |
| 403 | |
| 404 | unsigned PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
| 405 | VisitExpr(E); |
| 406 | E->setSizeof(Record[Idx++]); |
| 407 | if (Record[Idx] == 0) { |
| 408 | E->setArgument(cast<Expr>(StmtStack.back())); |
| 409 | ++Idx; |
| 410 | } else { |
| 411 | E->setArgument(Reader.GetType(Record[Idx++])); |
| 412 | } |
| 413 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 414 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 415 | return E->isArgumentType()? 0 : 1; |
| 416 | } |
| 417 | |
| 418 | unsigned PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 419 | VisitExpr(E); |
| 420 | E->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 2])); |
| 421 | E->setRHS(cast<Expr>(StmtStack[StmtStack.size() - 1])); |
| 422 | E->setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 423 | return 2; |
| 424 | } |
| 425 | |
| 426 | unsigned PCHStmtReader::VisitCallExpr(CallExpr *E) { |
| 427 | VisitExpr(E); |
| 428 | E->setNumArgs(Reader.getContext(), Record[Idx++]); |
| 429 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 430 | E->setCallee(cast<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1])); |
| 431 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) |
| 432 | E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I])); |
| 433 | return E->getNumArgs() + 1; |
| 434 | } |
| 435 | |
| 436 | unsigned PCHStmtReader::VisitMemberExpr(MemberExpr *E) { |
| 437 | VisitExpr(E); |
| 438 | E->setBase(cast<Expr>(StmtStack.back())); |
| 439 | E->setMemberDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 440 | E->setMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 441 | E->setArrow(Record[Idx++]); |
| 442 | return 1; |
| 443 | } |
| 444 | |
| 445 | unsigned PCHStmtReader::VisitCastExpr(CastExpr *E) { |
| 446 | VisitExpr(E); |
| 447 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 448 | return 1; |
| 449 | } |
| 450 | |
| 451 | unsigned PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) { |
| 452 | VisitExpr(E); |
| 453 | E->setLHS(cast<Expr>(StmtStack.end()[-2])); |
| 454 | E->setRHS(cast<Expr>(StmtStack.end()[-1])); |
| 455 | E->setOpcode((BinaryOperator::Opcode)Record[Idx++]); |
| 456 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 457 | return 2; |
| 458 | } |
| 459 | |
| 460 | unsigned PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 461 | VisitBinaryOperator(E); |
| 462 | E->setComputationLHSType(Reader.GetType(Record[Idx++])); |
| 463 | E->setComputationResultType(Reader.GetType(Record[Idx++])); |
| 464 | return 2; |
| 465 | } |
| 466 | |
| 467 | unsigned PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) { |
| 468 | VisitExpr(E); |
| 469 | E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 470 | E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 471 | E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1])); |
| 472 | return 3; |
| 473 | } |
| 474 | |
| 475 | unsigned PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 476 | VisitCastExpr(E); |
| 477 | E->setLvalueCast(Record[Idx++]); |
| 478 | return 1; |
| 479 | } |
| 480 | |
| 481 | unsigned PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 482 | VisitCastExpr(E); |
| 483 | E->setTypeAsWritten(Reader.GetType(Record[Idx++])); |
| 484 | return 1; |
| 485 | } |
| 486 | |
| 487 | unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) { |
| 488 | VisitExplicitCastExpr(E); |
| 489 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 490 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 491 | return 1; |
| 492 | } |
| 493 | |
| 494 | unsigned PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 495 | VisitExpr(E); |
| 496 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 497 | E->setInitializer(cast<Expr>(StmtStack.back())); |
| 498 | E->setFileScope(Record[Idx++]); |
| 499 | return 1; |
| 500 | } |
| 501 | |
| 502 | unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { |
| 503 | VisitExpr(E); |
| 504 | E->setBase(cast<Expr>(StmtStack.back())); |
| 505 | E->setAccessor(Reader.GetIdentifierInfo(Record, Idx)); |
| 506 | E->setAccessorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 507 | return 1; |
| 508 | } |
| 509 | |
| 510 | unsigned PCHStmtReader::VisitInitListExpr(InitListExpr *E) { |
| 511 | VisitExpr(E); |
| 512 | unsigned NumInits = Record[Idx++]; |
| 513 | E->reserveInits(NumInits); |
| 514 | for (unsigned I = 0; I != NumInits; ++I) |
| 515 | E->updateInit(I, |
| 516 | cast<Expr>(StmtStack[StmtStack.size() - NumInits - 1 + I])); |
| 517 | E->setSyntacticForm(cast_or_null<InitListExpr>(StmtStack.back())); |
| 518 | E->setLBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 519 | E->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 520 | E->setInitializedFieldInUnion( |
| 521 | cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]))); |
| 522 | E->sawArrayRangeDesignator(Record[Idx++]); |
| 523 | return NumInits + 1; |
| 524 | } |
| 525 | |
| 526 | unsigned PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 527 | typedef DesignatedInitExpr::Designator Designator; |
| 528 | |
| 529 | VisitExpr(E); |
| 530 | unsigned NumSubExprs = Record[Idx++]; |
| 531 | assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs"); |
| 532 | for (unsigned I = 0; I != NumSubExprs; ++I) |
| 533 | E->setSubExpr(I, cast<Expr>(StmtStack[StmtStack.size() - NumSubExprs + I])); |
| 534 | E->setEqualOrColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 535 | E->setGNUSyntax(Record[Idx++]); |
| 536 | |
| 537 | llvm::SmallVector<Designator, 4> Designators; |
| 538 | while (Idx < Record.size()) { |
| 539 | switch ((pch::DesignatorTypes)Record[Idx++]) { |
| 540 | case pch::DESIG_FIELD_DECL: { |
| 541 | FieldDecl *Field = cast<FieldDecl>(Reader.GetDecl(Record[Idx++])); |
| 542 | SourceLocation DotLoc |
| 543 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 544 | SourceLocation FieldLoc |
| 545 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 546 | Designators.push_back(Designator(Field->getIdentifier(), DotLoc, |
| 547 | FieldLoc)); |
| 548 | Designators.back().setField(Field); |
| 549 | break; |
| 550 | } |
| 551 | |
| 552 | case pch::DESIG_FIELD_NAME: { |
| 553 | const IdentifierInfo *Name = Reader.GetIdentifierInfo(Record, Idx); |
| 554 | SourceLocation DotLoc |
| 555 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 556 | SourceLocation FieldLoc |
| 557 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 558 | Designators.push_back(Designator(Name, DotLoc, FieldLoc)); |
| 559 | break; |
| 560 | } |
| 561 | |
| 562 | case pch::DESIG_ARRAY: { |
| 563 | unsigned Index = Record[Idx++]; |
| 564 | SourceLocation LBracketLoc |
| 565 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 566 | SourceLocation RBracketLoc |
| 567 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 568 | Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc)); |
| 569 | break; |
| 570 | } |
| 571 | |
| 572 | case pch::DESIG_ARRAY_RANGE: { |
| 573 | unsigned Index = Record[Idx++]; |
| 574 | SourceLocation LBracketLoc |
| 575 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 576 | SourceLocation EllipsisLoc |
| 577 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 578 | SourceLocation RBracketLoc |
| 579 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 580 | Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc, |
| 581 | RBracketLoc)); |
| 582 | break; |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | E->setDesignators(&Designators[0], Designators.size()); |
| 587 | |
| 588 | return NumSubExprs; |
| 589 | } |
| 590 | |
| 591 | unsigned PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 592 | VisitExpr(E); |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | unsigned PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) { |
| 597 | VisitExpr(E); |
| 598 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 599 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 600 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 601 | return 1; |
| 602 | } |
| 603 | |
| 604 | unsigned PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 605 | VisitExpr(E); |
| 606 | E->setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 607 | E->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 608 | Reader.SetLabelOf(E, Record[Idx++]); |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | unsigned PCHStmtReader::VisitStmtExpr(StmtExpr *E) { |
| 613 | VisitExpr(E); |
| 614 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 615 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 616 | E->setSubStmt(cast_or_null<CompoundStmt>(StmtStack.back())); |
| 617 | return 1; |
| 618 | } |
| 619 | |
| 620 | unsigned PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { |
| 621 | VisitExpr(E); |
| 622 | E->setArgType1(Reader.GetType(Record[Idx++])); |
| 623 | E->setArgType2(Reader.GetType(Record[Idx++])); |
| 624 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 625 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | unsigned PCHStmtReader::VisitChooseExpr(ChooseExpr *E) { |
| 630 | VisitExpr(E); |
| 631 | E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 632 | E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 633 | E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1])); |
| 634 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 635 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 636 | return 3; |
| 637 | } |
| 638 | |
| 639 | unsigned PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) { |
| 640 | VisitExpr(E); |
| 641 | E->setTokenLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | unsigned PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { |
| 646 | VisitExpr(E); |
| 647 | unsigned NumExprs = Record[Idx++]; |
| 648 | E->setExprs((Expr **)&StmtStack[StmtStack.size() - NumExprs], NumExprs); |
| 649 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 650 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 651 | return NumExprs; |
| 652 | } |
| 653 | |
| 654 | unsigned PCHStmtReader::VisitBlockExpr(BlockExpr *E) { |
| 655 | VisitExpr(E); |
| 656 | E->setBlockDecl(cast_or_null<BlockDecl>(Reader.GetDecl(Record[Idx++]))); |
| 657 | E->setHasBlockDeclRefExprs(Record[Idx++]); |
| 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | unsigned PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { |
| 662 | VisitExpr(E); |
| 663 | E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++]))); |
| 664 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 665 | E->setByRef(Record[Idx++]); |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | //===----------------------------------------------------------------------===// |
| 670 | // Objective-C Expressions and Statements |
| 671 | |
| 672 | unsigned PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) { |
| 673 | VisitExpr(E); |
| 674 | E->setString(cast<StringLiteral>(StmtStack.back())); |
| 675 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 676 | return 1; |
| 677 | } |
| 678 | |
| 679 | unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { |
| 680 | VisitExpr(E); |
| 681 | E->setEncodedType(Reader.GetType(Record[Idx++])); |
| 682 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 683 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | unsigned PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { |
| 688 | VisitExpr(E); |
| 689 | E->setSelector(Reader.GetSelector(Record, Idx)); |
| 690 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 691 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | unsigned PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { |
| 696 | VisitExpr(E); |
| 697 | E->setProtocol(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
| 698 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 699 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 700 | return 0; |
| 701 | } |
| 702 | |
| 703 | unsigned PCHStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| 704 | VisitExpr(E); |
| 705 | E->setDecl(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 706 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 707 | E->setBase(cast<Expr>(StmtStack.back())); |
| 708 | E->setIsArrow(Record[Idx++]); |
| 709 | E->setIsFreeIvar(Record[Idx++]); |
| 710 | return 1; |
| 711 | } |
| 712 | |
| 713 | unsigned PCHStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 714 | VisitExpr(E); |
| 715 | E->setProperty(cast<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++]))); |
| 716 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 717 | E->setBase(cast<Expr>(StmtStack.back())); |
| 718 | return 1; |
| 719 | } |
| 720 | |
| 721 | unsigned PCHStmtReader::VisitObjCKVCRefExpr(ObjCKVCRefExpr *E) { |
| 722 | VisitExpr(E); |
| 723 | E->setGetterMethod( |
| 724 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 725 | E->setSetterMethod( |
| 726 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 727 | E->setClassProp( |
| 728 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 729 | E->setBase(cast_or_null<Expr>(StmtStack.back())); |
| 730 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 731 | E->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 732 | return 1; |
| 733 | } |
| 734 | |
| 735 | unsigned PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { |
| 736 | VisitExpr(E); |
| 737 | E->setNumArgs(Record[Idx++]); |
| 738 | E->setLeftLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 739 | E->setRightLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 740 | E->setSelector(Reader.GetSelector(Record, Idx)); |
| 741 | E->setMethodDecl(cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 742 | |
| 743 | E->setReceiver( |
| 744 | cast_or_null<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1])); |
| 745 | if (!E->getReceiver()) { |
| 746 | ObjCMessageExpr::ClassInfo CI; |
| 747 | CI.first = cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])); |
| 748 | CI.second = Reader.GetIdentifierInfo(Record, Idx); |
| 749 | E->setClassInfo(CI); |
| 750 | } |
| 751 | |
| 752 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) |
| 753 | E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I])); |
| 754 | return E->getNumArgs() + 1; |
| 755 | } |
| 756 | |
| 757 | unsigned PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) { |
| 758 | VisitExpr(E); |
| 759 | E->setLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | unsigned PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 764 | VisitStmt(S); |
| 765 | S->setElement(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 3])); |
| 766 | S->setCollection(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 767 | S->setBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1])); |
| 768 | S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 769 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 770 | return 3; |
| 771 | } |
| 772 | |
| 773 | unsigned PCHStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 774 | VisitStmt(S); |
| 775 | S->setCatchBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 2])); |
| 776 | S->setNextCatchStmt(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1])); |
| 777 | S->setCatchParamDecl(cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 778 | S->setAtCatchLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 779 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 780 | return 2; |
| 781 | } |
| 782 | |
| 783 | unsigned PCHStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 784 | VisitStmt(S); |
| 785 | S->setFinallyBody(StmtStack.back()); |
| 786 | S->setAtFinallyLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 787 | return 1; |
| 788 | } |
| 789 | |
| 790 | unsigned PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 791 | VisitStmt(S); |
| 792 | S->setTryBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 3])); |
| 793 | S->setCatchStmts(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 2])); |
| 794 | S->setFinallyStmt(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1])); |
| 795 | S->setAtTryLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 796 | return 3; |
| 797 | } |
| 798 | |
| 799 | unsigned PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { |
| 800 | VisitStmt(S); |
| 801 | S->setSynchExpr(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 2])); |
| 802 | S->setSynchBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1])); |
| 803 | S->setAtSynchronizedLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 804 | return 2; |
| 805 | } |
| 806 | |
| 807 | unsigned PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 808 | VisitStmt(S); |
| 809 | S->setThrowExpr(StmtStack.back()); |
| 810 | S->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 811 | return 1; |
| 812 | } |
| 813 | |
| 814 | |
| 815 | Stmt *PCHReader::ReadStmt() { |
| 816 | // Within the bitstream, expressions are stored in Reverse Polish |
| 817 | // Notation, with each of the subexpressions preceding the |
| 818 | // expression they are stored in. To evaluate expressions, we |
| 819 | // continue reading expressions and placing them on the stack, with |
| 820 | // expressions having operands removing those operands from the |
| 821 | // stack. Evaluation terminates when we see a STMT_STOP record, and |
| 822 | // the single remaining expression on the stack is our result. |
| 823 | RecordData Record; |
| 824 | unsigned Idx; |
| 825 | llvm::SmallVector<Stmt *, 16> StmtStack; |
| 826 | PCHStmtReader Reader(*this, Record, Idx, StmtStack); |
| 827 | Stmt::EmptyShell Empty; |
| 828 | |
| 829 | while (true) { |
| 830 | unsigned Code = Stream.ReadCode(); |
| 831 | if (Code == llvm::bitc::END_BLOCK) { |
| 832 | if (Stream.ReadBlockEnd()) { |
| 833 | Error("Error at end of Source Manager block"); |
| 834 | return 0; |
| 835 | } |
| 836 | break; |
| 837 | } |
| 838 | |
| 839 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 840 | // No known subblocks, always skip them. |
| 841 | Stream.ReadSubBlockID(); |
| 842 | if (Stream.SkipBlock()) { |
| 843 | Error("Malformed block record"); |
| 844 | return 0; |
| 845 | } |
| 846 | continue; |
| 847 | } |
| 848 | |
| 849 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 850 | Stream.ReadAbbrevRecord(); |
| 851 | continue; |
| 852 | } |
| 853 | |
| 854 | Stmt *S = 0; |
| 855 | Idx = 0; |
| 856 | Record.clear(); |
| 857 | bool Finished = false; |
| 858 | switch ((pch::StmtCode)Stream.ReadRecord(Code, Record)) { |
| 859 | case pch::STMT_STOP: |
| 860 | Finished = true; |
| 861 | break; |
| 862 | |
| 863 | case pch::STMT_NULL_PTR: |
| 864 | S = 0; |
| 865 | break; |
| 866 | |
| 867 | case pch::STMT_NULL: |
| 868 | S = new (Context) NullStmt(Empty); |
| 869 | break; |
| 870 | |
| 871 | case pch::STMT_COMPOUND: |
| 872 | S = new (Context) CompoundStmt(Empty); |
| 873 | break; |
| 874 | |
| 875 | case pch::STMT_CASE: |
| 876 | S = new (Context) CaseStmt(Empty); |
| 877 | break; |
| 878 | |
| 879 | case pch::STMT_DEFAULT: |
| 880 | S = new (Context) DefaultStmt(Empty); |
| 881 | break; |
| 882 | |
| 883 | case pch::STMT_LABEL: |
| 884 | S = new (Context) LabelStmt(Empty); |
| 885 | break; |
| 886 | |
| 887 | case pch::STMT_IF: |
| 888 | S = new (Context) IfStmt(Empty); |
| 889 | break; |
| 890 | |
| 891 | case pch::STMT_SWITCH: |
| 892 | S = new (Context) SwitchStmt(Empty); |
| 893 | break; |
| 894 | |
| 895 | case pch::STMT_WHILE: |
| 896 | S = new (Context) WhileStmt(Empty); |
| 897 | break; |
| 898 | |
| 899 | case pch::STMT_DO: |
| 900 | S = new (Context) DoStmt(Empty); |
| 901 | break; |
| 902 | |
| 903 | case pch::STMT_FOR: |
| 904 | S = new (Context) ForStmt(Empty); |
| 905 | break; |
| 906 | |
| 907 | case pch::STMT_GOTO: |
| 908 | S = new (Context) GotoStmt(Empty); |
| 909 | break; |
| 910 | |
| 911 | case pch::STMT_INDIRECT_GOTO: |
| 912 | S = new (Context) IndirectGotoStmt(Empty); |
| 913 | break; |
| 914 | |
| 915 | case pch::STMT_CONTINUE: |
| 916 | S = new (Context) ContinueStmt(Empty); |
| 917 | break; |
| 918 | |
| 919 | case pch::STMT_BREAK: |
| 920 | S = new (Context) BreakStmt(Empty); |
| 921 | break; |
| 922 | |
| 923 | case pch::STMT_RETURN: |
| 924 | S = new (Context) ReturnStmt(Empty); |
| 925 | break; |
| 926 | |
| 927 | case pch::STMT_DECL: |
| 928 | S = new (Context) DeclStmt(Empty); |
| 929 | break; |
| 930 | |
| 931 | case pch::STMT_ASM: |
| 932 | S = new (Context) AsmStmt(Empty); |
| 933 | break; |
| 934 | |
| 935 | case pch::EXPR_PREDEFINED: |
| 936 | S = new (Context) PredefinedExpr(Empty); |
| 937 | break; |
| 938 | |
| 939 | case pch::EXPR_DECL_REF: |
| 940 | S = new (Context) DeclRefExpr(Empty); |
| 941 | break; |
| 942 | |
| 943 | case pch::EXPR_INTEGER_LITERAL: |
| 944 | S = new (Context) IntegerLiteral(Empty); |
| 945 | break; |
| 946 | |
| 947 | case pch::EXPR_FLOATING_LITERAL: |
| 948 | S = new (Context) FloatingLiteral(Empty); |
| 949 | break; |
| 950 | |
| 951 | case pch::EXPR_IMAGINARY_LITERAL: |
| 952 | S = new (Context) ImaginaryLiteral(Empty); |
| 953 | break; |
| 954 | |
| 955 | case pch::EXPR_STRING_LITERAL: |
| 956 | S = StringLiteral::CreateEmpty(Context, |
| 957 | Record[PCHStmtReader::NumExprFields + 1]); |
| 958 | break; |
| 959 | |
| 960 | case pch::EXPR_CHARACTER_LITERAL: |
| 961 | S = new (Context) CharacterLiteral(Empty); |
| 962 | break; |
| 963 | |
| 964 | case pch::EXPR_PAREN: |
| 965 | S = new (Context) ParenExpr(Empty); |
| 966 | break; |
| 967 | |
| 968 | case pch::EXPR_UNARY_OPERATOR: |
| 969 | S = new (Context) UnaryOperator(Empty); |
| 970 | break; |
| 971 | |
| 972 | case pch::EXPR_SIZEOF_ALIGN_OF: |
| 973 | S = new (Context) SizeOfAlignOfExpr(Empty); |
| 974 | break; |
| 975 | |
| 976 | case pch::EXPR_ARRAY_SUBSCRIPT: |
| 977 | S = new (Context) ArraySubscriptExpr(Empty); |
| 978 | break; |
| 979 | |
| 980 | case pch::EXPR_CALL: |
| 981 | S = new (Context) CallExpr(Context, Empty); |
| 982 | break; |
| 983 | |
| 984 | case pch::EXPR_MEMBER: |
| 985 | S = new (Context) MemberExpr(Empty); |
| 986 | break; |
| 987 | |
| 988 | case pch::EXPR_BINARY_OPERATOR: |
| 989 | S = new (Context) BinaryOperator(Empty); |
| 990 | break; |
| 991 | |
| 992 | case pch::EXPR_COMPOUND_ASSIGN_OPERATOR: |
| 993 | S = new (Context) CompoundAssignOperator(Empty); |
| 994 | break; |
| 995 | |
| 996 | case pch::EXPR_CONDITIONAL_OPERATOR: |
| 997 | S = new (Context) ConditionalOperator(Empty); |
| 998 | break; |
| 999 | |
| 1000 | case pch::EXPR_IMPLICIT_CAST: |
| 1001 | S = new (Context) ImplicitCastExpr(Empty); |
| 1002 | break; |
| 1003 | |
| 1004 | case pch::EXPR_CSTYLE_CAST: |
| 1005 | S = new (Context) CStyleCastExpr(Empty); |
| 1006 | break; |
| 1007 | |
| 1008 | case pch::EXPR_COMPOUND_LITERAL: |
| 1009 | S = new (Context) CompoundLiteralExpr(Empty); |
| 1010 | break; |
| 1011 | |
| 1012 | case pch::EXPR_EXT_VECTOR_ELEMENT: |
| 1013 | S = new (Context) ExtVectorElementExpr(Empty); |
| 1014 | break; |
| 1015 | |
| 1016 | case pch::EXPR_INIT_LIST: |
| 1017 | S = new (Context) InitListExpr(Empty); |
| 1018 | break; |
| 1019 | |
| 1020 | case pch::EXPR_DESIGNATED_INIT: |
| 1021 | S = DesignatedInitExpr::CreateEmpty(Context, |
| 1022 | Record[PCHStmtReader::NumExprFields] - 1); |
| 1023 | |
| 1024 | break; |
| 1025 | |
| 1026 | case pch::EXPR_IMPLICIT_VALUE_INIT: |
| 1027 | S = new (Context) ImplicitValueInitExpr(Empty); |
| 1028 | break; |
| 1029 | |
| 1030 | case pch::EXPR_VA_ARG: |
| 1031 | S = new (Context) VAArgExpr(Empty); |
| 1032 | break; |
| 1033 | |
| 1034 | case pch::EXPR_ADDR_LABEL: |
| 1035 | S = new (Context) AddrLabelExpr(Empty); |
| 1036 | break; |
| 1037 | |
| 1038 | case pch::EXPR_STMT: |
| 1039 | S = new (Context) StmtExpr(Empty); |
| 1040 | break; |
| 1041 | |
| 1042 | case pch::EXPR_TYPES_COMPATIBLE: |
| 1043 | S = new (Context) TypesCompatibleExpr(Empty); |
| 1044 | break; |
| 1045 | |
| 1046 | case pch::EXPR_CHOOSE: |
| 1047 | S = new (Context) ChooseExpr(Empty); |
| 1048 | break; |
| 1049 | |
| 1050 | case pch::EXPR_GNU_NULL: |
| 1051 | S = new (Context) GNUNullExpr(Empty); |
| 1052 | break; |
| 1053 | |
| 1054 | case pch::EXPR_SHUFFLE_VECTOR: |
| 1055 | S = new (Context) ShuffleVectorExpr(Empty); |
| 1056 | break; |
| 1057 | |
| 1058 | case pch::EXPR_BLOCK: |
| 1059 | S = new (Context) BlockExpr(Empty); |
| 1060 | break; |
| 1061 | |
| 1062 | case pch::EXPR_BLOCK_DECL_REF: |
| 1063 | S = new (Context) BlockDeclRefExpr(Empty); |
| 1064 | break; |
| 1065 | |
| 1066 | case pch::EXPR_OBJC_STRING_LITERAL: |
| 1067 | S = new (Context) ObjCStringLiteral(Empty); |
| 1068 | break; |
| 1069 | case pch::EXPR_OBJC_ENCODE: |
| 1070 | S = new (Context) ObjCEncodeExpr(Empty); |
| 1071 | break; |
| 1072 | case pch::EXPR_OBJC_SELECTOR_EXPR: |
| 1073 | S = new (Context) ObjCSelectorExpr(Empty); |
| 1074 | break; |
| 1075 | case pch::EXPR_OBJC_PROTOCOL_EXPR: |
| 1076 | S = new (Context) ObjCProtocolExpr(Empty); |
| 1077 | break; |
| 1078 | case pch::EXPR_OBJC_IVAR_REF_EXPR: |
| 1079 | S = new (Context) ObjCIvarRefExpr(Empty); |
| 1080 | break; |
| 1081 | case pch::EXPR_OBJC_PROPERTY_REF_EXPR: |
| 1082 | S = new (Context) ObjCPropertyRefExpr(Empty); |
| 1083 | break; |
| 1084 | case pch::EXPR_OBJC_KVC_REF_EXPR: |
| 1085 | S = new (Context) ObjCKVCRefExpr(Empty); |
| 1086 | break; |
| 1087 | case pch::EXPR_OBJC_MESSAGE_EXPR: |
| 1088 | S = new (Context) ObjCMessageExpr(Empty); |
| 1089 | break; |
| 1090 | case pch::EXPR_OBJC_SUPER_EXPR: |
| 1091 | S = new (Context) ObjCSuperExpr(Empty); |
| 1092 | break; |
| 1093 | case pch::STMT_OBJC_FOR_COLLECTION: |
| 1094 | S = new (Context) ObjCForCollectionStmt(Empty); |
| 1095 | break; |
| 1096 | case pch::STMT_OBJC_CATCH: |
| 1097 | S = new (Context) ObjCAtCatchStmt(Empty); |
| 1098 | break; |
| 1099 | case pch::STMT_OBJC_FINALLY: |
| 1100 | S = new (Context) ObjCAtFinallyStmt(Empty); |
| 1101 | break; |
| 1102 | case pch::STMT_OBJC_AT_TRY: |
| 1103 | S = new (Context) ObjCAtTryStmt(Empty); |
| 1104 | break; |
| 1105 | case pch::STMT_OBJC_AT_SYNCHRONIZED: |
| 1106 | S = new (Context) ObjCAtSynchronizedStmt(Empty); |
| 1107 | break; |
| 1108 | case pch::STMT_OBJC_AT_THROW: |
| 1109 | S = new (Context) ObjCAtThrowStmt(Empty); |
| 1110 | break; |
| 1111 | } |
| 1112 | |
| 1113 | // We hit a STMT_STOP, so we're done with this expression. |
| 1114 | if (Finished) |
| 1115 | break; |
| 1116 | |
| 1117 | ++NumStatementsRead; |
| 1118 | |
| 1119 | if (S) { |
| 1120 | unsigned NumSubStmts = Reader.Visit(S); |
| 1121 | while (NumSubStmts > 0) { |
| 1122 | StmtStack.pop_back(); |
| 1123 | --NumSubStmts; |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | assert(Idx == Record.size() && "Invalid deserialization of statement"); |
| 1128 | StmtStack.push_back(S); |
| 1129 | } |
| 1130 | assert(StmtStack.size() == 1 && "Extra expressions on stack!"); |
| 1131 | SwitchCaseStmts.clear(); |
| 1132 | return StmtStack.back(); |
| 1133 | } |
| 1134 | |