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); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 74 | unsigned VisitOffsetOfExpr(OffsetOfExpr *E); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 75 | unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); |
| 76 | unsigned VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 77 | unsigned VisitCallExpr(CallExpr *E); |
| 78 | unsigned VisitMemberExpr(MemberExpr *E); |
| 79 | unsigned VisitCastExpr(CastExpr *E); |
| 80 | unsigned VisitBinaryOperator(BinaryOperator *E); |
| 81 | unsigned VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 82 | unsigned VisitConditionalOperator(ConditionalOperator *E); |
| 83 | unsigned VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 84 | unsigned VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 85 | unsigned VisitCStyleCastExpr(CStyleCastExpr *E); |
| 86 | unsigned VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 87 | unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E); |
| 88 | unsigned VisitInitListExpr(InitListExpr *E); |
| 89 | unsigned VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 90 | unsigned VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 91 | unsigned VisitVAArgExpr(VAArgExpr *E); |
| 92 | unsigned VisitAddrLabelExpr(AddrLabelExpr *E); |
| 93 | unsigned VisitStmtExpr(StmtExpr *E); |
| 94 | unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr *E); |
| 95 | unsigned VisitChooseExpr(ChooseExpr *E); |
| 96 | unsigned VisitGNUNullExpr(GNUNullExpr *E); |
| 97 | unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E); |
| 98 | unsigned VisitBlockExpr(BlockExpr *E); |
| 99 | unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E); |
| 100 | unsigned VisitObjCStringLiteral(ObjCStringLiteral *E); |
| 101 | unsigned VisitObjCEncodeExpr(ObjCEncodeExpr *E); |
| 102 | unsigned VisitObjCSelectorExpr(ObjCSelectorExpr *E); |
| 103 | unsigned VisitObjCProtocolExpr(ObjCProtocolExpr *E); |
| 104 | unsigned VisitObjCIvarRefExpr(ObjCIvarRefExpr *E); |
| 105 | unsigned VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E); |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 106 | unsigned VisitObjCImplicitSetterGetterRefExpr( |
| 107 | ObjCImplicitSetterGetterRefExpr *E); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 108 | unsigned VisitObjCMessageExpr(ObjCMessageExpr *E); |
| 109 | unsigned VisitObjCSuperExpr(ObjCSuperExpr *E); |
Steve Naroff | f242b1b | 2009-07-24 17:54:45 +0000 | [diff] [blame] | 110 | unsigned VisitObjCIsaExpr(ObjCIsaExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 112 | unsigned VisitObjCForCollectionStmt(ObjCForCollectionStmt *); |
| 113 | unsigned VisitObjCAtCatchStmt(ObjCAtCatchStmt *); |
| 114 | unsigned VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *); |
| 115 | unsigned VisitObjCAtTryStmt(ObjCAtTryStmt *); |
| 116 | unsigned VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *); |
| 117 | unsigned VisitObjCAtThrowStmt(ObjCAtThrowStmt *); |
Argyrios Kyrtzidis | ba0a900 | 2009-07-14 03:19:21 +0000 | [diff] [blame] | 118 | |
| 119 | unsigned VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E); |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 120 | unsigned VisitCXXConstructExpr(CXXConstructExpr *E); |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 121 | unsigned VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 122 | unsigned VisitCXXStaticCastExpr(CXXStaticCastExpr *E); |
| 123 | unsigned VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E); |
| 124 | unsigned VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E); |
| 125 | unsigned VisitCXXConstCastExpr(CXXConstCastExpr *E); |
| 126 | unsigned VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 127 | unsigned VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 128 | unsigned VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Chris Lattner | 14ab24f | 2010-05-09 06:03:39 +0000 | [diff] [blame] | 129 | unsigned VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Chris Lattner | 2fbdfcd | 2010-05-09 06:15:05 +0000 | [diff] [blame] | 130 | unsigned VisitCXXThisExpr(CXXThisExpr *E); |
| 131 | unsigned VisitCXXThrowExpr(CXXThrowExpr *E); |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 132 | unsigned VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 133 | unsigned VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 134 | |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 135 | unsigned VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E); |
| 136 | unsigned VisitCXXNewExpr(CXXNewExpr *E); |
Argyrios Kyrtzidis | 95fc98c | 2010-06-22 17:07:59 +0000 | [diff] [blame] | 137 | unsigned VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 138 | |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 139 | unsigned VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 140 | |
| 141 | unsigned VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 142 | unsigned VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 143 | |
| 144 | unsigned VisitOverloadExpr(OverloadExpr *E); |
| 145 | unsigned VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 146 | unsigned VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 147 | }; |
| 148 | } |
| 149 | |
| 150 | unsigned PCHStmtReader::VisitStmt(Stmt *S) { |
| 151 | assert(Idx == NumStmtFields && "Incorrect statement field count"); |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | unsigned PCHStmtReader::VisitNullStmt(NullStmt *S) { |
| 156 | VisitStmt(S); |
| 157 | S->setSemiLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | unsigned PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) { |
| 162 | VisitStmt(S); |
| 163 | unsigned NumStmts = Record[Idx++]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 164 | S->setStmts(*Reader.getContext(), |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 165 | StmtStack.data() + StmtStack.size() - NumStmts, NumStmts); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 166 | S->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 167 | S->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 168 | return NumStmts; |
| 169 | } |
| 170 | |
| 171 | unsigned PCHStmtReader::VisitSwitchCase(SwitchCase *S) { |
| 172 | VisitStmt(S); |
| 173 | Reader.RecordSwitchCaseID(S, Record[Idx++]); |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | unsigned PCHStmtReader::VisitCaseStmt(CaseStmt *S) { |
| 178 | VisitSwitchCase(S); |
| 179 | S->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 180 | S->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 181 | S->setSubStmt(StmtStack.back()); |
| 182 | S->setCaseLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | dbb26db | 2009-05-15 23:57:33 +0000 | [diff] [blame] | 183 | S->setEllipsisLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 184 | S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 185 | return 3; |
| 186 | } |
| 187 | |
| 188 | unsigned PCHStmtReader::VisitDefaultStmt(DefaultStmt *S) { |
| 189 | VisitSwitchCase(S); |
| 190 | S->setSubStmt(StmtStack.back()); |
| 191 | S->setDefaultLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | dbb26db | 2009-05-15 23:57:33 +0000 | [diff] [blame] | 192 | S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 193 | return 1; |
| 194 | } |
| 195 | |
| 196 | unsigned PCHStmtReader::VisitLabelStmt(LabelStmt *S) { |
| 197 | VisitStmt(S); |
| 198 | S->setID(Reader.GetIdentifierInfo(Record, Idx)); |
| 199 | S->setSubStmt(StmtStack.back()); |
| 200 | S->setIdentLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 201 | Reader.RecordLabelStmt(S, Record[Idx++]); |
| 202 | return 1; |
| 203 | } |
| 204 | |
| 205 | unsigned PCHStmtReader::VisitIfStmt(IfStmt *S) { |
| 206 | VisitStmt(S); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 207 | S->setConditionVariable(*Reader.getContext(), |
| 208 | cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 209 | S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 210 | S->setThen(StmtStack[StmtStack.size() - 2]); |
| 211 | S->setElse(StmtStack[StmtStack.size() - 1]); |
| 212 | S->setIfLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | d06f6ca | 2009-05-15 18:53:42 +0000 | [diff] [blame] | 213 | S->setElseLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 214 | return 3; |
| 215 | } |
| 216 | |
| 217 | unsigned PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) { |
| 218 | VisitStmt(S); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 219 | S->setConditionVariable(*Reader.getContext(), |
| 220 | cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 221 | S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 2])); |
| 222 | S->setBody(StmtStack.back()); |
| 223 | S->setSwitchLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 224 | SwitchCase *PrevSC = 0; |
| 225 | for (unsigned N = Record.size(); Idx != N; ++Idx) { |
| 226 | SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]); |
| 227 | if (PrevSC) |
| 228 | PrevSC->setNextSwitchCase(SC); |
| 229 | else |
| 230 | S->setSwitchCaseList(SC); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 231 | |
Douglas Gregor | 43d9d92 | 2009-08-08 01:41:12 +0000 | [diff] [blame] | 232 | // Retain this SwitchCase, since SwitchStmt::addSwitchCase() would |
| 233 | // normally retain it (but we aren't calling addSwitchCase). |
| 234 | SC->Retain(); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 235 | PrevSC = SC; |
| 236 | } |
| 237 | return 2; |
| 238 | } |
| 239 | |
| 240 | unsigned PCHStmtReader::VisitWhileStmt(WhileStmt *S) { |
| 241 | VisitStmt(S); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 242 | S->setConditionVariable(*Reader.getContext(), |
| 243 | cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 244 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 245 | S->setBody(StmtStack.back()); |
| 246 | S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 247 | return 2; |
| 248 | } |
| 249 | |
| 250 | unsigned PCHStmtReader::VisitDoStmt(DoStmt *S) { |
| 251 | VisitStmt(S); |
| 252 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 253 | S->setBody(StmtStack.back()); |
| 254 | S->setDoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 9f3ca2a | 2009-05-15 21:56:04 +0000 | [diff] [blame] | 255 | S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 9891359 | 2009-06-12 23:04:47 +0000 | [diff] [blame] | 256 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 257 | return 2; |
| 258 | } |
| 259 | |
| 260 | unsigned PCHStmtReader::VisitForStmt(ForStmt *S) { |
| 261 | VisitStmt(S); |
| 262 | S->setInit(StmtStack[StmtStack.size() - 4]); |
| 263 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 3])); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 264 | S->setConditionVariable(*Reader.getContext(), |
| 265 | cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 266 | S->setInc(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 267 | S->setBody(StmtStack.back()); |
| 268 | S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 5831c6a | 2009-05-15 22:12:32 +0000 | [diff] [blame] | 269 | S->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 270 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 271 | return 4; |
| 272 | } |
| 273 | |
| 274 | unsigned PCHStmtReader::VisitGotoStmt(GotoStmt *S) { |
| 275 | VisitStmt(S); |
| 276 | Reader.SetLabelOf(S, Record[Idx++]); |
| 277 | S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 278 | S->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 283 | VisitStmt(S); |
| 284 | S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 5f1b9e6 | 2009-05-16 00:20:29 +0000 | [diff] [blame] | 285 | S->setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 286 | S->setTarget(cast_or_null<Expr>(StmtStack.back())); |
| 287 | return 1; |
| 288 | } |
| 289 | |
| 290 | unsigned PCHStmtReader::VisitContinueStmt(ContinueStmt *S) { |
| 291 | VisitStmt(S); |
| 292 | S->setContinueLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | unsigned PCHStmtReader::VisitBreakStmt(BreakStmt *S) { |
| 297 | VisitStmt(S); |
| 298 | S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) { |
| 303 | VisitStmt(S); |
| 304 | S->setRetValue(cast_or_null<Expr>(StmtStack.back())); |
| 305 | S->setReturnLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 5077c38 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 306 | S->setNRVOCandidate(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 307 | return 1; |
| 308 | } |
| 309 | |
| 310 | unsigned PCHStmtReader::VisitDeclStmt(DeclStmt *S) { |
| 311 | VisitStmt(S); |
| 312 | S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 313 | S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 314 | |
| 315 | if (Idx + 1 == Record.size()) { |
| 316 | // Single declaration |
| 317 | S->setDeclGroup(DeclGroupRef(Reader.GetDecl(Record[Idx++]))); |
| 318 | } else { |
| 319 | llvm::SmallVector<Decl *, 16> Decls; |
| 320 | Decls.reserve(Record.size() - Idx); |
| 321 | for (unsigned N = Record.size(); Idx != N; ++Idx) |
| 322 | Decls.push_back(Reader.GetDecl(Record[Idx])); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 323 | S->setDeclGroup(DeclGroupRef(DeclGroup::Create(*Reader.getContext(), |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 324 | Decls.data(), |
| 325 | Decls.size()))); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 326 | } |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | unsigned PCHStmtReader::VisitAsmStmt(AsmStmt *S) { |
| 331 | VisitStmt(S); |
| 332 | unsigned NumOutputs = Record[Idx++]; |
| 333 | unsigned NumInputs = Record[Idx++]; |
| 334 | unsigned NumClobbers = Record[Idx++]; |
| 335 | S->setAsmLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 336 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 337 | S->setVolatile(Record[Idx++]); |
| 338 | S->setSimple(Record[Idx++]); |
Mike Stump | 3b11fd3 | 2010-01-04 22:37:17 +0000 | [diff] [blame] | 339 | S->setMSAsm(Record[Idx++]); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 340 | |
| 341 | unsigned StackIdx |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 342 | = StmtStack.size() - (NumOutputs*2 + NumInputs*2 + NumClobbers + 1); |
| 343 | S->setAsmString(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 344 | |
| 345 | // Outputs and inputs |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 346 | llvm::SmallVector<IdentifierInfo *, 16> Names; |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 347 | llvm::SmallVector<StringLiteral*, 16> Constraints; |
| 348 | llvm::SmallVector<Stmt*, 16> Exprs; |
| 349 | for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 350 | Names.push_back(Reader.GetIdentifierInfo(Record, Idx)); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 351 | Constraints.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 352 | Exprs.push_back(StmtStack[StackIdx++]); |
| 353 | } |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 354 | |
| 355 | // Constraints |
| 356 | llvm::SmallVector<StringLiteral*, 16> Clobbers; |
| 357 | for (unsigned I = 0; I != NumClobbers; ++I) |
| 358 | Clobbers.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
Anders Carlsson | fdba9c0 | 2010-01-30 19:34:25 +0000 | [diff] [blame] | 359 | |
Anders Carlsson | acb6bcb | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 360 | S->setOutputsAndInputsAndClobbers(*Reader.getContext(), |
| 361 | Names.data(), Constraints.data(), |
Anders Carlsson | fdba9c0 | 2010-01-30 19:34:25 +0000 | [diff] [blame] | 362 | Exprs.data(), NumOutputs, NumInputs, |
| 363 | Clobbers.data(), NumClobbers); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 364 | |
| 365 | assert(StackIdx == StmtStack.size() && "Error deserializing AsmStmt"); |
| 366 | return NumOutputs*2 + NumInputs*2 + NumClobbers + 1; |
| 367 | } |
| 368 | |
| 369 | unsigned PCHStmtReader::VisitExpr(Expr *E) { |
| 370 | VisitStmt(E); |
| 371 | E->setType(Reader.GetType(Record[Idx++])); |
| 372 | E->setTypeDependent(Record[Idx++]); |
| 373 | E->setValueDependent(Record[Idx++]); |
| 374 | assert(Idx == NumExprFields && "Incorrect expression field count"); |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | unsigned PCHStmtReader::VisitPredefinedExpr(PredefinedExpr *E) { |
| 379 | VisitExpr(E); |
| 380 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 381 | E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]); |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | unsigned PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) { |
| 386 | VisitExpr(E); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 387 | E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 388 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 389 | // FIXME: read qualifier |
| 390 | // FIXME: read explicit template arguments |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | unsigned PCHStmtReader::VisitIntegerLiteral(IntegerLiteral *E) { |
| 395 | VisitExpr(E); |
| 396 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 397 | E->setValue(Reader.ReadAPInt(Record, Idx)); |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | unsigned PCHStmtReader::VisitFloatingLiteral(FloatingLiteral *E) { |
| 402 | VisitExpr(E); |
| 403 | E->setValue(Reader.ReadAPFloat(Record, Idx)); |
| 404 | E->setExact(Record[Idx++]); |
| 405 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | unsigned PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 410 | VisitExpr(E); |
| 411 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 412 | return 1; |
| 413 | } |
| 414 | |
| 415 | unsigned PCHStmtReader::VisitStringLiteral(StringLiteral *E) { |
| 416 | VisitExpr(E); |
| 417 | unsigned Len = Record[Idx++]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 418 | assert(Record[Idx] == E->getNumConcatenated() && |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 419 | "Wrong number of concatenated tokens!"); |
| 420 | ++Idx; |
| 421 | E->setWide(Record[Idx++]); |
| 422 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | // Read string data |
Daniel Dunbar | b648023 | 2009-09-22 03:27:33 +0000 | [diff] [blame] | 424 | llvm::SmallString<16> Str(&Record[Idx], &Record[Idx] + Len); |
| 425 | E->setString(*Reader.getContext(), Str.str()); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 426 | Idx += Len; |
| 427 | |
| 428 | // Read source locations |
| 429 | for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) |
| 430 | E->setStrTokenLoc(I, SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 431 | |
| 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | unsigned PCHStmtReader::VisitCharacterLiteral(CharacterLiteral *E) { |
| 436 | VisitExpr(E); |
| 437 | E->setValue(Record[Idx++]); |
| 438 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 439 | E->setWide(Record[Idx++]); |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | unsigned PCHStmtReader::VisitParenExpr(ParenExpr *E) { |
| 444 | VisitExpr(E); |
| 445 | E->setLParen(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 446 | E->setRParen(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 447 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 448 | return 1; |
| 449 | } |
| 450 | |
| 451 | unsigned PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) { |
| 452 | VisitExpr(E); |
| 453 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 454 | E->setOpcode((UnaryOperator::Opcode)Record[Idx++]); |
| 455 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 456 | return 1; |
| 457 | } |
| 458 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 459 | unsigned PCHStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 460 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 461 | VisitExpr(E); |
| 462 | assert(E->getNumComponents() == Record[Idx]); |
| 463 | ++Idx; |
| 464 | assert(E->getNumExpressions() == Record[Idx]); |
| 465 | ++Idx; |
| 466 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 467 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 468 | E->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx)); |
| 469 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 470 | Node::Kind Kind = static_cast<Node::Kind>(Record[Idx++]); |
| 471 | SourceLocation Start = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 472 | SourceLocation End = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 473 | switch (Kind) { |
| 474 | case Node::Array: |
| 475 | E->setComponent(I, Node(Start, Record[Idx++], End)); |
| 476 | break; |
| 477 | |
| 478 | case Node::Field: |
| 479 | E->setComponent(I, |
| 480 | Node(Start, |
| 481 | dyn_cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++])), |
| 482 | End)); |
| 483 | break; |
| 484 | |
| 485 | case Node::Identifier: |
| 486 | E->setComponent(I, Node(Start, Reader.GetIdentifier(Record[Idx++]), End)); |
| 487 | break; |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 488 | |
| 489 | case Node::Base: |
| 490 | // FIXME: Implement this! |
| 491 | llvm_unreachable("PCH for offsetof(base-specifier) not implemented"); |
| 492 | break; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
| 496 | for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I) |
| 497 | E->setIndexExpr(I, cast_or_null<Expr>(StmtStack[StmtStack.size() - N + I])); |
| 498 | |
| 499 | return E->getNumExpressions(); |
| 500 | } |
| 501 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 502 | unsigned PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
| 503 | VisitExpr(E); |
| 504 | E->setSizeof(Record[Idx++]); |
| 505 | if (Record[Idx] == 0) { |
| 506 | E->setArgument(cast<Expr>(StmtStack.back())); |
| 507 | ++Idx; |
| 508 | } else { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 509 | E->setArgument(Reader.GetTypeSourceInfo(Record, Idx)); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 510 | } |
| 511 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 512 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 513 | return E->isArgumentType()? 0 : 1; |
| 514 | } |
| 515 | |
| 516 | unsigned PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 517 | VisitExpr(E); |
| 518 | E->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 2])); |
| 519 | E->setRHS(cast<Expr>(StmtStack[StmtStack.size() - 1])); |
| 520 | E->setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 521 | return 2; |
| 522 | } |
| 523 | |
| 524 | unsigned PCHStmtReader::VisitCallExpr(CallExpr *E) { |
| 525 | VisitExpr(E); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 526 | E->setNumArgs(*Reader.getContext(), Record[Idx++]); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 527 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 528 | E->setCallee(cast<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1])); |
| 529 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) |
| 530 | E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I])); |
| 531 | return E->getNumArgs() + 1; |
| 532 | } |
| 533 | |
| 534 | unsigned PCHStmtReader::VisitMemberExpr(MemberExpr *E) { |
| 535 | VisitExpr(E); |
| 536 | E->setBase(cast<Expr>(StmtStack.back())); |
Eli Friedman | dd27a2d | 2009-12-04 06:46:54 +0000 | [diff] [blame] | 537 | E->setMemberDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 538 | E->setMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 539 | E->setArrow(Record[Idx++]); |
| 540 | return 1; |
| 541 | } |
| 542 | |
Steve Naroff | f242b1b | 2009-07-24 17:54:45 +0000 | [diff] [blame] | 543 | unsigned PCHStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) { |
| 544 | VisitExpr(E); |
| 545 | E->setBase(cast<Expr>(StmtStack.back())); |
| 546 | E->setIsaMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 547 | E->setArrow(Record[Idx++]); |
| 548 | return 1; |
| 549 | } |
| 550 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 551 | unsigned PCHStmtReader::VisitCastExpr(CastExpr *E) { |
| 552 | VisitExpr(E); |
| 553 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Anders Carlsson | cdef2b7 | 2009-07-31 00:48:10 +0000 | [diff] [blame] | 554 | E->setCastKind((CastExpr::CastKind)Record[Idx++]); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 555 | return 1; |
| 556 | } |
| 557 | |
| 558 | unsigned PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) { |
| 559 | VisitExpr(E); |
| 560 | E->setLHS(cast<Expr>(StmtStack.end()[-2])); |
| 561 | E->setRHS(cast<Expr>(StmtStack.end()[-1])); |
| 562 | E->setOpcode((BinaryOperator::Opcode)Record[Idx++]); |
| 563 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 564 | return 2; |
| 565 | } |
| 566 | |
| 567 | unsigned PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 568 | VisitBinaryOperator(E); |
| 569 | E->setComputationLHSType(Reader.GetType(Record[Idx++])); |
| 570 | E->setComputationResultType(Reader.GetType(Record[Idx++])); |
| 571 | return 2; |
| 572 | } |
| 573 | |
| 574 | unsigned PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) { |
| 575 | VisitExpr(E); |
| 576 | E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 577 | E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 578 | E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1])); |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 579 | E->setQuestionLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 580 | E->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 581 | return 3; |
| 582 | } |
| 583 | |
| 584 | unsigned PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 585 | VisitCastExpr(E); |
| 586 | E->setLvalueCast(Record[Idx++]); |
| 587 | return 1; |
| 588 | } |
| 589 | |
| 590 | unsigned PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 591 | VisitCastExpr(E); |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 592 | E->setTypeInfoAsWritten(Reader.GetTypeSourceInfo(Record, Idx)); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 593 | return 1; |
| 594 | } |
| 595 | |
| 596 | unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) { |
| 597 | VisitExplicitCastExpr(E); |
| 598 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 599 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 600 | return 1; |
| 601 | } |
| 602 | |
| 603 | unsigned PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 604 | VisitExpr(E); |
| 605 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 606 | E->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx)); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 607 | E->setInitializer(cast<Expr>(StmtStack.back())); |
| 608 | E->setFileScope(Record[Idx++]); |
| 609 | return 1; |
| 610 | } |
| 611 | |
| 612 | unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { |
| 613 | VisitExpr(E); |
| 614 | E->setBase(cast<Expr>(StmtStack.back())); |
| 615 | E->setAccessor(Reader.GetIdentifierInfo(Record, Idx)); |
| 616 | E->setAccessorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 617 | return 1; |
| 618 | } |
| 619 | |
| 620 | unsigned PCHStmtReader::VisitInitListExpr(InitListExpr *E) { |
| 621 | VisitExpr(E); |
| 622 | unsigned NumInits = Record[Idx++]; |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 623 | E->reserveInits(*Reader.getContext(), NumInits); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 624 | for (unsigned I = 0; I != NumInits; ++I) |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 625 | E->updateInit(*Reader.getContext(), I, |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 626 | cast<Expr>(StmtStack[StmtStack.size() - NumInits - 1 + I])); |
| 627 | E->setSyntacticForm(cast_or_null<InitListExpr>(StmtStack.back())); |
| 628 | E->setLBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 629 | E->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 630 | E->setInitializedFieldInUnion( |
| 631 | cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]))); |
| 632 | E->sawArrayRangeDesignator(Record[Idx++]); |
| 633 | return NumInits + 1; |
| 634 | } |
| 635 | |
| 636 | unsigned PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 637 | typedef DesignatedInitExpr::Designator Designator; |
| 638 | |
| 639 | VisitExpr(E); |
| 640 | unsigned NumSubExprs = Record[Idx++]; |
| 641 | assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs"); |
| 642 | for (unsigned I = 0; I != NumSubExprs; ++I) |
| 643 | E->setSubExpr(I, cast<Expr>(StmtStack[StmtStack.size() - NumSubExprs + I])); |
| 644 | E->setEqualOrColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 645 | E->setGNUSyntax(Record[Idx++]); |
| 646 | |
| 647 | llvm::SmallVector<Designator, 4> Designators; |
| 648 | while (Idx < Record.size()) { |
| 649 | switch ((pch::DesignatorTypes)Record[Idx++]) { |
| 650 | case pch::DESIG_FIELD_DECL: { |
| 651 | FieldDecl *Field = cast<FieldDecl>(Reader.GetDecl(Record[Idx++])); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 652 | SourceLocation DotLoc |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 653 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 654 | SourceLocation FieldLoc |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 655 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 656 | Designators.push_back(Designator(Field->getIdentifier(), DotLoc, |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 657 | FieldLoc)); |
| 658 | Designators.back().setField(Field); |
| 659 | break; |
| 660 | } |
| 661 | |
| 662 | case pch::DESIG_FIELD_NAME: { |
| 663 | const IdentifierInfo *Name = Reader.GetIdentifierInfo(Record, Idx); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | SourceLocation DotLoc |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 665 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | SourceLocation FieldLoc |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 667 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 668 | Designators.push_back(Designator(Name, DotLoc, FieldLoc)); |
| 669 | break; |
| 670 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 672 | case pch::DESIG_ARRAY: { |
| 673 | unsigned Index = Record[Idx++]; |
| 674 | SourceLocation LBracketLoc |
| 675 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 676 | SourceLocation RBracketLoc |
| 677 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 678 | Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc)); |
| 679 | break; |
| 680 | } |
| 681 | |
| 682 | case pch::DESIG_ARRAY_RANGE: { |
| 683 | unsigned Index = Record[Idx++]; |
| 684 | SourceLocation LBracketLoc |
| 685 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 686 | SourceLocation EllipsisLoc |
| 687 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 688 | SourceLocation RBracketLoc |
| 689 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 690 | Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc, |
| 691 | RBracketLoc)); |
| 692 | break; |
| 693 | } |
| 694 | } |
| 695 | } |
Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 696 | E->setDesignators(*Reader.getContext(), |
| 697 | Designators.data(), Designators.size()); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 698 | |
| 699 | return NumSubExprs; |
| 700 | } |
| 701 | |
| 702 | unsigned PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 703 | VisitExpr(E); |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | unsigned PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) { |
| 708 | VisitExpr(E); |
| 709 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 710 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 711 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 712 | return 1; |
| 713 | } |
| 714 | |
| 715 | unsigned PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 716 | VisitExpr(E); |
| 717 | E->setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 718 | E->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 719 | Reader.SetLabelOf(E, Record[Idx++]); |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | unsigned PCHStmtReader::VisitStmtExpr(StmtExpr *E) { |
| 724 | VisitExpr(E); |
| 725 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 726 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 727 | E->setSubStmt(cast_or_null<CompoundStmt>(StmtStack.back())); |
| 728 | return 1; |
| 729 | } |
| 730 | |
| 731 | unsigned PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { |
| 732 | VisitExpr(E); |
| 733 | E->setArgType1(Reader.GetType(Record[Idx++])); |
| 734 | E->setArgType2(Reader.GetType(Record[Idx++])); |
| 735 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 736 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | unsigned PCHStmtReader::VisitChooseExpr(ChooseExpr *E) { |
| 741 | VisitExpr(E); |
| 742 | E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 743 | E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 744 | E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1])); |
| 745 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 746 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 747 | return 3; |
| 748 | } |
| 749 | |
| 750 | unsigned PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) { |
| 751 | VisitExpr(E); |
| 752 | E->setTokenLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | unsigned PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { |
| 757 | VisitExpr(E); |
| 758 | unsigned NumExprs = Record[Idx++]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 759 | E->setExprs(*Reader.getContext(), |
Nate Begeman | 888376a | 2009-08-12 02:28:50 +0000 | [diff] [blame] | 760 | (Expr **)&StmtStack[StmtStack.size() - NumExprs], NumExprs); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 761 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 762 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 763 | return NumExprs; |
| 764 | } |
| 765 | |
| 766 | unsigned PCHStmtReader::VisitBlockExpr(BlockExpr *E) { |
| 767 | VisitExpr(E); |
| 768 | E->setBlockDecl(cast_or_null<BlockDecl>(Reader.GetDecl(Record[Idx++]))); |
| 769 | E->setHasBlockDeclRefExprs(Record[Idx++]); |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | unsigned PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { |
| 774 | VisitExpr(E); |
| 775 | E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++]))); |
| 776 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 777 | E->setByRef(Record[Idx++]); |
Fariborz Jahanian | 9b0b57c | 2009-06-20 00:02:26 +0000 | [diff] [blame] | 778 | E->setConstQualAdded(Record[Idx++]); |
Fariborz Jahanian | 89f9d3a | 2010-06-04 19:06:53 +0000 | [diff] [blame] | 779 | E->setCopyConstructorExpr(cast_or_null<Expr>(StmtStack.back())); |
| 780 | return 1; |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | //===----------------------------------------------------------------------===// |
| 784 | // Objective-C Expressions and Statements |
| 785 | |
| 786 | unsigned PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) { |
| 787 | VisitExpr(E); |
| 788 | E->setString(cast<StringLiteral>(StmtStack.back())); |
| 789 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 790 | return 1; |
| 791 | } |
| 792 | |
| 793 | unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { |
| 794 | VisitExpr(E); |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 795 | E->setEncodedTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx)); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 796 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 797 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 798 | return 0; |
| 799 | } |
| 800 | |
| 801 | unsigned PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { |
| 802 | VisitExpr(E); |
| 803 | E->setSelector(Reader.GetSelector(Record, Idx)); |
| 804 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 805 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | unsigned PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { |
| 810 | VisitExpr(E); |
| 811 | E->setProtocol(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
| 812 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 813 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | unsigned PCHStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| 818 | VisitExpr(E); |
| 819 | E->setDecl(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 820 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 821 | E->setBase(cast<Expr>(StmtStack.back())); |
| 822 | E->setIsArrow(Record[Idx++]); |
| 823 | E->setIsFreeIvar(Record[Idx++]); |
| 824 | return 1; |
| 825 | } |
| 826 | |
| 827 | unsigned PCHStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 828 | VisitExpr(E); |
| 829 | E->setProperty(cast<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++]))); |
| 830 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 831 | E->setBase(cast<Expr>(StmtStack.back())); |
| 832 | return 1; |
| 833 | } |
| 834 | |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 835 | unsigned PCHStmtReader::VisitObjCImplicitSetterGetterRefExpr( |
| 836 | ObjCImplicitSetterGetterRefExpr *E) { |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 837 | VisitExpr(E); |
| 838 | E->setGetterMethod( |
| 839 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 840 | E->setSetterMethod( |
| 841 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
Fariborz Jahanian | d2ae5aa | 2009-08-18 21:37:33 +0000 | [diff] [blame] | 842 | E->setInterfaceDecl( |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 843 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 844 | E->setBase(cast_or_null<Expr>(StmtStack.back())); |
| 845 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 846 | E->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 847 | return 1; |
| 848 | } |
| 849 | |
| 850 | unsigned PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { |
| 851 | VisitExpr(E); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 852 | assert(Record[Idx] == E->getNumArgs()); |
| 853 | ++Idx; |
| 854 | ObjCMessageExpr::ReceiverKind Kind |
| 855 | = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]); |
| 856 | switch (Kind) { |
| 857 | case ObjCMessageExpr::Instance: |
| 858 | E->setInstanceReceiver( |
| 859 | cast_or_null<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1])); |
| 860 | break; |
| 861 | |
| 862 | case ObjCMessageExpr::Class: |
| 863 | E->setClassReceiver(Reader.GetTypeSourceInfo(Record, Idx)); |
| 864 | break; |
| 865 | |
| 866 | case ObjCMessageExpr::SuperClass: |
| 867 | case ObjCMessageExpr::SuperInstance: { |
| 868 | QualType T = Reader.GetType(Record[Idx++]); |
| 869 | SourceLocation SuperLoc = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 870 | E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance); |
| 871 | break; |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | assert(Kind == E->getReceiverKind()); |
| 876 | |
| 877 | if (Record[Idx++]) |
| 878 | E->setMethodDecl(cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 879 | else |
| 880 | E->setSelector(Reader.GetSelector(Record, Idx)); |
| 881 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 882 | E->setLeftLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 883 | E->setRightLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 884 | |
| 885 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) |
| 886 | E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I])); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 887 | return E->getNumArgs() + (Kind == ObjCMessageExpr::Instance); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | unsigned PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) { |
| 891 | VisitExpr(E); |
| 892 | E->setLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | unsigned PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 897 | VisitStmt(S); |
| 898 | S->setElement(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 3])); |
| 899 | S->setCollection(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 900 | S->setBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1])); |
| 901 | S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 902 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 903 | return 3; |
| 904 | } |
| 905 | |
| 906 | unsigned PCHStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 907 | VisitStmt(S); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 908 | S->setCatchBody(cast_or_null<Stmt>(StmtStack.back())); |
Douglas Gregor | c00d8e1 | 2010-04-26 16:46:50 +0000 | [diff] [blame] | 909 | S->setCatchParamDecl(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 910 | S->setAtCatchLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 911 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 912 | return 1; |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | unsigned PCHStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 916 | VisitStmt(S); |
| 917 | S->setFinallyBody(StmtStack.back()); |
| 918 | S->setAtFinallyLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 919 | return 1; |
| 920 | } |
| 921 | |
| 922 | unsigned PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 923 | VisitStmt(S); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 924 | assert(Record[Idx] == S->getNumCatchStmts()); |
| 925 | ++Idx; |
| 926 | bool HasFinally = Record[Idx++]; |
| 927 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 928 | unsigned Offset = StmtStack.size() - N - HasFinally + I; |
| 929 | S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(StmtStack[Offset])); |
| 930 | } |
| 931 | |
| 932 | unsigned TryOffset |
| 933 | = StmtStack.size() - S->getNumCatchStmts() - HasFinally - 1; |
| 934 | S->setTryBody(cast_or_null<Stmt>(StmtStack[TryOffset])); |
| 935 | if (HasFinally) |
| 936 | S->setFinallyStmt(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1])); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 937 | S->setAtTryLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 938 | return 1 + S->getNumCatchStmts() + HasFinally; |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | unsigned PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { |
| 942 | VisitStmt(S); |
| 943 | S->setSynchExpr(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 2])); |
| 944 | S->setSynchBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1])); |
| 945 | S->setAtSynchronizedLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 946 | return 2; |
| 947 | } |
| 948 | |
| 949 | unsigned PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 950 | VisitStmt(S); |
| 951 | S->setThrowExpr(StmtStack.back()); |
| 952 | S->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 953 | return 1; |
| 954 | } |
| 955 | |
Argyrios Kyrtzidis | ba0a900 | 2009-07-14 03:19:21 +0000 | [diff] [blame] | 956 | //===----------------------------------------------------------------------===// |
| 957 | // C++ Expressions and Statements |
| 958 | |
| 959 | unsigned PCHStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
| 960 | unsigned num = VisitCallExpr(E); |
| 961 | E->setOperator((OverloadedOperatorKind)Record[Idx++]); |
| 962 | return num; |
| 963 | } |
| 964 | |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 965 | unsigned PCHStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 966 | VisitExpr(E); |
Argyrios Kyrtzidis | 5e1b7c2 | 2010-06-24 08:57:09 +0000 | [diff] [blame] | 967 | assert(Record[Idx] == E->getNumArgs() && |
| 968 | "Read wrong record during creation ?"); |
| 969 | ++Idx; // NumArgs; |
| 970 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) |
| 971 | E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I])); |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 972 | E->setConstructor(cast<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 973 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 974 | E->setElidable(Record[Idx++]); |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 975 | E->setRequiresZeroInitialization(Record[Idx++]); |
Douglas Gregor | 3c9034c | 2010-05-15 00:13:29 +0000 | [diff] [blame] | 976 | E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]); |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 977 | return E->getNumArgs(); |
| 978 | } |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 979 | |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 980 | unsigned PCHStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 981 | unsigned num = VisitExplicitCastExpr(E); |
| 982 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 983 | return num; |
| 984 | } |
| 985 | |
| 986 | unsigned PCHStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 987 | return VisitCXXNamedCastExpr(E); |
| 988 | } |
| 989 | |
| 990 | unsigned PCHStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 991 | return VisitCXXNamedCastExpr(E); |
| 992 | } |
| 993 | |
| 994 | unsigned PCHStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) { |
| 995 | return VisitCXXNamedCastExpr(E); |
| 996 | } |
| 997 | |
| 998 | unsigned PCHStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) { |
| 999 | return VisitCXXNamedCastExpr(E); |
| 1000 | } |
| 1001 | |
| 1002 | unsigned PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { |
| 1003 | unsigned num = VisitExplicitCastExpr(E); |
| 1004 | E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1005 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1006 | return num; |
| 1007 | } |
| 1008 | |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1009 | unsigned PCHStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 1010 | VisitExpr(E); |
| 1011 | E->setValue(Record[Idx++]); |
| 1012 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | unsigned PCHStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 1017 | VisitExpr(E); |
| 1018 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1019 | return 0; |
| 1020 | } |
| 1021 | |
Chris Lattner | 14ab24f | 2010-05-09 06:03:39 +0000 | [diff] [blame] | 1022 | unsigned PCHStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 1023 | VisitExpr(E); |
| 1024 | E->setSourceRange(Reader.ReadSourceRange(Record, Idx)); |
| 1025 | if (E->isTypeOperand()) { // typeid(int) |
| 1026 | E->setTypeOperandSourceInfo(Reader.GetTypeSourceInfo(Record, Idx)); |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | // typeid(42+2) |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 1031 | E->setExprOperand(cast<Expr>(StmtStack.back())); |
Chris Lattner | 14ab24f | 2010-05-09 06:03:39 +0000 | [diff] [blame] | 1032 | return 1; |
| 1033 | } |
| 1034 | |
Chris Lattner | 2fbdfcd | 2010-05-09 06:15:05 +0000 | [diff] [blame] | 1035 | unsigned PCHStmtReader::VisitCXXThisExpr(CXXThisExpr *E) { |
| 1036 | VisitExpr(E); |
| 1037 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1038 | E->setImplicit(Record[Idx++]); |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | unsigned PCHStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 1043 | VisitExpr(E); |
| 1044 | E->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Argyrios Kyrtzidis | 5e1b7c2 | 2010-06-24 08:57:09 +0000 | [diff] [blame] | 1045 | E->setSubExpr(cast_or_null<Expr>(StmtStack.back())); |
Chris Lattner | 2fbdfcd | 2010-05-09 06:15:05 +0000 | [diff] [blame] | 1046 | return 1; |
| 1047 | } |
Chris Lattner | 14ab24f | 2010-05-09 06:03:39 +0000 | [diff] [blame] | 1048 | |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 1049 | unsigned PCHStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 1050 | VisitExpr(E); |
| 1051 | E->setUsedLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1052 | bool HasStoredExpr = Record[Idx++]; |
| 1053 | if (!HasStoredExpr) return 0; |
| 1054 | E->setExpr(cast<Expr>(StmtStack.back())); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 1055 | return 1; |
| 1056 | } |
| 1057 | |
| 1058 | unsigned PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 1059 | VisitExpr(E); |
| 1060 | E->setTemporary(Reader.ReadCXXTemporary(Record, Idx)); |
| 1061 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 1062 | return 1; |
| 1063 | } |
| 1064 | |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 1065 | unsigned PCHStmtReader::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
| 1066 | VisitExpr(E); |
| 1067 | E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1068 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | unsigned PCHStmtReader::VisitCXXNewExpr(CXXNewExpr *E) { |
| 1073 | VisitExpr(E); |
| 1074 | E->setGlobalNew(Record[Idx++]); |
| 1075 | E->setParenTypeId(Record[Idx++]); |
| 1076 | E->setHasInitializer(Record[Idx++]); |
| 1077 | bool isArray = Record[Idx++]; |
| 1078 | unsigned NumPlacementArgs = Record[Idx++]; |
| 1079 | unsigned NumCtorArgs = Record[Idx++]; |
| 1080 | E->setOperatorNew(cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1081 | E->setOperatorDelete( |
| 1082 | cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1083 | E->setConstructor( |
| 1084 | cast_or_null<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1085 | E->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1086 | E->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1087 | |
| 1088 | E->AllocateArgsArray(*Reader.getContext(), isArray, NumPlacementArgs, |
| 1089 | NumCtorArgs); |
| 1090 | |
| 1091 | // Install all the subexpressions. |
| 1092 | unsigned TotalSubExprs = E->raw_arg_end()-E->raw_arg_begin(); |
| 1093 | unsigned SSIdx = StmtStack.size()-TotalSubExprs; |
| 1094 | for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end(); |
| 1095 | I != e; ++I) |
| 1096 | *I = StmtStack[SSIdx++]; |
| 1097 | |
| 1098 | return TotalSubExprs; |
| 1099 | } |
| 1100 | |
Argyrios Kyrtzidis | 95fc98c | 2010-06-22 17:07:59 +0000 | [diff] [blame] | 1101 | unsigned PCHStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 1102 | VisitExpr(E); |
| 1103 | E->setGlobalDelete(Record[Idx++]); |
| 1104 | E->setArrayForm(Record[Idx++]); |
| 1105 | E->setOperatorDelete( |
| 1106 | cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1107 | E->setArgument(cast_or_null<Expr>(StmtStack.back())); |
| 1108 | E->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1109 | return 1; |
| 1110 | } |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 1111 | |
| 1112 | unsigned PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) { |
| 1113 | VisitExpr(E); |
| 1114 | unsigned NumTemps = Record[Idx++]; |
| 1115 | if (NumTemps) { |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 1116 | E->setNumTemporaries(*Reader.getContext(), NumTemps); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 1117 | for (unsigned i = 0; i != NumTemps; ++i) |
| 1118 | E->setTemporary(i, Reader.ReadCXXTemporary(Record, Idx)); |
| 1119 | } |
| 1120 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
| 1121 | return 1; |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1124 | unsigned |
| 1125 | PCHStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){ |
| 1126 | VisitExpr(E); |
| 1127 | |
| 1128 | unsigned NumTemplateArgs = Record[Idx++]; |
| 1129 | assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() && |
| 1130 | "Read wrong record during creation ?"); |
| 1131 | if (E->hasExplicitTemplateArgs()) { |
| 1132 | TemplateArgumentListInfo ArgInfo; |
| 1133 | ArgInfo.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1134 | ArgInfo.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1135 | for (unsigned i = 0; i != NumTemplateArgs; ++i) |
| 1136 | ArgInfo.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx)); |
| 1137 | E->initializeTemplateArgumentsFrom(ArgInfo); |
| 1138 | } |
| 1139 | |
| 1140 | E->setBase(cast_or_null<Expr>(StmtStack.back())); |
| 1141 | E->setBaseType(Reader.GetType(Record[Idx++])); |
| 1142 | E->setArrow(Record[Idx++]); |
| 1143 | E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1144 | E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 1145 | E->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 1146 | E->setFirstQualifierFoundInScope( |
| 1147 | cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1148 | E->setMember(Reader.ReadDeclarationName(Record, Idx)); |
| 1149 | E->setMemberLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1150 | |
| 1151 | return 1; |
| 1152 | } |
| 1153 | |
| 1154 | unsigned |
| 1155 | PCHStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) { |
| 1156 | VisitExpr(E); |
| 1157 | assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?"); |
| 1158 | ++Idx; // NumArgs; |
| 1159 | for (unsigned I = 0, N = E->arg_size(); I != N; ++I) |
| 1160 | E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I])); |
| 1161 | E->setTypeBeginLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1162 | E->setTypeAsWritten(Reader.GetType(Record[Idx++])); |
| 1163 | E->setLParenLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1164 | E->setRParenLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1165 | return E->arg_size(); |
| 1166 | } |
| 1167 | |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1168 | unsigned PCHStmtReader::VisitOverloadExpr(OverloadExpr *E) { |
| 1169 | VisitExpr(E); |
| 1170 | |
| 1171 | unsigned NumTemplateArgs = Record[Idx++]; |
| 1172 | assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() && |
| 1173 | "Read wrong record during creation ?"); |
| 1174 | if (E->hasExplicitTemplateArgs()) { |
| 1175 | TemplateArgumentListInfo ArgInfo; |
| 1176 | ArgInfo.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1177 | ArgInfo.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1178 | for (unsigned i = 0; i != NumTemplateArgs; ++i) |
| 1179 | ArgInfo.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx)); |
| 1180 | E->getExplicitTemplateArgs().initializeFrom(ArgInfo); |
| 1181 | } |
| 1182 | |
| 1183 | unsigned NumDecls = Record[Idx++]; |
| 1184 | UnresolvedSet<8> Decls; |
| 1185 | for (unsigned i = 0; i != NumDecls; ++i) { |
| 1186 | NamedDecl *D = cast<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
| 1187 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 1188 | Decls.addDecl(D, AS); |
| 1189 | } |
| 1190 | E->initializeResults(*Reader.getContext(), Decls.begin(), Decls.end()); |
| 1191 | |
| 1192 | E->setName(Reader.ReadDeclarationName(Record, Idx)); |
| 1193 | E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 1194 | E->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 1195 | E->setNameLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | unsigned PCHStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 1200 | VisitOverloadExpr(E); |
| 1201 | E->setArrow(Record[Idx++]); |
| 1202 | E->setHasUnresolvedUsing(Record[Idx++]); |
| 1203 | E->setBase(cast_or_null<Expr>(StmtStack.back())); |
| 1204 | E->setBaseType(Reader.GetType(Record[Idx++])); |
| 1205 | E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 1206 | return 1; |
| 1207 | } |
| 1208 | |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 1209 | unsigned PCHStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 1210 | VisitOverloadExpr(E); |
| 1211 | E->setRequiresADL(Record[Idx++]); |
| 1212 | E->setOverloaded(Record[Idx++]); |
| 1213 | E->setNamingClass(cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 1217 | |
Chris Lattner | 52e97d1 | 2009-04-27 05:41:06 +0000 | [diff] [blame] | 1218 | // Within the bitstream, expressions are stored in Reverse Polish |
| 1219 | // Notation, with each of the subexpressions preceding the |
| 1220 | // expression they are stored in. To evaluate expressions, we |
| 1221 | // continue reading expressions and placing them on the stack, with |
| 1222 | // expressions having operands removing those operands from the |
| 1223 | // stack. Evaluation terminates when we see a STMT_STOP record, and |
| 1224 | // the single remaining expression on the stack is our result. |
| 1225 | Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) { |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1226 | RecordData Record; |
| 1227 | unsigned Idx; |
| 1228 | llvm::SmallVector<Stmt *, 16> StmtStack; |
| 1229 | PCHStmtReader Reader(*this, Record, Idx, StmtStack); |
| 1230 | Stmt::EmptyShell Empty; |
| 1231 | |
| 1232 | while (true) { |
Chris Lattner | 52e97d1 | 2009-04-27 05:41:06 +0000 | [diff] [blame] | 1233 | unsigned Code = Cursor.ReadCode(); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1234 | if (Code == llvm::bitc::END_BLOCK) { |
Chris Lattner | 52e97d1 | 2009-04-27 05:41:06 +0000 | [diff] [blame] | 1235 | if (Cursor.ReadBlockEnd()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1236 | Error("error at end of block in PCH file"); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1237 | return 0; |
| 1238 | } |
| 1239 | break; |
| 1240 | } |
| 1241 | |
| 1242 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1243 | // No known subblocks, always skip them. |
Chris Lattner | 52e97d1 | 2009-04-27 05:41:06 +0000 | [diff] [blame] | 1244 | Cursor.ReadSubBlockID(); |
| 1245 | if (Cursor.SkipBlock()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1246 | Error("malformed block record in PCH file"); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1247 | return 0; |
| 1248 | } |
| 1249 | continue; |
| 1250 | } |
| 1251 | |
| 1252 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Chris Lattner | 52e97d1 | 2009-04-27 05:41:06 +0000 | [diff] [blame] | 1253 | Cursor.ReadAbbrevRecord(); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1254 | continue; |
| 1255 | } |
| 1256 | |
| 1257 | Stmt *S = 0; |
| 1258 | Idx = 0; |
| 1259 | Record.clear(); |
| 1260 | bool Finished = false; |
Chris Lattner | 52e97d1 | 2009-04-27 05:41:06 +0000 | [diff] [blame] | 1261 | switch ((pch::StmtCode)Cursor.ReadRecord(Code, Record)) { |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1262 | case pch::STMT_STOP: |
| 1263 | Finished = true; |
| 1264 | break; |
| 1265 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1266 | case pch::STMT_NULL_PTR: |
| 1267 | S = 0; |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1268 | break; |
| 1269 | |
| 1270 | case pch::STMT_NULL: |
| 1271 | S = new (Context) NullStmt(Empty); |
| 1272 | break; |
| 1273 | |
| 1274 | case pch::STMT_COMPOUND: |
| 1275 | S = new (Context) CompoundStmt(Empty); |
| 1276 | break; |
| 1277 | |
| 1278 | case pch::STMT_CASE: |
| 1279 | S = new (Context) CaseStmt(Empty); |
| 1280 | break; |
| 1281 | |
| 1282 | case pch::STMT_DEFAULT: |
| 1283 | S = new (Context) DefaultStmt(Empty); |
| 1284 | break; |
| 1285 | |
| 1286 | case pch::STMT_LABEL: |
| 1287 | S = new (Context) LabelStmt(Empty); |
| 1288 | break; |
| 1289 | |
| 1290 | case pch::STMT_IF: |
| 1291 | S = new (Context) IfStmt(Empty); |
| 1292 | break; |
| 1293 | |
| 1294 | case pch::STMT_SWITCH: |
| 1295 | S = new (Context) SwitchStmt(Empty); |
| 1296 | break; |
| 1297 | |
| 1298 | case pch::STMT_WHILE: |
| 1299 | S = new (Context) WhileStmt(Empty); |
| 1300 | break; |
| 1301 | |
| 1302 | case pch::STMT_DO: |
| 1303 | S = new (Context) DoStmt(Empty); |
| 1304 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1305 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1306 | case pch::STMT_FOR: |
| 1307 | S = new (Context) ForStmt(Empty); |
| 1308 | break; |
| 1309 | |
| 1310 | case pch::STMT_GOTO: |
| 1311 | S = new (Context) GotoStmt(Empty); |
| 1312 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1314 | case pch::STMT_INDIRECT_GOTO: |
| 1315 | S = new (Context) IndirectGotoStmt(Empty); |
| 1316 | break; |
| 1317 | |
| 1318 | case pch::STMT_CONTINUE: |
| 1319 | S = new (Context) ContinueStmt(Empty); |
| 1320 | break; |
| 1321 | |
| 1322 | case pch::STMT_BREAK: |
| 1323 | S = new (Context) BreakStmt(Empty); |
| 1324 | break; |
| 1325 | |
| 1326 | case pch::STMT_RETURN: |
| 1327 | S = new (Context) ReturnStmt(Empty); |
| 1328 | break; |
| 1329 | |
| 1330 | case pch::STMT_DECL: |
| 1331 | S = new (Context) DeclStmt(Empty); |
| 1332 | break; |
| 1333 | |
| 1334 | case pch::STMT_ASM: |
| 1335 | S = new (Context) AsmStmt(Empty); |
| 1336 | break; |
| 1337 | |
| 1338 | case pch::EXPR_PREDEFINED: |
| 1339 | S = new (Context) PredefinedExpr(Empty); |
| 1340 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | |
| 1342 | case pch::EXPR_DECL_REF: |
| 1343 | S = new (Context) DeclRefExpr(Empty); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1344 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1345 | |
| 1346 | case pch::EXPR_INTEGER_LITERAL: |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1347 | S = new (Context) IntegerLiteral(Empty); |
| 1348 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1349 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1350 | case pch::EXPR_FLOATING_LITERAL: |
| 1351 | S = new (Context) FloatingLiteral(Empty); |
| 1352 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1353 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1354 | case pch::EXPR_IMAGINARY_LITERAL: |
| 1355 | S = new (Context) ImaginaryLiteral(Empty); |
| 1356 | break; |
| 1357 | |
| 1358 | case pch::EXPR_STRING_LITERAL: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | S = StringLiteral::CreateEmpty(*Context, |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1360 | Record[PCHStmtReader::NumExprFields + 1]); |
| 1361 | break; |
| 1362 | |
| 1363 | case pch::EXPR_CHARACTER_LITERAL: |
| 1364 | S = new (Context) CharacterLiteral(Empty); |
| 1365 | break; |
| 1366 | |
| 1367 | case pch::EXPR_PAREN: |
| 1368 | S = new (Context) ParenExpr(Empty); |
| 1369 | break; |
| 1370 | |
| 1371 | case pch::EXPR_UNARY_OPERATOR: |
| 1372 | S = new (Context) UnaryOperator(Empty); |
| 1373 | break; |
| 1374 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1375 | case pch::EXPR_OFFSETOF: |
| 1376 | S = OffsetOfExpr::CreateEmpty(*Context, |
| 1377 | Record[PCHStmtReader::NumExprFields], |
| 1378 | Record[PCHStmtReader::NumExprFields + 1]); |
| 1379 | break; |
| 1380 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1381 | case pch::EXPR_SIZEOF_ALIGN_OF: |
| 1382 | S = new (Context) SizeOfAlignOfExpr(Empty); |
| 1383 | break; |
| 1384 | |
| 1385 | case pch::EXPR_ARRAY_SUBSCRIPT: |
| 1386 | S = new (Context) ArraySubscriptExpr(Empty); |
| 1387 | break; |
| 1388 | |
| 1389 | case pch::EXPR_CALL: |
Argyrios Kyrtzidis | ba0a900 | 2009-07-14 03:19:21 +0000 | [diff] [blame] | 1390 | S = new (Context) CallExpr(*Context, Stmt::CallExprClass, Empty); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1391 | break; |
| 1392 | |
| 1393 | case pch::EXPR_MEMBER: |
| 1394 | S = new (Context) MemberExpr(Empty); |
| 1395 | break; |
| 1396 | |
| 1397 | case pch::EXPR_BINARY_OPERATOR: |
| 1398 | S = new (Context) BinaryOperator(Empty); |
| 1399 | break; |
| 1400 | |
| 1401 | case pch::EXPR_COMPOUND_ASSIGN_OPERATOR: |
| 1402 | S = new (Context) CompoundAssignOperator(Empty); |
| 1403 | break; |
| 1404 | |
| 1405 | case pch::EXPR_CONDITIONAL_OPERATOR: |
| 1406 | S = new (Context) ConditionalOperator(Empty); |
| 1407 | break; |
| 1408 | |
| 1409 | case pch::EXPR_IMPLICIT_CAST: |
| 1410 | S = new (Context) ImplicitCastExpr(Empty); |
| 1411 | break; |
| 1412 | |
| 1413 | case pch::EXPR_CSTYLE_CAST: |
| 1414 | S = new (Context) CStyleCastExpr(Empty); |
| 1415 | break; |
| 1416 | |
| 1417 | case pch::EXPR_COMPOUND_LITERAL: |
| 1418 | S = new (Context) CompoundLiteralExpr(Empty); |
| 1419 | break; |
| 1420 | |
| 1421 | case pch::EXPR_EXT_VECTOR_ELEMENT: |
| 1422 | S = new (Context) ExtVectorElementExpr(Empty); |
| 1423 | break; |
| 1424 | |
| 1425 | case pch::EXPR_INIT_LIST: |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1426 | S = new (Context) InitListExpr(*getContext(), Empty); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1427 | break; |
| 1428 | |
| 1429 | case pch::EXPR_DESIGNATED_INIT: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1430 | S = DesignatedInitExpr::CreateEmpty(*Context, |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1431 | Record[PCHStmtReader::NumExprFields] - 1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1432 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1433 | break; |
| 1434 | |
| 1435 | case pch::EXPR_IMPLICIT_VALUE_INIT: |
| 1436 | S = new (Context) ImplicitValueInitExpr(Empty); |
| 1437 | break; |
| 1438 | |
| 1439 | case pch::EXPR_VA_ARG: |
| 1440 | S = new (Context) VAArgExpr(Empty); |
| 1441 | break; |
| 1442 | |
| 1443 | case pch::EXPR_ADDR_LABEL: |
| 1444 | S = new (Context) AddrLabelExpr(Empty); |
| 1445 | break; |
| 1446 | |
| 1447 | case pch::EXPR_STMT: |
| 1448 | S = new (Context) StmtExpr(Empty); |
| 1449 | break; |
| 1450 | |
| 1451 | case pch::EXPR_TYPES_COMPATIBLE: |
| 1452 | S = new (Context) TypesCompatibleExpr(Empty); |
| 1453 | break; |
| 1454 | |
| 1455 | case pch::EXPR_CHOOSE: |
| 1456 | S = new (Context) ChooseExpr(Empty); |
| 1457 | break; |
| 1458 | |
| 1459 | case pch::EXPR_GNU_NULL: |
| 1460 | S = new (Context) GNUNullExpr(Empty); |
| 1461 | break; |
| 1462 | |
| 1463 | case pch::EXPR_SHUFFLE_VECTOR: |
| 1464 | S = new (Context) ShuffleVectorExpr(Empty); |
| 1465 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1466 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1467 | case pch::EXPR_BLOCK: |
| 1468 | S = new (Context) BlockExpr(Empty); |
| 1469 | break; |
| 1470 | |
| 1471 | case pch::EXPR_BLOCK_DECL_REF: |
| 1472 | S = new (Context) BlockDeclRefExpr(Empty); |
| 1473 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1474 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1475 | case pch::EXPR_OBJC_STRING_LITERAL: |
| 1476 | S = new (Context) ObjCStringLiteral(Empty); |
| 1477 | break; |
| 1478 | case pch::EXPR_OBJC_ENCODE: |
| 1479 | S = new (Context) ObjCEncodeExpr(Empty); |
| 1480 | break; |
| 1481 | case pch::EXPR_OBJC_SELECTOR_EXPR: |
| 1482 | S = new (Context) ObjCSelectorExpr(Empty); |
| 1483 | break; |
| 1484 | case pch::EXPR_OBJC_PROTOCOL_EXPR: |
| 1485 | S = new (Context) ObjCProtocolExpr(Empty); |
| 1486 | break; |
| 1487 | case pch::EXPR_OBJC_IVAR_REF_EXPR: |
| 1488 | S = new (Context) ObjCIvarRefExpr(Empty); |
| 1489 | break; |
| 1490 | case pch::EXPR_OBJC_PROPERTY_REF_EXPR: |
| 1491 | S = new (Context) ObjCPropertyRefExpr(Empty); |
| 1492 | break; |
| 1493 | case pch::EXPR_OBJC_KVC_REF_EXPR: |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 1494 | S = new (Context) ObjCImplicitSetterGetterRefExpr(Empty); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1495 | break; |
| 1496 | case pch::EXPR_OBJC_MESSAGE_EXPR: |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1497 | S = ObjCMessageExpr::CreateEmpty(*Context, |
| 1498 | Record[PCHStmtReader::NumExprFields]); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1499 | break; |
| 1500 | case pch::EXPR_OBJC_SUPER_EXPR: |
| 1501 | S = new (Context) ObjCSuperExpr(Empty); |
| 1502 | break; |
Steve Naroff | f242b1b | 2009-07-24 17:54:45 +0000 | [diff] [blame] | 1503 | case pch::EXPR_OBJC_ISA: |
| 1504 | S = new (Context) ObjCIsaExpr(Empty); |
| 1505 | break; |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1506 | case pch::STMT_OBJC_FOR_COLLECTION: |
| 1507 | S = new (Context) ObjCForCollectionStmt(Empty); |
| 1508 | break; |
| 1509 | case pch::STMT_OBJC_CATCH: |
| 1510 | S = new (Context) ObjCAtCatchStmt(Empty); |
| 1511 | break; |
| 1512 | case pch::STMT_OBJC_FINALLY: |
| 1513 | S = new (Context) ObjCAtFinallyStmt(Empty); |
| 1514 | break; |
| 1515 | case pch::STMT_OBJC_AT_TRY: |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1516 | S = ObjCAtTryStmt::CreateEmpty(*Context, |
| 1517 | Record[PCHStmtReader::NumStmtFields], |
| 1518 | Record[PCHStmtReader::NumStmtFields + 1]); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1519 | break; |
| 1520 | case pch::STMT_OBJC_AT_SYNCHRONIZED: |
| 1521 | S = new (Context) ObjCAtSynchronizedStmt(Empty); |
| 1522 | break; |
| 1523 | case pch::STMT_OBJC_AT_THROW: |
| 1524 | S = new (Context) ObjCAtThrowStmt(Empty); |
| 1525 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1526 | |
Argyrios Kyrtzidis | ba0a900 | 2009-07-14 03:19:21 +0000 | [diff] [blame] | 1527 | case pch::EXPR_CXX_OPERATOR_CALL: |
| 1528 | S = new (Context) CXXOperatorCallExpr(*Context, Empty); |
| 1529 | break; |
Chris Lattner | 1817bd4 | 2010-05-09 05:36:05 +0000 | [diff] [blame] | 1530 | |
| 1531 | case pch::EXPR_CXX_MEMBER_CALL: |
| 1532 | S = new (Context) CXXMemberCallExpr(*Context, Empty); |
| 1533 | break; |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 1534 | |
| 1535 | case pch::EXPR_CXX_CONSTRUCT: |
| 1536 | S = new (Context) CXXConstructExpr(Empty, *Context, |
Argyrios Kyrtzidis | 5e1b7c2 | 2010-06-24 08:57:09 +0000 | [diff] [blame] | 1537 | Record[PCHStmtReader::NumExprFields]); |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 1538 | break; |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 1539 | |
| 1540 | case pch::EXPR_CXX_STATIC_CAST: |
| 1541 | S = new (Context) CXXStaticCastExpr(Empty); |
| 1542 | break; |
| 1543 | |
| 1544 | case pch::EXPR_CXX_DYNAMIC_CAST: |
| 1545 | S = new (Context) CXXDynamicCastExpr(Empty); |
| 1546 | break; |
| 1547 | |
| 1548 | case pch::EXPR_CXX_REINTERPRET_CAST: |
| 1549 | S = new (Context) CXXReinterpretCastExpr(Empty); |
| 1550 | break; |
| 1551 | |
| 1552 | case pch::EXPR_CXX_CONST_CAST: |
| 1553 | S = new (Context) CXXConstCastExpr(Empty); |
| 1554 | break; |
| 1555 | |
| 1556 | case pch::EXPR_CXX_FUNCTIONAL_CAST: |
| 1557 | S = new (Context) CXXFunctionalCastExpr(Empty); |
| 1558 | break; |
| 1559 | |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1560 | case pch::EXPR_CXX_BOOL_LITERAL: |
| 1561 | S = new (Context) CXXBoolLiteralExpr(Empty); |
| 1562 | break; |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 1563 | |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1564 | case pch::EXPR_CXX_NULL_PTR_LITERAL: |
| 1565 | S = new (Context) CXXNullPtrLiteralExpr(Empty); |
| 1566 | break; |
Chris Lattner | 14ab24f | 2010-05-09 06:03:39 +0000 | [diff] [blame] | 1567 | case pch::EXPR_CXX_TYPEID_EXPR: |
| 1568 | S = new (Context) CXXTypeidExpr(Empty, true); |
| 1569 | break; |
| 1570 | case pch::EXPR_CXX_TYPEID_TYPE: |
| 1571 | S = new (Context) CXXTypeidExpr(Empty, false); |
| 1572 | break; |
Chris Lattner | 2fbdfcd | 2010-05-09 06:15:05 +0000 | [diff] [blame] | 1573 | case pch::EXPR_CXX_THIS: |
| 1574 | S = new (Context) CXXThisExpr(Empty); |
| 1575 | break; |
| 1576 | case pch::EXPR_CXX_THROW: |
| 1577 | S = new (Context) CXXThrowExpr(Empty); |
| 1578 | break; |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 1579 | case pch::EXPR_CXX_DEFAULT_ARG: |
| 1580 | S = new (Context) CXXDefaultArgExpr(Empty); |
| 1581 | break; |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 1582 | case pch::EXPR_CXX_BIND_TEMPORARY: |
| 1583 | S = new (Context) CXXBindTemporaryExpr(Empty); |
| 1584 | break; |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 1585 | |
| 1586 | case pch::EXPR_CXX_ZERO_INIT_VALUE: |
| 1587 | S = new (Context) CXXZeroInitValueExpr(Empty); |
| 1588 | break; |
| 1589 | case pch::EXPR_CXX_NEW: |
| 1590 | S = new (Context) CXXNewExpr(Empty); |
| 1591 | break; |
Argyrios Kyrtzidis | 95fc98c | 2010-06-22 17:07:59 +0000 | [diff] [blame] | 1592 | case pch::EXPR_CXX_DELETE: |
| 1593 | S = new (Context) CXXDeleteExpr(Empty); |
| 1594 | break; |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 1595 | |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 1596 | case pch::EXPR_CXX_EXPR_WITH_TEMPORARIES: |
| 1597 | S = new (Context) CXXExprWithTemporaries(Empty); |
| 1598 | break; |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1599 | |
| 1600 | case pch::EXPR_CXX_DEPENDENT_SCOPE_MEMBER: |
| 1601 | S = CXXDependentScopeMemberExpr::CreateEmpty(*Context, |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1602 | /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1603 | break; |
| 1604 | |
| 1605 | case pch::EXPR_CXX_UNRESOLVED_CONSTRUCT: |
| 1606 | S = CXXUnresolvedConstructExpr::CreateEmpty(*Context, |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1607 | /*NumArgs=*/Record[PCHStmtReader::NumExprFields]); |
| 1608 | break; |
| 1609 | |
| 1610 | case pch::EXPR_CXX_UNRESOLVED_MEMBER: |
| 1611 | S = UnresolvedMemberExpr::CreateEmpty(*Context, |
| 1612 | /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1613 | break; |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 1614 | |
| 1615 | case pch::EXPR_CXX_UNRESOLVED_LOOKUP: |
| 1616 | S = UnresolvedLookupExpr::CreateEmpty(*Context, |
| 1617 | /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]); |
| 1618 | break; |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | // We hit a STMT_STOP, so we're done with this expression. |
| 1622 | if (Finished) |
| 1623 | break; |
| 1624 | |
| 1625 | ++NumStatementsRead; |
| 1626 | |
| 1627 | if (S) { |
| 1628 | unsigned NumSubStmts = Reader.Visit(S); |
| 1629 | while (NumSubStmts > 0) { |
| 1630 | StmtStack.pop_back(); |
| 1631 | --NumSubStmts; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | assert(Idx == Record.size() && "Invalid deserialization of statement"); |
| 1636 | StmtStack.push_back(S); |
| 1637 | } |
| 1638 | assert(StmtStack.size() == 1 && "Extra expressions on stack!"); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 1639 | return StmtStack.back(); |
| 1640 | } |