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/ASTWriter.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/StmtVisitor.h"
20 #include "clang/Lex/Token.h"
21 #include "llvm/Bitstream/BitstreamWriter.h"
22 using namespace clang;
24 //===----------------------------------------------------------------------===//
25 // Statement/expression serialization
26 //===----------------------------------------------------------------------===//
30 class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
32 ASTRecordWriter Record;
34 serialization::StmtCode Code;
38 ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
39 : Writer(Writer), Record(Writer, Record),
40 Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
42 ASTStmtWriter(const ASTStmtWriter&) = delete;
45 assert(Code != serialization::STMT_NULL_PTR &&
46 "unhandled sub-statement writing AST file");
47 return Record.EmitStmt(Code, AbbrevToUse);
50 void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo,
51 const TemplateArgumentLoc *Args);
53 void VisitStmt(Stmt *S);
54 #define STMT(Type, Base) \
55 void Visit##Type(Type *);
56 #include "clang/AST/StmtNodes.inc"
60 void ASTStmtWriter::AddTemplateKWAndArgsInfo(
61 const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) {
62 Record.AddSourceLocation(ArgInfo.TemplateKWLoc);
63 Record.AddSourceLocation(ArgInfo.LAngleLoc);
64 Record.AddSourceLocation(ArgInfo.RAngleLoc);
65 for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i)
66 Record.AddTemplateArgumentLoc(Args[i]);
69 void ASTStmtWriter::VisitStmt(Stmt *S) {
70 Record.push_back(S->StmtBits.IsOMPStructuredBlock);
73 void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
75 Record.AddSourceLocation(S->getSemiLoc());
76 Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro);
77 Code = serialization::STMT_NULL;
80 void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
82 Record.push_back(S->size());
83 for (auto *CS : S->body())
85 Record.AddSourceLocation(S->getLBracLoc());
86 Record.AddSourceLocation(S->getRBracLoc());
87 Code = serialization::STMT_COMPOUND;
90 void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
92 Record.push_back(Writer.getSwitchCaseID(S));
93 Record.AddSourceLocation(S->getKeywordLoc());
94 Record.AddSourceLocation(S->getColonLoc());
97 void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
99 Record.push_back(S->caseStmtIsGNURange());
100 Record.AddStmt(S->getLHS());
101 Record.AddStmt(S->getSubStmt());
102 if (S->caseStmtIsGNURange()) {
103 Record.AddStmt(S->getRHS());
104 Record.AddSourceLocation(S->getEllipsisLoc());
106 Code = serialization::STMT_CASE;
109 void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
111 Record.AddStmt(S->getSubStmt());
112 Code = serialization::STMT_DEFAULT;
115 void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
117 Record.AddDeclRef(S->getDecl());
118 Record.AddStmt(S->getSubStmt());
119 Record.AddSourceLocation(S->getIdentLoc());
120 Code = serialization::STMT_LABEL;
123 void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
125 Record.push_back(S->getAttrs().size());
126 Record.AddAttributes(S->getAttrs());
127 Record.AddStmt(S->getSubStmt());
128 Record.AddSourceLocation(S->getAttrLoc());
129 Code = serialization::STMT_ATTRIBUTED;
132 void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
135 bool HasElse = S->getElse() != nullptr;
136 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
137 bool HasInit = S->getInit() != nullptr;
139 Record.push_back(S->isConstexpr());
140 Record.push_back(HasElse);
141 Record.push_back(HasVar);
142 Record.push_back(HasInit);
144 Record.AddStmt(S->getCond());
145 Record.AddStmt(S->getThen());
147 Record.AddStmt(S->getElse());
149 Record.AddDeclRef(S->getConditionVariable());
151 Record.AddStmt(S->getInit());
153 Record.AddSourceLocation(S->getIfLoc());
155 Record.AddSourceLocation(S->getElseLoc());
157 Code = serialization::STMT_IF;
160 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
163 bool HasInit = S->getInit() != nullptr;
164 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
165 Record.push_back(HasInit);
166 Record.push_back(HasVar);
167 Record.push_back(S->isAllEnumCasesCovered());
169 Record.AddStmt(S->getCond());
170 Record.AddStmt(S->getBody());
172 Record.AddStmt(S->getInit());
174 Record.AddDeclRef(S->getConditionVariable());
176 Record.AddSourceLocation(S->getSwitchLoc());
178 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
179 SC = SC->getNextSwitchCase())
180 Record.push_back(Writer.RecordSwitchCaseID(SC));
181 Code = serialization::STMT_SWITCH;
184 void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
187 bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
188 Record.push_back(HasVar);
190 Record.AddStmt(S->getCond());
191 Record.AddStmt(S->getBody());
193 Record.AddDeclRef(S->getConditionVariable());
195 Record.AddSourceLocation(S->getWhileLoc());
196 Code = serialization::STMT_WHILE;
199 void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
201 Record.AddStmt(S->getCond());
202 Record.AddStmt(S->getBody());
203 Record.AddSourceLocation(S->getDoLoc());
204 Record.AddSourceLocation(S->getWhileLoc());
205 Record.AddSourceLocation(S->getRParenLoc());
206 Code = serialization::STMT_DO;
209 void ASTStmtWriter::VisitForStmt(ForStmt *S) {
211 Record.AddStmt(S->getInit());
212 Record.AddStmt(S->getCond());
213 Record.AddDeclRef(S->getConditionVariable());
214 Record.AddStmt(S->getInc());
215 Record.AddStmt(S->getBody());
216 Record.AddSourceLocation(S->getForLoc());
217 Record.AddSourceLocation(S->getLParenLoc());
218 Record.AddSourceLocation(S->getRParenLoc());
219 Code = serialization::STMT_FOR;
222 void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
224 Record.AddDeclRef(S->getLabel());
225 Record.AddSourceLocation(S->getGotoLoc());
226 Record.AddSourceLocation(S->getLabelLoc());
227 Code = serialization::STMT_GOTO;
230 void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
232 Record.AddSourceLocation(S->getGotoLoc());
233 Record.AddSourceLocation(S->getStarLoc());
234 Record.AddStmt(S->getTarget());
235 Code = serialization::STMT_INDIRECT_GOTO;
238 void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
240 Record.AddSourceLocation(S->getContinueLoc());
241 Code = serialization::STMT_CONTINUE;
244 void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
246 Record.AddSourceLocation(S->getBreakLoc());
247 Code = serialization::STMT_BREAK;
250 void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
253 bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr;
254 Record.push_back(HasNRVOCandidate);
256 Record.AddStmt(S->getRetValue());
257 if (HasNRVOCandidate)
258 Record.AddDeclRef(S->getNRVOCandidate());
260 Record.AddSourceLocation(S->getReturnLoc());
261 Code = serialization::STMT_RETURN;
264 void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
266 Record.AddSourceLocation(S->getBeginLoc());
267 Record.AddSourceLocation(S->getEndLoc());
268 DeclGroupRef DG = S->getDeclGroup();
269 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
270 Record.AddDeclRef(*D);
271 Code = serialization::STMT_DECL;
274 void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
276 Record.push_back(S->getNumOutputs());
277 Record.push_back(S->getNumInputs());
278 Record.push_back(S->getNumClobbers());
279 Record.AddSourceLocation(S->getAsmLoc());
280 Record.push_back(S->isVolatile());
281 Record.push_back(S->isSimple());
284 void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
286 Record.push_back(S->getNumLabels());
287 Record.AddSourceLocation(S->getRParenLoc());
288 Record.AddStmt(S->getAsmString());
291 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
292 Record.AddIdentifierRef(S->getOutputIdentifier(I));
293 Record.AddStmt(S->getOutputConstraintLiteral(I));
294 Record.AddStmt(S->getOutputExpr(I));
298 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
299 Record.AddIdentifierRef(S->getInputIdentifier(I));
300 Record.AddStmt(S->getInputConstraintLiteral(I));
301 Record.AddStmt(S->getInputExpr(I));
305 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
306 Record.AddStmt(S->getClobberStringLiteral(I));
309 for (auto *E : S->labels()) Record.AddStmt(E);
311 Code = serialization::STMT_GCCASM;
314 void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
316 Record.AddSourceLocation(S->getLBraceLoc());
317 Record.AddSourceLocation(S->getEndLoc());
318 Record.push_back(S->getNumAsmToks());
319 Record.AddString(S->getAsmString());
322 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
323 // FIXME: Move this to ASTRecordWriter?
324 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
328 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
329 Record.AddString(S->getClobber(I));
333 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
334 Record.AddStmt(S->getOutputExpr(I));
335 Record.AddString(S->getOutputConstraint(I));
339 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
340 Record.AddStmt(S->getInputExpr(I));
341 Record.AddString(S->getInputConstraint(I));
344 Code = serialization::STMT_MSASM;
347 void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
349 Record.push_back(CoroStmt->getParamMoves().size());
350 for (Stmt *S : CoroStmt->children())
352 Code = serialization::STMT_COROUTINE_BODY;
355 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
357 Record.AddSourceLocation(S->getKeywordLoc());
358 Record.AddStmt(S->getOperand());
359 Record.AddStmt(S->getPromiseCall());
360 Record.push_back(S->isImplicit());
361 Code = serialization::STMT_CORETURN;
364 void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
366 Record.AddSourceLocation(E->getKeywordLoc());
367 for (Stmt *S : E->children())
369 Record.AddStmt(E->getOpaqueValue());
372 void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
373 VisitCoroutineSuspendExpr(E);
374 Record.push_back(E->isImplicit());
375 Code = serialization::EXPR_COAWAIT;
378 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
379 VisitCoroutineSuspendExpr(E);
380 Code = serialization::EXPR_COYIELD;
383 void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
385 Record.AddSourceLocation(E->getKeywordLoc());
386 for (Stmt *S : E->children())
388 Code = serialization::EXPR_DEPENDENT_COAWAIT;
391 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
394 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
396 // CapturedDecl and captured region kind
397 Record.AddDeclRef(S->getCapturedDecl());
398 Record.push_back(S->getCapturedRegionKind());
400 Record.AddDeclRef(S->getCapturedRecordDecl());
403 for (auto *I : S->capture_inits())
407 Record.AddStmt(S->getCapturedStmt());
410 for (const auto &I : S->captures()) {
411 if (I.capturesThis() || I.capturesVariableArrayType())
412 Record.AddDeclRef(nullptr);
414 Record.AddDeclRef(I.getCapturedVar());
415 Record.push_back(I.getCaptureKind());
416 Record.AddSourceLocation(I.getLocation());
419 Code = serialization::STMT_CAPTURED;
422 void ASTStmtWriter::VisitExpr(Expr *E) {
424 Record.AddTypeRef(E->getType());
425 Record.push_back(E->isTypeDependent());
426 Record.push_back(E->isValueDependent());
427 Record.push_back(E->isInstantiationDependent());
428 Record.push_back(E->containsUnexpandedParameterPack());
429 Record.push_back(E->getValueKind());
430 Record.push_back(E->getObjectKind());
433 void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
435 Record.push_back(static_cast<uint64_t>(E->ConstantExprBits.ResultKind));
436 switch (E->ConstantExprBits.ResultKind) {
437 case ConstantExpr::RSK_Int64:
438 Record.push_back(E->Int64Result());
439 Record.push_back(E->ConstantExprBits.IsUnsigned |
440 E->ConstantExprBits.BitWidth << 1);
442 case ConstantExpr::RSK_APValue:
443 Record.AddAPValue(E->APValueResult());
445 Record.AddStmt(E->getSubExpr());
446 Code = serialization::EXPR_CONSTANT;
449 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
452 bool HasFunctionName = E->getFunctionName() != nullptr;
453 Record.push_back(HasFunctionName);
454 Record.push_back(E->getIdentKind()); // FIXME: stable encoding
455 Record.AddSourceLocation(E->getLocation());
457 Record.AddStmt(E->getFunctionName());
458 Code = serialization::EXPR_PREDEFINED;
461 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
464 Record.push_back(E->hasQualifier());
465 Record.push_back(E->getDecl() != E->getFoundDecl());
466 Record.push_back(E->hasTemplateKWAndArgsInfo());
467 Record.push_back(E->hadMultipleCandidates());
468 Record.push_back(E->refersToEnclosingVariableOrCapture());
469 Record.push_back(E->isNonOdrUse());
471 if (E->hasTemplateKWAndArgsInfo()) {
472 unsigned NumTemplateArgs = E->getNumTemplateArgs();
473 Record.push_back(NumTemplateArgs);
476 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
478 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
479 (E->getDecl() == E->getFoundDecl()) &&
480 nk == DeclarationName::Identifier &&
481 !E->refersToEnclosingVariableOrCapture() && !E->isNonOdrUse()) {
482 AbbrevToUse = Writer.getDeclRefExprAbbrev();
485 if (E->hasQualifier())
486 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
488 if (E->getDecl() != E->getFoundDecl())
489 Record.AddDeclRef(E->getFoundDecl());
491 if (E->hasTemplateKWAndArgsInfo())
492 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
493 E->getTrailingObjects<TemplateArgumentLoc>());
495 Record.AddDeclRef(E->getDecl());
496 Record.AddSourceLocation(E->getLocation());
497 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
498 Code = serialization::EXPR_DECL_REF;
501 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
503 Record.AddSourceLocation(E->getLocation());
504 Record.AddAPInt(E->getValue());
506 if (E->getValue().getBitWidth() == 32) {
507 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
510 Code = serialization::EXPR_INTEGER_LITERAL;
513 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
515 Record.AddSourceLocation(E->getLocation());
516 Record.AddAPInt(E->getValue());
517 Code = serialization::EXPR_INTEGER_LITERAL;
520 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
522 Record.push_back(E->getRawSemantics());
523 Record.push_back(E->isExact());
524 Record.AddAPFloat(E->getValue());
525 Record.AddSourceLocation(E->getLocation());
526 Code = serialization::EXPR_FLOATING_LITERAL;
529 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
531 Record.AddStmt(E->getSubExpr());
532 Code = serialization::EXPR_IMAGINARY_LITERAL;
535 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
538 // Store the various bits of data of StringLiteral.
539 Record.push_back(E->getNumConcatenated());
540 Record.push_back(E->getLength());
541 Record.push_back(E->getCharByteWidth());
542 Record.push_back(E->getKind());
543 Record.push_back(E->isPascal());
545 // Store the trailing array of SourceLocation.
546 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
547 Record.AddSourceLocation(E->getStrTokenLoc(I));
549 // Store the trailing array of char holding the string data.
550 StringRef StrData = E->getBytes();
551 for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
552 Record.push_back(StrData[I]);
554 Code = serialization::EXPR_STRING_LITERAL;
557 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
559 Record.push_back(E->getValue());
560 Record.AddSourceLocation(E->getLocation());
561 Record.push_back(E->getKind());
563 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
565 Code = serialization::EXPR_CHARACTER_LITERAL;
568 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
570 Record.AddSourceLocation(E->getLParen());
571 Record.AddSourceLocation(E->getRParen());
572 Record.AddStmt(E->getSubExpr());
573 Code = serialization::EXPR_PAREN;
576 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
578 Record.push_back(E->getNumExprs());
579 for (auto *SubStmt : E->exprs())
580 Record.AddStmt(SubStmt);
581 Record.AddSourceLocation(E->getLParenLoc());
582 Record.AddSourceLocation(E->getRParenLoc());
583 Code = serialization::EXPR_PAREN_LIST;
586 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
588 Record.AddStmt(E->getSubExpr());
589 Record.push_back(E->getOpcode()); // FIXME: stable encoding
590 Record.AddSourceLocation(E->getOperatorLoc());
591 Record.push_back(E->canOverflow());
592 Code = serialization::EXPR_UNARY_OPERATOR;
595 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
597 Record.push_back(E->getNumComponents());
598 Record.push_back(E->getNumExpressions());
599 Record.AddSourceLocation(E->getOperatorLoc());
600 Record.AddSourceLocation(E->getRParenLoc());
601 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
602 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
603 const OffsetOfNode &ON = E->getComponent(I);
604 Record.push_back(ON.getKind()); // FIXME: Stable encoding
605 Record.AddSourceLocation(ON.getSourceRange().getBegin());
606 Record.AddSourceLocation(ON.getSourceRange().getEnd());
607 switch (ON.getKind()) {
608 case OffsetOfNode::Array:
609 Record.push_back(ON.getArrayExprIndex());
612 case OffsetOfNode::Field:
613 Record.AddDeclRef(ON.getField());
616 case OffsetOfNode::Identifier:
617 Record.AddIdentifierRef(ON.getFieldName());
620 case OffsetOfNode::Base:
621 Record.AddCXXBaseSpecifier(*ON.getBase());
625 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
626 Record.AddStmt(E->getIndexExpr(I));
627 Code = serialization::EXPR_OFFSETOF;
630 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
632 Record.push_back(E->getKind());
633 if (E->isArgumentType())
634 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
637 Record.AddStmt(E->getArgumentExpr());
639 Record.AddSourceLocation(E->getOperatorLoc());
640 Record.AddSourceLocation(E->getRParenLoc());
641 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
644 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
646 Record.AddStmt(E->getLHS());
647 Record.AddStmt(E->getRHS());
648 Record.AddSourceLocation(E->getRBracketLoc());
649 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
652 void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
654 Record.AddStmt(E->getBase());
655 Record.AddStmt(E->getLowerBound());
656 Record.AddStmt(E->getLength());
657 Record.AddSourceLocation(E->getColonLoc());
658 Record.AddSourceLocation(E->getRBracketLoc());
659 Code = serialization::EXPR_OMP_ARRAY_SECTION;
662 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
664 Record.push_back(E->getNumArgs());
665 Record.AddSourceLocation(E->getRParenLoc());
666 Record.AddStmt(E->getCallee());
667 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
668 Arg != ArgEnd; ++Arg)
669 Record.AddStmt(*Arg);
670 Record.push_back(static_cast<unsigned>(E->getADLCallKind()));
671 Code = serialization::EXPR_CALL;
674 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
677 bool HasQualifier = E->hasQualifier();
679 E->hasQualifierOrFoundDecl() &&
680 (E->getFoundDecl().getDecl() != E->getMemberDecl() ||
681 E->getFoundDecl().getAccess() != E->getMemberDecl()->getAccess());
682 bool HasTemplateInfo = E->hasTemplateKWAndArgsInfo();
683 unsigned NumTemplateArgs = E->getNumTemplateArgs();
685 // Write these first for easy access when deserializing, as they affect the
686 // size of the MemberExpr.
687 Record.push_back(HasQualifier);
688 Record.push_back(HasFoundDecl);
689 Record.push_back(HasTemplateInfo);
690 Record.push_back(NumTemplateArgs);
692 Record.AddStmt(E->getBase());
693 Record.AddDeclRef(E->getMemberDecl());
694 Record.AddDeclarationNameLoc(E->MemberDNLoc,
695 E->getMemberDecl()->getDeclName());
696 Record.AddSourceLocation(E->getMemberLoc());
697 Record.push_back(E->isArrow());
698 Record.push_back(E->hadMultipleCandidates());
699 Record.push_back(E->isNonOdrUse());
700 Record.AddSourceLocation(E->getOperatorLoc());
703 DeclAccessPair FoundDecl = E->getFoundDecl();
704 Record.AddDeclRef(FoundDecl.getDecl());
705 Record.push_back(FoundDecl.getAccess());
709 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
712 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
713 E->getTrailingObjects<TemplateArgumentLoc>());
715 Code = serialization::EXPR_MEMBER;
718 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
720 Record.AddStmt(E->getBase());
721 Record.AddSourceLocation(E->getIsaMemberLoc());
722 Record.AddSourceLocation(E->getOpLoc());
723 Record.push_back(E->isArrow());
724 Code = serialization::EXPR_OBJC_ISA;
728 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
730 Record.AddStmt(E->getSubExpr());
731 Record.push_back(E->shouldCopy());
732 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
735 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
736 VisitExplicitCastExpr(E);
737 Record.AddSourceLocation(E->getLParenLoc());
738 Record.AddSourceLocation(E->getBridgeKeywordLoc());
739 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
740 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
743 void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
745 Record.push_back(E->path_size());
746 Record.AddStmt(E->getSubExpr());
747 Record.push_back(E->getCastKind()); // FIXME: stable encoding
749 for (CastExpr::path_iterator
750 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
751 Record.AddCXXBaseSpecifier(**PI);
754 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
756 Record.AddStmt(E->getLHS());
757 Record.AddStmt(E->getRHS());
758 Record.push_back(E->getOpcode()); // FIXME: stable encoding
759 Record.AddSourceLocation(E->getOperatorLoc());
760 Record.push_back(E->getFPFeatures().getInt());
761 Code = serialization::EXPR_BINARY_OPERATOR;
764 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
765 VisitBinaryOperator(E);
766 Record.AddTypeRef(E->getComputationLHSType());
767 Record.AddTypeRef(E->getComputationResultType());
768 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
771 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
773 Record.AddStmt(E->getCond());
774 Record.AddStmt(E->getLHS());
775 Record.AddStmt(E->getRHS());
776 Record.AddSourceLocation(E->getQuestionLoc());
777 Record.AddSourceLocation(E->getColonLoc());
778 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
782 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
784 Record.AddStmt(E->getOpaqueValue());
785 Record.AddStmt(E->getCommon());
786 Record.AddStmt(E->getCond());
787 Record.AddStmt(E->getTrueExpr());
788 Record.AddStmt(E->getFalseExpr());
789 Record.AddSourceLocation(E->getQuestionLoc());
790 Record.AddSourceLocation(E->getColonLoc());
791 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
794 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
796 Record.push_back(E->isPartOfExplicitCast());
798 if (E->path_size() == 0)
799 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
801 Code = serialization::EXPR_IMPLICIT_CAST;
804 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
806 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
809 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
810 VisitExplicitCastExpr(E);
811 Record.AddSourceLocation(E->getLParenLoc());
812 Record.AddSourceLocation(E->getRParenLoc());
813 Code = serialization::EXPR_CSTYLE_CAST;
816 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
818 Record.AddSourceLocation(E->getLParenLoc());
819 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
820 Record.AddStmt(E->getInitializer());
821 Record.push_back(E->isFileScope());
822 Code = serialization::EXPR_COMPOUND_LITERAL;
825 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
827 Record.AddStmt(E->getBase());
828 Record.AddIdentifierRef(&E->getAccessor());
829 Record.AddSourceLocation(E->getAccessorLoc());
830 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
833 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
835 // NOTE: only add the (possibly null) syntactic form.
836 // No need to serialize the isSemanticForm flag and the semantic form.
837 Record.AddStmt(E->getSyntacticForm());
838 Record.AddSourceLocation(E->getLBraceLoc());
839 Record.AddSourceLocation(E->getRBraceLoc());
840 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
841 Record.push_back(isArrayFiller);
843 Record.AddStmt(E->getArrayFiller());
845 Record.AddDeclRef(E->getInitializedFieldInUnion());
846 Record.push_back(E->hadArrayRangeDesignator());
847 Record.push_back(E->getNumInits());
849 // ArrayFiller may have filled "holes" due to designated initializer.
850 // Replace them by 0 to indicate that the filler goes in that place.
851 Expr *filler = E->getArrayFiller();
852 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
853 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
855 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
856 Record.AddStmt(E->getInit(I));
858 Code = serialization::EXPR_INIT_LIST;
861 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
863 Record.push_back(E->getNumSubExprs());
864 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
865 Record.AddStmt(E->getSubExpr(I));
866 Record.AddSourceLocation(E->getEqualOrColonLoc());
867 Record.push_back(E->usesGNUSyntax());
868 for (const DesignatedInitExpr::Designator &D : E->designators()) {
869 if (D.isFieldDesignator()) {
870 if (FieldDecl *Field = D.getField()) {
871 Record.push_back(serialization::DESIG_FIELD_DECL);
872 Record.AddDeclRef(Field);
874 Record.push_back(serialization::DESIG_FIELD_NAME);
875 Record.AddIdentifierRef(D.getFieldName());
877 Record.AddSourceLocation(D.getDotLoc());
878 Record.AddSourceLocation(D.getFieldLoc());
879 } else if (D.isArrayDesignator()) {
880 Record.push_back(serialization::DESIG_ARRAY);
881 Record.push_back(D.getFirstExprIndex());
882 Record.AddSourceLocation(D.getLBracketLoc());
883 Record.AddSourceLocation(D.getRBracketLoc());
885 assert(D.isArrayRangeDesignator() && "Unknown designator");
886 Record.push_back(serialization::DESIG_ARRAY_RANGE);
887 Record.push_back(D.getFirstExprIndex());
888 Record.AddSourceLocation(D.getLBracketLoc());
889 Record.AddSourceLocation(D.getEllipsisLoc());
890 Record.AddSourceLocation(D.getRBracketLoc());
893 Code = serialization::EXPR_DESIGNATED_INIT;
896 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
898 Record.AddStmt(E->getBase());
899 Record.AddStmt(E->getUpdater());
900 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
903 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
905 Code = serialization::EXPR_NO_INIT;
908 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
910 Record.AddStmt(E->SubExprs[0]);
911 Record.AddStmt(E->SubExprs[1]);
912 Code = serialization::EXPR_ARRAY_INIT_LOOP;
915 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
917 Code = serialization::EXPR_ARRAY_INIT_INDEX;
920 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
922 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
925 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
927 Record.AddStmt(E->getSubExpr());
928 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
929 Record.AddSourceLocation(E->getBuiltinLoc());
930 Record.AddSourceLocation(E->getRParenLoc());
931 Record.push_back(E->isMicrosoftABI());
932 Code = serialization::EXPR_VA_ARG;
935 void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) {
937 Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext()));
938 Record.AddSourceLocation(E->getBeginLoc());
939 Record.AddSourceLocation(E->getEndLoc());
940 Record.push_back(E->getIdentKind());
941 Code = serialization::EXPR_SOURCE_LOC;
944 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
946 Record.AddSourceLocation(E->getAmpAmpLoc());
947 Record.AddSourceLocation(E->getLabelLoc());
948 Record.AddDeclRef(E->getLabel());
949 Code = serialization::EXPR_ADDR_LABEL;
952 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
954 Record.AddStmt(E->getSubStmt());
955 Record.AddSourceLocation(E->getLParenLoc());
956 Record.AddSourceLocation(E->getRParenLoc());
957 Code = serialization::EXPR_STMT;
960 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
962 Record.AddStmt(E->getCond());
963 Record.AddStmt(E->getLHS());
964 Record.AddStmt(E->getRHS());
965 Record.AddSourceLocation(E->getBuiltinLoc());
966 Record.AddSourceLocation(E->getRParenLoc());
967 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
968 Code = serialization::EXPR_CHOOSE;
971 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
973 Record.AddSourceLocation(E->getTokenLocation());
974 Code = serialization::EXPR_GNU_NULL;
977 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
979 Record.push_back(E->getNumSubExprs());
980 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
981 Record.AddStmt(E->getExpr(I));
982 Record.AddSourceLocation(E->getBuiltinLoc());
983 Record.AddSourceLocation(E->getRParenLoc());
984 Code = serialization::EXPR_SHUFFLE_VECTOR;
987 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
989 Record.AddSourceLocation(E->getBuiltinLoc());
990 Record.AddSourceLocation(E->getRParenLoc());
991 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
992 Record.AddStmt(E->getSrcExpr());
993 Code = serialization::EXPR_CONVERT_VECTOR;
996 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
998 Record.AddDeclRef(E->getBlockDecl());
999 Code = serialization::EXPR_BLOCK;
1002 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
1005 Record.push_back(E->getNumAssocs());
1006 Record.push_back(E->ResultIndex);
1007 Record.AddSourceLocation(E->getGenericLoc());
1008 Record.AddSourceLocation(E->getDefaultLoc());
1009 Record.AddSourceLocation(E->getRParenLoc());
1011 Stmt **Stmts = E->getTrailingObjects<Stmt *>();
1012 // Add 1 to account for the controlling expression which is the first
1013 // expression in the trailing array of Stmt *. This is not needed for
1014 // the trailing array of TypeSourceInfo *.
1015 for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I)
1016 Record.AddStmt(Stmts[I]);
1018 TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
1019 for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I)
1020 Record.AddTypeSourceInfo(TSIs[I]);
1022 Code = serialization::EXPR_GENERIC_SELECTION;
1025 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
1027 Record.push_back(E->getNumSemanticExprs());
1029 // Push the result index. Currently, this needs to exactly match
1030 // the encoding used internally for ResultIndex.
1031 unsigned result = E->getResultExprIndex();
1032 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
1033 Record.push_back(result);
1035 Record.AddStmt(E->getSyntacticForm());
1036 for (PseudoObjectExpr::semantics_iterator
1037 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
1040 Code = serialization::EXPR_PSEUDO_OBJECT;
1043 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
1045 Record.push_back(E->getOp());
1046 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
1047 Record.AddStmt(E->getSubExprs()[I]);
1048 Record.AddSourceLocation(E->getBuiltinLoc());
1049 Record.AddSourceLocation(E->getRParenLoc());
1050 Code = serialization::EXPR_ATOMIC;
1053 //===----------------------------------------------------------------------===//
1054 // Objective-C Expressions and Statements.
1055 //===----------------------------------------------------------------------===//
1057 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
1059 Record.AddStmt(E->getString());
1060 Record.AddSourceLocation(E->getAtLoc());
1061 Code = serialization::EXPR_OBJC_STRING_LITERAL;
1064 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1066 Record.AddStmt(E->getSubExpr());
1067 Record.AddDeclRef(E->getBoxingMethod());
1068 Record.AddSourceRange(E->getSourceRange());
1069 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
1072 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1074 Record.push_back(E->getNumElements());
1075 for (unsigned i = 0; i < E->getNumElements(); i++)
1076 Record.AddStmt(E->getElement(i));
1077 Record.AddDeclRef(E->getArrayWithObjectsMethod());
1078 Record.AddSourceRange(E->getSourceRange());
1079 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
1082 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1084 Record.push_back(E->getNumElements());
1085 Record.push_back(E->HasPackExpansions);
1086 for (unsigned i = 0; i < E->getNumElements(); i++) {
1087 ObjCDictionaryElement Element = E->getKeyValueElement(i);
1088 Record.AddStmt(Element.Key);
1089 Record.AddStmt(Element.Value);
1090 if (E->HasPackExpansions) {
1091 Record.AddSourceLocation(Element.EllipsisLoc);
1092 unsigned NumExpansions = 0;
1093 if (Element.NumExpansions)
1094 NumExpansions = *Element.NumExpansions + 1;
1095 Record.push_back(NumExpansions);
1099 Record.AddDeclRef(E->getDictWithObjectsMethod());
1100 Record.AddSourceRange(E->getSourceRange());
1101 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1104 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
1106 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1107 Record.AddSourceLocation(E->getAtLoc());
1108 Record.AddSourceLocation(E->getRParenLoc());
1109 Code = serialization::EXPR_OBJC_ENCODE;
1112 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
1114 Record.AddSelectorRef(E->getSelector());
1115 Record.AddSourceLocation(E->getAtLoc());
1116 Record.AddSourceLocation(E->getRParenLoc());
1117 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
1120 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
1122 Record.AddDeclRef(E->getProtocol());
1123 Record.AddSourceLocation(E->getAtLoc());
1124 Record.AddSourceLocation(E->ProtoLoc);
1125 Record.AddSourceLocation(E->getRParenLoc());
1126 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
1129 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1131 Record.AddDeclRef(E->getDecl());
1132 Record.AddSourceLocation(E->getLocation());
1133 Record.AddSourceLocation(E->getOpLoc());
1134 Record.AddStmt(E->getBase());
1135 Record.push_back(E->isArrow());
1136 Record.push_back(E->isFreeIvar());
1137 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
1140 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1142 Record.push_back(E->SetterAndMethodRefFlags.getInt());
1143 Record.push_back(E->isImplicitProperty());
1144 if (E->isImplicitProperty()) {
1145 Record.AddDeclRef(E->getImplicitPropertyGetter());
1146 Record.AddDeclRef(E->getImplicitPropertySetter());
1148 Record.AddDeclRef(E->getExplicitProperty());
1150 Record.AddSourceLocation(E->getLocation());
1151 Record.AddSourceLocation(E->getReceiverLocation());
1152 if (E->isObjectReceiver()) {
1153 Record.push_back(0);
1154 Record.AddStmt(E->getBase());
1155 } else if (E->isSuperReceiver()) {
1156 Record.push_back(1);
1157 Record.AddTypeRef(E->getSuperReceiverType());
1159 Record.push_back(2);
1160 Record.AddDeclRef(E->getClassReceiver());
1163 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
1166 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1168 Record.AddSourceLocation(E->getRBracket());
1169 Record.AddStmt(E->getBaseExpr());
1170 Record.AddStmt(E->getKeyExpr());
1171 Record.AddDeclRef(E->getAtIndexMethodDecl());
1172 Record.AddDeclRef(E->setAtIndexMethodDecl());
1174 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1177 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1179 Record.push_back(E->getNumArgs());
1180 Record.push_back(E->getNumStoredSelLocs());
1181 Record.push_back(E->SelLocsKind);
1182 Record.push_back(E->isDelegateInitCall());
1183 Record.push_back(E->IsImplicit);
1184 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1185 switch (E->getReceiverKind()) {
1186 case ObjCMessageExpr::Instance:
1187 Record.AddStmt(E->getInstanceReceiver());
1190 case ObjCMessageExpr::Class:
1191 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
1194 case ObjCMessageExpr::SuperClass:
1195 case ObjCMessageExpr::SuperInstance:
1196 Record.AddTypeRef(E->getSuperType());
1197 Record.AddSourceLocation(E->getSuperLoc());
1201 if (E->getMethodDecl()) {
1202 Record.push_back(1);
1203 Record.AddDeclRef(E->getMethodDecl());
1205 Record.push_back(0);
1206 Record.AddSelectorRef(E->getSelector());
1209 Record.AddSourceLocation(E->getLeftLoc());
1210 Record.AddSourceLocation(E->getRightLoc());
1212 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1213 Arg != ArgEnd; ++Arg)
1214 Record.AddStmt(*Arg);
1216 SourceLocation *Locs = E->getStoredSelLocs();
1217 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1218 Record.AddSourceLocation(Locs[i]);
1220 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1223 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1225 Record.AddStmt(S->getElement());
1226 Record.AddStmt(S->getCollection());
1227 Record.AddStmt(S->getBody());
1228 Record.AddSourceLocation(S->getForLoc());
1229 Record.AddSourceLocation(S->getRParenLoc());
1230 Code = serialization::STMT_OBJC_FOR_COLLECTION;
1233 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1235 Record.AddStmt(S->getCatchBody());
1236 Record.AddDeclRef(S->getCatchParamDecl());
1237 Record.AddSourceLocation(S->getAtCatchLoc());
1238 Record.AddSourceLocation(S->getRParenLoc());
1239 Code = serialization::STMT_OBJC_CATCH;
1242 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1244 Record.AddStmt(S->getFinallyBody());
1245 Record.AddSourceLocation(S->getAtFinallyLoc());
1246 Code = serialization::STMT_OBJC_FINALLY;
1249 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1250 VisitStmt(S); // FIXME: no test coverage.
1251 Record.AddStmt(S->getSubStmt());
1252 Record.AddSourceLocation(S->getAtLoc());
1253 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1256 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1258 Record.push_back(S->getNumCatchStmts());
1259 Record.push_back(S->getFinallyStmt() != nullptr);
1260 Record.AddStmt(S->getTryBody());
1261 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1262 Record.AddStmt(S->getCatchStmt(I));
1263 if (S->getFinallyStmt())
1264 Record.AddStmt(S->getFinallyStmt());
1265 Record.AddSourceLocation(S->getAtTryLoc());
1266 Code = serialization::STMT_OBJC_AT_TRY;
1269 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1270 VisitStmt(S); // FIXME: no test coverage.
1271 Record.AddStmt(S->getSynchExpr());
1272 Record.AddStmt(S->getSynchBody());
1273 Record.AddSourceLocation(S->getAtSynchronizedLoc());
1274 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1277 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1278 VisitStmt(S); // FIXME: no test coverage.
1279 Record.AddStmt(S->getThrowExpr());
1280 Record.AddSourceLocation(S->getThrowLoc());
1281 Code = serialization::STMT_OBJC_AT_THROW;
1284 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1286 Record.push_back(E->getValue());
1287 Record.AddSourceLocation(E->getLocation());
1288 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1291 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1293 Record.AddSourceRange(E->getSourceRange());
1294 Record.AddVersionTuple(E->getVersion());
1295 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1298 //===----------------------------------------------------------------------===//
1299 // C++ Expressions and Statements.
1300 //===----------------------------------------------------------------------===//
1302 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1304 Record.AddSourceLocation(S->getCatchLoc());
1305 Record.AddDeclRef(S->getExceptionDecl());
1306 Record.AddStmt(S->getHandlerBlock());
1307 Code = serialization::STMT_CXX_CATCH;
1310 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1312 Record.push_back(S->getNumHandlers());
1313 Record.AddSourceLocation(S->getTryLoc());
1314 Record.AddStmt(S->getTryBlock());
1315 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1316 Record.AddStmt(S->getHandler(i));
1317 Code = serialization::STMT_CXX_TRY;
1320 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1322 Record.AddSourceLocation(S->getForLoc());
1323 Record.AddSourceLocation(S->getCoawaitLoc());
1324 Record.AddSourceLocation(S->getColonLoc());
1325 Record.AddSourceLocation(S->getRParenLoc());
1326 Record.AddStmt(S->getInit());
1327 Record.AddStmt(S->getRangeStmt());
1328 Record.AddStmt(S->getBeginStmt());
1329 Record.AddStmt(S->getEndStmt());
1330 Record.AddStmt(S->getCond());
1331 Record.AddStmt(S->getInc());
1332 Record.AddStmt(S->getLoopVarStmt());
1333 Record.AddStmt(S->getBody());
1334 Code = serialization::STMT_CXX_FOR_RANGE;
1337 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1339 Record.AddSourceLocation(S->getKeywordLoc());
1340 Record.push_back(S->isIfExists());
1341 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1342 Record.AddDeclarationNameInfo(S->getNameInfo());
1343 Record.AddStmt(S->getSubStmt());
1344 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1347 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1349 Record.push_back(E->getOperator());
1350 Record.push_back(E->getFPFeatures().getInt());
1351 Record.AddSourceRange(E->Range);
1352 Code = serialization::EXPR_CXX_OPERATOR_CALL;
1355 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1357 Code = serialization::EXPR_CXX_MEMBER_CALL;
1360 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1363 Record.push_back(E->getNumArgs());
1364 Record.push_back(E->isElidable());
1365 Record.push_back(E->hadMultipleCandidates());
1366 Record.push_back(E->isListInitialization());
1367 Record.push_back(E->isStdInitListInitialization());
1368 Record.push_back(E->requiresZeroInitialization());
1369 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
1370 Record.AddSourceLocation(E->getLocation());
1371 Record.AddDeclRef(E->getConstructor());
1372 Record.AddSourceRange(E->getParenOrBraceRange());
1374 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1375 Record.AddStmt(E->getArg(I));
1377 Code = serialization::EXPR_CXX_CONSTRUCT;
1380 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1382 Record.AddDeclRef(E->getConstructor());
1383 Record.AddSourceLocation(E->getLocation());
1384 Record.push_back(E->constructsVBase());
1385 Record.push_back(E->inheritedFromVBase());
1386 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1389 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1390 VisitCXXConstructExpr(E);
1391 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1392 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1395 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1397 Record.push_back(E->NumCaptures);
1398 Record.AddSourceRange(E->IntroducerRange);
1399 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
1400 Record.AddSourceLocation(E->CaptureDefaultLoc);
1401 Record.push_back(E->ExplicitParams);
1402 Record.push_back(E->ExplicitResultType);
1403 Record.AddSourceLocation(E->ClosingBrace);
1405 // Add capture initializers.
1406 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1407 CEnd = E->capture_init_end();
1412 Code = serialization::EXPR_LAMBDA;
1415 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1417 Record.AddStmt(E->getSubExpr());
1418 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1421 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1422 VisitExplicitCastExpr(E);
1423 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1424 Record.AddSourceRange(E->getAngleBrackets());
1427 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1428 VisitCXXNamedCastExpr(E);
1429 Code = serialization::EXPR_CXX_STATIC_CAST;
1432 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1433 VisitCXXNamedCastExpr(E);
1434 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1437 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1438 VisitCXXNamedCastExpr(E);
1439 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1442 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1443 VisitCXXNamedCastExpr(E);
1444 Code = serialization::EXPR_CXX_CONST_CAST;
1447 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1448 VisitExplicitCastExpr(E);
1449 Record.AddSourceLocation(E->getLParenLoc());
1450 Record.AddSourceLocation(E->getRParenLoc());
1451 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1454 void ASTStmtWriter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
1455 VisitExplicitCastExpr(E);
1456 Record.AddSourceLocation(E->getBeginLoc());
1457 Record.AddSourceLocation(E->getEndLoc());
1460 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1462 Record.AddSourceLocation(E->UDSuffixLoc);
1463 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1466 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1468 Record.push_back(E->getValue());
1469 Record.AddSourceLocation(E->getLocation());
1470 Code = serialization::EXPR_CXX_BOOL_LITERAL;
1473 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1475 Record.AddSourceLocation(E->getLocation());
1476 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1479 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1481 Record.AddSourceRange(E->getSourceRange());
1482 if (E->isTypeOperand()) {
1483 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1484 Code = serialization::EXPR_CXX_TYPEID_TYPE;
1486 Record.AddStmt(E->getExprOperand());
1487 Code = serialization::EXPR_CXX_TYPEID_EXPR;
1491 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1493 Record.AddSourceLocation(E->getLocation());
1494 Record.push_back(E->isImplicit());
1495 Code = serialization::EXPR_CXX_THIS;
1498 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1500 Record.AddSourceLocation(E->getThrowLoc());
1501 Record.AddStmt(E->getSubExpr());
1502 Record.push_back(E->isThrownVariableInScope());
1503 Code = serialization::EXPR_CXX_THROW;
1506 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1508 Record.AddDeclRef(E->getParam());
1509 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1510 Record.AddSourceLocation(E->getUsedLocation());
1511 Code = serialization::EXPR_CXX_DEFAULT_ARG;
1514 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1516 Record.AddDeclRef(E->getField());
1517 Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
1518 Record.AddSourceLocation(E->getExprLoc());
1519 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1522 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1524 Record.AddCXXTemporary(E->getTemporary());
1525 Record.AddStmt(E->getSubExpr());
1526 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1529 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1531 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1532 Record.AddSourceLocation(E->getRParenLoc());
1533 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1536 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1539 Record.push_back(E->isArray());
1540 Record.push_back(E->hasInitializer());
1541 Record.push_back(E->getNumPlacementArgs());
1542 Record.push_back(E->isParenTypeId());
1544 Record.push_back(E->isGlobalNew());
1545 Record.push_back(E->passAlignment());
1546 Record.push_back(E->doesUsualArrayDeleteWantSize());
1547 Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
1549 Record.AddDeclRef(E->getOperatorNew());
1550 Record.AddDeclRef(E->getOperatorDelete());
1551 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1552 if (E->isParenTypeId())
1553 Record.AddSourceRange(E->getTypeIdParens());
1554 Record.AddSourceRange(E->getSourceRange());
1555 Record.AddSourceRange(E->getDirectInitRange());
1557 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
1561 Code = serialization::EXPR_CXX_NEW;
1564 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1566 Record.push_back(E->isGlobalDelete());
1567 Record.push_back(E->isArrayForm());
1568 Record.push_back(E->isArrayFormAsWritten());
1569 Record.push_back(E->doesUsualArrayDeleteWantSize());
1570 Record.AddDeclRef(E->getOperatorDelete());
1571 Record.AddStmt(E->getArgument());
1572 Record.AddSourceLocation(E->getBeginLoc());
1574 Code = serialization::EXPR_CXX_DELETE;
1577 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1580 Record.AddStmt(E->getBase());
1581 Record.push_back(E->isArrow());
1582 Record.AddSourceLocation(E->getOperatorLoc());
1583 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1584 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1585 Record.AddSourceLocation(E->getColonColonLoc());
1586 Record.AddSourceLocation(E->getTildeLoc());
1588 // PseudoDestructorTypeStorage.
1589 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
1590 if (E->getDestroyedTypeIdentifier())
1591 Record.AddSourceLocation(E->getDestroyedTypeLoc());
1593 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
1595 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1598 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1600 Record.push_back(E->getNumObjects());
1601 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
1602 Record.AddDeclRef(E->getObject(i));
1604 Record.push_back(E->cleanupsHaveSideEffects());
1605 Record.AddStmt(E->getSubExpr());
1606 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1609 void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
1610 CXXDependentScopeMemberExpr *E) {
1613 // Don't emit anything here (or if you do you will have to update
1614 // the corresponding deserialization function).
1616 Record.push_back(E->hasTemplateKWAndArgsInfo());
1617 Record.push_back(E->getNumTemplateArgs());
1618 Record.push_back(E->hasFirstQualifierFoundInScope());
1620 if (E->hasTemplateKWAndArgsInfo()) {
1621 const ASTTemplateKWAndArgsInfo &ArgInfo =
1622 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1623 AddTemplateKWAndArgsInfo(ArgInfo,
1624 E->getTrailingObjects<TemplateArgumentLoc>());
1627 Record.push_back(E->isArrow());
1628 Record.AddSourceLocation(E->getOperatorLoc());
1629 Record.AddTypeRef(E->getBaseType());
1630 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1631 if (!E->isImplicitAccess())
1632 Record.AddStmt(E->getBase());
1634 Record.AddStmt(nullptr);
1636 if (E->hasFirstQualifierFoundInScope())
1637 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1639 Record.AddDeclarationNameInfo(E->MemberNameInfo);
1640 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
1644 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1647 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1650 Record.push_back(E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
1651 if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
1652 const ASTTemplateKWAndArgsInfo &ArgInfo =
1653 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1654 Record.push_back(ArgInfo.NumTemplateArgs);
1655 AddTemplateKWAndArgsInfo(ArgInfo,
1656 E->getTrailingObjects<TemplateArgumentLoc>());
1659 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1660 Record.AddDeclarationNameInfo(E->NameInfo);
1661 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
1665 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1667 Record.push_back(E->arg_size());
1668 for (CXXUnresolvedConstructExpr::arg_iterator
1669 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
1670 Record.AddStmt(*ArgI);
1671 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1672 Record.AddSourceLocation(E->getLParenLoc());
1673 Record.AddSourceLocation(E->getRParenLoc());
1674 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
1677 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
1680 Record.push_back(E->getNumDecls());
1681 Record.push_back(E->hasTemplateKWAndArgsInfo());
1682 if (E->hasTemplateKWAndArgsInfo()) {
1683 const ASTTemplateKWAndArgsInfo &ArgInfo =
1684 *E->getTrailingASTTemplateKWAndArgsInfo();
1685 Record.push_back(ArgInfo.NumTemplateArgs);
1686 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
1689 for (OverloadExpr::decls_iterator OvI = E->decls_begin(),
1690 OvE = E->decls_end();
1691 OvI != OvE; ++OvI) {
1692 Record.AddDeclRef(OvI.getDecl());
1693 Record.push_back(OvI.getAccess());
1696 Record.AddDeclarationNameInfo(E->getNameInfo());
1697 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1700 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1701 VisitOverloadExpr(E);
1702 Record.push_back(E->isArrow());
1703 Record.push_back(E->hasUnresolvedUsing());
1704 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1705 Record.AddTypeRef(E->getBaseType());
1706 Record.AddSourceLocation(E->getOperatorLoc());
1707 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
1710 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1711 VisitOverloadExpr(E);
1712 Record.push_back(E->requiresADL());
1713 Record.push_back(E->isOverloaded());
1714 Record.AddDeclRef(E->getNamingClass());
1715 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
1718 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1720 Record.push_back(E->TypeTraitExprBits.NumArgs);
1721 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1722 Record.push_back(E->TypeTraitExprBits.Value);
1723 Record.AddSourceRange(E->getSourceRange());
1724 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1725 Record.AddTypeSourceInfo(E->getArg(I));
1726 Code = serialization::EXPR_TYPE_TRAIT;
1729 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1731 Record.push_back(E->getTrait());
1732 Record.push_back(E->getValue());
1733 Record.AddSourceRange(E->getSourceRange());
1734 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
1735 Record.AddStmt(E->getDimensionExpression());
1736 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1739 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1741 Record.push_back(E->getTrait());
1742 Record.push_back(E->getValue());
1743 Record.AddSourceRange(E->getSourceRange());
1744 Record.AddStmt(E->getQueriedExpression());
1745 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1748 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1750 Record.push_back(E->getValue());
1751 Record.AddSourceRange(E->getSourceRange());
1752 Record.AddStmt(E->getOperand());
1753 Code = serialization::EXPR_CXX_NOEXCEPT;
1756 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1758 Record.AddSourceLocation(E->getEllipsisLoc());
1759 Record.push_back(E->NumExpansions);
1760 Record.AddStmt(E->getPattern());
1761 Code = serialization::EXPR_PACK_EXPANSION;
1764 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1766 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1768 Record.AddSourceLocation(E->OperatorLoc);
1769 Record.AddSourceLocation(E->PackLoc);
1770 Record.AddSourceLocation(E->RParenLoc);
1771 Record.AddDeclRef(E->Pack);
1772 if (E->isPartiallySubstituted()) {
1773 for (const auto &TA : E->getPartialArguments())
1774 Record.AddTemplateArgument(TA);
1775 } else if (!E->isValueDependent()) {
1776 Record.push_back(E->getPackLength());
1778 Code = serialization::EXPR_SIZEOF_PACK;
1781 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1782 SubstNonTypeTemplateParmExpr *E) {
1784 Record.AddDeclRef(E->getParameter());
1785 Record.AddSourceLocation(E->getNameLoc());
1786 Record.AddStmt(E->getReplacement());
1787 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1790 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1791 SubstNonTypeTemplateParmPackExpr *E) {
1793 Record.AddDeclRef(E->getParameterPack());
1794 Record.AddTemplateArgument(E->getArgumentPack());
1795 Record.AddSourceLocation(E->getParameterPackLocation());
1796 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1799 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1801 Record.push_back(E->getNumExpansions());
1802 Record.AddDeclRef(E->getParameterPack());
1803 Record.AddSourceLocation(E->getParameterPackLocation());
1804 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1806 Record.AddDeclRef(*I);
1807 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1810 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1812 Record.AddStmt(E->getTemporary());
1813 Record.AddDeclRef(E->getExtendingDecl());
1814 Record.push_back(E->getManglingNumber());
1815 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1818 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1820 Record.AddSourceLocation(E->LParenLoc);
1821 Record.AddSourceLocation(E->EllipsisLoc);
1822 Record.AddSourceLocation(E->RParenLoc);
1823 Record.push_back(E->NumExpansions);
1824 Record.AddStmt(E->SubExprs[0]);
1825 Record.AddStmt(E->SubExprs[1]);
1826 Record.push_back(E->Opcode);
1827 Code = serialization::EXPR_CXX_FOLD;
1830 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1832 Record.AddStmt(E->getSourceExpr());
1833 Record.AddSourceLocation(E->getLocation());
1834 Record.push_back(E->isUnique());
1835 Code = serialization::EXPR_OPAQUE_VALUE;
1838 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1840 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
1841 llvm_unreachable("Cannot write TypoExpr nodes");
1844 //===----------------------------------------------------------------------===//
1845 // CUDA Expressions and Statements.
1846 //===----------------------------------------------------------------------===//
1848 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1850 Record.AddStmt(E->getConfig());
1851 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1854 //===----------------------------------------------------------------------===//
1855 // OpenCL Expressions and Statements.
1856 //===----------------------------------------------------------------------===//
1857 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1859 Record.AddSourceLocation(E->getBuiltinLoc());
1860 Record.AddSourceLocation(E->getRParenLoc());
1861 Record.AddStmt(E->getSrcExpr());
1862 Code = serialization::EXPR_ASTYPE;
1865 //===----------------------------------------------------------------------===//
1866 // Microsoft Expressions and Statements.
1867 //===----------------------------------------------------------------------===//
1868 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1870 Record.push_back(E->isArrow());
1871 Record.AddStmt(E->getBaseExpr());
1872 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1873 Record.AddSourceLocation(E->getMemberLoc());
1874 Record.AddDeclRef(E->getPropertyDecl());
1875 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1878 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1880 Record.AddStmt(E->getBase());
1881 Record.AddStmt(E->getIdx());
1882 Record.AddSourceLocation(E->getRBracketLoc());
1883 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1886 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1888 Record.AddSourceRange(E->getSourceRange());
1889 Record.AddString(E->getUuidStr());
1890 if (E->isTypeOperand()) {
1891 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1892 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1894 Record.AddStmt(E->getExprOperand());
1895 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1899 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1901 Record.AddSourceLocation(S->getExceptLoc());
1902 Record.AddStmt(S->getFilterExpr());
1903 Record.AddStmt(S->getBlock());
1904 Code = serialization::STMT_SEH_EXCEPT;
1907 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1909 Record.AddSourceLocation(S->getFinallyLoc());
1910 Record.AddStmt(S->getBlock());
1911 Code = serialization::STMT_SEH_FINALLY;
1914 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1916 Record.push_back(S->getIsCXXTry());
1917 Record.AddSourceLocation(S->getTryLoc());
1918 Record.AddStmt(S->getTryBlock());
1919 Record.AddStmt(S->getHandler());
1920 Code = serialization::STMT_SEH_TRY;
1923 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1925 Record.AddSourceLocation(S->getLeaveLoc());
1926 Code = serialization::STMT_SEH_LEAVE;
1929 //===----------------------------------------------------------------------===//
1930 // OpenMP Directives.
1931 //===----------------------------------------------------------------------===//
1932 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
1933 Record.AddSourceLocation(E->getBeginLoc());
1934 Record.AddSourceLocation(E->getEndLoc());
1935 OMPClauseWriter ClauseWriter(Record);
1936 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
1937 ClauseWriter.writeClause(E->getClause(i));
1939 if (E->hasAssociatedStmt())
1940 Record.AddStmt(E->getAssociatedStmt());
1943 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
1945 Record.push_back(D->getNumClauses());
1946 Record.push_back(D->getCollapsedNumber());
1947 VisitOMPExecutableDirective(D);
1948 Record.AddStmt(D->getIterationVariable());
1949 Record.AddStmt(D->getLastIteration());
1950 Record.AddStmt(D->getCalcLastIteration());
1951 Record.AddStmt(D->getPreCond());
1952 Record.AddStmt(D->getCond());
1953 Record.AddStmt(D->getInit());
1954 Record.AddStmt(D->getInc());
1955 Record.AddStmt(D->getPreInits());
1956 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
1957 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
1958 isOpenMPDistributeDirective(D->getDirectiveKind())) {
1959 Record.AddStmt(D->getIsLastIterVariable());
1960 Record.AddStmt(D->getLowerBoundVariable());
1961 Record.AddStmt(D->getUpperBoundVariable());
1962 Record.AddStmt(D->getStrideVariable());
1963 Record.AddStmt(D->getEnsureUpperBound());
1964 Record.AddStmt(D->getNextLowerBound());
1965 Record.AddStmt(D->getNextUpperBound());
1966 Record.AddStmt(D->getNumIterations());
1968 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
1969 Record.AddStmt(D->getPrevLowerBoundVariable());
1970 Record.AddStmt(D->getPrevUpperBoundVariable());
1971 Record.AddStmt(D->getDistInc());
1972 Record.AddStmt(D->getPrevEnsureUpperBound());
1973 Record.AddStmt(D->getCombinedLowerBoundVariable());
1974 Record.AddStmt(D->getCombinedUpperBoundVariable());
1975 Record.AddStmt(D->getCombinedEnsureUpperBound());
1976 Record.AddStmt(D->getCombinedInit());
1977 Record.AddStmt(D->getCombinedCond());
1978 Record.AddStmt(D->getCombinedNextLowerBound());
1979 Record.AddStmt(D->getCombinedNextUpperBound());
1980 Record.AddStmt(D->getCombinedDistCond());
1981 Record.AddStmt(D->getCombinedParForInDistCond());
1983 for (auto I : D->counters()) {
1986 for (auto I : D->private_counters()) {
1989 for (auto I : D->inits()) {
1992 for (auto I : D->updates()) {
1995 for (auto I : D->finals()) {
2000 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2002 Record.push_back(D->getNumClauses());
2003 VisitOMPExecutableDirective(D);
2004 Record.push_back(D->hasCancel() ? 1 : 0);
2005 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2008 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2009 VisitOMPLoopDirective(D);
2010 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2013 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2014 VisitOMPLoopDirective(D);
2015 Record.push_back(D->hasCancel() ? 1 : 0);
2016 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2019 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2020 VisitOMPLoopDirective(D);
2021 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2024 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2026 Record.push_back(D->getNumClauses());
2027 VisitOMPExecutableDirective(D);
2028 Record.push_back(D->hasCancel() ? 1 : 0);
2029 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2032 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2034 VisitOMPExecutableDirective(D);
2035 Record.push_back(D->hasCancel() ? 1 : 0);
2036 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2039 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2041 Record.push_back(D->getNumClauses());
2042 VisitOMPExecutableDirective(D);
2043 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2046 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2048 VisitOMPExecutableDirective(D);
2049 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2052 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2054 Record.push_back(D->getNumClauses());
2055 VisitOMPExecutableDirective(D);
2056 Record.AddDeclarationNameInfo(D->getDirectiveName());
2057 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2060 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2061 VisitOMPLoopDirective(D);
2062 Record.push_back(D->hasCancel() ? 1 : 0);
2063 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2066 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2067 OMPParallelForSimdDirective *D) {
2068 VisitOMPLoopDirective(D);
2069 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2072 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2073 OMPParallelSectionsDirective *D) {
2075 Record.push_back(D->getNumClauses());
2076 VisitOMPExecutableDirective(D);
2077 Record.push_back(D->hasCancel() ? 1 : 0);
2078 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2081 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2083 Record.push_back(D->getNumClauses());
2084 VisitOMPExecutableDirective(D);
2085 Record.push_back(D->hasCancel() ? 1 : 0);
2086 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2089 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2091 Record.push_back(D->getNumClauses());
2092 VisitOMPExecutableDirective(D);
2093 Record.AddStmt(D->getX());
2094 Record.AddStmt(D->getV());
2095 Record.AddStmt(D->getExpr());
2096 Record.AddStmt(D->getUpdateExpr());
2097 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
2098 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
2099 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2102 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2104 Record.push_back(D->getNumClauses());
2105 VisitOMPExecutableDirective(D);
2106 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2109 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2111 Record.push_back(D->getNumClauses());
2112 VisitOMPExecutableDirective(D);
2113 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2116 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2117 OMPTargetEnterDataDirective *D) {
2119 Record.push_back(D->getNumClauses());
2120 VisitOMPExecutableDirective(D);
2121 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2124 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2125 OMPTargetExitDataDirective *D) {
2127 Record.push_back(D->getNumClauses());
2128 VisitOMPExecutableDirective(D);
2129 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2132 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2133 OMPTargetParallelDirective *D) {
2135 Record.push_back(D->getNumClauses());
2136 VisitOMPExecutableDirective(D);
2137 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2140 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2141 OMPTargetParallelForDirective *D) {
2142 VisitOMPLoopDirective(D);
2143 Record.push_back(D->hasCancel() ? 1 : 0);
2144 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2147 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2149 VisitOMPExecutableDirective(D);
2150 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2153 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2155 VisitOMPExecutableDirective(D);
2156 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2159 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2161 VisitOMPExecutableDirective(D);
2162 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2165 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2167 Record.push_back(D->getNumClauses());
2168 VisitOMPExecutableDirective(D);
2169 Record.AddStmt(D->getReductionRef());
2170 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2173 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2175 Record.push_back(D->getNumClauses());
2176 VisitOMPExecutableDirective(D);
2177 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2180 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2182 Record.push_back(D->getNumClauses());
2183 VisitOMPExecutableDirective(D);
2184 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2187 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2189 Record.push_back(D->getNumClauses());
2190 VisitOMPExecutableDirective(D);
2191 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2194 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2195 OMPCancellationPointDirective *D) {
2197 VisitOMPExecutableDirective(D);
2198 Record.push_back(D->getCancelRegion());
2199 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2202 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2204 Record.push_back(D->getNumClauses());
2205 VisitOMPExecutableDirective(D);
2206 Record.push_back(D->getCancelRegion());
2207 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2210 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2211 VisitOMPLoopDirective(D);
2212 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2215 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2216 VisitOMPLoopDirective(D);
2217 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2220 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2221 VisitOMPLoopDirective(D);
2222 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2225 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2227 Record.push_back(D->getNumClauses());
2228 VisitOMPExecutableDirective(D);
2229 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2232 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2233 OMPDistributeParallelForDirective *D) {
2234 VisitOMPLoopDirective(D);
2235 Record.push_back(D->hasCancel() ? 1 : 0);
2236 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2239 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2240 OMPDistributeParallelForSimdDirective *D) {
2241 VisitOMPLoopDirective(D);
2242 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2245 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2246 OMPDistributeSimdDirective *D) {
2247 VisitOMPLoopDirective(D);
2248 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2251 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2252 OMPTargetParallelForSimdDirective *D) {
2253 VisitOMPLoopDirective(D);
2254 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2257 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2258 VisitOMPLoopDirective(D);
2259 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2262 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2263 OMPTeamsDistributeDirective *D) {
2264 VisitOMPLoopDirective(D);
2265 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2268 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2269 OMPTeamsDistributeSimdDirective *D) {
2270 VisitOMPLoopDirective(D);
2271 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2274 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2275 OMPTeamsDistributeParallelForSimdDirective *D) {
2276 VisitOMPLoopDirective(D);
2277 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2280 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2281 OMPTeamsDistributeParallelForDirective *D) {
2282 VisitOMPLoopDirective(D);
2283 Record.push_back(D->hasCancel() ? 1 : 0);
2284 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2287 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2289 Record.push_back(D->getNumClauses());
2290 VisitOMPExecutableDirective(D);
2291 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2294 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2295 OMPTargetTeamsDistributeDirective *D) {
2296 VisitOMPLoopDirective(D);
2297 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2300 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2301 OMPTargetTeamsDistributeParallelForDirective *D) {
2302 VisitOMPLoopDirective(D);
2303 Record.push_back(D->hasCancel() ? 1 : 0);
2304 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2307 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2308 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2309 VisitOMPLoopDirective(D);
2310 Code = serialization::
2311 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2314 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2315 OMPTargetTeamsDistributeSimdDirective *D) {
2316 VisitOMPLoopDirective(D);
2317 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2320 //===----------------------------------------------------------------------===//
2321 // ASTWriter Implementation
2322 //===----------------------------------------------------------------------===//
2324 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2325 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
2326 "SwitchCase recorded twice");
2327 unsigned NextID = SwitchCaseIDs.size();
2328 SwitchCaseIDs[S] = NextID;
2332 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2333 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
2334 "SwitchCase hasn't been seen yet");
2335 return SwitchCaseIDs[S];
2338 void ASTWriter::ClearSwitchCaseIDs() {
2339 SwitchCaseIDs.clear();
2342 /// Write the given substatement or subexpression to the
2344 void ASTWriter::WriteSubStmt(Stmt *S) {
2346 ASTStmtWriter Writer(*this, Record);
2350 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2354 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2355 if (I != SubStmtEntries.end()) {
2356 Record.push_back(I->second);
2357 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2362 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2364 struct ParentStmtInserterRAII {
2366 llvm::DenseSet<Stmt *> &ParentStmts;
2368 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2369 : S(S), ParentStmts(ParentStmts) {
2370 ParentStmts.insert(S);
2372 ~ParentStmtInserterRAII() {
2373 ParentStmts.erase(S);
2377 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2382 uint64_t Offset = Writer.Emit();
2383 SubStmtEntries[S] = Offset;
2386 /// Flush all of the statements that have been added to the
2387 /// queue via AddStmt().
2388 void ASTRecordWriter::FlushStmts() {
2389 // We expect to be the only consumer of the two temporary statement maps,
2390 // assert that they are empty.
2391 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2392 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2394 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2395 Writer->WriteSubStmt(StmtsToEmit[I]);
2397 assert(N == StmtsToEmit.size() && "record modified while being written!");
2399 // Note that we are at the end of a full expression. Any
2400 // expression records that follow this one are part of a different
2402 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2404 Writer->SubStmtEntries.clear();
2405 Writer->ParentStmts.clear();
2408 StmtsToEmit.clear();
2411 void ASTRecordWriter::FlushSubStmts() {
2412 // For a nested statement, write out the substatements in reverse order (so
2413 // that a simple stack machine can be used when loading), and don't emit a
2414 // STMT_STOP after each one.
2415 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2416 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
2417 assert(N == StmtsToEmit.size() && "record modified while being written!");
2420 StmtsToEmit.clear();