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