Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 1 | //===--- PCHWriterStmt.cpp - Statement and Expression Serialization -------===// |
| 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 | // This file implements serialization for Statements and Expressions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Frontend/PCHWriter.h" |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclCXX.h" |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclObjC.h" |
| 17 | #include "clang/AST/StmtVisitor.h" |
| 18 | #include "llvm/Bitcode/BitstreamWriter.h" |
| 19 | using namespace clang; |
| 20 | |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | // Statement/expression serialization |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | |
| 25 | namespace { |
| 26 | class PCHStmtWriter : public StmtVisitor<PCHStmtWriter, void> { |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 27 | PCHWriter &Writer; |
| 28 | PCHWriter::RecordData &Record; |
| 29 | |
| 30 | public: |
| 31 | pch::StmtCode Code; |
| 32 | |
| 33 | PCHStmtWriter(PCHWriter &Writer, PCHWriter::RecordData &Record) |
| 34 | : Writer(Writer), Record(Record) { } |
| 35 | |
| 36 | void VisitStmt(Stmt *S); |
| 37 | void VisitNullStmt(NullStmt *S); |
| 38 | void VisitCompoundStmt(CompoundStmt *S); |
| 39 | void VisitSwitchCase(SwitchCase *S); |
| 40 | void VisitCaseStmt(CaseStmt *S); |
| 41 | void VisitDefaultStmt(DefaultStmt *S); |
| 42 | void VisitLabelStmt(LabelStmt *S); |
| 43 | void VisitIfStmt(IfStmt *S); |
| 44 | void VisitSwitchStmt(SwitchStmt *S); |
| 45 | void VisitWhileStmt(WhileStmt *S); |
| 46 | void VisitDoStmt(DoStmt *S); |
| 47 | void VisitForStmt(ForStmt *S); |
| 48 | void VisitGotoStmt(GotoStmt *S); |
| 49 | void VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 50 | void VisitContinueStmt(ContinueStmt *S); |
| 51 | void VisitBreakStmt(BreakStmt *S); |
| 52 | void VisitReturnStmt(ReturnStmt *S); |
| 53 | void VisitDeclStmt(DeclStmt *S); |
| 54 | void VisitAsmStmt(AsmStmt *S); |
| 55 | void VisitExpr(Expr *E); |
| 56 | void VisitPredefinedExpr(PredefinedExpr *E); |
| 57 | void VisitDeclRefExpr(DeclRefExpr *E); |
| 58 | void VisitIntegerLiteral(IntegerLiteral *E); |
| 59 | void VisitFloatingLiteral(FloatingLiteral *E); |
| 60 | void VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 61 | void VisitStringLiteral(StringLiteral *E); |
| 62 | void VisitCharacterLiteral(CharacterLiteral *E); |
| 63 | void VisitParenExpr(ParenExpr *E); |
| 64 | void VisitUnaryOperator(UnaryOperator *E); |
| 65 | void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); |
| 66 | void VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 67 | void VisitCallExpr(CallExpr *E); |
| 68 | void VisitMemberExpr(MemberExpr *E); |
| 69 | void VisitCastExpr(CastExpr *E); |
| 70 | void VisitBinaryOperator(BinaryOperator *E); |
| 71 | void VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 72 | void VisitConditionalOperator(ConditionalOperator *E); |
| 73 | void VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 74 | void VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 75 | void VisitCStyleCastExpr(CStyleCastExpr *E); |
| 76 | void VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 77 | void VisitExtVectorElementExpr(ExtVectorElementExpr *E); |
| 78 | void VisitInitListExpr(InitListExpr *E); |
| 79 | void VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 80 | void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 81 | void VisitVAArgExpr(VAArgExpr *E); |
| 82 | void VisitAddrLabelExpr(AddrLabelExpr *E); |
| 83 | void VisitStmtExpr(StmtExpr *E); |
| 84 | void VisitTypesCompatibleExpr(TypesCompatibleExpr *E); |
| 85 | void VisitChooseExpr(ChooseExpr *E); |
| 86 | void VisitGNUNullExpr(GNUNullExpr *E); |
| 87 | void VisitShuffleVectorExpr(ShuffleVectorExpr *E); |
| 88 | void VisitBlockExpr(BlockExpr *E); |
| 89 | void VisitBlockDeclRefExpr(BlockDeclRefExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 91 | // Objective-C Expressions |
| 92 | void VisitObjCStringLiteral(ObjCStringLiteral *E); |
| 93 | void VisitObjCEncodeExpr(ObjCEncodeExpr *E); |
| 94 | void VisitObjCSelectorExpr(ObjCSelectorExpr *E); |
| 95 | void VisitObjCProtocolExpr(ObjCProtocolExpr *E); |
| 96 | void VisitObjCIvarRefExpr(ObjCIvarRefExpr *E); |
| 97 | void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E); |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 98 | void VisitObjCImplicitSetterGetterRefExpr( |
| 99 | ObjCImplicitSetterGetterRefExpr *E); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 100 | void VisitObjCMessageExpr(ObjCMessageExpr *E); |
| 101 | void VisitObjCSuperExpr(ObjCSuperExpr *E); |
Steve Naroff | f242b1b | 2009-07-24 17:54:45 +0000 | [diff] [blame] | 102 | void VisitObjCIsaExpr(ObjCIsaExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | |
| 104 | // Objective-C Statements |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 105 | void VisitObjCForCollectionStmt(ObjCForCollectionStmt *); |
| 106 | void VisitObjCAtCatchStmt(ObjCAtCatchStmt *); |
| 107 | void VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *); |
| 108 | void VisitObjCAtTryStmt(ObjCAtTryStmt *); |
| 109 | void VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *); |
| 110 | void VisitObjCAtThrowStmt(ObjCAtThrowStmt *); |
Argyrios Kyrtzidis | ba0a900 | 2009-07-14 03:19:21 +0000 | [diff] [blame] | 111 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | // C++ Statements |
Argyrios Kyrtzidis | ba0a900 | 2009-07-14 03:19:21 +0000 | [diff] [blame] | 113 | void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E); |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 114 | void VisitCXXConstructExpr(CXXConstructExpr *E); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 115 | }; |
| 116 | } |
| 117 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 118 | void PCHStmtWriter::VisitStmt(Stmt *S) { |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void PCHStmtWriter::VisitNullStmt(NullStmt *S) { |
| 122 | VisitStmt(S); |
| 123 | Writer.AddSourceLocation(S->getSemiLoc(), Record); |
| 124 | Code = pch::STMT_NULL; |
| 125 | } |
| 126 | |
| 127 | void PCHStmtWriter::VisitCompoundStmt(CompoundStmt *S) { |
| 128 | VisitStmt(S); |
| 129 | Record.push_back(S->size()); |
| 130 | for (CompoundStmt::body_iterator CS = S->body_begin(), CSEnd = S->body_end(); |
| 131 | CS != CSEnd; ++CS) |
| 132 | Writer.WriteSubStmt(*CS); |
| 133 | Writer.AddSourceLocation(S->getLBracLoc(), Record); |
| 134 | Writer.AddSourceLocation(S->getRBracLoc(), Record); |
| 135 | Code = pch::STMT_COMPOUND; |
| 136 | } |
| 137 | |
| 138 | void PCHStmtWriter::VisitSwitchCase(SwitchCase *S) { |
| 139 | VisitStmt(S); |
| 140 | Record.push_back(Writer.RecordSwitchCaseID(S)); |
| 141 | } |
| 142 | |
| 143 | void PCHStmtWriter::VisitCaseStmt(CaseStmt *S) { |
| 144 | VisitSwitchCase(S); |
| 145 | Writer.WriteSubStmt(S->getLHS()); |
| 146 | Writer.WriteSubStmt(S->getRHS()); |
| 147 | Writer.WriteSubStmt(S->getSubStmt()); |
| 148 | Writer.AddSourceLocation(S->getCaseLoc(), Record); |
Douglas Gregor | dbb26db | 2009-05-15 23:57:33 +0000 | [diff] [blame] | 149 | Writer.AddSourceLocation(S->getEllipsisLoc(), Record); |
| 150 | Writer.AddSourceLocation(S->getColonLoc(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 151 | Code = pch::STMT_CASE; |
| 152 | } |
| 153 | |
| 154 | void PCHStmtWriter::VisitDefaultStmt(DefaultStmt *S) { |
| 155 | VisitSwitchCase(S); |
| 156 | Writer.WriteSubStmt(S->getSubStmt()); |
| 157 | Writer.AddSourceLocation(S->getDefaultLoc(), Record); |
Douglas Gregor | dbb26db | 2009-05-15 23:57:33 +0000 | [diff] [blame] | 158 | Writer.AddSourceLocation(S->getColonLoc(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 159 | Code = pch::STMT_DEFAULT; |
| 160 | } |
| 161 | |
| 162 | void PCHStmtWriter::VisitLabelStmt(LabelStmt *S) { |
| 163 | VisitStmt(S); |
| 164 | Writer.AddIdentifierRef(S->getID(), Record); |
| 165 | Writer.WriteSubStmt(S->getSubStmt()); |
| 166 | Writer.AddSourceLocation(S->getIdentLoc(), Record); |
| 167 | Record.push_back(Writer.GetLabelID(S)); |
| 168 | Code = pch::STMT_LABEL; |
| 169 | } |
| 170 | |
| 171 | void PCHStmtWriter::VisitIfStmt(IfStmt *S) { |
| 172 | VisitStmt(S); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 173 | Writer.AddDeclRef(S->getConditionVariable(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 174 | Writer.WriteSubStmt(S->getCond()); |
| 175 | Writer.WriteSubStmt(S->getThen()); |
| 176 | Writer.WriteSubStmt(S->getElse()); |
| 177 | Writer.AddSourceLocation(S->getIfLoc(), Record); |
Douglas Gregor | d06f6ca | 2009-05-15 18:53:42 +0000 | [diff] [blame] | 178 | Writer.AddSourceLocation(S->getElseLoc(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 179 | Code = pch::STMT_IF; |
| 180 | } |
| 181 | |
| 182 | void PCHStmtWriter::VisitSwitchStmt(SwitchStmt *S) { |
| 183 | VisitStmt(S); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 184 | Writer.AddDeclRef(S->getConditionVariable(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 185 | Writer.WriteSubStmt(S->getCond()); |
| 186 | Writer.WriteSubStmt(S->getBody()); |
| 187 | Writer.AddSourceLocation(S->getSwitchLoc(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | for (SwitchCase *SC = S->getSwitchCaseList(); SC; |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 189 | SC = SC->getNextSwitchCase()) |
| 190 | Record.push_back(Writer.getSwitchCaseID(SC)); |
| 191 | Code = pch::STMT_SWITCH; |
| 192 | } |
| 193 | |
| 194 | void PCHStmtWriter::VisitWhileStmt(WhileStmt *S) { |
| 195 | VisitStmt(S); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 196 | Writer.AddDeclRef(S->getConditionVariable(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 197 | Writer.WriteSubStmt(S->getCond()); |
| 198 | Writer.WriteSubStmt(S->getBody()); |
| 199 | Writer.AddSourceLocation(S->getWhileLoc(), Record); |
| 200 | Code = pch::STMT_WHILE; |
| 201 | } |
| 202 | |
| 203 | void PCHStmtWriter::VisitDoStmt(DoStmt *S) { |
| 204 | VisitStmt(S); |
| 205 | Writer.WriteSubStmt(S->getCond()); |
| 206 | Writer.WriteSubStmt(S->getBody()); |
| 207 | Writer.AddSourceLocation(S->getDoLoc(), Record); |
Douglas Gregor | 9f3ca2a | 2009-05-15 21:56:04 +0000 | [diff] [blame] | 208 | Writer.AddSourceLocation(S->getWhileLoc(), Record); |
Chris Lattner | 9891359 | 2009-06-12 23:04:47 +0000 | [diff] [blame] | 209 | Writer.AddSourceLocation(S->getRParenLoc(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 210 | Code = pch::STMT_DO; |
| 211 | } |
| 212 | |
| 213 | void PCHStmtWriter::VisitForStmt(ForStmt *S) { |
| 214 | VisitStmt(S); |
| 215 | Writer.WriteSubStmt(S->getInit()); |
| 216 | Writer.WriteSubStmt(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 217 | Writer.AddDeclRef(S->getConditionVariable(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 218 | Writer.WriteSubStmt(S->getInc()); |
| 219 | Writer.WriteSubStmt(S->getBody()); |
| 220 | Writer.AddSourceLocation(S->getForLoc(), Record); |
Douglas Gregor | 5831c6a | 2009-05-15 22:12:32 +0000 | [diff] [blame] | 221 | Writer.AddSourceLocation(S->getLParenLoc(), Record); |
| 222 | Writer.AddSourceLocation(S->getRParenLoc(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 223 | Code = pch::STMT_FOR; |
| 224 | } |
| 225 | |
| 226 | void PCHStmtWriter::VisitGotoStmt(GotoStmt *S) { |
| 227 | VisitStmt(S); |
| 228 | Record.push_back(Writer.GetLabelID(S->getLabel())); |
| 229 | Writer.AddSourceLocation(S->getGotoLoc(), Record); |
| 230 | Writer.AddSourceLocation(S->getLabelLoc(), Record); |
| 231 | Code = pch::STMT_GOTO; |
| 232 | } |
| 233 | |
| 234 | void PCHStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 235 | VisitStmt(S); |
| 236 | Writer.AddSourceLocation(S->getGotoLoc(), Record); |
Douglas Gregor | 5f1b9e6 | 2009-05-16 00:20:29 +0000 | [diff] [blame] | 237 | Writer.AddSourceLocation(S->getStarLoc(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 238 | Writer.WriteSubStmt(S->getTarget()); |
| 239 | Code = pch::STMT_INDIRECT_GOTO; |
| 240 | } |
| 241 | |
| 242 | void PCHStmtWriter::VisitContinueStmt(ContinueStmt *S) { |
| 243 | VisitStmt(S); |
| 244 | Writer.AddSourceLocation(S->getContinueLoc(), Record); |
| 245 | Code = pch::STMT_CONTINUE; |
| 246 | } |
| 247 | |
| 248 | void PCHStmtWriter::VisitBreakStmt(BreakStmt *S) { |
| 249 | VisitStmt(S); |
| 250 | Writer.AddSourceLocation(S->getBreakLoc(), Record); |
| 251 | Code = pch::STMT_BREAK; |
| 252 | } |
| 253 | |
| 254 | void PCHStmtWriter::VisitReturnStmt(ReturnStmt *S) { |
| 255 | VisitStmt(S); |
| 256 | Writer.WriteSubStmt(S->getRetValue()); |
| 257 | Writer.AddSourceLocation(S->getReturnLoc(), Record); |
| 258 | Code = pch::STMT_RETURN; |
| 259 | } |
| 260 | |
| 261 | void PCHStmtWriter::VisitDeclStmt(DeclStmt *S) { |
| 262 | VisitStmt(S); |
| 263 | Writer.AddSourceLocation(S->getStartLoc(), Record); |
| 264 | Writer.AddSourceLocation(S->getEndLoc(), Record); |
| 265 | DeclGroupRef DG = S->getDeclGroup(); |
| 266 | for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D) |
| 267 | Writer.AddDeclRef(*D, Record); |
| 268 | Code = pch::STMT_DECL; |
| 269 | } |
| 270 | |
| 271 | void PCHStmtWriter::VisitAsmStmt(AsmStmt *S) { |
| 272 | VisitStmt(S); |
| 273 | Record.push_back(S->getNumOutputs()); |
| 274 | Record.push_back(S->getNumInputs()); |
| 275 | Record.push_back(S->getNumClobbers()); |
| 276 | Writer.AddSourceLocation(S->getAsmLoc(), Record); |
| 277 | Writer.AddSourceLocation(S->getRParenLoc(), Record); |
| 278 | Record.push_back(S->isVolatile()); |
| 279 | Record.push_back(S->isSimple()); |
| 280 | Writer.WriteSubStmt(S->getAsmString()); |
| 281 | |
| 282 | // Outputs |
| 283 | for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) { |
| 284 | Writer.AddString(S->getOutputName(I), Record); |
| 285 | Writer.WriteSubStmt(S->getOutputConstraintLiteral(I)); |
| 286 | Writer.WriteSubStmt(S->getOutputExpr(I)); |
| 287 | } |
| 288 | |
| 289 | // Inputs |
| 290 | for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) { |
| 291 | Writer.AddString(S->getInputName(I), Record); |
| 292 | Writer.WriteSubStmt(S->getInputConstraintLiteral(I)); |
| 293 | Writer.WriteSubStmt(S->getInputExpr(I)); |
| 294 | } |
| 295 | |
| 296 | // Clobbers |
| 297 | for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) |
| 298 | Writer.WriteSubStmt(S->getClobber(I)); |
| 299 | |
| 300 | Code = pch::STMT_ASM; |
| 301 | } |
| 302 | |
| 303 | void PCHStmtWriter::VisitExpr(Expr *E) { |
| 304 | VisitStmt(E); |
| 305 | Writer.AddTypeRef(E->getType(), Record); |
| 306 | Record.push_back(E->isTypeDependent()); |
| 307 | Record.push_back(E->isValueDependent()); |
| 308 | } |
| 309 | |
| 310 | void PCHStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 311 | VisitExpr(E); |
| 312 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 313 | Record.push_back(E->getIdentType()); // FIXME: stable encoding |
| 314 | Code = pch::EXPR_PREDEFINED; |
| 315 | } |
| 316 | |
| 317 | void PCHStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 318 | VisitExpr(E); |
| 319 | Writer.AddDeclRef(E->getDecl(), Record); |
| 320 | Writer.AddSourceLocation(E->getLocation(), Record); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 321 | // FIXME: write qualifier |
| 322 | // FIXME: write explicit template arguments |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 323 | Code = pch::EXPR_DECL_REF; |
| 324 | } |
| 325 | |
| 326 | void PCHStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 327 | VisitExpr(E); |
| 328 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 329 | Writer.AddAPInt(E->getValue(), Record); |
| 330 | Code = pch::EXPR_INTEGER_LITERAL; |
| 331 | } |
| 332 | |
| 333 | void PCHStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 334 | VisitExpr(E); |
| 335 | Writer.AddAPFloat(E->getValue(), Record); |
| 336 | Record.push_back(E->isExact()); |
| 337 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 338 | Code = pch::EXPR_FLOATING_LITERAL; |
| 339 | } |
| 340 | |
| 341 | void PCHStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 342 | VisitExpr(E); |
| 343 | Writer.WriteSubStmt(E->getSubExpr()); |
| 344 | Code = pch::EXPR_IMAGINARY_LITERAL; |
| 345 | } |
| 346 | |
| 347 | void PCHStmtWriter::VisitStringLiteral(StringLiteral *E) { |
| 348 | VisitExpr(E); |
| 349 | Record.push_back(E->getByteLength()); |
| 350 | Record.push_back(E->getNumConcatenated()); |
| 351 | Record.push_back(E->isWide()); |
| 352 | // FIXME: String data should be stored as a blob at the end of the |
| 353 | // StringLiteral. However, we can't do so now because we have no |
| 354 | // provision for coping with abbreviations when we're jumping around |
| 355 | // the PCH file during deserialization. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | Record.insert(Record.end(), |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 357 | E->getStrData(), E->getStrData() + E->getByteLength()); |
| 358 | for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) |
| 359 | Writer.AddSourceLocation(E->getStrTokenLoc(I), Record); |
| 360 | Code = pch::EXPR_STRING_LITERAL; |
| 361 | } |
| 362 | |
| 363 | void PCHStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 364 | VisitExpr(E); |
| 365 | Record.push_back(E->getValue()); |
Chris Lattner | 018d8e0 | 2009-08-24 17:39:36 +0000 | [diff] [blame] | 366 | Writer.AddSourceLocation(E->getLocation(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 367 | Record.push_back(E->isWide()); |
| 368 | Code = pch::EXPR_CHARACTER_LITERAL; |
| 369 | } |
| 370 | |
| 371 | void PCHStmtWriter::VisitParenExpr(ParenExpr *E) { |
| 372 | VisitExpr(E); |
| 373 | Writer.AddSourceLocation(E->getLParen(), Record); |
| 374 | Writer.AddSourceLocation(E->getRParen(), Record); |
| 375 | Writer.WriteSubStmt(E->getSubExpr()); |
| 376 | Code = pch::EXPR_PAREN; |
| 377 | } |
| 378 | |
| 379 | void PCHStmtWriter::VisitUnaryOperator(UnaryOperator *E) { |
| 380 | VisitExpr(E); |
| 381 | Writer.WriteSubStmt(E->getSubExpr()); |
| 382 | Record.push_back(E->getOpcode()); // FIXME: stable encoding |
| 383 | Writer.AddSourceLocation(E->getOperatorLoc(), Record); |
| 384 | Code = pch::EXPR_UNARY_OPERATOR; |
| 385 | } |
| 386 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | void PCHStmtWriter::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 388 | VisitExpr(E); |
| 389 | Record.push_back(E->isSizeOf()); |
| 390 | if (E->isArgumentType()) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 391 | Writer.AddTypeSourceInfo(E->getArgumentTypeInfo(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 392 | else { |
| 393 | Record.push_back(0); |
| 394 | Writer.WriteSubStmt(E->getArgumentExpr()); |
| 395 | } |
| 396 | Writer.AddSourceLocation(E->getOperatorLoc(), Record); |
| 397 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 398 | Code = pch::EXPR_SIZEOF_ALIGN_OF; |
| 399 | } |
| 400 | |
| 401 | void PCHStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 402 | VisitExpr(E); |
| 403 | Writer.WriteSubStmt(E->getLHS()); |
| 404 | Writer.WriteSubStmt(E->getRHS()); |
| 405 | Writer.AddSourceLocation(E->getRBracketLoc(), Record); |
| 406 | Code = pch::EXPR_ARRAY_SUBSCRIPT; |
| 407 | } |
| 408 | |
| 409 | void PCHStmtWriter::VisitCallExpr(CallExpr *E) { |
| 410 | VisitExpr(E); |
| 411 | Record.push_back(E->getNumArgs()); |
| 412 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 413 | Writer.WriteSubStmt(E->getCallee()); |
| 414 | for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); |
| 415 | Arg != ArgEnd; ++Arg) |
| 416 | Writer.WriteSubStmt(*Arg); |
| 417 | Code = pch::EXPR_CALL; |
| 418 | } |
| 419 | |
| 420 | void PCHStmtWriter::VisitMemberExpr(MemberExpr *E) { |
| 421 | VisitExpr(E); |
| 422 | Writer.WriteSubStmt(E->getBase()); |
| 423 | Writer.AddDeclRef(E->getMemberDecl(), Record); |
| 424 | Writer.AddSourceLocation(E->getMemberLoc(), Record); |
| 425 | Record.push_back(E->isArrow()); |
Douglas Gregor | 303e6d7 | 2009-08-31 23:44:04 +0000 | [diff] [blame] | 426 | // FIXME: C++ nested-name-specifier |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 427 | // FIXME: C++ template argument list |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 428 | Code = pch::EXPR_MEMBER; |
| 429 | } |
| 430 | |
Steve Naroff | f242b1b | 2009-07-24 17:54:45 +0000 | [diff] [blame] | 431 | void PCHStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) { |
| 432 | VisitExpr(E); |
| 433 | Writer.WriteSubStmt(E->getBase()); |
| 434 | Writer.AddSourceLocation(E->getIsaMemberLoc(), Record); |
| 435 | Record.push_back(E->isArrow()); |
| 436 | Code = pch::EXPR_OBJC_ISA; |
| 437 | } |
| 438 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 439 | void PCHStmtWriter::VisitCastExpr(CastExpr *E) { |
| 440 | VisitExpr(E); |
| 441 | Writer.WriteSubStmt(E->getSubExpr()); |
Anders Carlsson | cdef2b7 | 2009-07-31 00:48:10 +0000 | [diff] [blame] | 442 | Record.push_back(E->getCastKind()); // FIXME: stable encoding |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void PCHStmtWriter::VisitBinaryOperator(BinaryOperator *E) { |
| 446 | VisitExpr(E); |
| 447 | Writer.WriteSubStmt(E->getLHS()); |
| 448 | Writer.WriteSubStmt(E->getRHS()); |
| 449 | Record.push_back(E->getOpcode()); // FIXME: stable encoding |
| 450 | Writer.AddSourceLocation(E->getOperatorLoc(), Record); |
| 451 | Code = pch::EXPR_BINARY_OPERATOR; |
| 452 | } |
| 453 | |
| 454 | void PCHStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 455 | VisitBinaryOperator(E); |
| 456 | Writer.AddTypeRef(E->getComputationLHSType(), Record); |
| 457 | Writer.AddTypeRef(E->getComputationResultType(), Record); |
| 458 | Code = pch::EXPR_COMPOUND_ASSIGN_OPERATOR; |
| 459 | } |
| 460 | |
| 461 | void PCHStmtWriter::VisitConditionalOperator(ConditionalOperator *E) { |
| 462 | VisitExpr(E); |
| 463 | Writer.WriteSubStmt(E->getCond()); |
| 464 | Writer.WriteSubStmt(E->getLHS()); |
| 465 | Writer.WriteSubStmt(E->getRHS()); |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 466 | Writer.AddSourceLocation(E->getQuestionLoc(), Record); |
| 467 | Writer.AddSourceLocation(E->getColonLoc(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 468 | Code = pch::EXPR_CONDITIONAL_OPERATOR; |
| 469 | } |
| 470 | |
| 471 | void PCHStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 472 | VisitCastExpr(E); |
| 473 | Record.push_back(E->isLvalueCast()); |
| 474 | Code = pch::EXPR_IMPLICIT_CAST; |
| 475 | } |
| 476 | |
| 477 | void PCHStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 478 | VisitCastExpr(E); |
| 479 | Writer.AddTypeRef(E->getTypeAsWritten(), Record); |
| 480 | } |
| 481 | |
| 482 | void PCHStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) { |
| 483 | VisitExplicitCastExpr(E); |
| 484 | Writer.AddSourceLocation(E->getLParenLoc(), Record); |
| 485 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 486 | Code = pch::EXPR_CSTYLE_CAST; |
| 487 | } |
| 488 | |
| 489 | void PCHStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 490 | VisitExpr(E); |
| 491 | Writer.AddSourceLocation(E->getLParenLoc(), Record); |
| 492 | Writer.WriteSubStmt(E->getInitializer()); |
| 493 | Record.push_back(E->isFileScope()); |
| 494 | Code = pch::EXPR_COMPOUND_LITERAL; |
| 495 | } |
| 496 | |
| 497 | void PCHStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { |
| 498 | VisitExpr(E); |
| 499 | Writer.WriteSubStmt(E->getBase()); |
| 500 | Writer.AddIdentifierRef(&E->getAccessor(), Record); |
| 501 | Writer.AddSourceLocation(E->getAccessorLoc(), Record); |
| 502 | Code = pch::EXPR_EXT_VECTOR_ELEMENT; |
| 503 | } |
| 504 | |
| 505 | void PCHStmtWriter::VisitInitListExpr(InitListExpr *E) { |
| 506 | VisitExpr(E); |
| 507 | Record.push_back(E->getNumInits()); |
| 508 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) |
| 509 | Writer.WriteSubStmt(E->getInit(I)); |
| 510 | Writer.WriteSubStmt(E->getSyntacticForm()); |
| 511 | Writer.AddSourceLocation(E->getLBraceLoc(), Record); |
| 512 | Writer.AddSourceLocation(E->getRBraceLoc(), Record); |
| 513 | Writer.AddDeclRef(E->getInitializedFieldInUnion(), Record); |
| 514 | Record.push_back(E->hadArrayRangeDesignator()); |
| 515 | Code = pch::EXPR_INIT_LIST; |
| 516 | } |
| 517 | |
| 518 | void PCHStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 519 | VisitExpr(E); |
| 520 | Record.push_back(E->getNumSubExprs()); |
| 521 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) |
| 522 | Writer.WriteSubStmt(E->getSubExpr(I)); |
| 523 | Writer.AddSourceLocation(E->getEqualOrColonLoc(), Record); |
| 524 | Record.push_back(E->usesGNUSyntax()); |
| 525 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 526 | DEnd = E->designators_end(); |
| 527 | D != DEnd; ++D) { |
| 528 | if (D->isFieldDesignator()) { |
| 529 | if (FieldDecl *Field = D->getField()) { |
| 530 | Record.push_back(pch::DESIG_FIELD_DECL); |
| 531 | Writer.AddDeclRef(Field, Record); |
| 532 | } else { |
| 533 | Record.push_back(pch::DESIG_FIELD_NAME); |
| 534 | Writer.AddIdentifierRef(D->getFieldName(), Record); |
| 535 | } |
| 536 | Writer.AddSourceLocation(D->getDotLoc(), Record); |
| 537 | Writer.AddSourceLocation(D->getFieldLoc(), Record); |
| 538 | } else if (D->isArrayDesignator()) { |
| 539 | Record.push_back(pch::DESIG_ARRAY); |
| 540 | Record.push_back(D->getFirstExprIndex()); |
| 541 | Writer.AddSourceLocation(D->getLBracketLoc(), Record); |
| 542 | Writer.AddSourceLocation(D->getRBracketLoc(), Record); |
| 543 | } else { |
| 544 | assert(D->isArrayRangeDesignator() && "Unknown designator"); |
| 545 | Record.push_back(pch::DESIG_ARRAY_RANGE); |
| 546 | Record.push_back(D->getFirstExprIndex()); |
| 547 | Writer.AddSourceLocation(D->getLBracketLoc(), Record); |
| 548 | Writer.AddSourceLocation(D->getEllipsisLoc(), Record); |
| 549 | Writer.AddSourceLocation(D->getRBracketLoc(), Record); |
| 550 | } |
| 551 | } |
| 552 | Code = pch::EXPR_DESIGNATED_INIT; |
| 553 | } |
| 554 | |
| 555 | void PCHStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 556 | VisitExpr(E); |
| 557 | Code = pch::EXPR_IMPLICIT_VALUE_INIT; |
| 558 | } |
| 559 | |
| 560 | void PCHStmtWriter::VisitVAArgExpr(VAArgExpr *E) { |
| 561 | VisitExpr(E); |
| 562 | Writer.WriteSubStmt(E->getSubExpr()); |
| 563 | Writer.AddSourceLocation(E->getBuiltinLoc(), Record); |
| 564 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 565 | Code = pch::EXPR_VA_ARG; |
| 566 | } |
| 567 | |
| 568 | void PCHStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 569 | VisitExpr(E); |
| 570 | Writer.AddSourceLocation(E->getAmpAmpLoc(), Record); |
| 571 | Writer.AddSourceLocation(E->getLabelLoc(), Record); |
| 572 | Record.push_back(Writer.GetLabelID(E->getLabel())); |
| 573 | Code = pch::EXPR_ADDR_LABEL; |
| 574 | } |
| 575 | |
| 576 | void PCHStmtWriter::VisitStmtExpr(StmtExpr *E) { |
| 577 | VisitExpr(E); |
| 578 | Writer.WriteSubStmt(E->getSubStmt()); |
| 579 | Writer.AddSourceLocation(E->getLParenLoc(), Record); |
| 580 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 581 | Code = pch::EXPR_STMT; |
| 582 | } |
| 583 | |
| 584 | void PCHStmtWriter::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { |
| 585 | VisitExpr(E); |
| 586 | Writer.AddTypeRef(E->getArgType1(), Record); |
| 587 | Writer.AddTypeRef(E->getArgType2(), Record); |
| 588 | Writer.AddSourceLocation(E->getBuiltinLoc(), Record); |
| 589 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 590 | Code = pch::EXPR_TYPES_COMPATIBLE; |
| 591 | } |
| 592 | |
| 593 | void PCHStmtWriter::VisitChooseExpr(ChooseExpr *E) { |
| 594 | VisitExpr(E); |
| 595 | Writer.WriteSubStmt(E->getCond()); |
| 596 | Writer.WriteSubStmt(E->getLHS()); |
| 597 | Writer.WriteSubStmt(E->getRHS()); |
| 598 | Writer.AddSourceLocation(E->getBuiltinLoc(), Record); |
| 599 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 600 | Code = pch::EXPR_CHOOSE; |
| 601 | } |
| 602 | |
| 603 | void PCHStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 604 | VisitExpr(E); |
| 605 | Writer.AddSourceLocation(E->getTokenLocation(), Record); |
| 606 | Code = pch::EXPR_GNU_NULL; |
| 607 | } |
| 608 | |
| 609 | void PCHStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { |
| 610 | VisitExpr(E); |
| 611 | Record.push_back(E->getNumSubExprs()); |
| 612 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) |
| 613 | Writer.WriteSubStmt(E->getExpr(I)); |
| 614 | Writer.AddSourceLocation(E->getBuiltinLoc(), Record); |
| 615 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 616 | Code = pch::EXPR_SHUFFLE_VECTOR; |
| 617 | } |
| 618 | |
| 619 | void PCHStmtWriter::VisitBlockExpr(BlockExpr *E) { |
| 620 | VisitExpr(E); |
| 621 | Writer.AddDeclRef(E->getBlockDecl(), Record); |
| 622 | Record.push_back(E->hasBlockDeclRefExprs()); |
| 623 | Code = pch::EXPR_BLOCK; |
| 624 | } |
| 625 | |
| 626 | void PCHStmtWriter::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { |
| 627 | VisitExpr(E); |
| 628 | Writer.AddDeclRef(E->getDecl(), Record); |
| 629 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 630 | Record.push_back(E->isByRef()); |
Fariborz Jahanian | 9b0b57c | 2009-06-20 00:02:26 +0000 | [diff] [blame] | 631 | Record.push_back(E->isConstQualAdded()); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 632 | Code = pch::EXPR_BLOCK_DECL_REF; |
| 633 | } |
| 634 | |
| 635 | //===----------------------------------------------------------------------===// |
| 636 | // Objective-C Expressions and Statements. |
| 637 | //===----------------------------------------------------------------------===// |
| 638 | |
| 639 | void PCHStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) { |
| 640 | VisitExpr(E); |
| 641 | Writer.WriteSubStmt(E->getString()); |
| 642 | Writer.AddSourceLocation(E->getAtLoc(), Record); |
| 643 | Code = pch::EXPR_OBJC_STRING_LITERAL; |
| 644 | } |
| 645 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | void PCHStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 647 | VisitExpr(E); |
| 648 | Writer.AddTypeRef(E->getEncodedType(), Record); |
| 649 | Writer.AddSourceLocation(E->getAtLoc(), Record); |
| 650 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 651 | Code = pch::EXPR_OBJC_ENCODE; |
| 652 | } |
| 653 | |
| 654 | void PCHStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { |
| 655 | VisitExpr(E); |
| 656 | Writer.AddSelectorRef(E->getSelector(), Record); |
| 657 | Writer.AddSourceLocation(E->getAtLoc(), Record); |
| 658 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 659 | Code = pch::EXPR_OBJC_SELECTOR_EXPR; |
| 660 | } |
| 661 | |
| 662 | void PCHStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { |
| 663 | VisitExpr(E); |
| 664 | Writer.AddDeclRef(E->getProtocol(), Record); |
| 665 | Writer.AddSourceLocation(E->getAtLoc(), Record); |
| 666 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 667 | Code = pch::EXPR_OBJC_PROTOCOL_EXPR; |
| 668 | } |
| 669 | |
| 670 | void PCHStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| 671 | VisitExpr(E); |
| 672 | Writer.AddDeclRef(E->getDecl(), Record); |
| 673 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 674 | Writer.WriteSubStmt(E->getBase()); |
| 675 | Record.push_back(E->isArrow()); |
| 676 | Record.push_back(E->isFreeIvar()); |
| 677 | Code = pch::EXPR_OBJC_IVAR_REF_EXPR; |
| 678 | } |
| 679 | |
| 680 | void PCHStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 681 | VisitExpr(E); |
| 682 | Writer.AddDeclRef(E->getProperty(), Record); |
| 683 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 684 | Writer.WriteSubStmt(E->getBase()); |
| 685 | Code = pch::EXPR_OBJC_PROPERTY_REF_EXPR; |
| 686 | } |
| 687 | |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 688 | void PCHStmtWriter::VisitObjCImplicitSetterGetterRefExpr( |
| 689 | ObjCImplicitSetterGetterRefExpr *E) { |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 690 | VisitExpr(E); |
| 691 | Writer.AddDeclRef(E->getGetterMethod(), Record); |
| 692 | Writer.AddDeclRef(E->getSetterMethod(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 693 | |
Fariborz Jahanian | d2ae5aa | 2009-08-18 21:37:33 +0000 | [diff] [blame] | 694 | // NOTE: InterfaceDecl and Base are mutually exclusive. |
| 695 | Writer.AddDeclRef(E->getInterfaceDecl(), Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 696 | Writer.WriteSubStmt(E->getBase()); |
| 697 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 698 | Writer.AddSourceLocation(E->getClassLoc(), Record); |
| 699 | Code = pch::EXPR_OBJC_KVC_REF_EXPR; |
| 700 | } |
| 701 | |
| 702 | void PCHStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) { |
| 703 | VisitExpr(E); |
| 704 | Record.push_back(E->getNumArgs()); |
| 705 | Writer.AddSourceLocation(E->getLeftLoc(), Record); |
| 706 | Writer.AddSourceLocation(E->getRightLoc(), Record); |
| 707 | Writer.AddSelectorRef(E->getSelector(), Record); |
| 708 | Writer.AddDeclRef(E->getMethodDecl(), Record); // optional |
| 709 | Writer.WriteSubStmt(E->getReceiver()); |
| 710 | |
| 711 | if (!E->getReceiver()) { |
| 712 | ObjCMessageExpr::ClassInfo CI = E->getClassInfo(); |
| 713 | Writer.AddDeclRef(CI.first, Record); |
| 714 | Writer.AddIdentifierRef(CI.second, Record); |
| 715 | } |
| 716 | |
| 717 | for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); |
| 718 | Arg != ArgEnd; ++Arg) |
| 719 | Writer.WriteSubStmt(*Arg); |
| 720 | Code = pch::EXPR_OBJC_MESSAGE_EXPR; |
| 721 | } |
| 722 | |
| 723 | void PCHStmtWriter::VisitObjCSuperExpr(ObjCSuperExpr *E) { |
| 724 | VisitExpr(E); |
| 725 | Writer.AddSourceLocation(E->getLoc(), Record); |
| 726 | Code = pch::EXPR_OBJC_SUPER_EXPR; |
| 727 | } |
| 728 | |
| 729 | void PCHStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 730 | VisitStmt(S); |
| 731 | Writer.WriteSubStmt(S->getElement()); |
| 732 | Writer.WriteSubStmt(S->getCollection()); |
| 733 | Writer.WriteSubStmt(S->getBody()); |
| 734 | Writer.AddSourceLocation(S->getForLoc(), Record); |
| 735 | Writer.AddSourceLocation(S->getRParenLoc(), Record); |
| 736 | Code = pch::STMT_OBJC_FOR_COLLECTION; |
| 737 | } |
| 738 | |
| 739 | void PCHStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 740 | Writer.WriteSubStmt(S->getCatchBody()); |
| 741 | Writer.WriteSubStmt(S->getNextCatchStmt()); |
| 742 | Writer.AddDeclRef(S->getCatchParamDecl(), Record); |
| 743 | Writer.AddSourceLocation(S->getAtCatchLoc(), Record); |
| 744 | Writer.AddSourceLocation(S->getRParenLoc(), Record); |
| 745 | Code = pch::STMT_OBJC_CATCH; |
| 746 | } |
| 747 | |
| 748 | void PCHStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 749 | Writer.WriteSubStmt(S->getFinallyBody()); |
| 750 | Writer.AddSourceLocation(S->getAtFinallyLoc(), Record); |
| 751 | Code = pch::STMT_OBJC_FINALLY; |
| 752 | } |
| 753 | |
| 754 | void PCHStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 755 | Writer.WriteSubStmt(S->getTryBody()); |
| 756 | Writer.WriteSubStmt(S->getCatchStmts()); |
| 757 | Writer.WriteSubStmt(S->getFinallyStmt()); |
| 758 | Writer.AddSourceLocation(S->getAtTryLoc(), Record); |
| 759 | Code = pch::STMT_OBJC_AT_TRY; |
| 760 | } |
| 761 | |
| 762 | void PCHStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { |
| 763 | Writer.WriteSubStmt(S->getSynchExpr()); |
| 764 | Writer.WriteSubStmt(S->getSynchBody()); |
| 765 | Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record); |
| 766 | Code = pch::STMT_OBJC_AT_SYNCHRONIZED; |
| 767 | } |
| 768 | |
| 769 | void PCHStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 770 | Writer.WriteSubStmt(S->getThrowExpr()); |
| 771 | Writer.AddSourceLocation(S->getThrowLoc(), Record); |
| 772 | Code = pch::STMT_OBJC_AT_THROW; |
| 773 | } |
| 774 | |
| 775 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | ba0a900 | 2009-07-14 03:19:21 +0000 | [diff] [blame] | 776 | // C++ Expressions and Statements. |
| 777 | //===----------------------------------------------------------------------===// |
| 778 | |
| 779 | void PCHStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
| 780 | VisitCallExpr(E); |
| 781 | Record.push_back(E->getOperator()); |
| 782 | Code = pch::EXPR_CXX_OPERATOR_CALL; |
| 783 | } |
| 784 | |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 785 | void PCHStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 786 | VisitExpr(E); |
| 787 | Writer.AddDeclRef(E->getConstructor(), Record); |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 788 | Writer.AddSourceLocation(E->getLocation(), Record); |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 789 | Record.push_back(E->isElidable()); |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame^] | 790 | Record.push_back(E->requiresZeroInitialization()); |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 791 | Record.push_back(E->getNumArgs()); |
| 792 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) |
| 793 | Writer.WriteSubStmt(E->getArg(I)); |
| 794 | Code = pch::EXPR_CXX_CONSTRUCT; |
| 795 | } |
| 796 | |
Argyrios Kyrtzidis | ba0a900 | 2009-07-14 03:19:21 +0000 | [diff] [blame] | 797 | //===----------------------------------------------------------------------===// |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 798 | // PCHWriter Implementation |
| 799 | //===----------------------------------------------------------------------===// |
| 800 | |
| 801 | unsigned PCHWriter::RecordSwitchCaseID(SwitchCase *S) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 802 | assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() && |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 803 | "SwitchCase recorded twice"); |
| 804 | unsigned NextID = SwitchCaseIDs.size(); |
| 805 | SwitchCaseIDs[S] = NextID; |
| 806 | return NextID; |
| 807 | } |
| 808 | |
| 809 | unsigned PCHWriter::getSwitchCaseID(SwitchCase *S) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 810 | assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() && |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 811 | "SwitchCase hasn't been seen yet"); |
| 812 | return SwitchCaseIDs[S]; |
| 813 | } |
| 814 | |
| 815 | /// \brief Retrieve the ID for the given label statement, which may |
| 816 | /// or may not have been emitted yet. |
| 817 | unsigned PCHWriter::GetLabelID(LabelStmt *S) { |
| 818 | std::map<LabelStmt *, unsigned>::iterator Pos = LabelIDs.find(S); |
| 819 | if (Pos != LabelIDs.end()) |
| 820 | return Pos->second; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 821 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 822 | unsigned NextID = LabelIDs.size(); |
| 823 | LabelIDs[S] = NextID; |
| 824 | return NextID; |
| 825 | } |
| 826 | |
| 827 | /// \brief Write the given substatement or subexpression to the |
| 828 | /// bitstream. |
| 829 | void PCHWriter::WriteSubStmt(Stmt *S) { |
| 830 | RecordData Record; |
| 831 | PCHStmtWriter Writer(*this, Record); |
| 832 | ++NumStatements; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 834 | if (!S) { |
| 835 | Stream.EmitRecord(pch::STMT_NULL_PTR, Record); |
| 836 | return; |
| 837 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 838 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 839 | Writer.Code = pch::STMT_NULL_PTR; |
| 840 | Writer.Visit(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | assert(Writer.Code != pch::STMT_NULL_PTR && |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 842 | "Unhandled expression writing PCH file"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | Stream.EmitRecord(Writer.Code, Record); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | /// \brief Flush all of the statements that have been added to the |
| 847 | /// queue via AddStmt(). |
| 848 | void PCHWriter::FlushStmts() { |
| 849 | RecordData Record; |
| 850 | PCHStmtWriter Writer(*this, Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 851 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 852 | for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) { |
| 853 | ++NumStatements; |
| 854 | Stmt *S = StmtsToEmit[I]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 855 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 856 | if (!S) { |
| 857 | Stream.EmitRecord(pch::STMT_NULL_PTR, Record); |
| 858 | continue; |
| 859 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 861 | Writer.Code = pch::STMT_NULL_PTR; |
| 862 | Writer.Visit(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 863 | assert(Writer.Code != pch::STMT_NULL_PTR && |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 864 | "Unhandled expression writing PCH file"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 865 | Stream.EmitRecord(Writer.Code, Record); |
| 866 | |
| 867 | assert(N == StmtsToEmit.size() && |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 868 | "Substatement writen via AddStmt rather than WriteSubStmt!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 870 | // Note that we are at the end of a full expression. Any |
| 871 | // expression records that follow this one are part of a different |
| 872 | // expression. |
| 873 | Record.clear(); |
| 874 | Stream.EmitRecord(pch::STMT_STOP, Record); |
| 875 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 876 | |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 877 | StmtsToEmit.clear(); |
Chris Lattner | 63377d5 | 2009-04-27 06:20:01 +0000 | [diff] [blame] | 878 | } |