blob: 486cc14e6b0ca497e4f9290c710f16441958c009 [file] [log] [blame]
Sebastian Redld6522cf2010-08-18 23:56:31 +00001//===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
Chris Lattner1f551822009-04-27 06:20:01 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner1f551822009-04-27 06:20:01 +00006//
7//===----------------------------------------------------------------------===//
James Dennettddd36ff2013-08-09 23:08:25 +00008///
9/// \file
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010/// Implements serialization for Statements and Expressions.
James Dennettddd36ff2013-08-09 23:08:25 +000011///
Chris Lattner1f551822009-04-27 06:20:01 +000012//===----------------------------------------------------------------------===//
13
Sebastian Redl1914c6f2010-08-18 23:56:37 +000014#include "clang/Serialization/ASTWriter.h"
Benjamin Kramer4ab984e2012-07-04 20:19:54 +000015#include "clang/AST/ASTContext.h"
Douglas Gregor5d3507d2009-09-09 23:08:42 +000016#include "clang/AST/DeclCXX.h"
Chris Lattner1f551822009-04-27 06:20:01 +000017#include "clang/AST/DeclObjC.h"
Douglas Gregorcdbc5392011-01-15 01:15:58 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner1f551822009-04-27 06:20:01 +000019#include "clang/AST/StmtVisitor.h"
John McCallf413f5e2013-05-03 00:10:13 +000020#include "clang/Lex/Token.h"
Chris Lattner1f551822009-04-27 06:20:01 +000021#include "llvm/Bitcode/BitstreamWriter.h"
22using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// Statement/expression serialization
26//===----------------------------------------------------------------------===//
27
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +000028namespace clang {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000029
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000030 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
Sebastian Redl55c0ad52010-08-18 23:56:21 +000031 ASTWriter &Writer;
Richard Smith290d8012016-04-06 17:06:00 +000032 ASTRecordWriter Record;
Chris Lattner1f551822009-04-27 06:20:01 +000033
Sebastian Redl539c5062010-08-18 23:57:32 +000034 serialization::StmtCode Code;
Douglas Gregor03412ba2011-06-03 02:27:19 +000035 unsigned AbbrevToUse;
Chris Lattner1f551822009-04-27 06:20:01 +000036
Richard Smith290d8012016-04-06 17:06:00 +000037 public:
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000038 ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
Richard Smith290d8012016-04-06 17:06:00 +000039 : Writer(Writer), Record(Writer, Record),
40 Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
41
42 ASTStmtWriter(const ASTStmtWriter&) = delete;
43
Richard Smithf50422a2016-04-06 20:12:34 +000044 uint64_t Emit() {
Richard Smith290d8012016-04-06 17:06:00 +000045 assert(Code != serialization::STMT_NULL_PTR &&
46 "unhandled sub-statement writing AST file");
47 return Record.EmitStmt(Code, AbbrevToUse);
48 }
Abramo Bagnara7945c982012-01-27 09:46:47 +000049
James Y Knighte7d82282015-12-29 18:15:14 +000050 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo,
51 const TemplateArgumentLoc *Args);
Chris Lattner1f551822009-04-27 06:20:01 +000052
53 void VisitStmt(Stmt *S);
John McCallfa194042011-07-15 07:00:14 +000054#define STMT(Type, Base) \
55 void Visit##Type(Type *);
56#include "clang/AST/StmtNodes.inc"
Chris Lattner1f551822009-04-27 06:20:01 +000057 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +000058}
Chris Lattner1f551822009-04-27 06:20:01 +000059
James Y Knighte7d82282015-12-29 18:15:14 +000060void ASTStmtWriter::AddTemplateKWAndArgsInfo(
61 const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) {
Richard Smith290d8012016-04-06 17:06:00 +000062 Record.AddSourceLocation(ArgInfo.TemplateKWLoc);
63 Record.AddSourceLocation(ArgInfo.LAngleLoc);
64 Record.AddSourceLocation(ArgInfo.RAngleLoc);
James Y Knighte7d82282015-12-29 18:15:14 +000065 for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +000066 Record.AddTemplateArgumentLoc(Args[i]);
Argyrios Kyrtzidisb5288de2010-06-28 09:31:48 +000067}
68
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000069void ASTStmtWriter::VisitStmt(Stmt *S) {
Roman Lebedevb5700602019-03-20 16:32:36 +000070 Record.push_back(S->StmtBits.IsOMPStructuredBlock);
Chris Lattner1f551822009-04-27 06:20:01 +000071}
72
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000073void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000074 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +000075 Record.AddSourceLocation(S->getSemiLoc());
Bruno Ricci41d11c02018-10-27 18:43:27 +000076 Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro);
Sebastian Redl539c5062010-08-18 23:57:32 +000077 Code = serialization::STMT_NULL;
Chris Lattner1f551822009-04-27 06:20:01 +000078}
79
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000080void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000081 VisitStmt(S);
82 Record.push_back(S->size());
Aaron Ballmanc7e4e212014-03-17 14:19:37 +000083 for (auto *CS : S->body())
Richard Smith290d8012016-04-06 17:06:00 +000084 Record.AddStmt(CS);
85 Record.AddSourceLocation(S->getLBracLoc());
86 Record.AddSourceLocation(S->getRBracLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +000087 Code = serialization::STMT_COMPOUND;
Chris Lattner1f551822009-04-27 06:20:01 +000088}
89
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000090void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000091 VisitStmt(S);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +000092 Record.push_back(Writer.getSwitchCaseID(S));
Richard Smith290d8012016-04-06 17:06:00 +000093 Record.AddSourceLocation(S->getKeywordLoc());
94 Record.AddSourceLocation(S->getColonLoc());
Chris Lattner1f551822009-04-27 06:20:01 +000095}
96
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000097void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000098 VisitSwitchCase(S);
Bruno Ricci5b30571752018-10-28 12:30:53 +000099 Record.push_back(S->caseStmtIsGNURange());
Richard Smith290d8012016-04-06 17:06:00 +0000100 Record.AddStmt(S->getLHS());
Richard Smith290d8012016-04-06 17:06:00 +0000101 Record.AddStmt(S->getSubStmt());
Bruno Ricci5b30571752018-10-28 12:30:53 +0000102 if (S->caseStmtIsGNURange()) {
103 Record.AddStmt(S->getRHS());
104 Record.AddSourceLocation(S->getEllipsisLoc());
105 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000106 Code = serialization::STMT_CASE;
Chris Lattner1f551822009-04-27 06:20:01 +0000107}
108
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000109void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000110 VisitSwitchCase(S);
Richard Smith290d8012016-04-06 17:06:00 +0000111 Record.AddStmt(S->getSubStmt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000112 Code = serialization::STMT_DEFAULT;
Chris Lattner1f551822009-04-27 06:20:01 +0000113}
114
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000115void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000116 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000117 Record.AddDeclRef(S->getDecl());
118 Record.AddStmt(S->getSubStmt());
119 Record.AddSourceLocation(S->getIdentLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000120 Code = serialization::STMT_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000121}
122
Richard Smithc202b282012-04-14 00:33:13 +0000123void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
124 VisitStmt(S);
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000125 Record.push_back(S->getAttrs().size());
Richard Smith290d8012016-04-06 17:06:00 +0000126 Record.AddAttributes(S->getAttrs());
127 Record.AddStmt(S->getSubStmt());
128 Record.AddSourceLocation(S->getAttrLoc());
Richard Smithc202b282012-04-14 00:33:13 +0000129 Code = serialization::STMT_ATTRIBUTED;
130}
131
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000132void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000133 VisitStmt(S);
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000134
135 bool HasElse = S->getElse() != nullptr;
136 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
137 bool HasInit = S->getInit() != nullptr;
138
Richard Smithb130fe72016-06-23 19:16:49 +0000139 Record.push_back(S->isConstexpr());
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000140 Record.push_back(HasElse);
141 Record.push_back(HasVar);
142 Record.push_back(HasInit);
143
Richard Smith290d8012016-04-06 17:06:00 +0000144 Record.AddStmt(S->getCond());
145 Record.AddStmt(S->getThen());
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000146 if (HasElse)
147 Record.AddStmt(S->getElse());
148 if (HasVar)
149 Record.AddDeclRef(S->getConditionVariable());
150 if (HasInit)
151 Record.AddStmt(S->getInit());
152
Richard Smith290d8012016-04-06 17:06:00 +0000153 Record.AddSourceLocation(S->getIfLoc());
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000154 if (HasElse)
155 Record.AddSourceLocation(S->getElseLoc());
156
Sebastian Redl539c5062010-08-18 23:57:32 +0000157 Code = serialization::STMT_IF;
Chris Lattner1f551822009-04-27 06:20:01 +0000158}
159
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000160void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000161 VisitStmt(S);
Bruno Riccie2806f82018-10-29 16:12:37 +0000162
163 bool HasInit = S->getInit() != nullptr;
164 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
165 Record.push_back(HasInit);
166 Record.push_back(HasVar);
167 Record.push_back(S->isAllEnumCasesCovered());
168
Richard Smith290d8012016-04-06 17:06:00 +0000169 Record.AddStmt(S->getCond());
170 Record.AddStmt(S->getBody());
Bruno Riccie2806f82018-10-29 16:12:37 +0000171 if (HasInit)
172 Record.AddStmt(S->getInit());
173 if (HasVar)
174 Record.AddDeclRef(S->getConditionVariable());
175
Richard Smith290d8012016-04-06 17:06:00 +0000176 Record.AddSourceLocation(S->getSwitchLoc());
Bruno Riccie2806f82018-10-29 16:12:37 +0000177
Mike Stump11289f42009-09-09 15:08:12 +0000178 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
Chris Lattner1f551822009-04-27 06:20:01 +0000179 SC = SC->getNextSwitchCase())
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000180 Record.push_back(Writer.RecordSwitchCaseID(SC));
Sebastian Redl539c5062010-08-18 23:57:32 +0000181 Code = serialization::STMT_SWITCH;
Chris Lattner1f551822009-04-27 06:20:01 +0000182}
183
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000184void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000185 VisitStmt(S);
Bruno Riccibacf7512018-10-30 13:42:41 +0000186
187 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
188 Record.push_back(HasVar);
189
Richard Smith290d8012016-04-06 17:06:00 +0000190 Record.AddStmt(S->getCond());
191 Record.AddStmt(S->getBody());
Bruno Riccibacf7512018-10-30 13:42:41 +0000192 if (HasVar)
193 Record.AddDeclRef(S->getConditionVariable());
194
Richard Smith290d8012016-04-06 17:06:00 +0000195 Record.AddSourceLocation(S->getWhileLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000196 Code = serialization::STMT_WHILE;
Chris Lattner1f551822009-04-27 06:20:01 +0000197}
198
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000199void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000200 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000201 Record.AddStmt(S->getCond());
202 Record.AddStmt(S->getBody());
203 Record.AddSourceLocation(S->getDoLoc());
204 Record.AddSourceLocation(S->getWhileLoc());
205 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000206 Code = serialization::STMT_DO;
Chris Lattner1f551822009-04-27 06:20:01 +0000207}
208
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000209void ASTStmtWriter::VisitForStmt(ForStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000210 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000211 Record.AddStmt(S->getInit());
212 Record.AddStmt(S->getCond());
213 Record.AddDeclRef(S->getConditionVariable());
214 Record.AddStmt(S->getInc());
215 Record.AddStmt(S->getBody());
216 Record.AddSourceLocation(S->getForLoc());
217 Record.AddSourceLocation(S->getLParenLoc());
218 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000219 Code = serialization::STMT_FOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000220}
221
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000222void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000223 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000224 Record.AddDeclRef(S->getLabel());
225 Record.AddSourceLocation(S->getGotoLoc());
226 Record.AddSourceLocation(S->getLabelLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000227 Code = serialization::STMT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000228}
229
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000230void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000231 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000232 Record.AddSourceLocation(S->getGotoLoc());
233 Record.AddSourceLocation(S->getStarLoc());
234 Record.AddStmt(S->getTarget());
Sebastian Redl539c5062010-08-18 23:57:32 +0000235 Code = serialization::STMT_INDIRECT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000236}
237
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000238void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000239 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000240 Record.AddSourceLocation(S->getContinueLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000241 Code = serialization::STMT_CONTINUE;
Chris Lattner1f551822009-04-27 06:20:01 +0000242}
243
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000244void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000245 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000246 Record.AddSourceLocation(S->getBreakLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000247 Code = serialization::STMT_BREAK;
Chris Lattner1f551822009-04-27 06:20:01 +0000248}
249
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000250void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000251 VisitStmt(S);
Bruno Ricci023b1d12018-10-30 14:40:49 +0000252
253 bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr;
254 Record.push_back(HasNRVOCandidate);
255
Richard Smith290d8012016-04-06 17:06:00 +0000256 Record.AddStmt(S->getRetValue());
Bruno Ricci023b1d12018-10-30 14:40:49 +0000257 if (HasNRVOCandidate)
258 Record.AddDeclRef(S->getNRVOCandidate());
259
Richard Smith290d8012016-04-06 17:06:00 +0000260 Record.AddSourceLocation(S->getReturnLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000261 Code = serialization::STMT_RETURN;
Chris Lattner1f551822009-04-27 06:20:01 +0000262}
263
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000264void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000265 VisitStmt(S);
Stephen Kellya6e43582018-08-09 21:05:56 +0000266 Record.AddSourceLocation(S->getBeginLoc());
Richard Smith290d8012016-04-06 17:06:00 +0000267 Record.AddSourceLocation(S->getEndLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000268 DeclGroupRef DG = S->getDeclGroup();
269 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
Richard Smith290d8012016-04-06 17:06:00 +0000270 Record.AddDeclRef(*D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000271 Code = serialization::STMT_DECL;
Chris Lattner1f551822009-04-27 06:20:01 +0000272}
273
John McCallf413f5e2013-05-03 00:10:13 +0000274void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000275 VisitStmt(S);
276 Record.push_back(S->getNumOutputs());
277 Record.push_back(S->getNumInputs());
278 Record.push_back(S->getNumClobbers());
Richard Smith290d8012016-04-06 17:06:00 +0000279 Record.AddSourceLocation(S->getAsmLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000280 Record.push_back(S->isVolatile());
281 Record.push_back(S->isSimple());
John McCallf413f5e2013-05-03 00:10:13 +0000282}
283
284void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
285 VisitAsmStmt(S);
Jennifer Yub8fee672019-06-03 15:57:25 +0000286 Record.push_back(S->getNumLabels());
Richard Smith290d8012016-04-06 17:06:00 +0000287 Record.AddSourceLocation(S->getRParenLoc());
288 Record.AddStmt(S->getAsmString());
Chris Lattner1f551822009-04-27 06:20:01 +0000289
290 // Outputs
Fangrui Song6907ce22018-07-30 19:24:48 +0000291 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000292 Record.AddIdentifierRef(S->getOutputIdentifier(I));
293 Record.AddStmt(S->getOutputConstraintLiteral(I));
294 Record.AddStmt(S->getOutputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000295 }
296
297 // Inputs
298 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000299 Record.AddIdentifierRef(S->getInputIdentifier(I));
300 Record.AddStmt(S->getInputConstraintLiteral(I));
301 Record.AddStmt(S->getInputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000302 }
303
304 // Clobbers
305 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000306 Record.AddStmt(S->getClobberStringLiteral(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000307
Jennifer Yub8fee672019-06-03 15:57:25 +0000308 // Labels
309 for (auto *E : S->labels()) Record.AddStmt(E);
310
Chad Rosierde70e0e2012-08-25 00:11:56 +0000311 Code = serialization::STMT_GCCASM;
Chris Lattner1f551822009-04-27 06:20:01 +0000312}
313
Chad Rosier32503022012-06-11 20:47:18 +0000314void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
John McCallf413f5e2013-05-03 00:10:13 +0000315 VisitAsmStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000316 Record.AddSourceLocation(S->getLBraceLoc());
317 Record.AddSourceLocation(S->getEndLoc());
John McCallf413f5e2013-05-03 00:10:13 +0000318 Record.push_back(S->getNumAsmToks());
Richard Smith290d8012016-04-06 17:06:00 +0000319 Record.AddString(S->getAsmString());
John McCallf413f5e2013-05-03 00:10:13 +0000320
321 // Tokens
322 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000323 // FIXME: Move this to ASTRecordWriter?
324 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
John McCallf413f5e2013-05-03 00:10:13 +0000325 }
326
327 // Clobbers
328 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000329 Record.AddString(S->getClobber(I));
John McCallf413f5e2013-05-03 00:10:13 +0000330 }
331
332 // Outputs
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000333 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000334 Record.AddStmt(S->getOutputExpr(I));
335 Record.AddString(S->getOutputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000336 }
337
338 // Inputs
339 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000340 Record.AddStmt(S->getInputExpr(I));
341 Record.AddString(S->getInputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000342 }
Chad Rosiere30d4992012-08-24 23:51:02 +0000343
344 Code = serialization::STMT_MSASM;
Chad Rosier32503022012-06-11 20:47:18 +0000345}
346
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000347void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
348 VisitStmt(CoroStmt);
349 Record.push_back(CoroStmt->getParamMoves().size());
350 for (Stmt *S : CoroStmt->children())
351 Record.AddStmt(S);
352 Code = serialization::STMT_COROUTINE_BODY;
Richard Smith9f690bd2015-10-27 06:02:45 +0000353}
354
355void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000356 VisitStmt(S);
357 Record.AddSourceLocation(S->getKeywordLoc());
358 Record.AddStmt(S->getOperand());
359 Record.AddStmt(S->getPromiseCall());
360 Record.push_back(S->isImplicit());
361 Code = serialization::STMT_CORETURN;
Richard Smith9f690bd2015-10-27 06:02:45 +0000362}
363
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000364void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
365 VisitExpr(E);
366 Record.AddSourceLocation(E->getKeywordLoc());
367 for (Stmt *S : E->children())
368 Record.AddStmt(S);
369 Record.AddStmt(E->getOpaqueValue());
Richard Smith9f690bd2015-10-27 06:02:45 +0000370}
371
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000372void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
373 VisitCoroutineSuspendExpr(E);
374 Record.push_back(E->isImplicit());
375 Code = serialization::EXPR_COAWAIT;
Eric Fiselier20f25cb2017-03-06 23:38:15 +0000376}
377
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000378void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
379 VisitCoroutineSuspendExpr(E);
380 Code = serialization::EXPR_COYIELD;
381}
382
383void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
384 VisitExpr(E);
385 Record.AddSourceLocation(E->getKeywordLoc());
386 for (Stmt *S : E->children())
387 Record.AddStmt(S);
388 Code = serialization::EXPR_DEPENDENT_COAWAIT;
Richard Smith9f690bd2015-10-27 06:02:45 +0000389}
390
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000391void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
392 VisitStmt(S);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000393 // NumCaptures
394 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000395
Wei Pan17fbf6e2013-05-04 03:59:06 +0000396 // CapturedDecl and captured region kind
Richard Smith290d8012016-04-06 17:06:00 +0000397 Record.AddDeclRef(S->getCapturedDecl());
Wei Pan17fbf6e2013-05-04 03:59:06 +0000398 Record.push_back(S->getCapturedRegionKind());
399
Richard Smith290d8012016-04-06 17:06:00 +0000400 Record.AddDeclRef(S->getCapturedRecordDecl());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000401
402 // Capture inits
Aaron Ballmanba0238f2014-03-14 19:41:04 +0000403 for (auto *I : S->capture_inits())
Richard Smith290d8012016-04-06 17:06:00 +0000404 Record.AddStmt(I);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000405
406 // Body
Richard Smith290d8012016-04-06 17:06:00 +0000407 Record.AddStmt(S->getCapturedStmt());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000408
409 // Captures
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000410 for (const auto &I : S->captures()) {
Alexey Bataev330de032014-10-29 12:21:55 +0000411 if (I.capturesThis() || I.capturesVariableArrayType())
Richard Smith290d8012016-04-06 17:06:00 +0000412 Record.AddDeclRef(nullptr);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000413 else
Richard Smith290d8012016-04-06 17:06:00 +0000414 Record.AddDeclRef(I.getCapturedVar());
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000415 Record.push_back(I.getCaptureKind());
Richard Smith290d8012016-04-06 17:06:00 +0000416 Record.AddSourceLocation(I.getLocation());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000417 }
418
419 Code = serialization::STMT_CAPTURED;
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000420}
421
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000422void ASTStmtWriter::VisitExpr(Expr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000423 VisitStmt(E);
Richard Smith290d8012016-04-06 17:06:00 +0000424 Record.AddTypeRef(E->getType());
Chris Lattner1f551822009-04-27 06:20:01 +0000425 Record.push_back(E->isTypeDependent());
426 Record.push_back(E->isValueDependent());
Douglas Gregor678d76c2011-07-01 01:22:09 +0000427 Record.push_back(E->isInstantiationDependent());
Douglas Gregor506bd562010-12-13 22:49:22 +0000428 Record.push_back(E->containsUnexpandedParameterPack());
John McCall7decc9e2010-11-18 06:31:45 +0000429 Record.push_back(E->getValueKind());
430 Record.push_back(E->getObjectKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000431}
432
Bill Wendling7c44da22018-10-31 03:48:47 +0000433void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
434 VisitExpr(E);
Gauthier Harnisch83c7b612019-06-15 10:24:47 +0000435 Record.push_back(static_cast<uint64_t>(E->ConstantExprBits.ResultKind));
436 switch (E->ConstantExprBits.ResultKind) {
437 case ConstantExpr::RSK_Int64:
438 Record.push_back(E->Int64Result());
439 Record.push_back(E->ConstantExprBits.IsUnsigned |
440 E->ConstantExprBits.BitWidth << 1);
441 break;
442 case ConstantExpr::RSK_APValue:
443 Record.AddAPValue(E->APValueResult());
444 }
Bill Wendling7c44da22018-10-31 03:48:47 +0000445 Record.AddStmt(E->getSubExpr());
446 Code = serialization::EXPR_CONSTANT;
447}
448
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000449void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000450 VisitExpr(E);
Bruno Ricci17ff0262018-10-27 19:21:19 +0000451
452 bool HasFunctionName = E->getFunctionName() != nullptr;
453 Record.push_back(HasFunctionName);
454 Record.push_back(E->getIdentKind()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000455 Record.AddSourceLocation(E->getLocation());
Bruno Ricci17ff0262018-10-27 19:21:19 +0000456 if (HasFunctionName)
457 Record.AddStmt(E->getFunctionName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000458 Code = serialization::EXPR_PREDEFINED;
Chris Lattner1f551822009-04-27 06:20:01 +0000459}
460
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000461void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000462 VisitExpr(E);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000463
464 Record.push_back(E->hasQualifier());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000465 Record.push_back(E->getDecl() != E->getFoundDecl());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000466 Record.push_back(E->hasTemplateKWAndArgsInfo());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000467 Record.push_back(E->hadMultipleCandidates());
Alexey Bataev19acc3d2015-01-12 10:17:46 +0000468 Record.push_back(E->refersToEnclosingVariableOrCapture());
Richard Smith715f7a12019-06-11 17:50:32 +0000469 Record.push_back(E->isNonOdrUse());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000470
Abramo Bagnara7945c982012-01-27 09:46:47 +0000471 if (E->hasTemplateKWAndArgsInfo()) {
Douglas Gregor87866ce2011-02-04 12:01:24 +0000472 unsigned NumTemplateArgs = E->getNumTemplateArgs();
473 Record.push_back(NumTemplateArgs);
Douglas Gregor87866ce2011-02-04 12:01:24 +0000474 }
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000475
Douglas Gregor03412ba2011-06-03 02:27:19 +0000476 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
477
Abramo Bagnara7945c982012-01-27 09:46:47 +0000478 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000479 (E->getDecl() == E->getFoundDecl()) &&
Richard Smith715f7a12019-06-11 17:50:32 +0000480 nk == DeclarationName::Identifier &&
481 !E->refersToEnclosingVariableOrCapture() && !E->isNonOdrUse()) {
Douglas Gregor03412ba2011-06-03 02:27:19 +0000482 AbbrevToUse = Writer.getDeclRefExprAbbrev();
483 }
484
Anders Carlsson80756f62011-03-06 18:19:42 +0000485 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000486 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Anders Carlsson80756f62011-03-06 18:19:42 +0000487
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000488 if (E->getDecl() != E->getFoundDecl())
Richard Smith290d8012016-04-06 17:06:00 +0000489 Record.AddDeclRef(E->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000490
Abramo Bagnara7945c982012-01-27 09:46:47 +0000491 if (E->hasTemplateKWAndArgsInfo())
James Y Knighte7d82282015-12-29 18:15:14 +0000492 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
493 E->getTrailingObjects<TemplateArgumentLoc>());
Anders Carlsson80756f62011-03-06 18:19:42 +0000494
Richard Smith290d8012016-04-06 17:06:00 +0000495 Record.AddDeclRef(E->getDecl());
496 Record.AddSourceLocation(E->getLocation());
497 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000498 Code = serialization::EXPR_DECL_REF;
Chris Lattner1f551822009-04-27 06:20:01 +0000499}
500
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000501void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000502 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000503 Record.AddSourceLocation(E->getLocation());
504 Record.AddAPInt(E->getValue());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000505
506 if (E->getValue().getBitWidth() == 32) {
507 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
508 }
509
Sebastian Redl539c5062010-08-18 23:57:32 +0000510 Code = serialization::EXPR_INTEGER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000511}
512
Leonard Chandb01c3a2018-06-20 17:19:40 +0000513void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
514 VisitExpr(E);
515 Record.AddSourceLocation(E->getLocation());
516 Record.AddAPInt(E->getValue());
517 Code = serialization::EXPR_INTEGER_LITERAL;
518}
519
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000520void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000521 VisitExpr(E);
Tim Northover178723a2013-01-22 09:46:51 +0000522 Record.push_back(E->getRawSemantics());
Chris Lattner1f551822009-04-27 06:20:01 +0000523 Record.push_back(E->isExact());
Richard Smith290d8012016-04-06 17:06:00 +0000524 Record.AddAPFloat(E->getValue());
525 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000526 Code = serialization::EXPR_FLOATING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000527}
528
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000529void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000530 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000531 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000532 Code = serialization::EXPR_IMAGINARY_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000533}
534
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000535void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000536 VisitExpr(E);
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000537
538 // Store the various bits of data of StringLiteral.
Chris Lattner1f551822009-04-27 06:20:01 +0000539 Record.push_back(E->getNumConcatenated());
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000540 Record.push_back(E->getLength());
541 Record.push_back(E->getCharByteWidth());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000542 Record.push_back(E->getKind());
Anders Carlsson75245402011-04-14 00:40:03 +0000543 Record.push_back(E->isPascal());
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000544
545 // Store the trailing array of SourceLocation.
Chris Lattner1f551822009-04-27 06:20:01 +0000546 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000547 Record.AddSourceLocation(E->getStrTokenLoc(I));
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000548
549 // Store the trailing array of char holding the string data.
550 StringRef StrData = E->getBytes();
551 for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
552 Record.push_back(StrData[I]);
553
Sebastian Redl539c5062010-08-18 23:57:32 +0000554 Code = serialization::EXPR_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000555}
556
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000557void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000558 VisitExpr(E);
559 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +0000560 Record.AddSourceLocation(E->getLocation());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000561 Record.push_back(E->getKind());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000562
563 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
564
Sebastian Redl539c5062010-08-18 23:57:32 +0000565 Code = serialization::EXPR_CHARACTER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000566}
567
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000568void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000569 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000570 Record.AddSourceLocation(E->getLParen());
571 Record.AddSourceLocation(E->getRParen());
572 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000573 Code = serialization::EXPR_PAREN;
Chris Lattner1f551822009-04-27 06:20:01 +0000574}
575
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000576void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000577 VisitExpr(E);
Bruno Riccif49e1ca2018-11-20 16:20:40 +0000578 Record.push_back(E->getNumExprs());
579 for (auto *SubStmt : E->exprs())
580 Record.AddStmt(SubStmt);
581 Record.AddSourceLocation(E->getLParenLoc());
582 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000583 Code = serialization::EXPR_PAREN_LIST;
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000584}
585
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000586void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000587 VisitExpr(E);
Malcolm Parsonsfab36802018-04-16 08:31:08 +0000588 Record.AddStmt(E->getSubExpr());
589 Record.push_back(E->getOpcode()); // FIXME: stable encoding
590 Record.AddSourceLocation(E->getOperatorLoc());
591 Record.push_back(E->canOverflow());
592 Code = serialization::EXPR_UNARY_OPERATOR;
593}
594
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000595void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000596 VisitExpr(E);
597 Record.push_back(E->getNumComponents());
598 Record.push_back(E->getNumExpressions());
Richard Smith290d8012016-04-06 17:06:00 +0000599 Record.AddSourceLocation(E->getOperatorLoc());
600 Record.AddSourceLocation(E->getRParenLoc());
601 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Douglas Gregor882211c2010-04-28 22:16:22 +0000602 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +0000603 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +0000604 Record.push_back(ON.getKind()); // FIXME: Stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000605 Record.AddSourceLocation(ON.getSourceRange().getBegin());
606 Record.AddSourceLocation(ON.getSourceRange().getEnd());
Douglas Gregor882211c2010-04-28 22:16:22 +0000607 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +0000608 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +0000609 Record.push_back(ON.getArrayExprIndex());
610 break;
James Y Knight7281c352015-12-29 22:31:18 +0000611
612 case OffsetOfNode::Field:
Richard Smith290d8012016-04-06 17:06:00 +0000613 Record.AddDeclRef(ON.getField());
Douglas Gregor882211c2010-04-28 22:16:22 +0000614 break;
James Y Knight7281c352015-12-29 22:31:18 +0000615
616 case OffsetOfNode::Identifier:
Richard Smith290d8012016-04-06 17:06:00 +0000617 Record.AddIdentifierRef(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +0000618 break;
James Y Knight7281c352015-12-29 22:31:18 +0000619
620 case OffsetOfNode::Base:
Richard Smith290d8012016-04-06 17:06:00 +0000621 Record.AddCXXBaseSpecifier(*ON.getBase());
Douglas Gregord1702062010-04-29 00:18:15 +0000622 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000623 }
624 }
625 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000626 Record.AddStmt(E->getIndexExpr(I));
Sebastian Redl539c5062010-08-18 23:57:32 +0000627 Code = serialization::EXPR_OFFSETOF;
Douglas Gregor882211c2010-04-28 22:16:22 +0000628}
629
Peter Collingbournee190dee2011-03-11 19:24:49 +0000630void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000631 VisitExpr(E);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000632 Record.push_back(E->getKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000633 if (E->isArgumentType())
Richard Smith290d8012016-04-06 17:06:00 +0000634 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
Chris Lattner1f551822009-04-27 06:20:01 +0000635 else {
636 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +0000637 Record.AddStmt(E->getArgumentExpr());
Chris Lattner1f551822009-04-27 06:20:01 +0000638 }
Richard Smith290d8012016-04-06 17:06:00 +0000639 Record.AddSourceLocation(E->getOperatorLoc());
640 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000641 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
Chris Lattner1f551822009-04-27 06:20:01 +0000642}
643
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000644void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000645 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000646 Record.AddStmt(E->getLHS());
647 Record.AddStmt(E->getRHS());
648 Record.AddSourceLocation(E->getRBracketLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000649 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
Chris Lattner1f551822009-04-27 06:20:01 +0000650}
651
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000652void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
653 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000654 Record.AddStmt(E->getBase());
655 Record.AddStmt(E->getLowerBound());
656 Record.AddStmt(E->getLength());
657 Record.AddSourceLocation(E->getColonLoc());
658 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000659 Code = serialization::EXPR_OMP_ARRAY_SECTION;
660}
661
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000662void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000663 VisitExpr(E);
664 Record.push_back(E->getNumArgs());
Richard Smith290d8012016-04-06 17:06:00 +0000665 Record.AddSourceLocation(E->getRParenLoc());
666 Record.AddStmt(E->getCallee());
Chris Lattner1f551822009-04-27 06:20:01 +0000667 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
668 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +0000669 Record.AddStmt(*Arg);
Eric Fiselier5cdc2cd2018-12-12 21:50:55 +0000670 Record.push_back(static_cast<unsigned>(E->getADLCallKind()));
Sebastian Redl539c5062010-08-18 23:57:32 +0000671 Code = serialization::EXPR_CALL;
Chris Lattner1f551822009-04-27 06:20:01 +0000672}
673
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000674void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
Richard Smithdcf17de2019-06-06 23:24:15 +0000675 VisitExpr(E);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000676
Richard Smithdcf17de2019-06-06 23:24:15 +0000677 bool HasQualifier = E->hasQualifier();
678 bool HasFoundDecl =
679 E->hasQualifierOrFoundDecl() &&
680 (E->getFoundDecl().getDecl() != E->getMemberDecl() ||
681 E->getFoundDecl().getAccess() != E->getMemberDecl()->getAccess());
682 bool HasTemplateInfo = E->hasTemplateKWAndArgsInfo();
683 unsigned NumTemplateArgs = E->getNumTemplateArgs();
Richard Smithc32ef4b2019-06-04 21:29:28 +0000684
Richard Smithdcf17de2019-06-06 23:24:15 +0000685 // Write these first for easy access when deserializing, as they affect the
686 // size of the MemberExpr.
687 Record.push_back(HasQualifier);
688 Record.push_back(HasFoundDecl);
689 Record.push_back(HasTemplateInfo);
690 Record.push_back(NumTemplateArgs);
Richard Smithc32ef4b2019-06-04 21:29:28 +0000691
Benjamin Kramer9b2b8ad2019-06-05 11:46:57 +0000692 Record.AddStmt(E->getBase());
693 Record.AddDeclRef(E->getMemberDecl());
Benjamin Kramer9b2b8ad2019-06-05 11:46:57 +0000694 Record.AddDeclarationNameLoc(E->MemberDNLoc,
695 E->getMemberDecl()->getDeclName());
Richard Smithdcf17de2019-06-06 23:24:15 +0000696 Record.AddSourceLocation(E->getMemberLoc());
697 Record.push_back(E->isArrow());
698 Record.push_back(E->hadMultipleCandidates());
Richard Smith1bbad592019-06-11 17:50:36 +0000699 Record.push_back(E->isNonOdrUse());
Richard Smithdcf17de2019-06-06 23:24:15 +0000700 Record.AddSourceLocation(E->getOperatorLoc());
701
702 if (HasFoundDecl) {
703 DeclAccessPair FoundDecl = E->getFoundDecl();
704 Record.AddDeclRef(FoundDecl.getDecl());
705 Record.push_back(FoundDecl.getAccess());
706 }
707
708 if (HasQualifier)
709 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
710
711 if (HasTemplateInfo)
712 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
713 E->getTrailingObjects<TemplateArgumentLoc>());
714
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000715 Code = serialization::EXPR_MEMBER;
Chris Lattner1f551822009-04-27 06:20:01 +0000716}
717
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000718void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Naroffe87026a2009-07-24 17:54:45 +0000719 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000720 Record.AddStmt(E->getBase());
721 Record.AddSourceLocation(E->getIsaMemberLoc());
722 Record.AddSourceLocation(E->getOpLoc());
Steve Naroffe87026a2009-07-24 17:54:45 +0000723 Record.push_back(E->isArrow());
Sebastian Redl539c5062010-08-18 23:57:32 +0000724 Code = serialization::EXPR_OBJC_ISA;
Steve Naroffe87026a2009-07-24 17:54:45 +0000725}
726
John McCall31168b02011-06-15 23:02:42 +0000727void ASTStmtWriter::
728VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
729 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000730 Record.AddStmt(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +0000731 Record.push_back(E->shouldCopy());
732 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
733}
734
735void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
736 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000737 Record.AddSourceLocation(E->getLParenLoc());
738 Record.AddSourceLocation(E->getBridgeKeywordLoc());
John McCall31168b02011-06-15 23:02:42 +0000739 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
740 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
741}
742
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000743void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000744 VisitExpr(E);
John McCallcf142162010-08-07 06:22:56 +0000745 Record.push_back(E->path_size());
Richard Smith290d8012016-04-06 17:06:00 +0000746 Record.AddStmt(E->getSubExpr());
Anders Carlssona2615922009-07-31 00:48:10 +0000747 Record.push_back(E->getCastKind()); // FIXME: stable encoding
John McCallcf142162010-08-07 06:22:56 +0000748
749 for (CastExpr::path_iterator
750 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
Richard Smith290d8012016-04-06 17:06:00 +0000751 Record.AddCXXBaseSpecifier(**PI);
Chris Lattner1f551822009-04-27 06:20:01 +0000752}
753
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000754void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000755 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000756 Record.AddStmt(E->getLHS());
757 Record.AddStmt(E->getRHS());
Chris Lattner1f551822009-04-27 06:20:01 +0000758 Record.push_back(E->getOpcode()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000759 Record.AddSourceLocation(E->getOperatorLoc());
Adam Nemet484aa452017-03-27 19:17:25 +0000760 Record.push_back(E->getFPFeatures().getInt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000761 Code = serialization::EXPR_BINARY_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000762}
763
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000764void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000765 VisitBinaryOperator(E);
Richard Smith290d8012016-04-06 17:06:00 +0000766 Record.AddTypeRef(E->getComputationLHSType());
767 Record.AddTypeRef(E->getComputationResultType());
Sebastian Redl539c5062010-08-18 23:57:32 +0000768 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000769}
770
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000771void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000772 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000773 Record.AddStmt(E->getCond());
774 Record.AddStmt(E->getLHS());
775 Record.AddStmt(E->getRHS());
776 Record.AddSourceLocation(E->getQuestionLoc());
777 Record.AddSourceLocation(E->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000778 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000779}
780
John McCallc07a0c72011-02-17 10:25:35 +0000781void
782ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
783 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000784 Record.AddStmt(E->getOpaqueValue());
785 Record.AddStmt(E->getCommon());
786 Record.AddStmt(E->getCond());
787 Record.AddStmt(E->getTrueExpr());
788 Record.AddStmt(E->getFalseExpr());
789 Record.AddSourceLocation(E->getQuestionLoc());
790 Record.AddSourceLocation(E->getColonLoc());
John McCallc07a0c72011-02-17 10:25:35 +0000791 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
792}
793
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000794void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000795 VisitCastExpr(E);
Roman Lebedev12216f12018-07-27 07:27:14 +0000796 Record.push_back(E->isPartOfExplicitCast());
Richard Smitha27c26e2014-07-27 04:19:32 +0000797
798 if (E->path_size() == 0)
799 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
800
Sebastian Redl539c5062010-08-18 23:57:32 +0000801 Code = serialization::EXPR_IMPLICIT_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000802}
803
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000804void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000805 VisitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000806 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
Chris Lattner1f551822009-04-27 06:20:01 +0000807}
808
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000809void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000810 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000811 Record.AddSourceLocation(E->getLParenLoc());
812 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000813 Code = serialization::EXPR_CSTYLE_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000814}
815
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000816void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000817 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000818 Record.AddSourceLocation(E->getLParenLoc());
819 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
820 Record.AddStmt(E->getInitializer());
Chris Lattner1f551822009-04-27 06:20:01 +0000821 Record.push_back(E->isFileScope());
Sebastian Redl539c5062010-08-18 23:57:32 +0000822 Code = serialization::EXPR_COMPOUND_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000823}
824
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000825void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000826 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000827 Record.AddStmt(E->getBase());
828 Record.AddIdentifierRef(&E->getAccessor());
829 Record.AddSourceLocation(E->getAccessorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000830 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
Chris Lattner1f551822009-04-27 06:20:01 +0000831}
832
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000833void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000834 VisitExpr(E);
Abramo Bagnara8d16bd42012-11-08 18:41:43 +0000835 // NOTE: only add the (possibly null) syntactic form.
836 // No need to serialize the isSemanticForm flag and the semantic form.
Richard Smith290d8012016-04-06 17:06:00 +0000837 Record.AddStmt(E->getSyntacticForm());
838 Record.AddSourceLocation(E->getLBraceLoc());
839 Record.AddSourceLocation(E->getRBraceLoc());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000840 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
841 Record.push_back(isArrayFiller);
842 if (isArrayFiller)
Richard Smith290d8012016-04-06 17:06:00 +0000843 Record.AddStmt(E->getArrayFiller());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000844 else
Richard Smith290d8012016-04-06 17:06:00 +0000845 Record.AddDeclRef(E->getInitializedFieldInUnion());
Chris Lattner1f551822009-04-27 06:20:01 +0000846 Record.push_back(E->hadArrayRangeDesignator());
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000847 Record.push_back(E->getNumInits());
848 if (isArrayFiller) {
849 // ArrayFiller may have filled "holes" due to designated initializer.
850 // Replace them by 0 to indicate that the filler goes in that place.
851 Expr *filler = E->getArrayFiller();
852 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000853 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000854 } else {
855 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000856 Record.AddStmt(E->getInit(I));
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000857 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000858 Code = serialization::EXPR_INIT_LIST;
Chris Lattner1f551822009-04-27 06:20:01 +0000859}
860
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000861void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000862 VisitExpr(E);
863 Record.push_back(E->getNumSubExprs());
864 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000865 Record.AddStmt(E->getSubExpr(I));
866 Record.AddSourceLocation(E->getEqualOrColonLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000867 Record.push_back(E->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +0000868 for (const DesignatedInitExpr::Designator &D : E->designators()) {
869 if (D.isFieldDesignator()) {
870 if (FieldDecl *Field = D.getField()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000871 Record.push_back(serialization::DESIG_FIELD_DECL);
Richard Smith290d8012016-04-06 17:06:00 +0000872 Record.AddDeclRef(Field);
Chris Lattner1f551822009-04-27 06:20:01 +0000873 } else {
Sebastian Redl539c5062010-08-18 23:57:32 +0000874 Record.push_back(serialization::DESIG_FIELD_NAME);
David Majnemerf7e36092016-06-23 00:15:04 +0000875 Record.AddIdentifierRef(D.getFieldName());
Chris Lattner1f551822009-04-27 06:20:01 +0000876 }
David Majnemerf7e36092016-06-23 00:15:04 +0000877 Record.AddSourceLocation(D.getDotLoc());
878 Record.AddSourceLocation(D.getFieldLoc());
879 } else if (D.isArrayDesignator()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000880 Record.push_back(serialization::DESIG_ARRAY);
David Majnemerf7e36092016-06-23 00:15:04 +0000881 Record.push_back(D.getFirstExprIndex());
882 Record.AddSourceLocation(D.getLBracketLoc());
883 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000884 } else {
David Majnemerf7e36092016-06-23 00:15:04 +0000885 assert(D.isArrayRangeDesignator() && "Unknown designator");
Sebastian Redl539c5062010-08-18 23:57:32 +0000886 Record.push_back(serialization::DESIG_ARRAY_RANGE);
David Majnemerf7e36092016-06-23 00:15:04 +0000887 Record.push_back(D.getFirstExprIndex());
888 Record.AddSourceLocation(D.getLBracketLoc());
889 Record.AddSourceLocation(D.getEllipsisLoc());
890 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000891 }
892 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000893 Code = serialization::EXPR_DESIGNATED_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000894}
895
Yunzhong Gaocb779302015-06-10 00:27:52 +0000896void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
897 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000898 Record.AddStmt(E->getBase());
899 Record.AddStmt(E->getUpdater());
Yunzhong Gaocb779302015-06-10 00:27:52 +0000900 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
901}
902
903void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
904 VisitExpr(E);
905 Code = serialization::EXPR_NO_INIT;
906}
907
Richard Smith410306b2016-12-12 02:53:20 +0000908void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
909 VisitExpr(E);
910 Record.AddStmt(E->SubExprs[0]);
911 Record.AddStmt(E->SubExprs[1]);
912 Code = serialization::EXPR_ARRAY_INIT_LOOP;
913}
914
915void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
916 VisitExpr(E);
917 Code = serialization::EXPR_ARRAY_INIT_INDEX;
918}
919
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000920void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000921 VisitExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +0000922 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000923}
924
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000925void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000926 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000927 Record.AddStmt(E->getSubExpr());
928 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
929 Record.AddSourceLocation(E->getBuiltinLoc());
930 Record.AddSourceLocation(E->getRParenLoc());
Charles Davisc7d5c942015-09-17 20:55:33 +0000931 Record.push_back(E->isMicrosoftABI());
Sebastian Redl539c5062010-08-18 23:57:32 +0000932 Code = serialization::EXPR_VA_ARG;
Chris Lattner1f551822009-04-27 06:20:01 +0000933}
934
Eric Fiselier708afb52019-05-16 21:04:15 +0000935void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) {
936 VisitExpr(E);
937 Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext()));
938 Record.AddSourceLocation(E->getBeginLoc());
939 Record.AddSourceLocation(E->getEndLoc());
940 Record.push_back(E->getIdentKind());
941 Code = serialization::EXPR_SOURCE_LOC;
942}
943
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000944void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000945 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000946 Record.AddSourceLocation(E->getAmpAmpLoc());
947 Record.AddSourceLocation(E->getLabelLoc());
948 Record.AddDeclRef(E->getLabel());
Sebastian Redl539c5062010-08-18 23:57:32 +0000949 Code = serialization::EXPR_ADDR_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000950}
951
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000952void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000953 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000954 Record.AddStmt(E->getSubStmt());
955 Record.AddSourceLocation(E->getLParenLoc());
956 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000957 Code = serialization::EXPR_STMT;
Chris Lattner1f551822009-04-27 06:20:01 +0000958}
959
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000960void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000961 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000962 Record.AddStmt(E->getCond());
963 Record.AddStmt(E->getLHS());
964 Record.AddStmt(E->getRHS());
965 Record.AddSourceLocation(E->getBuiltinLoc());
966 Record.AddSourceLocation(E->getRParenLoc());
Eli Friedman75807f22013-07-20 00:40:58 +0000967 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
Sebastian Redl539c5062010-08-18 23:57:32 +0000968 Code = serialization::EXPR_CHOOSE;
Chris Lattner1f551822009-04-27 06:20:01 +0000969}
970
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000971void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000972 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000973 Record.AddSourceLocation(E->getTokenLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000974 Code = serialization::EXPR_GNU_NULL;
Chris Lattner1f551822009-04-27 06:20:01 +0000975}
976
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000977void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000978 VisitExpr(E);
979 Record.push_back(E->getNumSubExprs());
980 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000981 Record.AddStmt(E->getExpr(I));
982 Record.AddSourceLocation(E->getBuiltinLoc());
983 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000984 Code = serialization::EXPR_SHUFFLE_VECTOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000985}
986
Hal Finkelc4d7c822013-09-18 03:29:45 +0000987void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
988 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000989 Record.AddSourceLocation(E->getBuiltinLoc());
990 Record.AddSourceLocation(E->getRParenLoc());
991 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
992 Record.AddStmt(E->getSrcExpr());
Hal Finkelc4d7c822013-09-18 03:29:45 +0000993 Code = serialization::EXPR_CONVERT_VECTOR;
994}
995
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000996void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000997 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000998 Record.AddDeclRef(E->getBlockDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000999 Code = serialization::EXPR_BLOCK;
Chris Lattner1f551822009-04-27 06:20:01 +00001000}
1001
Peter Collingbourne91147592011-04-15 00:35:48 +00001002void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
1003 VisitExpr(E);
Bruno Riccidb076832019-01-26 14:15:10 +00001004
Peter Collingbourne91147592011-04-15 00:35:48 +00001005 Record.push_back(E->getNumAssocs());
Bruno Ricci94498c72019-01-26 13:58:15 +00001006 Record.push_back(E->ResultIndex);
Richard Smith290d8012016-04-06 17:06:00 +00001007 Record.AddSourceLocation(E->getGenericLoc());
1008 Record.AddSourceLocation(E->getDefaultLoc());
1009 Record.AddSourceLocation(E->getRParenLoc());
Bruno Riccidb076832019-01-26 14:15:10 +00001010
1011 Stmt **Stmts = E->getTrailingObjects<Stmt *>();
1012 // Add 1 to account for the controlling expression which is the first
1013 // expression in the trailing array of Stmt *. This is not needed for
1014 // the trailing array of TypeSourceInfo *.
1015 for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I)
1016 Record.AddStmt(Stmts[I]);
1017
1018 TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
1019 for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I)
1020 Record.AddTypeSourceInfo(TSIs[I]);
1021
Peter Collingbourne91147592011-04-15 00:35:48 +00001022 Code = serialization::EXPR_GENERIC_SELECTION;
1023}
1024
John McCallfe96e0b2011-11-06 09:01:30 +00001025void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
1026 VisitExpr(E);
1027 Record.push_back(E->getNumSemanticExprs());
1028
1029 // Push the result index. Currently, this needs to exactly match
1030 // the encoding used internally for ResultIndex.
1031 unsigned result = E->getResultExprIndex();
1032 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
1033 Record.push_back(result);
1034
Richard Smith290d8012016-04-06 17:06:00 +00001035 Record.AddStmt(E->getSyntacticForm());
John McCallfe96e0b2011-11-06 09:01:30 +00001036 for (PseudoObjectExpr::semantics_iterator
1037 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
Richard Smith290d8012016-04-06 17:06:00 +00001038 Record.AddStmt(*i);
John McCallfe96e0b2011-11-06 09:01:30 +00001039 }
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +00001040 Code = serialization::EXPR_PSEUDO_OBJECT;
John McCallfe96e0b2011-11-06 09:01:30 +00001041}
1042
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001043void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
1044 VisitExpr(E);
1045 Record.push_back(E->getOp());
Richard Smithaa22a8c2012-04-10 22:49:28 +00001046 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001047 Record.AddStmt(E->getSubExprs()[I]);
1048 Record.AddSourceLocation(E->getBuiltinLoc());
1049 Record.AddSourceLocation(E->getRParenLoc());
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +00001050 Code = serialization::EXPR_ATOMIC;
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001051}
1052
Chris Lattner1f551822009-04-27 06:20:01 +00001053//===----------------------------------------------------------------------===//
1054// Objective-C Expressions and Statements.
1055//===----------------------------------------------------------------------===//
1056
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001057void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001058 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001059 Record.AddStmt(E->getString());
1060 Record.AddSourceLocation(E->getAtLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001061 Code = serialization::EXPR_OBJC_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +00001062}
1063
Patrick Beard0caa3942012-04-19 00:25:12 +00001064void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001065 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001066 Record.AddStmt(E->getSubExpr());
1067 Record.AddDeclRef(E->getBoxingMethod());
1068 Record.AddSourceRange(E->getSourceRange());
Patrick Beard0caa3942012-04-19 00:25:12 +00001069 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
Ted Kremeneke65b0862012-03-06 20:05:56 +00001070}
1071
1072void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1073 VisitExpr(E);
1074 Record.push_back(E->getNumElements());
1075 for (unsigned i = 0; i < E->getNumElements(); i++)
Richard Smith290d8012016-04-06 17:06:00 +00001076 Record.AddStmt(E->getElement(i));
1077 Record.AddDeclRef(E->getArrayWithObjectsMethod());
1078 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001079 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1080}
1081
1082void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1083 VisitExpr(E);
1084 Record.push_back(E->getNumElements());
1085 Record.push_back(E->HasPackExpansions);
1086 for (unsigned i = 0; i < E->getNumElements(); i++) {
1087 ObjCDictionaryElement Element = E->getKeyValueElement(i);
Richard Smith290d8012016-04-06 17:06:00 +00001088 Record.AddStmt(Element.Key);
1089 Record.AddStmt(Element.Value);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001090 if (E->HasPackExpansions) {
Richard Smith290d8012016-04-06 17:06:00 +00001091 Record.AddSourceLocation(Element.EllipsisLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001092 unsigned NumExpansions = 0;
1093 if (Element.NumExpansions)
1094 NumExpansions = *Element.NumExpansions + 1;
1095 Record.push_back(NumExpansions);
1096 }
1097 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001098
Richard Smith290d8012016-04-06 17:06:00 +00001099 Record.AddDeclRef(E->getDictWithObjectsMethod());
1100 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001101 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1102}
1103
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001104void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001105 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001106 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1107 Record.AddSourceLocation(E->getAtLoc());
1108 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001109 Code = serialization::EXPR_OBJC_ENCODE;
Chris Lattner1f551822009-04-27 06:20:01 +00001110}
1111
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001112void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001113 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001114 Record.AddSelectorRef(E->getSelector());
1115 Record.AddSourceLocation(E->getAtLoc());
1116 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001117 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001118}
1119
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001120void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001121 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001122 Record.AddDeclRef(E->getProtocol());
1123 Record.AddSourceLocation(E->getAtLoc());
1124 Record.AddSourceLocation(E->ProtoLoc);
1125 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001126 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001127}
1128
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001129void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001130 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001131 Record.AddDeclRef(E->getDecl());
1132 Record.AddSourceLocation(E->getLocation());
1133 Record.AddSourceLocation(E->getOpLoc());
1134 Record.AddStmt(E->getBase());
Chris Lattner1f551822009-04-27 06:20:01 +00001135 Record.push_back(E->isArrow());
1136 Record.push_back(E->isFreeIvar());
Sebastian Redl539c5062010-08-18 23:57:32 +00001137 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001138}
1139
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001140void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001141 VisitExpr(E);
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001142 Record.push_back(E->SetterAndMethodRefFlags.getInt());
John McCallb7bd14f2010-12-02 01:19:52 +00001143 Record.push_back(E->isImplicitProperty());
1144 if (E->isImplicitProperty()) {
Richard Smith290d8012016-04-06 17:06:00 +00001145 Record.AddDeclRef(E->getImplicitPropertyGetter());
1146 Record.AddDeclRef(E->getImplicitPropertySetter());
John McCallb7bd14f2010-12-02 01:19:52 +00001147 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001148 Record.AddDeclRef(E->getExplicitProperty());
John McCallb7bd14f2010-12-02 01:19:52 +00001149 }
Richard Smith290d8012016-04-06 17:06:00 +00001150 Record.AddSourceLocation(E->getLocation());
1151 Record.AddSourceLocation(E->getReceiverLocation());
John McCallb7bd14f2010-12-02 01:19:52 +00001152 if (E->isObjectReceiver()) {
1153 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +00001154 Record.AddStmt(E->getBase());
John McCallb7bd14f2010-12-02 01:19:52 +00001155 } else if (E->isSuperReceiver()) {
1156 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001157 Record.AddTypeRef(E->getSuperReceiverType());
John McCallb7bd14f2010-12-02 01:19:52 +00001158 } else {
1159 Record.push_back(2);
Richard Smith290d8012016-04-06 17:06:00 +00001160 Record.AddDeclRef(E->getClassReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001161 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001162
Sebastian Redl539c5062010-08-18 23:57:32 +00001163 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001164}
1165
Ted Kremeneke65b0862012-03-06 20:05:56 +00001166void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1167 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001168 Record.AddSourceLocation(E->getRBracket());
1169 Record.AddStmt(E->getBaseExpr());
1170 Record.AddStmt(E->getKeyExpr());
1171 Record.AddDeclRef(E->getAtIndexMethodDecl());
1172 Record.AddDeclRef(E->setAtIndexMethodDecl());
Fangrui Song6907ce22018-07-30 19:24:48 +00001173
Ted Kremeneke65b0862012-03-06 20:05:56 +00001174 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1175}
1176
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001177void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001178 VisitExpr(E);
1179 Record.push_back(E->getNumArgs());
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001180 Record.push_back(E->getNumStoredSelLocs());
1181 Record.push_back(E->SelLocsKind);
John McCall31168b02011-06-15 23:02:42 +00001182 Record.push_back(E->isDelegateInitCall());
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +00001183 Record.push_back(E->IsImplicit);
Douglas Gregor9a129192010-04-21 00:45:42 +00001184 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1185 switch (E->getReceiverKind()) {
1186 case ObjCMessageExpr::Instance:
Richard Smith290d8012016-04-06 17:06:00 +00001187 Record.AddStmt(E->getInstanceReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001188 break;
1189
1190 case ObjCMessageExpr::Class:
Richard Smith290d8012016-04-06 17:06:00 +00001191 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
Douglas Gregor9a129192010-04-21 00:45:42 +00001192 break;
1193
1194 case ObjCMessageExpr::SuperClass:
1195 case ObjCMessageExpr::SuperInstance:
Richard Smith290d8012016-04-06 17:06:00 +00001196 Record.AddTypeRef(E->getSuperType());
1197 Record.AddSourceLocation(E->getSuperLoc());
Douglas Gregor9a129192010-04-21 00:45:42 +00001198 break;
1199 }
1200
1201 if (E->getMethodDecl()) {
1202 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001203 Record.AddDeclRef(E->getMethodDecl());
Douglas Gregor9a129192010-04-21 00:45:42 +00001204 } else {
1205 Record.push_back(0);
Fangrui Song6907ce22018-07-30 19:24:48 +00001206 Record.AddSelectorRef(E->getSelector());
Douglas Gregor9a129192010-04-21 00:45:42 +00001207 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001208
Richard Smith290d8012016-04-06 17:06:00 +00001209 Record.AddSourceLocation(E->getLeftLoc());
1210 Record.AddSourceLocation(E->getRightLoc());
Chris Lattner1f551822009-04-27 06:20:01 +00001211
1212 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1213 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +00001214 Record.AddStmt(*Arg);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001215
1216 SourceLocation *Locs = E->getStoredSelLocs();
1217 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001218 Record.AddSourceLocation(Locs[i]);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001219
Sebastian Redl539c5062010-08-18 23:57:32 +00001220 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001221}
1222
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001223void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00001224 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001225 Record.AddStmt(S->getElement());
1226 Record.AddStmt(S->getCollection());
1227 Record.AddStmt(S->getBody());
1228 Record.AddSourceLocation(S->getForLoc());
1229 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001230 Code = serialization::STMT_OBJC_FOR_COLLECTION;
Chris Lattner1f551822009-04-27 06:20:01 +00001231}
1232
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001233void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001234 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001235 Record.AddStmt(S->getCatchBody());
1236 Record.AddDeclRef(S->getCatchParamDecl());
1237 Record.AddSourceLocation(S->getAtCatchLoc());
1238 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001239 Code = serialization::STMT_OBJC_CATCH;
Chris Lattner1f551822009-04-27 06:20:01 +00001240}
1241
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001242void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001243 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001244 Record.AddStmt(S->getFinallyBody());
1245 Record.AddSourceLocation(S->getAtFinallyLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001246 Code = serialization::STMT_OBJC_FINALLY;
Chris Lattner1f551822009-04-27 06:20:01 +00001247}
1248
John McCall31168b02011-06-15 23:02:42 +00001249void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001250 VisitStmt(S); // FIXME: no test coverage.
Richard Smith290d8012016-04-06 17:06:00 +00001251 Record.AddStmt(S->getSubStmt());
1252 Record.AddSourceLocation(S->getAtLoc());
John McCall31168b02011-06-15 23:02:42 +00001253 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1254}
1255
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001256void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001257 VisitStmt(S);
Douglas Gregor96c79492010-04-23 22:50:49 +00001258 Record.push_back(S->getNumCatchStmts());
Craig Toppera13603a2014-05-22 05:54:18 +00001259 Record.push_back(S->getFinallyStmt() != nullptr);
Richard Smith290d8012016-04-06 17:06:00 +00001260 Record.AddStmt(S->getTryBody());
Douglas Gregor96c79492010-04-23 22:50:49 +00001261 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001262 Record.AddStmt(S->getCatchStmt(I));
Douglas Gregor96c79492010-04-23 22:50:49 +00001263 if (S->getFinallyStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001264 Record.AddStmt(S->getFinallyStmt());
1265 Record.AddSourceLocation(S->getAtTryLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001266 Code = serialization::STMT_OBJC_AT_TRY;
Chris Lattner1f551822009-04-27 06:20:01 +00001267}
1268
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001269void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001270 VisitStmt(S); // FIXME: no test coverage.
Richard Smith290d8012016-04-06 17:06:00 +00001271 Record.AddStmt(S->getSynchExpr());
1272 Record.AddStmt(S->getSynchBody());
1273 Record.AddSourceLocation(S->getAtSynchronizedLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001274 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
Chris Lattner1f551822009-04-27 06:20:01 +00001275}
1276
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001277void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001278 VisitStmt(S); // FIXME: no test coverage.
Richard Smith290d8012016-04-06 17:06:00 +00001279 Record.AddStmt(S->getThrowExpr());
1280 Record.AddSourceLocation(S->getThrowLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001281 Code = serialization::STMT_OBJC_AT_THROW;
Chris Lattner1f551822009-04-27 06:20:01 +00001282}
1283
Ted Kremeneke65b0862012-03-06 20:05:56 +00001284void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1285 VisitExpr(E);
1286 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001287 Record.AddSourceLocation(E->getLocation());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001288 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1289}
1290
Erik Pilkington29099de2016-07-16 00:35:23 +00001291void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1292 VisitExpr(E);
1293 Record.AddSourceRange(E->getSourceRange());
1294 Record.AddVersionTuple(E->getVersion());
1295 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1296}
1297
Chris Lattner1f551822009-04-27 06:20:01 +00001298//===----------------------------------------------------------------------===//
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001299// C++ Expressions and Statements.
1300//===----------------------------------------------------------------------===//
1301
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001302void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001303 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001304 Record.AddSourceLocation(S->getCatchLoc());
1305 Record.AddDeclRef(S->getExceptionDecl());
1306 Record.AddStmt(S->getHandlerBlock());
Sebastian Redl539c5062010-08-18 23:57:32 +00001307 Code = serialization::STMT_CXX_CATCH;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001308}
1309
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001310void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001311 VisitStmt(S);
1312 Record.push_back(S->getNumHandlers());
Richard Smith290d8012016-04-06 17:06:00 +00001313 Record.AddSourceLocation(S->getTryLoc());
1314 Record.AddStmt(S->getTryBlock());
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001315 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001316 Record.AddStmt(S->getHandler(i));
Sebastian Redl539c5062010-08-18 23:57:32 +00001317 Code = serialization::STMT_CXX_TRY;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001318}
1319
Richard Smith02e85f32011-04-14 22:09:26 +00001320void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1321 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001322 Record.AddSourceLocation(S->getForLoc());
1323 Record.AddSourceLocation(S->getCoawaitLoc());
1324 Record.AddSourceLocation(S->getColonLoc());
1325 Record.AddSourceLocation(S->getRParenLoc());
Richard Smith8baa5002018-09-28 18:44:09 +00001326 Record.AddStmt(S->getInit());
Richard Smith290d8012016-04-06 17:06:00 +00001327 Record.AddStmt(S->getRangeStmt());
1328 Record.AddStmt(S->getBeginStmt());
1329 Record.AddStmt(S->getEndStmt());
1330 Record.AddStmt(S->getCond());
1331 Record.AddStmt(S->getInc());
1332 Record.AddStmt(S->getLoopVarStmt());
1333 Record.AddStmt(S->getBody());
Richard Smith02e85f32011-04-14 22:09:26 +00001334 Code = serialization::STMT_CXX_FOR_RANGE;
1335}
1336
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001337void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1338 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001339 Record.AddSourceLocation(S->getKeywordLoc());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001340 Record.push_back(S->isIfExists());
Richard Smith290d8012016-04-06 17:06:00 +00001341 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1342 Record.AddDeclarationNameInfo(S->getNameInfo());
1343 Record.AddStmt(S->getSubStmt());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001344 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1345}
1346
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001347void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001348 VisitCallExpr(E);
1349 Record.push_back(E->getOperator());
Adam Nemet484aa452017-03-27 19:17:25 +00001350 Record.push_back(E->getFPFeatures().getInt());
Bruno Riccifeb19232018-12-21 16:51:57 +00001351 Record.AddSourceRange(E->Range);
Sebastian Redl539c5062010-08-18 23:57:32 +00001352 Code = serialization::EXPR_CXX_OPERATOR_CALL;
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001353}
1354
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001355void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001356 VisitCallExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001357 Code = serialization::EXPR_CXX_MEMBER_CALL;
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001358}
1359
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001360void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001361 VisitExpr(E);
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001362
Argyrios Kyrtzidis30d98f32010-06-24 08:57:09 +00001363 Record.push_back(E->getNumArgs());
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001364 Record.push_back(E->isElidable());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00001365 Record.push_back(E->hadMultipleCandidates());
Richard Smithd59b8322012-12-19 01:39:02 +00001366 Record.push_back(E->isListInitialization());
Richard Smithf8adcdc2014-07-17 05:12:35 +00001367 Record.push_back(E->isStdInitListInitialization());
Douglas Gregor4f4b1862009-12-16 18:50:27 +00001368 Record.push_back(E->requiresZeroInitialization());
Douglas Gregor222cf0e2010-05-15 00:13:29 +00001369 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001370 Record.AddSourceLocation(E->getLocation());
1371 Record.AddDeclRef(E->getConstructor());
Richard Smith290d8012016-04-06 17:06:00 +00001372 Record.AddSourceRange(E->getParenOrBraceRange());
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001373
1374 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1375 Record.AddStmt(E->getArg(I));
1376
Sebastian Redl539c5062010-08-18 23:57:32 +00001377 Code = serialization::EXPR_CXX_CONSTRUCT;
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001378}
1379
Richard Smith5179eb72016-06-28 19:03:57 +00001380void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1381 VisitExpr(E);
1382 Record.AddDeclRef(E->getConstructor());
1383 Record.AddSourceLocation(E->getLocation());
1384 Record.push_back(E->constructsVBase());
1385 Record.push_back(E->inheritedFromVBase());
1386 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1387}
1388
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001389void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001390 VisitCXXConstructExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001391 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001392 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001393}
1394
Douglas Gregore31e6062012-02-07 10:09:13 +00001395void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1396 VisitExpr(E);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001397 Record.push_back(E->NumCaptures);
Richard Smith290d8012016-04-06 17:06:00 +00001398 Record.AddSourceRange(E->IntroducerRange);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001399 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +00001400 Record.AddSourceLocation(E->CaptureDefaultLoc);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001401 Record.push_back(E->ExplicitParams);
1402 Record.push_back(E->ExplicitResultType);
Richard Smith290d8012016-04-06 17:06:00 +00001403 Record.AddSourceLocation(E->ClosingBrace);
Fangrui Song6907ce22018-07-30 19:24:48 +00001404
Douglas Gregor99ae8062012-02-14 17:54:36 +00001405 // Add capture initializers.
1406 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1407 CEnd = E->capture_init_end();
1408 C != CEnd; ++C) {
Richard Smith290d8012016-04-06 17:06:00 +00001409 Record.AddStmt(*C);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001410 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001411
Douglas Gregor99ae8062012-02-14 17:54:36 +00001412 Code = serialization::EXPR_LAMBDA;
Douglas Gregore31e6062012-02-07 10:09:13 +00001413}
1414
Richard Smithcc1b96d2013-06-12 22:31:48 +00001415void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1416 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001417 Record.AddStmt(E->getSubExpr());
Richard Smithcc1b96d2013-06-12 22:31:48 +00001418 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1419}
1420
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001421void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001422 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001423 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1424 Record.AddSourceRange(E->getAngleBrackets());
Sam Weinigd01101e2010-01-16 21:21:01 +00001425}
1426
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001427void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001428 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001429 Code = serialization::EXPR_CXX_STATIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001430}
1431
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001432void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001433 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001434 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001435}
1436
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001437void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001438 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001439 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001440}
1441
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001442void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001443 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001444 Code = serialization::EXPR_CXX_CONST_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001445}
1446
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001447void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001448 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001449 Record.AddSourceLocation(E->getLParenLoc());
1450 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001451 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001452}
1453
Erik Pilkingtoneee944e2019-07-02 18:28:13 +00001454void ASTStmtWriter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
1455 VisitExplicitCastExpr(E);
1456 Record.AddSourceLocation(E->getBeginLoc());
1457 Record.AddSourceLocation(E->getEndLoc());
1458}
1459
Richard Smithc67fdd42012-03-07 08:35:16 +00001460void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1461 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001462 Record.AddSourceLocation(E->UDSuffixLoc);
Richard Smithc67fdd42012-03-07 08:35:16 +00001463 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1464}
1465
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001466void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001467 VisitExpr(E);
1468 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001469 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001470 Code = serialization::EXPR_CXX_BOOL_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001471}
1472
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001473void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001474 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001475 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001476 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001477}
1478
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001479void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001480 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001481 Record.AddSourceRange(E->getSourceRange());
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001482 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001483 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001484 Code = serialization::EXPR_CXX_TYPEID_TYPE;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001485 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001486 Record.AddStmt(E->getExprOperand());
Sebastian Redl539c5062010-08-18 23:57:32 +00001487 Code = serialization::EXPR_CXX_TYPEID_EXPR;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001488 }
1489}
1490
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001491void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner98267332010-05-09 06:15:05 +00001492 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001493 Record.AddSourceLocation(E->getLocation());
Chris Lattner98267332010-05-09 06:15:05 +00001494 Record.push_back(E->isImplicit());
Sebastian Redl539c5062010-08-18 23:57:32 +00001495 Code = serialization::EXPR_CXX_THIS;
Chris Lattner98267332010-05-09 06:15:05 +00001496}
1497
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001498void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001499 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001500 Record.AddSourceLocation(E->getThrowLoc());
1501 Record.AddStmt(E->getSubExpr());
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001502 Record.push_back(E->isThrownVariableInScope());
Sebastian Redl539c5062010-08-18 23:57:32 +00001503 Code = serialization::EXPR_CXX_THROW;
Chris Lattner98267332010-05-09 06:15:05 +00001504}
1505
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001506void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001507 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001508 Record.AddDeclRef(E->getParam());
Eric Fiselier708afb52019-05-16 21:04:15 +00001509 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
Richard Smith290d8012016-04-06 17:06:00 +00001510 Record.AddSourceLocation(E->getUsedLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001511 Code = serialization::EXPR_CXX_DEFAULT_ARG;
Chris Lattnere2437f42010-05-09 06:40:08 +00001512}
1513
Richard Smith852c9db2013-04-20 22:23:05 +00001514void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1515 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001516 Record.AddDeclRef(E->getField());
Eric Fiselier708afb52019-05-16 21:04:15 +00001517 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
Richard Smith290d8012016-04-06 17:06:00 +00001518 Record.AddSourceLocation(E->getExprLoc());
Richard Smith852c9db2013-04-20 22:23:05 +00001519 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1520}
1521
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001522void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001523 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001524 Record.AddCXXTemporary(E->getTemporary());
1525 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +00001526 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
Chris Lattnercba86142010-05-10 00:25:06 +00001527}
1528
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001529void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001530 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001531 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1532 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001533 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001534}
1535
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001536void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001537 VisitExpr(E);
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001538
Sebastian Redlc3a3c602012-02-16 11:35:52 +00001539 Record.push_back(E->isArray());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001540 Record.push_back(E->hasInitializer());
1541 Record.push_back(E->getNumPlacementArgs());
1542 Record.push_back(E->isParenTypeId());
1543
1544 Record.push_back(E->isGlobalNew());
Richard Smithb2f0f052016-10-10 18:54:32 +00001545 Record.push_back(E->passAlignment());
Sebastian Redl6047f072012-02-16 12:22:20 +00001546 Record.push_back(E->doesUsualArrayDeleteWantSize());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001547 Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
1548
Richard Smith290d8012016-04-06 17:06:00 +00001549 Record.AddDeclRef(E->getOperatorNew());
1550 Record.AddDeclRef(E->getOperatorDelete());
1551 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001552 if (E->isParenTypeId())
1553 Record.AddSourceRange(E->getTypeIdParens());
Richard Smith290d8012016-04-06 17:06:00 +00001554 Record.AddSourceRange(E->getSourceRange());
1555 Record.AddSourceRange(E->getDirectInitRange());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001556
1557 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
1558 I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001559 Record.AddStmt(*I);
Sebastian Redl6047f072012-02-16 12:22:20 +00001560
Sebastian Redl539c5062010-08-18 23:57:32 +00001561 Code = serialization::EXPR_CXX_NEW;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001562}
1563
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001564void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001565 VisitExpr(E);
1566 Record.push_back(E->isGlobalDelete());
1567 Record.push_back(E->isArrayForm());
Argyrios Kyrtzidis14ec9f62010-09-13 20:15:54 +00001568 Record.push_back(E->isArrayFormAsWritten());
John McCall284c48f2011-01-27 09:37:56 +00001569 Record.push_back(E->doesUsualArrayDeleteWantSize());
Richard Smith290d8012016-04-06 17:06:00 +00001570 Record.AddDeclRef(E->getOperatorDelete());
1571 Record.AddStmt(E->getArgument());
Bruno Ricci91728fc2018-12-03 12:32:32 +00001572 Record.AddSourceLocation(E->getBeginLoc());
Fangrui Song6907ce22018-07-30 19:24:48 +00001573
Sebastian Redl539c5062010-08-18 23:57:32 +00001574 Code = serialization::EXPR_CXX_DELETE;
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001575}
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001576
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001577void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001578 VisitExpr(E);
1579
Richard Smith290d8012016-04-06 17:06:00 +00001580 Record.AddStmt(E->getBase());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001581 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001582 Record.AddSourceLocation(E->getOperatorLoc());
1583 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1584 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1585 Record.AddSourceLocation(E->getColonColonLoc());
1586 Record.AddSourceLocation(E->getTildeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001587
1588 // PseudoDestructorTypeStorage.
Richard Smith290d8012016-04-06 17:06:00 +00001589 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001590 if (E->getDestroyedTypeIdentifier())
Richard Smith290d8012016-04-06 17:06:00 +00001591 Record.AddSourceLocation(E->getDestroyedTypeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001592 else
Richard Smith290d8012016-04-06 17:06:00 +00001593 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001594
Sebastian Redl539c5062010-08-18 23:57:32 +00001595 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001596}
1597
John McCall5d413782010-12-06 08:20:24 +00001598void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001599 VisitExpr(E);
John McCall28fc7092011-11-10 05:35:25 +00001600 Record.push_back(E->getNumObjects());
1601 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001602 Record.AddDeclRef(E->getObject(i));
Tim Shen4a05bb82016-06-21 20:29:17 +00001603
1604 Record.push_back(E->cleanupsHaveSideEffects());
Richard Smith290d8012016-04-06 17:06:00 +00001605 Record.AddStmt(E->getSubExpr());
John McCall5d413782010-12-06 08:20:24 +00001606 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
Chris Lattnercba86142010-05-10 00:25:06 +00001607}
1608
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001609void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
1610 CXXDependentScopeMemberExpr *E) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001611 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001612
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001613 // Don't emit anything here (or if you do you will have to update
1614 // the corresponding deserialization function).
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001615
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001616 Record.push_back(E->hasTemplateKWAndArgsInfo());
1617 Record.push_back(E->getNumTemplateArgs());
1618 Record.push_back(E->hasFirstQualifierFoundInScope());
1619
1620 if (E->hasTemplateKWAndArgsInfo()) {
James Y Knighte7d82282015-12-29 18:15:14 +00001621 const ASTTemplateKWAndArgsInfo &ArgInfo =
1622 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
James Y Knighte7d82282015-12-29 18:15:14 +00001623 AddTemplateKWAndArgsInfo(ArgInfo,
1624 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001625 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00001626
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001627 Record.push_back(E->isArrow());
1628 Record.AddSourceLocation(E->getOperatorLoc());
1629 Record.AddTypeRef(E->getBaseType());
1630 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001631 if (!E->isImplicitAccess())
Richard Smith290d8012016-04-06 17:06:00 +00001632 Record.AddStmt(E->getBase());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001633 else
Richard Smith290d8012016-04-06 17:06:00 +00001634 Record.AddStmt(nullptr);
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001635
1636 if (E->hasFirstQualifierFoundInScope())
1637 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1638
Richard Smith290d8012016-04-06 17:06:00 +00001639 Record.AddDeclarationNameInfo(E->MemberNameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001640 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001641}
1642
1643void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001644ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001645 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001646
1647 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
Douglas Gregor87866ce2011-02-04 12:01:24 +00001648 // emitted first.
Abramo Bagnara7945c982012-01-27 09:46:47 +00001649
Bruno Ricci49ee9642019-01-07 14:27:04 +00001650 Record.push_back(E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
1651 if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001652 const ASTTemplateKWAndArgsInfo &ArgInfo =
1653 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1654 Record.push_back(ArgInfo.NumTemplateArgs);
1655 AddTemplateKWAndArgsInfo(ArgInfo,
1656 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001657 }
1658
Richard Smith290d8012016-04-06 17:06:00 +00001659 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1660 Record.AddDeclarationNameInfo(E->NameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001661 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001662}
1663
1664void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001665ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001666 VisitExpr(E);
1667 Record.push_back(E->arg_size());
1668 for (CXXUnresolvedConstructExpr::arg_iterator
1669 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
Richard Smith290d8012016-04-06 17:06:00 +00001670 Record.AddStmt(*ArgI);
1671 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1672 Record.AddSourceLocation(E->getLParenLoc());
1673 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001674 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001675}
Chris Lattner98267332010-05-09 06:15:05 +00001676
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001677void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001678 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001679
Bruno Riccid7628d92019-01-09 15:43:19 +00001680 Record.push_back(E->getNumDecls());
1681 Record.push_back(E->hasTemplateKWAndArgsInfo());
1682 if (E->hasTemplateKWAndArgsInfo()) {
James Y Knighte7d82282015-12-29 18:15:14 +00001683 const ASTTemplateKWAndArgsInfo &ArgInfo =
1684 *E->getTrailingASTTemplateKWAndArgsInfo();
1685 Record.push_back(ArgInfo.NumTemplateArgs);
1686 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001687 }
1688
Bruno Riccid7628d92019-01-09 15:43:19 +00001689 for (OverloadExpr::decls_iterator OvI = E->decls_begin(),
1690 OvE = E->decls_end();
1691 OvI != OvE; ++OvI) {
Richard Smith290d8012016-04-06 17:06:00 +00001692 Record.AddDeclRef(OvI.getDecl());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001693 Record.push_back(OvI.getAccess());
1694 }
1695
Bruno Riccid7628d92019-01-09 15:43:19 +00001696 Record.AddDeclarationNameInfo(E->getNameInfo());
Richard Smith290d8012016-04-06 17:06:00 +00001697 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001698}
1699
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001700void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001701 VisitOverloadExpr(E);
1702 Record.push_back(E->isArrow());
1703 Record.push_back(E->hasUnresolvedUsing());
Richard Smith290d8012016-04-06 17:06:00 +00001704 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1705 Record.AddTypeRef(E->getBaseType());
1706 Record.AddSourceLocation(E->getOperatorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001707 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001708}
1709
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001710void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001711 VisitOverloadExpr(E);
1712 Record.push_back(E->requiresADL());
1713 Record.push_back(E->isOverloaded());
Richard Smith290d8012016-04-06 17:06:00 +00001714 Record.AddDeclRef(E->getNamingClass());
Sebastian Redl539c5062010-08-18 23:57:32 +00001715 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001716}
1717
Douglas Gregor29c42f22012-02-24 07:38:34 +00001718void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1719 VisitExpr(E);
1720 Record.push_back(E->TypeTraitExprBits.NumArgs);
1721 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1722 Record.push_back(E->TypeTraitExprBits.Value);
Richard Smith290d8012016-04-06 17:06:00 +00001723 Record.AddSourceRange(E->getSourceRange());
Douglas Gregor29c42f22012-02-24 07:38:34 +00001724 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001725 Record.AddTypeSourceInfo(E->getArg(I));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001726 Code = serialization::EXPR_TYPE_TRAIT;
1727}
1728
John Wiegley6242b6a2011-04-28 00:16:57 +00001729void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1730 VisitExpr(E);
1731 Record.push_back(E->getTrait());
1732 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001733 Record.AddSourceRange(E->getSourceRange());
1734 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
Aleksei Sidorina693b372016-09-28 10:16:56 +00001735 Record.AddStmt(E->getDimensionExpression());
John Wiegley6242b6a2011-04-28 00:16:57 +00001736 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1737}
1738
John Wiegleyf9f65842011-04-25 06:54:41 +00001739void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1740 VisitExpr(E);
1741 Record.push_back(E->getTrait());
1742 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001743 Record.AddSourceRange(E->getSourceRange());
1744 Record.AddStmt(E->getQueriedExpression());
John Wiegleyf9f65842011-04-25 06:54:41 +00001745 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1746}
1747
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001748void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1749 VisitExpr(E);
1750 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001751 Record.AddSourceRange(E->getSourceRange());
1752 Record.AddStmt(E->getOperand());
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001753 Code = serialization::EXPR_CXX_NOEXCEPT;
1754}
1755
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001756void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1757 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001758 Record.AddSourceLocation(E->getEllipsisLoc());
Douglas Gregorb8840002011-01-14 21:20:45 +00001759 Record.push_back(E->NumExpansions);
Richard Smith290d8012016-04-06 17:06:00 +00001760 Record.AddStmt(E->getPattern());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001761 Code = serialization::EXPR_PACK_EXPANSION;
1762}
1763
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001764void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1765 VisitExpr(E);
Richard Smithd784e682015-09-23 21:41:42 +00001766 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1767 : 0);
Richard Smith290d8012016-04-06 17:06:00 +00001768 Record.AddSourceLocation(E->OperatorLoc);
1769 Record.AddSourceLocation(E->PackLoc);
1770 Record.AddSourceLocation(E->RParenLoc);
1771 Record.AddDeclRef(E->Pack);
Richard Smithd784e682015-09-23 21:41:42 +00001772 if (E->isPartiallySubstituted()) {
1773 for (const auto &TA : E->getPartialArguments())
Richard Smith290d8012016-04-06 17:06:00 +00001774 Record.AddTemplateArgument(TA);
Richard Smithd784e682015-09-23 21:41:42 +00001775 } else if (!E->isValueDependent()) {
1776 Record.push_back(E->getPackLength());
1777 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001778 Code = serialization::EXPR_SIZEOF_PACK;
1779}
1780
John McCallfa194042011-07-15 07:00:14 +00001781void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1782 SubstNonTypeTemplateParmExpr *E) {
1783 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001784 Record.AddDeclRef(E->getParameter());
1785 Record.AddSourceLocation(E->getNameLoc());
1786 Record.AddStmt(E->getReplacement());
John McCallfa194042011-07-15 07:00:14 +00001787 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1788}
1789
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001790void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1791 SubstNonTypeTemplateParmPackExpr *E) {
1792 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001793 Record.AddDeclRef(E->getParameterPack());
1794 Record.AddTemplateArgument(E->getArgumentPack());
1795 Record.AddSourceLocation(E->getParameterPackLocation());
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001796 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1797}
1798
Richard Smithb15fe3a2012-09-12 00:56:43 +00001799void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1800 VisitExpr(E);
1801 Record.push_back(E->getNumExpansions());
Richard Smith290d8012016-04-06 17:06:00 +00001802 Record.AddDeclRef(E->getParameterPack());
1803 Record.AddSourceLocation(E->getParameterPackLocation());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001804 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1805 I != End; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001806 Record.AddDeclRef(*I);
Richard Smithb15fe3a2012-09-12 00:56:43 +00001807 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1808}
1809
Douglas Gregorfe314812011-06-21 17:03:29 +00001810void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1811 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001812 Record.AddStmt(E->getTemporary());
1813 Record.AddDeclRef(E->getExtendingDecl());
David Majnemerdaff3702014-05-01 17:50:17 +00001814 Record.push_back(E->getManglingNumber());
Douglas Gregorfe314812011-06-21 17:03:29 +00001815 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1816}
1817
Richard Smith0f0af192014-11-08 05:07:16 +00001818void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1819 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001820 Record.AddSourceLocation(E->LParenLoc);
1821 Record.AddSourceLocation(E->EllipsisLoc);
1822 Record.AddSourceLocation(E->RParenLoc);
Richard Smithc7214f62019-05-13 08:31:14 +00001823 Record.push_back(E->NumExpansions);
Richard Smith290d8012016-04-06 17:06:00 +00001824 Record.AddStmt(E->SubExprs[0]);
1825 Record.AddStmt(E->SubExprs[1]);
Richard Smith0f0af192014-11-08 05:07:16 +00001826 Record.push_back(E->Opcode);
1827 Code = serialization::EXPR_CXX_FOLD;
1828}
1829
John McCall8d69a212010-11-15 23:31:06 +00001830void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1831 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001832 Record.AddStmt(E->getSourceExpr());
1833 Record.AddSourceLocation(E->getLocation());
Akira Hatanaka797afe32018-03-20 01:47:58 +00001834 Record.push_back(E->isUnique());
John McCall8d69a212010-11-15 23:31:06 +00001835 Code = serialization::EXPR_OPAQUE_VALUE;
1836}
1837
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001838void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1839 VisitExpr(E);
1840 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
Davide Italiano04839a52016-01-30 08:03:54 +00001841 llvm_unreachable("Cannot write TypoExpr nodes");
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001842}
1843
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001844//===----------------------------------------------------------------------===//
Peter Collingbourne41f85462011-02-09 21:07:24 +00001845// CUDA Expressions and Statements.
1846//===----------------------------------------------------------------------===//
1847
1848void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1849 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001850 Record.AddStmt(E->getConfig());
Peter Collingbourne41f85462011-02-09 21:07:24 +00001851 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1852}
1853
1854//===----------------------------------------------------------------------===//
Tanya Lattner55808c12011-06-04 00:47:47 +00001855// OpenCL Expressions and Statements.
1856//===----------------------------------------------------------------------===//
1857void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1858 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001859 Record.AddSourceLocation(E->getBuiltinLoc());
1860 Record.AddSourceLocation(E->getRParenLoc());
1861 Record.AddStmt(E->getSrcExpr());
Tanya Lattner55808c12011-06-04 00:47:47 +00001862 Code = serialization::EXPR_ASTYPE;
1863}
1864
1865//===----------------------------------------------------------------------===//
John McCallfa194042011-07-15 07:00:14 +00001866// Microsoft Expressions and Statements.
1867//===----------------------------------------------------------------------===//
John McCall5e77d762013-04-16 07:28:30 +00001868void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1869 VisitExpr(E);
1870 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001871 Record.AddStmt(E->getBaseExpr());
1872 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1873 Record.AddSourceLocation(E->getMemberLoc());
1874 Record.AddDeclRef(E->getPropertyDecl());
John McCall5e77d762013-04-16 07:28:30 +00001875 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1876}
1877
Alexey Bataevf7630272015-11-25 12:01:00 +00001878void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1879 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001880 Record.AddStmt(E->getBase());
1881 Record.AddStmt(E->getIdx());
1882 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataevf7630272015-11-25 12:01:00 +00001883 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1884}
1885
John McCallfa194042011-07-15 07:00:14 +00001886void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1887 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001888 Record.AddSourceRange(E->getSourceRange());
1889 Record.AddString(E->getUuidStr());
John McCallfa194042011-07-15 07:00:14 +00001890 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001891 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
John McCallfa194042011-07-15 07:00:14 +00001892 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1893 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001894 Record.AddStmt(E->getExprOperand());
John McCallfa194042011-07-15 07:00:14 +00001895 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1896 }
1897}
1898
1899void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1900 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001901 Record.AddSourceLocation(S->getExceptLoc());
1902 Record.AddStmt(S->getFilterExpr());
1903 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001904 Code = serialization::STMT_SEH_EXCEPT;
1905}
1906
1907void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1908 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001909 Record.AddSourceLocation(S->getFinallyLoc());
1910 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001911 Code = serialization::STMT_SEH_FINALLY;
1912}
1913
1914void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1915 VisitStmt(S);
1916 Record.push_back(S->getIsCXXTry());
Richard Smith290d8012016-04-06 17:06:00 +00001917 Record.AddSourceLocation(S->getTryLoc());
1918 Record.AddStmt(S->getTryBlock());
1919 Record.AddStmt(S->getHandler());
John McCallfa194042011-07-15 07:00:14 +00001920 Code = serialization::STMT_SEH_TRY;
1921}
1922
Nico Weber9b982072014-07-07 00:12:30 +00001923void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1924 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001925 Record.AddSourceLocation(S->getLeaveLoc());
Nico Weber9b982072014-07-07 00:12:30 +00001926 Code = serialization::STMT_SEH_LEAVE;
1927}
1928
John McCallfa194042011-07-15 07:00:14 +00001929//===----------------------------------------------------------------------===//
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001930// OpenMP Directives.
1931//===----------------------------------------------------------------------===//
1932void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001933 Record.AddSourceLocation(E->getBeginLoc());
Stephen Kelly1c301dc2018-08-09 21:09:38 +00001934 Record.AddSourceLocation(E->getEndLoc());
Richard Smith290d8012016-04-06 17:06:00 +00001935 OMPClauseWriter ClauseWriter(Record);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001936 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
1937 ClauseWriter.writeClause(E->getClause(i));
1938 }
Alexey Bataev68446b72014-07-18 07:47:19 +00001939 if (E->hasAssociatedStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001940 Record.AddStmt(E->getAssociatedStmt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001941}
1942
Alexander Musman3aaab662014-08-19 11:27:13 +00001943void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
1944 VisitStmt(D);
1945 Record.push_back(D->getNumClauses());
1946 Record.push_back(D->getCollapsedNumber());
1947 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001948 Record.AddStmt(D->getIterationVariable());
1949 Record.AddStmt(D->getLastIteration());
1950 Record.AddStmt(D->getCalcLastIteration());
1951 Record.AddStmt(D->getPreCond());
1952 Record.AddStmt(D->getCond());
1953 Record.AddStmt(D->getInit());
1954 Record.AddStmt(D->getInc());
1955 Record.AddStmt(D->getPreInits());
Alexey Bataev3392d762016-02-16 11:18:12 +00001956 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001957 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
1958 isOpenMPDistributeDirective(D->getDirectiveKind())) {
Richard Smith290d8012016-04-06 17:06:00 +00001959 Record.AddStmt(D->getIsLastIterVariable());
1960 Record.AddStmt(D->getLowerBoundVariable());
1961 Record.AddStmt(D->getUpperBoundVariable());
1962 Record.AddStmt(D->getStrideVariable());
1963 Record.AddStmt(D->getEnsureUpperBound());
1964 Record.AddStmt(D->getNextLowerBound());
1965 Record.AddStmt(D->getNextUpperBound());
Alexey Bataev8b427062016-05-25 12:36:08 +00001966 Record.AddStmt(D->getNumIterations());
Alexander Musmanc6388682014-12-15 07:07:06 +00001967 }
Carlo Bertolli9925f152016-06-27 14:55:37 +00001968 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
1969 Record.AddStmt(D->getPrevLowerBoundVariable());
1970 Record.AddStmt(D->getPrevUpperBoundVariable());
Carlo Bertolli8429d812017-02-17 21:29:13 +00001971 Record.AddStmt(D->getDistInc());
1972 Record.AddStmt(D->getPrevEnsureUpperBound());
Carlo Bertolliffafe102017-04-20 00:39:39 +00001973 Record.AddStmt(D->getCombinedLowerBoundVariable());
1974 Record.AddStmt(D->getCombinedUpperBoundVariable());
1975 Record.AddStmt(D->getCombinedEnsureUpperBound());
1976 Record.AddStmt(D->getCombinedInit());
1977 Record.AddStmt(D->getCombinedCond());
1978 Record.AddStmt(D->getCombinedNextLowerBound());
1979 Record.AddStmt(D->getCombinedNextUpperBound());
Gheorghe-Teodor Berceae9256762018-10-29 15:45:47 +00001980 Record.AddStmt(D->getCombinedDistCond());
1981 Record.AddStmt(D->getCombinedParForInDistCond());
Carlo Bertolli9925f152016-06-27 14:55:37 +00001982 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001983 for (auto I : D->counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001984 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001985 }
Alexey Bataeva8899172015-08-06 12:30:57 +00001986 for (auto I : D->private_counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001987 Record.AddStmt(I);
Alexey Bataeva8899172015-08-06 12:30:57 +00001988 }
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001989 for (auto I : D->inits()) {
Richard Smith290d8012016-04-06 17:06:00 +00001990 Record.AddStmt(I);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001991 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001992 for (auto I : D->updates()) {
Richard Smith290d8012016-04-06 17:06:00 +00001993 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001994 }
1995 for (auto I : D->finals()) {
Richard Smith290d8012016-04-06 17:06:00 +00001996 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001997 }
Alexander Musman3aaab662014-08-19 11:27:13 +00001998}
1999
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002000void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev1b59ab52014-02-27 08:29:12 +00002001 VisitStmt(D);
2002 Record.push_back(D->getNumClauses());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002003 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002004 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002005 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2006}
2007
Alexey Bataev1b59ab52014-02-27 08:29:12 +00002008void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00002009 VisitOMPLoopDirective(D);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00002010 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2011}
2012
Alexey Bataevf29276e2014-06-18 04:14:57 +00002013void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00002014 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002015 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevf29276e2014-06-18 04:14:57 +00002016 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2017}
2018
Alexander Musmanf82886e2014-09-18 05:12:34 +00002019void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2020 VisitOMPLoopDirective(D);
2021 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2022}
2023
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00002024void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2025 VisitStmt(D);
2026 Record.push_back(D->getNumClauses());
2027 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002028 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00002029 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2030}
2031
Alexey Bataev1e0498a2014-06-26 08:21:58 +00002032void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2033 VisitStmt(D);
2034 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002035 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev1e0498a2014-06-26 08:21:58 +00002036 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2037}
2038
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00002039void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2040 VisitStmt(D);
2041 Record.push_back(D->getNumClauses());
2042 VisitOMPExecutableDirective(D);
2043 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2044}
2045
Alexander Musman80c22892014-07-17 08:54:58 +00002046void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2047 VisitStmt(D);
2048 VisitOMPExecutableDirective(D);
2049 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2050}
2051
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002052void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2053 VisitStmt(D);
Alexey Bataev28c75412015-12-15 08:19:24 +00002054 Record.push_back(D->getNumClauses());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002055 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00002056 Record.AddDeclarationNameInfo(D->getDirectiveName());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002057 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2058}
2059
Alexey Bataev4acb8592014-07-07 13:01:15 +00002060void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00002061 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002062 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev4acb8592014-07-07 13:01:15 +00002063 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2064}
2065
Alexander Musmane4e893b2014-09-23 09:33:00 +00002066void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2067 OMPParallelForSimdDirective *D) {
2068 VisitOMPLoopDirective(D);
2069 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2070}
2071
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002072void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2073 OMPParallelSectionsDirective *D) {
2074 VisitStmt(D);
2075 Record.push_back(D->getNumClauses());
2076 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002077 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002078 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2079}
2080
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002081void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2082 VisitStmt(D);
2083 Record.push_back(D->getNumClauses());
2084 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002085 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002086 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2087}
2088
Alexey Bataev0162e452014-07-22 10:10:35 +00002089void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2090 VisitStmt(D);
2091 Record.push_back(D->getNumClauses());
2092 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00002093 Record.AddStmt(D->getX());
2094 Record.AddStmt(D->getV());
2095 Record.AddStmt(D->getExpr());
2096 Record.AddStmt(D->getUpdateExpr());
Alexey Bataevb4505a72015-03-30 05:20:59 +00002097 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
Alexey Bataevb78ca832015-04-01 03:33:17 +00002098 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
Alexey Bataev0162e452014-07-22 10:10:35 +00002099 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2100}
2101
Alexey Bataev0bd520b2014-09-19 08:19:49 +00002102void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2103 VisitStmt(D);
2104 Record.push_back(D->getNumClauses());
2105 VisitOMPExecutableDirective(D);
2106 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2107}
2108
Michael Wong65f367f2015-07-21 13:44:28 +00002109void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2110 VisitStmt(D);
2111 Record.push_back(D->getNumClauses());
2112 VisitOMPExecutableDirective(D);
2113 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2114}
2115
Samuel Antaodf67fc42016-01-19 19:15:56 +00002116void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2117 OMPTargetEnterDataDirective *D) {
2118 VisitStmt(D);
2119 Record.push_back(D->getNumClauses());
2120 VisitOMPExecutableDirective(D);
2121 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2122}
2123
Samuel Antao72590762016-01-19 20:04:50 +00002124void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2125 OMPTargetExitDataDirective *D) {
2126 VisitStmt(D);
2127 Record.push_back(D->getNumClauses());
2128 VisitOMPExecutableDirective(D);
2129 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2130}
2131
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00002132void ASTStmtWriter::VisitOMPTargetParallelDirective(
2133 OMPTargetParallelDirective *D) {
2134 VisitStmt(D);
2135 Record.push_back(D->getNumClauses());
2136 VisitOMPExecutableDirective(D);
2137 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2138}
2139
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00002140void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2141 OMPTargetParallelForDirective *D) {
2142 VisitOMPLoopDirective(D);
2143 Record.push_back(D->hasCancel() ? 1 : 0);
2144 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2145}
2146
Alexey Bataev68446b72014-07-18 07:47:19 +00002147void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2148 VisitStmt(D);
2149 VisitOMPExecutableDirective(D);
2150 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2151}
2152
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00002153void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2154 VisitStmt(D);
2155 VisitOMPExecutableDirective(D);
2156 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2157}
2158
Alexey Bataev2df347a2014-07-18 10:17:07 +00002159void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2160 VisitStmt(D);
2161 VisitOMPExecutableDirective(D);
2162 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2163}
2164
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002165void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2166 VisitStmt(D);
Alexey Bataev169d96a2017-07-18 20:17:46 +00002167 Record.push_back(D->getNumClauses());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002168 VisitOMPExecutableDirective(D);
Alexey Bataev3b1b8952017-07-25 15:53:26 +00002169 Record.AddStmt(D->getReductionRef());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002170 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2171}
2172
Alexey Bataev6125da92014-07-21 11:26:11 +00002173void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2174 VisitStmt(D);
2175 Record.push_back(D->getNumClauses());
2176 VisitOMPExecutableDirective(D);
2177 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2178}
2179
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002180void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2181 VisitStmt(D);
Alexey Bataev346265e2015-09-25 10:37:12 +00002182 Record.push_back(D->getNumClauses());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002183 VisitOMPExecutableDirective(D);
2184 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2185}
2186
Alexey Bataev13314bf2014-10-09 04:18:56 +00002187void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2188 VisitStmt(D);
2189 Record.push_back(D->getNumClauses());
2190 VisitOMPExecutableDirective(D);
2191 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2192}
2193
Alexey Bataev6d4ed052015-07-01 06:57:41 +00002194void ASTStmtWriter::VisitOMPCancellationPointDirective(
2195 OMPCancellationPointDirective *D) {
2196 VisitStmt(D);
2197 VisitOMPExecutableDirective(D);
2198 Record.push_back(D->getCancelRegion());
2199 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2200}
2201
Alexey Bataev80909872015-07-02 11:25:17 +00002202void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2203 VisitStmt(D);
Alexey Bataev87933c72015-09-18 08:07:34 +00002204 Record.push_back(D->getNumClauses());
Alexey Bataev80909872015-07-02 11:25:17 +00002205 VisitOMPExecutableDirective(D);
2206 Record.push_back(D->getCancelRegion());
2207 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2208}
2209
Alexey Bataev49f6e782015-12-01 04:18:41 +00002210void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2211 VisitOMPLoopDirective(D);
2212 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2213}
2214
Alexey Bataev0a6ed842015-12-03 09:40:15 +00002215void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2216 VisitOMPLoopDirective(D);
2217 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2218}
2219
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00002220void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2221 VisitOMPLoopDirective(D);
2222 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2223}
2224
Samuel Antao686c70c2016-05-26 17:30:50 +00002225void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2226 VisitStmt(D);
2227 Record.push_back(D->getNumClauses());
2228 VisitOMPExecutableDirective(D);
2229 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2230}
2231
Carlo Bertolli9925f152016-06-27 14:55:37 +00002232void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2233 OMPDistributeParallelForDirective *D) {
2234 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002235 Record.push_back(D->hasCancel() ? 1 : 0);
Carlo Bertolli9925f152016-06-27 14:55:37 +00002236 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2237}
2238
Kelvin Li4a39add2016-07-05 05:00:15 +00002239void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2240 OMPDistributeParallelForSimdDirective *D) {
2241 VisitOMPLoopDirective(D);
2242 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2243}
2244
Kelvin Li787f3fc2016-07-06 04:45:38 +00002245void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2246 OMPDistributeSimdDirective *D) {
2247 VisitOMPLoopDirective(D);
2248 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2249}
2250
Kelvin Lia579b912016-07-14 02:54:56 +00002251void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2252 OMPTargetParallelForSimdDirective *D) {
2253 VisitOMPLoopDirective(D);
2254 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2255}
2256
Kelvin Li986330c2016-07-20 22:57:10 +00002257void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2258 VisitOMPLoopDirective(D);
2259 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2260}
2261
Kelvin Li02532872016-08-05 14:37:37 +00002262void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2263 OMPTeamsDistributeDirective *D) {
2264 VisitOMPLoopDirective(D);
2265 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2266}
2267
Kelvin Li4e325f72016-10-25 12:50:55 +00002268void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2269 OMPTeamsDistributeSimdDirective *D) {
2270 VisitOMPLoopDirective(D);
2271 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2272}
2273
Kelvin Li579e41c2016-11-30 23:51:03 +00002274void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2275 OMPTeamsDistributeParallelForSimdDirective *D) {
2276 VisitOMPLoopDirective(D);
2277 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2278}
2279
Kelvin Li7ade93f2016-12-09 03:24:30 +00002280void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2281 OMPTeamsDistributeParallelForDirective *D) {
2282 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002283 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li7ade93f2016-12-09 03:24:30 +00002284 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2285}
2286
Kelvin Libf594a52016-12-17 05:48:59 +00002287void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2288 VisitStmt(D);
2289 Record.push_back(D->getNumClauses());
2290 VisitOMPExecutableDirective(D);
2291 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2292}
2293
Kelvin Li83c451e2016-12-25 04:52:54 +00002294void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2295 OMPTargetTeamsDistributeDirective *D) {
2296 VisitOMPLoopDirective(D);
2297 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2298}
2299
Kelvin Li80e8f562016-12-29 22:16:30 +00002300void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2301 OMPTargetTeamsDistributeParallelForDirective *D) {
2302 VisitOMPLoopDirective(D);
Alexey Bataev16e79882017-11-22 21:12:03 +00002303 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li80e8f562016-12-29 22:16:30 +00002304 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2305}
2306
Kelvin Li1851df52017-01-03 05:23:48 +00002307void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2308 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2309 VisitOMPLoopDirective(D);
2310 Code = serialization::
2311 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2312}
2313
Kelvin Lida681182017-01-10 18:08:18 +00002314void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2315 OMPTargetTeamsDistributeSimdDirective *D) {
2316 VisitOMPLoopDirective(D);
2317 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2318}
2319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002320//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002321// ASTWriter Implementation
Chris Lattner1f551822009-04-27 06:20:01 +00002322//===----------------------------------------------------------------------===//
2323
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002324unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002325 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002326 "SwitchCase recorded twice");
2327 unsigned NextID = SwitchCaseIDs.size();
2328 SwitchCaseIDs[S] = NextID;
2329 return NextID;
2330}
2331
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002332unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002333 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002334 "SwitchCase hasn't been seen yet");
2335 return SwitchCaseIDs[S];
2336}
2337
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002338void ASTWriter::ClearSwitchCaseIDs() {
2339 SwitchCaseIDs.clear();
2340}
2341
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002342/// Write the given substatement or subexpression to the
Chris Lattner1f551822009-04-27 06:20:01 +00002343/// bitstream.
Richard Smithf50422a2016-04-06 20:12:34 +00002344void ASTWriter::WriteSubStmt(Stmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00002345 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002346 ASTStmtWriter Writer(*this, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002347 ++NumStatements;
Fangrui Song6907ce22018-07-30 19:24:48 +00002348
Chris Lattner1f551822009-04-27 06:20:01 +00002349 if (!S) {
Sebastian Redl539c5062010-08-18 23:57:32 +00002350 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002351 return;
2352 }
Mike Stump11289f42009-09-09 15:08:12 +00002353
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002354 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2355 if (I != SubStmtEntries.end()) {
2356 Record.push_back(I->second);
2357 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2358 return;
2359 }
2360
2361#ifndef NDEBUG
2362 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2363
2364 struct ParentStmtInserterRAII {
2365 Stmt *S;
2366 llvm::DenseSet<Stmt *> &ParentStmts;
2367
2368 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2369 : S(S), ParentStmts(ParentStmts) {
2370 ParentStmts.insert(S);
2371 }
2372 ~ParentStmtInserterRAII() {
2373 ParentStmts.erase(S);
2374 }
2375 };
2376
2377 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2378#endif
2379
Chris Lattner1f551822009-04-27 06:20:01 +00002380 Writer.Visit(S);
Fangrui Song6907ce22018-07-30 19:24:48 +00002381
Richard Smithb41ddae2016-04-06 20:57:53 +00002382 uint64_t Offset = Writer.Emit();
2383 SubStmtEntries[S] = Offset;
Chris Lattner1f551822009-04-27 06:20:01 +00002384}
2385
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002386/// Flush all of the statements that have been added to the
Chris Lattner1f551822009-04-27 06:20:01 +00002387/// queue via AddStmt().
Richard Smith290d8012016-04-06 17:06:00 +00002388void ASTRecordWriter::FlushStmts() {
Daniel Dunbara5acaa32012-02-29 02:39:13 +00002389 // We expect to be the only consumer of the two temporary statement maps,
2390 // assert that they are empty.
Richard Smith290d8012016-04-06 17:06:00 +00002391 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2392 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002393
Chris Lattner1f551822009-04-27 06:20:01 +00002394 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002395 Writer->WriteSubStmt(StmtsToEmit[I]);
Fangrui Song6907ce22018-07-30 19:24:48 +00002396
Richard Smith290d8012016-04-06 17:06:00 +00002397 assert(N == StmtsToEmit.size() && "record modified while being written!");
Mike Stump11289f42009-09-09 15:08:12 +00002398
Chris Lattner1f551822009-04-27 06:20:01 +00002399 // Note that we are at the end of a full expression. Any
2400 // expression records that follow this one are part of a different
2401 // expression.
Richard Smith290d8012016-04-06 17:06:00 +00002402 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002403
Richard Smith290d8012016-04-06 17:06:00 +00002404 Writer->SubStmtEntries.clear();
2405 Writer->ParentStmts.clear();
2406 }
2407
2408 StmtsToEmit.clear();
2409}
2410
2411void ASTRecordWriter::FlushSubStmts() {
2412 // For a nested statement, write out the substatements in reverse order (so
2413 // that a simple stack machine can be used when loading), and don't emit a
2414 // STMT_STOP after each one.
2415 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002416 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
Richard Smith290d8012016-04-06 17:06:00 +00002417 assert(N == StmtsToEmit.size() && "record modified while being written!");
Chris Lattner1f551822009-04-27 06:20:01 +00002418 }
Mike Stump11289f42009-09-09 15:08:12 +00002419
Chris Lattner1f551822009-04-27 06:20:01 +00002420 StmtsToEmit.clear();
Chris Lattner1f551822009-04-27 06:20:01 +00002421}