1 //===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// Implements serialization for Statements and Expressions.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Serialization/ASTRecordWriter.h"
15 #include "clang/Sema/DeclSpec.h"
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/DeclTemplate.h"
20 #include "clang/AST/StmtVisitor.h"
21 #include "clang/Lex/Token.h"
22 #include "llvm/Bitstream/BitstreamWriter.h"
23 using namespace clang;
25 //===----------------------------------------------------------------------===//
26 // Statement/expression serialization
27 //===----------------------------------------------------------------------===//
31 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
33 ASTRecordWriter Record;
35 serialization::StmtCode Code;
39 ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
40 : Writer(Writer), Record(Writer, Record),
41 Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
43 ASTStmtWriter(const ASTStmtWriter&) = delete;
46 assert(Code != serialization::STMT_NULL_PTR &&
47 "unhandled sub-statement writing AST file");
48 return Record.EmitStmt(Code, AbbrevToUse);
51 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo,
52 const TemplateArgumentLoc *Args);
54 void VisitStmt(Stmt *S);
55 #define STMT(Type, Base) \
56 void Visit##Type(Type *);
57 #include "clang/AST/StmtNodes.inc"
61 void ASTStmtWriter::AddTemplateKWAndArgsInfo(
62 const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) {
63 Record.AddSourceLocation(ArgInfo.TemplateKWLoc);
64 Record.AddSourceLocation(ArgInfo.LAngleLoc);
65 Record.AddSourceLocation(ArgInfo.RAngleLoc);
66 for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i)
67 Record.AddTemplateArgumentLoc(Args[i]);
70 void ASTStmtWriter::VisitStmt(Stmt *S) {
71 Record.push_back(S->StmtBits.IsOMPStructuredBlock);
74 void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
76 Record.AddSourceLocation(S->getSemiLoc());
77 Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro);
78 Code = serialization::STMT_NULL;
81 void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
83 Record.push_back(S->size());
84 for (auto *CS : S->body())
86 Record.AddSourceLocation(S->getLBracLoc());
87 Record.AddSourceLocation(S->getRBracLoc());
88 Code = serialization::STMT_COMPOUND;
91 void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
93 Record.push_back(Writer.getSwitchCaseID(S));
94 Record.AddSourceLocation(S->getKeywordLoc());
95 Record.AddSourceLocation(S->getColonLoc());
98 void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
100 Record.push_back(S->caseStmtIsGNURange());
101 Record.AddStmt(S->getLHS());
102 Record.AddStmt(S->getSubStmt());
103 if (S->caseStmtIsGNURange()) {
104 Record.AddStmt(S->getRHS());
105 Record.AddSourceLocation(S->getEllipsisLoc());
107 Code = serialization::STMT_CASE;
110 void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
112 Record.AddStmt(S->getSubStmt());
113 Code = serialization::STMT_DEFAULT;
116 void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
118 Record.AddDeclRef(S->getDecl());
119 Record.AddStmt(S->getSubStmt());
120 Record.AddSourceLocation(S->getIdentLoc());
121 Code = serialization::STMT_LABEL;
124 void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
126 Record.push_back(S->getAttrs().size());
127 Record.AddAttributes(S->getAttrs());
128 Record.AddStmt(S->getSubStmt());
129 Record.AddSourceLocation(S->getAttrLoc());
130 Code = serialization::STMT_ATTRIBUTED;
133 void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
136 bool HasElse = S->getElse() != nullptr;
137 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
138 bool HasInit = S->getInit() != nullptr;
140 Record.push_back(S->isConstexpr());
141 Record.push_back(HasElse);
142 Record.push_back(HasVar);
143 Record.push_back(HasInit);
145 Record.AddStmt(S->getCond());
146 Record.AddStmt(S->getThen());
148 Record.AddStmt(S->getElse());
150 Record.AddDeclRef(S->getConditionVariable());
152 Record.AddStmt(S->getInit());
154 Record.AddSourceLocation(S->getIfLoc());
156 Record.AddSourceLocation(S->getElseLoc());
158 Code = serialization::STMT_IF;
161 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
164 bool HasInit = S->getInit() != nullptr;
165 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
166 Record.push_back(HasInit);
167 Record.push_back(HasVar);
168 Record.push_back(S->isAllEnumCasesCovered());
170 Record.AddStmt(S->getCond());
171 Record.AddStmt(S->getBody());
173 Record.AddStmt(S->getInit());
175 Record.AddDeclRef(S->getConditionVariable());
177 Record.AddSourceLocation(S->getSwitchLoc());
179 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
180 SC = SC->getNextSwitchCase())
181 Record.push_back(Writer.RecordSwitchCaseID(SC));
182 Code = serialization::STMT_SWITCH;
185 void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
188 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
189 Record.push_back(HasVar);
191 Record.AddStmt(S->getCond());
192 Record.AddStmt(S->getBody());
194 Record.AddDeclRef(S->getConditionVariable());
196 Record.AddSourceLocation(S->getWhileLoc());
197 Code = serialization::STMT_WHILE;
200 void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
202 Record.AddStmt(S->getCond());
203 Record.AddStmt(S->getBody());
204 Record.AddSourceLocation(S->getDoLoc());
205 Record.AddSourceLocation(S->getWhileLoc());
206 Record.AddSourceLocation(S->getRParenLoc());
207 Code = serialization::STMT_DO;
210 void ASTStmtWriter::VisitForStmt(ForStmt *S) {
212 Record.AddStmt(S->getInit());
213 Record.AddStmt(S->getCond());
214 Record.AddDeclRef(S->getConditionVariable());
215 Record.AddStmt(S->getInc());
216 Record.AddStmt(S->getBody());
217 Record.AddSourceLocation(S->getForLoc());
218 Record.AddSourceLocation(S->getLParenLoc());
219 Record.AddSourceLocation(S->getRParenLoc());
220 Code = serialization::STMT_FOR;
223 void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
225 Record.AddDeclRef(S->getLabel());
226 Record.AddSourceLocation(S->getGotoLoc());
227 Record.AddSourceLocation(S->getLabelLoc());
228 Code = serialization::STMT_GOTO;
231 void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
233 Record.AddSourceLocation(S->getGotoLoc());
234 Record.AddSourceLocation(S->getStarLoc());
235 Record.AddStmt(S->getTarget());
236 Code = serialization::STMT_INDIRECT_GOTO;
239 void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
241 Record.AddSourceLocation(S->getContinueLoc());
242 Code = serialization::STMT_CONTINUE;
245 void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
247 Record.AddSourceLocation(S->getBreakLoc());
248 Code = serialization::STMT_BREAK;
251 void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
254 bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr;
255 Record.push_back(HasNRVOCandidate);
257 Record.AddStmt(S->getRetValue());
258 if (HasNRVOCandidate)
259 Record.AddDeclRef(S->getNRVOCandidate());
261 Record.AddSourceLocation(S->getReturnLoc());
262 Code = serialization::STMT_RETURN;
265 void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
267 Record.AddSourceLocation(S->getBeginLoc());
268 Record.AddSourceLocation(S->getEndLoc());
269 DeclGroupRef DG = S->getDeclGroup();
270 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
271 Record.AddDeclRef(*D);
272 Code = serialization::STMT_DECL;
275 void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
277 Record.push_back(S->getNumOutputs());
278 Record.push_back(S->getNumInputs());
279 Record.push_back(S->getNumClobbers());
280 Record.AddSourceLocation(S->getAsmLoc());
281 Record.push_back(S->isVolatile());
282 Record.push_back(S->isSimple());
285 void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
287 Record.push_back(S->getNumLabels());
288 Record.AddSourceLocation(S->getRParenLoc());
289 Record.AddStmt(S->getAsmString());
292 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
293 Record.AddIdentifierRef(S->getOutputIdentifier(I));
294 Record.AddStmt(S->getOutputConstraintLiteral(I));
295 Record.AddStmt(S->getOutputExpr(I));
299 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
300 Record.AddIdentifierRef(S->getInputIdentifier(I));
301 Record.AddStmt(S->getInputConstraintLiteral(I));
302 Record.AddStmt(S->getInputExpr(I));
306 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
307 Record.AddStmt(S->getClobberStringLiteral(I));
310 for (auto *E : S->labels()) Record.AddStmt(E);
312 Code = serialization::STMT_GCCASM;
315 void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
317 Record.AddSourceLocation(S->getLBraceLoc());
318 Record.AddSourceLocation(S->getEndLoc());
319 Record.push_back(S->getNumAsmToks());
320 Record.AddString(S->getAsmString());
323 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
324 // FIXME: Move this to ASTRecordWriter?
325 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
329 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
330 Record.AddString(S->getClobber(I));
334 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
335 Record.AddStmt(S->getOutputExpr(I));
336 Record.AddString(S->getOutputConstraint(I));
340 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
341 Record.AddStmt(S->getInputExpr(I));
342 Record.AddString(S->getInputConstraint(I));
345 Code = serialization::STMT_MSASM;
348 void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
350 Record.push_back(CoroStmt->getParamMoves().size());
351 for (Stmt *S : CoroStmt->children())
353 Code = serialization::STMT_COROUTINE_BODY;
356 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
358 Record.AddSourceLocation(S->getKeywordLoc());
359 Record.AddStmt(S->getOperand());
360 Record.AddStmt(S->getPromiseCall());
361 Record.push_back(S->isImplicit());
362 Code = serialization::STMT_CORETURN;
365 void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
367 Record.AddSourceLocation(E->getKeywordLoc());
368 for (Stmt *S : E->children())
370 Record.AddStmt(E->getOpaqueValue());
373 void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
374 VisitCoroutineSuspendExpr(E);
375 Record.push_back(E->isImplicit());
376 Code = serialization::EXPR_COAWAIT;
379 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
380 VisitCoroutineSuspendExpr(E);
381 Code = serialization::EXPR_COYIELD;
384 void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
386 Record.AddSourceLocation(E->getKeywordLoc());
387 for (Stmt *S : E->children())
389 Code = serialization::EXPR_DEPENDENT_COAWAIT;
393 addConstraintSatisfaction(ASTRecordWriter &Record,
394 const ASTConstraintSatisfaction &Satisfaction) {
395 Record.push_back(Satisfaction.IsSatisfied);
396 if (!Satisfaction.IsSatisfied) {
397 Record.push_back(Satisfaction.NumRecords);
398 for (const auto &DetailRecord : Satisfaction) {
399 Record.AddStmt(const_cast<Expr *>(DetailRecord.first));
400 auto *E = DetailRecord.second.dyn_cast<Expr *>();
401 Record.push_back(E == nullptr);
405 auto *Diag = DetailRecord.second.get<std::pair<SourceLocation,
407 Record.AddSourceLocation(Diag->first);
408 Record.AddString(Diag->second);
415 addSubstitutionDiagnostic(
416 ASTRecordWriter &Record,
417 const concepts::Requirement::SubstitutionDiagnostic *D) {
418 Record.AddString(D->SubstitutedEntity);
419 Record.AddSourceLocation(D->DiagLoc);
420 Record.AddString(D->DiagMessage);
423 void ASTStmtWriter::VisitConceptSpecializationExpr(
424 ConceptSpecializationExpr *E) {
426 ArrayRef<TemplateArgument> TemplateArgs = E->getTemplateArguments();
427 Record.push_back(TemplateArgs.size());
428 Record.AddNestedNameSpecifierLoc(E->getNestedNameSpecifierLoc());
429 Record.AddSourceLocation(E->getTemplateKWLoc());
430 Record.AddDeclarationNameInfo(E->getConceptNameInfo());
431 Record.AddDeclRef(E->getNamedConcept());
432 Record.AddDeclRef(E->getFoundDecl());
433 Record.AddASTTemplateArgumentListInfo(E->getTemplateArgsAsWritten());
434 for (const TemplateArgument &Arg : TemplateArgs)
435 Record.AddTemplateArgument(Arg);
436 if (!E->isValueDependent())
437 addConstraintSatisfaction(Record, E->getSatisfaction());
439 Code = serialization::EXPR_CONCEPT_SPECIALIZATION;
442 void ASTStmtWriter::VisitRequiresExpr(RequiresExpr *E) {
444 Record.push_back(E->getLocalParameters().size());
445 Record.push_back(E->getRequirements().size());
446 Record.AddSourceLocation(E->RequiresExprBits.RequiresKWLoc);
447 Record.push_back(E->RequiresExprBits.IsSatisfied);
448 Record.AddDeclRef(E->getBody());
449 for (ParmVarDecl *P : E->getLocalParameters())
450 Record.AddDeclRef(P);
451 for (concepts::Requirement *R : E->getRequirements()) {
452 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(R)) {
453 Record.push_back(concepts::Requirement::RK_Type);
454 Record.push_back(TypeReq->Status);
455 if (TypeReq->Status == concepts::TypeRequirement::SS_SubstitutionFailure)
456 addSubstitutionDiagnostic(Record, TypeReq->getSubstitutionDiagnostic());
458 Record.AddTypeSourceInfo(TypeReq->getType());
459 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(R)) {
460 Record.push_back(ExprReq->getKind());
461 Record.push_back(ExprReq->Status);
462 if (ExprReq->isExprSubstitutionFailure()) {
463 addSubstitutionDiagnostic(Record,
464 ExprReq->Value.get<concepts::Requirement::SubstitutionDiagnostic *>());
466 Record.AddStmt(ExprReq->Value.get<Expr *>());
467 if (ExprReq->getKind() == concepts::Requirement::RK_Compound) {
468 Record.AddSourceLocation(ExprReq->NoexceptLoc);
469 const auto &RetReq = ExprReq->getReturnTypeRequirement();
470 if (RetReq.isSubstitutionFailure()) {
472 addSubstitutionDiagnostic(Record, RetReq.getSubstitutionDiagnostic());
473 } else if (RetReq.isTypeConstraint()) {
475 Record.AddTemplateParameterList(
476 RetReq.getTypeConstraintTemplateParameterList());
477 if (ExprReq->Status >=
478 concepts::ExprRequirement::SS_ConstraintsNotSatisfied)
480 ExprReq->getReturnTypeRequirementSubstitutedConstraintExpr());
482 assert(RetReq.isEmpty());
487 auto *NestedReq = cast<concepts::NestedRequirement>(R);
488 Record.push_back(concepts::Requirement::RK_Nested);
489 Record.push_back(NestedReq->isSubstitutionFailure());
490 if (NestedReq->isSubstitutionFailure()){
491 addSubstitutionDiagnostic(Record,
492 NestedReq->getSubstitutionDiagnostic());
494 Record.AddStmt(NestedReq->Value.get<Expr *>());
495 if (!NestedReq->isDependent())
496 addConstraintSatisfaction(Record, *NestedReq->Satisfaction);
500 Record.AddSourceLocation(E->getEndLoc());
502 Code = serialization::EXPR_REQUIRES;
506 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
509 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
511 // CapturedDecl and captured region kind
512 Record.AddDeclRef(S->getCapturedDecl());
513 Record.push_back(S->getCapturedRegionKind());
515 Record.AddDeclRef(S->getCapturedRecordDecl());
518 for (auto *I : S->capture_inits())
522 Record.AddStmt(S->getCapturedStmt());
525 for (const auto &I : S->captures()) {
526 if (I.capturesThis() || I.capturesVariableArrayType())
527 Record.AddDeclRef(nullptr);
529 Record.AddDeclRef(I.getCapturedVar());
530 Record.push_back(I.getCaptureKind());
531 Record.AddSourceLocation(I.getLocation());
534 Code = serialization::STMT_CAPTURED;
537 void ASTStmtWriter::VisitExpr(Expr *E) {
539 Record.AddTypeRef(E->getType());
540 Record.push_back(E->isTypeDependent());
541 Record.push_back(E->isValueDependent());
542 Record.push_back(E->isInstantiationDependent());
543 Record.push_back(E->containsUnexpandedParameterPack());
544 Record.push_back(E->getValueKind());
545 Record.push_back(E->getObjectKind());
548 void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
550 Record.push_back(static_cast<uint64_t>(E->ConstantExprBits.ResultKind));
551 switch (E->ConstantExprBits.ResultKind) {
552 case ConstantExpr::RSK_Int64:
553 Record.push_back(E->Int64Result());
554 Record.push_back(E->ConstantExprBits.IsUnsigned |
555 E->ConstantExprBits.BitWidth << 1);
557 case ConstantExpr::RSK_APValue:
558 Record.AddAPValue(E->APValueResult());
560 Record.AddStmt(E->getSubExpr());
561 Code = serialization::EXPR_CONSTANT;
564 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
567 bool HasFunctionName = E->getFunctionName() != nullptr;
568 Record.push_back(HasFunctionName);
569 Record.push_back(E->getIdentKind()); // FIXME: stable encoding
570 Record.AddSourceLocation(E->getLocation());
572 Record.AddStmt(E->getFunctionName());
573 Code = serialization::EXPR_PREDEFINED;
576 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
579 Record.push_back(E->hasQualifier());
580 Record.push_back(E->getDecl() != E->getFoundDecl());
581 Record.push_back(E->hasTemplateKWAndArgsInfo());
582 Record.push_back(E->hadMultipleCandidates());
583 Record.push_back(E->refersToEnclosingVariableOrCapture());
584 Record.push_back(E->isNonOdrUse());
586 if (E->hasTemplateKWAndArgsInfo()) {
587 unsigned NumTemplateArgs = E->getNumTemplateArgs();
588 Record.push_back(NumTemplateArgs);
591 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
593 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
594 (E->getDecl() == E->getFoundDecl()) &&
595 nk == DeclarationName::Identifier &&
596 !E->refersToEnclosingVariableOrCapture() && !E->isNonOdrUse()) {
597 AbbrevToUse = Writer.getDeclRefExprAbbrev();
600 if (E->hasQualifier())
601 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
603 if (E->getDecl() != E->getFoundDecl())
604 Record.AddDeclRef(E->getFoundDecl());
606 if (E->hasTemplateKWAndArgsInfo())
607 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
608 E->getTrailingObjects<TemplateArgumentLoc>());
610 Record.AddDeclRef(E->getDecl());
611 Record.AddSourceLocation(E->getLocation());
612 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
613 Code = serialization::EXPR_DECL_REF;
616 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
618 Record.AddSourceLocation(E->getLocation());
619 Record.AddAPInt(E->getValue());
621 if (E->getValue().getBitWidth() == 32) {
622 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
625 Code = serialization::EXPR_INTEGER_LITERAL;
628 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
630 Record.AddSourceLocation(E->getLocation());
631 Record.AddAPInt(E->getValue());
632 Code = serialization::EXPR_INTEGER_LITERAL;
635 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
637 Record.push_back(E->getRawSemantics());
638 Record.push_back(E->isExact());
639 Record.AddAPFloat(E->getValue());
640 Record.AddSourceLocation(E->getLocation());
641 Code = serialization::EXPR_FLOATING_LITERAL;
644 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
646 Record.AddStmt(E->getSubExpr());
647 Code = serialization::EXPR_IMAGINARY_LITERAL;
650 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
653 // Store the various bits of data of StringLiteral.
654 Record.push_back(E->getNumConcatenated());
655 Record.push_back(E->getLength());
656 Record.push_back(E->getCharByteWidth());
657 Record.push_back(E->getKind());
658 Record.push_back(E->isPascal());
660 // Store the trailing array of SourceLocation.
661 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
662 Record.AddSourceLocation(E->getStrTokenLoc(I));
664 // Store the trailing array of char holding the string data.
665 StringRef StrData = E->getBytes();
666 for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
667 Record.push_back(StrData[I]);
669 Code = serialization::EXPR_STRING_LITERAL;
672 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
674 Record.push_back(E->getValue());
675 Record.AddSourceLocation(E->getLocation());
676 Record.push_back(E->getKind());
678 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
680 Code = serialization::EXPR_CHARACTER_LITERAL;
683 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
685 Record.AddSourceLocation(E->getLParen());
686 Record.AddSourceLocation(E->getRParen());
687 Record.AddStmt(E->getSubExpr());
688 Code = serialization::EXPR_PAREN;
691 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
693 Record.push_back(E->getNumExprs());
694 for (auto *SubStmt : E->exprs())
695 Record.AddStmt(SubStmt);
696 Record.AddSourceLocation(E->getLParenLoc());
697 Record.AddSourceLocation(E->getRParenLoc());
698 Code = serialization::EXPR_PAREN_LIST;
701 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
703 Record.AddStmt(E->getSubExpr());
704 Record.push_back(E->getOpcode()); // FIXME: stable encoding
705 Record.AddSourceLocation(E->getOperatorLoc());
706 Record.push_back(E->canOverflow());
707 Code = serialization::EXPR_UNARY_OPERATOR;
710 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
712 Record.push_back(E->getNumComponents());
713 Record.push_back(E->getNumExpressions());
714 Record.AddSourceLocation(E->getOperatorLoc());
715 Record.AddSourceLocation(E->getRParenLoc());
716 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
717 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
718 const OffsetOfNode &ON = E->getComponent(I);
719 Record.push_back(ON.getKind()); // FIXME: Stable encoding
720 Record.AddSourceLocation(ON.getSourceRange().getBegin());
721 Record.AddSourceLocation(ON.getSourceRange().getEnd());
722 switch (ON.getKind()) {
723 case OffsetOfNode::Array:
724 Record.push_back(ON.getArrayExprIndex());
727 case OffsetOfNode::Field:
728 Record.AddDeclRef(ON.getField());
731 case OffsetOfNode::Identifier:
732 Record.AddIdentifierRef(ON.getFieldName());
735 case OffsetOfNode::Base:
736 Record.AddCXXBaseSpecifier(*ON.getBase());
740 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
741 Record.AddStmt(E->getIndexExpr(I));
742 Code = serialization::EXPR_OFFSETOF;
745 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
747 Record.push_back(E->getKind());
748 if (E->isArgumentType())
749 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
752 Record.AddStmt(E->getArgumentExpr());
754 Record.AddSourceLocation(E->getOperatorLoc());
755 Record.AddSourceLocation(E->getRParenLoc());
756 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
759 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
761 Record.AddStmt(E->getLHS());
762 Record.AddStmt(E->getRHS());
763 Record.AddSourceLocation(E->getRBracketLoc());
764 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
767 void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
769 Record.AddStmt(E->getBase());
770 Record.AddStmt(E->getLowerBound());
771 Record.AddStmt(E->getLength());
772 Record.AddSourceLocation(E->getColonLoc());
773 Record.AddSourceLocation(E->getRBracketLoc());
774 Code = serialization::EXPR_OMP_ARRAY_SECTION;
777 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
779 Record.push_back(E->getNumArgs());
780 Record.AddSourceLocation(E->getRParenLoc());
781 Record.AddStmt(E->getCallee());
782 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
783 Arg != ArgEnd; ++Arg)
784 Record.AddStmt(*Arg);
785 Record.push_back(static_cast<unsigned>(E->getADLCallKind()));
786 Code = serialization::EXPR_CALL;
789 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
792 bool HasQualifier = E->hasQualifier();
794 E->hasQualifierOrFoundDecl() &&
795 (E->getFoundDecl().getDecl() != E->getMemberDecl() ||
796 E->getFoundDecl().getAccess() != E->getMemberDecl()->getAccess());
797 bool HasTemplateInfo = E->hasTemplateKWAndArgsInfo();
798 unsigned NumTemplateArgs = E->getNumTemplateArgs();
800 // Write these first for easy access when deserializing, as they affect the
801 // size of the MemberExpr.
802 Record.push_back(HasQualifier);
803 Record.push_back(HasFoundDecl);
804 Record.push_back(HasTemplateInfo);
805 Record.push_back(NumTemplateArgs);
807 Record.AddStmt(E->getBase());
808 Record.AddDeclRef(E->getMemberDecl());
809 Record.AddDeclarationNameLoc(E->MemberDNLoc,
810 E->getMemberDecl()->getDeclName());
811 Record.AddSourceLocation(E->getMemberLoc());
812 Record.push_back(E->isArrow());
813 Record.push_back(E->hadMultipleCandidates());
814 Record.push_back(E->isNonOdrUse());
815 Record.AddSourceLocation(E->getOperatorLoc());
818 DeclAccessPair FoundDecl = E->getFoundDecl();
819 Record.AddDeclRef(FoundDecl.getDecl());
820 Record.push_back(FoundDecl.getAccess());
824 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
827 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
828 E->getTrailingObjects<TemplateArgumentLoc>());
830 Code = serialization::EXPR_MEMBER;
833 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
835 Record.AddStmt(E->getBase());
836 Record.AddSourceLocation(E->getIsaMemberLoc());
837 Record.AddSourceLocation(E->getOpLoc());
838 Record.push_back(E->isArrow());
839 Code = serialization::EXPR_OBJC_ISA;
843 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
845 Record.AddStmt(E->getSubExpr());
846 Record.push_back(E->shouldCopy());
847 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
850 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
851 VisitExplicitCastExpr(E);
852 Record.AddSourceLocation(E->getLParenLoc());
853 Record.AddSourceLocation(E->getBridgeKeywordLoc());
854 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
855 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
858 void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
860 Record.push_back(E->path_size());
861 Record.AddStmt(E->getSubExpr());
862 Record.push_back(E->getCastKind()); // FIXME: stable encoding
864 for (CastExpr::path_iterator
865 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
866 Record.AddCXXBaseSpecifier(**PI);
869 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
871 Record.AddStmt(E->getLHS());
872 Record.AddStmt(E->getRHS());
873 Record.push_back(E->getOpcode()); // FIXME: stable encoding
874 Record.AddSourceLocation(E->getOperatorLoc());
875 Record.push_back(E->getFPFeatures().getInt());
876 Code = serialization::EXPR_BINARY_OPERATOR;
879 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
880 VisitBinaryOperator(E);
881 Record.AddTypeRef(E->getComputationLHSType());
882 Record.AddTypeRef(E->getComputationResultType());
883 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
886 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
888 Record.AddStmt(E->getCond());
889 Record.AddStmt(E->getLHS());
890 Record.AddStmt(E->getRHS());
891 Record.AddSourceLocation(E->getQuestionLoc());
892 Record.AddSourceLocation(E->getColonLoc());
893 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
897 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
899 Record.AddStmt(E->getOpaqueValue());
900 Record.AddStmt(E->getCommon());
901 Record.AddStmt(E->getCond());
902 Record.AddStmt(E->getTrueExpr());
903 Record.AddStmt(E->getFalseExpr());
904 Record.AddSourceLocation(E->getQuestionLoc());
905 Record.AddSourceLocation(E->getColonLoc());
906 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
909 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
911 Record.push_back(E->isPartOfExplicitCast());
913 if (E->path_size() == 0)
914 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
916 Code = serialization::EXPR_IMPLICIT_CAST;
919 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
921 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
924 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
925 VisitExplicitCastExpr(E);
926 Record.AddSourceLocation(E->getLParenLoc());
927 Record.AddSourceLocation(E->getRParenLoc());
928 Code = serialization::EXPR_CSTYLE_CAST;
931 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
933 Record.AddSourceLocation(E->getLParenLoc());
934 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
935 Record.AddStmt(E->getInitializer());
936 Record.push_back(E->isFileScope());
937 Code = serialization::EXPR_COMPOUND_LITERAL;
940 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
942 Record.AddStmt(E->getBase());
943 Record.AddIdentifierRef(&E->getAccessor());
944 Record.AddSourceLocation(E->getAccessorLoc());
945 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
948 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
950 // NOTE: only add the (possibly null) syntactic form.
951 // No need to serialize the isSemanticForm flag and the semantic form.
952 Record.AddStmt(E->getSyntacticForm());
953 Record.AddSourceLocation(E->getLBraceLoc());
954 Record.AddSourceLocation(E->getRBraceLoc());
955 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
956 Record.push_back(isArrayFiller);
958 Record.AddStmt(E->getArrayFiller());
960 Record.AddDeclRef(E->getInitializedFieldInUnion());
961 Record.push_back(E->hadArrayRangeDesignator());
962 Record.push_back(E->getNumInits());
964 // ArrayFiller may have filled "holes" due to designated initializer.
965 // Replace them by 0 to indicate that the filler goes in that place.
966 Expr *filler = E->getArrayFiller();
967 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
968 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
970 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
971 Record.AddStmt(E->getInit(I));
973 Code = serialization::EXPR_INIT_LIST;
976 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
978 Record.push_back(E->getNumSubExprs());
979 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
980 Record.AddStmt(E->getSubExpr(I));
981 Record.AddSourceLocation(E->getEqualOrColonLoc());
982 Record.push_back(E->usesGNUSyntax());
983 for (const DesignatedInitExpr::Designator &D : E->designators()) {
984 if (D.isFieldDesignator()) {
985 if (FieldDecl *Field = D.getField()) {
986 Record.push_back(serialization::DESIG_FIELD_DECL);
987 Record.AddDeclRef(Field);
989 Record.push_back(serialization::DESIG_FIELD_NAME);
990 Record.AddIdentifierRef(D.getFieldName());
992 Record.AddSourceLocation(D.getDotLoc());
993 Record.AddSourceLocation(D.getFieldLoc());
994 } else if (D.isArrayDesignator()) {
995 Record.push_back(serialization::DESIG_ARRAY);
996 Record.push_back(D.getFirstExprIndex());
997 Record.AddSourceLocation(D.getLBracketLoc());
998 Record.AddSourceLocation(D.getRBracketLoc());
1000 assert(D.isArrayRangeDesignator() && "Unknown designator");
1001 Record.push_back(serialization::DESIG_ARRAY_RANGE);
1002 Record.push_back(D.getFirstExprIndex());
1003 Record.AddSourceLocation(D.getLBracketLoc());
1004 Record.AddSourceLocation(D.getEllipsisLoc());
1005 Record.AddSourceLocation(D.getRBracketLoc());
1008 Code = serialization::EXPR_DESIGNATED_INIT;
1011 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
1013 Record.AddStmt(E->getBase());
1014 Record.AddStmt(E->getUpdater());
1015 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
1018 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
1020 Code = serialization::EXPR_NO_INIT;
1023 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
1025 Record.AddStmt(E->SubExprs[0]);
1026 Record.AddStmt(E->SubExprs[1]);
1027 Code = serialization::EXPR_ARRAY_INIT_LOOP;
1030 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
1032 Code = serialization::EXPR_ARRAY_INIT_INDEX;
1035 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
1037 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
1040 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
1042 Record.AddStmt(E->getSubExpr());
1043 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
1044 Record.AddSourceLocation(E->getBuiltinLoc());
1045 Record.AddSourceLocation(E->getRParenLoc());
1046 Record.push_back(E->isMicrosoftABI());
1047 Code = serialization::EXPR_VA_ARG;
1050 void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) {
1052 Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext()));
1053 Record.AddSourceLocation(E->getBeginLoc());
1054 Record.AddSourceLocation(E->getEndLoc());
1055 Record.push_back(E->getIdentKind());
1056 Code = serialization::EXPR_SOURCE_LOC;
1059 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
1061 Record.AddSourceLocation(E->getAmpAmpLoc());
1062 Record.AddSourceLocation(E->getLabelLoc());
1063 Record.AddDeclRef(E->getLabel());
1064 Code = serialization::EXPR_ADDR_LABEL;
1067 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
1069 Record.AddStmt(E->getSubStmt());
1070 Record.AddSourceLocation(E->getLParenLoc());
1071 Record.AddSourceLocation(E->getRParenLoc());
1072 Record.push_back(E->getTemplateDepth());
1073 Code = serialization::EXPR_STMT;
1076 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
1078 Record.AddStmt(E->getCond());
1079 Record.AddStmt(E->getLHS());
1080 Record.AddStmt(E->getRHS());
1081 Record.AddSourceLocation(E->getBuiltinLoc());
1082 Record.AddSourceLocation(E->getRParenLoc());
1083 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
1084 Code = serialization::EXPR_CHOOSE;
1087 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
1089 Record.AddSourceLocation(E->getTokenLocation());
1090 Code = serialization::EXPR_GNU_NULL;
1093 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
1095 Record.push_back(E->getNumSubExprs());
1096 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1097 Record.AddStmt(E->getExpr(I));
1098 Record.AddSourceLocation(E->getBuiltinLoc());
1099 Record.AddSourceLocation(E->getRParenLoc());
1100 Code = serialization::EXPR_SHUFFLE_VECTOR;
1103 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
1105 Record.AddSourceLocation(E->getBuiltinLoc());
1106 Record.AddSourceLocation(E->getRParenLoc());
1107 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1108 Record.AddStmt(E->getSrcExpr());
1109 Code = serialization::EXPR_CONVERT_VECTOR;
1112 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
1114 Record.AddDeclRef(E->getBlockDecl());
1115 Code = serialization::EXPR_BLOCK;
1118 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
1121 Record.push_back(E->getNumAssocs());
1122 Record.push_back(E->ResultIndex);
1123 Record.AddSourceLocation(E->getGenericLoc());
1124 Record.AddSourceLocation(E->getDefaultLoc());
1125 Record.AddSourceLocation(E->getRParenLoc());
1127 Stmt **Stmts = E->getTrailingObjects<Stmt *>();
1128 // Add 1 to account for the controlling expression which is the first
1129 // expression in the trailing array of Stmt *. This is not needed for
1130 // the trailing array of TypeSourceInfo *.
1131 for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I)
1132 Record.AddStmt(Stmts[I]);
1134 TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
1135 for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I)
1136 Record.AddTypeSourceInfo(TSIs[I]);
1138 Code = serialization::EXPR_GENERIC_SELECTION;
1141 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
1143 Record.push_back(E->getNumSemanticExprs());
1145 // Push the result index. Currently, this needs to exactly match
1146 // the encoding used internally for ResultIndex.
1147 unsigned result = E->getResultExprIndex();
1148 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
1149 Record.push_back(result);
1151 Record.AddStmt(E->getSyntacticForm());
1152 for (PseudoObjectExpr::semantics_iterator
1153 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
1156 Code = serialization::EXPR_PSEUDO_OBJECT;
1159 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
1161 Record.push_back(E->getOp());
1162 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1163 Record.AddStmt(E->getSubExprs()[I]);
1164 Record.AddSourceLocation(E->getBuiltinLoc());
1165 Record.AddSourceLocation(E->getRParenLoc());
1166 Code = serialization::EXPR_ATOMIC;
1169 //===----------------------------------------------------------------------===//
1170 // Objective-C Expressions and Statements.
1171 //===----------------------------------------------------------------------===//
1173 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
1175 Record.AddStmt(E->getString());
1176 Record.AddSourceLocation(E->getAtLoc());
1177 Code = serialization::EXPR_OBJC_STRING_LITERAL;
1180 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1182 Record.AddStmt(E->getSubExpr());
1183 Record.AddDeclRef(E->getBoxingMethod());
1184 Record.AddSourceRange(E->getSourceRange());
1185 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
1188 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1190 Record.push_back(E->getNumElements());
1191 for (unsigned i = 0; i < E->getNumElements(); i++)
1192 Record.AddStmt(E->getElement(i));
1193 Record.AddDeclRef(E->getArrayWithObjectsMethod());
1194 Record.AddSourceRange(E->getSourceRange());
1195 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1198 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1200 Record.push_back(E->getNumElements());
1201 Record.push_back(E->HasPackExpansions);
1202 for (unsigned i = 0; i < E->getNumElements(); i++) {
1203 ObjCDictionaryElement Element = E->getKeyValueElement(i);
1204 Record.AddStmt(Element.Key);
1205 Record.AddStmt(Element.Value);
1206 if (E->HasPackExpansions) {
1207 Record.AddSourceLocation(Element.EllipsisLoc);
1208 unsigned NumExpansions = 0;
1209 if (Element.NumExpansions)
1210 NumExpansions = *Element.NumExpansions + 1;
1211 Record.push_back(NumExpansions);
1215 Record.AddDeclRef(E->getDictWithObjectsMethod());
1216 Record.AddSourceRange(E->getSourceRange());
1217 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1220 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
1222 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1223 Record.AddSourceLocation(E->getAtLoc());
1224 Record.AddSourceLocation(E->getRParenLoc());
1225 Code = serialization::EXPR_OBJC_ENCODE;
1228 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
1230 Record.AddSelectorRef(E->getSelector());
1231 Record.AddSourceLocation(E->getAtLoc());
1232 Record.AddSourceLocation(E->getRParenLoc());
1233 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
1236 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
1238 Record.AddDeclRef(E->getProtocol());
1239 Record.AddSourceLocation(E->getAtLoc());
1240 Record.AddSourceLocation(E->ProtoLoc);
1241 Record.AddSourceLocation(E->getRParenLoc());
1242 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
1245 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1247 Record.AddDeclRef(E->getDecl());
1248 Record.AddSourceLocation(E->getLocation());
1249 Record.AddSourceLocation(E->getOpLoc());
1250 Record.AddStmt(E->getBase());
1251 Record.push_back(E->isArrow());
1252 Record.push_back(E->isFreeIvar());
1253 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
1256 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1258 Record.push_back(E->SetterAndMethodRefFlags.getInt());
1259 Record.push_back(E->isImplicitProperty());
1260 if (E->isImplicitProperty()) {
1261 Record.AddDeclRef(E->getImplicitPropertyGetter());
1262 Record.AddDeclRef(E->getImplicitPropertySetter());
1264 Record.AddDeclRef(E->getExplicitProperty());
1266 Record.AddSourceLocation(E->getLocation());
1267 Record.AddSourceLocation(E->getReceiverLocation());
1268 if (E->isObjectReceiver()) {
1269 Record.push_back(0);
1270 Record.AddStmt(E->getBase());
1271 } else if (E->isSuperReceiver()) {
1272 Record.push_back(1);
1273 Record.AddTypeRef(E->getSuperReceiverType());
1275 Record.push_back(2);
1276 Record.AddDeclRef(E->getClassReceiver());
1279 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
1282 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1284 Record.AddSourceLocation(E->getRBracket());
1285 Record.AddStmt(E->getBaseExpr());
1286 Record.AddStmt(E->getKeyExpr());
1287 Record.AddDeclRef(E->getAtIndexMethodDecl());
1288 Record.AddDeclRef(E->setAtIndexMethodDecl());
1290 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1293 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1295 Record.push_back(E->getNumArgs());
1296 Record.push_back(E->getNumStoredSelLocs());
1297 Record.push_back(E->SelLocsKind);
1298 Record.push_back(E->isDelegateInitCall());
1299 Record.push_back(E->IsImplicit);
1300 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1301 switch (E->getReceiverKind()) {
1302 case ObjCMessageExpr::Instance:
1303 Record.AddStmt(E->getInstanceReceiver());
1306 case ObjCMessageExpr::Class:
1307 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
1310 case ObjCMessageExpr::SuperClass:
1311 case ObjCMessageExpr::SuperInstance:
1312 Record.AddTypeRef(E->getSuperType());
1313 Record.AddSourceLocation(E->getSuperLoc());
1317 if (E->getMethodDecl()) {
1318 Record.push_back(1);
1319 Record.AddDeclRef(E->getMethodDecl());
1321 Record.push_back(0);
1322 Record.AddSelectorRef(E->getSelector());
1325 Record.AddSourceLocation(E->getLeftLoc());
1326 Record.AddSourceLocation(E->getRightLoc());
1328 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1329 Arg != ArgEnd; ++Arg)
1330 Record.AddStmt(*Arg);
1332 SourceLocation *Locs = E->getStoredSelLocs();
1333 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1334 Record.AddSourceLocation(Locs[i]);
1336 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1339 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1341 Record.AddStmt(S->getElement());
1342 Record.AddStmt(S->getCollection());
1343 Record.AddStmt(S->getBody());
1344 Record.AddSourceLocation(S->getForLoc());
1345 Record.AddSourceLocation(S->getRParenLoc());
1346 Code = serialization::STMT_OBJC_FOR_COLLECTION;
1349 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1351 Record.AddStmt(S->getCatchBody());
1352 Record.AddDeclRef(S->getCatchParamDecl());
1353 Record.AddSourceLocation(S->getAtCatchLoc());
1354 Record.AddSourceLocation(S->getRParenLoc());
1355 Code = serialization::STMT_OBJC_CATCH;
1358 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1360 Record.AddStmt(S->getFinallyBody());
1361 Record.AddSourceLocation(S->getAtFinallyLoc());
1362 Code = serialization::STMT_OBJC_FINALLY;
1365 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1366 VisitStmt(S); // FIXME: no test coverage.
1367 Record.AddStmt(S->getSubStmt());
1368 Record.AddSourceLocation(S->getAtLoc());
1369 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1372 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1374 Record.push_back(S->getNumCatchStmts());
1375 Record.push_back(S->getFinallyStmt() != nullptr);
1376 Record.AddStmt(S->getTryBody());
1377 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1378 Record.AddStmt(S->getCatchStmt(I));
1379 if (S->getFinallyStmt())
1380 Record.AddStmt(S->getFinallyStmt());
1381 Record.AddSourceLocation(S->getAtTryLoc());
1382 Code = serialization::STMT_OBJC_AT_TRY;
1385 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1386 VisitStmt(S); // FIXME: no test coverage.
1387 Record.AddStmt(S->getSynchExpr());
1388 Record.AddStmt(S->getSynchBody());
1389 Record.AddSourceLocation(S->getAtSynchronizedLoc());
1390 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1393 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1394 VisitStmt(S); // FIXME: no test coverage.
1395 Record.AddStmt(S->getThrowExpr());
1396 Record.AddSourceLocation(S->getThrowLoc());
1397 Code = serialization::STMT_OBJC_AT_THROW;
1400 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1402 Record.push_back(E->getValue());
1403 Record.AddSourceLocation(E->getLocation());
1404 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1407 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1409 Record.AddSourceRange(E->getSourceRange());
1410 Record.AddVersionTuple(E->getVersion());
1411 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1414 //===----------------------------------------------------------------------===//
1415 // C++ Expressions and Statements.
1416 //===----------------------------------------------------------------------===//
1418 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1420 Record.AddSourceLocation(S->getCatchLoc());
1421 Record.AddDeclRef(S->getExceptionDecl());
1422 Record.AddStmt(S->getHandlerBlock());
1423 Code = serialization::STMT_CXX_CATCH;
1426 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1428 Record.push_back(S->getNumHandlers());
1429 Record.AddSourceLocation(S->getTryLoc());
1430 Record.AddStmt(S->getTryBlock());
1431 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1432 Record.AddStmt(S->getHandler(i));
1433 Code = serialization::STMT_CXX_TRY;
1436 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1438 Record.AddSourceLocation(S->getForLoc());
1439 Record.AddSourceLocation(S->getCoawaitLoc());
1440 Record.AddSourceLocation(S->getColonLoc());
1441 Record.AddSourceLocation(S->getRParenLoc());
1442 Record.AddStmt(S->getInit());
1443 Record.AddStmt(S->getRangeStmt());
1444 Record.AddStmt(S->getBeginStmt());
1445 Record.AddStmt(S->getEndStmt());
1446 Record.AddStmt(S->getCond());
1447 Record.AddStmt(S->getInc());
1448 Record.AddStmt(S->getLoopVarStmt());
1449 Record.AddStmt(S->getBody());
1450 Code = serialization::STMT_CXX_FOR_RANGE;
1453 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1455 Record.AddSourceLocation(S->getKeywordLoc());
1456 Record.push_back(S->isIfExists());
1457 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1458 Record.AddDeclarationNameInfo(S->getNameInfo());
1459 Record.AddStmt(S->getSubStmt());
1460 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1463 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1465 Record.push_back(E->getOperator());
1466 Record.push_back(E->getFPFeatures().getInt());
1467 Record.AddSourceRange(E->Range);
1468 Code = serialization::EXPR_CXX_OPERATOR_CALL;
1471 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1473 Code = serialization::EXPR_CXX_MEMBER_CALL;
1476 void ASTStmtWriter::VisitCXXRewrittenBinaryOperator(
1477 CXXRewrittenBinaryOperator *E) {
1479 Record.push_back(E->isReversed());
1480 Record.AddStmt(E->getSemanticForm());
1481 Code = serialization::EXPR_CXX_REWRITTEN_BINARY_OPERATOR;
1484 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1487 Record.push_back(E->getNumArgs());
1488 Record.push_back(E->isElidable());
1489 Record.push_back(E->hadMultipleCandidates());
1490 Record.push_back(E->isListInitialization());
1491 Record.push_back(E->isStdInitListInitialization());
1492 Record.push_back(E->requiresZeroInitialization());
1493 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
1494 Record.AddSourceLocation(E->getLocation());
1495 Record.AddDeclRef(E->getConstructor());
1496 Record.AddSourceRange(E->getParenOrBraceRange());
1498 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1499 Record.AddStmt(E->getArg(I));
1501 Code = serialization::EXPR_CXX_CONSTRUCT;
1504 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1506 Record.AddDeclRef(E->getConstructor());
1507 Record.AddSourceLocation(E->getLocation());
1508 Record.push_back(E->constructsVBase());
1509 Record.push_back(E->inheritedFromVBase());
1510 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1513 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1514 VisitCXXConstructExpr(E);
1515 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1516 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1519 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1521 Record.push_back(E->NumCaptures);
1522 Record.AddSourceRange(E->IntroducerRange);
1523 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
1524 Record.AddSourceLocation(E->CaptureDefaultLoc);
1525 Record.push_back(E->ExplicitParams);
1526 Record.push_back(E->ExplicitResultType);
1527 Record.AddSourceLocation(E->ClosingBrace);
1529 // Add capture initializers.
1530 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1531 CEnd = E->capture_init_end();
1536 Code = serialization::EXPR_LAMBDA;
1539 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1541 Record.AddStmt(E->getSubExpr());
1542 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1545 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1546 VisitExplicitCastExpr(E);
1547 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1548 Record.AddSourceRange(E->getAngleBrackets());
1551 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1552 VisitCXXNamedCastExpr(E);
1553 Code = serialization::EXPR_CXX_STATIC_CAST;
1556 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1557 VisitCXXNamedCastExpr(E);
1558 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1561 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1562 VisitCXXNamedCastExpr(E);
1563 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1566 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1567 VisitCXXNamedCastExpr(E);
1568 Code = serialization::EXPR_CXX_CONST_CAST;
1571 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1572 VisitExplicitCastExpr(E);
1573 Record.AddSourceLocation(E->getLParenLoc());
1574 Record.AddSourceLocation(E->getRParenLoc());
1575 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1578 void ASTStmtWriter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
1579 VisitExplicitCastExpr(E);
1580 Record.AddSourceLocation(E->getBeginLoc());
1581 Record.AddSourceLocation(E->getEndLoc());
1584 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1586 Record.AddSourceLocation(E->UDSuffixLoc);
1587 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1590 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1592 Record.push_back(E->getValue());
1593 Record.AddSourceLocation(E->getLocation());
1594 Code = serialization::EXPR_CXX_BOOL_LITERAL;
1597 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1599 Record.AddSourceLocation(E->getLocation());
1600 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1603 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1605 Record.AddSourceRange(E->getSourceRange());
1606 if (E->isTypeOperand()) {
1607 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1608 Code = serialization::EXPR_CXX_TYPEID_TYPE;
1610 Record.AddStmt(E->getExprOperand());
1611 Code = serialization::EXPR_CXX_TYPEID_EXPR;
1615 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1617 Record.AddSourceLocation(E->getLocation());
1618 Record.push_back(E->isImplicit());
1619 Code = serialization::EXPR_CXX_THIS;
1622 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1624 Record.AddSourceLocation(E->getThrowLoc());
1625 Record.AddStmt(E->getSubExpr());
1626 Record.push_back(E->isThrownVariableInScope());
1627 Code = serialization::EXPR_CXX_THROW;
1630 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1632 Record.AddDeclRef(E->getParam());
1633 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1634 Record.AddSourceLocation(E->getUsedLocation());
1635 Code = serialization::EXPR_CXX_DEFAULT_ARG;
1638 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1640 Record.AddDeclRef(E->getField());
1641 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1642 Record.AddSourceLocation(E->getExprLoc());
1643 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1646 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1648 Record.AddCXXTemporary(E->getTemporary());
1649 Record.AddStmt(E->getSubExpr());
1650 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1653 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1655 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1656 Record.AddSourceLocation(E->getRParenLoc());
1657 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1660 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1663 Record.push_back(E->isArray());
1664 Record.push_back(E->hasInitializer());
1665 Record.push_back(E->getNumPlacementArgs());
1666 Record.push_back(E->isParenTypeId());
1668 Record.push_back(E->isGlobalNew());
1669 Record.push_back(E->passAlignment());
1670 Record.push_back(E->doesUsualArrayDeleteWantSize());
1671 Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
1673 Record.AddDeclRef(E->getOperatorNew());
1674 Record.AddDeclRef(E->getOperatorDelete());
1675 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1676 if (E->isParenTypeId())
1677 Record.AddSourceRange(E->getTypeIdParens());
1678 Record.AddSourceRange(E->getSourceRange());
1679 Record.AddSourceRange(E->getDirectInitRange());
1681 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
1685 Code = serialization::EXPR_CXX_NEW;
1688 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1690 Record.push_back(E->isGlobalDelete());
1691 Record.push_back(E->isArrayForm());
1692 Record.push_back(E->isArrayFormAsWritten());
1693 Record.push_back(E->doesUsualArrayDeleteWantSize());
1694 Record.AddDeclRef(E->getOperatorDelete());
1695 Record.AddStmt(E->getArgument());
1696 Record.AddSourceLocation(E->getBeginLoc());
1698 Code = serialization::EXPR_CXX_DELETE;
1701 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1704 Record.AddStmt(E->getBase());
1705 Record.push_back(E->isArrow());
1706 Record.AddSourceLocation(E->getOperatorLoc());
1707 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1708 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1709 Record.AddSourceLocation(E->getColonColonLoc());
1710 Record.AddSourceLocation(E->getTildeLoc());
1712 // PseudoDestructorTypeStorage.
1713 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
1714 if (E->getDestroyedTypeIdentifier())
1715 Record.AddSourceLocation(E->getDestroyedTypeLoc());
1717 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
1719 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1722 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1724 Record.push_back(E->getNumObjects());
1725 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
1726 Record.AddDeclRef(E->getObject(i));
1728 Record.push_back(E->cleanupsHaveSideEffects());
1729 Record.AddStmt(E->getSubExpr());
1730 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1733 void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
1734 CXXDependentScopeMemberExpr *E) {
1737 // Don't emit anything here (or if you do you will have to update
1738 // the corresponding deserialization function).
1740 Record.push_back(E->hasTemplateKWAndArgsInfo());
1741 Record.push_back(E->getNumTemplateArgs());
1742 Record.push_back(E->hasFirstQualifierFoundInScope());
1744 if (E->hasTemplateKWAndArgsInfo()) {
1745 const ASTTemplateKWAndArgsInfo &ArgInfo =
1746 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1747 AddTemplateKWAndArgsInfo(ArgInfo,
1748 E->getTrailingObjects<TemplateArgumentLoc>());
1751 Record.push_back(E->isArrow());
1752 Record.AddSourceLocation(E->getOperatorLoc());
1753 Record.AddTypeRef(E->getBaseType());
1754 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1755 if (!E->isImplicitAccess())
1756 Record.AddStmt(E->getBase());
1758 Record.AddStmt(nullptr);
1760 if (E->hasFirstQualifierFoundInScope())
1761 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1763 Record.AddDeclarationNameInfo(E->MemberNameInfo);
1764 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
1768 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1771 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1774 Record.push_back(E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
1775 if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
1776 const ASTTemplateKWAndArgsInfo &ArgInfo =
1777 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1778 Record.push_back(ArgInfo.NumTemplateArgs);
1779 AddTemplateKWAndArgsInfo(ArgInfo,
1780 E->getTrailingObjects<TemplateArgumentLoc>());
1783 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1784 Record.AddDeclarationNameInfo(E->NameInfo);
1785 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
1789 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1791 Record.push_back(E->arg_size());
1792 for (CXXUnresolvedConstructExpr::arg_iterator
1793 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
1794 Record.AddStmt(*ArgI);
1795 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1796 Record.AddSourceLocation(E->getLParenLoc());
1797 Record.AddSourceLocation(E->getRParenLoc());
1798 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
1801 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
1804 Record.push_back(E->getNumDecls());
1805 Record.push_back(E->hasTemplateKWAndArgsInfo());
1806 if (E->hasTemplateKWAndArgsInfo()) {
1807 const ASTTemplateKWAndArgsInfo &ArgInfo =
1808 *E->getTrailingASTTemplateKWAndArgsInfo();
1809 Record.push_back(ArgInfo.NumTemplateArgs);
1810 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
1813 for (OverloadExpr::decls_iterator OvI = E->decls_begin(),
1814 OvE = E->decls_end();
1815 OvI != OvE; ++OvI) {
1816 Record.AddDeclRef(OvI.getDecl());
1817 Record.push_back(OvI.getAccess());
1820 Record.AddDeclarationNameInfo(E->getNameInfo());
1821 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1824 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1825 VisitOverloadExpr(E);
1826 Record.push_back(E->isArrow());
1827 Record.push_back(E->hasUnresolvedUsing());
1828 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1829 Record.AddTypeRef(E->getBaseType());
1830 Record.AddSourceLocation(E->getOperatorLoc());
1831 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
1834 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1835 VisitOverloadExpr(E);
1836 Record.push_back(E->requiresADL());
1837 Record.push_back(E->isOverloaded());
1838 Record.AddDeclRef(E->getNamingClass());
1839 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
1842 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1844 Record.push_back(E->TypeTraitExprBits.NumArgs);
1845 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1846 Record.push_back(E->TypeTraitExprBits.Value);
1847 Record.AddSourceRange(E->getSourceRange());
1848 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1849 Record.AddTypeSourceInfo(E->getArg(I));
1850 Code = serialization::EXPR_TYPE_TRAIT;
1853 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1855 Record.push_back(E->getTrait());
1856 Record.push_back(E->getValue());
1857 Record.AddSourceRange(E->getSourceRange());
1858 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
1859 Record.AddStmt(E->getDimensionExpression());
1860 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1863 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1865 Record.push_back(E->getTrait());
1866 Record.push_back(E->getValue());
1867 Record.AddSourceRange(E->getSourceRange());
1868 Record.AddStmt(E->getQueriedExpression());
1869 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1872 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1874 Record.push_back(E->getValue());
1875 Record.AddSourceRange(E->getSourceRange());
1876 Record.AddStmt(E->getOperand());
1877 Code = serialization::EXPR_CXX_NOEXCEPT;
1880 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1882 Record.AddSourceLocation(E->getEllipsisLoc());
1883 Record.push_back(E->NumExpansions);
1884 Record.AddStmt(E->getPattern());
1885 Code = serialization::EXPR_PACK_EXPANSION;
1888 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1890 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1892 Record.AddSourceLocation(E->OperatorLoc);
1893 Record.AddSourceLocation(E->PackLoc);
1894 Record.AddSourceLocation(E->RParenLoc);
1895 Record.AddDeclRef(E->Pack);
1896 if (E->isPartiallySubstituted()) {
1897 for (const auto &TA : E->getPartialArguments())
1898 Record.AddTemplateArgument(TA);
1899 } else if (!E->isValueDependent()) {
1900 Record.push_back(E->getPackLength());
1902 Code = serialization::EXPR_SIZEOF_PACK;
1905 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1906 SubstNonTypeTemplateParmExpr *E) {
1908 Record.AddDeclRef(E->getParameter());
1909 Record.AddSourceLocation(E->getNameLoc());
1910 Record.AddStmt(E->getReplacement());
1911 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1914 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1915 SubstNonTypeTemplateParmPackExpr *E) {
1917 Record.AddDeclRef(E->getParameterPack());
1918 Record.AddTemplateArgument(E->getArgumentPack());
1919 Record.AddSourceLocation(E->getParameterPackLocation());
1920 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1923 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1925 Record.push_back(E->getNumExpansions());
1926 Record.AddDeclRef(E->getParameterPack());
1927 Record.AddSourceLocation(E->getParameterPackLocation());
1928 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1930 Record.AddDeclRef(*I);
1931 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1934 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1936 Record.push_back(static_cast<bool>(E->getLifetimeExtendedTemporaryDecl()));
1937 if (E->getLifetimeExtendedTemporaryDecl())
1938 Record.AddDeclRef(E->getLifetimeExtendedTemporaryDecl());
1940 Record.AddStmt(E->getSubExpr());
1941 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1944 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1946 Record.AddSourceLocation(E->LParenLoc);
1947 Record.AddSourceLocation(E->EllipsisLoc);
1948 Record.AddSourceLocation(E->RParenLoc);
1949 Record.push_back(E->NumExpansions);
1950 Record.AddStmt(E->SubExprs[0]);
1951 Record.AddStmt(E->SubExprs[1]);
1952 Record.push_back(E->Opcode);
1953 Code = serialization::EXPR_CXX_FOLD;
1956 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1958 Record.AddStmt(E->getSourceExpr());
1959 Record.AddSourceLocation(E->getLocation());
1960 Record.push_back(E->isUnique());
1961 Code = serialization::EXPR_OPAQUE_VALUE;
1964 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1966 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
1967 llvm_unreachable("Cannot write TypoExpr nodes");
1970 //===----------------------------------------------------------------------===//
1971 // CUDA Expressions and Statements.
1972 //===----------------------------------------------------------------------===//
1974 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1976 Record.AddStmt(E->getConfig());
1977 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1980 //===----------------------------------------------------------------------===//
1981 // OpenCL Expressions and Statements.
1982 //===----------------------------------------------------------------------===//
1983 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1985 Record.AddSourceLocation(E->getBuiltinLoc());
1986 Record.AddSourceLocation(E->getRParenLoc());
1987 Record.AddStmt(E->getSrcExpr());
1988 Code = serialization::EXPR_ASTYPE;
1991 //===----------------------------------------------------------------------===//
1992 // Microsoft Expressions and Statements.
1993 //===----------------------------------------------------------------------===//
1994 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1996 Record.push_back(E->isArrow());
1997 Record.AddStmt(E->getBaseExpr());
1998 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1999 Record.AddSourceLocation(E->getMemberLoc());
2000 Record.AddDeclRef(E->getPropertyDecl());
2001 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
2004 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
2006 Record.AddStmt(E->getBase());
2007 Record.AddStmt(E->getIdx());
2008 Record.AddSourceLocation(E->getRBracketLoc());
2009 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
2012 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
2014 Record.AddSourceRange(E->getSourceRange());
2015 Record.AddString(E->getUuidStr());
2016 if (E->isTypeOperand()) {
2017 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
2018 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
2020 Record.AddStmt(E->getExprOperand());
2021 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
2025 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
2027 Record.AddSourceLocation(S->getExceptLoc());
2028 Record.AddStmt(S->getFilterExpr());
2029 Record.AddStmt(S->getBlock());
2030 Code = serialization::STMT_SEH_EXCEPT;
2033 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
2035 Record.AddSourceLocation(S->getFinallyLoc());
2036 Record.AddStmt(S->getBlock());
2037 Code = serialization::STMT_SEH_FINALLY;
2040 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
2042 Record.push_back(S->getIsCXXTry());
2043 Record.AddSourceLocation(S->getTryLoc());
2044 Record.AddStmt(S->getTryBlock());
2045 Record.AddStmt(S->getHandler());
2046 Code = serialization::STMT_SEH_TRY;
2049 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
2051 Record.AddSourceLocation(S->getLeaveLoc());
2052 Code = serialization::STMT_SEH_LEAVE;
2055 //===----------------------------------------------------------------------===//
2056 // OpenMP Directives.
2057 //===----------------------------------------------------------------------===//
2058 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2059 Record.AddSourceLocation(E->getBeginLoc());
2060 Record.AddSourceLocation(E->getEndLoc());
2061 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
2062 Record.writeOMPClause(E->getClause(i));
2064 if (E->hasAssociatedStmt())
2065 Record.AddStmt(E->getAssociatedStmt());
2068 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
2070 Record.push_back(D->getNumClauses());
2071 Record.push_back(D->getCollapsedNumber());
2072 VisitOMPExecutableDirective(D);
2073 Record.AddStmt(D->getIterationVariable());
2074 Record.AddStmt(D->getLastIteration());
2075 Record.AddStmt(D->getCalcLastIteration());
2076 Record.AddStmt(D->getPreCond());
2077 Record.AddStmt(D->getCond());
2078 Record.AddStmt(D->getInit());
2079 Record.AddStmt(D->getInc());
2080 Record.AddStmt(D->getPreInits());
2081 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
2082 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
2083 isOpenMPDistributeDirective(D->getDirectiveKind())) {
2084 Record.AddStmt(D->getIsLastIterVariable());
2085 Record.AddStmt(D->getLowerBoundVariable());
2086 Record.AddStmt(D->getUpperBoundVariable());
2087 Record.AddStmt(D->getStrideVariable());
2088 Record.AddStmt(D->getEnsureUpperBound());
2089 Record.AddStmt(D->getNextLowerBound());
2090 Record.AddStmt(D->getNextUpperBound());
2091 Record.AddStmt(D->getNumIterations());
2093 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
2094 Record.AddStmt(D->getPrevLowerBoundVariable());
2095 Record.AddStmt(D->getPrevUpperBoundVariable());
2096 Record.AddStmt(D->getDistInc());
2097 Record.AddStmt(D->getPrevEnsureUpperBound());
2098 Record.AddStmt(D->getCombinedLowerBoundVariable());
2099 Record.AddStmt(D->getCombinedUpperBoundVariable());
2100 Record.AddStmt(D->getCombinedEnsureUpperBound());
2101 Record.AddStmt(D->getCombinedInit());
2102 Record.AddStmt(D->getCombinedCond());
2103 Record.AddStmt(D->getCombinedNextLowerBound());
2104 Record.AddStmt(D->getCombinedNextUpperBound());
2105 Record.AddStmt(D->getCombinedDistCond());
2106 Record.AddStmt(D->getCombinedParForInDistCond());
2108 for (auto I : D->counters()) {
2111 for (auto I : D->private_counters()) {
2114 for (auto I : D->inits()) {
2117 for (auto I : D->updates()) {
2120 for (auto I : D->finals()) {
2123 for (Stmt *S : D->dependent_counters())
2125 for (Stmt *S : D->dependent_inits())
2127 for (Stmt *S : D->finals_conditions())
2131 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2133 Record.push_back(D->getNumClauses());
2134 VisitOMPExecutableDirective(D);
2135 Record.push_back(D->hasCancel() ? 1 : 0);
2136 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2139 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2140 VisitOMPLoopDirective(D);
2141 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2144 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2145 VisitOMPLoopDirective(D);
2146 Record.push_back(D->hasCancel() ? 1 : 0);
2147 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2150 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2151 VisitOMPLoopDirective(D);
2152 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2155 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2157 Record.push_back(D->getNumClauses());
2158 VisitOMPExecutableDirective(D);
2159 Record.push_back(D->hasCancel() ? 1 : 0);
2160 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2163 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2165 VisitOMPExecutableDirective(D);
2166 Record.push_back(D->hasCancel() ? 1 : 0);
2167 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2170 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2172 Record.push_back(D->getNumClauses());
2173 VisitOMPExecutableDirective(D);
2174 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2177 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2179 VisitOMPExecutableDirective(D);
2180 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2183 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2185 Record.push_back(D->getNumClauses());
2186 VisitOMPExecutableDirective(D);
2187 Record.AddDeclarationNameInfo(D->getDirectiveName());
2188 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2191 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2192 VisitOMPLoopDirective(D);
2193 Record.push_back(D->hasCancel() ? 1 : 0);
2194 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2197 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2198 OMPParallelForSimdDirective *D) {
2199 VisitOMPLoopDirective(D);
2200 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2203 void ASTStmtWriter::VisitOMPParallelMasterDirective(
2204 OMPParallelMasterDirective *D) {
2206 Record.push_back(D->getNumClauses());
2207 VisitOMPExecutableDirective(D);
2208 Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE;
2211 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2212 OMPParallelSectionsDirective *D) {
2214 Record.push_back(D->getNumClauses());
2215 VisitOMPExecutableDirective(D);
2216 Record.push_back(D->hasCancel() ? 1 : 0);
2217 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2220 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2222 Record.push_back(D->getNumClauses());
2223 VisitOMPExecutableDirective(D);
2224 Record.push_back(D->hasCancel() ? 1 : 0);
2225 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2228 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2230 Record.push_back(D->getNumClauses());
2231 VisitOMPExecutableDirective(D);
2232 Record.AddStmt(D->getX());
2233 Record.AddStmt(D->getV());
2234 Record.AddStmt(D->getExpr());
2235 Record.AddStmt(D->getUpdateExpr());
2236 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
2237 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
2238 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2241 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2243 Record.push_back(D->getNumClauses());
2244 VisitOMPExecutableDirective(D);
2245 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2248 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2250 Record.push_back(D->getNumClauses());
2251 VisitOMPExecutableDirective(D);
2252 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2255 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2256 OMPTargetEnterDataDirective *D) {
2258 Record.push_back(D->getNumClauses());
2259 VisitOMPExecutableDirective(D);
2260 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2263 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2264 OMPTargetExitDataDirective *D) {
2266 Record.push_back(D->getNumClauses());
2267 VisitOMPExecutableDirective(D);
2268 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2271 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2272 OMPTargetParallelDirective *D) {
2274 Record.push_back(D->getNumClauses());
2275 VisitOMPExecutableDirective(D);
2276 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2279 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2280 OMPTargetParallelForDirective *D) {
2281 VisitOMPLoopDirective(D);
2282 Record.push_back(D->hasCancel() ? 1 : 0);
2283 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2286 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2288 VisitOMPExecutableDirective(D);
2289 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2292 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2294 VisitOMPExecutableDirective(D);
2295 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2298 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2300 VisitOMPExecutableDirective(D);
2301 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2304 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2306 Record.push_back(D->getNumClauses());
2307 VisitOMPExecutableDirective(D);
2308 Record.AddStmt(D->getReductionRef());
2309 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2312 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2314 Record.push_back(D->getNumClauses());
2315 VisitOMPExecutableDirective(D);
2316 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2319 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2321 Record.push_back(D->getNumClauses());
2322 VisitOMPExecutableDirective(D);
2323 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2326 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2328 Record.push_back(D->getNumClauses());
2329 VisitOMPExecutableDirective(D);
2330 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2333 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2334 OMPCancellationPointDirective *D) {
2336 VisitOMPExecutableDirective(D);
2337 Record.push_back(uint64_t(D->getCancelRegion()));
2338 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2341 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2343 Record.push_back(D->getNumClauses());
2344 VisitOMPExecutableDirective(D);
2345 Record.push_back(uint64_t(D->getCancelRegion()));
2346 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2349 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2350 VisitOMPLoopDirective(D);
2351 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2354 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2355 VisitOMPLoopDirective(D);
2356 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2359 void ASTStmtWriter::VisitOMPMasterTaskLoopDirective(
2360 OMPMasterTaskLoopDirective *D) {
2361 VisitOMPLoopDirective(D);
2362 Code = serialization::STMT_OMP_MASTER_TASKLOOP_DIRECTIVE;
2365 void ASTStmtWriter::VisitOMPMasterTaskLoopSimdDirective(
2366 OMPMasterTaskLoopSimdDirective *D) {
2367 VisitOMPLoopDirective(D);
2368 Code = serialization::STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE;
2371 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopDirective(
2372 OMPParallelMasterTaskLoopDirective *D) {
2373 VisitOMPLoopDirective(D);
2374 Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE;
2377 void ASTStmtWriter::VisitOMPParallelMasterTaskLoopSimdDirective(
2378 OMPParallelMasterTaskLoopSimdDirective *D) {
2379 VisitOMPLoopDirective(D);
2380 Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE;
2383 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2384 VisitOMPLoopDirective(D);
2385 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2388 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2390 Record.push_back(D->getNumClauses());
2391 VisitOMPExecutableDirective(D);
2392 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2395 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2396 OMPDistributeParallelForDirective *D) {
2397 VisitOMPLoopDirective(D);
2398 Record.push_back(D->hasCancel() ? 1 : 0);
2399 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2402 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2403 OMPDistributeParallelForSimdDirective *D) {
2404 VisitOMPLoopDirective(D);
2405 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2408 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2409 OMPDistributeSimdDirective *D) {
2410 VisitOMPLoopDirective(D);
2411 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2414 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2415 OMPTargetParallelForSimdDirective *D) {
2416 VisitOMPLoopDirective(D);
2417 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2420 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2421 VisitOMPLoopDirective(D);
2422 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2425 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2426 OMPTeamsDistributeDirective *D) {
2427 VisitOMPLoopDirective(D);
2428 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2431 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2432 OMPTeamsDistributeSimdDirective *D) {
2433 VisitOMPLoopDirective(D);
2434 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2437 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2438 OMPTeamsDistributeParallelForSimdDirective *D) {
2439 VisitOMPLoopDirective(D);
2440 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2443 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2444 OMPTeamsDistributeParallelForDirective *D) {
2445 VisitOMPLoopDirective(D);
2446 Record.push_back(D->hasCancel() ? 1 : 0);
2447 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2450 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2452 Record.push_back(D->getNumClauses());
2453 VisitOMPExecutableDirective(D);
2454 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2457 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2458 OMPTargetTeamsDistributeDirective *D) {
2459 VisitOMPLoopDirective(D);
2460 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2463 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2464 OMPTargetTeamsDistributeParallelForDirective *D) {
2465 VisitOMPLoopDirective(D);
2466 Record.push_back(D->hasCancel() ? 1 : 0);
2467 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2470 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2471 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2472 VisitOMPLoopDirective(D);
2473 Code = serialization::
2474 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2477 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2478 OMPTargetTeamsDistributeSimdDirective *D) {
2479 VisitOMPLoopDirective(D);
2480 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2483 //===----------------------------------------------------------------------===//
2484 // ASTWriter Implementation
2485 //===----------------------------------------------------------------------===//
2487 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2488 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
2489 "SwitchCase recorded twice");
2490 unsigned NextID = SwitchCaseIDs.size();
2491 SwitchCaseIDs[S] = NextID;
2495 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2496 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
2497 "SwitchCase hasn't been seen yet");
2498 return SwitchCaseIDs[S];
2501 void ASTWriter::ClearSwitchCaseIDs() {
2502 SwitchCaseIDs.clear();
2505 /// Write the given substatement or subexpression to the
2507 void ASTWriter::WriteSubStmt(Stmt *S) {
2509 ASTStmtWriter Writer(*this, Record);
2513 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2517 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2518 if (I != SubStmtEntries.end()) {
2519 Record.push_back(I->second);
2520 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2525 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2527 struct ParentStmtInserterRAII {
2529 llvm::DenseSet<Stmt *> &ParentStmts;
2531 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2532 : S(S), ParentStmts(ParentStmts) {
2533 ParentStmts.insert(S);
2535 ~ParentStmtInserterRAII() {
2536 ParentStmts.erase(S);
2540 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2545 uint64_t Offset = Writer.Emit();
2546 SubStmtEntries[S] = Offset;
2549 /// Flush all of the statements that have been added to the
2550 /// queue via AddStmt().
2551 void ASTRecordWriter::FlushStmts() {
2552 // We expect to be the only consumer of the two temporary statement maps,
2553 // assert that they are empty.
2554 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2555 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2557 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2558 Writer->WriteSubStmt(StmtsToEmit[I]);
2560 assert(N == StmtsToEmit.size() && "record modified while being written!");
2562 // Note that we are at the end of a full expression. Any
2563 // expression records that follow this one are part of a different
2565 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2567 Writer->SubStmtEntries.clear();
2568 Writer->ParentStmts.clear();
2571 StmtsToEmit.clear();
2574 void ASTRecordWriter::FlushSubStmts() {
2575 // For a nested statement, write out the substatements in reverse order (so
2576 // that a simple stack machine can be used when loading), and don't emit a
2577 // STMT_STOP after each one.
2578 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2579 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
2580 assert(N == StmtsToEmit.size() && "record modified while being written!");
2583 StmtsToEmit.clear();