1d6522cfcSSebastian Redl //===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
2d6522cfcSSebastian Redl //
3d6522cfcSSebastian Redl //                     The LLVM Compiler Infrastructure
4d6522cfcSSebastian Redl //
5d6522cfcSSebastian Redl // This file is distributed under the University of Illinois Open Source
6d6522cfcSSebastian Redl // License. See LICENSE.TXT for details.
7d6522cfcSSebastian Redl //
8d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
9ddd36fffSJames Dennett ///
10ddd36fffSJames Dennett /// \file
11ddd36fffSJames Dennett /// \brief Implements serialization for Statements and Expressions.
12ddd36fffSJames Dennett ///
13d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
14d6522cfcSSebastian Redl 
151914c6feSSebastian Redl #include "clang/Serialization/ASTWriter.h"
164ab984e7SBenjamin Kramer #include "clang/AST/ASTContext.h"
17d6522cfcSSebastian Redl #include "clang/AST/DeclCXX.h"
18d6522cfcSSebastian Redl #include "clang/AST/DeclObjC.h"
19cdbc539aSDouglas Gregor #include "clang/AST/DeclTemplate.h"
20d6522cfcSSebastian Redl #include "clang/AST/StmtVisitor.h"
21f413f5edSJohn McCall #include "clang/Lex/Token.h"
22d6522cfcSSebastian Redl #include "llvm/Bitcode/BitstreamWriter.h"
23d6522cfcSSebastian Redl using namespace clang;
24d6522cfcSSebastian Redl 
25d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
26d6522cfcSSebastian Redl // Statement/expression serialization
27d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
28d6522cfcSSebastian Redl 
29d6522cfcSSebastian Redl namespace clang {
305ec3eb11SAlexey Bataev 
31d6522cfcSSebastian Redl   class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
325ec3eb11SAlexey Bataev     friend class OMPClauseWriter;
33d6522cfcSSebastian Redl     ASTWriter &Writer;
34d6522cfcSSebastian Redl     ASTWriter::RecordData &Record;
35d6522cfcSSebastian Redl 
36d6522cfcSSebastian Redl   public:
37539c5061SSebastian Redl     serialization::StmtCode Code;
3803412ba0SDouglas Gregor     unsigned AbbrevToUse;
39d6522cfcSSebastian Redl 
40d6522cfcSSebastian Redl     ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
41d6522cfcSSebastian Redl       : Writer(Writer), Record(Record) { }
42d6522cfcSSebastian Redl 
437945c981SAbramo Bagnara     void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &Args);
44d6522cfcSSebastian Redl 
45d6522cfcSSebastian Redl     void VisitStmt(Stmt *S);
46fa19404cSJohn McCall #define STMT(Type, Base) \
47fa19404cSJohn McCall     void Visit##Type(Type *);
48fa19404cSJohn McCall #include "clang/AST/StmtNodes.inc"
49d6522cfcSSebastian Redl   };
50d6522cfcSSebastian Redl }
51d6522cfcSSebastian Redl 
52d6522cfcSSebastian Redl void ASTStmtWriter::
537945c981SAbramo Bagnara AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &Args) {
547945c981SAbramo Bagnara   Writer.AddSourceLocation(Args.getTemplateKeywordLoc(), Record);
55d6522cfcSSebastian Redl   Writer.AddSourceLocation(Args.LAngleLoc, Record);
56d6522cfcSSebastian Redl   Writer.AddSourceLocation(Args.RAngleLoc, Record);
57d6522cfcSSebastian Redl   for (unsigned i=0; i != Args.NumTemplateArgs; ++i)
58d6522cfcSSebastian Redl     Writer.AddTemplateArgumentLoc(Args.getTemplateArgs()[i], Record);
59d6522cfcSSebastian Redl }
60d6522cfcSSebastian Redl 
61d6522cfcSSebastian Redl void ASTStmtWriter::VisitStmt(Stmt *S) {
62d6522cfcSSebastian Redl }
63d6522cfcSSebastian Redl 
64d6522cfcSSebastian Redl void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
65d6522cfcSSebastian Redl   VisitStmt(S);
66d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getSemiLoc(), Record);
6743ea78b4SArgyrios Kyrtzidis   Record.push_back(S->HasLeadingEmptyMacro);
68539c5061SSebastian Redl   Code = serialization::STMT_NULL;
69d6522cfcSSebastian Redl }
70d6522cfcSSebastian Redl 
71d6522cfcSSebastian Redl void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
72d6522cfcSSebastian Redl   VisitStmt(S);
73d6522cfcSSebastian Redl   Record.push_back(S->size());
74c7e4e219SAaron Ballman   for (auto *CS : S->body())
75c7e4e219SAaron Ballman     Writer.AddStmt(CS);
76d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getLBracLoc(), Record);
77d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getRBracLoc(), Record);
78539c5061SSebastian Redl   Code = serialization::STMT_COMPOUND;
79d6522cfcSSebastian Redl }
80d6522cfcSSebastian Redl 
81d6522cfcSSebastian Redl void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
82d6522cfcSSebastian Redl   VisitStmt(S);
83d6522cfcSSebastian Redl   Record.push_back(Writer.getSwitchCaseID(S));
84aa1ce901SArgyrios Kyrtzidis   Writer.AddSourceLocation(S->getKeywordLoc(), Record);
85aa1ce901SArgyrios Kyrtzidis   Writer.AddSourceLocation(S->getColonLoc(), Record);
86d6522cfcSSebastian Redl }
87d6522cfcSSebastian Redl 
88d6522cfcSSebastian Redl void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
89d6522cfcSSebastian Redl   VisitSwitchCase(S);
90d6522cfcSSebastian Redl   Writer.AddStmt(S->getLHS());
91d6522cfcSSebastian Redl   Writer.AddStmt(S->getRHS());
92d6522cfcSSebastian Redl   Writer.AddStmt(S->getSubStmt());
93d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getEllipsisLoc(), Record);
94539c5061SSebastian Redl   Code = serialization::STMT_CASE;
95d6522cfcSSebastian Redl }
96d6522cfcSSebastian Redl 
97d6522cfcSSebastian Redl void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
98d6522cfcSSebastian Redl   VisitSwitchCase(S);
99d6522cfcSSebastian Redl   Writer.AddStmt(S->getSubStmt());
100539c5061SSebastian Redl   Code = serialization::STMT_DEFAULT;
101d6522cfcSSebastian Redl }
102d6522cfcSSebastian Redl 
103d6522cfcSSebastian Redl void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
104d6522cfcSSebastian Redl   VisitStmt(S);
105c8e630e4SChris Lattner   Writer.AddDeclRef(S->getDecl(), Record);
106d6522cfcSSebastian Redl   Writer.AddStmt(S->getSubStmt());
107d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getIdentLoc(), Record);
108539c5061SSebastian Redl   Code = serialization::STMT_LABEL;
109d6522cfcSSebastian Redl }
110d6522cfcSSebastian Redl 
111c202b280SRichard Smith void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
112c202b280SRichard Smith   VisitStmt(S);
11320f6fc62SAlexander Kornienko   Record.push_back(S->getAttrs().size());
114c202b280SRichard Smith   Writer.WriteAttributes(S->getAttrs(), Record);
115c202b280SRichard Smith   Writer.AddStmt(S->getSubStmt());
116c202b280SRichard Smith   Writer.AddSourceLocation(S->getAttrLoc(), Record);
117c202b280SRichard Smith   Code = serialization::STMT_ATTRIBUTED;
118c202b280SRichard Smith }
119c202b280SRichard Smith 
120d6522cfcSSebastian Redl void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
121d6522cfcSSebastian Redl   VisitStmt(S);
122d6522cfcSSebastian Redl   Writer.AddDeclRef(S->getConditionVariable(), Record);
123d6522cfcSSebastian Redl   Writer.AddStmt(S->getCond());
124d6522cfcSSebastian Redl   Writer.AddStmt(S->getThen());
125d6522cfcSSebastian Redl   Writer.AddStmt(S->getElse());
126d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getIfLoc(), Record);
127d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getElseLoc(), Record);
128539c5061SSebastian Redl   Code = serialization::STMT_IF;
129d6522cfcSSebastian Redl }
130d6522cfcSSebastian Redl 
131d6522cfcSSebastian Redl void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
132d6522cfcSSebastian Redl   VisitStmt(S);
133d6522cfcSSebastian Redl   Writer.AddDeclRef(S->getConditionVariable(), Record);
134d6522cfcSSebastian Redl   Writer.AddStmt(S->getCond());
135d6522cfcSSebastian Redl   Writer.AddStmt(S->getBody());
136d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getSwitchLoc(), Record);
137c42f3451STed Kremenek   Record.push_back(S->isAllEnumCasesCovered());
138d6522cfcSSebastian Redl   for (SwitchCase *SC = S->getSwitchCaseList(); SC;
139d6522cfcSSebastian Redl        SC = SC->getNextSwitchCase())
140d6522cfcSSebastian Redl     Record.push_back(Writer.RecordSwitchCaseID(SC));
141539c5061SSebastian Redl   Code = serialization::STMT_SWITCH;
142d6522cfcSSebastian Redl }
143d6522cfcSSebastian Redl 
144d6522cfcSSebastian Redl void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
145d6522cfcSSebastian Redl   VisitStmt(S);
146d6522cfcSSebastian Redl   Writer.AddDeclRef(S->getConditionVariable(), Record);
147d6522cfcSSebastian Redl   Writer.AddStmt(S->getCond());
148d6522cfcSSebastian Redl   Writer.AddStmt(S->getBody());
149d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getWhileLoc(), Record);
150539c5061SSebastian Redl   Code = serialization::STMT_WHILE;
151d6522cfcSSebastian Redl }
152d6522cfcSSebastian Redl 
153d6522cfcSSebastian Redl void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
154d6522cfcSSebastian Redl   VisitStmt(S);
155d6522cfcSSebastian Redl   Writer.AddStmt(S->getCond());
156d6522cfcSSebastian Redl   Writer.AddStmt(S->getBody());
157d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getDoLoc(), Record);
158d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getWhileLoc(), Record);
159d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getRParenLoc(), Record);
160539c5061SSebastian Redl   Code = serialization::STMT_DO;
161d6522cfcSSebastian Redl }
162d6522cfcSSebastian Redl 
163d6522cfcSSebastian Redl void ASTStmtWriter::VisitForStmt(ForStmt *S) {
164d6522cfcSSebastian Redl   VisitStmt(S);
165d6522cfcSSebastian Redl   Writer.AddStmt(S->getInit());
166d6522cfcSSebastian Redl   Writer.AddStmt(S->getCond());
167d6522cfcSSebastian Redl   Writer.AddDeclRef(S->getConditionVariable(), Record);
168d6522cfcSSebastian Redl   Writer.AddStmt(S->getInc());
169d6522cfcSSebastian Redl   Writer.AddStmt(S->getBody());
170d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getForLoc(), Record);
171d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getLParenLoc(), Record);
172d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getRParenLoc(), Record);
173539c5061SSebastian Redl   Code = serialization::STMT_FOR;
174d6522cfcSSebastian Redl }
175d6522cfcSSebastian Redl 
176d6522cfcSSebastian Redl void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
177d6522cfcSSebastian Redl   VisitStmt(S);
178c8e630e4SChris Lattner   Writer.AddDeclRef(S->getLabel(), Record);
179d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getGotoLoc(), Record);
180d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getLabelLoc(), Record);
181539c5061SSebastian Redl   Code = serialization::STMT_GOTO;
182d6522cfcSSebastian Redl }
183d6522cfcSSebastian Redl 
184d6522cfcSSebastian Redl void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
185d6522cfcSSebastian Redl   VisitStmt(S);
186d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getGotoLoc(), Record);
187d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getStarLoc(), Record);
188d6522cfcSSebastian Redl   Writer.AddStmt(S->getTarget());
189539c5061SSebastian Redl   Code = serialization::STMT_INDIRECT_GOTO;
190d6522cfcSSebastian Redl }
191d6522cfcSSebastian Redl 
192d6522cfcSSebastian Redl void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
193d6522cfcSSebastian Redl   VisitStmt(S);
194d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getContinueLoc(), Record);
195539c5061SSebastian Redl   Code = serialization::STMT_CONTINUE;
196d6522cfcSSebastian Redl }
197d6522cfcSSebastian Redl 
198d6522cfcSSebastian Redl void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
199d6522cfcSSebastian Redl   VisitStmt(S);
200d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getBreakLoc(), Record);
201539c5061SSebastian Redl   Code = serialization::STMT_BREAK;
202d6522cfcSSebastian Redl }
203d6522cfcSSebastian Redl 
204d6522cfcSSebastian Redl void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
205d6522cfcSSebastian Redl   VisitStmt(S);
206d6522cfcSSebastian Redl   Writer.AddStmt(S->getRetValue());
207d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getReturnLoc(), Record);
208d6522cfcSSebastian Redl   Writer.AddDeclRef(S->getNRVOCandidate(), Record);
209539c5061SSebastian Redl   Code = serialization::STMT_RETURN;
210d6522cfcSSebastian Redl }
211d6522cfcSSebastian Redl 
212d6522cfcSSebastian Redl void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
213d6522cfcSSebastian Redl   VisitStmt(S);
214d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getStartLoc(), Record);
215d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getEndLoc(), Record);
216d6522cfcSSebastian Redl   DeclGroupRef DG = S->getDeclGroup();
217d6522cfcSSebastian Redl   for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
218d6522cfcSSebastian Redl     Writer.AddDeclRef(*D, Record);
219539c5061SSebastian Redl   Code = serialization::STMT_DECL;
220d6522cfcSSebastian Redl }
221d6522cfcSSebastian Redl 
222f413f5edSJohn McCall void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
223d6522cfcSSebastian Redl   VisitStmt(S);
224d6522cfcSSebastian Redl   Record.push_back(S->getNumOutputs());
225d6522cfcSSebastian Redl   Record.push_back(S->getNumInputs());
226d6522cfcSSebastian Redl   Record.push_back(S->getNumClobbers());
227d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getAsmLoc(), Record);
228d6522cfcSSebastian Redl   Record.push_back(S->isVolatile());
229d6522cfcSSebastian Redl   Record.push_back(S->isSimple());
230f413f5edSJohn McCall }
231f413f5edSJohn McCall 
232f413f5edSJohn McCall void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
233f413f5edSJohn McCall   VisitAsmStmt(S);
234f413f5edSJohn McCall   Writer.AddSourceLocation(S->getRParenLoc(), Record);
235d6522cfcSSebastian Redl   Writer.AddStmt(S->getAsmString());
236d6522cfcSSebastian Redl 
237d6522cfcSSebastian Redl   // Outputs
238d6522cfcSSebastian Redl   for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
239d6522cfcSSebastian Redl     Writer.AddIdentifierRef(S->getOutputIdentifier(I), Record);
240d6522cfcSSebastian Redl     Writer.AddStmt(S->getOutputConstraintLiteral(I));
241d6522cfcSSebastian Redl     Writer.AddStmt(S->getOutputExpr(I));
242d6522cfcSSebastian Redl   }
243d6522cfcSSebastian Redl 
244d6522cfcSSebastian Redl   // Inputs
245d6522cfcSSebastian Redl   for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
246d6522cfcSSebastian Redl     Writer.AddIdentifierRef(S->getInputIdentifier(I), Record);
247d6522cfcSSebastian Redl     Writer.AddStmt(S->getInputConstraintLiteral(I));
248d6522cfcSSebastian Redl     Writer.AddStmt(S->getInputExpr(I));
249d6522cfcSSebastian Redl   }
250d6522cfcSSebastian Redl 
251d6522cfcSSebastian Redl   // Clobbers
252d6522cfcSSebastian Redl   for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
253d9fb09a9SChad Rosier     Writer.AddStmt(S->getClobberStringLiteral(I));
254d6522cfcSSebastian Redl 
255de70e0efSChad Rosier   Code = serialization::STMT_GCCASM;
256d6522cfcSSebastian Redl }
257d6522cfcSSebastian Redl 
25832503020SChad Rosier void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
259f413f5edSJohn McCall   VisitAsmStmt(S);
260f413f5edSJohn McCall   Writer.AddSourceLocation(S->getLBraceLoc(), Record);
261f413f5edSJohn McCall   Writer.AddSourceLocation(S->getEndLoc(), Record);
262f413f5edSJohn McCall   Record.push_back(S->getNumAsmToks());
263f413f5edSJohn McCall   Writer.AddString(S->getAsmString(), Record);
264f413f5edSJohn McCall 
265f413f5edSJohn McCall   // Tokens
266f413f5edSJohn McCall   for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
267f413f5edSJohn McCall     Writer.AddToken(S->getAsmToks()[I], Record);
268f413f5edSJohn McCall   }
269f413f5edSJohn McCall 
270f413f5edSJohn McCall   // Clobbers
271f413f5edSJohn McCall   for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
272f413f5edSJohn McCall     Writer.AddString(S->getClobber(I), Record);
273f413f5edSJohn McCall   }
274f413f5edSJohn McCall 
275f413f5edSJohn McCall   // Outputs
276f413f5edSJohn McCall   for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
277f413f5edSJohn McCall     Writer.AddStmt(S->getOutputExpr(I));
278f413f5edSJohn McCall     Writer.AddString(S->getOutputConstraint(I), Record);
279f413f5edSJohn McCall   }
280f413f5edSJohn McCall 
281f413f5edSJohn McCall   // Inputs
282f413f5edSJohn McCall   for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
283f413f5edSJohn McCall     Writer.AddStmt(S->getInputExpr(I));
284f413f5edSJohn McCall     Writer.AddString(S->getInputConstraint(I), Record);
285f413f5edSJohn McCall   }
286e30d4994SChad Rosier 
287e30d4994SChad Rosier   Code = serialization::STMT_MSASM;
28832503020SChad Rosier }
28932503020SChad Rosier 
29024110cc7STareq A. Siraj void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
29124110cc7STareq A. Siraj   VisitStmt(S);
292ce914fc8SBen Langmuir   // NumCaptures
293ce914fc8SBen Langmuir   Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
29424110cc7STareq A. Siraj 
29517fbf6edSWei Pan   // CapturedDecl and captured region kind
296ce914fc8SBen Langmuir   Writer.AddDeclRef(S->getCapturedDecl(), Record);
29717fbf6edSWei Pan   Record.push_back(S->getCapturedRegionKind());
29817fbf6edSWei Pan 
299ce914fc8SBen Langmuir   Writer.AddDeclRef(S->getCapturedRecordDecl(), Record);
300ce914fc8SBen Langmuir 
301ce914fc8SBen Langmuir   // Capture inits
302ba0238faSAaron Ballman   for (auto *I : S->capture_inits())
303ba0238faSAaron Ballman     Writer.AddStmt(I);
304ce914fc8SBen Langmuir 
305ce914fc8SBen Langmuir   // Body
306ce914fc8SBen Langmuir   Writer.AddStmt(S->getCapturedStmt());
307ce914fc8SBen Langmuir 
308ce914fc8SBen Langmuir   // Captures
309c656303aSAaron Ballman   for (const auto &I : S->captures()) {
310c656303aSAaron Ballman     if (I.capturesThis())
311a13603a2SCraig Topper       Writer.AddDeclRef(nullptr, Record);
312ce914fc8SBen Langmuir     else
313c656303aSAaron Ballman       Writer.AddDeclRef(I.getCapturedVar(), Record);
314c656303aSAaron Ballman     Record.push_back(I.getCaptureKind());
315c656303aSAaron Ballman     Writer.AddSourceLocation(I.getLocation(), Record);
316ce914fc8SBen Langmuir   }
317ce914fc8SBen Langmuir 
318ce914fc8SBen Langmuir   Code = serialization::STMT_CAPTURED;
31924110cc7STareq A. Siraj }
32024110cc7STareq A. Siraj 
321d6522cfcSSebastian Redl void ASTStmtWriter::VisitExpr(Expr *E) {
322d6522cfcSSebastian Redl   VisitStmt(E);
323d6522cfcSSebastian Redl   Writer.AddTypeRef(E->getType(), Record);
324d6522cfcSSebastian Redl   Record.push_back(E->isTypeDependent());
325d6522cfcSSebastian Redl   Record.push_back(E->isValueDependent());
326678d76c0SDouglas Gregor   Record.push_back(E->isInstantiationDependent());
327506bd564SDouglas Gregor   Record.push_back(E->containsUnexpandedParameterPack());
3287decc9e4SJohn McCall   Record.push_back(E->getValueKind());
3297decc9e4SJohn McCall   Record.push_back(E->getObjectKind());
330d6522cfcSSebastian Redl }
331d6522cfcSSebastian Redl 
332d6522cfcSSebastian Redl void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
333d6522cfcSSebastian Redl   VisitExpr(E);
334d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
335d6522cfcSSebastian Redl   Record.push_back(E->getIdentType()); // FIXME: stable encoding
336539c5061SSebastian Redl   Code = serialization::EXPR_PREDEFINED;
337d6522cfcSSebastian Redl }
338d6522cfcSSebastian Redl 
339d6522cfcSSebastian Redl void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
340d6522cfcSSebastian Redl   VisitExpr(E);
341d6522cfcSSebastian Redl 
342d6522cfcSSebastian Redl   Record.push_back(E->hasQualifier());
3438d26bb08SChandler Carruth   Record.push_back(E->getDecl() != E->getFoundDecl());
3447945c981SAbramo Bagnara   Record.push_back(E->hasTemplateKWAndArgsInfo());
345635ed24eSAbramo Bagnara   Record.push_back(E->hadMultipleCandidates());
346113bee05SJohn McCall   Record.push_back(E->refersToEnclosingLocal());
347d6522cfcSSebastian Redl 
3487945c981SAbramo Bagnara   if (E->hasTemplateKWAndArgsInfo()) {
34987866cedSDouglas Gregor     unsigned NumTemplateArgs = E->getNumTemplateArgs();
35087866cedSDouglas Gregor     Record.push_back(NumTemplateArgs);
35187866cedSDouglas Gregor   }
352d6522cfcSSebastian Redl 
35303412ba0SDouglas Gregor   DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
35403412ba0SDouglas Gregor 
3557945c981SAbramo Bagnara   if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
35603412ba0SDouglas Gregor       (E->getDecl() == E->getFoundDecl()) &&
35703412ba0SDouglas Gregor       nk == DeclarationName::Identifier) {
35803412ba0SDouglas Gregor     AbbrevToUse = Writer.getDeclRefExprAbbrev();
35903412ba0SDouglas Gregor   }
36003412ba0SDouglas Gregor 
36180756f62SAnders Carlsson   if (E->hasQualifier())
36280756f62SAnders Carlsson     Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record);
36380756f62SAnders Carlsson 
3648d26bb08SChandler Carruth   if (E->getDecl() != E->getFoundDecl())
3658d26bb08SChandler Carruth     Writer.AddDeclRef(E->getFoundDecl(), Record);
3668d26bb08SChandler Carruth 
3677945c981SAbramo Bagnara   if (E->hasTemplateKWAndArgsInfo())
3687945c981SAbramo Bagnara     AddTemplateKWAndArgsInfo(*E->getTemplateKWAndArgsInfo());
36980756f62SAnders Carlsson 
370d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getDecl(), Record);
371d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
372434383d7SArgyrios Kyrtzidis   Writer.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName(), Record);
373539c5061SSebastian Redl   Code = serialization::EXPR_DECL_REF;
374d6522cfcSSebastian Redl }
375d6522cfcSSebastian Redl 
376d6522cfcSSebastian Redl void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
377d6522cfcSSebastian Redl   VisitExpr(E);
378d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
379d6522cfcSSebastian Redl   Writer.AddAPInt(E->getValue(), Record);
38003412ba0SDouglas Gregor 
38103412ba0SDouglas Gregor   if (E->getValue().getBitWidth() == 32) {
38203412ba0SDouglas Gregor     AbbrevToUse = Writer.getIntegerLiteralAbbrev();
38303412ba0SDouglas Gregor   }
38403412ba0SDouglas Gregor 
385539c5061SSebastian Redl   Code = serialization::EXPR_INTEGER_LITERAL;
386d6522cfcSSebastian Redl }
387d6522cfcSSebastian Redl 
388d6522cfcSSebastian Redl void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
389d6522cfcSSebastian Redl   VisitExpr(E);
390178723a6STim Northover   Record.push_back(E->getRawSemantics());
391d6522cfcSSebastian Redl   Record.push_back(E->isExact());
392178723a6STim Northover   Writer.AddAPFloat(E->getValue(), Record);
393d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
394539c5061SSebastian Redl   Code = serialization::EXPR_FLOATING_LITERAL;
395d6522cfcSSebastian Redl }
396d6522cfcSSebastian Redl 
397d6522cfcSSebastian Redl void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
398d6522cfcSSebastian Redl   VisitExpr(E);
399d6522cfcSSebastian Redl   Writer.AddStmt(E->getSubExpr());
400539c5061SSebastian Redl   Code = serialization::EXPR_IMAGINARY_LITERAL;
401d6522cfcSSebastian Redl }
402d6522cfcSSebastian Redl 
403d6522cfcSSebastian Redl void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
404d6522cfcSSebastian Redl   VisitExpr(E);
405d6522cfcSSebastian Redl   Record.push_back(E->getByteLength());
406d6522cfcSSebastian Redl   Record.push_back(E->getNumConcatenated());
407fb65e592SDouglas Gregor   Record.push_back(E->getKind());
40875245409SAnders Carlsson   Record.push_back(E->isPascal());
409d6522cfcSSebastian Redl   // FIXME: String data should be stored as a blob at the end of the
410d6522cfcSSebastian Redl   // StringLiteral. However, we can't do so now because we have no
411d6522cfcSSebastian Redl   // provision for coping with abbreviations when we're jumping around
412d6522cfcSSebastian Redl   // the AST file during deserialization.
413fcec630aSEli Friedman   Record.append(E->getBytes().begin(), E->getBytes().end());
414d6522cfcSSebastian Redl   for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
415d6522cfcSSebastian Redl     Writer.AddSourceLocation(E->getStrTokenLoc(I), Record);
416539c5061SSebastian Redl   Code = serialization::EXPR_STRING_LITERAL;
417d6522cfcSSebastian Redl }
418d6522cfcSSebastian Redl 
419d6522cfcSSebastian Redl void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
420d6522cfcSSebastian Redl   VisitExpr(E);
421d6522cfcSSebastian Redl   Record.push_back(E->getValue());
422d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
423fb65e592SDouglas Gregor   Record.push_back(E->getKind());
42403412ba0SDouglas Gregor 
42503412ba0SDouglas Gregor   AbbrevToUse = Writer.getCharacterLiteralAbbrev();
42603412ba0SDouglas Gregor 
427539c5061SSebastian Redl   Code = serialization::EXPR_CHARACTER_LITERAL;
428d6522cfcSSebastian Redl }
429d6522cfcSSebastian Redl 
430d6522cfcSSebastian Redl void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
431d6522cfcSSebastian Redl   VisitExpr(E);
432d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLParen(), Record);
433d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParen(), Record);
434d6522cfcSSebastian Redl   Writer.AddStmt(E->getSubExpr());
435539c5061SSebastian Redl   Code = serialization::EXPR_PAREN;
436d6522cfcSSebastian Redl }
437d6522cfcSSebastian Redl 
438d6522cfcSSebastian Redl void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
439d6522cfcSSebastian Redl   VisitExpr(E);
440d6522cfcSSebastian Redl   Record.push_back(E->NumExprs);
441d6522cfcSSebastian Redl   for (unsigned i=0; i != E->NumExprs; ++i)
442d6522cfcSSebastian Redl     Writer.AddStmt(E->Exprs[i]);
443d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->LParenLoc, Record);
444d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->RParenLoc, Record);
445539c5061SSebastian Redl   Code = serialization::EXPR_PAREN_LIST;
446d6522cfcSSebastian Redl }
447d6522cfcSSebastian Redl 
448d6522cfcSSebastian Redl void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
449d6522cfcSSebastian Redl   VisitExpr(E);
450d6522cfcSSebastian Redl   Writer.AddStmt(E->getSubExpr());
451d6522cfcSSebastian Redl   Record.push_back(E->getOpcode()); // FIXME: stable encoding
452d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
453539c5061SSebastian Redl   Code = serialization::EXPR_UNARY_OPERATOR;
454d6522cfcSSebastian Redl }
455d6522cfcSSebastian Redl 
456d6522cfcSSebastian Redl void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
457d6522cfcSSebastian Redl   VisitExpr(E);
458d6522cfcSSebastian Redl   Record.push_back(E->getNumComponents());
459d6522cfcSSebastian Redl   Record.push_back(E->getNumExpressions());
460d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
461d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
462d6522cfcSSebastian Redl   Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
463d6522cfcSSebastian Redl   for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
464d6522cfcSSebastian Redl     const OffsetOfExpr::OffsetOfNode &ON = E->getComponent(I);
465d6522cfcSSebastian Redl     Record.push_back(ON.getKind()); // FIXME: Stable encoding
4666b6f051eSAbramo Bagnara     Writer.AddSourceLocation(ON.getSourceRange().getBegin(), Record);
4676b6f051eSAbramo Bagnara     Writer.AddSourceLocation(ON.getSourceRange().getEnd(), Record);
468d6522cfcSSebastian Redl     switch (ON.getKind()) {
469d6522cfcSSebastian Redl     case OffsetOfExpr::OffsetOfNode::Array:
470d6522cfcSSebastian Redl       Record.push_back(ON.getArrayExprIndex());
471d6522cfcSSebastian Redl       break;
472d6522cfcSSebastian Redl 
473d6522cfcSSebastian Redl     case OffsetOfExpr::OffsetOfNode::Field:
474d6522cfcSSebastian Redl       Writer.AddDeclRef(ON.getField(), Record);
475d6522cfcSSebastian Redl       break;
476d6522cfcSSebastian Redl 
477d6522cfcSSebastian Redl     case OffsetOfExpr::OffsetOfNode::Identifier:
478d6522cfcSSebastian Redl       Writer.AddIdentifierRef(ON.getFieldName(), Record);
479d6522cfcSSebastian Redl       break;
480d6522cfcSSebastian Redl 
481d6522cfcSSebastian Redl     case OffsetOfExpr::OffsetOfNode::Base:
482d6522cfcSSebastian Redl       Writer.AddCXXBaseSpecifier(*ON.getBase(), Record);
483d6522cfcSSebastian Redl       break;
484d6522cfcSSebastian Redl     }
485d6522cfcSSebastian Redl   }
486d6522cfcSSebastian Redl   for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
487d6522cfcSSebastian Redl     Writer.AddStmt(E->getIndexExpr(I));
488539c5061SSebastian Redl   Code = serialization::EXPR_OFFSETOF;
489d6522cfcSSebastian Redl }
490d6522cfcSSebastian Redl 
491e190dee7SPeter Collingbourne void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
492d6522cfcSSebastian Redl   VisitExpr(E);
493e190dee7SPeter Collingbourne   Record.push_back(E->getKind());
494d6522cfcSSebastian Redl   if (E->isArgumentType())
495d6522cfcSSebastian Redl     Writer.AddTypeSourceInfo(E->getArgumentTypeInfo(), Record);
496d6522cfcSSebastian Redl   else {
497d6522cfcSSebastian Redl     Record.push_back(0);
498d6522cfcSSebastian Redl     Writer.AddStmt(E->getArgumentExpr());
499d6522cfcSSebastian Redl   }
500d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
501d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
502539c5061SSebastian Redl   Code = serialization::EXPR_SIZEOF_ALIGN_OF;
503d6522cfcSSebastian Redl }
504d6522cfcSSebastian Redl 
505d6522cfcSSebastian Redl void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
506d6522cfcSSebastian Redl   VisitExpr(E);
507d6522cfcSSebastian Redl   Writer.AddStmt(E->getLHS());
508d6522cfcSSebastian Redl   Writer.AddStmt(E->getRHS());
509d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRBracketLoc(), Record);
510539c5061SSebastian Redl   Code = serialization::EXPR_ARRAY_SUBSCRIPT;
511d6522cfcSSebastian Redl }
512d6522cfcSSebastian Redl 
513d6522cfcSSebastian Redl void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
514d6522cfcSSebastian Redl   VisitExpr(E);
515d6522cfcSSebastian Redl   Record.push_back(E->getNumArgs());
516d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
517d6522cfcSSebastian Redl   Writer.AddStmt(E->getCallee());
518d6522cfcSSebastian Redl   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
519d6522cfcSSebastian Redl        Arg != ArgEnd; ++Arg)
520d6522cfcSSebastian Redl     Writer.AddStmt(*Arg);
521539c5061SSebastian Redl   Code = serialization::EXPR_CALL;
522d6522cfcSSebastian Redl }
523d6522cfcSSebastian Redl 
524d6522cfcSSebastian Redl void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
525d6522cfcSSebastian Redl   // Don't call VisitExpr, we'll write everything here.
526d6522cfcSSebastian Redl 
527d6522cfcSSebastian Redl   Record.push_back(E->hasQualifier());
528ea972d3fSDouglas Gregor   if (E->hasQualifier())
529ea972d3fSDouglas Gregor     Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record);
530d6522cfcSSebastian Redl 
5317945c981SAbramo Bagnara   Record.push_back(E->HasTemplateKWAndArgsInfo);
5327945c981SAbramo Bagnara   if (E->HasTemplateKWAndArgsInfo) {
5337945c981SAbramo Bagnara     Writer.AddSourceLocation(E->getTemplateKeywordLoc(), Record);
534d6522cfcSSebastian Redl     unsigned NumTemplateArgs = E->getNumTemplateArgs();
535d6522cfcSSebastian Redl     Record.push_back(NumTemplateArgs);
536d6522cfcSSebastian Redl     Writer.AddSourceLocation(E->getLAngleLoc(), Record);
537d6522cfcSSebastian Redl     Writer.AddSourceLocation(E->getRAngleLoc(), Record);
538d6522cfcSSebastian Redl     for (unsigned i=0; i != NumTemplateArgs; ++i)
539d6522cfcSSebastian Redl       Writer.AddTemplateArgumentLoc(E->getTemplateArgs()[i], Record);
540d6522cfcSSebastian Redl   }
541d6522cfcSSebastian Redl 
542635ed24eSAbramo Bagnara   Record.push_back(E->hadMultipleCandidates());
543635ed24eSAbramo Bagnara 
544d6522cfcSSebastian Redl   DeclAccessPair FoundDecl = E->getFoundDecl();
545d6522cfcSSebastian Redl   Writer.AddDeclRef(FoundDecl.getDecl(), Record);
546d6522cfcSSebastian Redl   Record.push_back(FoundDecl.getAccess());
547d6522cfcSSebastian Redl 
548d6522cfcSSebastian Redl   Writer.AddTypeRef(E->getType(), Record);
5497decc9e4SJohn McCall   Record.push_back(E->getValueKind());
5507decc9e4SJohn McCall   Record.push_back(E->getObjectKind());
551d6522cfcSSebastian Redl   Writer.AddStmt(E->getBase());
552d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getMemberDecl(), Record);
553d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getMemberLoc(), Record);
554d6522cfcSSebastian Redl   Record.push_back(E->isArrow());
555434383d7SArgyrios Kyrtzidis   Writer.AddDeclarationNameLoc(E->MemberDNLoc,
556434383d7SArgyrios Kyrtzidis                                E->getMemberDecl()->getDeclName(), Record);
557539c5061SSebastian Redl   Code = serialization::EXPR_MEMBER;
558d6522cfcSSebastian Redl }
559d6522cfcSSebastian Redl 
560d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
561d6522cfcSSebastian Redl   VisitExpr(E);
562d6522cfcSSebastian Redl   Writer.AddStmt(E->getBase());
563d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getIsaMemberLoc(), Record);
56406bb7f7eSFariborz Jahanian   Writer.AddSourceLocation(E->getOpLoc(), Record);
565d6522cfcSSebastian Redl   Record.push_back(E->isArrow());
566539c5061SSebastian Redl   Code = serialization::EXPR_OBJC_ISA;
567d6522cfcSSebastian Redl }
568d6522cfcSSebastian Redl 
56931168b07SJohn McCall void ASTStmtWriter::
57031168b07SJohn McCall VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
57131168b07SJohn McCall   VisitExpr(E);
57231168b07SJohn McCall   Writer.AddStmt(E->getSubExpr());
57331168b07SJohn McCall   Record.push_back(E->shouldCopy());
57431168b07SJohn McCall   Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
57531168b07SJohn McCall }
57631168b07SJohn McCall 
57731168b07SJohn McCall void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
57831168b07SJohn McCall   VisitExplicitCastExpr(E);
57931168b07SJohn McCall   Writer.AddSourceLocation(E->getLParenLoc(), Record);
58031168b07SJohn McCall   Writer.AddSourceLocation(E->getBridgeKeywordLoc(), Record);
58131168b07SJohn McCall   Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
58231168b07SJohn McCall   Code = serialization::EXPR_OBJC_BRIDGED_CAST;
58331168b07SJohn McCall }
58431168b07SJohn McCall 
585d6522cfcSSebastian Redl void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
586d6522cfcSSebastian Redl   VisitExpr(E);
587d6522cfcSSebastian Redl   Record.push_back(E->path_size());
588d6522cfcSSebastian Redl   Writer.AddStmt(E->getSubExpr());
589d6522cfcSSebastian Redl   Record.push_back(E->getCastKind()); // FIXME: stable encoding
590d6522cfcSSebastian Redl 
591d6522cfcSSebastian Redl   for (CastExpr::path_iterator
592d6522cfcSSebastian Redl          PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
593d6522cfcSSebastian Redl     Writer.AddCXXBaseSpecifier(**PI, Record);
594d6522cfcSSebastian Redl }
595d6522cfcSSebastian Redl 
596d6522cfcSSebastian Redl void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
597d6522cfcSSebastian Redl   VisitExpr(E);
598d6522cfcSSebastian Redl   Writer.AddStmt(E->getLHS());
599d6522cfcSSebastian Redl   Writer.AddStmt(E->getRHS());
600d6522cfcSSebastian Redl   Record.push_back(E->getOpcode()); // FIXME: stable encoding
601d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
6025de91cc3SLang Hames   Record.push_back(E->isFPContractable());
603539c5061SSebastian Redl   Code = serialization::EXPR_BINARY_OPERATOR;
604d6522cfcSSebastian Redl }
605d6522cfcSSebastian Redl 
606d6522cfcSSebastian Redl void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
607d6522cfcSSebastian Redl   VisitBinaryOperator(E);
608d6522cfcSSebastian Redl   Writer.AddTypeRef(E->getComputationLHSType(), Record);
609d6522cfcSSebastian Redl   Writer.AddTypeRef(E->getComputationResultType(), Record);
610539c5061SSebastian Redl   Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
611d6522cfcSSebastian Redl }
612d6522cfcSSebastian Redl 
613d6522cfcSSebastian Redl void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
614d6522cfcSSebastian Redl   VisitExpr(E);
615d6522cfcSSebastian Redl   Writer.AddStmt(E->getCond());
616d6522cfcSSebastian Redl   Writer.AddStmt(E->getLHS());
617d6522cfcSSebastian Redl   Writer.AddStmt(E->getRHS());
618d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getQuestionLoc(), Record);
619d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getColonLoc(), Record);
620539c5061SSebastian Redl   Code = serialization::EXPR_CONDITIONAL_OPERATOR;
621d6522cfcSSebastian Redl }
622d6522cfcSSebastian Redl 
623c07a0c7eSJohn McCall void
624c07a0c7eSJohn McCall ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
625c07a0c7eSJohn McCall   VisitExpr(E);
626c07a0c7eSJohn McCall   Writer.AddStmt(E->getOpaqueValue());
627c07a0c7eSJohn McCall   Writer.AddStmt(E->getCommon());
628c07a0c7eSJohn McCall   Writer.AddStmt(E->getCond());
629c07a0c7eSJohn McCall   Writer.AddStmt(E->getTrueExpr());
630c07a0c7eSJohn McCall   Writer.AddStmt(E->getFalseExpr());
631c07a0c7eSJohn McCall   Writer.AddSourceLocation(E->getQuestionLoc(), Record);
632c07a0c7eSJohn McCall   Writer.AddSourceLocation(E->getColonLoc(), Record);
633c07a0c7eSJohn McCall   Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
634c07a0c7eSJohn McCall }
635c07a0c7eSJohn McCall 
636d6522cfcSSebastian Redl void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
637d6522cfcSSebastian Redl   VisitCastExpr(E);
638a27c26e7SRichard Smith 
639a27c26e7SRichard Smith   if (E->path_size() == 0)
640a27c26e7SRichard Smith     AbbrevToUse = Writer.getExprImplicitCastAbbrev();
641a27c26e7SRichard Smith 
642539c5061SSebastian Redl   Code = serialization::EXPR_IMPLICIT_CAST;
643d6522cfcSSebastian Redl }
644d6522cfcSSebastian Redl 
645d6522cfcSSebastian Redl void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
646d6522cfcSSebastian Redl   VisitCastExpr(E);
647d6522cfcSSebastian Redl   Writer.AddTypeSourceInfo(E->getTypeInfoAsWritten(), Record);
648d6522cfcSSebastian Redl }
649d6522cfcSSebastian Redl 
650d6522cfcSSebastian Redl void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
651d6522cfcSSebastian Redl   VisitExplicitCastExpr(E);
652d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLParenLoc(), Record);
653d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
654539c5061SSebastian Redl   Code = serialization::EXPR_CSTYLE_CAST;
655d6522cfcSSebastian Redl }
656d6522cfcSSebastian Redl 
657d6522cfcSSebastian Redl void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
658d6522cfcSSebastian Redl   VisitExpr(E);
659d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLParenLoc(), Record);
660d6522cfcSSebastian Redl   Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
661d6522cfcSSebastian Redl   Writer.AddStmt(E->getInitializer());
662d6522cfcSSebastian Redl   Record.push_back(E->isFileScope());
663539c5061SSebastian Redl   Code = serialization::EXPR_COMPOUND_LITERAL;
664d6522cfcSSebastian Redl }
665d6522cfcSSebastian Redl 
666d6522cfcSSebastian Redl void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
667d6522cfcSSebastian Redl   VisitExpr(E);
668d6522cfcSSebastian Redl   Writer.AddStmt(E->getBase());
669d6522cfcSSebastian Redl   Writer.AddIdentifierRef(&E->getAccessor(), Record);
670d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getAccessorLoc(), Record);
671539c5061SSebastian Redl   Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
672d6522cfcSSebastian Redl }
673d6522cfcSSebastian Redl 
674d6522cfcSSebastian Redl void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
675d6522cfcSSebastian Redl   VisitExpr(E);
6768d16bd4dSAbramo Bagnara   // NOTE: only add the (possibly null) syntactic form.
6778d16bd4dSAbramo Bagnara   // No need to serialize the isSemanticForm flag and the semantic form.
678d6522cfcSSebastian Redl   Writer.AddStmt(E->getSyntacticForm());
679d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLBraceLoc(), Record);
680d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRBraceLoc(), Record);
681b2ed28eaSArgyrios Kyrtzidis   bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
682b2ed28eaSArgyrios Kyrtzidis   Record.push_back(isArrayFiller);
683b2ed28eaSArgyrios Kyrtzidis   if (isArrayFiller)
684b2ed28eaSArgyrios Kyrtzidis     Writer.AddStmt(E->getArrayFiller());
685b2ed28eaSArgyrios Kyrtzidis   else
686d6522cfcSSebastian Redl     Writer.AddDeclRef(E->getInitializedFieldInUnion(), Record);
687d6522cfcSSebastian Redl   Record.push_back(E->hadArrayRangeDesignator());
688bbcefa7dSArgyrios Kyrtzidis   Record.push_back(E->getNumInits());
689bbcefa7dSArgyrios Kyrtzidis   if (isArrayFiller) {
690bbcefa7dSArgyrios Kyrtzidis     // ArrayFiller may have filled "holes" due to designated initializer.
691bbcefa7dSArgyrios Kyrtzidis     // Replace them by 0 to indicate that the filler goes in that place.
692bbcefa7dSArgyrios Kyrtzidis     Expr *filler = E->getArrayFiller();
693bbcefa7dSArgyrios Kyrtzidis     for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
694a13603a2SCraig Topper       Writer.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
695bbcefa7dSArgyrios Kyrtzidis   } else {
696bbcefa7dSArgyrios Kyrtzidis     for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
697bbcefa7dSArgyrios Kyrtzidis       Writer.AddStmt(E->getInit(I));
698bbcefa7dSArgyrios Kyrtzidis   }
699539c5061SSebastian Redl   Code = serialization::EXPR_INIT_LIST;
700d6522cfcSSebastian Redl }
701d6522cfcSSebastian Redl 
702d6522cfcSSebastian Redl void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
703d6522cfcSSebastian Redl   VisitExpr(E);
704d6522cfcSSebastian Redl   Record.push_back(E->getNumSubExprs());
705d6522cfcSSebastian Redl   for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
706d6522cfcSSebastian Redl     Writer.AddStmt(E->getSubExpr(I));
707d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getEqualOrColonLoc(), Record);
708d6522cfcSSebastian Redl   Record.push_back(E->usesGNUSyntax());
709d6522cfcSSebastian Redl   for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
710d6522cfcSSebastian Redl                                              DEnd = E->designators_end();
711d6522cfcSSebastian Redl        D != DEnd; ++D) {
712d6522cfcSSebastian Redl     if (D->isFieldDesignator()) {
713d6522cfcSSebastian Redl       if (FieldDecl *Field = D->getField()) {
714539c5061SSebastian Redl         Record.push_back(serialization::DESIG_FIELD_DECL);
715d6522cfcSSebastian Redl         Writer.AddDeclRef(Field, Record);
716d6522cfcSSebastian Redl       } else {
717539c5061SSebastian Redl         Record.push_back(serialization::DESIG_FIELD_NAME);
718d6522cfcSSebastian Redl         Writer.AddIdentifierRef(D->getFieldName(), Record);
719d6522cfcSSebastian Redl       }
720d6522cfcSSebastian Redl       Writer.AddSourceLocation(D->getDotLoc(), Record);
721d6522cfcSSebastian Redl       Writer.AddSourceLocation(D->getFieldLoc(), Record);
722d6522cfcSSebastian Redl     } else if (D->isArrayDesignator()) {
723539c5061SSebastian Redl       Record.push_back(serialization::DESIG_ARRAY);
724d6522cfcSSebastian Redl       Record.push_back(D->getFirstExprIndex());
725d6522cfcSSebastian Redl       Writer.AddSourceLocation(D->getLBracketLoc(), Record);
726d6522cfcSSebastian Redl       Writer.AddSourceLocation(D->getRBracketLoc(), Record);
727d6522cfcSSebastian Redl     } else {
728d6522cfcSSebastian Redl       assert(D->isArrayRangeDesignator() && "Unknown designator");
729539c5061SSebastian Redl       Record.push_back(serialization::DESIG_ARRAY_RANGE);
730d6522cfcSSebastian Redl       Record.push_back(D->getFirstExprIndex());
731d6522cfcSSebastian Redl       Writer.AddSourceLocation(D->getLBracketLoc(), Record);
732d6522cfcSSebastian Redl       Writer.AddSourceLocation(D->getEllipsisLoc(), Record);
733d6522cfcSSebastian Redl       Writer.AddSourceLocation(D->getRBracketLoc(), Record);
734d6522cfcSSebastian Redl     }
735d6522cfcSSebastian Redl   }
736539c5061SSebastian Redl   Code = serialization::EXPR_DESIGNATED_INIT;
737d6522cfcSSebastian Redl }
738d6522cfcSSebastian Redl 
739d6522cfcSSebastian Redl void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
740d6522cfcSSebastian Redl   VisitExpr(E);
741539c5061SSebastian Redl   Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
742d6522cfcSSebastian Redl }
743d6522cfcSSebastian Redl 
744d6522cfcSSebastian Redl void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
745d6522cfcSSebastian Redl   VisitExpr(E);
746d6522cfcSSebastian Redl   Writer.AddStmt(E->getSubExpr());
747d6522cfcSSebastian Redl   Writer.AddTypeSourceInfo(E->getWrittenTypeInfo(), Record);
748d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
749d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
750539c5061SSebastian Redl   Code = serialization::EXPR_VA_ARG;
751d6522cfcSSebastian Redl }
752d6522cfcSSebastian Redl 
753d6522cfcSSebastian Redl void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
754d6522cfcSSebastian Redl   VisitExpr(E);
755d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getAmpAmpLoc(), Record);
756d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLabelLoc(), Record);
757c8e630e4SChris Lattner   Writer.AddDeclRef(E->getLabel(), Record);
758539c5061SSebastian Redl   Code = serialization::EXPR_ADDR_LABEL;
759d6522cfcSSebastian Redl }
760d6522cfcSSebastian Redl 
761d6522cfcSSebastian Redl void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
762d6522cfcSSebastian Redl   VisitExpr(E);
763d6522cfcSSebastian Redl   Writer.AddStmt(E->getSubStmt());
764d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLParenLoc(), Record);
765d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
766539c5061SSebastian Redl   Code = serialization::EXPR_STMT;
767d6522cfcSSebastian Redl }
768d6522cfcSSebastian Redl 
769d6522cfcSSebastian Redl void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
770d6522cfcSSebastian Redl   VisitExpr(E);
771d6522cfcSSebastian Redl   Writer.AddStmt(E->getCond());
772d6522cfcSSebastian Redl   Writer.AddStmt(E->getLHS());
773d6522cfcSSebastian Redl   Writer.AddStmt(E->getRHS());
774d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
775d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
77675807f23SEli Friedman   Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
777539c5061SSebastian Redl   Code = serialization::EXPR_CHOOSE;
778d6522cfcSSebastian Redl }
779d6522cfcSSebastian Redl 
780d6522cfcSSebastian Redl void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
781d6522cfcSSebastian Redl   VisitExpr(E);
782d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getTokenLocation(), Record);
783539c5061SSebastian Redl   Code = serialization::EXPR_GNU_NULL;
784d6522cfcSSebastian Redl }
785d6522cfcSSebastian Redl 
786d6522cfcSSebastian Redl void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
787d6522cfcSSebastian Redl   VisitExpr(E);
788d6522cfcSSebastian Redl   Record.push_back(E->getNumSubExprs());
789d6522cfcSSebastian Redl   for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
790d6522cfcSSebastian Redl     Writer.AddStmt(E->getExpr(I));
791d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
792d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
793539c5061SSebastian Redl   Code = serialization::EXPR_SHUFFLE_VECTOR;
794d6522cfcSSebastian Redl }
795d6522cfcSSebastian Redl 
796c4d7c82cSHal Finkel void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
797c4d7c82cSHal Finkel   VisitExpr(E);
798c4d7c82cSHal Finkel   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
799c4d7c82cSHal Finkel   Writer.AddSourceLocation(E->getRParenLoc(), Record);
800c4d7c82cSHal Finkel   Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
801c4d7c82cSHal Finkel   Writer.AddStmt(E->getSrcExpr());
802c4d7c82cSHal Finkel   Code = serialization::EXPR_CONVERT_VECTOR;
803c4d7c82cSHal Finkel }
804c4d7c82cSHal Finkel 
805d6522cfcSSebastian Redl void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
806d6522cfcSSebastian Redl   VisitExpr(E);
807d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getBlockDecl(), Record);
808539c5061SSebastian Redl   Code = serialization::EXPR_BLOCK;
809d6522cfcSSebastian Redl }
810d6522cfcSSebastian Redl 
81191147596SPeter Collingbourne void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
81291147596SPeter Collingbourne   VisitExpr(E);
81391147596SPeter Collingbourne   Record.push_back(E->getNumAssocs());
81491147596SPeter Collingbourne 
81591147596SPeter Collingbourne   Writer.AddStmt(E->getControllingExpr());
81691147596SPeter Collingbourne   for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
81791147596SPeter Collingbourne     Writer.AddTypeSourceInfo(E->getAssocTypeSourceInfo(I), Record);
81891147596SPeter Collingbourne     Writer.AddStmt(E->getAssocExpr(I));
81991147596SPeter Collingbourne   }
82091147596SPeter Collingbourne   Record.push_back(E->isResultDependent() ? -1U : E->getResultIndex());
82191147596SPeter Collingbourne 
82291147596SPeter Collingbourne   Writer.AddSourceLocation(E->getGenericLoc(), Record);
82391147596SPeter Collingbourne   Writer.AddSourceLocation(E->getDefaultLoc(), Record);
82491147596SPeter Collingbourne   Writer.AddSourceLocation(E->getRParenLoc(), Record);
82591147596SPeter Collingbourne   Code = serialization::EXPR_GENERIC_SELECTION;
82691147596SPeter Collingbourne }
82791147596SPeter Collingbourne 
828fe96e0b6SJohn McCall void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
829fe96e0b6SJohn McCall   VisitExpr(E);
830fe96e0b6SJohn McCall   Record.push_back(E->getNumSemanticExprs());
831fe96e0b6SJohn McCall 
832fe96e0b6SJohn McCall   // Push the result index.  Currently, this needs to exactly match
833fe96e0b6SJohn McCall   // the encoding used internally for ResultIndex.
834fe96e0b6SJohn McCall   unsigned result = E->getResultExprIndex();
835fe96e0b6SJohn McCall   result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
836fe96e0b6SJohn McCall   Record.push_back(result);
837fe96e0b6SJohn McCall 
838fe96e0b6SJohn McCall   Writer.AddStmt(E->getSyntacticForm());
839fe96e0b6SJohn McCall   for (PseudoObjectExpr::semantics_iterator
840fe96e0b6SJohn McCall          i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
841fe96e0b6SJohn McCall     Writer.AddStmt(*i);
842fe96e0b6SJohn McCall   }
8435938650bSArgyrios Kyrtzidis   Code = serialization::EXPR_PSEUDO_OBJECT;
844fe96e0b6SJohn McCall }
845fe96e0b6SJohn McCall 
846df14b3a8SEli Friedman void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
847df14b3a8SEli Friedman   VisitExpr(E);
848df14b3a8SEli Friedman   Record.push_back(E->getOp());
849aa22a8cdSRichard Smith   for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
850aa22a8cdSRichard Smith     Writer.AddStmt(E->getSubExprs()[I]);
851df14b3a8SEli Friedman   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
852df14b3a8SEli Friedman   Writer.AddSourceLocation(E->getRParenLoc(), Record);
8535938650bSArgyrios Kyrtzidis   Code = serialization::EXPR_ATOMIC;
854df14b3a8SEli Friedman }
855df14b3a8SEli Friedman 
856d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
857d6522cfcSSebastian Redl // Objective-C Expressions and Statements.
858d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
859d6522cfcSSebastian Redl 
860d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
861d6522cfcSSebastian Redl   VisitExpr(E);
862d6522cfcSSebastian Redl   Writer.AddStmt(E->getString());
863d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getAtLoc(), Record);
864539c5061SSebastian Redl   Code = serialization::EXPR_OBJC_STRING_LITERAL;
865d6522cfcSSebastian Redl }
866d6522cfcSSebastian Redl 
8670caa3947SPatrick Beard void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
868e65b086eSTed Kremenek   VisitExpr(E);
8690caa3947SPatrick Beard   Writer.AddStmt(E->getSubExpr());
8700caa3947SPatrick Beard   Writer.AddDeclRef(E->getBoxingMethod(), Record);
8710caa3947SPatrick Beard   Writer.AddSourceRange(E->getSourceRange(), Record);
8720caa3947SPatrick Beard   Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
873e65b086eSTed Kremenek }
874e65b086eSTed Kremenek 
875e65b086eSTed Kremenek void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
876e65b086eSTed Kremenek   VisitExpr(E);
877e65b086eSTed Kremenek   Record.push_back(E->getNumElements());
878e65b086eSTed Kremenek   for (unsigned i = 0; i < E->getNumElements(); i++)
879e65b086eSTed Kremenek     Writer.AddStmt(E->getElement(i));
880e65b086eSTed Kremenek   Writer.AddDeclRef(E->getArrayWithObjectsMethod(), Record);
881413297c5SFariborz Jahanian   Writer.AddDeclRef(E->getArrayAllocMethod(), Record);
882e65b086eSTed Kremenek   Writer.AddSourceRange(E->getSourceRange(), Record);
883e65b086eSTed Kremenek   Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
884e65b086eSTed Kremenek }
885e65b086eSTed Kremenek 
886e65b086eSTed Kremenek void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
887e65b086eSTed Kremenek   VisitExpr(E);
888e65b086eSTed Kremenek   Record.push_back(E->getNumElements());
889e65b086eSTed Kremenek   Record.push_back(E->HasPackExpansions);
890e65b086eSTed Kremenek   for (unsigned i = 0; i < E->getNumElements(); i++) {
891e65b086eSTed Kremenek     ObjCDictionaryElement Element = E->getKeyValueElement(i);
892e65b086eSTed Kremenek     Writer.AddStmt(Element.Key);
893e65b086eSTed Kremenek     Writer.AddStmt(Element.Value);
894e65b086eSTed Kremenek     if (E->HasPackExpansions) {
895e65b086eSTed Kremenek       Writer.AddSourceLocation(Element.EllipsisLoc, Record);
896e65b086eSTed Kremenek       unsigned NumExpansions = 0;
897e65b086eSTed Kremenek       if (Element.NumExpansions)
898e65b086eSTed Kremenek         NumExpansions = *Element.NumExpansions + 1;
899e65b086eSTed Kremenek       Record.push_back(NumExpansions);
900e65b086eSTed Kremenek     }
901e65b086eSTed Kremenek   }
902e65b086eSTed Kremenek 
903e65b086eSTed Kremenek   Writer.AddDeclRef(E->getDictWithObjectsMethod(), Record);
904413297c5SFariborz Jahanian   Writer.AddDeclRef(E->getDictAllocMethod(), Record);
905e65b086eSTed Kremenek   Writer.AddSourceRange(E->getSourceRange(), Record);
906e65b086eSTed Kremenek   Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
907e65b086eSTed Kremenek }
908e65b086eSTed Kremenek 
909d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
910d6522cfcSSebastian Redl   VisitExpr(E);
911d6522cfcSSebastian Redl   Writer.AddTypeSourceInfo(E->getEncodedTypeSourceInfo(), Record);
912d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getAtLoc(), Record);
913d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
914539c5061SSebastian Redl   Code = serialization::EXPR_OBJC_ENCODE;
915d6522cfcSSebastian Redl }
916d6522cfcSSebastian Redl 
917d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
918d6522cfcSSebastian Redl   VisitExpr(E);
919d6522cfcSSebastian Redl   Writer.AddSelectorRef(E->getSelector(), Record);
920d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getAtLoc(), Record);
921d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
922539c5061SSebastian Redl   Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
923d6522cfcSSebastian Redl }
924d6522cfcSSebastian Redl 
925d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
926d6522cfcSSebastian Redl   VisitExpr(E);
927d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getProtocol(), Record);
928d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getAtLoc(), Record);
929b7e4367fSArgyrios Kyrtzidis   Writer.AddSourceLocation(E->ProtoLoc, Record);
930d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
931539c5061SSebastian Redl   Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
932d6522cfcSSebastian Redl }
933d6522cfcSSebastian Redl 
934d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
935d6522cfcSSebastian Redl   VisitExpr(E);
936d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getDecl(), Record);
937d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
938f12ff4dfSFariborz Jahanian   Writer.AddSourceLocation(E->getOpLoc(), Record);
939d6522cfcSSebastian Redl   Writer.AddStmt(E->getBase());
940d6522cfcSSebastian Redl   Record.push_back(E->isArrow());
941d6522cfcSSebastian Redl   Record.push_back(E->isFreeIvar());
942539c5061SSebastian Redl   Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
943d6522cfcSSebastian Redl }
944d6522cfcSSebastian Redl 
945d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
946d6522cfcSSebastian Redl   VisitExpr(E);
947ab468b03SArgyrios Kyrtzidis   Record.push_back(E->SetterAndMethodRefFlags.getInt());
948b7bd14faSJohn McCall   Record.push_back(E->isImplicitProperty());
949b7bd14faSJohn McCall   if (E->isImplicitProperty()) {
950b7bd14faSJohn McCall     Writer.AddDeclRef(E->getImplicitPropertyGetter(), Record);
951b7bd14faSJohn McCall     Writer.AddDeclRef(E->getImplicitPropertySetter(), Record);
952b7bd14faSJohn McCall   } else {
953b7bd14faSJohn McCall     Writer.AddDeclRef(E->getExplicitProperty(), Record);
954b7bd14faSJohn McCall   }
955d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
956b7bd14faSJohn McCall   Writer.AddSourceLocation(E->getReceiverLocation(), Record);
957b7bd14faSJohn McCall   if (E->isObjectReceiver()) {
958b7bd14faSJohn McCall     Record.push_back(0);
959d6522cfcSSebastian Redl     Writer.AddStmt(E->getBase());
960b7bd14faSJohn McCall   } else if (E->isSuperReceiver()) {
961b7bd14faSJohn McCall     Record.push_back(1);
962b7bd14faSJohn McCall     Writer.AddTypeRef(E->getSuperReceiverType(), Record);
963b7bd14faSJohn McCall   } else {
964b7bd14faSJohn McCall     Record.push_back(2);
965b7bd14faSJohn McCall     Writer.AddDeclRef(E->getClassReceiver(), Record);
966d6522cfcSSebastian Redl   }
967d6522cfcSSebastian Redl 
968b7bd14faSJohn McCall   Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
969d6522cfcSSebastian Redl }
970d6522cfcSSebastian Redl 
971e65b086eSTed Kremenek void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
972e65b086eSTed Kremenek   VisitExpr(E);
973e65b086eSTed Kremenek   Writer.AddSourceLocation(E->getRBracket(), Record);
974e65b086eSTed Kremenek   Writer.AddStmt(E->getBaseExpr());
975e65b086eSTed Kremenek   Writer.AddStmt(E->getKeyExpr());
976e65b086eSTed Kremenek   Writer.AddDeclRef(E->getAtIndexMethodDecl(), Record);
977e65b086eSTed Kremenek   Writer.AddDeclRef(E->setAtIndexMethodDecl(), Record);
978e65b086eSTed Kremenek 
979e65b086eSTed Kremenek   Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
980e65b086eSTed Kremenek }
981e65b086eSTed Kremenek 
982d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
983d6522cfcSSebastian Redl   VisitExpr(E);
984d6522cfcSSebastian Redl   Record.push_back(E->getNumArgs());
985a6011e25SArgyrios Kyrtzidis   Record.push_back(E->getNumStoredSelLocs());
986a6011e25SArgyrios Kyrtzidis   Record.push_back(E->SelLocsKind);
98731168b07SJohn McCall   Record.push_back(E->isDelegateInitCall());
988a80f1bf2SArgyrios Kyrtzidis   Record.push_back(E->IsImplicit);
989d6522cfcSSebastian Redl   Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
990d6522cfcSSebastian Redl   switch (E->getReceiverKind()) {
991d6522cfcSSebastian Redl   case ObjCMessageExpr::Instance:
992d6522cfcSSebastian Redl     Writer.AddStmt(E->getInstanceReceiver());
993d6522cfcSSebastian Redl     break;
994d6522cfcSSebastian Redl 
995d6522cfcSSebastian Redl   case ObjCMessageExpr::Class:
996d6522cfcSSebastian Redl     Writer.AddTypeSourceInfo(E->getClassReceiverTypeInfo(), Record);
997d6522cfcSSebastian Redl     break;
998d6522cfcSSebastian Redl 
999d6522cfcSSebastian Redl   case ObjCMessageExpr::SuperClass:
1000d6522cfcSSebastian Redl   case ObjCMessageExpr::SuperInstance:
1001d6522cfcSSebastian Redl     Writer.AddTypeRef(E->getSuperType(), Record);
1002d6522cfcSSebastian Redl     Writer.AddSourceLocation(E->getSuperLoc(), Record);
1003d6522cfcSSebastian Redl     break;
1004d6522cfcSSebastian Redl   }
1005d6522cfcSSebastian Redl 
1006d6522cfcSSebastian Redl   if (E->getMethodDecl()) {
1007d6522cfcSSebastian Redl     Record.push_back(1);
1008d6522cfcSSebastian Redl     Writer.AddDeclRef(E->getMethodDecl(), Record);
1009d6522cfcSSebastian Redl   } else {
1010d6522cfcSSebastian Redl     Record.push_back(0);
1011d6522cfcSSebastian Redl     Writer.AddSelectorRef(E->getSelector(), Record);
1012d6522cfcSSebastian Redl   }
1013d6522cfcSSebastian Redl 
1014d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLeftLoc(), Record);
1015d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRightLoc(), Record);
1016d6522cfcSSebastian Redl 
1017d6522cfcSSebastian Redl   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1018d6522cfcSSebastian Redl        Arg != ArgEnd; ++Arg)
1019d6522cfcSSebastian Redl     Writer.AddStmt(*Arg);
1020a6011e25SArgyrios Kyrtzidis 
1021a6011e25SArgyrios Kyrtzidis   SourceLocation *Locs = E->getStoredSelLocs();
1022a6011e25SArgyrios Kyrtzidis   for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1023a6011e25SArgyrios Kyrtzidis     Writer.AddSourceLocation(Locs[i], Record);
1024a6011e25SArgyrios Kyrtzidis 
1025539c5061SSebastian Redl   Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1026d6522cfcSSebastian Redl }
1027d6522cfcSSebastian Redl 
1028d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1029d6522cfcSSebastian Redl   VisitStmt(S);
1030d6522cfcSSebastian Redl   Writer.AddStmt(S->getElement());
1031d6522cfcSSebastian Redl   Writer.AddStmt(S->getCollection());
1032d6522cfcSSebastian Redl   Writer.AddStmt(S->getBody());
1033d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getForLoc(), Record);
1034d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getRParenLoc(), Record);
1035539c5061SSebastian Redl   Code = serialization::STMT_OBJC_FOR_COLLECTION;
1036d6522cfcSSebastian Redl }
1037d6522cfcSSebastian Redl 
1038d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1039d6522cfcSSebastian Redl   Writer.AddStmt(S->getCatchBody());
1040d6522cfcSSebastian Redl   Writer.AddDeclRef(S->getCatchParamDecl(), Record);
1041d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getAtCatchLoc(), Record);
1042d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getRParenLoc(), Record);
1043539c5061SSebastian Redl   Code = serialization::STMT_OBJC_CATCH;
1044d6522cfcSSebastian Redl }
1045d6522cfcSSebastian Redl 
1046d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1047d6522cfcSSebastian Redl   Writer.AddStmt(S->getFinallyBody());
1048d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getAtFinallyLoc(), Record);
1049539c5061SSebastian Redl   Code = serialization::STMT_OBJC_FINALLY;
1050d6522cfcSSebastian Redl }
1051d6522cfcSSebastian Redl 
105231168b07SJohn McCall void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
105331168b07SJohn McCall   Writer.AddStmt(S->getSubStmt());
105431168b07SJohn McCall   Writer.AddSourceLocation(S->getAtLoc(), Record);
105531168b07SJohn McCall   Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
105631168b07SJohn McCall }
105731168b07SJohn McCall 
1058d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1059d6522cfcSSebastian Redl   Record.push_back(S->getNumCatchStmts());
1060a13603a2SCraig Topper   Record.push_back(S->getFinallyStmt() != nullptr);
1061d6522cfcSSebastian Redl   Writer.AddStmt(S->getTryBody());
1062d6522cfcSSebastian Redl   for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1063d6522cfcSSebastian Redl     Writer.AddStmt(S->getCatchStmt(I));
1064d6522cfcSSebastian Redl   if (S->getFinallyStmt())
1065d6522cfcSSebastian Redl     Writer.AddStmt(S->getFinallyStmt());
1066d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getAtTryLoc(), Record);
1067539c5061SSebastian Redl   Code = serialization::STMT_OBJC_AT_TRY;
1068d6522cfcSSebastian Redl }
1069d6522cfcSSebastian Redl 
1070d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1071d6522cfcSSebastian Redl   Writer.AddStmt(S->getSynchExpr());
1072d6522cfcSSebastian Redl   Writer.AddStmt(S->getSynchBody());
1073d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record);
1074539c5061SSebastian Redl   Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1075d6522cfcSSebastian Redl }
1076d6522cfcSSebastian Redl 
1077d6522cfcSSebastian Redl void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1078d6522cfcSSebastian Redl   Writer.AddStmt(S->getThrowExpr());
1079d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getThrowLoc(), Record);
1080539c5061SSebastian Redl   Code = serialization::STMT_OBJC_AT_THROW;
1081d6522cfcSSebastian Redl }
1082d6522cfcSSebastian Redl 
1083e65b086eSTed Kremenek void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1084e65b086eSTed Kremenek   VisitExpr(E);
1085e65b086eSTed Kremenek   Record.push_back(E->getValue());
1086e65b086eSTed Kremenek   Writer.AddSourceLocation(E->getLocation(), Record);
1087e65b086eSTed Kremenek   Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1088e65b086eSTed Kremenek }
1089e65b086eSTed Kremenek 
1090d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
1091d6522cfcSSebastian Redl // C++ Expressions and Statements.
1092d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
1093d6522cfcSSebastian Redl 
1094d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1095d6522cfcSSebastian Redl   VisitStmt(S);
1096d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getCatchLoc(), Record);
1097d6522cfcSSebastian Redl   Writer.AddDeclRef(S->getExceptionDecl(), Record);
1098d6522cfcSSebastian Redl   Writer.AddStmt(S->getHandlerBlock());
1099539c5061SSebastian Redl   Code = serialization::STMT_CXX_CATCH;
1100d6522cfcSSebastian Redl }
1101d6522cfcSSebastian Redl 
1102d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1103d6522cfcSSebastian Redl   VisitStmt(S);
1104d6522cfcSSebastian Redl   Record.push_back(S->getNumHandlers());
1105d6522cfcSSebastian Redl   Writer.AddSourceLocation(S->getTryLoc(), Record);
1106d6522cfcSSebastian Redl   Writer.AddStmt(S->getTryBlock());
1107d6522cfcSSebastian Redl   for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1108d6522cfcSSebastian Redl     Writer.AddStmt(S->getHandler(i));
1109539c5061SSebastian Redl   Code = serialization::STMT_CXX_TRY;
1110d6522cfcSSebastian Redl }
1111d6522cfcSSebastian Redl 
111202e85f3bSRichard Smith void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
111302e85f3bSRichard Smith   VisitStmt(S);
111402e85f3bSRichard Smith   Writer.AddSourceLocation(S->getForLoc(), Record);
111502e85f3bSRichard Smith   Writer.AddSourceLocation(S->getColonLoc(), Record);
111602e85f3bSRichard Smith   Writer.AddSourceLocation(S->getRParenLoc(), Record);
111702e85f3bSRichard Smith   Writer.AddStmt(S->getRangeStmt());
111802e85f3bSRichard Smith   Writer.AddStmt(S->getBeginEndStmt());
111902e85f3bSRichard Smith   Writer.AddStmt(S->getCond());
112002e85f3bSRichard Smith   Writer.AddStmt(S->getInc());
112102e85f3bSRichard Smith   Writer.AddStmt(S->getLoopVarStmt());
112202e85f3bSRichard Smith   Writer.AddStmt(S->getBody());
112302e85f3bSRichard Smith   Code = serialization::STMT_CXX_FOR_RANGE;
112402e85f3bSRichard Smith }
112502e85f3bSRichard Smith 
1126deb4a2beSDouglas Gregor void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1127deb4a2beSDouglas Gregor   VisitStmt(S);
1128deb4a2beSDouglas Gregor   Writer.AddSourceLocation(S->getKeywordLoc(), Record);
1129deb4a2beSDouglas Gregor   Record.push_back(S->isIfExists());
1130deb4a2beSDouglas Gregor   Writer.AddNestedNameSpecifierLoc(S->getQualifierLoc(), Record);
1131deb4a2beSDouglas Gregor   Writer.AddDeclarationNameInfo(S->getNameInfo(), Record);
1132deb4a2beSDouglas Gregor   Writer.AddStmt(S->getSubStmt());
1133deb4a2beSDouglas Gregor   Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1134deb4a2beSDouglas Gregor }
1135deb4a2beSDouglas Gregor 
1136d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1137d6522cfcSSebastian Redl   VisitCallExpr(E);
1138d6522cfcSSebastian Redl   Record.push_back(E->getOperator());
1139d8e07697SArgyrios Kyrtzidis   Writer.AddSourceRange(E->Range, Record);
11405de91cc3SLang Hames   Record.push_back(E->isFPContractable());
1141539c5061SSebastian Redl   Code = serialization::EXPR_CXX_OPERATOR_CALL;
1142d6522cfcSSebastian Redl }
1143d6522cfcSSebastian Redl 
1144d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1145d6522cfcSSebastian Redl   VisitCallExpr(E);
1146539c5061SSebastian Redl   Code = serialization::EXPR_CXX_MEMBER_CALL;
1147d6522cfcSSebastian Redl }
1148d6522cfcSSebastian Redl 
1149d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1150d6522cfcSSebastian Redl   VisitExpr(E);
1151d6522cfcSSebastian Redl   Record.push_back(E->getNumArgs());
1152d6522cfcSSebastian Redl   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1153d6522cfcSSebastian Redl     Writer.AddStmt(E->getArg(I));
1154d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getConstructor(), Record);
1155d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
1156d6522cfcSSebastian Redl   Record.push_back(E->isElidable());
1157635ed24eSAbramo Bagnara   Record.push_back(E->hadMultipleCandidates());
1158d59b8323SRichard Smith   Record.push_back(E->isListInitialization());
1159f8adcdc4SRichard Smith   Record.push_back(E->isStdInitListInitialization());
1160d6522cfcSSebastian Redl   Record.push_back(E->requiresZeroInitialization());
1161d6522cfcSSebastian Redl   Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
116276e98febSEnea Zaffanella   Writer.AddSourceRange(E->getParenOrBraceRange(), Record);
1163539c5061SSebastian Redl   Code = serialization::EXPR_CXX_CONSTRUCT;
1164d6522cfcSSebastian Redl }
1165d6522cfcSSebastian Redl 
1166d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1167d6522cfcSSebastian Redl   VisitCXXConstructExpr(E);
11682b88c115SDouglas Gregor   Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
1169539c5061SSebastian Redl   Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1170d6522cfcSSebastian Redl }
1171d6522cfcSSebastian Redl 
1172e31e606fSDouglas Gregor void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1173e31e606fSDouglas Gregor   VisitExpr(E);
117499ae806aSDouglas Gregor   Record.push_back(E->NumCaptures);
117599ae806aSDouglas Gregor   unsigned NumArrayIndexVars = 0;
117699ae806aSDouglas Gregor   if (E->HasArrayIndexVars)
117799ae806aSDouglas Gregor     NumArrayIndexVars = E->getArrayIndexStarts()[E->NumCaptures];
117899ae806aSDouglas Gregor   Record.push_back(NumArrayIndexVars);
117999ae806aSDouglas Gregor   Writer.AddSourceRange(E->IntroducerRange, Record);
118099ae806aSDouglas Gregor   Record.push_back(E->CaptureDefault); // FIXME: stable encoding
1181ddd36fffSJames Dennett   Writer.AddSourceLocation(E->CaptureDefaultLoc, Record);
118299ae806aSDouglas Gregor   Record.push_back(E->ExplicitParams);
118399ae806aSDouglas Gregor   Record.push_back(E->ExplicitResultType);
118499ae806aSDouglas Gregor   Writer.AddSourceLocation(E->ClosingBrace, Record);
118599ae806aSDouglas Gregor 
118699ae806aSDouglas Gregor   // Add capture initializers.
118799ae806aSDouglas Gregor   for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
118899ae806aSDouglas Gregor                                       CEnd = E->capture_init_end();
118999ae806aSDouglas Gregor        C != CEnd; ++C) {
119099ae806aSDouglas Gregor     Writer.AddStmt(*C);
119199ae806aSDouglas Gregor   }
119299ae806aSDouglas Gregor 
119399ae806aSDouglas Gregor   // Add array index variables, if any.
119499ae806aSDouglas Gregor   if (NumArrayIndexVars) {
119599ae806aSDouglas Gregor     Record.append(E->getArrayIndexStarts(),
119699ae806aSDouglas Gregor                   E->getArrayIndexStarts() + E->NumCaptures + 1);
119799ae806aSDouglas Gregor     VarDecl **ArrayIndexVars = E->getArrayIndexVars();
119899ae806aSDouglas Gregor     for (unsigned I = 0; I != NumArrayIndexVars; ++I)
119999ae806aSDouglas Gregor       Writer.AddDeclRef(ArrayIndexVars[I], Record);
120099ae806aSDouglas Gregor   }
120199ae806aSDouglas Gregor 
120299ae806aSDouglas Gregor   Code = serialization::EXPR_LAMBDA;
1203e31e606fSDouglas Gregor }
1204e31e606fSDouglas Gregor 
1205cc1b96d3SRichard Smith void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1206cc1b96d3SRichard Smith   VisitExpr(E);
1207cc1b96d3SRichard Smith   Writer.AddStmt(E->getSubExpr());
1208cc1b96d3SRichard Smith   Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1209cc1b96d3SRichard Smith }
1210cc1b96d3SRichard Smith 
1211d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1212d6522cfcSSebastian Redl   VisitExplicitCastExpr(E);
12134478f858SDouglas Gregor   Writer.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()),
12144478f858SDouglas Gregor                         Record);
1215f073871fSFariborz Jahanian   Writer.AddSourceRange(E->getAngleBrackets(), Record);
1216d6522cfcSSebastian Redl }
1217d6522cfcSSebastian Redl 
1218d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1219d6522cfcSSebastian Redl   VisitCXXNamedCastExpr(E);
1220539c5061SSebastian Redl   Code = serialization::EXPR_CXX_STATIC_CAST;
1221d6522cfcSSebastian Redl }
1222d6522cfcSSebastian Redl 
1223d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1224d6522cfcSSebastian Redl   VisitCXXNamedCastExpr(E);
1225539c5061SSebastian Redl   Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1226d6522cfcSSebastian Redl }
1227d6522cfcSSebastian Redl 
1228d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1229d6522cfcSSebastian Redl   VisitCXXNamedCastExpr(E);
1230539c5061SSebastian Redl   Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1231d6522cfcSSebastian Redl }
1232d6522cfcSSebastian Redl 
1233d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1234d6522cfcSSebastian Redl   VisitCXXNamedCastExpr(E);
1235539c5061SSebastian Redl   Code = serialization::EXPR_CXX_CONST_CAST;
1236d6522cfcSSebastian Redl }
1237d6522cfcSSebastian Redl 
1238d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1239d6522cfcSSebastian Redl   VisitExplicitCastExpr(E);
124089fe0d58SEli Friedman   Writer.AddSourceLocation(E->getLParenLoc(), Record);
1241d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
1242539c5061SSebastian Redl   Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1243d6522cfcSSebastian Redl }
1244d6522cfcSSebastian Redl 
1245c67fdd4eSRichard Smith void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1246c67fdd4eSRichard Smith   VisitCallExpr(E);
1247c67fdd4eSRichard Smith   Writer.AddSourceLocation(E->UDSuffixLoc, Record);
1248c67fdd4eSRichard Smith   Code = serialization::EXPR_USER_DEFINED_LITERAL;
1249c67fdd4eSRichard Smith }
1250c67fdd4eSRichard Smith 
1251d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1252d6522cfcSSebastian Redl   VisitExpr(E);
1253d6522cfcSSebastian Redl   Record.push_back(E->getValue());
1254d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
1255539c5061SSebastian Redl   Code = serialization::EXPR_CXX_BOOL_LITERAL;
1256d6522cfcSSebastian Redl }
1257d6522cfcSSebastian Redl 
1258d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1259d6522cfcSSebastian Redl   VisitExpr(E);
1260d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
1261539c5061SSebastian Redl   Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1262d6522cfcSSebastian Redl }
1263d6522cfcSSebastian Redl 
1264d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1265d6522cfcSSebastian Redl   VisitExpr(E);
1266d6522cfcSSebastian Redl   Writer.AddSourceRange(E->getSourceRange(), Record);
1267d6522cfcSSebastian Redl   if (E->isTypeOperand()) {
1268d6522cfcSSebastian Redl     Writer.AddTypeSourceInfo(E->getTypeOperandSourceInfo(), Record);
1269539c5061SSebastian Redl     Code = serialization::EXPR_CXX_TYPEID_TYPE;
1270d6522cfcSSebastian Redl   } else {
1271d6522cfcSSebastian Redl     Writer.AddStmt(E->getExprOperand());
1272539c5061SSebastian Redl     Code = serialization::EXPR_CXX_TYPEID_EXPR;
1273d6522cfcSSebastian Redl   }
1274d6522cfcSSebastian Redl }
1275d6522cfcSSebastian Redl 
1276d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1277d6522cfcSSebastian Redl   VisitExpr(E);
1278d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLocation(), Record);
1279d6522cfcSSebastian Redl   Record.push_back(E->isImplicit());
1280539c5061SSebastian Redl   Code = serialization::EXPR_CXX_THIS;
1281d6522cfcSSebastian Redl }
1282d6522cfcSSebastian Redl 
1283d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1284d6522cfcSSebastian Redl   VisitExpr(E);
1285d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getThrowLoc(), Record);
1286d6522cfcSSebastian Redl   Writer.AddStmt(E->getSubExpr());
128753e191edSDouglas Gregor   Record.push_back(E->isThrownVariableInScope());
1288539c5061SSebastian Redl   Code = serialization::EXPR_CXX_THROW;
1289d6522cfcSSebastian Redl }
1290d6522cfcSSebastian Redl 
1291d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1292d6522cfcSSebastian Redl   VisitExpr(E);
1293d6522cfcSSebastian Redl 
1294d6522cfcSSebastian Redl   bool HasOtherExprStored = E->Param.getInt();
1295d6522cfcSSebastian Redl   // Store these first, the reader reads them before creation.
1296d6522cfcSSebastian Redl   Record.push_back(HasOtherExprStored);
1297d6522cfcSSebastian Redl   if (HasOtherExprStored)
1298d6522cfcSSebastian Redl     Writer.AddStmt(E->getExpr());
1299d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getParam(), Record);
1300d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getUsedLocation(), Record);
1301d6522cfcSSebastian Redl 
1302539c5061SSebastian Redl   Code = serialization::EXPR_CXX_DEFAULT_ARG;
1303d6522cfcSSebastian Redl }
1304d6522cfcSSebastian Redl 
1305852c9db7SRichard Smith void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1306852c9db7SRichard Smith   VisitExpr(E);
1307852c9db7SRichard Smith   Writer.AddDeclRef(E->getField(), Record);
1308852c9db7SRichard Smith   Writer.AddSourceLocation(E->getExprLoc(), Record);
1309852c9db7SRichard Smith   Code = serialization::EXPR_CXX_DEFAULT_INIT;
1310852c9db7SRichard Smith }
1311852c9db7SRichard Smith 
1312d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1313d6522cfcSSebastian Redl   VisitExpr(E);
1314d6522cfcSSebastian Redl   Writer.AddCXXTemporary(E->getTemporary(), Record);
1315d6522cfcSSebastian Redl   Writer.AddStmt(E->getSubExpr());
1316539c5061SSebastian Redl   Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1317d6522cfcSSebastian Redl }
1318d6522cfcSSebastian Redl 
1319d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1320d6522cfcSSebastian Redl   VisitExpr(E);
13212b88c115SDouglas Gregor   Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
1322d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
1323539c5061SSebastian Redl   Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1324d6522cfcSSebastian Redl }
1325d6522cfcSSebastian Redl 
1326d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1327d6522cfcSSebastian Redl   VisitExpr(E);
1328d6522cfcSSebastian Redl   Record.push_back(E->isGlobalNew());
1329c3a3c600SSebastian Redl   Record.push_back(E->isArray());
13306047f07eSSebastian Redl   Record.push_back(E->doesUsualArrayDeleteWantSize());
1331d6522cfcSSebastian Redl   Record.push_back(E->getNumPlacementArgs());
13326047f07eSSebastian Redl   Record.push_back(E->StoredInitializationStyle);
1333d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getOperatorNew(), Record);
1334d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getOperatorDelete(), Record);
13350744ef63SDouglas Gregor   Writer.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo(), Record);
1336d6522cfcSSebastian Redl   Writer.AddSourceRange(E->getTypeIdParens(), Record);
13377b97aef9SDavid Blaikie   Writer.AddSourceRange(E->getSourceRange(), Record);
13386047f07eSSebastian Redl   Writer.AddSourceRange(E->getDirectInitRange(), Record);
1339d6522cfcSSebastian Redl   for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
1340d6522cfcSSebastian Redl        I != e; ++I)
1341d6522cfcSSebastian Redl     Writer.AddStmt(*I);
1342d6522cfcSSebastian Redl 
1343539c5061SSebastian Redl   Code = serialization::EXPR_CXX_NEW;
1344d6522cfcSSebastian Redl }
1345d6522cfcSSebastian Redl 
1346d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1347d6522cfcSSebastian Redl   VisitExpr(E);
1348d6522cfcSSebastian Redl   Record.push_back(E->isGlobalDelete());
1349d6522cfcSSebastian Redl   Record.push_back(E->isArrayForm());
135014ec9f67SArgyrios Kyrtzidis   Record.push_back(E->isArrayFormAsWritten());
1351284c48ffSJohn McCall   Record.push_back(E->doesUsualArrayDeleteWantSize());
1352d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getOperatorDelete(), Record);
1353d6522cfcSSebastian Redl   Writer.AddStmt(E->getArgument());
1354d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getSourceRange().getBegin(), Record);
1355d6522cfcSSebastian Redl 
1356539c5061SSebastian Redl   Code = serialization::EXPR_CXX_DELETE;
1357d6522cfcSSebastian Redl }
1358d6522cfcSSebastian Redl 
1359d6522cfcSSebastian Redl void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1360d6522cfcSSebastian Redl   VisitExpr(E);
1361d6522cfcSSebastian Redl 
1362d6522cfcSSebastian Redl   Writer.AddStmt(E->getBase());
1363d6522cfcSSebastian Redl   Record.push_back(E->isArrow());
1364d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
1365a6ce608bSDouglas Gregor   Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record);
1366d6522cfcSSebastian Redl   Writer.AddTypeSourceInfo(E->getScopeTypeInfo(), Record);
1367d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getColonColonLoc(), Record);
1368d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getTildeLoc(), Record);
1369d6522cfcSSebastian Redl 
1370d6522cfcSSebastian Redl   // PseudoDestructorTypeStorage.
1371d6522cfcSSebastian Redl   Writer.AddIdentifierRef(E->getDestroyedTypeIdentifier(), Record);
1372d6522cfcSSebastian Redl   if (E->getDestroyedTypeIdentifier())
1373d6522cfcSSebastian Redl     Writer.AddSourceLocation(E->getDestroyedTypeLoc(), Record);
1374d6522cfcSSebastian Redl   else
1375d6522cfcSSebastian Redl     Writer.AddTypeSourceInfo(E->getDestroyedTypeInfo(), Record);
1376d6522cfcSSebastian Redl 
1377539c5061SSebastian Redl   Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1378d6522cfcSSebastian Redl }
1379d6522cfcSSebastian Redl 
13805d413781SJohn McCall void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1381d6522cfcSSebastian Redl   VisitExpr(E);
138228fc7091SJohn McCall   Record.push_back(E->getNumObjects());
138328fc7091SJohn McCall   for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
138428fc7091SJohn McCall     Writer.AddDeclRef(E->getObject(i), Record);
1385d6522cfcSSebastian Redl 
1386d6522cfcSSebastian Redl   Writer.AddStmt(E->getSubExpr());
13875d413781SJohn McCall   Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1388d6522cfcSSebastian Redl }
1389d6522cfcSSebastian Redl 
1390d6522cfcSSebastian Redl void
1391d6522cfcSSebastian Redl ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
1392d6522cfcSSebastian Redl   VisitExpr(E);
1393d6522cfcSSebastian Redl 
13947945c981SAbramo Bagnara   // Don't emit anything here, HasTemplateKWAndArgsInfo must be
139587866cedSDouglas Gregor   // emitted first.
1396d6522cfcSSebastian Redl 
13977945c981SAbramo Bagnara   Record.push_back(E->HasTemplateKWAndArgsInfo);
13987945c981SAbramo Bagnara   if (E->HasTemplateKWAndArgsInfo) {
13997945c981SAbramo Bagnara     const ASTTemplateKWAndArgsInfo &Args = *E->getTemplateKWAndArgsInfo();
1400d6522cfcSSebastian Redl     Record.push_back(Args.NumTemplateArgs);
14017945c981SAbramo Bagnara     AddTemplateKWAndArgsInfo(Args);
1402d6522cfcSSebastian Redl   }
1403d6522cfcSSebastian Redl 
1404d6522cfcSSebastian Redl   if (!E->isImplicitAccess())
1405d6522cfcSSebastian Redl     Writer.AddStmt(E->getBase());
1406d6522cfcSSebastian Redl   else
1407a13603a2SCraig Topper     Writer.AddStmt(nullptr);
1408d6522cfcSSebastian Redl   Writer.AddTypeRef(E->getBaseType(), Record);
1409d6522cfcSSebastian Redl   Record.push_back(E->isArrow());
1410d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
1411e16af536SDouglas Gregor   Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record);
1412d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getFirstQualifierFoundInScope(), Record);
1413434383d7SArgyrios Kyrtzidis   Writer.AddDeclarationNameInfo(E->MemberNameInfo, Record);
1414539c5061SSebastian Redl   Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
1415d6522cfcSSebastian Redl }
1416d6522cfcSSebastian Redl 
1417d6522cfcSSebastian Redl void
1418d6522cfcSSebastian Redl ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1419d6522cfcSSebastian Redl   VisitExpr(E);
1420d6522cfcSSebastian Redl 
14217945c981SAbramo Bagnara   // Don't emit anything here, HasTemplateKWAndArgsInfo must be
142287866cedSDouglas Gregor   // emitted first.
14237945c981SAbramo Bagnara 
14247945c981SAbramo Bagnara   Record.push_back(E->HasTemplateKWAndArgsInfo);
14257945c981SAbramo Bagnara   if (E->HasTemplateKWAndArgsInfo) {
14267945c981SAbramo Bagnara     const ASTTemplateKWAndArgsInfo &Args = *E->getTemplateKWAndArgsInfo();
1427d6522cfcSSebastian Redl     Record.push_back(Args.NumTemplateArgs);
14287945c981SAbramo Bagnara     AddTemplateKWAndArgsInfo(Args);
1429d6522cfcSSebastian Redl   }
1430d6522cfcSSebastian Redl 
14313a43fd64SDouglas Gregor   Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record);
1432434383d7SArgyrios Kyrtzidis   Writer.AddDeclarationNameInfo(E->NameInfo, Record);
1433539c5061SSebastian Redl   Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
1434d6522cfcSSebastian Redl }
1435d6522cfcSSebastian Redl 
1436d6522cfcSSebastian Redl void
1437d6522cfcSSebastian Redl ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1438d6522cfcSSebastian Redl   VisitExpr(E);
1439d6522cfcSSebastian Redl   Record.push_back(E->arg_size());
1440d6522cfcSSebastian Redl   for (CXXUnresolvedConstructExpr::arg_iterator
1441d6522cfcSSebastian Redl          ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
1442d6522cfcSSebastian Redl     Writer.AddStmt(*ArgI);
14432b88c115SDouglas Gregor   Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
1444d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getLParenLoc(), Record);
1445d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getRParenLoc(), Record);
1446539c5061SSebastian Redl   Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
1447d6522cfcSSebastian Redl }
1448d6522cfcSSebastian Redl 
1449d6522cfcSSebastian Redl void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
1450d6522cfcSSebastian Redl   VisitExpr(E);
1451d6522cfcSSebastian Redl 
14527945c981SAbramo Bagnara   // Don't emit anything here, HasTemplateKWAndArgsInfo must be
14537945c981SAbramo Bagnara   // emitted first.
14547945c981SAbramo Bagnara 
14557945c981SAbramo Bagnara   Record.push_back(E->HasTemplateKWAndArgsInfo);
14567945c981SAbramo Bagnara   if (E->HasTemplateKWAndArgsInfo) {
14577945c981SAbramo Bagnara     const ASTTemplateKWAndArgsInfo &Args = *E->getTemplateKWAndArgsInfo();
1458d6522cfcSSebastian Redl     Record.push_back(Args.NumTemplateArgs);
14597945c981SAbramo Bagnara     AddTemplateKWAndArgsInfo(Args);
1460d6522cfcSSebastian Redl   }
1461d6522cfcSSebastian Redl 
1462d6522cfcSSebastian Redl   Record.push_back(E->getNumDecls());
1463d6522cfcSSebastian Redl   for (OverloadExpr::decls_iterator
1464d6522cfcSSebastian Redl          OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
1465d6522cfcSSebastian Redl     Writer.AddDeclRef(OvI.getDecl(), Record);
1466d6522cfcSSebastian Redl     Record.push_back(OvI.getAccess());
1467d6522cfcSSebastian Redl   }
1468d6522cfcSSebastian Redl 
1469434383d7SArgyrios Kyrtzidis   Writer.AddDeclarationNameInfo(E->NameInfo, Record);
14700da1d43eSDouglas Gregor   Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record);
1471d6522cfcSSebastian Redl }
1472d6522cfcSSebastian Redl 
1473d6522cfcSSebastian Redl void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1474d6522cfcSSebastian Redl   VisitOverloadExpr(E);
1475d6522cfcSSebastian Redl   Record.push_back(E->isArrow());
1476d6522cfcSSebastian Redl   Record.push_back(E->hasUnresolvedUsing());
1477a13603a2SCraig Topper   Writer.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1478d6522cfcSSebastian Redl   Writer.AddTypeRef(E->getBaseType(), Record);
1479d6522cfcSSebastian Redl   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
1480539c5061SSebastian Redl   Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
1481d6522cfcSSebastian Redl }
1482d6522cfcSSebastian Redl 
1483d6522cfcSSebastian Redl void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1484d6522cfcSSebastian Redl   VisitOverloadExpr(E);
1485d6522cfcSSebastian Redl   Record.push_back(E->requiresADL());
1486d6522cfcSSebastian Redl   Record.push_back(E->isOverloaded());
1487d6522cfcSSebastian Redl   Writer.AddDeclRef(E->getNamingClass(), Record);
1488539c5061SSebastian Redl   Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
1489d6522cfcSSebastian Redl }
1490d6522cfcSSebastian Redl 
149129c42f2aSDouglas Gregor void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
149229c42f2aSDouglas Gregor   VisitExpr(E);
149329c42f2aSDouglas Gregor   Record.push_back(E->TypeTraitExprBits.NumArgs);
149429c42f2aSDouglas Gregor   Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
149529c42f2aSDouglas Gregor   Record.push_back(E->TypeTraitExprBits.Value);
149699e80c14SJordan Rose   Writer.AddSourceRange(E->getSourceRange(), Record);
149729c42f2aSDouglas Gregor   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
149829c42f2aSDouglas Gregor     Writer.AddTypeSourceInfo(E->getArg(I), Record);
149929c42f2aSDouglas Gregor   Code = serialization::EXPR_TYPE_TRAIT;
150029c42f2aSDouglas Gregor }
150129c42f2aSDouglas Gregor 
15026242b6a6SJohn Wiegley void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
15036242b6a6SJohn Wiegley   VisitExpr(E);
15046242b6a6SJohn Wiegley   Record.push_back(E->getTrait());
15056242b6a6SJohn Wiegley   Record.push_back(E->getValue());
15066242b6a6SJohn Wiegley   Writer.AddSourceRange(E->getSourceRange(), Record);
15076242b6a6SJohn Wiegley   Writer.AddTypeSourceInfo(E->getQueriedTypeSourceInfo(), Record);
15086242b6a6SJohn Wiegley   Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
15096242b6a6SJohn Wiegley }
15106242b6a6SJohn Wiegley 
1511f9f6584eSJohn Wiegley void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1512f9f6584eSJohn Wiegley   VisitExpr(E);
1513f9f6584eSJohn Wiegley   Record.push_back(E->getTrait());
1514f9f6584eSJohn Wiegley   Record.push_back(E->getValue());
1515f9f6584eSJohn Wiegley   Writer.AddSourceRange(E->getSourceRange(), Record);
1516f9f6584eSJohn Wiegley   Writer.AddStmt(E->getQueriedExpression());
1517f9f6584eSJohn Wiegley   Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1518f9f6584eSJohn Wiegley }
1519f9f6584eSJohn Wiegley 
15209ac55dd8SSebastian Redl void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
15219ac55dd8SSebastian Redl   VisitExpr(E);
15229ac55dd8SSebastian Redl   Record.push_back(E->getValue());
15239ac55dd8SSebastian Redl   Writer.AddSourceRange(E->getSourceRange(), Record);
15249ac55dd8SSebastian Redl   Writer.AddStmt(E->getOperand());
15259ac55dd8SSebastian Redl   Code = serialization::EXPR_CXX_NOEXCEPT;
15269ac55dd8SSebastian Redl }
15279ac55dd8SSebastian Redl 
1528e8e9dd62SDouglas Gregor void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1529e8e9dd62SDouglas Gregor   VisitExpr(E);
1530e8e9dd62SDouglas Gregor   Writer.AddSourceLocation(E->getEllipsisLoc(), Record);
1531b884000bSDouglas Gregor   Record.push_back(E->NumExpansions);
1532e8e9dd62SDouglas Gregor   Writer.AddStmt(E->getPattern());
1533e8e9dd62SDouglas Gregor   Code = serialization::EXPR_PACK_EXPANSION;
1534e8e9dd62SDouglas Gregor }
1535e8e9dd62SDouglas Gregor 
1536820ba7baSDouglas Gregor void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1537820ba7baSDouglas Gregor   VisitExpr(E);
1538820ba7baSDouglas Gregor   Writer.AddSourceLocation(E->OperatorLoc, Record);
1539820ba7baSDouglas Gregor   Writer.AddSourceLocation(E->PackLoc, Record);
1540820ba7baSDouglas Gregor   Writer.AddSourceLocation(E->RParenLoc, Record);
1541820ba7baSDouglas Gregor   Record.push_back(E->Length);
1542820ba7baSDouglas Gregor   Writer.AddDeclRef(E->Pack, Record);
1543820ba7baSDouglas Gregor   Code = serialization::EXPR_SIZEOF_PACK;
1544820ba7baSDouglas Gregor }
1545820ba7baSDouglas Gregor 
1546fa19404cSJohn McCall void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1547fa19404cSJohn McCall                                               SubstNonTypeTemplateParmExpr *E) {
1548fa19404cSJohn McCall   VisitExpr(E);
1549fa19404cSJohn McCall   Writer.AddDeclRef(E->getParameter(), Record);
1550fa19404cSJohn McCall   Writer.AddSourceLocation(E->getNameLoc(), Record);
1551fa19404cSJohn McCall   Writer.AddStmt(E->getReplacement());
1552fa19404cSJohn McCall   Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1553fa19404cSJohn McCall }
1554fa19404cSJohn McCall 
1555cdbc539aSDouglas Gregor void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1556cdbc539aSDouglas Gregor                                           SubstNonTypeTemplateParmPackExpr *E) {
1557cdbc539aSDouglas Gregor   VisitExpr(E);
1558fa19404cSJohn McCall   Writer.AddDeclRef(E->getParameterPack(), Record);
1559cdbc539aSDouglas Gregor   Writer.AddTemplateArgument(E->getArgumentPack(), Record);
1560fa19404cSJohn McCall   Writer.AddSourceLocation(E->getParameterPackLocation(), Record);
1561cdbc539aSDouglas Gregor   Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1562cdbc539aSDouglas Gregor }
1563cdbc539aSDouglas Gregor 
1564b15fe3a5SRichard Smith void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1565b15fe3a5SRichard Smith   VisitExpr(E);
1566b15fe3a5SRichard Smith   Record.push_back(E->getNumExpansions());
1567b15fe3a5SRichard Smith   Writer.AddDeclRef(E->getParameterPack(), Record);
1568b15fe3a5SRichard Smith   Writer.AddSourceLocation(E->getParameterPackLocation(), Record);
1569b15fe3a5SRichard Smith   for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1570b15fe3a5SRichard Smith        I != End; ++I)
1571b15fe3a5SRichard Smith     Writer.AddDeclRef(*I, Record);
1572b15fe3a5SRichard Smith   Code = serialization::EXPR_FUNCTION_PARM_PACK;
1573b15fe3a5SRichard Smith }
1574b15fe3a5SRichard Smith 
1575fe31481fSDouglas Gregor void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1576fe31481fSDouglas Gregor   VisitExpr(E);
1577daff3701SDavid Majnemer   Writer.AddStmt(E->getTemporary());
1578daff3701SDavid Majnemer   Writer.AddDeclRef(E->getExtendingDecl(), Record);
1579daff3701SDavid Majnemer   Record.push_back(E->getManglingNumber());
1580fe31481fSDouglas Gregor   Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1581fe31481fSDouglas Gregor }
1582fe31481fSDouglas Gregor 
15838d69a216SJohn McCall void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
15848d69a216SJohn McCall   VisitExpr(E);
1585b2b0795cSArgyrios Kyrtzidis   Writer.AddStmt(E->getSourceExpr());
1586c03a1083SDouglas Gregor   Writer.AddSourceLocation(E->getLocation(), Record);
15878d69a216SJohn McCall   Code = serialization::EXPR_OPAQUE_VALUE;
15888d69a216SJohn McCall }
15898d69a216SJohn McCall 
1590d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
159141f85462SPeter Collingbourne // CUDA Expressions and Statements.
159241f85462SPeter Collingbourne //===----------------------------------------------------------------------===//
159341f85462SPeter Collingbourne 
159441f85462SPeter Collingbourne void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
159541f85462SPeter Collingbourne   VisitCallExpr(E);
159641f85462SPeter Collingbourne   Writer.AddStmt(E->getConfig());
159741f85462SPeter Collingbourne   Code = serialization::EXPR_CUDA_KERNEL_CALL;
159841f85462SPeter Collingbourne }
159941f85462SPeter Collingbourne 
160041f85462SPeter Collingbourne //===----------------------------------------------------------------------===//
160155808c10STanya Lattner // OpenCL Expressions and Statements.
160255808c10STanya Lattner //===----------------------------------------------------------------------===//
160355808c10STanya Lattner void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
160455808c10STanya Lattner   VisitExpr(E);
1605fa19404cSJohn McCall   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
1606fa19404cSJohn McCall   Writer.AddSourceLocation(E->getRParenLoc(), Record);
160755808c10STanya Lattner   Writer.AddStmt(E->getSrcExpr());
160855808c10STanya Lattner   Code = serialization::EXPR_ASTYPE;
160955808c10STanya Lattner }
161055808c10STanya Lattner 
161155808c10STanya Lattner //===----------------------------------------------------------------------===//
1612fa19404cSJohn McCall // Microsoft Expressions and Statements.
1613fa19404cSJohn McCall //===----------------------------------------------------------------------===//
16145e77d76cSJohn McCall void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
16155e77d76cSJohn McCall   VisitExpr(E);
16165e77d76cSJohn McCall   Record.push_back(E->isArrow());
16175e77d76cSJohn McCall   Writer.AddStmt(E->getBaseExpr());
16185e77d76cSJohn McCall   Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record);
16195e77d76cSJohn McCall   Writer.AddSourceLocation(E->getMemberLoc(), Record);
16205e77d76cSJohn McCall   Writer.AddDeclRef(E->getPropertyDecl(), Record);
16215e77d76cSJohn McCall   Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
16225e77d76cSJohn McCall }
16235e77d76cSJohn McCall 
1624fa19404cSJohn McCall void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1625fa19404cSJohn McCall   VisitExpr(E);
1626fa19404cSJohn McCall   Writer.AddSourceRange(E->getSourceRange(), Record);
1627fa19404cSJohn McCall   if (E->isTypeOperand()) {
1628fa19404cSJohn McCall     Writer.AddTypeSourceInfo(E->getTypeOperandSourceInfo(), Record);
1629fa19404cSJohn McCall     Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1630fa19404cSJohn McCall   } else {
1631fa19404cSJohn McCall     Writer.AddStmt(E->getExprOperand());
1632fa19404cSJohn McCall     Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1633fa19404cSJohn McCall   }
1634fa19404cSJohn McCall }
1635fa19404cSJohn McCall 
1636fa19404cSJohn McCall void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1637fa19404cSJohn McCall   VisitStmt(S);
1638fa19404cSJohn McCall   Writer.AddSourceLocation(S->getExceptLoc(), Record);
1639fa19404cSJohn McCall   Writer.AddStmt(S->getFilterExpr());
1640fa19404cSJohn McCall   Writer.AddStmt(S->getBlock());
1641fa19404cSJohn McCall   Code = serialization::STMT_SEH_EXCEPT;
1642fa19404cSJohn McCall }
1643fa19404cSJohn McCall 
1644fa19404cSJohn McCall void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1645fa19404cSJohn McCall   VisitStmt(S);
1646fa19404cSJohn McCall   Writer.AddSourceLocation(S->getFinallyLoc(), Record);
1647fa19404cSJohn McCall   Writer.AddStmt(S->getBlock());
1648fa19404cSJohn McCall   Code = serialization::STMT_SEH_FINALLY;
1649fa19404cSJohn McCall }
1650fa19404cSJohn McCall 
1651fa19404cSJohn McCall void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1652fa19404cSJohn McCall   VisitStmt(S);
1653fa19404cSJohn McCall   Record.push_back(S->getIsCXXTry());
1654fa19404cSJohn McCall   Writer.AddSourceLocation(S->getTryLoc(), Record);
1655fa19404cSJohn McCall   Writer.AddStmt(S->getTryBlock());
1656fa19404cSJohn McCall   Writer.AddStmt(S->getHandler());
1657fa19404cSJohn McCall   Code = serialization::STMT_SEH_TRY;
1658fa19404cSJohn McCall }
1659fa19404cSJohn McCall 
16609b982078SNico Weber void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
16619b982078SNico Weber   VisitStmt(S);
16629b982078SNico Weber   Writer.AddSourceLocation(S->getLeaveLoc(), Record);
16639b982078SNico Weber   Code = serialization::STMT_SEH_LEAVE;
16649b982078SNico Weber }
16659b982078SNico Weber 
1666fa19404cSJohn McCall //===----------------------------------------------------------------------===//
16675ec3eb11SAlexey Bataev // OpenMP Clauses.
16685ec3eb11SAlexey Bataev //===----------------------------------------------------------------------===//
16695ec3eb11SAlexey Bataev 
16705ec3eb11SAlexey Bataev namespace clang {
16715ec3eb11SAlexey Bataev class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> {
16725ec3eb11SAlexey Bataev   ASTStmtWriter *Writer;
16735ec3eb11SAlexey Bataev   ASTWriter::RecordData &Record;
16745ec3eb11SAlexey Bataev public:
16755ec3eb11SAlexey Bataev   OMPClauseWriter(ASTStmtWriter *W, ASTWriter::RecordData &Record)
16765ec3eb11SAlexey Bataev     : Writer(W), Record(Record) { }
16775ec3eb11SAlexey Bataev #define OPENMP_CLAUSE(Name, Class)    \
16785ec3eb11SAlexey Bataev   void Visit##Class(Class *S);
16795ec3eb11SAlexey Bataev #include "clang/Basic/OpenMPKinds.def"
16805ec3eb11SAlexey Bataev   void writeClause(OMPClause *C);
16815ec3eb11SAlexey Bataev };
16825ec3eb11SAlexey Bataev }
16835ec3eb11SAlexey Bataev 
16845ec3eb11SAlexey Bataev void OMPClauseWriter::writeClause(OMPClause *C) {
16855ec3eb11SAlexey Bataev   Record.push_back(C->getClauseKind());
16865ec3eb11SAlexey Bataev   Visit(C);
16875ec3eb11SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLocStart(), Record);
16885ec3eb11SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLocEnd(), Record);
16895ec3eb11SAlexey Bataev }
16905ec3eb11SAlexey Bataev 
1691aadd52e5SAlexey Bataev void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) {
1692aadd52e5SAlexey Bataev   Writer->Writer.AddStmt(C->getCondition());
1693aadd52e5SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1694aadd52e5SAlexey Bataev }
1695aadd52e5SAlexey Bataev 
16963778b601SAlexey Bataev void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) {
16973778b601SAlexey Bataev   Writer->Writer.AddStmt(C->getCondition());
16983778b601SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
16993778b601SAlexey Bataev }
17003778b601SAlexey Bataev 
1701568a833fSAlexey Bataev void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
1702568a833fSAlexey Bataev   Writer->Writer.AddStmt(C->getNumThreads());
1703568a833fSAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1704568a833fSAlexey Bataev }
1705568a833fSAlexey Bataev 
170662c87d25SAlexey Bataev void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) {
170762c87d25SAlexey Bataev   Writer->Writer.AddStmt(C->getSafelen());
170862c87d25SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
170962c87d25SAlexey Bataev }
171062c87d25SAlexey Bataev 
17118bd31e69SAlexander Musman void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) {
17128bd31e69SAlexander Musman   Writer->Writer.AddStmt(C->getNumForLoops());
17138bd31e69SAlexander Musman   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
17148bd31e69SAlexander Musman }
17158bd31e69SAlexander Musman 
17165ec3eb11SAlexey Bataev void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
17175ec3eb11SAlexey Bataev   Record.push_back(C->getDefaultKind());
17185ec3eb11SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
17195ec3eb11SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getDefaultKindKwLoc(), Record);
17205ec3eb11SAlexey Bataev }
17215ec3eb11SAlexey Bataev 
1722bcbadb65SAlexey Bataev void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
1723bcbadb65SAlexey Bataev   Record.push_back(C->getProcBindKind());
1724bcbadb65SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1725bcbadb65SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getProcBindKindKwLoc(), Record);
1726bcbadb65SAlexey Bataev }
1727bcbadb65SAlexey Bataev 
172856dafe87SAlexey Bataev void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
172956dafe87SAlexey Bataev   Record.push_back(C->getScheduleKind());
173056dafe87SAlexey Bataev   Writer->Writer.AddStmt(C->getChunkSize());
173156dafe87SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
173256dafe87SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getScheduleKindLoc(), Record);
173356dafe87SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getCommaLoc(), Record);
173456dafe87SAlexey Bataev }
173556dafe87SAlexey Bataev 
1736142e1fc9SAlexey Bataev void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *) {}
1737142e1fc9SAlexey Bataev 
1738236070f2SAlexey Bataev void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {}
1739236070f2SAlexey Bataev 
17407aea99a3SAlexey Bataev void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}
17417aea99a3SAlexey Bataev 
174274ba3a58SAlexey Bataev void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
174374ba3a58SAlexey Bataev 
1744f98b00c3SAlexey Bataev void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {}
1745f98b00c3SAlexey Bataev 
1746dea4761cSAlexey Bataev void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {}
1747dea4761cSAlexey Bataev 
174867a4f22fSAlexey Bataev void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {}
174967a4f22fSAlexey Bataev 
1750459dec0cSAlexey Bataev void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {}
1751459dec0cSAlexey Bataev 
175282bad8b0SAlexey Bataev void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
175382bad8b0SAlexey Bataev 
17545ec3eb11SAlexey Bataev void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
17555ec3eb11SAlexey Bataev   Record.push_back(C->varlist_size());
17565ec3eb11SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1757444120d4SAlexey Bataev   for (auto *VE : C->varlists())
1758444120d4SAlexey Bataev     Writer->Writer.AddStmt(VE);
17595ec3eb11SAlexey Bataev }
17605ec3eb11SAlexey Bataev 
1761d5af8e47SAlexey Bataev void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
1762d5af8e47SAlexey Bataev   Record.push_back(C->varlist_size());
1763d5af8e47SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1764444120d4SAlexey Bataev   for (auto *VE : C->varlists())
1765444120d4SAlexey Bataev     Writer->Writer.AddStmt(VE);
1766d5af8e47SAlexey Bataev }
1767d5af8e47SAlexey Bataev 
17681bb328ccSAlexander Musman void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
17691bb328ccSAlexander Musman   Record.push_back(C->varlist_size());
17701bb328ccSAlexander Musman   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
17711bb328ccSAlexander Musman   for (auto *VE : C->varlists())
17721bb328ccSAlexander Musman     Writer->Writer.AddStmt(VE);
17731bb328ccSAlexander Musman }
17741bb328ccSAlexander Musman 
1775758e55eeSAlexey Bataev void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {
1776758e55eeSAlexey Bataev   Record.push_back(C->varlist_size());
1777758e55eeSAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1778444120d4SAlexey Bataev   for (auto *VE : C->varlists())
1779444120d4SAlexey Bataev     Writer->Writer.AddStmt(VE);
1780758e55eeSAlexey Bataev }
1781758e55eeSAlexey Bataev 
1782c5e02583SAlexey Bataev void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) {
1783c5e02583SAlexey Bataev   Record.push_back(C->varlist_size());
1784c5e02583SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1785c5e02583SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getColonLoc(), Record);
1786c5e02583SAlexey Bataev   Writer->Writer.AddNestedNameSpecifierLoc(C->getQualifierLoc(), Record);
1787c5e02583SAlexey Bataev   Writer->Writer.AddDeclarationNameInfo(C->getNameInfo(), Record);
1788c5e02583SAlexey Bataev   for (auto *VE : C->varlists())
1789c5e02583SAlexey Bataev     Writer->Writer.AddStmt(VE);
1790c5e02583SAlexey Bataev }
1791c5e02583SAlexey Bataev 
17928dba6641SAlexander Musman void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) {
17938dba6641SAlexander Musman   Record.push_back(C->varlist_size());
17948dba6641SAlexander Musman   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
17958dba6641SAlexander Musman   Writer->Writer.AddSourceLocation(C->getColonLoc(), Record);
17968dba6641SAlexander Musman   for (auto *VE : C->varlists())
17978dba6641SAlexander Musman     Writer->Writer.AddStmt(VE);
17988dba6641SAlexander Musman   Writer->Writer.AddStmt(C->getStep());
17998dba6641SAlexander Musman }
18008dba6641SAlexander Musman 
1801f0d76e7dSAlexander Musman void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) {
1802f0d76e7dSAlexander Musman   Record.push_back(C->varlist_size());
1803f0d76e7dSAlexander Musman   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1804f0d76e7dSAlexander Musman   Writer->Writer.AddSourceLocation(C->getColonLoc(), Record);
1805f0d76e7dSAlexander Musman   for (auto *VE : C->varlists())
1806f0d76e7dSAlexander Musman     Writer->Writer.AddStmt(VE);
1807f0d76e7dSAlexander Musman   Writer->Writer.AddStmt(C->getAlignment());
1808f0d76e7dSAlexander Musman }
1809f0d76e7dSAlexander Musman 
1810d48bcd8aSAlexey Bataev void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) {
1811d48bcd8aSAlexey Bataev   Record.push_back(C->varlist_size());
1812d48bcd8aSAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1813444120d4SAlexey Bataev   for (auto *VE : C->varlists())
1814444120d4SAlexey Bataev     Writer->Writer.AddStmt(VE);
1815d48bcd8aSAlexey Bataev }
1816d48bcd8aSAlexey Bataev 
1817bae9a793SAlexey Bataev void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
1818bae9a793SAlexey Bataev   Record.push_back(C->varlist_size());
1819bae9a793SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
1820bae9a793SAlexey Bataev   for (auto *VE : C->varlists())
1821bae9a793SAlexey Bataev     Writer->Writer.AddStmt(VE);
1822bae9a793SAlexey Bataev }
1823bae9a793SAlexey Bataev 
18246125da92SAlexey Bataev void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) {
18256125da92SAlexey Bataev   Record.push_back(C->varlist_size());
18266125da92SAlexey Bataev   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
18276125da92SAlexey Bataev   for (auto *VE : C->varlists())
18286125da92SAlexey Bataev     Writer->Writer.AddStmt(VE);
18296125da92SAlexey Bataev }
18306125da92SAlexey Bataev 
18315ec3eb11SAlexey Bataev //===----------------------------------------------------------------------===//
18325ec3eb11SAlexey Bataev // OpenMP Directives.
18335ec3eb11SAlexey Bataev //===----------------------------------------------------------------------===//
18345ec3eb11SAlexey Bataev void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
18355ec3eb11SAlexey Bataev   Writer.AddSourceLocation(E->getLocStart(), Record);
18365ec3eb11SAlexey Bataev   Writer.AddSourceLocation(E->getLocEnd(), Record);
18375ec3eb11SAlexey Bataev   OMPClauseWriter ClauseWriter(this, Record);
18385ec3eb11SAlexey Bataev   for (unsigned i = 0; i < E->getNumClauses(); ++i) {
18395ec3eb11SAlexey Bataev     ClauseWriter.writeClause(E->getClause(i));
18405ec3eb11SAlexey Bataev   }
184168446b72SAlexey Bataev   if (E->hasAssociatedStmt())
18425ec3eb11SAlexey Bataev     Writer.AddStmt(E->getAssociatedStmt());
18435ec3eb11SAlexey Bataev }
18445ec3eb11SAlexey Bataev 
18453aaab669SAlexander Musman void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
18463aaab669SAlexander Musman   VisitStmt(D);
18473aaab669SAlexander Musman   Record.push_back(D->getNumClauses());
18483aaab669SAlexander Musman   Record.push_back(D->getCollapsedNumber());
18493aaab669SAlexander Musman   VisitOMPExecutableDirective(D);
18503aaab669SAlexander Musman }
18513aaab669SAlexander Musman 
18525ec3eb11SAlexey Bataev void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
18531b59ab56SAlexey Bataev   VisitStmt(D);
18541b59ab56SAlexey Bataev   Record.push_back(D->getNumClauses());
18555ec3eb11SAlexey Bataev   VisitOMPExecutableDirective(D);
18565ec3eb11SAlexey Bataev   Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
18575ec3eb11SAlexey Bataev }
18585ec3eb11SAlexey Bataev 
18591b59ab56SAlexey Bataev void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
18603aaab669SAlexander Musman   VisitOMPLoopDirective(D);
18611b59ab56SAlexey Bataev   Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
18621b59ab56SAlexey Bataev }
18631b59ab56SAlexey Bataev 
1864f29276edSAlexey Bataev void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
18653aaab669SAlexander Musman   VisitOMPLoopDirective(D);
1866f29276edSAlexey Bataev   Code = serialization::STMT_OMP_FOR_DIRECTIVE;
1867f29276edSAlexey Bataev }
1868f29276edSAlexey Bataev 
1869f82886e5SAlexander Musman void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
1870f82886e5SAlexander Musman   VisitOMPLoopDirective(D);
1871f82886e5SAlexander Musman   Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
1872f82886e5SAlexander Musman }
1873f82886e5SAlexander Musman 
1874d3f8dd2dSAlexey Bataev void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
1875d3f8dd2dSAlexey Bataev   VisitStmt(D);
1876d3f8dd2dSAlexey Bataev   Record.push_back(D->getNumClauses());
1877d3f8dd2dSAlexey Bataev   VisitOMPExecutableDirective(D);
1878d3f8dd2dSAlexey Bataev   Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
1879d3f8dd2dSAlexey Bataev }
1880d3f8dd2dSAlexey Bataev 
18811e0498a9SAlexey Bataev void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
18821e0498a9SAlexey Bataev   VisitStmt(D);
18831e0498a9SAlexey Bataev   VisitOMPExecutableDirective(D);
18841e0498a9SAlexey Bataev   Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
18851e0498a9SAlexey Bataev }
18861e0498a9SAlexey Bataev 
1887d1e40fbfSAlexey Bataev void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
1888d1e40fbfSAlexey Bataev   VisitStmt(D);
1889d1e40fbfSAlexey Bataev   Record.push_back(D->getNumClauses());
1890d1e40fbfSAlexey Bataev   VisitOMPExecutableDirective(D);
1891d1e40fbfSAlexey Bataev   Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
1892d1e40fbfSAlexey Bataev }
1893d1e40fbfSAlexey Bataev 
189480c2289aSAlexander Musman void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
189580c2289aSAlexander Musman   VisitStmt(D);
189680c2289aSAlexander Musman   VisitOMPExecutableDirective(D);
189780c2289aSAlexander Musman   Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
189880c2289aSAlexander Musman }
189980c2289aSAlexander Musman 
1900d9ed09f7SAlexander Musman void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
1901d9ed09f7SAlexander Musman   VisitStmt(D);
1902d9ed09f7SAlexander Musman   VisitOMPExecutableDirective(D);
1903d9ed09f7SAlexander Musman   Writer.AddDeclarationNameInfo(D->getDirectiveName(), Record);
1904d9ed09f7SAlexander Musman   Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
1905d9ed09f7SAlexander Musman }
1906d9ed09f7SAlexander Musman 
19074acb859fSAlexey Bataev void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
19083aaab669SAlexander Musman   VisitOMPLoopDirective(D);
19094acb859fSAlexey Bataev   Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
19104acb859fSAlexey Bataev }
19114acb859fSAlexey Bataev 
1912*e4e893bbSAlexander Musman void ASTStmtWriter::VisitOMPParallelForSimdDirective(
1913*e4e893bbSAlexander Musman     OMPParallelForSimdDirective *D) {
1914*e4e893bbSAlexander Musman   VisitOMPLoopDirective(D);
1915*e4e893bbSAlexander Musman   Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
1916*e4e893bbSAlexander Musman }
1917*e4e893bbSAlexander Musman 
191884d0b3efSAlexey Bataev void ASTStmtWriter::VisitOMPParallelSectionsDirective(
191984d0b3efSAlexey Bataev     OMPParallelSectionsDirective *D) {
192084d0b3efSAlexey Bataev   VisitStmt(D);
192184d0b3efSAlexey Bataev   Record.push_back(D->getNumClauses());
192284d0b3efSAlexey Bataev   VisitOMPExecutableDirective(D);
192384d0b3efSAlexey Bataev   Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
192484d0b3efSAlexey Bataev }
192584d0b3efSAlexey Bataev 
19269c2e8ee7SAlexey Bataev void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
19279c2e8ee7SAlexey Bataev   VisitStmt(D);
19289c2e8ee7SAlexey Bataev   Record.push_back(D->getNumClauses());
19299c2e8ee7SAlexey Bataev   VisitOMPExecutableDirective(D);
19309c2e8ee7SAlexey Bataev   Code = serialization::STMT_OMP_TASK_DIRECTIVE;
19319c2e8ee7SAlexey Bataev }
19329c2e8ee7SAlexey Bataev 
19330162e459SAlexey Bataev void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
19340162e459SAlexey Bataev   VisitStmt(D);
19350162e459SAlexey Bataev   Record.push_back(D->getNumClauses());
19360162e459SAlexey Bataev   VisitOMPExecutableDirective(D);
19370162e459SAlexey Bataev   Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
19380162e459SAlexey Bataev }
19390162e459SAlexey Bataev 
19400bd520b7SAlexey Bataev void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
19410bd520b7SAlexey Bataev   VisitStmt(D);
19420bd520b7SAlexey Bataev   Record.push_back(D->getNumClauses());
19430bd520b7SAlexey Bataev   VisitOMPExecutableDirective(D);
19440bd520b7SAlexey Bataev   Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
19450bd520b7SAlexey Bataev }
19460bd520b7SAlexey Bataev 
194768446b72SAlexey Bataev void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
194868446b72SAlexey Bataev   VisitStmt(D);
194968446b72SAlexey Bataev   VisitOMPExecutableDirective(D);
195068446b72SAlexey Bataev   Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
195168446b72SAlexey Bataev }
195268446b72SAlexey Bataev 
19534d1dfeabSAlexey Bataev void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
19544d1dfeabSAlexey Bataev   VisitStmt(D);
19554d1dfeabSAlexey Bataev   VisitOMPExecutableDirective(D);
19564d1dfeabSAlexey Bataev   Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
19574d1dfeabSAlexey Bataev }
19584d1dfeabSAlexey Bataev 
19592df347adSAlexey Bataev void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
19602df347adSAlexey Bataev   VisitStmt(D);
19612df347adSAlexey Bataev   VisitOMPExecutableDirective(D);
19622df347adSAlexey Bataev   Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
19632df347adSAlexey Bataev }
19642df347adSAlexey Bataev 
19656125da92SAlexey Bataev void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
19666125da92SAlexey Bataev   VisitStmt(D);
19676125da92SAlexey Bataev   Record.push_back(D->getNumClauses());
19686125da92SAlexey Bataev   VisitOMPExecutableDirective(D);
19696125da92SAlexey Bataev   Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
19706125da92SAlexey Bataev }
19716125da92SAlexey Bataev 
19729fb6e647SAlexey Bataev void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
19739fb6e647SAlexey Bataev   VisitStmt(D);
19749fb6e647SAlexey Bataev   VisitOMPExecutableDirective(D);
19759fb6e647SAlexey Bataev   Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
19769fb6e647SAlexey Bataev }
19779fb6e647SAlexey Bataev 
19785ec3eb11SAlexey Bataev //===----------------------------------------------------------------------===//
1979d6522cfcSSebastian Redl // ASTWriter Implementation
1980d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
1981d6522cfcSSebastian Redl 
1982d6522cfcSSebastian Redl unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
1983d6522cfcSSebastian Redl   assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
1984d6522cfcSSebastian Redl          "SwitchCase recorded twice");
1985d6522cfcSSebastian Redl   unsigned NextID = SwitchCaseIDs.size();
1986d6522cfcSSebastian Redl   SwitchCaseIDs[S] = NextID;
1987d6522cfcSSebastian Redl   return NextID;
1988d6522cfcSSebastian Redl }
1989d6522cfcSSebastian Redl 
1990d6522cfcSSebastian Redl unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
1991d6522cfcSSebastian Redl   assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
1992d6522cfcSSebastian Redl          "SwitchCase hasn't been seen yet");
1993d6522cfcSSebastian Redl   return SwitchCaseIDs[S];
1994d6522cfcSSebastian Redl }
1995d6522cfcSSebastian Redl 
1996d9f526fcSArgyrios Kyrtzidis void ASTWriter::ClearSwitchCaseIDs() {
1997d9f526fcSArgyrios Kyrtzidis   SwitchCaseIDs.clear();
1998d9f526fcSArgyrios Kyrtzidis }
1999d9f526fcSArgyrios Kyrtzidis 
2000d6522cfcSSebastian Redl /// \brief Write the given substatement or subexpression to the
2001d6522cfcSSebastian Redl /// bitstream.
20026a59897dSArgyrios Kyrtzidis void ASTWriter::WriteSubStmt(Stmt *S,
20036a59897dSArgyrios Kyrtzidis                              llvm::DenseMap<Stmt *, uint64_t> &SubStmtEntries,
20046a59897dSArgyrios Kyrtzidis                              llvm::DenseSet<Stmt *> &ParentStmts) {
2005d6522cfcSSebastian Redl   RecordData Record;
2006d6522cfcSSebastian Redl   ASTStmtWriter Writer(*this, Record);
2007d6522cfcSSebastian Redl   ++NumStatements;
2008d6522cfcSSebastian Redl 
2009d6522cfcSSebastian Redl   if (!S) {
2010539c5061SSebastian Redl     Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2011d6522cfcSSebastian Redl     return;
2012d6522cfcSSebastian Redl   }
2013d6522cfcSSebastian Redl 
20146a59897dSArgyrios Kyrtzidis   llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
20156a59897dSArgyrios Kyrtzidis   if (I != SubStmtEntries.end()) {
20166a59897dSArgyrios Kyrtzidis     Record.push_back(I->second);
20176a59897dSArgyrios Kyrtzidis     Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
20186a59897dSArgyrios Kyrtzidis     return;
20196a59897dSArgyrios Kyrtzidis   }
20206a59897dSArgyrios Kyrtzidis 
20216a59897dSArgyrios Kyrtzidis #ifndef NDEBUG
20226a59897dSArgyrios Kyrtzidis   assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
20236a59897dSArgyrios Kyrtzidis 
20246a59897dSArgyrios Kyrtzidis   struct ParentStmtInserterRAII {
20256a59897dSArgyrios Kyrtzidis     Stmt *S;
20266a59897dSArgyrios Kyrtzidis     llvm::DenseSet<Stmt *> &ParentStmts;
20276a59897dSArgyrios Kyrtzidis 
20286a59897dSArgyrios Kyrtzidis     ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
20296a59897dSArgyrios Kyrtzidis       : S(S), ParentStmts(ParentStmts) {
20306a59897dSArgyrios Kyrtzidis       ParentStmts.insert(S);
20316a59897dSArgyrios Kyrtzidis     }
20326a59897dSArgyrios Kyrtzidis     ~ParentStmtInserterRAII() {
20336a59897dSArgyrios Kyrtzidis       ParentStmts.erase(S);
20346a59897dSArgyrios Kyrtzidis     }
20356a59897dSArgyrios Kyrtzidis   };
20366a59897dSArgyrios Kyrtzidis 
20376a59897dSArgyrios Kyrtzidis   ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
20386a59897dSArgyrios Kyrtzidis #endif
20396a59897dSArgyrios Kyrtzidis 
2040028ed911SAlp Toker   // Redirect ASTWriter::AddStmt to collect sub-stmts.
20410e62c1ccSChris Lattner   SmallVector<Stmt *, 16> SubStmts;
2042d6522cfcSSebastian Redl   CollectedStmts = &SubStmts;
2043d6522cfcSSebastian Redl 
2044539c5061SSebastian Redl   Writer.Code = serialization::STMT_NULL_PTR;
204503412ba0SDouglas Gregor   Writer.AbbrevToUse = 0;
2046d6522cfcSSebastian Redl   Writer.Visit(S);
2047d6522cfcSSebastian Redl 
2048d6522cfcSSebastian Redl #ifndef NDEBUG
2049539c5061SSebastian Redl   if (Writer.Code == serialization::STMT_NULL_PTR) {
2050d6522cfcSSebastian Redl     SourceManager &SrcMgr
2051d6522cfcSSebastian Redl       = DeclIDs.begin()->first->getASTContext().getSourceManager();
2052d6522cfcSSebastian Redl     S->dump(SrcMgr);
2053028ed911SAlp Toker     llvm_unreachable("Unhandled sub-statement writing AST file");
2054d6522cfcSSebastian Redl   }
2055d6522cfcSSebastian Redl #endif
2056d6522cfcSSebastian Redl 
2057d6522cfcSSebastian Redl   // Revert ASTWriter::AddStmt.
2058d6522cfcSSebastian Redl   CollectedStmts = &StmtsToEmit;
2059d6522cfcSSebastian Redl 
2060028ed911SAlp Toker   // Write the sub-stmts in reverse order, last to first. When reading them back
2061d6522cfcSSebastian Redl   // we will read them in correct order by "pop"ing them from the Stmts stack.
2062028ed911SAlp Toker   // This simplifies reading and allows to store a variable number of sub-stmts
2063d6522cfcSSebastian Redl   // without knowing it in advance.
2064d6522cfcSSebastian Redl   while (!SubStmts.empty())
20656a59897dSArgyrios Kyrtzidis     WriteSubStmt(SubStmts.pop_back_val(), SubStmtEntries, ParentStmts);
2066d6522cfcSSebastian Redl 
206703412ba0SDouglas Gregor   Stream.EmitRecord(Writer.Code, Record, Writer.AbbrevToUse);
20686a59897dSArgyrios Kyrtzidis 
20696a59897dSArgyrios Kyrtzidis   SubStmtEntries[S] = Stream.GetCurrentBitNo();
2070d6522cfcSSebastian Redl }
2071d6522cfcSSebastian Redl 
2072d6522cfcSSebastian Redl /// \brief Flush all of the statements that have been added to the
2073d6522cfcSSebastian Redl /// queue via AddStmt().
2074d6522cfcSSebastian Redl void ASTWriter::FlushStmts() {
2075d6522cfcSSebastian Redl   RecordData Record;
2076d6522cfcSSebastian Redl 
2077a5acaa3cSDaniel Dunbar   // We expect to be the only consumer of the two temporary statement maps,
2078a5acaa3cSDaniel Dunbar   // assert that they are empty.
2079028ed911SAlp Toker   assert(SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2080a5acaa3cSDaniel Dunbar   assert(ParentStmts.empty() && "unexpected entries in parent stmt map");
20816a59897dSArgyrios Kyrtzidis 
2082d6522cfcSSebastian Redl   for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
20836a59897dSArgyrios Kyrtzidis     WriteSubStmt(StmtsToEmit[I], SubStmtEntries, ParentStmts);
2084d6522cfcSSebastian Redl 
2085d6522cfcSSebastian Redl     assert(N == StmtsToEmit.size() &&
208657540c5bSChris Lattner            "Substatement written via AddStmt rather than WriteSubStmt!");
2087d6522cfcSSebastian Redl 
2088d6522cfcSSebastian Redl     // Note that we are at the end of a full expression. Any
2089d6522cfcSSebastian Redl     // expression records that follow this one are part of a different
2090d6522cfcSSebastian Redl     // expression.
2091539c5061SSebastian Redl     Stream.EmitRecord(serialization::STMT_STOP, Record);
20926a59897dSArgyrios Kyrtzidis 
20936a59897dSArgyrios Kyrtzidis     SubStmtEntries.clear();
20946a59897dSArgyrios Kyrtzidis     ParentStmts.clear();
2095d6522cfcSSebastian Redl   }
2096d6522cfcSSebastian Redl 
2097d6522cfcSSebastian Redl   StmtsToEmit.clear();
2098d6522cfcSSebastian Redl }
2099