[clang-format] Fix a bug in aligning comments above PPDirective (#72791)
[llvm-project.git] / clang / lib / Serialization / ASTWriterStmt.cpp
blob59be6828fafabf6ac17cbf155e1826dea560ac97
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 //===----------------------------------------------------------------------===//
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/Sema/DeclSpec.h"
23 #include "clang/Serialization/ASTRecordWriter.h"
24 #include "llvm/Bitstream/BitstreamWriter.h"
25 using namespace clang;
27 //===----------------------------------------------------------------------===//
28 // Statement/expression serialization
29 //===----------------------------------------------------------------------===//
31 namespace clang {
33 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
34 ASTWriter &Writer;
35 ASTRecordWriter Record;
37 serialization::StmtCode Code;
38 unsigned AbbrevToUse;
40 public:
41 ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
42 : Writer(Writer), Record(Writer, Record),
43 Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
45 ASTStmtWriter(const ASTStmtWriter&) = delete;
46 ASTStmtWriter &operator=(const ASTStmtWriter &) = delete;
48 uint64_t Emit() {
49 assert(Code != serialization::STMT_NULL_PTR &&
50 "unhandled sub-statement writing AST file");
51 return Record.EmitStmt(Code, AbbrevToUse);
54 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo,
55 const TemplateArgumentLoc *Args);
57 void VisitStmt(Stmt *S);
58 #define STMT(Type, Base) \
59 void Visit##Type(Type *);
60 #include "clang/AST/StmtNodes.inc"
64 void ASTStmtWriter::AddTemplateKWAndArgsInfo(
65 const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) {
66 Record.AddSourceLocation(ArgInfo.TemplateKWLoc);
67 Record.AddSourceLocation(ArgInfo.LAngleLoc);
68 Record.AddSourceLocation(ArgInfo.RAngleLoc);
69 for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i)
70 Record.AddTemplateArgumentLoc(Args[i]);
73 void ASTStmtWriter::VisitStmt(Stmt *S) {
76 void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
77 VisitStmt(S);
78 Record.AddSourceLocation(S->getSemiLoc());
79 Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro);
80 Code = serialization::STMT_NULL;
83 void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
84 VisitStmt(S);
85 Record.push_back(S->size());
86 Record.push_back(S->hasStoredFPFeatures());
87 for (auto *CS : S->body())
88 Record.AddStmt(CS);
89 if (S->hasStoredFPFeatures())
90 Record.push_back(S->getStoredFPFeatures().getAsOpaqueInt());
91 Record.AddSourceLocation(S->getLBracLoc());
92 Record.AddSourceLocation(S->getRBracLoc());
93 Code = serialization::STMT_COMPOUND;
96 void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
97 VisitStmt(S);
98 Record.push_back(Writer.getSwitchCaseID(S));
99 Record.AddSourceLocation(S->getKeywordLoc());
100 Record.AddSourceLocation(S->getColonLoc());
103 void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
104 VisitSwitchCase(S);
105 Record.push_back(S->caseStmtIsGNURange());
106 Record.AddStmt(S->getLHS());
107 Record.AddStmt(S->getSubStmt());
108 if (S->caseStmtIsGNURange()) {
109 Record.AddStmt(S->getRHS());
110 Record.AddSourceLocation(S->getEllipsisLoc());
112 Code = serialization::STMT_CASE;
115 void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
116 VisitSwitchCase(S);
117 Record.AddStmt(S->getSubStmt());
118 Code = serialization::STMT_DEFAULT;
121 void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
122 VisitStmt(S);
123 Record.push_back(S->isSideEntry());
124 Record.AddDeclRef(S->getDecl());
125 Record.AddStmt(S->getSubStmt());
126 Record.AddSourceLocation(S->getIdentLoc());
127 Code = serialization::STMT_LABEL;
130 void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
131 VisitStmt(S);
132 Record.push_back(S->getAttrs().size());
133 Record.AddAttributes(S->getAttrs());
134 Record.AddStmt(S->getSubStmt());
135 Record.AddSourceLocation(S->getAttrLoc());
136 Code = serialization::STMT_ATTRIBUTED;
139 void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
140 VisitStmt(S);
142 bool HasElse = S->getElse() != nullptr;
143 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
144 bool HasInit = S->getInit() != nullptr;
146 Record.push_back(HasElse);
147 Record.push_back(HasVar);
148 Record.push_back(HasInit);
149 Record.push_back(static_cast<uint64_t>(S->getStatementKind()));
150 Record.AddStmt(S->getCond());
151 Record.AddStmt(S->getThen());
152 if (HasElse)
153 Record.AddStmt(S->getElse());
154 if (HasVar)
155 Record.AddStmt(S->getConditionVariableDeclStmt());
156 if (HasInit)
157 Record.AddStmt(S->getInit());
159 Record.AddSourceLocation(S->getIfLoc());
160 Record.AddSourceLocation(S->getLParenLoc());
161 Record.AddSourceLocation(S->getRParenLoc());
162 if (HasElse)
163 Record.AddSourceLocation(S->getElseLoc());
165 Code = serialization::STMT_IF;
168 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
169 VisitStmt(S);
171 bool HasInit = S->getInit() != nullptr;
172 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
173 Record.push_back(HasInit);
174 Record.push_back(HasVar);
175 Record.push_back(S->isAllEnumCasesCovered());
177 Record.AddStmt(S->getCond());
178 Record.AddStmt(S->getBody());
179 if (HasInit)
180 Record.AddStmt(S->getInit());
181 if (HasVar)
182 Record.AddStmt(S->getConditionVariableDeclStmt());
184 Record.AddSourceLocation(S->getSwitchLoc());
185 Record.AddSourceLocation(S->getLParenLoc());
186 Record.AddSourceLocation(S->getRParenLoc());
188 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
189 SC = SC->getNextSwitchCase())
190 Record.push_back(Writer.RecordSwitchCaseID(SC));
191 Code = serialization::STMT_SWITCH;
194 void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
195 VisitStmt(S);
197 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
198 Record.push_back(HasVar);
200 Record.AddStmt(S->getCond());
201 Record.AddStmt(S->getBody());
202 if (HasVar)
203 Record.AddStmt(S->getConditionVariableDeclStmt());
205 Record.AddSourceLocation(S->getWhileLoc());
206 Record.AddSourceLocation(S->getLParenLoc());
207 Record.AddSourceLocation(S->getRParenLoc());
208 Code = serialization::STMT_WHILE;
211 void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
212 VisitStmt(S);
213 Record.AddStmt(S->getCond());
214 Record.AddStmt(S->getBody());
215 Record.AddSourceLocation(S->getDoLoc());
216 Record.AddSourceLocation(S->getWhileLoc());
217 Record.AddSourceLocation(S->getRParenLoc());
218 Code = serialization::STMT_DO;
221 void ASTStmtWriter::VisitForStmt(ForStmt *S) {
222 VisitStmt(S);
223 Record.AddStmt(S->getInit());
224 Record.AddStmt(S->getCond());
225 Record.AddStmt(S->getConditionVariableDeclStmt());
226 Record.AddStmt(S->getInc());
227 Record.AddStmt(S->getBody());
228 Record.AddSourceLocation(S->getForLoc());
229 Record.AddSourceLocation(S->getLParenLoc());
230 Record.AddSourceLocation(S->getRParenLoc());
231 Code = serialization::STMT_FOR;
234 void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
235 VisitStmt(S);
236 Record.AddDeclRef(S->getLabel());
237 Record.AddSourceLocation(S->getGotoLoc());
238 Record.AddSourceLocation(S->getLabelLoc());
239 Code = serialization::STMT_GOTO;
242 void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
243 VisitStmt(S);
244 Record.AddSourceLocation(S->getGotoLoc());
245 Record.AddSourceLocation(S->getStarLoc());
246 Record.AddStmt(S->getTarget());
247 Code = serialization::STMT_INDIRECT_GOTO;
250 void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
251 VisitStmt(S);
252 Record.AddSourceLocation(S->getContinueLoc());
253 Code = serialization::STMT_CONTINUE;
256 void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
257 VisitStmt(S);
258 Record.AddSourceLocation(S->getBreakLoc());
259 Code = serialization::STMT_BREAK;
262 void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
263 VisitStmt(S);
265 bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr;
266 Record.push_back(HasNRVOCandidate);
268 Record.AddStmt(S->getRetValue());
269 if (HasNRVOCandidate)
270 Record.AddDeclRef(S->getNRVOCandidate());
272 Record.AddSourceLocation(S->getReturnLoc());
273 Code = serialization::STMT_RETURN;
276 void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
277 VisitStmt(S);
278 Record.AddSourceLocation(S->getBeginLoc());
279 Record.AddSourceLocation(S->getEndLoc());
280 DeclGroupRef DG = S->getDeclGroup();
281 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
282 Record.AddDeclRef(*D);
283 Code = serialization::STMT_DECL;
286 void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
287 VisitStmt(S);
288 Record.push_back(S->getNumOutputs());
289 Record.push_back(S->getNumInputs());
290 Record.push_back(S->getNumClobbers());
291 Record.AddSourceLocation(S->getAsmLoc());
292 Record.push_back(S->isVolatile());
293 Record.push_back(S->isSimple());
296 void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
297 VisitAsmStmt(S);
298 Record.push_back(S->getNumLabels());
299 Record.AddSourceLocation(S->getRParenLoc());
300 Record.AddStmt(S->getAsmString());
302 // Outputs
303 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
304 Record.AddIdentifierRef(S->getOutputIdentifier(I));
305 Record.AddStmt(S->getOutputConstraintLiteral(I));
306 Record.AddStmt(S->getOutputExpr(I));
309 // Inputs
310 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
311 Record.AddIdentifierRef(S->getInputIdentifier(I));
312 Record.AddStmt(S->getInputConstraintLiteral(I));
313 Record.AddStmt(S->getInputExpr(I));
316 // Clobbers
317 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
318 Record.AddStmt(S->getClobberStringLiteral(I));
320 // Labels
321 for (unsigned I = 0, N = S->getNumLabels(); I != N; ++I) {
322 Record.AddIdentifierRef(S->getLabelIdentifier(I));
323 Record.AddStmt(S->getLabelExpr(I));
326 Code = serialization::STMT_GCCASM;
329 void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
330 VisitAsmStmt(S);
331 Record.AddSourceLocation(S->getLBraceLoc());
332 Record.AddSourceLocation(S->getEndLoc());
333 Record.push_back(S->getNumAsmToks());
334 Record.AddString(S->getAsmString());
336 // Tokens
337 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
338 // FIXME: Move this to ASTRecordWriter?
339 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
342 // Clobbers
343 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
344 Record.AddString(S->getClobber(I));
347 // Outputs
348 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
349 Record.AddStmt(S->getOutputExpr(I));
350 Record.AddString(S->getOutputConstraint(I));
353 // Inputs
354 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
355 Record.AddStmt(S->getInputExpr(I));
356 Record.AddString(S->getInputConstraint(I));
359 Code = serialization::STMT_MSASM;
362 void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
363 VisitStmt(CoroStmt);
364 Record.push_back(CoroStmt->getParamMoves().size());
365 for (Stmt *S : CoroStmt->children())
366 Record.AddStmt(S);
367 Code = serialization::STMT_COROUTINE_BODY;
370 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
371 VisitStmt(S);
372 Record.AddSourceLocation(S->getKeywordLoc());
373 Record.AddStmt(S->getOperand());
374 Record.AddStmt(S->getPromiseCall());
375 Record.push_back(S->isImplicit());
376 Code = serialization::STMT_CORETURN;
379 void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
380 VisitExpr(E);
381 Record.AddSourceLocation(E->getKeywordLoc());
382 for (Stmt *S : E->children())
383 Record.AddStmt(S);
384 Record.AddStmt(E->getOpaqueValue());
387 void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
388 VisitCoroutineSuspendExpr(E);
389 Record.push_back(E->isImplicit());
390 Code = serialization::EXPR_COAWAIT;
393 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
394 VisitCoroutineSuspendExpr(E);
395 Code = serialization::EXPR_COYIELD;
398 void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
399 VisitExpr(E);
400 Record.AddSourceLocation(E->getKeywordLoc());
401 for (Stmt *S : E->children())
402 Record.AddStmt(S);
403 Code = serialization::EXPR_DEPENDENT_COAWAIT;
406 static void
407 addConstraintSatisfaction(ASTRecordWriter &Record,
408 const ASTConstraintSatisfaction &Satisfaction) {
409 Record.push_back(Satisfaction.IsSatisfied);
410 Record.push_back(Satisfaction.ContainsErrors);
411 if (!Satisfaction.IsSatisfied) {
412 Record.push_back(Satisfaction.NumRecords);
413 for (const auto &DetailRecord : Satisfaction) {
414 Record.AddStmt(const_cast<Expr *>(DetailRecord.first));
415 auto *E = DetailRecord.second.dyn_cast<Expr *>();
416 Record.push_back(E == nullptr);
417 if (E)
418 Record.AddStmt(E);
419 else {
420 auto *Diag = DetailRecord.second.get<std::pair<SourceLocation,
421 StringRef> *>();
422 Record.AddSourceLocation(Diag->first);
423 Record.AddString(Diag->second);
429 static void
430 addSubstitutionDiagnostic(
431 ASTRecordWriter &Record,
432 const concepts::Requirement::SubstitutionDiagnostic *D) {
433 Record.AddString(D->SubstitutedEntity);
434 Record.AddSourceLocation(D->DiagLoc);
435 Record.AddString(D->DiagMessage);
438 void ASTStmtWriter::VisitConceptSpecializationExpr(
439 ConceptSpecializationExpr *E) {
440 VisitExpr(E);
441 Record.AddDeclRef(E->getSpecializationDecl());
442 const ConceptReference *CR = E->getConceptReference();
443 Record.push_back(CR != nullptr);
444 if (CR)
445 Record.AddConceptReference(CR);
446 if (!E->isValueDependent())
447 addConstraintSatisfaction(Record, E->getSatisfaction());
449 Code = serialization::EXPR_CONCEPT_SPECIALIZATION;
452 void ASTStmtWriter::VisitRequiresExpr(RequiresExpr *E) {
453 VisitExpr(E);
454 Record.push_back(E->getLocalParameters().size());
455 Record.push_back(E->getRequirements().size());
456 Record.AddSourceLocation(E->RequiresExprBits.RequiresKWLoc);
457 Record.push_back(E->RequiresExprBits.IsSatisfied);
458 Record.AddDeclRef(E->getBody());
459 for (ParmVarDecl *P : E->getLocalParameters())
460 Record.AddDeclRef(P);
461 for (concepts::Requirement *R : E->getRequirements()) {
462 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(R)) {
463 Record.push_back(concepts::Requirement::RK_Type);
464 Record.push_back(TypeReq->Status);
465 if (TypeReq->Status == concepts::TypeRequirement::SS_SubstitutionFailure)
466 addSubstitutionDiagnostic(Record, TypeReq->getSubstitutionDiagnostic());
467 else
468 Record.AddTypeSourceInfo(TypeReq->getType());
469 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(R)) {
470 Record.push_back(ExprReq->getKind());
471 Record.push_back(ExprReq->Status);
472 if (ExprReq->isExprSubstitutionFailure()) {
473 addSubstitutionDiagnostic(Record,
474 ExprReq->Value.get<concepts::Requirement::SubstitutionDiagnostic *>());
475 } else
476 Record.AddStmt(ExprReq->Value.get<Expr *>());
477 if (ExprReq->getKind() == concepts::Requirement::RK_Compound) {
478 Record.AddSourceLocation(ExprReq->NoexceptLoc);
479 const auto &RetReq = ExprReq->getReturnTypeRequirement();
480 if (RetReq.isSubstitutionFailure()) {
481 Record.push_back(2);
482 addSubstitutionDiagnostic(Record, RetReq.getSubstitutionDiagnostic());
483 } else if (RetReq.isTypeConstraint()) {
484 Record.push_back(1);
485 Record.AddTemplateParameterList(
486 RetReq.getTypeConstraintTemplateParameterList());
487 if (ExprReq->Status >=
488 concepts::ExprRequirement::SS_ConstraintsNotSatisfied)
489 Record.AddStmt(
490 ExprReq->getReturnTypeRequirementSubstitutedConstraintExpr());
491 } else {
492 assert(RetReq.isEmpty());
493 Record.push_back(0);
496 } else {
497 auto *NestedReq = cast<concepts::NestedRequirement>(R);
498 Record.push_back(concepts::Requirement::RK_Nested);
499 Record.push_back(NestedReq->hasInvalidConstraint());
500 if (NestedReq->hasInvalidConstraint()) {
501 Record.AddString(NestedReq->getInvalidConstraintEntity());
502 addConstraintSatisfaction(Record, *NestedReq->Satisfaction);
503 } else {
504 Record.AddStmt(NestedReq->getConstraintExpr());
505 if (!NestedReq->isDependent())
506 addConstraintSatisfaction(Record, *NestedReq->Satisfaction);
510 Record.AddSourceLocation(E->getLParenLoc());
511 Record.AddSourceLocation(E->getRParenLoc());
512 Record.AddSourceLocation(E->getEndLoc());
514 Code = serialization::EXPR_REQUIRES;
518 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
519 VisitStmt(S);
520 // NumCaptures
521 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
523 // CapturedDecl and captured region kind
524 Record.AddDeclRef(S->getCapturedDecl());
525 Record.push_back(S->getCapturedRegionKind());
527 Record.AddDeclRef(S->getCapturedRecordDecl());
529 // Capture inits
530 for (auto *I : S->capture_inits())
531 Record.AddStmt(I);
533 // Body
534 Record.AddStmt(S->getCapturedStmt());
536 // Captures
537 for (const auto &I : S->captures()) {
538 if (I.capturesThis() || I.capturesVariableArrayType())
539 Record.AddDeclRef(nullptr);
540 else
541 Record.AddDeclRef(I.getCapturedVar());
542 Record.push_back(I.getCaptureKind());
543 Record.AddSourceLocation(I.getLocation());
546 Code = serialization::STMT_CAPTURED;
549 void ASTStmtWriter::VisitExpr(Expr *E) {
550 VisitStmt(E);
551 Record.AddTypeRef(E->getType());
552 Record.push_back(E->getDependence());
553 Record.push_back(E->getValueKind());
554 Record.push_back(E->getObjectKind());
557 void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
558 VisitExpr(E);
559 Record.push_back(E->ConstantExprBits.ResultKind);
561 Record.push_back(E->ConstantExprBits.APValueKind);
562 Record.push_back(E->ConstantExprBits.IsUnsigned);
563 Record.push_back(E->ConstantExprBits.BitWidth);
564 // HasCleanup not serialized since we can just query the APValue.
565 Record.push_back(E->ConstantExprBits.IsImmediateInvocation);
567 switch (E->getResultStorageKind()) {
568 case ConstantResultStorageKind::None:
569 break;
570 case ConstantResultStorageKind::Int64:
571 Record.push_back(E->Int64Result());
572 break;
573 case ConstantResultStorageKind::APValue:
574 Record.AddAPValue(E->APValueResult());
575 break;
578 Record.AddStmt(E->getSubExpr());
579 Code = serialization::EXPR_CONSTANT;
582 void ASTStmtWriter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
583 VisitExpr(E);
585 Record.AddSourceLocation(E->getLocation());
586 Record.AddSourceLocation(E->getLParenLocation());
587 Record.AddSourceLocation(E->getRParenLocation());
588 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
590 Code = serialization::EXPR_SYCL_UNIQUE_STABLE_NAME;
593 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
594 VisitExpr(E);
596 bool HasFunctionName = E->getFunctionName() != nullptr;
597 Record.push_back(HasFunctionName);
598 Record.push_back(
599 llvm::to_underlying(E->getIdentKind())); // FIXME: stable encoding
600 Record.push_back(E->isTransparent());
601 Record.AddSourceLocation(E->getLocation());
602 if (HasFunctionName)
603 Record.AddStmt(E->getFunctionName());
604 Code = serialization::EXPR_PREDEFINED;
607 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
608 VisitExpr(E);
610 Record.push_back(E->hasQualifier());
611 Record.push_back(E->getDecl() != E->getFoundDecl());
612 Record.push_back(E->hasTemplateKWAndArgsInfo());
613 Record.push_back(E->hadMultipleCandidates());
614 Record.push_back(E->refersToEnclosingVariableOrCapture());
615 Record.push_back(E->isNonOdrUse());
616 Record.push_back(E->isImmediateEscalating());
618 if (E->hasTemplateKWAndArgsInfo()) {
619 unsigned NumTemplateArgs = E->getNumTemplateArgs();
620 Record.push_back(NumTemplateArgs);
623 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
625 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
626 (E->getDecl() == E->getFoundDecl()) &&
627 nk == DeclarationName::Identifier &&
628 !E->refersToEnclosingVariableOrCapture() && !E->isNonOdrUse() &&
629 !E->isImmediateEscalating()) {
630 AbbrevToUse = Writer.getDeclRefExprAbbrev();
633 if (E->hasQualifier())
634 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
636 if (E->getDecl() != E->getFoundDecl())
637 Record.AddDeclRef(E->getFoundDecl());
639 if (E->hasTemplateKWAndArgsInfo())
640 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
641 E->getTrailingObjects<TemplateArgumentLoc>());
643 Record.AddDeclRef(E->getDecl());
644 Record.AddSourceLocation(E->getLocation());
645 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
646 Code = serialization::EXPR_DECL_REF;
649 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
650 VisitExpr(E);
651 Record.AddSourceLocation(E->getLocation());
652 Record.AddAPInt(E->getValue());
654 if (E->getValue().getBitWidth() == 32) {
655 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
658 Code = serialization::EXPR_INTEGER_LITERAL;
661 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
662 VisitExpr(E);
663 Record.AddSourceLocation(E->getLocation());
664 Record.push_back(E->getScale());
665 Record.AddAPInt(E->getValue());
666 Code = serialization::EXPR_FIXEDPOINT_LITERAL;
669 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
670 VisitExpr(E);
671 Record.push_back(E->getRawSemantics());
672 Record.push_back(E->isExact());
673 Record.AddAPFloat(E->getValue());
674 Record.AddSourceLocation(E->getLocation());
675 Code = serialization::EXPR_FLOATING_LITERAL;
678 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
679 VisitExpr(E);
680 Record.AddStmt(E->getSubExpr());
681 Code = serialization::EXPR_IMAGINARY_LITERAL;
684 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
685 VisitExpr(E);
687 // Store the various bits of data of StringLiteral.
688 Record.push_back(E->getNumConcatenated());
689 Record.push_back(E->getLength());
690 Record.push_back(E->getCharByteWidth());
691 Record.push_back(llvm::to_underlying(E->getKind()));
692 Record.push_back(E->isPascal());
694 // Store the trailing array of SourceLocation.
695 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
696 Record.AddSourceLocation(E->getStrTokenLoc(I));
698 // Store the trailing array of char holding the string data.
699 StringRef StrData = E->getBytes();
700 for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
701 Record.push_back(StrData[I]);
703 Code = serialization::EXPR_STRING_LITERAL;
706 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
707 VisitExpr(E);
708 Record.push_back(E->getValue());
709 Record.AddSourceLocation(E->getLocation());
710 Record.push_back(llvm::to_underlying(E->getKind()));
712 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
714 Code = serialization::EXPR_CHARACTER_LITERAL;
717 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
718 VisitExpr(E);
719 Record.AddSourceLocation(E->getLParen());
720 Record.AddSourceLocation(E->getRParen());
721 Record.AddStmt(E->getSubExpr());
722 Code = serialization::EXPR_PAREN;
725 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
726 VisitExpr(E);
727 Record.push_back(E->getNumExprs());
728 for (auto *SubStmt : E->exprs())
729 Record.AddStmt(SubStmt);
730 Record.AddSourceLocation(E->getLParenLoc());
731 Record.AddSourceLocation(E->getRParenLoc());
732 Code = serialization::EXPR_PAREN_LIST;
735 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
736 VisitExpr(E);
737 bool HasFPFeatures = E->hasStoredFPFeatures();
738 // Write this first for easy access when deserializing, as they affect the
739 // size of the UnaryOperator.
740 Record.push_back(HasFPFeatures);
741 Record.AddStmt(E->getSubExpr());
742 Record.push_back(E->getOpcode()); // FIXME: stable encoding
743 Record.AddSourceLocation(E->getOperatorLoc());
744 Record.push_back(E->canOverflow());
745 if (HasFPFeatures)
746 Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt());
747 Code = serialization::EXPR_UNARY_OPERATOR;
750 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
751 VisitExpr(E);
752 Record.push_back(E->getNumComponents());
753 Record.push_back(E->getNumExpressions());
754 Record.AddSourceLocation(E->getOperatorLoc());
755 Record.AddSourceLocation(E->getRParenLoc());
756 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
757 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
758 const OffsetOfNode &ON = E->getComponent(I);
759 Record.push_back(ON.getKind()); // FIXME: Stable encoding
760 Record.AddSourceLocation(ON.getSourceRange().getBegin());
761 Record.AddSourceLocation(ON.getSourceRange().getEnd());
762 switch (ON.getKind()) {
763 case OffsetOfNode::Array:
764 Record.push_back(ON.getArrayExprIndex());
765 break;
767 case OffsetOfNode::Field:
768 Record.AddDeclRef(ON.getField());
769 break;
771 case OffsetOfNode::Identifier:
772 Record.AddIdentifierRef(ON.getFieldName());
773 break;
775 case OffsetOfNode::Base:
776 Record.AddCXXBaseSpecifier(*ON.getBase());
777 break;
780 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
781 Record.AddStmt(E->getIndexExpr(I));
782 Code = serialization::EXPR_OFFSETOF;
785 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
786 VisitExpr(E);
787 Record.push_back(E->getKind());
788 if (E->isArgumentType())
789 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
790 else {
791 Record.push_back(0);
792 Record.AddStmt(E->getArgumentExpr());
794 Record.AddSourceLocation(E->getOperatorLoc());
795 Record.AddSourceLocation(E->getRParenLoc());
796 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
799 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
800 VisitExpr(E);
801 Record.AddStmt(E->getLHS());
802 Record.AddStmt(E->getRHS());
803 Record.AddSourceLocation(E->getRBracketLoc());
804 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
807 void ASTStmtWriter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
808 VisitExpr(E);
809 Record.AddStmt(E->getBase());
810 Record.AddStmt(E->getRowIdx());
811 Record.AddStmt(E->getColumnIdx());
812 Record.AddSourceLocation(E->getRBracketLoc());
813 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
816 void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
817 VisitExpr(E);
818 Record.AddStmt(E->getBase());
819 Record.AddStmt(E->getLowerBound());
820 Record.AddStmt(E->getLength());
821 Record.AddStmt(E->getStride());
822 Record.AddSourceLocation(E->getColonLocFirst());
823 Record.AddSourceLocation(E->getColonLocSecond());
824 Record.AddSourceLocation(E->getRBracketLoc());
825 Code = serialization::EXPR_OMP_ARRAY_SECTION;
828 void ASTStmtWriter::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
829 VisitExpr(E);
830 Record.push_back(E->getDimensions().size());
831 Record.AddStmt(E->getBase());
832 for (Expr *Dim : E->getDimensions())
833 Record.AddStmt(Dim);
834 for (SourceRange SR : E->getBracketsRanges())
835 Record.AddSourceRange(SR);
836 Record.AddSourceLocation(E->getLParenLoc());
837 Record.AddSourceLocation(E->getRParenLoc());
838 Code = serialization::EXPR_OMP_ARRAY_SHAPING;
841 void ASTStmtWriter::VisitOMPIteratorExpr(OMPIteratorExpr *E) {
842 VisitExpr(E);
843 Record.push_back(E->numOfIterators());
844 Record.AddSourceLocation(E->getIteratorKwLoc());
845 Record.AddSourceLocation(E->getLParenLoc());
846 Record.AddSourceLocation(E->getRParenLoc());
847 for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) {
848 Record.AddDeclRef(E->getIteratorDecl(I));
849 Record.AddSourceLocation(E->getAssignLoc(I));
850 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
851 Record.AddStmt(Range.Begin);
852 Record.AddStmt(Range.End);
853 Record.AddStmt(Range.Step);
854 Record.AddSourceLocation(E->getColonLoc(I));
855 if (Range.Step)
856 Record.AddSourceLocation(E->getSecondColonLoc(I));
857 // Serialize helpers
858 OMPIteratorHelperData &HD = E->getHelper(I);
859 Record.AddDeclRef(HD.CounterVD);
860 Record.AddStmt(HD.Upper);
861 Record.AddStmt(HD.Update);
862 Record.AddStmt(HD.CounterUpdate);
864 Code = serialization::EXPR_OMP_ITERATOR;
867 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
868 VisitExpr(E);
869 Record.push_back(E->getNumArgs());
870 Record.push_back(E->hasStoredFPFeatures());
871 Record.AddSourceLocation(E->getRParenLoc());
872 Record.AddStmt(E->getCallee());
873 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
874 Arg != ArgEnd; ++Arg)
875 Record.AddStmt(*Arg);
876 Record.push_back(static_cast<unsigned>(E->getADLCallKind()));
877 if (E->hasStoredFPFeatures())
878 Record.push_back(E->getFPFeatures().getAsOpaqueInt());
879 Code = serialization::EXPR_CALL;
882 void ASTStmtWriter::VisitRecoveryExpr(RecoveryExpr *E) {
883 VisitExpr(E);
884 Record.push_back(std::distance(E->children().begin(), E->children().end()));
885 Record.AddSourceLocation(E->getBeginLoc());
886 Record.AddSourceLocation(E->getEndLoc());
887 for (Stmt *Child : E->children())
888 Record.AddStmt(Child);
889 Code = serialization::EXPR_RECOVERY;
892 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
893 VisitExpr(E);
895 bool HasQualifier = E->hasQualifier();
896 bool HasFoundDecl =
897 E->hasQualifierOrFoundDecl() &&
898 (E->getFoundDecl().getDecl() != E->getMemberDecl() ||
899 E->getFoundDecl().getAccess() != E->getMemberDecl()->getAccess());
900 bool HasTemplateInfo = E->hasTemplateKWAndArgsInfo();
901 unsigned NumTemplateArgs = E->getNumTemplateArgs();
903 // Write these first for easy access when deserializing, as they affect the
904 // size of the MemberExpr.
905 Record.push_back(HasQualifier);
906 Record.push_back(HasFoundDecl);
907 Record.push_back(HasTemplateInfo);
908 Record.push_back(NumTemplateArgs);
910 Record.AddStmt(E->getBase());
911 Record.AddDeclRef(E->getMemberDecl());
912 Record.AddDeclarationNameLoc(E->MemberDNLoc,
913 E->getMemberDecl()->getDeclName());
914 Record.AddSourceLocation(E->getMemberLoc());
915 Record.push_back(E->isArrow());
916 Record.push_back(E->hadMultipleCandidates());
917 Record.push_back(E->isNonOdrUse());
918 Record.AddSourceLocation(E->getOperatorLoc());
920 if (HasFoundDecl) {
921 DeclAccessPair FoundDecl = E->getFoundDecl();
922 Record.AddDeclRef(FoundDecl.getDecl());
923 Record.push_back(FoundDecl.getAccess());
926 if (HasQualifier)
927 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
929 if (HasTemplateInfo)
930 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
931 E->getTrailingObjects<TemplateArgumentLoc>());
933 Code = serialization::EXPR_MEMBER;
936 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
937 VisitExpr(E);
938 Record.AddStmt(E->getBase());
939 Record.AddSourceLocation(E->getIsaMemberLoc());
940 Record.AddSourceLocation(E->getOpLoc());
941 Record.push_back(E->isArrow());
942 Code = serialization::EXPR_OBJC_ISA;
945 void ASTStmtWriter::
946 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
947 VisitExpr(E);
948 Record.AddStmt(E->getSubExpr());
949 Record.push_back(E->shouldCopy());
950 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
953 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
954 VisitExplicitCastExpr(E);
955 Record.AddSourceLocation(E->getLParenLoc());
956 Record.AddSourceLocation(E->getBridgeKeywordLoc());
957 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
958 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
961 void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
962 VisitExpr(E);
963 Record.push_back(E->path_size());
964 Record.push_back(E->hasStoredFPFeatures());
965 Record.AddStmt(E->getSubExpr());
966 Record.push_back(E->getCastKind()); // FIXME: stable encoding
968 for (CastExpr::path_iterator
969 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
970 Record.AddCXXBaseSpecifier(**PI);
972 if (E->hasStoredFPFeatures())
973 Record.push_back(E->getFPFeatures().getAsOpaqueInt());
976 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
977 VisitExpr(E);
978 bool HasFPFeatures = E->hasStoredFPFeatures();
979 // Write this first for easy access when deserializing, as they affect the
980 // size of the UnaryOperator.
981 Record.push_back(HasFPFeatures);
982 Record.push_back(E->getOpcode()); // FIXME: stable encoding
983 Record.AddStmt(E->getLHS());
984 Record.AddStmt(E->getRHS());
985 Record.AddSourceLocation(E->getOperatorLoc());
986 if (HasFPFeatures)
987 Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt());
988 Code = serialization::EXPR_BINARY_OPERATOR;
991 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
992 VisitBinaryOperator(E);
993 Record.AddTypeRef(E->getComputationLHSType());
994 Record.AddTypeRef(E->getComputationResultType());
995 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
998 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
999 VisitExpr(E);
1000 Record.AddStmt(E->getCond());
1001 Record.AddStmt(E->getLHS());
1002 Record.AddStmt(E->getRHS());
1003 Record.AddSourceLocation(E->getQuestionLoc());
1004 Record.AddSourceLocation(E->getColonLoc());
1005 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
1008 void
1009 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
1010 VisitExpr(E);
1011 Record.AddStmt(E->getOpaqueValue());
1012 Record.AddStmt(E->getCommon());
1013 Record.AddStmt(E->getCond());
1014 Record.AddStmt(E->getTrueExpr());
1015 Record.AddStmt(E->getFalseExpr());
1016 Record.AddSourceLocation(E->getQuestionLoc());
1017 Record.AddSourceLocation(E->getColonLoc());
1018 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
1021 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
1022 VisitCastExpr(E);
1023 Record.push_back(E->isPartOfExplicitCast());
1025 if (E->path_size() == 0 && !E->hasStoredFPFeatures())
1026 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
1028 Code = serialization::EXPR_IMPLICIT_CAST;
1031 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
1032 VisitCastExpr(E);
1033 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
1036 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
1037 VisitExplicitCastExpr(E);
1038 Record.AddSourceLocation(E->getLParenLoc());
1039 Record.AddSourceLocation(E->getRParenLoc());
1040 Code = serialization::EXPR_CSTYLE_CAST;
1043 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
1044 VisitExpr(E);
1045 Record.AddSourceLocation(E->getLParenLoc());
1046 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1047 Record.AddStmt(E->getInitializer());
1048 Record.push_back(E->isFileScope());
1049 Code = serialization::EXPR_COMPOUND_LITERAL;
1052 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
1053 VisitExpr(E);
1054 Record.AddStmt(E->getBase());
1055 Record.AddIdentifierRef(&E->getAccessor());
1056 Record.AddSourceLocation(E->getAccessorLoc());
1057 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
1060 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
1061 VisitExpr(E);
1062 // NOTE: only add the (possibly null) syntactic form.
1063 // No need to serialize the isSemanticForm flag and the semantic form.
1064 Record.AddStmt(E->getSyntacticForm());
1065 Record.AddSourceLocation(E->getLBraceLoc());
1066 Record.AddSourceLocation(E->getRBraceLoc());
1067 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
1068 Record.push_back(isArrayFiller);
1069 if (isArrayFiller)
1070 Record.AddStmt(E->getArrayFiller());
1071 else
1072 Record.AddDeclRef(E->getInitializedFieldInUnion());
1073 Record.push_back(E->hadArrayRangeDesignator());
1074 Record.push_back(E->getNumInits());
1075 if (isArrayFiller) {
1076 // ArrayFiller may have filled "holes" due to designated initializer.
1077 // Replace them by 0 to indicate that the filler goes in that place.
1078 Expr *filler = E->getArrayFiller();
1079 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
1080 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
1081 } else {
1082 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
1083 Record.AddStmt(E->getInit(I));
1085 Code = serialization::EXPR_INIT_LIST;
1088 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
1089 VisitExpr(E);
1090 Record.push_back(E->getNumSubExprs());
1091 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1092 Record.AddStmt(E->getSubExpr(I));
1093 Record.AddSourceLocation(E->getEqualOrColonLoc());
1094 Record.push_back(E->usesGNUSyntax());
1095 for (const DesignatedInitExpr::Designator &D : E->designators()) {
1096 if (D.isFieldDesignator()) {
1097 if (FieldDecl *Field = D.getFieldDecl()) {
1098 Record.push_back(serialization::DESIG_FIELD_DECL);
1099 Record.AddDeclRef(Field);
1100 } else {
1101 Record.push_back(serialization::DESIG_FIELD_NAME);
1102 Record.AddIdentifierRef(D.getFieldName());
1104 Record.AddSourceLocation(D.getDotLoc());
1105 Record.AddSourceLocation(D.getFieldLoc());
1106 } else if (D.isArrayDesignator()) {
1107 Record.push_back(serialization::DESIG_ARRAY);
1108 Record.push_back(D.getArrayIndex());
1109 Record.AddSourceLocation(D.getLBracketLoc());
1110 Record.AddSourceLocation(D.getRBracketLoc());
1111 } else {
1112 assert(D.isArrayRangeDesignator() && "Unknown designator");
1113 Record.push_back(serialization::DESIG_ARRAY_RANGE);
1114 Record.push_back(D.getArrayIndex());
1115 Record.AddSourceLocation(D.getLBracketLoc());
1116 Record.AddSourceLocation(D.getEllipsisLoc());
1117 Record.AddSourceLocation(D.getRBracketLoc());
1120 Code = serialization::EXPR_DESIGNATED_INIT;
1123 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
1124 VisitExpr(E);
1125 Record.AddStmt(E->getBase());
1126 Record.AddStmt(E->getUpdater());
1127 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
1130 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
1131 VisitExpr(E);
1132 Code = serialization::EXPR_NO_INIT;
1135 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
1136 VisitExpr(E);
1137 Record.AddStmt(E->SubExprs[0]);
1138 Record.AddStmt(E->SubExprs[1]);
1139 Code = serialization::EXPR_ARRAY_INIT_LOOP;
1142 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
1143 VisitExpr(E);
1144 Code = serialization::EXPR_ARRAY_INIT_INDEX;
1147 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
1148 VisitExpr(E);
1149 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
1152 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
1153 VisitExpr(E);
1154 Record.AddStmt(E->getSubExpr());
1155 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
1156 Record.AddSourceLocation(E->getBuiltinLoc());
1157 Record.AddSourceLocation(E->getRParenLoc());
1158 Record.push_back(E->isMicrosoftABI());
1159 Code = serialization::EXPR_VA_ARG;
1162 void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) {
1163 VisitExpr(E);
1164 Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext()));
1165 Record.AddSourceLocation(E->getBeginLoc());
1166 Record.AddSourceLocation(E->getEndLoc());
1167 Record.push_back(llvm::to_underlying(E->getIdentKind()));
1168 Code = serialization::EXPR_SOURCE_LOC;
1171 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
1172 VisitExpr(E);
1173 Record.AddSourceLocation(E->getAmpAmpLoc());
1174 Record.AddSourceLocation(E->getLabelLoc());
1175 Record.AddDeclRef(E->getLabel());
1176 Code = serialization::EXPR_ADDR_LABEL;
1179 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
1180 VisitExpr(E);
1181 Record.AddStmt(E->getSubStmt());
1182 Record.AddSourceLocation(E->getLParenLoc());
1183 Record.AddSourceLocation(E->getRParenLoc());
1184 Record.push_back(E->getTemplateDepth());
1185 Code = serialization::EXPR_STMT;
1188 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
1189 VisitExpr(E);
1190 Record.AddStmt(E->getCond());
1191 Record.AddStmt(E->getLHS());
1192 Record.AddStmt(E->getRHS());
1193 Record.AddSourceLocation(E->getBuiltinLoc());
1194 Record.AddSourceLocation(E->getRParenLoc());
1195 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
1196 Code = serialization::EXPR_CHOOSE;
1199 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
1200 VisitExpr(E);
1201 Record.AddSourceLocation(E->getTokenLocation());
1202 Code = serialization::EXPR_GNU_NULL;
1205 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
1206 VisitExpr(E);
1207 Record.push_back(E->getNumSubExprs());
1208 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1209 Record.AddStmt(E->getExpr(I));
1210 Record.AddSourceLocation(E->getBuiltinLoc());
1211 Record.AddSourceLocation(E->getRParenLoc());
1212 Code = serialization::EXPR_SHUFFLE_VECTOR;
1215 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
1216 VisitExpr(E);
1217 Record.AddSourceLocation(E->getBuiltinLoc());
1218 Record.AddSourceLocation(E->getRParenLoc());
1219 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1220 Record.AddStmt(E->getSrcExpr());
1221 Code = serialization::EXPR_CONVERT_VECTOR;
1224 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
1225 VisitExpr(E);
1226 Record.AddDeclRef(E->getBlockDecl());
1227 Code = serialization::EXPR_BLOCK;
1230 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
1231 VisitExpr(E);
1233 Record.push_back(E->getNumAssocs());
1234 Record.push_back(E->isExprPredicate());
1235 Record.push_back(E->ResultIndex);
1236 Record.AddSourceLocation(E->getGenericLoc());
1237 Record.AddSourceLocation(E->getDefaultLoc());
1238 Record.AddSourceLocation(E->getRParenLoc());
1240 Stmt **Stmts = E->getTrailingObjects<Stmt *>();
1241 // Add 1 to account for the controlling expression which is the first
1242 // expression in the trailing array of Stmt *. This is not needed for
1243 // the trailing array of TypeSourceInfo *.
1244 for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I)
1245 Record.AddStmt(Stmts[I]);
1247 TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
1248 for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I)
1249 Record.AddTypeSourceInfo(TSIs[I]);
1251 Code = serialization::EXPR_GENERIC_SELECTION;
1254 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
1255 VisitExpr(E);
1256 Record.push_back(E->getNumSemanticExprs());
1258 // Push the result index. Currently, this needs to exactly match
1259 // the encoding used internally for ResultIndex.
1260 unsigned result = E->getResultExprIndex();
1261 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
1262 Record.push_back(result);
1264 Record.AddStmt(E->getSyntacticForm());
1265 for (PseudoObjectExpr::semantics_iterator
1266 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
1267 Record.AddStmt(*i);
1269 Code = serialization::EXPR_PSEUDO_OBJECT;
1272 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
1273 VisitExpr(E);
1274 Record.push_back(E->getOp());
1275 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1276 Record.AddStmt(E->getSubExprs()[I]);
1277 Record.AddSourceLocation(E->getBuiltinLoc());
1278 Record.AddSourceLocation(E->getRParenLoc());
1279 Code = serialization::EXPR_ATOMIC;
1282 //===----------------------------------------------------------------------===//
1283 // Objective-C Expressions and Statements.
1284 //===----------------------------------------------------------------------===//
1286 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
1287 VisitExpr(E);
1288 Record.AddStmt(E->getString());
1289 Record.AddSourceLocation(E->getAtLoc());
1290 Code = serialization::EXPR_OBJC_STRING_LITERAL;
1293 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1294 VisitExpr(E);
1295 Record.AddStmt(E->getSubExpr());
1296 Record.AddDeclRef(E->getBoxingMethod());
1297 Record.AddSourceRange(E->getSourceRange());
1298 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
1301 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1302 VisitExpr(E);
1303 Record.push_back(E->getNumElements());
1304 for (unsigned i = 0; i < E->getNumElements(); i++)
1305 Record.AddStmt(E->getElement(i));
1306 Record.AddDeclRef(E->getArrayWithObjectsMethod());
1307 Record.AddSourceRange(E->getSourceRange());
1308 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1311 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1312 VisitExpr(E);
1313 Record.push_back(E->getNumElements());
1314 Record.push_back(E->HasPackExpansions);
1315 for (unsigned i = 0; i < E->getNumElements(); i++) {
1316 ObjCDictionaryElement Element = E->getKeyValueElement(i);
1317 Record.AddStmt(Element.Key);
1318 Record.AddStmt(Element.Value);
1319 if (E->HasPackExpansions) {
1320 Record.AddSourceLocation(Element.EllipsisLoc);
1321 unsigned NumExpansions = 0;
1322 if (Element.NumExpansions)
1323 NumExpansions = *Element.NumExpansions + 1;
1324 Record.push_back(NumExpansions);
1328 Record.AddDeclRef(E->getDictWithObjectsMethod());
1329 Record.AddSourceRange(E->getSourceRange());
1330 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1333 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
1334 VisitExpr(E);
1335 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1336 Record.AddSourceLocation(E->getAtLoc());
1337 Record.AddSourceLocation(E->getRParenLoc());
1338 Code = serialization::EXPR_OBJC_ENCODE;
1341 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
1342 VisitExpr(E);
1343 Record.AddSelectorRef(E->getSelector());
1344 Record.AddSourceLocation(E->getAtLoc());
1345 Record.AddSourceLocation(E->getRParenLoc());
1346 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
1349 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
1350 VisitExpr(E);
1351 Record.AddDeclRef(E->getProtocol());
1352 Record.AddSourceLocation(E->getAtLoc());
1353 Record.AddSourceLocation(E->ProtoLoc);
1354 Record.AddSourceLocation(E->getRParenLoc());
1355 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
1358 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1359 VisitExpr(E);
1360 Record.AddDeclRef(E->getDecl());
1361 Record.AddSourceLocation(E->getLocation());
1362 Record.AddSourceLocation(E->getOpLoc());
1363 Record.AddStmt(E->getBase());
1364 Record.push_back(E->isArrow());
1365 Record.push_back(E->isFreeIvar());
1366 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
1369 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1370 VisitExpr(E);
1371 Record.push_back(E->SetterAndMethodRefFlags.getInt());
1372 Record.push_back(E->isImplicitProperty());
1373 if (E->isImplicitProperty()) {
1374 Record.AddDeclRef(E->getImplicitPropertyGetter());
1375 Record.AddDeclRef(E->getImplicitPropertySetter());
1376 } else {
1377 Record.AddDeclRef(E->getExplicitProperty());
1379 Record.AddSourceLocation(E->getLocation());
1380 Record.AddSourceLocation(E->getReceiverLocation());
1381 if (E->isObjectReceiver()) {
1382 Record.push_back(0);
1383 Record.AddStmt(E->getBase());
1384 } else if (E->isSuperReceiver()) {
1385 Record.push_back(1);
1386 Record.AddTypeRef(E->getSuperReceiverType());
1387 } else {
1388 Record.push_back(2);
1389 Record.AddDeclRef(E->getClassReceiver());
1392 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
1395 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1396 VisitExpr(E);
1397 Record.AddSourceLocation(E->getRBracket());
1398 Record.AddStmt(E->getBaseExpr());
1399 Record.AddStmt(E->getKeyExpr());
1400 Record.AddDeclRef(E->getAtIndexMethodDecl());
1401 Record.AddDeclRef(E->setAtIndexMethodDecl());
1403 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1406 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1407 VisitExpr(E);
1408 Record.push_back(E->getNumArgs());
1409 Record.push_back(E->getNumStoredSelLocs());
1410 Record.push_back(E->SelLocsKind);
1411 Record.push_back(E->isDelegateInitCall());
1412 Record.push_back(E->IsImplicit);
1413 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1414 switch (E->getReceiverKind()) {
1415 case ObjCMessageExpr::Instance:
1416 Record.AddStmt(E->getInstanceReceiver());
1417 break;
1419 case ObjCMessageExpr::Class:
1420 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
1421 break;
1423 case ObjCMessageExpr::SuperClass:
1424 case ObjCMessageExpr::SuperInstance:
1425 Record.AddTypeRef(E->getSuperType());
1426 Record.AddSourceLocation(E->getSuperLoc());
1427 break;
1430 if (E->getMethodDecl()) {
1431 Record.push_back(1);
1432 Record.AddDeclRef(E->getMethodDecl());
1433 } else {
1434 Record.push_back(0);
1435 Record.AddSelectorRef(E->getSelector());
1438 Record.AddSourceLocation(E->getLeftLoc());
1439 Record.AddSourceLocation(E->getRightLoc());
1441 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1442 Arg != ArgEnd; ++Arg)
1443 Record.AddStmt(*Arg);
1445 SourceLocation *Locs = E->getStoredSelLocs();
1446 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1447 Record.AddSourceLocation(Locs[i]);
1449 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1452 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1453 VisitStmt(S);
1454 Record.AddStmt(S->getElement());
1455 Record.AddStmt(S->getCollection());
1456 Record.AddStmt(S->getBody());
1457 Record.AddSourceLocation(S->getForLoc());
1458 Record.AddSourceLocation(S->getRParenLoc());
1459 Code = serialization::STMT_OBJC_FOR_COLLECTION;
1462 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1463 VisitStmt(S);
1464 Record.AddStmt(S->getCatchBody());
1465 Record.AddDeclRef(S->getCatchParamDecl());
1466 Record.AddSourceLocation(S->getAtCatchLoc());
1467 Record.AddSourceLocation(S->getRParenLoc());
1468 Code = serialization::STMT_OBJC_CATCH;
1471 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1472 VisitStmt(S);
1473 Record.AddStmt(S->getFinallyBody());
1474 Record.AddSourceLocation(S->getAtFinallyLoc());
1475 Code = serialization::STMT_OBJC_FINALLY;
1478 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1479 VisitStmt(S); // FIXME: no test coverage.
1480 Record.AddStmt(S->getSubStmt());
1481 Record.AddSourceLocation(S->getAtLoc());
1482 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1485 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1486 VisitStmt(S);
1487 Record.push_back(S->getNumCatchStmts());
1488 Record.push_back(S->getFinallyStmt() != nullptr);
1489 Record.AddStmt(S->getTryBody());
1490 for (ObjCAtCatchStmt *C : S->catch_stmts())
1491 Record.AddStmt(C);
1492 if (S->getFinallyStmt())
1493 Record.AddStmt(S->getFinallyStmt());
1494 Record.AddSourceLocation(S->getAtTryLoc());
1495 Code = serialization::STMT_OBJC_AT_TRY;
1498 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1499 VisitStmt(S); // FIXME: no test coverage.
1500 Record.AddStmt(S->getSynchExpr());
1501 Record.AddStmt(S->getSynchBody());
1502 Record.AddSourceLocation(S->getAtSynchronizedLoc());
1503 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1506 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1507 VisitStmt(S); // FIXME: no test coverage.
1508 Record.AddStmt(S->getThrowExpr());
1509 Record.AddSourceLocation(S->getThrowLoc());
1510 Code = serialization::STMT_OBJC_AT_THROW;
1513 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1514 VisitExpr(E);
1515 Record.push_back(E->getValue());
1516 Record.AddSourceLocation(E->getLocation());
1517 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1520 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1521 VisitExpr(E);
1522 Record.AddSourceRange(E->getSourceRange());
1523 Record.AddVersionTuple(E->getVersion());
1524 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1527 //===----------------------------------------------------------------------===//
1528 // C++ Expressions and Statements.
1529 //===----------------------------------------------------------------------===//
1531 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1532 VisitStmt(S);
1533 Record.AddSourceLocation(S->getCatchLoc());
1534 Record.AddDeclRef(S->getExceptionDecl());
1535 Record.AddStmt(S->getHandlerBlock());
1536 Code = serialization::STMT_CXX_CATCH;
1539 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1540 VisitStmt(S);
1541 Record.push_back(S->getNumHandlers());
1542 Record.AddSourceLocation(S->getTryLoc());
1543 Record.AddStmt(S->getTryBlock());
1544 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1545 Record.AddStmt(S->getHandler(i));
1546 Code = serialization::STMT_CXX_TRY;
1549 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1550 VisitStmt(S);
1551 Record.AddSourceLocation(S->getForLoc());
1552 Record.AddSourceLocation(S->getCoawaitLoc());
1553 Record.AddSourceLocation(S->getColonLoc());
1554 Record.AddSourceLocation(S->getRParenLoc());
1555 Record.AddStmt(S->getInit());
1556 Record.AddStmt(S->getRangeStmt());
1557 Record.AddStmt(S->getBeginStmt());
1558 Record.AddStmt(S->getEndStmt());
1559 Record.AddStmt(S->getCond());
1560 Record.AddStmt(S->getInc());
1561 Record.AddStmt(S->getLoopVarStmt());
1562 Record.AddStmt(S->getBody());
1563 Code = serialization::STMT_CXX_FOR_RANGE;
1566 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1567 VisitStmt(S);
1568 Record.AddSourceLocation(S->getKeywordLoc());
1569 Record.push_back(S->isIfExists());
1570 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1571 Record.AddDeclarationNameInfo(S->getNameInfo());
1572 Record.AddStmt(S->getSubStmt());
1573 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1576 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1577 VisitCallExpr(E);
1578 Record.push_back(E->getOperator());
1579 Record.AddSourceRange(E->Range);
1580 Code = serialization::EXPR_CXX_OPERATOR_CALL;
1583 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1584 VisitCallExpr(E);
1585 Code = serialization::EXPR_CXX_MEMBER_CALL;
1588 void ASTStmtWriter::VisitCXXRewrittenBinaryOperator(
1589 CXXRewrittenBinaryOperator *E) {
1590 VisitExpr(E);
1591 Record.push_back(E->isReversed());
1592 Record.AddStmt(E->getSemanticForm());
1593 Code = serialization::EXPR_CXX_REWRITTEN_BINARY_OPERATOR;
1596 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1597 VisitExpr(E);
1599 Record.push_back(E->getNumArgs());
1600 Record.push_back(E->isElidable());
1601 Record.push_back(E->hadMultipleCandidates());
1602 Record.push_back(E->isListInitialization());
1603 Record.push_back(E->isStdInitListInitialization());
1604 Record.push_back(E->requiresZeroInitialization());
1605 Record.push_back(
1606 llvm::to_underlying(E->getConstructionKind())); // FIXME: stable encoding
1607 Record.push_back(E->isImmediateEscalating());
1608 Record.AddSourceLocation(E->getLocation());
1609 Record.AddDeclRef(E->getConstructor());
1610 Record.AddSourceRange(E->getParenOrBraceRange());
1612 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1613 Record.AddStmt(E->getArg(I));
1615 Code = serialization::EXPR_CXX_CONSTRUCT;
1618 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1619 VisitExpr(E);
1620 Record.AddDeclRef(E->getConstructor());
1621 Record.AddSourceLocation(E->getLocation());
1622 Record.push_back(E->constructsVBase());
1623 Record.push_back(E->inheritedFromVBase());
1624 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1627 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1628 VisitCXXConstructExpr(E);
1629 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1630 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1633 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1634 VisitExpr(E);
1635 Record.push_back(E->LambdaExprBits.NumCaptures);
1636 Record.AddSourceRange(E->IntroducerRange);
1637 Record.push_back(E->LambdaExprBits.CaptureDefault); // FIXME: stable encoding
1638 Record.AddSourceLocation(E->CaptureDefaultLoc);
1639 Record.push_back(E->LambdaExprBits.ExplicitParams);
1640 Record.push_back(E->LambdaExprBits.ExplicitResultType);
1641 Record.AddSourceLocation(E->ClosingBrace);
1643 // Add capture initializers.
1644 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1645 CEnd = E->capture_init_end();
1646 C != CEnd; ++C) {
1647 Record.AddStmt(*C);
1650 // Don't serialize the body. It belongs to the call operator declaration.
1651 // LambdaExpr only stores a copy of the Stmt *.
1653 Code = serialization::EXPR_LAMBDA;
1656 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1657 VisitExpr(E);
1658 Record.AddStmt(E->getSubExpr());
1659 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1662 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1663 VisitExplicitCastExpr(E);
1664 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1665 Record.AddSourceRange(E->getAngleBrackets());
1668 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1669 VisitCXXNamedCastExpr(E);
1670 Code = serialization::EXPR_CXX_STATIC_CAST;
1673 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1674 VisitCXXNamedCastExpr(E);
1675 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1678 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1679 VisitCXXNamedCastExpr(E);
1680 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1683 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1684 VisitCXXNamedCastExpr(E);
1685 Code = serialization::EXPR_CXX_CONST_CAST;
1688 void ASTStmtWriter::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
1689 VisitCXXNamedCastExpr(E);
1690 Code = serialization::EXPR_CXX_ADDRSPACE_CAST;
1693 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1694 VisitExplicitCastExpr(E);
1695 Record.AddSourceLocation(E->getLParenLoc());
1696 Record.AddSourceLocation(E->getRParenLoc());
1697 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1700 void ASTStmtWriter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
1701 VisitExplicitCastExpr(E);
1702 Record.AddSourceLocation(E->getBeginLoc());
1703 Record.AddSourceLocation(E->getEndLoc());
1704 Code = serialization::EXPR_BUILTIN_BIT_CAST;
1707 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1708 VisitCallExpr(E);
1709 Record.AddSourceLocation(E->UDSuffixLoc);
1710 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1713 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1714 VisitExpr(E);
1715 Record.push_back(E->getValue());
1716 Record.AddSourceLocation(E->getLocation());
1717 Code = serialization::EXPR_CXX_BOOL_LITERAL;
1720 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1721 VisitExpr(E);
1722 Record.AddSourceLocation(E->getLocation());
1723 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1726 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1727 VisitExpr(E);
1728 Record.AddSourceRange(E->getSourceRange());
1729 if (E->isTypeOperand()) {
1730 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1731 Code = serialization::EXPR_CXX_TYPEID_TYPE;
1732 } else {
1733 Record.AddStmt(E->getExprOperand());
1734 Code = serialization::EXPR_CXX_TYPEID_EXPR;
1738 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1739 VisitExpr(E);
1740 Record.AddSourceLocation(E->getLocation());
1741 Record.push_back(E->isImplicit());
1742 Code = serialization::EXPR_CXX_THIS;
1745 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1746 VisitExpr(E);
1747 Record.AddSourceLocation(E->getThrowLoc());
1748 Record.AddStmt(E->getSubExpr());
1749 Record.push_back(E->isThrownVariableInScope());
1750 Code = serialization::EXPR_CXX_THROW;
1753 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1754 VisitExpr(E);
1755 Record.AddDeclRef(E->getParam());
1756 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1757 Record.AddSourceLocation(E->getUsedLocation());
1758 Record.push_back(E->hasRewrittenInit());
1759 if (E->hasRewrittenInit())
1760 Record.AddStmt(E->getRewrittenExpr());
1761 Code = serialization::EXPR_CXX_DEFAULT_ARG;
1764 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1765 VisitExpr(E);
1766 Record.push_back(E->hasRewrittenInit());
1767 Record.AddDeclRef(E->getField());
1768 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1769 Record.AddSourceLocation(E->getExprLoc());
1770 if (E->hasRewrittenInit())
1771 Record.AddStmt(E->getRewrittenExpr());
1772 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1775 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1776 VisitExpr(E);
1777 Record.AddCXXTemporary(E->getTemporary());
1778 Record.AddStmt(E->getSubExpr());
1779 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1782 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1783 VisitExpr(E);
1784 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1785 Record.AddSourceLocation(E->getRParenLoc());
1786 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1789 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1790 VisitExpr(E);
1792 Record.push_back(E->isArray());
1793 Record.push_back(E->hasInitializer());
1794 Record.push_back(E->getNumPlacementArgs());
1795 Record.push_back(E->isParenTypeId());
1797 Record.push_back(E->isGlobalNew());
1798 Record.push_back(E->passAlignment());
1799 Record.push_back(E->doesUsualArrayDeleteWantSize());
1800 Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
1802 Record.AddDeclRef(E->getOperatorNew());
1803 Record.AddDeclRef(E->getOperatorDelete());
1804 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1805 if (E->isParenTypeId())
1806 Record.AddSourceRange(E->getTypeIdParens());
1807 Record.AddSourceRange(E->getSourceRange());
1808 Record.AddSourceRange(E->getDirectInitRange());
1810 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
1811 I != N; ++I)
1812 Record.AddStmt(*I);
1814 Code = serialization::EXPR_CXX_NEW;
1817 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1818 VisitExpr(E);
1819 Record.push_back(E->isGlobalDelete());
1820 Record.push_back(E->isArrayForm());
1821 Record.push_back(E->isArrayFormAsWritten());
1822 Record.push_back(E->doesUsualArrayDeleteWantSize());
1823 Record.AddDeclRef(E->getOperatorDelete());
1824 Record.AddStmt(E->getArgument());
1825 Record.AddSourceLocation(E->getBeginLoc());
1827 Code = serialization::EXPR_CXX_DELETE;
1830 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1831 VisitExpr(E);
1833 Record.AddStmt(E->getBase());
1834 Record.push_back(E->isArrow());
1835 Record.AddSourceLocation(E->getOperatorLoc());
1836 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1837 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1838 Record.AddSourceLocation(E->getColonColonLoc());
1839 Record.AddSourceLocation(E->getTildeLoc());
1841 // PseudoDestructorTypeStorage.
1842 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
1843 if (E->getDestroyedTypeIdentifier())
1844 Record.AddSourceLocation(E->getDestroyedTypeLoc());
1845 else
1846 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
1848 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1851 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1852 VisitExpr(E);
1853 Record.push_back(E->getNumObjects());
1854 for (auto &Obj : E->getObjects()) {
1855 if (auto *BD = Obj.dyn_cast<BlockDecl *>()) {
1856 Record.push_back(serialization::COK_Block);
1857 Record.AddDeclRef(BD);
1858 } else if (auto *CLE = Obj.dyn_cast<CompoundLiteralExpr *>()) {
1859 Record.push_back(serialization::COK_CompoundLiteral);
1860 Record.AddStmt(CLE);
1864 Record.push_back(E->cleanupsHaveSideEffects());
1865 Record.AddStmt(E->getSubExpr());
1866 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1869 void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
1870 CXXDependentScopeMemberExpr *E) {
1871 VisitExpr(E);
1873 // Don't emit anything here (or if you do you will have to update
1874 // the corresponding deserialization function).
1876 Record.push_back(E->hasTemplateKWAndArgsInfo());
1877 Record.push_back(E->getNumTemplateArgs());
1878 Record.push_back(E->hasFirstQualifierFoundInScope());
1880 if (E->hasTemplateKWAndArgsInfo()) {
1881 const ASTTemplateKWAndArgsInfo &ArgInfo =
1882 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1883 AddTemplateKWAndArgsInfo(ArgInfo,
1884 E->getTrailingObjects<TemplateArgumentLoc>());
1887 Record.push_back(E->isArrow());
1888 Record.AddSourceLocation(E->getOperatorLoc());
1889 Record.AddTypeRef(E->getBaseType());
1890 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1891 if (!E->isImplicitAccess())
1892 Record.AddStmt(E->getBase());
1893 else
1894 Record.AddStmt(nullptr);
1896 if (E->hasFirstQualifierFoundInScope())
1897 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1899 Record.AddDeclarationNameInfo(E->MemberNameInfo);
1900 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
1903 void
1904 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1905 VisitExpr(E);
1907 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1908 // emitted first.
1910 Record.push_back(E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
1911 if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
1912 const ASTTemplateKWAndArgsInfo &ArgInfo =
1913 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1914 Record.push_back(ArgInfo.NumTemplateArgs);
1915 AddTemplateKWAndArgsInfo(ArgInfo,
1916 E->getTrailingObjects<TemplateArgumentLoc>());
1919 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1920 Record.AddDeclarationNameInfo(E->NameInfo);
1921 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
1924 void
1925 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1926 VisitExpr(E);
1927 Record.push_back(E->getNumArgs());
1928 for (CXXUnresolvedConstructExpr::arg_iterator
1929 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
1930 Record.AddStmt(*ArgI);
1931 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1932 Record.AddSourceLocation(E->getLParenLoc());
1933 Record.AddSourceLocation(E->getRParenLoc());
1934 Record.push_back(E->isListInitialization());
1935 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
1938 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
1939 VisitExpr(E);
1941 Record.push_back(E->getNumDecls());
1942 Record.push_back(E->hasTemplateKWAndArgsInfo());
1943 if (E->hasTemplateKWAndArgsInfo()) {
1944 const ASTTemplateKWAndArgsInfo &ArgInfo =
1945 *E->getTrailingASTTemplateKWAndArgsInfo();
1946 Record.push_back(ArgInfo.NumTemplateArgs);
1947 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
1950 for (OverloadExpr::decls_iterator OvI = E->decls_begin(),
1951 OvE = E->decls_end();
1952 OvI != OvE; ++OvI) {
1953 Record.AddDeclRef(OvI.getDecl());
1954 Record.push_back(OvI.getAccess());
1957 Record.AddDeclarationNameInfo(E->getNameInfo());
1958 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1961 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1962 VisitOverloadExpr(E);
1963 Record.push_back(E->isArrow());
1964 Record.push_back(E->hasUnresolvedUsing());
1965 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1966 Record.AddTypeRef(E->getBaseType());
1967 Record.AddSourceLocation(E->getOperatorLoc());
1968 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
1971 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1972 VisitOverloadExpr(E);
1973 Record.push_back(E->requiresADL());
1974 Record.push_back(E->isOverloaded());
1975 Record.AddDeclRef(E->getNamingClass());
1976 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
1979 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1980 VisitExpr(E);
1981 Record.push_back(E->TypeTraitExprBits.NumArgs);
1982 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1983 Record.push_back(E->TypeTraitExprBits.Value);
1984 Record.AddSourceRange(E->getSourceRange());
1985 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1986 Record.AddTypeSourceInfo(E->getArg(I));
1987 Code = serialization::EXPR_TYPE_TRAIT;
1990 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1991 VisitExpr(E);
1992 Record.push_back(E->getTrait());
1993 Record.push_back(E->getValue());
1994 Record.AddSourceRange(E->getSourceRange());
1995 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
1996 Record.AddStmt(E->getDimensionExpression());
1997 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
2000 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2001 VisitExpr(E);
2002 Record.push_back(E->getTrait());
2003 Record.push_back(E->getValue());
2004 Record.AddSourceRange(E->getSourceRange());
2005 Record.AddStmt(E->getQueriedExpression());
2006 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
2009 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2010 VisitExpr(E);
2011 Record.push_back(E->getValue());
2012 Record.AddSourceRange(E->getSourceRange());
2013 Record.AddStmt(E->getOperand());
2014 Code = serialization::EXPR_CXX_NOEXCEPT;
2017 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
2018 VisitExpr(E);
2019 Record.AddSourceLocation(E->getEllipsisLoc());
2020 Record.push_back(E->NumExpansions);
2021 Record.AddStmt(E->getPattern());
2022 Code = serialization::EXPR_PACK_EXPANSION;
2025 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2026 VisitExpr(E);
2027 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
2028 : 0);
2029 Record.AddSourceLocation(E->OperatorLoc);
2030 Record.AddSourceLocation(E->PackLoc);
2031 Record.AddSourceLocation(E->RParenLoc);
2032 Record.AddDeclRef(E->Pack);
2033 if (E->isPartiallySubstituted()) {
2034 for (const auto &TA : E->getPartialArguments())
2035 Record.AddTemplateArgument(TA);
2036 } else if (!E->isValueDependent()) {
2037 Record.push_back(E->getPackLength());
2039 Code = serialization::EXPR_SIZEOF_PACK;
2042 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
2043 SubstNonTypeTemplateParmExpr *E) {
2044 VisitExpr(E);
2045 Record.AddDeclRef(E->getAssociatedDecl());
2046 Record.push_back(E->isReferenceParameter());
2047 Record.push_back(E->getIndex());
2048 if (auto PackIndex = E->getPackIndex())
2049 Record.push_back(*PackIndex + 1);
2050 else
2051 Record.push_back(0);
2052 Record.AddSourceLocation(E->getNameLoc());
2053 Record.AddStmt(E->getReplacement());
2054 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
2057 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
2058 SubstNonTypeTemplateParmPackExpr *E) {
2059 VisitExpr(E);
2060 Record.AddDeclRef(E->getAssociatedDecl());
2061 Record.push_back(E->getIndex());
2062 Record.AddTemplateArgument(E->getArgumentPack());
2063 Record.AddSourceLocation(E->getParameterPackLocation());
2064 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
2067 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2068 VisitExpr(E);
2069 Record.push_back(E->getNumExpansions());
2070 Record.AddDeclRef(E->getParameterPack());
2071 Record.AddSourceLocation(E->getParameterPackLocation());
2072 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
2073 I != End; ++I)
2074 Record.AddDeclRef(*I);
2075 Code = serialization::EXPR_FUNCTION_PARM_PACK;
2078 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
2079 VisitExpr(E);
2080 Record.push_back(static_cast<bool>(E->getLifetimeExtendedTemporaryDecl()));
2081 if (E->getLifetimeExtendedTemporaryDecl())
2082 Record.AddDeclRef(E->getLifetimeExtendedTemporaryDecl());
2083 else
2084 Record.AddStmt(E->getSubExpr());
2085 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
2088 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
2089 VisitExpr(E);
2090 Record.AddSourceLocation(E->LParenLoc);
2091 Record.AddSourceLocation(E->EllipsisLoc);
2092 Record.AddSourceLocation(E->RParenLoc);
2093 Record.push_back(E->NumExpansions);
2094 Record.AddStmt(E->SubExprs[0]);
2095 Record.AddStmt(E->SubExprs[1]);
2096 Record.AddStmt(E->SubExprs[2]);
2097 Record.push_back(E->Opcode);
2098 Code = serialization::EXPR_CXX_FOLD;
2101 void ASTStmtWriter::VisitCXXParenListInitExpr(CXXParenListInitExpr *E) {
2102 VisitExpr(E);
2103 ArrayRef<Expr *> InitExprs = E->getInitExprs();
2104 Record.push_back(InitExprs.size());
2105 Record.push_back(E->getUserSpecifiedInitExprs().size());
2106 Record.AddSourceLocation(E->getInitLoc());
2107 Record.AddSourceLocation(E->getBeginLoc());
2108 Record.AddSourceLocation(E->getEndLoc());
2109 for (Expr *InitExpr : E->getInitExprs())
2110 Record.AddStmt(InitExpr);
2111 Expr *ArrayFiller = E->getArrayFiller();
2112 FieldDecl *UnionField = E->getInitializedFieldInUnion();
2113 bool HasArrayFillerOrUnionDecl = ArrayFiller || UnionField;
2114 Record.push_back(HasArrayFillerOrUnionDecl);
2115 if (HasArrayFillerOrUnionDecl) {
2116 Record.push_back(static_cast<bool>(ArrayFiller));
2117 if (ArrayFiller)
2118 Record.AddStmt(ArrayFiller);
2119 else
2120 Record.AddDeclRef(UnionField);
2122 Code = serialization::EXPR_CXX_PAREN_LIST_INIT;
2125 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
2126 VisitExpr(E);
2127 Record.AddStmt(E->getSourceExpr());
2128 Record.AddSourceLocation(E->getLocation());
2129 Record.push_back(E->isUnique());
2130 Code = serialization::EXPR_OPAQUE_VALUE;
2133 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
2134 VisitExpr(E);
2135 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
2136 llvm_unreachable("Cannot write TypoExpr nodes");
2139 //===----------------------------------------------------------------------===//
2140 // CUDA Expressions and Statements.
2141 //===----------------------------------------------------------------------===//
2143 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
2144 VisitCallExpr(E);
2145 Record.AddStmt(E->getConfig());
2146 Code = serialization::EXPR_CUDA_KERNEL_CALL;
2149 //===----------------------------------------------------------------------===//
2150 // OpenCL Expressions and Statements.
2151 //===----------------------------------------------------------------------===//
2152 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
2153 VisitExpr(E);
2154 Record.AddSourceLocation(E->getBuiltinLoc());
2155 Record.AddSourceLocation(E->getRParenLoc());
2156 Record.AddStmt(E->getSrcExpr());
2157 Code = serialization::EXPR_ASTYPE;
2160 //===----------------------------------------------------------------------===//
2161 // Microsoft Expressions and Statements.
2162 //===----------------------------------------------------------------------===//
2163 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
2164 VisitExpr(E);
2165 Record.push_back(E->isArrow());
2166 Record.AddStmt(E->getBaseExpr());
2167 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
2168 Record.AddSourceLocation(E->getMemberLoc());
2169 Record.AddDeclRef(E->getPropertyDecl());
2170 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
2173 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
2174 VisitExpr(E);
2175 Record.AddStmt(E->getBase());
2176 Record.AddStmt(E->getIdx());
2177 Record.AddSourceLocation(E->getRBracketLoc());
2178 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
2181 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
2182 VisitExpr(E);
2183 Record.AddSourceRange(E->getSourceRange());
2184 Record.AddDeclRef(E->getGuidDecl());
2185 if (E->isTypeOperand()) {
2186 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
2187 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
2188 } else {
2189 Record.AddStmt(E->getExprOperand());
2190 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
2194 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
2195 VisitStmt(S);
2196 Record.AddSourceLocation(S->getExceptLoc());
2197 Record.AddStmt(S->getFilterExpr());
2198 Record.AddStmt(S->getBlock());
2199 Code = serialization::STMT_SEH_EXCEPT;
2202 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
2203 VisitStmt(S);
2204 Record.AddSourceLocation(S->getFinallyLoc());
2205 Record.AddStmt(S->getBlock());
2206 Code = serialization::STMT_SEH_FINALLY;
2209 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
2210 VisitStmt(S);
2211 Record.push_back(S->getIsCXXTry());
2212 Record.AddSourceLocation(S->getTryLoc());
2213 Record.AddStmt(S->getTryBlock());
2214 Record.AddStmt(S->getHandler());
2215 Code = serialization::STMT_SEH_TRY;
2218 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
2219 VisitStmt(S);
2220 Record.AddSourceLocation(S->getLeaveLoc());
2221 Code = serialization::STMT_SEH_LEAVE;
2224 //===----------------------------------------------------------------------===//
2225 // OpenMP Directives.
2226 //===----------------------------------------------------------------------===//
2228 void ASTStmtWriter::VisitOMPCanonicalLoop(OMPCanonicalLoop *S) {
2229 VisitStmt(S);
2230 for (Stmt *SubStmt : S->SubStmts)
2231 Record.AddStmt(SubStmt);
2232 Code = serialization::STMT_OMP_CANONICAL_LOOP;
2235 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2236 Record.writeOMPChildren(E->Data);
2237 Record.AddSourceLocation(E->getBeginLoc());
2238 Record.AddSourceLocation(E->getEndLoc());
2239 Record.writeEnum(E->getMappedDirective());
2242 void ASTStmtWriter::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {
2243 VisitStmt(D);
2244 Record.writeUInt32(D->getLoopsNumber());
2245 VisitOMPExecutableDirective(D);
2248 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
2249 VisitOMPLoopBasedDirective(D);
2252 void ASTStmtWriter::VisitOMPMetaDirective(OMPMetaDirective *D) {
2253 VisitStmt(D);
2254 Record.push_back(D->getNumClauses());
2255 VisitOMPExecutableDirective(D);
2256 Code = serialization::STMT_OMP_META_DIRECTIVE;
2259 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2260 VisitStmt(D);
2261 VisitOMPExecutableDirective(D);
2262 Record.writeBool(D->hasCancel());
2263 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2266 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2267 VisitOMPLoopDirective(D);
2268 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2271 void ASTStmtWriter::VisitOMPLoopTransformationDirective(
2272 OMPLoopTransformationDirective *D) {
2273 VisitOMPLoopBasedDirective(D);
2274 Record.writeUInt32(D->getNumGeneratedLoops());
2277 void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective *D) {
2278 VisitOMPLoopTransformationDirective(D);
2279 Code = serialization::STMT_OMP_TILE_DIRECTIVE;
2282 void ASTStmtWriter::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
2283 VisitOMPLoopTransformationDirective(D);
2284 Code = serialization::STMT_OMP_UNROLL_DIRECTIVE;
2287 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2288 VisitOMPLoopDirective(D);
2289 Record.writeBool(D->hasCancel());
2290 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2293 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2294 VisitOMPLoopDirective(D);
2295 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2298 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2299 VisitStmt(D);
2300 VisitOMPExecutableDirective(D);
2301 Record.writeBool(D->hasCancel());
2302 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2305 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2306 VisitStmt(D);
2307 VisitOMPExecutableDirective(D);
2308 Record.writeBool(D->hasCancel());
2309 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2312 void ASTStmtWriter::VisitOMPScopeDirective(OMPScopeDirective *D) {
2313 VisitStmt(D);
2314 VisitOMPExecutableDirective(D);
2315 Code = serialization::STMT_OMP_SCOPE_DIRECTIVE;
2318 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2319 VisitStmt(D);
2320 VisitOMPExecutableDirective(D);
2321 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2324 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2325 VisitStmt(D);
2326 VisitOMPExecutableDirective(D);
2327 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2330 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2331 VisitStmt(D);
2332 VisitOMPExecutableDirective(D);
2333 Record.AddDeclarationNameInfo(D->getDirectiveName());
2334 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2337 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2338 VisitOMPLoopDirective(D);
2339 Record.writeBool(D->hasCancel());
2340 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2343 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2344 OMPParallelForSimdDirective *D) {
2345 VisitOMPLoopDirective(D);
2346 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2349 void ASTStmtWriter::VisitOMPParallelMasterDirective(
2350 OMPParallelMasterDirective *D) {
2351 VisitStmt(D);
2352 VisitOMPExecutableDirective(D);
2353 Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE;
2356 void ASTStmtWriter::VisitOMPParallelMaskedDirective(
2357 OMPParallelMaskedDirective *D) {
2358 VisitStmt(D);
2359 VisitOMPExecutableDirective(D);
2360 Code = serialization::STMT_OMP_PARALLEL_MASKED_DIRECTIVE;
2363 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2364 OMPParallelSectionsDirective *D) {
2365 VisitStmt(D);
2366 VisitOMPExecutableDirective(D);
2367 Record.writeBool(D->hasCancel());
2368 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2371 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2372 VisitStmt(D);
2373 VisitOMPExecutableDirective(D);
2374 Record.writeBool(D->hasCancel());
2375 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2378 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2379 VisitStmt(D);
2380 VisitOMPExecutableDirective(D);
2381 Record.writeBool(D->isXLHSInRHSPart());
2382 Record.writeBool(D->isPostfixUpdate());
2383 Record.writeBool(D->isFailOnly());
2384 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2387 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2388 VisitStmt(D);
2389 VisitOMPExecutableDirective(D);
2390 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2393 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2394 VisitStmt(D);
2395 VisitOMPExecutableDirective(D);
2396 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2399 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2400 OMPTargetEnterDataDirective *D) {
2401 VisitStmt(D);
2402 VisitOMPExecutableDirective(D);
2403 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2406 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2407 OMPTargetExitDataDirective *D) {
2408 VisitStmt(D);
2409 VisitOMPExecutableDirective(D);
2410 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2413 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2414 OMPTargetParallelDirective *D) {
2415 VisitStmt(D);
2416 VisitOMPExecutableDirective(D);
2417 Record.writeBool(D->hasCancel());
2418 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2421 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2422 OMPTargetParallelForDirective *D) {
2423 VisitOMPLoopDirective(D);
2424 Record.writeBool(D->hasCancel());
2425 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2428 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2429 VisitStmt(D);
2430 VisitOMPExecutableDirective(D);
2431 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2434 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2435 VisitStmt(D);
2436 VisitOMPExecutableDirective(D);
2437 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2440 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2441 VisitStmt(D);
2442 Record.push_back(D->getNumClauses());
2443 VisitOMPExecutableDirective(D);
2444 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2447 void ASTStmtWriter::VisitOMPErrorDirective(OMPErrorDirective *D) {
2448 VisitStmt(D);
2449 Record.push_back(D->getNumClauses());
2450 VisitOMPExecutableDirective(D);
2451 Code = serialization::STMT_OMP_ERROR_DIRECTIVE;
2454 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2455 VisitStmt(D);
2456 VisitOMPExecutableDirective(D);
2457 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2460 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2461 VisitStmt(D);
2462 VisitOMPExecutableDirective(D);
2463 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2466 void ASTStmtWriter::VisitOMPDepobjDirective(OMPDepobjDirective *D) {
2467 VisitStmt(D);
2468 VisitOMPExecutableDirective(D);
2469 Code = serialization::STMT_OMP_DEPOBJ_DIRECTIVE;
2472 void ASTStmtWriter::VisitOMPScanDirective(OMPScanDirective *D) {
2473 VisitStmt(D);
2474 VisitOMPExecutableDirective(D);
2475 Code = serialization::STMT_OMP_SCAN_DIRECTIVE;
2478 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2479 VisitStmt(D);
2480 VisitOMPExecutableDirective(D);
2481 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2484 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2485 VisitStmt(D);
2486 VisitOMPExecutableDirective(D);
2487 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2490 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2491 OMPCancellationPointDirective *D) {
2492 VisitStmt(D);
2493 VisitOMPExecutableDirective(D);
2494 Record.writeEnum(D->getCancelRegion());
2495 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2498 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2499 VisitStmt(D);
2500 VisitOMPExecutableDirective(D);
2501 Record.writeEnum(D->getCancelRegion());
2502 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2505 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2506 VisitOMPLoopDirective(D);
2507 Record.writeBool(D->hasCancel());
2508 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2511 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2512 VisitOMPLoopDirective(D);
2513 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2516 void ASTStmtWriter::VisitOMPMasterTaskLoopDirective(
2517 OMPMasterTaskLoopDirective *D) {
2518 VisitOMPLoopDirective(D);
2519 Record.writeBool(D->hasCancel());
2520 Code = serialization::STMT_OMP_MASTER_TASKLOOP_DIRECTIVE;
2523 void ASTStmtWriter::VisitOMPMaskedTaskLoopDirective(
2524 OMPMaskedTaskLoopDirective *D) {
2525 VisitOMPLoopDirective(D);
2526 Record.writeBool(D->hasCancel());
2527 Code = serialization::STMT_OMP_MASKED_TASKLOOP_DIRECTIVE;
2530 void ASTStmtWriter::VisitOMPMasterTaskLoopSimdDirective(
2531 OMPMasterTaskLoopSimdDirective *D) {
2532 VisitOMPLoopDirective(D);
2533 Code = serialization::STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE;
2536 void ASTStmtWriter::VisitOMPMaskedTaskLoopSimdDirective(
2537 OMPMaskedTaskLoopSimdDirective *D) {
2538 VisitOMPLoopDirective(D);
2539 Code = serialization::STMT_OMP_MASKED_TASKLOOP_SIMD_DIRECTIVE;
2542 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopDirective(
2543 OMPParallelMasterTaskLoopDirective *D) {
2544 VisitOMPLoopDirective(D);
2545 Record.writeBool(D->hasCancel());
2546 Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE;
2549 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopDirective(
2550 OMPParallelMaskedTaskLoopDirective *D) {
2551 VisitOMPLoopDirective(D);
2552 Record.writeBool(D->hasCancel());
2553 Code = serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_DIRECTIVE;
2556 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopSimdDirective(
2557 OMPParallelMasterTaskLoopSimdDirective *D) {
2558 VisitOMPLoopDirective(D);
2559 Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE;
2562 void ASTStmtWriter::VisitOMPParallelMaskedTaskLoopSimdDirective(
2563 OMPParallelMaskedTaskLoopSimdDirective *D) {
2564 VisitOMPLoopDirective(D);
2565 Code = serialization::STMT_OMP_PARALLEL_MASKED_TASKLOOP_SIMD_DIRECTIVE;
2568 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2569 VisitOMPLoopDirective(D);
2570 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2573 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2574 VisitStmt(D);
2575 VisitOMPExecutableDirective(D);
2576 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2579 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2580 OMPDistributeParallelForDirective *D) {
2581 VisitOMPLoopDirective(D);
2582 Record.writeBool(D->hasCancel());
2583 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2586 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2587 OMPDistributeParallelForSimdDirective *D) {
2588 VisitOMPLoopDirective(D);
2589 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2592 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2593 OMPDistributeSimdDirective *D) {
2594 VisitOMPLoopDirective(D);
2595 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2598 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2599 OMPTargetParallelForSimdDirective *D) {
2600 VisitOMPLoopDirective(D);
2601 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2604 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2605 VisitOMPLoopDirective(D);
2606 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2609 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2610 OMPTeamsDistributeDirective *D) {
2611 VisitOMPLoopDirective(D);
2612 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2615 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2616 OMPTeamsDistributeSimdDirective *D) {
2617 VisitOMPLoopDirective(D);
2618 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2621 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2622 OMPTeamsDistributeParallelForSimdDirective *D) {
2623 VisitOMPLoopDirective(D);
2624 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2627 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2628 OMPTeamsDistributeParallelForDirective *D) {
2629 VisitOMPLoopDirective(D);
2630 Record.writeBool(D->hasCancel());
2631 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2634 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2635 VisitStmt(D);
2636 VisitOMPExecutableDirective(D);
2637 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2640 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2641 OMPTargetTeamsDistributeDirective *D) {
2642 VisitOMPLoopDirective(D);
2643 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2646 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2647 OMPTargetTeamsDistributeParallelForDirective *D) {
2648 VisitOMPLoopDirective(D);
2649 Record.writeBool(D->hasCancel());
2650 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2653 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2654 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2655 VisitOMPLoopDirective(D);
2656 Code = serialization::
2657 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2660 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2661 OMPTargetTeamsDistributeSimdDirective *D) {
2662 VisitOMPLoopDirective(D);
2663 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2666 void ASTStmtWriter::VisitOMPInteropDirective(OMPInteropDirective *D) {
2667 VisitStmt(D);
2668 VisitOMPExecutableDirective(D);
2669 Code = serialization::STMT_OMP_INTEROP_DIRECTIVE;
2672 void ASTStmtWriter::VisitOMPDispatchDirective(OMPDispatchDirective *D) {
2673 VisitStmt(D);
2674 VisitOMPExecutableDirective(D);
2675 Record.AddSourceLocation(D->getTargetCallLoc());
2676 Code = serialization::STMT_OMP_DISPATCH_DIRECTIVE;
2679 void ASTStmtWriter::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
2680 VisitStmt(D);
2681 VisitOMPExecutableDirective(D);
2682 Code = serialization::STMT_OMP_MASKED_DIRECTIVE;
2685 void ASTStmtWriter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
2686 VisitOMPLoopDirective(D);
2687 Code = serialization::STMT_OMP_GENERIC_LOOP_DIRECTIVE;
2690 void ASTStmtWriter::VisitOMPTeamsGenericLoopDirective(
2691 OMPTeamsGenericLoopDirective *D) {
2692 VisitOMPLoopDirective(D);
2693 Code = serialization::STMT_OMP_TEAMS_GENERIC_LOOP_DIRECTIVE;
2696 void ASTStmtWriter::VisitOMPTargetTeamsGenericLoopDirective(
2697 OMPTargetTeamsGenericLoopDirective *D) {
2698 VisitOMPLoopDirective(D);
2699 Code = serialization::STMT_OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE;
2702 void ASTStmtWriter::VisitOMPParallelGenericLoopDirective(
2703 OMPParallelGenericLoopDirective *D) {
2704 VisitOMPLoopDirective(D);
2705 Code = serialization::STMT_OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE;
2708 void ASTStmtWriter::VisitOMPTargetParallelGenericLoopDirective(
2709 OMPTargetParallelGenericLoopDirective *D) {
2710 VisitOMPLoopDirective(D);
2711 Code = serialization::STMT_OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE;
2714 //===----------------------------------------------------------------------===//
2715 // ASTWriter Implementation
2716 //===----------------------------------------------------------------------===//
2718 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2719 assert(!SwitchCaseIDs.contains(S) && "SwitchCase recorded twice");
2720 unsigned NextID = SwitchCaseIDs.size();
2721 SwitchCaseIDs[S] = NextID;
2722 return NextID;
2725 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2726 assert(SwitchCaseIDs.contains(S) && "SwitchCase hasn't been seen yet");
2727 return SwitchCaseIDs[S];
2730 void ASTWriter::ClearSwitchCaseIDs() {
2731 SwitchCaseIDs.clear();
2734 /// Write the given substatement or subexpression to the
2735 /// bitstream.
2736 void ASTWriter::WriteSubStmt(Stmt *S) {
2737 RecordData Record;
2738 ASTStmtWriter Writer(*this, Record);
2739 ++NumStatements;
2741 if (!S) {
2742 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2743 return;
2746 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2747 if (I != SubStmtEntries.end()) {
2748 Record.push_back(I->second);
2749 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2750 return;
2753 #ifndef NDEBUG
2754 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2756 struct ParentStmtInserterRAII {
2757 Stmt *S;
2758 llvm::DenseSet<Stmt *> &ParentStmts;
2760 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2761 : S(S), ParentStmts(ParentStmts) {
2762 ParentStmts.insert(S);
2764 ~ParentStmtInserterRAII() {
2765 ParentStmts.erase(S);
2769 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2770 #endif
2772 Writer.Visit(S);
2774 uint64_t Offset = Writer.Emit();
2775 SubStmtEntries[S] = Offset;
2778 /// Flush all of the statements that have been added to the
2779 /// queue via AddStmt().
2780 void ASTRecordWriter::FlushStmts() {
2781 // We expect to be the only consumer of the two temporary statement maps,
2782 // assert that they are empty.
2783 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2784 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2786 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2787 Writer->WriteSubStmt(StmtsToEmit[I]);
2789 assert(N == StmtsToEmit.size() && "record modified while being written!");
2791 // Note that we are at the end of a full expression. Any
2792 // expression records that follow this one are part of a different
2793 // expression.
2794 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2796 Writer->SubStmtEntries.clear();
2797 Writer->ParentStmts.clear();
2800 StmtsToEmit.clear();
2803 void ASTRecordWriter::FlushSubStmts() {
2804 // For a nested statement, write out the substatements in reverse order (so
2805 // that a simple stack machine can be used when loading), and don't emit a
2806 // STMT_STOP after each one.
2807 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2808 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
2809 assert(N == StmtsToEmit.size() && "record modified while being written!");
2812 StmtsToEmit.clear();