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

source code of clang/lib/Serialization/ASTWriterStmt.cpp