blob: 4d2fb8a0301fc45ef112d3191e23f664958c0a50 [file] [log] [blame]
Sebastian Redl4ee2ad02010-08-18 23:56:31 +00001//===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
Chris Lattner63377d52009-04-27 06:20:01 +00002//
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
Sebastian Redl7faa2ec2010-08-18 23:56:37 +000014#include "clang/Serialization/ASTWriter.h"
Douglas Gregor39da0b82009-09-09 23:08:42 +000015#include "clang/AST/DeclCXX.h"
Chris Lattner63377d52009-04-27 06:20:01 +000016#include "clang/AST/DeclObjC.h"
17#include "clang/AST/StmtVisitor.h"
18#include "llvm/Bitcode/BitstreamWriter.h"
19using namespace clang;
20
21//===----------------------------------------------------------------------===//
22// Statement/expression serialization
23//===----------------------------------------------------------------------===//
24
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +000025namespace clang {
Sebastian Redl3397c552010-08-18 23:56:27 +000026 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
Sebastian Redla4232eb2010-08-18 23:56:21 +000027 ASTWriter &Writer;
28 ASTWriter::RecordData &Record;
Chris Lattner63377d52009-04-27 06:20:01 +000029
30 public:
Sebastian Redl8538e8d2010-08-18 23:57:32 +000031 serialization::StmtCode Code;
Chris Lattner63377d52009-04-27 06:20:01 +000032
Sebastian Redl3397c552010-08-18 23:56:27 +000033 ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
Chris Lattner63377d52009-04-27 06:20:01 +000034 : Writer(Writer), Record(Record) { }
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +000035
36 void
37 AddExplicitTemplateArgumentList(const ExplicitTemplateArgumentList &Args);
Chris Lattner63377d52009-04-27 06:20:01 +000038
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 Kyrtzidis37bdfe22010-06-30 08:49:18 +000067 void VisitParenListExpr(ParenListExpr *E);
Chris Lattner63377d52009-04-27 06:20:01 +000068 void VisitUnaryOperator(UnaryOperator *E);
Douglas Gregor8ecdb652010-04-28 22:16:22 +000069 void VisitOffsetOfExpr(OffsetOfExpr *E);
Chris Lattner63377d52009-04-27 06:20:01 +000070 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 Stump1eb44332009-09-09 15:08:12 +000095
Chris Lattner63377d52009-04-27 06:20:01 +000096 // 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 Jahanian09105f52009-08-20 17:02:02 +0000103 void VisitObjCImplicitSetterGetterRefExpr(
104 ObjCImplicitSetterGetterRefExpr *E);
Chris Lattner63377d52009-04-27 06:20:01 +0000105 void VisitObjCMessageExpr(ObjCMessageExpr *E);
Steve Narofff242b1b2009-07-24 17:54:45 +0000106 void VisitObjCIsaExpr(ObjCIsaExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000107
108 // Objective-C Statements
Chris Lattner63377d52009-04-27 06:20:01 +0000109 void VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
110 void VisitObjCAtCatchStmt(ObjCAtCatchStmt *);
111 void VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *);
112 void VisitObjCAtTryStmt(ObjCAtTryStmt *);
113 void VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
114 void VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000115
Mike Stump1eb44332009-09-09 15:08:12 +0000116 // C++ Statements
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000117 void VisitCXXCatchStmt(CXXCatchStmt *S);
118 void VisitCXXTryStmt(CXXTryStmt *S);
119
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000120 void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
Chris Lattner1817bd42010-05-09 05:36:05 +0000121 void VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
Douglas Gregor39da0b82009-09-09 23:08:42 +0000122 void VisitCXXConstructExpr(CXXConstructExpr *E);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000123 void VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
Sam Weinigce757a72010-01-16 21:21:01 +0000124 void VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
125 void VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
126 void VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
127 void VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
128 void VisitCXXConstCastExpr(CXXConstCastExpr *E);
129 void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
Sam Weinigeb7f9612010-02-07 06:32:43 +0000130 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
131 void VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
Chris Lattner14ab24f2010-05-09 06:03:39 +0000132 void VisitCXXTypeidExpr(CXXTypeidExpr *E);
Francois Pichet01b7c302010-09-08 12:20:18 +0000133 void VisitCXXUuidofExpr(CXXUuidofExpr *E);
Chris Lattner2fbdfcd2010-05-09 06:15:05 +0000134 void VisitCXXThisExpr(CXXThisExpr *E);
135 void VisitCXXThrowExpr(CXXThrowExpr *E);
Chris Lattner030854b2010-05-09 06:40:08 +0000136 void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
Chris Lattnerd2598362010-05-10 00:25:06 +0000137 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000138
Douglas Gregored8abf12010-07-08 06:14:04 +0000139 void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
Chris Lattner59218632010-05-10 01:22:27 +0000140 void VisitCXXNewExpr(CXXNewExpr *E);
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +0000141 void VisitCXXDeleteExpr(CXXDeleteExpr *E);
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +0000142 void VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000143
Chris Lattnerd2598362010-05-10 00:25:06 +0000144 void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000145 void VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000146 void VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000147 void VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000148
149 void VisitOverloadExpr(OverloadExpr *E);
150 void VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000151 void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000152
153 void VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E);
Sebastian Redl6b219d02010-09-10 20:55:54 +0000154 void VisitCXXNoexceptExpr(CXXNoexceptExpr *E);
John McCall7cd7d1a2010-11-15 23:31:06 +0000155
156 void VisitOpaqueValueExpr(OpaqueValueExpr *E);
Chris Lattner63377d52009-04-27 06:20:01 +0000157 };
158}
159
Sebastian Redl3397c552010-08-18 23:56:27 +0000160void ASTStmtWriter::
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +0000161AddExplicitTemplateArgumentList(const ExplicitTemplateArgumentList &Args) {
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +0000162 Writer.AddSourceLocation(Args.LAngleLoc, Record);
163 Writer.AddSourceLocation(Args.RAngleLoc, Record);
164 for (unsigned i=0; i != Args.NumTemplateArgs; ++i)
165 Writer.AddTemplateArgumentLoc(Args.getTemplateArgs()[i], Record);
166}
167
Sebastian Redl3397c552010-08-18 23:56:27 +0000168void ASTStmtWriter::VisitStmt(Stmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000169}
170
Sebastian Redl3397c552010-08-18 23:56:27 +0000171void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000172 VisitStmt(S);
173 Writer.AddSourceLocation(S->getSemiLoc(), Record);
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000174 Record.push_back(S->LeadingEmptyMacro);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000175 Code = serialization::STMT_NULL;
Chris Lattner63377d52009-04-27 06:20:01 +0000176}
177
Sebastian Redl3397c552010-08-18 23:56:27 +0000178void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000179 VisitStmt(S);
180 Record.push_back(S->size());
181 for (CompoundStmt::body_iterator CS = S->body_begin(), CSEnd = S->body_end();
182 CS != CSEnd; ++CS)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000183 Writer.AddStmt(*CS);
Chris Lattner63377d52009-04-27 06:20:01 +0000184 Writer.AddSourceLocation(S->getLBracLoc(), Record);
185 Writer.AddSourceLocation(S->getRBracLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000186 Code = serialization::STMT_COMPOUND;
Chris Lattner63377d52009-04-27 06:20:01 +0000187}
188
Sebastian Redl3397c552010-08-18 23:56:27 +0000189void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000190 VisitStmt(S);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000191 Record.push_back(Writer.getSwitchCaseID(S));
Chris Lattner63377d52009-04-27 06:20:01 +0000192}
193
Sebastian Redl3397c552010-08-18 23:56:27 +0000194void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000195 VisitSwitchCase(S);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000196 Writer.AddStmt(S->getLHS());
197 Writer.AddStmt(S->getRHS());
198 Writer.AddStmt(S->getSubStmt());
Chris Lattner63377d52009-04-27 06:20:01 +0000199 Writer.AddSourceLocation(S->getCaseLoc(), Record);
Douglas Gregordbb26db2009-05-15 23:57:33 +0000200 Writer.AddSourceLocation(S->getEllipsisLoc(), Record);
201 Writer.AddSourceLocation(S->getColonLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000202 Code = serialization::STMT_CASE;
Chris Lattner63377d52009-04-27 06:20:01 +0000203}
204
Sebastian Redl3397c552010-08-18 23:56:27 +0000205void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000206 VisitSwitchCase(S);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000207 Writer.AddStmt(S->getSubStmt());
Chris Lattner63377d52009-04-27 06:20:01 +0000208 Writer.AddSourceLocation(S->getDefaultLoc(), Record);
Douglas Gregordbb26db2009-05-15 23:57:33 +0000209 Writer.AddSourceLocation(S->getColonLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000210 Code = serialization::STMT_DEFAULT;
Chris Lattner63377d52009-04-27 06:20:01 +0000211}
212
Sebastian Redl3397c552010-08-18 23:56:27 +0000213void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000214 VisitStmt(S);
215 Writer.AddIdentifierRef(S->getID(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000216 Writer.AddStmt(S->getSubStmt());
Chris Lattner63377d52009-04-27 06:20:01 +0000217 Writer.AddSourceLocation(S->getIdentLoc(), Record);
Argyrios Kyrtzidis355a9fe2010-09-19 21:21:25 +0000218 Record.push_back(S->isUsed());
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000219 Record.push_back(S->HasUnusedAttribute());
Chris Lattner63377d52009-04-27 06:20:01 +0000220 Record.push_back(Writer.GetLabelID(S));
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000221 Code = serialization::STMT_LABEL;
Chris Lattner63377d52009-04-27 06:20:01 +0000222}
223
Sebastian Redl3397c552010-08-18 23:56:27 +0000224void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000225 VisitStmt(S);
Douglas Gregor8cfe5a72009-11-23 23:44:04 +0000226 Writer.AddDeclRef(S->getConditionVariable(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000227 Writer.AddStmt(S->getCond());
228 Writer.AddStmt(S->getThen());
229 Writer.AddStmt(S->getElse());
Chris Lattner63377d52009-04-27 06:20:01 +0000230 Writer.AddSourceLocation(S->getIfLoc(), Record);
Douglas Gregord06f6ca2009-05-15 18:53:42 +0000231 Writer.AddSourceLocation(S->getElseLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000232 Code = serialization::STMT_IF;
Chris Lattner63377d52009-04-27 06:20:01 +0000233}
234
Sebastian Redl3397c552010-08-18 23:56:27 +0000235void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000236 VisitStmt(S);
Douglas Gregord3d53012009-11-24 17:07:59 +0000237 Writer.AddDeclRef(S->getConditionVariable(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000238 Writer.AddStmt(S->getCond());
239 Writer.AddStmt(S->getBody());
Chris Lattner63377d52009-04-27 06:20:01 +0000240 Writer.AddSourceLocation(S->getSwitchLoc(), Record);
Ted Kremenek559fb552010-09-09 00:05:53 +0000241 Record.push_back(S->isAllEnumCasesCovered());
Mike Stump1eb44332009-09-09 15:08:12 +0000242 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
Chris Lattner63377d52009-04-27 06:20:01 +0000243 SC = SC->getNextSwitchCase())
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000244 Record.push_back(Writer.RecordSwitchCaseID(SC));
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000245 Code = serialization::STMT_SWITCH;
Chris Lattner63377d52009-04-27 06:20:01 +0000246}
247
Sebastian Redl3397c552010-08-18 23:56:27 +0000248void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000249 VisitStmt(S);
Douglas Gregor5656e142009-11-24 21:15:44 +0000250 Writer.AddDeclRef(S->getConditionVariable(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000251 Writer.AddStmt(S->getCond());
252 Writer.AddStmt(S->getBody());
Chris Lattner63377d52009-04-27 06:20:01 +0000253 Writer.AddSourceLocation(S->getWhileLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000254 Code = serialization::STMT_WHILE;
Chris Lattner63377d52009-04-27 06:20:01 +0000255}
256
Sebastian Redl3397c552010-08-18 23:56:27 +0000257void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000258 VisitStmt(S);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000259 Writer.AddStmt(S->getCond());
260 Writer.AddStmt(S->getBody());
Chris Lattner63377d52009-04-27 06:20:01 +0000261 Writer.AddSourceLocation(S->getDoLoc(), Record);
Douglas Gregor9f3ca2a2009-05-15 21:56:04 +0000262 Writer.AddSourceLocation(S->getWhileLoc(), Record);
Chris Lattner98913592009-06-12 23:04:47 +0000263 Writer.AddSourceLocation(S->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000264 Code = serialization::STMT_DO;
Chris Lattner63377d52009-04-27 06:20:01 +0000265}
266
Sebastian Redl3397c552010-08-18 23:56:27 +0000267void ASTStmtWriter::VisitForStmt(ForStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000268 VisitStmt(S);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000269 Writer.AddStmt(S->getInit());
270 Writer.AddStmt(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000271 Writer.AddDeclRef(S->getConditionVariable(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000272 Writer.AddStmt(S->getInc());
273 Writer.AddStmt(S->getBody());
Chris Lattner63377d52009-04-27 06:20:01 +0000274 Writer.AddSourceLocation(S->getForLoc(), Record);
Douglas Gregor5831c6a2009-05-15 22:12:32 +0000275 Writer.AddSourceLocation(S->getLParenLoc(), Record);
276 Writer.AddSourceLocation(S->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000277 Code = serialization::STMT_FOR;
Chris Lattner63377d52009-04-27 06:20:01 +0000278}
279
Sebastian Redl3397c552010-08-18 23:56:27 +0000280void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000281 VisitStmt(S);
282 Record.push_back(Writer.GetLabelID(S->getLabel()));
283 Writer.AddSourceLocation(S->getGotoLoc(), Record);
284 Writer.AddSourceLocation(S->getLabelLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000285 Code = serialization::STMT_GOTO;
Chris Lattner63377d52009-04-27 06:20:01 +0000286}
287
Sebastian Redl3397c552010-08-18 23:56:27 +0000288void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000289 VisitStmt(S);
290 Writer.AddSourceLocation(S->getGotoLoc(), Record);
Douglas Gregor5f1b9e62009-05-16 00:20:29 +0000291 Writer.AddSourceLocation(S->getStarLoc(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000292 Writer.AddStmt(S->getTarget());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000293 Code = serialization::STMT_INDIRECT_GOTO;
Chris Lattner63377d52009-04-27 06:20:01 +0000294}
295
Sebastian Redl3397c552010-08-18 23:56:27 +0000296void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000297 VisitStmt(S);
298 Writer.AddSourceLocation(S->getContinueLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000299 Code = serialization::STMT_CONTINUE;
Chris Lattner63377d52009-04-27 06:20:01 +0000300}
301
Sebastian Redl3397c552010-08-18 23:56:27 +0000302void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000303 VisitStmt(S);
304 Writer.AddSourceLocation(S->getBreakLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000305 Code = serialization::STMT_BREAK;
Chris Lattner63377d52009-04-27 06:20:01 +0000306}
307
Sebastian Redl3397c552010-08-18 23:56:27 +0000308void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000309 VisitStmt(S);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000310 Writer.AddStmt(S->getRetValue());
Chris Lattner63377d52009-04-27 06:20:01 +0000311 Writer.AddSourceLocation(S->getReturnLoc(), Record);
Douglas Gregor5077c382010-05-15 06:01:05 +0000312 Writer.AddDeclRef(S->getNRVOCandidate(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000313 Code = serialization::STMT_RETURN;
Chris Lattner63377d52009-04-27 06:20:01 +0000314}
315
Sebastian Redl3397c552010-08-18 23:56:27 +0000316void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000317 VisitStmt(S);
318 Writer.AddSourceLocation(S->getStartLoc(), Record);
319 Writer.AddSourceLocation(S->getEndLoc(), Record);
320 DeclGroupRef DG = S->getDeclGroup();
321 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
322 Writer.AddDeclRef(*D, Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000323 Code = serialization::STMT_DECL;
Chris Lattner63377d52009-04-27 06:20:01 +0000324}
325
Sebastian Redl3397c552010-08-18 23:56:27 +0000326void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000327 VisitStmt(S);
328 Record.push_back(S->getNumOutputs());
329 Record.push_back(S->getNumInputs());
330 Record.push_back(S->getNumClobbers());
331 Writer.AddSourceLocation(S->getAsmLoc(), Record);
332 Writer.AddSourceLocation(S->getRParenLoc(), Record);
333 Record.push_back(S->isVolatile());
334 Record.push_back(S->isSimple());
Mike Stump3b11fd32010-01-04 22:37:17 +0000335 Record.push_back(S->isMSAsm());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000336 Writer.AddStmt(S->getAsmString());
Chris Lattner63377d52009-04-27 06:20:01 +0000337
338 // Outputs
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000339 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
340 Writer.AddIdentifierRef(S->getOutputIdentifier(I), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000341 Writer.AddStmt(S->getOutputConstraintLiteral(I));
342 Writer.AddStmt(S->getOutputExpr(I));
Chris Lattner63377d52009-04-27 06:20:01 +0000343 }
344
345 // Inputs
346 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000347 Writer.AddIdentifierRef(S->getInputIdentifier(I), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000348 Writer.AddStmt(S->getInputConstraintLiteral(I));
349 Writer.AddStmt(S->getInputExpr(I));
Chris Lattner63377d52009-04-27 06:20:01 +0000350 }
351
352 // Clobbers
353 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000354 Writer.AddStmt(S->getClobber(I));
Chris Lattner63377d52009-04-27 06:20:01 +0000355
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000356 Code = serialization::STMT_ASM;
Chris Lattner63377d52009-04-27 06:20:01 +0000357}
358
Sebastian Redl3397c552010-08-18 23:56:27 +0000359void ASTStmtWriter::VisitExpr(Expr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000360 VisitStmt(E);
361 Writer.AddTypeRef(E->getType(), Record);
362 Record.push_back(E->isTypeDependent());
363 Record.push_back(E->isValueDependent());
John McCallf89e55a2010-11-18 06:31:45 +0000364 Record.push_back(E->getValueKind());
365 Record.push_back(E->getObjectKind());
Chris Lattner63377d52009-04-27 06:20:01 +0000366}
367
Sebastian Redl3397c552010-08-18 23:56:27 +0000368void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000369 VisitExpr(E);
370 Writer.AddSourceLocation(E->getLocation(), Record);
371 Record.push_back(E->getIdentType()); // FIXME: stable encoding
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000372 Code = serialization::EXPR_PREDEFINED;
Chris Lattner63377d52009-04-27 06:20:01 +0000373}
374
Sebastian Redl3397c552010-08-18 23:56:27 +0000375void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000376 VisitExpr(E);
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000377
378 Record.push_back(E->hasQualifier());
379 unsigned NumTemplateArgs = E->getNumTemplateArgs();
John McCall096832c2010-08-19 23:49:38 +0000380 assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000381 "Template args list with no args ?");
382 Record.push_back(NumTemplateArgs);
383
384 if (E->hasQualifier()) {
385 Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
386 Writer.AddSourceRange(E->getQualifierRange(), Record);
387 }
388
389 if (NumTemplateArgs)
John McCall096832c2010-08-19 23:49:38 +0000390 AddExplicitTemplateArgumentList(E->getExplicitTemplateArgs());
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000391
Chris Lattner63377d52009-04-27 06:20:01 +0000392 Writer.AddDeclRef(E->getDecl(), Record);
393 Writer.AddSourceLocation(E->getLocation(), Record);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000394 Writer.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000395 Code = serialization::EXPR_DECL_REF;
Chris Lattner63377d52009-04-27 06:20:01 +0000396}
397
Sebastian Redl3397c552010-08-18 23:56:27 +0000398void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000399 VisitExpr(E);
400 Writer.AddSourceLocation(E->getLocation(), Record);
401 Writer.AddAPInt(E->getValue(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000402 Code = serialization::EXPR_INTEGER_LITERAL;
Chris Lattner63377d52009-04-27 06:20:01 +0000403}
404
Sebastian Redl3397c552010-08-18 23:56:27 +0000405void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000406 VisitExpr(E);
407 Writer.AddAPFloat(E->getValue(), Record);
408 Record.push_back(E->isExact());
409 Writer.AddSourceLocation(E->getLocation(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000410 Code = serialization::EXPR_FLOATING_LITERAL;
Chris Lattner63377d52009-04-27 06:20:01 +0000411}
412
Sebastian Redl3397c552010-08-18 23:56:27 +0000413void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000414 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000415 Writer.AddStmt(E->getSubExpr());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000416 Code = serialization::EXPR_IMAGINARY_LITERAL;
Chris Lattner63377d52009-04-27 06:20:01 +0000417}
418
Sebastian Redl3397c552010-08-18 23:56:27 +0000419void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000420 VisitExpr(E);
421 Record.push_back(E->getByteLength());
422 Record.push_back(E->getNumConcatenated());
423 Record.push_back(E->isWide());
424 // FIXME: String data should be stored as a blob at the end of the
425 // StringLiteral. However, we can't do so now because we have no
426 // provision for coping with abbreviations when we're jumping around
Sebastian Redl3397c552010-08-18 23:56:27 +0000427 // the AST file during deserialization.
Benjamin Kramer2f4eaef2010-08-17 12:54:38 +0000428 Record.append(E->getString().begin(), E->getString().end());
Chris Lattner63377d52009-04-27 06:20:01 +0000429 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
430 Writer.AddSourceLocation(E->getStrTokenLoc(I), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000431 Code = serialization::EXPR_STRING_LITERAL;
Chris Lattner63377d52009-04-27 06:20:01 +0000432}
433
Sebastian Redl3397c552010-08-18 23:56:27 +0000434void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000435 VisitExpr(E);
436 Record.push_back(E->getValue());
Chris Lattner018d8e02009-08-24 17:39:36 +0000437 Writer.AddSourceLocation(E->getLocation(), Record);
Chris Lattner63377d52009-04-27 06:20:01 +0000438 Record.push_back(E->isWide());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000439 Code = serialization::EXPR_CHARACTER_LITERAL;
Chris Lattner63377d52009-04-27 06:20:01 +0000440}
441
Sebastian Redl3397c552010-08-18 23:56:27 +0000442void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000443 VisitExpr(E);
444 Writer.AddSourceLocation(E->getLParen(), Record);
445 Writer.AddSourceLocation(E->getRParen(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000446 Writer.AddStmt(E->getSubExpr());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000447 Code = serialization::EXPR_PAREN;
Chris Lattner63377d52009-04-27 06:20:01 +0000448}
449
Sebastian Redl3397c552010-08-18 23:56:27 +0000450void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +0000451 VisitExpr(E);
452 Record.push_back(E->NumExprs);
453 for (unsigned i=0; i != E->NumExprs; ++i)
454 Writer.AddStmt(E->Exprs[i]);
455 Writer.AddSourceLocation(E->LParenLoc, Record);
456 Writer.AddSourceLocation(E->RParenLoc, Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000457 Code = serialization::EXPR_PAREN_LIST;
Argyrios Kyrtzidis37bdfe22010-06-30 08:49:18 +0000458}
459
Sebastian Redl3397c552010-08-18 23:56:27 +0000460void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000461 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000462 Writer.AddStmt(E->getSubExpr());
Chris Lattner63377d52009-04-27 06:20:01 +0000463 Record.push_back(E->getOpcode()); // FIXME: stable encoding
464 Writer.AddSourceLocation(E->getOperatorLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000465 Code = serialization::EXPR_UNARY_OPERATOR;
Chris Lattner63377d52009-04-27 06:20:01 +0000466}
467
Sebastian Redl3397c552010-08-18 23:56:27 +0000468void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000469 VisitExpr(E);
470 Record.push_back(E->getNumComponents());
471 Record.push_back(E->getNumExpressions());
472 Writer.AddSourceLocation(E->getOperatorLoc(), Record);
473 Writer.AddSourceLocation(E->getRParenLoc(), Record);
474 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
475 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
476 const OffsetOfExpr::OffsetOfNode &ON = E->getComponent(I);
477 Record.push_back(ON.getKind()); // FIXME: Stable encoding
478 Writer.AddSourceLocation(ON.getRange().getBegin(), Record);
479 Writer.AddSourceLocation(ON.getRange().getEnd(), Record);
480 switch (ON.getKind()) {
481 case OffsetOfExpr::OffsetOfNode::Array:
482 Record.push_back(ON.getArrayExprIndex());
483 break;
484
485 case OffsetOfExpr::OffsetOfNode::Field:
486 Writer.AddDeclRef(ON.getField(), Record);
487 break;
488
489 case OffsetOfExpr::OffsetOfNode::Identifier:
490 Writer.AddIdentifierRef(ON.getFieldName(), Record);
491 break;
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000492
493 case OffsetOfExpr::OffsetOfNode::Base:
Argyrios Kyrtzidisafbf3122010-07-29 18:16:10 +0000494 Writer.AddCXXBaseSpecifier(*ON.getBase(), Record);
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000495 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000496 }
497 }
498 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000499 Writer.AddStmt(E->getIndexExpr(I));
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000500 Code = serialization::EXPR_OFFSETOF;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000501}
502
Sebastian Redl3397c552010-08-18 23:56:27 +0000503void ASTStmtWriter::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000504 VisitExpr(E);
505 Record.push_back(E->isSizeOf());
506 if (E->isArgumentType())
John McCalla93c9342009-12-07 02:54:59 +0000507 Writer.AddTypeSourceInfo(E->getArgumentTypeInfo(), Record);
Chris Lattner63377d52009-04-27 06:20:01 +0000508 else {
509 Record.push_back(0);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000510 Writer.AddStmt(E->getArgumentExpr());
Chris Lattner63377d52009-04-27 06:20:01 +0000511 }
512 Writer.AddSourceLocation(E->getOperatorLoc(), Record);
513 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000514 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
Chris Lattner63377d52009-04-27 06:20:01 +0000515}
516
Sebastian Redl3397c552010-08-18 23:56:27 +0000517void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000518 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000519 Writer.AddStmt(E->getLHS());
520 Writer.AddStmt(E->getRHS());
Chris Lattner63377d52009-04-27 06:20:01 +0000521 Writer.AddSourceLocation(E->getRBracketLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000522 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
Chris Lattner63377d52009-04-27 06:20:01 +0000523}
524
Sebastian Redl3397c552010-08-18 23:56:27 +0000525void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000526 VisitExpr(E);
527 Record.push_back(E->getNumArgs());
528 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000529 Writer.AddStmt(E->getCallee());
Chris Lattner63377d52009-04-27 06:20:01 +0000530 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
531 Arg != ArgEnd; ++Arg)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000532 Writer.AddStmt(*Arg);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000533 Code = serialization::EXPR_CALL;
Chris Lattner63377d52009-04-27 06:20:01 +0000534}
535
Sebastian Redl3397c552010-08-18 23:56:27 +0000536void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000537 // Don't call VisitExpr, we'll write everything here.
538
539 Record.push_back(E->hasQualifier());
540 if (E->hasQualifier()) {
541 Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
542 Writer.AddSourceRange(E->getQualifierRange(), Record);
543 }
544
545 unsigned NumTemplateArgs = E->getNumTemplateArgs();
John McCall096832c2010-08-19 23:49:38 +0000546 assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
Argyrios Kyrtzidis663e3802010-07-08 13:09:47 +0000547 "Template args list with no args ?");
548 Record.push_back(NumTemplateArgs);
549 if (NumTemplateArgs) {
550 Writer.AddSourceLocation(E->getLAngleLoc(), Record);
551 Writer.AddSourceLocation(E->getRAngleLoc(), Record);
552 for (unsigned i=0; i != NumTemplateArgs; ++i)
553 Writer.AddTemplateArgumentLoc(E->getTemplateArgs()[i], Record);
554 }
555
556 DeclAccessPair FoundDecl = E->getFoundDecl();
557 Writer.AddDeclRef(FoundDecl.getDecl(), Record);
558 Record.push_back(FoundDecl.getAccess());
559
560 Writer.AddTypeRef(E->getType(), Record);
John McCallf89e55a2010-11-18 06:31:45 +0000561 Record.push_back(E->getValueKind());
562 Record.push_back(E->getObjectKind());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000563 Writer.AddStmt(E->getBase());
Chris Lattner63377d52009-04-27 06:20:01 +0000564 Writer.AddDeclRef(E->getMemberDecl(), Record);
565 Writer.AddSourceLocation(E->getMemberLoc(), Record);
566 Record.push_back(E->isArrow());
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000567 Writer.AddDeclarationNameLoc(E->MemberDNLoc,
568 E->getMemberDecl()->getDeclName(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000569 Code = serialization::EXPR_MEMBER;
Chris Lattner63377d52009-04-27 06:20:01 +0000570}
571
Sebastian Redl3397c552010-08-18 23:56:27 +0000572void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Narofff242b1b2009-07-24 17:54:45 +0000573 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000574 Writer.AddStmt(E->getBase());
Steve Narofff242b1b2009-07-24 17:54:45 +0000575 Writer.AddSourceLocation(E->getIsaMemberLoc(), Record);
576 Record.push_back(E->isArrow());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000577 Code = serialization::EXPR_OBJC_ISA;
Steve Narofff242b1b2009-07-24 17:54:45 +0000578}
579
Sebastian Redl3397c552010-08-18 23:56:27 +0000580void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000581 VisitExpr(E);
John McCallf871d0c2010-08-07 06:22:56 +0000582 Record.push_back(E->path_size());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000583 Writer.AddStmt(E->getSubExpr());
Anders Carlssoncdef2b72009-07-31 00:48:10 +0000584 Record.push_back(E->getCastKind()); // FIXME: stable encoding
John McCallf871d0c2010-08-07 06:22:56 +0000585
586 for (CastExpr::path_iterator
587 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
588 Writer.AddCXXBaseSpecifier(**PI, Record);
Chris Lattner63377d52009-04-27 06:20:01 +0000589}
590
Sebastian Redl3397c552010-08-18 23:56:27 +0000591void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000592 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000593 Writer.AddStmt(E->getLHS());
594 Writer.AddStmt(E->getRHS());
Chris Lattner63377d52009-04-27 06:20:01 +0000595 Record.push_back(E->getOpcode()); // FIXME: stable encoding
596 Writer.AddSourceLocation(E->getOperatorLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000597 Code = serialization::EXPR_BINARY_OPERATOR;
Chris Lattner63377d52009-04-27 06:20:01 +0000598}
599
Sebastian Redl3397c552010-08-18 23:56:27 +0000600void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000601 VisitBinaryOperator(E);
602 Writer.AddTypeRef(E->getComputationLHSType(), Record);
603 Writer.AddTypeRef(E->getComputationResultType(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000604 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
Chris Lattner63377d52009-04-27 06:20:01 +0000605}
606
Sebastian Redl3397c552010-08-18 23:56:27 +0000607void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000608 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000609 Writer.AddStmt(E->getCond());
610 Writer.AddStmt(E->getLHS());
611 Writer.AddStmt(E->getRHS());
Fariborz Jahanianf9b949f2010-08-31 18:02:20 +0000612 Writer.AddStmt(E->getSAVE());
Douglas Gregor47e1f7c2009-08-26 14:37:04 +0000613 Writer.AddSourceLocation(E->getQuestionLoc(), Record);
614 Writer.AddSourceLocation(E->getColonLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000615 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
Chris Lattner63377d52009-04-27 06:20:01 +0000616}
617
Sebastian Redl3397c552010-08-18 23:56:27 +0000618void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000619 VisitCastExpr(E);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000620 Code = serialization::EXPR_IMPLICIT_CAST;
Chris Lattner63377d52009-04-27 06:20:01 +0000621}
622
Sebastian Redl3397c552010-08-18 23:56:27 +0000623void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000624 VisitCastExpr(E);
John McCall9d125032010-01-15 18:39:57 +0000625 Writer.AddTypeSourceInfo(E->getTypeInfoAsWritten(), Record);
Chris Lattner63377d52009-04-27 06:20:01 +0000626}
627
Sebastian Redl3397c552010-08-18 23:56:27 +0000628void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000629 VisitExplicitCastExpr(E);
630 Writer.AddSourceLocation(E->getLParenLoc(), Record);
631 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000632 Code = serialization::EXPR_CSTYLE_CAST;
Chris Lattner63377d52009-04-27 06:20:01 +0000633}
634
Sebastian Redl3397c552010-08-18 23:56:27 +0000635void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000636 VisitExpr(E);
637 Writer.AddSourceLocation(E->getLParenLoc(), Record);
John McCall42f56b52010-01-18 19:35:47 +0000638 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000639 Writer.AddStmt(E->getInitializer());
Chris Lattner63377d52009-04-27 06:20:01 +0000640 Record.push_back(E->isFileScope());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000641 Code = serialization::EXPR_COMPOUND_LITERAL;
Chris Lattner63377d52009-04-27 06:20:01 +0000642}
643
Sebastian Redl3397c552010-08-18 23:56:27 +0000644void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000645 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000646 Writer.AddStmt(E->getBase());
Chris Lattner63377d52009-04-27 06:20:01 +0000647 Writer.AddIdentifierRef(&E->getAccessor(), Record);
648 Writer.AddSourceLocation(E->getAccessorLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000649 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
Chris Lattner63377d52009-04-27 06:20:01 +0000650}
651
Sebastian Redl3397c552010-08-18 23:56:27 +0000652void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000653 VisitExpr(E);
654 Record.push_back(E->getNumInits());
655 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000656 Writer.AddStmt(E->getInit(I));
657 Writer.AddStmt(E->getSyntacticForm());
Chris Lattner63377d52009-04-27 06:20:01 +0000658 Writer.AddSourceLocation(E->getLBraceLoc(), Record);
659 Writer.AddSourceLocation(E->getRBraceLoc(), Record);
660 Writer.AddDeclRef(E->getInitializedFieldInUnion(), Record);
661 Record.push_back(E->hadArrayRangeDesignator());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000662 Code = serialization::EXPR_INIT_LIST;
Chris Lattner63377d52009-04-27 06:20:01 +0000663}
664
Sebastian Redl3397c552010-08-18 23:56:27 +0000665void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000666 VisitExpr(E);
667 Record.push_back(E->getNumSubExprs());
668 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000669 Writer.AddStmt(E->getSubExpr(I));
Chris Lattner63377d52009-04-27 06:20:01 +0000670 Writer.AddSourceLocation(E->getEqualOrColonLoc(), Record);
671 Record.push_back(E->usesGNUSyntax());
672 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
673 DEnd = E->designators_end();
674 D != DEnd; ++D) {
675 if (D->isFieldDesignator()) {
676 if (FieldDecl *Field = D->getField()) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000677 Record.push_back(serialization::DESIG_FIELD_DECL);
Chris Lattner63377d52009-04-27 06:20:01 +0000678 Writer.AddDeclRef(Field, Record);
679 } else {
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000680 Record.push_back(serialization::DESIG_FIELD_NAME);
Chris Lattner63377d52009-04-27 06:20:01 +0000681 Writer.AddIdentifierRef(D->getFieldName(), Record);
682 }
683 Writer.AddSourceLocation(D->getDotLoc(), Record);
684 Writer.AddSourceLocation(D->getFieldLoc(), Record);
685 } else if (D->isArrayDesignator()) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000686 Record.push_back(serialization::DESIG_ARRAY);
Chris Lattner63377d52009-04-27 06:20:01 +0000687 Record.push_back(D->getFirstExprIndex());
688 Writer.AddSourceLocation(D->getLBracketLoc(), Record);
689 Writer.AddSourceLocation(D->getRBracketLoc(), Record);
690 } else {
691 assert(D->isArrayRangeDesignator() && "Unknown designator");
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000692 Record.push_back(serialization::DESIG_ARRAY_RANGE);
Chris Lattner63377d52009-04-27 06:20:01 +0000693 Record.push_back(D->getFirstExprIndex());
694 Writer.AddSourceLocation(D->getLBracketLoc(), Record);
695 Writer.AddSourceLocation(D->getEllipsisLoc(), Record);
696 Writer.AddSourceLocation(D->getRBracketLoc(), Record);
697 }
698 }
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000699 Code = serialization::EXPR_DESIGNATED_INIT;
Chris Lattner63377d52009-04-27 06:20:01 +0000700}
701
Sebastian Redl3397c552010-08-18 23:56:27 +0000702void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000703 VisitExpr(E);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000704 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
Chris Lattner63377d52009-04-27 06:20:01 +0000705}
706
Sebastian Redl3397c552010-08-18 23:56:27 +0000707void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000708 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000709 Writer.AddStmt(E->getSubExpr());
Abramo Bagnara2cad9002010-08-10 10:06:15 +0000710 Writer.AddTypeSourceInfo(E->getWrittenTypeInfo(), Record);
Chris Lattner63377d52009-04-27 06:20:01 +0000711 Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
712 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000713 Code = serialization::EXPR_VA_ARG;
Chris Lattner63377d52009-04-27 06:20:01 +0000714}
715
Sebastian Redl3397c552010-08-18 23:56:27 +0000716void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000717 VisitExpr(E);
718 Writer.AddSourceLocation(E->getAmpAmpLoc(), Record);
719 Writer.AddSourceLocation(E->getLabelLoc(), Record);
720 Record.push_back(Writer.GetLabelID(E->getLabel()));
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000721 Code = serialization::EXPR_ADDR_LABEL;
Chris Lattner63377d52009-04-27 06:20:01 +0000722}
723
Sebastian Redl3397c552010-08-18 23:56:27 +0000724void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000725 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000726 Writer.AddStmt(E->getSubStmt());
Chris Lattner63377d52009-04-27 06:20:01 +0000727 Writer.AddSourceLocation(E->getLParenLoc(), Record);
728 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000729 Code = serialization::EXPR_STMT;
Chris Lattner63377d52009-04-27 06:20:01 +0000730}
731
Sebastian Redl3397c552010-08-18 23:56:27 +0000732void ASTStmtWriter::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000733 VisitExpr(E);
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +0000734 Writer.AddTypeSourceInfo(E->getArgTInfo1(), Record);
735 Writer.AddTypeSourceInfo(E->getArgTInfo2(), Record);
Chris Lattner63377d52009-04-27 06:20:01 +0000736 Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
737 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000738 Code = serialization::EXPR_TYPES_COMPATIBLE;
Chris Lattner63377d52009-04-27 06:20:01 +0000739}
740
Sebastian Redl3397c552010-08-18 23:56:27 +0000741void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000742 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000743 Writer.AddStmt(E->getCond());
744 Writer.AddStmt(E->getLHS());
745 Writer.AddStmt(E->getRHS());
Chris Lattner63377d52009-04-27 06:20:01 +0000746 Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
747 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000748 Code = serialization::EXPR_CHOOSE;
Chris Lattner63377d52009-04-27 06:20:01 +0000749}
750
Sebastian Redl3397c552010-08-18 23:56:27 +0000751void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000752 VisitExpr(E);
753 Writer.AddSourceLocation(E->getTokenLocation(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000754 Code = serialization::EXPR_GNU_NULL;
Chris Lattner63377d52009-04-27 06:20:01 +0000755}
756
Sebastian Redl3397c552010-08-18 23:56:27 +0000757void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000758 VisitExpr(E);
759 Record.push_back(E->getNumSubExprs());
760 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000761 Writer.AddStmt(E->getExpr(I));
Chris Lattner63377d52009-04-27 06:20:01 +0000762 Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
763 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000764 Code = serialization::EXPR_SHUFFLE_VECTOR;
Chris Lattner63377d52009-04-27 06:20:01 +0000765}
766
Sebastian Redl3397c552010-08-18 23:56:27 +0000767void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000768 VisitExpr(E);
769 Writer.AddDeclRef(E->getBlockDecl(), Record);
770 Record.push_back(E->hasBlockDeclRefExprs());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000771 Code = serialization::EXPR_BLOCK;
Chris Lattner63377d52009-04-27 06:20:01 +0000772}
773
Sebastian Redl3397c552010-08-18 23:56:27 +0000774void ASTStmtWriter::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000775 VisitExpr(E);
776 Writer.AddDeclRef(E->getDecl(), Record);
777 Writer.AddSourceLocation(E->getLocation(), Record);
778 Record.push_back(E->isByRef());
Fariborz Jahanian9b0b57c2009-06-20 00:02:26 +0000779 Record.push_back(E->isConstQualAdded());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000780 Writer.AddStmt(E->getCopyConstructorExpr());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000781 Code = serialization::EXPR_BLOCK_DECL_REF;
Chris Lattner63377d52009-04-27 06:20:01 +0000782}
783
784//===----------------------------------------------------------------------===//
785// Objective-C Expressions and Statements.
786//===----------------------------------------------------------------------===//
787
Sebastian Redl3397c552010-08-18 23:56:27 +0000788void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000789 VisitExpr(E);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000790 Writer.AddStmt(E->getString());
Chris Lattner63377d52009-04-27 06:20:01 +0000791 Writer.AddSourceLocation(E->getAtLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000792 Code = serialization::EXPR_OBJC_STRING_LITERAL;
Chris Lattner63377d52009-04-27 06:20:01 +0000793}
794
Sebastian Redl3397c552010-08-18 23:56:27 +0000795void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000796 VisitExpr(E);
Douglas Gregor81d34662010-04-20 15:39:42 +0000797 Writer.AddTypeSourceInfo(E->getEncodedTypeSourceInfo(), Record);
Chris Lattner63377d52009-04-27 06:20:01 +0000798 Writer.AddSourceLocation(E->getAtLoc(), Record);
799 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000800 Code = serialization::EXPR_OBJC_ENCODE;
Chris Lattner63377d52009-04-27 06:20:01 +0000801}
802
Sebastian Redl3397c552010-08-18 23:56:27 +0000803void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000804 VisitExpr(E);
805 Writer.AddSelectorRef(E->getSelector(), Record);
806 Writer.AddSourceLocation(E->getAtLoc(), Record);
807 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000808 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
Chris Lattner63377d52009-04-27 06:20:01 +0000809}
810
Sebastian Redl3397c552010-08-18 23:56:27 +0000811void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000812 VisitExpr(E);
813 Writer.AddDeclRef(E->getProtocol(), Record);
814 Writer.AddSourceLocation(E->getAtLoc(), Record);
815 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000816 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
Chris Lattner63377d52009-04-27 06:20:01 +0000817}
818
Sebastian Redl3397c552010-08-18 23:56:27 +0000819void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000820 VisitExpr(E);
821 Writer.AddDeclRef(E->getDecl(), Record);
822 Writer.AddSourceLocation(E->getLocation(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000823 Writer.AddStmt(E->getBase());
Chris Lattner63377d52009-04-27 06:20:01 +0000824 Record.push_back(E->isArrow());
825 Record.push_back(E->isFreeIvar());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000826 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
Chris Lattner63377d52009-04-27 06:20:01 +0000827}
828
Sebastian Redl3397c552010-08-18 23:56:27 +0000829void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000830 VisitExpr(E);
831 Writer.AddDeclRef(E->getProperty(), Record);
832 Writer.AddSourceLocation(E->getLocation(), Record);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000833 Writer.AddSourceLocation(E->getSuperLocation(), Record);
834 if (E->isSuperReceiver())
835 Writer.AddTypeRef(E->getSuperType(), Record);
836 else
837 Writer.AddStmt(E->getBase());
838
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000839 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
Chris Lattner63377d52009-04-27 06:20:01 +0000840}
841
Sebastian Redl3397c552010-08-18 23:56:27 +0000842void ASTStmtWriter::VisitObjCImplicitSetterGetterRefExpr(
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000843 ObjCImplicitSetterGetterRefExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000844 VisitExpr(E);
845 Writer.AddDeclRef(E->getGetterMethod(), Record);
846 Writer.AddDeclRef(E->getSetterMethod(), Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000847
Fariborz Jahaniand2ae5aa2009-08-18 21:37:33 +0000848 // NOTE: InterfaceDecl and Base are mutually exclusive.
849 Writer.AddDeclRef(E->getInterfaceDecl(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000850 Writer.AddStmt(E->getBase());
Chris Lattner63377d52009-04-27 06:20:01 +0000851 Writer.AddSourceLocation(E->getLocation(), Record);
852 Writer.AddSourceLocation(E->getClassLoc(), Record);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000853 Writer.AddSourceLocation(E->getSuperLocation(), Record);
854 Writer.AddTypeRef(E->getSuperType(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000855 Code = serialization::EXPR_OBJC_KVC_REF_EXPR;
Chris Lattner63377d52009-04-27 06:20:01 +0000856}
857
Sebastian Redl3397c552010-08-18 23:56:27 +0000858void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner63377d52009-04-27 06:20:01 +0000859 VisitExpr(E);
860 Record.push_back(E->getNumArgs());
Douglas Gregor04badcf2010-04-21 00:45:42 +0000861 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
862 switch (E->getReceiverKind()) {
863 case ObjCMessageExpr::Instance:
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000864 Writer.AddStmt(E->getInstanceReceiver());
Douglas Gregor04badcf2010-04-21 00:45:42 +0000865 break;
866
867 case ObjCMessageExpr::Class:
868 Writer.AddTypeSourceInfo(E->getClassReceiverTypeInfo(), Record);
869 break;
870
871 case ObjCMessageExpr::SuperClass:
872 case ObjCMessageExpr::SuperInstance:
873 Writer.AddTypeRef(E->getSuperType(), Record);
874 Writer.AddSourceLocation(E->getSuperLoc(), Record);
875 break;
876 }
877
878 if (E->getMethodDecl()) {
879 Record.push_back(1);
880 Writer.AddDeclRef(E->getMethodDecl(), Record);
881 } else {
882 Record.push_back(0);
883 Writer.AddSelectorRef(E->getSelector(), Record);
884 }
885
Chris Lattner63377d52009-04-27 06:20:01 +0000886 Writer.AddSourceLocation(E->getLeftLoc(), Record);
887 Writer.AddSourceLocation(E->getRightLoc(), Record);
Chris Lattner63377d52009-04-27 06:20:01 +0000888
889 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
890 Arg != ArgEnd; ++Arg)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000891 Writer.AddStmt(*Arg);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000892 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
Chris Lattner63377d52009-04-27 06:20:01 +0000893}
894
Sebastian Redl3397c552010-08-18 23:56:27 +0000895void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +0000896 VisitStmt(S);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000897 Writer.AddStmt(S->getElement());
898 Writer.AddStmt(S->getCollection());
899 Writer.AddStmt(S->getBody());
Chris Lattner63377d52009-04-27 06:20:01 +0000900 Writer.AddSourceLocation(S->getForLoc(), Record);
901 Writer.AddSourceLocation(S->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000902 Code = serialization::STMT_OBJC_FOR_COLLECTION;
Chris Lattner63377d52009-04-27 06:20:01 +0000903}
904
Sebastian Redl3397c552010-08-18 23:56:27 +0000905void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000906 Writer.AddStmt(S->getCatchBody());
Chris Lattner63377d52009-04-27 06:20:01 +0000907 Writer.AddDeclRef(S->getCatchParamDecl(), Record);
908 Writer.AddSourceLocation(S->getAtCatchLoc(), Record);
909 Writer.AddSourceLocation(S->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000910 Code = serialization::STMT_OBJC_CATCH;
Chris Lattner63377d52009-04-27 06:20:01 +0000911}
912
Sebastian Redl3397c552010-08-18 23:56:27 +0000913void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000914 Writer.AddStmt(S->getFinallyBody());
Chris Lattner63377d52009-04-27 06:20:01 +0000915 Writer.AddSourceLocation(S->getAtFinallyLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000916 Code = serialization::STMT_OBJC_FINALLY;
Chris Lattner63377d52009-04-27 06:20:01 +0000917}
918
Sebastian Redl3397c552010-08-18 23:56:27 +0000919void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000920 Record.push_back(S->getNumCatchStmts());
921 Record.push_back(S->getFinallyStmt() != 0);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000922 Writer.AddStmt(S->getTryBody());
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000923 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000924 Writer.AddStmt(S->getCatchStmt(I));
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000925 if (S->getFinallyStmt())
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000926 Writer.AddStmt(S->getFinallyStmt());
Chris Lattner63377d52009-04-27 06:20:01 +0000927 Writer.AddSourceLocation(S->getAtTryLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000928 Code = serialization::STMT_OBJC_AT_TRY;
Chris Lattner63377d52009-04-27 06:20:01 +0000929}
930
Sebastian Redl3397c552010-08-18 23:56:27 +0000931void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000932 Writer.AddStmt(S->getSynchExpr());
933 Writer.AddStmt(S->getSynchBody());
Chris Lattner63377d52009-04-27 06:20:01 +0000934 Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000935 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
Chris Lattner63377d52009-04-27 06:20:01 +0000936}
937
Sebastian Redl3397c552010-08-18 23:56:27 +0000938void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000939 Writer.AddStmt(S->getThrowExpr());
Chris Lattner63377d52009-04-27 06:20:01 +0000940 Writer.AddSourceLocation(S->getThrowLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000941 Code = serialization::STMT_OBJC_AT_THROW;
Chris Lattner63377d52009-04-27 06:20:01 +0000942}
943
944//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000945// C++ Expressions and Statements.
946//===----------------------------------------------------------------------===//
947
Sebastian Redl3397c552010-08-18 23:56:27 +0000948void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000949 VisitStmt(S);
950 Writer.AddSourceLocation(S->getCatchLoc(), Record);
951 Writer.AddDeclRef(S->getExceptionDecl(), Record);
952 Writer.AddStmt(S->getHandlerBlock());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000953 Code = serialization::STMT_CXX_CATCH;
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000954}
955
Sebastian Redl3397c552010-08-18 23:56:27 +0000956void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000957 VisitStmt(S);
958 Record.push_back(S->getNumHandlers());
959 Writer.AddSourceLocation(S->getTryLoc(), Record);
960 Writer.AddStmt(S->getTryBlock());
961 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
962 Writer.AddStmt(S->getHandler(i));
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000963 Code = serialization::STMT_CXX_TRY;
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000964}
965
Sebastian Redl3397c552010-08-18 23:56:27 +0000966void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000967 VisitCallExpr(E);
968 Record.push_back(E->getOperator());
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000969 Code = serialization::EXPR_CXX_OPERATOR_CALL;
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +0000970}
971
Sebastian Redl3397c552010-08-18 23:56:27 +0000972void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Chris Lattner1817bd42010-05-09 05:36:05 +0000973 VisitCallExpr(E);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000974 Code = serialization::EXPR_CXX_MEMBER_CALL;
Chris Lattner1817bd42010-05-09 05:36:05 +0000975}
976
Sebastian Redl3397c552010-08-18 23:56:27 +0000977void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor39da0b82009-09-09 23:08:42 +0000978 VisitExpr(E);
Argyrios Kyrtzidis5e1b7c22010-06-24 08:57:09 +0000979 Record.push_back(E->getNumArgs());
980 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000981 Writer.AddStmt(E->getArg(I));
Douglas Gregor39da0b82009-09-09 23:08:42 +0000982 Writer.AddDeclRef(E->getConstructor(), Record);
Douglas Gregor99a2e602009-12-16 01:38:02 +0000983 Writer.AddSourceLocation(E->getLocation(), Record);
Douglas Gregor39da0b82009-09-09 23:08:42 +0000984 Record.push_back(E->isElidable());
Douglas Gregor16006c92009-12-16 18:50:27 +0000985 Record.push_back(E->requiresZeroInitialization());
Douglas Gregor3c9034c2010-05-15 00:13:29 +0000986 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
Chandler Carruth428edaf2010-10-25 08:47:36 +0000987 Writer.AddSourceRange(E->getParenRange(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000988 Code = serialization::EXPR_CXX_CONSTRUCT;
Douglas Gregor39da0b82009-09-09 23:08:42 +0000989}
990
Sebastian Redl3397c552010-08-18 23:56:27 +0000991void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000992 VisitCXXConstructExpr(E);
Douglas Gregorab6677e2010-09-08 00:15:04 +0000993 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +0000994 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +0000995}
996
Sebastian Redl3397c552010-08-18 23:56:27 +0000997void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +0000998 VisitExplicitCastExpr(E);
999 Writer.AddSourceLocation(E->getOperatorLoc(), Record);
1000}
1001
Sebastian Redl3397c552010-08-18 23:56:27 +00001002void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001003 VisitCXXNamedCastExpr(E);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001004 Code = serialization::EXPR_CXX_STATIC_CAST;
Sam Weinigce757a72010-01-16 21:21:01 +00001005}
1006
Sebastian Redl3397c552010-08-18 23:56:27 +00001007void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001008 VisitCXXNamedCastExpr(E);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001009 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
Sam Weinigce757a72010-01-16 21:21:01 +00001010}
1011
Sebastian Redl3397c552010-08-18 23:56:27 +00001012void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001013 VisitCXXNamedCastExpr(E);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001014 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
Sam Weinigce757a72010-01-16 21:21:01 +00001015}
1016
Sebastian Redl3397c552010-08-18 23:56:27 +00001017void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001018 VisitCXXNamedCastExpr(E);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001019 Code = serialization::EXPR_CXX_CONST_CAST;
Sam Weinigce757a72010-01-16 21:21:01 +00001020}
1021
Sebastian Redl3397c552010-08-18 23:56:27 +00001022void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Sam Weinigce757a72010-01-16 21:21:01 +00001023 VisitExplicitCastExpr(E);
1024 Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
1025 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001026 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
Sam Weinigce757a72010-01-16 21:21:01 +00001027}
1028
Sebastian Redl3397c552010-08-18 23:56:27 +00001029void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001030 VisitExpr(E);
1031 Record.push_back(E->getValue());
1032 Writer.AddSourceLocation(E->getLocation(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001033 Code = serialization::EXPR_CXX_BOOL_LITERAL;
Sam Weinigeb7f9612010-02-07 06:32:43 +00001034}
1035
Sebastian Redl3397c552010-08-18 23:56:27 +00001036void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinigeb7f9612010-02-07 06:32:43 +00001037 VisitExpr(E);
1038 Writer.AddSourceLocation(E->getLocation(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001039 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
Sam Weinigeb7f9612010-02-07 06:32:43 +00001040}
1041
Sebastian Redl3397c552010-08-18 23:56:27 +00001042void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner14ab24f2010-05-09 06:03:39 +00001043 VisitExpr(E);
1044 Writer.AddSourceRange(E->getSourceRange(), Record);
1045 if (E->isTypeOperand()) {
1046 Writer.AddTypeSourceInfo(E->getTypeOperandSourceInfo(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001047 Code = serialization::EXPR_CXX_TYPEID_TYPE;
Chris Lattner14ab24f2010-05-09 06:03:39 +00001048 } else {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001049 Writer.AddStmt(E->getExprOperand());
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001050 Code = serialization::EXPR_CXX_TYPEID_EXPR;
Chris Lattner14ab24f2010-05-09 06:03:39 +00001051 }
1052}
1053
Francois Pichet01b7c302010-09-08 12:20:18 +00001054void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1055 VisitExpr(E);
1056 Writer.AddSourceRange(E->getSourceRange(), Record);
1057 if (E->isTypeOperand()) {
1058 Writer.AddTypeSourceInfo(E->getTypeOperandSourceInfo(), Record);
1059 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1060 } else {
1061 Writer.AddStmt(E->getExprOperand());
1062 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1063 }
1064}
1065
Sebastian Redl3397c552010-08-18 23:56:27 +00001066void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001067 VisitExpr(E);
1068 Writer.AddSourceLocation(E->getLocation(), Record);
1069 Record.push_back(E->isImplicit());
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001070 Code = serialization::EXPR_CXX_THIS;
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001071}
1072
Sebastian Redl3397c552010-08-18 23:56:27 +00001073void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattner030854b2010-05-09 06:40:08 +00001074 VisitExpr(E);
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001075 Writer.AddSourceLocation(E->getThrowLoc(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001076 Writer.AddStmt(E->getSubExpr());
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001077 Code = serialization::EXPR_CXX_THROW;
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001078}
1079
Sebastian Redl3397c552010-08-18 23:56:27 +00001080void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattner030854b2010-05-09 06:40:08 +00001081 VisitExpr(E);
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001082
1083 bool HasOtherExprStored = E->Param.getInt();
1084 // Store these first, the reader reads them before creation.
1085 Record.push_back(HasOtherExprStored);
1086 if (HasOtherExprStored)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001087 Writer.AddStmt(E->getExpr());
Argyrios Kyrtzidis8a507332010-07-02 23:30:15 +00001088 Writer.AddDeclRef(E->getParam(), Record);
1089 Writer.AddSourceLocation(E->getUsedLocation(), Record);
Chris Lattner030854b2010-05-09 06:40:08 +00001090
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001091 Code = serialization::EXPR_CXX_DEFAULT_ARG;
Chris Lattner030854b2010-05-09 06:40:08 +00001092}
1093
Sebastian Redl3397c552010-08-18 23:56:27 +00001094void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001095 VisitExpr(E);
1096 Writer.AddCXXTemporary(E->getTemporary(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001097 Writer.AddStmt(E->getSubExpr());
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001098 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
Chris Lattnerd2598362010-05-10 00:25:06 +00001099}
1100
Sebastian Redl3397c552010-08-18 23:56:27 +00001101void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001102 VisitExpr(E);
Douglas Gregorab6677e2010-09-08 00:15:04 +00001103 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
Chris Lattner59218632010-05-10 01:22:27 +00001104 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001105 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
Chris Lattner59218632010-05-10 01:22:27 +00001106}
1107
Sebastian Redl3397c552010-08-18 23:56:27 +00001108void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattner59218632010-05-10 01:22:27 +00001109 VisitExpr(E);
1110 Record.push_back(E->isGlobalNew());
Chris Lattner59218632010-05-10 01:22:27 +00001111 Record.push_back(E->hasInitializer());
1112 Record.push_back(E->isArray());
1113 Record.push_back(E->getNumPlacementArgs());
1114 Record.push_back(E->getNumConstructorArgs());
1115 Writer.AddDeclRef(E->getOperatorNew(), Record);
1116 Writer.AddDeclRef(E->getOperatorDelete(), Record);
1117 Writer.AddDeclRef(E->getConstructor(), Record);
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001118 Writer.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo(), Record);
Douglas Gregor4bd40312010-07-13 15:54:32 +00001119 Writer.AddSourceRange(E->getTypeIdParens(), Record);
Chris Lattner59218632010-05-10 01:22:27 +00001120 Writer.AddSourceLocation(E->getStartLoc(), Record);
1121 Writer.AddSourceLocation(E->getEndLoc(), Record);
Chandler Carruth428edaf2010-10-25 08:47:36 +00001122 Writer.AddSourceLocation(E->getConstructorLParen(), Record);
1123 Writer.AddSourceLocation(E->getConstructorRParen(), Record);
Chris Lattner59218632010-05-10 01:22:27 +00001124 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
1125 I != e; ++I)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001126 Writer.AddStmt(*I);
Chris Lattner59218632010-05-10 01:22:27 +00001127
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001128 Code = serialization::EXPR_CXX_NEW;
Chris Lattner59218632010-05-10 01:22:27 +00001129}
1130
Sebastian Redl3397c552010-08-18 23:56:27 +00001131void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001132 VisitExpr(E);
1133 Record.push_back(E->isGlobalDelete());
1134 Record.push_back(E->isArrayForm());
Argyrios Kyrtzidis4076dac2010-09-13 20:15:54 +00001135 Record.push_back(E->isArrayFormAsWritten());
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001136 Writer.AddDeclRef(E->getOperatorDelete(), Record);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001137 Writer.AddStmt(E->getArgument());
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001138 Writer.AddSourceLocation(E->getSourceRange().getBegin(), Record);
1139
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001140 Code = serialization::EXPR_CXX_DELETE;
Argyrios Kyrtzidis95fc98c2010-06-22 17:07:59 +00001141}
Chris Lattner59218632010-05-10 01:22:27 +00001142
Sebastian Redl3397c552010-08-18 23:56:27 +00001143void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001144 VisitExpr(E);
1145
1146 Writer.AddStmt(E->getBase());
1147 Record.push_back(E->isArrow());
1148 Writer.AddSourceLocation(E->getOperatorLoc(), Record);
1149 Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
1150 Writer.AddSourceRange(E->getQualifierRange(), Record);
1151 Writer.AddTypeSourceInfo(E->getScopeTypeInfo(), Record);
1152 Writer.AddSourceLocation(E->getColonColonLoc(), Record);
1153 Writer.AddSourceLocation(E->getTildeLoc(), Record);
1154
1155 // PseudoDestructorTypeStorage.
1156 Writer.AddIdentifierRef(E->getDestroyedTypeIdentifier(), Record);
1157 if (E->getDestroyedTypeIdentifier())
1158 Writer.AddSourceLocation(E->getDestroyedTypeLoc(), Record);
1159 else
1160 Writer.AddTypeSourceInfo(E->getDestroyedTypeInfo(), Record);
1161
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001162 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
Argyrios Kyrtzidisde4bd182010-06-28 09:32:03 +00001163}
1164
Sebastian Redl3397c552010-08-18 23:56:27 +00001165void ASTStmtWriter::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
Chris Lattnerd2598362010-05-10 00:25:06 +00001166 VisitExpr(E);
1167 Record.push_back(E->getNumTemporaries());
1168 for (unsigned i = 0, e = E->getNumTemporaries(); i != e; ++i)
1169 Writer.AddCXXTemporary(E->getTemporary(i), Record);
1170
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001171 Writer.AddStmt(E->getSubExpr());
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001172 Code = serialization::EXPR_CXX_EXPR_WITH_TEMPORARIES;
Chris Lattnerd2598362010-05-10 00:25:06 +00001173}
1174
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001175void
Sebastian Redl3397c552010-08-18 23:56:27 +00001176ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001177 VisitExpr(E);
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +00001178
1179 // Don't emit anything here, NumTemplateArgs must be emitted first.
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001180
1181 if (E->hasExplicitTemplateArgs()) {
John McCall096832c2010-08-19 23:49:38 +00001182 const ExplicitTemplateArgumentList &Args = E->getExplicitTemplateArgs();
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +00001183 assert(Args.NumTemplateArgs &&
Sebastian Redl3397c552010-08-18 23:56:27 +00001184 "Num of template args was zero! AST reading will mess up!");
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +00001185 Record.push_back(Args.NumTemplateArgs);
1186 AddExplicitTemplateArgumentList(Args);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001187 } else {
1188 Record.push_back(0);
1189 }
1190
1191 if (!E->isImplicitAccess())
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001192 Writer.AddStmt(E->getBase());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001193 else
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001194 Writer.AddStmt(0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001195 Writer.AddTypeRef(E->getBaseType(), Record);
1196 Record.push_back(E->isArrow());
1197 Writer.AddSourceLocation(E->getOperatorLoc(), Record);
1198 Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
1199 Writer.AddSourceRange(E->getQualifierRange(), Record);
1200 Writer.AddDeclRef(E->getFirstQualifierFoundInScope(), Record);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001201 Writer.AddDeclarationNameInfo(E->MemberNameInfo, Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001202 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001203}
1204
1205void
Sebastian Redl3397c552010-08-18 23:56:27 +00001206ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001207 VisitExpr(E);
1208
1209 // Don't emit anything here, NumTemplateArgs must be emitted first.
1210
1211 if (E->hasExplicitTemplateArgs()) {
1212 const ExplicitTemplateArgumentList &Args = E->getExplicitTemplateArgs();
1213 assert(Args.NumTemplateArgs &&
Sebastian Redl3397c552010-08-18 23:56:27 +00001214 "Num of template args was zero! AST reading will mess up!");
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001215 Record.push_back(Args.NumTemplateArgs);
1216 AddExplicitTemplateArgumentList(Args);
1217 } else {
1218 Record.push_back(0);
1219 }
1220
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001221 Writer.AddDeclarationNameInfo(E->NameInfo, Record);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001222 Writer.AddSourceRange(E->getQualifierRange(), Record);
1223 Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001224 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +00001225}
1226
1227void
Sebastian Redl3397c552010-08-18 23:56:27 +00001228ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001229 VisitExpr(E);
1230 Record.push_back(E->arg_size());
1231 for (CXXUnresolvedConstructExpr::arg_iterator
1232 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001233 Writer.AddStmt(*ArgI);
Douglas Gregorab6677e2010-09-08 00:15:04 +00001234 Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001235 Writer.AddSourceLocation(E->getLParenLoc(), Record);
1236 Writer.AddSourceLocation(E->getRParenLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001237 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001238}
Chris Lattner2fbdfcd2010-05-09 06:15:05 +00001239
Sebastian Redl3397c552010-08-18 23:56:27 +00001240void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001241 VisitExpr(E);
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +00001242
1243 // Don't emit anything here, NumTemplateArgs must be emitted first.
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001244
1245 if (E->hasExplicitTemplateArgs()) {
1246 const ExplicitTemplateArgumentList &Args = E->getExplicitTemplateArgs();
1247 assert(Args.NumTemplateArgs &&
Sebastian Redl3397c552010-08-18 23:56:27 +00001248 "Num of template args was zero! AST reading will mess up!");
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001249 Record.push_back(Args.NumTemplateArgs);
Argyrios Kyrtzidis36c76f02010-06-28 09:31:48 +00001250 AddExplicitTemplateArgumentList(Args);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001251 } else {
1252 Record.push_back(0);
1253 }
1254
1255 Record.push_back(E->getNumDecls());
1256 for (OverloadExpr::decls_iterator
1257 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
1258 Writer.AddDeclRef(OvI.getDecl(), Record);
1259 Record.push_back(OvI.getAccess());
1260 }
1261
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001262 Writer.AddDeclarationNameInfo(E->NameInfo, Record);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001263 Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
1264 Writer.AddSourceRange(E->getQualifierRange(), Record);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001265}
1266
Sebastian Redl3397c552010-08-18 23:56:27 +00001267void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001268 VisitOverloadExpr(E);
1269 Record.push_back(E->isArrow());
1270 Record.push_back(E->hasUnresolvedUsing());
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001271 Writer.AddStmt(!E->isImplicitAccess() ? E->getBase() : 0);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001272 Writer.AddTypeRef(E->getBaseType(), Record);
1273 Writer.AddSourceLocation(E->getOperatorLoc(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001274 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001275}
1276
Sebastian Redl3397c552010-08-18 23:56:27 +00001277void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001278 VisitOverloadExpr(E);
1279 Record.push_back(E->requiresADL());
1280 Record.push_back(E->isOverloaded());
1281 Writer.AddDeclRef(E->getNamingClass(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001282 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +00001283}
1284
Sebastian Redl3397c552010-08-18 23:56:27 +00001285void ASTStmtWriter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001286 VisitExpr(E);
1287 Record.push_back(E->getTrait());
Sebastian Redl0dfd8482010-09-13 20:56:31 +00001288 Record.push_back(E->getValue());
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001289 Writer.AddSourceRange(E->getSourceRange(), Record);
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001290 Writer.AddTypeSourceInfo(E->getQueriedTypeSourceInfo(), Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001291 Code = serialization::EXPR_CXX_UNARY_TYPE_TRAIT;
Argyrios Kyrtzidis6d00c132010-07-10 11:46:15 +00001292}
1293
Sebastian Redl6b219d02010-09-10 20:55:54 +00001294void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1295 VisitExpr(E);
1296 Record.push_back(E->getValue());
1297 Writer.AddSourceRange(E->getSourceRange(), Record);
1298 Writer.AddStmt(E->getOperand());
1299 Code = serialization::EXPR_CXX_NOEXCEPT;
1300}
1301
John McCall7cd7d1a2010-11-15 23:31:06 +00001302void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1303 VisitExpr(E);
John McCall7cd7d1a2010-11-15 23:31:06 +00001304 Code = serialization::EXPR_OPAQUE_VALUE;
1305}
1306
Argyrios Kyrtzidisba0a9002009-07-14 03:19:21 +00001307//===----------------------------------------------------------------------===//
Sebastian Redla4232eb2010-08-18 23:56:21 +00001308// ASTWriter Implementation
Chris Lattner63377d52009-04-27 06:20:01 +00001309//===----------------------------------------------------------------------===//
1310
Sebastian Redla4232eb2010-08-18 23:56:21 +00001311unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
Mike Stump1eb44332009-09-09 15:08:12 +00001312 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
Chris Lattner63377d52009-04-27 06:20:01 +00001313 "SwitchCase recorded twice");
1314 unsigned NextID = SwitchCaseIDs.size();
1315 SwitchCaseIDs[S] = NextID;
1316 return NextID;
1317}
1318
Sebastian Redla4232eb2010-08-18 23:56:21 +00001319unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
Mike Stump1eb44332009-09-09 15:08:12 +00001320 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
Chris Lattner63377d52009-04-27 06:20:01 +00001321 "SwitchCase hasn't been seen yet");
1322 return SwitchCaseIDs[S];
1323}
1324
Argyrios Kyrtzidise09a2752010-10-28 09:29:32 +00001325void ASTWriter::ClearSwitchCaseIDs() {
1326 SwitchCaseIDs.clear();
1327}
1328
Chris Lattner63377d52009-04-27 06:20:01 +00001329/// \brief Retrieve the ID for the given label statement, which may
1330/// or may not have been emitted yet.
Sebastian Redla4232eb2010-08-18 23:56:21 +00001331unsigned ASTWriter::GetLabelID(LabelStmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +00001332 std::map<LabelStmt *, unsigned>::iterator Pos = LabelIDs.find(S);
1333 if (Pos != LabelIDs.end())
1334 return Pos->second;
Mike Stump1eb44332009-09-09 15:08:12 +00001335
Chris Lattner63377d52009-04-27 06:20:01 +00001336 unsigned NextID = LabelIDs.size();
1337 LabelIDs[S] = NextID;
1338 return NextID;
1339}
1340
1341/// \brief Write the given substatement or subexpression to the
1342/// bitstream.
Sebastian Redla4232eb2010-08-18 23:56:21 +00001343void ASTWriter::WriteSubStmt(Stmt *S) {
Chris Lattner63377d52009-04-27 06:20:01 +00001344 RecordData Record;
Sebastian Redl3397c552010-08-18 23:56:27 +00001345 ASTStmtWriter Writer(*this, Record);
Chris Lattner63377d52009-04-27 06:20:01 +00001346 ++NumStatements;
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001347
Chris Lattner63377d52009-04-27 06:20:01 +00001348 if (!S) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001349 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
Chris Lattner63377d52009-04-27 06:20:01 +00001350 return;
1351 }
Mike Stump1eb44332009-09-09 15:08:12 +00001352
Sebastian Redla4232eb2010-08-18 23:56:21 +00001353 // Redirect ASTWriter::AddStmt to collect sub stmts.
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001354 llvm::SmallVector<Stmt *, 16> SubStmts;
1355 CollectedStmts = &SubStmts;
1356
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001357 Writer.Code = serialization::STMT_NULL_PTR;
Chris Lattner63377d52009-04-27 06:20:01 +00001358 Writer.Visit(S);
Chris Lattner59218632010-05-10 01:22:27 +00001359
1360#ifndef NDEBUG
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001361 if (Writer.Code == serialization::STMT_NULL_PTR) {
Argyrios Kyrtzidis12bf28f2010-06-25 09:03:12 +00001362 SourceManager &SrcMgr
1363 = DeclIDs.begin()->first->getASTContext().getSourceManager();
1364 S->dump(SrcMgr);
Sebastian Redl3397c552010-08-18 23:56:27 +00001365 assert(0 && "Unhandled sub statement writing AST file");
Chris Lattner59218632010-05-10 01:22:27 +00001366 }
1367#endif
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001368
Sebastian Redla4232eb2010-08-18 23:56:21 +00001369 // Revert ASTWriter::AddStmt.
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001370 CollectedStmts = &StmtsToEmit;
1371
1372 // Write the sub stmts in reverse order, last to first. When reading them back
1373 // we will read them in correct order by "pop"ing them from the Stmts stack.
1374 // This simplifies reading and allows to store a variable number of sub stmts
1375 // without knowing it in advance.
1376 while (!SubStmts.empty())
1377 WriteSubStmt(SubStmts.pop_back_val());
1378
Mike Stump1eb44332009-09-09 15:08:12 +00001379 Stream.EmitRecord(Writer.Code, Record);
Chris Lattner63377d52009-04-27 06:20:01 +00001380}
1381
1382/// \brief Flush all of the statements that have been added to the
1383/// queue via AddStmt().
Sebastian Redla4232eb2010-08-18 23:56:21 +00001384void ASTWriter::FlushStmts() {
Chris Lattner63377d52009-04-27 06:20:01 +00001385 RecordData Record;
Mike Stump1eb44332009-09-09 15:08:12 +00001386
Chris Lattner63377d52009-04-27 06:20:01 +00001387 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001388 WriteSubStmt(StmtsToEmit[I]);
1389
Mike Stump1eb44332009-09-09 15:08:12 +00001390 assert(N == StmtsToEmit.size() &&
Chris Lattner63377d52009-04-27 06:20:01 +00001391 "Substatement writen via AddStmt rather than WriteSubStmt!");
Mike Stump1eb44332009-09-09 15:08:12 +00001392
Chris Lattner63377d52009-04-27 06:20:01 +00001393 // Note that we are at the end of a full expression. Any
1394 // expression records that follow this one are part of a different
1395 // expression.
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001396 Stream.EmitRecord(serialization::STMT_STOP, Record);
Chris Lattner63377d52009-04-27 06:20:01 +00001397 }
Mike Stump1eb44332009-09-09 15:08:12 +00001398
Chris Lattner63377d52009-04-27 06:20:01 +00001399 StmtsToEmit.clear();
Chris Lattner63377d52009-04-27 06:20:01 +00001400}