1 //===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Implements serialization for Statements and Expressions.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/AST/ASTConcept.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/DeclTemplate.h"
19 #include "clang/AST/ExprOpenMP.h"
20 #include "clang/AST/StmtVisitor.h"
21 #include "clang/Lex/Token.h"
22 #include "clang/Serialization/ASTReader.h"
23 #include "clang/Serialization/ASTRecordWriter.h"
24 #include "llvm/Bitstream/BitstreamWriter.h"
25 using namespace clang;
26
27 //===----------------------------------------------------------------------===//
28 // Statement/expression serialization
29 //===----------------------------------------------------------------------===//
30
31 namespace clang {
32
33 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
34 ASTWriter &Writer;
35 ASTRecordWriter Record;
36
37 serialization::StmtCode Code;
38 unsigned AbbrevToUse;
39
40 /// A helper that can help us to write a packed bit across function
41 /// calls. For example, we may write separate bits in separate functions:
42 ///
43 /// void VisitA(A* a) {
44 /// Record.push_back(a->isSomething());
45 /// }
46 ///
47 /// void Visitb(B *b) {
48 /// VisitA(b);
49 /// Record.push_back(b->isAnother());
50 /// }
51 ///
52 /// In such cases, it'll be better if we can pack these 2 bits. We achieve
53 /// this by writing a zero value in `VisitA` and recorded that first and add
54 /// the new bit to the recorded value.
55 class PakedBitsWriter {
56 public:
PakedBitsWriter(ASTRecordWriter & Record)57 PakedBitsWriter(ASTRecordWriter &Record) : RecordRef(Record) {}
~PakedBitsWriter()58 ~PakedBitsWriter() { assert(!CurrentIndex); }
59
addBit(bool Value)60 void addBit(bool Value) {
61 assert(CurrentIndex && "Writing Bits without recording first!");
62 PackingBits.addBit(Value);
63 }
addBits(uint32_t Value,uint32_t BitsWidth)64 void addBits(uint32_t Value, uint32_t BitsWidth) {
65 assert(CurrentIndex && "Writing Bits without recording first!");
66 PackingBits.addBits(Value, BitsWidth);
67 }
68
writeBits()69 void writeBits() {
70 if (!CurrentIndex)
71 return;
72
73 RecordRef[*CurrentIndex] = (uint32_t)PackingBits;
74 CurrentIndex = std::nullopt;
75 PackingBits.reset(0);
76 }
77
updateBits()78 void updateBits() {
79 writeBits();
80
81 CurrentIndex = RecordRef.size();
82 RecordRef.push_back(0);
83 }
84
85 private:
86 BitsPacker PackingBits;
87 ASTRecordWriter &RecordRef;
88 std::optional<unsigned> CurrentIndex;
89 };
90
91 PakedBitsWriter CurrentPackingBits;
92
93 public:
ASTStmtWriter(ASTWriter & Writer,ASTWriter::RecordData & Record)94 ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
95 : Writer(Writer), Record(Writer, Record),
96 Code(serialization::STMT_NULL_PTR), AbbrevToUse(0),
97 CurrentPackingBits(this->Record) {}
98
99 ASTStmtWriter(const ASTStmtWriter&) = delete;
100 ASTStmtWriter &operator=(const ASTStmtWriter &) = delete;
101
Emit()102 uint64_t Emit() {
103 CurrentPackingBits.writeBits();
104 assert(Code != serialization::STMT_NULL_PTR &&
105 "unhandled sub-statement writing AST file");
106 return Record.EmitStmt(Code, AbbrevToUse);
107 }
108
109 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo,
110 const TemplateArgumentLoc *Args);
111
112 void VisitStmt(Stmt *S);
113 #define STMT(Type, Base) \
114 void Visit##Type(Type *);
115 #include "clang/AST/StmtNodes.inc"
116 };
117 }
118
AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo & ArgInfo,const TemplateArgumentLoc * Args)119 void ASTStmtWriter::AddTemplateKWAndArgsInfo(
120 const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) {
121 Record.AddSourceLocation(ArgInfo.TemplateKWLoc);
122 Record.AddSourceLocation(ArgInfo.LAngleLoc);
123 Record.AddSourceLocation(ArgInfo.RAngleLoc);
124 for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i)
125 Record.AddTemplateArgumentLoc(Args[i]);
126 }
127
VisitStmt(Stmt * S)128 void ASTStmtWriter::VisitStmt(Stmt *S) {
129 }
130
VisitNullStmt(NullStmt * S)131 void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
132 VisitStmt(S);
133 Record.AddSourceLocation(S->getSemiLoc());
134 Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro);
135 Code = serialization::STMT_NULL;
136 }
137
VisitCompoundStmt(CompoundStmt * S)138 void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
139 VisitStmt(S);
140
141 Record.push_back(S->size());
142 Record.push_back(S->hasStoredFPFeatures());
143
144 for (auto *CS : S->body())
145 Record.AddStmt(CS);
146 if (S->hasStoredFPFeatures())
147 Record.push_back(S->getStoredFPFeatures().getAsOpaqueInt());
148 Record.AddSourceLocation(S->getLBracLoc());
149 Record.AddSourceLocation(S->getRBracLoc());
150
151 if (!S->hasStoredFPFeatures())
152 AbbrevToUse = Writer.getCompoundStmtAbbrev();
153
154 Code = serialization::STMT_COMPOUND;
155 }
156
VisitSwitchCase(SwitchCase * S)157 void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
158 VisitStmt(S);
159 Record.push_back(Writer.getSwitchCaseID(S));
160 Record.AddSourceLocation(S->getKeywordLoc());
161 Record.AddSourceLocation(S->getColonLoc());
162 }
163
VisitCaseStmt(CaseStmt * S)164 void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
165 VisitSwitchCase(S);
166 Record.push_back(S->caseStmtIsGNURange());
167 Record.AddStmt(S->getLHS());
168 Record.AddStmt(S->getSubStmt());
169 if (S->caseStmtIsGNURange()) {
170 Record.AddStmt(S->getRHS());
171 Record.AddSourceLocation(S->getEllipsisLoc());
172 }
173 Code = serialization::STMT_CASE;
174 }
175
VisitDefaultStmt(DefaultStmt * S)176 void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
177 VisitSwitchCase(S);
178 Record.AddStmt(S->getSubStmt());
179 Code = serialization::STMT_DEFAULT;
180 }
181
VisitLabelStmt(LabelStmt * S)182 void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
183 VisitStmt(S);
184 Record.push_back(S->isSideEntry());
185 Record.AddDeclRef(S->getDecl());
186 Record.AddStmt(S->getSubStmt());
187 Record.AddSourceLocation(S->getIdentLoc());
188 Code = serialization::STMT_LABEL;
189 }
190
VisitAttributedStmt(AttributedStmt * S)191 void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
192 VisitStmt(S);
193 Record.push_back(S->getAttrs().size());
194 Record.AddAttributes(S->getAttrs());
195 Record.AddStmt(S->getSubStmt());
196 Record.AddSourceLocation(S->getAttrLoc());
197 Code = serialization::STMT_ATTRIBUTED;
198 }
199
VisitIfStmt(IfStmt * S)200 void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
201 VisitStmt(S);
202
203 bool HasElse = S->getElse() != nullptr;
204 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
205 bool HasInit = S->getInit() != nullptr;
206
207 CurrentPackingBits.updateBits();
208
209 CurrentPackingBits.addBit(HasElse);
210 CurrentPackingBits.addBit(HasVar);
211 CurrentPackingBits.addBit(HasInit);
212 Record.push_back(static_cast<uint64_t>(S->getStatementKind()));
213 Record.AddStmt(S->getCond());
214 Record.AddStmt(S->getThen());
215 if (HasElse)
216 Record.AddStmt(S->getElse());
217 if (HasVar)
218 Record.AddStmt(S->getConditionVariableDeclStmt());
219 if (HasInit)
220 Record.AddStmt(S->getInit());
221
222 Record.AddSourceLocation(S->getIfLoc());
223 Record.AddSourceLocation(S->getLParenLoc());
224 Record.AddSourceLocation(S->getRParenLoc());
225 if (HasElse)
226 Record.AddSourceLocation(S->getElseLoc());
227
228 Code = serialization::STMT_IF;
229 }
230
VisitSwitchStmt(SwitchStmt * S)231 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
232 VisitStmt(S);
233
234 bool HasInit = S->getInit() != nullptr;
235 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
236 Record.push_back(HasInit);
237 Record.push_back(HasVar);
238 Record.push_back(S->isAllEnumCasesCovered());
239
240 Record.AddStmt(S->getCond());
241 Record.AddStmt(S->getBody());
242 if (HasInit)
243 Record.AddStmt(S->getInit());
244 if (HasVar)
245 Record.AddStmt(S->getConditionVariableDeclStmt());
246
247 Record.AddSourceLocation(S->getSwitchLoc());
248 Record.AddSourceLocation(S->getLParenLoc());
249 Record.AddSourceLocation(S->getRParenLoc());
250
251 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
252 SC = SC->getNextSwitchCase())
253 Record.push_back(Writer.RecordSwitchCaseID(SC));
254 Code = serialization::STMT_SWITCH;
255 }
256
VisitWhileStmt(WhileStmt * S)257 void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
258 VisitStmt(S);
259
260 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
261 Record.push_back(HasVar);
262
263 Record.AddStmt(S->getCond());
264 Record.AddStmt(S->getBody());
265 if (HasVar)
266 Record.AddStmt(S->getConditionVariableDeclStmt());
267
268 Record.AddSourceLocation(S->getWhileLoc());
269 Record.AddSourceLocation(S->getLParenLoc());
270 Record.AddSourceLocation(S->getRParenLoc());
271 Code = serialization::STMT_WHILE;
272 }
273
VisitDoStmt(DoStmt * S)274 void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
275 VisitStmt(S);
276 Record.AddStmt(S->getCond());
277 Record.AddStmt(S->getBody());
278 Record.AddSourceLocation(S->getDoLoc());
279 Record.AddSourceLocation(S->getWhileLoc());
280 Record.AddSourceLocation(S->getRParenLoc());
281 Code = serialization::STMT_DO;
282 }
283
VisitForStmt(ForStmt * S)284 void ASTStmtWriter::VisitForStmt(ForStmt *S) {
285 VisitStmt(S);
286 Record.AddStmt(S->getInit());
287 Record.AddStmt(S->getCond());
288 Record.AddStmt(S->getConditionVariableDeclStmt());
289 Record.AddStmt(S->getInc());
290 Record.AddStmt(S->getBody());
291 Record.AddSourceLocation(S->getForLoc());
292 Record.AddSourceLocation(S->getLParenLoc());
293 Record.AddSourceLocation(S->getRParenLoc());
294 Code = serialization::STMT_FOR;
295 }
296
VisitGotoStmt(GotoStmt * S)297 void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
298 VisitStmt(S);
299 Record.AddDeclRef(S->getLabel());
300 Record.AddSourceLocation(S->getGotoLoc());
301 Record.AddSourceLocation(S->getLabelLoc());
302 Code = serialization::STMT_GOTO;
303 }
304
VisitIndirectGotoStmt(IndirectGotoStmt * S)305 void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
306 VisitStmt(S);
307 Record.AddSourceLocation(S->getGotoLoc());
308 Record.AddSourceLocation(S->getStarLoc());
309 Record.AddStmt(S->getTarget());
310 Code = serialization::STMT_INDIRECT_GOTO;
311 }
312
VisitContinueStmt(ContinueStmt * S)313 void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
314 VisitStmt(S);
315 Record.AddSourceLocation(S->getContinueLoc());
316 Code = serialization::STMT_CONTINUE;
317 }
318
VisitBreakStmt(BreakStmt * S)319 void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
320 VisitStmt(S);
321 Record.AddSourceLocation(S->getBreakLoc());
322 Code = serialization::STMT_BREAK;
323 }
324
VisitReturnStmt(ReturnStmt * S)325 void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
326 VisitStmt(S);
327
328 bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr;
329 Record.push_back(HasNRVOCandidate);
330
331 Record.AddStmt(S->getRetValue());
332 if (HasNRVOCandidate)
333 Record.AddDeclRef(S->getNRVOCandidate());
334
335 Record.AddSourceLocation(S->getReturnLoc());
336 Code = serialization::STMT_RETURN;
337 }
338
VisitDeclStmt(DeclStmt * S)339 void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
340 VisitStmt(S);
341 Record.AddSourceLocation(S->getBeginLoc());
342 Record.AddSourceLocation(S->getEndLoc());
343 DeclGroupRef DG = S->getDeclGroup();
344 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
345 Record.AddDeclRef(*D);
346 Code = serialization::STMT_DECL;
347 }
348
VisitAsmStmt(AsmStmt * S)349 void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
350 VisitStmt(S);
351 Record.push_back(S->getNumOutputs());
352 Record.push_back(S->getNumInputs());
353 Record.push_back(S->getNumClobbers());
354 Record.AddSourceLocation(S->getAsmLoc());
355 Record.push_back(S->isVolatile());
356 Record.push_back(S->isSimple());
357 }
358
VisitGCCAsmStmt(GCCAsmStmt * S)359 void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
360 VisitAsmStmt(S);
361 Record.push_back(S->getNumLabels());
362 Record.AddSourceLocation(S->getRParenLoc());
363 Record.AddStmt(S->getAsmString());
364
365 // Outputs
366 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
367 Record.AddIdentifierRef(S->getOutputIdentifier(I));
368 Record.AddStmt(S->getOutputConstraintLiteral(I));
369 Record.AddStmt(S->getOutputExpr(I));
370 }
371
372 // Inputs
373 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
374 Record.AddIdentifierRef(S->getInputIdentifier(I));
375 Record.AddStmt(S->getInputConstraintLiteral(I));
376 Record.AddStmt(S->getInputExpr(I));
377 }
378
379 // Clobbers
380 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
381 Record.AddStmt(S->getClobberStringLiteral(I));
382
383 // Labels
384 for (unsigned I = 0, N = S->getNumLabels(); I != N; ++I) {
385 Record.AddIdentifierRef(S->getLabelIdentifier(I));
386 Record.AddStmt(S->getLabelExpr(I));
387 }
388
389 Code = serialization::STMT_GCCASM;
390 }
391
VisitMSAsmStmt(MSAsmStmt * S)392 void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
393 VisitAsmStmt(S);
394 Record.AddSourceLocation(S->getLBraceLoc());
395 Record.AddSourceLocation(S->getEndLoc());
396 Record.push_back(S->getNumAsmToks());
397 Record.AddString(S->getAsmString());
398
399 // Tokens
400 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
401 // FIXME: Move this to ASTRecordWriter?
402 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
403 }
404
405 // Clobbers
406 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
407 Record.AddString(S->getClobber(I));
408 }
409
410 // Outputs
411 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
412 Record.AddStmt(S->getOutputExpr(I));
413 Record.AddString(S->getOutputConstraint(I));
414 }
415
416 // Inputs
417 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
418 Record.AddStmt(S->getInputExpr(I));
419 Record.AddString(S->getInputConstraint(I));
420 }
421
422 Code = serialization::STMT_MSASM;
423 }
424
VisitCoroutineBodyStmt(CoroutineBodyStmt * CoroStmt)425 void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
426 VisitStmt(CoroStmt);
427 Record.push_back(CoroStmt->getParamMoves().size());
428 for (Stmt *S : CoroStmt->children())
429 Record.AddStmt(S);
430 Code = serialization::STMT_COROUTINE_BODY;
431 }
432
VisitCoreturnStmt(CoreturnStmt * S)433 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
434 VisitStmt(S);
435 Record.AddSourceLocation(S->getKeywordLoc());
436 Record.AddStmt(S->getOperand());
437 Record.AddStmt(S->getPromiseCall());
438 Record.push_back(S->isImplicit());
439 Code = serialization::STMT_CORETURN;
440 }
441
VisitCoroutineSuspendExpr(CoroutineSuspendExpr * E)442 void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
443 VisitExpr(E);
444 Record.AddSourceLocation(E->getKeywordLoc());
445 for (Stmt *S : E->children())
446 Record.AddStmt(S);
447 Record.AddStmt(E->getOpaqueValue());
448 }
449
VisitCoawaitExpr(CoawaitExpr * E)450 void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
451 VisitCoroutineSuspendExpr(E);
452 Record.push_back(E->isImplicit());
453 Code = serialization::EXPR_COAWAIT;
454 }
455
VisitCoyieldExpr(CoyieldExpr * E)456 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
457 VisitCoroutineSuspendExpr(E);
458 Code = serialization::EXPR_COYIELD;
459 }
460
VisitDependentCoawaitExpr(DependentCoawaitExpr * E)461 void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
462 VisitExpr(E);
463 Record.AddSourceLocation(E->getKeywordLoc());
464 for (Stmt *S : E->children())
465 Record.AddStmt(S);
466 Code = serialization::EXPR_DEPENDENT_COAWAIT;
467 }
468
469 static void
addConstraintSatisfaction(ASTRecordWriter & Record,const ASTConstraintSatisfaction & Satisfaction)470 addConstraintSatisfaction(ASTRecordWriter &Record,
471 const ASTConstraintSatisfaction &Satisfaction) {
472 Record.push_back(Satisfaction.IsSatisfied);
473 Record.push_back(Satisfaction.ContainsErrors);
474 if (!Satisfaction.IsSatisfied) {
475 Record.push_back(Satisfaction.NumRecords);
476 for (const auto &DetailRecord : Satisfaction) {
477 auto *E = DetailRecord.dyn_cast<Expr *>();
478 Record.push_back(/* IsDiagnostic */ E == nullptr);
479 if (E)
480 Record.AddStmt(E);
481 else {
482 auto *Diag = DetailRecord.get<std::pair<SourceLocation, StringRef> *>();
483 Record.AddSourceLocation(Diag->first);
484 Record.AddString(Diag->second);
485 }
486 }
487 }
488 }
489
490 static void
addSubstitutionDiagnostic(ASTRecordWriter & Record,const concepts::Requirement::SubstitutionDiagnostic * D)491 addSubstitutionDiagnostic(
492 ASTRecordWriter &Record,
493 const concepts::Requirement::SubstitutionDiagnostic *D) {
494 Record.AddString(D->SubstitutedEntity);
495 Record.AddSourceLocation(D->DiagLoc);
496 Record.AddString(D->DiagMessage);
497 }
498
VisitConceptSpecializationExpr(ConceptSpecializationExpr * E)499 void ASTStmtWriter::VisitConceptSpecializationExpr(
500 ConceptSpecializationExpr *E) {
501 VisitExpr(E);
502 Record.AddDeclRef(E->getSpecializationDecl());
503 const ConceptReference *CR = E->getConceptReference();
504 Record.push_back(CR != nullptr);
505 if (CR)
506 Record.AddConceptReference(CR);
507 if (!E->isValueDependent())
508 addConstraintSatisfaction(Record, E->getSatisfaction());
509
510 Code = serialization::EXPR_CONCEPT_SPECIALIZATION;
511 }
512
VisitRequiresExpr(RequiresExpr * E)513 void ASTStmtWriter::VisitRequiresExpr(RequiresExpr *E) {
514 VisitExpr(E);
515 Record.push_back(E->getLocalParameters().size());
516 Record.push_back(E->getRequirements().size());
517 Record.AddSourceLocation(E->RequiresExprBits.RequiresKWLoc);
518 Record.push_back(E->RequiresExprBits.IsSatisfied);
519 Record.AddDeclRef(E->getBody());
520 for (ParmVarDecl *P : E->getLocalParameters())
521 Record.AddDeclRef(P);
522 for (concepts::Requirement *R : E->getRequirements()) {
523 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(R)) {
524 Record.push_back(concepts::Requirement::RK_Type);
525 Record.push_back(TypeReq->Status);
526 if (TypeReq->Status == concepts::TypeRequirement::SS_SubstitutionFailure)
527 addSubstitutionDiagnostic(Record, TypeReq->getSubstitutionDiagnostic());
528 else
529 Record.AddTypeSourceInfo(TypeReq->getType());
530 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(R)) {
531 Record.push_back(ExprReq->getKind());
532 Record.push_back(ExprReq->Status);
533 if (ExprReq->isExprSubstitutionFailure()) {
534 addSubstitutionDiagnostic(Record,
535 ExprReq->Value.get<concepts::Requirement::SubstitutionDiagnostic *>());
536 } else
537 Record.AddStmt(ExprReq->Value.get<Expr *>());
538 if (ExprReq->getKind() == concepts::Requirement::RK_Compound) {
539 Record.AddSourceLocation(ExprReq->NoexceptLoc);
540 const auto &RetReq = ExprReq->getReturnTypeRequirement();
541 if (RetReq.isSubstitutionFailure()) {
542 Record.push_back(2);
543 addSubstitutionDiagnostic(Record, RetReq.getSubstitutionDiagnostic());
544 } else if (RetReq.isTypeConstraint()) {
545 Record.push_back(1);
546 Record.AddTemplateParameterList(
547 RetReq.getTypeConstraintTemplateParameterList());
548 if (ExprReq->Status >=
549 concepts::ExprRequirement::SS_ConstraintsNotSatisfied)
550 Record.AddStmt(
551 ExprReq->getReturnTypeRequirementSubstitutedConstraintExpr());
552 } else {
553 assert(RetReq.isEmpty());
554 Record.push_back(0);
555 }
556 }
557 } else {
558 auto *NestedReq = cast<concepts::NestedRequirement>(R);
559 Record.push_back(concepts::Requirement::RK_Nested);
560 Record.push_back(NestedReq->hasInvalidConstraint());
561 if (NestedReq->hasInvalidConstraint()) {
562 Record.AddString(NestedReq->getInvalidConstraintEntity());
563 addConstraintSatisfaction(Record, *NestedReq->Satisfaction);
564 } else {
565 Record.AddStmt(NestedReq->getConstraintExpr());
566 if (!NestedReq->isDependent())
567 addConstraintSatisfaction(Record, *NestedReq->Satisfaction);
568 }
569 }
570 }
571 Record.AddSourceLocation(E->getLParenLoc());
572 Record.AddSourceLocation(E->getRParenLoc());
573 Record.AddSourceLocation(E->getEndLoc());
574
575 Code = serialization::EXPR_REQUIRES;
576 }
577
578
VisitCapturedStmt(CapturedStmt * S)579 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
580 VisitStmt(S);
581 // NumCaptures
582 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
583
584 // CapturedDecl and captured region kind
585 Record.AddDeclRef(S->getCapturedDecl());
586 Record.push_back(S->getCapturedRegionKind());
587
588 Record.AddDeclRef(S->getCapturedRecordDecl());
589
590 // Capture inits
591 for (auto *I : S->capture_inits())
592 Record.AddStmt(I);
593
594 // Body
595 Record.AddStmt(S->getCapturedStmt());
596
597 // Captures
598 for (const auto &I : S->captures()) {
599 if (I.capturesThis() || I.capturesVariableArrayType())
600 Record.AddDeclRef(nullptr);
601 else
602 Record.AddDeclRef(I.getCapturedVar());
603 Record.push_back(I.getCaptureKind());
604 Record.AddSourceLocation(I.getLocation());
605 }
606
607 Code = serialization::STMT_CAPTURED;
608 }
609
VisitExpr(Expr * E)610 void ASTStmtWriter::VisitExpr(Expr *E) {
611 VisitStmt(E);
612
613 CurrentPackingBits.updateBits();
614 CurrentPackingBits.addBits(E->getDependence(), /*BitsWidth=*/5);
615 CurrentPackingBits.addBits(E->getValueKind(), /*BitsWidth=*/2);
616 CurrentPackingBits.addBits(E->getObjectKind(), /*BitsWidth=*/3);
617
618 Record.AddTypeRef(E->getType());
619 }
620
VisitConstantExpr(ConstantExpr * E)621 void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
622 VisitExpr(E);
623 Record.push_back(E->ConstantExprBits.ResultKind);
624
625 Record.push_back(E->ConstantExprBits.APValueKind);
626 Record.push_back(E->ConstantExprBits.IsUnsigned);
627 Record.push_back(E->ConstantExprBits.BitWidth);
628 // HasCleanup not serialized since we can just query the APValue.
629 Record.push_back(E->ConstantExprBits.IsImmediateInvocation);
630
631 switch (E->getResultStorageKind()) {
632 case ConstantResultStorageKind::None:
633 break;
634 case ConstantResultStorageKind::Int64:
635 Record.push_back(E->Int64Result());
636 break;
637 case ConstantResultStorageKind::APValue:
638 Record.AddAPValue(E->APValueResult());
639 break;
640 }
641
642 Record.AddStmt(E->getSubExpr());
643 Code = serialization::EXPR_CONSTANT;
644 }
645
VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr * E)646 void ASTStmtWriter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
647 VisitExpr(E);
648
649 Record.AddSourceLocation(E->getLocation());
650 Record.AddSourceLocation(E->getLParenLocation());
651 Record.AddSourceLocation(E->getRParenLocation());
652 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
653
654 Code = serialization::EXPR_SYCL_UNIQUE_STABLE_NAME;
655 }
656
VisitPredefinedExpr(PredefinedExpr * E)657 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
658 VisitExpr(E);
659
660 bool HasFunctionName = E->getFunctionName() != nullptr;
661 Record.push_back(HasFunctionName);
662 Record.push_back(
663 llvm::to_underlying(E->getIdentKind())); // FIXME: stable encoding
664 Record.push_back(E->isTransparent());
665 Record.AddSourceLocation(E->getLocation());
666 if (HasFunctionName)
667 Record.AddStmt(E->getFunctionName());
668 Code = serialization::EXPR_PREDEFINED;
669 }
670
VisitDeclRefExpr(DeclRefExpr * E)671 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
672 VisitExpr(E);
673
674 CurrentPackingBits.updateBits();
675
676 CurrentPackingBits.addBit(E->hadMultipleCandidates());
677 CurrentPackingBits.addBit(E->refersToEnclosingVariableOrCapture());
678 CurrentPackingBits.addBits(E->isNonOdrUse(), /*Width=*/2);
679 CurrentPackingBits.addBit(E->isImmediateEscalating());
680 CurrentPackingBits.addBit(E->getDecl() != E->getFoundDecl());
681 CurrentPackingBits.addBit(E->hasQualifier());
682 CurrentPackingBits.addBit(E->hasTemplateKWAndArgsInfo());
683
684 if (E->hasTemplateKWAndArgsInfo()) {
685 unsigned NumTemplateArgs = E->getNumTemplateArgs();
686 Record.push_back(NumTemplateArgs);
687 }
688
689 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
690
691 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
692 (E->getDecl() == E->getFoundDecl()) &&
693 nk == DeclarationName::Identifier && E->getObjectKind() == OK_Ordinary) {
694 AbbrevToUse = Writer.getDeclRefExprAbbrev();
695 }
696
697 if (E->hasQualifier())
698 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
699
700 if (E->getDecl() != E->getFoundDecl())
701 Record.AddDeclRef(E->getFoundDecl());
702
703 if (E->hasTemplateKWAndArgsInfo())
704 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
705 E->getTrailingObjects<TemplateArgumentLoc>());
706
707 Record.AddDeclRef(E->getDecl());
708 Record.AddSourceLocation(E->getLocation());
709 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
710 Code = serialization::EXPR_DECL_REF;
711 }
712
VisitIntegerLiteral(IntegerLiteral * E)713 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
714 VisitExpr(E);
715 Record.AddSourceLocation(E->getLocation());
716 Record.AddAPInt(E->getValue());
717
718 if (E->getValue().getBitWidth() == 32) {
719 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
720 }
721
722 Code = serialization::EXPR_INTEGER_LITERAL;
723 }
724
VisitFixedPointLiteral(FixedPointLiteral * E)725 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
726 VisitExpr(E);
727 Record.AddSourceLocation(E->getLocation());
728 Record.push_back(E->getScale());
729 Record.AddAPInt(E->getValue());
730 Code = serialization::EXPR_FIXEDPOINT_LITERAL;
731 }
732
VisitFloatingLiteral(FloatingLiteral * E)733 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
734 VisitExpr(E);
735 Record.push_back(E->getRawSemantics());
736 Record.push_back(E->isExact());
737 Record.AddAPFloat(E->getValue());
738 Record.AddSourceLocation(E->getLocation());
739 Code = serialization::EXPR_FLOATING_LITERAL;
740 }
741
VisitImaginaryLiteral(ImaginaryLiteral * E)742 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
743 VisitExpr(E);
744 Record.AddStmt(E->getSubExpr());
745 Code = serialization::EXPR_IMAGINARY_LITERAL;
746 }
747
VisitStringLiteral(StringLiteral * E)748 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
749 VisitExpr(E);
750
751 // Store the various bits of data of StringLiteral.
752 Record.push_back(E->getNumConcatenated());
753 Record.push_back(E->getLength());
754 Record.push_back(E->getCharByteWidth());
755 Record.push_back(llvm::to_underlying(E->getKind()));
756 Record.push_back(E->isPascal());
757
758 // Store the trailing array of SourceLocation.
759 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
760 Record.AddSourceLocation(E->getStrTokenLoc(I));
761
762 // Store the trailing array of char holding the string data.
763 StringRef StrData = E->getBytes();
764 for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
765 Record.push_back(StrData[I]);
766
767 Code = serialization::EXPR_STRING_LITERAL;
768 }
769
VisitCharacterLiteral(CharacterLiteral * E)770 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
771 VisitExpr(E);
772 Record.push_back(E->getValue());
773 Record.AddSourceLocation(E->getLocation());
774 Record.push_back(llvm::to_underlying(E->getKind()));
775
776 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
777
778 Code = serialization::EXPR_CHARACTER_LITERAL;
779 }
780
VisitParenExpr(ParenExpr * E)781 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
782 VisitExpr(E);
783 Record.AddSourceLocation(E->getLParen());
784 Record.AddSourceLocation(E->getRParen());
785 Record.AddStmt(E->getSubExpr());
786 Code = serialization::EXPR_PAREN;
787 }
788
VisitParenListExpr(ParenListExpr * E)789 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
790 VisitExpr(E);
791 Record.push_back(E->getNumExprs());
792 for (auto *SubStmt : E->exprs())
793 Record.AddStmt(SubStmt);
794 Record.AddSourceLocation(E->getLParenLoc());
795 Record.AddSourceLocation(E->getRParenLoc());
796 Code = serialization::EXPR_PAREN_LIST;
797 }
798
VisitUnaryOperator(UnaryOperator * E)799 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
800 VisitExpr(E);
801 bool HasFPFeatures = E->hasStoredFPFeatures();
802 // Write this first for easy access when deserializing, as they affect the
803 // size of the UnaryOperator.
804 CurrentPackingBits.addBit(HasFPFeatures);
805 Record.AddStmt(E->getSubExpr());
806 CurrentPackingBits.addBits(E->getOpcode(),
807 /*Width=*/5); // FIXME: stable encoding
808 Record.AddSourceLocation(E->getOperatorLoc());
809 CurrentPackingBits.addBit(E->canOverflow());
810
811 if (HasFPFeatures)
812 Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt());
813 Code = serialization::EXPR_UNARY_OPERATOR;
814 }
815
VisitOffsetOfExpr(OffsetOfExpr * E)816 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
817 VisitExpr(E);
818 Record.push_back(E->getNumComponents());
819 Record.push_back(E->getNumExpressions());
820 Record.AddSourceLocation(E->getOperatorLoc());
821 Record.AddSourceLocation(E->getRParenLoc());
822 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
823 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
824 const OffsetOfNode &ON = E->getComponent(I);
825 Record.push_back(ON.getKind()); // FIXME: Stable encoding
826 Record.AddSourceLocation(ON.getSourceRange().getBegin());
827 Record.AddSourceLocation(ON.getSourceRange().getEnd());
828 switch (ON.getKind()) {
829 case OffsetOfNode::Array:
830 Record.push_back(ON.getArrayExprIndex());
831 break;
832
833 case OffsetOfNode::Field:
834 Record.AddDeclRef(ON.getField());
835 break;
836
837 case OffsetOfNode::Identifier:
838 Record.AddIdentifierRef(ON.getFieldName());
839 break;
840
841 case OffsetOfNode::Base:
842 Record.AddCXXBaseSpecifier(*ON.getBase());
843 break;
844 }
845 }
846 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
847 Record.AddStmt(E->getIndexExpr(I));
848 Code = serialization::EXPR_OFFSETOF;
849 }
850
VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr * E)851 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
852 VisitExpr(E);
853 Record.push_back(E->getKind());
854 if (E->isArgumentType())
855 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
856 else {
857 Record.push_back(0);
858 Record.AddStmt(E->getArgumentExpr());
859 }
860 Record.AddSourceLocation(E->getOperatorLoc());
861 Record.AddSourceLocation(E->getRParenLoc());
862 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
863 }
864
VisitArraySubscriptExpr(ArraySubscriptExpr * E)865 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
866 VisitExpr(E);
867 Record.AddStmt(E->getLHS());
868 Record.AddStmt(E->getRHS());
869 Record.AddSourceLocation(E->getRBracketLoc());
870 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
871 }
872
VisitMatrixSubscriptExpr(MatrixSubscriptExpr * E)873 void ASTStmtWriter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
874 VisitExpr(E);
875 Record.AddStmt(E->getBase());
876 Record.AddStmt(E->getRowIdx());
877 Record.AddStmt(E->getColumnIdx());
878 Record.AddSourceLocation(E->getRBracketLoc());
879 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
880 }
881
VisitArraySectionExpr(ArraySectionExpr * E)882 void ASTStmtWriter::VisitArraySectionExpr(ArraySectionExpr *E) {
883 VisitExpr(E);
884 Record.writeEnum(E->ASType);
885 Record.AddStmt(E->getBase());
886 Record.AddStmt(E->getLowerBound());
887 Record.AddStmt(E->getLength());
888 if (E->isOMPArraySection())
889 Record.AddStmt(E->getStride());
890 Record.AddSourceLocation(E->getColonLocFirst());
891
892 if (E->isOMPArraySection())
893 Record.AddSourceLocation(E->getColonLocSecond());
894
895 Record.AddSourceLocation(E->getRBracketLoc());
896 Code = serialization::EXPR_ARRAY_SECTION;
897 }
898
VisitOMPArrayShapingExpr(OMPArrayShapingExpr * E)899 void ASTStmtWriter::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
900 VisitExpr(E);
901 Record.push_back(E->getDimensions().size());
902 Record.AddStmt(E->getBase());
903 for (Expr *Dim : E->getDimensions())
904 Record.AddStmt(Dim);
905 for (SourceRange SR : E->getBracketsRanges())
906 Record.AddSourceRange(SR);
907 Record.AddSourceLocation(E->getLParenLoc());
908 Record.AddSourceLocation(E->getRParenLoc());
909 Code = serialization::EXPR_OMP_ARRAY_SHAPING;
910 }
911
VisitOMPIteratorExpr(OMPIteratorExpr * E)912 void ASTStmtWriter::VisitOMPIteratorExpr(OMPIteratorExpr *E) {
913 VisitExpr(E);
914 Record.push_back(E->numOfIterators());
915 Record.AddSourceLocation(E->getIteratorKwLoc());
916 Record.AddSourceLocation(E->getLParenLoc());
917 Record.AddSourceLocation(E->getRParenLoc());
918 for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) {
919 Record.AddDeclRef(E->getIteratorDecl(I));
920 Record.AddSourceLocation(E->getAssignLoc(I));
921 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
922 Record.AddStmt(Range.Begin);
923 Record.AddStmt(Range.End);
924 Record.AddStmt(Range.Step);
925 Record.AddSourceLocation(E->getColonLoc(I));
926 if (Range.Step)
927 Record.AddSourceLocation(E->getSecondColonLoc(I));
928 // Serialize helpers
929 OMPIteratorHelperData &HD = E->getHelper(I);
930 Record.AddDeclRef(HD.CounterVD);
931 Record.AddStmt(HD.Upper);
932 Record.AddStmt(HD.Update);
933 Record.AddStmt(HD.CounterUpdate);
934 }
935 Code = serialization::EXPR_OMP_ITERATOR;
936 }
937
VisitCallExpr(CallExpr * E)938 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
939 VisitExpr(E);
940
941 Record.push_back(E->getNumArgs());
942 CurrentPackingBits.updateBits();
943 CurrentPackingBits.addBit(static_cast<bool>(E->getADLCallKind()));
944 CurrentPackingBits.addBit(E->hasStoredFPFeatures());
945
946 Record.AddSourceLocation(E->getRParenLoc());
947 Record.AddStmt(E->getCallee());
948 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
949 Arg != ArgEnd; ++Arg)
950 Record.AddStmt(*Arg);
951
952 if (E->hasStoredFPFeatures())
953 Record.push_back(E->getFPFeatures().getAsOpaqueInt());
954
955 if (!E->hasStoredFPFeatures() && !static_cast<bool>(E->getADLCallKind()) &&
956 E->getStmtClass() == Stmt::CallExprClass)
957 AbbrevToUse = Writer.getCallExprAbbrev();
958
959 Code = serialization::EXPR_CALL;
960 }
961
VisitRecoveryExpr(RecoveryExpr * E)962 void ASTStmtWriter::VisitRecoveryExpr(RecoveryExpr *E) {
963 VisitExpr(E);
964 Record.push_back(std::distance(E->children().begin(), E->children().end()));
965 Record.AddSourceLocation(E->getBeginLoc());
966 Record.AddSourceLocation(E->getEndLoc());
967 for (Stmt *Child : E->children())
968 Record.AddStmt(Child);
969 Code = serialization::EXPR_RECOVERY;
970 }
971
VisitMemberExpr(MemberExpr * E)972 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
973 VisitExpr(E);
974
975 bool HasQualifier = E->hasQualifier();
976 bool HasFoundDecl = E->hasFoundDecl();
977 bool HasTemplateInfo = E->hasTemplateKWAndArgsInfo();
978 unsigned NumTemplateArgs = E->getNumTemplateArgs();
979
980 // Write these first for easy access when deserializing, as they affect the
981 // size of the MemberExpr.
982 CurrentPackingBits.updateBits();
983 CurrentPackingBits.addBit(HasQualifier);
984 CurrentPackingBits.addBit(HasFoundDecl);
985 CurrentPackingBits.addBit(HasTemplateInfo);
986 Record.push_back(NumTemplateArgs);
987
988 Record.AddStmt(E->getBase());
989 Record.AddDeclRef(E->getMemberDecl());
990 Record.AddDeclarationNameLoc(E->MemberDNLoc,
991 E->getMemberDecl()->getDeclName());
992 Record.AddSourceLocation(E->getMemberLoc());
993 CurrentPackingBits.addBit(E->isArrow());
994 CurrentPackingBits.addBit(E->hadMultipleCandidates());
995 CurrentPackingBits.addBits(E->isNonOdrUse(), /*Width=*/2);
996 Record.AddSourceLocation(E->getOperatorLoc());
997
998 if (HasQualifier)
999 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1000
1001 if (HasFoundDecl) {
1002 DeclAccessPair FoundDecl = E->getFoundDecl();
1003 Record.AddDeclRef(FoundDecl.getDecl());
1004 CurrentPackingBits.addBits(FoundDecl.getAccess(), /*BitWidth=*/2);
1005 }
1006
1007 if (HasTemplateInfo)
1008 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
1009 E->getTrailingObjects<TemplateArgumentLoc>());
1010
1011 Code = serialization::EXPR_MEMBER;
1012 }
1013
VisitObjCIsaExpr(ObjCIsaExpr * E)1014 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
1015 VisitExpr(E);
1016 Record.AddStmt(E->getBase());
1017 Record.AddSourceLocation(E->getIsaMemberLoc());
1018 Record.AddSourceLocation(E->getOpLoc());
1019 Record.push_back(E->isArrow());
1020 Code = serialization::EXPR_OBJC_ISA;
1021 }
1022
1023 void ASTStmtWriter::
VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr * E)1024 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
1025 VisitExpr(E);
1026 Record.AddStmt(E->getSubExpr());
1027 Record.push_back(E->shouldCopy());
1028 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
1029 }
1030
VisitObjCBridgedCastExpr(ObjCBridgedCastExpr * E)1031 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
1032 VisitExplicitCastExpr(E);
1033 Record.AddSourceLocation(E->getLParenLoc());
1034 Record.AddSourceLocation(E->getBridgeKeywordLoc());
1035 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
1036 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
1037 }
1038
VisitCastExpr(CastExpr * E)1039 void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
1040 VisitExpr(E);
1041
1042 Record.push_back(E->path_size());
1043 CurrentPackingBits.updateBits();
1044 // 7 bits should be enough to store the casting kinds.
1045 CurrentPackingBits.addBits(E->getCastKind(), /*Width=*/7);
1046 CurrentPackingBits.addBit(E->hasStoredFPFeatures());
1047 Record.AddStmt(E->getSubExpr());
1048
1049 for (CastExpr::path_iterator
1050 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
1051 Record.AddCXXBaseSpecifier(**PI);
1052
1053 if (E->hasStoredFPFeatures())
1054 Record.push_back(E->getFPFeatures().getAsOpaqueInt());
1055 }
1056
VisitBinaryOperator(BinaryOperator * E)1057 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
1058 VisitExpr(E);
1059
1060 // Write this first for easy access when deserializing, as they affect the
1061 // size of the UnaryOperator.
1062 CurrentPackingBits.updateBits();
1063 CurrentPackingBits.addBits(E->getOpcode(), /*Width=*/6);
1064 bool HasFPFeatures = E->hasStoredFPFeatures();
1065 CurrentPackingBits.addBit(HasFPFeatures);
1066 Record.AddStmt(E->getLHS());
1067 Record.AddStmt(E->getRHS());
1068 Record.AddSourceLocation(E->getOperatorLoc());
1069 if (HasFPFeatures)
1070 Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt());
1071
1072 if (!HasFPFeatures && E->getValueKind() == VK_PRValue &&
1073 E->getObjectKind() == OK_Ordinary)
1074 AbbrevToUse = Writer.getBinaryOperatorAbbrev();
1075
1076 Code = serialization::EXPR_BINARY_OPERATOR;
1077 }
1078
VisitCompoundAssignOperator(CompoundAssignOperator * E)1079 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
1080 VisitBinaryOperator(E);
1081 Record.AddTypeRef(E->getComputationLHSType());
1082 Record.AddTypeRef(E->getComputationResultType());
1083
1084 if (!E->hasStoredFPFeatures() && E->getValueKind() == VK_PRValue &&
1085 E->getObjectKind() == OK_Ordinary)
1086 AbbrevToUse = Writer.getCompoundAssignOperatorAbbrev();
1087
1088 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
1089 }
1090
VisitConditionalOperator(ConditionalOperator * E)1091 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
1092 VisitExpr(E);
1093 Record.AddStmt(E->getCond());
1094 Record.AddStmt(E->getLHS());
1095 Record.AddStmt(E->getRHS());
1096 Record.AddSourceLocation(E->getQuestionLoc());
1097 Record.AddSourceLocation(E->getColonLoc());
1098 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
1099 }
1100
1101 void
VisitBinaryConditionalOperator(BinaryConditionalOperator * E)1102 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
1103 VisitExpr(E);
1104 Record.AddStmt(E->getOpaqueValue());
1105 Record.AddStmt(E->getCommon());
1106 Record.AddStmt(E->getCond());
1107 Record.AddStmt(E->getTrueExpr());
1108 Record.AddStmt(E->getFalseExpr());
1109 Record.AddSourceLocation(E->getQuestionLoc());
1110 Record.AddSourceLocation(E->getColonLoc());
1111 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
1112 }
1113
VisitImplicitCastExpr(ImplicitCastExpr * E)1114 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
1115 VisitCastExpr(E);
1116 CurrentPackingBits.addBit(E->isPartOfExplicitCast());
1117
1118 if (E->path_size() == 0 && !E->hasStoredFPFeatures())
1119 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
1120
1121 Code = serialization::EXPR_IMPLICIT_CAST;
1122 }
1123
VisitExplicitCastExpr(ExplicitCastExpr * E)1124 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
1125 VisitCastExpr(E);
1126 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
1127 }
1128
VisitCStyleCastExpr(CStyleCastExpr * E)1129 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
1130 VisitExplicitCastExpr(E);
1131 Record.AddSourceLocation(E->getLParenLoc());
1132 Record.AddSourceLocation(E->getRParenLoc());
1133 Code = serialization::EXPR_CSTYLE_CAST;
1134 }
1135
VisitCompoundLiteralExpr(CompoundLiteralExpr * E)1136 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
1137 VisitExpr(E);
1138 Record.AddSourceLocation(E->getLParenLoc());
1139 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1140 Record.AddStmt(E->getInitializer());
1141 Record.push_back(E->isFileScope());
1142 Code = serialization::EXPR_COMPOUND_LITERAL;
1143 }
1144
VisitExtVectorElementExpr(ExtVectorElementExpr * E)1145 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
1146 VisitExpr(E);
1147 Record.AddStmt(E->getBase());
1148 Record.AddIdentifierRef(&E->getAccessor());
1149 Record.AddSourceLocation(E->getAccessorLoc());
1150 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
1151 }
1152
VisitInitListExpr(InitListExpr * E)1153 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
1154 VisitExpr(E);
1155 // NOTE: only add the (possibly null) syntactic form.
1156 // No need to serialize the isSemanticForm flag and the semantic form.
1157 Record.AddStmt(E->getSyntacticForm());
1158 Record.AddSourceLocation(E->getLBraceLoc());
1159 Record.AddSourceLocation(E->getRBraceLoc());
1160 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
1161 Record.push_back(isArrayFiller);
1162 if (isArrayFiller)
1163 Record.AddStmt(E->getArrayFiller());
1164 else
1165 Record.AddDeclRef(E->getInitializedFieldInUnion());
1166 Record.push_back(E->hadArrayRangeDesignator());
1167 Record.push_back(E->getNumInits());
1168 if (isArrayFiller) {
1169 // ArrayFiller may have filled "holes" due to designated initializer.
1170 // Replace them by 0 to indicate that the filler goes in that place.
1171 Expr *filler = E->getArrayFiller();
1172 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
1173 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
1174 } else {
1175 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
1176 Record.AddStmt(E->getInit(I));
1177 }
1178 Code = serialization::EXPR_INIT_LIST;
1179 }
1180
VisitDesignatedInitExpr(DesignatedInitExpr * E)1181 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
1182 VisitExpr(E);
1183 Record.push_back(E->getNumSubExprs());
1184 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1185 Record.AddStmt(E->getSubExpr(I));
1186 Record.AddSourceLocation(E->getEqualOrColonLoc());
1187 Record.push_back(E->usesGNUSyntax());
1188 for (const DesignatedInitExpr::Designator &D : E->designators()) {
1189 if (D.isFieldDesignator()) {
1190 if (FieldDecl *Field = D.getFieldDecl()) {
1191 Record.push_back(serialization::DESIG_FIELD_DECL);
1192 Record.AddDeclRef(Field);
1193 } else {
1194 Record.push_back(serialization::DESIG_FIELD_NAME);
1195 Record.AddIdentifierRef(D.getFieldName());
1196 }
1197 Record.AddSourceLocation(D.getDotLoc());
1198 Record.AddSourceLocation(D.getFieldLoc());
1199 } else if (D.isArrayDesignator()) {
1200 Record.push_back(serialization::DESIG_ARRAY);
1201 Record.push_back(D.getArrayIndex());
1202 Record.AddSourceLocation(D.getLBracketLoc());
1203 Record.AddSourceLocation(D.getRBracketLoc());
1204 } else {
1205 assert(D.isArrayRangeDesignator() && "Unknown designator");
1206 Record.push_back(serialization::DESIG_ARRAY_RANGE);
1207 Record.push_back(D.getArrayIndex());
1208 Record.AddSourceLocation(D.getLBracketLoc());
1209 Record.AddSourceLocation(D.getEllipsisLoc());
1210 Record.AddSourceLocation(D.getRBracketLoc());
1211 }
1212 }
1213 Code = serialization::EXPR_DESIGNATED_INIT;
1214 }
1215
VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr * E)1216 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
1217 VisitExpr(E);
1218 Record.AddStmt(E->getBase());
1219 Record.AddStmt(E->getUpdater());
1220 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
1221 }
1222
VisitNoInitExpr(NoInitExpr * E)1223 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
1224 VisitExpr(E);
1225 Code = serialization::EXPR_NO_INIT;
1226 }
1227
VisitArrayInitLoopExpr(ArrayInitLoopExpr * E)1228 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
1229 VisitExpr(E);
1230 Record.AddStmt(E->SubExprs[0]);
1231 Record.AddStmt(E->SubExprs[1]);
1232 Code = serialization::EXPR_ARRAY_INIT_LOOP;
1233 }
1234
VisitArrayInitIndexExpr(ArrayInitIndexExpr * E)1235 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
1236 VisitExpr(E);
1237 Code = serialization::EXPR_ARRAY_INIT_INDEX;
1238 }
1239
VisitImplicitValueInitExpr(ImplicitValueInitExpr * E)1240 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
1241 VisitExpr(E);
1242 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
1243 }
1244
VisitVAArgExpr(VAArgExpr * E)1245 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
1246 VisitExpr(E);
1247 Record.AddStmt(E->getSubExpr());
1248 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
1249 Record.AddSourceLocation(E->getBuiltinLoc());
1250 Record.AddSourceLocation(E->getRParenLoc());
1251 Record.push_back(E->isMicrosoftABI());
1252 Code = serialization::EXPR_VA_ARG;
1253 }
1254
VisitSourceLocExpr(SourceLocExpr * E)1255 void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) {
1256 VisitExpr(E);
1257 Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext()));
1258 Record.AddSourceLocation(E->getBeginLoc());
1259 Record.AddSourceLocation(E->getEndLoc());
1260 Record.push_back(llvm::to_underlying(E->getIdentKind()));
1261 Code = serialization::EXPR_SOURCE_LOC;
1262 }
1263
VisitEmbedExpr(EmbedExpr * E)1264 void ASTStmtWriter::VisitEmbedExpr(EmbedExpr *E) {
1265 VisitExpr(E);
1266 Record.AddSourceLocation(E->getBeginLoc());
1267 Record.AddSourceLocation(E->getEndLoc());
1268 Record.AddStmt(E->getDataStringLiteral());
1269 Record.writeUInt32(E->getStartingElementPos());
1270 Record.writeUInt32(E->getDataElementCount());
1271 Code = serialization::EXPR_BUILTIN_PP_EMBED;
1272 }
1273
VisitAddrLabelExpr(AddrLabelExpr * E)1274 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
1275 VisitExpr(E);
1276 Record.AddSourceLocation(E->getAmpAmpLoc());
1277 Record.AddSourceLocation(E->getLabelLoc());
1278 Record.AddDeclRef(E->getLabel());
1279 Code = serialization::EXPR_ADDR_LABEL;
1280 }
1281
VisitStmtExpr(StmtExpr * E)1282 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
1283 VisitExpr(E);
1284 Record.AddStmt(E->getSubStmt());
1285 Record.AddSourceLocation(E->getLParenLoc());
1286 Record.AddSourceLocation(E->getRParenLoc());
1287 Record.push_back(E->getTemplateDepth());
1288 Code = serialization::EXPR_STMT;
1289 }
1290
VisitChooseExpr(ChooseExpr * E)1291 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
1292 VisitExpr(E);
1293 Record.AddStmt(E->getCond());
1294 Record.AddStmt(E->getLHS());
1295 Record.AddStmt(E->getRHS());
1296 Record.AddSourceLocation(E->getBuiltinLoc());
1297 Record.AddSourceLocation(E->getRParenLoc());
1298 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
1299 Code = serialization::EXPR_CHOOSE;
1300 }
1301
VisitGNUNullExpr(GNUNullExpr * E)1302 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
1303 VisitExpr(E);
1304 Record.AddSourceLocation(E->getTokenLocation());
1305 Code = serialization::EXPR_GNU_NULL;
1306 }
1307
VisitShuffleVectorExpr(ShuffleVectorExpr * E)1308 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
1309 VisitExpr(E);
1310 Record.push_back(E->getNumSubExprs());
1311 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1312 Record.AddStmt(E->getExpr(I));
1313 Record.AddSourceLocation(E->getBuiltinLoc());
1314 Record.AddSourceLocation(E->getRParenLoc());
1315 Code = serialization::EXPR_SHUFFLE_VECTOR;
1316 }
1317
VisitConvertVectorExpr(ConvertVectorExpr * E)1318 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
1319 VisitExpr(E);
1320 Record.AddSourceLocation(E->getBuiltinLoc());
1321 Record.AddSourceLocation(E->getRParenLoc());
1322 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1323 Record.AddStmt(E->getSrcExpr());
1324 Code = serialization::EXPR_CONVERT_VECTOR;
1325 }
1326
VisitBlockExpr(BlockExpr * E)1327 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
1328 VisitExpr(E);
1329 Record.AddDeclRef(E->getBlockDecl());
1330 Code = serialization::EXPR_BLOCK;
1331 }
1332
VisitGenericSelectionExpr(GenericSelectionExpr * E)1333 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
1334 VisitExpr(E);
1335
1336 Record.push_back(E->getNumAssocs());
1337 Record.push_back(E->isExprPredicate());
1338 Record.push_back(E->ResultIndex);
1339 Record.AddSourceLocation(E->getGenericLoc());
1340 Record.AddSourceLocation(E->getDefaultLoc());
1341 Record.AddSourceLocation(E->getRParenLoc());
1342
1343 Stmt **Stmts = E->getTrailingObjects<Stmt *>();
1344 // Add 1 to account for the controlling expression which is the first
1345 // expression in the trailing array of Stmt *. This is not needed for
1346 // the trailing array of TypeSourceInfo *.
1347 for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I)
1348 Record.AddStmt(Stmts[I]);
1349
1350 TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
1351 for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I)
1352 Record.AddTypeSourceInfo(TSIs[I]);
1353
1354 Code = serialization::EXPR_GENERIC_SELECTION;
1355 }
1356
VisitPseudoObjectExpr(PseudoObjectExpr * E)1357 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
1358 VisitExpr(E);
1359 Record.push_back(E->getNumSemanticExprs());
1360
1361 // Push the result index. Currently, this needs to exactly match
1362 // the encoding used internally for ResultIndex.
1363 unsigned result = E->getResultExprIndex();
1364 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
1365 Record.push_back(result);
1366
1367 Record.AddStmt(E->getSyntacticForm());
1368 for (PseudoObjectExpr::semantics_iterator
1369 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
1370 Record.AddStmt(*i);
1371 }
1372 Code = serialization::EXPR_PSEUDO_OBJECT;
1373 }
1374
VisitAtomicExpr(AtomicExpr * E)1375 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
1376 VisitExpr(E);
1377 Record.push_back(E->getOp());
1378 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1379 Record.AddStmt(E->getSubExprs()[I]);
1380 Record.AddSourceLocation(E->getBuiltinLoc());
1381 Record.AddSourceLocation(E->getRParenLoc());
1382 Code = serialization::EXPR_ATOMIC;
1383 }
1384
1385 //===----------------------------------------------------------------------===//
1386 // Objective-C Expressions and Statements.
1387 //===----------------------------------------------------------------------===//
1388
VisitObjCStringLiteral(ObjCStringLiteral * E)1389 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
1390 VisitExpr(E);
1391 Record.AddStmt(E->getString());
1392 Record.AddSourceLocation(E->getAtLoc());
1393 Code = serialization::EXPR_OBJC_STRING_LITERAL;
1394 }
1395
VisitObjCBoxedExpr(ObjCBoxedExpr * E)1396 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1397 VisitExpr(E);
1398 Record.AddStmt(E->getSubExpr());
1399 Record.AddDeclRef(E->getBoxingMethod());
1400 Record.AddSourceRange(E->getSourceRange());
1401 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
1402 }
1403
VisitObjCArrayLiteral(ObjCArrayLiteral * E)1404 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1405 VisitExpr(E);
1406 Record.push_back(E->getNumElements());
1407 for (unsigned i = 0; i < E->getNumElements(); i++)
1408 Record.AddStmt(E->getElement(i));
1409 Record.AddDeclRef(E->getArrayWithObjectsMethod());
1410 Record.AddSourceRange(E->getSourceRange());
1411 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1412 }
1413
VisitObjCDictionaryLiteral(ObjCDictionaryLiteral * E)1414 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1415 VisitExpr(E);
1416 Record.push_back(E->getNumElements());
1417 Record.push_back(E->HasPackExpansions);
1418 for (unsigned i = 0; i < E->getNumElements(); i++) {
1419 ObjCDictionaryElement Element = E->getKeyValueElement(i);
1420 Record.AddStmt(Element.Key);
1421 Record.AddStmt(Element.Value);
1422 if (E->HasPackExpansions) {
1423 Record.AddSourceLocation(Element.EllipsisLoc);
1424 unsigned NumExpansions = 0;
1425 if (Element.NumExpansions)
1426 NumExpansions = *Element.NumExpansions + 1;
1427 Record.push_back(NumExpansions);
1428 }
1429 }
1430
1431 Record.AddDeclRef(E->getDictWithObjectsMethod());
1432 Record.AddSourceRange(E->getSourceRange());
1433 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1434 }
1435
VisitObjCEncodeExpr(ObjCEncodeExpr * E)1436 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
1437 VisitExpr(E);
1438 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1439 Record.AddSourceLocation(E->getAtLoc());
1440 Record.AddSourceLocation(E->getRParenLoc());
1441 Code = serialization::EXPR_OBJC_ENCODE;
1442 }
1443
VisitObjCSelectorExpr(ObjCSelectorExpr * E)1444 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
1445 VisitExpr(E);
1446 Record.AddSelectorRef(E->getSelector());
1447 Record.AddSourceLocation(E->getAtLoc());
1448 Record.AddSourceLocation(E->getRParenLoc());
1449 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
1450 }
1451
VisitObjCProtocolExpr(ObjCProtocolExpr * E)1452 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
1453 VisitExpr(E);
1454 Record.AddDeclRef(E->getProtocol());
1455 Record.AddSourceLocation(E->getAtLoc());
1456 Record.AddSourceLocation(E->ProtoLoc);
1457 Record.AddSourceLocation(E->getRParenLoc());
1458 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
1459 }
1460
VisitObjCIvarRefExpr(ObjCIvarRefExpr * E)1461 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1462 VisitExpr(E);
1463 Record.AddDeclRef(E->getDecl());
1464 Record.AddSourceLocation(E->getLocation());
1465 Record.AddSourceLocation(E->getOpLoc());
1466 Record.AddStmt(E->getBase());
1467 Record.push_back(E->isArrow());
1468 Record.push_back(E->isFreeIvar());
1469 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
1470 }
1471
VisitObjCPropertyRefExpr(ObjCPropertyRefExpr * E)1472 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1473 VisitExpr(E);
1474 Record.push_back(E->SetterAndMethodRefFlags.getInt());
1475 Record.push_back(E->isImplicitProperty());
1476 if (E->isImplicitProperty()) {
1477 Record.AddDeclRef(E->getImplicitPropertyGetter());
1478 Record.AddDeclRef(E->getImplicitPropertySetter());
1479 } else {
1480 Record.AddDeclRef(E->getExplicitProperty());
1481 }
1482 Record.AddSourceLocation(E->getLocation());
1483 Record.AddSourceLocation(E->getReceiverLocation());
1484 if (E->isObjectReceiver()) {
1485 Record.push_back(0);
1486 Record.AddStmt(E->getBase());
1487 } else if (E->isSuperReceiver()) {
1488 Record.push_back(1);
1489 Record.AddTypeRef(E->getSuperReceiverType());
1490 } else {
1491 Record.push_back(2);
1492 Record.AddDeclRef(E->getClassReceiver());
1493 }
1494
1495 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
1496 }
1497
VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr * E)1498 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1499 VisitExpr(E);
1500 Record.AddSourceLocation(E->getRBracket());
1501 Record.AddStmt(E->getBaseExpr());
1502 Record.AddStmt(E->getKeyExpr());
1503 Record.AddDeclRef(E->getAtIndexMethodDecl());
1504 Record.AddDeclRef(E->setAtIndexMethodDecl());
1505
1506 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1507 }
1508
VisitObjCMessageExpr(ObjCMessageExpr * E)1509 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1510 VisitExpr(E);
1511 Record.push_back(E->getNumArgs());
1512 Record.push_back(E->getNumStoredSelLocs());
1513 Record.push_back(E->SelLocsKind);
1514 Record.push_back(E->isDelegateInitCall());
1515 Record.push_back(E->IsImplicit);
1516 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1517 switch (E->getReceiverKind()) {
1518 case ObjCMessageExpr::Instance:
1519 Record.AddStmt(E->getInstanceReceiver());
1520 break;
1521
1522 case ObjCMessageExpr::Class:
1523 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
1524 break;
1525
1526 case ObjCMessageExpr::SuperClass:
1527 case ObjCMessageExpr::SuperInstance:
1528 Record.AddTypeRef(E->getSuperType());
1529 Record.AddSourceLocation(E->getSuperLoc());
1530 break;
1531 }
1532
1533 if (E->getMethodDecl()) {
1534 Record.push_back(1);
1535 Record.AddDeclRef(E->getMethodDecl());
1536 } else {
1537 Record.push_back(0);
1538 Record.AddSelectorRef(E->getSelector());
1539 }
1540
1541 Record.AddSourceLocation(E->getLeftLoc());
1542 Record.AddSourceLocation(E->getRightLoc());
1543
1544 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1545 Arg != ArgEnd; ++Arg)
1546 Record.AddStmt(*Arg);
1547
1548 SourceLocation *Locs = E->getStoredSelLocs();
1549 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1550 Record.AddSourceLocation(Locs[i]);
1551
1552 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1553 }
1554
VisitObjCForCollectionStmt(ObjCForCollectionStmt * S)1555 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1556 VisitStmt(S);
1557 Record.AddStmt(S->getElement());
1558 Record.AddStmt(S->getCollection());
1559 Record.AddStmt(S->getBody());
1560 Record.AddSourceLocation(S->getForLoc());
1561 Record.AddSourceLocation(S->getRParenLoc());
1562 Code = serialization::STMT_OBJC_FOR_COLLECTION;
1563 }
1564
VisitObjCAtCatchStmt(ObjCAtCatchStmt * S)1565 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1566 VisitStmt(S);
1567 Record.AddStmt(S->getCatchBody());
1568 Record.AddDeclRef(S->getCatchParamDecl());
1569 Record.AddSourceLocation(S->getAtCatchLoc());
1570 Record.AddSourceLocation(S->getRParenLoc());
1571 Code = serialization::STMT_OBJC_CATCH;
1572 }
1573
VisitObjCAtFinallyStmt(ObjCAtFinallyStmt * S)1574 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1575 VisitStmt(S);
1576 Record.AddStmt(S->getFinallyBody());
1577 Record.AddSourceLocation(S->getAtFinallyLoc());
1578 Code = serialization::STMT_OBJC_FINALLY;
1579 }
1580
VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt * S)1581 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1582 VisitStmt(S); // FIXME: no test coverage.
1583 Record.AddStmt(S->getSubStmt());
1584 Record.AddSourceLocation(S->getAtLoc());
1585 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1586 }
1587
VisitObjCAtTryStmt(ObjCAtTryStmt * S)1588 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1589 VisitStmt(S);
1590 Record.push_back(S->getNumCatchStmts());
1591 Record.push_back(S->getFinallyStmt() != nullptr);
1592 Record.AddStmt(S->getTryBody());
1593 for (ObjCAtCatchStmt *C : S->catch_stmts())
1594 Record.AddStmt(C);
1595 if (S->getFinallyStmt())
1596 Record.AddStmt(S->getFinallyStmt());
1597 Record.AddSourceLocation(S->getAtTryLoc());
1598 Code = serialization::STMT_OBJC_AT_TRY;
1599 }
1600
VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt * S)1601 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1602 VisitStmt(S); // FIXME: no test coverage.
1603 Record.AddStmt(S->getSynchExpr());
1604 Record.AddStmt(S->getSynchBody());
1605 Record.AddSourceLocation(S->getAtSynchronizedLoc());
1606 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1607 }
1608
VisitObjCAtThrowStmt(ObjCAtThrowStmt * S)1609 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1610 VisitStmt(S); // FIXME: no test coverage.
1611 Record.AddStmt(S->getThrowExpr());
1612 Record.AddSourceLocation(S->getThrowLoc());
1613 Code = serialization::STMT_OBJC_AT_THROW;
1614 }
1615
VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr * E)1616 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1617 VisitExpr(E);
1618 Record.push_back(E->getValue());
1619 Record.AddSourceLocation(E->getLocation());
1620 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1621 }
1622
VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr * E)1623 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1624 VisitExpr(E);
1625 Record.AddSourceRange(E->getSourceRange());
1626 Record.AddVersionTuple(E->getVersion());
1627 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1628 }
1629
1630 //===----------------------------------------------------------------------===//
1631 // C++ Expressions and Statements.
1632 //===----------------------------------------------------------------------===//
1633
VisitCXXCatchStmt(CXXCatchStmt * S)1634 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1635 VisitStmt(S);
1636 Record.AddSourceLocation(S->getCatchLoc());
1637 Record.AddDeclRef(S->getExceptionDecl());
1638 Record.AddStmt(S->getHandlerBlock());
1639 Code = serialization::STMT_CXX_CATCH;
1640 }
1641
VisitCXXTryStmt(CXXTryStmt * S)1642 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1643 VisitStmt(S);
1644 Record.push_back(S->getNumHandlers());
1645 Record.AddSourceLocation(S->getTryLoc());
1646 Record.AddStmt(S->getTryBlock());
1647 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1648 Record.AddStmt(S->getHandler(i));
1649 Code = serialization::STMT_CXX_TRY;
1650 }
1651
VisitCXXForRangeStmt(CXXForRangeStmt * S)1652 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1653 VisitStmt(S);
1654 Record.AddSourceLocation(S->getForLoc());
1655 Record.AddSourceLocation(S->getCoawaitLoc());
1656 Record.AddSourceLocation(S->getColonLoc());
1657 Record.AddSourceLocation(S->getRParenLoc());
1658 Record.AddStmt(S->getInit());
1659 Record.AddStmt(S->getRangeStmt());
1660 Record.AddStmt(S->getBeginStmt());
1661 Record.AddStmt(S->getEndStmt());
1662 Record.AddStmt(S->getCond());
1663 Record.AddStmt(S->getInc());
1664 Record.AddStmt(S->getLoopVarStmt());
1665 Record.AddStmt(S->getBody());
1666 Code = serialization::STMT_CXX_FOR_RANGE;
1667 }
1668
VisitMSDependentExistsStmt(MSDependentExistsStmt * S)1669 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1670 VisitStmt(S);
1671 Record.AddSourceLocation(S->getKeywordLoc());
1672 Record.push_back(S->isIfExists());
1673 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1674 Record.AddDeclarationNameInfo(S->getNameInfo());
1675 Record.AddStmt(S->getSubStmt());
1676 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1677 }
1678
VisitCXXOperatorCallExpr(CXXOperatorCallExpr * E)1679 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1680 VisitCallExpr(E);
1681 Record.push_back(E->getOperator());
1682 Record.AddSourceRange(E->Range);
1683
1684 if (!E->hasStoredFPFeatures() && !static_cast<bool>(E->getADLCallKind()))
1685 AbbrevToUse = Writer.getCXXOperatorCallExprAbbrev();
1686
1687 Code = serialization::EXPR_CXX_OPERATOR_CALL;
1688 }
1689
VisitCXXMemberCallExpr(CXXMemberCallExpr * E)1690 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1691 VisitCallExpr(E);
1692
1693 if (!E->hasStoredFPFeatures() && !static_cast<bool>(E->getADLCallKind()))
1694 AbbrevToUse = Writer.getCXXMemberCallExprAbbrev();
1695
1696 Code = serialization::EXPR_CXX_MEMBER_CALL;
1697 }
1698
VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator * E)1699 void ASTStmtWriter::VisitCXXRewrittenBinaryOperator(
1700 CXXRewrittenBinaryOperator *E) {
1701 VisitExpr(E);
1702 Record.push_back(E->isReversed());
1703 Record.AddStmt(E->getSemanticForm());
1704 Code = serialization::EXPR_CXX_REWRITTEN_BINARY_OPERATOR;
1705 }
1706
VisitCXXConstructExpr(CXXConstructExpr * E)1707 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1708 VisitExpr(E);
1709
1710 Record.push_back(E->getNumArgs());
1711 Record.push_back(E->isElidable());
1712 Record.push_back(E->hadMultipleCandidates());
1713 Record.push_back(E->isListInitialization());
1714 Record.push_back(E->isStdInitListInitialization());
1715 Record.push_back(E->requiresZeroInitialization());
1716 Record.push_back(
1717 llvm::to_underlying(E->getConstructionKind())); // FIXME: stable encoding
1718 Record.push_back(E->isImmediateEscalating());
1719 Record.AddSourceLocation(E->getLocation());
1720 Record.AddDeclRef(E->getConstructor());
1721 Record.AddSourceRange(E->getParenOrBraceRange());
1722
1723 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1724 Record.AddStmt(E->getArg(I));
1725
1726 Code = serialization::EXPR_CXX_CONSTRUCT;
1727 }
1728
VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr * E)1729 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1730 VisitExpr(E);
1731 Record.AddDeclRef(E->getConstructor());
1732 Record.AddSourceLocation(E->getLocation());
1733 Record.push_back(E->constructsVBase());
1734 Record.push_back(E->inheritedFromVBase());
1735 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1736 }
1737
VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr * E)1738 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1739 VisitCXXConstructExpr(E);
1740 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1741 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1742 }
1743
VisitLambdaExpr(LambdaExpr * E)1744 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1745 VisitExpr(E);
1746 Record.push_back(E->LambdaExprBits.NumCaptures);
1747 Record.AddSourceRange(E->IntroducerRange);
1748 Record.push_back(E->LambdaExprBits.CaptureDefault); // FIXME: stable encoding
1749 Record.AddSourceLocation(E->CaptureDefaultLoc);
1750 Record.push_back(E->LambdaExprBits.ExplicitParams);
1751 Record.push_back(E->LambdaExprBits.ExplicitResultType);
1752 Record.AddSourceLocation(E->ClosingBrace);
1753
1754 // Add capture initializers.
1755 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1756 CEnd = E->capture_init_end();
1757 C != CEnd; ++C) {
1758 Record.AddStmt(*C);
1759 }
1760
1761 // Don't serialize the body. It belongs to the call operator declaration.
1762 // LambdaExpr only stores a copy of the Stmt *.
1763
1764 Code = serialization::EXPR_LAMBDA;
1765 }
1766
VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr * E)1767 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1768 VisitExpr(E);
1769 Record.AddStmt(E->getSubExpr());
1770 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1771 }
1772
VisitCXXNamedCastExpr(CXXNamedCastExpr * E)1773 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1774 VisitExplicitCastExpr(E);
1775 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1776 CurrentPackingBits.addBit(E->getAngleBrackets().isValid());
1777 if (E->getAngleBrackets().isValid())
1778 Record.AddSourceRange(E->getAngleBrackets());
1779 }
1780
VisitCXXStaticCastExpr(CXXStaticCastExpr * E)1781 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1782 VisitCXXNamedCastExpr(E);
1783 Code = serialization::EXPR_CXX_STATIC_CAST;
1784 }
1785
VisitCXXDynamicCastExpr(CXXDynamicCastExpr * E)1786 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1787 VisitCXXNamedCastExpr(E);
1788 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1789 }
1790
VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr * E)1791 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1792 VisitCXXNamedCastExpr(E);
1793 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1794 }
1795
VisitCXXConstCastExpr(CXXConstCastExpr * E)1796 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1797 VisitCXXNamedCastExpr(E);
1798 Code = serialization::EXPR_CXX_CONST_CAST;
1799 }
1800
VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr * E)1801 void ASTStmtWriter::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
1802 VisitCXXNamedCastExpr(E);
1803 Code = serialization::EXPR_CXX_ADDRSPACE_CAST;
1804 }
1805
VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr * E)1806 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1807 VisitExplicitCastExpr(E);
1808 Record.AddSourceLocation(E->getLParenLoc());
1809 Record.AddSourceLocation(E->getRParenLoc());
1810 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1811 }
1812
VisitBuiltinBitCastExpr(BuiltinBitCastExpr * E)1813 void ASTStmtWriter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
1814 VisitExplicitCastExpr(E);
1815 Record.AddSourceLocation(E->getBeginLoc());
1816 Record.AddSourceLocation(E->getEndLoc());
1817 Code = serialization::EXPR_BUILTIN_BIT_CAST;
1818 }
1819
VisitUserDefinedLiteral(UserDefinedLiteral * E)1820 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1821 VisitCallExpr(E);
1822 Record.AddSourceLocation(E->UDSuffixLoc);
1823 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1824 }
1825
VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr * E)1826 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1827 VisitExpr(E);
1828 Record.push_back(E->getValue());
1829 Record.AddSourceLocation(E->getLocation());
1830 Code = serialization::EXPR_CXX_BOOL_LITERAL;
1831 }
1832
VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr * E)1833 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1834 VisitExpr(E);
1835 Record.AddSourceLocation(E->getLocation());
1836 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1837 }
1838
VisitCXXTypeidExpr(CXXTypeidExpr * E)1839 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1840 VisitExpr(E);
1841 Record.AddSourceRange(E->getSourceRange());
1842 if (E->isTypeOperand()) {
1843 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1844 Code = serialization::EXPR_CXX_TYPEID_TYPE;
1845 } else {
1846 Record.AddStmt(E->getExprOperand());
1847 Code = serialization::EXPR_CXX_TYPEID_EXPR;
1848 }
1849 }
1850
VisitCXXThisExpr(CXXThisExpr * E)1851 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1852 VisitExpr(E);
1853 Record.AddSourceLocation(E->getLocation());
1854 Record.push_back(E->isImplicit());
1855 Record.push_back(E->isCapturedByCopyInLambdaWithExplicitObjectParameter());
1856
1857 Code = serialization::EXPR_CXX_THIS;
1858 }
1859
VisitCXXThrowExpr(CXXThrowExpr * E)1860 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1861 VisitExpr(E);
1862 Record.AddSourceLocation(E->getThrowLoc());
1863 Record.AddStmt(E->getSubExpr());
1864 Record.push_back(E->isThrownVariableInScope());
1865 Code = serialization::EXPR_CXX_THROW;
1866 }
1867
VisitCXXDefaultArgExpr(CXXDefaultArgExpr * E)1868 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1869 VisitExpr(E);
1870 Record.AddDeclRef(E->getParam());
1871 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1872 Record.AddSourceLocation(E->getUsedLocation());
1873 Record.push_back(E->hasRewrittenInit());
1874 if (E->hasRewrittenInit())
1875 Record.AddStmt(E->getRewrittenExpr());
1876 Code = serialization::EXPR_CXX_DEFAULT_ARG;
1877 }
1878
VisitCXXDefaultInitExpr(CXXDefaultInitExpr * E)1879 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1880 VisitExpr(E);
1881 Record.push_back(E->hasRewrittenInit());
1882 Record.AddDeclRef(E->getField());
1883 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1884 Record.AddSourceLocation(E->getExprLoc());
1885 if (E->hasRewrittenInit())
1886 Record.AddStmt(E->getRewrittenExpr());
1887 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1888 }
1889
VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr * E)1890 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1891 VisitExpr(E);
1892 Record.AddCXXTemporary(E->getTemporary());
1893 Record.AddStmt(E->getSubExpr());
1894 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1895 }
1896
VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr * E)1897 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1898 VisitExpr(E);
1899 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1900 Record.AddSourceLocation(E->getRParenLoc());
1901 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1902 }
1903
VisitCXXNewExpr(CXXNewExpr * E)1904 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1905 VisitExpr(E);
1906
1907 Record.push_back(E->isArray());
1908 Record.push_back(E->hasInitializer());
1909 Record.push_back(E->getNumPlacementArgs());
1910 Record.push_back(E->isParenTypeId());
1911
1912 Record.push_back(E->isGlobalNew());
1913 Record.push_back(E->passAlignment());
1914 Record.push_back(E->doesUsualArrayDeleteWantSize());
1915 Record.push_back(E->CXXNewExprBits.HasInitializer);
1916 Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
1917
1918 Record.AddDeclRef(E->getOperatorNew());
1919 Record.AddDeclRef(E->getOperatorDelete());
1920 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1921 if (E->isParenTypeId())
1922 Record.AddSourceRange(E->getTypeIdParens());
1923 Record.AddSourceRange(E->getSourceRange());
1924 Record.AddSourceRange(E->getDirectInitRange());
1925
1926 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
1927 I != N; ++I)
1928 Record.AddStmt(*I);
1929
1930 Code = serialization::EXPR_CXX_NEW;
1931 }
1932
VisitCXXDeleteExpr(CXXDeleteExpr * E)1933 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1934 VisitExpr(E);
1935 Record.push_back(E->isGlobalDelete());
1936 Record.push_back(E->isArrayForm());
1937 Record.push_back(E->isArrayFormAsWritten());
1938 Record.push_back(E->doesUsualArrayDeleteWantSize());
1939 Record.AddDeclRef(E->getOperatorDelete());
1940 Record.AddStmt(E->getArgument());
1941 Record.AddSourceLocation(E->getBeginLoc());
1942
1943 Code = serialization::EXPR_CXX_DELETE;
1944 }
1945
VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr * E)1946 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1947 VisitExpr(E);
1948
1949 Record.AddStmt(E->getBase());
1950 Record.push_back(E->isArrow());
1951 Record.AddSourceLocation(E->getOperatorLoc());
1952 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1953 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1954 Record.AddSourceLocation(E->getColonColonLoc());
1955 Record.AddSourceLocation(E->getTildeLoc());
1956
1957 // PseudoDestructorTypeStorage.
1958 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
1959 if (E->getDestroyedTypeIdentifier())
1960 Record.AddSourceLocation(E->getDestroyedTypeLoc());
1961 else
1962 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
1963
1964 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1965 }
1966
VisitExprWithCleanups(ExprWithCleanups * E)1967 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1968 VisitExpr(E);
1969 Record.push_back(E->getNumObjects());
1970 for (auto &Obj : E->getObjects()) {
1971 if (auto *BD = Obj.dyn_cast<BlockDecl *>()) {
1972 Record.push_back(serialization::COK_Block);
1973 Record.AddDeclRef(BD);
1974 } else if (auto *CLE = Obj.dyn_cast<CompoundLiteralExpr *>()) {
1975 Record.push_back(serialization::COK_CompoundLiteral);
1976 Record.AddStmt(CLE);
1977 }
1978 }
1979
1980 Record.push_back(E->cleanupsHaveSideEffects());
1981 Record.AddStmt(E->getSubExpr());
1982 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1983 }
1984
VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr * E)1985 void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
1986 CXXDependentScopeMemberExpr *E) {
1987 VisitExpr(E);
1988
1989 // Don't emit anything here (or if you do you will have to update
1990 // the corresponding deserialization function).
1991 Record.push_back(E->getNumTemplateArgs());
1992 CurrentPackingBits.updateBits();
1993 CurrentPackingBits.addBit(E->hasTemplateKWAndArgsInfo());
1994 CurrentPackingBits.addBit(E->hasFirstQualifierFoundInScope());
1995
1996 if (E->hasTemplateKWAndArgsInfo()) {
1997 const ASTTemplateKWAndArgsInfo &ArgInfo =
1998 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1999 AddTemplateKWAndArgsInfo(ArgInfo,
2000 E->getTrailingObjects<TemplateArgumentLoc>());
2001 }
2002
2003 CurrentPackingBits.addBit(E->isArrow());
2004
2005 Record.AddTypeRef(E->getBaseType());
2006 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
2007 CurrentPackingBits.addBit(!E->isImplicitAccess());
2008 if (!E->isImplicitAccess())
2009 Record.AddStmt(E->getBase());
2010
2011 Record.AddSourceLocation(E->getOperatorLoc());
2012
2013 if (E->hasFirstQualifierFoundInScope())
2014 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
2015
2016 Record.AddDeclarationNameInfo(E->MemberNameInfo);
2017 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
2018 }
2019
2020 void
VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr * E)2021 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
2022 VisitExpr(E);
2023
2024 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
2025 // emitted first.
2026 CurrentPackingBits.addBit(
2027 E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
2028
2029 if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
2030 const ASTTemplateKWAndArgsInfo &ArgInfo =
2031 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
2032 // 16 bits should be enought to store the number of args
2033 CurrentPackingBits.addBits(ArgInfo.NumTemplateArgs, /*Width=*/16);
2034 AddTemplateKWAndArgsInfo(ArgInfo,
2035 E->getTrailingObjects<TemplateArgumentLoc>());
2036 }
2037
2038 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
2039 Record.AddDeclarationNameInfo(E->NameInfo);
2040 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
2041 }
2042
2043 void
VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr * E)2044 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
2045 VisitExpr(E);
2046 Record.push_back(E->getNumArgs());
2047 for (CXXUnresolvedConstructExpr::arg_iterator
2048 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
2049 Record.AddStmt(*ArgI);
2050 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
2051 Record.AddSourceLocation(E->getLParenLoc());
2052 Record.AddSourceLocation(E->getRParenLoc());
2053 Record.push_back(E->isListInitialization());
2054 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
2055 }
2056
VisitOverloadExpr(OverloadExpr * E)2057 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
2058 VisitExpr(E);
2059
2060 Record.push_back(E->getNumDecls());
2061
2062 CurrentPackingBits.updateBits();
2063 CurrentPackingBits.addBit(E->hasTemplateKWAndArgsInfo());
2064 if (E->hasTemplateKWAndArgsInfo()) {
2065 const ASTTemplateKWAndArgsInfo &ArgInfo =
2066 *E->getTrailingASTTemplateKWAndArgsInfo();
2067 Record.push_back(ArgInfo.NumTemplateArgs);
2068 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
2069 }
2070
2071 for (OverloadExpr::decls_iterator OvI = E->decls_begin(),
2072 OvE = E->decls_end();
2073 OvI != OvE; ++OvI) {
2074 Record.AddDeclRef(OvI.getDecl());
2075 Record.push_back(OvI.getAccess());
2076 }
2077
2078 Record.AddDeclarationNameInfo(E->getNameInfo());
2079 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
2080 }
2081
VisitUnresolvedMemberExpr(UnresolvedMemberExpr * E)2082 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
2083 VisitOverloadExpr(E);
2084 CurrentPackingBits.addBit(E->isArrow());
2085 CurrentPackingBits.addBit(E->hasUnresolvedUsing());
2086 CurrentPackingBits.addBit(!E->isImplicitAccess());
2087 if (!E->isImplicitAccess())
2088 Record.AddStmt(E->getBase());
2089
2090 Record.AddSourceLocation(E->getOperatorLoc());
2091
2092 Record.AddTypeRef(E->getBaseType());
2093 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
2094 }
2095
VisitUnresolvedLookupExpr(UnresolvedLookupExpr * E)2096 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
2097 VisitOverloadExpr(E);
2098 CurrentPackingBits.addBit(E->requiresADL());
2099 Record.AddDeclRef(E->getNamingClass());
2100 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
2101
2102 if (Writer.isWritingStdCXXNamedModules() && Writer.getChain()) {
2103 // Referencing all the possible declarations to make sure the change get
2104 // propagted.
2105 DeclarationName Name = E->getName();
2106 for (auto *Found :
2107 Writer.getASTContext().getTranslationUnitDecl()->lookup(Name))
2108 if (Found->isFromASTFile())
2109 Writer.GetDeclRef(Found);
2110
2111 llvm::SmallVector<NamespaceDecl *> ExternalNSs;
2112 Writer.getChain()->ReadKnownNamespaces(ExternalNSs);
2113 for (auto *NS : ExternalNSs)
2114 for (auto *Found : NS->lookup(Name))
2115 Writer.GetDeclRef(Found);
2116 }
2117 }
2118
VisitTypeTraitExpr(TypeTraitExpr * E)2119 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
2120 VisitExpr(E);
2121 Record.push_back(E->TypeTraitExprBits.NumArgs);
2122 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
2123 Record.push_back(E->TypeTraitExprBits.Value);
2124 Record.AddSourceRange(E->getSourceRange());
2125 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
2126 Record.AddTypeSourceInfo(E->getArg(I));
2127 Code = serialization::EXPR_TYPE_TRAIT;
2128 }
2129
VisitArrayTypeTraitExpr(ArrayTypeTraitExpr * E)2130 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
2131 VisitExpr(E);
2132 Record.push_back(E->getTrait());
2133 Record.push_back(E->getValue());
2134 Record.AddSourceRange(E->getSourceRange());
2135 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
2136 Record.AddStmt(E->getDimensionExpression());
2137 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
2138 }
2139
VisitExpressionTraitExpr(ExpressionTraitExpr * E)2140 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2141 VisitExpr(E);
2142 Record.push_back(E->getTrait());
2143 Record.push_back(E->getValue());
2144 Record.AddSourceRange(E->getSourceRange());
2145 Record.AddStmt(E->getQueriedExpression());
2146 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
2147 }
2148
VisitCXXNoexceptExpr(CXXNoexceptExpr * E)2149 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2150 VisitExpr(E);
2151 Record.push_back(E->getValue());
2152 Record.AddSourceRange(E->getSourceRange());
2153 Record.AddStmt(E->getOperand());
2154 Code = serialization::EXPR_CXX_NOEXCEPT;
2155 }
2156
VisitPackExpansionExpr(PackExpansionExpr * E)2157 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
2158 VisitExpr(E);
2159 Record.AddSourceLocation(E->getEllipsisLoc());
2160 Record.push_back(E->NumExpansions);
2161 Record.AddStmt(E->getPattern());
2162 Code = serialization::EXPR_PACK_EXPANSION;
2163 }
2164
VisitSizeOfPackExpr(SizeOfPackExpr * E)2165 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2166 VisitExpr(E);
2167 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
2168 : 0);
2169 Record.AddSourceLocation(E->OperatorLoc);
2170 Record.AddSourceLocation(E->PackLoc);
2171 Record.AddSourceLocation(E->RParenLoc);
2172 Record.AddDeclRef(E->Pack);
2173 if (E->isPartiallySubstituted()) {
2174 for (const auto &TA : E->getPartialArguments())
2175 Record.AddTemplateArgument(TA);
2176 } else if (!E->isValueDependent()) {
2177 Record.push_back(E->getPackLength());
2178 }
2179 Code = serialization::EXPR_SIZEOF_PACK;
2180 }
2181
VisitPackIndexingExpr(PackIndexingExpr * E)2182 void ASTStmtWriter::VisitPackIndexingExpr(PackIndexingExpr *E) {
2183 VisitExpr(E);
2184 Record.push_back(E->TransformedExpressions);
2185 Record.push_back(E->ExpandedToEmptyPack);
2186 Record.AddSourceLocation(E->getEllipsisLoc());
2187 Record.AddSourceLocation(E->getRSquareLoc());
2188 Record.AddStmt(E->getPackIdExpression());
2189 Record.AddStmt(E->getIndexExpr());
2190 for (Expr *Sub : E->getExpressions())
2191 Record.AddStmt(Sub);
2192 Code = serialization::EXPR_PACK_INDEXING;
2193 }
2194
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr * E)2195 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
2196 SubstNonTypeTemplateParmExpr *E) {
2197 VisitExpr(E);
2198 Record.AddDeclRef(E->getAssociatedDecl());
2199 CurrentPackingBits.addBit(E->isReferenceParameter());
2200 CurrentPackingBits.addBits(E->getIndex(), /*Width=*/12);
2201 CurrentPackingBits.addBit((bool)E->getPackIndex());
2202 if (auto PackIndex = E->getPackIndex())
2203 Record.push_back(*PackIndex + 1);
2204
2205 Record.AddSourceLocation(E->getNameLoc());
2206 Record.AddStmt(E->getReplacement());
2207 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
2208 }
2209
VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr * E)2210 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
2211 SubstNonTypeTemplateParmPackExpr *E) {
2212 VisitExpr(E);
2213 Record.AddDeclRef(E->getAssociatedDecl());
2214 Record.push_back(E->getIndex());
2215 Record.AddTemplateArgument(E->getArgumentPack());
2216 Record.AddSourceLocation(E->getParameterPackLocation());
2217 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
2218 }
2219
VisitFunctionParmPackExpr(FunctionParmPackExpr * E)2220 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2221 VisitExpr(E);
2222 Record.push_back(E->getNumExpansions());
2223 Record.AddDeclRef(E->getParameterPack());
2224 Record.AddSourceLocation(E->getParameterPackLocation());
2225 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
2226 I != End; ++I)
2227 Record.AddDeclRef(*I);
2228 Code = serialization::EXPR_FUNCTION_PARM_PACK;
2229 }
2230
VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr * E)2231 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
2232 VisitExpr(E);
2233 Record.push_back(static_cast<bool>(E->getLifetimeExtendedTemporaryDecl()));
2234 if (E->getLifetimeExtendedTemporaryDecl())
2235 Record.AddDeclRef(E->getLifetimeExtendedTemporaryDecl());
2236 else
2237 Record.AddStmt(E->getSubExpr());
2238 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
2239 }
2240
VisitCXXFoldExpr(CXXFoldExpr * E)2241 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
2242 VisitExpr(E);
2243 Record.AddSourceLocation(E->LParenLoc);
2244 Record.AddSourceLocation(E->EllipsisLoc);
2245 Record.AddSourceLocation(E->RParenLoc);
2246 Record.push_back(E->NumExpansions);
2247 Record.AddStmt(E->SubExprs[0]);
2248 Record.AddStmt(E->SubExprs[1]);
2249 Record.AddStmt(E->SubExprs[2]);
2250 Record.push_back(E->Opcode);
2251 Code = serialization::EXPR_CXX_FOLD;
2252 }
2253
VisitCXXParenListInitExpr(CXXParenListInitExpr * E)2254 void ASTStmtWriter::VisitCXXParenListInitExpr(CXXParenListInitExpr *E) {
2255 VisitExpr(E);
2256 ArrayRef<Expr *> InitExprs = E->getInitExprs();
2257 Record.push_back(InitExprs.size());
2258 Record.push_back(E->getUserSpecifiedInitExprs().size());
2259 Record.AddSourceLocation(E->getInitLoc());
2260 Record.AddSourceLocation(E->getBeginLoc());
2261 Record.AddSourceLocation(E->getEndLoc());
2262 for (Expr *InitExpr : E->getInitExprs())
2263 Record.AddStmt(InitExpr);
2264 Expr *ArrayFiller = E->getArrayFiller();
2265 FieldDecl *UnionField = E->getInitializedFieldInUnion();
2266 bool HasArrayFillerOrUnionDecl = ArrayFiller || UnionField;
2267 Record.push_back(HasArrayFillerOrUnionDecl);
2268 if (HasArrayFillerOrUnionDecl) {
2269 Record.push_back(static_cast<bool>(ArrayFiller));
2270 if (ArrayFiller)
2271 Record.AddStmt(ArrayFiller);
2272 else
2273 Record.AddDeclRef(UnionField);
2274 }
2275 Code = serialization::EXPR_CXX_PAREN_LIST_INIT;
2276 }
2277
VisitOpaqueValueExpr(OpaqueValueExpr * E)2278 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
2279 VisitExpr(E);
2280 Record.AddStmt(E->getSourceExpr());
2281 Record.AddSourceLocation(E->getLocation());
2282 Record.push_back(E->isUnique());
2283 Code = serialization::EXPR_OPAQUE_VALUE;
2284 }
2285
VisitTypoExpr(TypoExpr * E)2286 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
2287 VisitExpr(E);
2288 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
2289 llvm_unreachable("Cannot write TypoExpr nodes");
2290 }
2291
2292 //===----------------------------------------------------------------------===//
2293 // CUDA Expressions and Statements.
2294 //===----------------------------------------------------------------------===//
2295
VisitCUDAKernelCallExpr(CUDAKernelCallExpr * E)2296 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
2297 VisitCallExpr(E);
2298 Record.AddStmt(E->getConfig());
2299 Code = serialization::EXPR_CUDA_KERNEL_CALL;
2300 }
2301
2302 //===----------------------------------------------------------------------===//
2303 // OpenCL Expressions and Statements.
2304 //===----------------------------------------------------------------------===//
VisitAsTypeExpr(AsTypeExpr * E)2305 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
2306 VisitExpr(E);
2307 Record.AddSourceLocation(E->getBuiltinLoc());
2308 Record.AddSourceLocation(E->getRParenLoc());
2309 Record.AddStmt(E->getSrcExpr());
2310 Code = serialization::EXPR_ASTYPE;
2311 }
2312
2313 //===----------------------------------------------------------------------===//
2314 // Microsoft Expressions and Statements.
2315 //===----------------------------------------------------------------------===//
VisitMSPropertyRefExpr(MSPropertyRefExpr * E)2316 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
2317 VisitExpr(E);
2318 Record.push_back(E->isArrow());
2319 Record.AddStmt(E->getBaseExpr());
2320 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
2321 Record.AddSourceLocation(E->getMemberLoc());
2322 Record.AddDeclRef(E->getPropertyDecl());
2323 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
2324 }
2325
VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr * E)2326 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
2327 VisitExpr(E);
2328 Record.AddStmt(E->getBase());
2329 Record.AddStmt(E->getIdx());
2330 Record.AddSourceLocation(E->getRBracketLoc());
2331 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
2332 }
2333
VisitCXXUuidofExpr(CXXUuidofExpr * E)2334 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
2335 VisitExpr(E);
2336 Record.AddSourceRange(E->getSourceRange());
2337 Record.AddDeclRef(E->getGuidDecl());
2338 if (E->isTypeOperand()) {
2339 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
2340 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
2341 } else {
2342 Record.AddStmt(E->getExprOperand());
2343 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
2344 }
2345 }
2346
VisitSEHExceptStmt(SEHExceptStmt * S)2347 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
2348 VisitStmt(S);
2349 Record.AddSourceLocation(S->getExceptLoc());
2350 Record.AddStmt(S->getFilterExpr());
2351 Record.AddStmt(S->getBlock());
2352 Code = serialization::STMT_SEH_EXCEPT;
2353 }
2354
VisitSEHFinallyStmt(SEHFinallyStmt * S)2355 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
2356 VisitStmt(S);
2357 Record.AddSourceLocation(S->getFinallyLoc());
2358 Record.AddStmt(S->getBlock());
2359 Code = serialization::STMT_SEH_FINALLY;
2360 }
2361
VisitSEHTryStmt(SEHTryStmt * S)2362 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
2363 VisitStmt(S);
2364 Record.push_back(S->getIsCXXTry());
2365 Record.AddSourceLocation(S->getTryLoc());
2366 Record.AddStmt(S->getTryBlock());
2367 Record.AddStmt(S->getHandler());
2368 Code = serialization::STMT_SEH_TRY;
2369 }
2370
VisitSEHLeaveStmt(SEHLeaveStmt * S)2371 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
2372 VisitStmt(S);
2373 Record.AddSourceLocation(S->getLeaveLoc());
2374 Code = serialization::STMT_SEH_LEAVE;
2375 }
2376
2377 //===----------------------------------------------------------------------===//
2378 // OpenMP Directives.
2379 //===----------------------------------------------------------------------===//
2380
VisitOMPCanonicalLoop(OMPCanonicalLoop * S)2381 void ASTStmtWriter::VisitOMPCanonicalLoop(OMPCanonicalLoop *S) {
2382 VisitStmt(S);
2383 for (Stmt *SubStmt : S->SubStmts)
2384 Record.AddStmt(SubStmt);
2385 Code = serialization::STMT_OMP_CANONICAL_LOOP;
2386 }
2387
VisitOMPExecutableDirective(OMPExecutableDirective * E)2388 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2389 Record.writeOMPChildren(E->Data);
2390 Record.AddSourceLocation(E->getBeginLoc());
2391 Record.AddSourceLocation(E->getEndLoc());
2392 Record.writeEnum(E->getMappedDirective());
2393 }
2394
VisitOMPLoopBasedDirective(OMPLoopBasedDirective * D)2395 void ASTStmtWriter::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {
2396 VisitStmt(D);
2397 Record.writeUInt32(D->getLoopsNumber());
2398 VisitOMPExecutableDirective(D);
2399 }
2400
VisitOMPLoopDirective(OMPLoopDirective * D)2401 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
2402 VisitOMPLoopBasedDirective(D);
2403 }
2404
VisitOMPMetaDirective(OMPMetaDirective * D)2405 void ASTStmtWriter::VisitOMPMetaDirective(OMPMetaDirective *D) {
2406 VisitStmt(D);
2407 Record.push_back(D->getNumClauses());
2408 VisitOMPExecutableDirective(D);
2409 Code = serialization::STMT_OMP_META_DIRECTIVE;
2410 }
2411
VisitOMPParallelDirective(OMPParallelDirective * D)2412 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2413 VisitStmt(D);
2414 VisitOMPExecutableDirective(D);
2415 Record.writeBool(D->hasCancel());
2416 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2417 }
2418
VisitOMPSimdDirective(OMPSimdDirective * D)2419 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2420 VisitOMPLoopDirective(D);
2421 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2422 }
2423
VisitOMPLoopTransformationDirective(OMPLoopTransformationDirective * D)2424 void ASTStmtWriter::VisitOMPLoopTransformationDirective(
2425 OMPLoopTransformationDirective *D) {
2426 VisitOMPLoopBasedDirective(D);
2427 Record.writeUInt32(D->getNumGeneratedLoops());
2428 }
2429
VisitOMPTileDirective(OMPTileDirective * D)2430 void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective *D) {
2431 VisitOMPLoopTransformationDirective(D);
2432 Code = serialization::STMT_OMP_TILE_DIRECTIVE;
2433 }
2434
VisitOMPUnrollDirective(OMPUnrollDirective * D)2435 void ASTStmtWriter::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
2436 VisitOMPLoopTransformationDirective(D);
2437 Code = serialization::STMT_OMP_UNROLL_DIRECTIVE;
2438 }
2439
VisitOMPReverseDirective(OMPReverseDirective * D)2440 void ASTStmtWriter::VisitOMPReverseDirective(OMPReverseDirective *D) {
2441 VisitOMPLoopTransformationDirective(D);
2442 Code = serialization::STMT_OMP_REVERSE_DIRECTIVE;
2443 }
2444
VisitOMPInterchangeDirective(OMPInterchangeDirective * D)2445 void ASTStmtWriter::VisitOMPInterchangeDirective(OMPInterchangeDirective *D) {
2446 VisitOMPLoopTransformationDirective(D);
2447 Code = serialization::STMT_OMP_INTERCHANGE_DIRECTIVE;
2448 }
2449
VisitOMPForDirective(OMPForDirective * D)2450 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2451 VisitOMPLoopDirective(D);
2452 Record.writeBool(D->hasCancel());
2453 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2454 }
2455
VisitOMPForSimdDirective(OMPForSimdDirective * D)2456 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2457 VisitOMPLoopDirective(D);
2458 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2459 }
2460
VisitOMPSectionsDirective(OMPSectionsDirective * D)2461 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2462 VisitStmt(D);
2463 VisitOMPExecutableDirective(D);
2464 Record.writeBool(D->hasCancel());
2465 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2466 }
2467
VisitOMPSectionDirective(OMPSectionDirective * D)2468 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2469 VisitStmt(D);
2470 VisitOMPExecutableDirective(D);
2471 Record.writeBool(D->hasCancel());
2472 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2473 }
2474
VisitOMPScopeDirective(OMPScopeDirective * D)2475 void ASTStmtWriter::VisitOMPScopeDirective(OMPScopeDirective *D) {
2476 VisitStmt(D);
2477 VisitOMPExecutableDirective(D);
2478 Code = serialization::STMT_OMP_SCOPE_DIRECTIVE;
2479 }
2480
VisitOMPSingleDirective(OMPSingleDirective * D)2481 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2482 VisitStmt(D);
2483 VisitOMPExecutableDirective(D);
2484 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2485 }
2486
VisitOMPMasterDirective(OMPMasterDirective * D)2487 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2488 VisitStmt(D);
2489 VisitOMPExecutableDirective(D);
2490 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2491 }
2492
VisitOMPCriticalDirective(OMPCriticalDirective * D)2493 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2494 VisitStmt(D);
2495 VisitOMPExecutableDirective(D);
2496 Record.AddDeclarationNameInfo(D->getDirectiveName());
2497 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2498 }
2499
VisitOMPParallelForDirective(OMPParallelForDirective * D)2500 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2501 VisitOMPLoopDirective(D);
2502 Record.writeBool(D->hasCancel());
2503 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2504 }
2505
VisitOMPParallelForSimdDirective(OMPParallelForSimdDirective * D)2506 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2507 OMPParallelForSimdDirective *D) {
2508 VisitOMPLoopDirective(D);
2509 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2510 }
2511
VisitOMPParallelMasterDirective(OMPParallelMasterDirective * D)2512 void ASTStmtWriter::VisitOMPParallelMasterDirective(
2513 OMPParallelMasterDirective *D) {
2514 VisitStmt(D);
2515 VisitOMPExecutableDirective(D);
2516 Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE;
2517 }
2518
VisitOMPParallelMaskedDirective(OMPParallelMaskedDirective * D)2519 void ASTStmtWriter::VisitOMPParallelMaskedDirective(
2520 OMPParallelMaskedDirective *D) {
2521 VisitStmt(D);
2522 VisitOMPExecutableDirective(D);
2523 Code = serialization::STMT_OMP_PARALLEL_MASKED_DIRECTIVE;
2524 }
2525
VisitOMPParallelSectionsDirective(OMPParallelSectionsDirective * D)2526 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2527 OMPParallelSectionsDirective *D) {
2528 VisitStmt(D);
2529 VisitOMPExecutableDirective(D);
2530 Record.writeBool(D->hasCancel());
2531 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2532 }
2533
VisitOMPTaskDirective(OMPTaskDirective * D)2534 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2535 VisitStmt(D);
2536 VisitOMPExecutableDirective(D);
2537 Record.writeBool(D->hasCancel());
2538 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2539 }
2540
VisitOMPAtomicDirective(OMPAtomicDirective * D)2541 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2542 VisitStmt(D);
2543 VisitOMPExecutableDirective(D);
2544 Record.writeBool(D->isXLHSInRHSPart());
2545 Record.writeBool(D->isPostfixUpdate());
2546 Record.writeBool(D->isFailOnly());
2547 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2548 }
2549
VisitOMPTargetDirective(OMPTargetDirective * D)2550 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2551 VisitStmt(D);
2552 VisitOMPExecutableDirective(D);
2553 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2554 }
2555
VisitOMPTargetDataDirective(OMPTargetDataDirective * D)2556 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2557 VisitStmt(D);
2558 VisitOMPExecutableDirective(D);
2559 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2560 }
2561
VisitOMPTargetEnterDataDirective(OMPTargetEnterDataDirective * D)2562 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2563 OMPTargetEnterDataDirective *D) {
2564 VisitStmt(D);
2565 VisitOMPExecutableDirective(D);
2566 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2567 }
2568
VisitOMPTargetExitDataDirective(OMPTargetExitDataDirective * D)2569 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2570 OMPTargetExitDataDirective *D) {
2571 VisitStmt(D);
2572 VisitOMPExecutableDirective(D);
2573 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2574 }
2575
VisitOMPTargetParallelDirective(OMPTargetParallelDirective * D)2576 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2577 OMPTargetParallelDirective *D) {
2578 VisitStmt(D);
2579 VisitOMPExecutableDirective(D);
2580 Record.writeBool(D->hasCancel());
2581 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2582 }
2583
VisitOMPTargetParallelForDirective(OMPTargetParallelForDirective * D)2584 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2585 OMPTargetParallelForDirective *D) {
2586 VisitOMPLoopDirective(D);
2587 Record.writeBool(D->hasCancel());
2588 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2589 }
2590
VisitOMPTaskyieldDirective(OMPTaskyieldDirective * D)2591 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2592 VisitStmt(D);
2593 VisitOMPExecutableDirective(D);
2594 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2595 }
2596
VisitOMPBarrierDirective(OMPBarrierDirective * D)2597 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2598 VisitStmt(D);
2599 VisitOMPExecutableDirective(D);
2600 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2601 }
2602
VisitOMPTaskwaitDirective(OMPTaskwaitDirective * D)2603 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2604 VisitStmt(D);
2605 Record.push_back(D->getNumClauses());
2606 VisitOMPExecutableDirective(D);
2607 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2608 }
2609
VisitOMPErrorDirective(OMPErrorDirective * D)2610 void ASTStmtWriter::VisitOMPErrorDirective(OMPErrorDirective *D) {
2611 VisitStmt(D);
2612 Record.push_back(D->getNumClauses());
2613 VisitOMPExecutableDirective(D);
2614 Code = serialization::STMT_OMP_ERROR_DIRECTIVE;
2615 }
2616
VisitOMPTaskgroupDirective(OMPTaskgroupDirective * D)2617 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2618 VisitStmt(D);
2619 VisitOMPExecutableDirective(D);
2620 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2621 }
2622
VisitOMPFlushDirective(OMPFlushDirective * D)2623 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2624 VisitStmt(D);
2625 VisitOMPExecutableDirective(D);
2626 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2627 }
2628
VisitOMPDepobjDirective(OMPDepobjDirective * D)2629 void ASTStmtWriter::VisitOMPDepobjDirective(OMPDepobjDirective *D) {
2630 VisitStmt(D);
2631 VisitOMPExecutableDirective(D);
2632 Code = serialization::STMT_OMP_DEPOBJ_DIRECTIVE;
2633 }
2634
VisitOMPScanDirective(OMPScanDirective * D)2635 void ASTStmtWriter::VisitOMPScanDirective(OMPScanDirective *D) {
2636 VisitStmt(D);
2637 VisitOMPExecutableDirective(D);
2638 Code = serialization::STMT_OMP_SCAN_DIRECTIVE;
2639 }
2640
VisitOMPOrderedDirective(OMPOrderedDirective * D)2641 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2642 VisitStmt(D);
2643 VisitOMPExecutableDirective(D);
2644 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2645 }
2646
VisitOMPTeamsDirective(OMPTeamsDirective * D)2647 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2648 VisitStmt(D);
2649 VisitOMPExecutableDirective(D);
2650 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2651 }
2652
VisitOMPCancellationPointDirective(OMPCancellationPointDirective * D)2653 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2654 OMPCancellationPointDirective *D) {
2655 VisitStmt(D);
2656 VisitOMPExecutableDirective(D);
2657 Record.writeEnum(D->getCancelRegion());
2658 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2659 }
2660
VisitOMPCancelDirective(OMPCancelDirective * D)2661 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2662 VisitStmt(D);
2663 VisitOMPExecutableDirective(D);
2664 Record.writeEnum(D->getCancelRegion());
2665 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2666 }
2667
VisitOMPTaskLoopDirective(OMPTaskLoopDirective * D)2668 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2669 VisitOMPLoopDirective(D);
2670 Record.writeBool(D->hasCancel());
2671 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2672 }
2673
VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective * D)2674 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2675 VisitOMPLoopDirective(D);
2676 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2677 }
2678
VisitOMPMasterTaskLoopDirective(OMPMasterTaskLoopDirective * D)2679 void ASTStmtWriter::VisitOMPMasterTaskLoopDirective(
2680 OMPMasterTaskLoopDirective *D) {
2681 VisitOMPLoopDirective(D);
2682 Record.writeBool(D->hasCancel());
2683 Code = serialization::STMT_OMP_MASTER_TASKLOOP_DIRECTIVE;
2684 }
2685
VisitOMPMaskedTaskLoopDirective(OMPMaskedTaskLoopDirective * D)2686 void ASTStmtWriter::VisitOMPMaskedTaskLoopDirective(
2687 OMPMaskedTaskLoopDirective *D) {
2688 VisitOMPLoopDirective(D);
2689 Record.writeBool(D->hasCancel());
2690 Code = serialization::STMT_OMP_MASKED_TASKLOOP_DIRECTIVE;
2691 }
2692
VisitOMPMasterTaskLoopSimdDirective(OMPMasterTaskLoopSimdDirective * D)2693 void ASTStmtWriter::VisitOMPMasterTaskLoopSimdDirective(
2694 OMPMasterTaskLoopSimdDirective *D) {
2695 VisitOMPLoopDirective(D);
2696 Code = serialization::STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE;
2697 }
2698
VisitOMPMaskedTaskLoopSimdDirective(OMPMaskedTaskLoopSimdDirective * D)2699 void ASTStmtWriter::VisitOMPMaskedTaskLoopSimdDirective(
2700 OMPMaskedTaskLoopSimdDirective *D) {
2701 VisitOMPLoopDirective(D);
2702 Code = serialization::STMT_OMP_MASKED_TASKLOOP_SIMD_DIRECTIVE;
2703 }
2704
VisitOMPParallelMasterTaskLoopDirective(OMPParallelMasterTaskLoopDirective * D)2705 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopDirective(
2706 OMPParallelMasterTaskLoopDirective *D) {
2707 VisitOMPLoopDirective(D);
2708 Record.writeBool(D->hasCancel());
2709 Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE;
2710 }
2711
VisitOMPParallelMaskedTaskLoopDirective(OMPParallelMaskedTaskLoopDirective * D)2712 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopDirective(
2713 OMPParallelMaskedTaskLoopDirective *D) {
2714 VisitOMPLoopDirective(D);
2715 Record.writeBool(D->hasCancel());
2716 Code = serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_DIRECTIVE;
2717 }
2718
VisitOMPParallelMasterTaskLoopSimdDirective(OMPParallelMasterTaskLoopSimdDirective * D)2719 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopSimdDirective(
2720 OMPParallelMasterTaskLoopSimdDirective *D) {
2721 VisitOMPLoopDirective(D);
2722 Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE;
2723 }
2724
VisitOMPParallelMaskedTaskLoopSimdDirective(OMPParallelMaskedTaskLoopSimdDirective * D)2725 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopSimdDirective(
2726 OMPParallelMaskedTaskLoopSimdDirective *D) {
2727 VisitOMPLoopDirective(D);
2728 Code = serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_SIMD_DIRECTIVE;
2729 }
2730
VisitOMPDistributeDirective(OMPDistributeDirective * D)2731 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2732 VisitOMPLoopDirective(D);
2733 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2734 }
2735
VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective * D)2736 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2737 VisitStmt(D);
2738 VisitOMPExecutableDirective(D);
2739 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2740 }
2741
VisitOMPDistributeParallelForDirective(OMPDistributeParallelForDirective * D)2742 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2743 OMPDistributeParallelForDirective *D) {
2744 VisitOMPLoopDirective(D);
2745 Record.writeBool(D->hasCancel());
2746 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2747 }
2748
VisitOMPDistributeParallelForSimdDirective(OMPDistributeParallelForSimdDirective * D)2749 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2750 OMPDistributeParallelForSimdDirective *D) {
2751 VisitOMPLoopDirective(D);
2752 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2753 }
2754
VisitOMPDistributeSimdDirective(OMPDistributeSimdDirective * D)2755 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2756 OMPDistributeSimdDirective *D) {
2757 VisitOMPLoopDirective(D);
2758 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2759 }
2760
VisitOMPTargetParallelForSimdDirective(OMPTargetParallelForSimdDirective * D)2761 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2762 OMPTargetParallelForSimdDirective *D) {
2763 VisitOMPLoopDirective(D);
2764 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2765 }
2766
VisitOMPTargetSimdDirective(OMPTargetSimdDirective * D)2767 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2768 VisitOMPLoopDirective(D);
2769 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2770 }
2771
VisitOMPTeamsDistributeDirective(OMPTeamsDistributeDirective * D)2772 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2773 OMPTeamsDistributeDirective *D) {
2774 VisitOMPLoopDirective(D);
2775 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2776 }
2777
VisitOMPTeamsDistributeSimdDirective(OMPTeamsDistributeSimdDirective * D)2778 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2779 OMPTeamsDistributeSimdDirective *D) {
2780 VisitOMPLoopDirective(D);
2781 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2782 }
2783
VisitOMPTeamsDistributeParallelForSimdDirective(OMPTeamsDistributeParallelForSimdDirective * D)2784 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2785 OMPTeamsDistributeParallelForSimdDirective *D) {
2786 VisitOMPLoopDirective(D);
2787 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2788 }
2789
VisitOMPTeamsDistributeParallelForDirective(OMPTeamsDistributeParallelForDirective * D)2790 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2791 OMPTeamsDistributeParallelForDirective *D) {
2792 VisitOMPLoopDirective(D);
2793 Record.writeBool(D->hasCancel());
2794 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2795 }
2796
VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective * D)2797 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2798 VisitStmt(D);
2799 VisitOMPExecutableDirective(D);
2800 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2801 }
2802
VisitOMPTargetTeamsDistributeDirective(OMPTargetTeamsDistributeDirective * D)2803 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2804 OMPTargetTeamsDistributeDirective *D) {
2805 VisitOMPLoopDirective(D);
2806 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2807 }
2808
VisitOMPTargetTeamsDistributeParallelForDirective(OMPTargetTeamsDistributeParallelForDirective * D)2809 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2810 OMPTargetTeamsDistributeParallelForDirective *D) {
2811 VisitOMPLoopDirective(D);
2812 Record.writeBool(D->hasCancel());
2813 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2814 }
2815
VisitOMPTargetTeamsDistributeParallelForSimdDirective(OMPTargetTeamsDistributeParallelForSimdDirective * D)2816 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2817 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2818 VisitOMPLoopDirective(D);
2819 Code = serialization::
2820 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2821 }
2822
VisitOMPTargetTeamsDistributeSimdDirective(OMPTargetTeamsDistributeSimdDirective * D)2823 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2824 OMPTargetTeamsDistributeSimdDirective *D) {
2825 VisitOMPLoopDirective(D);
2826 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2827 }
2828
VisitOMPInteropDirective(OMPInteropDirective * D)2829 void ASTStmtWriter::VisitOMPInteropDirective(OMPInteropDirective *D) {
2830 VisitStmt(D);
2831 VisitOMPExecutableDirective(D);
2832 Code = serialization::STMT_OMP_INTEROP_DIRECTIVE;
2833 }
2834
VisitOMPDispatchDirective(OMPDispatchDirective * D)2835 void ASTStmtWriter::VisitOMPDispatchDirective(OMPDispatchDirective *D) {
2836 VisitStmt(D);
2837 VisitOMPExecutableDirective(D);
2838 Record.AddSourceLocation(D->getTargetCallLoc());
2839 Code = serialization::STMT_OMP_DISPATCH_DIRECTIVE;
2840 }
2841
VisitOMPMaskedDirective(OMPMaskedDirective * D)2842 void ASTStmtWriter::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
2843 VisitStmt(D);
2844 VisitOMPExecutableDirective(D);
2845 Code = serialization::STMT_OMP_MASKED_DIRECTIVE;
2846 }
2847
VisitOMPGenericLoopDirective(OMPGenericLoopDirective * D)2848 void ASTStmtWriter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
2849 VisitOMPLoopDirective(D);
2850 Code = serialization::STMT_OMP_GENERIC_LOOP_DIRECTIVE;
2851 }
2852
VisitOMPTeamsGenericLoopDirective(OMPTeamsGenericLoopDirective * D)2853 void ASTStmtWriter::VisitOMPTeamsGenericLoopDirective(
2854 OMPTeamsGenericLoopDirective *D) {
2855 VisitOMPLoopDirective(D);
2856 Code = serialization::STMT_OMP_TEAMS_GENERIC_LOOP_DIRECTIVE;
2857 }
2858
VisitOMPTargetTeamsGenericLoopDirective(OMPTargetTeamsGenericLoopDirective * D)2859 void ASTStmtWriter::VisitOMPTargetTeamsGenericLoopDirective(
2860 OMPTargetTeamsGenericLoopDirective *D) {
2861 VisitOMPLoopDirective(D);
2862 Record.writeBool(D->canBeParallelFor());
2863 Code = serialization::STMT_OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE;
2864 }
2865
VisitOMPParallelGenericLoopDirective(OMPParallelGenericLoopDirective * D)2866 void ASTStmtWriter::VisitOMPParallelGenericLoopDirective(
2867 OMPParallelGenericLoopDirective *D) {
2868 VisitOMPLoopDirective(D);
2869 Code = serialization::STMT_OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE;
2870 }
2871
VisitOMPTargetParallelGenericLoopDirective(OMPTargetParallelGenericLoopDirective * D)2872 void ASTStmtWriter::VisitOMPTargetParallelGenericLoopDirective(
2873 OMPTargetParallelGenericLoopDirective *D) {
2874 VisitOMPLoopDirective(D);
2875 Code = serialization::STMT_OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE;
2876 }
2877
2878 //===----------------------------------------------------------------------===//
2879 // OpenACC Constructs/Directives.
2880 //===----------------------------------------------------------------------===//
VisitOpenACCConstructStmt(OpenACCConstructStmt * S)2881 void ASTStmtWriter::VisitOpenACCConstructStmt(OpenACCConstructStmt *S) {
2882 Record.push_back(S->clauses().size());
2883 Record.writeEnum(S->Kind);
2884 Record.AddSourceRange(S->Range);
2885 Record.AddSourceLocation(S->DirectiveLoc);
2886 Record.writeOpenACCClauseList(S->clauses());
2887 }
2888
VisitOpenACCAssociatedStmtConstruct(OpenACCAssociatedStmtConstruct * S)2889 void ASTStmtWriter::VisitOpenACCAssociatedStmtConstruct(
2890 OpenACCAssociatedStmtConstruct *S) {
2891 VisitOpenACCConstructStmt(S);
2892 Record.AddStmt(S->getAssociatedStmt());
2893 }
2894
VisitOpenACCComputeConstruct(OpenACCComputeConstruct * S)2895 void ASTStmtWriter::VisitOpenACCComputeConstruct(OpenACCComputeConstruct *S) {
2896 VisitStmt(S);
2897 VisitOpenACCAssociatedStmtConstruct(S);
2898 Code = serialization::STMT_OPENACC_COMPUTE_CONSTRUCT;
2899 }
2900
VisitOpenACCLoopConstruct(OpenACCLoopConstruct * S)2901 void ASTStmtWriter::VisitOpenACCLoopConstruct(OpenACCLoopConstruct *S) {
2902 VisitStmt(S);
2903 VisitOpenACCAssociatedStmtConstruct(S);
2904 Code = serialization::STMT_OPENACC_LOOP_CONSTRUCT;
2905 }
2906
2907 //===----------------------------------------------------------------------===//
2908 // ASTWriter Implementation
2909 //===----------------------------------------------------------------------===//
2910
RecordSwitchCaseID(SwitchCase * S)2911 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2912 assert(!SwitchCaseIDs.contains(S) && "SwitchCase recorded twice");
2913 unsigned NextID = SwitchCaseIDs.size();
2914 SwitchCaseIDs[S] = NextID;
2915 return NextID;
2916 }
2917
getSwitchCaseID(SwitchCase * S)2918 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2919 assert(SwitchCaseIDs.contains(S) && "SwitchCase hasn't been seen yet");
2920 return SwitchCaseIDs[S];
2921 }
2922
ClearSwitchCaseIDs()2923 void ASTWriter::ClearSwitchCaseIDs() {
2924 SwitchCaseIDs.clear();
2925 }
2926
2927 /// Write the given substatement or subexpression to the
2928 /// bitstream.
WriteSubStmt(Stmt * S)2929 void ASTWriter::WriteSubStmt(Stmt *S) {
2930 RecordData Record;
2931 ASTStmtWriter Writer(*this, Record);
2932 ++NumStatements;
2933
2934 if (!S) {
2935 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2936 return;
2937 }
2938
2939 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2940 if (I != SubStmtEntries.end()) {
2941 Record.push_back(I->second);
2942 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2943 return;
2944 }
2945
2946 #ifndef NDEBUG
2947 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2948
2949 struct ParentStmtInserterRAII {
2950 Stmt *S;
2951 llvm::DenseSet<Stmt *> &ParentStmts;
2952
2953 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2954 : S(S), ParentStmts(ParentStmts) {
2955 ParentStmts.insert(S);
2956 }
2957 ~ParentStmtInserterRAII() {
2958 ParentStmts.erase(S);
2959 }
2960 };
2961
2962 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2963 #endif
2964
2965 Writer.Visit(S);
2966
2967 uint64_t Offset = Writer.Emit();
2968 SubStmtEntries[S] = Offset;
2969 }
2970
2971 /// Flush all of the statements that have been added to the
2972 /// queue via AddStmt().
FlushStmts()2973 void ASTRecordWriter::FlushStmts() {
2974 // We expect to be the only consumer of the two temporary statement maps,
2975 // assert that they are empty.
2976 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2977 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2978
2979 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2980 Writer->WriteSubStmt(StmtsToEmit[I]);
2981
2982 assert(N == StmtsToEmit.size() && "record modified while being written!");
2983
2984 // Note that we are at the end of a full expression. Any
2985 // expression records that follow this one are part of a different
2986 // expression.
2987 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2988
2989 Writer->SubStmtEntries.clear();
2990 Writer->ParentStmts.clear();
2991 }
2992
2993 StmtsToEmit.clear();
2994 }
2995
FlushSubStmts()2996 void ASTRecordWriter::FlushSubStmts() {
2997 // For a nested statement, write out the substatements in reverse order (so
2998 // that a simple stack machine can be used when loading), and don't emit a
2999 // STMT_STOP after each one.
3000 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
3001 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
3002 assert(N == StmtsToEmit.size() && "record modified while being written!");
3003 }
3004
3005 StmtsToEmit.clear();
3006 }
3007