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