blob: 776aab6bf51d2080f699ed4397f345a7198a048f [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);
435 Record.AddStmt(E->getSubExpr());
436 Code = serialization::EXPR_CONSTANT;
437}
438
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000439void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000440 VisitExpr(E);
Bruno Ricci17ff0262018-10-27 19:21:19 +0000441
442 bool HasFunctionName = E->getFunctionName() != nullptr;
443 Record.push_back(HasFunctionName);
444 Record.push_back(E->getIdentKind()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000445 Record.AddSourceLocation(E->getLocation());
Bruno Ricci17ff0262018-10-27 19:21:19 +0000446 if (HasFunctionName)
447 Record.AddStmt(E->getFunctionName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000448 Code = serialization::EXPR_PREDEFINED;
Chris Lattner1f551822009-04-27 06:20:01 +0000449}
450
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000451void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000452 VisitExpr(E);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000453
454 Record.push_back(E->hasQualifier());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000455 Record.push_back(E->getDecl() != E->getFoundDecl());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000456 Record.push_back(E->hasTemplateKWAndArgsInfo());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000457 Record.push_back(E->hadMultipleCandidates());
Alexey Bataev19acc3d2015-01-12 10:17:46 +0000458 Record.push_back(E->refersToEnclosingVariableOrCapture());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000459
Abramo Bagnara7945c982012-01-27 09:46:47 +0000460 if (E->hasTemplateKWAndArgsInfo()) {
Douglas Gregor87866ce2011-02-04 12:01:24 +0000461 unsigned NumTemplateArgs = E->getNumTemplateArgs();
462 Record.push_back(NumTemplateArgs);
Douglas Gregor87866ce2011-02-04 12:01:24 +0000463 }
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000464
Douglas Gregor03412ba2011-06-03 02:27:19 +0000465 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
466
Abramo Bagnara7945c982012-01-27 09:46:47 +0000467 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000468 (E->getDecl() == E->getFoundDecl()) &&
469 nk == DeclarationName::Identifier) {
470 AbbrevToUse = Writer.getDeclRefExprAbbrev();
471 }
472
Anders Carlsson80756f62011-03-06 18:19:42 +0000473 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000474 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Anders Carlsson80756f62011-03-06 18:19:42 +0000475
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000476 if (E->getDecl() != E->getFoundDecl())
Richard Smith290d8012016-04-06 17:06:00 +0000477 Record.AddDeclRef(E->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000478
Abramo Bagnara7945c982012-01-27 09:46:47 +0000479 if (E->hasTemplateKWAndArgsInfo())
James Y Knighte7d82282015-12-29 18:15:14 +0000480 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
481 E->getTrailingObjects<TemplateArgumentLoc>());
Anders Carlsson80756f62011-03-06 18:19:42 +0000482
Richard Smith290d8012016-04-06 17:06:00 +0000483 Record.AddDeclRef(E->getDecl());
484 Record.AddSourceLocation(E->getLocation());
485 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000486 Code = serialization::EXPR_DECL_REF;
Chris Lattner1f551822009-04-27 06:20:01 +0000487}
488
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000489void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000490 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000491 Record.AddSourceLocation(E->getLocation());
492 Record.AddAPInt(E->getValue());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000493
494 if (E->getValue().getBitWidth() == 32) {
495 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
496 }
497
Sebastian Redl539c5062010-08-18 23:57:32 +0000498 Code = serialization::EXPR_INTEGER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000499}
500
Leonard Chandb01c3a2018-06-20 17:19:40 +0000501void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
502 VisitExpr(E);
503 Record.AddSourceLocation(E->getLocation());
504 Record.AddAPInt(E->getValue());
505 Code = serialization::EXPR_INTEGER_LITERAL;
506}
507
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000508void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000509 VisitExpr(E);
Tim Northover178723a2013-01-22 09:46:51 +0000510 Record.push_back(E->getRawSemantics());
Chris Lattner1f551822009-04-27 06:20:01 +0000511 Record.push_back(E->isExact());
Richard Smith290d8012016-04-06 17:06:00 +0000512 Record.AddAPFloat(E->getValue());
513 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000514 Code = serialization::EXPR_FLOATING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000515}
516
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000517void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000518 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000519 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000520 Code = serialization::EXPR_IMAGINARY_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000521}
522
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000523void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000524 VisitExpr(E);
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000525
526 // Store the various bits of data of StringLiteral.
Chris Lattner1f551822009-04-27 06:20:01 +0000527 Record.push_back(E->getNumConcatenated());
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000528 Record.push_back(E->getLength());
529 Record.push_back(E->getCharByteWidth());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000530 Record.push_back(E->getKind());
Anders Carlsson75245402011-04-14 00:40:03 +0000531 Record.push_back(E->isPascal());
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000532
533 // Store the trailing array of SourceLocation.
Chris Lattner1f551822009-04-27 06:20:01 +0000534 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000535 Record.AddSourceLocation(E->getStrTokenLoc(I));
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000536
537 // Store the trailing array of char holding the string data.
538 StringRef StrData = E->getBytes();
539 for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
540 Record.push_back(StrData[I]);
541
Sebastian Redl539c5062010-08-18 23:57:32 +0000542 Code = serialization::EXPR_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000543}
544
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000545void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000546 VisitExpr(E);
547 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +0000548 Record.AddSourceLocation(E->getLocation());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000549 Record.push_back(E->getKind());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000550
551 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
552
Sebastian Redl539c5062010-08-18 23:57:32 +0000553 Code = serialization::EXPR_CHARACTER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000554}
555
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000556void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000557 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000558 Record.AddSourceLocation(E->getLParen());
559 Record.AddSourceLocation(E->getRParen());
560 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000561 Code = serialization::EXPR_PAREN;
Chris Lattner1f551822009-04-27 06:20:01 +0000562}
563
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000564void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000565 VisitExpr(E);
Bruno Riccif49e1ca2018-11-20 16:20:40 +0000566 Record.push_back(E->getNumExprs());
567 for (auto *SubStmt : E->exprs())
568 Record.AddStmt(SubStmt);
569 Record.AddSourceLocation(E->getLParenLoc());
570 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000571 Code = serialization::EXPR_PAREN_LIST;
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000572}
573
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000574void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000575 VisitExpr(E);
Malcolm Parsonsfab36802018-04-16 08:31:08 +0000576 Record.AddStmt(E->getSubExpr());
577 Record.push_back(E->getOpcode()); // FIXME: stable encoding
578 Record.AddSourceLocation(E->getOperatorLoc());
579 Record.push_back(E->canOverflow());
580 Code = serialization::EXPR_UNARY_OPERATOR;
581}
582
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000583void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000584 VisitExpr(E);
585 Record.push_back(E->getNumComponents());
586 Record.push_back(E->getNumExpressions());
Richard Smith290d8012016-04-06 17:06:00 +0000587 Record.AddSourceLocation(E->getOperatorLoc());
588 Record.AddSourceLocation(E->getRParenLoc());
589 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Douglas Gregor882211c2010-04-28 22:16:22 +0000590 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +0000591 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +0000592 Record.push_back(ON.getKind()); // FIXME: Stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000593 Record.AddSourceLocation(ON.getSourceRange().getBegin());
594 Record.AddSourceLocation(ON.getSourceRange().getEnd());
Douglas Gregor882211c2010-04-28 22:16:22 +0000595 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +0000596 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +0000597 Record.push_back(ON.getArrayExprIndex());
598 break;
James Y Knight7281c352015-12-29 22:31:18 +0000599
600 case OffsetOfNode::Field:
Richard Smith290d8012016-04-06 17:06:00 +0000601 Record.AddDeclRef(ON.getField());
Douglas Gregor882211c2010-04-28 22:16:22 +0000602 break;
James Y Knight7281c352015-12-29 22:31:18 +0000603
604 case OffsetOfNode::Identifier:
Richard Smith290d8012016-04-06 17:06:00 +0000605 Record.AddIdentifierRef(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +0000606 break;
James Y Knight7281c352015-12-29 22:31:18 +0000607
608 case OffsetOfNode::Base:
Richard Smith290d8012016-04-06 17:06:00 +0000609 Record.AddCXXBaseSpecifier(*ON.getBase());
Douglas Gregord1702062010-04-29 00:18:15 +0000610 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000611 }
612 }
613 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000614 Record.AddStmt(E->getIndexExpr(I));
Sebastian Redl539c5062010-08-18 23:57:32 +0000615 Code = serialization::EXPR_OFFSETOF;
Douglas Gregor882211c2010-04-28 22:16:22 +0000616}
617
Peter Collingbournee190dee2011-03-11 19:24:49 +0000618void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000619 VisitExpr(E);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000620 Record.push_back(E->getKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000621 if (E->isArgumentType())
Richard Smith290d8012016-04-06 17:06:00 +0000622 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
Chris Lattner1f551822009-04-27 06:20:01 +0000623 else {
624 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +0000625 Record.AddStmt(E->getArgumentExpr());
Chris Lattner1f551822009-04-27 06:20:01 +0000626 }
Richard Smith290d8012016-04-06 17:06:00 +0000627 Record.AddSourceLocation(E->getOperatorLoc());
628 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000629 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
Chris Lattner1f551822009-04-27 06:20:01 +0000630}
631
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000632void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000633 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000634 Record.AddStmt(E->getLHS());
635 Record.AddStmt(E->getRHS());
636 Record.AddSourceLocation(E->getRBracketLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000637 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
Chris Lattner1f551822009-04-27 06:20:01 +0000638}
639
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000640void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
641 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000642 Record.AddStmt(E->getBase());
643 Record.AddStmt(E->getLowerBound());
644 Record.AddStmt(E->getLength());
645 Record.AddSourceLocation(E->getColonLoc());
646 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000647 Code = serialization::EXPR_OMP_ARRAY_SECTION;
648}
649
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000650void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000651 VisitExpr(E);
652 Record.push_back(E->getNumArgs());
Richard Smith290d8012016-04-06 17:06:00 +0000653 Record.AddSourceLocation(E->getRParenLoc());
654 Record.AddStmt(E->getCallee());
Chris Lattner1f551822009-04-27 06:20:01 +0000655 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
656 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +0000657 Record.AddStmt(*Arg);
Eric Fiselier5cdc2cd2018-12-12 21:50:55 +0000658 Record.push_back(static_cast<unsigned>(E->getADLCallKind()));
Sebastian Redl539c5062010-08-18 23:57:32 +0000659 Code = serialization::EXPR_CALL;
Chris Lattner1f551822009-04-27 06:20:01 +0000660}
661
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000662void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000663 // Don't call VisitExpr, we'll write everything here.
664
665 Record.push_back(E->hasQualifier());
Douglas Gregorea972d32011-02-28 21:54:11 +0000666 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000667 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000668
Bruno Ricci4c742532018-11-15 13:56:22 +0000669 Record.push_back(E->hasTemplateKWAndArgsInfo());
670 if (E->hasTemplateKWAndArgsInfo()) {
Richard Smith290d8012016-04-06 17:06:00 +0000671 Record.AddSourceLocation(E->getTemplateKeywordLoc());
Douglas Gregor87866ce2011-02-04 12:01:24 +0000672 unsigned NumTemplateArgs = E->getNumTemplateArgs();
673 Record.push_back(NumTemplateArgs);
Richard Smith290d8012016-04-06 17:06:00 +0000674 Record.AddSourceLocation(E->getLAngleLoc());
675 Record.AddSourceLocation(E->getRAngleLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000676 for (unsigned i=0; i != NumTemplateArgs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +0000677 Record.AddTemplateArgumentLoc(E->getTemplateArgs()[i]);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000678 }
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000679
680 Record.push_back(E->hadMultipleCandidates());
681
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000682 DeclAccessPair FoundDecl = E->getFoundDecl();
Richard Smith290d8012016-04-06 17:06:00 +0000683 Record.AddDeclRef(FoundDecl.getDecl());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000684 Record.push_back(FoundDecl.getAccess());
685
Richard Smith290d8012016-04-06 17:06:00 +0000686 Record.AddTypeRef(E->getType());
John McCall7decc9e2010-11-18 06:31:45 +0000687 Record.push_back(E->getValueKind());
688 Record.push_back(E->getObjectKind());
Richard Smith290d8012016-04-06 17:06:00 +0000689 Record.AddStmt(E->getBase());
690 Record.AddDeclRef(E->getMemberDecl());
691 Record.AddSourceLocation(E->getMemberLoc());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000692 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +0000693 Record.AddSourceLocation(E->getOperatorLoc());
694 Record.AddDeclarationNameLoc(E->MemberDNLoc,
695 E->getMemberDecl()->getDeclName());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000696 Code = serialization::EXPR_MEMBER;
Chris Lattner1f551822009-04-27 06:20:01 +0000697}
698
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000699void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Naroffe87026a2009-07-24 17:54:45 +0000700 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000701 Record.AddStmt(E->getBase());
702 Record.AddSourceLocation(E->getIsaMemberLoc());
703 Record.AddSourceLocation(E->getOpLoc());
Steve Naroffe87026a2009-07-24 17:54:45 +0000704 Record.push_back(E->isArrow());
Sebastian Redl539c5062010-08-18 23:57:32 +0000705 Code = serialization::EXPR_OBJC_ISA;
Steve Naroffe87026a2009-07-24 17:54:45 +0000706}
707
John McCall31168b02011-06-15 23:02:42 +0000708void ASTStmtWriter::
709VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
710 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000711 Record.AddStmt(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +0000712 Record.push_back(E->shouldCopy());
713 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
714}
715
716void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
717 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000718 Record.AddSourceLocation(E->getLParenLoc());
719 Record.AddSourceLocation(E->getBridgeKeywordLoc());
John McCall31168b02011-06-15 23:02:42 +0000720 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
721 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
722}
723
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000724void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000725 VisitExpr(E);
John McCallcf142162010-08-07 06:22:56 +0000726 Record.push_back(E->path_size());
Richard Smith290d8012016-04-06 17:06:00 +0000727 Record.AddStmt(E->getSubExpr());
Anders Carlssona2615922009-07-31 00:48:10 +0000728 Record.push_back(E->getCastKind()); // FIXME: stable encoding
John McCallcf142162010-08-07 06:22:56 +0000729
730 for (CastExpr::path_iterator
731 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
Richard Smith290d8012016-04-06 17:06:00 +0000732 Record.AddCXXBaseSpecifier(**PI);
Chris Lattner1f551822009-04-27 06:20:01 +0000733}
734
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000735void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000736 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000737 Record.AddStmt(E->getLHS());
738 Record.AddStmt(E->getRHS());
Chris Lattner1f551822009-04-27 06:20:01 +0000739 Record.push_back(E->getOpcode()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000740 Record.AddSourceLocation(E->getOperatorLoc());
Adam Nemet484aa452017-03-27 19:17:25 +0000741 Record.push_back(E->getFPFeatures().getInt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000742 Code = serialization::EXPR_BINARY_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000743}
744
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000745void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000746 VisitBinaryOperator(E);
Richard Smith290d8012016-04-06 17:06:00 +0000747 Record.AddTypeRef(E->getComputationLHSType());
748 Record.AddTypeRef(E->getComputationResultType());
Sebastian Redl539c5062010-08-18 23:57:32 +0000749 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000750}
751
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000752void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000753 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000754 Record.AddStmt(E->getCond());
755 Record.AddStmt(E->getLHS());
756 Record.AddStmt(E->getRHS());
757 Record.AddSourceLocation(E->getQuestionLoc());
758 Record.AddSourceLocation(E->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000759 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000760}
761
John McCallc07a0c72011-02-17 10:25:35 +0000762void
763ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
764 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000765 Record.AddStmt(E->getOpaqueValue());
766 Record.AddStmt(E->getCommon());
767 Record.AddStmt(E->getCond());
768 Record.AddStmt(E->getTrueExpr());
769 Record.AddStmt(E->getFalseExpr());
770 Record.AddSourceLocation(E->getQuestionLoc());
771 Record.AddSourceLocation(E->getColonLoc());
John McCallc07a0c72011-02-17 10:25:35 +0000772 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
773}
774
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000775void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000776 VisitCastExpr(E);
Roman Lebedev12216f12018-07-27 07:27:14 +0000777 Record.push_back(E->isPartOfExplicitCast());
Richard Smitha27c26e2014-07-27 04:19:32 +0000778
779 if (E->path_size() == 0)
780 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
781
Sebastian Redl539c5062010-08-18 23:57:32 +0000782 Code = serialization::EXPR_IMPLICIT_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000783}
784
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000785void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000786 VisitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000787 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
Chris Lattner1f551822009-04-27 06:20:01 +0000788}
789
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000790void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000791 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000792 Record.AddSourceLocation(E->getLParenLoc());
793 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000794 Code = serialization::EXPR_CSTYLE_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000795}
796
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000797void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000798 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000799 Record.AddSourceLocation(E->getLParenLoc());
800 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
801 Record.AddStmt(E->getInitializer());
Chris Lattner1f551822009-04-27 06:20:01 +0000802 Record.push_back(E->isFileScope());
Sebastian Redl539c5062010-08-18 23:57:32 +0000803 Code = serialization::EXPR_COMPOUND_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000804}
805
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000806void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000807 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000808 Record.AddStmt(E->getBase());
809 Record.AddIdentifierRef(&E->getAccessor());
810 Record.AddSourceLocation(E->getAccessorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000811 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
Chris Lattner1f551822009-04-27 06:20:01 +0000812}
813
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000814void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000815 VisitExpr(E);
Abramo Bagnara8d16bd42012-11-08 18:41:43 +0000816 // NOTE: only add the (possibly null) syntactic form.
817 // No need to serialize the isSemanticForm flag and the semantic form.
Richard Smith290d8012016-04-06 17:06:00 +0000818 Record.AddStmt(E->getSyntacticForm());
819 Record.AddSourceLocation(E->getLBraceLoc());
820 Record.AddSourceLocation(E->getRBraceLoc());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000821 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
822 Record.push_back(isArrayFiller);
823 if (isArrayFiller)
Richard Smith290d8012016-04-06 17:06:00 +0000824 Record.AddStmt(E->getArrayFiller());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000825 else
Richard Smith290d8012016-04-06 17:06:00 +0000826 Record.AddDeclRef(E->getInitializedFieldInUnion());
Chris Lattner1f551822009-04-27 06:20:01 +0000827 Record.push_back(E->hadArrayRangeDesignator());
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000828 Record.push_back(E->getNumInits());
829 if (isArrayFiller) {
830 // ArrayFiller may have filled "holes" due to designated initializer.
831 // Replace them by 0 to indicate that the filler goes in that place.
832 Expr *filler = E->getArrayFiller();
833 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000834 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000835 } else {
836 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000837 Record.AddStmt(E->getInit(I));
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000838 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000839 Code = serialization::EXPR_INIT_LIST;
Chris Lattner1f551822009-04-27 06:20:01 +0000840}
841
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000842void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000843 VisitExpr(E);
844 Record.push_back(E->getNumSubExprs());
845 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000846 Record.AddStmt(E->getSubExpr(I));
847 Record.AddSourceLocation(E->getEqualOrColonLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000848 Record.push_back(E->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +0000849 for (const DesignatedInitExpr::Designator &D : E->designators()) {
850 if (D.isFieldDesignator()) {
851 if (FieldDecl *Field = D.getField()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000852 Record.push_back(serialization::DESIG_FIELD_DECL);
Richard Smith290d8012016-04-06 17:06:00 +0000853 Record.AddDeclRef(Field);
Chris Lattner1f551822009-04-27 06:20:01 +0000854 } else {
Sebastian Redl539c5062010-08-18 23:57:32 +0000855 Record.push_back(serialization::DESIG_FIELD_NAME);
David Majnemerf7e36092016-06-23 00:15:04 +0000856 Record.AddIdentifierRef(D.getFieldName());
Chris Lattner1f551822009-04-27 06:20:01 +0000857 }
David Majnemerf7e36092016-06-23 00:15:04 +0000858 Record.AddSourceLocation(D.getDotLoc());
859 Record.AddSourceLocation(D.getFieldLoc());
860 } else if (D.isArrayDesignator()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000861 Record.push_back(serialization::DESIG_ARRAY);
David Majnemerf7e36092016-06-23 00:15:04 +0000862 Record.push_back(D.getFirstExprIndex());
863 Record.AddSourceLocation(D.getLBracketLoc());
864 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000865 } else {
David Majnemerf7e36092016-06-23 00:15:04 +0000866 assert(D.isArrayRangeDesignator() && "Unknown designator");
Sebastian Redl539c5062010-08-18 23:57:32 +0000867 Record.push_back(serialization::DESIG_ARRAY_RANGE);
David Majnemerf7e36092016-06-23 00:15:04 +0000868 Record.push_back(D.getFirstExprIndex());
869 Record.AddSourceLocation(D.getLBracketLoc());
870 Record.AddSourceLocation(D.getEllipsisLoc());
871 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000872 }
873 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000874 Code = serialization::EXPR_DESIGNATED_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000875}
876
Yunzhong Gaocb779302015-06-10 00:27:52 +0000877void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
878 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000879 Record.AddStmt(E->getBase());
880 Record.AddStmt(E->getUpdater());
Yunzhong Gaocb779302015-06-10 00:27:52 +0000881 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
882}
883
884void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
885 VisitExpr(E);
886 Code = serialization::EXPR_NO_INIT;
887}
888
Richard Smith410306b2016-12-12 02:53:20 +0000889void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
890 VisitExpr(E);
891 Record.AddStmt(E->SubExprs[0]);
892 Record.AddStmt(E->SubExprs[1]);
893 Code = serialization::EXPR_ARRAY_INIT_LOOP;
894}
895
896void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
897 VisitExpr(E);
898 Code = serialization::EXPR_ARRAY_INIT_INDEX;
899}
900
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000901void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000902 VisitExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +0000903 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000904}
905
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000906void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000907 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000908 Record.AddStmt(E->getSubExpr());
909 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
910 Record.AddSourceLocation(E->getBuiltinLoc());
911 Record.AddSourceLocation(E->getRParenLoc());
Charles Davisc7d5c942015-09-17 20:55:33 +0000912 Record.push_back(E->isMicrosoftABI());
Sebastian Redl539c5062010-08-18 23:57:32 +0000913 Code = serialization::EXPR_VA_ARG;
Chris Lattner1f551822009-04-27 06:20:01 +0000914}
915
Eric Fiselier708afb52019-05-16 21:04:15 +0000916void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) {
917 VisitExpr(E);
918 Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext()));
919 Record.AddSourceLocation(E->getBeginLoc());
920 Record.AddSourceLocation(E->getEndLoc());
921 Record.push_back(E->getIdentKind());
922 Code = serialization::EXPR_SOURCE_LOC;
923}
924
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000925void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000926 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000927 Record.AddSourceLocation(E->getAmpAmpLoc());
928 Record.AddSourceLocation(E->getLabelLoc());
929 Record.AddDeclRef(E->getLabel());
Sebastian Redl539c5062010-08-18 23:57:32 +0000930 Code = serialization::EXPR_ADDR_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000931}
932
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000933void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000934 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000935 Record.AddStmt(E->getSubStmt());
936 Record.AddSourceLocation(E->getLParenLoc());
937 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000938 Code = serialization::EXPR_STMT;
Chris Lattner1f551822009-04-27 06:20:01 +0000939}
940
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000941void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000942 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000943 Record.AddStmt(E->getCond());
944 Record.AddStmt(E->getLHS());
945 Record.AddStmt(E->getRHS());
946 Record.AddSourceLocation(E->getBuiltinLoc());
947 Record.AddSourceLocation(E->getRParenLoc());
Eli Friedman75807f22013-07-20 00:40:58 +0000948 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
Sebastian Redl539c5062010-08-18 23:57:32 +0000949 Code = serialization::EXPR_CHOOSE;
Chris Lattner1f551822009-04-27 06:20:01 +0000950}
951
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000952void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000953 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000954 Record.AddSourceLocation(E->getTokenLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000955 Code = serialization::EXPR_GNU_NULL;
Chris Lattner1f551822009-04-27 06:20:01 +0000956}
957
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000958void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000959 VisitExpr(E);
960 Record.push_back(E->getNumSubExprs());
961 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000962 Record.AddStmt(E->getExpr(I));
963 Record.AddSourceLocation(E->getBuiltinLoc());
964 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000965 Code = serialization::EXPR_SHUFFLE_VECTOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000966}
967
Hal Finkelc4d7c822013-09-18 03:29:45 +0000968void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
969 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000970 Record.AddSourceLocation(E->getBuiltinLoc());
971 Record.AddSourceLocation(E->getRParenLoc());
972 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
973 Record.AddStmt(E->getSrcExpr());
Hal Finkelc4d7c822013-09-18 03:29:45 +0000974 Code = serialization::EXPR_CONVERT_VECTOR;
975}
976
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000977void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000978 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000979 Record.AddDeclRef(E->getBlockDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000980 Code = serialization::EXPR_BLOCK;
Chris Lattner1f551822009-04-27 06:20:01 +0000981}
982
Peter Collingbourne91147592011-04-15 00:35:48 +0000983void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
984 VisitExpr(E);
Bruno Riccidb076832019-01-26 14:15:10 +0000985
Peter Collingbourne91147592011-04-15 00:35:48 +0000986 Record.push_back(E->getNumAssocs());
Bruno Ricci94498c72019-01-26 13:58:15 +0000987 Record.push_back(E->ResultIndex);
Richard Smith290d8012016-04-06 17:06:00 +0000988 Record.AddSourceLocation(E->getGenericLoc());
989 Record.AddSourceLocation(E->getDefaultLoc());
990 Record.AddSourceLocation(E->getRParenLoc());
Bruno Riccidb076832019-01-26 14:15:10 +0000991
992 Stmt **Stmts = E->getTrailingObjects<Stmt *>();
993 // Add 1 to account for the controlling expression which is the first
994 // expression in the trailing array of Stmt *. This is not needed for
995 // the trailing array of TypeSourceInfo *.
996 for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I)
997 Record.AddStmt(Stmts[I]);
998
999 TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
1000 for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I)
1001 Record.AddTypeSourceInfo(TSIs[I]);
1002
Peter Collingbourne91147592011-04-15 00:35:48 +00001003 Code = serialization::EXPR_GENERIC_SELECTION;
1004}
1005
John McCallfe96e0b2011-11-06 09:01:30 +00001006void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
1007 VisitExpr(E);
1008 Record.push_back(E->getNumSemanticExprs());
1009
1010 // Push the result index. Currently, this needs to exactly match
1011 // the encoding used internally for ResultIndex.
1012 unsigned result = E->getResultExprIndex();
1013 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
1014 Record.push_back(result);
1015
Richard Smith290d8012016-04-06 17:06:00 +00001016 Record.AddStmt(E->getSyntacticForm());
John McCallfe96e0b2011-11-06 09:01:30 +00001017 for (PseudoObjectExpr::semantics_iterator
1018 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
Richard Smith290d8012016-04-06 17:06:00 +00001019 Record.AddStmt(*i);
John McCallfe96e0b2011-11-06 09:01:30 +00001020 }
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +00001021 Code = serialization::EXPR_PSEUDO_OBJECT;
John McCallfe96e0b2011-11-06 09:01:30 +00001022}
1023
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001024void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
1025 VisitExpr(E);
1026 Record.push_back(E->getOp());
Richard Smithaa22a8c2012-04-10 22:49:28 +00001027 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001028 Record.AddStmt(E->getSubExprs()[I]);
1029 Record.AddSourceLocation(E->getBuiltinLoc());
1030 Record.AddSourceLocation(E->getRParenLoc());
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +00001031 Code = serialization::EXPR_ATOMIC;
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001032}
1033
Chris Lattner1f551822009-04-27 06:20:01 +00001034//===----------------------------------------------------------------------===//
1035// Objective-C Expressions and Statements.
1036//===----------------------------------------------------------------------===//
1037
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001038void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001039 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001040 Record.AddStmt(E->getString());
1041 Record.AddSourceLocation(E->getAtLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001042 Code = serialization::EXPR_OBJC_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +00001043}
1044
Patrick Beard0caa3942012-04-19 00:25:12 +00001045void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001046 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001047 Record.AddStmt(E->getSubExpr());
1048 Record.AddDeclRef(E->getBoxingMethod());
1049 Record.AddSourceRange(E->getSourceRange());
Patrick Beard0caa3942012-04-19 00:25:12 +00001050 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
Ted Kremeneke65b0862012-03-06 20:05:56 +00001051}
1052
1053void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1054 VisitExpr(E);
1055 Record.push_back(E->getNumElements());
1056 for (unsigned i = 0; i < E->getNumElements(); i++)
Richard Smith290d8012016-04-06 17:06:00 +00001057 Record.AddStmt(E->getElement(i));
1058 Record.AddDeclRef(E->getArrayWithObjectsMethod());
1059 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001060 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1061}
1062
1063void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1064 VisitExpr(E);
1065 Record.push_back(E->getNumElements());
1066 Record.push_back(E->HasPackExpansions);
1067 for (unsigned i = 0; i < E->getNumElements(); i++) {
1068 ObjCDictionaryElement Element = E->getKeyValueElement(i);
Richard Smith290d8012016-04-06 17:06:00 +00001069 Record.AddStmt(Element.Key);
1070 Record.AddStmt(Element.Value);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001071 if (E->HasPackExpansions) {
Richard Smith290d8012016-04-06 17:06:00 +00001072 Record.AddSourceLocation(Element.EllipsisLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001073 unsigned NumExpansions = 0;
1074 if (Element.NumExpansions)
1075 NumExpansions = *Element.NumExpansions + 1;
1076 Record.push_back(NumExpansions);
1077 }
1078 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001079
Richard Smith290d8012016-04-06 17:06:00 +00001080 Record.AddDeclRef(E->getDictWithObjectsMethod());
1081 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001082 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1083}
1084
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001085void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001086 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001087 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1088 Record.AddSourceLocation(E->getAtLoc());
1089 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001090 Code = serialization::EXPR_OBJC_ENCODE;
Chris Lattner1f551822009-04-27 06:20:01 +00001091}
1092
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001093void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001094 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001095 Record.AddSelectorRef(E->getSelector());
1096 Record.AddSourceLocation(E->getAtLoc());
1097 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001098 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001099}
1100
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001101void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001102 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001103 Record.AddDeclRef(E->getProtocol());
1104 Record.AddSourceLocation(E->getAtLoc());
1105 Record.AddSourceLocation(E->ProtoLoc);
1106 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001107 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001108}
1109
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001110void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001111 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001112 Record.AddDeclRef(E->getDecl());
1113 Record.AddSourceLocation(E->getLocation());
1114 Record.AddSourceLocation(E->getOpLoc());
1115 Record.AddStmt(E->getBase());
Chris Lattner1f551822009-04-27 06:20:01 +00001116 Record.push_back(E->isArrow());
1117 Record.push_back(E->isFreeIvar());
Sebastian Redl539c5062010-08-18 23:57:32 +00001118 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001119}
1120
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001121void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001122 VisitExpr(E);
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001123 Record.push_back(E->SetterAndMethodRefFlags.getInt());
John McCallb7bd14f2010-12-02 01:19:52 +00001124 Record.push_back(E->isImplicitProperty());
1125 if (E->isImplicitProperty()) {
Richard Smith290d8012016-04-06 17:06:00 +00001126 Record.AddDeclRef(E->getImplicitPropertyGetter());
1127 Record.AddDeclRef(E->getImplicitPropertySetter());
John McCallb7bd14f2010-12-02 01:19:52 +00001128 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001129 Record.AddDeclRef(E->getExplicitProperty());
John McCallb7bd14f2010-12-02 01:19:52 +00001130 }
Richard Smith290d8012016-04-06 17:06:00 +00001131 Record.AddSourceLocation(E->getLocation());
1132 Record.AddSourceLocation(E->getReceiverLocation());
John McCallb7bd14f2010-12-02 01:19:52 +00001133 if (E->isObjectReceiver()) {
1134 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +00001135 Record.AddStmt(E->getBase());
John McCallb7bd14f2010-12-02 01:19:52 +00001136 } else if (E->isSuperReceiver()) {
1137 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001138 Record.AddTypeRef(E->getSuperReceiverType());
John McCallb7bd14f2010-12-02 01:19:52 +00001139 } else {
1140 Record.push_back(2);
Richard Smith290d8012016-04-06 17:06:00 +00001141 Record.AddDeclRef(E->getClassReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001142 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001143
Sebastian Redl539c5062010-08-18 23:57:32 +00001144 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001145}
1146
Ted Kremeneke65b0862012-03-06 20:05:56 +00001147void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1148 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001149 Record.AddSourceLocation(E->getRBracket());
1150 Record.AddStmt(E->getBaseExpr());
1151 Record.AddStmt(E->getKeyExpr());
1152 Record.AddDeclRef(E->getAtIndexMethodDecl());
1153 Record.AddDeclRef(E->setAtIndexMethodDecl());
Fangrui Song6907ce22018-07-30 19:24:48 +00001154
Ted Kremeneke65b0862012-03-06 20:05:56 +00001155 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1156}
1157
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001158void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001159 VisitExpr(E);
1160 Record.push_back(E->getNumArgs());
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001161 Record.push_back(E->getNumStoredSelLocs());
1162 Record.push_back(E->SelLocsKind);
John McCall31168b02011-06-15 23:02:42 +00001163 Record.push_back(E->isDelegateInitCall());
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +00001164 Record.push_back(E->IsImplicit);
Douglas Gregor9a129192010-04-21 00:45:42 +00001165 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1166 switch (E->getReceiverKind()) {
1167 case ObjCMessageExpr::Instance:
Richard Smith290d8012016-04-06 17:06:00 +00001168 Record.AddStmt(E->getInstanceReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001169 break;
1170
1171 case ObjCMessageExpr::Class:
Richard Smith290d8012016-04-06 17:06:00 +00001172 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
Douglas Gregor9a129192010-04-21 00:45:42 +00001173 break;
1174
1175 case ObjCMessageExpr::SuperClass:
1176 case ObjCMessageExpr::SuperInstance:
Richard Smith290d8012016-04-06 17:06:00 +00001177 Record.AddTypeRef(E->getSuperType());
1178 Record.AddSourceLocation(E->getSuperLoc());
Douglas Gregor9a129192010-04-21 00:45:42 +00001179 break;
1180 }
1181
1182 if (E->getMethodDecl()) {
1183 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001184 Record.AddDeclRef(E->getMethodDecl());
Douglas Gregor9a129192010-04-21 00:45:42 +00001185 } else {
1186 Record.push_back(0);
Fangrui Song6907ce22018-07-30 19:24:48 +00001187 Record.AddSelectorRef(E->getSelector());
Douglas Gregor9a129192010-04-21 00:45:42 +00001188 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001189
Richard Smith290d8012016-04-06 17:06:00 +00001190 Record.AddSourceLocation(E->getLeftLoc());
1191 Record.AddSourceLocation(E->getRightLoc());
Chris Lattner1f551822009-04-27 06:20:01 +00001192
1193 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1194 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +00001195 Record.AddStmt(*Arg);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001196
1197 SourceLocation *Locs = E->getStoredSelLocs();
1198 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001199 Record.AddSourceLocation(Locs[i]);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001200
Sebastian Redl539c5062010-08-18 23:57:32 +00001201 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001202}
1203
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001204void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00001205 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001206 Record.AddStmt(S->getElement());
1207 Record.AddStmt(S->getCollection());
1208 Record.AddStmt(S->getBody());
1209 Record.AddSourceLocation(S->getForLoc());
1210 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001211 Code = serialization::STMT_OBJC_FOR_COLLECTION;
Chris Lattner1f551822009-04-27 06:20:01 +00001212}
1213
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001214void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001215 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001216 Record.AddStmt(S->getCatchBody());
1217 Record.AddDeclRef(S->getCatchParamDecl());
1218 Record.AddSourceLocation(S->getAtCatchLoc());
1219 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001220 Code = serialization::STMT_OBJC_CATCH;
Chris Lattner1f551822009-04-27 06:20:01 +00001221}
1222
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001223void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001224 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001225 Record.AddStmt(S->getFinallyBody());
1226 Record.AddSourceLocation(S->getAtFinallyLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001227 Code = serialization::STMT_OBJC_FINALLY;
Chris Lattner1f551822009-04-27 06:20:01 +00001228}
1229
John McCall31168b02011-06-15 23:02:42 +00001230void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001231 VisitStmt(S); // FIXME: no test coverage.
Richard Smith290d8012016-04-06 17:06:00 +00001232 Record.AddStmt(S->getSubStmt());
1233 Record.AddSourceLocation(S->getAtLoc());
John McCall31168b02011-06-15 23:02:42 +00001234 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1235}
1236
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001237void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001238 VisitStmt(S);
Douglas Gregor96c79492010-04-23 22:50:49 +00001239 Record.push_back(S->getNumCatchStmts());
Craig Toppera13603a2014-05-22 05:54:18 +00001240 Record.push_back(S->getFinallyStmt() != nullptr);
Richard Smith290d8012016-04-06 17:06:00 +00001241 Record.AddStmt(S->getTryBody());
Douglas Gregor96c79492010-04-23 22:50:49 +00001242 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001243 Record.AddStmt(S->getCatchStmt(I));
Douglas Gregor96c79492010-04-23 22:50:49 +00001244 if (S->getFinallyStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001245 Record.AddStmt(S->getFinallyStmt());
1246 Record.AddSourceLocation(S->getAtTryLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001247 Code = serialization::STMT_OBJC_AT_TRY;
Chris Lattner1f551822009-04-27 06:20:01 +00001248}
1249
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001250void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001251 VisitStmt(S); // FIXME: no test coverage.
Richard Smith290d8012016-04-06 17:06:00 +00001252 Record.AddStmt(S->getSynchExpr());
1253 Record.AddStmt(S->getSynchBody());
1254 Record.AddSourceLocation(S->getAtSynchronizedLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001255 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
Chris Lattner1f551822009-04-27 06:20:01 +00001256}
1257
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001258void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Roman Lebedev773c3912019-03-12 21:31:00 +00001259 VisitStmt(S); // FIXME: no test coverage.
Richard Smith290d8012016-04-06 17:06:00 +00001260 Record.AddStmt(S->getThrowExpr());
1261 Record.AddSourceLocation(S->getThrowLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001262 Code = serialization::STMT_OBJC_AT_THROW;
Chris Lattner1f551822009-04-27 06:20:01 +00001263}
1264
Ted Kremeneke65b0862012-03-06 20:05:56 +00001265void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1266 VisitExpr(E);
1267 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001268 Record.AddSourceLocation(E->getLocation());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001269 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1270}
1271
Erik Pilkington29099de2016-07-16 00:35:23 +00001272void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1273 VisitExpr(E);
1274 Record.AddSourceRange(E->getSourceRange());
1275 Record.AddVersionTuple(E->getVersion());
1276 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1277}
1278
Chris Lattner1f551822009-04-27 06:20:01 +00001279//===----------------------------------------------------------------------===//
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001280// C++ Expressions and Statements.
1281//===----------------------------------------------------------------------===//
1282
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001283void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001284 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001285 Record.AddSourceLocation(S->getCatchLoc());
1286 Record.AddDeclRef(S->getExceptionDecl());
1287 Record.AddStmt(S->getHandlerBlock());
Sebastian Redl539c5062010-08-18 23:57:32 +00001288 Code = serialization::STMT_CXX_CATCH;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001289}
1290
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001291void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001292 VisitStmt(S);
1293 Record.push_back(S->getNumHandlers());
Richard Smith290d8012016-04-06 17:06:00 +00001294 Record.AddSourceLocation(S->getTryLoc());
1295 Record.AddStmt(S->getTryBlock());
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001296 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001297 Record.AddStmt(S->getHandler(i));
Sebastian Redl539c5062010-08-18 23:57:32 +00001298 Code = serialization::STMT_CXX_TRY;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001299}
1300
Richard Smith02e85f32011-04-14 22:09:26 +00001301void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1302 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001303 Record.AddSourceLocation(S->getForLoc());
1304 Record.AddSourceLocation(S->getCoawaitLoc());
1305 Record.AddSourceLocation(S->getColonLoc());
1306 Record.AddSourceLocation(S->getRParenLoc());
Richard Smith8baa5002018-09-28 18:44:09 +00001307 Record.AddStmt(S->getInit());
Richard Smith290d8012016-04-06 17:06:00 +00001308 Record.AddStmt(S->getRangeStmt());
1309 Record.AddStmt(S->getBeginStmt());
1310 Record.AddStmt(S->getEndStmt());
1311 Record.AddStmt(S->getCond());
1312 Record.AddStmt(S->getInc());
1313 Record.AddStmt(S->getLoopVarStmt());
1314 Record.AddStmt(S->getBody());
Richard Smith02e85f32011-04-14 22:09:26 +00001315 Code = serialization::STMT_CXX_FOR_RANGE;
1316}
1317
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001318void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1319 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001320 Record.AddSourceLocation(S->getKeywordLoc());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001321 Record.push_back(S->isIfExists());
Richard Smith290d8012016-04-06 17:06:00 +00001322 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1323 Record.AddDeclarationNameInfo(S->getNameInfo());
1324 Record.AddStmt(S->getSubStmt());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001325 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1326}
1327
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001328void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001329 VisitCallExpr(E);
1330 Record.push_back(E->getOperator());
Adam Nemet484aa452017-03-27 19:17:25 +00001331 Record.push_back(E->getFPFeatures().getInt());
Bruno Riccifeb19232018-12-21 16:51:57 +00001332 Record.AddSourceRange(E->Range);
Sebastian Redl539c5062010-08-18 23:57:32 +00001333 Code = serialization::EXPR_CXX_OPERATOR_CALL;
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001334}
1335
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001336void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001337 VisitCallExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001338 Code = serialization::EXPR_CXX_MEMBER_CALL;
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001339}
1340
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001341void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001342 VisitExpr(E);
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001343
Argyrios Kyrtzidis30d98f32010-06-24 08:57:09 +00001344 Record.push_back(E->getNumArgs());
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001345 Record.push_back(E->isElidable());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00001346 Record.push_back(E->hadMultipleCandidates());
Richard Smithd59b8322012-12-19 01:39:02 +00001347 Record.push_back(E->isListInitialization());
Richard Smithf8adcdc2014-07-17 05:12:35 +00001348 Record.push_back(E->isStdInitListInitialization());
Douglas Gregor4f4b1862009-12-16 18:50:27 +00001349 Record.push_back(E->requiresZeroInitialization());
Douglas Gregor222cf0e2010-05-15 00:13:29 +00001350 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001351 Record.AddSourceLocation(E->getLocation());
1352 Record.AddDeclRef(E->getConstructor());
Richard Smith290d8012016-04-06 17:06:00 +00001353 Record.AddSourceRange(E->getParenOrBraceRange());
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001354
1355 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1356 Record.AddStmt(E->getArg(I));
1357
Sebastian Redl539c5062010-08-18 23:57:32 +00001358 Code = serialization::EXPR_CXX_CONSTRUCT;
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001359}
1360
Richard Smith5179eb72016-06-28 19:03:57 +00001361void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1362 VisitExpr(E);
1363 Record.AddDeclRef(E->getConstructor());
1364 Record.AddSourceLocation(E->getLocation());
1365 Record.push_back(E->constructsVBase());
1366 Record.push_back(E->inheritedFromVBase());
1367 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1368}
1369
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001370void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001371 VisitCXXConstructExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001372 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001373 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001374}
1375
Douglas Gregore31e6062012-02-07 10:09:13 +00001376void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1377 VisitExpr(E);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001378 Record.push_back(E->NumCaptures);
Richard Smith290d8012016-04-06 17:06:00 +00001379 Record.AddSourceRange(E->IntroducerRange);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001380 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +00001381 Record.AddSourceLocation(E->CaptureDefaultLoc);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001382 Record.push_back(E->ExplicitParams);
1383 Record.push_back(E->ExplicitResultType);
Richard Smith290d8012016-04-06 17:06:00 +00001384 Record.AddSourceLocation(E->ClosingBrace);
Fangrui Song6907ce22018-07-30 19:24:48 +00001385
Douglas Gregor99ae8062012-02-14 17:54:36 +00001386 // Add capture initializers.
1387 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1388 CEnd = E->capture_init_end();
1389 C != CEnd; ++C) {
Richard Smith290d8012016-04-06 17:06:00 +00001390 Record.AddStmt(*C);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001391 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001392
Douglas Gregor99ae8062012-02-14 17:54:36 +00001393 Code = serialization::EXPR_LAMBDA;
Douglas Gregore31e6062012-02-07 10:09:13 +00001394}
1395
Richard Smithcc1b96d2013-06-12 22:31:48 +00001396void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1397 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001398 Record.AddStmt(E->getSubExpr());
Richard Smithcc1b96d2013-06-12 22:31:48 +00001399 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1400}
1401
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001402void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001403 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001404 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1405 Record.AddSourceRange(E->getAngleBrackets());
Sam Weinigd01101e2010-01-16 21:21:01 +00001406}
1407
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001408void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001409 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001410 Code = serialization::EXPR_CXX_STATIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001411}
1412
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001413void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001414 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001415 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001416}
1417
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001418void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001419 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001420 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001421}
1422
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001423void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001424 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001425 Code = serialization::EXPR_CXX_CONST_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001426}
1427
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001428void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001429 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001430 Record.AddSourceLocation(E->getLParenLoc());
1431 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001432 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001433}
1434
Richard Smithc67fdd42012-03-07 08:35:16 +00001435void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1436 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001437 Record.AddSourceLocation(E->UDSuffixLoc);
Richard Smithc67fdd42012-03-07 08:35:16 +00001438 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1439}
1440
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001441void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001442 VisitExpr(E);
1443 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001444 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001445 Code = serialization::EXPR_CXX_BOOL_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001446}
1447
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001448void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001449 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001450 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001451 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001452}
1453
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001454void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001455 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001456 Record.AddSourceRange(E->getSourceRange());
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001457 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001458 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001459 Code = serialization::EXPR_CXX_TYPEID_TYPE;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001460 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001461 Record.AddStmt(E->getExprOperand());
Sebastian Redl539c5062010-08-18 23:57:32 +00001462 Code = serialization::EXPR_CXX_TYPEID_EXPR;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001463 }
1464}
1465
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001466void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner98267332010-05-09 06:15:05 +00001467 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001468 Record.AddSourceLocation(E->getLocation());
Chris Lattner98267332010-05-09 06:15:05 +00001469 Record.push_back(E->isImplicit());
Sebastian Redl539c5062010-08-18 23:57:32 +00001470 Code = serialization::EXPR_CXX_THIS;
Chris Lattner98267332010-05-09 06:15:05 +00001471}
1472
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001473void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001474 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001475 Record.AddSourceLocation(E->getThrowLoc());
1476 Record.AddStmt(E->getSubExpr());
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001477 Record.push_back(E->isThrownVariableInScope());
Sebastian Redl539c5062010-08-18 23:57:32 +00001478 Code = serialization::EXPR_CXX_THROW;
Chris Lattner98267332010-05-09 06:15:05 +00001479}
1480
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001481void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001482 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001483 Record.AddDeclRef(E->getParam());
Eric Fiselier708afb52019-05-16 21:04:15 +00001484 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
Richard Smith290d8012016-04-06 17:06:00 +00001485 Record.AddSourceLocation(E->getUsedLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001486 Code = serialization::EXPR_CXX_DEFAULT_ARG;
Chris Lattnere2437f42010-05-09 06:40:08 +00001487}
1488
Richard Smith852c9db2013-04-20 22:23:05 +00001489void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1490 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001491 Record.AddDeclRef(E->getField());
Eric Fiselier708afb52019-05-16 21:04:15 +00001492 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
Richard Smith290d8012016-04-06 17:06:00 +00001493 Record.AddSourceLocation(E->getExprLoc());
Richard Smith852c9db2013-04-20 22:23:05 +00001494 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1495}
1496
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001497void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001498 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001499 Record.AddCXXTemporary(E->getTemporary());
1500 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +00001501 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
Chris Lattnercba86142010-05-10 00:25:06 +00001502}
1503
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001504void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001505 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001506 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1507 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001508 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001509}
1510
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001511void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001512 VisitExpr(E);
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001513
Sebastian Redlc3a3c602012-02-16 11:35:52 +00001514 Record.push_back(E->isArray());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001515 Record.push_back(E->hasInitializer());
1516 Record.push_back(E->getNumPlacementArgs());
1517 Record.push_back(E->isParenTypeId());
1518
1519 Record.push_back(E->isGlobalNew());
Richard Smithb2f0f052016-10-10 18:54:32 +00001520 Record.push_back(E->passAlignment());
Sebastian Redl6047f072012-02-16 12:22:20 +00001521 Record.push_back(E->doesUsualArrayDeleteWantSize());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001522 Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
1523
Richard Smith290d8012016-04-06 17:06:00 +00001524 Record.AddDeclRef(E->getOperatorNew());
1525 Record.AddDeclRef(E->getOperatorDelete());
1526 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001527 if (E->isParenTypeId())
1528 Record.AddSourceRange(E->getTypeIdParens());
Richard Smith290d8012016-04-06 17:06:00 +00001529 Record.AddSourceRange(E->getSourceRange());
1530 Record.AddSourceRange(E->getDirectInitRange());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001531
1532 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
1533 I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001534 Record.AddStmt(*I);
Sebastian Redl6047f072012-02-16 12:22:20 +00001535
Sebastian Redl539c5062010-08-18 23:57:32 +00001536 Code = serialization::EXPR_CXX_NEW;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001537}
1538
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001539void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001540 VisitExpr(E);
1541 Record.push_back(E->isGlobalDelete());
1542 Record.push_back(E->isArrayForm());
Argyrios Kyrtzidis14ec9f62010-09-13 20:15:54 +00001543 Record.push_back(E->isArrayFormAsWritten());
John McCall284c48f2011-01-27 09:37:56 +00001544 Record.push_back(E->doesUsualArrayDeleteWantSize());
Richard Smith290d8012016-04-06 17:06:00 +00001545 Record.AddDeclRef(E->getOperatorDelete());
1546 Record.AddStmt(E->getArgument());
Bruno Ricci91728fc2018-12-03 12:32:32 +00001547 Record.AddSourceLocation(E->getBeginLoc());
Fangrui Song6907ce22018-07-30 19:24:48 +00001548
Sebastian Redl539c5062010-08-18 23:57:32 +00001549 Code = serialization::EXPR_CXX_DELETE;
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001550}
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001551
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001552void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001553 VisitExpr(E);
1554
Richard Smith290d8012016-04-06 17:06:00 +00001555 Record.AddStmt(E->getBase());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001556 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001557 Record.AddSourceLocation(E->getOperatorLoc());
1558 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1559 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1560 Record.AddSourceLocation(E->getColonColonLoc());
1561 Record.AddSourceLocation(E->getTildeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001562
1563 // PseudoDestructorTypeStorage.
Richard Smith290d8012016-04-06 17:06:00 +00001564 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001565 if (E->getDestroyedTypeIdentifier())
Richard Smith290d8012016-04-06 17:06:00 +00001566 Record.AddSourceLocation(E->getDestroyedTypeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001567 else
Richard Smith290d8012016-04-06 17:06:00 +00001568 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001569
Sebastian Redl539c5062010-08-18 23:57:32 +00001570 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001571}
1572
John McCall5d413782010-12-06 08:20:24 +00001573void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001574 VisitExpr(E);
John McCall28fc7092011-11-10 05:35:25 +00001575 Record.push_back(E->getNumObjects());
1576 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001577 Record.AddDeclRef(E->getObject(i));
Tim Shen4a05bb82016-06-21 20:29:17 +00001578
1579 Record.push_back(E->cleanupsHaveSideEffects());
Richard Smith290d8012016-04-06 17:06:00 +00001580 Record.AddStmt(E->getSubExpr());
John McCall5d413782010-12-06 08:20:24 +00001581 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
Chris Lattnercba86142010-05-10 00:25:06 +00001582}
1583
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001584void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
1585 CXXDependentScopeMemberExpr *E) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001586 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001587
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001588 // Don't emit anything here (or if you do you will have to update
1589 // the corresponding deserialization function).
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001590
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001591 Record.push_back(E->hasTemplateKWAndArgsInfo());
1592 Record.push_back(E->getNumTemplateArgs());
1593 Record.push_back(E->hasFirstQualifierFoundInScope());
1594
1595 if (E->hasTemplateKWAndArgsInfo()) {
James Y Knighte7d82282015-12-29 18:15:14 +00001596 const ASTTemplateKWAndArgsInfo &ArgInfo =
1597 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
James Y Knighte7d82282015-12-29 18:15:14 +00001598 AddTemplateKWAndArgsInfo(ArgInfo,
1599 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001600 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00001601
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001602 Record.push_back(E->isArrow());
1603 Record.AddSourceLocation(E->getOperatorLoc());
1604 Record.AddTypeRef(E->getBaseType());
1605 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001606 if (!E->isImplicitAccess())
Richard Smith290d8012016-04-06 17:06:00 +00001607 Record.AddStmt(E->getBase());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001608 else
Richard Smith290d8012016-04-06 17:06:00 +00001609 Record.AddStmt(nullptr);
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001610
1611 if (E->hasFirstQualifierFoundInScope())
1612 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1613
Richard Smith290d8012016-04-06 17:06:00 +00001614 Record.AddDeclarationNameInfo(E->MemberNameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001615 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001616}
1617
1618void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001619ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001620 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001621
1622 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
Douglas Gregor87866ce2011-02-04 12:01:24 +00001623 // emitted first.
Abramo Bagnara7945c982012-01-27 09:46:47 +00001624
Bruno Ricci49ee9642019-01-07 14:27:04 +00001625 Record.push_back(E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
1626 if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001627 const ASTTemplateKWAndArgsInfo &ArgInfo =
1628 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1629 Record.push_back(ArgInfo.NumTemplateArgs);
1630 AddTemplateKWAndArgsInfo(ArgInfo,
1631 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001632 }
1633
Richard Smith290d8012016-04-06 17:06:00 +00001634 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1635 Record.AddDeclarationNameInfo(E->NameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001636 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001637}
1638
1639void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001640ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001641 VisitExpr(E);
1642 Record.push_back(E->arg_size());
1643 for (CXXUnresolvedConstructExpr::arg_iterator
1644 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
Richard Smith290d8012016-04-06 17:06:00 +00001645 Record.AddStmt(*ArgI);
1646 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1647 Record.AddSourceLocation(E->getLParenLoc());
1648 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001649 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001650}
Chris Lattner98267332010-05-09 06:15:05 +00001651
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001652void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001653 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001654
Bruno Riccid7628d92019-01-09 15:43:19 +00001655 Record.push_back(E->getNumDecls());
1656 Record.push_back(E->hasTemplateKWAndArgsInfo());
1657 if (E->hasTemplateKWAndArgsInfo()) {
James Y Knighte7d82282015-12-29 18:15:14 +00001658 const ASTTemplateKWAndArgsInfo &ArgInfo =
1659 *E->getTrailingASTTemplateKWAndArgsInfo();
1660 Record.push_back(ArgInfo.NumTemplateArgs);
1661 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001662 }
1663
Bruno Riccid7628d92019-01-09 15:43:19 +00001664 for (OverloadExpr::decls_iterator OvI = E->decls_begin(),
1665 OvE = E->decls_end();
1666 OvI != OvE; ++OvI) {
Richard Smith290d8012016-04-06 17:06:00 +00001667 Record.AddDeclRef(OvI.getDecl());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001668 Record.push_back(OvI.getAccess());
1669 }
1670
Bruno Riccid7628d92019-01-09 15:43:19 +00001671 Record.AddDeclarationNameInfo(E->getNameInfo());
Richard Smith290d8012016-04-06 17:06:00 +00001672 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001673}
1674
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001675void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001676 VisitOverloadExpr(E);
1677 Record.push_back(E->isArrow());
1678 Record.push_back(E->hasUnresolvedUsing());
Richard Smith290d8012016-04-06 17:06:00 +00001679 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1680 Record.AddTypeRef(E->getBaseType());
1681 Record.AddSourceLocation(E->getOperatorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001682 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001683}
1684
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001685void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001686 VisitOverloadExpr(E);
1687 Record.push_back(E->requiresADL());
1688 Record.push_back(E->isOverloaded());
Richard Smith290d8012016-04-06 17:06:00 +00001689 Record.AddDeclRef(E->getNamingClass());
Sebastian Redl539c5062010-08-18 23:57:32 +00001690 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001691}
1692
Douglas Gregor29c42f22012-02-24 07:38:34 +00001693void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1694 VisitExpr(E);
1695 Record.push_back(E->TypeTraitExprBits.NumArgs);
1696 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1697 Record.push_back(E->TypeTraitExprBits.Value);
Richard Smith290d8012016-04-06 17:06:00 +00001698 Record.AddSourceRange(E->getSourceRange());
Douglas Gregor29c42f22012-02-24 07:38:34 +00001699 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001700 Record.AddTypeSourceInfo(E->getArg(I));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001701 Code = serialization::EXPR_TYPE_TRAIT;
1702}
1703
John Wiegley6242b6a2011-04-28 00:16:57 +00001704void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1705 VisitExpr(E);
1706 Record.push_back(E->getTrait());
1707 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001708 Record.AddSourceRange(E->getSourceRange());
1709 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
Aleksei Sidorina693b372016-09-28 10:16:56 +00001710 Record.AddStmt(E->getDimensionExpression());
John Wiegley6242b6a2011-04-28 00:16:57 +00001711 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1712}
1713
John Wiegleyf9f65842011-04-25 06:54:41 +00001714void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1715 VisitExpr(E);
1716 Record.push_back(E->getTrait());
1717 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001718 Record.AddSourceRange(E->getSourceRange());
1719 Record.AddStmt(E->getQueriedExpression());
John Wiegleyf9f65842011-04-25 06:54:41 +00001720 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1721}
1722
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001723void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1724 VisitExpr(E);
1725 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001726 Record.AddSourceRange(E->getSourceRange());
1727 Record.AddStmt(E->getOperand());
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001728 Code = serialization::EXPR_CXX_NOEXCEPT;
1729}
1730
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001731void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1732 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001733 Record.AddSourceLocation(E->getEllipsisLoc());
Douglas Gregorb8840002011-01-14 21:20:45 +00001734 Record.push_back(E->NumExpansions);
Richard Smith290d8012016-04-06 17:06:00 +00001735 Record.AddStmt(E->getPattern());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001736 Code = serialization::EXPR_PACK_EXPANSION;
1737}
1738
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001739void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1740 VisitExpr(E);
Richard Smithd784e682015-09-23 21:41:42 +00001741 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1742 : 0);
Richard Smith290d8012016-04-06 17:06:00 +00001743 Record.AddSourceLocation(E->OperatorLoc);
1744 Record.AddSourceLocation(E->PackLoc);
1745 Record.AddSourceLocation(E->RParenLoc);
1746 Record.AddDeclRef(E->Pack);
Richard Smithd784e682015-09-23 21:41:42 +00001747 if (E->isPartiallySubstituted()) {
1748 for (const auto &TA : E->getPartialArguments())
Richard Smith290d8012016-04-06 17:06:00 +00001749 Record.AddTemplateArgument(TA);
Richard Smithd784e682015-09-23 21:41:42 +00001750 } else if (!E->isValueDependent()) {
1751 Record.push_back(E->getPackLength());
1752 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001753 Code = serialization::EXPR_SIZEOF_PACK;
1754}
1755
John McCallfa194042011-07-15 07:00:14 +00001756void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1757 SubstNonTypeTemplateParmExpr *E) {
1758 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001759 Record.AddDeclRef(E->getParameter());
1760 Record.AddSourceLocation(E->getNameLoc());
1761 Record.AddStmt(E->getReplacement());
John McCallfa194042011-07-15 07:00:14 +00001762 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1763}
1764
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001765void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1766 SubstNonTypeTemplateParmPackExpr *E) {
1767 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001768 Record.AddDeclRef(E->getParameterPack());
1769 Record.AddTemplateArgument(E->getArgumentPack());
1770 Record.AddSourceLocation(E->getParameterPackLocation());
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001771 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1772}
1773
Richard Smithb15fe3a2012-09-12 00:56:43 +00001774void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1775 VisitExpr(E);
1776 Record.push_back(E->getNumExpansions());
Richard Smith290d8012016-04-06 17:06:00 +00001777 Record.AddDeclRef(E->getParameterPack());
1778 Record.AddSourceLocation(E->getParameterPackLocation());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001779 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1780 I != End; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001781 Record.AddDeclRef(*I);
Richard Smithb15fe3a2012-09-12 00:56:43 +00001782 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1783}
1784
Douglas Gregorfe314812011-06-21 17:03:29 +00001785void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1786 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001787 Record.AddStmt(E->getTemporary());
1788 Record.AddDeclRef(E->getExtendingDecl());
David Majnemerdaff3702014-05-01 17:50:17 +00001789 Record.push_back(E->getManglingNumber());
Douglas Gregorfe314812011-06-21 17:03:29 +00001790 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1791}
1792
Richard Smith0f0af192014-11-08 05:07:16 +00001793void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1794 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001795 Record.AddSourceLocation(E->LParenLoc);
1796 Record.AddSourceLocation(E->EllipsisLoc);
1797 Record.AddSourceLocation(E->RParenLoc);
Richard Smithc7214f62019-05-13 08:31:14 +00001798 Record.push_back(E->NumExpansions);
Richard Smith290d8012016-04-06 17:06:00 +00001799 Record.AddStmt(E->SubExprs[0]);
1800 Record.AddStmt(E->SubExprs[1]);
Richard Smith0f0af192014-11-08 05:07:16 +00001801 Record.push_back(E->Opcode);
1802 Code = serialization::EXPR_CXX_FOLD;
1803}
1804
John McCall8d69a212010-11-15 23:31:06 +00001805void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1806 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001807 Record.AddStmt(E->getSourceExpr());
1808 Record.AddSourceLocation(E->getLocation());
Akira Hatanaka797afe32018-03-20 01:47:58 +00001809 Record.push_back(E->isUnique());
John McCall8d69a212010-11-15 23:31:06 +00001810 Code = serialization::EXPR_OPAQUE_VALUE;
1811}
1812
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001813void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1814 VisitExpr(E);
1815 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
Davide Italiano04839a52016-01-30 08:03:54 +00001816 llvm_unreachable("Cannot write TypoExpr nodes");
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001817}
1818
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001819//===----------------------------------------------------------------------===//
Peter Collingbourne41f85462011-02-09 21:07:24 +00001820// CUDA Expressions and Statements.
1821//===----------------------------------------------------------------------===//
1822
1823void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1824 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001825 Record.AddStmt(E->getConfig());
Peter Collingbourne41f85462011-02-09 21:07:24 +00001826 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1827}
1828
1829//===----------------------------------------------------------------------===//
Tanya Lattner55808c12011-06-04 00:47:47 +00001830// OpenCL Expressions and Statements.
1831//===----------------------------------------------------------------------===//
1832void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1833 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001834 Record.AddSourceLocation(E->getBuiltinLoc());
1835 Record.AddSourceLocation(E->getRParenLoc());
1836 Record.AddStmt(E->getSrcExpr());
Tanya Lattner55808c12011-06-04 00:47:47 +00001837 Code = serialization::EXPR_ASTYPE;
1838}
1839
1840//===----------------------------------------------------------------------===//
John McCallfa194042011-07-15 07:00:14 +00001841// Microsoft Expressions and Statements.
1842//===----------------------------------------------------------------------===//
John McCall5e77d762013-04-16 07:28:30 +00001843void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1844 VisitExpr(E);
1845 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001846 Record.AddStmt(E->getBaseExpr());
1847 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1848 Record.AddSourceLocation(E->getMemberLoc());
1849 Record.AddDeclRef(E->getPropertyDecl());
John McCall5e77d762013-04-16 07:28:30 +00001850 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1851}
1852
Alexey Bataevf7630272015-11-25 12:01:00 +00001853void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1854 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001855 Record.AddStmt(E->getBase());
1856 Record.AddStmt(E->getIdx());
1857 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataevf7630272015-11-25 12:01:00 +00001858 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1859}
1860
John McCallfa194042011-07-15 07:00:14 +00001861void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1862 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001863 Record.AddSourceRange(E->getSourceRange());
1864 Record.AddString(E->getUuidStr());
John McCallfa194042011-07-15 07:00:14 +00001865 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001866 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
John McCallfa194042011-07-15 07:00:14 +00001867 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1868 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001869 Record.AddStmt(E->getExprOperand());
John McCallfa194042011-07-15 07:00:14 +00001870 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1871 }
1872}
1873
1874void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1875 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001876 Record.AddSourceLocation(S->getExceptLoc());
1877 Record.AddStmt(S->getFilterExpr());
1878 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001879 Code = serialization::STMT_SEH_EXCEPT;
1880}
1881
1882void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1883 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001884 Record.AddSourceLocation(S->getFinallyLoc());
1885 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001886 Code = serialization::STMT_SEH_FINALLY;
1887}
1888
1889void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1890 VisitStmt(S);
1891 Record.push_back(S->getIsCXXTry());
Richard Smith290d8012016-04-06 17:06:00 +00001892 Record.AddSourceLocation(S->getTryLoc());
1893 Record.AddStmt(S->getTryBlock());
1894 Record.AddStmt(S->getHandler());
John McCallfa194042011-07-15 07:00:14 +00001895 Code = serialization::STMT_SEH_TRY;
1896}
1897
Nico Weber9b982072014-07-07 00:12:30 +00001898void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1899 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001900 Record.AddSourceLocation(S->getLeaveLoc());
Nico Weber9b982072014-07-07 00:12:30 +00001901 Code = serialization::STMT_SEH_LEAVE;
1902}
1903
John McCallfa194042011-07-15 07:00:14 +00001904//===----------------------------------------------------------------------===//
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001905// OpenMP Directives.
1906//===----------------------------------------------------------------------===//
1907void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001908 Record.AddSourceLocation(E->getBeginLoc());
Stephen Kelly1c301dc2018-08-09 21:09:38 +00001909 Record.AddSourceLocation(E->getEndLoc());
Richard Smith290d8012016-04-06 17:06:00 +00001910 OMPClauseWriter ClauseWriter(Record);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001911 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
1912 ClauseWriter.writeClause(E->getClause(i));
1913 }
Alexey Bataev68446b72014-07-18 07:47:19 +00001914 if (E->hasAssociatedStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001915 Record.AddStmt(E->getAssociatedStmt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001916}
1917
Alexander Musman3aaab662014-08-19 11:27:13 +00001918void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
1919 VisitStmt(D);
1920 Record.push_back(D->getNumClauses());
1921 Record.push_back(D->getCollapsedNumber());
1922 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001923 Record.AddStmt(D->getIterationVariable());
1924 Record.AddStmt(D->getLastIteration());
1925 Record.AddStmt(D->getCalcLastIteration());
1926 Record.AddStmt(D->getPreCond());
1927 Record.AddStmt(D->getCond());
1928 Record.AddStmt(D->getInit());
1929 Record.AddStmt(D->getInc());
1930 Record.AddStmt(D->getPreInits());
Alexey Bataev3392d762016-02-16 11:18:12 +00001931 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001932 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
1933 isOpenMPDistributeDirective(D->getDirectiveKind())) {
Richard Smith290d8012016-04-06 17:06:00 +00001934 Record.AddStmt(D->getIsLastIterVariable());
1935 Record.AddStmt(D->getLowerBoundVariable());
1936 Record.AddStmt(D->getUpperBoundVariable());
1937 Record.AddStmt(D->getStrideVariable());
1938 Record.AddStmt(D->getEnsureUpperBound());
1939 Record.AddStmt(D->getNextLowerBound());
1940 Record.AddStmt(D->getNextUpperBound());
Alexey Bataev8b427062016-05-25 12:36:08 +00001941 Record.AddStmt(D->getNumIterations());
Alexander Musmanc6388682014-12-15 07:07:06 +00001942 }
Carlo Bertolli9925f152016-06-27 14:55:37 +00001943 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
1944 Record.AddStmt(D->getPrevLowerBoundVariable());
1945 Record.AddStmt(D->getPrevUpperBoundVariable());
Carlo Bertolli8429d812017-02-17 21:29:13 +00001946 Record.AddStmt(D->getDistInc());
1947 Record.AddStmt(D->getPrevEnsureUpperBound());
Carlo Bertolliffafe102017-04-20 00:39:39 +00001948 Record.AddStmt(D->getCombinedLowerBoundVariable());
1949 Record.AddStmt(D->getCombinedUpperBoundVariable());
1950 Record.AddStmt(D->getCombinedEnsureUpperBound());
1951 Record.AddStmt(D->getCombinedInit());
1952 Record.AddStmt(D->getCombinedCond());
1953 Record.AddStmt(D->getCombinedNextLowerBound());
1954 Record.AddStmt(D->getCombinedNextUpperBound());
Gheorghe-Teodor Berceae9256762018-10-29 15:45:47 +00001955 Record.AddStmt(D->getCombinedDistCond());
1956 Record.AddStmt(D->getCombinedParForInDistCond());
Carlo Bertolli9925f152016-06-27 14:55:37 +00001957 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001958 for (auto I : D->counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001959 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001960 }
Alexey Bataeva8899172015-08-06 12:30:57 +00001961 for (auto I : D->private_counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001962 Record.AddStmt(I);
Alexey Bataeva8899172015-08-06 12:30:57 +00001963 }
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001964 for (auto I : D->inits()) {
Richard Smith290d8012016-04-06 17:06:00 +00001965 Record.AddStmt(I);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001966 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001967 for (auto I : D->updates()) {
Richard Smith290d8012016-04-06 17:06:00 +00001968 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001969 }
1970 for (auto I : D->finals()) {
Richard Smith290d8012016-04-06 17:06:00 +00001971 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001972 }
Alexander Musman3aaab662014-08-19 11:27:13 +00001973}
1974
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001975void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001976 VisitStmt(D);
1977 Record.push_back(D->getNumClauses());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001978 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001979 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001980 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
1981}
1982
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001983void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001984 VisitOMPLoopDirective(D);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001985 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
1986}
1987
Alexey Bataevf29276e2014-06-18 04:14:57 +00001988void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001989 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001990 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevf29276e2014-06-18 04:14:57 +00001991 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
1992}
1993
Alexander Musmanf82886e2014-09-18 05:12:34 +00001994void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
1995 VisitOMPLoopDirective(D);
1996 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
1997}
1998
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001999void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2000 VisitStmt(D);
2001 Record.push_back(D->getNumClauses());
2002 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002003 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00002004 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2005}
2006
Alexey Bataev1e0498a2014-06-26 08:21:58 +00002007void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2008 VisitStmt(D);
2009 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002010 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev1e0498a2014-06-26 08:21:58 +00002011 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2012}
2013
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00002014void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2015 VisitStmt(D);
2016 Record.push_back(D->getNumClauses());
2017 VisitOMPExecutableDirective(D);
2018 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2019}
2020
Alexander Musman80c22892014-07-17 08:54:58 +00002021void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2022 VisitStmt(D);
2023 VisitOMPExecutableDirective(D);
2024 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2025}
2026
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002027void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2028 VisitStmt(D);
Alexey Bataev28c75412015-12-15 08:19:24 +00002029 Record.push_back(D->getNumClauses());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002030 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00002031 Record.AddDeclarationNameInfo(D->getDirectiveName());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002032 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2033}
2034
Alexey Bataev4acb8592014-07-07 13:01:15 +00002035void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00002036 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002037 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev4acb8592014-07-07 13:01:15 +00002038 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2039}
2040
Alexander Musmane4e893b2014-09-23 09:33:00 +00002041void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2042 OMPParallelForSimdDirective *D) {
2043 VisitOMPLoopDirective(D);
2044 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2045}
2046
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002047void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2048 OMPParallelSectionsDirective *D) {
2049 VisitStmt(D);
2050 Record.push_back(D->getNumClauses());
2051 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002052 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002053 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2054}
2055
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002056void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2057 VisitStmt(D);
2058 Record.push_back(D->getNumClauses());
2059 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002060 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002061 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2062}
2063
Alexey Bataev0162e452014-07-22 10:10:35 +00002064void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2065 VisitStmt(D);
2066 Record.push_back(D->getNumClauses());
2067 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00002068 Record.AddStmt(D->getX());
2069 Record.AddStmt(D->getV());
2070 Record.AddStmt(D->getExpr());
2071 Record.AddStmt(D->getUpdateExpr());
Alexey Bataevb4505a72015-03-30 05:20:59 +00002072 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
Alexey Bataevb78ca832015-04-01 03:33:17 +00002073 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
Alexey Bataev0162e452014-07-22 10:10:35 +00002074 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2075}
2076
Alexey Bataev0bd520b2014-09-19 08:19:49 +00002077void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2078 VisitStmt(D);
2079 Record.push_back(D->getNumClauses());
2080 VisitOMPExecutableDirective(D);
2081 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2082}
2083
Michael Wong65f367f2015-07-21 13:44:28 +00002084void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2085 VisitStmt(D);
2086 Record.push_back(D->getNumClauses());
2087 VisitOMPExecutableDirective(D);
2088 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2089}
2090
Samuel Antaodf67fc42016-01-19 19:15:56 +00002091void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2092 OMPTargetEnterDataDirective *D) {
2093 VisitStmt(D);
2094 Record.push_back(D->getNumClauses());
2095 VisitOMPExecutableDirective(D);
2096 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2097}
2098
Samuel Antao72590762016-01-19 20:04:50 +00002099void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2100 OMPTargetExitDataDirective *D) {
2101 VisitStmt(D);
2102 Record.push_back(D->getNumClauses());
2103 VisitOMPExecutableDirective(D);
2104 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2105}
2106
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00002107void ASTStmtWriter::VisitOMPTargetParallelDirective(
2108 OMPTargetParallelDirective *D) {
2109 VisitStmt(D);
2110 Record.push_back(D->getNumClauses());
2111 VisitOMPExecutableDirective(D);
2112 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2113}
2114
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00002115void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2116 OMPTargetParallelForDirective *D) {
2117 VisitOMPLoopDirective(D);
2118 Record.push_back(D->hasCancel() ? 1 : 0);
2119 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2120}
2121
Alexey Bataev68446b72014-07-18 07:47:19 +00002122void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2123 VisitStmt(D);
2124 VisitOMPExecutableDirective(D);
2125 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2126}
2127
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00002128void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2129 VisitStmt(D);
2130 VisitOMPExecutableDirective(D);
2131 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2132}
2133
Alexey Bataev2df347a2014-07-18 10:17:07 +00002134void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2135 VisitStmt(D);
2136 VisitOMPExecutableDirective(D);
2137 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2138}
2139
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002140void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2141 VisitStmt(D);
Alexey Bataev169d96a2017-07-18 20:17:46 +00002142 Record.push_back(D->getNumClauses());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002143 VisitOMPExecutableDirective(D);
Alexey Bataev3b1b8952017-07-25 15:53:26 +00002144 Record.AddStmt(D->getReductionRef());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002145 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2146}
2147
Alexey Bataev6125da92014-07-21 11:26:11 +00002148void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2149 VisitStmt(D);
2150 Record.push_back(D->getNumClauses());
2151 VisitOMPExecutableDirective(D);
2152 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2153}
2154
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002155void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2156 VisitStmt(D);
Alexey Bataev346265e2015-09-25 10:37:12 +00002157 Record.push_back(D->getNumClauses());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002158 VisitOMPExecutableDirective(D);
2159 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2160}
2161
Alexey Bataev13314bf2014-10-09 04:18:56 +00002162void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2163 VisitStmt(D);
2164 Record.push_back(D->getNumClauses());
2165 VisitOMPExecutableDirective(D);
2166 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2167}
2168
Alexey Bataev6d4ed052015-07-01 06:57:41 +00002169void ASTStmtWriter::VisitOMPCancellationPointDirective(
2170 OMPCancellationPointDirective *D) {
2171 VisitStmt(D);
2172 VisitOMPExecutableDirective(D);
2173 Record.push_back(D->getCancelRegion());
2174 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2175}
2176
Alexey Bataev80909872015-07-02 11:25:17 +00002177void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2178 VisitStmt(D);
Alexey Bataev87933c72015-09-18 08:07:34 +00002179 Record.push_back(D->getNumClauses());
Alexey Bataev80909872015-07-02 11:25:17 +00002180 VisitOMPExecutableDirective(D);
2181 Record.push_back(D->getCancelRegion());
2182 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2183}
2184
Alexey Bataev49f6e782015-12-01 04:18:41 +00002185void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2186 VisitOMPLoopDirective(D);
2187 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2188}
2189
Alexey Bataev0a6ed842015-12-03 09:40:15 +00002190void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2191 VisitOMPLoopDirective(D);
2192 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2193}
2194
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00002195void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2196 VisitOMPLoopDirective(D);
2197 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2198}
2199
Samuel Antao686c70c2016-05-26 17:30:50 +00002200void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2201 VisitStmt(D);
2202 Record.push_back(D->getNumClauses());
2203 VisitOMPExecutableDirective(D);
2204 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2205}
2206
Carlo Bertolli9925f152016-06-27 14:55:37 +00002207void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2208 OMPDistributeParallelForDirective *D) {
2209 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002210 Record.push_back(D->hasCancel() ? 1 : 0);
Carlo Bertolli9925f152016-06-27 14:55:37 +00002211 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2212}
2213
Kelvin Li4a39add2016-07-05 05:00:15 +00002214void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2215 OMPDistributeParallelForSimdDirective *D) {
2216 VisitOMPLoopDirective(D);
2217 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2218}
2219
Kelvin Li787f3fc2016-07-06 04:45:38 +00002220void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2221 OMPDistributeSimdDirective *D) {
2222 VisitOMPLoopDirective(D);
2223 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2224}
2225
Kelvin Lia579b912016-07-14 02:54:56 +00002226void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2227 OMPTargetParallelForSimdDirective *D) {
2228 VisitOMPLoopDirective(D);
2229 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2230}
2231
Kelvin Li986330c2016-07-20 22:57:10 +00002232void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2233 VisitOMPLoopDirective(D);
2234 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2235}
2236
Kelvin Li02532872016-08-05 14:37:37 +00002237void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2238 OMPTeamsDistributeDirective *D) {
2239 VisitOMPLoopDirective(D);
2240 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2241}
2242
Kelvin Li4e325f72016-10-25 12:50:55 +00002243void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2244 OMPTeamsDistributeSimdDirective *D) {
2245 VisitOMPLoopDirective(D);
2246 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2247}
2248
Kelvin Li579e41c2016-11-30 23:51:03 +00002249void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2250 OMPTeamsDistributeParallelForSimdDirective *D) {
2251 VisitOMPLoopDirective(D);
2252 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2253}
2254
Kelvin Li7ade93f2016-12-09 03:24:30 +00002255void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2256 OMPTeamsDistributeParallelForDirective *D) {
2257 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002258 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li7ade93f2016-12-09 03:24:30 +00002259 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2260}
2261
Kelvin Libf594a52016-12-17 05:48:59 +00002262void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2263 VisitStmt(D);
2264 Record.push_back(D->getNumClauses());
2265 VisitOMPExecutableDirective(D);
2266 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2267}
2268
Kelvin Li83c451e2016-12-25 04:52:54 +00002269void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2270 OMPTargetTeamsDistributeDirective *D) {
2271 VisitOMPLoopDirective(D);
2272 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2273}
2274
Kelvin Li80e8f562016-12-29 22:16:30 +00002275void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2276 OMPTargetTeamsDistributeParallelForDirective *D) {
2277 VisitOMPLoopDirective(D);
Alexey Bataev16e79882017-11-22 21:12:03 +00002278 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li80e8f562016-12-29 22:16:30 +00002279 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2280}
2281
Kelvin Li1851df52017-01-03 05:23:48 +00002282void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2283 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2284 VisitOMPLoopDirective(D);
2285 Code = serialization::
2286 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2287}
2288
Kelvin Lida681182017-01-10 18:08:18 +00002289void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2290 OMPTargetTeamsDistributeSimdDirective *D) {
2291 VisitOMPLoopDirective(D);
2292 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2293}
2294
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002295//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002296// ASTWriter Implementation
Chris Lattner1f551822009-04-27 06:20:01 +00002297//===----------------------------------------------------------------------===//
2298
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002299unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002300 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002301 "SwitchCase recorded twice");
2302 unsigned NextID = SwitchCaseIDs.size();
2303 SwitchCaseIDs[S] = NextID;
2304 return NextID;
2305}
2306
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002307unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002308 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002309 "SwitchCase hasn't been seen yet");
2310 return SwitchCaseIDs[S];
2311}
2312
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002313void ASTWriter::ClearSwitchCaseIDs() {
2314 SwitchCaseIDs.clear();
2315}
2316
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002317/// Write the given substatement or subexpression to the
Chris Lattner1f551822009-04-27 06:20:01 +00002318/// bitstream.
Richard Smithf50422a2016-04-06 20:12:34 +00002319void ASTWriter::WriteSubStmt(Stmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00002320 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002321 ASTStmtWriter Writer(*this, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002322 ++NumStatements;
Fangrui Song6907ce22018-07-30 19:24:48 +00002323
Chris Lattner1f551822009-04-27 06:20:01 +00002324 if (!S) {
Sebastian Redl539c5062010-08-18 23:57:32 +00002325 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002326 return;
2327 }
Mike Stump11289f42009-09-09 15:08:12 +00002328
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002329 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2330 if (I != SubStmtEntries.end()) {
2331 Record.push_back(I->second);
2332 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2333 return;
2334 }
2335
2336#ifndef NDEBUG
2337 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2338
2339 struct ParentStmtInserterRAII {
2340 Stmt *S;
2341 llvm::DenseSet<Stmt *> &ParentStmts;
2342
2343 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2344 : S(S), ParentStmts(ParentStmts) {
2345 ParentStmts.insert(S);
2346 }
2347 ~ParentStmtInserterRAII() {
2348 ParentStmts.erase(S);
2349 }
2350 };
2351
2352 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2353#endif
2354
Chris Lattner1f551822009-04-27 06:20:01 +00002355 Writer.Visit(S);
Fangrui Song6907ce22018-07-30 19:24:48 +00002356
Richard Smithb41ddae2016-04-06 20:57:53 +00002357 uint64_t Offset = Writer.Emit();
2358 SubStmtEntries[S] = Offset;
Chris Lattner1f551822009-04-27 06:20:01 +00002359}
2360
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002361/// Flush all of the statements that have been added to the
Chris Lattner1f551822009-04-27 06:20:01 +00002362/// queue via AddStmt().
Richard Smith290d8012016-04-06 17:06:00 +00002363void ASTRecordWriter::FlushStmts() {
Daniel Dunbara5acaa32012-02-29 02:39:13 +00002364 // We expect to be the only consumer of the two temporary statement maps,
2365 // assert that they are empty.
Richard Smith290d8012016-04-06 17:06:00 +00002366 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2367 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002368
Chris Lattner1f551822009-04-27 06:20:01 +00002369 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002370 Writer->WriteSubStmt(StmtsToEmit[I]);
Fangrui Song6907ce22018-07-30 19:24:48 +00002371
Richard Smith290d8012016-04-06 17:06:00 +00002372 assert(N == StmtsToEmit.size() && "record modified while being written!");
Mike Stump11289f42009-09-09 15:08:12 +00002373
Chris Lattner1f551822009-04-27 06:20:01 +00002374 // Note that we are at the end of a full expression. Any
2375 // expression records that follow this one are part of a different
2376 // expression.
Richard Smith290d8012016-04-06 17:06:00 +00002377 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002378
Richard Smith290d8012016-04-06 17:06:00 +00002379 Writer->SubStmtEntries.clear();
2380 Writer->ParentStmts.clear();
2381 }
2382
2383 StmtsToEmit.clear();
2384}
2385
2386void ASTRecordWriter::FlushSubStmts() {
2387 // For a nested statement, write out the substatements in reverse order (so
2388 // that a simple stack machine can be used when loading), and don't emit a
2389 // STMT_STOP after each one.
2390 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002391 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
Richard Smith290d8012016-04-06 17:06:00 +00002392 assert(N == StmtsToEmit.size() && "record modified while being written!");
Chris Lattner1f551822009-04-27 06:20:01 +00002393 }
Mike Stump11289f42009-09-09 15:08:12 +00002394
Chris Lattner1f551822009-04-27 06:20:01 +00002395 StmtsToEmit.clear();
Chris Lattner1f551822009-04-27 06:20:01 +00002396}