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