blob: 17aca06e1a6f4c5c24c5dfc632a5a9dcab89d5f4 [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//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
James Dennettddd36ff2013-08-09 23:08:25 +00009///
10/// \file
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011/// Implements serialization for Statements and Expressions.
James Dennettddd36ff2013-08-09 23:08:25 +000012///
Chris Lattner1f551822009-04-27 06:20:01 +000013//===----------------------------------------------------------------------===//
14
Sebastian Redl1914c6f2010-08-18 23:56:37 +000015#include "clang/Serialization/ASTWriter.h"
Benjamin Kramer4ab984e2012-07-04 20:19:54 +000016#include "clang/AST/ASTContext.h"
Douglas Gregor5d3507d2009-09-09 23:08:42 +000017#include "clang/AST/DeclCXX.h"
Chris Lattner1f551822009-04-27 06:20:01 +000018#include "clang/AST/DeclObjC.h"
Douglas Gregorcdbc5392011-01-15 01:15:58 +000019#include "clang/AST/DeclTemplate.h"
Chris Lattner1f551822009-04-27 06:20:01 +000020#include "clang/AST/StmtVisitor.h"
John McCallf413f5e2013-05-03 00:10:13 +000021#include "clang/Lex/Token.h"
Chris Lattner1f551822009-04-27 06:20:01 +000022#include "llvm/Bitcode/BitstreamWriter.h"
23using namespace clang;
24
25//===----------------------------------------------------------------------===//
26// Statement/expression serialization
27//===----------------------------------------------------------------------===//
28
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +000029namespace clang {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000030
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000031 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
Sebastian Redl55c0ad52010-08-18 23:56:21 +000032 ASTWriter &Writer;
Richard Smith290d8012016-04-06 17:06:00 +000033 ASTRecordWriter Record;
Chris Lattner1f551822009-04-27 06:20:01 +000034
Sebastian Redl539c5062010-08-18 23:57:32 +000035 serialization::StmtCode Code;
Douglas Gregor03412ba2011-06-03 02:27:19 +000036 unsigned AbbrevToUse;
Chris Lattner1f551822009-04-27 06:20:01 +000037
Richard Smith290d8012016-04-06 17:06:00 +000038 public:
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000039 ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
Richard Smith290d8012016-04-06 17:06:00 +000040 : Writer(Writer), Record(Writer, Record),
41 Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
42
43 ASTStmtWriter(const ASTStmtWriter&) = delete;
44
Richard Smithf50422a2016-04-06 20:12:34 +000045 uint64_t Emit() {
Richard Smith290d8012016-04-06 17:06:00 +000046 assert(Code != serialization::STMT_NULL_PTR &&
47 "unhandled sub-statement writing AST file");
48 return Record.EmitStmt(Code, AbbrevToUse);
49 }
Abramo Bagnara7945c982012-01-27 09:46:47 +000050
James Y Knighte7d82282015-12-29 18:15:14 +000051 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo,
52 const TemplateArgumentLoc *Args);
Chris Lattner1f551822009-04-27 06:20:01 +000053
54 void VisitStmt(Stmt *S);
John McCallfa194042011-07-15 07:00:14 +000055#define STMT(Type, Base) \
56 void Visit##Type(Type *);
57#include "clang/AST/StmtNodes.inc"
Chris Lattner1f551822009-04-27 06:20:01 +000058 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +000059}
Chris Lattner1f551822009-04-27 06:20:01 +000060
James Y Knighte7d82282015-12-29 18:15:14 +000061void ASTStmtWriter::AddTemplateKWAndArgsInfo(
62 const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) {
Richard Smith290d8012016-04-06 17:06:00 +000063 Record.AddSourceLocation(ArgInfo.TemplateKWLoc);
64 Record.AddSourceLocation(ArgInfo.LAngleLoc);
65 Record.AddSourceLocation(ArgInfo.RAngleLoc);
James Y Knighte7d82282015-12-29 18:15:14 +000066 for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +000067 Record.AddTemplateArgumentLoc(Args[i]);
Argyrios Kyrtzidisb5288de2010-06-28 09:31:48 +000068}
69
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000070void ASTStmtWriter::VisitStmt(Stmt *S) {
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());
Argyrios Kyrtzidis43ea78b2011-09-01 21:53:45 +000076 Record.push_back(S->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);
Richard Smith290d8012016-04-06 17:06:00 +000099 Record.AddStmt(S->getLHS());
100 Record.AddStmt(S->getRHS());
101 Record.AddStmt(S->getSubStmt());
102 Record.AddSourceLocation(S->getEllipsisLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000103 Code = serialization::STMT_CASE;
Chris Lattner1f551822009-04-27 06:20:01 +0000104}
105
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000106void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000107 VisitSwitchCase(S);
Richard Smith290d8012016-04-06 17:06:00 +0000108 Record.AddStmt(S->getSubStmt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000109 Code = serialization::STMT_DEFAULT;
Chris Lattner1f551822009-04-27 06:20:01 +0000110}
111
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000112void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000113 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000114 Record.AddDeclRef(S->getDecl());
115 Record.AddStmt(S->getSubStmt());
116 Record.AddSourceLocation(S->getIdentLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000117 Code = serialization::STMT_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000118}
119
Richard Smithc202b282012-04-14 00:33:13 +0000120void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
121 VisitStmt(S);
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000122 Record.push_back(S->getAttrs().size());
Richard Smith290d8012016-04-06 17:06:00 +0000123 Record.AddAttributes(S->getAttrs());
124 Record.AddStmt(S->getSubStmt());
125 Record.AddSourceLocation(S->getAttrLoc());
Richard Smithc202b282012-04-14 00:33:13 +0000126 Code = serialization::STMT_ATTRIBUTED;
127}
128
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000129void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000130 VisitStmt(S);
Richard Smithb130fe72016-06-23 19:16:49 +0000131 Record.push_back(S->isConstexpr());
Richard Smitha547eb22016-07-14 00:11:03 +0000132 Record.AddStmt(S->getInit());
Richard Smith290d8012016-04-06 17:06:00 +0000133 Record.AddDeclRef(S->getConditionVariable());
134 Record.AddStmt(S->getCond());
135 Record.AddStmt(S->getThen());
136 Record.AddStmt(S->getElse());
137 Record.AddSourceLocation(S->getIfLoc());
138 Record.AddSourceLocation(S->getElseLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000139 Code = serialization::STMT_IF;
Chris Lattner1f551822009-04-27 06:20:01 +0000140}
141
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000142void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000143 VisitStmt(S);
Richard Smitha547eb22016-07-14 00:11:03 +0000144 Record.AddStmt(S->getInit());
Richard Smith290d8012016-04-06 17:06:00 +0000145 Record.AddDeclRef(S->getConditionVariable());
146 Record.AddStmt(S->getCond());
147 Record.AddStmt(S->getBody());
148 Record.AddSourceLocation(S->getSwitchLoc());
Ted Kremenekc42f3452010-09-09 00:05:53 +0000149 Record.push_back(S->isAllEnumCasesCovered());
Mike Stump11289f42009-09-09 15:08:12 +0000150 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
Chris Lattner1f551822009-04-27 06:20:01 +0000151 SC = SC->getNextSwitchCase())
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000152 Record.push_back(Writer.RecordSwitchCaseID(SC));
Sebastian Redl539c5062010-08-18 23:57:32 +0000153 Code = serialization::STMT_SWITCH;
Chris Lattner1f551822009-04-27 06:20:01 +0000154}
155
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000156void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000157 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000158 Record.AddDeclRef(S->getConditionVariable());
159 Record.AddStmt(S->getCond());
160 Record.AddStmt(S->getBody());
161 Record.AddSourceLocation(S->getWhileLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000162 Code = serialization::STMT_WHILE;
Chris Lattner1f551822009-04-27 06:20:01 +0000163}
164
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000165void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000166 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000167 Record.AddStmt(S->getCond());
168 Record.AddStmt(S->getBody());
169 Record.AddSourceLocation(S->getDoLoc());
170 Record.AddSourceLocation(S->getWhileLoc());
171 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000172 Code = serialization::STMT_DO;
Chris Lattner1f551822009-04-27 06:20:01 +0000173}
174
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000175void ASTStmtWriter::VisitForStmt(ForStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000176 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000177 Record.AddStmt(S->getInit());
178 Record.AddStmt(S->getCond());
179 Record.AddDeclRef(S->getConditionVariable());
180 Record.AddStmt(S->getInc());
181 Record.AddStmt(S->getBody());
182 Record.AddSourceLocation(S->getForLoc());
183 Record.AddSourceLocation(S->getLParenLoc());
184 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000185 Code = serialization::STMT_FOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000186}
187
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000188void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000189 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000190 Record.AddDeclRef(S->getLabel());
191 Record.AddSourceLocation(S->getGotoLoc());
192 Record.AddSourceLocation(S->getLabelLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000193 Code = serialization::STMT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000194}
195
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000196void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000197 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000198 Record.AddSourceLocation(S->getGotoLoc());
199 Record.AddSourceLocation(S->getStarLoc());
200 Record.AddStmt(S->getTarget());
Sebastian Redl539c5062010-08-18 23:57:32 +0000201 Code = serialization::STMT_INDIRECT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000202}
203
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000204void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000205 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000206 Record.AddSourceLocation(S->getContinueLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000207 Code = serialization::STMT_CONTINUE;
Chris Lattner1f551822009-04-27 06:20:01 +0000208}
209
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000210void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000211 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000212 Record.AddSourceLocation(S->getBreakLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000213 Code = serialization::STMT_BREAK;
Chris Lattner1f551822009-04-27 06:20:01 +0000214}
215
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000216void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000217 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000218 Record.AddStmt(S->getRetValue());
219 Record.AddSourceLocation(S->getReturnLoc());
220 Record.AddDeclRef(S->getNRVOCandidate());
Sebastian Redl539c5062010-08-18 23:57:32 +0000221 Code = serialization::STMT_RETURN;
Chris Lattner1f551822009-04-27 06:20:01 +0000222}
223
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000224void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000225 VisitStmt(S);
Stephen Kellya6e43582018-08-09 21:05:56 +0000226 Record.AddSourceLocation(S->getBeginLoc());
Richard Smith290d8012016-04-06 17:06:00 +0000227 Record.AddSourceLocation(S->getEndLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000228 DeclGroupRef DG = S->getDeclGroup();
229 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
Richard Smith290d8012016-04-06 17:06:00 +0000230 Record.AddDeclRef(*D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000231 Code = serialization::STMT_DECL;
Chris Lattner1f551822009-04-27 06:20:01 +0000232}
233
John McCallf413f5e2013-05-03 00:10:13 +0000234void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000235 VisitStmt(S);
236 Record.push_back(S->getNumOutputs());
237 Record.push_back(S->getNumInputs());
238 Record.push_back(S->getNumClobbers());
Richard Smith290d8012016-04-06 17:06:00 +0000239 Record.AddSourceLocation(S->getAsmLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000240 Record.push_back(S->isVolatile());
241 Record.push_back(S->isSimple());
John McCallf413f5e2013-05-03 00:10:13 +0000242}
243
244void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
245 VisitAsmStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000246 Record.AddSourceLocation(S->getRParenLoc());
247 Record.AddStmt(S->getAsmString());
Chris Lattner1f551822009-04-27 06:20:01 +0000248
249 // Outputs
Fangrui Song6907ce22018-07-30 19:24:48 +0000250 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000251 Record.AddIdentifierRef(S->getOutputIdentifier(I));
252 Record.AddStmt(S->getOutputConstraintLiteral(I));
253 Record.AddStmt(S->getOutputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000254 }
255
256 // Inputs
257 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000258 Record.AddIdentifierRef(S->getInputIdentifier(I));
259 Record.AddStmt(S->getInputConstraintLiteral(I));
260 Record.AddStmt(S->getInputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000261 }
262
263 // Clobbers
264 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000265 Record.AddStmt(S->getClobberStringLiteral(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000266
Chad Rosierde70e0e2012-08-25 00:11:56 +0000267 Code = serialization::STMT_GCCASM;
Chris Lattner1f551822009-04-27 06:20:01 +0000268}
269
Chad Rosier32503022012-06-11 20:47:18 +0000270void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
John McCallf413f5e2013-05-03 00:10:13 +0000271 VisitAsmStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000272 Record.AddSourceLocation(S->getLBraceLoc());
273 Record.AddSourceLocation(S->getEndLoc());
John McCallf413f5e2013-05-03 00:10:13 +0000274 Record.push_back(S->getNumAsmToks());
Richard Smith290d8012016-04-06 17:06:00 +0000275 Record.AddString(S->getAsmString());
John McCallf413f5e2013-05-03 00:10:13 +0000276
277 // Tokens
278 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000279 // FIXME: Move this to ASTRecordWriter?
280 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
John McCallf413f5e2013-05-03 00:10:13 +0000281 }
282
283 // Clobbers
284 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000285 Record.AddString(S->getClobber(I));
John McCallf413f5e2013-05-03 00:10:13 +0000286 }
287
288 // Outputs
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000289 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000290 Record.AddStmt(S->getOutputExpr(I));
291 Record.AddString(S->getOutputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000292 }
293
294 // Inputs
295 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000296 Record.AddStmt(S->getInputExpr(I));
297 Record.AddString(S->getInputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000298 }
Chad Rosiere30d4992012-08-24 23:51:02 +0000299
300 Code = serialization::STMT_MSASM;
Chad Rosier32503022012-06-11 20:47:18 +0000301}
302
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000303void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
304 VisitStmt(CoroStmt);
305 Record.push_back(CoroStmt->getParamMoves().size());
306 for (Stmt *S : CoroStmt->children())
307 Record.AddStmt(S);
308 Code = serialization::STMT_COROUTINE_BODY;
Richard Smith9f690bd2015-10-27 06:02:45 +0000309}
310
311void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000312 VisitStmt(S);
313 Record.AddSourceLocation(S->getKeywordLoc());
314 Record.AddStmt(S->getOperand());
315 Record.AddStmt(S->getPromiseCall());
316 Record.push_back(S->isImplicit());
317 Code = serialization::STMT_CORETURN;
Richard Smith9f690bd2015-10-27 06:02:45 +0000318}
319
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000320void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
321 VisitExpr(E);
322 Record.AddSourceLocation(E->getKeywordLoc());
323 for (Stmt *S : E->children())
324 Record.AddStmt(S);
325 Record.AddStmt(E->getOpaqueValue());
Richard Smith9f690bd2015-10-27 06:02:45 +0000326}
327
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000328void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
329 VisitCoroutineSuspendExpr(E);
330 Record.push_back(E->isImplicit());
331 Code = serialization::EXPR_COAWAIT;
Eric Fiselier20f25cb2017-03-06 23:38:15 +0000332}
333
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000334void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
335 VisitCoroutineSuspendExpr(E);
336 Code = serialization::EXPR_COYIELD;
337}
338
339void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
340 VisitExpr(E);
341 Record.AddSourceLocation(E->getKeywordLoc());
342 for (Stmt *S : E->children())
343 Record.AddStmt(S);
344 Code = serialization::EXPR_DEPENDENT_COAWAIT;
Richard Smith9f690bd2015-10-27 06:02:45 +0000345}
346
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000347void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
348 VisitStmt(S);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000349 // NumCaptures
350 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000351
Wei Pan17fbf6e2013-05-04 03:59:06 +0000352 // CapturedDecl and captured region kind
Richard Smith290d8012016-04-06 17:06:00 +0000353 Record.AddDeclRef(S->getCapturedDecl());
Wei Pan17fbf6e2013-05-04 03:59:06 +0000354 Record.push_back(S->getCapturedRegionKind());
355
Richard Smith290d8012016-04-06 17:06:00 +0000356 Record.AddDeclRef(S->getCapturedRecordDecl());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000357
358 // Capture inits
Aaron Ballmanba0238f2014-03-14 19:41:04 +0000359 for (auto *I : S->capture_inits())
Richard Smith290d8012016-04-06 17:06:00 +0000360 Record.AddStmt(I);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000361
362 // Body
Richard Smith290d8012016-04-06 17:06:00 +0000363 Record.AddStmt(S->getCapturedStmt());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000364
365 // Captures
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000366 for (const auto &I : S->captures()) {
Alexey Bataev330de032014-10-29 12:21:55 +0000367 if (I.capturesThis() || I.capturesVariableArrayType())
Richard Smith290d8012016-04-06 17:06:00 +0000368 Record.AddDeclRef(nullptr);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000369 else
Richard Smith290d8012016-04-06 17:06:00 +0000370 Record.AddDeclRef(I.getCapturedVar());
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000371 Record.push_back(I.getCaptureKind());
Richard Smith290d8012016-04-06 17:06:00 +0000372 Record.AddSourceLocation(I.getLocation());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000373 }
374
375 Code = serialization::STMT_CAPTURED;
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000376}
377
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000378void ASTStmtWriter::VisitExpr(Expr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000379 VisitStmt(E);
Richard Smith290d8012016-04-06 17:06:00 +0000380 Record.AddTypeRef(E->getType());
Chris Lattner1f551822009-04-27 06:20:01 +0000381 Record.push_back(E->isTypeDependent());
382 Record.push_back(E->isValueDependent());
Douglas Gregor678d76c2011-07-01 01:22:09 +0000383 Record.push_back(E->isInstantiationDependent());
Douglas Gregor506bd562010-12-13 22:49:22 +0000384 Record.push_back(E->containsUnexpandedParameterPack());
John McCall7decc9e2010-11-18 06:31:45 +0000385 Record.push_back(E->getValueKind());
386 Record.push_back(E->getObjectKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000387}
388
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000389void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000390 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000391 Record.AddSourceLocation(E->getLocation());
Chris Lattner1f551822009-04-27 06:20:01 +0000392 Record.push_back(E->getIdentType()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000393 Record.AddStmt(E->getFunctionName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000394 Code = serialization::EXPR_PREDEFINED;
Chris Lattner1f551822009-04-27 06:20:01 +0000395}
396
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000397void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000398 VisitExpr(E);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000399
400 Record.push_back(E->hasQualifier());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000401 Record.push_back(E->getDecl() != E->getFoundDecl());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000402 Record.push_back(E->hasTemplateKWAndArgsInfo());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000403 Record.push_back(E->hadMultipleCandidates());
Alexey Bataev19acc3d2015-01-12 10:17:46 +0000404 Record.push_back(E->refersToEnclosingVariableOrCapture());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000405
Abramo Bagnara7945c982012-01-27 09:46:47 +0000406 if (E->hasTemplateKWAndArgsInfo()) {
Douglas Gregor87866ce2011-02-04 12:01:24 +0000407 unsigned NumTemplateArgs = E->getNumTemplateArgs();
408 Record.push_back(NumTemplateArgs);
Douglas Gregor87866ce2011-02-04 12:01:24 +0000409 }
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000410
Douglas Gregor03412ba2011-06-03 02:27:19 +0000411 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
412
Abramo Bagnara7945c982012-01-27 09:46:47 +0000413 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000414 (E->getDecl() == E->getFoundDecl()) &&
415 nk == DeclarationName::Identifier) {
416 AbbrevToUse = Writer.getDeclRefExprAbbrev();
417 }
418
Anders Carlsson80756f62011-03-06 18:19:42 +0000419 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000420 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Anders Carlsson80756f62011-03-06 18:19:42 +0000421
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000422 if (E->getDecl() != E->getFoundDecl())
Richard Smith290d8012016-04-06 17:06:00 +0000423 Record.AddDeclRef(E->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000424
Abramo Bagnara7945c982012-01-27 09:46:47 +0000425 if (E->hasTemplateKWAndArgsInfo())
James Y Knighte7d82282015-12-29 18:15:14 +0000426 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
427 E->getTrailingObjects<TemplateArgumentLoc>());
Anders Carlsson80756f62011-03-06 18:19:42 +0000428
Richard Smith290d8012016-04-06 17:06:00 +0000429 Record.AddDeclRef(E->getDecl());
430 Record.AddSourceLocation(E->getLocation());
431 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000432 Code = serialization::EXPR_DECL_REF;
Chris Lattner1f551822009-04-27 06:20:01 +0000433}
434
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000435void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000436 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000437 Record.AddSourceLocation(E->getLocation());
438 Record.AddAPInt(E->getValue());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000439
440 if (E->getValue().getBitWidth() == 32) {
441 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
442 }
443
Sebastian Redl539c5062010-08-18 23:57:32 +0000444 Code = serialization::EXPR_INTEGER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000445}
446
Leonard Chandb01c3a2018-06-20 17:19:40 +0000447void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
448 VisitExpr(E);
449 Record.AddSourceLocation(E->getLocation());
450 Record.AddAPInt(E->getValue());
451 Code = serialization::EXPR_INTEGER_LITERAL;
452}
453
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000454void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000455 VisitExpr(E);
Tim Northover178723a2013-01-22 09:46:51 +0000456 Record.push_back(E->getRawSemantics());
Chris Lattner1f551822009-04-27 06:20:01 +0000457 Record.push_back(E->isExact());
Richard Smith290d8012016-04-06 17:06:00 +0000458 Record.AddAPFloat(E->getValue());
459 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000460 Code = serialization::EXPR_FLOATING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000461}
462
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000463void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000464 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000465 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000466 Code = serialization::EXPR_IMAGINARY_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000467}
468
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000469void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000470 VisitExpr(E);
471 Record.push_back(E->getByteLength());
472 Record.push_back(E->getNumConcatenated());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000473 Record.push_back(E->getKind());
Anders Carlsson75245402011-04-14 00:40:03 +0000474 Record.push_back(E->isPascal());
Chris Lattner1f551822009-04-27 06:20:01 +0000475 // FIXME: String data should be stored as a blob at the end of the
476 // StringLiteral. However, we can't do so now because we have no
477 // provision for coping with abbreviations when we're jumping around
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000478 // the AST file during deserialization.
Eli Friedmanfcec6302011-11-01 02:23:42 +0000479 Record.append(E->getBytes().begin(), E->getBytes().end());
Chris Lattner1f551822009-04-27 06:20:01 +0000480 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000481 Record.AddSourceLocation(E->getStrTokenLoc(I));
Sebastian Redl539c5062010-08-18 23:57:32 +0000482 Code = serialization::EXPR_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000483}
484
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000485void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000486 VisitExpr(E);
487 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +0000488 Record.AddSourceLocation(E->getLocation());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000489 Record.push_back(E->getKind());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000490
491 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
492
Sebastian Redl539c5062010-08-18 23:57:32 +0000493 Code = serialization::EXPR_CHARACTER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000494}
495
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000496void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000497 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000498 Record.AddSourceLocation(E->getLParen());
499 Record.AddSourceLocation(E->getRParen());
500 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000501 Code = serialization::EXPR_PAREN;
Chris Lattner1f551822009-04-27 06:20:01 +0000502}
503
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000504void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000505 VisitExpr(E);
506 Record.push_back(E->NumExprs);
507 for (unsigned i=0; i != E->NumExprs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +0000508 Record.AddStmt(E->Exprs[i]);
509 Record.AddSourceLocation(E->LParenLoc);
510 Record.AddSourceLocation(E->RParenLoc);
Sebastian Redl539c5062010-08-18 23:57:32 +0000511 Code = serialization::EXPR_PAREN_LIST;
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000512}
513
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000514void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000515 VisitExpr(E);
Malcolm Parsonsfab36802018-04-16 08:31:08 +0000516 Record.AddStmt(E->getSubExpr());
517 Record.push_back(E->getOpcode()); // FIXME: stable encoding
518 Record.AddSourceLocation(E->getOperatorLoc());
519 Record.push_back(E->canOverflow());
520 Code = serialization::EXPR_UNARY_OPERATOR;
521}
522
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000523void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000524 VisitExpr(E);
525 Record.push_back(E->getNumComponents());
526 Record.push_back(E->getNumExpressions());
Richard Smith290d8012016-04-06 17:06:00 +0000527 Record.AddSourceLocation(E->getOperatorLoc());
528 Record.AddSourceLocation(E->getRParenLoc());
529 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Douglas Gregor882211c2010-04-28 22:16:22 +0000530 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +0000531 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +0000532 Record.push_back(ON.getKind()); // FIXME: Stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000533 Record.AddSourceLocation(ON.getSourceRange().getBegin());
534 Record.AddSourceLocation(ON.getSourceRange().getEnd());
Douglas Gregor882211c2010-04-28 22:16:22 +0000535 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +0000536 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +0000537 Record.push_back(ON.getArrayExprIndex());
538 break;
James Y Knight7281c352015-12-29 22:31:18 +0000539
540 case OffsetOfNode::Field:
Richard Smith290d8012016-04-06 17:06:00 +0000541 Record.AddDeclRef(ON.getField());
Douglas Gregor882211c2010-04-28 22:16:22 +0000542 break;
James Y Knight7281c352015-12-29 22:31:18 +0000543
544 case OffsetOfNode::Identifier:
Richard Smith290d8012016-04-06 17:06:00 +0000545 Record.AddIdentifierRef(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +0000546 break;
James Y Knight7281c352015-12-29 22:31:18 +0000547
548 case OffsetOfNode::Base:
Richard Smith290d8012016-04-06 17:06:00 +0000549 Record.AddCXXBaseSpecifier(*ON.getBase());
Douglas Gregord1702062010-04-29 00:18:15 +0000550 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000551 }
552 }
553 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000554 Record.AddStmt(E->getIndexExpr(I));
Sebastian Redl539c5062010-08-18 23:57:32 +0000555 Code = serialization::EXPR_OFFSETOF;
Douglas Gregor882211c2010-04-28 22:16:22 +0000556}
557
Peter Collingbournee190dee2011-03-11 19:24:49 +0000558void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000559 VisitExpr(E);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000560 Record.push_back(E->getKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000561 if (E->isArgumentType())
Richard Smith290d8012016-04-06 17:06:00 +0000562 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
Chris Lattner1f551822009-04-27 06:20:01 +0000563 else {
564 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +0000565 Record.AddStmt(E->getArgumentExpr());
Chris Lattner1f551822009-04-27 06:20:01 +0000566 }
Richard Smith290d8012016-04-06 17:06:00 +0000567 Record.AddSourceLocation(E->getOperatorLoc());
568 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000569 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
Chris Lattner1f551822009-04-27 06:20:01 +0000570}
571
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000572void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000573 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000574 Record.AddStmt(E->getLHS());
575 Record.AddStmt(E->getRHS());
576 Record.AddSourceLocation(E->getRBracketLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000577 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
Chris Lattner1f551822009-04-27 06:20:01 +0000578}
579
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000580void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
581 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000582 Record.AddStmt(E->getBase());
583 Record.AddStmt(E->getLowerBound());
584 Record.AddStmt(E->getLength());
585 Record.AddSourceLocation(E->getColonLoc());
586 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000587 Code = serialization::EXPR_OMP_ARRAY_SECTION;
588}
589
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000590void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000591 VisitExpr(E);
592 Record.push_back(E->getNumArgs());
Richard Smith290d8012016-04-06 17:06:00 +0000593 Record.AddSourceLocation(E->getRParenLoc());
594 Record.AddStmt(E->getCallee());
Chris Lattner1f551822009-04-27 06:20:01 +0000595 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
596 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +0000597 Record.AddStmt(*Arg);
Sebastian Redl539c5062010-08-18 23:57:32 +0000598 Code = serialization::EXPR_CALL;
Chris Lattner1f551822009-04-27 06:20:01 +0000599}
600
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000601void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000602 // Don't call VisitExpr, we'll write everything here.
603
604 Record.push_back(E->hasQualifier());
Douglas Gregorea972d32011-02-28 21:54:11 +0000605 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000606 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000607
Abramo Bagnara7945c982012-01-27 09:46:47 +0000608 Record.push_back(E->HasTemplateKWAndArgsInfo);
609 if (E->HasTemplateKWAndArgsInfo) {
Richard Smith290d8012016-04-06 17:06:00 +0000610 Record.AddSourceLocation(E->getTemplateKeywordLoc());
Douglas Gregor87866ce2011-02-04 12:01:24 +0000611 unsigned NumTemplateArgs = E->getNumTemplateArgs();
612 Record.push_back(NumTemplateArgs);
Richard Smith290d8012016-04-06 17:06:00 +0000613 Record.AddSourceLocation(E->getLAngleLoc());
614 Record.AddSourceLocation(E->getRAngleLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000615 for (unsigned i=0; i != NumTemplateArgs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +0000616 Record.AddTemplateArgumentLoc(E->getTemplateArgs()[i]);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000617 }
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000618
619 Record.push_back(E->hadMultipleCandidates());
620
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000621 DeclAccessPair FoundDecl = E->getFoundDecl();
Richard Smith290d8012016-04-06 17:06:00 +0000622 Record.AddDeclRef(FoundDecl.getDecl());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000623 Record.push_back(FoundDecl.getAccess());
624
Richard Smith290d8012016-04-06 17:06:00 +0000625 Record.AddTypeRef(E->getType());
John McCall7decc9e2010-11-18 06:31:45 +0000626 Record.push_back(E->getValueKind());
627 Record.push_back(E->getObjectKind());
Richard Smith290d8012016-04-06 17:06:00 +0000628 Record.AddStmt(E->getBase());
629 Record.AddDeclRef(E->getMemberDecl());
630 Record.AddSourceLocation(E->getMemberLoc());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000631 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +0000632 Record.AddSourceLocation(E->getOperatorLoc());
633 Record.AddDeclarationNameLoc(E->MemberDNLoc,
634 E->getMemberDecl()->getDeclName());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000635 Code = serialization::EXPR_MEMBER;
Chris Lattner1f551822009-04-27 06:20:01 +0000636}
637
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000638void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Naroffe87026a2009-07-24 17:54:45 +0000639 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000640 Record.AddStmt(E->getBase());
641 Record.AddSourceLocation(E->getIsaMemberLoc());
642 Record.AddSourceLocation(E->getOpLoc());
Steve Naroffe87026a2009-07-24 17:54:45 +0000643 Record.push_back(E->isArrow());
Sebastian Redl539c5062010-08-18 23:57:32 +0000644 Code = serialization::EXPR_OBJC_ISA;
Steve Naroffe87026a2009-07-24 17:54:45 +0000645}
646
John McCall31168b02011-06-15 23:02:42 +0000647void ASTStmtWriter::
648VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
649 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000650 Record.AddStmt(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +0000651 Record.push_back(E->shouldCopy());
652 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
653}
654
655void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
656 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000657 Record.AddSourceLocation(E->getLParenLoc());
658 Record.AddSourceLocation(E->getBridgeKeywordLoc());
John McCall31168b02011-06-15 23:02:42 +0000659 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
660 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
661}
662
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000663void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000664 VisitExpr(E);
John McCallcf142162010-08-07 06:22:56 +0000665 Record.push_back(E->path_size());
Richard Smith290d8012016-04-06 17:06:00 +0000666 Record.AddStmt(E->getSubExpr());
Anders Carlssona2615922009-07-31 00:48:10 +0000667 Record.push_back(E->getCastKind()); // FIXME: stable encoding
John McCallcf142162010-08-07 06:22:56 +0000668
669 for (CastExpr::path_iterator
670 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
Richard Smith290d8012016-04-06 17:06:00 +0000671 Record.AddCXXBaseSpecifier(**PI);
Chris Lattner1f551822009-04-27 06:20:01 +0000672}
673
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000674void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000675 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000676 Record.AddStmt(E->getLHS());
677 Record.AddStmt(E->getRHS());
Chris Lattner1f551822009-04-27 06:20:01 +0000678 Record.push_back(E->getOpcode()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000679 Record.AddSourceLocation(E->getOperatorLoc());
Adam Nemet484aa452017-03-27 19:17:25 +0000680 Record.push_back(E->getFPFeatures().getInt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000681 Code = serialization::EXPR_BINARY_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000682}
683
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000684void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000685 VisitBinaryOperator(E);
Richard Smith290d8012016-04-06 17:06:00 +0000686 Record.AddTypeRef(E->getComputationLHSType());
687 Record.AddTypeRef(E->getComputationResultType());
Sebastian Redl539c5062010-08-18 23:57:32 +0000688 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000689}
690
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000691void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000692 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000693 Record.AddStmt(E->getCond());
694 Record.AddStmt(E->getLHS());
695 Record.AddStmt(E->getRHS());
696 Record.AddSourceLocation(E->getQuestionLoc());
697 Record.AddSourceLocation(E->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000698 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000699}
700
John McCallc07a0c72011-02-17 10:25:35 +0000701void
702ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
703 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000704 Record.AddStmt(E->getOpaqueValue());
705 Record.AddStmt(E->getCommon());
706 Record.AddStmt(E->getCond());
707 Record.AddStmt(E->getTrueExpr());
708 Record.AddStmt(E->getFalseExpr());
709 Record.AddSourceLocation(E->getQuestionLoc());
710 Record.AddSourceLocation(E->getColonLoc());
John McCallc07a0c72011-02-17 10:25:35 +0000711 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
712}
713
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000714void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000715 VisitCastExpr(E);
Roman Lebedev12216f12018-07-27 07:27:14 +0000716 Record.push_back(E->isPartOfExplicitCast());
Richard Smitha27c26e2014-07-27 04:19:32 +0000717
718 if (E->path_size() == 0)
719 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
720
Sebastian Redl539c5062010-08-18 23:57:32 +0000721 Code = serialization::EXPR_IMPLICIT_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000722}
723
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000724void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000725 VisitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000726 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
Chris Lattner1f551822009-04-27 06:20:01 +0000727}
728
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000729void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000730 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000731 Record.AddSourceLocation(E->getLParenLoc());
732 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000733 Code = serialization::EXPR_CSTYLE_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000734}
735
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000736void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000737 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000738 Record.AddSourceLocation(E->getLParenLoc());
739 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
740 Record.AddStmt(E->getInitializer());
Chris Lattner1f551822009-04-27 06:20:01 +0000741 Record.push_back(E->isFileScope());
Sebastian Redl539c5062010-08-18 23:57:32 +0000742 Code = serialization::EXPR_COMPOUND_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000743}
744
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000745void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000746 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000747 Record.AddStmt(E->getBase());
748 Record.AddIdentifierRef(&E->getAccessor());
749 Record.AddSourceLocation(E->getAccessorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000750 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
Chris Lattner1f551822009-04-27 06:20:01 +0000751}
752
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000753void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000754 VisitExpr(E);
Abramo Bagnara8d16bd42012-11-08 18:41:43 +0000755 // NOTE: only add the (possibly null) syntactic form.
756 // No need to serialize the isSemanticForm flag and the semantic form.
Richard Smith290d8012016-04-06 17:06:00 +0000757 Record.AddStmt(E->getSyntacticForm());
758 Record.AddSourceLocation(E->getLBraceLoc());
759 Record.AddSourceLocation(E->getRBraceLoc());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000760 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
761 Record.push_back(isArrayFiller);
762 if (isArrayFiller)
Richard Smith290d8012016-04-06 17:06:00 +0000763 Record.AddStmt(E->getArrayFiller());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000764 else
Richard Smith290d8012016-04-06 17:06:00 +0000765 Record.AddDeclRef(E->getInitializedFieldInUnion());
Chris Lattner1f551822009-04-27 06:20:01 +0000766 Record.push_back(E->hadArrayRangeDesignator());
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000767 Record.push_back(E->getNumInits());
768 if (isArrayFiller) {
769 // ArrayFiller may have filled "holes" due to designated initializer.
770 // Replace them by 0 to indicate that the filler goes in that place.
771 Expr *filler = E->getArrayFiller();
772 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000773 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000774 } else {
775 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000776 Record.AddStmt(E->getInit(I));
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000777 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000778 Code = serialization::EXPR_INIT_LIST;
Chris Lattner1f551822009-04-27 06:20:01 +0000779}
780
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000781void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000782 VisitExpr(E);
783 Record.push_back(E->getNumSubExprs());
784 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000785 Record.AddStmt(E->getSubExpr(I));
786 Record.AddSourceLocation(E->getEqualOrColonLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000787 Record.push_back(E->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +0000788 for (const DesignatedInitExpr::Designator &D : E->designators()) {
789 if (D.isFieldDesignator()) {
790 if (FieldDecl *Field = D.getField()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000791 Record.push_back(serialization::DESIG_FIELD_DECL);
Richard Smith290d8012016-04-06 17:06:00 +0000792 Record.AddDeclRef(Field);
Chris Lattner1f551822009-04-27 06:20:01 +0000793 } else {
Sebastian Redl539c5062010-08-18 23:57:32 +0000794 Record.push_back(serialization::DESIG_FIELD_NAME);
David Majnemerf7e36092016-06-23 00:15:04 +0000795 Record.AddIdentifierRef(D.getFieldName());
Chris Lattner1f551822009-04-27 06:20:01 +0000796 }
David Majnemerf7e36092016-06-23 00:15:04 +0000797 Record.AddSourceLocation(D.getDotLoc());
798 Record.AddSourceLocation(D.getFieldLoc());
799 } else if (D.isArrayDesignator()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000800 Record.push_back(serialization::DESIG_ARRAY);
David Majnemerf7e36092016-06-23 00:15:04 +0000801 Record.push_back(D.getFirstExprIndex());
802 Record.AddSourceLocation(D.getLBracketLoc());
803 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000804 } else {
David Majnemerf7e36092016-06-23 00:15:04 +0000805 assert(D.isArrayRangeDesignator() && "Unknown designator");
Sebastian Redl539c5062010-08-18 23:57:32 +0000806 Record.push_back(serialization::DESIG_ARRAY_RANGE);
David Majnemerf7e36092016-06-23 00:15:04 +0000807 Record.push_back(D.getFirstExprIndex());
808 Record.AddSourceLocation(D.getLBracketLoc());
809 Record.AddSourceLocation(D.getEllipsisLoc());
810 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000811 }
812 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000813 Code = serialization::EXPR_DESIGNATED_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000814}
815
Yunzhong Gaocb779302015-06-10 00:27:52 +0000816void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
817 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000818 Record.AddStmt(E->getBase());
819 Record.AddStmt(E->getUpdater());
Yunzhong Gaocb779302015-06-10 00:27:52 +0000820 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
821}
822
823void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
824 VisitExpr(E);
825 Code = serialization::EXPR_NO_INIT;
826}
827
Richard Smith410306b2016-12-12 02:53:20 +0000828void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
829 VisitExpr(E);
830 Record.AddStmt(E->SubExprs[0]);
831 Record.AddStmt(E->SubExprs[1]);
832 Code = serialization::EXPR_ARRAY_INIT_LOOP;
833}
834
835void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
836 VisitExpr(E);
837 Code = serialization::EXPR_ARRAY_INIT_INDEX;
838}
839
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000840void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000841 VisitExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +0000842 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000843}
844
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000845void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000846 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000847 Record.AddStmt(E->getSubExpr());
848 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
849 Record.AddSourceLocation(E->getBuiltinLoc());
850 Record.AddSourceLocation(E->getRParenLoc());
Charles Davisc7d5c942015-09-17 20:55:33 +0000851 Record.push_back(E->isMicrosoftABI());
Sebastian Redl539c5062010-08-18 23:57:32 +0000852 Code = serialization::EXPR_VA_ARG;
Chris Lattner1f551822009-04-27 06:20:01 +0000853}
854
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000855void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000856 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000857 Record.AddSourceLocation(E->getAmpAmpLoc());
858 Record.AddSourceLocation(E->getLabelLoc());
859 Record.AddDeclRef(E->getLabel());
Sebastian Redl539c5062010-08-18 23:57:32 +0000860 Code = serialization::EXPR_ADDR_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000861}
862
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000863void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000864 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000865 Record.AddStmt(E->getSubStmt());
866 Record.AddSourceLocation(E->getLParenLoc());
867 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000868 Code = serialization::EXPR_STMT;
Chris Lattner1f551822009-04-27 06:20:01 +0000869}
870
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000871void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000872 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000873 Record.AddStmt(E->getCond());
874 Record.AddStmt(E->getLHS());
875 Record.AddStmt(E->getRHS());
876 Record.AddSourceLocation(E->getBuiltinLoc());
877 Record.AddSourceLocation(E->getRParenLoc());
Eli Friedman75807f22013-07-20 00:40:58 +0000878 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
Sebastian Redl539c5062010-08-18 23:57:32 +0000879 Code = serialization::EXPR_CHOOSE;
Chris Lattner1f551822009-04-27 06:20:01 +0000880}
881
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000882void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000883 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000884 Record.AddSourceLocation(E->getTokenLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000885 Code = serialization::EXPR_GNU_NULL;
Chris Lattner1f551822009-04-27 06:20:01 +0000886}
887
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000888void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000889 VisitExpr(E);
890 Record.push_back(E->getNumSubExprs());
891 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000892 Record.AddStmt(E->getExpr(I));
893 Record.AddSourceLocation(E->getBuiltinLoc());
894 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000895 Code = serialization::EXPR_SHUFFLE_VECTOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000896}
897
Hal Finkelc4d7c822013-09-18 03:29:45 +0000898void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
899 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000900 Record.AddSourceLocation(E->getBuiltinLoc());
901 Record.AddSourceLocation(E->getRParenLoc());
902 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
903 Record.AddStmt(E->getSrcExpr());
Hal Finkelc4d7c822013-09-18 03:29:45 +0000904 Code = serialization::EXPR_CONVERT_VECTOR;
905}
906
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000907void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000908 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000909 Record.AddDeclRef(E->getBlockDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000910 Code = serialization::EXPR_BLOCK;
Chris Lattner1f551822009-04-27 06:20:01 +0000911}
912
Peter Collingbourne91147592011-04-15 00:35:48 +0000913void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
914 VisitExpr(E);
915 Record.push_back(E->getNumAssocs());
916
Richard Smith290d8012016-04-06 17:06:00 +0000917 Record.AddStmt(E->getControllingExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +0000918 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000919 Record.AddTypeSourceInfo(E->getAssocTypeSourceInfo(I));
920 Record.AddStmt(E->getAssocExpr(I));
Peter Collingbourne91147592011-04-15 00:35:48 +0000921 }
922 Record.push_back(E->isResultDependent() ? -1U : E->getResultIndex());
923
Richard Smith290d8012016-04-06 17:06:00 +0000924 Record.AddSourceLocation(E->getGenericLoc());
925 Record.AddSourceLocation(E->getDefaultLoc());
926 Record.AddSourceLocation(E->getRParenLoc());
Peter Collingbourne91147592011-04-15 00:35:48 +0000927 Code = serialization::EXPR_GENERIC_SELECTION;
928}
929
John McCallfe96e0b2011-11-06 09:01:30 +0000930void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
931 VisitExpr(E);
932 Record.push_back(E->getNumSemanticExprs());
933
934 // Push the result index. Currently, this needs to exactly match
935 // the encoding used internally for ResultIndex.
936 unsigned result = E->getResultExprIndex();
937 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
938 Record.push_back(result);
939
Richard Smith290d8012016-04-06 17:06:00 +0000940 Record.AddStmt(E->getSyntacticForm());
John McCallfe96e0b2011-11-06 09:01:30 +0000941 for (PseudoObjectExpr::semantics_iterator
942 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
Richard Smith290d8012016-04-06 17:06:00 +0000943 Record.AddStmt(*i);
John McCallfe96e0b2011-11-06 09:01:30 +0000944 }
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +0000945 Code = serialization::EXPR_PSEUDO_OBJECT;
John McCallfe96e0b2011-11-06 09:01:30 +0000946}
947
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000948void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
949 VisitExpr(E);
950 Record.push_back(E->getOp());
Richard Smithaa22a8c2012-04-10 22:49:28 +0000951 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000952 Record.AddStmt(E->getSubExprs()[I]);
953 Record.AddSourceLocation(E->getBuiltinLoc());
954 Record.AddSourceLocation(E->getRParenLoc());
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +0000955 Code = serialization::EXPR_ATOMIC;
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000956}
957
Chris Lattner1f551822009-04-27 06:20:01 +0000958//===----------------------------------------------------------------------===//
959// Objective-C Expressions and Statements.
960//===----------------------------------------------------------------------===//
961
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000962void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000963 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000964 Record.AddStmt(E->getString());
965 Record.AddSourceLocation(E->getAtLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000966 Code = serialization::EXPR_OBJC_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000967}
968
Patrick Beard0caa3942012-04-19 00:25:12 +0000969void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +0000970 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000971 Record.AddStmt(E->getSubExpr());
972 Record.AddDeclRef(E->getBoxingMethod());
973 Record.AddSourceRange(E->getSourceRange());
Patrick Beard0caa3942012-04-19 00:25:12 +0000974 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
Ted Kremeneke65b0862012-03-06 20:05:56 +0000975}
976
977void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
978 VisitExpr(E);
979 Record.push_back(E->getNumElements());
980 for (unsigned i = 0; i < E->getNumElements(); i++)
Richard Smith290d8012016-04-06 17:06:00 +0000981 Record.AddStmt(E->getElement(i));
982 Record.AddDeclRef(E->getArrayWithObjectsMethod());
983 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +0000984 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
985}
986
987void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
988 VisitExpr(E);
989 Record.push_back(E->getNumElements());
990 Record.push_back(E->HasPackExpansions);
991 for (unsigned i = 0; i < E->getNumElements(); i++) {
992 ObjCDictionaryElement Element = E->getKeyValueElement(i);
Richard Smith290d8012016-04-06 17:06:00 +0000993 Record.AddStmt(Element.Key);
994 Record.AddStmt(Element.Value);
Ted Kremeneke65b0862012-03-06 20:05:56 +0000995 if (E->HasPackExpansions) {
Richard Smith290d8012016-04-06 17:06:00 +0000996 Record.AddSourceLocation(Element.EllipsisLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +0000997 unsigned NumExpansions = 0;
998 if (Element.NumExpansions)
999 NumExpansions = *Element.NumExpansions + 1;
1000 Record.push_back(NumExpansions);
1001 }
1002 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001003
Richard Smith290d8012016-04-06 17:06:00 +00001004 Record.AddDeclRef(E->getDictWithObjectsMethod());
1005 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001006 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1007}
1008
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001009void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001010 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001011 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1012 Record.AddSourceLocation(E->getAtLoc());
1013 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001014 Code = serialization::EXPR_OBJC_ENCODE;
Chris Lattner1f551822009-04-27 06:20:01 +00001015}
1016
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001017void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001018 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001019 Record.AddSelectorRef(E->getSelector());
1020 Record.AddSourceLocation(E->getAtLoc());
1021 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001022 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001023}
1024
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001025void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001026 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001027 Record.AddDeclRef(E->getProtocol());
1028 Record.AddSourceLocation(E->getAtLoc());
1029 Record.AddSourceLocation(E->ProtoLoc);
1030 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001031 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001032}
1033
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001034void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001035 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001036 Record.AddDeclRef(E->getDecl());
1037 Record.AddSourceLocation(E->getLocation());
1038 Record.AddSourceLocation(E->getOpLoc());
1039 Record.AddStmt(E->getBase());
Chris Lattner1f551822009-04-27 06:20:01 +00001040 Record.push_back(E->isArrow());
1041 Record.push_back(E->isFreeIvar());
Sebastian Redl539c5062010-08-18 23:57:32 +00001042 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001043}
1044
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001045void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001046 VisitExpr(E);
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001047 Record.push_back(E->SetterAndMethodRefFlags.getInt());
John McCallb7bd14f2010-12-02 01:19:52 +00001048 Record.push_back(E->isImplicitProperty());
1049 if (E->isImplicitProperty()) {
Richard Smith290d8012016-04-06 17:06:00 +00001050 Record.AddDeclRef(E->getImplicitPropertyGetter());
1051 Record.AddDeclRef(E->getImplicitPropertySetter());
John McCallb7bd14f2010-12-02 01:19:52 +00001052 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001053 Record.AddDeclRef(E->getExplicitProperty());
John McCallb7bd14f2010-12-02 01:19:52 +00001054 }
Richard Smith290d8012016-04-06 17:06:00 +00001055 Record.AddSourceLocation(E->getLocation());
1056 Record.AddSourceLocation(E->getReceiverLocation());
John McCallb7bd14f2010-12-02 01:19:52 +00001057 if (E->isObjectReceiver()) {
1058 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +00001059 Record.AddStmt(E->getBase());
John McCallb7bd14f2010-12-02 01:19:52 +00001060 } else if (E->isSuperReceiver()) {
1061 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001062 Record.AddTypeRef(E->getSuperReceiverType());
John McCallb7bd14f2010-12-02 01:19:52 +00001063 } else {
1064 Record.push_back(2);
Richard Smith290d8012016-04-06 17:06:00 +00001065 Record.AddDeclRef(E->getClassReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001066 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001067
Sebastian Redl539c5062010-08-18 23:57:32 +00001068 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001069}
1070
Ted Kremeneke65b0862012-03-06 20:05:56 +00001071void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1072 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001073 Record.AddSourceLocation(E->getRBracket());
1074 Record.AddStmt(E->getBaseExpr());
1075 Record.AddStmt(E->getKeyExpr());
1076 Record.AddDeclRef(E->getAtIndexMethodDecl());
1077 Record.AddDeclRef(E->setAtIndexMethodDecl());
Fangrui Song6907ce22018-07-30 19:24:48 +00001078
Ted Kremeneke65b0862012-03-06 20:05:56 +00001079 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1080}
1081
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001082void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001083 VisitExpr(E);
1084 Record.push_back(E->getNumArgs());
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001085 Record.push_back(E->getNumStoredSelLocs());
1086 Record.push_back(E->SelLocsKind);
John McCall31168b02011-06-15 23:02:42 +00001087 Record.push_back(E->isDelegateInitCall());
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +00001088 Record.push_back(E->IsImplicit);
Douglas Gregor9a129192010-04-21 00:45:42 +00001089 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1090 switch (E->getReceiverKind()) {
1091 case ObjCMessageExpr::Instance:
Richard Smith290d8012016-04-06 17:06:00 +00001092 Record.AddStmt(E->getInstanceReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001093 break;
1094
1095 case ObjCMessageExpr::Class:
Richard Smith290d8012016-04-06 17:06:00 +00001096 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
Douglas Gregor9a129192010-04-21 00:45:42 +00001097 break;
1098
1099 case ObjCMessageExpr::SuperClass:
1100 case ObjCMessageExpr::SuperInstance:
Richard Smith290d8012016-04-06 17:06:00 +00001101 Record.AddTypeRef(E->getSuperType());
1102 Record.AddSourceLocation(E->getSuperLoc());
Douglas Gregor9a129192010-04-21 00:45:42 +00001103 break;
1104 }
1105
1106 if (E->getMethodDecl()) {
1107 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001108 Record.AddDeclRef(E->getMethodDecl());
Douglas Gregor9a129192010-04-21 00:45:42 +00001109 } else {
1110 Record.push_back(0);
Fangrui Song6907ce22018-07-30 19:24:48 +00001111 Record.AddSelectorRef(E->getSelector());
Douglas Gregor9a129192010-04-21 00:45:42 +00001112 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001113
Richard Smith290d8012016-04-06 17:06:00 +00001114 Record.AddSourceLocation(E->getLeftLoc());
1115 Record.AddSourceLocation(E->getRightLoc());
Chris Lattner1f551822009-04-27 06:20:01 +00001116
1117 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1118 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +00001119 Record.AddStmt(*Arg);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001120
1121 SourceLocation *Locs = E->getStoredSelLocs();
1122 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001123 Record.AddSourceLocation(Locs[i]);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001124
Sebastian Redl539c5062010-08-18 23:57:32 +00001125 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001126}
1127
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001128void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00001129 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001130 Record.AddStmt(S->getElement());
1131 Record.AddStmt(S->getCollection());
1132 Record.AddStmt(S->getBody());
1133 Record.AddSourceLocation(S->getForLoc());
1134 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001135 Code = serialization::STMT_OBJC_FOR_COLLECTION;
Chris Lattner1f551822009-04-27 06:20:01 +00001136}
1137
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001138void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001139 Record.AddStmt(S->getCatchBody());
1140 Record.AddDeclRef(S->getCatchParamDecl());
1141 Record.AddSourceLocation(S->getAtCatchLoc());
1142 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001143 Code = serialization::STMT_OBJC_CATCH;
Chris Lattner1f551822009-04-27 06:20:01 +00001144}
1145
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001146void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001147 Record.AddStmt(S->getFinallyBody());
1148 Record.AddSourceLocation(S->getAtFinallyLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001149 Code = serialization::STMT_OBJC_FINALLY;
Chris Lattner1f551822009-04-27 06:20:01 +00001150}
1151
John McCall31168b02011-06-15 23:02:42 +00001152void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001153 Record.AddStmt(S->getSubStmt());
1154 Record.AddSourceLocation(S->getAtLoc());
John McCall31168b02011-06-15 23:02:42 +00001155 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1156}
1157
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001158void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor96c79492010-04-23 22:50:49 +00001159 Record.push_back(S->getNumCatchStmts());
Craig Toppera13603a2014-05-22 05:54:18 +00001160 Record.push_back(S->getFinallyStmt() != nullptr);
Richard Smith290d8012016-04-06 17:06:00 +00001161 Record.AddStmt(S->getTryBody());
Douglas Gregor96c79492010-04-23 22:50:49 +00001162 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001163 Record.AddStmt(S->getCatchStmt(I));
Douglas Gregor96c79492010-04-23 22:50:49 +00001164 if (S->getFinallyStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001165 Record.AddStmt(S->getFinallyStmt());
1166 Record.AddSourceLocation(S->getAtTryLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001167 Code = serialization::STMT_OBJC_AT_TRY;
Chris Lattner1f551822009-04-27 06:20:01 +00001168}
1169
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001170void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001171 Record.AddStmt(S->getSynchExpr());
1172 Record.AddStmt(S->getSynchBody());
1173 Record.AddSourceLocation(S->getAtSynchronizedLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001174 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
Chris Lattner1f551822009-04-27 06:20:01 +00001175}
1176
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001177void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001178 Record.AddStmt(S->getThrowExpr());
1179 Record.AddSourceLocation(S->getThrowLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001180 Code = serialization::STMT_OBJC_AT_THROW;
Chris Lattner1f551822009-04-27 06:20:01 +00001181}
1182
Ted Kremeneke65b0862012-03-06 20:05:56 +00001183void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1184 VisitExpr(E);
1185 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001186 Record.AddSourceLocation(E->getLocation());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001187 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1188}
1189
Erik Pilkington29099de2016-07-16 00:35:23 +00001190void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1191 VisitExpr(E);
1192 Record.AddSourceRange(E->getSourceRange());
1193 Record.AddVersionTuple(E->getVersion());
1194 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1195}
1196
Chris Lattner1f551822009-04-27 06:20:01 +00001197//===----------------------------------------------------------------------===//
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001198// C++ Expressions and Statements.
1199//===----------------------------------------------------------------------===//
1200
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001201void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001202 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001203 Record.AddSourceLocation(S->getCatchLoc());
1204 Record.AddDeclRef(S->getExceptionDecl());
1205 Record.AddStmt(S->getHandlerBlock());
Sebastian Redl539c5062010-08-18 23:57:32 +00001206 Code = serialization::STMT_CXX_CATCH;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001207}
1208
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001209void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001210 VisitStmt(S);
1211 Record.push_back(S->getNumHandlers());
Richard Smith290d8012016-04-06 17:06:00 +00001212 Record.AddSourceLocation(S->getTryLoc());
1213 Record.AddStmt(S->getTryBlock());
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001214 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001215 Record.AddStmt(S->getHandler(i));
Sebastian Redl539c5062010-08-18 23:57:32 +00001216 Code = serialization::STMT_CXX_TRY;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001217}
1218
Richard Smith02e85f32011-04-14 22:09:26 +00001219void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1220 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001221 Record.AddSourceLocation(S->getForLoc());
1222 Record.AddSourceLocation(S->getCoawaitLoc());
1223 Record.AddSourceLocation(S->getColonLoc());
1224 Record.AddSourceLocation(S->getRParenLoc());
1225 Record.AddStmt(S->getRangeStmt());
1226 Record.AddStmt(S->getBeginStmt());
1227 Record.AddStmt(S->getEndStmt());
1228 Record.AddStmt(S->getCond());
1229 Record.AddStmt(S->getInc());
1230 Record.AddStmt(S->getLoopVarStmt());
1231 Record.AddStmt(S->getBody());
Richard Smith02e85f32011-04-14 22:09:26 +00001232 Code = serialization::STMT_CXX_FOR_RANGE;
1233}
1234
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001235void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1236 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001237 Record.AddSourceLocation(S->getKeywordLoc());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001238 Record.push_back(S->isIfExists());
Richard Smith290d8012016-04-06 17:06:00 +00001239 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1240 Record.AddDeclarationNameInfo(S->getNameInfo());
1241 Record.AddStmt(S->getSubStmt());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001242 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1243}
1244
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001245void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001246 VisitCallExpr(E);
1247 Record.push_back(E->getOperator());
Richard Smith290d8012016-04-06 17:06:00 +00001248 Record.AddSourceRange(E->Range);
Adam Nemet484aa452017-03-27 19:17:25 +00001249 Record.push_back(E->getFPFeatures().getInt());
Sebastian Redl539c5062010-08-18 23:57:32 +00001250 Code = serialization::EXPR_CXX_OPERATOR_CALL;
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001251}
1252
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001253void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001254 VisitCallExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001255 Code = serialization::EXPR_CXX_MEMBER_CALL;
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001256}
1257
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001258void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001259 VisitExpr(E);
Argyrios Kyrtzidis30d98f32010-06-24 08:57:09 +00001260 Record.push_back(E->getNumArgs());
1261 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001262 Record.AddStmt(E->getArg(I));
1263 Record.AddDeclRef(E->getConstructor());
1264 Record.AddSourceLocation(E->getLocation());
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001265 Record.push_back(E->isElidable());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00001266 Record.push_back(E->hadMultipleCandidates());
Richard Smithd59b8322012-12-19 01:39:02 +00001267 Record.push_back(E->isListInitialization());
Richard Smithf8adcdc2014-07-17 05:12:35 +00001268 Record.push_back(E->isStdInitListInitialization());
Douglas Gregor4f4b1862009-12-16 18:50:27 +00001269 Record.push_back(E->requiresZeroInitialization());
Douglas Gregor222cf0e2010-05-15 00:13:29 +00001270 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +00001271 Record.AddSourceRange(E->getParenOrBraceRange());
Sebastian Redl539c5062010-08-18 23:57:32 +00001272 Code = serialization::EXPR_CXX_CONSTRUCT;
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001273}
1274
Richard Smith5179eb72016-06-28 19:03:57 +00001275void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1276 VisitExpr(E);
1277 Record.AddDeclRef(E->getConstructor());
1278 Record.AddSourceLocation(E->getLocation());
1279 Record.push_back(E->constructsVBase());
1280 Record.push_back(E->inheritedFromVBase());
1281 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1282}
1283
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001284void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001285 VisitCXXConstructExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001286 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001287 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001288}
1289
Douglas Gregore31e6062012-02-07 10:09:13 +00001290void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1291 VisitExpr(E);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001292 Record.push_back(E->NumCaptures);
Richard Smith290d8012016-04-06 17:06:00 +00001293 Record.AddSourceRange(E->IntroducerRange);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001294 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +00001295 Record.AddSourceLocation(E->CaptureDefaultLoc);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001296 Record.push_back(E->ExplicitParams);
1297 Record.push_back(E->ExplicitResultType);
Richard Smith290d8012016-04-06 17:06:00 +00001298 Record.AddSourceLocation(E->ClosingBrace);
Fangrui Song6907ce22018-07-30 19:24:48 +00001299
Douglas Gregor99ae8062012-02-14 17:54:36 +00001300 // Add capture initializers.
1301 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1302 CEnd = E->capture_init_end();
1303 C != CEnd; ++C) {
Richard Smith290d8012016-04-06 17:06:00 +00001304 Record.AddStmt(*C);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001305 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001306
Douglas Gregor99ae8062012-02-14 17:54:36 +00001307 Code = serialization::EXPR_LAMBDA;
Douglas Gregore31e6062012-02-07 10:09:13 +00001308}
1309
Richard Smithcc1b96d2013-06-12 22:31:48 +00001310void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1311 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001312 Record.AddStmt(E->getSubExpr());
Richard Smithcc1b96d2013-06-12 22:31:48 +00001313 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1314}
1315
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001316void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001317 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001318 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1319 Record.AddSourceRange(E->getAngleBrackets());
Sam Weinigd01101e2010-01-16 21:21:01 +00001320}
1321
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001322void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001323 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001324 Code = serialization::EXPR_CXX_STATIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001325}
1326
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001327void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001328 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001329 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001330}
1331
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001332void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001333 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001334 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001335}
1336
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001337void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001338 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001339 Code = serialization::EXPR_CXX_CONST_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001340}
1341
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001342void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001343 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001344 Record.AddSourceLocation(E->getLParenLoc());
1345 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001346 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001347}
1348
Richard Smithc67fdd42012-03-07 08:35:16 +00001349void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1350 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001351 Record.AddSourceLocation(E->UDSuffixLoc);
Richard Smithc67fdd42012-03-07 08:35:16 +00001352 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1353}
1354
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001355void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001356 VisitExpr(E);
1357 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001358 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001359 Code = serialization::EXPR_CXX_BOOL_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001360}
1361
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001362void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001363 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001364 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001365 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001366}
1367
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001368void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001369 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001370 Record.AddSourceRange(E->getSourceRange());
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001371 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001372 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001373 Code = serialization::EXPR_CXX_TYPEID_TYPE;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001374 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001375 Record.AddStmt(E->getExprOperand());
Sebastian Redl539c5062010-08-18 23:57:32 +00001376 Code = serialization::EXPR_CXX_TYPEID_EXPR;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001377 }
1378}
1379
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001380void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner98267332010-05-09 06:15:05 +00001381 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001382 Record.AddSourceLocation(E->getLocation());
Chris Lattner98267332010-05-09 06:15:05 +00001383 Record.push_back(E->isImplicit());
Sebastian Redl539c5062010-08-18 23:57:32 +00001384 Code = serialization::EXPR_CXX_THIS;
Chris Lattner98267332010-05-09 06:15:05 +00001385}
1386
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001387void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001388 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001389 Record.AddSourceLocation(E->getThrowLoc());
1390 Record.AddStmt(E->getSubExpr());
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001391 Record.push_back(E->isThrownVariableInScope());
Sebastian Redl539c5062010-08-18 23:57:32 +00001392 Code = serialization::EXPR_CXX_THROW;
Chris Lattner98267332010-05-09 06:15:05 +00001393}
1394
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001395void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001396 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001397 Record.AddDeclRef(E->getParam());
1398 Record.AddSourceLocation(E->getUsedLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001399 Code = serialization::EXPR_CXX_DEFAULT_ARG;
Chris Lattnere2437f42010-05-09 06:40:08 +00001400}
1401
Richard Smith852c9db2013-04-20 22:23:05 +00001402void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1403 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001404 Record.AddDeclRef(E->getField());
1405 Record.AddSourceLocation(E->getExprLoc());
Richard Smith852c9db2013-04-20 22:23:05 +00001406 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1407}
1408
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001409void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001410 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001411 Record.AddCXXTemporary(E->getTemporary());
1412 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +00001413 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
Chris Lattnercba86142010-05-10 00:25:06 +00001414}
1415
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001416void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001417 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001418 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1419 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001420 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001421}
1422
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001423void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001424 VisitExpr(E);
1425 Record.push_back(E->isGlobalNew());
Sebastian Redlc3a3c602012-02-16 11:35:52 +00001426 Record.push_back(E->isArray());
Richard Smithb2f0f052016-10-10 18:54:32 +00001427 Record.push_back(E->passAlignment());
Sebastian Redl6047f072012-02-16 12:22:20 +00001428 Record.push_back(E->doesUsualArrayDeleteWantSize());
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001429 Record.push_back(E->getNumPlacementArgs());
Sebastian Redl6047f072012-02-16 12:22:20 +00001430 Record.push_back(E->StoredInitializationStyle);
Richard Smith290d8012016-04-06 17:06:00 +00001431 Record.AddDeclRef(E->getOperatorNew());
1432 Record.AddDeclRef(E->getOperatorDelete());
1433 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1434 Record.AddSourceRange(E->getTypeIdParens());
1435 Record.AddSourceRange(E->getSourceRange());
1436 Record.AddSourceRange(E->getDirectInitRange());
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001437 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
1438 I != e; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001439 Record.AddStmt(*I);
Sebastian Redl6047f072012-02-16 12:22:20 +00001440
Sebastian Redl539c5062010-08-18 23:57:32 +00001441 Code = serialization::EXPR_CXX_NEW;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001442}
1443
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001444void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001445 VisitExpr(E);
1446 Record.push_back(E->isGlobalDelete());
1447 Record.push_back(E->isArrayForm());
Argyrios Kyrtzidis14ec9f62010-09-13 20:15:54 +00001448 Record.push_back(E->isArrayFormAsWritten());
John McCall284c48f2011-01-27 09:37:56 +00001449 Record.push_back(E->doesUsualArrayDeleteWantSize());
Richard Smith290d8012016-04-06 17:06:00 +00001450 Record.AddDeclRef(E->getOperatorDelete());
1451 Record.AddStmt(E->getArgument());
1452 Record.AddSourceLocation(E->getSourceRange().getBegin());
Fangrui Song6907ce22018-07-30 19:24:48 +00001453
Sebastian Redl539c5062010-08-18 23:57:32 +00001454 Code = serialization::EXPR_CXX_DELETE;
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001455}
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001456
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001457void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001458 VisitExpr(E);
1459
Richard Smith290d8012016-04-06 17:06:00 +00001460 Record.AddStmt(E->getBase());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001461 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001462 Record.AddSourceLocation(E->getOperatorLoc());
1463 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1464 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1465 Record.AddSourceLocation(E->getColonColonLoc());
1466 Record.AddSourceLocation(E->getTildeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001467
1468 // PseudoDestructorTypeStorage.
Richard Smith290d8012016-04-06 17:06:00 +00001469 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001470 if (E->getDestroyedTypeIdentifier())
Richard Smith290d8012016-04-06 17:06:00 +00001471 Record.AddSourceLocation(E->getDestroyedTypeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001472 else
Richard Smith290d8012016-04-06 17:06:00 +00001473 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001474
Sebastian Redl539c5062010-08-18 23:57:32 +00001475 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001476}
1477
John McCall5d413782010-12-06 08:20:24 +00001478void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001479 VisitExpr(E);
John McCall28fc7092011-11-10 05:35:25 +00001480 Record.push_back(E->getNumObjects());
1481 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001482 Record.AddDeclRef(E->getObject(i));
Tim Shen4a05bb82016-06-21 20:29:17 +00001483
1484 Record.push_back(E->cleanupsHaveSideEffects());
Richard Smith290d8012016-04-06 17:06:00 +00001485 Record.AddStmt(E->getSubExpr());
John McCall5d413782010-12-06 08:20:24 +00001486 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
Chris Lattnercba86142010-05-10 00:25:06 +00001487}
1488
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001489void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001490ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001491 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001492
1493 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
Douglas Gregor87866ce2011-02-04 12:01:24 +00001494 // emitted first.
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001495
Abramo Bagnara7945c982012-01-27 09:46:47 +00001496 Record.push_back(E->HasTemplateKWAndArgsInfo);
1497 if (E->HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001498 const ASTTemplateKWAndArgsInfo &ArgInfo =
1499 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1500 Record.push_back(ArgInfo.NumTemplateArgs);
1501 AddTemplateKWAndArgsInfo(ArgInfo,
1502 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001503 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00001504
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001505 if (!E->isImplicitAccess())
Richard Smith290d8012016-04-06 17:06:00 +00001506 Record.AddStmt(E->getBase());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001507 else
Richard Smith290d8012016-04-06 17:06:00 +00001508 Record.AddStmt(nullptr);
1509 Record.AddTypeRef(E->getBaseType());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001510 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001511 Record.AddSourceLocation(E->getOperatorLoc());
1512 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1513 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1514 Record.AddDeclarationNameInfo(E->MemberNameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001515 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001516}
1517
1518void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001519ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001520 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001521
1522 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
Douglas Gregor87866ce2011-02-04 12:01:24 +00001523 // emitted first.
Abramo Bagnara7945c982012-01-27 09:46:47 +00001524
1525 Record.push_back(E->HasTemplateKWAndArgsInfo);
1526 if (E->HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001527 const ASTTemplateKWAndArgsInfo &ArgInfo =
1528 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1529 Record.push_back(ArgInfo.NumTemplateArgs);
1530 AddTemplateKWAndArgsInfo(ArgInfo,
1531 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001532 }
1533
Richard Smith290d8012016-04-06 17:06:00 +00001534 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1535 Record.AddDeclarationNameInfo(E->NameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001536 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001537}
1538
1539void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001540ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001541 VisitExpr(E);
1542 Record.push_back(E->arg_size());
1543 for (CXXUnresolvedConstructExpr::arg_iterator
1544 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
Richard Smith290d8012016-04-06 17:06:00 +00001545 Record.AddStmt(*ArgI);
1546 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1547 Record.AddSourceLocation(E->getLParenLoc());
1548 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001549 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001550}
Chris Lattner98267332010-05-09 06:15:05 +00001551
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001552void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001553 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001554
1555 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1556 // emitted first.
1557
1558 Record.push_back(E->HasTemplateKWAndArgsInfo);
1559 if (E->HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001560 const ASTTemplateKWAndArgsInfo &ArgInfo =
1561 *E->getTrailingASTTemplateKWAndArgsInfo();
1562 Record.push_back(ArgInfo.NumTemplateArgs);
1563 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001564 }
1565
1566 Record.push_back(E->getNumDecls());
1567 for (OverloadExpr::decls_iterator
1568 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
Richard Smith290d8012016-04-06 17:06:00 +00001569 Record.AddDeclRef(OvI.getDecl());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001570 Record.push_back(OvI.getAccess());
1571 }
1572
Richard Smith290d8012016-04-06 17:06:00 +00001573 Record.AddDeclarationNameInfo(E->NameInfo);
1574 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001575}
1576
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001577void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001578 VisitOverloadExpr(E);
1579 Record.push_back(E->isArrow());
1580 Record.push_back(E->hasUnresolvedUsing());
Richard Smith290d8012016-04-06 17:06:00 +00001581 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1582 Record.AddTypeRef(E->getBaseType());
1583 Record.AddSourceLocation(E->getOperatorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001584 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001585}
1586
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001587void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001588 VisitOverloadExpr(E);
1589 Record.push_back(E->requiresADL());
1590 Record.push_back(E->isOverloaded());
Richard Smith290d8012016-04-06 17:06:00 +00001591 Record.AddDeclRef(E->getNamingClass());
Sebastian Redl539c5062010-08-18 23:57:32 +00001592 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001593}
1594
Douglas Gregor29c42f22012-02-24 07:38:34 +00001595void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1596 VisitExpr(E);
1597 Record.push_back(E->TypeTraitExprBits.NumArgs);
1598 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1599 Record.push_back(E->TypeTraitExprBits.Value);
Richard Smith290d8012016-04-06 17:06:00 +00001600 Record.AddSourceRange(E->getSourceRange());
Douglas Gregor29c42f22012-02-24 07:38:34 +00001601 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001602 Record.AddTypeSourceInfo(E->getArg(I));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001603 Code = serialization::EXPR_TYPE_TRAIT;
1604}
1605
John Wiegley6242b6a2011-04-28 00:16:57 +00001606void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1607 VisitExpr(E);
1608 Record.push_back(E->getTrait());
1609 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001610 Record.AddSourceRange(E->getSourceRange());
1611 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
Aleksei Sidorina693b372016-09-28 10:16:56 +00001612 Record.AddStmt(E->getDimensionExpression());
John Wiegley6242b6a2011-04-28 00:16:57 +00001613 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1614}
1615
John Wiegleyf9f65842011-04-25 06:54:41 +00001616void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1617 VisitExpr(E);
1618 Record.push_back(E->getTrait());
1619 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001620 Record.AddSourceRange(E->getSourceRange());
1621 Record.AddStmt(E->getQueriedExpression());
John Wiegleyf9f65842011-04-25 06:54:41 +00001622 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1623}
1624
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001625void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1626 VisitExpr(E);
1627 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001628 Record.AddSourceRange(E->getSourceRange());
1629 Record.AddStmt(E->getOperand());
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001630 Code = serialization::EXPR_CXX_NOEXCEPT;
1631}
1632
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001633void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1634 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001635 Record.AddSourceLocation(E->getEllipsisLoc());
Douglas Gregorb8840002011-01-14 21:20:45 +00001636 Record.push_back(E->NumExpansions);
Richard Smith290d8012016-04-06 17:06:00 +00001637 Record.AddStmt(E->getPattern());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001638 Code = serialization::EXPR_PACK_EXPANSION;
1639}
1640
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001641void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1642 VisitExpr(E);
Richard Smithd784e682015-09-23 21:41:42 +00001643 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1644 : 0);
Richard Smith290d8012016-04-06 17:06:00 +00001645 Record.AddSourceLocation(E->OperatorLoc);
1646 Record.AddSourceLocation(E->PackLoc);
1647 Record.AddSourceLocation(E->RParenLoc);
1648 Record.AddDeclRef(E->Pack);
Richard Smithd784e682015-09-23 21:41:42 +00001649 if (E->isPartiallySubstituted()) {
1650 for (const auto &TA : E->getPartialArguments())
Richard Smith290d8012016-04-06 17:06:00 +00001651 Record.AddTemplateArgument(TA);
Richard Smithd784e682015-09-23 21:41:42 +00001652 } else if (!E->isValueDependent()) {
1653 Record.push_back(E->getPackLength());
1654 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001655 Code = serialization::EXPR_SIZEOF_PACK;
1656}
1657
John McCallfa194042011-07-15 07:00:14 +00001658void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1659 SubstNonTypeTemplateParmExpr *E) {
1660 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001661 Record.AddDeclRef(E->getParameter());
1662 Record.AddSourceLocation(E->getNameLoc());
1663 Record.AddStmt(E->getReplacement());
John McCallfa194042011-07-15 07:00:14 +00001664 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1665}
1666
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001667void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1668 SubstNonTypeTemplateParmPackExpr *E) {
1669 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001670 Record.AddDeclRef(E->getParameterPack());
1671 Record.AddTemplateArgument(E->getArgumentPack());
1672 Record.AddSourceLocation(E->getParameterPackLocation());
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001673 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1674}
1675
Richard Smithb15fe3a2012-09-12 00:56:43 +00001676void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1677 VisitExpr(E);
1678 Record.push_back(E->getNumExpansions());
Richard Smith290d8012016-04-06 17:06:00 +00001679 Record.AddDeclRef(E->getParameterPack());
1680 Record.AddSourceLocation(E->getParameterPackLocation());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001681 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1682 I != End; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001683 Record.AddDeclRef(*I);
Richard Smithb15fe3a2012-09-12 00:56:43 +00001684 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1685}
1686
Douglas Gregorfe314812011-06-21 17:03:29 +00001687void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1688 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001689 Record.AddStmt(E->getTemporary());
1690 Record.AddDeclRef(E->getExtendingDecl());
David Majnemerdaff3702014-05-01 17:50:17 +00001691 Record.push_back(E->getManglingNumber());
Douglas Gregorfe314812011-06-21 17:03:29 +00001692 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1693}
1694
Richard Smith0f0af192014-11-08 05:07:16 +00001695void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1696 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001697 Record.AddSourceLocation(E->LParenLoc);
1698 Record.AddSourceLocation(E->EllipsisLoc);
1699 Record.AddSourceLocation(E->RParenLoc);
1700 Record.AddStmt(E->SubExprs[0]);
1701 Record.AddStmt(E->SubExprs[1]);
Richard Smith0f0af192014-11-08 05:07:16 +00001702 Record.push_back(E->Opcode);
1703 Code = serialization::EXPR_CXX_FOLD;
1704}
1705
John McCall8d69a212010-11-15 23:31:06 +00001706void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1707 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001708 Record.AddStmt(E->getSourceExpr());
1709 Record.AddSourceLocation(E->getLocation());
Akira Hatanaka797afe32018-03-20 01:47:58 +00001710 Record.push_back(E->isUnique());
John McCall8d69a212010-11-15 23:31:06 +00001711 Code = serialization::EXPR_OPAQUE_VALUE;
1712}
1713
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001714void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1715 VisitExpr(E);
1716 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
Davide Italiano04839a52016-01-30 08:03:54 +00001717 llvm_unreachable("Cannot write TypoExpr nodes");
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001718}
1719
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001720//===----------------------------------------------------------------------===//
Peter Collingbourne41f85462011-02-09 21:07:24 +00001721// CUDA Expressions and Statements.
1722//===----------------------------------------------------------------------===//
1723
1724void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1725 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001726 Record.AddStmt(E->getConfig());
Peter Collingbourne41f85462011-02-09 21:07:24 +00001727 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1728}
1729
1730//===----------------------------------------------------------------------===//
Tanya Lattner55808c12011-06-04 00:47:47 +00001731// OpenCL Expressions and Statements.
1732//===----------------------------------------------------------------------===//
1733void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1734 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001735 Record.AddSourceLocation(E->getBuiltinLoc());
1736 Record.AddSourceLocation(E->getRParenLoc());
1737 Record.AddStmt(E->getSrcExpr());
Tanya Lattner55808c12011-06-04 00:47:47 +00001738 Code = serialization::EXPR_ASTYPE;
1739}
1740
1741//===----------------------------------------------------------------------===//
John McCallfa194042011-07-15 07:00:14 +00001742// Microsoft Expressions and Statements.
1743//===----------------------------------------------------------------------===//
John McCall5e77d762013-04-16 07:28:30 +00001744void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1745 VisitExpr(E);
1746 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001747 Record.AddStmt(E->getBaseExpr());
1748 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1749 Record.AddSourceLocation(E->getMemberLoc());
1750 Record.AddDeclRef(E->getPropertyDecl());
John McCall5e77d762013-04-16 07:28:30 +00001751 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1752}
1753
Alexey Bataevf7630272015-11-25 12:01:00 +00001754void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1755 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001756 Record.AddStmt(E->getBase());
1757 Record.AddStmt(E->getIdx());
1758 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataevf7630272015-11-25 12:01:00 +00001759 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1760}
1761
John McCallfa194042011-07-15 07:00:14 +00001762void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1763 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001764 Record.AddSourceRange(E->getSourceRange());
1765 Record.AddString(E->getUuidStr());
John McCallfa194042011-07-15 07:00:14 +00001766 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001767 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
John McCallfa194042011-07-15 07:00:14 +00001768 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1769 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001770 Record.AddStmt(E->getExprOperand());
John McCallfa194042011-07-15 07:00:14 +00001771 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1772 }
1773}
1774
1775void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1776 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001777 Record.AddSourceLocation(S->getExceptLoc());
1778 Record.AddStmt(S->getFilterExpr());
1779 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001780 Code = serialization::STMT_SEH_EXCEPT;
1781}
1782
1783void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1784 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001785 Record.AddSourceLocation(S->getFinallyLoc());
1786 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001787 Code = serialization::STMT_SEH_FINALLY;
1788}
1789
1790void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1791 VisitStmt(S);
1792 Record.push_back(S->getIsCXXTry());
Richard Smith290d8012016-04-06 17:06:00 +00001793 Record.AddSourceLocation(S->getTryLoc());
1794 Record.AddStmt(S->getTryBlock());
1795 Record.AddStmt(S->getHandler());
John McCallfa194042011-07-15 07:00:14 +00001796 Code = serialization::STMT_SEH_TRY;
1797}
1798
Nico Weber9b982072014-07-07 00:12:30 +00001799void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1800 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001801 Record.AddSourceLocation(S->getLeaveLoc());
Nico Weber9b982072014-07-07 00:12:30 +00001802 Code = serialization::STMT_SEH_LEAVE;
1803}
1804
John McCallfa194042011-07-15 07:00:14 +00001805//===----------------------------------------------------------------------===//
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001806// OpenMP Directives.
1807//===----------------------------------------------------------------------===//
1808void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001809 Record.AddSourceLocation(E->getBeginLoc());
Stephen Kelly1c301dc2018-08-09 21:09:38 +00001810 Record.AddSourceLocation(E->getEndLoc());
Richard Smith290d8012016-04-06 17:06:00 +00001811 OMPClauseWriter ClauseWriter(Record);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001812 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
1813 ClauseWriter.writeClause(E->getClause(i));
1814 }
Alexey Bataev68446b72014-07-18 07:47:19 +00001815 if (E->hasAssociatedStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001816 Record.AddStmt(E->getAssociatedStmt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001817}
1818
Alexander Musman3aaab662014-08-19 11:27:13 +00001819void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
1820 VisitStmt(D);
1821 Record.push_back(D->getNumClauses());
1822 Record.push_back(D->getCollapsedNumber());
1823 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001824 Record.AddStmt(D->getIterationVariable());
1825 Record.AddStmt(D->getLastIteration());
1826 Record.AddStmt(D->getCalcLastIteration());
1827 Record.AddStmt(D->getPreCond());
1828 Record.AddStmt(D->getCond());
1829 Record.AddStmt(D->getInit());
1830 Record.AddStmt(D->getInc());
1831 Record.AddStmt(D->getPreInits());
Alexey Bataev3392d762016-02-16 11:18:12 +00001832 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001833 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
1834 isOpenMPDistributeDirective(D->getDirectiveKind())) {
Richard Smith290d8012016-04-06 17:06:00 +00001835 Record.AddStmt(D->getIsLastIterVariable());
1836 Record.AddStmt(D->getLowerBoundVariable());
1837 Record.AddStmt(D->getUpperBoundVariable());
1838 Record.AddStmt(D->getStrideVariable());
1839 Record.AddStmt(D->getEnsureUpperBound());
1840 Record.AddStmt(D->getNextLowerBound());
1841 Record.AddStmt(D->getNextUpperBound());
Alexey Bataev8b427062016-05-25 12:36:08 +00001842 Record.AddStmt(D->getNumIterations());
Alexander Musmanc6388682014-12-15 07:07:06 +00001843 }
Carlo Bertolli9925f152016-06-27 14:55:37 +00001844 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
1845 Record.AddStmt(D->getPrevLowerBoundVariable());
1846 Record.AddStmt(D->getPrevUpperBoundVariable());
Carlo Bertolli8429d812017-02-17 21:29:13 +00001847 Record.AddStmt(D->getDistInc());
1848 Record.AddStmt(D->getPrevEnsureUpperBound());
Carlo Bertolliffafe102017-04-20 00:39:39 +00001849 Record.AddStmt(D->getCombinedLowerBoundVariable());
1850 Record.AddStmt(D->getCombinedUpperBoundVariable());
1851 Record.AddStmt(D->getCombinedEnsureUpperBound());
1852 Record.AddStmt(D->getCombinedInit());
1853 Record.AddStmt(D->getCombinedCond());
1854 Record.AddStmt(D->getCombinedNextLowerBound());
1855 Record.AddStmt(D->getCombinedNextUpperBound());
Carlo Bertolli9925f152016-06-27 14:55:37 +00001856 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001857 for (auto I : D->counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001858 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001859 }
Alexey Bataeva8899172015-08-06 12:30:57 +00001860 for (auto I : D->private_counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001861 Record.AddStmt(I);
Alexey Bataeva8899172015-08-06 12:30:57 +00001862 }
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001863 for (auto I : D->inits()) {
Richard Smith290d8012016-04-06 17:06:00 +00001864 Record.AddStmt(I);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001865 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001866 for (auto I : D->updates()) {
Richard Smith290d8012016-04-06 17:06:00 +00001867 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001868 }
1869 for (auto I : D->finals()) {
Richard Smith290d8012016-04-06 17:06:00 +00001870 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001871 }
Alexander Musman3aaab662014-08-19 11:27:13 +00001872}
1873
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001874void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001875 VisitStmt(D);
1876 Record.push_back(D->getNumClauses());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001877 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001878 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001879 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
1880}
1881
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001882void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001883 VisitOMPLoopDirective(D);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001884 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
1885}
1886
Alexey Bataevf29276e2014-06-18 04:14:57 +00001887void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001888 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001889 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevf29276e2014-06-18 04:14:57 +00001890 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
1891}
1892
Alexander Musmanf82886e2014-09-18 05:12:34 +00001893void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
1894 VisitOMPLoopDirective(D);
1895 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
1896}
1897
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001898void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
1899 VisitStmt(D);
1900 Record.push_back(D->getNumClauses());
1901 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001902 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001903 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
1904}
1905
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001906void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
1907 VisitStmt(D);
1908 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001909 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001910 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
1911}
1912
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00001913void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
1914 VisitStmt(D);
1915 Record.push_back(D->getNumClauses());
1916 VisitOMPExecutableDirective(D);
1917 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
1918}
1919
Alexander Musman80c22892014-07-17 08:54:58 +00001920void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
1921 VisitStmt(D);
1922 VisitOMPExecutableDirective(D);
1923 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
1924}
1925
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001926void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
1927 VisitStmt(D);
Alexey Bataev28c75412015-12-15 08:19:24 +00001928 Record.push_back(D->getNumClauses());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001929 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001930 Record.AddDeclarationNameInfo(D->getDirectiveName());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001931 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
1932}
1933
Alexey Bataev4acb8592014-07-07 13:01:15 +00001934void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001935 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001936 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev4acb8592014-07-07 13:01:15 +00001937 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
1938}
1939
Alexander Musmane4e893b2014-09-23 09:33:00 +00001940void ASTStmtWriter::VisitOMPParallelForSimdDirective(
1941 OMPParallelForSimdDirective *D) {
1942 VisitOMPLoopDirective(D);
1943 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
1944}
1945
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00001946void ASTStmtWriter::VisitOMPParallelSectionsDirective(
1947 OMPParallelSectionsDirective *D) {
1948 VisitStmt(D);
1949 Record.push_back(D->getNumClauses());
1950 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001951 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00001952 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
1953}
1954
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00001955void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
1956 VisitStmt(D);
1957 Record.push_back(D->getNumClauses());
1958 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001959 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00001960 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
1961}
1962
Alexey Bataev0162e452014-07-22 10:10:35 +00001963void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
1964 VisitStmt(D);
1965 Record.push_back(D->getNumClauses());
1966 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001967 Record.AddStmt(D->getX());
1968 Record.AddStmt(D->getV());
1969 Record.AddStmt(D->getExpr());
1970 Record.AddStmt(D->getUpdateExpr());
Alexey Bataevb4505a72015-03-30 05:20:59 +00001971 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
Alexey Bataevb78ca832015-04-01 03:33:17 +00001972 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
Alexey Bataev0162e452014-07-22 10:10:35 +00001973 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
1974}
1975
Alexey Bataev0bd520b2014-09-19 08:19:49 +00001976void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
1977 VisitStmt(D);
1978 Record.push_back(D->getNumClauses());
1979 VisitOMPExecutableDirective(D);
1980 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
1981}
1982
Michael Wong65f367f2015-07-21 13:44:28 +00001983void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
1984 VisitStmt(D);
1985 Record.push_back(D->getNumClauses());
1986 VisitOMPExecutableDirective(D);
1987 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
1988}
1989
Samuel Antaodf67fc42016-01-19 19:15:56 +00001990void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
1991 OMPTargetEnterDataDirective *D) {
1992 VisitStmt(D);
1993 Record.push_back(D->getNumClauses());
1994 VisitOMPExecutableDirective(D);
1995 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
1996}
1997
Samuel Antao72590762016-01-19 20:04:50 +00001998void ASTStmtWriter::VisitOMPTargetExitDataDirective(
1999 OMPTargetExitDataDirective *D) {
2000 VisitStmt(D);
2001 Record.push_back(D->getNumClauses());
2002 VisitOMPExecutableDirective(D);
2003 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2004}
2005
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00002006void ASTStmtWriter::VisitOMPTargetParallelDirective(
2007 OMPTargetParallelDirective *D) {
2008 VisitStmt(D);
2009 Record.push_back(D->getNumClauses());
2010 VisitOMPExecutableDirective(D);
2011 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2012}
2013
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00002014void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2015 OMPTargetParallelForDirective *D) {
2016 VisitOMPLoopDirective(D);
2017 Record.push_back(D->hasCancel() ? 1 : 0);
2018 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2019}
2020
Alexey Bataev68446b72014-07-18 07:47:19 +00002021void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2022 VisitStmt(D);
2023 VisitOMPExecutableDirective(D);
2024 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2025}
2026
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00002027void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2028 VisitStmt(D);
2029 VisitOMPExecutableDirective(D);
2030 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2031}
2032
Alexey Bataev2df347a2014-07-18 10:17:07 +00002033void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2034 VisitStmt(D);
2035 VisitOMPExecutableDirective(D);
2036 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2037}
2038
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002039void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2040 VisitStmt(D);
Alexey Bataev169d96a2017-07-18 20:17:46 +00002041 Record.push_back(D->getNumClauses());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002042 VisitOMPExecutableDirective(D);
Alexey Bataev3b1b8952017-07-25 15:53:26 +00002043 Record.AddStmt(D->getReductionRef());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002044 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2045}
2046
Alexey Bataev6125da92014-07-21 11:26:11 +00002047void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2048 VisitStmt(D);
2049 Record.push_back(D->getNumClauses());
2050 VisitOMPExecutableDirective(D);
2051 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2052}
2053
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002054void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2055 VisitStmt(D);
Alexey Bataev346265e2015-09-25 10:37:12 +00002056 Record.push_back(D->getNumClauses());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002057 VisitOMPExecutableDirective(D);
2058 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2059}
2060
Alexey Bataev13314bf2014-10-09 04:18:56 +00002061void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2062 VisitStmt(D);
2063 Record.push_back(D->getNumClauses());
2064 VisitOMPExecutableDirective(D);
2065 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2066}
2067
Alexey Bataev6d4ed052015-07-01 06:57:41 +00002068void ASTStmtWriter::VisitOMPCancellationPointDirective(
2069 OMPCancellationPointDirective *D) {
2070 VisitStmt(D);
2071 VisitOMPExecutableDirective(D);
2072 Record.push_back(D->getCancelRegion());
2073 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2074}
2075
Alexey Bataev80909872015-07-02 11:25:17 +00002076void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2077 VisitStmt(D);
Alexey Bataev87933c72015-09-18 08:07:34 +00002078 Record.push_back(D->getNumClauses());
Alexey Bataev80909872015-07-02 11:25:17 +00002079 VisitOMPExecutableDirective(D);
2080 Record.push_back(D->getCancelRegion());
2081 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2082}
2083
Alexey Bataev49f6e782015-12-01 04:18:41 +00002084void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2085 VisitOMPLoopDirective(D);
2086 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2087}
2088
Alexey Bataev0a6ed842015-12-03 09:40:15 +00002089void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2090 VisitOMPLoopDirective(D);
2091 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2092}
2093
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00002094void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2095 VisitOMPLoopDirective(D);
2096 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2097}
2098
Samuel Antao686c70c2016-05-26 17:30:50 +00002099void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2100 VisitStmt(D);
2101 Record.push_back(D->getNumClauses());
2102 VisitOMPExecutableDirective(D);
2103 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2104}
2105
Carlo Bertolli9925f152016-06-27 14:55:37 +00002106void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2107 OMPDistributeParallelForDirective *D) {
2108 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002109 Record.push_back(D->hasCancel() ? 1 : 0);
Carlo Bertolli9925f152016-06-27 14:55:37 +00002110 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2111}
2112
Kelvin Li4a39add2016-07-05 05:00:15 +00002113void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2114 OMPDistributeParallelForSimdDirective *D) {
2115 VisitOMPLoopDirective(D);
2116 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2117}
2118
Kelvin Li787f3fc2016-07-06 04:45:38 +00002119void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2120 OMPDistributeSimdDirective *D) {
2121 VisitOMPLoopDirective(D);
2122 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2123}
2124
Kelvin Lia579b912016-07-14 02:54:56 +00002125void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2126 OMPTargetParallelForSimdDirective *D) {
2127 VisitOMPLoopDirective(D);
2128 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2129}
2130
Kelvin Li986330c2016-07-20 22:57:10 +00002131void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2132 VisitOMPLoopDirective(D);
2133 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2134}
2135
Kelvin Li02532872016-08-05 14:37:37 +00002136void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2137 OMPTeamsDistributeDirective *D) {
2138 VisitOMPLoopDirective(D);
2139 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2140}
2141
Kelvin Li4e325f72016-10-25 12:50:55 +00002142void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2143 OMPTeamsDistributeSimdDirective *D) {
2144 VisitOMPLoopDirective(D);
2145 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2146}
2147
Kelvin Li579e41c2016-11-30 23:51:03 +00002148void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2149 OMPTeamsDistributeParallelForSimdDirective *D) {
2150 VisitOMPLoopDirective(D);
2151 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2152}
2153
Kelvin Li7ade93f2016-12-09 03:24:30 +00002154void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2155 OMPTeamsDistributeParallelForDirective *D) {
2156 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002157 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li7ade93f2016-12-09 03:24:30 +00002158 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2159}
2160
Kelvin Libf594a52016-12-17 05:48:59 +00002161void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2162 VisitStmt(D);
2163 Record.push_back(D->getNumClauses());
2164 VisitOMPExecutableDirective(D);
2165 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2166}
2167
Kelvin Li83c451e2016-12-25 04:52:54 +00002168void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2169 OMPTargetTeamsDistributeDirective *D) {
2170 VisitOMPLoopDirective(D);
2171 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2172}
2173
Kelvin Li80e8f562016-12-29 22:16:30 +00002174void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2175 OMPTargetTeamsDistributeParallelForDirective *D) {
2176 VisitOMPLoopDirective(D);
Alexey Bataev16e79882017-11-22 21:12:03 +00002177 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li80e8f562016-12-29 22:16:30 +00002178 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2179}
2180
Kelvin Li1851df52017-01-03 05:23:48 +00002181void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2182 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2183 VisitOMPLoopDirective(D);
2184 Code = serialization::
2185 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2186}
2187
Kelvin Lida681182017-01-10 18:08:18 +00002188void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2189 OMPTargetTeamsDistributeSimdDirective *D) {
2190 VisitOMPLoopDirective(D);
2191 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2192}
2193
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002194//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002195// ASTWriter Implementation
Chris Lattner1f551822009-04-27 06:20:01 +00002196//===----------------------------------------------------------------------===//
2197
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002198unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002199 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002200 "SwitchCase recorded twice");
2201 unsigned NextID = SwitchCaseIDs.size();
2202 SwitchCaseIDs[S] = NextID;
2203 return NextID;
2204}
2205
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002206unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002207 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002208 "SwitchCase hasn't been seen yet");
2209 return SwitchCaseIDs[S];
2210}
2211
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002212void ASTWriter::ClearSwitchCaseIDs() {
2213 SwitchCaseIDs.clear();
2214}
2215
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002216/// Write the given substatement or subexpression to the
Chris Lattner1f551822009-04-27 06:20:01 +00002217/// bitstream.
Richard Smithf50422a2016-04-06 20:12:34 +00002218void ASTWriter::WriteSubStmt(Stmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00002219 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002220 ASTStmtWriter Writer(*this, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002221 ++NumStatements;
Fangrui Song6907ce22018-07-30 19:24:48 +00002222
Chris Lattner1f551822009-04-27 06:20:01 +00002223 if (!S) {
Sebastian Redl539c5062010-08-18 23:57:32 +00002224 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002225 return;
2226 }
Mike Stump11289f42009-09-09 15:08:12 +00002227
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002228 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2229 if (I != SubStmtEntries.end()) {
2230 Record.push_back(I->second);
2231 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2232 return;
2233 }
2234
2235#ifndef NDEBUG
2236 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2237
2238 struct ParentStmtInserterRAII {
2239 Stmt *S;
2240 llvm::DenseSet<Stmt *> &ParentStmts;
2241
2242 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2243 : S(S), ParentStmts(ParentStmts) {
2244 ParentStmts.insert(S);
2245 }
2246 ~ParentStmtInserterRAII() {
2247 ParentStmts.erase(S);
2248 }
2249 };
2250
2251 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2252#endif
2253
Chris Lattner1f551822009-04-27 06:20:01 +00002254 Writer.Visit(S);
Fangrui Song6907ce22018-07-30 19:24:48 +00002255
Richard Smithb41ddae2016-04-06 20:57:53 +00002256 uint64_t Offset = Writer.Emit();
2257 SubStmtEntries[S] = Offset;
Chris Lattner1f551822009-04-27 06:20:01 +00002258}
2259
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002260/// Flush all of the statements that have been added to the
Chris Lattner1f551822009-04-27 06:20:01 +00002261/// queue via AddStmt().
Richard Smith290d8012016-04-06 17:06:00 +00002262void ASTRecordWriter::FlushStmts() {
Daniel Dunbara5acaa32012-02-29 02:39:13 +00002263 // We expect to be the only consumer of the two temporary statement maps,
2264 // assert that they are empty.
Richard Smith290d8012016-04-06 17:06:00 +00002265 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2266 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002267
Chris Lattner1f551822009-04-27 06:20:01 +00002268 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002269 Writer->WriteSubStmt(StmtsToEmit[I]);
Fangrui Song6907ce22018-07-30 19:24:48 +00002270
Richard Smith290d8012016-04-06 17:06:00 +00002271 assert(N == StmtsToEmit.size() && "record modified while being written!");
Mike Stump11289f42009-09-09 15:08:12 +00002272
Chris Lattner1f551822009-04-27 06:20:01 +00002273 // Note that we are at the end of a full expression. Any
2274 // expression records that follow this one are part of a different
2275 // expression.
Richard Smith290d8012016-04-06 17:06:00 +00002276 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002277
Richard Smith290d8012016-04-06 17:06:00 +00002278 Writer->SubStmtEntries.clear();
2279 Writer->ParentStmts.clear();
2280 }
2281
2282 StmtsToEmit.clear();
2283}
2284
2285void ASTRecordWriter::FlushSubStmts() {
2286 // For a nested statement, write out the substatements in reverse order (so
2287 // that a simple stack machine can be used when loading), and don't emit a
2288 // STMT_STOP after each one.
2289 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002290 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
Richard Smith290d8012016-04-06 17:06:00 +00002291 assert(N == StmtsToEmit.size() && "record modified while being written!");
Chris Lattner1f551822009-04-27 06:20:01 +00002292 }
Mike Stump11289f42009-09-09 15:08:12 +00002293
Chris Lattner1f551822009-04-27 06:20:01 +00002294 StmtsToEmit.clear();
Chris Lattner1f551822009-04-27 06:20:01 +00002295}