blob: 14c3b3278e23c76a7910e4108bac4fc021912ccb [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);
Bruno Riccie2806f82018-10-29 16:12:37 +0000162
163 bool HasInit = S->getInit() != nullptr;
164 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
165 Record.push_back(HasInit);
166 Record.push_back(HasVar);
167 Record.push_back(S->isAllEnumCasesCovered());
168
Richard Smith290d8012016-04-06 17:06:00 +0000169 Record.AddStmt(S->getCond());
170 Record.AddStmt(S->getBody());
Bruno Riccie2806f82018-10-29 16:12:37 +0000171 if (HasInit)
172 Record.AddStmt(S->getInit());
173 if (HasVar)
174 Record.AddDeclRef(S->getConditionVariable());
175
Richard Smith290d8012016-04-06 17:06:00 +0000176 Record.AddSourceLocation(S->getSwitchLoc());
Bruno Riccie2806f82018-10-29 16:12:37 +0000177
Mike Stump11289f42009-09-09 15:08:12 +0000178 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
Chris Lattner1f551822009-04-27 06:20:01 +0000179 SC = SC->getNextSwitchCase())
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000180 Record.push_back(Writer.RecordSwitchCaseID(SC));
Sebastian Redl539c5062010-08-18 23:57:32 +0000181 Code = serialization::STMT_SWITCH;
Chris Lattner1f551822009-04-27 06:20:01 +0000182}
183
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000184void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000185 VisitStmt(S);
Bruno Riccibacf7512018-10-30 13:42:41 +0000186
187 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
188 Record.push_back(HasVar);
189
Richard Smith290d8012016-04-06 17:06:00 +0000190 Record.AddStmt(S->getCond());
191 Record.AddStmt(S->getBody());
Bruno Riccibacf7512018-10-30 13:42:41 +0000192 if (HasVar)
193 Record.AddDeclRef(S->getConditionVariable());
194
Richard Smith290d8012016-04-06 17:06:00 +0000195 Record.AddSourceLocation(S->getWhileLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000196 Code = serialization::STMT_WHILE;
Chris Lattner1f551822009-04-27 06:20:01 +0000197}
198
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000199void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000200 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000201 Record.AddStmt(S->getCond());
202 Record.AddStmt(S->getBody());
203 Record.AddSourceLocation(S->getDoLoc());
204 Record.AddSourceLocation(S->getWhileLoc());
205 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000206 Code = serialization::STMT_DO;
Chris Lattner1f551822009-04-27 06:20:01 +0000207}
208
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000209void ASTStmtWriter::VisitForStmt(ForStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000210 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000211 Record.AddStmt(S->getInit());
212 Record.AddStmt(S->getCond());
213 Record.AddDeclRef(S->getConditionVariable());
214 Record.AddStmt(S->getInc());
215 Record.AddStmt(S->getBody());
216 Record.AddSourceLocation(S->getForLoc());
217 Record.AddSourceLocation(S->getLParenLoc());
218 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000219 Code = serialization::STMT_FOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000220}
221
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000222void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000223 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000224 Record.AddDeclRef(S->getLabel());
225 Record.AddSourceLocation(S->getGotoLoc());
226 Record.AddSourceLocation(S->getLabelLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000227 Code = serialization::STMT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000228}
229
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000230void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000231 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000232 Record.AddSourceLocation(S->getGotoLoc());
233 Record.AddSourceLocation(S->getStarLoc());
234 Record.AddStmt(S->getTarget());
Sebastian Redl539c5062010-08-18 23:57:32 +0000235 Code = serialization::STMT_INDIRECT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000236}
237
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000238void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000239 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000240 Record.AddSourceLocation(S->getContinueLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000241 Code = serialization::STMT_CONTINUE;
Chris Lattner1f551822009-04-27 06:20:01 +0000242}
243
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000244void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000245 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000246 Record.AddSourceLocation(S->getBreakLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000247 Code = serialization::STMT_BREAK;
Chris Lattner1f551822009-04-27 06:20:01 +0000248}
249
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000250void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000251 VisitStmt(S);
Bruno Ricci023b1d12018-10-30 14:40:49 +0000252
253 bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr;
254 Record.push_back(HasNRVOCandidate);
255
Richard Smith290d8012016-04-06 17:06:00 +0000256 Record.AddStmt(S->getRetValue());
Bruno Ricci023b1d12018-10-30 14:40:49 +0000257 if (HasNRVOCandidate)
258 Record.AddDeclRef(S->getNRVOCandidate());
259
Richard Smith290d8012016-04-06 17:06:00 +0000260 Record.AddSourceLocation(S->getReturnLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000261 Code = serialization::STMT_RETURN;
Chris Lattner1f551822009-04-27 06:20:01 +0000262}
263
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000264void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000265 VisitStmt(S);
Stephen Kellya6e43582018-08-09 21:05:56 +0000266 Record.AddSourceLocation(S->getBeginLoc());
Richard Smith290d8012016-04-06 17:06:00 +0000267 Record.AddSourceLocation(S->getEndLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000268 DeclGroupRef DG = S->getDeclGroup();
269 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
Richard Smith290d8012016-04-06 17:06:00 +0000270 Record.AddDeclRef(*D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000271 Code = serialization::STMT_DECL;
Chris Lattner1f551822009-04-27 06:20:01 +0000272}
273
John McCallf413f5e2013-05-03 00:10:13 +0000274void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000275 VisitStmt(S);
276 Record.push_back(S->getNumOutputs());
277 Record.push_back(S->getNumInputs());
278 Record.push_back(S->getNumClobbers());
Richard Smith290d8012016-04-06 17:06:00 +0000279 Record.AddSourceLocation(S->getAsmLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000280 Record.push_back(S->isVolatile());
281 Record.push_back(S->isSimple());
John McCallf413f5e2013-05-03 00:10:13 +0000282}
283
284void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
285 VisitAsmStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000286 Record.AddSourceLocation(S->getRParenLoc());
287 Record.AddStmt(S->getAsmString());
Chris Lattner1f551822009-04-27 06:20:01 +0000288
289 // Outputs
Fangrui Song6907ce22018-07-30 19:24:48 +0000290 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000291 Record.AddIdentifierRef(S->getOutputIdentifier(I));
292 Record.AddStmt(S->getOutputConstraintLiteral(I));
293 Record.AddStmt(S->getOutputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000294 }
295
296 // Inputs
297 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000298 Record.AddIdentifierRef(S->getInputIdentifier(I));
299 Record.AddStmt(S->getInputConstraintLiteral(I));
300 Record.AddStmt(S->getInputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000301 }
302
303 // Clobbers
304 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000305 Record.AddStmt(S->getClobberStringLiteral(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000306
Chad Rosierde70e0e2012-08-25 00:11:56 +0000307 Code = serialization::STMT_GCCASM;
Chris Lattner1f551822009-04-27 06:20:01 +0000308}
309
Chad Rosier32503022012-06-11 20:47:18 +0000310void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
John McCallf413f5e2013-05-03 00:10:13 +0000311 VisitAsmStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000312 Record.AddSourceLocation(S->getLBraceLoc());
313 Record.AddSourceLocation(S->getEndLoc());
John McCallf413f5e2013-05-03 00:10:13 +0000314 Record.push_back(S->getNumAsmToks());
Richard Smith290d8012016-04-06 17:06:00 +0000315 Record.AddString(S->getAsmString());
John McCallf413f5e2013-05-03 00:10:13 +0000316
317 // Tokens
318 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000319 // FIXME: Move this to ASTRecordWriter?
320 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
John McCallf413f5e2013-05-03 00:10:13 +0000321 }
322
323 // Clobbers
324 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000325 Record.AddString(S->getClobber(I));
John McCallf413f5e2013-05-03 00:10:13 +0000326 }
327
328 // Outputs
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000329 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000330 Record.AddStmt(S->getOutputExpr(I));
331 Record.AddString(S->getOutputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000332 }
333
334 // Inputs
335 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000336 Record.AddStmt(S->getInputExpr(I));
337 Record.AddString(S->getInputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000338 }
Chad Rosiere30d4992012-08-24 23:51:02 +0000339
340 Code = serialization::STMT_MSASM;
Chad Rosier32503022012-06-11 20:47:18 +0000341}
342
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000343void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
344 VisitStmt(CoroStmt);
345 Record.push_back(CoroStmt->getParamMoves().size());
346 for (Stmt *S : CoroStmt->children())
347 Record.AddStmt(S);
348 Code = serialization::STMT_COROUTINE_BODY;
Richard Smith9f690bd2015-10-27 06:02:45 +0000349}
350
351void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000352 VisitStmt(S);
353 Record.AddSourceLocation(S->getKeywordLoc());
354 Record.AddStmt(S->getOperand());
355 Record.AddStmt(S->getPromiseCall());
356 Record.push_back(S->isImplicit());
357 Code = serialization::STMT_CORETURN;
Richard Smith9f690bd2015-10-27 06:02:45 +0000358}
359
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000360void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
361 VisitExpr(E);
362 Record.AddSourceLocation(E->getKeywordLoc());
363 for (Stmt *S : E->children())
364 Record.AddStmt(S);
365 Record.AddStmt(E->getOpaqueValue());
Richard Smith9f690bd2015-10-27 06:02:45 +0000366}
367
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000368void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
369 VisitCoroutineSuspendExpr(E);
370 Record.push_back(E->isImplicit());
371 Code = serialization::EXPR_COAWAIT;
Eric Fiselier20f25cb2017-03-06 23:38:15 +0000372}
373
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000374void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
375 VisitCoroutineSuspendExpr(E);
376 Code = serialization::EXPR_COYIELD;
377}
378
379void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
380 VisitExpr(E);
381 Record.AddSourceLocation(E->getKeywordLoc());
382 for (Stmt *S : E->children())
383 Record.AddStmt(S);
384 Code = serialization::EXPR_DEPENDENT_COAWAIT;
Richard Smith9f690bd2015-10-27 06:02:45 +0000385}
386
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000387void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
388 VisitStmt(S);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000389 // NumCaptures
390 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000391
Wei Pan17fbf6e2013-05-04 03:59:06 +0000392 // CapturedDecl and captured region kind
Richard Smith290d8012016-04-06 17:06:00 +0000393 Record.AddDeclRef(S->getCapturedDecl());
Wei Pan17fbf6e2013-05-04 03:59:06 +0000394 Record.push_back(S->getCapturedRegionKind());
395
Richard Smith290d8012016-04-06 17:06:00 +0000396 Record.AddDeclRef(S->getCapturedRecordDecl());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000397
398 // Capture inits
Aaron Ballmanba0238f2014-03-14 19:41:04 +0000399 for (auto *I : S->capture_inits())
Richard Smith290d8012016-04-06 17:06:00 +0000400 Record.AddStmt(I);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000401
402 // Body
Richard Smith290d8012016-04-06 17:06:00 +0000403 Record.AddStmt(S->getCapturedStmt());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000404
405 // Captures
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000406 for (const auto &I : S->captures()) {
Alexey Bataev330de032014-10-29 12:21:55 +0000407 if (I.capturesThis() || I.capturesVariableArrayType())
Richard Smith290d8012016-04-06 17:06:00 +0000408 Record.AddDeclRef(nullptr);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000409 else
Richard Smith290d8012016-04-06 17:06:00 +0000410 Record.AddDeclRef(I.getCapturedVar());
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000411 Record.push_back(I.getCaptureKind());
Richard Smith290d8012016-04-06 17:06:00 +0000412 Record.AddSourceLocation(I.getLocation());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000413 }
414
415 Code = serialization::STMT_CAPTURED;
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000416}
417
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000418void ASTStmtWriter::VisitExpr(Expr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000419 VisitStmt(E);
Richard Smith290d8012016-04-06 17:06:00 +0000420 Record.AddTypeRef(E->getType());
Chris Lattner1f551822009-04-27 06:20:01 +0000421 Record.push_back(E->isTypeDependent());
422 Record.push_back(E->isValueDependent());
Douglas Gregor678d76c2011-07-01 01:22:09 +0000423 Record.push_back(E->isInstantiationDependent());
Douglas Gregor506bd562010-12-13 22:49:22 +0000424 Record.push_back(E->containsUnexpandedParameterPack());
John McCall7decc9e2010-11-18 06:31:45 +0000425 Record.push_back(E->getValueKind());
426 Record.push_back(E->getObjectKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000427}
428
Bill Wendling7c44da22018-10-31 03:48:47 +0000429void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
430 VisitExpr(E);
431 Record.AddStmt(E->getSubExpr());
432 Code = serialization::EXPR_CONSTANT;
433}
434
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000435void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000436 VisitExpr(E);
Bruno Ricci17ff0262018-10-27 19:21:19 +0000437
438 bool HasFunctionName = E->getFunctionName() != nullptr;
439 Record.push_back(HasFunctionName);
440 Record.push_back(E->getIdentKind()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000441 Record.AddSourceLocation(E->getLocation());
Bruno Ricci17ff0262018-10-27 19:21:19 +0000442 if (HasFunctionName)
443 Record.AddStmt(E->getFunctionName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000444 Code = serialization::EXPR_PREDEFINED;
Chris Lattner1f551822009-04-27 06:20:01 +0000445}
446
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000447void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000448 VisitExpr(E);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000449
450 Record.push_back(E->hasQualifier());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000451 Record.push_back(E->getDecl() != E->getFoundDecl());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000452 Record.push_back(E->hasTemplateKWAndArgsInfo());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000453 Record.push_back(E->hadMultipleCandidates());
Alexey Bataev19acc3d2015-01-12 10:17:46 +0000454 Record.push_back(E->refersToEnclosingVariableOrCapture());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000455
Abramo Bagnara7945c982012-01-27 09:46:47 +0000456 if (E->hasTemplateKWAndArgsInfo()) {
Douglas Gregor87866ce2011-02-04 12:01:24 +0000457 unsigned NumTemplateArgs = E->getNumTemplateArgs();
458 Record.push_back(NumTemplateArgs);
Douglas Gregor87866ce2011-02-04 12:01:24 +0000459 }
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000460
Douglas Gregor03412ba2011-06-03 02:27:19 +0000461 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
462
Abramo Bagnara7945c982012-01-27 09:46:47 +0000463 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000464 (E->getDecl() == E->getFoundDecl()) &&
465 nk == DeclarationName::Identifier) {
466 AbbrevToUse = Writer.getDeclRefExprAbbrev();
467 }
468
Anders Carlsson80756f62011-03-06 18:19:42 +0000469 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000470 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Anders Carlsson80756f62011-03-06 18:19:42 +0000471
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000472 if (E->getDecl() != E->getFoundDecl())
Richard Smith290d8012016-04-06 17:06:00 +0000473 Record.AddDeclRef(E->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000474
Abramo Bagnara7945c982012-01-27 09:46:47 +0000475 if (E->hasTemplateKWAndArgsInfo())
James Y Knighte7d82282015-12-29 18:15:14 +0000476 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
477 E->getTrailingObjects<TemplateArgumentLoc>());
Anders Carlsson80756f62011-03-06 18:19:42 +0000478
Richard Smith290d8012016-04-06 17:06:00 +0000479 Record.AddDeclRef(E->getDecl());
480 Record.AddSourceLocation(E->getLocation());
481 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000482 Code = serialization::EXPR_DECL_REF;
Chris Lattner1f551822009-04-27 06:20:01 +0000483}
484
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000485void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000486 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000487 Record.AddSourceLocation(E->getLocation());
488 Record.AddAPInt(E->getValue());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000489
490 if (E->getValue().getBitWidth() == 32) {
491 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
492 }
493
Sebastian Redl539c5062010-08-18 23:57:32 +0000494 Code = serialization::EXPR_INTEGER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000495}
496
Leonard Chandb01c3a2018-06-20 17:19:40 +0000497void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
498 VisitExpr(E);
499 Record.AddSourceLocation(E->getLocation());
500 Record.AddAPInt(E->getValue());
501 Code = serialization::EXPR_INTEGER_LITERAL;
502}
503
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000504void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000505 VisitExpr(E);
Tim Northover178723a2013-01-22 09:46:51 +0000506 Record.push_back(E->getRawSemantics());
Chris Lattner1f551822009-04-27 06:20:01 +0000507 Record.push_back(E->isExact());
Richard Smith290d8012016-04-06 17:06:00 +0000508 Record.AddAPFloat(E->getValue());
509 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000510 Code = serialization::EXPR_FLOATING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000511}
512
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000513void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000514 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000515 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000516 Code = serialization::EXPR_IMAGINARY_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000517}
518
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000519void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000520 VisitExpr(E);
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000521
522 // Store the various bits of data of StringLiteral.
Chris Lattner1f551822009-04-27 06:20:01 +0000523 Record.push_back(E->getNumConcatenated());
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000524 Record.push_back(E->getLength());
525 Record.push_back(E->getCharByteWidth());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000526 Record.push_back(E->getKind());
Anders Carlsson75245402011-04-14 00:40:03 +0000527 Record.push_back(E->isPascal());
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000528
529 // Store the trailing array of SourceLocation.
Chris Lattner1f551822009-04-27 06:20:01 +0000530 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000531 Record.AddSourceLocation(E->getStrTokenLoc(I));
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000532
533 // Store the trailing array of char holding the string data.
534 StringRef StrData = E->getBytes();
535 for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
536 Record.push_back(StrData[I]);
537
Sebastian Redl539c5062010-08-18 23:57:32 +0000538 Code = serialization::EXPR_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000539}
540
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000541void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000542 VisitExpr(E);
543 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +0000544 Record.AddSourceLocation(E->getLocation());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000545 Record.push_back(E->getKind());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000546
547 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
548
Sebastian Redl539c5062010-08-18 23:57:32 +0000549 Code = serialization::EXPR_CHARACTER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000550}
551
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000552void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000553 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000554 Record.AddSourceLocation(E->getLParen());
555 Record.AddSourceLocation(E->getRParen());
556 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000557 Code = serialization::EXPR_PAREN;
Chris Lattner1f551822009-04-27 06:20:01 +0000558}
559
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000560void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000561 VisitExpr(E);
Bruno Riccif49e1ca2018-11-20 16:20:40 +0000562 Record.push_back(E->getNumExprs());
563 for (auto *SubStmt : E->exprs())
564 Record.AddStmt(SubStmt);
565 Record.AddSourceLocation(E->getLParenLoc());
566 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000567 Code = serialization::EXPR_PAREN_LIST;
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000568}
569
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000570void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000571 VisitExpr(E);
Malcolm Parsonsfab36802018-04-16 08:31:08 +0000572 Record.AddStmt(E->getSubExpr());
573 Record.push_back(E->getOpcode()); // FIXME: stable encoding
574 Record.AddSourceLocation(E->getOperatorLoc());
575 Record.push_back(E->canOverflow());
576 Code = serialization::EXPR_UNARY_OPERATOR;
577}
578
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000579void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000580 VisitExpr(E);
581 Record.push_back(E->getNumComponents());
582 Record.push_back(E->getNumExpressions());
Richard Smith290d8012016-04-06 17:06:00 +0000583 Record.AddSourceLocation(E->getOperatorLoc());
584 Record.AddSourceLocation(E->getRParenLoc());
585 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Douglas Gregor882211c2010-04-28 22:16:22 +0000586 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +0000587 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +0000588 Record.push_back(ON.getKind()); // FIXME: Stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000589 Record.AddSourceLocation(ON.getSourceRange().getBegin());
590 Record.AddSourceLocation(ON.getSourceRange().getEnd());
Douglas Gregor882211c2010-04-28 22:16:22 +0000591 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +0000592 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +0000593 Record.push_back(ON.getArrayExprIndex());
594 break;
James Y Knight7281c352015-12-29 22:31:18 +0000595
596 case OffsetOfNode::Field:
Richard Smith290d8012016-04-06 17:06:00 +0000597 Record.AddDeclRef(ON.getField());
Douglas Gregor882211c2010-04-28 22:16:22 +0000598 break;
James Y Knight7281c352015-12-29 22:31:18 +0000599
600 case OffsetOfNode::Identifier:
Richard Smith290d8012016-04-06 17:06:00 +0000601 Record.AddIdentifierRef(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +0000602 break;
James Y Knight7281c352015-12-29 22:31:18 +0000603
604 case OffsetOfNode::Base:
Richard Smith290d8012016-04-06 17:06:00 +0000605 Record.AddCXXBaseSpecifier(*ON.getBase());
Douglas Gregord1702062010-04-29 00:18:15 +0000606 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000607 }
608 }
609 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000610 Record.AddStmt(E->getIndexExpr(I));
Sebastian Redl539c5062010-08-18 23:57:32 +0000611 Code = serialization::EXPR_OFFSETOF;
Douglas Gregor882211c2010-04-28 22:16:22 +0000612}
613
Peter Collingbournee190dee2011-03-11 19:24:49 +0000614void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000615 VisitExpr(E);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000616 Record.push_back(E->getKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000617 if (E->isArgumentType())
Richard Smith290d8012016-04-06 17:06:00 +0000618 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
Chris Lattner1f551822009-04-27 06:20:01 +0000619 else {
620 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +0000621 Record.AddStmt(E->getArgumentExpr());
Chris Lattner1f551822009-04-27 06:20:01 +0000622 }
Richard Smith290d8012016-04-06 17:06:00 +0000623 Record.AddSourceLocation(E->getOperatorLoc());
624 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000625 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
Chris Lattner1f551822009-04-27 06:20:01 +0000626}
627
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000628void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000629 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000630 Record.AddStmt(E->getLHS());
631 Record.AddStmt(E->getRHS());
632 Record.AddSourceLocation(E->getRBracketLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000633 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
Chris Lattner1f551822009-04-27 06:20:01 +0000634}
635
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000636void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
637 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000638 Record.AddStmt(E->getBase());
639 Record.AddStmt(E->getLowerBound());
640 Record.AddStmt(E->getLength());
641 Record.AddSourceLocation(E->getColonLoc());
642 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000643 Code = serialization::EXPR_OMP_ARRAY_SECTION;
644}
645
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000646void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000647 VisitExpr(E);
648 Record.push_back(E->getNumArgs());
Richard Smith290d8012016-04-06 17:06:00 +0000649 Record.AddSourceLocation(E->getRParenLoc());
650 Record.AddStmt(E->getCallee());
Chris Lattner1f551822009-04-27 06:20:01 +0000651 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
652 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +0000653 Record.AddStmt(*Arg);
Eric Fiselier5cdc2cd2018-12-12 21:50:55 +0000654 Record.push_back(static_cast<unsigned>(E->getADLCallKind()));
Sebastian Redl539c5062010-08-18 23:57:32 +0000655 Code = serialization::EXPR_CALL;
Chris Lattner1f551822009-04-27 06:20:01 +0000656}
657
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000658void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000659 // Don't call VisitExpr, we'll write everything here.
660
661 Record.push_back(E->hasQualifier());
Douglas Gregorea972d32011-02-28 21:54:11 +0000662 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000663 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000664
Bruno Ricci4c742532018-11-15 13:56:22 +0000665 Record.push_back(E->hasTemplateKWAndArgsInfo());
666 if (E->hasTemplateKWAndArgsInfo()) {
Richard Smith290d8012016-04-06 17:06:00 +0000667 Record.AddSourceLocation(E->getTemplateKeywordLoc());
Douglas Gregor87866ce2011-02-04 12:01:24 +0000668 unsigned NumTemplateArgs = E->getNumTemplateArgs();
669 Record.push_back(NumTemplateArgs);
Richard Smith290d8012016-04-06 17:06:00 +0000670 Record.AddSourceLocation(E->getLAngleLoc());
671 Record.AddSourceLocation(E->getRAngleLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000672 for (unsigned i=0; i != NumTemplateArgs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +0000673 Record.AddTemplateArgumentLoc(E->getTemplateArgs()[i]);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000674 }
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000675
676 Record.push_back(E->hadMultipleCandidates());
677
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000678 DeclAccessPair FoundDecl = E->getFoundDecl();
Richard Smith290d8012016-04-06 17:06:00 +0000679 Record.AddDeclRef(FoundDecl.getDecl());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000680 Record.push_back(FoundDecl.getAccess());
681
Richard Smith290d8012016-04-06 17:06:00 +0000682 Record.AddTypeRef(E->getType());
John McCall7decc9e2010-11-18 06:31:45 +0000683 Record.push_back(E->getValueKind());
684 Record.push_back(E->getObjectKind());
Richard Smith290d8012016-04-06 17:06:00 +0000685 Record.AddStmt(E->getBase());
686 Record.AddDeclRef(E->getMemberDecl());
687 Record.AddSourceLocation(E->getMemberLoc());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000688 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +0000689 Record.AddSourceLocation(E->getOperatorLoc());
690 Record.AddDeclarationNameLoc(E->MemberDNLoc,
691 E->getMemberDecl()->getDeclName());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000692 Code = serialization::EXPR_MEMBER;
Chris Lattner1f551822009-04-27 06:20:01 +0000693}
694
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000695void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Naroffe87026a2009-07-24 17:54:45 +0000696 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000697 Record.AddStmt(E->getBase());
698 Record.AddSourceLocation(E->getIsaMemberLoc());
699 Record.AddSourceLocation(E->getOpLoc());
Steve Naroffe87026a2009-07-24 17:54:45 +0000700 Record.push_back(E->isArrow());
Sebastian Redl539c5062010-08-18 23:57:32 +0000701 Code = serialization::EXPR_OBJC_ISA;
Steve Naroffe87026a2009-07-24 17:54:45 +0000702}
703
John McCall31168b02011-06-15 23:02:42 +0000704void ASTStmtWriter::
705VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
706 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000707 Record.AddStmt(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +0000708 Record.push_back(E->shouldCopy());
709 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
710}
711
712void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
713 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000714 Record.AddSourceLocation(E->getLParenLoc());
715 Record.AddSourceLocation(E->getBridgeKeywordLoc());
John McCall31168b02011-06-15 23:02:42 +0000716 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
717 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
718}
719
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000720void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000721 VisitExpr(E);
John McCallcf142162010-08-07 06:22:56 +0000722 Record.push_back(E->path_size());
Richard Smith290d8012016-04-06 17:06:00 +0000723 Record.AddStmt(E->getSubExpr());
Anders Carlssona2615922009-07-31 00:48:10 +0000724 Record.push_back(E->getCastKind()); // FIXME: stable encoding
John McCallcf142162010-08-07 06:22:56 +0000725
726 for (CastExpr::path_iterator
727 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
Richard Smith290d8012016-04-06 17:06:00 +0000728 Record.AddCXXBaseSpecifier(**PI);
Chris Lattner1f551822009-04-27 06:20:01 +0000729}
730
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000731void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000732 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000733 Record.AddStmt(E->getLHS());
734 Record.AddStmt(E->getRHS());
Chris Lattner1f551822009-04-27 06:20:01 +0000735 Record.push_back(E->getOpcode()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000736 Record.AddSourceLocation(E->getOperatorLoc());
Adam Nemet484aa452017-03-27 19:17:25 +0000737 Record.push_back(E->getFPFeatures().getInt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000738 Code = serialization::EXPR_BINARY_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000739}
740
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000741void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000742 VisitBinaryOperator(E);
Richard Smith290d8012016-04-06 17:06:00 +0000743 Record.AddTypeRef(E->getComputationLHSType());
744 Record.AddTypeRef(E->getComputationResultType());
Sebastian Redl539c5062010-08-18 23:57:32 +0000745 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000746}
747
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000748void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000749 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000750 Record.AddStmt(E->getCond());
751 Record.AddStmt(E->getLHS());
752 Record.AddStmt(E->getRHS());
753 Record.AddSourceLocation(E->getQuestionLoc());
754 Record.AddSourceLocation(E->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000755 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000756}
757
John McCallc07a0c72011-02-17 10:25:35 +0000758void
759ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
760 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000761 Record.AddStmt(E->getOpaqueValue());
762 Record.AddStmt(E->getCommon());
763 Record.AddStmt(E->getCond());
764 Record.AddStmt(E->getTrueExpr());
765 Record.AddStmt(E->getFalseExpr());
766 Record.AddSourceLocation(E->getQuestionLoc());
767 Record.AddSourceLocation(E->getColonLoc());
John McCallc07a0c72011-02-17 10:25:35 +0000768 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
769}
770
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000771void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000772 VisitCastExpr(E);
Roman Lebedev12216f12018-07-27 07:27:14 +0000773 Record.push_back(E->isPartOfExplicitCast());
Richard Smitha27c26e2014-07-27 04:19:32 +0000774
775 if (E->path_size() == 0)
776 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
777
Sebastian Redl539c5062010-08-18 23:57:32 +0000778 Code = serialization::EXPR_IMPLICIT_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000779}
780
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000781void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000782 VisitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000783 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
Chris Lattner1f551822009-04-27 06:20:01 +0000784}
785
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000786void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000787 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000788 Record.AddSourceLocation(E->getLParenLoc());
789 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000790 Code = serialization::EXPR_CSTYLE_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000791}
792
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000793void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000794 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000795 Record.AddSourceLocation(E->getLParenLoc());
796 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
797 Record.AddStmt(E->getInitializer());
Chris Lattner1f551822009-04-27 06:20:01 +0000798 Record.push_back(E->isFileScope());
Sebastian Redl539c5062010-08-18 23:57:32 +0000799 Code = serialization::EXPR_COMPOUND_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000800}
801
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000802void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000803 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000804 Record.AddStmt(E->getBase());
805 Record.AddIdentifierRef(&E->getAccessor());
806 Record.AddSourceLocation(E->getAccessorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000807 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
Chris Lattner1f551822009-04-27 06:20:01 +0000808}
809
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000810void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000811 VisitExpr(E);
Abramo Bagnara8d16bd42012-11-08 18:41:43 +0000812 // NOTE: only add the (possibly null) syntactic form.
813 // No need to serialize the isSemanticForm flag and the semantic form.
Richard Smith290d8012016-04-06 17:06:00 +0000814 Record.AddStmt(E->getSyntacticForm());
815 Record.AddSourceLocation(E->getLBraceLoc());
816 Record.AddSourceLocation(E->getRBraceLoc());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000817 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
818 Record.push_back(isArrayFiller);
819 if (isArrayFiller)
Richard Smith290d8012016-04-06 17:06:00 +0000820 Record.AddStmt(E->getArrayFiller());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000821 else
Richard Smith290d8012016-04-06 17:06:00 +0000822 Record.AddDeclRef(E->getInitializedFieldInUnion());
Chris Lattner1f551822009-04-27 06:20:01 +0000823 Record.push_back(E->hadArrayRangeDesignator());
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000824 Record.push_back(E->getNumInits());
825 if (isArrayFiller) {
826 // ArrayFiller may have filled "holes" due to designated initializer.
827 // Replace them by 0 to indicate that the filler goes in that place.
828 Expr *filler = E->getArrayFiller();
829 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000830 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000831 } else {
832 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000833 Record.AddStmt(E->getInit(I));
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000834 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000835 Code = serialization::EXPR_INIT_LIST;
Chris Lattner1f551822009-04-27 06:20:01 +0000836}
837
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000838void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000839 VisitExpr(E);
840 Record.push_back(E->getNumSubExprs());
841 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000842 Record.AddStmt(E->getSubExpr(I));
843 Record.AddSourceLocation(E->getEqualOrColonLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000844 Record.push_back(E->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +0000845 for (const DesignatedInitExpr::Designator &D : E->designators()) {
846 if (D.isFieldDesignator()) {
847 if (FieldDecl *Field = D.getField()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000848 Record.push_back(serialization::DESIG_FIELD_DECL);
Richard Smith290d8012016-04-06 17:06:00 +0000849 Record.AddDeclRef(Field);
Chris Lattner1f551822009-04-27 06:20:01 +0000850 } else {
Sebastian Redl539c5062010-08-18 23:57:32 +0000851 Record.push_back(serialization::DESIG_FIELD_NAME);
David Majnemerf7e36092016-06-23 00:15:04 +0000852 Record.AddIdentifierRef(D.getFieldName());
Chris Lattner1f551822009-04-27 06:20:01 +0000853 }
David Majnemerf7e36092016-06-23 00:15:04 +0000854 Record.AddSourceLocation(D.getDotLoc());
855 Record.AddSourceLocation(D.getFieldLoc());
856 } else if (D.isArrayDesignator()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000857 Record.push_back(serialization::DESIG_ARRAY);
David Majnemerf7e36092016-06-23 00:15:04 +0000858 Record.push_back(D.getFirstExprIndex());
859 Record.AddSourceLocation(D.getLBracketLoc());
860 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000861 } else {
David Majnemerf7e36092016-06-23 00:15:04 +0000862 assert(D.isArrayRangeDesignator() && "Unknown designator");
Sebastian Redl539c5062010-08-18 23:57:32 +0000863 Record.push_back(serialization::DESIG_ARRAY_RANGE);
David Majnemerf7e36092016-06-23 00:15:04 +0000864 Record.push_back(D.getFirstExprIndex());
865 Record.AddSourceLocation(D.getLBracketLoc());
866 Record.AddSourceLocation(D.getEllipsisLoc());
867 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000868 }
869 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000870 Code = serialization::EXPR_DESIGNATED_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000871}
872
Yunzhong Gaocb779302015-06-10 00:27:52 +0000873void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
874 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000875 Record.AddStmt(E->getBase());
876 Record.AddStmt(E->getUpdater());
Yunzhong Gaocb779302015-06-10 00:27:52 +0000877 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
878}
879
880void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
881 VisitExpr(E);
882 Code = serialization::EXPR_NO_INIT;
883}
884
Richard Smith410306b2016-12-12 02:53:20 +0000885void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
886 VisitExpr(E);
887 Record.AddStmt(E->SubExprs[0]);
888 Record.AddStmt(E->SubExprs[1]);
889 Code = serialization::EXPR_ARRAY_INIT_LOOP;
890}
891
892void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
893 VisitExpr(E);
894 Code = serialization::EXPR_ARRAY_INIT_INDEX;
895}
896
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000897void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000898 VisitExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +0000899 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000900}
901
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000902void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000903 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000904 Record.AddStmt(E->getSubExpr());
905 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
906 Record.AddSourceLocation(E->getBuiltinLoc());
907 Record.AddSourceLocation(E->getRParenLoc());
Charles Davisc7d5c942015-09-17 20:55:33 +0000908 Record.push_back(E->isMicrosoftABI());
Sebastian Redl539c5062010-08-18 23:57:32 +0000909 Code = serialization::EXPR_VA_ARG;
Chris Lattner1f551822009-04-27 06:20:01 +0000910}
911
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000912void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000913 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000914 Record.AddSourceLocation(E->getAmpAmpLoc());
915 Record.AddSourceLocation(E->getLabelLoc());
916 Record.AddDeclRef(E->getLabel());
Sebastian Redl539c5062010-08-18 23:57:32 +0000917 Code = serialization::EXPR_ADDR_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000918}
919
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000920void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000921 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000922 Record.AddStmt(E->getSubStmt());
923 Record.AddSourceLocation(E->getLParenLoc());
924 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000925 Code = serialization::EXPR_STMT;
Chris Lattner1f551822009-04-27 06:20:01 +0000926}
927
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000928void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000929 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000930 Record.AddStmt(E->getCond());
931 Record.AddStmt(E->getLHS());
932 Record.AddStmt(E->getRHS());
933 Record.AddSourceLocation(E->getBuiltinLoc());
934 Record.AddSourceLocation(E->getRParenLoc());
Eli Friedman75807f22013-07-20 00:40:58 +0000935 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
Sebastian Redl539c5062010-08-18 23:57:32 +0000936 Code = serialization::EXPR_CHOOSE;
Chris Lattner1f551822009-04-27 06:20:01 +0000937}
938
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000939void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000940 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000941 Record.AddSourceLocation(E->getTokenLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000942 Code = serialization::EXPR_GNU_NULL;
Chris Lattner1f551822009-04-27 06:20:01 +0000943}
944
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000945void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000946 VisitExpr(E);
947 Record.push_back(E->getNumSubExprs());
948 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000949 Record.AddStmt(E->getExpr(I));
950 Record.AddSourceLocation(E->getBuiltinLoc());
951 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000952 Code = serialization::EXPR_SHUFFLE_VECTOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000953}
954
Hal Finkelc4d7c822013-09-18 03:29:45 +0000955void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
956 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000957 Record.AddSourceLocation(E->getBuiltinLoc());
958 Record.AddSourceLocation(E->getRParenLoc());
959 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
960 Record.AddStmt(E->getSrcExpr());
Hal Finkelc4d7c822013-09-18 03:29:45 +0000961 Code = serialization::EXPR_CONVERT_VECTOR;
962}
963
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000964void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000965 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000966 Record.AddDeclRef(E->getBlockDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000967 Code = serialization::EXPR_BLOCK;
Chris Lattner1f551822009-04-27 06:20:01 +0000968}
969
Peter Collingbourne91147592011-04-15 00:35:48 +0000970void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
971 VisitExpr(E);
972 Record.push_back(E->getNumAssocs());
973
Richard Smith290d8012016-04-06 17:06:00 +0000974 Record.AddStmt(E->getControllingExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +0000975 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000976 Record.AddTypeSourceInfo(E->getAssocTypeSourceInfo(I));
977 Record.AddStmt(E->getAssocExpr(I));
Peter Collingbourne91147592011-04-15 00:35:48 +0000978 }
979 Record.push_back(E->isResultDependent() ? -1U : E->getResultIndex());
980
Richard Smith290d8012016-04-06 17:06:00 +0000981 Record.AddSourceLocation(E->getGenericLoc());
982 Record.AddSourceLocation(E->getDefaultLoc());
983 Record.AddSourceLocation(E->getRParenLoc());
Peter Collingbourne91147592011-04-15 00:35:48 +0000984 Code = serialization::EXPR_GENERIC_SELECTION;
985}
986
John McCallfe96e0b2011-11-06 09:01:30 +0000987void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
988 VisitExpr(E);
989 Record.push_back(E->getNumSemanticExprs());
990
991 // Push the result index. Currently, this needs to exactly match
992 // the encoding used internally for ResultIndex.
993 unsigned result = E->getResultExprIndex();
994 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
995 Record.push_back(result);
996
Richard Smith290d8012016-04-06 17:06:00 +0000997 Record.AddStmt(E->getSyntacticForm());
John McCallfe96e0b2011-11-06 09:01:30 +0000998 for (PseudoObjectExpr::semantics_iterator
999 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
Richard Smith290d8012016-04-06 17:06:00 +00001000 Record.AddStmt(*i);
John McCallfe96e0b2011-11-06 09:01:30 +00001001 }
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +00001002 Code = serialization::EXPR_PSEUDO_OBJECT;
John McCallfe96e0b2011-11-06 09:01:30 +00001003}
1004
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001005void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
1006 VisitExpr(E);
1007 Record.push_back(E->getOp());
Richard Smithaa22a8c2012-04-10 22:49:28 +00001008 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001009 Record.AddStmt(E->getSubExprs()[I]);
1010 Record.AddSourceLocation(E->getBuiltinLoc());
1011 Record.AddSourceLocation(E->getRParenLoc());
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +00001012 Code = serialization::EXPR_ATOMIC;
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001013}
1014
Chris Lattner1f551822009-04-27 06:20:01 +00001015//===----------------------------------------------------------------------===//
1016// Objective-C Expressions and Statements.
1017//===----------------------------------------------------------------------===//
1018
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001019void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001020 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001021 Record.AddStmt(E->getString());
1022 Record.AddSourceLocation(E->getAtLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001023 Code = serialization::EXPR_OBJC_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +00001024}
1025
Patrick Beard0caa3942012-04-19 00:25:12 +00001026void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001027 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001028 Record.AddStmt(E->getSubExpr());
1029 Record.AddDeclRef(E->getBoxingMethod());
1030 Record.AddSourceRange(E->getSourceRange());
Patrick Beard0caa3942012-04-19 00:25:12 +00001031 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
Ted Kremeneke65b0862012-03-06 20:05:56 +00001032}
1033
1034void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1035 VisitExpr(E);
1036 Record.push_back(E->getNumElements());
1037 for (unsigned i = 0; i < E->getNumElements(); i++)
Richard Smith290d8012016-04-06 17:06:00 +00001038 Record.AddStmt(E->getElement(i));
1039 Record.AddDeclRef(E->getArrayWithObjectsMethod());
1040 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001041 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1042}
1043
1044void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1045 VisitExpr(E);
1046 Record.push_back(E->getNumElements());
1047 Record.push_back(E->HasPackExpansions);
1048 for (unsigned i = 0; i < E->getNumElements(); i++) {
1049 ObjCDictionaryElement Element = E->getKeyValueElement(i);
Richard Smith290d8012016-04-06 17:06:00 +00001050 Record.AddStmt(Element.Key);
1051 Record.AddStmt(Element.Value);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001052 if (E->HasPackExpansions) {
Richard Smith290d8012016-04-06 17:06:00 +00001053 Record.AddSourceLocation(Element.EllipsisLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001054 unsigned NumExpansions = 0;
1055 if (Element.NumExpansions)
1056 NumExpansions = *Element.NumExpansions + 1;
1057 Record.push_back(NumExpansions);
1058 }
1059 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001060
Richard Smith290d8012016-04-06 17:06:00 +00001061 Record.AddDeclRef(E->getDictWithObjectsMethod());
1062 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001063 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1064}
1065
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001066void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001067 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001068 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1069 Record.AddSourceLocation(E->getAtLoc());
1070 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001071 Code = serialization::EXPR_OBJC_ENCODE;
Chris Lattner1f551822009-04-27 06:20:01 +00001072}
1073
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001074void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001075 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001076 Record.AddSelectorRef(E->getSelector());
1077 Record.AddSourceLocation(E->getAtLoc());
1078 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001079 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001080}
1081
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001082void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001083 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001084 Record.AddDeclRef(E->getProtocol());
1085 Record.AddSourceLocation(E->getAtLoc());
1086 Record.AddSourceLocation(E->ProtoLoc);
1087 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001088 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001089}
1090
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001091void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001092 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001093 Record.AddDeclRef(E->getDecl());
1094 Record.AddSourceLocation(E->getLocation());
1095 Record.AddSourceLocation(E->getOpLoc());
1096 Record.AddStmt(E->getBase());
Chris Lattner1f551822009-04-27 06:20:01 +00001097 Record.push_back(E->isArrow());
1098 Record.push_back(E->isFreeIvar());
Sebastian Redl539c5062010-08-18 23:57:32 +00001099 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001100}
1101
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001102void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001103 VisitExpr(E);
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001104 Record.push_back(E->SetterAndMethodRefFlags.getInt());
John McCallb7bd14f2010-12-02 01:19:52 +00001105 Record.push_back(E->isImplicitProperty());
1106 if (E->isImplicitProperty()) {
Richard Smith290d8012016-04-06 17:06:00 +00001107 Record.AddDeclRef(E->getImplicitPropertyGetter());
1108 Record.AddDeclRef(E->getImplicitPropertySetter());
John McCallb7bd14f2010-12-02 01:19:52 +00001109 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001110 Record.AddDeclRef(E->getExplicitProperty());
John McCallb7bd14f2010-12-02 01:19:52 +00001111 }
Richard Smith290d8012016-04-06 17:06:00 +00001112 Record.AddSourceLocation(E->getLocation());
1113 Record.AddSourceLocation(E->getReceiverLocation());
John McCallb7bd14f2010-12-02 01:19:52 +00001114 if (E->isObjectReceiver()) {
1115 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +00001116 Record.AddStmt(E->getBase());
John McCallb7bd14f2010-12-02 01:19:52 +00001117 } else if (E->isSuperReceiver()) {
1118 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001119 Record.AddTypeRef(E->getSuperReceiverType());
John McCallb7bd14f2010-12-02 01:19:52 +00001120 } else {
1121 Record.push_back(2);
Richard Smith290d8012016-04-06 17:06:00 +00001122 Record.AddDeclRef(E->getClassReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001123 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001124
Sebastian Redl539c5062010-08-18 23:57:32 +00001125 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001126}
1127
Ted Kremeneke65b0862012-03-06 20:05:56 +00001128void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1129 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001130 Record.AddSourceLocation(E->getRBracket());
1131 Record.AddStmt(E->getBaseExpr());
1132 Record.AddStmt(E->getKeyExpr());
1133 Record.AddDeclRef(E->getAtIndexMethodDecl());
1134 Record.AddDeclRef(E->setAtIndexMethodDecl());
Fangrui Song6907ce22018-07-30 19:24:48 +00001135
Ted Kremeneke65b0862012-03-06 20:05:56 +00001136 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1137}
1138
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001139void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001140 VisitExpr(E);
1141 Record.push_back(E->getNumArgs());
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001142 Record.push_back(E->getNumStoredSelLocs());
1143 Record.push_back(E->SelLocsKind);
John McCall31168b02011-06-15 23:02:42 +00001144 Record.push_back(E->isDelegateInitCall());
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +00001145 Record.push_back(E->IsImplicit);
Douglas Gregor9a129192010-04-21 00:45:42 +00001146 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1147 switch (E->getReceiverKind()) {
1148 case ObjCMessageExpr::Instance:
Richard Smith290d8012016-04-06 17:06:00 +00001149 Record.AddStmt(E->getInstanceReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001150 break;
1151
1152 case ObjCMessageExpr::Class:
Richard Smith290d8012016-04-06 17:06:00 +00001153 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
Douglas Gregor9a129192010-04-21 00:45:42 +00001154 break;
1155
1156 case ObjCMessageExpr::SuperClass:
1157 case ObjCMessageExpr::SuperInstance:
Richard Smith290d8012016-04-06 17:06:00 +00001158 Record.AddTypeRef(E->getSuperType());
1159 Record.AddSourceLocation(E->getSuperLoc());
Douglas Gregor9a129192010-04-21 00:45:42 +00001160 break;
1161 }
1162
1163 if (E->getMethodDecl()) {
1164 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001165 Record.AddDeclRef(E->getMethodDecl());
Douglas Gregor9a129192010-04-21 00:45:42 +00001166 } else {
1167 Record.push_back(0);
Fangrui Song6907ce22018-07-30 19:24:48 +00001168 Record.AddSelectorRef(E->getSelector());
Douglas Gregor9a129192010-04-21 00:45:42 +00001169 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001170
Richard Smith290d8012016-04-06 17:06:00 +00001171 Record.AddSourceLocation(E->getLeftLoc());
1172 Record.AddSourceLocation(E->getRightLoc());
Chris Lattner1f551822009-04-27 06:20:01 +00001173
1174 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1175 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +00001176 Record.AddStmt(*Arg);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001177
1178 SourceLocation *Locs = E->getStoredSelLocs();
1179 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001180 Record.AddSourceLocation(Locs[i]);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001181
Sebastian Redl539c5062010-08-18 23:57:32 +00001182 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001183}
1184
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001185void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00001186 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001187 Record.AddStmt(S->getElement());
1188 Record.AddStmt(S->getCollection());
1189 Record.AddStmt(S->getBody());
1190 Record.AddSourceLocation(S->getForLoc());
1191 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001192 Code = serialization::STMT_OBJC_FOR_COLLECTION;
Chris Lattner1f551822009-04-27 06:20:01 +00001193}
1194
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001195void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001196 Record.AddStmt(S->getCatchBody());
1197 Record.AddDeclRef(S->getCatchParamDecl());
1198 Record.AddSourceLocation(S->getAtCatchLoc());
1199 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001200 Code = serialization::STMT_OBJC_CATCH;
Chris Lattner1f551822009-04-27 06:20:01 +00001201}
1202
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001203void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001204 Record.AddStmt(S->getFinallyBody());
1205 Record.AddSourceLocation(S->getAtFinallyLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001206 Code = serialization::STMT_OBJC_FINALLY;
Chris Lattner1f551822009-04-27 06:20:01 +00001207}
1208
John McCall31168b02011-06-15 23:02:42 +00001209void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001210 Record.AddStmt(S->getSubStmt());
1211 Record.AddSourceLocation(S->getAtLoc());
John McCall31168b02011-06-15 23:02:42 +00001212 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1213}
1214
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001215void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor96c79492010-04-23 22:50:49 +00001216 Record.push_back(S->getNumCatchStmts());
Craig Toppera13603a2014-05-22 05:54:18 +00001217 Record.push_back(S->getFinallyStmt() != nullptr);
Richard Smith290d8012016-04-06 17:06:00 +00001218 Record.AddStmt(S->getTryBody());
Douglas Gregor96c79492010-04-23 22:50:49 +00001219 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001220 Record.AddStmt(S->getCatchStmt(I));
Douglas Gregor96c79492010-04-23 22:50:49 +00001221 if (S->getFinallyStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001222 Record.AddStmt(S->getFinallyStmt());
1223 Record.AddSourceLocation(S->getAtTryLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001224 Code = serialization::STMT_OBJC_AT_TRY;
Chris Lattner1f551822009-04-27 06:20:01 +00001225}
1226
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001227void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001228 Record.AddStmt(S->getSynchExpr());
1229 Record.AddStmt(S->getSynchBody());
1230 Record.AddSourceLocation(S->getAtSynchronizedLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001231 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
Chris Lattner1f551822009-04-27 06:20:01 +00001232}
1233
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001234void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001235 Record.AddStmt(S->getThrowExpr());
1236 Record.AddSourceLocation(S->getThrowLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001237 Code = serialization::STMT_OBJC_AT_THROW;
Chris Lattner1f551822009-04-27 06:20:01 +00001238}
1239
Ted Kremeneke65b0862012-03-06 20:05:56 +00001240void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1241 VisitExpr(E);
1242 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001243 Record.AddSourceLocation(E->getLocation());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001244 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1245}
1246
Erik Pilkington29099de2016-07-16 00:35:23 +00001247void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1248 VisitExpr(E);
1249 Record.AddSourceRange(E->getSourceRange());
1250 Record.AddVersionTuple(E->getVersion());
1251 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1252}
1253
Chris Lattner1f551822009-04-27 06:20:01 +00001254//===----------------------------------------------------------------------===//
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001255// C++ Expressions and Statements.
1256//===----------------------------------------------------------------------===//
1257
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001258void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001259 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001260 Record.AddSourceLocation(S->getCatchLoc());
1261 Record.AddDeclRef(S->getExceptionDecl());
1262 Record.AddStmt(S->getHandlerBlock());
Sebastian Redl539c5062010-08-18 23:57:32 +00001263 Code = serialization::STMT_CXX_CATCH;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001264}
1265
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001266void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001267 VisitStmt(S);
1268 Record.push_back(S->getNumHandlers());
Richard Smith290d8012016-04-06 17:06:00 +00001269 Record.AddSourceLocation(S->getTryLoc());
1270 Record.AddStmt(S->getTryBlock());
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001271 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001272 Record.AddStmt(S->getHandler(i));
Sebastian Redl539c5062010-08-18 23:57:32 +00001273 Code = serialization::STMT_CXX_TRY;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001274}
1275
Richard Smith02e85f32011-04-14 22:09:26 +00001276void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1277 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001278 Record.AddSourceLocation(S->getForLoc());
1279 Record.AddSourceLocation(S->getCoawaitLoc());
1280 Record.AddSourceLocation(S->getColonLoc());
1281 Record.AddSourceLocation(S->getRParenLoc());
Richard Smith8baa5002018-09-28 18:44:09 +00001282 Record.AddStmt(S->getInit());
Richard Smith290d8012016-04-06 17:06:00 +00001283 Record.AddStmt(S->getRangeStmt());
1284 Record.AddStmt(S->getBeginStmt());
1285 Record.AddStmt(S->getEndStmt());
1286 Record.AddStmt(S->getCond());
1287 Record.AddStmt(S->getInc());
1288 Record.AddStmt(S->getLoopVarStmt());
1289 Record.AddStmt(S->getBody());
Richard Smith02e85f32011-04-14 22:09:26 +00001290 Code = serialization::STMT_CXX_FOR_RANGE;
1291}
1292
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001293void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1294 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001295 Record.AddSourceLocation(S->getKeywordLoc());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001296 Record.push_back(S->isIfExists());
Richard Smith290d8012016-04-06 17:06:00 +00001297 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1298 Record.AddDeclarationNameInfo(S->getNameInfo());
1299 Record.AddStmt(S->getSubStmt());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001300 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1301}
1302
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001303void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001304 VisitCallExpr(E);
1305 Record.push_back(E->getOperator());
Adam Nemet484aa452017-03-27 19:17:25 +00001306 Record.push_back(E->getFPFeatures().getInt());
Bruno Riccifeb19232018-12-21 16:51:57 +00001307 Record.AddSourceRange(E->Range);
Sebastian Redl539c5062010-08-18 23:57:32 +00001308 Code = serialization::EXPR_CXX_OPERATOR_CALL;
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001309}
1310
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001311void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001312 VisitCallExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001313 Code = serialization::EXPR_CXX_MEMBER_CALL;
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001314}
1315
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001316void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001317 VisitExpr(E);
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001318
Argyrios Kyrtzidis30d98f32010-06-24 08:57:09 +00001319 Record.push_back(E->getNumArgs());
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001320 Record.push_back(E->isElidable());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00001321 Record.push_back(E->hadMultipleCandidates());
Richard Smithd59b8322012-12-19 01:39:02 +00001322 Record.push_back(E->isListInitialization());
Richard Smithf8adcdc2014-07-17 05:12:35 +00001323 Record.push_back(E->isStdInitListInitialization());
Douglas Gregor4f4b1862009-12-16 18:50:27 +00001324 Record.push_back(E->requiresZeroInitialization());
Douglas Gregor222cf0e2010-05-15 00:13:29 +00001325 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001326 Record.AddSourceLocation(E->getLocation());
1327 Record.AddDeclRef(E->getConstructor());
Richard Smith290d8012016-04-06 17:06:00 +00001328 Record.AddSourceRange(E->getParenOrBraceRange());
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001329
1330 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1331 Record.AddStmt(E->getArg(I));
1332
Sebastian Redl539c5062010-08-18 23:57:32 +00001333 Code = serialization::EXPR_CXX_CONSTRUCT;
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001334}
1335
Richard Smith5179eb72016-06-28 19:03:57 +00001336void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1337 VisitExpr(E);
1338 Record.AddDeclRef(E->getConstructor());
1339 Record.AddSourceLocation(E->getLocation());
1340 Record.push_back(E->constructsVBase());
1341 Record.push_back(E->inheritedFromVBase());
1342 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1343}
1344
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001345void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001346 VisitCXXConstructExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001347 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001348 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001349}
1350
Douglas Gregore31e6062012-02-07 10:09:13 +00001351void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1352 VisitExpr(E);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001353 Record.push_back(E->NumCaptures);
Richard Smith290d8012016-04-06 17:06:00 +00001354 Record.AddSourceRange(E->IntroducerRange);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001355 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +00001356 Record.AddSourceLocation(E->CaptureDefaultLoc);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001357 Record.push_back(E->ExplicitParams);
1358 Record.push_back(E->ExplicitResultType);
Richard Smith290d8012016-04-06 17:06:00 +00001359 Record.AddSourceLocation(E->ClosingBrace);
Fangrui Song6907ce22018-07-30 19:24:48 +00001360
Douglas Gregor99ae8062012-02-14 17:54:36 +00001361 // Add capture initializers.
1362 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1363 CEnd = E->capture_init_end();
1364 C != CEnd; ++C) {
Richard Smith290d8012016-04-06 17:06:00 +00001365 Record.AddStmt(*C);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001366 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001367
Douglas Gregor99ae8062012-02-14 17:54:36 +00001368 Code = serialization::EXPR_LAMBDA;
Douglas Gregore31e6062012-02-07 10:09:13 +00001369}
1370
Richard Smithcc1b96d2013-06-12 22:31:48 +00001371void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1372 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001373 Record.AddStmt(E->getSubExpr());
Richard Smithcc1b96d2013-06-12 22:31:48 +00001374 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1375}
1376
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001377void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001378 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001379 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1380 Record.AddSourceRange(E->getAngleBrackets());
Sam Weinigd01101e2010-01-16 21:21:01 +00001381}
1382
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001383void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001384 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001385 Code = serialization::EXPR_CXX_STATIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001386}
1387
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001388void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001389 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001390 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001391}
1392
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001393void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001394 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001395 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001396}
1397
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001398void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001399 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001400 Code = serialization::EXPR_CXX_CONST_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001401}
1402
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001403void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001404 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001405 Record.AddSourceLocation(E->getLParenLoc());
1406 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001407 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001408}
1409
Richard Smithc67fdd42012-03-07 08:35:16 +00001410void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1411 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001412 Record.AddSourceLocation(E->UDSuffixLoc);
Richard Smithc67fdd42012-03-07 08:35:16 +00001413 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1414}
1415
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001416void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001417 VisitExpr(E);
1418 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001419 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001420 Code = serialization::EXPR_CXX_BOOL_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001421}
1422
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001423void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001424 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001425 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001426 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001427}
1428
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001429void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001430 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001431 Record.AddSourceRange(E->getSourceRange());
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001432 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001433 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001434 Code = serialization::EXPR_CXX_TYPEID_TYPE;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001435 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001436 Record.AddStmt(E->getExprOperand());
Sebastian Redl539c5062010-08-18 23:57:32 +00001437 Code = serialization::EXPR_CXX_TYPEID_EXPR;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001438 }
1439}
1440
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001441void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner98267332010-05-09 06:15:05 +00001442 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001443 Record.AddSourceLocation(E->getLocation());
Chris Lattner98267332010-05-09 06:15:05 +00001444 Record.push_back(E->isImplicit());
Sebastian Redl539c5062010-08-18 23:57:32 +00001445 Code = serialization::EXPR_CXX_THIS;
Chris Lattner98267332010-05-09 06:15:05 +00001446}
1447
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001448void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001449 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001450 Record.AddSourceLocation(E->getThrowLoc());
1451 Record.AddStmt(E->getSubExpr());
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001452 Record.push_back(E->isThrownVariableInScope());
Sebastian Redl539c5062010-08-18 23:57:32 +00001453 Code = serialization::EXPR_CXX_THROW;
Chris Lattner98267332010-05-09 06:15:05 +00001454}
1455
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001456void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001457 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001458 Record.AddDeclRef(E->getParam());
1459 Record.AddSourceLocation(E->getUsedLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001460 Code = serialization::EXPR_CXX_DEFAULT_ARG;
Chris Lattnere2437f42010-05-09 06:40:08 +00001461}
1462
Richard Smith852c9db2013-04-20 22:23:05 +00001463void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1464 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001465 Record.AddDeclRef(E->getField());
1466 Record.AddSourceLocation(E->getExprLoc());
Richard Smith852c9db2013-04-20 22:23:05 +00001467 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1468}
1469
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001470void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001471 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001472 Record.AddCXXTemporary(E->getTemporary());
1473 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +00001474 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
Chris Lattnercba86142010-05-10 00:25:06 +00001475}
1476
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001477void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001478 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001479 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1480 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001481 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001482}
1483
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001484void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001485 VisitExpr(E);
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001486
Sebastian Redlc3a3c602012-02-16 11:35:52 +00001487 Record.push_back(E->isArray());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001488 Record.push_back(E->hasInitializer());
1489 Record.push_back(E->getNumPlacementArgs());
1490 Record.push_back(E->isParenTypeId());
1491
1492 Record.push_back(E->isGlobalNew());
Richard Smithb2f0f052016-10-10 18:54:32 +00001493 Record.push_back(E->passAlignment());
Sebastian Redl6047f072012-02-16 12:22:20 +00001494 Record.push_back(E->doesUsualArrayDeleteWantSize());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001495 Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
1496
Richard Smith290d8012016-04-06 17:06:00 +00001497 Record.AddDeclRef(E->getOperatorNew());
1498 Record.AddDeclRef(E->getOperatorDelete());
1499 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001500 if (E->isParenTypeId())
1501 Record.AddSourceRange(E->getTypeIdParens());
Richard Smith290d8012016-04-06 17:06:00 +00001502 Record.AddSourceRange(E->getSourceRange());
1503 Record.AddSourceRange(E->getDirectInitRange());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001504
1505 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
1506 I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001507 Record.AddStmt(*I);
Sebastian Redl6047f072012-02-16 12:22:20 +00001508
Sebastian Redl539c5062010-08-18 23:57:32 +00001509 Code = serialization::EXPR_CXX_NEW;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001510}
1511
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001512void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001513 VisitExpr(E);
1514 Record.push_back(E->isGlobalDelete());
1515 Record.push_back(E->isArrayForm());
Argyrios Kyrtzidis14ec9f62010-09-13 20:15:54 +00001516 Record.push_back(E->isArrayFormAsWritten());
John McCall284c48f2011-01-27 09:37:56 +00001517 Record.push_back(E->doesUsualArrayDeleteWantSize());
Richard Smith290d8012016-04-06 17:06:00 +00001518 Record.AddDeclRef(E->getOperatorDelete());
1519 Record.AddStmt(E->getArgument());
Bruno Ricci91728fc2018-12-03 12:32:32 +00001520 Record.AddSourceLocation(E->getBeginLoc());
Fangrui Song6907ce22018-07-30 19:24:48 +00001521
Sebastian Redl539c5062010-08-18 23:57:32 +00001522 Code = serialization::EXPR_CXX_DELETE;
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001523}
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001524
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001525void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001526 VisitExpr(E);
1527
Richard Smith290d8012016-04-06 17:06:00 +00001528 Record.AddStmt(E->getBase());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001529 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001530 Record.AddSourceLocation(E->getOperatorLoc());
1531 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1532 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1533 Record.AddSourceLocation(E->getColonColonLoc());
1534 Record.AddSourceLocation(E->getTildeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001535
1536 // PseudoDestructorTypeStorage.
Richard Smith290d8012016-04-06 17:06:00 +00001537 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001538 if (E->getDestroyedTypeIdentifier())
Richard Smith290d8012016-04-06 17:06:00 +00001539 Record.AddSourceLocation(E->getDestroyedTypeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001540 else
Richard Smith290d8012016-04-06 17:06:00 +00001541 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001542
Sebastian Redl539c5062010-08-18 23:57:32 +00001543 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001544}
1545
John McCall5d413782010-12-06 08:20:24 +00001546void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001547 VisitExpr(E);
John McCall28fc7092011-11-10 05:35:25 +00001548 Record.push_back(E->getNumObjects());
1549 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001550 Record.AddDeclRef(E->getObject(i));
Tim Shen4a05bb82016-06-21 20:29:17 +00001551
1552 Record.push_back(E->cleanupsHaveSideEffects());
Richard Smith290d8012016-04-06 17:06:00 +00001553 Record.AddStmt(E->getSubExpr());
John McCall5d413782010-12-06 08:20:24 +00001554 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
Chris Lattnercba86142010-05-10 00:25:06 +00001555}
1556
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001557void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001558ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001559 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001560
1561 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
Douglas Gregor87866ce2011-02-04 12:01:24 +00001562 // emitted first.
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001563
Abramo Bagnara7945c982012-01-27 09:46:47 +00001564 Record.push_back(E->HasTemplateKWAndArgsInfo);
1565 if (E->HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001566 const ASTTemplateKWAndArgsInfo &ArgInfo =
1567 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1568 Record.push_back(ArgInfo.NumTemplateArgs);
1569 AddTemplateKWAndArgsInfo(ArgInfo,
1570 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001571 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00001572
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001573 if (!E->isImplicitAccess())
Richard Smith290d8012016-04-06 17:06:00 +00001574 Record.AddStmt(E->getBase());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001575 else
Richard Smith290d8012016-04-06 17:06:00 +00001576 Record.AddStmt(nullptr);
1577 Record.AddTypeRef(E->getBaseType());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001578 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001579 Record.AddSourceLocation(E->getOperatorLoc());
1580 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1581 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1582 Record.AddDeclarationNameInfo(E->MemberNameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001583 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001584}
1585
1586void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001587ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001588 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001589
1590 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
Douglas Gregor87866ce2011-02-04 12:01:24 +00001591 // emitted first.
Abramo Bagnara7945c982012-01-27 09:46:47 +00001592
Bruno Ricci49ee9642019-01-07 14:27:04 +00001593 Record.push_back(E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
1594 if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001595 const ASTTemplateKWAndArgsInfo &ArgInfo =
1596 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1597 Record.push_back(ArgInfo.NumTemplateArgs);
1598 AddTemplateKWAndArgsInfo(ArgInfo,
1599 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001600 }
1601
Richard Smith290d8012016-04-06 17:06:00 +00001602 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1603 Record.AddDeclarationNameInfo(E->NameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001604 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001605}
1606
1607void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001608ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001609 VisitExpr(E);
1610 Record.push_back(E->arg_size());
1611 for (CXXUnresolvedConstructExpr::arg_iterator
1612 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
Richard Smith290d8012016-04-06 17:06:00 +00001613 Record.AddStmt(*ArgI);
1614 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1615 Record.AddSourceLocation(E->getLParenLoc());
1616 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001617 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001618}
Chris Lattner98267332010-05-09 06:15:05 +00001619
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001620void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001621 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001622
1623 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1624 // emitted first.
1625
1626 Record.push_back(E->HasTemplateKWAndArgsInfo);
1627 if (E->HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001628 const ASTTemplateKWAndArgsInfo &ArgInfo =
1629 *E->getTrailingASTTemplateKWAndArgsInfo();
1630 Record.push_back(ArgInfo.NumTemplateArgs);
1631 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001632 }
1633
1634 Record.push_back(E->getNumDecls());
1635 for (OverloadExpr::decls_iterator
1636 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
Richard Smith290d8012016-04-06 17:06:00 +00001637 Record.AddDeclRef(OvI.getDecl());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001638 Record.push_back(OvI.getAccess());
1639 }
1640
Richard Smith290d8012016-04-06 17:06:00 +00001641 Record.AddDeclarationNameInfo(E->NameInfo);
1642 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001643}
1644
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001645void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001646 VisitOverloadExpr(E);
1647 Record.push_back(E->isArrow());
1648 Record.push_back(E->hasUnresolvedUsing());
Richard Smith290d8012016-04-06 17:06:00 +00001649 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1650 Record.AddTypeRef(E->getBaseType());
1651 Record.AddSourceLocation(E->getOperatorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001652 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001653}
1654
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001655void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001656 VisitOverloadExpr(E);
1657 Record.push_back(E->requiresADL());
1658 Record.push_back(E->isOverloaded());
Richard Smith290d8012016-04-06 17:06:00 +00001659 Record.AddDeclRef(E->getNamingClass());
Sebastian Redl539c5062010-08-18 23:57:32 +00001660 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001661}
1662
Douglas Gregor29c42f22012-02-24 07:38:34 +00001663void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1664 VisitExpr(E);
1665 Record.push_back(E->TypeTraitExprBits.NumArgs);
1666 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1667 Record.push_back(E->TypeTraitExprBits.Value);
Richard Smith290d8012016-04-06 17:06:00 +00001668 Record.AddSourceRange(E->getSourceRange());
Douglas Gregor29c42f22012-02-24 07:38:34 +00001669 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001670 Record.AddTypeSourceInfo(E->getArg(I));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001671 Code = serialization::EXPR_TYPE_TRAIT;
1672}
1673
John Wiegley6242b6a2011-04-28 00:16:57 +00001674void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1675 VisitExpr(E);
1676 Record.push_back(E->getTrait());
1677 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001678 Record.AddSourceRange(E->getSourceRange());
1679 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
Aleksei Sidorina693b372016-09-28 10:16:56 +00001680 Record.AddStmt(E->getDimensionExpression());
John Wiegley6242b6a2011-04-28 00:16:57 +00001681 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1682}
1683
John Wiegleyf9f65842011-04-25 06:54:41 +00001684void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1685 VisitExpr(E);
1686 Record.push_back(E->getTrait());
1687 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001688 Record.AddSourceRange(E->getSourceRange());
1689 Record.AddStmt(E->getQueriedExpression());
John Wiegleyf9f65842011-04-25 06:54:41 +00001690 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1691}
1692
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001693void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1694 VisitExpr(E);
1695 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001696 Record.AddSourceRange(E->getSourceRange());
1697 Record.AddStmt(E->getOperand());
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001698 Code = serialization::EXPR_CXX_NOEXCEPT;
1699}
1700
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001701void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1702 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001703 Record.AddSourceLocation(E->getEllipsisLoc());
Douglas Gregorb8840002011-01-14 21:20:45 +00001704 Record.push_back(E->NumExpansions);
Richard Smith290d8012016-04-06 17:06:00 +00001705 Record.AddStmt(E->getPattern());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001706 Code = serialization::EXPR_PACK_EXPANSION;
1707}
1708
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001709void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1710 VisitExpr(E);
Richard Smithd784e682015-09-23 21:41:42 +00001711 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1712 : 0);
Richard Smith290d8012016-04-06 17:06:00 +00001713 Record.AddSourceLocation(E->OperatorLoc);
1714 Record.AddSourceLocation(E->PackLoc);
1715 Record.AddSourceLocation(E->RParenLoc);
1716 Record.AddDeclRef(E->Pack);
Richard Smithd784e682015-09-23 21:41:42 +00001717 if (E->isPartiallySubstituted()) {
1718 for (const auto &TA : E->getPartialArguments())
Richard Smith290d8012016-04-06 17:06:00 +00001719 Record.AddTemplateArgument(TA);
Richard Smithd784e682015-09-23 21:41:42 +00001720 } else if (!E->isValueDependent()) {
1721 Record.push_back(E->getPackLength());
1722 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001723 Code = serialization::EXPR_SIZEOF_PACK;
1724}
1725
John McCallfa194042011-07-15 07:00:14 +00001726void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1727 SubstNonTypeTemplateParmExpr *E) {
1728 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001729 Record.AddDeclRef(E->getParameter());
1730 Record.AddSourceLocation(E->getNameLoc());
1731 Record.AddStmt(E->getReplacement());
John McCallfa194042011-07-15 07:00:14 +00001732 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1733}
1734
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001735void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1736 SubstNonTypeTemplateParmPackExpr *E) {
1737 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001738 Record.AddDeclRef(E->getParameterPack());
1739 Record.AddTemplateArgument(E->getArgumentPack());
1740 Record.AddSourceLocation(E->getParameterPackLocation());
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001741 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1742}
1743
Richard Smithb15fe3a2012-09-12 00:56:43 +00001744void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1745 VisitExpr(E);
1746 Record.push_back(E->getNumExpansions());
Richard Smith290d8012016-04-06 17:06:00 +00001747 Record.AddDeclRef(E->getParameterPack());
1748 Record.AddSourceLocation(E->getParameterPackLocation());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001749 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1750 I != End; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001751 Record.AddDeclRef(*I);
Richard Smithb15fe3a2012-09-12 00:56:43 +00001752 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1753}
1754
Douglas Gregorfe314812011-06-21 17:03:29 +00001755void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1756 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001757 Record.AddStmt(E->getTemporary());
1758 Record.AddDeclRef(E->getExtendingDecl());
David Majnemerdaff3702014-05-01 17:50:17 +00001759 Record.push_back(E->getManglingNumber());
Douglas Gregorfe314812011-06-21 17:03:29 +00001760 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1761}
1762
Richard Smith0f0af192014-11-08 05:07:16 +00001763void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1764 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001765 Record.AddSourceLocation(E->LParenLoc);
1766 Record.AddSourceLocation(E->EllipsisLoc);
1767 Record.AddSourceLocation(E->RParenLoc);
1768 Record.AddStmt(E->SubExprs[0]);
1769 Record.AddStmt(E->SubExprs[1]);
Richard Smith0f0af192014-11-08 05:07:16 +00001770 Record.push_back(E->Opcode);
1771 Code = serialization::EXPR_CXX_FOLD;
1772}
1773
John McCall8d69a212010-11-15 23:31:06 +00001774void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1775 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001776 Record.AddStmt(E->getSourceExpr());
1777 Record.AddSourceLocation(E->getLocation());
Akira Hatanaka797afe32018-03-20 01:47:58 +00001778 Record.push_back(E->isUnique());
John McCall8d69a212010-11-15 23:31:06 +00001779 Code = serialization::EXPR_OPAQUE_VALUE;
1780}
1781
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001782void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1783 VisitExpr(E);
1784 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
Davide Italiano04839a52016-01-30 08:03:54 +00001785 llvm_unreachable("Cannot write TypoExpr nodes");
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001786}
1787
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001788//===----------------------------------------------------------------------===//
Peter Collingbourne41f85462011-02-09 21:07:24 +00001789// CUDA Expressions and Statements.
1790//===----------------------------------------------------------------------===//
1791
1792void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1793 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001794 Record.AddStmt(E->getConfig());
Peter Collingbourne41f85462011-02-09 21:07:24 +00001795 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1796}
1797
1798//===----------------------------------------------------------------------===//
Tanya Lattner55808c12011-06-04 00:47:47 +00001799// OpenCL Expressions and Statements.
1800//===----------------------------------------------------------------------===//
1801void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1802 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001803 Record.AddSourceLocation(E->getBuiltinLoc());
1804 Record.AddSourceLocation(E->getRParenLoc());
1805 Record.AddStmt(E->getSrcExpr());
Tanya Lattner55808c12011-06-04 00:47:47 +00001806 Code = serialization::EXPR_ASTYPE;
1807}
1808
1809//===----------------------------------------------------------------------===//
John McCallfa194042011-07-15 07:00:14 +00001810// Microsoft Expressions and Statements.
1811//===----------------------------------------------------------------------===//
John McCall5e77d762013-04-16 07:28:30 +00001812void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1813 VisitExpr(E);
1814 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001815 Record.AddStmt(E->getBaseExpr());
1816 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1817 Record.AddSourceLocation(E->getMemberLoc());
1818 Record.AddDeclRef(E->getPropertyDecl());
John McCall5e77d762013-04-16 07:28:30 +00001819 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1820}
1821
Alexey Bataevf7630272015-11-25 12:01:00 +00001822void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1823 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001824 Record.AddStmt(E->getBase());
1825 Record.AddStmt(E->getIdx());
1826 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataevf7630272015-11-25 12:01:00 +00001827 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1828}
1829
John McCallfa194042011-07-15 07:00:14 +00001830void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1831 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001832 Record.AddSourceRange(E->getSourceRange());
1833 Record.AddString(E->getUuidStr());
John McCallfa194042011-07-15 07:00:14 +00001834 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001835 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
John McCallfa194042011-07-15 07:00:14 +00001836 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1837 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001838 Record.AddStmt(E->getExprOperand());
John McCallfa194042011-07-15 07:00:14 +00001839 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1840 }
1841}
1842
1843void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1844 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001845 Record.AddSourceLocation(S->getExceptLoc());
1846 Record.AddStmt(S->getFilterExpr());
1847 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001848 Code = serialization::STMT_SEH_EXCEPT;
1849}
1850
1851void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1852 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001853 Record.AddSourceLocation(S->getFinallyLoc());
1854 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001855 Code = serialization::STMT_SEH_FINALLY;
1856}
1857
1858void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1859 VisitStmt(S);
1860 Record.push_back(S->getIsCXXTry());
Richard Smith290d8012016-04-06 17:06:00 +00001861 Record.AddSourceLocation(S->getTryLoc());
1862 Record.AddStmt(S->getTryBlock());
1863 Record.AddStmt(S->getHandler());
John McCallfa194042011-07-15 07:00:14 +00001864 Code = serialization::STMT_SEH_TRY;
1865}
1866
Nico Weber9b982072014-07-07 00:12:30 +00001867void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1868 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001869 Record.AddSourceLocation(S->getLeaveLoc());
Nico Weber9b982072014-07-07 00:12:30 +00001870 Code = serialization::STMT_SEH_LEAVE;
1871}
1872
John McCallfa194042011-07-15 07:00:14 +00001873//===----------------------------------------------------------------------===//
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001874// OpenMP Directives.
1875//===----------------------------------------------------------------------===//
1876void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001877 Record.AddSourceLocation(E->getBeginLoc());
Stephen Kelly1c301dc2018-08-09 21:09:38 +00001878 Record.AddSourceLocation(E->getEndLoc());
Richard Smith290d8012016-04-06 17:06:00 +00001879 OMPClauseWriter ClauseWriter(Record);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001880 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
1881 ClauseWriter.writeClause(E->getClause(i));
1882 }
Alexey Bataev68446b72014-07-18 07:47:19 +00001883 if (E->hasAssociatedStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001884 Record.AddStmt(E->getAssociatedStmt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001885}
1886
Alexander Musman3aaab662014-08-19 11:27:13 +00001887void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
1888 VisitStmt(D);
1889 Record.push_back(D->getNumClauses());
1890 Record.push_back(D->getCollapsedNumber());
1891 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001892 Record.AddStmt(D->getIterationVariable());
1893 Record.AddStmt(D->getLastIteration());
1894 Record.AddStmt(D->getCalcLastIteration());
1895 Record.AddStmt(D->getPreCond());
1896 Record.AddStmt(D->getCond());
1897 Record.AddStmt(D->getInit());
1898 Record.AddStmt(D->getInc());
1899 Record.AddStmt(D->getPreInits());
Alexey Bataev3392d762016-02-16 11:18:12 +00001900 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001901 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
1902 isOpenMPDistributeDirective(D->getDirectiveKind())) {
Richard Smith290d8012016-04-06 17:06:00 +00001903 Record.AddStmt(D->getIsLastIterVariable());
1904 Record.AddStmt(D->getLowerBoundVariable());
1905 Record.AddStmt(D->getUpperBoundVariable());
1906 Record.AddStmt(D->getStrideVariable());
1907 Record.AddStmt(D->getEnsureUpperBound());
1908 Record.AddStmt(D->getNextLowerBound());
1909 Record.AddStmt(D->getNextUpperBound());
Alexey Bataev8b427062016-05-25 12:36:08 +00001910 Record.AddStmt(D->getNumIterations());
Alexander Musmanc6388682014-12-15 07:07:06 +00001911 }
Carlo Bertolli9925f152016-06-27 14:55:37 +00001912 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
1913 Record.AddStmt(D->getPrevLowerBoundVariable());
1914 Record.AddStmt(D->getPrevUpperBoundVariable());
Carlo Bertolli8429d812017-02-17 21:29:13 +00001915 Record.AddStmt(D->getDistInc());
1916 Record.AddStmt(D->getPrevEnsureUpperBound());
Carlo Bertolliffafe102017-04-20 00:39:39 +00001917 Record.AddStmt(D->getCombinedLowerBoundVariable());
1918 Record.AddStmt(D->getCombinedUpperBoundVariable());
1919 Record.AddStmt(D->getCombinedEnsureUpperBound());
1920 Record.AddStmt(D->getCombinedInit());
1921 Record.AddStmt(D->getCombinedCond());
1922 Record.AddStmt(D->getCombinedNextLowerBound());
1923 Record.AddStmt(D->getCombinedNextUpperBound());
Gheorghe-Teodor Berceae9256762018-10-29 15:45:47 +00001924 Record.AddStmt(D->getCombinedDistCond());
1925 Record.AddStmt(D->getCombinedParForInDistCond());
Carlo Bertolli9925f152016-06-27 14:55:37 +00001926 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001927 for (auto I : D->counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001928 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001929 }
Alexey Bataeva8899172015-08-06 12:30:57 +00001930 for (auto I : D->private_counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001931 Record.AddStmt(I);
Alexey Bataeva8899172015-08-06 12:30:57 +00001932 }
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001933 for (auto I : D->inits()) {
Richard Smith290d8012016-04-06 17:06:00 +00001934 Record.AddStmt(I);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001935 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001936 for (auto I : D->updates()) {
Richard Smith290d8012016-04-06 17:06:00 +00001937 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001938 }
1939 for (auto I : D->finals()) {
Richard Smith290d8012016-04-06 17:06:00 +00001940 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001941 }
Alexander Musman3aaab662014-08-19 11:27:13 +00001942}
1943
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001944void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001945 VisitStmt(D);
1946 Record.push_back(D->getNumClauses());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001947 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001948 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001949 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
1950}
1951
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001952void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001953 VisitOMPLoopDirective(D);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001954 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
1955}
1956
Alexey Bataevf29276e2014-06-18 04:14:57 +00001957void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001958 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001959 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevf29276e2014-06-18 04:14:57 +00001960 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
1961}
1962
Alexander Musmanf82886e2014-09-18 05:12:34 +00001963void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
1964 VisitOMPLoopDirective(D);
1965 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
1966}
1967
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001968void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
1969 VisitStmt(D);
1970 Record.push_back(D->getNumClauses());
1971 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001972 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001973 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
1974}
1975
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001976void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
1977 VisitStmt(D);
1978 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001979 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001980 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
1981}
1982
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00001983void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
1984 VisitStmt(D);
1985 Record.push_back(D->getNumClauses());
1986 VisitOMPExecutableDirective(D);
1987 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
1988}
1989
Alexander Musman80c22892014-07-17 08:54:58 +00001990void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
1991 VisitStmt(D);
1992 VisitOMPExecutableDirective(D);
1993 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
1994}
1995
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001996void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
1997 VisitStmt(D);
Alexey Bataev28c75412015-12-15 08:19:24 +00001998 Record.push_back(D->getNumClauses());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001999 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00002000 Record.AddDeclarationNameInfo(D->getDirectiveName());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002001 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2002}
2003
Alexey Bataev4acb8592014-07-07 13:01:15 +00002004void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00002005 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002006 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev4acb8592014-07-07 13:01:15 +00002007 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2008}
2009
Alexander Musmane4e893b2014-09-23 09:33:00 +00002010void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2011 OMPParallelForSimdDirective *D) {
2012 VisitOMPLoopDirective(D);
2013 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2014}
2015
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002016void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2017 OMPParallelSectionsDirective *D) {
2018 VisitStmt(D);
2019 Record.push_back(D->getNumClauses());
2020 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002021 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002022 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2023}
2024
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002025void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2026 VisitStmt(D);
2027 Record.push_back(D->getNumClauses());
2028 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002029 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002030 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2031}
2032
Alexey Bataev0162e452014-07-22 10:10:35 +00002033void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2034 VisitStmt(D);
2035 Record.push_back(D->getNumClauses());
2036 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00002037 Record.AddStmt(D->getX());
2038 Record.AddStmt(D->getV());
2039 Record.AddStmt(D->getExpr());
2040 Record.AddStmt(D->getUpdateExpr());
Alexey Bataevb4505a72015-03-30 05:20:59 +00002041 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
Alexey Bataevb78ca832015-04-01 03:33:17 +00002042 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
Alexey Bataev0162e452014-07-22 10:10:35 +00002043 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2044}
2045
Alexey Bataev0bd520b2014-09-19 08:19:49 +00002046void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2047 VisitStmt(D);
2048 Record.push_back(D->getNumClauses());
2049 VisitOMPExecutableDirective(D);
2050 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2051}
2052
Michael Wong65f367f2015-07-21 13:44:28 +00002053void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2054 VisitStmt(D);
2055 Record.push_back(D->getNumClauses());
2056 VisitOMPExecutableDirective(D);
2057 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2058}
2059
Samuel Antaodf67fc42016-01-19 19:15:56 +00002060void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2061 OMPTargetEnterDataDirective *D) {
2062 VisitStmt(D);
2063 Record.push_back(D->getNumClauses());
2064 VisitOMPExecutableDirective(D);
2065 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2066}
2067
Samuel Antao72590762016-01-19 20:04:50 +00002068void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2069 OMPTargetExitDataDirective *D) {
2070 VisitStmt(D);
2071 Record.push_back(D->getNumClauses());
2072 VisitOMPExecutableDirective(D);
2073 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2074}
2075
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00002076void ASTStmtWriter::VisitOMPTargetParallelDirective(
2077 OMPTargetParallelDirective *D) {
2078 VisitStmt(D);
2079 Record.push_back(D->getNumClauses());
2080 VisitOMPExecutableDirective(D);
2081 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2082}
2083
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00002084void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2085 OMPTargetParallelForDirective *D) {
2086 VisitOMPLoopDirective(D);
2087 Record.push_back(D->hasCancel() ? 1 : 0);
2088 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2089}
2090
Alexey Bataev68446b72014-07-18 07:47:19 +00002091void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2092 VisitStmt(D);
2093 VisitOMPExecutableDirective(D);
2094 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2095}
2096
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00002097void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2098 VisitStmt(D);
2099 VisitOMPExecutableDirective(D);
2100 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2101}
2102
Alexey Bataev2df347a2014-07-18 10:17:07 +00002103void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2104 VisitStmt(D);
2105 VisitOMPExecutableDirective(D);
2106 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2107}
2108
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002109void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2110 VisitStmt(D);
Alexey Bataev169d96a2017-07-18 20:17:46 +00002111 Record.push_back(D->getNumClauses());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002112 VisitOMPExecutableDirective(D);
Alexey Bataev3b1b8952017-07-25 15:53:26 +00002113 Record.AddStmt(D->getReductionRef());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002114 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2115}
2116
Alexey Bataev6125da92014-07-21 11:26:11 +00002117void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2118 VisitStmt(D);
2119 Record.push_back(D->getNumClauses());
2120 VisitOMPExecutableDirective(D);
2121 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2122}
2123
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002124void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2125 VisitStmt(D);
Alexey Bataev346265e2015-09-25 10:37:12 +00002126 Record.push_back(D->getNumClauses());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002127 VisitOMPExecutableDirective(D);
2128 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2129}
2130
Alexey Bataev13314bf2014-10-09 04:18:56 +00002131void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2132 VisitStmt(D);
2133 Record.push_back(D->getNumClauses());
2134 VisitOMPExecutableDirective(D);
2135 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2136}
2137
Alexey Bataev6d4ed052015-07-01 06:57:41 +00002138void ASTStmtWriter::VisitOMPCancellationPointDirective(
2139 OMPCancellationPointDirective *D) {
2140 VisitStmt(D);
2141 VisitOMPExecutableDirective(D);
2142 Record.push_back(D->getCancelRegion());
2143 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2144}
2145
Alexey Bataev80909872015-07-02 11:25:17 +00002146void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2147 VisitStmt(D);
Alexey Bataev87933c72015-09-18 08:07:34 +00002148 Record.push_back(D->getNumClauses());
Alexey Bataev80909872015-07-02 11:25:17 +00002149 VisitOMPExecutableDirective(D);
2150 Record.push_back(D->getCancelRegion());
2151 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2152}
2153
Alexey Bataev49f6e782015-12-01 04:18:41 +00002154void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2155 VisitOMPLoopDirective(D);
2156 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2157}
2158
Alexey Bataev0a6ed842015-12-03 09:40:15 +00002159void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2160 VisitOMPLoopDirective(D);
2161 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2162}
2163
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00002164void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2165 VisitOMPLoopDirective(D);
2166 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2167}
2168
Samuel Antao686c70c2016-05-26 17:30:50 +00002169void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2170 VisitStmt(D);
2171 Record.push_back(D->getNumClauses());
2172 VisitOMPExecutableDirective(D);
2173 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2174}
2175
Carlo Bertolli9925f152016-06-27 14:55:37 +00002176void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2177 OMPDistributeParallelForDirective *D) {
2178 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002179 Record.push_back(D->hasCancel() ? 1 : 0);
Carlo Bertolli9925f152016-06-27 14:55:37 +00002180 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2181}
2182
Kelvin Li4a39add2016-07-05 05:00:15 +00002183void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2184 OMPDistributeParallelForSimdDirective *D) {
2185 VisitOMPLoopDirective(D);
2186 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2187}
2188
Kelvin Li787f3fc2016-07-06 04:45:38 +00002189void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2190 OMPDistributeSimdDirective *D) {
2191 VisitOMPLoopDirective(D);
2192 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2193}
2194
Kelvin Lia579b912016-07-14 02:54:56 +00002195void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2196 OMPTargetParallelForSimdDirective *D) {
2197 VisitOMPLoopDirective(D);
2198 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2199}
2200
Kelvin Li986330c2016-07-20 22:57:10 +00002201void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2202 VisitOMPLoopDirective(D);
2203 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2204}
2205
Kelvin Li02532872016-08-05 14:37:37 +00002206void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2207 OMPTeamsDistributeDirective *D) {
2208 VisitOMPLoopDirective(D);
2209 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2210}
2211
Kelvin Li4e325f72016-10-25 12:50:55 +00002212void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2213 OMPTeamsDistributeSimdDirective *D) {
2214 VisitOMPLoopDirective(D);
2215 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2216}
2217
Kelvin Li579e41c2016-11-30 23:51:03 +00002218void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2219 OMPTeamsDistributeParallelForSimdDirective *D) {
2220 VisitOMPLoopDirective(D);
2221 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2222}
2223
Kelvin Li7ade93f2016-12-09 03:24:30 +00002224void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2225 OMPTeamsDistributeParallelForDirective *D) {
2226 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002227 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li7ade93f2016-12-09 03:24:30 +00002228 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2229}
2230
Kelvin Libf594a52016-12-17 05:48:59 +00002231void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2232 VisitStmt(D);
2233 Record.push_back(D->getNumClauses());
2234 VisitOMPExecutableDirective(D);
2235 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2236}
2237
Kelvin Li83c451e2016-12-25 04:52:54 +00002238void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2239 OMPTargetTeamsDistributeDirective *D) {
2240 VisitOMPLoopDirective(D);
2241 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2242}
2243
Kelvin Li80e8f562016-12-29 22:16:30 +00002244void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2245 OMPTargetTeamsDistributeParallelForDirective *D) {
2246 VisitOMPLoopDirective(D);
Alexey Bataev16e79882017-11-22 21:12:03 +00002247 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li80e8f562016-12-29 22:16:30 +00002248 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2249}
2250
Kelvin Li1851df52017-01-03 05:23:48 +00002251void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2252 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2253 VisitOMPLoopDirective(D);
2254 Code = serialization::
2255 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2256}
2257
Kelvin Lida681182017-01-10 18:08:18 +00002258void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2259 OMPTargetTeamsDistributeSimdDirective *D) {
2260 VisitOMPLoopDirective(D);
2261 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2262}
2263
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002264//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002265// ASTWriter Implementation
Chris Lattner1f551822009-04-27 06:20:01 +00002266//===----------------------------------------------------------------------===//
2267
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002268unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002269 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002270 "SwitchCase recorded twice");
2271 unsigned NextID = SwitchCaseIDs.size();
2272 SwitchCaseIDs[S] = NextID;
2273 return NextID;
2274}
2275
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002276unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002277 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002278 "SwitchCase hasn't been seen yet");
2279 return SwitchCaseIDs[S];
2280}
2281
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002282void ASTWriter::ClearSwitchCaseIDs() {
2283 SwitchCaseIDs.clear();
2284}
2285
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002286/// Write the given substatement or subexpression to the
Chris Lattner1f551822009-04-27 06:20:01 +00002287/// bitstream.
Richard Smithf50422a2016-04-06 20:12:34 +00002288void ASTWriter::WriteSubStmt(Stmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00002289 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002290 ASTStmtWriter Writer(*this, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002291 ++NumStatements;
Fangrui Song6907ce22018-07-30 19:24:48 +00002292
Chris Lattner1f551822009-04-27 06:20:01 +00002293 if (!S) {
Sebastian Redl539c5062010-08-18 23:57:32 +00002294 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002295 return;
2296 }
Mike Stump11289f42009-09-09 15:08:12 +00002297
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002298 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2299 if (I != SubStmtEntries.end()) {
2300 Record.push_back(I->second);
2301 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2302 return;
2303 }
2304
2305#ifndef NDEBUG
2306 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2307
2308 struct ParentStmtInserterRAII {
2309 Stmt *S;
2310 llvm::DenseSet<Stmt *> &ParentStmts;
2311
2312 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2313 : S(S), ParentStmts(ParentStmts) {
2314 ParentStmts.insert(S);
2315 }
2316 ~ParentStmtInserterRAII() {
2317 ParentStmts.erase(S);
2318 }
2319 };
2320
2321 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2322#endif
2323
Chris Lattner1f551822009-04-27 06:20:01 +00002324 Writer.Visit(S);
Fangrui Song6907ce22018-07-30 19:24:48 +00002325
Richard Smithb41ddae2016-04-06 20:57:53 +00002326 uint64_t Offset = Writer.Emit();
2327 SubStmtEntries[S] = Offset;
Chris Lattner1f551822009-04-27 06:20:01 +00002328}
2329
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002330/// Flush all of the statements that have been added to the
Chris Lattner1f551822009-04-27 06:20:01 +00002331/// queue via AddStmt().
Richard Smith290d8012016-04-06 17:06:00 +00002332void ASTRecordWriter::FlushStmts() {
Daniel Dunbara5acaa32012-02-29 02:39:13 +00002333 // We expect to be the only consumer of the two temporary statement maps,
2334 // assert that they are empty.
Richard Smith290d8012016-04-06 17:06:00 +00002335 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2336 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002337
Chris Lattner1f551822009-04-27 06:20:01 +00002338 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002339 Writer->WriteSubStmt(StmtsToEmit[I]);
Fangrui Song6907ce22018-07-30 19:24:48 +00002340
Richard Smith290d8012016-04-06 17:06:00 +00002341 assert(N == StmtsToEmit.size() && "record modified while being written!");
Mike Stump11289f42009-09-09 15:08:12 +00002342
Chris Lattner1f551822009-04-27 06:20:01 +00002343 // Note that we are at the end of a full expression. Any
2344 // expression records that follow this one are part of a different
2345 // expression.
Richard Smith290d8012016-04-06 17:06:00 +00002346 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002347
Richard Smith290d8012016-04-06 17:06:00 +00002348 Writer->SubStmtEntries.clear();
2349 Writer->ParentStmts.clear();
2350 }
2351
2352 StmtsToEmit.clear();
2353}
2354
2355void ASTRecordWriter::FlushSubStmts() {
2356 // For a nested statement, write out the substatements in reverse order (so
2357 // that a simple stack machine can be used when loading), and don't emit a
2358 // STMT_STOP after each one.
2359 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002360 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
Richard Smith290d8012016-04-06 17:06:00 +00002361 assert(N == StmtsToEmit.size() && "record modified while being written!");
Chris Lattner1f551822009-04-27 06:20:01 +00002362 }
Mike Stump11289f42009-09-09 15:08:12 +00002363
Chris Lattner1f551822009-04-27 06:20:01 +00002364 StmtsToEmit.clear();
Chris Lattner1f551822009-04-27 06:20:01 +00002365}