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