blob: 4f7b492d0248b99d53d727a660d0c3dc8c947adc [file] [log] [blame]
Sebastian Redld6522cf2010-08-18 23:56:31 +00001//===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
Chris Lattner1f551822009-04-27 06:20:01 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner1f551822009-04-27 06:20:01 +00006//
7//===----------------------------------------------------------------------===//
James Dennettddd36ff2013-08-09 23:08:25 +00008///
9/// \file
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010/// Implements serialization for Statements and Expressions.
James Dennettddd36ff2013-08-09 23:08:25 +000011///
Chris Lattner1f551822009-04-27 06:20:01 +000012//===----------------------------------------------------------------------===//
13
Sebastian Redl1914c6f2010-08-18 23:56:37 +000014#include "clang/Serialization/ASTWriter.h"
Benjamin Kramer4ab984e2012-07-04 20:19:54 +000015#include "clang/AST/ASTContext.h"
Douglas Gregor5d3507d2009-09-09 23:08:42 +000016#include "clang/AST/DeclCXX.h"
Chris Lattner1f551822009-04-27 06:20:01 +000017#include "clang/AST/DeclObjC.h"
Douglas Gregorcdbc5392011-01-15 01:15:58 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner1f551822009-04-27 06:20:01 +000019#include "clang/AST/StmtVisitor.h"
John McCallf413f5e2013-05-03 00:10:13 +000020#include "clang/Lex/Token.h"
Chris Lattner1f551822009-04-27 06:20:01 +000021#include "llvm/Bitcode/BitstreamWriter.h"
22using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// Statement/expression serialization
26//===----------------------------------------------------------------------===//
27
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +000028namespace clang {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000029
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000030 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
Sebastian Redl55c0ad52010-08-18 23:56:21 +000031 ASTWriter &Writer;
Richard Smith290d8012016-04-06 17:06:00 +000032 ASTRecordWriter Record;
Chris Lattner1f551822009-04-27 06:20:01 +000033
Sebastian Redl539c5062010-08-18 23:57:32 +000034 serialization::StmtCode Code;
Douglas Gregor03412ba2011-06-03 02:27:19 +000035 unsigned AbbrevToUse;
Chris Lattner1f551822009-04-27 06:20:01 +000036
Richard Smith290d8012016-04-06 17:06:00 +000037 public:
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000038 ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
Richard Smith290d8012016-04-06 17:06:00 +000039 : Writer(Writer), Record(Writer, Record),
40 Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
41
42 ASTStmtWriter(const ASTStmtWriter&) = delete;
43
Richard Smithf50422a2016-04-06 20:12:34 +000044 uint64_t Emit() {
Richard Smith290d8012016-04-06 17:06:00 +000045 assert(Code != serialization::STMT_NULL_PTR &&
46 "unhandled sub-statement writing AST file");
47 return Record.EmitStmt(Code, AbbrevToUse);
48 }
Abramo Bagnara7945c982012-01-27 09:46:47 +000049
James Y Knighte7d82282015-12-29 18:15:14 +000050 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo,
51 const TemplateArgumentLoc *Args);
Chris Lattner1f551822009-04-27 06:20:01 +000052
53 void VisitStmt(Stmt *S);
John McCallfa194042011-07-15 07:00:14 +000054#define STMT(Type, Base) \
55 void Visit##Type(Type *);
56#include "clang/AST/StmtNodes.inc"
Chris Lattner1f551822009-04-27 06:20:01 +000057 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +000058}
Chris Lattner1f551822009-04-27 06:20:01 +000059
James Y Knighte7d82282015-12-29 18:15:14 +000060void ASTStmtWriter::AddTemplateKWAndArgsInfo(
61 const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) {
Richard Smith290d8012016-04-06 17:06:00 +000062 Record.AddSourceLocation(ArgInfo.TemplateKWLoc);
63 Record.AddSourceLocation(ArgInfo.LAngleLoc);
64 Record.AddSourceLocation(ArgInfo.RAngleLoc);
James Y Knighte7d82282015-12-29 18:15:14 +000065 for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +000066 Record.AddTemplateArgumentLoc(Args[i]);
Argyrios Kyrtzidisb5288de2010-06-28 09:31:48 +000067}
68
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000069void ASTStmtWriter::VisitStmt(Stmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000070}
71
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000072void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000073 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +000074 Record.AddSourceLocation(S->getSemiLoc());
Bruno Ricci41d11c02018-10-27 18:43:27 +000075 Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro);
Sebastian Redl539c5062010-08-18 23:57:32 +000076 Code = serialization::STMT_NULL;
Chris Lattner1f551822009-04-27 06:20:01 +000077}
78
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000079void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000080 VisitStmt(S);
81 Record.push_back(S->size());
Aaron Ballmanc7e4e212014-03-17 14:19:37 +000082 for (auto *CS : S->body())
Richard Smith290d8012016-04-06 17:06:00 +000083 Record.AddStmt(CS);
84 Record.AddSourceLocation(S->getLBracLoc());
85 Record.AddSourceLocation(S->getRBracLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +000086 Code = serialization::STMT_COMPOUND;
Chris Lattner1f551822009-04-27 06:20:01 +000087}
88
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000089void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000090 VisitStmt(S);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +000091 Record.push_back(Writer.getSwitchCaseID(S));
Richard Smith290d8012016-04-06 17:06:00 +000092 Record.AddSourceLocation(S->getKeywordLoc());
93 Record.AddSourceLocation(S->getColonLoc());
Chris Lattner1f551822009-04-27 06:20:01 +000094}
95
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000096void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +000097 VisitSwitchCase(S);
Bruno Ricci5b30571752018-10-28 12:30:53 +000098 Record.push_back(S->caseStmtIsGNURange());
Richard Smith290d8012016-04-06 17:06:00 +000099 Record.AddStmt(S->getLHS());
Richard Smith290d8012016-04-06 17:06:00 +0000100 Record.AddStmt(S->getSubStmt());
Bruno Ricci5b30571752018-10-28 12:30:53 +0000101 if (S->caseStmtIsGNURange()) {
102 Record.AddStmt(S->getRHS());
103 Record.AddSourceLocation(S->getEllipsisLoc());
104 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000105 Code = serialization::STMT_CASE;
Chris Lattner1f551822009-04-27 06:20:01 +0000106}
107
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000108void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000109 VisitSwitchCase(S);
Richard Smith290d8012016-04-06 17:06:00 +0000110 Record.AddStmt(S->getSubStmt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000111 Code = serialization::STMT_DEFAULT;
Chris Lattner1f551822009-04-27 06:20:01 +0000112}
113
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000114void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000115 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000116 Record.AddDeclRef(S->getDecl());
117 Record.AddStmt(S->getSubStmt());
118 Record.AddSourceLocation(S->getIdentLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000119 Code = serialization::STMT_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000120}
121
Richard Smithc202b282012-04-14 00:33:13 +0000122void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
123 VisitStmt(S);
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000124 Record.push_back(S->getAttrs().size());
Richard Smith290d8012016-04-06 17:06:00 +0000125 Record.AddAttributes(S->getAttrs());
126 Record.AddStmt(S->getSubStmt());
127 Record.AddSourceLocation(S->getAttrLoc());
Richard Smithc202b282012-04-14 00:33:13 +0000128 Code = serialization::STMT_ATTRIBUTED;
129}
130
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000131void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000132 VisitStmt(S);
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000133
134 bool HasElse = S->getElse() != nullptr;
135 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
136 bool HasInit = S->getInit() != nullptr;
137
Richard Smithb130fe72016-06-23 19:16:49 +0000138 Record.push_back(S->isConstexpr());
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000139 Record.push_back(HasElse);
140 Record.push_back(HasVar);
141 Record.push_back(HasInit);
142
Richard Smith290d8012016-04-06 17:06:00 +0000143 Record.AddStmt(S->getCond());
144 Record.AddStmt(S->getThen());
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000145 if (HasElse)
146 Record.AddStmt(S->getElse());
147 if (HasVar)
148 Record.AddDeclRef(S->getConditionVariable());
149 if (HasInit)
150 Record.AddStmt(S->getInit());
151
Richard Smith290d8012016-04-06 17:06:00 +0000152 Record.AddSourceLocation(S->getIfLoc());
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000153 if (HasElse)
154 Record.AddSourceLocation(S->getElseLoc());
155
Sebastian Redl539c5062010-08-18 23:57:32 +0000156 Code = serialization::STMT_IF;
Chris Lattner1f551822009-04-27 06:20:01 +0000157}
158
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000159void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000160 VisitStmt(S);
Bruno Riccie2806f82018-10-29 16:12:37 +0000161
162 bool HasInit = S->getInit() != nullptr;
163 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
164 Record.push_back(HasInit);
165 Record.push_back(HasVar);
166 Record.push_back(S->isAllEnumCasesCovered());
167
Richard Smith290d8012016-04-06 17:06:00 +0000168 Record.AddStmt(S->getCond());
169 Record.AddStmt(S->getBody());
Bruno Riccie2806f82018-10-29 16:12:37 +0000170 if (HasInit)
171 Record.AddStmt(S->getInit());
172 if (HasVar)
173 Record.AddDeclRef(S->getConditionVariable());
174
Richard Smith290d8012016-04-06 17:06:00 +0000175 Record.AddSourceLocation(S->getSwitchLoc());
Bruno Riccie2806f82018-10-29 16:12:37 +0000176
Mike Stump11289f42009-09-09 15:08:12 +0000177 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
Chris Lattner1f551822009-04-27 06:20:01 +0000178 SC = SC->getNextSwitchCase())
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000179 Record.push_back(Writer.RecordSwitchCaseID(SC));
Sebastian Redl539c5062010-08-18 23:57:32 +0000180 Code = serialization::STMT_SWITCH;
Chris Lattner1f551822009-04-27 06:20:01 +0000181}
182
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000183void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000184 VisitStmt(S);
Bruno Riccibacf7512018-10-30 13:42:41 +0000185
186 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
187 Record.push_back(HasVar);
188
Richard Smith290d8012016-04-06 17:06:00 +0000189 Record.AddStmt(S->getCond());
190 Record.AddStmt(S->getBody());
Bruno Riccibacf7512018-10-30 13:42:41 +0000191 if (HasVar)
192 Record.AddDeclRef(S->getConditionVariable());
193
Richard Smith290d8012016-04-06 17:06:00 +0000194 Record.AddSourceLocation(S->getWhileLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000195 Code = serialization::STMT_WHILE;
Chris Lattner1f551822009-04-27 06:20:01 +0000196}
197
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000198void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000199 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000200 Record.AddStmt(S->getCond());
201 Record.AddStmt(S->getBody());
202 Record.AddSourceLocation(S->getDoLoc());
203 Record.AddSourceLocation(S->getWhileLoc());
204 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000205 Code = serialization::STMT_DO;
Chris Lattner1f551822009-04-27 06:20:01 +0000206}
207
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000208void ASTStmtWriter::VisitForStmt(ForStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000209 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000210 Record.AddStmt(S->getInit());
211 Record.AddStmt(S->getCond());
212 Record.AddDeclRef(S->getConditionVariable());
213 Record.AddStmt(S->getInc());
214 Record.AddStmt(S->getBody());
215 Record.AddSourceLocation(S->getForLoc());
216 Record.AddSourceLocation(S->getLParenLoc());
217 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000218 Code = serialization::STMT_FOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000219}
220
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000221void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000222 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000223 Record.AddDeclRef(S->getLabel());
224 Record.AddSourceLocation(S->getGotoLoc());
225 Record.AddSourceLocation(S->getLabelLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000226 Code = serialization::STMT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000227}
228
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000229void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000230 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000231 Record.AddSourceLocation(S->getGotoLoc());
232 Record.AddSourceLocation(S->getStarLoc());
233 Record.AddStmt(S->getTarget());
Sebastian Redl539c5062010-08-18 23:57:32 +0000234 Code = serialization::STMT_INDIRECT_GOTO;
Chris Lattner1f551822009-04-27 06:20:01 +0000235}
236
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000237void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000238 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000239 Record.AddSourceLocation(S->getContinueLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000240 Code = serialization::STMT_CONTINUE;
Chris Lattner1f551822009-04-27 06:20:01 +0000241}
242
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000243void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000244 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000245 Record.AddSourceLocation(S->getBreakLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000246 Code = serialization::STMT_BREAK;
Chris Lattner1f551822009-04-27 06:20:01 +0000247}
248
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000249void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000250 VisitStmt(S);
Bruno Ricci023b1d12018-10-30 14:40:49 +0000251
252 bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr;
253 Record.push_back(HasNRVOCandidate);
254
Richard Smith290d8012016-04-06 17:06:00 +0000255 Record.AddStmt(S->getRetValue());
Bruno Ricci023b1d12018-10-30 14:40:49 +0000256 if (HasNRVOCandidate)
257 Record.AddDeclRef(S->getNRVOCandidate());
258
Richard Smith290d8012016-04-06 17:06:00 +0000259 Record.AddSourceLocation(S->getReturnLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000260 Code = serialization::STMT_RETURN;
Chris Lattner1f551822009-04-27 06:20:01 +0000261}
262
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000263void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000264 VisitStmt(S);
Stephen Kellya6e43582018-08-09 21:05:56 +0000265 Record.AddSourceLocation(S->getBeginLoc());
Richard Smith290d8012016-04-06 17:06:00 +0000266 Record.AddSourceLocation(S->getEndLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000267 DeclGroupRef DG = S->getDeclGroup();
268 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
Richard Smith290d8012016-04-06 17:06:00 +0000269 Record.AddDeclRef(*D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000270 Code = serialization::STMT_DECL;
Chris Lattner1f551822009-04-27 06:20:01 +0000271}
272
John McCallf413f5e2013-05-03 00:10:13 +0000273void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +0000274 VisitStmt(S);
275 Record.push_back(S->getNumOutputs());
276 Record.push_back(S->getNumInputs());
277 Record.push_back(S->getNumClobbers());
Richard Smith290d8012016-04-06 17:06:00 +0000278 Record.AddSourceLocation(S->getAsmLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000279 Record.push_back(S->isVolatile());
280 Record.push_back(S->isSimple());
John McCallf413f5e2013-05-03 00:10:13 +0000281}
282
283void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
284 VisitAsmStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000285 Record.AddSourceLocation(S->getRParenLoc());
286 Record.AddStmt(S->getAsmString());
Chris Lattner1f551822009-04-27 06:20:01 +0000287
288 // Outputs
Fangrui Song6907ce22018-07-30 19:24:48 +0000289 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000290 Record.AddIdentifierRef(S->getOutputIdentifier(I));
291 Record.AddStmt(S->getOutputConstraintLiteral(I));
292 Record.AddStmt(S->getOutputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000293 }
294
295 // Inputs
296 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000297 Record.AddIdentifierRef(S->getInputIdentifier(I));
298 Record.AddStmt(S->getInputConstraintLiteral(I));
299 Record.AddStmt(S->getInputExpr(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000300 }
301
302 // Clobbers
303 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000304 Record.AddStmt(S->getClobberStringLiteral(I));
Chris Lattner1f551822009-04-27 06:20:01 +0000305
Chad Rosierde70e0e2012-08-25 00:11:56 +0000306 Code = serialization::STMT_GCCASM;
Chris Lattner1f551822009-04-27 06:20:01 +0000307}
308
Chad Rosier32503022012-06-11 20:47:18 +0000309void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
John McCallf413f5e2013-05-03 00:10:13 +0000310 VisitAsmStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +0000311 Record.AddSourceLocation(S->getLBraceLoc());
312 Record.AddSourceLocation(S->getEndLoc());
John McCallf413f5e2013-05-03 00:10:13 +0000313 Record.push_back(S->getNumAsmToks());
Richard Smith290d8012016-04-06 17:06:00 +0000314 Record.AddString(S->getAsmString());
John McCallf413f5e2013-05-03 00:10:13 +0000315
316 // Tokens
317 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000318 // FIXME: Move this to ASTRecordWriter?
319 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
John McCallf413f5e2013-05-03 00:10:13 +0000320 }
321
322 // Clobbers
323 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000324 Record.AddString(S->getClobber(I));
John McCallf413f5e2013-05-03 00:10:13 +0000325 }
326
327 // Outputs
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000328 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000329 Record.AddStmt(S->getOutputExpr(I));
330 Record.AddString(S->getOutputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000331 }
332
333 // Inputs
334 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
Richard Smith290d8012016-04-06 17:06:00 +0000335 Record.AddStmt(S->getInputExpr(I));
336 Record.AddString(S->getInputConstraint(I));
John McCallf413f5e2013-05-03 00:10:13 +0000337 }
Chad Rosiere30d4992012-08-24 23:51:02 +0000338
339 Code = serialization::STMT_MSASM;
Chad Rosier32503022012-06-11 20:47:18 +0000340}
341
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000342void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
343 VisitStmt(CoroStmt);
344 Record.push_back(CoroStmt->getParamMoves().size());
345 for (Stmt *S : CoroStmt->children())
346 Record.AddStmt(S);
347 Code = serialization::STMT_COROUTINE_BODY;
Richard Smith9f690bd2015-10-27 06:02:45 +0000348}
349
350void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000351 VisitStmt(S);
352 Record.AddSourceLocation(S->getKeywordLoc());
353 Record.AddStmt(S->getOperand());
354 Record.AddStmt(S->getPromiseCall());
355 Record.push_back(S->isImplicit());
356 Code = serialization::STMT_CORETURN;
Richard Smith9f690bd2015-10-27 06:02:45 +0000357}
358
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000359void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
360 VisitExpr(E);
361 Record.AddSourceLocation(E->getKeywordLoc());
362 for (Stmt *S : E->children())
363 Record.AddStmt(S);
364 Record.AddStmt(E->getOpaqueValue());
Richard Smith9f690bd2015-10-27 06:02:45 +0000365}
366
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000367void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
368 VisitCoroutineSuspendExpr(E);
369 Record.push_back(E->isImplicit());
370 Code = serialization::EXPR_COAWAIT;
Eric Fiselier20f25cb2017-03-06 23:38:15 +0000371}
372
Gor Nishanovf5ecb5e2017-07-25 18:01:49 +0000373void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
374 VisitCoroutineSuspendExpr(E);
375 Code = serialization::EXPR_COYIELD;
376}
377
378void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
379 VisitExpr(E);
380 Record.AddSourceLocation(E->getKeywordLoc());
381 for (Stmt *S : E->children())
382 Record.AddStmt(S);
383 Code = serialization::EXPR_DEPENDENT_COAWAIT;
Richard Smith9f690bd2015-10-27 06:02:45 +0000384}
385
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000386void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
387 VisitStmt(S);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000388 // NumCaptures
389 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000390
Wei Pan17fbf6e2013-05-04 03:59:06 +0000391 // CapturedDecl and captured region kind
Richard Smith290d8012016-04-06 17:06:00 +0000392 Record.AddDeclRef(S->getCapturedDecl());
Wei Pan17fbf6e2013-05-04 03:59:06 +0000393 Record.push_back(S->getCapturedRegionKind());
394
Richard Smith290d8012016-04-06 17:06:00 +0000395 Record.AddDeclRef(S->getCapturedRecordDecl());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000396
397 // Capture inits
Aaron Ballmanba0238f2014-03-14 19:41:04 +0000398 for (auto *I : S->capture_inits())
Richard Smith290d8012016-04-06 17:06:00 +0000399 Record.AddStmt(I);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000400
401 // Body
Richard Smith290d8012016-04-06 17:06:00 +0000402 Record.AddStmt(S->getCapturedStmt());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000403
404 // Captures
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000405 for (const auto &I : S->captures()) {
Alexey Bataev330de032014-10-29 12:21:55 +0000406 if (I.capturesThis() || I.capturesVariableArrayType())
Richard Smith290d8012016-04-06 17:06:00 +0000407 Record.AddDeclRef(nullptr);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000408 else
Richard Smith290d8012016-04-06 17:06:00 +0000409 Record.AddDeclRef(I.getCapturedVar());
Aaron Ballmanc656303a2014-03-14 18:08:33 +0000410 Record.push_back(I.getCaptureKind());
Richard Smith290d8012016-04-06 17:06:00 +0000411 Record.AddSourceLocation(I.getLocation());
Ben Langmuirce914fc2013-05-03 19:20:19 +0000412 }
413
414 Code = serialization::STMT_CAPTURED;
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000415}
416
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000417void ASTStmtWriter::VisitExpr(Expr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000418 VisitStmt(E);
Richard Smith290d8012016-04-06 17:06:00 +0000419 Record.AddTypeRef(E->getType());
Chris Lattner1f551822009-04-27 06:20:01 +0000420 Record.push_back(E->isTypeDependent());
421 Record.push_back(E->isValueDependent());
Douglas Gregor678d76c2011-07-01 01:22:09 +0000422 Record.push_back(E->isInstantiationDependent());
Douglas Gregor506bd562010-12-13 22:49:22 +0000423 Record.push_back(E->containsUnexpandedParameterPack());
John McCall7decc9e2010-11-18 06:31:45 +0000424 Record.push_back(E->getValueKind());
425 Record.push_back(E->getObjectKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000426}
427
Bill Wendling7c44da22018-10-31 03:48:47 +0000428void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
429 VisitExpr(E);
430 Record.AddStmt(E->getSubExpr());
431 Code = serialization::EXPR_CONSTANT;
432}
433
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000434void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000435 VisitExpr(E);
Bruno Ricci17ff0262018-10-27 19:21:19 +0000436
437 bool HasFunctionName = E->getFunctionName() != nullptr;
438 Record.push_back(HasFunctionName);
439 Record.push_back(E->getIdentKind()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000440 Record.AddSourceLocation(E->getLocation());
Bruno Ricci17ff0262018-10-27 19:21:19 +0000441 if (HasFunctionName)
442 Record.AddStmt(E->getFunctionName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000443 Code = serialization::EXPR_PREDEFINED;
Chris Lattner1f551822009-04-27 06:20:01 +0000444}
445
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000446void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000447 VisitExpr(E);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000448
449 Record.push_back(E->hasQualifier());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000450 Record.push_back(E->getDecl() != E->getFoundDecl());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000451 Record.push_back(E->hasTemplateKWAndArgsInfo());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000452 Record.push_back(E->hadMultipleCandidates());
Alexey Bataev19acc3d2015-01-12 10:17:46 +0000453 Record.push_back(E->refersToEnclosingVariableOrCapture());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000454
Abramo Bagnara7945c982012-01-27 09:46:47 +0000455 if (E->hasTemplateKWAndArgsInfo()) {
Douglas Gregor87866ce2011-02-04 12:01:24 +0000456 unsigned NumTemplateArgs = E->getNumTemplateArgs();
457 Record.push_back(NumTemplateArgs);
Douglas Gregor87866ce2011-02-04 12:01:24 +0000458 }
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000459
Douglas Gregor03412ba2011-06-03 02:27:19 +0000460 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
461
Abramo Bagnara7945c982012-01-27 09:46:47 +0000462 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000463 (E->getDecl() == E->getFoundDecl()) &&
464 nk == DeclarationName::Identifier) {
465 AbbrevToUse = Writer.getDeclRefExprAbbrev();
466 }
467
Anders Carlsson80756f62011-03-06 18:19:42 +0000468 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000469 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Anders Carlsson80756f62011-03-06 18:19:42 +0000470
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000471 if (E->getDecl() != E->getFoundDecl())
Richard Smith290d8012016-04-06 17:06:00 +0000472 Record.AddDeclRef(E->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +0000473
Abramo Bagnara7945c982012-01-27 09:46:47 +0000474 if (E->hasTemplateKWAndArgsInfo())
James Y Knighte7d82282015-12-29 18:15:14 +0000475 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
476 E->getTrailingObjects<TemplateArgumentLoc>());
Anders Carlsson80756f62011-03-06 18:19:42 +0000477
Richard Smith290d8012016-04-06 17:06:00 +0000478 Record.AddDeclRef(E->getDecl());
479 Record.AddSourceLocation(E->getLocation());
480 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
Sebastian Redl539c5062010-08-18 23:57:32 +0000481 Code = serialization::EXPR_DECL_REF;
Chris Lattner1f551822009-04-27 06:20:01 +0000482}
483
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000484void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000485 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000486 Record.AddSourceLocation(E->getLocation());
487 Record.AddAPInt(E->getValue());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000488
489 if (E->getValue().getBitWidth() == 32) {
490 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
491 }
492
Sebastian Redl539c5062010-08-18 23:57:32 +0000493 Code = serialization::EXPR_INTEGER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000494}
495
Leonard Chandb01c3a2018-06-20 17:19:40 +0000496void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
497 VisitExpr(E);
498 Record.AddSourceLocation(E->getLocation());
499 Record.AddAPInt(E->getValue());
500 Code = serialization::EXPR_INTEGER_LITERAL;
501}
502
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000503void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000504 VisitExpr(E);
Tim Northover178723a2013-01-22 09:46:51 +0000505 Record.push_back(E->getRawSemantics());
Chris Lattner1f551822009-04-27 06:20:01 +0000506 Record.push_back(E->isExact());
Richard Smith290d8012016-04-06 17:06:00 +0000507 Record.AddAPFloat(E->getValue());
508 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000509 Code = serialization::EXPR_FLOATING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000510}
511
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000512void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000513 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000514 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000515 Code = serialization::EXPR_IMAGINARY_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000516}
517
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000518void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000519 VisitExpr(E);
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000520
521 // Store the various bits of data of StringLiteral.
Chris Lattner1f551822009-04-27 06:20:01 +0000522 Record.push_back(E->getNumConcatenated());
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000523 Record.push_back(E->getLength());
524 Record.push_back(E->getCharByteWidth());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000525 Record.push_back(E->getKind());
Anders Carlsson75245402011-04-14 00:40:03 +0000526 Record.push_back(E->isPascal());
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000527
528 // Store the trailing array of SourceLocation.
Chris Lattner1f551822009-04-27 06:20:01 +0000529 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000530 Record.AddSourceLocation(E->getStrTokenLoc(I));
Bruno Riccib94ad1e2018-11-15 17:31:16 +0000531
532 // Store the trailing array of char holding the string data.
533 StringRef StrData = E->getBytes();
534 for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
535 Record.push_back(StrData[I]);
536
Sebastian Redl539c5062010-08-18 23:57:32 +0000537 Code = serialization::EXPR_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000538}
539
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000540void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000541 VisitExpr(E);
542 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +0000543 Record.AddSourceLocation(E->getLocation());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000544 Record.push_back(E->getKind());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000545
546 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
547
Sebastian Redl539c5062010-08-18 23:57:32 +0000548 Code = serialization::EXPR_CHARACTER_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000549}
550
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000551void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000552 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000553 Record.AddSourceLocation(E->getLParen());
554 Record.AddSourceLocation(E->getRParen());
555 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +0000556 Code = serialization::EXPR_PAREN;
Chris Lattner1f551822009-04-27 06:20:01 +0000557}
558
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000559void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000560 VisitExpr(E);
Bruno Riccif49e1ca2018-11-20 16:20:40 +0000561 Record.push_back(E->getNumExprs());
562 for (auto *SubStmt : E->exprs())
563 Record.AddStmt(SubStmt);
564 Record.AddSourceLocation(E->getLParenLoc());
565 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000566 Code = serialization::EXPR_PAREN_LIST;
Argyrios Kyrtzidisf9f47c82010-06-30 08:49:18 +0000567}
568
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000569void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000570 VisitExpr(E);
Malcolm Parsonsfab36802018-04-16 08:31:08 +0000571 Record.AddStmt(E->getSubExpr());
572 Record.push_back(E->getOpcode()); // FIXME: stable encoding
573 Record.AddSourceLocation(E->getOperatorLoc());
574 Record.push_back(E->canOverflow());
575 Code = serialization::EXPR_UNARY_OPERATOR;
576}
577
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000578void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000579 VisitExpr(E);
580 Record.push_back(E->getNumComponents());
581 Record.push_back(E->getNumExpressions());
Richard Smith290d8012016-04-06 17:06:00 +0000582 Record.AddSourceLocation(E->getOperatorLoc());
583 Record.AddSourceLocation(E->getRParenLoc());
584 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Douglas Gregor882211c2010-04-28 22:16:22 +0000585 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +0000586 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +0000587 Record.push_back(ON.getKind()); // FIXME: Stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000588 Record.AddSourceLocation(ON.getSourceRange().getBegin());
589 Record.AddSourceLocation(ON.getSourceRange().getEnd());
Douglas Gregor882211c2010-04-28 22:16:22 +0000590 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +0000591 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +0000592 Record.push_back(ON.getArrayExprIndex());
593 break;
James Y Knight7281c352015-12-29 22:31:18 +0000594
595 case OffsetOfNode::Field:
Richard Smith290d8012016-04-06 17:06:00 +0000596 Record.AddDeclRef(ON.getField());
Douglas Gregor882211c2010-04-28 22:16:22 +0000597 break;
James Y Knight7281c352015-12-29 22:31:18 +0000598
599 case OffsetOfNode::Identifier:
Richard Smith290d8012016-04-06 17:06:00 +0000600 Record.AddIdentifierRef(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +0000601 break;
James Y Knight7281c352015-12-29 22:31:18 +0000602
603 case OffsetOfNode::Base:
Richard Smith290d8012016-04-06 17:06:00 +0000604 Record.AddCXXBaseSpecifier(*ON.getBase());
Douglas Gregord1702062010-04-29 00:18:15 +0000605 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000606 }
607 }
608 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000609 Record.AddStmt(E->getIndexExpr(I));
Sebastian Redl539c5062010-08-18 23:57:32 +0000610 Code = serialization::EXPR_OFFSETOF;
Douglas Gregor882211c2010-04-28 22:16:22 +0000611}
612
Peter Collingbournee190dee2011-03-11 19:24:49 +0000613void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000614 VisitExpr(E);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000615 Record.push_back(E->getKind());
Chris Lattner1f551822009-04-27 06:20:01 +0000616 if (E->isArgumentType())
Richard Smith290d8012016-04-06 17:06:00 +0000617 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
Chris Lattner1f551822009-04-27 06:20:01 +0000618 else {
619 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +0000620 Record.AddStmt(E->getArgumentExpr());
Chris Lattner1f551822009-04-27 06:20:01 +0000621 }
Richard Smith290d8012016-04-06 17:06:00 +0000622 Record.AddSourceLocation(E->getOperatorLoc());
623 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000624 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
Chris Lattner1f551822009-04-27 06:20:01 +0000625}
626
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000627void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000628 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000629 Record.AddStmt(E->getLHS());
630 Record.AddStmt(E->getRHS());
631 Record.AddSourceLocation(E->getRBracketLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000632 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
Chris Lattner1f551822009-04-27 06:20:01 +0000633}
634
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000635void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
636 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000637 Record.AddStmt(E->getBase());
638 Record.AddStmt(E->getLowerBound());
639 Record.AddStmt(E->getLength());
640 Record.AddSourceLocation(E->getColonLoc());
641 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000642 Code = serialization::EXPR_OMP_ARRAY_SECTION;
643}
644
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000645void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000646 VisitExpr(E);
647 Record.push_back(E->getNumArgs());
Richard Smith290d8012016-04-06 17:06:00 +0000648 Record.AddSourceLocation(E->getRParenLoc());
649 Record.AddStmt(E->getCallee());
Chris Lattner1f551822009-04-27 06:20:01 +0000650 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
651 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +0000652 Record.AddStmt(*Arg);
Eric Fiselier5cdc2cd2018-12-12 21:50:55 +0000653 Record.push_back(static_cast<unsigned>(E->getADLCallKind()));
Sebastian Redl539c5062010-08-18 23:57:32 +0000654 Code = serialization::EXPR_CALL;
Chris Lattner1f551822009-04-27 06:20:01 +0000655}
656
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000657void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000658 // Don't call VisitExpr, we'll write everything here.
659
660 Record.push_back(E->hasQualifier());
Douglas Gregorea972d32011-02-28 21:54:11 +0000661 if (E->hasQualifier())
Richard Smith290d8012016-04-06 17:06:00 +0000662 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000663
Bruno Ricci4c742532018-11-15 13:56:22 +0000664 Record.push_back(E->hasTemplateKWAndArgsInfo());
665 if (E->hasTemplateKWAndArgsInfo()) {
Richard Smith290d8012016-04-06 17:06:00 +0000666 Record.AddSourceLocation(E->getTemplateKeywordLoc());
Douglas Gregor87866ce2011-02-04 12:01:24 +0000667 unsigned NumTemplateArgs = E->getNumTemplateArgs();
668 Record.push_back(NumTemplateArgs);
Richard Smith290d8012016-04-06 17:06:00 +0000669 Record.AddSourceLocation(E->getLAngleLoc());
670 Record.AddSourceLocation(E->getRAngleLoc());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000671 for (unsigned i=0; i != NumTemplateArgs; ++i)
Richard Smith290d8012016-04-06 17:06:00 +0000672 Record.AddTemplateArgumentLoc(E->getTemplateArgs()[i]);
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000673 }
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000674
675 Record.push_back(E->hadMultipleCandidates());
676
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000677 DeclAccessPair FoundDecl = E->getFoundDecl();
Richard Smith290d8012016-04-06 17:06:00 +0000678 Record.AddDeclRef(FoundDecl.getDecl());
Argyrios Kyrtzidis1985bb32010-07-08 13:09:47 +0000679 Record.push_back(FoundDecl.getAccess());
680
Richard Smith290d8012016-04-06 17:06:00 +0000681 Record.AddTypeRef(E->getType());
John McCall7decc9e2010-11-18 06:31:45 +0000682 Record.push_back(E->getValueKind());
683 Record.push_back(E->getObjectKind());
Richard Smith290d8012016-04-06 17:06:00 +0000684 Record.AddStmt(E->getBase());
685 Record.AddDeclRef(E->getMemberDecl());
686 Record.AddSourceLocation(E->getMemberLoc());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000687 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +0000688 Record.AddSourceLocation(E->getOperatorLoc());
689 Record.AddDeclarationNameLoc(E->MemberDNLoc,
690 E->getMemberDecl()->getDeclName());
Yunzhong Gaoeba323a2015-05-01 02:04:32 +0000691 Code = serialization::EXPR_MEMBER;
Chris Lattner1f551822009-04-27 06:20:01 +0000692}
693
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000694void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
Steve Naroffe87026a2009-07-24 17:54:45 +0000695 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000696 Record.AddStmt(E->getBase());
697 Record.AddSourceLocation(E->getIsaMemberLoc());
698 Record.AddSourceLocation(E->getOpLoc());
Steve Naroffe87026a2009-07-24 17:54:45 +0000699 Record.push_back(E->isArrow());
Sebastian Redl539c5062010-08-18 23:57:32 +0000700 Code = serialization::EXPR_OBJC_ISA;
Steve Naroffe87026a2009-07-24 17:54:45 +0000701}
702
John McCall31168b02011-06-15 23:02:42 +0000703void ASTStmtWriter::
704VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
705 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000706 Record.AddStmt(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +0000707 Record.push_back(E->shouldCopy());
708 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
709}
710
711void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
712 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000713 Record.AddSourceLocation(E->getLParenLoc());
714 Record.AddSourceLocation(E->getBridgeKeywordLoc());
John McCall31168b02011-06-15 23:02:42 +0000715 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
716 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
717}
718
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000719void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000720 VisitExpr(E);
John McCallcf142162010-08-07 06:22:56 +0000721 Record.push_back(E->path_size());
Richard Smith290d8012016-04-06 17:06:00 +0000722 Record.AddStmt(E->getSubExpr());
Anders Carlssona2615922009-07-31 00:48:10 +0000723 Record.push_back(E->getCastKind()); // FIXME: stable encoding
John McCallcf142162010-08-07 06:22:56 +0000724
725 for (CastExpr::path_iterator
726 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
Richard Smith290d8012016-04-06 17:06:00 +0000727 Record.AddCXXBaseSpecifier(**PI);
Chris Lattner1f551822009-04-27 06:20:01 +0000728}
729
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000730void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000731 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000732 Record.AddStmt(E->getLHS());
733 Record.AddStmt(E->getRHS());
Chris Lattner1f551822009-04-27 06:20:01 +0000734 Record.push_back(E->getOpcode()); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +0000735 Record.AddSourceLocation(E->getOperatorLoc());
Adam Nemet484aa452017-03-27 19:17:25 +0000736 Record.push_back(E->getFPFeatures().getInt());
Sebastian Redl539c5062010-08-18 23:57:32 +0000737 Code = serialization::EXPR_BINARY_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000738}
739
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000740void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000741 VisitBinaryOperator(E);
Richard Smith290d8012016-04-06 17:06:00 +0000742 Record.AddTypeRef(E->getComputationLHSType());
743 Record.AddTypeRef(E->getComputationResultType());
Sebastian Redl539c5062010-08-18 23:57:32 +0000744 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000745}
746
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000747void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000748 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000749 Record.AddStmt(E->getCond());
750 Record.AddStmt(E->getLHS());
751 Record.AddStmt(E->getRHS());
752 Record.AddSourceLocation(E->getQuestionLoc());
753 Record.AddSourceLocation(E->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000754 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000755}
756
John McCallc07a0c72011-02-17 10:25:35 +0000757void
758ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
759 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000760 Record.AddStmt(E->getOpaqueValue());
761 Record.AddStmt(E->getCommon());
762 Record.AddStmt(E->getCond());
763 Record.AddStmt(E->getTrueExpr());
764 Record.AddStmt(E->getFalseExpr());
765 Record.AddSourceLocation(E->getQuestionLoc());
766 Record.AddSourceLocation(E->getColonLoc());
John McCallc07a0c72011-02-17 10:25:35 +0000767 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
768}
769
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000770void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000771 VisitCastExpr(E);
Roman Lebedev12216f12018-07-27 07:27:14 +0000772 Record.push_back(E->isPartOfExplicitCast());
Richard Smitha27c26e2014-07-27 04:19:32 +0000773
774 if (E->path_size() == 0)
775 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
776
Sebastian Redl539c5062010-08-18 23:57:32 +0000777 Code = serialization::EXPR_IMPLICIT_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000778}
779
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000780void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000781 VisitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000782 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
Chris Lattner1f551822009-04-27 06:20:01 +0000783}
784
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000785void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000786 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000787 Record.AddSourceLocation(E->getLParenLoc());
788 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000789 Code = serialization::EXPR_CSTYLE_CAST;
Chris Lattner1f551822009-04-27 06:20:01 +0000790}
791
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000792void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000793 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000794 Record.AddSourceLocation(E->getLParenLoc());
795 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
796 Record.AddStmt(E->getInitializer());
Chris Lattner1f551822009-04-27 06:20:01 +0000797 Record.push_back(E->isFileScope());
Sebastian Redl539c5062010-08-18 23:57:32 +0000798 Code = serialization::EXPR_COMPOUND_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +0000799}
800
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000801void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000802 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000803 Record.AddStmt(E->getBase());
804 Record.AddIdentifierRef(&E->getAccessor());
805 Record.AddSourceLocation(E->getAccessorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000806 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
Chris Lattner1f551822009-04-27 06:20:01 +0000807}
808
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000809void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000810 VisitExpr(E);
Abramo Bagnara8d16bd42012-11-08 18:41:43 +0000811 // NOTE: only add the (possibly null) syntactic form.
812 // No need to serialize the isSemanticForm flag and the semantic form.
Richard Smith290d8012016-04-06 17:06:00 +0000813 Record.AddStmt(E->getSyntacticForm());
814 Record.AddSourceLocation(E->getLBraceLoc());
815 Record.AddSourceLocation(E->getRBraceLoc());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000816 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
817 Record.push_back(isArrayFiller);
818 if (isArrayFiller)
Richard Smith290d8012016-04-06 17:06:00 +0000819 Record.AddStmt(E->getArrayFiller());
Argyrios Kyrtzidisb2ed28e2011-04-21 00:27:41 +0000820 else
Richard Smith290d8012016-04-06 17:06:00 +0000821 Record.AddDeclRef(E->getInitializedFieldInUnion());
Chris Lattner1f551822009-04-27 06:20:01 +0000822 Record.push_back(E->hadArrayRangeDesignator());
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000823 Record.push_back(E->getNumInits());
824 if (isArrayFiller) {
825 // ArrayFiller may have filled "holes" due to designated initializer.
826 // Replace them by 0 to indicate that the filler goes in that place.
827 Expr *filler = E->getArrayFiller();
828 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000829 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000830 } else {
831 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000832 Record.AddStmt(E->getInit(I));
Argyrios Kyrtzidisbbcefa72011-04-22 05:29:30 +0000833 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000834 Code = serialization::EXPR_INIT_LIST;
Chris Lattner1f551822009-04-27 06:20:01 +0000835}
836
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000837void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000838 VisitExpr(E);
839 Record.push_back(E->getNumSubExprs());
840 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000841 Record.AddStmt(E->getSubExpr(I));
842 Record.AddSourceLocation(E->getEqualOrColonLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000843 Record.push_back(E->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +0000844 for (const DesignatedInitExpr::Designator &D : E->designators()) {
845 if (D.isFieldDesignator()) {
846 if (FieldDecl *Field = D.getField()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000847 Record.push_back(serialization::DESIG_FIELD_DECL);
Richard Smith290d8012016-04-06 17:06:00 +0000848 Record.AddDeclRef(Field);
Chris Lattner1f551822009-04-27 06:20:01 +0000849 } else {
Sebastian Redl539c5062010-08-18 23:57:32 +0000850 Record.push_back(serialization::DESIG_FIELD_NAME);
David Majnemerf7e36092016-06-23 00:15:04 +0000851 Record.AddIdentifierRef(D.getFieldName());
Chris Lattner1f551822009-04-27 06:20:01 +0000852 }
David Majnemerf7e36092016-06-23 00:15:04 +0000853 Record.AddSourceLocation(D.getDotLoc());
854 Record.AddSourceLocation(D.getFieldLoc());
855 } else if (D.isArrayDesignator()) {
Sebastian Redl539c5062010-08-18 23:57:32 +0000856 Record.push_back(serialization::DESIG_ARRAY);
David Majnemerf7e36092016-06-23 00:15:04 +0000857 Record.push_back(D.getFirstExprIndex());
858 Record.AddSourceLocation(D.getLBracketLoc());
859 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000860 } else {
David Majnemerf7e36092016-06-23 00:15:04 +0000861 assert(D.isArrayRangeDesignator() && "Unknown designator");
Sebastian Redl539c5062010-08-18 23:57:32 +0000862 Record.push_back(serialization::DESIG_ARRAY_RANGE);
David Majnemerf7e36092016-06-23 00:15:04 +0000863 Record.push_back(D.getFirstExprIndex());
864 Record.AddSourceLocation(D.getLBracketLoc());
865 Record.AddSourceLocation(D.getEllipsisLoc());
866 Record.AddSourceLocation(D.getRBracketLoc());
Chris Lattner1f551822009-04-27 06:20:01 +0000867 }
868 }
Sebastian Redl539c5062010-08-18 23:57:32 +0000869 Code = serialization::EXPR_DESIGNATED_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000870}
871
Yunzhong Gaocb779302015-06-10 00:27:52 +0000872void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
873 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000874 Record.AddStmt(E->getBase());
875 Record.AddStmt(E->getUpdater());
Yunzhong Gaocb779302015-06-10 00:27:52 +0000876 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
877}
878
879void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
880 VisitExpr(E);
881 Code = serialization::EXPR_NO_INIT;
882}
883
Richard Smith410306b2016-12-12 02:53:20 +0000884void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
885 VisitExpr(E);
886 Record.AddStmt(E->SubExprs[0]);
887 Record.AddStmt(E->SubExprs[1]);
888 Code = serialization::EXPR_ARRAY_INIT_LOOP;
889}
890
891void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
892 VisitExpr(E);
893 Code = serialization::EXPR_ARRAY_INIT_INDEX;
894}
895
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000896void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000897 VisitExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +0000898 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
Chris Lattner1f551822009-04-27 06:20:01 +0000899}
900
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000901void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000902 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000903 Record.AddStmt(E->getSubExpr());
904 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
905 Record.AddSourceLocation(E->getBuiltinLoc());
906 Record.AddSourceLocation(E->getRParenLoc());
Charles Davisc7d5c942015-09-17 20:55:33 +0000907 Record.push_back(E->isMicrosoftABI());
Sebastian Redl539c5062010-08-18 23:57:32 +0000908 Code = serialization::EXPR_VA_ARG;
Chris Lattner1f551822009-04-27 06:20:01 +0000909}
910
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000911void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000912 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000913 Record.AddSourceLocation(E->getAmpAmpLoc());
914 Record.AddSourceLocation(E->getLabelLoc());
915 Record.AddDeclRef(E->getLabel());
Sebastian Redl539c5062010-08-18 23:57:32 +0000916 Code = serialization::EXPR_ADDR_LABEL;
Chris Lattner1f551822009-04-27 06:20:01 +0000917}
918
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000919void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000920 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000921 Record.AddStmt(E->getSubStmt());
922 Record.AddSourceLocation(E->getLParenLoc());
923 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000924 Code = serialization::EXPR_STMT;
Chris Lattner1f551822009-04-27 06:20:01 +0000925}
926
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000927void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000928 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000929 Record.AddStmt(E->getCond());
930 Record.AddStmt(E->getLHS());
931 Record.AddStmt(E->getRHS());
932 Record.AddSourceLocation(E->getBuiltinLoc());
933 Record.AddSourceLocation(E->getRParenLoc());
Eli Friedman75807f22013-07-20 00:40:58 +0000934 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
Sebastian Redl539c5062010-08-18 23:57:32 +0000935 Code = serialization::EXPR_CHOOSE;
Chris Lattner1f551822009-04-27 06:20:01 +0000936}
937
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000938void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000939 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000940 Record.AddSourceLocation(E->getTokenLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +0000941 Code = serialization::EXPR_GNU_NULL;
Chris Lattner1f551822009-04-27 06:20:01 +0000942}
943
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000944void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000945 VisitExpr(E);
946 Record.push_back(E->getNumSubExprs());
947 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +0000948 Record.AddStmt(E->getExpr(I));
949 Record.AddSourceLocation(E->getBuiltinLoc());
950 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000951 Code = serialization::EXPR_SHUFFLE_VECTOR;
Chris Lattner1f551822009-04-27 06:20:01 +0000952}
953
Hal Finkelc4d7c822013-09-18 03:29:45 +0000954void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
955 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000956 Record.AddSourceLocation(E->getBuiltinLoc());
957 Record.AddSourceLocation(E->getRParenLoc());
958 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
959 Record.AddStmt(E->getSrcExpr());
Hal Finkelc4d7c822013-09-18 03:29:45 +0000960 Code = serialization::EXPR_CONVERT_VECTOR;
961}
962
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000963void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +0000964 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +0000965 Record.AddDeclRef(E->getBlockDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000966 Code = serialization::EXPR_BLOCK;
Chris Lattner1f551822009-04-27 06:20:01 +0000967}
968
Peter Collingbourne91147592011-04-15 00:35:48 +0000969void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
970 VisitExpr(E);
Bruno Riccidb076832019-01-26 14:15:10 +0000971
Peter Collingbourne91147592011-04-15 00:35:48 +0000972 Record.push_back(E->getNumAssocs());
Bruno Ricci94498c72019-01-26 13:58:15 +0000973 Record.push_back(E->ResultIndex);
Richard Smith290d8012016-04-06 17:06:00 +0000974 Record.AddSourceLocation(E->getGenericLoc());
975 Record.AddSourceLocation(E->getDefaultLoc());
976 Record.AddSourceLocation(E->getRParenLoc());
Bruno Riccidb076832019-01-26 14:15:10 +0000977
978 Stmt **Stmts = E->getTrailingObjects<Stmt *>();
979 // Add 1 to account for the controlling expression which is the first
980 // expression in the trailing array of Stmt *. This is not needed for
981 // the trailing array of TypeSourceInfo *.
982 for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I)
983 Record.AddStmt(Stmts[I]);
984
985 TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
986 for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I)
987 Record.AddTypeSourceInfo(TSIs[I]);
988
Peter Collingbourne91147592011-04-15 00:35:48 +0000989 Code = serialization::EXPR_GENERIC_SELECTION;
990}
991
John McCallfe96e0b2011-11-06 09:01:30 +0000992void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
993 VisitExpr(E);
994 Record.push_back(E->getNumSemanticExprs());
995
996 // Push the result index. Currently, this needs to exactly match
997 // the encoding used internally for ResultIndex.
998 unsigned result = E->getResultExprIndex();
999 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
1000 Record.push_back(result);
1001
Richard Smith290d8012016-04-06 17:06:00 +00001002 Record.AddStmt(E->getSyntacticForm());
John McCallfe96e0b2011-11-06 09:01:30 +00001003 for (PseudoObjectExpr::semantics_iterator
1004 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
Richard Smith290d8012016-04-06 17:06:00 +00001005 Record.AddStmt(*i);
John McCallfe96e0b2011-11-06 09:01:30 +00001006 }
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +00001007 Code = serialization::EXPR_PSEUDO_OBJECT;
John McCallfe96e0b2011-11-06 09:01:30 +00001008}
1009
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001010void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
1011 VisitExpr(E);
1012 Record.push_back(E->getOp());
Richard Smithaa22a8c2012-04-10 22:49:28 +00001013 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001014 Record.AddStmt(E->getSubExprs()[I]);
1015 Record.AddSourceLocation(E->getBuiltinLoc());
1016 Record.AddSourceLocation(E->getRParenLoc());
Argyrios Kyrtzidis59386502011-11-15 06:20:27 +00001017 Code = serialization::EXPR_ATOMIC;
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001018}
1019
Chris Lattner1f551822009-04-27 06:20:01 +00001020//===----------------------------------------------------------------------===//
1021// Objective-C Expressions and Statements.
1022//===----------------------------------------------------------------------===//
1023
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001024void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001025 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001026 Record.AddStmt(E->getString());
1027 Record.AddSourceLocation(E->getAtLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001028 Code = serialization::EXPR_OBJC_STRING_LITERAL;
Chris Lattner1f551822009-04-27 06:20:01 +00001029}
1030
Patrick Beard0caa3942012-04-19 00:25:12 +00001031void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001032 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001033 Record.AddStmt(E->getSubExpr());
1034 Record.AddDeclRef(E->getBoxingMethod());
1035 Record.AddSourceRange(E->getSourceRange());
Patrick Beard0caa3942012-04-19 00:25:12 +00001036 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
Ted Kremeneke65b0862012-03-06 20:05:56 +00001037}
1038
1039void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1040 VisitExpr(E);
1041 Record.push_back(E->getNumElements());
1042 for (unsigned i = 0; i < E->getNumElements(); i++)
Richard Smith290d8012016-04-06 17:06:00 +00001043 Record.AddStmt(E->getElement(i));
1044 Record.AddDeclRef(E->getArrayWithObjectsMethod());
1045 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001046 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1047}
1048
1049void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1050 VisitExpr(E);
1051 Record.push_back(E->getNumElements());
1052 Record.push_back(E->HasPackExpansions);
1053 for (unsigned i = 0; i < E->getNumElements(); i++) {
1054 ObjCDictionaryElement Element = E->getKeyValueElement(i);
Richard Smith290d8012016-04-06 17:06:00 +00001055 Record.AddStmt(Element.Key);
1056 Record.AddStmt(Element.Value);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001057 if (E->HasPackExpansions) {
Richard Smith290d8012016-04-06 17:06:00 +00001058 Record.AddSourceLocation(Element.EllipsisLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001059 unsigned NumExpansions = 0;
1060 if (Element.NumExpansions)
1061 NumExpansions = *Element.NumExpansions + 1;
1062 Record.push_back(NumExpansions);
1063 }
1064 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001065
Richard Smith290d8012016-04-06 17:06:00 +00001066 Record.AddDeclRef(E->getDictWithObjectsMethod());
1067 Record.AddSourceRange(E->getSourceRange());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001068 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1069}
1070
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001071void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001072 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001073 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1074 Record.AddSourceLocation(E->getAtLoc());
1075 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001076 Code = serialization::EXPR_OBJC_ENCODE;
Chris Lattner1f551822009-04-27 06:20:01 +00001077}
1078
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001079void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001080 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001081 Record.AddSelectorRef(E->getSelector());
1082 Record.AddSourceLocation(E->getAtLoc());
1083 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001084 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001085}
1086
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001087void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001088 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001089 Record.AddDeclRef(E->getProtocol());
1090 Record.AddSourceLocation(E->getAtLoc());
1091 Record.AddSourceLocation(E->ProtoLoc);
1092 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001093 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001094}
1095
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001096void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001097 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001098 Record.AddDeclRef(E->getDecl());
1099 Record.AddSourceLocation(E->getLocation());
1100 Record.AddSourceLocation(E->getOpLoc());
1101 Record.AddStmt(E->getBase());
Chris Lattner1f551822009-04-27 06:20:01 +00001102 Record.push_back(E->isArrow());
1103 Record.push_back(E->isFreeIvar());
Sebastian Redl539c5062010-08-18 23:57:32 +00001104 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001105}
1106
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001107void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001108 VisitExpr(E);
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001109 Record.push_back(E->SetterAndMethodRefFlags.getInt());
John McCallb7bd14f2010-12-02 01:19:52 +00001110 Record.push_back(E->isImplicitProperty());
1111 if (E->isImplicitProperty()) {
Richard Smith290d8012016-04-06 17:06:00 +00001112 Record.AddDeclRef(E->getImplicitPropertyGetter());
1113 Record.AddDeclRef(E->getImplicitPropertySetter());
John McCallb7bd14f2010-12-02 01:19:52 +00001114 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001115 Record.AddDeclRef(E->getExplicitProperty());
John McCallb7bd14f2010-12-02 01:19:52 +00001116 }
Richard Smith290d8012016-04-06 17:06:00 +00001117 Record.AddSourceLocation(E->getLocation());
1118 Record.AddSourceLocation(E->getReceiverLocation());
John McCallb7bd14f2010-12-02 01:19:52 +00001119 if (E->isObjectReceiver()) {
1120 Record.push_back(0);
Richard Smith290d8012016-04-06 17:06:00 +00001121 Record.AddStmt(E->getBase());
John McCallb7bd14f2010-12-02 01:19:52 +00001122 } else if (E->isSuperReceiver()) {
1123 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001124 Record.AddTypeRef(E->getSuperReceiverType());
John McCallb7bd14f2010-12-02 01:19:52 +00001125 } else {
1126 Record.push_back(2);
Richard Smith290d8012016-04-06 17:06:00 +00001127 Record.AddDeclRef(E->getClassReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001128 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001129
Sebastian Redl539c5062010-08-18 23:57:32 +00001130 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001131}
1132
Ted Kremeneke65b0862012-03-06 20:05:56 +00001133void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1134 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001135 Record.AddSourceLocation(E->getRBracket());
1136 Record.AddStmt(E->getBaseExpr());
1137 Record.AddStmt(E->getKeyExpr());
1138 Record.AddDeclRef(E->getAtIndexMethodDecl());
1139 Record.AddDeclRef(E->setAtIndexMethodDecl());
Fangrui Song6907ce22018-07-30 19:24:48 +00001140
Ted Kremeneke65b0862012-03-06 20:05:56 +00001141 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1142}
1143
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001144void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Chris Lattner1f551822009-04-27 06:20:01 +00001145 VisitExpr(E);
1146 Record.push_back(E->getNumArgs());
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001147 Record.push_back(E->getNumStoredSelLocs());
1148 Record.push_back(E->SelLocsKind);
John McCall31168b02011-06-15 23:02:42 +00001149 Record.push_back(E->isDelegateInitCall());
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +00001150 Record.push_back(E->IsImplicit);
Douglas Gregor9a129192010-04-21 00:45:42 +00001151 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1152 switch (E->getReceiverKind()) {
1153 case ObjCMessageExpr::Instance:
Richard Smith290d8012016-04-06 17:06:00 +00001154 Record.AddStmt(E->getInstanceReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001155 break;
1156
1157 case ObjCMessageExpr::Class:
Richard Smith290d8012016-04-06 17:06:00 +00001158 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
Douglas Gregor9a129192010-04-21 00:45:42 +00001159 break;
1160
1161 case ObjCMessageExpr::SuperClass:
1162 case ObjCMessageExpr::SuperInstance:
Richard Smith290d8012016-04-06 17:06:00 +00001163 Record.AddTypeRef(E->getSuperType());
1164 Record.AddSourceLocation(E->getSuperLoc());
Douglas Gregor9a129192010-04-21 00:45:42 +00001165 break;
1166 }
1167
1168 if (E->getMethodDecl()) {
1169 Record.push_back(1);
Richard Smith290d8012016-04-06 17:06:00 +00001170 Record.AddDeclRef(E->getMethodDecl());
Douglas Gregor9a129192010-04-21 00:45:42 +00001171 } else {
1172 Record.push_back(0);
Fangrui Song6907ce22018-07-30 19:24:48 +00001173 Record.AddSelectorRef(E->getSelector());
Douglas Gregor9a129192010-04-21 00:45:42 +00001174 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001175
Richard Smith290d8012016-04-06 17:06:00 +00001176 Record.AddSourceLocation(E->getLeftLoc());
1177 Record.AddSourceLocation(E->getRightLoc());
Chris Lattner1f551822009-04-27 06:20:01 +00001178
1179 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1180 Arg != ArgEnd; ++Arg)
Richard Smith290d8012016-04-06 17:06:00 +00001181 Record.AddStmt(*Arg);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001182
1183 SourceLocation *Locs = E->getStoredSelLocs();
1184 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001185 Record.AddSourceLocation(Locs[i]);
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00001186
Sebastian Redl539c5062010-08-18 23:57:32 +00001187 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
Chris Lattner1f551822009-04-27 06:20:01 +00001188}
1189
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001190void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00001191 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001192 Record.AddStmt(S->getElement());
1193 Record.AddStmt(S->getCollection());
1194 Record.AddStmt(S->getBody());
1195 Record.AddSourceLocation(S->getForLoc());
1196 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001197 Code = serialization::STMT_OBJC_FOR_COLLECTION;
Chris Lattner1f551822009-04-27 06:20:01 +00001198}
1199
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001200void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001201 Record.AddStmt(S->getCatchBody());
1202 Record.AddDeclRef(S->getCatchParamDecl());
1203 Record.AddSourceLocation(S->getAtCatchLoc());
1204 Record.AddSourceLocation(S->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001205 Code = serialization::STMT_OBJC_CATCH;
Chris Lattner1f551822009-04-27 06:20:01 +00001206}
1207
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001208void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001209 Record.AddStmt(S->getFinallyBody());
1210 Record.AddSourceLocation(S->getAtFinallyLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001211 Code = serialization::STMT_OBJC_FINALLY;
Chris Lattner1f551822009-04-27 06:20:01 +00001212}
1213
John McCall31168b02011-06-15 23:02:42 +00001214void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001215 Record.AddStmt(S->getSubStmt());
1216 Record.AddSourceLocation(S->getAtLoc());
John McCall31168b02011-06-15 23:02:42 +00001217 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1218}
1219
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001220void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor96c79492010-04-23 22:50:49 +00001221 Record.push_back(S->getNumCatchStmts());
Craig Toppera13603a2014-05-22 05:54:18 +00001222 Record.push_back(S->getFinallyStmt() != nullptr);
Richard Smith290d8012016-04-06 17:06:00 +00001223 Record.AddStmt(S->getTryBody());
Douglas Gregor96c79492010-04-23 22:50:49 +00001224 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001225 Record.AddStmt(S->getCatchStmt(I));
Douglas Gregor96c79492010-04-23 22:50:49 +00001226 if (S->getFinallyStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001227 Record.AddStmt(S->getFinallyStmt());
1228 Record.AddSourceLocation(S->getAtTryLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001229 Code = serialization::STMT_OBJC_AT_TRY;
Chris Lattner1f551822009-04-27 06:20:01 +00001230}
1231
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001232void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001233 Record.AddStmt(S->getSynchExpr());
1234 Record.AddStmt(S->getSynchBody());
1235 Record.AddSourceLocation(S->getAtSynchronizedLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001236 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
Chris Lattner1f551822009-04-27 06:20:01 +00001237}
1238
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001239void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Richard Smith290d8012016-04-06 17:06:00 +00001240 Record.AddStmt(S->getThrowExpr());
1241 Record.AddSourceLocation(S->getThrowLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001242 Code = serialization::STMT_OBJC_AT_THROW;
Chris Lattner1f551822009-04-27 06:20:01 +00001243}
1244
Ted Kremeneke65b0862012-03-06 20:05:56 +00001245void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1246 VisitExpr(E);
1247 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001248 Record.AddSourceLocation(E->getLocation());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001249 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1250}
1251
Erik Pilkington29099de2016-07-16 00:35:23 +00001252void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1253 VisitExpr(E);
1254 Record.AddSourceRange(E->getSourceRange());
1255 Record.AddVersionTuple(E->getVersion());
1256 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1257}
1258
Chris Lattner1f551822009-04-27 06:20:01 +00001259//===----------------------------------------------------------------------===//
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001260// C++ Expressions and Statements.
1261//===----------------------------------------------------------------------===//
1262
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001263void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001264 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001265 Record.AddSourceLocation(S->getCatchLoc());
1266 Record.AddDeclRef(S->getExceptionDecl());
1267 Record.AddStmt(S->getHandlerBlock());
Sebastian Redl539c5062010-08-18 23:57:32 +00001268 Code = serialization::STMT_CXX_CATCH;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001269}
1270
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001271void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001272 VisitStmt(S);
1273 Record.push_back(S->getNumHandlers());
Richard Smith290d8012016-04-06 17:06:00 +00001274 Record.AddSourceLocation(S->getTryLoc());
1275 Record.AddStmt(S->getTryBlock());
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001276 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001277 Record.AddStmt(S->getHandler(i));
Sebastian Redl539c5062010-08-18 23:57:32 +00001278 Code = serialization::STMT_CXX_TRY;
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +00001279}
1280
Richard Smith02e85f32011-04-14 22:09:26 +00001281void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1282 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001283 Record.AddSourceLocation(S->getForLoc());
1284 Record.AddSourceLocation(S->getCoawaitLoc());
1285 Record.AddSourceLocation(S->getColonLoc());
1286 Record.AddSourceLocation(S->getRParenLoc());
Richard Smith8baa5002018-09-28 18:44:09 +00001287 Record.AddStmt(S->getInit());
Richard Smith290d8012016-04-06 17:06:00 +00001288 Record.AddStmt(S->getRangeStmt());
1289 Record.AddStmt(S->getBeginStmt());
1290 Record.AddStmt(S->getEndStmt());
1291 Record.AddStmt(S->getCond());
1292 Record.AddStmt(S->getInc());
1293 Record.AddStmt(S->getLoopVarStmt());
1294 Record.AddStmt(S->getBody());
Richard Smith02e85f32011-04-14 22:09:26 +00001295 Code = serialization::STMT_CXX_FOR_RANGE;
1296}
1297
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001298void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1299 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001300 Record.AddSourceLocation(S->getKeywordLoc());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001301 Record.push_back(S->isIfExists());
Richard Smith290d8012016-04-06 17:06:00 +00001302 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1303 Record.AddDeclarationNameInfo(S->getNameInfo());
1304 Record.AddStmt(S->getSubStmt());
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001305 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1306}
1307
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001308void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001309 VisitCallExpr(E);
1310 Record.push_back(E->getOperator());
Adam Nemet484aa452017-03-27 19:17:25 +00001311 Record.push_back(E->getFPFeatures().getInt());
Bruno Riccifeb19232018-12-21 16:51:57 +00001312 Record.AddSourceRange(E->Range);
Sebastian Redl539c5062010-08-18 23:57:32 +00001313 Code = serialization::EXPR_CXX_OPERATOR_CALL;
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001314}
1315
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001316void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001317 VisitCallExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001318 Code = serialization::EXPR_CXX_MEMBER_CALL;
Chris Lattnerb7e7f722010-05-09 05:36:05 +00001319}
1320
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001321void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001322 VisitExpr(E);
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001323
Argyrios Kyrtzidis30d98f32010-06-24 08:57:09 +00001324 Record.push_back(E->getNumArgs());
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001325 Record.push_back(E->isElidable());
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00001326 Record.push_back(E->hadMultipleCandidates());
Richard Smithd59b8322012-12-19 01:39:02 +00001327 Record.push_back(E->isListInitialization());
Richard Smithf8adcdc2014-07-17 05:12:35 +00001328 Record.push_back(E->isStdInitListInitialization());
Douglas Gregor4f4b1862009-12-16 18:50:27 +00001329 Record.push_back(E->requiresZeroInitialization());
Douglas Gregor222cf0e2010-05-15 00:13:29 +00001330 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001331 Record.AddSourceLocation(E->getLocation());
1332 Record.AddDeclRef(E->getConstructor());
Richard Smith290d8012016-04-06 17:06:00 +00001333 Record.AddSourceRange(E->getParenOrBraceRange());
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001334
1335 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1336 Record.AddStmt(E->getArg(I));
1337
Sebastian Redl539c5062010-08-18 23:57:32 +00001338 Code = serialization::EXPR_CXX_CONSTRUCT;
Douglas Gregor5d3507d2009-09-09 23:08:42 +00001339}
1340
Richard Smith5179eb72016-06-28 19:03:57 +00001341void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1342 VisitExpr(E);
1343 Record.AddDeclRef(E->getConstructor());
1344 Record.AddSourceLocation(E->getLocation());
1345 Record.push_back(E->constructsVBase());
1346 Record.push_back(E->inheritedFromVBase());
1347 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1348}
1349
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001350void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001351 VisitCXXConstructExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001352 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001353 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
Argyrios Kyrtzidisb8d77eb2010-07-10 11:46:15 +00001354}
1355
Douglas Gregore31e6062012-02-07 10:09:13 +00001356void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1357 VisitExpr(E);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001358 Record.push_back(E->NumCaptures);
Richard Smith290d8012016-04-06 17:06:00 +00001359 Record.AddSourceRange(E->IntroducerRange);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001360 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
Richard Smith290d8012016-04-06 17:06:00 +00001361 Record.AddSourceLocation(E->CaptureDefaultLoc);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001362 Record.push_back(E->ExplicitParams);
1363 Record.push_back(E->ExplicitResultType);
Richard Smith290d8012016-04-06 17:06:00 +00001364 Record.AddSourceLocation(E->ClosingBrace);
Fangrui Song6907ce22018-07-30 19:24:48 +00001365
Douglas Gregor99ae8062012-02-14 17:54:36 +00001366 // Add capture initializers.
1367 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1368 CEnd = E->capture_init_end();
1369 C != CEnd; ++C) {
Richard Smith290d8012016-04-06 17:06:00 +00001370 Record.AddStmt(*C);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001371 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001372
Douglas Gregor99ae8062012-02-14 17:54:36 +00001373 Code = serialization::EXPR_LAMBDA;
Douglas Gregore31e6062012-02-07 10:09:13 +00001374}
1375
Richard Smithcc1b96d2013-06-12 22:31:48 +00001376void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1377 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001378 Record.AddStmt(E->getSubExpr());
Richard Smithcc1b96d2013-06-12 22:31:48 +00001379 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1380}
1381
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001382void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001383 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001384 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1385 Record.AddSourceRange(E->getAngleBrackets());
Sam Weinigd01101e2010-01-16 21:21:01 +00001386}
1387
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001388void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001389 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001390 Code = serialization::EXPR_CXX_STATIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001391}
1392
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001393void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001394 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001395 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001396}
1397
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001398void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001399 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001400 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001401}
1402
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001403void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001404 VisitCXXNamedCastExpr(E);
Sebastian Redl539c5062010-08-18 23:57:32 +00001405 Code = serialization::EXPR_CXX_CONST_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001406}
1407
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001408void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Sam Weinigd01101e2010-01-16 21:21:01 +00001409 VisitExplicitCastExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001410 Record.AddSourceLocation(E->getLParenLoc());
1411 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001412 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
Sam Weinigd01101e2010-01-16 21:21:01 +00001413}
1414
Richard Smithc67fdd42012-03-07 08:35:16 +00001415void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1416 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001417 Record.AddSourceLocation(E->UDSuffixLoc);
Richard Smithc67fdd42012-03-07 08:35:16 +00001418 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1419}
1420
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001421void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001422 VisitExpr(E);
1423 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001424 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001425 Code = serialization::EXPR_CXX_BOOL_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001426}
1427
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001428void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
Sam Weinige83b3ac2010-02-07 06:32:43 +00001429 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001430 Record.AddSourceLocation(E->getLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001431 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
Sam Weinige83b3ac2010-02-07 06:32:43 +00001432}
1433
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001434void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001435 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001436 Record.AddSourceRange(E->getSourceRange());
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001437 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001438 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
Sebastian Redl539c5062010-08-18 23:57:32 +00001439 Code = serialization::EXPR_CXX_TYPEID_TYPE;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001440 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001441 Record.AddStmt(E->getExprOperand());
Sebastian Redl539c5062010-08-18 23:57:32 +00001442 Code = serialization::EXPR_CXX_TYPEID_EXPR;
Chris Lattner13a5ecc2010-05-09 06:03:39 +00001443 }
1444}
1445
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001446void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
Chris Lattner98267332010-05-09 06:15:05 +00001447 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001448 Record.AddSourceLocation(E->getLocation());
Chris Lattner98267332010-05-09 06:15:05 +00001449 Record.push_back(E->isImplicit());
Sebastian Redl539c5062010-08-18 23:57:32 +00001450 Code = serialization::EXPR_CXX_THIS;
Chris Lattner98267332010-05-09 06:15:05 +00001451}
1452
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001453void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001454 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001455 Record.AddSourceLocation(E->getThrowLoc());
1456 Record.AddStmt(E->getSubExpr());
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001457 Record.push_back(E->isThrownVariableInScope());
Sebastian Redl539c5062010-08-18 23:57:32 +00001458 Code = serialization::EXPR_CXX_THROW;
Chris Lattner98267332010-05-09 06:15:05 +00001459}
1460
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001461void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Chris Lattnere2437f42010-05-09 06:40:08 +00001462 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001463 Record.AddDeclRef(E->getParam());
1464 Record.AddSourceLocation(E->getUsedLocation());
Sebastian Redl539c5062010-08-18 23:57:32 +00001465 Code = serialization::EXPR_CXX_DEFAULT_ARG;
Chris Lattnere2437f42010-05-09 06:40:08 +00001466}
1467
Richard Smith852c9db2013-04-20 22:23:05 +00001468void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1469 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001470 Record.AddDeclRef(E->getField());
1471 Record.AddSourceLocation(E->getExprLoc());
Richard Smith852c9db2013-04-20 22:23:05 +00001472 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1473}
1474
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001475void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001476 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001477 Record.AddCXXTemporary(E->getTemporary());
1478 Record.AddStmt(E->getSubExpr());
Sebastian Redl539c5062010-08-18 23:57:32 +00001479 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
Chris Lattnercba86142010-05-10 00:25:06 +00001480}
1481
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001482void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001483 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001484 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1485 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001486 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001487}
1488
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001489void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001490 VisitExpr(E);
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001491
Sebastian Redlc3a3c602012-02-16 11:35:52 +00001492 Record.push_back(E->isArray());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001493 Record.push_back(E->hasInitializer());
1494 Record.push_back(E->getNumPlacementArgs());
1495 Record.push_back(E->isParenTypeId());
1496
1497 Record.push_back(E->isGlobalNew());
Richard Smithb2f0f052016-10-10 18:54:32 +00001498 Record.push_back(E->passAlignment());
Sebastian Redl6047f072012-02-16 12:22:20 +00001499 Record.push_back(E->doesUsualArrayDeleteWantSize());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001500 Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
1501
Richard Smith290d8012016-04-06 17:06:00 +00001502 Record.AddDeclRef(E->getOperatorNew());
1503 Record.AddDeclRef(E->getOperatorDelete());
1504 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001505 if (E->isParenTypeId())
1506 Record.AddSourceRange(E->getTypeIdParens());
Richard Smith290d8012016-04-06 17:06:00 +00001507 Record.AddSourceRange(E->getSourceRange());
1508 Record.AddSourceRange(E->getDirectInitRange());
Bruno Ricci9b6dfac2019-01-07 15:04:45 +00001509
1510 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
1511 I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001512 Record.AddStmt(*I);
Sebastian Redl6047f072012-02-16 12:22:20 +00001513
Sebastian Redl539c5062010-08-18 23:57:32 +00001514 Code = serialization::EXPR_CXX_NEW;
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001515}
1516
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001517void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001518 VisitExpr(E);
1519 Record.push_back(E->isGlobalDelete());
1520 Record.push_back(E->isArrayForm());
Argyrios Kyrtzidis14ec9f62010-09-13 20:15:54 +00001521 Record.push_back(E->isArrayFormAsWritten());
John McCall284c48f2011-01-27 09:37:56 +00001522 Record.push_back(E->doesUsualArrayDeleteWantSize());
Richard Smith290d8012016-04-06 17:06:00 +00001523 Record.AddDeclRef(E->getOperatorDelete());
1524 Record.AddStmt(E->getArgument());
Bruno Ricci91728fc2018-12-03 12:32:32 +00001525 Record.AddSourceLocation(E->getBeginLoc());
Fangrui Song6907ce22018-07-30 19:24:48 +00001526
Sebastian Redl539c5062010-08-18 23:57:32 +00001527 Code = serialization::EXPR_CXX_DELETE;
Argyrios Kyrtzidis6e57c352010-06-22 17:07:59 +00001528}
Chris Lattnerabfb58d2010-05-10 01:22:27 +00001529
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001530void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001531 VisitExpr(E);
1532
Richard Smith290d8012016-04-06 17:06:00 +00001533 Record.AddStmt(E->getBase());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001534 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001535 Record.AddSourceLocation(E->getOperatorLoc());
1536 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1537 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1538 Record.AddSourceLocation(E->getColonColonLoc());
1539 Record.AddSourceLocation(E->getTildeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001540
1541 // PseudoDestructorTypeStorage.
Richard Smith290d8012016-04-06 17:06:00 +00001542 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001543 if (E->getDestroyedTypeIdentifier())
Richard Smith290d8012016-04-06 17:06:00 +00001544 Record.AddSourceLocation(E->getDestroyedTypeLoc());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001545 else
Richard Smith290d8012016-04-06 17:06:00 +00001546 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001547
Sebastian Redl539c5062010-08-18 23:57:32 +00001548 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
Argyrios Kyrtzidis99a226d2010-06-28 09:32:03 +00001549}
1550
John McCall5d413782010-12-06 08:20:24 +00001551void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
Chris Lattnercba86142010-05-10 00:25:06 +00001552 VisitExpr(E);
John McCall28fc7092011-11-10 05:35:25 +00001553 Record.push_back(E->getNumObjects());
1554 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
Richard Smith290d8012016-04-06 17:06:00 +00001555 Record.AddDeclRef(E->getObject(i));
Tim Shen4a05bb82016-06-21 20:29:17 +00001556
1557 Record.push_back(E->cleanupsHaveSideEffects());
Richard Smith290d8012016-04-06 17:06:00 +00001558 Record.AddStmt(E->getSubExpr());
John McCall5d413782010-12-06 08:20:24 +00001559 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
Chris Lattnercba86142010-05-10 00:25:06 +00001560}
1561
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001562void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
1563 CXXDependentScopeMemberExpr *E) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001564 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001565
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001566 // Don't emit anything here (or if you do you will have to update
1567 // the corresponding deserialization function).
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001568
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001569 Record.push_back(E->hasTemplateKWAndArgsInfo());
1570 Record.push_back(E->getNumTemplateArgs());
1571 Record.push_back(E->hasFirstQualifierFoundInScope());
1572
1573 if (E->hasTemplateKWAndArgsInfo()) {
James Y Knighte7d82282015-12-29 18:15:14 +00001574 const ASTTemplateKWAndArgsInfo &ArgInfo =
1575 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
James Y Knighte7d82282015-12-29 18:15:14 +00001576 AddTemplateKWAndArgsInfo(ArgInfo,
1577 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001578 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00001579
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001580 Record.push_back(E->isArrow());
1581 Record.AddSourceLocation(E->getOperatorLoc());
1582 Record.AddTypeRef(E->getBaseType());
1583 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001584 if (!E->isImplicitAccess())
Richard Smith290d8012016-04-06 17:06:00 +00001585 Record.AddStmt(E->getBase());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001586 else
Richard Smith290d8012016-04-06 17:06:00 +00001587 Record.AddStmt(nullptr);
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001588
1589 if (E->hasFirstQualifierFoundInScope())
1590 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1591
Richard Smith290d8012016-04-06 17:06:00 +00001592 Record.AddDeclarationNameInfo(E->MemberNameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001593 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001594}
1595
1596void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001597ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001598 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001599
1600 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
Douglas Gregor87866ce2011-02-04 12:01:24 +00001601 // emitted first.
Abramo Bagnara7945c982012-01-27 09:46:47 +00001602
Bruno Ricci49ee9642019-01-07 14:27:04 +00001603 Record.push_back(E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
1604 if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
James Y Knighte7d82282015-12-29 18:15:14 +00001605 const ASTTemplateKWAndArgsInfo &ArgInfo =
1606 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1607 Record.push_back(ArgInfo.NumTemplateArgs);
1608 AddTemplateKWAndArgsInfo(ArgInfo,
1609 E->getTrailingObjects<TemplateArgumentLoc>());
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001610 }
1611
Richard Smith290d8012016-04-06 17:06:00 +00001612 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1613 Record.AddDeclarationNameInfo(E->NameInfo);
Sebastian Redl539c5062010-08-18 23:57:32 +00001614 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +00001615}
1616
1617void
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001618ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001619 VisitExpr(E);
1620 Record.push_back(E->arg_size());
1621 for (CXXUnresolvedConstructExpr::arg_iterator
1622 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
Richard Smith290d8012016-04-06 17:06:00 +00001623 Record.AddStmt(*ArgI);
1624 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1625 Record.AddSourceLocation(E->getLParenLoc());
1626 Record.AddSourceLocation(E->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001627 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001628}
Chris Lattner98267332010-05-09 06:15:05 +00001629
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001630void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001631 VisitExpr(E);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001632
Bruno Riccid7628d92019-01-09 15:43:19 +00001633 Record.push_back(E->getNumDecls());
1634 Record.push_back(E->hasTemplateKWAndArgsInfo());
1635 if (E->hasTemplateKWAndArgsInfo()) {
James Y Knighte7d82282015-12-29 18:15:14 +00001636 const ASTTemplateKWAndArgsInfo &ArgInfo =
1637 *E->getTrailingASTTemplateKWAndArgsInfo();
1638 Record.push_back(ArgInfo.NumTemplateArgs);
1639 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001640 }
1641
Bruno Riccid7628d92019-01-09 15:43:19 +00001642 for (OverloadExpr::decls_iterator OvI = E->decls_begin(),
1643 OvE = E->decls_end();
1644 OvI != OvE; ++OvI) {
Richard Smith290d8012016-04-06 17:06:00 +00001645 Record.AddDeclRef(OvI.getDecl());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001646 Record.push_back(OvI.getAccess());
1647 }
1648
Bruno Riccid7628d92019-01-09 15:43:19 +00001649 Record.AddDeclarationNameInfo(E->getNameInfo());
Richard Smith290d8012016-04-06 17:06:00 +00001650 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001651}
1652
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001653void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001654 VisitOverloadExpr(E);
1655 Record.push_back(E->isArrow());
1656 Record.push_back(E->hasUnresolvedUsing());
Richard Smith290d8012016-04-06 17:06:00 +00001657 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1658 Record.AddTypeRef(E->getBaseType());
1659 Record.AddSourceLocation(E->getOperatorLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001660 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001661}
1662
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001663void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001664 VisitOverloadExpr(E);
1665 Record.push_back(E->requiresADL());
1666 Record.push_back(E->isOverloaded());
Richard Smith290d8012016-04-06 17:06:00 +00001667 Record.AddDeclRef(E->getNamingClass());
Sebastian Redl539c5062010-08-18 23:57:32 +00001668 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +00001669}
1670
Douglas Gregor29c42f22012-02-24 07:38:34 +00001671void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1672 VisitExpr(E);
1673 Record.push_back(E->TypeTraitExprBits.NumArgs);
1674 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1675 Record.push_back(E->TypeTraitExprBits.Value);
Richard Smith290d8012016-04-06 17:06:00 +00001676 Record.AddSourceRange(E->getSourceRange());
Douglas Gregor29c42f22012-02-24 07:38:34 +00001677 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001678 Record.AddTypeSourceInfo(E->getArg(I));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001679 Code = serialization::EXPR_TYPE_TRAIT;
1680}
1681
John Wiegley6242b6a2011-04-28 00:16:57 +00001682void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1683 VisitExpr(E);
1684 Record.push_back(E->getTrait());
1685 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001686 Record.AddSourceRange(E->getSourceRange());
1687 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
Aleksei Sidorina693b372016-09-28 10:16:56 +00001688 Record.AddStmt(E->getDimensionExpression());
John Wiegley6242b6a2011-04-28 00:16:57 +00001689 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1690}
1691
John Wiegleyf9f65842011-04-25 06:54:41 +00001692void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1693 VisitExpr(E);
1694 Record.push_back(E->getTrait());
1695 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001696 Record.AddSourceRange(E->getSourceRange());
1697 Record.AddStmt(E->getQueriedExpression());
John Wiegleyf9f65842011-04-25 06:54:41 +00001698 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1699}
1700
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001701void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1702 VisitExpr(E);
1703 Record.push_back(E->getValue());
Richard Smith290d8012016-04-06 17:06:00 +00001704 Record.AddSourceRange(E->getSourceRange());
1705 Record.AddStmt(E->getOperand());
Sebastian Redl9ac55dd2010-09-10 20:55:54 +00001706 Code = serialization::EXPR_CXX_NOEXCEPT;
1707}
1708
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001709void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1710 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001711 Record.AddSourceLocation(E->getEllipsisLoc());
Douglas Gregorb8840002011-01-14 21:20:45 +00001712 Record.push_back(E->NumExpansions);
Richard Smith290d8012016-04-06 17:06:00 +00001713 Record.AddStmt(E->getPattern());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001714 Code = serialization::EXPR_PACK_EXPANSION;
1715}
1716
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001717void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1718 VisitExpr(E);
Richard Smithd784e682015-09-23 21:41:42 +00001719 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1720 : 0);
Richard Smith290d8012016-04-06 17:06:00 +00001721 Record.AddSourceLocation(E->OperatorLoc);
1722 Record.AddSourceLocation(E->PackLoc);
1723 Record.AddSourceLocation(E->RParenLoc);
1724 Record.AddDeclRef(E->Pack);
Richard Smithd784e682015-09-23 21:41:42 +00001725 if (E->isPartiallySubstituted()) {
1726 for (const auto &TA : E->getPartialArguments())
Richard Smith290d8012016-04-06 17:06:00 +00001727 Record.AddTemplateArgument(TA);
Richard Smithd784e682015-09-23 21:41:42 +00001728 } else if (!E->isValueDependent()) {
1729 Record.push_back(E->getPackLength());
1730 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001731 Code = serialization::EXPR_SIZEOF_PACK;
1732}
1733
John McCallfa194042011-07-15 07:00:14 +00001734void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1735 SubstNonTypeTemplateParmExpr *E) {
1736 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001737 Record.AddDeclRef(E->getParameter());
1738 Record.AddSourceLocation(E->getNameLoc());
1739 Record.AddStmt(E->getReplacement());
John McCallfa194042011-07-15 07:00:14 +00001740 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1741}
1742
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001743void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1744 SubstNonTypeTemplateParmPackExpr *E) {
1745 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001746 Record.AddDeclRef(E->getParameterPack());
1747 Record.AddTemplateArgument(E->getArgumentPack());
1748 Record.AddSourceLocation(E->getParameterPackLocation());
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001749 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1750}
1751
Richard Smithb15fe3a2012-09-12 00:56:43 +00001752void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1753 VisitExpr(E);
1754 Record.push_back(E->getNumExpansions());
Richard Smith290d8012016-04-06 17:06:00 +00001755 Record.AddDeclRef(E->getParameterPack());
1756 Record.AddSourceLocation(E->getParameterPackLocation());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001757 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1758 I != End; ++I)
Richard Smith290d8012016-04-06 17:06:00 +00001759 Record.AddDeclRef(*I);
Richard Smithb15fe3a2012-09-12 00:56:43 +00001760 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1761}
1762
Douglas Gregorfe314812011-06-21 17:03:29 +00001763void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1764 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001765 Record.AddStmt(E->getTemporary());
1766 Record.AddDeclRef(E->getExtendingDecl());
David Majnemerdaff3702014-05-01 17:50:17 +00001767 Record.push_back(E->getManglingNumber());
Douglas Gregorfe314812011-06-21 17:03:29 +00001768 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1769}
1770
Richard Smith0f0af192014-11-08 05:07:16 +00001771void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1772 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001773 Record.AddSourceLocation(E->LParenLoc);
1774 Record.AddSourceLocation(E->EllipsisLoc);
1775 Record.AddSourceLocation(E->RParenLoc);
1776 Record.AddStmt(E->SubExprs[0]);
1777 Record.AddStmt(E->SubExprs[1]);
Richard Smith0f0af192014-11-08 05:07:16 +00001778 Record.push_back(E->Opcode);
1779 Code = serialization::EXPR_CXX_FOLD;
1780}
1781
John McCall8d69a212010-11-15 23:31:06 +00001782void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1783 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001784 Record.AddStmt(E->getSourceExpr());
1785 Record.AddSourceLocation(E->getLocation());
Akira Hatanaka797afe32018-03-20 01:47:58 +00001786 Record.push_back(E->isUnique());
John McCall8d69a212010-11-15 23:31:06 +00001787 Code = serialization::EXPR_OPAQUE_VALUE;
1788}
1789
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001790void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1791 VisitExpr(E);
1792 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
Davide Italiano04839a52016-01-30 08:03:54 +00001793 llvm_unreachable("Cannot write TypoExpr nodes");
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001794}
1795
Argyrios Kyrtzidiseeaaead2009-07-14 03:19:21 +00001796//===----------------------------------------------------------------------===//
Peter Collingbourne41f85462011-02-09 21:07:24 +00001797// CUDA Expressions and Statements.
1798//===----------------------------------------------------------------------===//
1799
1800void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1801 VisitCallExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001802 Record.AddStmt(E->getConfig());
Peter Collingbourne41f85462011-02-09 21:07:24 +00001803 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1804}
1805
1806//===----------------------------------------------------------------------===//
Tanya Lattner55808c12011-06-04 00:47:47 +00001807// OpenCL Expressions and Statements.
1808//===----------------------------------------------------------------------===//
1809void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1810 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001811 Record.AddSourceLocation(E->getBuiltinLoc());
1812 Record.AddSourceLocation(E->getRParenLoc());
1813 Record.AddStmt(E->getSrcExpr());
Tanya Lattner55808c12011-06-04 00:47:47 +00001814 Code = serialization::EXPR_ASTYPE;
1815}
1816
1817//===----------------------------------------------------------------------===//
John McCallfa194042011-07-15 07:00:14 +00001818// Microsoft Expressions and Statements.
1819//===----------------------------------------------------------------------===//
John McCall5e77d762013-04-16 07:28:30 +00001820void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1821 VisitExpr(E);
1822 Record.push_back(E->isArrow());
Richard Smith290d8012016-04-06 17:06:00 +00001823 Record.AddStmt(E->getBaseExpr());
1824 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1825 Record.AddSourceLocation(E->getMemberLoc());
1826 Record.AddDeclRef(E->getPropertyDecl());
John McCall5e77d762013-04-16 07:28:30 +00001827 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1828}
1829
Alexey Bataevf7630272015-11-25 12:01:00 +00001830void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1831 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001832 Record.AddStmt(E->getBase());
1833 Record.AddStmt(E->getIdx());
1834 Record.AddSourceLocation(E->getRBracketLoc());
Alexey Bataevf7630272015-11-25 12:01:00 +00001835 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1836}
1837
John McCallfa194042011-07-15 07:00:14 +00001838void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1839 VisitExpr(E);
Richard Smith290d8012016-04-06 17:06:00 +00001840 Record.AddSourceRange(E->getSourceRange());
1841 Record.AddString(E->getUuidStr());
John McCallfa194042011-07-15 07:00:14 +00001842 if (E->isTypeOperand()) {
Richard Smith290d8012016-04-06 17:06:00 +00001843 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
John McCallfa194042011-07-15 07:00:14 +00001844 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1845 } else {
Richard Smith290d8012016-04-06 17:06:00 +00001846 Record.AddStmt(E->getExprOperand());
John McCallfa194042011-07-15 07:00:14 +00001847 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1848 }
1849}
1850
1851void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1852 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001853 Record.AddSourceLocation(S->getExceptLoc());
1854 Record.AddStmt(S->getFilterExpr());
1855 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001856 Code = serialization::STMT_SEH_EXCEPT;
1857}
1858
1859void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1860 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001861 Record.AddSourceLocation(S->getFinallyLoc());
1862 Record.AddStmt(S->getBlock());
John McCallfa194042011-07-15 07:00:14 +00001863 Code = serialization::STMT_SEH_FINALLY;
1864}
1865
1866void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1867 VisitStmt(S);
1868 Record.push_back(S->getIsCXXTry());
Richard Smith290d8012016-04-06 17:06:00 +00001869 Record.AddSourceLocation(S->getTryLoc());
1870 Record.AddStmt(S->getTryBlock());
1871 Record.AddStmt(S->getHandler());
John McCallfa194042011-07-15 07:00:14 +00001872 Code = serialization::STMT_SEH_TRY;
1873}
1874
Nico Weber9b982072014-07-07 00:12:30 +00001875void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1876 VisitStmt(S);
Richard Smith290d8012016-04-06 17:06:00 +00001877 Record.AddSourceLocation(S->getLeaveLoc());
Nico Weber9b982072014-07-07 00:12:30 +00001878 Code = serialization::STMT_SEH_LEAVE;
1879}
1880
John McCallfa194042011-07-15 07:00:14 +00001881//===----------------------------------------------------------------------===//
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001882// OpenMP Directives.
1883//===----------------------------------------------------------------------===//
1884void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001885 Record.AddSourceLocation(E->getBeginLoc());
Stephen Kelly1c301dc2018-08-09 21:09:38 +00001886 Record.AddSourceLocation(E->getEndLoc());
Richard Smith290d8012016-04-06 17:06:00 +00001887 OMPClauseWriter ClauseWriter(Record);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001888 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
1889 ClauseWriter.writeClause(E->getClause(i));
1890 }
Alexey Bataev68446b72014-07-18 07:47:19 +00001891 if (E->hasAssociatedStmt())
Richard Smith290d8012016-04-06 17:06:00 +00001892 Record.AddStmt(E->getAssociatedStmt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001893}
1894
Alexander Musman3aaab662014-08-19 11:27:13 +00001895void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
1896 VisitStmt(D);
1897 Record.push_back(D->getNumClauses());
1898 Record.push_back(D->getCollapsedNumber());
1899 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00001900 Record.AddStmt(D->getIterationVariable());
1901 Record.AddStmt(D->getLastIteration());
1902 Record.AddStmt(D->getCalcLastIteration());
1903 Record.AddStmt(D->getPreCond());
1904 Record.AddStmt(D->getCond());
1905 Record.AddStmt(D->getInit());
1906 Record.AddStmt(D->getInc());
1907 Record.AddStmt(D->getPreInits());
Alexey Bataev3392d762016-02-16 11:18:12 +00001908 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001909 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
1910 isOpenMPDistributeDirective(D->getDirectiveKind())) {
Richard Smith290d8012016-04-06 17:06:00 +00001911 Record.AddStmt(D->getIsLastIterVariable());
1912 Record.AddStmt(D->getLowerBoundVariable());
1913 Record.AddStmt(D->getUpperBoundVariable());
1914 Record.AddStmt(D->getStrideVariable());
1915 Record.AddStmt(D->getEnsureUpperBound());
1916 Record.AddStmt(D->getNextLowerBound());
1917 Record.AddStmt(D->getNextUpperBound());
Alexey Bataev8b427062016-05-25 12:36:08 +00001918 Record.AddStmt(D->getNumIterations());
Alexander Musmanc6388682014-12-15 07:07:06 +00001919 }
Carlo Bertolli9925f152016-06-27 14:55:37 +00001920 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
1921 Record.AddStmt(D->getPrevLowerBoundVariable());
1922 Record.AddStmt(D->getPrevUpperBoundVariable());
Carlo Bertolli8429d812017-02-17 21:29:13 +00001923 Record.AddStmt(D->getDistInc());
1924 Record.AddStmt(D->getPrevEnsureUpperBound());
Carlo Bertolliffafe102017-04-20 00:39:39 +00001925 Record.AddStmt(D->getCombinedLowerBoundVariable());
1926 Record.AddStmt(D->getCombinedUpperBoundVariable());
1927 Record.AddStmt(D->getCombinedEnsureUpperBound());
1928 Record.AddStmt(D->getCombinedInit());
1929 Record.AddStmt(D->getCombinedCond());
1930 Record.AddStmt(D->getCombinedNextLowerBound());
1931 Record.AddStmt(D->getCombinedNextUpperBound());
Gheorghe-Teodor Berceae9256762018-10-29 15:45:47 +00001932 Record.AddStmt(D->getCombinedDistCond());
1933 Record.AddStmt(D->getCombinedParForInDistCond());
Carlo Bertolli9925f152016-06-27 14:55:37 +00001934 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001935 for (auto I : D->counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001936 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001937 }
Alexey Bataeva8899172015-08-06 12:30:57 +00001938 for (auto I : D->private_counters()) {
Richard Smith290d8012016-04-06 17:06:00 +00001939 Record.AddStmt(I);
Alexey Bataeva8899172015-08-06 12:30:57 +00001940 }
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001941 for (auto I : D->inits()) {
Richard Smith290d8012016-04-06 17:06:00 +00001942 Record.AddStmt(I);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001943 }
Alexander Musmana5f070a2014-10-01 06:03:56 +00001944 for (auto I : D->updates()) {
Richard Smith290d8012016-04-06 17:06:00 +00001945 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001946 }
1947 for (auto I : D->finals()) {
Richard Smith290d8012016-04-06 17:06:00 +00001948 Record.AddStmt(I);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001949 }
Alexander Musman3aaab662014-08-19 11:27:13 +00001950}
1951
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001952void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001953 VisitStmt(D);
1954 Record.push_back(D->getNumClauses());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001955 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001956 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001957 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
1958}
1959
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001960void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001961 VisitOMPLoopDirective(D);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001962 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
1963}
1964
Alexey Bataevf29276e2014-06-18 04:14:57 +00001965void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00001966 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001967 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevf29276e2014-06-18 04:14:57 +00001968 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
1969}
1970
Alexander Musmanf82886e2014-09-18 05:12:34 +00001971void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
1972 VisitOMPLoopDirective(D);
1973 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
1974}
1975
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001976void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
1977 VisitStmt(D);
1978 Record.push_back(D->getNumClauses());
1979 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001980 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001981 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
1982}
1983
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001984void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
1985 VisitStmt(D);
1986 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00001987 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001988 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
1989}
1990
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00001991void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
1992 VisitStmt(D);
1993 Record.push_back(D->getNumClauses());
1994 VisitOMPExecutableDirective(D);
1995 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
1996}
1997
Alexander Musman80c22892014-07-17 08:54:58 +00001998void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
1999 VisitStmt(D);
2000 VisitOMPExecutableDirective(D);
2001 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2002}
2003
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002004void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2005 VisitStmt(D);
Alexey Bataev28c75412015-12-15 08:19:24 +00002006 Record.push_back(D->getNumClauses());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002007 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00002008 Record.AddDeclarationNameInfo(D->getDirectiveName());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002009 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2010}
2011
Alexey Bataev4acb8592014-07-07 13:01:15 +00002012void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
Alexander Musman3aaab662014-08-19 11:27:13 +00002013 VisitOMPLoopDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002014 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev4acb8592014-07-07 13:01:15 +00002015 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2016}
2017
Alexander Musmane4e893b2014-09-23 09:33:00 +00002018void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2019 OMPParallelForSimdDirective *D) {
2020 VisitOMPLoopDirective(D);
2021 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2022}
2023
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002024void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2025 OMPParallelSectionsDirective *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 Bataev84d0b3e2014-07-08 08:12:03 +00002030 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2031}
2032
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002033void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2034 VisitStmt(D);
2035 Record.push_back(D->getNumClauses());
2036 VisitOMPExecutableDirective(D);
Alexey Bataev25e5b442015-09-15 12:52:43 +00002037 Record.push_back(D->hasCancel() ? 1 : 0);
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002038 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2039}
2040
Alexey Bataev0162e452014-07-22 10:10:35 +00002041void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2042 VisitStmt(D);
2043 Record.push_back(D->getNumClauses());
2044 VisitOMPExecutableDirective(D);
Richard Smith290d8012016-04-06 17:06:00 +00002045 Record.AddStmt(D->getX());
2046 Record.AddStmt(D->getV());
2047 Record.AddStmt(D->getExpr());
2048 Record.AddStmt(D->getUpdateExpr());
Alexey Bataevb4505a72015-03-30 05:20:59 +00002049 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
Alexey Bataevb78ca832015-04-01 03:33:17 +00002050 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
Alexey Bataev0162e452014-07-22 10:10:35 +00002051 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2052}
2053
Alexey Bataev0bd520b2014-09-19 08:19:49 +00002054void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2055 VisitStmt(D);
2056 Record.push_back(D->getNumClauses());
2057 VisitOMPExecutableDirective(D);
2058 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2059}
2060
Michael Wong65f367f2015-07-21 13:44:28 +00002061void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2062 VisitStmt(D);
2063 Record.push_back(D->getNumClauses());
2064 VisitOMPExecutableDirective(D);
2065 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2066}
2067
Samuel Antaodf67fc42016-01-19 19:15:56 +00002068void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2069 OMPTargetEnterDataDirective *D) {
2070 VisitStmt(D);
2071 Record.push_back(D->getNumClauses());
2072 VisitOMPExecutableDirective(D);
2073 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2074}
2075
Samuel Antao72590762016-01-19 20:04:50 +00002076void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2077 OMPTargetExitDataDirective *D) {
2078 VisitStmt(D);
2079 Record.push_back(D->getNumClauses());
2080 VisitOMPExecutableDirective(D);
2081 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2082}
2083
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00002084void ASTStmtWriter::VisitOMPTargetParallelDirective(
2085 OMPTargetParallelDirective *D) {
2086 VisitStmt(D);
2087 Record.push_back(D->getNumClauses());
2088 VisitOMPExecutableDirective(D);
2089 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2090}
2091
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00002092void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2093 OMPTargetParallelForDirective *D) {
2094 VisitOMPLoopDirective(D);
2095 Record.push_back(D->hasCancel() ? 1 : 0);
2096 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2097}
2098
Alexey Bataev68446b72014-07-18 07:47:19 +00002099void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2100 VisitStmt(D);
2101 VisitOMPExecutableDirective(D);
2102 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2103}
2104
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00002105void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2106 VisitStmt(D);
2107 VisitOMPExecutableDirective(D);
2108 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2109}
2110
Alexey Bataev2df347a2014-07-18 10:17:07 +00002111void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2112 VisitStmt(D);
2113 VisitOMPExecutableDirective(D);
2114 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2115}
2116
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002117void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2118 VisitStmt(D);
Alexey Bataev169d96a2017-07-18 20:17:46 +00002119 Record.push_back(D->getNumClauses());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002120 VisitOMPExecutableDirective(D);
Alexey Bataev3b1b8952017-07-25 15:53:26 +00002121 Record.AddStmt(D->getReductionRef());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002122 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2123}
2124
Alexey Bataev6125da92014-07-21 11:26:11 +00002125void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2126 VisitStmt(D);
2127 Record.push_back(D->getNumClauses());
2128 VisitOMPExecutableDirective(D);
2129 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2130}
2131
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002132void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2133 VisitStmt(D);
Alexey Bataev346265e2015-09-25 10:37:12 +00002134 Record.push_back(D->getNumClauses());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002135 VisitOMPExecutableDirective(D);
2136 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2137}
2138
Alexey Bataev13314bf2014-10-09 04:18:56 +00002139void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2140 VisitStmt(D);
2141 Record.push_back(D->getNumClauses());
2142 VisitOMPExecutableDirective(D);
2143 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2144}
2145
Alexey Bataev6d4ed052015-07-01 06:57:41 +00002146void ASTStmtWriter::VisitOMPCancellationPointDirective(
2147 OMPCancellationPointDirective *D) {
2148 VisitStmt(D);
2149 VisitOMPExecutableDirective(D);
2150 Record.push_back(D->getCancelRegion());
2151 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2152}
2153
Alexey Bataev80909872015-07-02 11:25:17 +00002154void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2155 VisitStmt(D);
Alexey Bataev87933c72015-09-18 08:07:34 +00002156 Record.push_back(D->getNumClauses());
Alexey Bataev80909872015-07-02 11:25:17 +00002157 VisitOMPExecutableDirective(D);
2158 Record.push_back(D->getCancelRegion());
2159 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2160}
2161
Alexey Bataev49f6e782015-12-01 04:18:41 +00002162void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2163 VisitOMPLoopDirective(D);
2164 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2165}
2166
Alexey Bataev0a6ed842015-12-03 09:40:15 +00002167void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2168 VisitOMPLoopDirective(D);
2169 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2170}
2171
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00002172void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2173 VisitOMPLoopDirective(D);
2174 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2175}
2176
Samuel Antao686c70c2016-05-26 17:30:50 +00002177void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2178 VisitStmt(D);
2179 Record.push_back(D->getNumClauses());
2180 VisitOMPExecutableDirective(D);
2181 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2182}
2183
Carlo Bertolli9925f152016-06-27 14:55:37 +00002184void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2185 OMPDistributeParallelForDirective *D) {
2186 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002187 Record.push_back(D->hasCancel() ? 1 : 0);
Carlo Bertolli9925f152016-06-27 14:55:37 +00002188 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2189}
2190
Kelvin Li4a39add2016-07-05 05:00:15 +00002191void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2192 OMPDistributeParallelForSimdDirective *D) {
2193 VisitOMPLoopDirective(D);
2194 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2195}
2196
Kelvin Li787f3fc2016-07-06 04:45:38 +00002197void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2198 OMPDistributeSimdDirective *D) {
2199 VisitOMPLoopDirective(D);
2200 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2201}
2202
Kelvin Lia579b912016-07-14 02:54:56 +00002203void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2204 OMPTargetParallelForSimdDirective *D) {
2205 VisitOMPLoopDirective(D);
2206 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2207}
2208
Kelvin Li986330c2016-07-20 22:57:10 +00002209void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2210 VisitOMPLoopDirective(D);
2211 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2212}
2213
Kelvin Li02532872016-08-05 14:37:37 +00002214void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2215 OMPTeamsDistributeDirective *D) {
2216 VisitOMPLoopDirective(D);
2217 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2218}
2219
Kelvin Li4e325f72016-10-25 12:50:55 +00002220void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2221 OMPTeamsDistributeSimdDirective *D) {
2222 VisitOMPLoopDirective(D);
2223 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2224}
2225
Kelvin Li579e41c2016-11-30 23:51:03 +00002226void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2227 OMPTeamsDistributeParallelForSimdDirective *D) {
2228 VisitOMPLoopDirective(D);
2229 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2230}
2231
Kelvin Li7ade93f2016-12-09 03:24:30 +00002232void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2233 OMPTeamsDistributeParallelForDirective *D) {
2234 VisitOMPLoopDirective(D);
Alexey Bataevdcb4b8fb2017-11-22 20:19:50 +00002235 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li7ade93f2016-12-09 03:24:30 +00002236 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2237}
2238
Kelvin Libf594a52016-12-17 05:48:59 +00002239void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2240 VisitStmt(D);
2241 Record.push_back(D->getNumClauses());
2242 VisitOMPExecutableDirective(D);
2243 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2244}
2245
Kelvin Li83c451e2016-12-25 04:52:54 +00002246void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2247 OMPTargetTeamsDistributeDirective *D) {
2248 VisitOMPLoopDirective(D);
2249 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2250}
2251
Kelvin Li80e8f562016-12-29 22:16:30 +00002252void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2253 OMPTargetTeamsDistributeParallelForDirective *D) {
2254 VisitOMPLoopDirective(D);
Alexey Bataev16e79882017-11-22 21:12:03 +00002255 Record.push_back(D->hasCancel() ? 1 : 0);
Kelvin Li80e8f562016-12-29 22:16:30 +00002256 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2257}
2258
Kelvin Li1851df52017-01-03 05:23:48 +00002259void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2260 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2261 VisitOMPLoopDirective(D);
2262 Code = serialization::
2263 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2264}
2265
Kelvin Lida681182017-01-10 18:08:18 +00002266void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2267 OMPTargetTeamsDistributeSimdDirective *D) {
2268 VisitOMPLoopDirective(D);
2269 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2270}
2271
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002272//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002273// ASTWriter Implementation
Chris Lattner1f551822009-04-27 06:20:01 +00002274//===----------------------------------------------------------------------===//
2275
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002276unsigned ASTWriter::RecordSwitchCaseID(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 recorded twice");
2279 unsigned NextID = SwitchCaseIDs.size();
2280 SwitchCaseIDs[S] = NextID;
2281 return NextID;
2282}
2283
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002284unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
Mike Stump11289f42009-09-09 15:08:12 +00002285 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
Chris Lattner1f551822009-04-27 06:20:01 +00002286 "SwitchCase hasn't been seen yet");
2287 return SwitchCaseIDs[S];
2288}
2289
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002290void ASTWriter::ClearSwitchCaseIDs() {
2291 SwitchCaseIDs.clear();
2292}
2293
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002294/// Write the given substatement or subexpression to the
Chris Lattner1f551822009-04-27 06:20:01 +00002295/// bitstream.
Richard Smithf50422a2016-04-06 20:12:34 +00002296void ASTWriter::WriteSubStmt(Stmt *S) {
Chris Lattner1f551822009-04-27 06:20:01 +00002297 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002298 ASTStmtWriter Writer(*this, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002299 ++NumStatements;
Fangrui Song6907ce22018-07-30 19:24:48 +00002300
Chris Lattner1f551822009-04-27 06:20:01 +00002301 if (!S) {
Sebastian Redl539c5062010-08-18 23:57:32 +00002302 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
Chris Lattner1f551822009-04-27 06:20:01 +00002303 return;
2304 }
Mike Stump11289f42009-09-09 15:08:12 +00002305
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002306 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2307 if (I != SubStmtEntries.end()) {
2308 Record.push_back(I->second);
2309 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2310 return;
2311 }
2312
2313#ifndef NDEBUG
2314 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2315
2316 struct ParentStmtInserterRAII {
2317 Stmt *S;
2318 llvm::DenseSet<Stmt *> &ParentStmts;
2319
2320 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2321 : S(S), ParentStmts(ParentStmts) {
2322 ParentStmts.insert(S);
2323 }
2324 ~ParentStmtInserterRAII() {
2325 ParentStmts.erase(S);
2326 }
2327 };
2328
2329 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2330#endif
2331
Chris Lattner1f551822009-04-27 06:20:01 +00002332 Writer.Visit(S);
Fangrui Song6907ce22018-07-30 19:24:48 +00002333
Richard Smithb41ddae2016-04-06 20:57:53 +00002334 uint64_t Offset = Writer.Emit();
2335 SubStmtEntries[S] = Offset;
Chris Lattner1f551822009-04-27 06:20:01 +00002336}
2337
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002338/// Flush all of the statements that have been added to the
Chris Lattner1f551822009-04-27 06:20:01 +00002339/// queue via AddStmt().
Richard Smith290d8012016-04-06 17:06:00 +00002340void ASTRecordWriter::FlushStmts() {
Daniel Dunbara5acaa32012-02-29 02:39:13 +00002341 // We expect to be the only consumer of the two temporary statement maps,
2342 // assert that they are empty.
Richard Smith290d8012016-04-06 17:06:00 +00002343 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2344 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002345
Chris Lattner1f551822009-04-27 06:20:01 +00002346 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002347 Writer->WriteSubStmt(StmtsToEmit[I]);
Fangrui Song6907ce22018-07-30 19:24:48 +00002348
Richard Smith290d8012016-04-06 17:06:00 +00002349 assert(N == StmtsToEmit.size() && "record modified while being written!");
Mike Stump11289f42009-09-09 15:08:12 +00002350
Chris Lattner1f551822009-04-27 06:20:01 +00002351 // Note that we are at the end of a full expression. Any
2352 // expression records that follow this one are part of a different
2353 // expression.
Richard Smith290d8012016-04-06 17:06:00 +00002354 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
Argyrios Kyrtzidis6a598972011-10-21 23:02:28 +00002355
Richard Smith290d8012016-04-06 17:06:00 +00002356 Writer->SubStmtEntries.clear();
2357 Writer->ParentStmts.clear();
2358 }
2359
2360 StmtsToEmit.clear();
2361}
2362
2363void ASTRecordWriter::FlushSubStmts() {
2364 // For a nested statement, write out the substatements in reverse order (so
2365 // that a simple stack machine can be used when loading), and don't emit a
2366 // STMT_STOP after each one.
2367 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
Richard Smithf50422a2016-04-06 20:12:34 +00002368 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
Richard Smith290d8012016-04-06 17:06:00 +00002369 assert(N == StmtsToEmit.size() && "record modified while being written!");
Chris Lattner1f551822009-04-27 06:20:01 +00002370 }
Mike Stump11289f42009-09-09 15:08:12 +00002371
Chris Lattner1f551822009-04-27 06:20:01 +00002372 StmtsToEmit.clear();
Chris Lattner1f551822009-04-27 06:20:01 +00002373}