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