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