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