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