1 //===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
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
7 //===----------------------------------------------------------------------===//
10 /// Implements serialization for Statements and Expressions.
12 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ExprOpenMP.h"
15 #include "clang/Serialization/ASTRecordWriter.h"
16 #include "clang/Sema/DeclSpec.h"
17 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/StmtVisitor.h"
22 #include "clang/Lex/Token.h"
23 #include "llvm/Bitstream/BitstreamWriter.h"
24 using namespace clang
;
26 //===----------------------------------------------------------------------===//
27 // Statement/expression serialization
28 //===----------------------------------------------------------------------===//
32 class ASTStmtWriter
: public StmtVisitor
<ASTStmtWriter
, void> {
34 ASTRecordWriter Record
;
36 serialization::StmtCode Code
;
40 ASTStmtWriter(ASTWriter
&Writer
, ASTWriter::RecordData
&Record
)
41 : Writer(Writer
), Record(Writer
, Record
),
42 Code(serialization::STMT_NULL_PTR
), AbbrevToUse(0) {}
44 ASTStmtWriter(const ASTStmtWriter
&) = delete;
47 assert(Code
!= serialization::STMT_NULL_PTR
&&
48 "unhandled sub-statement writing AST file");
49 return Record
.EmitStmt(Code
, AbbrevToUse
);
52 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo
&ArgInfo
,
53 const TemplateArgumentLoc
*Args
);
55 void VisitStmt(Stmt
*S
);
56 #define STMT(Type, Base) \
57 void Visit##Type(Type *);
58 #include "clang/AST/StmtNodes.inc"
62 void ASTStmtWriter::AddTemplateKWAndArgsInfo(
63 const ASTTemplateKWAndArgsInfo
&ArgInfo
, const TemplateArgumentLoc
*Args
) {
64 Record
.AddSourceLocation(ArgInfo
.TemplateKWLoc
);
65 Record
.AddSourceLocation(ArgInfo
.LAngleLoc
);
66 Record
.AddSourceLocation(ArgInfo
.RAngleLoc
);
67 for (unsigned i
= 0; i
!= ArgInfo
.NumTemplateArgs
; ++i
)
68 Record
.AddTemplateArgumentLoc(Args
[i
]);
71 void ASTStmtWriter::VisitStmt(Stmt
*S
) {
74 void ASTStmtWriter::VisitNullStmt(NullStmt
*S
) {
76 Record
.AddSourceLocation(S
->getSemiLoc());
77 Record
.push_back(S
->NullStmtBits
.HasLeadingEmptyMacro
);
78 Code
= serialization::STMT_NULL
;
81 void ASTStmtWriter::VisitCompoundStmt(CompoundStmt
*S
) {
83 Record
.push_back(S
->size());
84 Record
.push_back(S
->hasStoredFPFeatures());
85 for (auto *CS
: S
->body())
87 if (S
->hasStoredFPFeatures())
88 Record
.push_back(S
->getStoredFPFeatures().getAsOpaqueInt());
89 Record
.AddSourceLocation(S
->getLBracLoc());
90 Record
.AddSourceLocation(S
->getRBracLoc());
91 Code
= serialization::STMT_COMPOUND
;
94 void ASTStmtWriter::VisitSwitchCase(SwitchCase
*S
) {
96 Record
.push_back(Writer
.getSwitchCaseID(S
));
97 Record
.AddSourceLocation(S
->getKeywordLoc());
98 Record
.AddSourceLocation(S
->getColonLoc());
101 void ASTStmtWriter::VisitCaseStmt(CaseStmt
*S
) {
103 Record
.push_back(S
->caseStmtIsGNURange());
104 Record
.AddStmt(S
->getLHS());
105 Record
.AddStmt(S
->getSubStmt());
106 if (S
->caseStmtIsGNURange()) {
107 Record
.AddStmt(S
->getRHS());
108 Record
.AddSourceLocation(S
->getEllipsisLoc());
110 Code
= serialization::STMT_CASE
;
113 void ASTStmtWriter::VisitDefaultStmt(DefaultStmt
*S
) {
115 Record
.AddStmt(S
->getSubStmt());
116 Code
= serialization::STMT_DEFAULT
;
119 void ASTStmtWriter::VisitLabelStmt(LabelStmt
*S
) {
121 Record
.push_back(S
->isSideEntry());
122 Record
.AddDeclRef(S
->getDecl());
123 Record
.AddStmt(S
->getSubStmt());
124 Record
.AddSourceLocation(S
->getIdentLoc());
125 Code
= serialization::STMT_LABEL
;
128 void ASTStmtWriter::VisitAttributedStmt(AttributedStmt
*S
) {
130 Record
.push_back(S
->getAttrs().size());
131 Record
.AddAttributes(S
->getAttrs());
132 Record
.AddStmt(S
->getSubStmt());
133 Record
.AddSourceLocation(S
->getAttrLoc());
134 Code
= serialization::STMT_ATTRIBUTED
;
137 void ASTStmtWriter::VisitIfStmt(IfStmt
*S
) {
140 bool HasElse
= S
->getElse() != nullptr;
141 bool HasVar
= S
->getConditionVariableDeclStmt() != nullptr;
142 bool HasInit
= S
->getInit() != nullptr;
144 Record
.push_back(HasElse
);
145 Record
.push_back(HasVar
);
146 Record
.push_back(HasInit
);
147 Record
.push_back(static_cast<uint64_t>(S
->getStatementKind()));
148 Record
.AddStmt(S
->getCond());
149 Record
.AddStmt(S
->getThen());
151 Record
.AddStmt(S
->getElse());
153 Record
.AddDeclRef(S
->getConditionVariable());
155 Record
.AddStmt(S
->getInit());
157 Record
.AddSourceLocation(S
->getIfLoc());
158 Record
.AddSourceLocation(S
->getLParenLoc());
159 Record
.AddSourceLocation(S
->getRParenLoc());
161 Record
.AddSourceLocation(S
->getElseLoc());
163 Code
= serialization::STMT_IF
;
166 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt
*S
) {
169 bool HasInit
= S
->getInit() != nullptr;
170 bool HasVar
= S
->getConditionVariableDeclStmt() != nullptr;
171 Record
.push_back(HasInit
);
172 Record
.push_back(HasVar
);
173 Record
.push_back(S
->isAllEnumCasesCovered());
175 Record
.AddStmt(S
->getCond());
176 Record
.AddStmt(S
->getBody());
178 Record
.AddStmt(S
->getInit());
180 Record
.AddDeclRef(S
->getConditionVariable());
182 Record
.AddSourceLocation(S
->getSwitchLoc());
183 Record
.AddSourceLocation(S
->getLParenLoc());
184 Record
.AddSourceLocation(S
->getRParenLoc());
186 for (SwitchCase
*SC
= S
->getSwitchCaseList(); SC
;
187 SC
= SC
->getNextSwitchCase())
188 Record
.push_back(Writer
.RecordSwitchCaseID(SC
));
189 Code
= serialization::STMT_SWITCH
;
192 void ASTStmtWriter::VisitWhileStmt(WhileStmt
*S
) {
195 bool HasVar
= S
->getConditionVariableDeclStmt() != nullptr;
196 Record
.push_back(HasVar
);
198 Record
.AddStmt(S
->getCond());
199 Record
.AddStmt(S
->getBody());
201 Record
.AddDeclRef(S
->getConditionVariable());
203 Record
.AddSourceLocation(S
->getWhileLoc());
204 Record
.AddSourceLocation(S
->getLParenLoc());
205 Record
.AddSourceLocation(S
->getRParenLoc());
206 Code
= serialization::STMT_WHILE
;
209 void ASTStmtWriter::VisitDoStmt(DoStmt
*S
) {
211 Record
.AddStmt(S
->getCond());
212 Record
.AddStmt(S
->getBody());
213 Record
.AddSourceLocation(S
->getDoLoc());
214 Record
.AddSourceLocation(S
->getWhileLoc());
215 Record
.AddSourceLocation(S
->getRParenLoc());
216 Code
= serialization::STMT_DO
;
219 void ASTStmtWriter::VisitForStmt(ForStmt
*S
) {
221 Record
.AddStmt(S
->getInit());
222 Record
.AddStmt(S
->getCond());
223 Record
.AddDeclRef(S
->getConditionVariable());
224 Record
.AddStmt(S
->getInc());
225 Record
.AddStmt(S
->getBody());
226 Record
.AddSourceLocation(S
->getForLoc());
227 Record
.AddSourceLocation(S
->getLParenLoc());
228 Record
.AddSourceLocation(S
->getRParenLoc());
229 Code
= serialization::STMT_FOR
;
232 void ASTStmtWriter::VisitGotoStmt(GotoStmt
*S
) {
234 Record
.AddDeclRef(S
->getLabel());
235 Record
.AddSourceLocation(S
->getGotoLoc());
236 Record
.AddSourceLocation(S
->getLabelLoc());
237 Code
= serialization::STMT_GOTO
;
240 void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt
*S
) {
242 Record
.AddSourceLocation(S
->getGotoLoc());
243 Record
.AddSourceLocation(S
->getStarLoc());
244 Record
.AddStmt(S
->getTarget());
245 Code
= serialization::STMT_INDIRECT_GOTO
;
248 void ASTStmtWriter::VisitContinueStmt(ContinueStmt
*S
) {
250 Record
.AddSourceLocation(S
->getContinueLoc());
251 Code
= serialization::STMT_CONTINUE
;
254 void ASTStmtWriter::VisitBreakStmt(BreakStmt
*S
) {
256 Record
.AddSourceLocation(S
->getBreakLoc());
257 Code
= serialization::STMT_BREAK
;
260 void ASTStmtWriter::VisitReturnStmt(ReturnStmt
*S
) {
263 bool HasNRVOCandidate
= S
->getNRVOCandidate() != nullptr;
264 Record
.push_back(HasNRVOCandidate
);
266 Record
.AddStmt(S
->getRetValue());
267 if (HasNRVOCandidate
)
268 Record
.AddDeclRef(S
->getNRVOCandidate());
270 Record
.AddSourceLocation(S
->getReturnLoc());
271 Code
= serialization::STMT_RETURN
;
274 void ASTStmtWriter::VisitDeclStmt(DeclStmt
*S
) {
276 Record
.AddSourceLocation(S
->getBeginLoc());
277 Record
.AddSourceLocation(S
->getEndLoc());
278 DeclGroupRef DG
= S
->getDeclGroup();
279 for (DeclGroupRef::iterator D
= DG
.begin(), DEnd
= DG
.end(); D
!= DEnd
; ++D
)
280 Record
.AddDeclRef(*D
);
281 Code
= serialization::STMT_DECL
;
284 void ASTStmtWriter::VisitAsmStmt(AsmStmt
*S
) {
286 Record
.push_back(S
->getNumOutputs());
287 Record
.push_back(S
->getNumInputs());
288 Record
.push_back(S
->getNumClobbers());
289 Record
.AddSourceLocation(S
->getAsmLoc());
290 Record
.push_back(S
->isVolatile());
291 Record
.push_back(S
->isSimple());
294 void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt
*S
) {
296 Record
.push_back(S
->getNumLabels());
297 Record
.AddSourceLocation(S
->getRParenLoc());
298 Record
.AddStmt(S
->getAsmString());
301 for (unsigned I
= 0, N
= S
->getNumOutputs(); I
!= N
; ++I
) {
302 Record
.AddIdentifierRef(S
->getOutputIdentifier(I
));
303 Record
.AddStmt(S
->getOutputConstraintLiteral(I
));
304 Record
.AddStmt(S
->getOutputExpr(I
));
308 for (unsigned I
= 0, N
= S
->getNumInputs(); I
!= N
; ++I
) {
309 Record
.AddIdentifierRef(S
->getInputIdentifier(I
));
310 Record
.AddStmt(S
->getInputConstraintLiteral(I
));
311 Record
.AddStmt(S
->getInputExpr(I
));
315 for (unsigned I
= 0, N
= S
->getNumClobbers(); I
!= N
; ++I
)
316 Record
.AddStmt(S
->getClobberStringLiteral(I
));
319 for (auto *E
: S
->labels()) Record
.AddStmt(E
);
321 Code
= serialization::STMT_GCCASM
;
324 void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt
*S
) {
326 Record
.AddSourceLocation(S
->getLBraceLoc());
327 Record
.AddSourceLocation(S
->getEndLoc());
328 Record
.push_back(S
->getNumAsmToks());
329 Record
.AddString(S
->getAsmString());
332 for (unsigned I
= 0, N
= S
->getNumAsmToks(); I
!= N
; ++I
) {
333 // FIXME: Move this to ASTRecordWriter?
334 Writer
.AddToken(S
->getAsmToks()[I
], Record
.getRecordData());
338 for (unsigned I
= 0, N
= S
->getNumClobbers(); I
!= N
; ++I
) {
339 Record
.AddString(S
->getClobber(I
));
343 for (unsigned I
= 0, N
= S
->getNumOutputs(); I
!= N
; ++I
) {
344 Record
.AddStmt(S
->getOutputExpr(I
));
345 Record
.AddString(S
->getOutputConstraint(I
));
349 for (unsigned I
= 0, N
= S
->getNumInputs(); I
!= N
; ++I
) {
350 Record
.AddStmt(S
->getInputExpr(I
));
351 Record
.AddString(S
->getInputConstraint(I
));
354 Code
= serialization::STMT_MSASM
;
357 void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt
*CoroStmt
) {
359 Record
.push_back(CoroStmt
->getParamMoves().size());
360 for (Stmt
*S
: CoroStmt
->children())
362 Code
= serialization::STMT_COROUTINE_BODY
;
365 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt
*S
) {
367 Record
.AddSourceLocation(S
->getKeywordLoc());
368 Record
.AddStmt(S
->getOperand());
369 Record
.AddStmt(S
->getPromiseCall());
370 Record
.push_back(S
->isImplicit());
371 Code
= serialization::STMT_CORETURN
;
374 void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr
*E
) {
376 Record
.AddSourceLocation(E
->getKeywordLoc());
377 for (Stmt
*S
: E
->children())
379 Record
.AddStmt(E
->getOpaqueValue());
382 void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr
*E
) {
383 VisitCoroutineSuspendExpr(E
);
384 Record
.push_back(E
->isImplicit());
385 Code
= serialization::EXPR_COAWAIT
;
388 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr
*E
) {
389 VisitCoroutineSuspendExpr(E
);
390 Code
= serialization::EXPR_COYIELD
;
393 void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr
*E
) {
395 Record
.AddSourceLocation(E
->getKeywordLoc());
396 for (Stmt
*S
: E
->children())
398 Code
= serialization::EXPR_DEPENDENT_COAWAIT
;
402 addConstraintSatisfaction(ASTRecordWriter
&Record
,
403 const ASTConstraintSatisfaction
&Satisfaction
) {
404 Record
.push_back(Satisfaction
.IsSatisfied
);
405 if (!Satisfaction
.IsSatisfied
) {
406 Record
.push_back(Satisfaction
.NumRecords
);
407 for (const auto &DetailRecord
: Satisfaction
) {
408 Record
.AddStmt(const_cast<Expr
*>(DetailRecord
.first
));
409 auto *E
= DetailRecord
.second
.dyn_cast
<Expr
*>();
410 Record
.push_back(E
== nullptr);
414 auto *Diag
= DetailRecord
.second
.get
<std::pair
<SourceLocation
,
416 Record
.AddSourceLocation(Diag
->first
);
417 Record
.AddString(Diag
->second
);
424 addSubstitutionDiagnostic(
425 ASTRecordWriter
&Record
,
426 const concepts::Requirement::SubstitutionDiagnostic
*D
) {
427 Record
.AddString(D
->SubstitutedEntity
);
428 Record
.AddSourceLocation(D
->DiagLoc
);
429 Record
.AddString(D
->DiagMessage
);
432 void ASTStmtWriter::VisitConceptSpecializationExpr(
433 ConceptSpecializationExpr
*E
) {
435 ArrayRef
<TemplateArgument
> TemplateArgs
= E
->getTemplateArguments();
436 Record
.push_back(TemplateArgs
.size());
437 Record
.AddNestedNameSpecifierLoc(E
->getNestedNameSpecifierLoc());
438 Record
.AddSourceLocation(E
->getTemplateKWLoc());
439 Record
.AddDeclarationNameInfo(E
->getConceptNameInfo());
440 Record
.AddDeclRef(E
->getNamedConcept());
441 Record
.AddDeclRef(E
->getFoundDecl());
442 Record
.AddASTTemplateArgumentListInfo(E
->getTemplateArgsAsWritten());
443 for (const TemplateArgument
&Arg
: TemplateArgs
)
444 Record
.AddTemplateArgument(Arg
);
445 if (!E
->isValueDependent())
446 addConstraintSatisfaction(Record
, E
->getSatisfaction());
448 Code
= serialization::EXPR_CONCEPT_SPECIALIZATION
;
451 void ASTStmtWriter::VisitRequiresExpr(RequiresExpr
*E
) {
453 Record
.push_back(E
->getLocalParameters().size());
454 Record
.push_back(E
->getRequirements().size());
455 Record
.AddSourceLocation(E
->RequiresExprBits
.RequiresKWLoc
);
456 Record
.push_back(E
->RequiresExprBits
.IsSatisfied
);
457 Record
.AddDeclRef(E
->getBody());
458 for (ParmVarDecl
*P
: E
->getLocalParameters())
459 Record
.AddDeclRef(P
);
460 for (concepts::Requirement
*R
: E
->getRequirements()) {
461 if (auto *TypeReq
= dyn_cast
<concepts::TypeRequirement
>(R
)) {
462 Record
.push_back(concepts::Requirement::RK_Type
);
463 Record
.push_back(TypeReq
->Status
);
464 if (TypeReq
->Status
== concepts::TypeRequirement::SS_SubstitutionFailure
)
465 addSubstitutionDiagnostic(Record
, TypeReq
->getSubstitutionDiagnostic());
467 Record
.AddTypeSourceInfo(TypeReq
->getType());
468 } else if (auto *ExprReq
= dyn_cast
<concepts::ExprRequirement
>(R
)) {
469 Record
.push_back(ExprReq
->getKind());
470 Record
.push_back(ExprReq
->Status
);
471 if (ExprReq
->isExprSubstitutionFailure()) {
472 addSubstitutionDiagnostic(Record
,
473 ExprReq
->Value
.get
<concepts::Requirement::SubstitutionDiagnostic
*>());
475 Record
.AddStmt(ExprReq
->Value
.get
<Expr
*>());
476 if (ExprReq
->getKind() == concepts::Requirement::RK_Compound
) {
477 Record
.AddSourceLocation(ExprReq
->NoexceptLoc
);
478 const auto &RetReq
= ExprReq
->getReturnTypeRequirement();
479 if (RetReq
.isSubstitutionFailure()) {
481 addSubstitutionDiagnostic(Record
, RetReq
.getSubstitutionDiagnostic());
482 } else if (RetReq
.isTypeConstraint()) {
484 Record
.AddTemplateParameterList(
485 RetReq
.getTypeConstraintTemplateParameterList());
486 if (ExprReq
->Status
>=
487 concepts::ExprRequirement::SS_ConstraintsNotSatisfied
)
489 ExprReq
->getReturnTypeRequirementSubstitutedConstraintExpr());
491 assert(RetReq
.isEmpty());
496 auto *NestedReq
= cast
<concepts::NestedRequirement
>(R
);
497 Record
.push_back(concepts::Requirement::RK_Nested
);
498 Record
.push_back(NestedReq
->isSubstitutionFailure());
499 if (NestedReq
->isSubstitutionFailure()){
500 addSubstitutionDiagnostic(Record
,
501 NestedReq
->getSubstitutionDiagnostic());
503 Record
.AddStmt(NestedReq
->Value
.get
<Expr
*>());
504 if (!NestedReq
->isDependent())
505 addConstraintSatisfaction(Record
, *NestedReq
->Satisfaction
);
509 Record
.AddSourceLocation(E
->getEndLoc());
511 Code
= serialization::EXPR_REQUIRES
;
515 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt
*S
) {
518 Record
.push_back(std::distance(S
->capture_begin(), S
->capture_end()));
520 // CapturedDecl and captured region kind
521 Record
.AddDeclRef(S
->getCapturedDecl());
522 Record
.push_back(S
->getCapturedRegionKind());
524 Record
.AddDeclRef(S
->getCapturedRecordDecl());
527 for (auto *I
: S
->capture_inits())
531 Record
.AddStmt(S
->getCapturedStmt());
534 for (const auto &I
: S
->captures()) {
535 if (I
.capturesThis() || I
.capturesVariableArrayType())
536 Record
.AddDeclRef(nullptr);
538 Record
.AddDeclRef(I
.getCapturedVar());
539 Record
.push_back(I
.getCaptureKind());
540 Record
.AddSourceLocation(I
.getLocation());
543 Code
= serialization::STMT_CAPTURED
;
546 void ASTStmtWriter::VisitExpr(Expr
*E
) {
548 Record
.AddTypeRef(E
->getType());
549 Record
.push_back(E
->getDependence());
550 Record
.push_back(E
->getValueKind());
551 Record
.push_back(E
->getObjectKind());
554 void ASTStmtWriter::VisitConstantExpr(ConstantExpr
*E
) {
556 Record
.push_back(E
->ConstantExprBits
.ResultKind
);
558 Record
.push_back(E
->ConstantExprBits
.APValueKind
);
559 Record
.push_back(E
->ConstantExprBits
.IsUnsigned
);
560 Record
.push_back(E
->ConstantExprBits
.BitWidth
);
561 // HasCleanup not serialized since we can just query the APValue.
562 Record
.push_back(E
->ConstantExprBits
.IsImmediateInvocation
);
564 switch (E
->ConstantExprBits
.ResultKind
) {
565 case ConstantExpr::RSK_None
:
567 case ConstantExpr::RSK_Int64
:
568 Record
.push_back(E
->Int64Result());
570 case ConstantExpr::RSK_APValue
:
571 Record
.AddAPValue(E
->APValueResult());
574 llvm_unreachable("unexpected ResultKind!");
577 Record
.AddStmt(E
->getSubExpr());
578 Code
= serialization::EXPR_CONSTANT
;
581 void ASTStmtWriter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr
*E
) {
584 Record
.AddSourceLocation(E
->getLocation());
585 Record
.AddSourceLocation(E
->getLParenLocation());
586 Record
.AddSourceLocation(E
->getRParenLocation());
587 Record
.AddTypeSourceInfo(E
->getTypeSourceInfo());
589 Code
= serialization::EXPR_SYCL_UNIQUE_STABLE_NAME
;
592 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr
*E
) {
595 bool HasFunctionName
= E
->getFunctionName() != nullptr;
596 Record
.push_back(HasFunctionName
);
597 Record
.push_back(E
->getIdentKind()); // FIXME: stable encoding
598 Record
.AddSourceLocation(E
->getLocation());
600 Record
.AddStmt(E
->getFunctionName());
601 Code
= serialization::EXPR_PREDEFINED
;
604 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr
*E
) {
607 Record
.push_back(E
->hasQualifier());
608 Record
.push_back(E
->getDecl() != E
->getFoundDecl());
609 Record
.push_back(E
->hasTemplateKWAndArgsInfo());
610 Record
.push_back(E
->hadMultipleCandidates());
611 Record
.push_back(E
->refersToEnclosingVariableOrCapture());
612 Record
.push_back(E
->isNonOdrUse());
614 if (E
->hasTemplateKWAndArgsInfo()) {
615 unsigned NumTemplateArgs
= E
->getNumTemplateArgs();
616 Record
.push_back(NumTemplateArgs
);
619 DeclarationName::NameKind nk
= (E
->getDecl()->getDeclName().getNameKind());
621 if ((!E
->hasTemplateKWAndArgsInfo()) && (!E
->hasQualifier()) &&
622 (E
->getDecl() == E
->getFoundDecl()) &&
623 nk
== DeclarationName::Identifier
&&
624 !E
->refersToEnclosingVariableOrCapture() && !E
->isNonOdrUse()) {
625 AbbrevToUse
= Writer
.getDeclRefExprAbbrev();
628 if (E
->hasQualifier())
629 Record
.AddNestedNameSpecifierLoc(E
->getQualifierLoc());
631 if (E
->getDecl() != E
->getFoundDecl())
632 Record
.AddDeclRef(E
->getFoundDecl());
634 if (E
->hasTemplateKWAndArgsInfo())
635 AddTemplateKWAndArgsInfo(*E
->getTrailingObjects
<ASTTemplateKWAndArgsInfo
>(),
636 E
->getTrailingObjects
<TemplateArgumentLoc
>());
638 Record
.AddDeclRef(E
->getDecl());
639 Record
.AddSourceLocation(E
->getLocation());
640 Record
.AddDeclarationNameLoc(E
->DNLoc
, E
->getDecl()->getDeclName());
641 Code
= serialization::EXPR_DECL_REF
;
644 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral
*E
) {
646 Record
.AddSourceLocation(E
->getLocation());
647 Record
.AddAPInt(E
->getValue());
649 if (E
->getValue().getBitWidth() == 32) {
650 AbbrevToUse
= Writer
.getIntegerLiteralAbbrev();
653 Code
= serialization::EXPR_INTEGER_LITERAL
;
656 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral
*E
) {
658 Record
.AddSourceLocation(E
->getLocation());
659 Record
.push_back(E
->getScale());
660 Record
.AddAPInt(E
->getValue());
661 Code
= serialization::EXPR_FIXEDPOINT_LITERAL
;
664 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral
*E
) {
666 Record
.push_back(E
->getRawSemantics());
667 Record
.push_back(E
->isExact());
668 Record
.AddAPFloat(E
->getValue());
669 Record
.AddSourceLocation(E
->getLocation());
670 Code
= serialization::EXPR_FLOATING_LITERAL
;
673 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral
*E
) {
675 Record
.AddStmt(E
->getSubExpr());
676 Code
= serialization::EXPR_IMAGINARY_LITERAL
;
679 void ASTStmtWriter::VisitStringLiteral(StringLiteral
*E
) {
682 // Store the various bits of data of StringLiteral.
683 Record
.push_back(E
->getNumConcatenated());
684 Record
.push_back(E
->getLength());
685 Record
.push_back(E
->getCharByteWidth());
686 Record
.push_back(E
->getKind());
687 Record
.push_back(E
->isPascal());
689 // Store the trailing array of SourceLocation.
690 for (unsigned I
= 0, N
= E
->getNumConcatenated(); I
!= N
; ++I
)
691 Record
.AddSourceLocation(E
->getStrTokenLoc(I
));
693 // Store the trailing array of char holding the string data.
694 StringRef StrData
= E
->getBytes();
695 for (unsigned I
= 0, N
= E
->getByteLength(); I
!= N
; ++I
)
696 Record
.push_back(StrData
[I
]);
698 Code
= serialization::EXPR_STRING_LITERAL
;
701 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral
*E
) {
703 Record
.push_back(E
->getValue());
704 Record
.AddSourceLocation(E
->getLocation());
705 Record
.push_back(E
->getKind());
707 AbbrevToUse
= Writer
.getCharacterLiteralAbbrev();
709 Code
= serialization::EXPR_CHARACTER_LITERAL
;
712 void ASTStmtWriter::VisitParenExpr(ParenExpr
*E
) {
714 Record
.AddSourceLocation(E
->getLParen());
715 Record
.AddSourceLocation(E
->getRParen());
716 Record
.AddStmt(E
->getSubExpr());
717 Code
= serialization::EXPR_PAREN
;
720 void ASTStmtWriter::VisitParenListExpr(ParenListExpr
*E
) {
722 Record
.push_back(E
->getNumExprs());
723 for (auto *SubStmt
: E
->exprs())
724 Record
.AddStmt(SubStmt
);
725 Record
.AddSourceLocation(E
->getLParenLoc());
726 Record
.AddSourceLocation(E
->getRParenLoc());
727 Code
= serialization::EXPR_PAREN_LIST
;
730 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator
*E
) {
732 bool HasFPFeatures
= E
->hasStoredFPFeatures();
733 // Write this first for easy access when deserializing, as they affect the
734 // size of the UnaryOperator.
735 Record
.push_back(HasFPFeatures
);
736 Record
.AddStmt(E
->getSubExpr());
737 Record
.push_back(E
->getOpcode()); // FIXME: stable encoding
738 Record
.AddSourceLocation(E
->getOperatorLoc());
739 Record
.push_back(E
->canOverflow());
741 Record
.push_back(E
->getStoredFPFeatures().getAsOpaqueInt());
742 Code
= serialization::EXPR_UNARY_OPERATOR
;
745 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr
*E
) {
747 Record
.push_back(E
->getNumComponents());
748 Record
.push_back(E
->getNumExpressions());
749 Record
.AddSourceLocation(E
->getOperatorLoc());
750 Record
.AddSourceLocation(E
->getRParenLoc());
751 Record
.AddTypeSourceInfo(E
->getTypeSourceInfo());
752 for (unsigned I
= 0, N
= E
->getNumComponents(); I
!= N
; ++I
) {
753 const OffsetOfNode
&ON
= E
->getComponent(I
);
754 Record
.push_back(ON
.getKind()); // FIXME: Stable encoding
755 Record
.AddSourceLocation(ON
.getSourceRange().getBegin());
756 Record
.AddSourceLocation(ON
.getSourceRange().getEnd());
757 switch (ON
.getKind()) {
758 case OffsetOfNode::Array
:
759 Record
.push_back(ON
.getArrayExprIndex());
762 case OffsetOfNode::Field
:
763 Record
.AddDeclRef(ON
.getField());
766 case OffsetOfNode::Identifier
:
767 Record
.AddIdentifierRef(ON
.getFieldName());
770 case OffsetOfNode::Base
:
771 Record
.AddCXXBaseSpecifier(*ON
.getBase());
775 for (unsigned I
= 0, N
= E
->getNumExpressions(); I
!= N
; ++I
)
776 Record
.AddStmt(E
->getIndexExpr(I
));
777 Code
= serialization::EXPR_OFFSETOF
;
780 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr
*E
) {
782 Record
.push_back(E
->getKind());
783 if (E
->isArgumentType())
784 Record
.AddTypeSourceInfo(E
->getArgumentTypeInfo());
787 Record
.AddStmt(E
->getArgumentExpr());
789 Record
.AddSourceLocation(E
->getOperatorLoc());
790 Record
.AddSourceLocation(E
->getRParenLoc());
791 Code
= serialization::EXPR_SIZEOF_ALIGN_OF
;
794 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr
*E
) {
796 Record
.AddStmt(E
->getLHS());
797 Record
.AddStmt(E
->getRHS());
798 Record
.AddSourceLocation(E
->getRBracketLoc());
799 Code
= serialization::EXPR_ARRAY_SUBSCRIPT
;
802 void ASTStmtWriter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr
*E
) {
804 Record
.AddStmt(E
->getBase());
805 Record
.AddStmt(E
->getRowIdx());
806 Record
.AddStmt(E
->getColumnIdx());
807 Record
.AddSourceLocation(E
->getRBracketLoc());
808 Code
= serialization::EXPR_ARRAY_SUBSCRIPT
;
811 void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr
*E
) {
813 Record
.AddStmt(E
->getBase());
814 Record
.AddStmt(E
->getLowerBound());
815 Record
.AddStmt(E
->getLength());
816 Record
.AddStmt(E
->getStride());
817 Record
.AddSourceLocation(E
->getColonLocFirst());
818 Record
.AddSourceLocation(E
->getColonLocSecond());
819 Record
.AddSourceLocation(E
->getRBracketLoc());
820 Code
= serialization::EXPR_OMP_ARRAY_SECTION
;
823 void ASTStmtWriter::VisitOMPArrayShapingExpr(OMPArrayShapingExpr
*E
) {
825 Record
.push_back(E
->getDimensions().size());
826 Record
.AddStmt(E
->getBase());
827 for (Expr
*Dim
: E
->getDimensions())
829 for (SourceRange SR
: E
->getBracketsRanges())
830 Record
.AddSourceRange(SR
);
831 Record
.AddSourceLocation(E
->getLParenLoc());
832 Record
.AddSourceLocation(E
->getRParenLoc());
833 Code
= serialization::EXPR_OMP_ARRAY_SHAPING
;
836 void ASTStmtWriter::VisitOMPIteratorExpr(OMPIteratorExpr
*E
) {
838 Record
.push_back(E
->numOfIterators());
839 Record
.AddSourceLocation(E
->getIteratorKwLoc());
840 Record
.AddSourceLocation(E
->getLParenLoc());
841 Record
.AddSourceLocation(E
->getRParenLoc());
842 for (unsigned I
= 0, End
= E
->numOfIterators(); I
< End
; ++I
) {
843 Record
.AddDeclRef(E
->getIteratorDecl(I
));
844 Record
.AddSourceLocation(E
->getAssignLoc(I
));
845 OMPIteratorExpr::IteratorRange Range
= E
->getIteratorRange(I
);
846 Record
.AddStmt(Range
.Begin
);
847 Record
.AddStmt(Range
.End
);
848 Record
.AddStmt(Range
.Step
);
849 Record
.AddSourceLocation(E
->getColonLoc(I
));
851 Record
.AddSourceLocation(E
->getSecondColonLoc(I
));
853 OMPIteratorHelperData
&HD
= E
->getHelper(I
);
854 Record
.AddDeclRef(HD
.CounterVD
);
855 Record
.AddStmt(HD
.Upper
);
856 Record
.AddStmt(HD
.Update
);
857 Record
.AddStmt(HD
.CounterUpdate
);
859 Code
= serialization::EXPR_OMP_ITERATOR
;
862 void ASTStmtWriter::VisitCallExpr(CallExpr
*E
) {
864 Record
.push_back(E
->getNumArgs());
865 Record
.push_back(E
->hasStoredFPFeatures());
866 Record
.AddSourceLocation(E
->getRParenLoc());
867 Record
.AddStmt(E
->getCallee());
868 for (CallExpr::arg_iterator Arg
= E
->arg_begin(), ArgEnd
= E
->arg_end();
869 Arg
!= ArgEnd
; ++Arg
)
870 Record
.AddStmt(*Arg
);
871 Record
.push_back(static_cast<unsigned>(E
->getADLCallKind()));
872 if (E
->hasStoredFPFeatures())
873 Record
.push_back(E
->getFPFeatures().getAsOpaqueInt());
874 Code
= serialization::EXPR_CALL
;
877 void ASTStmtWriter::VisitRecoveryExpr(RecoveryExpr
*E
) {
879 Record
.push_back(std::distance(E
->children().begin(), E
->children().end()));
880 Record
.AddSourceLocation(E
->getBeginLoc());
881 Record
.AddSourceLocation(E
->getEndLoc());
882 for (Stmt
*Child
: E
->children())
883 Record
.AddStmt(Child
);
884 Code
= serialization::EXPR_RECOVERY
;
887 void ASTStmtWriter::VisitMemberExpr(MemberExpr
*E
) {
890 bool HasQualifier
= E
->hasQualifier();
892 E
->hasQualifierOrFoundDecl() &&
893 (E
->getFoundDecl().getDecl() != E
->getMemberDecl() ||
894 E
->getFoundDecl().getAccess() != E
->getMemberDecl()->getAccess());
895 bool HasTemplateInfo
= E
->hasTemplateKWAndArgsInfo();
896 unsigned NumTemplateArgs
= E
->getNumTemplateArgs();
898 // Write these first for easy access when deserializing, as they affect the
899 // size of the MemberExpr.
900 Record
.push_back(HasQualifier
);
901 Record
.push_back(HasFoundDecl
);
902 Record
.push_back(HasTemplateInfo
);
903 Record
.push_back(NumTemplateArgs
);
905 Record
.AddStmt(E
->getBase());
906 Record
.AddDeclRef(E
->getMemberDecl());
907 Record
.AddDeclarationNameLoc(E
->MemberDNLoc
,
908 E
->getMemberDecl()->getDeclName());
909 Record
.AddSourceLocation(E
->getMemberLoc());
910 Record
.push_back(E
->isArrow());
911 Record
.push_back(E
->hadMultipleCandidates());
912 Record
.push_back(E
->isNonOdrUse());
913 Record
.AddSourceLocation(E
->getOperatorLoc());
916 DeclAccessPair FoundDecl
= E
->getFoundDecl();
917 Record
.AddDeclRef(FoundDecl
.getDecl());
918 Record
.push_back(FoundDecl
.getAccess());
922 Record
.AddNestedNameSpecifierLoc(E
->getQualifierLoc());
925 AddTemplateKWAndArgsInfo(*E
->getTrailingObjects
<ASTTemplateKWAndArgsInfo
>(),
926 E
->getTrailingObjects
<TemplateArgumentLoc
>());
928 Code
= serialization::EXPR_MEMBER
;
931 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr
*E
) {
933 Record
.AddStmt(E
->getBase());
934 Record
.AddSourceLocation(E
->getIsaMemberLoc());
935 Record
.AddSourceLocation(E
->getOpLoc());
936 Record
.push_back(E
->isArrow());
937 Code
= serialization::EXPR_OBJC_ISA
;
941 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr
*E
) {
943 Record
.AddStmt(E
->getSubExpr());
944 Record
.push_back(E
->shouldCopy());
945 Code
= serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE
;
948 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr
*E
) {
949 VisitExplicitCastExpr(E
);
950 Record
.AddSourceLocation(E
->getLParenLoc());
951 Record
.AddSourceLocation(E
->getBridgeKeywordLoc());
952 Record
.push_back(E
->getBridgeKind()); // FIXME: Stable encoding
953 Code
= serialization::EXPR_OBJC_BRIDGED_CAST
;
956 void ASTStmtWriter::VisitCastExpr(CastExpr
*E
) {
958 Record
.push_back(E
->path_size());
959 Record
.push_back(E
->hasStoredFPFeatures());
960 Record
.AddStmt(E
->getSubExpr());
961 Record
.push_back(E
->getCastKind()); // FIXME: stable encoding
963 for (CastExpr::path_iterator
964 PI
= E
->path_begin(), PE
= E
->path_end(); PI
!= PE
; ++PI
)
965 Record
.AddCXXBaseSpecifier(**PI
);
967 if (E
->hasStoredFPFeatures())
968 Record
.push_back(E
->getFPFeatures().getAsOpaqueInt());
971 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator
*E
) {
973 bool HasFPFeatures
= E
->hasStoredFPFeatures();
974 // Write this first for easy access when deserializing, as they affect the
975 // size of the UnaryOperator.
976 Record
.push_back(HasFPFeatures
);
977 Record
.push_back(E
->getOpcode()); // FIXME: stable encoding
978 Record
.AddStmt(E
->getLHS());
979 Record
.AddStmt(E
->getRHS());
980 Record
.AddSourceLocation(E
->getOperatorLoc());
982 Record
.push_back(E
->getStoredFPFeatures().getAsOpaqueInt());
983 Code
= serialization::EXPR_BINARY_OPERATOR
;
986 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator
*E
) {
987 VisitBinaryOperator(E
);
988 Record
.AddTypeRef(E
->getComputationLHSType());
989 Record
.AddTypeRef(E
->getComputationResultType());
990 Code
= serialization::EXPR_COMPOUND_ASSIGN_OPERATOR
;
993 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator
*E
) {
995 Record
.AddStmt(E
->getCond());
996 Record
.AddStmt(E
->getLHS());
997 Record
.AddStmt(E
->getRHS());
998 Record
.AddSourceLocation(E
->getQuestionLoc());
999 Record
.AddSourceLocation(E
->getColonLoc());
1000 Code
= serialization::EXPR_CONDITIONAL_OPERATOR
;
1004 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator
*E
) {
1006 Record
.AddStmt(E
->getOpaqueValue());
1007 Record
.AddStmt(E
->getCommon());
1008 Record
.AddStmt(E
->getCond());
1009 Record
.AddStmt(E
->getTrueExpr());
1010 Record
.AddStmt(E
->getFalseExpr());
1011 Record
.AddSourceLocation(E
->getQuestionLoc());
1012 Record
.AddSourceLocation(E
->getColonLoc());
1013 Code
= serialization::EXPR_BINARY_CONDITIONAL_OPERATOR
;
1016 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr
*E
) {
1018 Record
.push_back(E
->isPartOfExplicitCast());
1020 if (E
->path_size() == 0 && !E
->hasStoredFPFeatures())
1021 AbbrevToUse
= Writer
.getExprImplicitCastAbbrev();
1023 Code
= serialization::EXPR_IMPLICIT_CAST
;
1026 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr
*E
) {
1028 Record
.AddTypeSourceInfo(E
->getTypeInfoAsWritten());
1031 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr
*E
) {
1032 VisitExplicitCastExpr(E
);
1033 Record
.AddSourceLocation(E
->getLParenLoc());
1034 Record
.AddSourceLocation(E
->getRParenLoc());
1035 Code
= serialization::EXPR_CSTYLE_CAST
;
1038 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr
*E
) {
1040 Record
.AddSourceLocation(E
->getLParenLoc());
1041 Record
.AddTypeSourceInfo(E
->getTypeSourceInfo());
1042 Record
.AddStmt(E
->getInitializer());
1043 Record
.push_back(E
->isFileScope());
1044 Code
= serialization::EXPR_COMPOUND_LITERAL
;
1047 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr
*E
) {
1049 Record
.AddStmt(E
->getBase());
1050 Record
.AddIdentifierRef(&E
->getAccessor());
1051 Record
.AddSourceLocation(E
->getAccessorLoc());
1052 Code
= serialization::EXPR_EXT_VECTOR_ELEMENT
;
1055 void ASTStmtWriter::VisitInitListExpr(InitListExpr
*E
) {
1057 // NOTE: only add the (possibly null) syntactic form.
1058 // No need to serialize the isSemanticForm flag and the semantic form.
1059 Record
.AddStmt(E
->getSyntacticForm());
1060 Record
.AddSourceLocation(E
->getLBraceLoc());
1061 Record
.AddSourceLocation(E
->getRBraceLoc());
1062 bool isArrayFiller
= E
->ArrayFillerOrUnionFieldInit
.is
<Expr
*>();
1063 Record
.push_back(isArrayFiller
);
1065 Record
.AddStmt(E
->getArrayFiller());
1067 Record
.AddDeclRef(E
->getInitializedFieldInUnion());
1068 Record
.push_back(E
->hadArrayRangeDesignator());
1069 Record
.push_back(E
->getNumInits());
1070 if (isArrayFiller
) {
1071 // ArrayFiller may have filled "holes" due to designated initializer.
1072 // Replace them by 0 to indicate that the filler goes in that place.
1073 Expr
*filler
= E
->getArrayFiller();
1074 for (unsigned I
= 0, N
= E
->getNumInits(); I
!= N
; ++I
)
1075 Record
.AddStmt(E
->getInit(I
) != filler
? E
->getInit(I
) : nullptr);
1077 for (unsigned I
= 0, N
= E
->getNumInits(); I
!= N
; ++I
)
1078 Record
.AddStmt(E
->getInit(I
));
1080 Code
= serialization::EXPR_INIT_LIST
;
1083 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr
*E
) {
1085 Record
.push_back(E
->getNumSubExprs());
1086 for (unsigned I
= 0, N
= E
->getNumSubExprs(); I
!= N
; ++I
)
1087 Record
.AddStmt(E
->getSubExpr(I
));
1088 Record
.AddSourceLocation(E
->getEqualOrColonLoc());
1089 Record
.push_back(E
->usesGNUSyntax());
1090 for (const DesignatedInitExpr::Designator
&D
: E
->designators()) {
1091 if (D
.isFieldDesignator()) {
1092 if (FieldDecl
*Field
= D
.getField()) {
1093 Record
.push_back(serialization::DESIG_FIELD_DECL
);
1094 Record
.AddDeclRef(Field
);
1096 Record
.push_back(serialization::DESIG_FIELD_NAME
);
1097 Record
.AddIdentifierRef(D
.getFieldName());
1099 Record
.AddSourceLocation(D
.getDotLoc());
1100 Record
.AddSourceLocation(D
.getFieldLoc());
1101 } else if (D
.isArrayDesignator()) {
1102 Record
.push_back(serialization::DESIG_ARRAY
);
1103 Record
.push_back(D
.getFirstExprIndex());
1104 Record
.AddSourceLocation(D
.getLBracketLoc());
1105 Record
.AddSourceLocation(D
.getRBracketLoc());
1107 assert(D
.isArrayRangeDesignator() && "Unknown designator");
1108 Record
.push_back(serialization::DESIG_ARRAY_RANGE
);
1109 Record
.push_back(D
.getFirstExprIndex());
1110 Record
.AddSourceLocation(D
.getLBracketLoc());
1111 Record
.AddSourceLocation(D
.getEllipsisLoc());
1112 Record
.AddSourceLocation(D
.getRBracketLoc());
1115 Code
= serialization::EXPR_DESIGNATED_INIT
;
1118 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr
*E
) {
1120 Record
.AddStmt(E
->getBase());
1121 Record
.AddStmt(E
->getUpdater());
1122 Code
= serialization::EXPR_DESIGNATED_INIT_UPDATE
;
1125 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr
*E
) {
1127 Code
= serialization::EXPR_NO_INIT
;
1130 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr
*E
) {
1132 Record
.AddStmt(E
->SubExprs
[0]);
1133 Record
.AddStmt(E
->SubExprs
[1]);
1134 Code
= serialization::EXPR_ARRAY_INIT_LOOP
;
1137 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr
*E
) {
1139 Code
= serialization::EXPR_ARRAY_INIT_INDEX
;
1142 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr
*E
) {
1144 Code
= serialization::EXPR_IMPLICIT_VALUE_INIT
;
1147 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr
*E
) {
1149 Record
.AddStmt(E
->getSubExpr());
1150 Record
.AddTypeSourceInfo(E
->getWrittenTypeInfo());
1151 Record
.AddSourceLocation(E
->getBuiltinLoc());
1152 Record
.AddSourceLocation(E
->getRParenLoc());
1153 Record
.push_back(E
->isMicrosoftABI());
1154 Code
= serialization::EXPR_VA_ARG
;
1157 void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr
*E
) {
1159 Record
.AddDeclRef(cast_or_null
<Decl
>(E
->getParentContext()));
1160 Record
.AddSourceLocation(E
->getBeginLoc());
1161 Record
.AddSourceLocation(E
->getEndLoc());
1162 Record
.push_back(E
->getIdentKind());
1163 Code
= serialization::EXPR_SOURCE_LOC
;
1166 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr
*E
) {
1168 Record
.AddSourceLocation(E
->getAmpAmpLoc());
1169 Record
.AddSourceLocation(E
->getLabelLoc());
1170 Record
.AddDeclRef(E
->getLabel());
1171 Code
= serialization::EXPR_ADDR_LABEL
;
1174 void ASTStmtWriter::VisitStmtExpr(StmtExpr
*E
) {
1176 Record
.AddStmt(E
->getSubStmt());
1177 Record
.AddSourceLocation(E
->getLParenLoc());
1178 Record
.AddSourceLocation(E
->getRParenLoc());
1179 Record
.push_back(E
->getTemplateDepth());
1180 Code
= serialization::EXPR_STMT
;
1183 void ASTStmtWriter::VisitChooseExpr(ChooseExpr
*E
) {
1185 Record
.AddStmt(E
->getCond());
1186 Record
.AddStmt(E
->getLHS());
1187 Record
.AddStmt(E
->getRHS());
1188 Record
.AddSourceLocation(E
->getBuiltinLoc());
1189 Record
.AddSourceLocation(E
->getRParenLoc());
1190 Record
.push_back(E
->isConditionDependent() ? false : E
->isConditionTrue());
1191 Code
= serialization::EXPR_CHOOSE
;
1194 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr
*E
) {
1196 Record
.AddSourceLocation(E
->getTokenLocation());
1197 Code
= serialization::EXPR_GNU_NULL
;
1200 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr
*E
) {
1202 Record
.push_back(E
->getNumSubExprs());
1203 for (unsigned I
= 0, N
= E
->getNumSubExprs(); I
!= N
; ++I
)
1204 Record
.AddStmt(E
->getExpr(I
));
1205 Record
.AddSourceLocation(E
->getBuiltinLoc());
1206 Record
.AddSourceLocation(E
->getRParenLoc());
1207 Code
= serialization::EXPR_SHUFFLE_VECTOR
;
1210 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr
*E
) {
1212 Record
.AddSourceLocation(E
->getBuiltinLoc());
1213 Record
.AddSourceLocation(E
->getRParenLoc());
1214 Record
.AddTypeSourceInfo(E
->getTypeSourceInfo());
1215 Record
.AddStmt(E
->getSrcExpr());
1216 Code
= serialization::EXPR_CONVERT_VECTOR
;
1219 void ASTStmtWriter::VisitBlockExpr(BlockExpr
*E
) {
1221 Record
.AddDeclRef(E
->getBlockDecl());
1222 Code
= serialization::EXPR_BLOCK
;
1225 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr
*E
) {
1228 Record
.push_back(E
->getNumAssocs());
1229 Record
.push_back(E
->ResultIndex
);
1230 Record
.AddSourceLocation(E
->getGenericLoc());
1231 Record
.AddSourceLocation(E
->getDefaultLoc());
1232 Record
.AddSourceLocation(E
->getRParenLoc());
1234 Stmt
**Stmts
= E
->getTrailingObjects
<Stmt
*>();
1235 // Add 1 to account for the controlling expression which is the first
1236 // expression in the trailing array of Stmt *. This is not needed for
1237 // the trailing array of TypeSourceInfo *.
1238 for (unsigned I
= 0, N
= E
->getNumAssocs() + 1; I
< N
; ++I
)
1239 Record
.AddStmt(Stmts
[I
]);
1241 TypeSourceInfo
**TSIs
= E
->getTrailingObjects
<TypeSourceInfo
*>();
1242 for (unsigned I
= 0, N
= E
->getNumAssocs(); I
< N
; ++I
)
1243 Record
.AddTypeSourceInfo(TSIs
[I
]);
1245 Code
= serialization::EXPR_GENERIC_SELECTION
;
1248 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr
*E
) {
1250 Record
.push_back(E
->getNumSemanticExprs());
1252 // Push the result index. Currently, this needs to exactly match
1253 // the encoding used internally for ResultIndex.
1254 unsigned result
= E
->getResultExprIndex();
1255 result
= (result
== PseudoObjectExpr::NoResult
? 0 : result
+ 1);
1256 Record
.push_back(result
);
1258 Record
.AddStmt(E
->getSyntacticForm());
1259 for (PseudoObjectExpr::semantics_iterator
1260 i
= E
->semantics_begin(), e
= E
->semantics_end(); i
!= e
; ++i
) {
1263 Code
= serialization::EXPR_PSEUDO_OBJECT
;
1266 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr
*E
) {
1268 Record
.push_back(E
->getOp());
1269 for (unsigned I
= 0, N
= E
->getNumSubExprs(); I
!= N
; ++I
)
1270 Record
.AddStmt(E
->getSubExprs()[I
]);
1271 Record
.AddSourceLocation(E
->getBuiltinLoc());
1272 Record
.AddSourceLocation(E
->getRParenLoc());
1273 Code
= serialization::EXPR_ATOMIC
;
1276 //===----------------------------------------------------------------------===//
1277 // Objective-C Expressions and Statements.
1278 //===----------------------------------------------------------------------===//
1280 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral
*E
) {
1282 Record
.AddStmt(E
->getString());
1283 Record
.AddSourceLocation(E
->getAtLoc());
1284 Code
= serialization::EXPR_OBJC_STRING_LITERAL
;
1287 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr
*E
) {
1289 Record
.AddStmt(E
->getSubExpr());
1290 Record
.AddDeclRef(E
->getBoxingMethod());
1291 Record
.AddSourceRange(E
->getSourceRange());
1292 Code
= serialization::EXPR_OBJC_BOXED_EXPRESSION
;
1295 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral
*E
) {
1297 Record
.push_back(E
->getNumElements());
1298 for (unsigned i
= 0; i
< E
->getNumElements(); i
++)
1299 Record
.AddStmt(E
->getElement(i
));
1300 Record
.AddDeclRef(E
->getArrayWithObjectsMethod());
1301 Record
.AddSourceRange(E
->getSourceRange());
1302 Code
= serialization::EXPR_OBJC_ARRAY_LITERAL
;
1305 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral
*E
) {
1307 Record
.push_back(E
->getNumElements());
1308 Record
.push_back(E
->HasPackExpansions
);
1309 for (unsigned i
= 0; i
< E
->getNumElements(); i
++) {
1310 ObjCDictionaryElement Element
= E
->getKeyValueElement(i
);
1311 Record
.AddStmt(Element
.Key
);
1312 Record
.AddStmt(Element
.Value
);
1313 if (E
->HasPackExpansions
) {
1314 Record
.AddSourceLocation(Element
.EllipsisLoc
);
1315 unsigned NumExpansions
= 0;
1316 if (Element
.NumExpansions
)
1317 NumExpansions
= *Element
.NumExpansions
+ 1;
1318 Record
.push_back(NumExpansions
);
1322 Record
.AddDeclRef(E
->getDictWithObjectsMethod());
1323 Record
.AddSourceRange(E
->getSourceRange());
1324 Code
= serialization::EXPR_OBJC_DICTIONARY_LITERAL
;
1327 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr
*E
) {
1329 Record
.AddTypeSourceInfo(E
->getEncodedTypeSourceInfo());
1330 Record
.AddSourceLocation(E
->getAtLoc());
1331 Record
.AddSourceLocation(E
->getRParenLoc());
1332 Code
= serialization::EXPR_OBJC_ENCODE
;
1335 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr
*E
) {
1337 Record
.AddSelectorRef(E
->getSelector());
1338 Record
.AddSourceLocation(E
->getAtLoc());
1339 Record
.AddSourceLocation(E
->getRParenLoc());
1340 Code
= serialization::EXPR_OBJC_SELECTOR_EXPR
;
1343 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr
*E
) {
1345 Record
.AddDeclRef(E
->getProtocol());
1346 Record
.AddSourceLocation(E
->getAtLoc());
1347 Record
.AddSourceLocation(E
->ProtoLoc
);
1348 Record
.AddSourceLocation(E
->getRParenLoc());
1349 Code
= serialization::EXPR_OBJC_PROTOCOL_EXPR
;
1352 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr
*E
) {
1354 Record
.AddDeclRef(E
->getDecl());
1355 Record
.AddSourceLocation(E
->getLocation());
1356 Record
.AddSourceLocation(E
->getOpLoc());
1357 Record
.AddStmt(E
->getBase());
1358 Record
.push_back(E
->isArrow());
1359 Record
.push_back(E
->isFreeIvar());
1360 Code
= serialization::EXPR_OBJC_IVAR_REF_EXPR
;
1363 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr
*E
) {
1365 Record
.push_back(E
->SetterAndMethodRefFlags
.getInt());
1366 Record
.push_back(E
->isImplicitProperty());
1367 if (E
->isImplicitProperty()) {
1368 Record
.AddDeclRef(E
->getImplicitPropertyGetter());
1369 Record
.AddDeclRef(E
->getImplicitPropertySetter());
1371 Record
.AddDeclRef(E
->getExplicitProperty());
1373 Record
.AddSourceLocation(E
->getLocation());
1374 Record
.AddSourceLocation(E
->getReceiverLocation());
1375 if (E
->isObjectReceiver()) {
1376 Record
.push_back(0);
1377 Record
.AddStmt(E
->getBase());
1378 } else if (E
->isSuperReceiver()) {
1379 Record
.push_back(1);
1380 Record
.AddTypeRef(E
->getSuperReceiverType());
1382 Record
.push_back(2);
1383 Record
.AddDeclRef(E
->getClassReceiver());
1386 Code
= serialization::EXPR_OBJC_PROPERTY_REF_EXPR
;
1389 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr
*E
) {
1391 Record
.AddSourceLocation(E
->getRBracket());
1392 Record
.AddStmt(E
->getBaseExpr());
1393 Record
.AddStmt(E
->getKeyExpr());
1394 Record
.AddDeclRef(E
->getAtIndexMethodDecl());
1395 Record
.AddDeclRef(E
->setAtIndexMethodDecl());
1397 Code
= serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR
;
1400 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr
*E
) {
1402 Record
.push_back(E
->getNumArgs());
1403 Record
.push_back(E
->getNumStoredSelLocs());
1404 Record
.push_back(E
->SelLocsKind
);
1405 Record
.push_back(E
->isDelegateInitCall());
1406 Record
.push_back(E
->IsImplicit
);
1407 Record
.push_back((unsigned)E
->getReceiverKind()); // FIXME: stable encoding
1408 switch (E
->getReceiverKind()) {
1409 case ObjCMessageExpr::Instance
:
1410 Record
.AddStmt(E
->getInstanceReceiver());
1413 case ObjCMessageExpr::Class
:
1414 Record
.AddTypeSourceInfo(E
->getClassReceiverTypeInfo());
1417 case ObjCMessageExpr::SuperClass
:
1418 case ObjCMessageExpr::SuperInstance
:
1419 Record
.AddTypeRef(E
->getSuperType());
1420 Record
.AddSourceLocation(E
->getSuperLoc());
1424 if (E
->getMethodDecl()) {
1425 Record
.push_back(1);
1426 Record
.AddDeclRef(E
->getMethodDecl());
1428 Record
.push_back(0);
1429 Record
.AddSelectorRef(E
->getSelector());
1432 Record
.AddSourceLocation(E
->getLeftLoc());
1433 Record
.AddSourceLocation(E
->getRightLoc());
1435 for (CallExpr::arg_iterator Arg
= E
->arg_begin(), ArgEnd
= E
->arg_end();
1436 Arg
!= ArgEnd
; ++Arg
)
1437 Record
.AddStmt(*Arg
);
1439 SourceLocation
*Locs
= E
->getStoredSelLocs();
1440 for (unsigned i
= 0, e
= E
->getNumStoredSelLocs(); i
!= e
; ++i
)
1441 Record
.AddSourceLocation(Locs
[i
]);
1443 Code
= serialization::EXPR_OBJC_MESSAGE_EXPR
;
1446 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt
*S
) {
1448 Record
.AddStmt(S
->getElement());
1449 Record
.AddStmt(S
->getCollection());
1450 Record
.AddStmt(S
->getBody());
1451 Record
.AddSourceLocation(S
->getForLoc());
1452 Record
.AddSourceLocation(S
->getRParenLoc());
1453 Code
= serialization::STMT_OBJC_FOR_COLLECTION
;
1456 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt
*S
) {
1458 Record
.AddStmt(S
->getCatchBody());
1459 Record
.AddDeclRef(S
->getCatchParamDecl());
1460 Record
.AddSourceLocation(S
->getAtCatchLoc());
1461 Record
.AddSourceLocation(S
->getRParenLoc());
1462 Code
= serialization::STMT_OBJC_CATCH
;
1465 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt
*S
) {
1467 Record
.AddStmt(S
->getFinallyBody());
1468 Record
.AddSourceLocation(S
->getAtFinallyLoc());
1469 Code
= serialization::STMT_OBJC_FINALLY
;
1472 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt
*S
) {
1473 VisitStmt(S
); // FIXME: no test coverage.
1474 Record
.AddStmt(S
->getSubStmt());
1475 Record
.AddSourceLocation(S
->getAtLoc());
1476 Code
= serialization::STMT_OBJC_AUTORELEASE_POOL
;
1479 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt
*S
) {
1481 Record
.push_back(S
->getNumCatchStmts());
1482 Record
.push_back(S
->getFinallyStmt() != nullptr);
1483 Record
.AddStmt(S
->getTryBody());
1484 for (ObjCAtCatchStmt
*C
: S
->catch_stmts())
1486 if (S
->getFinallyStmt())
1487 Record
.AddStmt(S
->getFinallyStmt());
1488 Record
.AddSourceLocation(S
->getAtTryLoc());
1489 Code
= serialization::STMT_OBJC_AT_TRY
;
1492 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt
*S
) {
1493 VisitStmt(S
); // FIXME: no test coverage.
1494 Record
.AddStmt(S
->getSynchExpr());
1495 Record
.AddStmt(S
->getSynchBody());
1496 Record
.AddSourceLocation(S
->getAtSynchronizedLoc());
1497 Code
= serialization::STMT_OBJC_AT_SYNCHRONIZED
;
1500 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt
*S
) {
1501 VisitStmt(S
); // FIXME: no test coverage.
1502 Record
.AddStmt(S
->getThrowExpr());
1503 Record
.AddSourceLocation(S
->getThrowLoc());
1504 Code
= serialization::STMT_OBJC_AT_THROW
;
1507 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr
*E
) {
1509 Record
.push_back(E
->getValue());
1510 Record
.AddSourceLocation(E
->getLocation());
1511 Code
= serialization::EXPR_OBJC_BOOL_LITERAL
;
1514 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr
*E
) {
1516 Record
.AddSourceRange(E
->getSourceRange());
1517 Record
.AddVersionTuple(E
->getVersion());
1518 Code
= serialization::EXPR_OBJC_AVAILABILITY_CHECK
;
1521 //===----------------------------------------------------------------------===//
1522 // C++ Expressions and Statements.
1523 //===----------------------------------------------------------------------===//
1525 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt
*S
) {
1527 Record
.AddSourceLocation(S
->getCatchLoc());
1528 Record
.AddDeclRef(S
->getExceptionDecl());
1529 Record
.AddStmt(S
->getHandlerBlock());
1530 Code
= serialization::STMT_CXX_CATCH
;
1533 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt
*S
) {
1535 Record
.push_back(S
->getNumHandlers());
1536 Record
.AddSourceLocation(S
->getTryLoc());
1537 Record
.AddStmt(S
->getTryBlock());
1538 for (unsigned i
= 0, e
= S
->getNumHandlers(); i
!= e
; ++i
)
1539 Record
.AddStmt(S
->getHandler(i
));
1540 Code
= serialization::STMT_CXX_TRY
;
1543 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt
*S
) {
1545 Record
.AddSourceLocation(S
->getForLoc());
1546 Record
.AddSourceLocation(S
->getCoawaitLoc());
1547 Record
.AddSourceLocation(S
->getColonLoc());
1548 Record
.AddSourceLocation(S
->getRParenLoc());
1549 Record
.AddStmt(S
->getInit());
1550 Record
.AddStmt(S
->getRangeStmt());
1551 Record
.AddStmt(S
->getBeginStmt());
1552 Record
.AddStmt(S
->getEndStmt());
1553 Record
.AddStmt(S
->getCond());
1554 Record
.AddStmt(S
->getInc());
1555 Record
.AddStmt(S
->getLoopVarStmt());
1556 Record
.AddStmt(S
->getBody());
1557 Code
= serialization::STMT_CXX_FOR_RANGE
;
1560 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt
*S
) {
1562 Record
.AddSourceLocation(S
->getKeywordLoc());
1563 Record
.push_back(S
->isIfExists());
1564 Record
.AddNestedNameSpecifierLoc(S
->getQualifierLoc());
1565 Record
.AddDeclarationNameInfo(S
->getNameInfo());
1566 Record
.AddStmt(S
->getSubStmt());
1567 Code
= serialization::STMT_MS_DEPENDENT_EXISTS
;
1570 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr
*E
) {
1572 Record
.push_back(E
->getOperator());
1573 Record
.AddSourceRange(E
->Range
);
1574 Code
= serialization::EXPR_CXX_OPERATOR_CALL
;
1577 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr
*E
) {
1579 Code
= serialization::EXPR_CXX_MEMBER_CALL
;
1582 void ASTStmtWriter::VisitCXXRewrittenBinaryOperator(
1583 CXXRewrittenBinaryOperator
*E
) {
1585 Record
.push_back(E
->isReversed());
1586 Record
.AddStmt(E
->getSemanticForm());
1587 Code
= serialization::EXPR_CXX_REWRITTEN_BINARY_OPERATOR
;
1590 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr
*E
) {
1593 Record
.push_back(E
->getNumArgs());
1594 Record
.push_back(E
->isElidable());
1595 Record
.push_back(E
->hadMultipleCandidates());
1596 Record
.push_back(E
->isListInitialization());
1597 Record
.push_back(E
->isStdInitListInitialization());
1598 Record
.push_back(E
->requiresZeroInitialization());
1599 Record
.push_back(E
->getConstructionKind()); // FIXME: stable encoding
1600 Record
.AddSourceLocation(E
->getLocation());
1601 Record
.AddDeclRef(E
->getConstructor());
1602 Record
.AddSourceRange(E
->getParenOrBraceRange());
1604 for (unsigned I
= 0, N
= E
->getNumArgs(); I
!= N
; ++I
)
1605 Record
.AddStmt(E
->getArg(I
));
1607 Code
= serialization::EXPR_CXX_CONSTRUCT
;
1610 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr
*E
) {
1612 Record
.AddDeclRef(E
->getConstructor());
1613 Record
.AddSourceLocation(E
->getLocation());
1614 Record
.push_back(E
->constructsVBase());
1615 Record
.push_back(E
->inheritedFromVBase());
1616 Code
= serialization::EXPR_CXX_INHERITED_CTOR_INIT
;
1619 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr
*E
) {
1620 VisitCXXConstructExpr(E
);
1621 Record
.AddTypeSourceInfo(E
->getTypeSourceInfo());
1622 Code
= serialization::EXPR_CXX_TEMPORARY_OBJECT
;
1625 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr
*E
) {
1627 Record
.push_back(E
->LambdaExprBits
.NumCaptures
);
1628 Record
.AddSourceRange(E
->IntroducerRange
);
1629 Record
.push_back(E
->LambdaExprBits
.CaptureDefault
); // FIXME: stable encoding
1630 Record
.AddSourceLocation(E
->CaptureDefaultLoc
);
1631 Record
.push_back(E
->LambdaExprBits
.ExplicitParams
);
1632 Record
.push_back(E
->LambdaExprBits
.ExplicitResultType
);
1633 Record
.AddSourceLocation(E
->ClosingBrace
);
1635 // Add capture initializers.
1636 for (LambdaExpr::capture_init_iterator C
= E
->capture_init_begin(),
1637 CEnd
= E
->capture_init_end();
1642 // Don't serialize the body. It belongs to the call operator declaration.
1643 // LambdaExpr only stores a copy of the Stmt *.
1645 Code
= serialization::EXPR_LAMBDA
;
1648 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr
*E
) {
1650 Record
.AddStmt(E
->getSubExpr());
1651 Code
= serialization::EXPR_CXX_STD_INITIALIZER_LIST
;
1654 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr
*E
) {
1655 VisitExplicitCastExpr(E
);
1656 Record
.AddSourceRange(SourceRange(E
->getOperatorLoc(), E
->getRParenLoc()));
1657 Record
.AddSourceRange(E
->getAngleBrackets());
1660 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr
*E
) {
1661 VisitCXXNamedCastExpr(E
);
1662 Code
= serialization::EXPR_CXX_STATIC_CAST
;
1665 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr
*E
) {
1666 VisitCXXNamedCastExpr(E
);
1667 Code
= serialization::EXPR_CXX_DYNAMIC_CAST
;
1670 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr
*E
) {
1671 VisitCXXNamedCastExpr(E
);
1672 Code
= serialization::EXPR_CXX_REINTERPRET_CAST
;
1675 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr
*E
) {
1676 VisitCXXNamedCastExpr(E
);
1677 Code
= serialization::EXPR_CXX_CONST_CAST
;
1680 void ASTStmtWriter::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr
*E
) {
1681 VisitCXXNamedCastExpr(E
);
1682 Code
= serialization::EXPR_CXX_ADDRSPACE_CAST
;
1685 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr
*E
) {
1686 VisitExplicitCastExpr(E
);
1687 Record
.AddSourceLocation(E
->getLParenLoc());
1688 Record
.AddSourceLocation(E
->getRParenLoc());
1689 Code
= serialization::EXPR_CXX_FUNCTIONAL_CAST
;
1692 void ASTStmtWriter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr
*E
) {
1693 VisitExplicitCastExpr(E
);
1694 Record
.AddSourceLocation(E
->getBeginLoc());
1695 Record
.AddSourceLocation(E
->getEndLoc());
1696 Code
= serialization::EXPR_BUILTIN_BIT_CAST
;
1699 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral
*E
) {
1701 Record
.AddSourceLocation(E
->UDSuffixLoc
);
1702 Code
= serialization::EXPR_USER_DEFINED_LITERAL
;
1705 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr
*E
) {
1707 Record
.push_back(E
->getValue());
1708 Record
.AddSourceLocation(E
->getLocation());
1709 Code
= serialization::EXPR_CXX_BOOL_LITERAL
;
1712 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr
*E
) {
1714 Record
.AddSourceLocation(E
->getLocation());
1715 Code
= serialization::EXPR_CXX_NULL_PTR_LITERAL
;
1718 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr
*E
) {
1720 Record
.AddSourceRange(E
->getSourceRange());
1721 if (E
->isTypeOperand()) {
1722 Record
.AddTypeSourceInfo(E
->getTypeOperandSourceInfo());
1723 Code
= serialization::EXPR_CXX_TYPEID_TYPE
;
1725 Record
.AddStmt(E
->getExprOperand());
1726 Code
= serialization::EXPR_CXX_TYPEID_EXPR
;
1730 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr
*E
) {
1732 Record
.AddSourceLocation(E
->getLocation());
1733 Record
.push_back(E
->isImplicit());
1734 Code
= serialization::EXPR_CXX_THIS
;
1737 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr
*E
) {
1739 Record
.AddSourceLocation(E
->getThrowLoc());
1740 Record
.AddStmt(E
->getSubExpr());
1741 Record
.push_back(E
->isThrownVariableInScope());
1742 Code
= serialization::EXPR_CXX_THROW
;
1745 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr
*E
) {
1747 Record
.AddDeclRef(E
->getParam());
1748 Record
.AddDeclRef(cast_or_null
<Decl
>(E
->getUsedContext()));
1749 Record
.AddSourceLocation(E
->getUsedLocation());
1750 Code
= serialization::EXPR_CXX_DEFAULT_ARG
;
1753 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr
*E
) {
1755 Record
.AddDeclRef(E
->getField());
1756 Record
.AddDeclRef(cast_or_null
<Decl
>(E
->getUsedContext()));
1757 Record
.AddSourceLocation(E
->getExprLoc());
1758 Code
= serialization::EXPR_CXX_DEFAULT_INIT
;
1761 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr
*E
) {
1763 Record
.AddCXXTemporary(E
->getTemporary());
1764 Record
.AddStmt(E
->getSubExpr());
1765 Code
= serialization::EXPR_CXX_BIND_TEMPORARY
;
1768 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr
*E
) {
1770 Record
.AddTypeSourceInfo(E
->getTypeSourceInfo());
1771 Record
.AddSourceLocation(E
->getRParenLoc());
1772 Code
= serialization::EXPR_CXX_SCALAR_VALUE_INIT
;
1775 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr
*E
) {
1778 Record
.push_back(E
->isArray());
1779 Record
.push_back(E
->hasInitializer());
1780 Record
.push_back(E
->getNumPlacementArgs());
1781 Record
.push_back(E
->isParenTypeId());
1783 Record
.push_back(E
->isGlobalNew());
1784 Record
.push_back(E
->passAlignment());
1785 Record
.push_back(E
->doesUsualArrayDeleteWantSize());
1786 Record
.push_back(E
->CXXNewExprBits
.StoredInitializationStyle
);
1788 Record
.AddDeclRef(E
->getOperatorNew());
1789 Record
.AddDeclRef(E
->getOperatorDelete());
1790 Record
.AddTypeSourceInfo(E
->getAllocatedTypeSourceInfo());
1791 if (E
->isParenTypeId())
1792 Record
.AddSourceRange(E
->getTypeIdParens());
1793 Record
.AddSourceRange(E
->getSourceRange());
1794 Record
.AddSourceRange(E
->getDirectInitRange());
1796 for (CXXNewExpr::arg_iterator I
= E
->raw_arg_begin(), N
= E
->raw_arg_end();
1800 Code
= serialization::EXPR_CXX_NEW
;
1803 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr
*E
) {
1805 Record
.push_back(E
->isGlobalDelete());
1806 Record
.push_back(E
->isArrayForm());
1807 Record
.push_back(E
->isArrayFormAsWritten());
1808 Record
.push_back(E
->doesUsualArrayDeleteWantSize());
1809 Record
.AddDeclRef(E
->getOperatorDelete());
1810 Record
.AddStmt(E
->getArgument());
1811 Record
.AddSourceLocation(E
->getBeginLoc());
1813 Code
= serialization::EXPR_CXX_DELETE
;
1816 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr
*E
) {
1819 Record
.AddStmt(E
->getBase());
1820 Record
.push_back(E
->isArrow());
1821 Record
.AddSourceLocation(E
->getOperatorLoc());
1822 Record
.AddNestedNameSpecifierLoc(E
->getQualifierLoc());
1823 Record
.AddTypeSourceInfo(E
->getScopeTypeInfo());
1824 Record
.AddSourceLocation(E
->getColonColonLoc());
1825 Record
.AddSourceLocation(E
->getTildeLoc());
1827 // PseudoDestructorTypeStorage.
1828 Record
.AddIdentifierRef(E
->getDestroyedTypeIdentifier());
1829 if (E
->getDestroyedTypeIdentifier())
1830 Record
.AddSourceLocation(E
->getDestroyedTypeLoc());
1832 Record
.AddTypeSourceInfo(E
->getDestroyedTypeInfo());
1834 Code
= serialization::EXPR_CXX_PSEUDO_DESTRUCTOR
;
1837 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups
*E
) {
1839 Record
.push_back(E
->getNumObjects());
1840 for (auto &Obj
: E
->getObjects()) {
1841 if (auto *BD
= Obj
.dyn_cast
<BlockDecl
*>()) {
1842 Record
.push_back(serialization::COK_Block
);
1843 Record
.AddDeclRef(BD
);
1844 } else if (auto *CLE
= Obj
.dyn_cast
<CompoundLiteralExpr
*>()) {
1845 Record
.push_back(serialization::COK_CompoundLiteral
);
1846 Record
.AddStmt(CLE
);
1850 Record
.push_back(E
->cleanupsHaveSideEffects());
1851 Record
.AddStmt(E
->getSubExpr());
1852 Code
= serialization::EXPR_EXPR_WITH_CLEANUPS
;
1855 void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
1856 CXXDependentScopeMemberExpr
*E
) {
1859 // Don't emit anything here (or if you do you will have to update
1860 // the corresponding deserialization function).
1862 Record
.push_back(E
->hasTemplateKWAndArgsInfo());
1863 Record
.push_back(E
->getNumTemplateArgs());
1864 Record
.push_back(E
->hasFirstQualifierFoundInScope());
1866 if (E
->hasTemplateKWAndArgsInfo()) {
1867 const ASTTemplateKWAndArgsInfo
&ArgInfo
=
1868 *E
->getTrailingObjects
<ASTTemplateKWAndArgsInfo
>();
1869 AddTemplateKWAndArgsInfo(ArgInfo
,
1870 E
->getTrailingObjects
<TemplateArgumentLoc
>());
1873 Record
.push_back(E
->isArrow());
1874 Record
.AddSourceLocation(E
->getOperatorLoc());
1875 Record
.AddTypeRef(E
->getBaseType());
1876 Record
.AddNestedNameSpecifierLoc(E
->getQualifierLoc());
1877 if (!E
->isImplicitAccess())
1878 Record
.AddStmt(E
->getBase());
1880 Record
.AddStmt(nullptr);
1882 if (E
->hasFirstQualifierFoundInScope())
1883 Record
.AddDeclRef(E
->getFirstQualifierFoundInScope());
1885 Record
.AddDeclarationNameInfo(E
->MemberNameInfo
);
1886 Code
= serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER
;
1890 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr
*E
) {
1893 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1896 Record
.push_back(E
->DependentScopeDeclRefExprBits
.HasTemplateKWAndArgsInfo
);
1897 if (E
->DependentScopeDeclRefExprBits
.HasTemplateKWAndArgsInfo
) {
1898 const ASTTemplateKWAndArgsInfo
&ArgInfo
=
1899 *E
->getTrailingObjects
<ASTTemplateKWAndArgsInfo
>();
1900 Record
.push_back(ArgInfo
.NumTemplateArgs
);
1901 AddTemplateKWAndArgsInfo(ArgInfo
,
1902 E
->getTrailingObjects
<TemplateArgumentLoc
>());
1905 Record
.AddNestedNameSpecifierLoc(E
->getQualifierLoc());
1906 Record
.AddDeclarationNameInfo(E
->NameInfo
);
1907 Code
= serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF
;
1911 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr
*E
) {
1913 Record
.push_back(E
->getNumArgs());
1914 for (CXXUnresolvedConstructExpr::arg_iterator
1915 ArgI
= E
->arg_begin(), ArgE
= E
->arg_end(); ArgI
!= ArgE
; ++ArgI
)
1916 Record
.AddStmt(*ArgI
);
1917 Record
.AddTypeSourceInfo(E
->getTypeSourceInfo());
1918 Record
.AddSourceLocation(E
->getLParenLoc());
1919 Record
.AddSourceLocation(E
->getRParenLoc());
1920 Code
= serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT
;
1923 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr
*E
) {
1926 Record
.push_back(E
->getNumDecls());
1927 Record
.push_back(E
->hasTemplateKWAndArgsInfo());
1928 if (E
->hasTemplateKWAndArgsInfo()) {
1929 const ASTTemplateKWAndArgsInfo
&ArgInfo
=
1930 *E
->getTrailingASTTemplateKWAndArgsInfo();
1931 Record
.push_back(ArgInfo
.NumTemplateArgs
);
1932 AddTemplateKWAndArgsInfo(ArgInfo
, E
->getTrailingTemplateArgumentLoc());
1935 for (OverloadExpr::decls_iterator OvI
= E
->decls_begin(),
1936 OvE
= E
->decls_end();
1937 OvI
!= OvE
; ++OvI
) {
1938 Record
.AddDeclRef(OvI
.getDecl());
1939 Record
.push_back(OvI
.getAccess());
1942 Record
.AddDeclarationNameInfo(E
->getNameInfo());
1943 Record
.AddNestedNameSpecifierLoc(E
->getQualifierLoc());
1946 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr
*E
) {
1947 VisitOverloadExpr(E
);
1948 Record
.push_back(E
->isArrow());
1949 Record
.push_back(E
->hasUnresolvedUsing());
1950 Record
.AddStmt(!E
->isImplicitAccess() ? E
->getBase() : nullptr);
1951 Record
.AddTypeRef(E
->getBaseType());
1952 Record
.AddSourceLocation(E
->getOperatorLoc());
1953 Code
= serialization::EXPR_CXX_UNRESOLVED_MEMBER
;
1956 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr
*E
) {
1957 VisitOverloadExpr(E
);
1958 Record
.push_back(E
->requiresADL());
1959 Record
.push_back(E
->isOverloaded());
1960 Record
.AddDeclRef(E
->getNamingClass());
1961 Code
= serialization::EXPR_CXX_UNRESOLVED_LOOKUP
;
1964 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr
*E
) {
1966 Record
.push_back(E
->TypeTraitExprBits
.NumArgs
);
1967 Record
.push_back(E
->TypeTraitExprBits
.Kind
); // FIXME: Stable encoding
1968 Record
.push_back(E
->TypeTraitExprBits
.Value
);
1969 Record
.AddSourceRange(E
->getSourceRange());
1970 for (unsigned I
= 0, N
= E
->getNumArgs(); I
!= N
; ++I
)
1971 Record
.AddTypeSourceInfo(E
->getArg(I
));
1972 Code
= serialization::EXPR_TYPE_TRAIT
;
1975 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr
*E
) {
1977 Record
.push_back(E
->getTrait());
1978 Record
.push_back(E
->getValue());
1979 Record
.AddSourceRange(E
->getSourceRange());
1980 Record
.AddTypeSourceInfo(E
->getQueriedTypeSourceInfo());
1981 Record
.AddStmt(E
->getDimensionExpression());
1982 Code
= serialization::EXPR_ARRAY_TYPE_TRAIT
;
1985 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr
*E
) {
1987 Record
.push_back(E
->getTrait());
1988 Record
.push_back(E
->getValue());
1989 Record
.AddSourceRange(E
->getSourceRange());
1990 Record
.AddStmt(E
->getQueriedExpression());
1991 Code
= serialization::EXPR_CXX_EXPRESSION_TRAIT
;
1994 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr
*E
) {
1996 Record
.push_back(E
->getValue());
1997 Record
.AddSourceRange(E
->getSourceRange());
1998 Record
.AddStmt(E
->getOperand());
1999 Code
= serialization::EXPR_CXX_NOEXCEPT
;
2002 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr
*E
) {
2004 Record
.AddSourceLocation(E
->getEllipsisLoc());
2005 Record
.push_back(E
->NumExpansions
);
2006 Record
.AddStmt(E
->getPattern());
2007 Code
= serialization::EXPR_PACK_EXPANSION
;
2010 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr
*E
) {
2012 Record
.push_back(E
->isPartiallySubstituted() ? E
->getPartialArguments().size()
2014 Record
.AddSourceLocation(E
->OperatorLoc
);
2015 Record
.AddSourceLocation(E
->PackLoc
);
2016 Record
.AddSourceLocation(E
->RParenLoc
);
2017 Record
.AddDeclRef(E
->Pack
);
2018 if (E
->isPartiallySubstituted()) {
2019 for (const auto &TA
: E
->getPartialArguments())
2020 Record
.AddTemplateArgument(TA
);
2021 } else if (!E
->isValueDependent()) {
2022 Record
.push_back(E
->getPackLength());
2024 Code
= serialization::EXPR_SIZEOF_PACK
;
2027 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
2028 SubstNonTypeTemplateParmExpr
*E
) {
2030 Record
.AddDeclRef(E
->getParameter());
2031 Record
.push_back(E
->isReferenceParameter());
2032 Record
.AddSourceLocation(E
->getNameLoc());
2033 Record
.AddStmt(E
->getReplacement());
2034 Code
= serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM
;
2037 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
2038 SubstNonTypeTemplateParmPackExpr
*E
) {
2040 Record
.AddDeclRef(E
->getParameterPack());
2041 Record
.AddTemplateArgument(E
->getArgumentPack());
2042 Record
.AddSourceLocation(E
->getParameterPackLocation());
2043 Code
= serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK
;
2046 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr
*E
) {
2048 Record
.push_back(E
->getNumExpansions());
2049 Record
.AddDeclRef(E
->getParameterPack());
2050 Record
.AddSourceLocation(E
->getParameterPackLocation());
2051 for (FunctionParmPackExpr::iterator I
= E
->begin(), End
= E
->end();
2053 Record
.AddDeclRef(*I
);
2054 Code
= serialization::EXPR_FUNCTION_PARM_PACK
;
2057 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr
*E
) {
2059 Record
.push_back(static_cast<bool>(E
->getLifetimeExtendedTemporaryDecl()));
2060 if (E
->getLifetimeExtendedTemporaryDecl())
2061 Record
.AddDeclRef(E
->getLifetimeExtendedTemporaryDecl());
2063 Record
.AddStmt(E
->getSubExpr());
2064 Code
= serialization::EXPR_MATERIALIZE_TEMPORARY
;
2067 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr
*E
) {
2069 Record
.AddSourceLocation(E
->LParenLoc
);
2070 Record
.AddSourceLocation(E
->EllipsisLoc
);
2071 Record
.AddSourceLocation(E
->RParenLoc
);
2072 Record
.push_back(E
->NumExpansions
);
2073 Record
.AddStmt(E
->SubExprs
[0]);
2074 Record
.AddStmt(E
->SubExprs
[1]);
2075 Record
.AddStmt(E
->SubExprs
[2]);
2076 Record
.push_back(E
->Opcode
);
2077 Code
= serialization::EXPR_CXX_FOLD
;
2080 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr
*E
) {
2082 Record
.AddStmt(E
->getSourceExpr());
2083 Record
.AddSourceLocation(E
->getLocation());
2084 Record
.push_back(E
->isUnique());
2085 Code
= serialization::EXPR_OPAQUE_VALUE
;
2088 void ASTStmtWriter::VisitTypoExpr(TypoExpr
*E
) {
2090 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
2091 llvm_unreachable("Cannot write TypoExpr nodes");
2094 //===----------------------------------------------------------------------===//
2095 // CUDA Expressions and Statements.
2096 //===----------------------------------------------------------------------===//
2098 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr
*E
) {
2100 Record
.AddStmt(E
->getConfig());
2101 Code
= serialization::EXPR_CUDA_KERNEL_CALL
;
2104 //===----------------------------------------------------------------------===//
2105 // OpenCL Expressions and Statements.
2106 //===----------------------------------------------------------------------===//
2107 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr
*E
) {
2109 Record
.AddSourceLocation(E
->getBuiltinLoc());
2110 Record
.AddSourceLocation(E
->getRParenLoc());
2111 Record
.AddStmt(E
->getSrcExpr());
2112 Code
= serialization::EXPR_ASTYPE
;
2115 //===----------------------------------------------------------------------===//
2116 // Microsoft Expressions and Statements.
2117 //===----------------------------------------------------------------------===//
2118 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr
*E
) {
2120 Record
.push_back(E
->isArrow());
2121 Record
.AddStmt(E
->getBaseExpr());
2122 Record
.AddNestedNameSpecifierLoc(E
->getQualifierLoc());
2123 Record
.AddSourceLocation(E
->getMemberLoc());
2124 Record
.AddDeclRef(E
->getPropertyDecl());
2125 Code
= serialization::EXPR_CXX_PROPERTY_REF_EXPR
;
2128 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr
*E
) {
2130 Record
.AddStmt(E
->getBase());
2131 Record
.AddStmt(E
->getIdx());
2132 Record
.AddSourceLocation(E
->getRBracketLoc());
2133 Code
= serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR
;
2136 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr
*E
) {
2138 Record
.AddSourceRange(E
->getSourceRange());
2139 Record
.AddDeclRef(E
->getGuidDecl());
2140 if (E
->isTypeOperand()) {
2141 Record
.AddTypeSourceInfo(E
->getTypeOperandSourceInfo());
2142 Code
= serialization::EXPR_CXX_UUIDOF_TYPE
;
2144 Record
.AddStmt(E
->getExprOperand());
2145 Code
= serialization::EXPR_CXX_UUIDOF_EXPR
;
2149 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt
*S
) {
2151 Record
.AddSourceLocation(S
->getExceptLoc());
2152 Record
.AddStmt(S
->getFilterExpr());
2153 Record
.AddStmt(S
->getBlock());
2154 Code
= serialization::STMT_SEH_EXCEPT
;
2157 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt
*S
) {
2159 Record
.AddSourceLocation(S
->getFinallyLoc());
2160 Record
.AddStmt(S
->getBlock());
2161 Code
= serialization::STMT_SEH_FINALLY
;
2164 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt
*S
) {
2166 Record
.push_back(S
->getIsCXXTry());
2167 Record
.AddSourceLocation(S
->getTryLoc());
2168 Record
.AddStmt(S
->getTryBlock());
2169 Record
.AddStmt(S
->getHandler());
2170 Code
= serialization::STMT_SEH_TRY
;
2173 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt
*S
) {
2175 Record
.AddSourceLocation(S
->getLeaveLoc());
2176 Code
= serialization::STMT_SEH_LEAVE
;
2179 //===----------------------------------------------------------------------===//
2180 // OpenMP Directives.
2181 //===----------------------------------------------------------------------===//
2183 void ASTStmtWriter::VisitOMPCanonicalLoop(OMPCanonicalLoop
*S
) {
2185 for (Stmt
*SubStmt
: S
->SubStmts
)
2186 Record
.AddStmt(SubStmt
);
2187 Code
= serialization::STMT_OMP_CANONICAL_LOOP
;
2190 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective
*E
) {
2191 Record
.writeOMPChildren(E
->Data
);
2192 Record
.AddSourceLocation(E
->getBeginLoc());
2193 Record
.AddSourceLocation(E
->getEndLoc());
2196 void ASTStmtWriter::VisitOMPLoopBasedDirective(OMPLoopBasedDirective
*D
) {
2198 Record
.writeUInt32(D
->getLoopsNumber());
2199 VisitOMPExecutableDirective(D
);
2202 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective
*D
) {
2203 VisitOMPLoopBasedDirective(D
);
2206 void ASTStmtWriter::VisitOMPMetaDirective(OMPMetaDirective
*D
) {
2208 Record
.push_back(D
->getNumClauses());
2209 VisitOMPExecutableDirective(D
);
2210 Code
= serialization::STMT_OMP_META_DIRECTIVE
;
2213 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective
*D
) {
2215 VisitOMPExecutableDirective(D
);
2216 Record
.writeBool(D
->hasCancel());
2217 Code
= serialization::STMT_OMP_PARALLEL_DIRECTIVE
;
2220 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective
*D
) {
2221 VisitOMPLoopDirective(D
);
2222 Code
= serialization::STMT_OMP_SIMD_DIRECTIVE
;
2225 void ASTStmtWriter::VisitOMPLoopTransformationDirective(
2226 OMPLoopTransformationDirective
*D
) {
2227 VisitOMPLoopBasedDirective(D
);
2228 Record
.writeUInt32(D
->getNumGeneratedLoops());
2231 void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective
*D
) {
2232 VisitOMPLoopTransformationDirective(D
);
2233 Code
= serialization::STMT_OMP_TILE_DIRECTIVE
;
2236 void ASTStmtWriter::VisitOMPUnrollDirective(OMPUnrollDirective
*D
) {
2237 VisitOMPLoopTransformationDirective(D
);
2238 Code
= serialization::STMT_OMP_UNROLL_DIRECTIVE
;
2241 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective
*D
) {
2242 VisitOMPLoopDirective(D
);
2243 Record
.writeBool(D
->hasCancel());
2244 Code
= serialization::STMT_OMP_FOR_DIRECTIVE
;
2247 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective
*D
) {
2248 VisitOMPLoopDirective(D
);
2249 Code
= serialization::STMT_OMP_FOR_SIMD_DIRECTIVE
;
2252 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective
*D
) {
2254 VisitOMPExecutableDirective(D
);
2255 Record
.writeBool(D
->hasCancel());
2256 Code
= serialization::STMT_OMP_SECTIONS_DIRECTIVE
;
2259 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective
*D
) {
2261 VisitOMPExecutableDirective(D
);
2262 Record
.writeBool(D
->hasCancel());
2263 Code
= serialization::STMT_OMP_SECTION_DIRECTIVE
;
2266 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective
*D
) {
2268 VisitOMPExecutableDirective(D
);
2269 Code
= serialization::STMT_OMP_SINGLE_DIRECTIVE
;
2272 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective
*D
) {
2274 VisitOMPExecutableDirective(D
);
2275 Code
= serialization::STMT_OMP_MASTER_DIRECTIVE
;
2278 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective
*D
) {
2280 VisitOMPExecutableDirective(D
);
2281 Record
.AddDeclarationNameInfo(D
->getDirectiveName());
2282 Code
= serialization::STMT_OMP_CRITICAL_DIRECTIVE
;
2285 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective
*D
) {
2286 VisitOMPLoopDirective(D
);
2287 Record
.writeBool(D
->hasCancel());
2288 Code
= serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE
;
2291 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2292 OMPParallelForSimdDirective
*D
) {
2293 VisitOMPLoopDirective(D
);
2294 Code
= serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE
;
2297 void ASTStmtWriter::VisitOMPParallelMasterDirective(
2298 OMPParallelMasterDirective
*D
) {
2300 VisitOMPExecutableDirective(D
);
2301 Code
= serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE
;
2304 void ASTStmtWriter::VisitOMPParallelMaskedDirective(
2305 OMPParallelMaskedDirective
*D
) {
2307 VisitOMPExecutableDirective(D
);
2308 Code
= serialization::STMT_OMP_PARALLEL_MASKED_DIRECTIVE
;
2311 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2312 OMPParallelSectionsDirective
*D
) {
2314 VisitOMPExecutableDirective(D
);
2315 Record
.writeBool(D
->hasCancel());
2316 Code
= serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE
;
2319 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective
*D
) {
2321 VisitOMPExecutableDirective(D
);
2322 Record
.writeBool(D
->hasCancel());
2323 Code
= serialization::STMT_OMP_TASK_DIRECTIVE
;
2326 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective
*D
) {
2328 VisitOMPExecutableDirective(D
);
2329 Record
.writeBool(D
->isXLHSInRHSPart());
2330 Record
.writeBool(D
->isPostfixUpdate());
2331 Record
.writeBool(D
->isFailOnly());
2332 Code
= serialization::STMT_OMP_ATOMIC_DIRECTIVE
;
2335 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective
*D
) {
2337 VisitOMPExecutableDirective(D
);
2338 Code
= serialization::STMT_OMP_TARGET_DIRECTIVE
;
2341 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective
*D
) {
2343 VisitOMPExecutableDirective(D
);
2344 Code
= serialization::STMT_OMP_TARGET_DATA_DIRECTIVE
;
2347 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2348 OMPTargetEnterDataDirective
*D
) {
2350 VisitOMPExecutableDirective(D
);
2351 Code
= serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE
;
2354 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2355 OMPTargetExitDataDirective
*D
) {
2357 VisitOMPExecutableDirective(D
);
2358 Code
= serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE
;
2361 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2362 OMPTargetParallelDirective
*D
) {
2364 VisitOMPExecutableDirective(D
);
2365 Record
.writeBool(D
->hasCancel());
2366 Code
= serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE
;
2369 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2370 OMPTargetParallelForDirective
*D
) {
2371 VisitOMPLoopDirective(D
);
2372 Record
.writeBool(D
->hasCancel());
2373 Code
= serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE
;
2376 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective
*D
) {
2378 VisitOMPExecutableDirective(D
);
2379 Code
= serialization::STMT_OMP_TASKYIELD_DIRECTIVE
;
2382 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective
*D
) {
2384 VisitOMPExecutableDirective(D
);
2385 Code
= serialization::STMT_OMP_BARRIER_DIRECTIVE
;
2388 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective
*D
) {
2390 Record
.push_back(D
->getNumClauses());
2391 VisitOMPExecutableDirective(D
);
2392 Code
= serialization::STMT_OMP_TASKWAIT_DIRECTIVE
;
2395 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective
*D
) {
2397 VisitOMPExecutableDirective(D
);
2398 Code
= serialization::STMT_OMP_TASKGROUP_DIRECTIVE
;
2401 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective
*D
) {
2403 VisitOMPExecutableDirective(D
);
2404 Code
= serialization::STMT_OMP_FLUSH_DIRECTIVE
;
2407 void ASTStmtWriter::VisitOMPDepobjDirective(OMPDepobjDirective
*D
) {
2409 VisitOMPExecutableDirective(D
);
2410 Code
= serialization::STMT_OMP_DEPOBJ_DIRECTIVE
;
2413 void ASTStmtWriter::VisitOMPScanDirective(OMPScanDirective
*D
) {
2415 VisitOMPExecutableDirective(D
);
2416 Code
= serialization::STMT_OMP_SCAN_DIRECTIVE
;
2419 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective
*D
) {
2421 VisitOMPExecutableDirective(D
);
2422 Code
= serialization::STMT_OMP_ORDERED_DIRECTIVE
;
2425 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective
*D
) {
2427 VisitOMPExecutableDirective(D
);
2428 Code
= serialization::STMT_OMP_TEAMS_DIRECTIVE
;
2431 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2432 OMPCancellationPointDirective
*D
) {
2434 VisitOMPExecutableDirective(D
);
2435 Record
.writeEnum(D
->getCancelRegion());
2436 Code
= serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE
;
2439 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective
*D
) {
2441 VisitOMPExecutableDirective(D
);
2442 Record
.writeEnum(D
->getCancelRegion());
2443 Code
= serialization::STMT_OMP_CANCEL_DIRECTIVE
;
2446 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective
*D
) {
2447 VisitOMPLoopDirective(D
);
2448 Record
.writeBool(D
->hasCancel());
2449 Code
= serialization::STMT_OMP_TASKLOOP_DIRECTIVE
;
2452 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective
*D
) {
2453 VisitOMPLoopDirective(D
);
2454 Code
= serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE
;
2457 void ASTStmtWriter::VisitOMPMasterTaskLoopDirective(
2458 OMPMasterTaskLoopDirective
*D
) {
2459 VisitOMPLoopDirective(D
);
2460 Record
.writeBool(D
->hasCancel());
2461 Code
= serialization::STMT_OMP_MASTER_TASKLOOP_DIRECTIVE
;
2464 void ASTStmtWriter::VisitOMPMaskedTaskLoopDirective(
2465 OMPMaskedTaskLoopDirective
*D
) {
2466 VisitOMPLoopDirective(D
);
2467 Record
.writeBool(D
->hasCancel());
2468 Code
= serialization::STMT_OMP_MASKED_TASKLOOP_DIRECTIVE
;
2471 void ASTStmtWriter::VisitOMPMasterTaskLoopSimdDirective(
2472 OMPMasterTaskLoopSimdDirective
*D
) {
2473 VisitOMPLoopDirective(D
);
2474 Code
= serialization::STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE
;
2477 void ASTStmtWriter::VisitOMPMaskedTaskLoopSimdDirective(
2478 OMPMaskedTaskLoopSimdDirective
*D
) {
2479 VisitOMPLoopDirective(D
);
2480 Code
= serialization::STMT_OMP_MASKED_TASKLOOP_SIMD_DIRECTIVE
;
2483 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopDirective(
2484 OMPParallelMasterTaskLoopDirective
*D
) {
2485 VisitOMPLoopDirective(D
);
2486 Record
.writeBool(D
->hasCancel());
2487 Code
= serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE
;
2490 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopDirective(
2491 OMPParallelMaskedTaskLoopDirective
*D
) {
2492 VisitOMPLoopDirective(D
);
2493 Record
.writeBool(D
->hasCancel());
2494 Code
= serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_DIRECTIVE
;
2497 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopSimdDirective(
2498 OMPParallelMasterTaskLoopSimdDirective
*D
) {
2499 VisitOMPLoopDirective(D
);
2500 Code
= serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE
;
2503 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopSimdDirective(
2504 OMPParallelMaskedTaskLoopSimdDirective
*D
) {
2505 VisitOMPLoopDirective(D
);
2506 Code
= serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_SIMD_DIRECTIVE
;
2509 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective
*D
) {
2510 VisitOMPLoopDirective(D
);
2511 Code
= serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE
;
2514 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective
*D
) {
2516 VisitOMPExecutableDirective(D
);
2517 Code
= serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE
;
2520 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2521 OMPDistributeParallelForDirective
*D
) {
2522 VisitOMPLoopDirective(D
);
2523 Record
.writeBool(D
->hasCancel());
2524 Code
= serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE
;
2527 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2528 OMPDistributeParallelForSimdDirective
*D
) {
2529 VisitOMPLoopDirective(D
);
2530 Code
= serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE
;
2533 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2534 OMPDistributeSimdDirective
*D
) {
2535 VisitOMPLoopDirective(D
);
2536 Code
= serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE
;
2539 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2540 OMPTargetParallelForSimdDirective
*D
) {
2541 VisitOMPLoopDirective(D
);
2542 Code
= serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE
;
2545 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective
*D
) {
2546 VisitOMPLoopDirective(D
);
2547 Code
= serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE
;
2550 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2551 OMPTeamsDistributeDirective
*D
) {
2552 VisitOMPLoopDirective(D
);
2553 Code
= serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE
;
2556 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2557 OMPTeamsDistributeSimdDirective
*D
) {
2558 VisitOMPLoopDirective(D
);
2559 Code
= serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE
;
2562 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2563 OMPTeamsDistributeParallelForSimdDirective
*D
) {
2564 VisitOMPLoopDirective(D
);
2565 Code
= serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE
;
2568 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2569 OMPTeamsDistributeParallelForDirective
*D
) {
2570 VisitOMPLoopDirective(D
);
2571 Record
.writeBool(D
->hasCancel());
2572 Code
= serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE
;
2575 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective
*D
) {
2577 VisitOMPExecutableDirective(D
);
2578 Code
= serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE
;
2581 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2582 OMPTargetTeamsDistributeDirective
*D
) {
2583 VisitOMPLoopDirective(D
);
2584 Code
= serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE
;
2587 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2588 OMPTargetTeamsDistributeParallelForDirective
*D
) {
2589 VisitOMPLoopDirective(D
);
2590 Record
.writeBool(D
->hasCancel());
2591 Code
= serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE
;
2594 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2595 OMPTargetTeamsDistributeParallelForSimdDirective
*D
) {
2596 VisitOMPLoopDirective(D
);
2597 Code
= serialization::
2598 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE
;
2601 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2602 OMPTargetTeamsDistributeSimdDirective
*D
) {
2603 VisitOMPLoopDirective(D
);
2604 Code
= serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE
;
2607 void ASTStmtWriter::VisitOMPInteropDirective(OMPInteropDirective
*D
) {
2609 VisitOMPExecutableDirective(D
);
2610 Code
= serialization::STMT_OMP_INTEROP_DIRECTIVE
;
2613 void ASTStmtWriter::VisitOMPDispatchDirective(OMPDispatchDirective
*D
) {
2615 VisitOMPExecutableDirective(D
);
2616 Record
.AddSourceLocation(D
->getTargetCallLoc());
2617 Code
= serialization::STMT_OMP_DISPATCH_DIRECTIVE
;
2620 void ASTStmtWriter::VisitOMPMaskedDirective(OMPMaskedDirective
*D
) {
2622 VisitOMPExecutableDirective(D
);
2623 Code
= serialization::STMT_OMP_MASKED_DIRECTIVE
;
2626 void ASTStmtWriter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective
*D
) {
2627 VisitOMPLoopDirective(D
);
2628 Code
= serialization::STMT_OMP_GENERIC_LOOP_DIRECTIVE
;
2631 void ASTStmtWriter::VisitOMPTeamsGenericLoopDirective(
2632 OMPTeamsGenericLoopDirective
*D
) {
2633 VisitOMPLoopDirective(D
);
2634 Code
= serialization::STMT_OMP_TEAMS_GENERIC_LOOP_DIRECTIVE
;
2637 void ASTStmtWriter::VisitOMPTargetTeamsGenericLoopDirective(
2638 OMPTargetTeamsGenericLoopDirective
*D
) {
2639 VisitOMPLoopDirective(D
);
2640 Code
= serialization::STMT_OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE
;
2643 void ASTStmtWriter::VisitOMPParallelGenericLoopDirective(
2644 OMPParallelGenericLoopDirective
*D
) {
2645 VisitOMPLoopDirective(D
);
2646 Code
= serialization::STMT_OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE
;
2649 void ASTStmtWriter::VisitOMPTargetParallelGenericLoopDirective(
2650 OMPTargetParallelGenericLoopDirective
*D
) {
2651 VisitOMPLoopDirective(D
);
2652 Code
= serialization::STMT_OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE
;
2655 //===----------------------------------------------------------------------===//
2656 // ASTWriter Implementation
2657 //===----------------------------------------------------------------------===//
2659 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase
*S
) {
2660 assert(SwitchCaseIDs
.find(S
) == SwitchCaseIDs
.end() &&
2661 "SwitchCase recorded twice");
2662 unsigned NextID
= SwitchCaseIDs
.size();
2663 SwitchCaseIDs
[S
] = NextID
;
2667 unsigned ASTWriter::getSwitchCaseID(SwitchCase
*S
) {
2668 assert(SwitchCaseIDs
.find(S
) != SwitchCaseIDs
.end() &&
2669 "SwitchCase hasn't been seen yet");
2670 return SwitchCaseIDs
[S
];
2673 void ASTWriter::ClearSwitchCaseIDs() {
2674 SwitchCaseIDs
.clear();
2677 /// Write the given substatement or subexpression to the
2679 void ASTWriter::WriteSubStmt(Stmt
*S
) {
2681 ASTStmtWriter
Writer(*this, Record
);
2685 Stream
.EmitRecord(serialization::STMT_NULL_PTR
, Record
);
2689 llvm::DenseMap
<Stmt
*, uint64_t>::iterator I
= SubStmtEntries
.find(S
);
2690 if (I
!= SubStmtEntries
.end()) {
2691 Record
.push_back(I
->second
);
2692 Stream
.EmitRecord(serialization::STMT_REF_PTR
, Record
);
2697 assert(!ParentStmts
.count(S
) && "There is a Stmt cycle!");
2699 struct ParentStmtInserterRAII
{
2701 llvm::DenseSet
<Stmt
*> &ParentStmts
;
2703 ParentStmtInserterRAII(Stmt
*S
, llvm::DenseSet
<Stmt
*> &ParentStmts
)
2704 : S(S
), ParentStmts(ParentStmts
) {
2705 ParentStmts
.insert(S
);
2707 ~ParentStmtInserterRAII() {
2708 ParentStmts
.erase(S
);
2712 ParentStmtInserterRAII
ParentStmtInserter(S
, ParentStmts
);
2717 uint64_t Offset
= Writer
.Emit();
2718 SubStmtEntries
[S
] = Offset
;
2721 /// Flush all of the statements that have been added to the
2722 /// queue via AddStmt().
2723 void ASTRecordWriter::FlushStmts() {
2724 // We expect to be the only consumer of the two temporary statement maps,
2725 // assert that they are empty.
2726 assert(Writer
->SubStmtEntries
.empty() && "unexpected entries in sub-stmt map");
2727 assert(Writer
->ParentStmts
.empty() && "unexpected entries in parent stmt map");
2729 for (unsigned I
= 0, N
= StmtsToEmit
.size(); I
!= N
; ++I
) {
2730 Writer
->WriteSubStmt(StmtsToEmit
[I
]);
2732 assert(N
== StmtsToEmit
.size() && "record modified while being written!");
2734 // Note that we are at the end of a full expression. Any
2735 // expression records that follow this one are part of a different
2737 Writer
->Stream
.EmitRecord(serialization::STMT_STOP
, ArrayRef
<uint32_t>());
2739 Writer
->SubStmtEntries
.clear();
2740 Writer
->ParentStmts
.clear();
2743 StmtsToEmit
.clear();
2746 void ASTRecordWriter::FlushSubStmts() {
2747 // For a nested statement, write out the substatements in reverse order (so
2748 // that a simple stack machine can be used when loading), and don't emit a
2749 // STMT_STOP after each one.
2750 for (unsigned I
= 0, N
= StmtsToEmit
.size(); I
!= N
; ++I
) {
2751 Writer
->WriteSubStmt(StmtsToEmit
[N
- I
- 1]);
2752 assert(N
== StmtsToEmit
.size() && "record modified while being written!");
2755 StmtsToEmit
.clear();