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