blob: e7f9f35dcc2406452146c0eaf4d12cd1e5921237 [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());
Bruno Ricci41d11c02018-10-27 18:43:27 +000076 Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro);
Sebastian Redl539c5062010-08-18 23:57:32 +000077 Code = serialization::STMT_NULL;
Chris Lattner1f551822009-04-27 06:20:01 +000078}
79
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000080void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000081 VisitStmt(S);
82 Record.push_back(S->size());
Aaron Ballmanc7e4e212014-03-17 14:19:37 +000083 for (auto *CS : S->body())
Richard Smith290d8012016-04-06 17:06:00 +000084 Record.AddStmt(CS);
85 Record.AddSourceLocation(S->getLBracLoc());
86 Record.AddSourceLocation(S->getRBracLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +000087 Code = serialization::STMT_COMPOUND;
Chris Lattner1f551822009-04-27 06:20:01 +000088}
89
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000090void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000091 VisitStmt(S);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +000092 Record.push_back(Writer.getSwitchCaseID(S));
Richard Smith290d8012016-04-06 17:06:00 +000093 Record.AddSourceLocation(S->getKeywordLoc());
94 Record.AddSourceLocation(S->getColonLoc());
Chris Lattner1f551822009-04-27 06:20:01 +000095}
96
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000097void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000098 VisitSwitchCase(S);
Bruno Ricci5b30571752018-10-28 12:30:53 +000099 Record.push_back(S->caseStmtIsGNURange());
Richard Smith290d8012016-04-06 17:06:00 +0000100 Record.AddStmt(S->getLHS());
Richard Smith290d8012016-04-06 17:06:00 +0000101 Record.AddStmt(S->getSubStmt());
Bruno Ricci5b30571752018-10-28 12:30:53 +0000102 if (S->caseStmtIsGNURange()) {
103 Record.AddStmt(S->getRHS());
104 Record.AddSourceLocation(S->getEllipsisLoc());
105 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000106 Code = serialization::STMT_CASE;
Chris Lattner1f551822009-04-27 06:20:01 +0000107}
108
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000109void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000110 VisitSwitchCase(S);
Richard Smith290d8012016-04-06 17:06:00 +0000111 Record.AddStmt(S->getSubStmt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000112 Code = serialization::STMT_DEFAULT;
Chris Lattner1f551822009-04-27 06:20:01 +0000113}
114
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000115void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000116 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000117 Record.AddDeclRef(S->getDecl());
118 Record.AddStmt(S->getSubStmt());
119 Record.AddSourceLocation(S->getIdentLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000120 Code = serialization::STMT_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000121}
122
Richard Smithc202b282012-04-14 00:33:13 +0000123void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
124 VisitStmt(S);
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000125 Record.push_back(S->getAttrs().size());
Richard Smith290d8012016-04-06 17:06:00 +0000126 Record.AddAttributes(S->getAttrs());
127 Record.AddStmt(S->getSubStmt());
128 Record.AddSourceLocation(S->getAttrLoc());
Richard Smithc202b282012-04-14 00:33:13 +0000129 Code = serialization::STMT_ATTRIBUTED;
130}
131
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000132void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000133 VisitStmt(S);
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000134
135 bool HasElse = S->getElse() != nullptr;
136 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
137 bool HasInit = S->getInit() != nullptr;
138
Richard Smithb130fe72016-06-23 19:16:49 +0000139 Record.push_back(S->isConstexpr());
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000140 Record.push_back(HasElse);
141 Record.push_back(HasVar);
142 Record.push_back(HasInit);
143
Richard Smith290d8012016-04-06 17:06:00 +0000144 Record.AddStmt(S->getCond());
145 Record.AddStmt(S->getThen());
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000146 if (HasElse)
147 Record.AddStmt(S->getElse());
148 if (HasVar)
149 Record.AddDeclRef(S->getConditionVariable());
150 if (HasInit)
151 Record.AddStmt(S->getInit());
152
Richard Smith290d8012016-04-06 17:06:00 +0000153 Record.AddSourceLocation(S->getIfLoc());
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000154 if (HasElse)
155 Record.AddSourceLocation(S->getElseLoc());
156
Sebastian Redl539c5062010-08-18 23:57:32 +0000157 Code = serialization::STMT_IF;
Chris Lattner1f551822009-04-27 06:20:01 +0000158}
159
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000160void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000161 VisitStmt(S);
Richard Smitha547eb22016-07-14 00:11:03 +0000162 Record.AddStmt(S->getInit());
Richard Smith290d8012016-04-06 17:06:00 +0000163 Record.AddDeclRef(S->getConditionVariable());
164 Record.AddStmt(S->getCond());
165 Record.AddStmt(S->getBody());
166 Record.AddSourceLocation(S->getSwitchLoc());
Ted Kremenekc42f3452010-09-09 00:05:53 +0000167 Record.push_back(S->isAllEnumCasesCovered());
Mike Stump11289f42009-09-09 15:08:12 +0000168 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
Chris Lattner1f551822009-04-27 06:20:01 +0000169 SC = SC->getNextSwitchCase())
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000170 Record.push_back(Writer.RecordSwitchCaseID(SC));
Sebastian Redl539c5062010-08-18 23:57:32 +0000171 Code = serialization::STMT_SWITCH;
Chris Lattner1f551822009-04-27 06:20:01 +0000172}
173
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000174void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000175 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000176 Record.AddDeclRef(S->getConditionVariable());
177 Record.AddStmt(S->getCond());
178 Record.AddStmt(S->getBody());
179 Record.AddSourceLocation(S->getWhileLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000180 Code = serialization::STMT_WHILE;
Chris Lattner1f551822009-04-27 06:20:01 +0000181}
182
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000183void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000184 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000185 Record.AddStmt(S->getCond());
186 Record.AddStmt(S->getBody());
187 Record.AddSourceLocation(S->getDoLoc());
188 Record.AddSourceLocation(S->getWhileLoc());
189 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000190 Code = serialization::STMT_DO;
Chris Lattner1f551822009-04-27 06:20:01 +0000191}
192
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000193void ASTStmtWriter::VisitForStmt(ForStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000194 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000195 Record.AddStmt(S->getInit());
196 Record.AddStmt(S->getCond());
197 Record.AddDeclRef(S->getConditionVariable());
198 Record.AddStmt(S->getInc());
199 Record.AddStmt(S->getBody());
200 Record.AddSourceLocation(S->getForLoc());
201 Record.AddSourceLocation(S->getLParenLoc());
202 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000203 Code = serialization::STMT_FOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000204}
205
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000206void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000207 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000208 Record.AddDeclRef(S->getLabel());
209 Record.AddSourceLocation(S->getGotoLoc());
210 Record.AddSourceLocation(S->getLabelLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000211 Code = serialization::STMT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000212}
213
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000214void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000215 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000216 Record.AddSourceLocation(S->getGotoLoc());
217 Record.AddSourceLocation(S->getStarLoc());
218 Record.AddStmt(S->getTarget());
Sebastian Redl539c5062010-08-18 23:57:32 +0000219 Code = serialization::STMT_INDIRECT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000220}
221
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000222void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000223 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000224 Record.AddSourceLocation(S->getContinueLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000225 Code = serialization::STMT_CONTINUE;
Chris Lattner1f551822009-04-27 06:20:01 +0000226}
227
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000228void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000229 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000230 Record.AddSourceLocation(S->getBreakLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000231 Code = serialization::STMT_BREAK;
Chris Lattner1f551822009-04-27 06:20:01 +0000232}
233
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000234void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000235 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000236 Record.AddStmt(S->getRetValue());
237 Record.AddSourceLocation(S->getReturnLoc());
238 Record.AddDeclRef(S->getNRVOCandidate());
Sebastian Redl539c5062010-08-18 23:57:32 +0000239 Code = serialization::STMT_RETURN;
Chris Lattner1f551822009-04-27 06:20:01 +0000240}
241
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000242void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000243 VisitStmt(S);
Stephen Kellya6e43582018-08-09 21:05:56 +0000244 Record.AddSourceLocation(S->getBeginLoc());
Richard Smith290d8012016-04-06 17:06:00 +0000245 Record.AddSourceLocation(S->getEndLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000246 DeclGroupRef DG = S->getDeclGroup();
247 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
Richard Smith290d8012016-04-06 17:06:00 +0000248 Record.AddDeclRef(*D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000249 Code = serialization::STMT_DECL;
Chris Lattner1f551822009-04-27 06:20:01 +0000250}
251
John McCallf413f5e2013-05-03 00:10:13 +0000252void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000253 VisitStmt(S);
254 Record.push_back(S->getNumOutputs());
255 Record.push_back(S->getNumInputs());
256 Record.push_back(S->getNumClobbers());
Richard Smith290d8012016-04-06 17:06:00 +0000257 Record.AddSourceLocation(S->getAsmLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000258 Record.push_back(S->isVolatile());
259 Record.push_back(S->isSimple());
John McCallf413f5e2013-05-03 00:10:13 +0000260}
261
262void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
263 VisitAsmStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000264 Record.AddSourceLocation(S->getRParenLoc());
265 Record.AddStmt(S->getAsmString());
Chris Lattner1f551822009-04-27 06:20:01 +0000266
267 // Outputs
Fangrui Song6907ce22018-07-30 19:24:48 +0000268 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000269 Record.AddIdentifierRef(S->getOutputIdentifier(I));
270 Record.AddStmt(S->getOutputConstraintLiteral(I));
271 Record.AddStmt(S->getOutputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000272 }
273
274 // Inputs
275 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000276 Record.AddIdentifierRef(S->getInputIdentifier(I));
277 Record.AddStmt(S->getInputConstraintLiteral(I));
278 Record.AddStmt(S->getInputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000279 }
280
281 // Clobbers
282 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000283 Record.AddStmt(S->getClobberStringLiteral(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000284
Chad Rosierde70e0e2012-08-25 00:11:56 +0000285 Code = serialization::STMT_GCCASM;
Chris Lattner1f551822009-04-27 06:20:01 +0000286}
287
Chad Rosier32503022012-06-11 20:47:18 +0000288void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
John McCallf413f5e2013-05-03 00:10:13 +0000289 VisitAsmStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000290 Record.AddSourceLocation(S->getLBraceLoc());
291 Record.AddSourceLocation(S->getEndLoc());
John McCallf413f5e2013-05-03 00:10:13 +0000292 Record.push_back(S->getNumAsmToks());
Richard Smith290d8012016-04-06 17:06:00 +0000293 Record.AddString(S->getAsmString());
John McCallf413f5e2013-05-03 00:10:13 +0000294
295 // Tokens
296 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000297 // FIXME: Move this to ASTRecordWriter?
298 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
John McCallf413f5e2013-05-03 00:10:13 +0000299 }
300
301 // Clobbers
302 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000303 Record.AddString(S->getClobber(I));
John McCallf413f5e2013-05-03 00:10:13 +0000304 }
305
306 // Outputs
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000307 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000308 Record.AddStmt(S->getOutputExpr(I));
309 Record.AddString(S->getOutputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000310 }
311
312 // Inputs
313 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000314 Record.AddStmt(S->getInputExpr(I));
315 Record.AddString(S->getInputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000316 }
Chad Rosiere30d4992012-08-24 23:51:02 +0000317
318 Code = serialization::STMT_MSASM;
Chad Rosier32503022012-06-11 20:47:18 +0000319}
320
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000321void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
322 VisitStmt(CoroStmt);
323 Record.push_back(CoroStmt->getParamMoves().size());
324 for (Stmt *S : CoroStmt->children())
325 Record.AddStmt(S);
326 Code = serialization::STMT_COROUTINE_BODY;
Richard Smith9f690bd2015-10-27 06:02:45 +0000327}
328
329void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000330 VisitStmt(S);
331 Record.AddSourceLocation(S->getKeywordLoc());
332 Record.AddStmt(S->getOperand());
333 Record.AddStmt(S->getPromiseCall());
334 Record.push_back(S->isImplicit());
335 Code = serialization::STMT_CORETURN;
Richard Smith9f690bd2015-10-27 06:02:45 +0000336}
337
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000338void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
339 VisitExpr(E);
340 Record.AddSourceLocation(E->getKeywordLoc());
341 for (Stmt *S : E->children())
342 Record.AddStmt(S);
343 Record.AddStmt(E->getOpaqueValue());
Richard Smith9f690bd2015-10-27 06:02:45 +0000344}
345
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000346void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
347 VisitCoroutineSuspendExpr(E);
348 Record.push_back(E->isImplicit());
349 Code = serialization::EXPR_COAWAIT;
Eric Fiselier20f25cb2017-03-06 23:38:15 +0000350}
351
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000352void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
353 VisitCoroutineSuspendExpr(E);
354 Code = serialization::EXPR_COYIELD;
355}
356
357void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
358 VisitExpr(E);
359 Record.AddSourceLocation(E->getKeywordLoc());
360 for (Stmt *S : E->children())
361 Record.AddStmt(S);
362 Code = serialization::EXPR_DEPENDENT_COAWAIT;
Richard Smith9f690bd2015-10-27 06:02:45 +0000363}
364
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000365void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
366 VisitStmt(S);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000367 // NumCaptures
368 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000369
Wei Pan17fbf6e2013-05-04 03:59:06 +0000370 // CapturedDecl and captured region kind
Richard Smith290d8012016-04-06 17:06:00 +0000371 Record.AddDeclRef(S->getCapturedDecl());
Wei Pan17fbf6e2013-05-04 03:59:06 +0000372 Record.push_back(S->getCapturedRegionKind());
373
Richard Smith290d8012016-04-06 17:06:00 +0000374 Record.AddDeclRef(S->getCapturedRecordDecl());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000375
376 // Capture inits
Aaron Ballmanba0238f2014-03-14 19:41:04 +0000377 for (auto *I : S->capture_inits())
Richard Smith290d8012016-04-06 17:06:00 +0000378 Record.AddStmt(I);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000379
380 // Body
Richard Smith290d8012016-04-06 17:06:00 +0000381 Record.AddStmt(S->getCapturedStmt());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000382
383 // Captures
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000384 for (const auto &I : S->captures()) {
Alexey Bataev330de032014-10-29 12:21:55 +0000385 if (I.capturesThis() || I.capturesVariableArrayType())
Richard Smith290d8012016-04-06 17:06:00 +0000386 Record.AddDeclRef(nullptr);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000387 else
Richard Smith290d8012016-04-06 17:06:00 +0000388 Record.AddDeclRef(I.getCapturedVar());
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000389 Record.push_back(I.getCaptureKind());
Richard Smith290d8012016-04-06 17:06:00 +0000390 Record.AddSourceLocation(I.getLocation());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000391 }
392
393 Code = serialization::STMT_CAPTURED;
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000394}
395
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000396void ASTStmtWriter::VisitExpr(Expr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000397 VisitStmt(E);
Richard Smith290d8012016-04-06 17:06:00 +0000398 Record.AddTypeRef(E->getType());
Chris Lattner1f551822009-04-27 06:20:01 +0000399 Record.push_back(E->isTypeDependent());
400 Record.push_back(E->isValueDependent());
Douglas Gregor678d76c2011-07-01 01:22:09 +0000401 Record.push_back(E->isInstantiationDependent());
Douglas Gregor506bd562010-12-13 22:49:22 +0000402 Record.push_back(E->containsUnexpandedParameterPack());
John McCall7decc9e2010-11-18 06:31:45 +0000403 Record.push_back(E->getValueKind());
404 Record.push_back(E->getObjectKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000405}
406
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000407void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000408 VisitExpr(E);
Bruno Ricci17ff0262018-10-27 19:21:19 +0000409
410 bool HasFunctionName = E->getFunctionName() != nullptr;
411 Record.push_back(HasFunctionName);
412 Record.push_back(E->getIdentKind()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000413 Record.AddSourceLocation(E->getLocation());
Bruno Ricci17ff0262018-10-27 19:21:19 +0000414 if (HasFunctionName)
415 Record.AddStmt(E->getFunctionName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000416 Code = serialization::EXPR_PREDEFINED;
Chris Lattner1f551822009-04-27 06:20:01 +0000417}
418
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000419void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000420 VisitExpr(E);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000421
422 Record.push_back(E->hasQualifier());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000423 Record.push_back(E->getDecl() != E->getFoundDecl());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000424 Record.push_back(E->hasTemplateKWAndArgsInfo());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000425 Record.push_back(E->hadMultipleCandidates());
Alexey Bataev19acc3d2015-01-12 10:17:46 +0000426 Record.push_back(E->refersToEnclosingVariableOrCapture());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000427
Abramo Bagnara7945c982012-01-27 09:46:47 +0000428 if (E->hasTemplateKWAndArgsInfo()) {
Douglas Gregor87866ce2011-02-04 12:01:24 +0000429 unsigned NumTemplateArgs = E->getNumTemplateArgs();
430 Record.push_back(NumTemplateArgs);
Douglas Gregor87866ce2011-02-04 12:01:24 +0000431 }
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000432
Douglas Gregor03412ba2011-06-03 02:27:19 +0000433 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
434
Abramo Bagnara7945c982012-01-27 09:46:47 +0000435 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000436 (E->getDecl() == E->getFoundDecl()) &&
437 nk == DeclarationName::Identifier) {
438 AbbrevToUse = Writer.getDeclRefExprAbbrev();
439 }
440
Anders Carlsson80756f62011-03-06 18:19:42 +0000441 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000442 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Anders Carlsson80756f62011-03-06 18:19:42 +0000443
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000444 if (E->getDecl() != E->getFoundDecl())
Richard Smith290d8012016-04-06 17:06:00 +0000445 Record.AddDeclRef(E->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000446
Abramo Bagnara7945c982012-01-27 09:46:47 +0000447 if (E->hasTemplateKWAndArgsInfo())
James Y Knighte7d82282015-12-29 18:15:14 +0000448 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
449 E->getTrailingObjects<TemplateArgumentLoc>());
Anders Carlsson80756f62011-03-06 18:19:42 +0000450
Richard Smith290d8012016-04-06 17:06:00 +0000451 Record.AddDeclRef(E->getDecl());
452 Record.AddSourceLocation(E->getLocation());
453 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000454 Code = serialization::EXPR_DECL_REF;
Chris Lattner1f551822009-04-27 06:20:01 +0000455}
456
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000457void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000458 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000459 Record.AddSourceLocation(E->getLocation());
460 Record.AddAPInt(E->getValue());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000461
462 if (E->getValue().getBitWidth() == 32) {
463 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
464 }
465
Sebastian Redl539c5062010-08-18 23:57:32 +0000466 Code = serialization::EXPR_INTEGER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000467}
468
Leonard Chandb01c3a2018-06-20 17:19:40 +0000469void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
470 VisitExpr(E);
471 Record.AddSourceLocation(E->getLocation());
472 Record.AddAPInt(E->getValue());
473 Code = serialization::EXPR_INTEGER_LITERAL;
474}
475
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000476void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000477 VisitExpr(E);
Tim Northover178723a2013-01-22 09:46:51 +0000478 Record.push_back(E->getRawSemantics());
Chris Lattner1f551822009-04-27 06:20:01 +0000479 Record.push_back(E->isExact());
Richard Smith290d8012016-04-06 17:06:00 +0000480 Record.AddAPFloat(E->getValue());
481 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000482 Code = serialization::EXPR_FLOATING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000483}
484
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000485void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000486 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000487 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000488 Code = serialization::EXPR_IMAGINARY_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000489}
490
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000491void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000492 VisitExpr(E);
493 Record.push_back(E->getByteLength());
494 Record.push_back(E->getNumConcatenated());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000495 Record.push_back(E->getKind());
Anders Carlsson75245402011-04-14 00:40:03 +0000496 Record.push_back(E->isPascal());
Chris Lattner1f551822009-04-27 06:20:01 +0000497 // FIXME: String data should be stored as a blob at the end of the
498 // StringLiteral. However, we can't do so now because we have no
499 // provision for coping with abbreviations when we're jumping around
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000500 // the AST file during deserialization.
Eli Friedmanfcec6302011-11-01 02:23:42 +0000501 Record.append(E->getBytes().begin(), E->getBytes().end());
Chris Lattner1f551822009-04-27 06:20:01 +0000502 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000503 Record.AddSourceLocation(E->getStrTokenLoc(I));
Sebastian Redl539c5062010-08-18 23:57:32 +0000504 Code = serialization::EXPR_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000505}
506
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000507void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000508 VisitExpr(E);
509 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +0000510 Record.AddSourceLocation(E->getLocation());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000511 Record.push_back(E->getKind());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000512
513 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
514
Sebastian Redl539c5062010-08-18 23:57:32 +0000515 Code = serialization::EXPR_CHARACTER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000516}
517
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000518void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000519 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000520 Record.AddSourceLocation(E->getLParen());
521 Record.AddSourceLocation(E->getRParen());
522 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000523 Code = serialization::EXPR_PAREN;
Chris Lattner1f551822009-04-27 06:20:01 +0000524}
525
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000526void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000527 VisitExpr(E);
528 Record.push_back(E->NumExprs);
529 for (unsigned i=0; i != E->NumExprs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +0000530 Record.AddStmt(E->Exprs[i]);
531 Record.AddSourceLocation(E->LParenLoc);
532 Record.AddSourceLocation(E->RParenLoc);
Sebastian Redl539c5062010-08-18 23:57:32 +0000533 Code = serialization::EXPR_PAREN_LIST;
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000534}
535
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000536void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000537 VisitExpr(E);
Malcolm Parsonsfab36802018-04-16 08:31:08 +0000538 Record.AddStmt(E->getSubExpr());
539 Record.push_back(E->getOpcode()); // FIXME: stable encoding
540 Record.AddSourceLocation(E->getOperatorLoc());
541 Record.push_back(E->canOverflow());
542 Code = serialization::EXPR_UNARY_OPERATOR;
543}
544
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000545void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000546 VisitExpr(E);
547 Record.push_back(E->getNumComponents());
548 Record.push_back(E->getNumExpressions());
Richard Smith290d8012016-04-06 17:06:00 +0000549 Record.AddSourceLocation(E->getOperatorLoc());
550 Record.AddSourceLocation(E->getRParenLoc());
551 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Douglas Gregor882211c2010-04-28 22:16:22 +0000552 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +0000553 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +0000554 Record.push_back(ON.getKind()); // FIXME: Stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000555 Record.AddSourceLocation(ON.getSourceRange().getBegin());
556 Record.AddSourceLocation(ON.getSourceRange().getEnd());
Douglas Gregor882211c2010-04-28 22:16:22 +0000557 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +0000558 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +0000559 Record.push_back(ON.getArrayExprIndex());
560 break;
James Y Knight7281c352015-12-29 22:31:18 +0000561
562 case OffsetOfNode::Field:
Richard Smith290d8012016-04-06 17:06:00 +0000563 Record.AddDeclRef(ON.getField());
Douglas Gregor882211c2010-04-28 22:16:22 +0000564 break;
James Y Knight7281c352015-12-29 22:31:18 +0000565
566 case OffsetOfNode::Identifier:
Richard Smith290d8012016-04-06 17:06:00 +0000567 Record.AddIdentifierRef(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +0000568 break;
James Y Knight7281c352015-12-29 22:31:18 +0000569
570 case OffsetOfNode::Base:
Richard Smith290d8012016-04-06 17:06:00 +0000571 Record.AddCXXBaseSpecifier(*ON.getBase());
Douglas Gregord1702062010-04-29 00:18:15 +0000572 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000573 }
574 }
575 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000576 Record.AddStmt(E->getIndexExpr(I));
Sebastian Redl539c5062010-08-18 23:57:32 +0000577 Code = serialization::EXPR_OFFSETOF;
Douglas Gregor882211c2010-04-28 22:16:22 +0000578}
579
Peter Collingbournee190dee2011-03-11 19:24:49 +0000580void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000581 VisitExpr(E);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000582 Record.push_back(E->getKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000583 if (E->isArgumentType())
Richard Smith290d8012016-04-06 17:06:00 +0000584 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
Chris Lattner1f551822009-04-27 06:20:01 +0000585 else {
586 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +0000587 Record.AddStmt(E->getArgumentExpr());
Chris Lattner1f551822009-04-27 06:20:01 +0000588 }
Richard Smith290d8012016-04-06 17:06:00 +0000589 Record.AddSourceLocation(E->getOperatorLoc());
590 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000591 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
Chris Lattner1f551822009-04-27 06:20:01 +0000592}
593
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000594void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000595 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000596 Record.AddStmt(E->getLHS());
597 Record.AddStmt(E->getRHS());
598 Record.AddSourceLocation(E->getRBracketLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000599 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
Chris Lattner1f551822009-04-27 06:20:01 +0000600}
601
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000602void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
603 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000604 Record.AddStmt(E->getBase());
605 Record.AddStmt(E->getLowerBound());
606 Record.AddStmt(E->getLength());
607 Record.AddSourceLocation(E->getColonLoc());
608 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000609 Code = serialization::EXPR_OMP_ARRAY_SECTION;
610}
611
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000612void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000613 VisitExpr(E);
614 Record.push_back(E->getNumArgs());
Richard Smith290d8012016-04-06 17:06:00 +0000615 Record.AddSourceLocation(E->getRParenLoc());
616 Record.AddStmt(E->getCallee());
Chris Lattner1f551822009-04-27 06:20:01 +0000617 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
618 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +0000619 Record.AddStmt(*Arg);
Sebastian Redl539c5062010-08-18 23:57:32 +0000620 Code = serialization::EXPR_CALL;
Chris Lattner1f551822009-04-27 06:20:01 +0000621}
622
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000623void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000624 // Don't call VisitExpr, we'll write everything here.
625
626 Record.push_back(E->hasQualifier());
Douglas Gregorea972d32011-02-28 21:54:11 +0000627 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000628 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000629
Abramo Bagnara7945c982012-01-27 09:46:47 +0000630 Record.push_back(E->HasTemplateKWAndArgsInfo);
631 if (E->HasTemplateKWAndArgsInfo) {
Richard Smith290d8012016-04-06 17:06:00 +0000632 Record.AddSourceLocation(E->getTemplateKeywordLoc());
Douglas Gregor87866ce2011-02-04 12:01:24 +0000633 unsigned NumTemplateArgs = E->getNumTemplateArgs();
634 Record.push_back(NumTemplateArgs);
Richard Smith290d8012016-04-06 17:06:00 +0000635 Record.AddSourceLocation(E->getLAngleLoc());
636 Record.AddSourceLocation(E->getRAngleLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000637 for (unsigned i=0; i != NumTemplateArgs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +0000638 Record.AddTemplateArgumentLoc(E->getTemplateArgs()[i]);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000639 }
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000640
641 Record.push_back(E->hadMultipleCandidates());
642
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000643 DeclAccessPair FoundDecl = E->getFoundDecl();
Richard Smith290d8012016-04-06 17:06:00 +0000644 Record.AddDeclRef(FoundDecl.getDecl());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000645 Record.push_back(FoundDecl.getAccess());
646
Richard Smith290d8012016-04-06 17:06:00 +0000647 Record.AddTypeRef(E->getType());
John McCall7decc9e2010-11-18 06:31:45 +0000648 Record.push_back(E->getValueKind());
649 Record.push_back(E->getObjectKind());
Richard Smith290d8012016-04-06 17:06:00 +0000650 Record.AddStmt(E->getBase());
651 Record.AddDeclRef(E->getMemberDecl());
652 Record.AddSourceLocation(E->getMemberLoc());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000653 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +0000654 Record.AddSourceLocation(E->getOperatorLoc());
655 Record.AddDeclarationNameLoc(E->MemberDNLoc,
656 E->getMemberDecl()->getDeclName());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000657 Code = serialization::EXPR_MEMBER;
Chris Lattner1f551822009-04-27 06:20:01 +0000658}
659
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000660void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Naroffe87026a2009-07-24 17:54:45 +0000661 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000662 Record.AddStmt(E->getBase());
663 Record.AddSourceLocation(E->getIsaMemberLoc());
664 Record.AddSourceLocation(E->getOpLoc());
Steve Naroffe87026a2009-07-24 17:54:45 +0000665 Record.push_back(E->isArrow());
Sebastian Redl539c5062010-08-18 23:57:32 +0000666 Code = serialization::EXPR_OBJC_ISA;
Steve Naroffe87026a2009-07-24 17:54:45 +0000667}
668
John McCall31168b02011-06-15 23:02:42 +0000669void ASTStmtWriter::
670VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
671 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000672 Record.AddStmt(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +0000673 Record.push_back(E->shouldCopy());
674 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
675}
676
677void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
678 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000679 Record.AddSourceLocation(E->getLParenLoc());
680 Record.AddSourceLocation(E->getBridgeKeywordLoc());
John McCall31168b02011-06-15 23:02:42 +0000681 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
682 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
683}
684
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000685void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000686 VisitExpr(E);
John McCallcf142162010-08-07 06:22:56 +0000687 Record.push_back(E->path_size());
Richard Smith290d8012016-04-06 17:06:00 +0000688 Record.AddStmt(E->getSubExpr());
Anders Carlssona2615922009-07-31 00:48:10 +0000689 Record.push_back(E->getCastKind()); // FIXME: stable encoding
John McCallcf142162010-08-07 06:22:56 +0000690
691 for (CastExpr::path_iterator
692 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
Richard Smith290d8012016-04-06 17:06:00 +0000693 Record.AddCXXBaseSpecifier(**PI);
Chris Lattner1f551822009-04-27 06:20:01 +0000694}
695
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000696void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000697 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000698 Record.AddStmt(E->getLHS());
699 Record.AddStmt(E->getRHS());
Chris Lattner1f551822009-04-27 06:20:01 +0000700 Record.push_back(E->getOpcode()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000701 Record.AddSourceLocation(E->getOperatorLoc());
Adam Nemet484aa452017-03-27 19:17:25 +0000702 Record.push_back(E->getFPFeatures().getInt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000703 Code = serialization::EXPR_BINARY_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000704}
705
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000706void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000707 VisitBinaryOperator(E);
Richard Smith290d8012016-04-06 17:06:00 +0000708 Record.AddTypeRef(E->getComputationLHSType());
709 Record.AddTypeRef(E->getComputationResultType());
Sebastian Redl539c5062010-08-18 23:57:32 +0000710 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000711}
712
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000713void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000714 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000715 Record.AddStmt(E->getCond());
716 Record.AddStmt(E->getLHS());
717 Record.AddStmt(E->getRHS());
718 Record.AddSourceLocation(E->getQuestionLoc());
719 Record.AddSourceLocation(E->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000720 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000721}
722
John McCallc07a0c72011-02-17 10:25:35 +0000723void
724ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
725 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000726 Record.AddStmt(E->getOpaqueValue());
727 Record.AddStmt(E->getCommon());
728 Record.AddStmt(E->getCond());
729 Record.AddStmt(E->getTrueExpr());
730 Record.AddStmt(E->getFalseExpr());
731 Record.AddSourceLocation(E->getQuestionLoc());
732 Record.AddSourceLocation(E->getColonLoc());
John McCallc07a0c72011-02-17 10:25:35 +0000733 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
734}
735
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000736void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000737 VisitCastExpr(E);
Roman Lebedev12216f12018-07-27 07:27:14 +0000738 Record.push_back(E->isPartOfExplicitCast());
Richard Smitha27c26e2014-07-27 04:19:32 +0000739
740 if (E->path_size() == 0)
741 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
742
Sebastian Redl539c5062010-08-18 23:57:32 +0000743 Code = serialization::EXPR_IMPLICIT_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000744}
745
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000746void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000747 VisitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000748 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
Chris Lattner1f551822009-04-27 06:20:01 +0000749}
750
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000751void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000752 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000753 Record.AddSourceLocation(E->getLParenLoc());
754 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000755 Code = serialization::EXPR_CSTYLE_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000756}
757
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000758void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000759 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000760 Record.AddSourceLocation(E->getLParenLoc());
761 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
762 Record.AddStmt(E->getInitializer());
Chris Lattner1f551822009-04-27 06:20:01 +0000763 Record.push_back(E->isFileScope());
Sebastian Redl539c5062010-08-18 23:57:32 +0000764 Code = serialization::EXPR_COMPOUND_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000765}
766
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000767void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000768 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000769 Record.AddStmt(E->getBase());
770 Record.AddIdentifierRef(&E->getAccessor());
771 Record.AddSourceLocation(E->getAccessorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000772 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
Chris Lattner1f551822009-04-27 06:20:01 +0000773}
774
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000775void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000776 VisitExpr(E);
Abramo Bagnara8d16bd42012-11-08 18:41:43 +0000777 // NOTE: only add the (possibly null) syntactic form.
778 // No need to serialize the isSemanticForm flag and the semantic form.
Richard Smith290d8012016-04-06 17:06:00 +0000779 Record.AddStmt(E->getSyntacticForm());
780 Record.AddSourceLocation(E->getLBraceLoc());
781 Record.AddSourceLocation(E->getRBraceLoc());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000782 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
783 Record.push_back(isArrayFiller);
784 if (isArrayFiller)
Richard Smith290d8012016-04-06 17:06:00 +0000785 Record.AddStmt(E->getArrayFiller());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000786 else
Richard Smith290d8012016-04-06 17:06:00 +0000787 Record.AddDeclRef(E->getInitializedFieldInUnion());
Chris Lattner1f551822009-04-27 06:20:01 +0000788 Record.push_back(E->hadArrayRangeDesignator());
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000789 Record.push_back(E->getNumInits());
790 if (isArrayFiller) {
791 // ArrayFiller may have filled "holes" due to designated initializer.
792 // Replace them by 0 to indicate that the filler goes in that place.
793 Expr *filler = E->getArrayFiller();
794 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000795 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000796 } else {
797 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000798 Record.AddStmt(E->getInit(I));
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000799 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000800 Code = serialization::EXPR_INIT_LIST;
Chris Lattner1f551822009-04-27 06:20:01 +0000801}
802
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000803void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000804 VisitExpr(E);
805 Record.push_back(E->getNumSubExprs());
806 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000807 Record.AddStmt(E->getSubExpr(I));
808 Record.AddSourceLocation(E->getEqualOrColonLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000809 Record.push_back(E->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +0000810 for (const DesignatedInitExpr::Designator &D : E->designators()) {
811 if (D.isFieldDesignator()) {
812 if (FieldDecl *Field = D.getField()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000813 Record.push_back(serialization::DESIG_FIELD_DECL);
Richard Smith290d8012016-04-06 17:06:00 +0000814 Record.AddDeclRef(Field);
Chris Lattner1f551822009-04-27 06:20:01 +0000815 } else {
Sebastian Redl539c5062010-08-18 23:57:32 +0000816 Record.push_back(serialization::DESIG_FIELD_NAME);
David Majnemerf7e36092016-06-23 00:15:04 +0000817 Record.AddIdentifierRef(D.getFieldName());
Chris Lattner1f551822009-04-27 06:20:01 +0000818 }
David Majnemerf7e36092016-06-23 00:15:04 +0000819 Record.AddSourceLocation(D.getDotLoc());
820 Record.AddSourceLocation(D.getFieldLoc());
821 } else if (D.isArrayDesignator()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000822 Record.push_back(serialization::DESIG_ARRAY);
David Majnemerf7e36092016-06-23 00:15:04 +0000823 Record.push_back(D.getFirstExprIndex());
824 Record.AddSourceLocation(D.getLBracketLoc());
825 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000826 } else {
David Majnemerf7e36092016-06-23 00:15:04 +0000827 assert(D.isArrayRangeDesignator() && "Unknown designator");
Sebastian Redl539c5062010-08-18 23:57:32 +0000828 Record.push_back(serialization::DESIG_ARRAY_RANGE);
David Majnemerf7e36092016-06-23 00:15:04 +0000829 Record.push_back(D.getFirstExprIndex());
830 Record.AddSourceLocation(D.getLBracketLoc());
831 Record.AddSourceLocation(D.getEllipsisLoc());
832 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000833 }
834 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000835 Code = serialization::EXPR_DESIGNATED_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000836}
837
Yunzhong Gaocb779302015-06-10 00:27:52 +0000838void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
839 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000840 Record.AddStmt(E->getBase());
841 Record.AddStmt(E->getUpdater());
Yunzhong Gaocb779302015-06-10 00:27:52 +0000842 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
843}
844
845void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
846 VisitExpr(E);
847 Code = serialization::EXPR_NO_INIT;
848}
849
Richard Smith410306b2016-12-12 02:53:20 +0000850void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
851 VisitExpr(E);
852 Record.AddStmt(E->SubExprs[0]);
853 Record.AddStmt(E->SubExprs[1]);
854 Code = serialization::EXPR_ARRAY_INIT_LOOP;
855}
856
857void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
858 VisitExpr(E);
859 Code = serialization::EXPR_ARRAY_INIT_INDEX;
860}
861
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000862void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000863 VisitExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +0000864 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000865}
866
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000867void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000868 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000869 Record.AddStmt(E->getSubExpr());
870 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
871 Record.AddSourceLocation(E->getBuiltinLoc());
872 Record.AddSourceLocation(E->getRParenLoc());
Charles Davisc7d5c942015-09-17 20:55:33 +0000873 Record.push_back(E->isMicrosoftABI());
Sebastian Redl539c5062010-08-18 23:57:32 +0000874 Code = serialization::EXPR_VA_ARG;
Chris Lattner1f551822009-04-27 06:20:01 +0000875}
876
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000877void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000878 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000879 Record.AddSourceLocation(E->getAmpAmpLoc());
880 Record.AddSourceLocation(E->getLabelLoc());
881 Record.AddDeclRef(E->getLabel());
Sebastian Redl539c5062010-08-18 23:57:32 +0000882 Code = serialization::EXPR_ADDR_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000883}
884
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000885void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000886 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000887 Record.AddStmt(E->getSubStmt());
888 Record.AddSourceLocation(E->getLParenLoc());
889 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000890 Code = serialization::EXPR_STMT;
Chris Lattner1f551822009-04-27 06:20:01 +0000891}
892
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000893void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000894 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000895 Record.AddStmt(E->getCond());
896 Record.AddStmt(E->getLHS());
897 Record.AddStmt(E->getRHS());
898 Record.AddSourceLocation(E->getBuiltinLoc());
899 Record.AddSourceLocation(E->getRParenLoc());
Eli Friedman75807f22013-07-20 00:40:58 +0000900 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
Sebastian Redl539c5062010-08-18 23:57:32 +0000901 Code = serialization::EXPR_CHOOSE;
Chris Lattner1f551822009-04-27 06:20:01 +0000902}
903
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000904void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000905 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000906 Record.AddSourceLocation(E->getTokenLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000907 Code = serialization::EXPR_GNU_NULL;
Chris Lattner1f551822009-04-27 06:20:01 +0000908}
909
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000910void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000911 VisitExpr(E);
912 Record.push_back(E->getNumSubExprs());
913 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000914 Record.AddStmt(E->getExpr(I));
915 Record.AddSourceLocation(E->getBuiltinLoc());
916 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000917 Code = serialization::EXPR_SHUFFLE_VECTOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000918}
919
Hal Finkelc4d7c822013-09-18 03:29:45 +0000920void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
921 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000922 Record.AddSourceLocation(E->getBuiltinLoc());
923 Record.AddSourceLocation(E->getRParenLoc());
924 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
925 Record.AddStmt(E->getSrcExpr());
Hal Finkelc4d7c822013-09-18 03:29:45 +0000926 Code = serialization::EXPR_CONVERT_VECTOR;
927}
928
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000929void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000930 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000931 Record.AddDeclRef(E->getBlockDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000932 Code = serialization::EXPR_BLOCK;
Chris Lattner1f551822009-04-27 06:20:01 +0000933}
934
Peter Collingbourne91147592011-04-15 00:35:48 +0000935void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
936 VisitExpr(E);
937 Record.push_back(E->getNumAssocs());
938
Richard Smith290d8012016-04-06 17:06:00 +0000939 Record.AddStmt(E->getControllingExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +0000940 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000941 Record.AddTypeSourceInfo(E->getAssocTypeSourceInfo(I));
942 Record.AddStmt(E->getAssocExpr(I));
Peter Collingbourne91147592011-04-15 00:35:48 +0000943 }
944 Record.push_back(E->isResultDependent() ? -1U : E->getResultIndex());
945
Richard Smith290d8012016-04-06 17:06:00 +0000946 Record.AddSourceLocation(E->getGenericLoc());
947 Record.AddSourceLocation(E->getDefaultLoc());
948 Record.AddSourceLocation(E->getRParenLoc());
Peter Collingbourne91147592011-04-15 00:35:48 +0000949 Code = serialization::EXPR_GENERIC_SELECTION;
950}
951
John McCallfe96e0b2011-11-06 09:01:30 +0000952void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
953 VisitExpr(E);
954 Record.push_back(E->getNumSemanticExprs());
955
956 // Push the result index. Currently, this needs to exactly match
957 // the encoding used internally for ResultIndex.
958 unsigned result = E->getResultExprIndex();
959 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
960 Record.push_back(result);
961
Richard Smith290d8012016-04-06 17:06:00 +0000962 Record.AddStmt(E->getSyntacticForm());
John McCallfe96e0b2011-11-06 09:01:30 +0000963 for (PseudoObjectExpr::semantics_iterator
964 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
Richard Smith290d8012016-04-06 17:06:00 +0000965 Record.AddStmt(*i);
John McCallfe96e0b2011-11-06 09:01:30 +0000966 }
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +0000967 Code = serialization::EXPR_PSEUDO_OBJECT;
John McCallfe96e0b2011-11-06 09:01:30 +0000968}
969
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000970void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
971 VisitExpr(E);
972 Record.push_back(E->getOp());
Richard Smithaa22a8c2012-04-10 22:49:28 +0000973 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000974 Record.AddStmt(E->getSubExprs()[I]);
975 Record.AddSourceLocation(E->getBuiltinLoc());
976 Record.AddSourceLocation(E->getRParenLoc());
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +0000977 Code = serialization::EXPR_ATOMIC;
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000978}
979
Chris Lattner1f551822009-04-27 06:20:01 +0000980//===----------------------------------------------------------------------===//
981// Objective-C Expressions and Statements.
982//===----------------------------------------------------------------------===//
983
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000984void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000985 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000986 Record.AddStmt(E->getString());
987 Record.AddSourceLocation(E->getAtLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000988 Code = serialization::EXPR_OBJC_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000989}
990
Patrick Beard0caa3942012-04-19 00:25:12 +0000991void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +0000992 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000993 Record.AddStmt(E->getSubExpr());
994 Record.AddDeclRef(E->getBoxingMethod());
995 Record.AddSourceRange(E->getSourceRange());
Patrick Beard0caa3942012-04-19 00:25:12 +0000996 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
Ted Kremeneke65b0862012-03-06 20:05:56 +0000997}
998
999void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1000 VisitExpr(E);
1001 Record.push_back(E->getNumElements());
1002 for (unsigned i = 0; i < E->getNumElements(); i++)
Richard Smith290d8012016-04-06 17:06:00 +00001003 Record.AddStmt(E->getElement(i));
1004 Record.AddDeclRef(E->getArrayWithObjectsMethod());
1005 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001006 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1007}
1008
1009void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1010 VisitExpr(E);
1011 Record.push_back(E->getNumElements());
1012 Record.push_back(E->HasPackExpansions);
1013 for (unsigned i = 0; i < E->getNumElements(); i++) {
1014 ObjCDictionaryElement Element = E->getKeyValueElement(i);
Richard Smith290d8012016-04-06 17:06:00 +00001015 Record.AddStmt(Element.Key);
1016 Record.AddStmt(Element.Value);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001017 if (E->HasPackExpansions) {
Richard Smith290d8012016-04-06 17:06:00 +00001018 Record.AddSourceLocation(Element.EllipsisLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001019 unsigned NumExpansions = 0;
1020 if (Element.NumExpansions)
1021 NumExpansions = *Element.NumExpansions + 1;
1022 Record.push_back(NumExpansions);
1023 }
1024 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001025
Richard Smith290d8012016-04-06 17:06:00 +00001026 Record.AddDeclRef(E->getDictWithObjectsMethod());
1027 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001028 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1029}
1030
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001031void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001032 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001033 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1034 Record.AddSourceLocation(E->getAtLoc());
1035 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001036 Code = serialization::EXPR_OBJC_ENCODE;
Chris Lattner1f551822009-04-27 06:20:01 +00001037}
1038
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001039void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001040 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001041 Record.AddSelectorRef(E->getSelector());
1042 Record.AddSourceLocation(E->getAtLoc());
1043 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001044 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001045}
1046
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001047void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001048 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001049 Record.AddDeclRef(E->getProtocol());
1050 Record.AddSourceLocation(E->getAtLoc());
1051 Record.AddSourceLocation(E->ProtoLoc);
1052 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001053 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001054}
1055
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001056void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001057 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001058 Record.AddDeclRef(E->getDecl());
1059 Record.AddSourceLocation(E->getLocation());
1060 Record.AddSourceLocation(E->getOpLoc());
1061 Record.AddStmt(E->getBase());
Chris Lattner1f551822009-04-27 06:20:01 +00001062 Record.push_back(E->isArrow());
1063 Record.push_back(E->isFreeIvar());
Sebastian Redl539c5062010-08-18 23:57:32 +00001064 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001065}
1066
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001067void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001068 VisitExpr(E);
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001069 Record.push_back(E->SetterAndMethodRefFlags.getInt());
John McCallb7bd14f2010-12-02 01:19:52 +00001070 Record.push_back(E->isImplicitProperty());
1071 if (E->isImplicitProperty()) {
Richard Smith290d8012016-04-06 17:06:00 +00001072 Record.AddDeclRef(E->getImplicitPropertyGetter());
1073 Record.AddDeclRef(E->getImplicitPropertySetter());
John McCallb7bd14f2010-12-02 01:19:52 +00001074 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001075 Record.AddDeclRef(E->getExplicitProperty());
John McCallb7bd14f2010-12-02 01:19:52 +00001076 }
Richard Smith290d8012016-04-06 17:06:00 +00001077 Record.AddSourceLocation(E->getLocation());
1078 Record.AddSourceLocation(E->getReceiverLocation());
John McCallb7bd14f2010-12-02 01:19:52 +00001079 if (E->isObjectReceiver()) {
1080 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +00001081 Record.AddStmt(E->getBase());
John McCallb7bd14f2010-12-02 01:19:52 +00001082 } else if (E->isSuperReceiver()) {
1083 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001084 Record.AddTypeRef(E->getSuperReceiverType());
John McCallb7bd14f2010-12-02 01:19:52 +00001085 } else {
1086 Record.push_back(2);
Richard Smith290d8012016-04-06 17:06:00 +00001087 Record.AddDeclRef(E->getClassReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001088 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001089
Sebastian Redl539c5062010-08-18 23:57:32 +00001090 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001091}
1092
Ted Kremeneke65b0862012-03-06 20:05:56 +00001093void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1094 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001095 Record.AddSourceLocation(E->getRBracket());
1096 Record.AddStmt(E->getBaseExpr());
1097 Record.AddStmt(E->getKeyExpr());
1098 Record.AddDeclRef(E->getAtIndexMethodDecl());
1099 Record.AddDeclRef(E->setAtIndexMethodDecl());
Fangrui Song6907ce22018-07-30 19:24:48 +00001100
Ted Kremeneke65b0862012-03-06 20:05:56 +00001101 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1102}
1103
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001104void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001105 VisitExpr(E);
1106 Record.push_back(E->getNumArgs());
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001107 Record.push_back(E->getNumStoredSelLocs());
1108 Record.push_back(E->SelLocsKind);
John McCall31168b02011-06-15 23:02:42 +00001109 Record.push_back(E->isDelegateInitCall());
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +00001110 Record.push_back(E->IsImplicit);
Douglas Gregor9a129192010-04-21 00:45:42 +00001111 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1112 switch (E->getReceiverKind()) {
1113 case ObjCMessageExpr::Instance:
Richard Smith290d8012016-04-06 17:06:00 +00001114 Record.AddStmt(E->getInstanceReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001115 break;
1116
1117 case ObjCMessageExpr::Class:
Richard Smith290d8012016-04-06 17:06:00 +00001118 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
Douglas Gregor9a129192010-04-21 00:45:42 +00001119 break;
1120
1121 case ObjCMessageExpr::SuperClass:
1122 case ObjCMessageExpr::SuperInstance:
Richard Smith290d8012016-04-06 17:06:00 +00001123 Record.AddTypeRef(E->getSuperType());
1124 Record.AddSourceLocation(E->getSuperLoc());
Douglas Gregor9a129192010-04-21 00:45:42 +00001125 break;
1126 }
1127
1128 if (E->getMethodDecl()) {
1129 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001130 Record.AddDeclRef(E->getMethodDecl());
Douglas Gregor9a129192010-04-21 00:45:42 +00001131 } else {
1132 Record.push_back(0);
Fangrui Song6907ce22018-07-30 19:24:48 +00001133 Record.AddSelectorRef(E->getSelector());
Douglas Gregor9a129192010-04-21 00:45:42 +00001134 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001135
Richard Smith290d8012016-04-06 17:06:00 +00001136 Record.AddSourceLocation(E->getLeftLoc());
1137 Record.AddSourceLocation(E->getRightLoc());
Chris Lattner1f551822009-04-27 06:20:01 +00001138
1139 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1140 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +00001141 Record.AddStmt(*Arg);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001142
1143 SourceLocation *Locs = E->getStoredSelLocs();
1144 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001145 Record.AddSourceLocation(Locs[i]);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001146
Sebastian Redl539c5062010-08-18 23:57:32 +00001147 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001148}
1149
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001150void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00001151 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001152 Record.AddStmt(S->getElement());
1153 Record.AddStmt(S->getCollection());
1154 Record.AddStmt(S->getBody());
1155 Record.AddSourceLocation(S->getForLoc());
1156 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001157 Code = serialization::STMT_OBJC_FOR_COLLECTION;
Chris Lattner1f551822009-04-27 06:20:01 +00001158}
1159
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001160void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001161 Record.AddStmt(S->getCatchBody());
1162 Record.AddDeclRef(S->getCatchParamDecl());
1163 Record.AddSourceLocation(S->getAtCatchLoc());
1164 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001165 Code = serialization::STMT_OBJC_CATCH;
Chris Lattner1f551822009-04-27 06:20:01 +00001166}
1167
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001168void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001169 Record.AddStmt(S->getFinallyBody());
1170 Record.AddSourceLocation(S->getAtFinallyLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001171 Code = serialization::STMT_OBJC_FINALLY;
Chris Lattner1f551822009-04-27 06:20:01 +00001172}
1173
John McCall31168b02011-06-15 23:02:42 +00001174void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001175 Record.AddStmt(S->getSubStmt());
1176 Record.AddSourceLocation(S->getAtLoc());
John McCall31168b02011-06-15 23:02:42 +00001177 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1178}
1179
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001180void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor96c79492010-04-23 22:50:49 +00001181 Record.push_back(S->getNumCatchStmts());
Craig Toppera13603a2014-05-22 05:54:18 +00001182 Record.push_back(S->getFinallyStmt() != nullptr);
Richard Smith290d8012016-04-06 17:06:00 +00001183 Record.AddStmt(S->getTryBody());
Douglas Gregor96c79492010-04-23 22:50:49 +00001184 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001185 Record.AddStmt(S->getCatchStmt(I));
Douglas Gregor96c79492010-04-23 22:50:49 +00001186 if (S->getFinallyStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001187 Record.AddStmt(S->getFinallyStmt());
1188 Record.AddSourceLocation(S->getAtTryLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001189 Code = serialization::STMT_OBJC_AT_TRY;
Chris Lattner1f551822009-04-27 06:20:01 +00001190}
1191
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001192void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001193 Record.AddStmt(S->getSynchExpr());
1194 Record.AddStmt(S->getSynchBody());
1195 Record.AddSourceLocation(S->getAtSynchronizedLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001196 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
Chris Lattner1f551822009-04-27 06:20:01 +00001197}
1198
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001199void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001200 Record.AddStmt(S->getThrowExpr());
1201 Record.AddSourceLocation(S->getThrowLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001202 Code = serialization::STMT_OBJC_AT_THROW;
Chris Lattner1f551822009-04-27 06:20:01 +00001203}
1204
Ted Kremeneke65b0862012-03-06 20:05:56 +00001205void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1206 VisitExpr(E);
1207 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001208 Record.AddSourceLocation(E->getLocation());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001209 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1210}
1211
Erik Pilkington29099de2016-07-16 00:35:23 +00001212void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1213 VisitExpr(E);
1214 Record.AddSourceRange(E->getSourceRange());
1215 Record.AddVersionTuple(E->getVersion());
1216 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1217}
1218
Chris Lattner1f551822009-04-27 06:20:01 +00001219//===----------------------------------------------------------------------===//
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001220// C++ Expressions and Statements.
1221//===----------------------------------------------------------------------===//
1222
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001223void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001224 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001225 Record.AddSourceLocation(S->getCatchLoc());
1226 Record.AddDeclRef(S->getExceptionDecl());
1227 Record.AddStmt(S->getHandlerBlock());
Sebastian Redl539c5062010-08-18 23:57:32 +00001228 Code = serialization::STMT_CXX_CATCH;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001229}
1230
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001231void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001232 VisitStmt(S);
1233 Record.push_back(S->getNumHandlers());
Richard Smith290d8012016-04-06 17:06:00 +00001234 Record.AddSourceLocation(S->getTryLoc());
1235 Record.AddStmt(S->getTryBlock());
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001236 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001237 Record.AddStmt(S->getHandler(i));
Sebastian Redl539c5062010-08-18 23:57:32 +00001238 Code = serialization::STMT_CXX_TRY;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001239}
1240
Richard Smith02e85f32011-04-14 22:09:26 +00001241void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1242 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001243 Record.AddSourceLocation(S->getForLoc());
1244 Record.AddSourceLocation(S->getCoawaitLoc());
1245 Record.AddSourceLocation(S->getColonLoc());
1246 Record.AddSourceLocation(S->getRParenLoc());
Richard Smith8baa5002018-09-28 18:44:09 +00001247 Record.AddStmt(S->getInit());
Richard Smith290d8012016-04-06 17:06:00 +00001248 Record.AddStmt(S->getRangeStmt());
1249 Record.AddStmt(S->getBeginStmt());
1250 Record.AddStmt(S->getEndStmt());
1251 Record.AddStmt(S->getCond());
1252 Record.AddStmt(S->getInc());
1253 Record.AddStmt(S->getLoopVarStmt());
1254 Record.AddStmt(S->getBody());
Richard Smith02e85f32011-04-14 22:09:26 +00001255 Code = serialization::STMT_CXX_FOR_RANGE;
1256}
1257
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001258void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1259 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001260 Record.AddSourceLocation(S->getKeywordLoc());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001261 Record.push_back(S->isIfExists());
Richard Smith290d8012016-04-06 17:06:00 +00001262 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1263 Record.AddDeclarationNameInfo(S->getNameInfo());
1264 Record.AddStmt(S->getSubStmt());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001265 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1266}
1267
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001268void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001269 VisitCallExpr(E);
1270 Record.push_back(E->getOperator());
Richard Smith290d8012016-04-06 17:06:00 +00001271 Record.AddSourceRange(E->Range);
Adam Nemet484aa452017-03-27 19:17:25 +00001272 Record.push_back(E->getFPFeatures().getInt());
Sebastian Redl539c5062010-08-18 23:57:32 +00001273 Code = serialization::EXPR_CXX_OPERATOR_CALL;
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001274}
1275
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001276void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001277 VisitCallExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001278 Code = serialization::EXPR_CXX_MEMBER_CALL;
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001279}
1280
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001281void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001282 VisitExpr(E);
Argyrios Kyrtzidis30d98f32010-06-24 08:57:09 +00001283 Record.push_back(E->getNumArgs());
1284 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001285 Record.AddStmt(E->getArg(I));
1286 Record.AddDeclRef(E->getConstructor());
1287 Record.AddSourceLocation(E->getLocation());
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001288 Record.push_back(E->isElidable());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00001289 Record.push_back(E->hadMultipleCandidates());
Richard Smithd59b8322012-12-19 01:39:02 +00001290 Record.push_back(E->isListInitialization());
Richard Smithf8adcdc2014-07-17 05:12:35 +00001291 Record.push_back(E->isStdInitListInitialization());
Douglas Gregor4f4b1862009-12-16 18:50:27 +00001292 Record.push_back(E->requiresZeroInitialization());
Douglas Gregor222cf0e2010-05-15 00:13:29 +00001293 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +00001294 Record.AddSourceRange(E->getParenOrBraceRange());
Sebastian Redl539c5062010-08-18 23:57:32 +00001295 Code = serialization::EXPR_CXX_CONSTRUCT;
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001296}
1297
Richard Smith5179eb72016-06-28 19:03:57 +00001298void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1299 VisitExpr(E);
1300 Record.AddDeclRef(E->getConstructor());
1301 Record.AddSourceLocation(E->getLocation());
1302 Record.push_back(E->constructsVBase());
1303 Record.push_back(E->inheritedFromVBase());
1304 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1305}
1306
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001307void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001308 VisitCXXConstructExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001309 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001310 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001311}
1312
Douglas Gregore31e6062012-02-07 10:09:13 +00001313void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1314 VisitExpr(E);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001315 Record.push_back(E->NumCaptures);
Richard Smith290d8012016-04-06 17:06:00 +00001316 Record.AddSourceRange(E->IntroducerRange);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001317 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +00001318 Record.AddSourceLocation(E->CaptureDefaultLoc);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001319 Record.push_back(E->ExplicitParams);
1320 Record.push_back(E->ExplicitResultType);
Richard Smith290d8012016-04-06 17:06:00 +00001321 Record.AddSourceLocation(E->ClosingBrace);
Fangrui Song6907ce22018-07-30 19:24:48 +00001322
Douglas Gregor99ae8062012-02-14 17:54:36 +00001323 // Add capture initializers.
1324 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1325 CEnd = E->capture_init_end();
1326 C != CEnd; ++C) {
Richard Smith290d8012016-04-06 17:06:00 +00001327 Record.AddStmt(*C);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001328 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001329
Douglas Gregor99ae8062012-02-14 17:54:36 +00001330 Code = serialization::EXPR_LAMBDA;
Douglas Gregore31e6062012-02-07 10:09:13 +00001331}
1332
Richard Smithcc1b96d2013-06-12 22:31:48 +00001333void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1334 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001335 Record.AddStmt(E->getSubExpr());
Richard Smithcc1b96d2013-06-12 22:31:48 +00001336 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1337}
1338
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001339void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001340 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001341 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1342 Record.AddSourceRange(E->getAngleBrackets());
Sam Weinigd01101e2010-01-16 21:21:01 +00001343}
1344
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001345void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001346 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001347 Code = serialization::EXPR_CXX_STATIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001348}
1349
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001350void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001351 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001352 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001353}
1354
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001355void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001356 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001357 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001358}
1359
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001360void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001361 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001362 Code = serialization::EXPR_CXX_CONST_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001363}
1364
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001365void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001366 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001367 Record.AddSourceLocation(E->getLParenLoc());
1368 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001369 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001370}
1371
Richard Smithc67fdd42012-03-07 08:35:16 +00001372void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1373 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001374 Record.AddSourceLocation(E->UDSuffixLoc);
Richard Smithc67fdd42012-03-07 08:35:16 +00001375 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1376}
1377
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001378void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001379 VisitExpr(E);
1380 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001381 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001382 Code = serialization::EXPR_CXX_BOOL_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001383}
1384
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001385void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001386 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001387 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001388 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001389}
1390
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001391void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001392 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001393 Record.AddSourceRange(E->getSourceRange());
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001394 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001395 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001396 Code = serialization::EXPR_CXX_TYPEID_TYPE;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001397 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001398 Record.AddStmt(E->getExprOperand());
Sebastian Redl539c5062010-08-18 23:57:32 +00001399 Code = serialization::EXPR_CXX_TYPEID_EXPR;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001400 }
1401}
1402
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001403void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner98267332010-05-09 06:15:05 +00001404 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001405 Record.AddSourceLocation(E->getLocation());
Chris Lattner98267332010-05-09 06:15:05 +00001406 Record.push_back(E->isImplicit());
Sebastian Redl539c5062010-08-18 23:57:32 +00001407 Code = serialization::EXPR_CXX_THIS;
Chris Lattner98267332010-05-09 06:15:05 +00001408}
1409
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001410void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001411 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001412 Record.AddSourceLocation(E->getThrowLoc());
1413 Record.AddStmt(E->getSubExpr());
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001414 Record.push_back(E->isThrownVariableInScope());
Sebastian Redl539c5062010-08-18 23:57:32 +00001415 Code = serialization::EXPR_CXX_THROW;
Chris Lattner98267332010-05-09 06:15:05 +00001416}
1417
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001418void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001419 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001420 Record.AddDeclRef(E->getParam());
1421 Record.AddSourceLocation(E->getUsedLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001422 Code = serialization::EXPR_CXX_DEFAULT_ARG;
Chris Lattnere2437f42010-05-09 06:40:08 +00001423}
1424
Richard Smith852c9db2013-04-20 22:23:05 +00001425void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1426 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001427 Record.AddDeclRef(E->getField());
1428 Record.AddSourceLocation(E->getExprLoc());
Richard Smith852c9db2013-04-20 22:23:05 +00001429 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1430}
1431
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001432void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001433 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001434 Record.AddCXXTemporary(E->getTemporary());
1435 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +00001436 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
Chris Lattnercba86142010-05-10 00:25:06 +00001437}
1438
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001439void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001440 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001441 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1442 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001443 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001444}
1445
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001446void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001447 VisitExpr(E);
1448 Record.push_back(E->isGlobalNew());
Sebastian Redlc3a3c602012-02-16 11:35:52 +00001449 Record.push_back(E->isArray());
Richard Smithb2f0f052016-10-10 18:54:32 +00001450 Record.push_back(E->passAlignment());
Sebastian Redl6047f072012-02-16 12:22:20 +00001451 Record.push_back(E->doesUsualArrayDeleteWantSize());
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001452 Record.push_back(E->getNumPlacementArgs());
Sebastian Redl6047f072012-02-16 12:22:20 +00001453 Record.push_back(E->StoredInitializationStyle);
Richard Smith290d8012016-04-06 17:06:00 +00001454 Record.AddDeclRef(E->getOperatorNew());
1455 Record.AddDeclRef(E->getOperatorDelete());
1456 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1457 Record.AddSourceRange(E->getTypeIdParens());
1458 Record.AddSourceRange(E->getSourceRange());
1459 Record.AddSourceRange(E->getDirectInitRange());
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001460 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
1461 I != e; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001462 Record.AddStmt(*I);
Sebastian Redl6047f072012-02-16 12:22:20 +00001463
Sebastian Redl539c5062010-08-18 23:57:32 +00001464 Code = serialization::EXPR_CXX_NEW;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001465}
1466
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001467void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001468 VisitExpr(E);
1469 Record.push_back(E->isGlobalDelete());
1470 Record.push_back(E->isArrayForm());
Argyrios Kyrtzidis14ec9f62010-09-13 20:15:54 +00001471 Record.push_back(E->isArrayFormAsWritten());
John McCall284c48f2011-01-27 09:37:56 +00001472 Record.push_back(E->doesUsualArrayDeleteWantSize());
Richard Smith290d8012016-04-06 17:06:00 +00001473 Record.AddDeclRef(E->getOperatorDelete());
1474 Record.AddStmt(E->getArgument());
1475 Record.AddSourceLocation(E->getSourceRange().getBegin());
Fangrui Song6907ce22018-07-30 19:24:48 +00001476
Sebastian Redl539c5062010-08-18 23:57:32 +00001477 Code = serialization::EXPR_CXX_DELETE;
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001478}
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001479
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001480void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001481 VisitExpr(E);
1482
Richard Smith290d8012016-04-06 17:06:00 +00001483 Record.AddStmt(E->getBase());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001484 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001485 Record.AddSourceLocation(E->getOperatorLoc());
1486 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1487 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1488 Record.AddSourceLocation(E->getColonColonLoc());
1489 Record.AddSourceLocation(E->getTildeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001490
1491 // PseudoDestructorTypeStorage.
Richard Smith290d8012016-04-06 17:06:00 +00001492 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001493 if (E->getDestroyedTypeIdentifier())
Richard Smith290d8012016-04-06 17:06:00 +00001494 Record.AddSourceLocation(E->getDestroyedTypeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001495 else
Richard Smith290d8012016-04-06 17:06:00 +00001496 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001497
Sebastian Redl539c5062010-08-18 23:57:32 +00001498 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001499}
1500
John McCall5d413782010-12-06 08:20:24 +00001501void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001502 VisitExpr(E);
John McCall28fc7092011-11-10 05:35:25 +00001503 Record.push_back(E->getNumObjects());
1504 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001505 Record.AddDeclRef(E->getObject(i));
Tim Shen4a05bb82016-06-21 20:29:17 +00001506
1507 Record.push_back(E->cleanupsHaveSideEffects());
Richard Smith290d8012016-04-06 17:06:00 +00001508 Record.AddStmt(E->getSubExpr());
John McCall5d413782010-12-06 08:20:24 +00001509 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
Chris Lattnercba86142010-05-10 00:25:06 +00001510}
1511
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001512void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001513ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001514 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001515
1516 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
Douglas Gregor87866ce2011-02-04 12:01:24 +00001517 // emitted first.
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001518
Abramo Bagnara7945c982012-01-27 09:46:47 +00001519 Record.push_back(E->HasTemplateKWAndArgsInfo);
1520 if (E->HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001521 const ASTTemplateKWAndArgsInfo &ArgInfo =
1522 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1523 Record.push_back(ArgInfo.NumTemplateArgs);
1524 AddTemplateKWAndArgsInfo(ArgInfo,
1525 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001526 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00001527
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001528 if (!E->isImplicitAccess())
Richard Smith290d8012016-04-06 17:06:00 +00001529 Record.AddStmt(E->getBase());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001530 else
Richard Smith290d8012016-04-06 17:06:00 +00001531 Record.AddStmt(nullptr);
1532 Record.AddTypeRef(E->getBaseType());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001533 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001534 Record.AddSourceLocation(E->getOperatorLoc());
1535 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1536 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1537 Record.AddDeclarationNameInfo(E->MemberNameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001538 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001539}
1540
1541void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001542ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001543 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001544
1545 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
Douglas Gregor87866ce2011-02-04 12:01:24 +00001546 // emitted first.
Abramo Bagnara7945c982012-01-27 09:46:47 +00001547
1548 Record.push_back(E->HasTemplateKWAndArgsInfo);
1549 if (E->HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001550 const ASTTemplateKWAndArgsInfo &ArgInfo =
1551 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1552 Record.push_back(ArgInfo.NumTemplateArgs);
1553 AddTemplateKWAndArgsInfo(ArgInfo,
1554 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001555 }
1556
Richard Smith290d8012016-04-06 17:06:00 +00001557 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1558 Record.AddDeclarationNameInfo(E->NameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001559 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001560}
1561
1562void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001563ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001564 VisitExpr(E);
1565 Record.push_back(E->arg_size());
1566 for (CXXUnresolvedConstructExpr::arg_iterator
1567 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
Richard Smith290d8012016-04-06 17:06:00 +00001568 Record.AddStmt(*ArgI);
1569 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1570 Record.AddSourceLocation(E->getLParenLoc());
1571 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001572 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001573}
Chris Lattner98267332010-05-09 06:15:05 +00001574
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001575void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001576 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001577
1578 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1579 // emitted first.
1580
1581 Record.push_back(E->HasTemplateKWAndArgsInfo);
1582 if (E->HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001583 const ASTTemplateKWAndArgsInfo &ArgInfo =
1584 *E->getTrailingASTTemplateKWAndArgsInfo();
1585 Record.push_back(ArgInfo.NumTemplateArgs);
1586 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001587 }
1588
1589 Record.push_back(E->getNumDecls());
1590 for (OverloadExpr::decls_iterator
1591 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
Richard Smith290d8012016-04-06 17:06:00 +00001592 Record.AddDeclRef(OvI.getDecl());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001593 Record.push_back(OvI.getAccess());
1594 }
1595
Richard Smith290d8012016-04-06 17:06:00 +00001596 Record.AddDeclarationNameInfo(E->NameInfo);
1597 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001598}
1599
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001600void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001601 VisitOverloadExpr(E);
1602 Record.push_back(E->isArrow());
1603 Record.push_back(E->hasUnresolvedUsing());
Richard Smith290d8012016-04-06 17:06:00 +00001604 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1605 Record.AddTypeRef(E->getBaseType());
1606 Record.AddSourceLocation(E->getOperatorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001607 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001608}
1609
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001610void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001611 VisitOverloadExpr(E);
1612 Record.push_back(E->requiresADL());
1613 Record.push_back(E->isOverloaded());
Richard Smith290d8012016-04-06 17:06:00 +00001614 Record.AddDeclRef(E->getNamingClass());
Sebastian Redl539c5062010-08-18 23:57:32 +00001615 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001616}
1617
Douglas Gregor29c42f22012-02-24 07:38:34 +00001618void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1619 VisitExpr(E);
1620 Record.push_back(E->TypeTraitExprBits.NumArgs);
1621 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1622 Record.push_back(E->TypeTraitExprBits.Value);
Richard Smith290d8012016-04-06 17:06:00 +00001623 Record.AddSourceRange(E->getSourceRange());
Douglas Gregor29c42f22012-02-24 07:38:34 +00001624 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001625 Record.AddTypeSourceInfo(E->getArg(I));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001626 Code = serialization::EXPR_TYPE_TRAIT;
1627}
1628
John Wiegley6242b6a2011-04-28 00:16:57 +00001629void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1630 VisitExpr(E);
1631 Record.push_back(E->getTrait());
1632 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001633 Record.AddSourceRange(E->getSourceRange());
1634 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
Aleksei Sidorina693b372016-09-28 10:16:56 +00001635 Record.AddStmt(E->getDimensionExpression());
John Wiegley6242b6a2011-04-28 00:16:57 +00001636 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1637}
1638
John Wiegleyf9f65842011-04-25 06:54:41 +00001639void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1640 VisitExpr(E);
1641 Record.push_back(E->getTrait());
1642 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001643 Record.AddSourceRange(E->getSourceRange());
1644 Record.AddStmt(E->getQueriedExpression());
John Wiegleyf9f65842011-04-25 06:54:41 +00001645 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1646}
1647
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001648void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1649 VisitExpr(E);
1650 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001651 Record.AddSourceRange(E->getSourceRange());
1652 Record.AddStmt(E->getOperand());
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001653 Code = serialization::EXPR_CXX_NOEXCEPT;
1654}
1655
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001656void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1657 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001658 Record.AddSourceLocation(E->getEllipsisLoc());
Douglas Gregorb8840002011-01-14 21:20:45 +00001659 Record.push_back(E->NumExpansions);
Richard Smith290d8012016-04-06 17:06:00 +00001660 Record.AddStmt(E->getPattern());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001661 Code = serialization::EXPR_PACK_EXPANSION;
1662}
1663
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001664void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1665 VisitExpr(E);
Richard Smithd784e682015-09-23 21:41:42 +00001666 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1667 : 0);
Richard Smith290d8012016-04-06 17:06:00 +00001668 Record.AddSourceLocation(E->OperatorLoc);
1669 Record.AddSourceLocation(E->PackLoc);
1670 Record.AddSourceLocation(E->RParenLoc);
1671 Record.AddDeclRef(E->Pack);
Richard Smithd784e682015-09-23 21:41:42 +00001672 if (E->isPartiallySubstituted()) {
1673 for (const auto &TA : E->getPartialArguments())
Richard Smith290d8012016-04-06 17:06:00 +00001674 Record.AddTemplateArgument(TA);
Richard Smithd784e682015-09-23 21:41:42 +00001675 } else if (!E->isValueDependent()) {
1676 Record.push_back(E->getPackLength());
1677 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001678 Code = serialization::EXPR_SIZEOF_PACK;
1679}
1680
John McCallfa194042011-07-15 07:00:14 +00001681void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1682 SubstNonTypeTemplateParmExpr *E) {
1683 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001684 Record.AddDeclRef(E->getParameter());
1685 Record.AddSourceLocation(E->getNameLoc());
1686 Record.AddStmt(E->getReplacement());
John McCallfa194042011-07-15 07:00:14 +00001687 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1688}
1689
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001690void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1691 SubstNonTypeTemplateParmPackExpr *E) {
1692 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001693 Record.AddDeclRef(E->getParameterPack());
1694 Record.AddTemplateArgument(E->getArgumentPack());
1695 Record.AddSourceLocation(E->getParameterPackLocation());
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001696 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1697}
1698
Richard Smithb15fe3a2012-09-12 00:56:43 +00001699void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1700 VisitExpr(E);
1701 Record.push_back(E->getNumExpansions());
Richard Smith290d8012016-04-06 17:06:00 +00001702 Record.AddDeclRef(E->getParameterPack());
1703 Record.AddSourceLocation(E->getParameterPackLocation());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001704 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1705 I != End; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001706 Record.AddDeclRef(*I);
Richard Smithb15fe3a2012-09-12 00:56:43 +00001707 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1708}
1709
Douglas Gregorfe314812011-06-21 17:03:29 +00001710void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1711 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001712 Record.AddStmt(E->getTemporary());
1713 Record.AddDeclRef(E->getExtendingDecl());
David Majnemerdaff3702014-05-01 17:50:17 +00001714 Record.push_back(E->getManglingNumber());
Douglas Gregorfe314812011-06-21 17:03:29 +00001715 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1716}
1717
Richard Smith0f0af192014-11-08 05:07:16 +00001718void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1719 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001720 Record.AddSourceLocation(E->LParenLoc);
1721 Record.AddSourceLocation(E->EllipsisLoc);
1722 Record.AddSourceLocation(E->RParenLoc);
1723 Record.AddStmt(E->SubExprs[0]);
1724 Record.AddStmt(E->SubExprs[1]);
Richard Smith0f0af192014-11-08 05:07:16 +00001725 Record.push_back(E->Opcode);
1726 Code = serialization::EXPR_CXX_FOLD;
1727}
1728
John McCall8d69a212010-11-15 23:31:06 +00001729void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1730 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001731 Record.AddStmt(E->getSourceExpr());
1732 Record.AddSourceLocation(E->getLocation());
Akira Hatanaka797afe32018-03-20 01:47:58 +00001733 Record.push_back(E->isUnique());
John McCall8d69a212010-11-15 23:31:06 +00001734 Code = serialization::EXPR_OPAQUE_VALUE;
1735}
1736
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001737void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1738 VisitExpr(E);
1739 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
Davide Italiano04839a52016-01-30 08:03:54 +00001740 llvm_unreachable("Cannot write TypoExpr nodes");
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001741}
1742
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001743//===----------------------------------------------------------------------===//
Peter Collingbourne41f85462011-02-09 21:07:24 +00001744// CUDA Expressions and Statements.
1745//===----------------------------------------------------------------------===//
1746
1747void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1748 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001749 Record.AddStmt(E->getConfig());
Peter Collingbourne41f85462011-02-09 21:07:24 +00001750 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1751}
1752
1753//===----------------------------------------------------------------------===//
Tanya Lattner55808c12011-06-04 00:47:47 +00001754// OpenCL Expressions and Statements.
1755//===----------------------------------------------------------------------===//
1756void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1757 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001758 Record.AddSourceLocation(E->getBuiltinLoc());
1759 Record.AddSourceLocation(E->getRParenLoc());
1760 Record.AddStmt(E->getSrcExpr());
Tanya Lattner55808c12011-06-04 00:47:47 +00001761 Code = serialization::EXPR_ASTYPE;
1762}
1763
1764//===----------------------------------------------------------------------===//
John McCallfa194042011-07-15 07:00:14 +00001765// Microsoft Expressions and Statements.
1766//===----------------------------------------------------------------------===//
John McCall5e77d762013-04-16 07:28:30 +00001767void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1768 VisitExpr(E);
1769 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001770 Record.AddStmt(E->getBaseExpr());
1771 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1772 Record.AddSourceLocation(E->getMemberLoc());
1773 Record.AddDeclRef(E->getPropertyDecl());
John McCall5e77d762013-04-16 07:28:30 +00001774 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1775}
1776
Alexey Bataevf7630272015-11-25 12:01:00 +00001777void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1778 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001779 Record.AddStmt(E->getBase());
1780 Record.AddStmt(E->getIdx());
1781 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataevf7630272015-11-25 12:01:00 +00001782 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1783}
1784
John McCallfa194042011-07-15 07:00:14 +00001785void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1786 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001787 Record.AddSourceRange(E->getSourceRange());
1788 Record.AddString(E->getUuidStr());
John McCallfa194042011-07-15 07:00:14 +00001789 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001790 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
John McCallfa194042011-07-15 07:00:14 +00001791 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1792 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001793 Record.AddStmt(E->getExprOperand());
John McCallfa194042011-07-15 07:00:14 +00001794 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1795 }
1796}
1797
1798void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1799 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001800 Record.AddSourceLocation(S->getExceptLoc());
1801 Record.AddStmt(S->getFilterExpr());
1802 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001803 Code = serialization::STMT_SEH_EXCEPT;
1804}
1805
1806void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1807 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001808 Record.AddSourceLocation(S->getFinallyLoc());
1809 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001810 Code = serialization::STMT_SEH_FINALLY;
1811}
1812
1813void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1814 VisitStmt(S);
1815 Record.push_back(S->getIsCXXTry());
Richard Smith290d8012016-04-06 17:06:00 +00001816 Record.AddSourceLocation(S->getTryLoc());
1817 Record.AddStmt(S->getTryBlock());
1818 Record.AddStmt(S->getHandler());
John McCallfa194042011-07-15 07:00:14 +00001819 Code = serialization::STMT_SEH_TRY;
1820}
1821
Nico Weber9b982072014-07-07 00:12:30 +00001822void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1823 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001824 Record.AddSourceLocation(S->getLeaveLoc());
Nico Weber9b982072014-07-07 00:12:30 +00001825 Code = serialization::STMT_SEH_LEAVE;
1826}
1827
John McCallfa194042011-07-15 07:00:14 +00001828//===----------------------------------------------------------------------===//
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001829// OpenMP Directives.
1830//===----------------------------------------------------------------------===//
1831void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001832 Record.AddSourceLocation(E->getBeginLoc());
Stephen Kelly1c301dc2018-08-09 21:09:38 +00001833 Record.AddSourceLocation(E->getEndLoc());
Richard Smith290d8012016-04-06 17:06:00 +00001834 OMPClauseWriter ClauseWriter(Record);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001835 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
1836 ClauseWriter.writeClause(E->getClause(i));
1837 }
Alexey Bataev68446b72014-07-18 07:47:19 +00001838 if (E->hasAssociatedStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001839 Record.AddStmt(E->getAssociatedStmt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001840}
1841
Alexander Musman3aaab662014-08-19 11:27:13 +00001842void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
1843 VisitStmt(D);
1844 Record.push_back(D->getNumClauses());
1845 Record.push_back(D->getCollapsedNumber());
1846 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001847 Record.AddStmt(D->getIterationVariable());
1848 Record.AddStmt(D->getLastIteration());
1849 Record.AddStmt(D->getCalcLastIteration());
1850 Record.AddStmt(D->getPreCond());
1851 Record.AddStmt(D->getCond());
1852 Record.AddStmt(D->getInit());
1853 Record.AddStmt(D->getInc());
1854 Record.AddStmt(D->getPreInits());
Alexey Bataev3392d762016-02-16 11:18:12 +00001855 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001856 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
1857 isOpenMPDistributeDirective(D->getDirectiveKind())) {
Richard Smith290d8012016-04-06 17:06:00 +00001858 Record.AddStmt(D->getIsLastIterVariable());
1859 Record.AddStmt(D->getLowerBoundVariable());
1860 Record.AddStmt(D->getUpperBoundVariable());
1861 Record.AddStmt(D->getStrideVariable());
1862 Record.AddStmt(D->getEnsureUpperBound());
1863 Record.AddStmt(D->getNextLowerBound());
1864 Record.AddStmt(D->getNextUpperBound());
Alexey Bataev8b427062016-05-25 12:36:08 +00001865 Record.AddStmt(D->getNumIterations());
Alexander Musmanc6388682014-12-15 07:07:06 +00001866 }
Carlo Bertolli9925f152016-06-27 14:55:37 +00001867 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
1868 Record.AddStmt(D->getPrevLowerBoundVariable());
1869 Record.AddStmt(D->getPrevUpperBoundVariable());
Carlo Bertolli8429d812017-02-17 21:29:13 +00001870 Record.AddStmt(D->getDistInc());
1871 Record.AddStmt(D->getPrevEnsureUpperBound());
Carlo Bertolliffafe102017-04-20 00:39:39 +00001872 Record.AddStmt(D->getCombinedLowerBoundVariable());
1873 Record.AddStmt(D->getCombinedUpperBoundVariable());
1874 Record.AddStmt(D->getCombinedEnsureUpperBound());
1875 Record.AddStmt(D->getCombinedInit());
1876 Record.AddStmt(D->getCombinedCond());
1877 Record.AddStmt(D->getCombinedNextLowerBound());
1878 Record.AddStmt(D->getCombinedNextUpperBound());
Gheorghe-Teodor Berceae9256762018-10-29 15:45:47 +00001879 Record.AddStmt(D->getCombinedDistCond());
1880 Record.AddStmt(D->getCombinedParForInDistCond());
Carlo Bertolli9925f152016-06-27 14:55:37 +00001881 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001882 for (auto I : D->counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001883 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001884 }
Alexey Bataeva8899172015-08-06 12:30:57 +00001885 for (auto I : D->private_counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001886 Record.AddStmt(I);
Alexey Bataeva8899172015-08-06 12:30:57 +00001887 }
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001888 for (auto I : D->inits()) {
Richard Smith290d8012016-04-06 17:06:00 +00001889 Record.AddStmt(I);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001890 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001891 for (auto I : D->updates()) {
Richard Smith290d8012016-04-06 17:06:00 +00001892 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001893 }
1894 for (auto I : D->finals()) {
Richard Smith290d8012016-04-06 17:06:00 +00001895 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001896 }
Alexander Musman3aaab662014-08-19 11:27:13 +00001897}
1898
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001899void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001900 VisitStmt(D);
1901 Record.push_back(D->getNumClauses());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001902 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001903 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001904 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
1905}
1906
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001907void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001908 VisitOMPLoopDirective(D);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001909 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
1910}
1911
Alexey Bataevf29276e2014-06-18 04:14:57 +00001912void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001913 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001914 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevf29276e2014-06-18 04:14:57 +00001915 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
1916}
1917
Alexander Musmanf82886e2014-09-18 05:12:34 +00001918void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
1919 VisitOMPLoopDirective(D);
1920 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
1921}
1922
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001923void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
1924 VisitStmt(D);
1925 Record.push_back(D->getNumClauses());
1926 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001927 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001928 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
1929}
1930
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001931void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
1932 VisitStmt(D);
1933 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001934 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001935 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
1936}
1937
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00001938void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
1939 VisitStmt(D);
1940 Record.push_back(D->getNumClauses());
1941 VisitOMPExecutableDirective(D);
1942 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
1943}
1944
Alexander Musman80c22892014-07-17 08:54:58 +00001945void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
1946 VisitStmt(D);
1947 VisitOMPExecutableDirective(D);
1948 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
1949}
1950
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001951void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
1952 VisitStmt(D);
Alexey Bataev28c75412015-12-15 08:19:24 +00001953 Record.push_back(D->getNumClauses());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001954 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001955 Record.AddDeclarationNameInfo(D->getDirectiveName());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001956 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
1957}
1958
Alexey Bataev4acb8592014-07-07 13:01:15 +00001959void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001960 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001961 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev4acb8592014-07-07 13:01:15 +00001962 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
1963}
1964
Alexander Musmane4e893b2014-09-23 09:33:00 +00001965void ASTStmtWriter::VisitOMPParallelForSimdDirective(
1966 OMPParallelForSimdDirective *D) {
1967 VisitOMPLoopDirective(D);
1968 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
1969}
1970
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00001971void ASTStmtWriter::VisitOMPParallelSectionsDirective(
1972 OMPParallelSectionsDirective *D) {
1973 VisitStmt(D);
1974 Record.push_back(D->getNumClauses());
1975 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001976 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00001977 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
1978}
1979
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00001980void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
1981 VisitStmt(D);
1982 Record.push_back(D->getNumClauses());
1983 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001984 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00001985 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
1986}
1987
Alexey Bataev0162e452014-07-22 10:10:35 +00001988void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
1989 VisitStmt(D);
1990 Record.push_back(D->getNumClauses());
1991 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001992 Record.AddStmt(D->getX());
1993 Record.AddStmt(D->getV());
1994 Record.AddStmt(D->getExpr());
1995 Record.AddStmt(D->getUpdateExpr());
Alexey Bataevb4505a72015-03-30 05:20:59 +00001996 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
Alexey Bataevb78ca832015-04-01 03:33:17 +00001997 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
Alexey Bataev0162e452014-07-22 10:10:35 +00001998 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
1999}
2000
Alexey Bataev0bd520b2014-09-19 08:19:49 +00002001void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2002 VisitStmt(D);
2003 Record.push_back(D->getNumClauses());
2004 VisitOMPExecutableDirective(D);
2005 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2006}
2007
Michael Wong65f367f2015-07-21 13:44:28 +00002008void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2009 VisitStmt(D);
2010 Record.push_back(D->getNumClauses());
2011 VisitOMPExecutableDirective(D);
2012 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2013}
2014
Samuel Antaodf67fc42016-01-19 19:15:56 +00002015void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2016 OMPTargetEnterDataDirective *D) {
2017 VisitStmt(D);
2018 Record.push_back(D->getNumClauses());
2019 VisitOMPExecutableDirective(D);
2020 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2021}
2022
Samuel Antao72590762016-01-19 20:04:50 +00002023void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2024 OMPTargetExitDataDirective *D) {
2025 VisitStmt(D);
2026 Record.push_back(D->getNumClauses());
2027 VisitOMPExecutableDirective(D);
2028 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2029}
2030
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00002031void ASTStmtWriter::VisitOMPTargetParallelDirective(
2032 OMPTargetParallelDirective *D) {
2033 VisitStmt(D);
2034 Record.push_back(D->getNumClauses());
2035 VisitOMPExecutableDirective(D);
2036 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2037}
2038
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00002039void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2040 OMPTargetParallelForDirective *D) {
2041 VisitOMPLoopDirective(D);
2042 Record.push_back(D->hasCancel() ? 1 : 0);
2043 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2044}
2045
Alexey Bataev68446b72014-07-18 07:47:19 +00002046void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2047 VisitStmt(D);
2048 VisitOMPExecutableDirective(D);
2049 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2050}
2051
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00002052void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2053 VisitStmt(D);
2054 VisitOMPExecutableDirective(D);
2055 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2056}
2057
Alexey Bataev2df347a2014-07-18 10:17:07 +00002058void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2059 VisitStmt(D);
2060 VisitOMPExecutableDirective(D);
2061 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2062}
2063
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002064void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2065 VisitStmt(D);
Alexey Bataev169d96a2017-07-18 20:17:46 +00002066 Record.push_back(D->getNumClauses());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002067 VisitOMPExecutableDirective(D);
Alexey Bataev3b1b8952017-07-25 15:53:26 +00002068 Record.AddStmt(D->getReductionRef());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002069 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2070}
2071
Alexey Bataev6125da92014-07-21 11:26:11 +00002072void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2073 VisitStmt(D);
2074 Record.push_back(D->getNumClauses());
2075 VisitOMPExecutableDirective(D);
2076 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2077}
2078
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002079void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2080 VisitStmt(D);
Alexey Bataev346265e2015-09-25 10:37:12 +00002081 Record.push_back(D->getNumClauses());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002082 VisitOMPExecutableDirective(D);
2083 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2084}
2085
Alexey Bataev13314bf2014-10-09 04:18:56 +00002086void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2087 VisitStmt(D);
2088 Record.push_back(D->getNumClauses());
2089 VisitOMPExecutableDirective(D);
2090 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2091}
2092
Alexey Bataev6d4ed052015-07-01 06:57:41 +00002093void ASTStmtWriter::VisitOMPCancellationPointDirective(
2094 OMPCancellationPointDirective *D) {
2095 VisitStmt(D);
2096 VisitOMPExecutableDirective(D);
2097 Record.push_back(D->getCancelRegion());
2098 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2099}
2100
Alexey Bataev80909872015-07-02 11:25:17 +00002101void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2102 VisitStmt(D);
Alexey Bataev87933c72015-09-18 08:07:34 +00002103 Record.push_back(D->getNumClauses());
Alexey Bataev80909872015-07-02 11:25:17 +00002104 VisitOMPExecutableDirective(D);
2105 Record.push_back(D->getCancelRegion());
2106 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2107}
2108
Alexey Bataev49f6e782015-12-01 04:18:41 +00002109void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2110 VisitOMPLoopDirective(D);
2111 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2112}
2113
Alexey Bataev0a6ed842015-12-03 09:40:15 +00002114void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2115 VisitOMPLoopDirective(D);
2116 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2117}
2118
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00002119void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2120 VisitOMPLoopDirective(D);
2121 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2122}
2123
Samuel Antao686c70c2016-05-26 17:30:50 +00002124void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2125 VisitStmt(D);
2126 Record.push_back(D->getNumClauses());
2127 VisitOMPExecutableDirective(D);
2128 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2129}
2130
Carlo Bertolli9925f152016-06-27 14:55:37 +00002131void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2132 OMPDistributeParallelForDirective *D) {
2133 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002134 Record.push_back(D->hasCancel() ? 1 : 0);
Carlo Bertolli9925f152016-06-27 14:55:37 +00002135 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2136}
2137
Kelvin Li4a39add2016-07-05 05:00:15 +00002138void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2139 OMPDistributeParallelForSimdDirective *D) {
2140 VisitOMPLoopDirective(D);
2141 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2142}
2143
Kelvin Li787f3fc2016-07-06 04:45:38 +00002144void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2145 OMPDistributeSimdDirective *D) {
2146 VisitOMPLoopDirective(D);
2147 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2148}
2149
Kelvin Lia579b912016-07-14 02:54:56 +00002150void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2151 OMPTargetParallelForSimdDirective *D) {
2152 VisitOMPLoopDirective(D);
2153 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2154}
2155
Kelvin Li986330c2016-07-20 22:57:10 +00002156void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2157 VisitOMPLoopDirective(D);
2158 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2159}
2160
Kelvin Li02532872016-08-05 14:37:37 +00002161void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2162 OMPTeamsDistributeDirective *D) {
2163 VisitOMPLoopDirective(D);
2164 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2165}
2166
Kelvin Li4e325f72016-10-25 12:50:55 +00002167void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2168 OMPTeamsDistributeSimdDirective *D) {
2169 VisitOMPLoopDirective(D);
2170 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2171}
2172
Kelvin Li579e41c2016-11-30 23:51:03 +00002173void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2174 OMPTeamsDistributeParallelForSimdDirective *D) {
2175 VisitOMPLoopDirective(D);
2176 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2177}
2178
Kelvin Li7ade93f2016-12-09 03:24:30 +00002179void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2180 OMPTeamsDistributeParallelForDirective *D) {
2181 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002182 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li7ade93f2016-12-09 03:24:30 +00002183 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2184}
2185
Kelvin Libf594a52016-12-17 05:48:59 +00002186void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2187 VisitStmt(D);
2188 Record.push_back(D->getNumClauses());
2189 VisitOMPExecutableDirective(D);
2190 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2191}
2192
Kelvin Li83c451e2016-12-25 04:52:54 +00002193void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2194 OMPTargetTeamsDistributeDirective *D) {
2195 VisitOMPLoopDirective(D);
2196 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2197}
2198
Kelvin Li80e8f562016-12-29 22:16:30 +00002199void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2200 OMPTargetTeamsDistributeParallelForDirective *D) {
2201 VisitOMPLoopDirective(D);
Alexey Bataev16e79882017-11-22 21:12:03 +00002202 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li80e8f562016-12-29 22:16:30 +00002203 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2204}
2205
Kelvin Li1851df52017-01-03 05:23:48 +00002206void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2207 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2208 VisitOMPLoopDirective(D);
2209 Code = serialization::
2210 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2211}
2212
Kelvin Lida681182017-01-10 18:08:18 +00002213void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2214 OMPTargetTeamsDistributeSimdDirective *D) {
2215 VisitOMPLoopDirective(D);
2216 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2217}
2218
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002219//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002220// ASTWriter Implementation
Chris Lattner1f551822009-04-27 06:20:01 +00002221//===----------------------------------------------------------------------===//
2222
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002223unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002224 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002225 "SwitchCase recorded twice");
2226 unsigned NextID = SwitchCaseIDs.size();
2227 SwitchCaseIDs[S] = NextID;
2228 return NextID;
2229}
2230
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002231unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002232 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002233 "SwitchCase hasn't been seen yet");
2234 return SwitchCaseIDs[S];
2235}
2236
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002237void ASTWriter::ClearSwitchCaseIDs() {
2238 SwitchCaseIDs.clear();
2239}
2240
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002241/// Write the given substatement or subexpression to the
Chris Lattner1f551822009-04-27 06:20:01 +00002242/// bitstream.
Richard Smithf50422a2016-04-06 20:12:34 +00002243void ASTWriter::WriteSubStmt(Stmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00002244 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002245 ASTStmtWriter Writer(*this, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002246 ++NumStatements;
Fangrui Song6907ce22018-07-30 19:24:48 +00002247
Chris Lattner1f551822009-04-27 06:20:01 +00002248 if (!S) {
Sebastian Redl539c5062010-08-18 23:57:32 +00002249 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002250 return;
2251 }
Mike Stump11289f42009-09-09 15:08:12 +00002252
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002253 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2254 if (I != SubStmtEntries.end()) {
2255 Record.push_back(I->second);
2256 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2257 return;
2258 }
2259
2260#ifndef NDEBUG
2261 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2262
2263 struct ParentStmtInserterRAII {
2264 Stmt *S;
2265 llvm::DenseSet<Stmt *> &ParentStmts;
2266
2267 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2268 : S(S), ParentStmts(ParentStmts) {
2269 ParentStmts.insert(S);
2270 }
2271 ~ParentStmtInserterRAII() {
2272 ParentStmts.erase(S);
2273 }
2274 };
2275
2276 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2277#endif
2278
Chris Lattner1f551822009-04-27 06:20:01 +00002279 Writer.Visit(S);
Fangrui Song6907ce22018-07-30 19:24:48 +00002280
Richard Smithb41ddae2016-04-06 20:57:53 +00002281 uint64_t Offset = Writer.Emit();
2282 SubStmtEntries[S] = Offset;
Chris Lattner1f551822009-04-27 06:20:01 +00002283}
2284
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002285/// Flush all of the statements that have been added to the
Chris Lattner1f551822009-04-27 06:20:01 +00002286/// queue via AddStmt().
Richard Smith290d8012016-04-06 17:06:00 +00002287void ASTRecordWriter::FlushStmts() {
Daniel Dunbara5acaa32012-02-29 02:39:13 +00002288 // We expect to be the only consumer of the two temporary statement maps,
2289 // assert that they are empty.
Richard Smith290d8012016-04-06 17:06:00 +00002290 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2291 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002292
Chris Lattner1f551822009-04-27 06:20:01 +00002293 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002294 Writer->WriteSubStmt(StmtsToEmit[I]);
Fangrui Song6907ce22018-07-30 19:24:48 +00002295
Richard Smith290d8012016-04-06 17:06:00 +00002296 assert(N == StmtsToEmit.size() && "record modified while being written!");
Mike Stump11289f42009-09-09 15:08:12 +00002297
Chris Lattner1f551822009-04-27 06:20:01 +00002298 // Note that we are at the end of a full expression. Any
2299 // expression records that follow this one are part of a different
2300 // expression.
Richard Smith290d8012016-04-06 17:06:00 +00002301 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002302
Richard Smith290d8012016-04-06 17:06:00 +00002303 Writer->SubStmtEntries.clear();
2304 Writer->ParentStmts.clear();
2305 }
2306
2307 StmtsToEmit.clear();
2308}
2309
2310void ASTRecordWriter::FlushSubStmts() {
2311 // For a nested statement, write out the substatements in reverse order (so
2312 // that a simple stack machine can be used when loading), and don't emit a
2313 // STMT_STOP after each one.
2314 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002315 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
Richard Smith290d8012016-04-06 17:06:00 +00002316 assert(N == StmtsToEmit.size() && "record modified while being written!");
Chris Lattner1f551822009-04-27 06:20:01 +00002317 }
Mike Stump11289f42009-09-09 15:08:12 +00002318
Chris Lattner1f551822009-04-27 06:20:01 +00002319 StmtsToEmit.clear();
Chris Lattner1f551822009-04-27 06:20:01 +00002320}