1 //===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Implements serialization for Statements and Expressions.
13 //===----------------------------------------------------------------------===//
15 #include "clang/Serialization/ASTWriter.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/Bitcode/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) {
73 void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
75 Record.AddSourceLocation(S->getSemiLoc());
76 Record.push_back(S->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.AddStmt(S->getLHS());
100 Record.AddStmt(S->getRHS());
101 Record.AddStmt(S->getSubStmt());
102 Record.AddSourceLocation(S->getEllipsisLoc());
103 Code = serialization::STMT_CASE;
106 void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
108 Record.AddStmt(S->getSubStmt());
109 Code = serialization::STMT_DEFAULT;
112 void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
114 Record.AddDeclRef(S->getDecl());
115 Record.AddStmt(S->getSubStmt());
116 Record.AddSourceLocation(S->getIdentLoc());
117 Code = serialization::STMT_LABEL;
120 void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
122 Record.push_back(S->getAttrs().size());
123 Record.AddAttributes(S->getAttrs());
124 Record.AddStmt(S->getSubStmt());
125 Record.AddSourceLocation(S->getAttrLoc());
126 Code = serialization::STMT_ATTRIBUTED;
129 void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
131 Record.push_back(S->isConstexpr());
132 Record.AddStmt(S->getInit());
133 Record.AddDeclRef(S->getConditionVariable());
134 Record.AddStmt(S->getCond());
135 Record.AddStmt(S->getThen());
136 Record.AddStmt(S->getElse());
137 Record.AddSourceLocation(S->getIfLoc());
138 Record.AddSourceLocation(S->getElseLoc());
139 Code = serialization::STMT_IF;
142 void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
144 Record.AddStmt(S->getInit());
145 Record.AddDeclRef(S->getConditionVariable());
146 Record.AddStmt(S->getCond());
147 Record.AddStmt(S->getBody());
148 Record.AddSourceLocation(S->getSwitchLoc());
149 Record.push_back(S->isAllEnumCasesCovered());
150 for (SwitchCase *SC = S->getSwitchCaseList(); SC;
151 SC = SC->getNextSwitchCase())
152 Record.push_back(Writer.RecordSwitchCaseID(SC));
153 Code = serialization::STMT_SWITCH;
156 void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
158 Record.AddDeclRef(S->getConditionVariable());
159 Record.AddStmt(S->getCond());
160 Record.AddStmt(S->getBody());
161 Record.AddSourceLocation(S->getWhileLoc());
162 Code = serialization::STMT_WHILE;
165 void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
167 Record.AddStmt(S->getCond());
168 Record.AddStmt(S->getBody());
169 Record.AddSourceLocation(S->getDoLoc());
170 Record.AddSourceLocation(S->getWhileLoc());
171 Record.AddSourceLocation(S->getRParenLoc());
172 Code = serialization::STMT_DO;
175 void ASTStmtWriter::VisitForStmt(ForStmt *S) {
177 Record.AddStmt(S->getInit());
178 Record.AddStmt(S->getCond());
179 Record.AddDeclRef(S->getConditionVariable());
180 Record.AddStmt(S->getInc());
181 Record.AddStmt(S->getBody());
182 Record.AddSourceLocation(S->getForLoc());
183 Record.AddSourceLocation(S->getLParenLoc());
184 Record.AddSourceLocation(S->getRParenLoc());
185 Code = serialization::STMT_FOR;
188 void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
190 Record.AddDeclRef(S->getLabel());
191 Record.AddSourceLocation(S->getGotoLoc());
192 Record.AddSourceLocation(S->getLabelLoc());
193 Code = serialization::STMT_GOTO;
196 void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
198 Record.AddSourceLocation(S->getGotoLoc());
199 Record.AddSourceLocation(S->getStarLoc());
200 Record.AddStmt(S->getTarget());
201 Code = serialization::STMT_INDIRECT_GOTO;
204 void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
206 Record.AddSourceLocation(S->getContinueLoc());
207 Code = serialization::STMT_CONTINUE;
210 void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
212 Record.AddSourceLocation(S->getBreakLoc());
213 Code = serialization::STMT_BREAK;
216 void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
218 Record.AddStmt(S->getRetValue());
219 Record.AddSourceLocation(S->getReturnLoc());
220 Record.AddDeclRef(S->getNRVOCandidate());
221 Code = serialization::STMT_RETURN;
224 void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
226 Record.AddSourceLocation(S->getStartLoc());
227 Record.AddSourceLocation(S->getEndLoc());
228 DeclGroupRef DG = S->getDeclGroup();
229 for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
230 Record.AddDeclRef(*D);
231 Code = serialization::STMT_DECL;
234 void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
236 Record.push_back(S->getNumOutputs());
237 Record.push_back(S->getNumInputs());
238 Record.push_back(S->getNumClobbers());
239 Record.AddSourceLocation(S->getAsmLoc());
240 Record.push_back(S->isVolatile());
241 Record.push_back(S->isSimple());
244 void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
246 Record.AddSourceLocation(S->getRParenLoc());
247 Record.AddStmt(S->getAsmString());
250 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
251 Record.AddIdentifierRef(S->getOutputIdentifier(I));
252 Record.AddStmt(S->getOutputConstraintLiteral(I));
253 Record.AddStmt(S->getOutputExpr(I));
257 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
258 Record.AddIdentifierRef(S->getInputIdentifier(I));
259 Record.AddStmt(S->getInputConstraintLiteral(I));
260 Record.AddStmt(S->getInputExpr(I));
264 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
265 Record.AddStmt(S->getClobberStringLiteral(I));
267 Code = serialization::STMT_GCCASM;
270 void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
272 Record.AddSourceLocation(S->getLBraceLoc());
273 Record.AddSourceLocation(S->getEndLoc());
274 Record.push_back(S->getNumAsmToks());
275 Record.AddString(S->getAsmString());
278 for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
279 // FIXME: Move this to ASTRecordWriter?
280 Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
284 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
285 Record.AddString(S->getClobber(I));
289 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
290 Record.AddStmt(S->getOutputExpr(I));
291 Record.AddString(S->getOutputConstraint(I));
295 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
296 Record.AddStmt(S->getInputExpr(I));
297 Record.AddString(S->getInputConstraint(I));
300 Code = serialization::STMT_MSASM;
303 void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
305 Record.push_back(CoroStmt->getParamMoves().size());
306 for (Stmt *S : CoroStmt->children())
308 Code = serialization::STMT_COROUTINE_BODY;
311 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
313 Record.AddSourceLocation(S->getKeywordLoc());
314 Record.AddStmt(S->getOperand());
315 Record.AddStmt(S->getPromiseCall());
316 Record.push_back(S->isImplicit());
317 Code = serialization::STMT_CORETURN;
320 void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
322 Record.AddSourceLocation(E->getKeywordLoc());
323 for (Stmt *S : E->children())
325 Record.AddStmt(E->getOpaqueValue());
328 void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
329 VisitCoroutineSuspendExpr(E);
330 Record.push_back(E->isImplicit());
331 Code = serialization::EXPR_COAWAIT;
334 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
335 VisitCoroutineSuspendExpr(E);
336 Code = serialization::EXPR_COYIELD;
339 void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
341 Record.AddSourceLocation(E->getKeywordLoc());
342 for (Stmt *S : E->children())
344 Code = serialization::EXPR_DEPENDENT_COAWAIT;
347 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
350 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
352 // CapturedDecl and captured region kind
353 Record.AddDeclRef(S->getCapturedDecl());
354 Record.push_back(S->getCapturedRegionKind());
356 Record.AddDeclRef(S->getCapturedRecordDecl());
359 for (auto *I : S->capture_inits())
363 Record.AddStmt(S->getCapturedStmt());
366 for (const auto &I : S->captures()) {
367 if (I.capturesThis() || I.capturesVariableArrayType())
368 Record.AddDeclRef(nullptr);
370 Record.AddDeclRef(I.getCapturedVar());
371 Record.push_back(I.getCaptureKind());
372 Record.AddSourceLocation(I.getLocation());
375 Code = serialization::STMT_CAPTURED;
378 void ASTStmtWriter::VisitExpr(Expr *E) {
380 Record.AddTypeRef(E->getType());
381 Record.push_back(E->isTypeDependent());
382 Record.push_back(E->isValueDependent());
383 Record.push_back(E->isInstantiationDependent());
384 Record.push_back(E->containsUnexpandedParameterPack());
385 Record.push_back(E->getValueKind());
386 Record.push_back(E->getObjectKind());
389 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
391 Record.AddSourceLocation(E->getLocation());
392 Record.push_back(E->getIdentType()); // FIXME: stable encoding
393 Record.AddStmt(E->getFunctionName());
394 Code = serialization::EXPR_PREDEFINED;
397 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
400 Record.push_back(E->hasQualifier());
401 Record.push_back(E->getDecl() != E->getFoundDecl());
402 Record.push_back(E->hasTemplateKWAndArgsInfo());
403 Record.push_back(E->hadMultipleCandidates());
404 Record.push_back(E->refersToEnclosingVariableOrCapture());
406 if (E->hasTemplateKWAndArgsInfo()) {
407 unsigned NumTemplateArgs = E->getNumTemplateArgs();
408 Record.push_back(NumTemplateArgs);
411 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
413 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
414 (E->getDecl() == E->getFoundDecl()) &&
415 nk == DeclarationName::Identifier) {
416 AbbrevToUse = Writer.getDeclRefExprAbbrev();
419 if (E->hasQualifier())
420 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
422 if (E->getDecl() != E->getFoundDecl())
423 Record.AddDeclRef(E->getFoundDecl());
425 if (E->hasTemplateKWAndArgsInfo())
426 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
427 E->getTrailingObjects<TemplateArgumentLoc>());
429 Record.AddDeclRef(E->getDecl());
430 Record.AddSourceLocation(E->getLocation());
431 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
432 Code = serialization::EXPR_DECL_REF;
435 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
437 Record.AddSourceLocation(E->getLocation());
438 Record.AddAPInt(E->getValue());
440 if (E->getValue().getBitWidth() == 32) {
441 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
444 Code = serialization::EXPR_INTEGER_LITERAL;
447 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
449 Record.AddSourceLocation(E->getLocation());
450 Record.AddAPInt(E->getValue());
451 Code = serialization::EXPR_INTEGER_LITERAL;
454 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
456 Record.push_back(E->getRawSemantics());
457 Record.push_back(E->isExact());
458 Record.AddAPFloat(E->getValue());
459 Record.AddSourceLocation(E->getLocation());
460 Code = serialization::EXPR_FLOATING_LITERAL;
463 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
465 Record.AddStmt(E->getSubExpr());
466 Code = serialization::EXPR_IMAGINARY_LITERAL;
469 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
471 Record.push_back(E->getByteLength());
472 Record.push_back(E->getNumConcatenated());
473 Record.push_back(E->getKind());
474 Record.push_back(E->isPascal());
475 // FIXME: String data should be stored as a blob at the end of the
476 // StringLiteral. However, we can't do so now because we have no
477 // provision for coping with abbreviations when we're jumping around
478 // the AST file during deserialization.
479 Record.append(E->getBytes().begin(), E->getBytes().end());
480 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
481 Record.AddSourceLocation(E->getStrTokenLoc(I));
482 Code = serialization::EXPR_STRING_LITERAL;
485 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
487 Record.push_back(E->getValue());
488 Record.AddSourceLocation(E->getLocation());
489 Record.push_back(E->getKind());
491 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
493 Code = serialization::EXPR_CHARACTER_LITERAL;
496 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
498 Record.AddSourceLocation(E->getLParen());
499 Record.AddSourceLocation(E->getRParen());
500 Record.AddStmt(E->getSubExpr());
501 Code = serialization::EXPR_PAREN;
504 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
506 Record.push_back(E->NumExprs);
507 for (unsigned i=0; i != E->NumExprs; ++i)
508 Record.AddStmt(E->Exprs[i]);
509 Record.AddSourceLocation(E->LParenLoc);
510 Record.AddSourceLocation(E->RParenLoc);
511 Code = serialization::EXPR_PAREN_LIST;
514 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
516 Record.AddStmt(E->getSubExpr());
517 Record.push_back(E->getOpcode()); // FIXME: stable encoding
518 Record.AddSourceLocation(E->getOperatorLoc());
519 Record.push_back(E->canOverflow());
520 Code = serialization::EXPR_UNARY_OPERATOR;
523 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
525 Record.push_back(E->getNumComponents());
526 Record.push_back(E->getNumExpressions());
527 Record.AddSourceLocation(E->getOperatorLoc());
528 Record.AddSourceLocation(E->getRParenLoc());
529 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
530 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
531 const OffsetOfNode &ON = E->getComponent(I);
532 Record.push_back(ON.getKind()); // FIXME: Stable encoding
533 Record.AddSourceLocation(ON.getSourceRange().getBegin());
534 Record.AddSourceLocation(ON.getSourceRange().getEnd());
535 switch (ON.getKind()) {
536 case OffsetOfNode::Array:
537 Record.push_back(ON.getArrayExprIndex());
540 case OffsetOfNode::Field:
541 Record.AddDeclRef(ON.getField());
544 case OffsetOfNode::Identifier:
545 Record.AddIdentifierRef(ON.getFieldName());
548 case OffsetOfNode::Base:
549 Record.AddCXXBaseSpecifier(*ON.getBase());
553 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
554 Record.AddStmt(E->getIndexExpr(I));
555 Code = serialization::EXPR_OFFSETOF;
558 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
560 Record.push_back(E->getKind());
561 if (E->isArgumentType())
562 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
565 Record.AddStmt(E->getArgumentExpr());
567 Record.AddSourceLocation(E->getOperatorLoc());
568 Record.AddSourceLocation(E->getRParenLoc());
569 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
572 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
574 Record.AddStmt(E->getLHS());
575 Record.AddStmt(E->getRHS());
576 Record.AddSourceLocation(E->getRBracketLoc());
577 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
580 void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
582 Record.AddStmt(E->getBase());
583 Record.AddStmt(E->getLowerBound());
584 Record.AddStmt(E->getLength());
585 Record.AddSourceLocation(E->getColonLoc());
586 Record.AddSourceLocation(E->getRBracketLoc());
587 Code = serialization::EXPR_OMP_ARRAY_SECTION;
590 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
592 Record.push_back(E->getNumArgs());
593 Record.AddSourceLocation(E->getRParenLoc());
594 Record.AddStmt(E->getCallee());
595 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
596 Arg != ArgEnd; ++Arg)
597 Record.AddStmt(*Arg);
598 Code = serialization::EXPR_CALL;
601 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
602 // Don't call VisitExpr, we'll write everything here.
604 Record.push_back(E->hasQualifier());
605 if (E->hasQualifier())
606 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
608 Record.push_back(E->HasTemplateKWAndArgsInfo);
609 if (E->HasTemplateKWAndArgsInfo) {
610 Record.AddSourceLocation(E->getTemplateKeywordLoc());
611 unsigned NumTemplateArgs = E->getNumTemplateArgs();
612 Record.push_back(NumTemplateArgs);
613 Record.AddSourceLocation(E->getLAngleLoc());
614 Record.AddSourceLocation(E->getRAngleLoc());
615 for (unsigned i=0; i != NumTemplateArgs; ++i)
616 Record.AddTemplateArgumentLoc(E->getTemplateArgs()[i]);
619 Record.push_back(E->hadMultipleCandidates());
621 DeclAccessPair FoundDecl = E->getFoundDecl();
622 Record.AddDeclRef(FoundDecl.getDecl());
623 Record.push_back(FoundDecl.getAccess());
625 Record.AddTypeRef(E->getType());
626 Record.push_back(E->getValueKind());
627 Record.push_back(E->getObjectKind());
628 Record.AddStmt(E->getBase());
629 Record.AddDeclRef(E->getMemberDecl());
630 Record.AddSourceLocation(E->getMemberLoc());
631 Record.push_back(E->isArrow());
632 Record.AddSourceLocation(E->getOperatorLoc());
633 Record.AddDeclarationNameLoc(E->MemberDNLoc,
634 E->getMemberDecl()->getDeclName());
635 Code = serialization::EXPR_MEMBER;
638 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
640 Record.AddStmt(E->getBase());
641 Record.AddSourceLocation(E->getIsaMemberLoc());
642 Record.AddSourceLocation(E->getOpLoc());
643 Record.push_back(E->isArrow());
644 Code = serialization::EXPR_OBJC_ISA;
648 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
650 Record.AddStmt(E->getSubExpr());
651 Record.push_back(E->shouldCopy());
652 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
655 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
656 VisitExplicitCastExpr(E);
657 Record.AddSourceLocation(E->getLParenLoc());
658 Record.AddSourceLocation(E->getBridgeKeywordLoc());
659 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
660 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
663 void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
665 Record.push_back(E->path_size());
666 Record.AddStmt(E->getSubExpr());
667 Record.push_back(E->getCastKind()); // FIXME: stable encoding
669 for (CastExpr::path_iterator
670 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
671 Record.AddCXXBaseSpecifier(**PI);
674 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
676 Record.AddStmt(E->getLHS());
677 Record.AddStmt(E->getRHS());
678 Record.push_back(E->getOpcode()); // FIXME: stable encoding
679 Record.AddSourceLocation(E->getOperatorLoc());
680 Record.push_back(E->getFPFeatures().getInt());
681 Code = serialization::EXPR_BINARY_OPERATOR;
684 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
685 VisitBinaryOperator(E);
686 Record.AddTypeRef(E->getComputationLHSType());
687 Record.AddTypeRef(E->getComputationResultType());
688 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
691 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
693 Record.AddStmt(E->getCond());
694 Record.AddStmt(E->getLHS());
695 Record.AddStmt(E->getRHS());
696 Record.AddSourceLocation(E->getQuestionLoc());
697 Record.AddSourceLocation(E->getColonLoc());
698 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
702 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
704 Record.AddStmt(E->getOpaqueValue());
705 Record.AddStmt(E->getCommon());
706 Record.AddStmt(E->getCond());
707 Record.AddStmt(E->getTrueExpr());
708 Record.AddStmt(E->getFalseExpr());
709 Record.AddSourceLocation(E->getQuestionLoc());
710 Record.AddSourceLocation(E->getColonLoc());
711 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
714 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
716 Record.push_back(E->isPartOfExplicitCast());
718 if (E->path_size() == 0)
719 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
721 Code = serialization::EXPR_IMPLICIT_CAST;
724 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
726 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
729 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
730 VisitExplicitCastExpr(E);
731 Record.AddSourceLocation(E->getLParenLoc());
732 Record.AddSourceLocation(E->getRParenLoc());
733 Code = serialization::EXPR_CSTYLE_CAST;
736 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
738 Record.AddSourceLocation(E->getLParenLoc());
739 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
740 Record.AddStmt(E->getInitializer());
741 Record.push_back(E->isFileScope());
742 Code = serialization::EXPR_COMPOUND_LITERAL;
745 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
747 Record.AddStmt(E->getBase());
748 Record.AddIdentifierRef(&E->getAccessor());
749 Record.AddSourceLocation(E->getAccessorLoc());
750 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
753 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
755 // NOTE: only add the (possibly null) syntactic form.
756 // No need to serialize the isSemanticForm flag and the semantic form.
757 Record.AddStmt(E->getSyntacticForm());
758 Record.AddSourceLocation(E->getLBraceLoc());
759 Record.AddSourceLocation(E->getRBraceLoc());
760 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
761 Record.push_back(isArrayFiller);
763 Record.AddStmt(E->getArrayFiller());
765 Record.AddDeclRef(E->getInitializedFieldInUnion());
766 Record.push_back(E->hadArrayRangeDesignator());
767 Record.push_back(E->getNumInits());
769 // ArrayFiller may have filled "holes" due to designated initializer.
770 // Replace them by 0 to indicate that the filler goes in that place.
771 Expr *filler = E->getArrayFiller();
772 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
773 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
775 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
776 Record.AddStmt(E->getInit(I));
778 Code = serialization::EXPR_INIT_LIST;
781 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
783 Record.push_back(E->getNumSubExprs());
784 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
785 Record.AddStmt(E->getSubExpr(I));
786 Record.AddSourceLocation(E->getEqualOrColonLoc());
787 Record.push_back(E->usesGNUSyntax());
788 for (const DesignatedInitExpr::Designator &D : E->designators()) {
789 if (D.isFieldDesignator()) {
790 if (FieldDecl *Field = D.getField()) {
791 Record.push_back(serialization::DESIG_FIELD_DECL);
792 Record.AddDeclRef(Field);
794 Record.push_back(serialization::DESIG_FIELD_NAME);
795 Record.AddIdentifierRef(D.getFieldName());
797 Record.AddSourceLocation(D.getDotLoc());
798 Record.AddSourceLocation(D.getFieldLoc());
799 } else if (D.isArrayDesignator()) {
800 Record.push_back(serialization::DESIG_ARRAY);
801 Record.push_back(D.getFirstExprIndex());
802 Record.AddSourceLocation(D.getLBracketLoc());
803 Record.AddSourceLocation(D.getRBracketLoc());
805 assert(D.isArrayRangeDesignator() && "Unknown designator");
806 Record.push_back(serialization::DESIG_ARRAY_RANGE);
807 Record.push_back(D.getFirstExprIndex());
808 Record.AddSourceLocation(D.getLBracketLoc());
809 Record.AddSourceLocation(D.getEllipsisLoc());
810 Record.AddSourceLocation(D.getRBracketLoc());
813 Code = serialization::EXPR_DESIGNATED_INIT;
816 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
818 Record.AddStmt(E->getBase());
819 Record.AddStmt(E->getUpdater());
820 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
823 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
825 Code = serialization::EXPR_NO_INIT;
828 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
830 Record.AddStmt(E->SubExprs[0]);
831 Record.AddStmt(E->SubExprs[1]);
832 Code = serialization::EXPR_ARRAY_INIT_LOOP;
835 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
837 Code = serialization::EXPR_ARRAY_INIT_INDEX;
840 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
842 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
845 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
847 Record.AddStmt(E->getSubExpr());
848 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
849 Record.AddSourceLocation(E->getBuiltinLoc());
850 Record.AddSourceLocation(E->getRParenLoc());
851 Record.push_back(E->isMicrosoftABI());
852 Code = serialization::EXPR_VA_ARG;
855 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
857 Record.AddSourceLocation(E->getAmpAmpLoc());
858 Record.AddSourceLocation(E->getLabelLoc());
859 Record.AddDeclRef(E->getLabel());
860 Code = serialization::EXPR_ADDR_LABEL;
863 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
865 Record.AddStmt(E->getSubStmt());
866 Record.AddSourceLocation(E->getLParenLoc());
867 Record.AddSourceLocation(E->getRParenLoc());
868 Code = serialization::EXPR_STMT;
871 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
873 Record.AddStmt(E->getCond());
874 Record.AddStmt(E->getLHS());
875 Record.AddStmt(E->getRHS());
876 Record.AddSourceLocation(E->getBuiltinLoc());
877 Record.AddSourceLocation(E->getRParenLoc());
878 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
879 Code = serialization::EXPR_CHOOSE;
882 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
884 Record.AddSourceLocation(E->getTokenLocation());
885 Code = serialization::EXPR_GNU_NULL;
888 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
890 Record.push_back(E->getNumSubExprs());
891 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
892 Record.AddStmt(E->getExpr(I));
893 Record.AddSourceLocation(E->getBuiltinLoc());
894 Record.AddSourceLocation(E->getRParenLoc());
895 Code = serialization::EXPR_SHUFFLE_VECTOR;
898 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
900 Record.AddSourceLocation(E->getBuiltinLoc());
901 Record.AddSourceLocation(E->getRParenLoc());
902 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
903 Record.AddStmt(E->getSrcExpr());
904 Code = serialization::EXPR_CONVERT_VECTOR;
907 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
909 Record.AddDeclRef(E->getBlockDecl());
910 Code = serialization::EXPR_BLOCK;
913 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
915 Record.push_back(E->getNumAssocs());
917 Record.AddStmt(E->getControllingExpr());
918 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
919 Record.AddTypeSourceInfo(E->getAssocTypeSourceInfo(I));
920 Record.AddStmt(E->getAssocExpr(I));
922 Record.push_back(E->isResultDependent() ? -1U : E->getResultIndex());
924 Record.AddSourceLocation(E->getGenericLoc());
925 Record.AddSourceLocation(E->getDefaultLoc());
926 Record.AddSourceLocation(E->getRParenLoc());
927 Code = serialization::EXPR_GENERIC_SELECTION;
930 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
932 Record.push_back(E->getNumSemanticExprs());
934 // Push the result index. Currently, this needs to exactly match
935 // the encoding used internally for ResultIndex.
936 unsigned result = E->getResultExprIndex();
937 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
938 Record.push_back(result);
940 Record.AddStmt(E->getSyntacticForm());
941 for (PseudoObjectExpr::semantics_iterator
942 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
945 Code = serialization::EXPR_PSEUDO_OBJECT;
948 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
950 Record.push_back(E->getOp());
951 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
952 Record.AddStmt(E->getSubExprs()[I]);
953 Record.AddSourceLocation(E->getBuiltinLoc());
954 Record.AddSourceLocation(E->getRParenLoc());
955 Code = serialization::EXPR_ATOMIC;
958 //===----------------------------------------------------------------------===//
959 // Objective-C Expressions and Statements.
960 //===----------------------------------------------------------------------===//
962 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
964 Record.AddStmt(E->getString());
965 Record.AddSourceLocation(E->getAtLoc());
966 Code = serialization::EXPR_OBJC_STRING_LITERAL;
969 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
971 Record.AddStmt(E->getSubExpr());
972 Record.AddDeclRef(E->getBoxingMethod());
973 Record.AddSourceRange(E->getSourceRange());
974 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
977 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
979 Record.push_back(E->getNumElements());
980 for (unsigned i = 0; i < E->getNumElements(); i++)
981 Record.AddStmt(E->getElement(i));
982 Record.AddDeclRef(E->getArrayWithObjectsMethod());
983 Record.AddSourceRange(E->getSourceRange());
984 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
987 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
989 Record.push_back(E->getNumElements());
990 Record.push_back(E->HasPackExpansions);
991 for (unsigned i = 0; i < E->getNumElements(); i++) {
992 ObjCDictionaryElement Element = E->getKeyValueElement(i);
993 Record.AddStmt(Element.Key);
994 Record.AddStmt(Element.Value);
995 if (E->HasPackExpansions) {
996 Record.AddSourceLocation(Element.EllipsisLoc);
997 unsigned NumExpansions = 0;
998 if (Element.NumExpansions)
999 NumExpansions = *Element.NumExpansions + 1;
1000 Record.push_back(NumExpansions);
1004 Record.AddDeclRef(E->getDictWithObjectsMethod());
1005 Record.AddSourceRange(E->getSourceRange());
1006 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1009 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
1011 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1012 Record.AddSourceLocation(E->getAtLoc());
1013 Record.AddSourceLocation(E->getRParenLoc());
1014 Code = serialization::EXPR_OBJC_ENCODE;
1017 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
1019 Record.AddSelectorRef(E->getSelector());
1020 Record.AddSourceLocation(E->getAtLoc());
1021 Record.AddSourceLocation(E->getRParenLoc());
1022 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
1025 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
1027 Record.AddDeclRef(E->getProtocol());
1028 Record.AddSourceLocation(E->getAtLoc());
1029 Record.AddSourceLocation(E->ProtoLoc);
1030 Record.AddSourceLocation(E->getRParenLoc());
1031 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
1034 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1036 Record.AddDeclRef(E->getDecl());
1037 Record.AddSourceLocation(E->getLocation());
1038 Record.AddSourceLocation(E->getOpLoc());
1039 Record.AddStmt(E->getBase());
1040 Record.push_back(E->isArrow());
1041 Record.push_back(E->isFreeIvar());
1042 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
1045 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1047 Record.push_back(E->SetterAndMethodRefFlags.getInt());
1048 Record.push_back(E->isImplicitProperty());
1049 if (E->isImplicitProperty()) {
1050 Record.AddDeclRef(E->getImplicitPropertyGetter());
1051 Record.AddDeclRef(E->getImplicitPropertySetter());
1053 Record.AddDeclRef(E->getExplicitProperty());
1055 Record.AddSourceLocation(E->getLocation());
1056 Record.AddSourceLocation(E->getReceiverLocation());
1057 if (E->isObjectReceiver()) {
1058 Record.push_back(0);
1059 Record.AddStmt(E->getBase());
1060 } else if (E->isSuperReceiver()) {
1061 Record.push_back(1);
1062 Record.AddTypeRef(E->getSuperReceiverType());
1064 Record.push_back(2);
1065 Record.AddDeclRef(E->getClassReceiver());
1068 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
1071 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1073 Record.AddSourceLocation(E->getRBracket());
1074 Record.AddStmt(E->getBaseExpr());
1075 Record.AddStmt(E->getKeyExpr());
1076 Record.AddDeclRef(E->getAtIndexMethodDecl());
1077 Record.AddDeclRef(E->setAtIndexMethodDecl());
1079 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1082 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1084 Record.push_back(E->getNumArgs());
1085 Record.push_back(E->getNumStoredSelLocs());
1086 Record.push_back(E->SelLocsKind);
1087 Record.push_back(E->isDelegateInitCall());
1088 Record.push_back(E->IsImplicit);
1089 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1090 switch (E->getReceiverKind()) {
1091 case ObjCMessageExpr::Instance:
1092 Record.AddStmt(E->getInstanceReceiver());
1095 case ObjCMessageExpr::Class:
1096 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
1099 case ObjCMessageExpr::SuperClass:
1100 case ObjCMessageExpr::SuperInstance:
1101 Record.AddTypeRef(E->getSuperType());
1102 Record.AddSourceLocation(E->getSuperLoc());
1106 if (E->getMethodDecl()) {
1107 Record.push_back(1);
1108 Record.AddDeclRef(E->getMethodDecl());
1110 Record.push_back(0);
1111 Record.AddSelectorRef(E->getSelector());
1114 Record.AddSourceLocation(E->getLeftLoc());
1115 Record.AddSourceLocation(E->getRightLoc());
1117 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1118 Arg != ArgEnd; ++Arg)
1119 Record.AddStmt(*Arg);
1121 SourceLocation *Locs = E->getStoredSelLocs();
1122 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1123 Record.AddSourceLocation(Locs[i]);
1125 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1128 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1130 Record.AddStmt(S->getElement());
1131 Record.AddStmt(S->getCollection());
1132 Record.AddStmt(S->getBody());
1133 Record.AddSourceLocation(S->getForLoc());
1134 Record.AddSourceLocation(S->getRParenLoc());
1135 Code = serialization::STMT_OBJC_FOR_COLLECTION;
1138 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1139 Record.AddStmt(S->getCatchBody());
1140 Record.AddDeclRef(S->getCatchParamDecl());
1141 Record.AddSourceLocation(S->getAtCatchLoc());
1142 Record.AddSourceLocation(S->getRParenLoc());
1143 Code = serialization::STMT_OBJC_CATCH;
1146 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1147 Record.AddStmt(S->getFinallyBody());
1148 Record.AddSourceLocation(S->getAtFinallyLoc());
1149 Code = serialization::STMT_OBJC_FINALLY;
1152 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1153 Record.AddStmt(S->getSubStmt());
1154 Record.AddSourceLocation(S->getAtLoc());
1155 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1158 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1159 Record.push_back(S->getNumCatchStmts());
1160 Record.push_back(S->getFinallyStmt() != nullptr);
1161 Record.AddStmt(S->getTryBody());
1162 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1163 Record.AddStmt(S->getCatchStmt(I));
1164 if (S->getFinallyStmt())
1165 Record.AddStmt(S->getFinallyStmt());
1166 Record.AddSourceLocation(S->getAtTryLoc());
1167 Code = serialization::STMT_OBJC_AT_TRY;
1170 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1171 Record.AddStmt(S->getSynchExpr());
1172 Record.AddStmt(S->getSynchBody());
1173 Record.AddSourceLocation(S->getAtSynchronizedLoc());
1174 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1177 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1178 Record.AddStmt(S->getThrowExpr());
1179 Record.AddSourceLocation(S->getThrowLoc());
1180 Code = serialization::STMT_OBJC_AT_THROW;
1183 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1185 Record.push_back(E->getValue());
1186 Record.AddSourceLocation(E->getLocation());
1187 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1190 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1192 Record.AddSourceRange(E->getSourceRange());
1193 Record.AddVersionTuple(E->getVersion());
1194 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1197 //===----------------------------------------------------------------------===//
1198 // C++ Expressions and Statements.
1199 //===----------------------------------------------------------------------===//
1201 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1203 Record.AddSourceLocation(S->getCatchLoc());
1204 Record.AddDeclRef(S->getExceptionDecl());
1205 Record.AddStmt(S->getHandlerBlock());
1206 Code = serialization::STMT_CXX_CATCH;
1209 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1211 Record.push_back(S->getNumHandlers());
1212 Record.AddSourceLocation(S->getTryLoc());
1213 Record.AddStmt(S->getTryBlock());
1214 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1215 Record.AddStmt(S->getHandler(i));
1216 Code = serialization::STMT_CXX_TRY;
1219 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1221 Record.AddSourceLocation(S->getForLoc());
1222 Record.AddSourceLocation(S->getCoawaitLoc());
1223 Record.AddSourceLocation(S->getColonLoc());
1224 Record.AddSourceLocation(S->getRParenLoc());
1225 Record.AddStmt(S->getRangeStmt());
1226 Record.AddStmt(S->getBeginStmt());
1227 Record.AddStmt(S->getEndStmt());
1228 Record.AddStmt(S->getCond());
1229 Record.AddStmt(S->getInc());
1230 Record.AddStmt(S->getLoopVarStmt());
1231 Record.AddStmt(S->getBody());
1232 Code = serialization::STMT_CXX_FOR_RANGE;
1235 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1237 Record.AddSourceLocation(S->getKeywordLoc());
1238 Record.push_back(S->isIfExists());
1239 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1240 Record.AddDeclarationNameInfo(S->getNameInfo());
1241 Record.AddStmt(S->getSubStmt());
1242 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1245 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1247 Record.push_back(E->getOperator());
1248 Record.AddSourceRange(E->Range);
1249 Record.push_back(E->getFPFeatures().getInt());
1250 Code = serialization::EXPR_CXX_OPERATOR_CALL;
1253 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1255 Code = serialization::EXPR_CXX_MEMBER_CALL;
1258 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1260 Record.push_back(E->getNumArgs());
1261 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1262 Record.AddStmt(E->getArg(I));
1263 Record.AddDeclRef(E->getConstructor());
1264 Record.AddSourceLocation(E->getLocation());
1265 Record.push_back(E->isElidable());
1266 Record.push_back(E->hadMultipleCandidates());
1267 Record.push_back(E->isListInitialization());
1268 Record.push_back(E->isStdInitListInitialization());
1269 Record.push_back(E->requiresZeroInitialization());
1270 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
1271 Record.AddSourceRange(E->getParenOrBraceRange());
1272 Code = serialization::EXPR_CXX_CONSTRUCT;
1275 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1277 Record.AddDeclRef(E->getConstructor());
1278 Record.AddSourceLocation(E->getLocation());
1279 Record.push_back(E->constructsVBase());
1280 Record.push_back(E->inheritedFromVBase());
1281 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1284 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1285 VisitCXXConstructExpr(E);
1286 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1287 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1290 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1292 Record.push_back(E->NumCaptures);
1293 Record.AddSourceRange(E->IntroducerRange);
1294 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
1295 Record.AddSourceLocation(E->CaptureDefaultLoc);
1296 Record.push_back(E->ExplicitParams);
1297 Record.push_back(E->ExplicitResultType);
1298 Record.AddSourceLocation(E->ClosingBrace);
1300 // Add capture initializers.
1301 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1302 CEnd = E->capture_init_end();
1307 Code = serialization::EXPR_LAMBDA;
1310 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1312 Record.AddStmt(E->getSubExpr());
1313 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1316 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1317 VisitExplicitCastExpr(E);
1318 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1319 Record.AddSourceRange(E->getAngleBrackets());
1322 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1323 VisitCXXNamedCastExpr(E);
1324 Code = serialization::EXPR_CXX_STATIC_CAST;
1327 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1328 VisitCXXNamedCastExpr(E);
1329 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1332 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1333 VisitCXXNamedCastExpr(E);
1334 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1337 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1338 VisitCXXNamedCastExpr(E);
1339 Code = serialization::EXPR_CXX_CONST_CAST;
1342 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1343 VisitExplicitCastExpr(E);
1344 Record.AddSourceLocation(E->getLParenLoc());
1345 Record.AddSourceLocation(E->getRParenLoc());
1346 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1349 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1351 Record.AddSourceLocation(E->UDSuffixLoc);
1352 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1355 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1357 Record.push_back(E->getValue());
1358 Record.AddSourceLocation(E->getLocation());
1359 Code = serialization::EXPR_CXX_BOOL_LITERAL;
1362 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1364 Record.AddSourceLocation(E->getLocation());
1365 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1368 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1370 Record.AddSourceRange(E->getSourceRange());
1371 if (E->isTypeOperand()) {
1372 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1373 Code = serialization::EXPR_CXX_TYPEID_TYPE;
1375 Record.AddStmt(E->getExprOperand());
1376 Code = serialization::EXPR_CXX_TYPEID_EXPR;
1380 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1382 Record.AddSourceLocation(E->getLocation());
1383 Record.push_back(E->isImplicit());
1384 Code = serialization::EXPR_CXX_THIS;
1387 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1389 Record.AddSourceLocation(E->getThrowLoc());
1390 Record.AddStmt(E->getSubExpr());
1391 Record.push_back(E->isThrownVariableInScope());
1392 Code = serialization::EXPR_CXX_THROW;
1395 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1397 Record.AddDeclRef(E->getParam());
1398 Record.AddSourceLocation(E->getUsedLocation());
1399 Code = serialization::EXPR_CXX_DEFAULT_ARG;
1402 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1404 Record.AddDeclRef(E->getField());
1405 Record.AddSourceLocation(E->getExprLoc());
1406 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1409 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1411 Record.AddCXXTemporary(E->getTemporary());
1412 Record.AddStmt(E->getSubExpr());
1413 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1416 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1418 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1419 Record.AddSourceLocation(E->getRParenLoc());
1420 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1423 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1425 Record.push_back(E->isGlobalNew());
1426 Record.push_back(E->isArray());
1427 Record.push_back(E->passAlignment());
1428 Record.push_back(E->doesUsualArrayDeleteWantSize());
1429 Record.push_back(E->getNumPlacementArgs());
1430 Record.push_back(E->StoredInitializationStyle);
1431 Record.AddDeclRef(E->getOperatorNew());
1432 Record.AddDeclRef(E->getOperatorDelete());
1433 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1434 Record.AddSourceRange(E->getTypeIdParens());
1435 Record.AddSourceRange(E->getSourceRange());
1436 Record.AddSourceRange(E->getDirectInitRange());
1437 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
1441 Code = serialization::EXPR_CXX_NEW;
1444 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1446 Record.push_back(E->isGlobalDelete());
1447 Record.push_back(E->isArrayForm());
1448 Record.push_back(E->isArrayFormAsWritten());
1449 Record.push_back(E->doesUsualArrayDeleteWantSize());
1450 Record.AddDeclRef(E->getOperatorDelete());
1451 Record.AddStmt(E->getArgument());
1452 Record.AddSourceLocation(E->getSourceRange().getBegin());
1454 Code = serialization::EXPR_CXX_DELETE;
1457 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1460 Record.AddStmt(E->getBase());
1461 Record.push_back(E->isArrow());
1462 Record.AddSourceLocation(E->getOperatorLoc());
1463 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1464 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1465 Record.AddSourceLocation(E->getColonColonLoc());
1466 Record.AddSourceLocation(E->getTildeLoc());
1468 // PseudoDestructorTypeStorage.
1469 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
1470 if (E->getDestroyedTypeIdentifier())
1471 Record.AddSourceLocation(E->getDestroyedTypeLoc());
1473 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
1475 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1478 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1480 Record.push_back(E->getNumObjects());
1481 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
1482 Record.AddDeclRef(E->getObject(i));
1484 Record.push_back(E->cleanupsHaveSideEffects());
1485 Record.AddStmt(E->getSubExpr());
1486 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1490 ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
1493 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1496 Record.push_back(E->HasTemplateKWAndArgsInfo);
1497 if (E->HasTemplateKWAndArgsInfo) {
1498 const ASTTemplateKWAndArgsInfo &ArgInfo =
1499 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1500 Record.push_back(ArgInfo.NumTemplateArgs);
1501 AddTemplateKWAndArgsInfo(ArgInfo,
1502 E->getTrailingObjects<TemplateArgumentLoc>());
1505 if (!E->isImplicitAccess())
1506 Record.AddStmt(E->getBase());
1508 Record.AddStmt(nullptr);
1509 Record.AddTypeRef(E->getBaseType());
1510 Record.push_back(E->isArrow());
1511 Record.AddSourceLocation(E->getOperatorLoc());
1512 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1513 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1514 Record.AddDeclarationNameInfo(E->MemberNameInfo);
1515 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
1519 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1522 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1525 Record.push_back(E->HasTemplateKWAndArgsInfo);
1526 if (E->HasTemplateKWAndArgsInfo) {
1527 const ASTTemplateKWAndArgsInfo &ArgInfo =
1528 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1529 Record.push_back(ArgInfo.NumTemplateArgs);
1530 AddTemplateKWAndArgsInfo(ArgInfo,
1531 E->getTrailingObjects<TemplateArgumentLoc>());
1534 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1535 Record.AddDeclarationNameInfo(E->NameInfo);
1536 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
1540 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1542 Record.push_back(E->arg_size());
1543 for (CXXUnresolvedConstructExpr::arg_iterator
1544 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
1545 Record.AddStmt(*ArgI);
1546 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1547 Record.AddSourceLocation(E->getLParenLoc());
1548 Record.AddSourceLocation(E->getRParenLoc());
1549 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
1552 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
1555 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1558 Record.push_back(E->HasTemplateKWAndArgsInfo);
1559 if (E->HasTemplateKWAndArgsInfo) {
1560 const ASTTemplateKWAndArgsInfo &ArgInfo =
1561 *E->getTrailingASTTemplateKWAndArgsInfo();
1562 Record.push_back(ArgInfo.NumTemplateArgs);
1563 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
1566 Record.push_back(E->getNumDecls());
1567 for (OverloadExpr::decls_iterator
1568 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
1569 Record.AddDeclRef(OvI.getDecl());
1570 Record.push_back(OvI.getAccess());
1573 Record.AddDeclarationNameInfo(E->NameInfo);
1574 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1577 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1578 VisitOverloadExpr(E);
1579 Record.push_back(E->isArrow());
1580 Record.push_back(E->hasUnresolvedUsing());
1581 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1582 Record.AddTypeRef(E->getBaseType());
1583 Record.AddSourceLocation(E->getOperatorLoc());
1584 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
1587 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1588 VisitOverloadExpr(E);
1589 Record.push_back(E->requiresADL());
1590 Record.push_back(E->isOverloaded());
1591 Record.AddDeclRef(E->getNamingClass());
1592 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
1595 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1597 Record.push_back(E->TypeTraitExprBits.NumArgs);
1598 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1599 Record.push_back(E->TypeTraitExprBits.Value);
1600 Record.AddSourceRange(E->getSourceRange());
1601 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1602 Record.AddTypeSourceInfo(E->getArg(I));
1603 Code = serialization::EXPR_TYPE_TRAIT;
1606 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1608 Record.push_back(E->getTrait());
1609 Record.push_back(E->getValue());
1610 Record.AddSourceRange(E->getSourceRange());
1611 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
1612 Record.AddStmt(E->getDimensionExpression());
1613 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1616 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1618 Record.push_back(E->getTrait());
1619 Record.push_back(E->getValue());
1620 Record.AddSourceRange(E->getSourceRange());
1621 Record.AddStmt(E->getQueriedExpression());
1622 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1625 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1627 Record.push_back(E->getValue());
1628 Record.AddSourceRange(E->getSourceRange());
1629 Record.AddStmt(E->getOperand());
1630 Code = serialization::EXPR_CXX_NOEXCEPT;
1633 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1635 Record.AddSourceLocation(E->getEllipsisLoc());
1636 Record.push_back(E->NumExpansions);
1637 Record.AddStmt(E->getPattern());
1638 Code = serialization::EXPR_PACK_EXPANSION;
1641 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1643 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1645 Record.AddSourceLocation(E->OperatorLoc);
1646 Record.AddSourceLocation(E->PackLoc);
1647 Record.AddSourceLocation(E->RParenLoc);
1648 Record.AddDeclRef(E->Pack);
1649 if (E->isPartiallySubstituted()) {
1650 for (const auto &TA : E->getPartialArguments())
1651 Record.AddTemplateArgument(TA);
1652 } else if (!E->isValueDependent()) {
1653 Record.push_back(E->getPackLength());
1655 Code = serialization::EXPR_SIZEOF_PACK;
1658 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1659 SubstNonTypeTemplateParmExpr *E) {
1661 Record.AddDeclRef(E->getParameter());
1662 Record.AddSourceLocation(E->getNameLoc());
1663 Record.AddStmt(E->getReplacement());
1664 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1667 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1668 SubstNonTypeTemplateParmPackExpr *E) {
1670 Record.AddDeclRef(E->getParameterPack());
1671 Record.AddTemplateArgument(E->getArgumentPack());
1672 Record.AddSourceLocation(E->getParameterPackLocation());
1673 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1676 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1678 Record.push_back(E->getNumExpansions());
1679 Record.AddDeclRef(E->getParameterPack());
1680 Record.AddSourceLocation(E->getParameterPackLocation());
1681 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1683 Record.AddDeclRef(*I);
1684 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1687 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1689 Record.AddStmt(E->getTemporary());
1690 Record.AddDeclRef(E->getExtendingDecl());
1691 Record.push_back(E->getManglingNumber());
1692 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1695 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1697 Record.AddSourceLocation(E->LParenLoc);
1698 Record.AddSourceLocation(E->EllipsisLoc);
1699 Record.AddSourceLocation(E->RParenLoc);
1700 Record.AddStmt(E->SubExprs[0]);
1701 Record.AddStmt(E->SubExprs[1]);
1702 Record.push_back(E->Opcode);
1703 Code = serialization::EXPR_CXX_FOLD;
1706 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1708 Record.AddStmt(E->getSourceExpr());
1709 Record.AddSourceLocation(E->getLocation());
1710 Record.push_back(E->isUnique());
1711 Code = serialization::EXPR_OPAQUE_VALUE;
1714 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1716 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
1717 llvm_unreachable("Cannot write TypoExpr nodes");
1720 //===----------------------------------------------------------------------===//
1721 // CUDA Expressions and Statements.
1722 //===----------------------------------------------------------------------===//
1724 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1726 Record.AddStmt(E->getConfig());
1727 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1730 //===----------------------------------------------------------------------===//
1731 // OpenCL Expressions and Statements.
1732 //===----------------------------------------------------------------------===//
1733 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1735 Record.AddSourceLocation(E->getBuiltinLoc());
1736 Record.AddSourceLocation(E->getRParenLoc());
1737 Record.AddStmt(E->getSrcExpr());
1738 Code = serialization::EXPR_ASTYPE;
1741 //===----------------------------------------------------------------------===//
1742 // Microsoft Expressions and Statements.
1743 //===----------------------------------------------------------------------===//
1744 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1746 Record.push_back(E->isArrow());
1747 Record.AddStmt(E->getBaseExpr());
1748 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1749 Record.AddSourceLocation(E->getMemberLoc());
1750 Record.AddDeclRef(E->getPropertyDecl());
1751 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1754 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1756 Record.AddStmt(E->getBase());
1757 Record.AddStmt(E->getIdx());
1758 Record.AddSourceLocation(E->getRBracketLoc());
1759 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1762 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1764 Record.AddSourceRange(E->getSourceRange());
1765 Record.AddString(E->getUuidStr());
1766 if (E->isTypeOperand()) {
1767 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1768 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1770 Record.AddStmt(E->getExprOperand());
1771 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1775 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1777 Record.AddSourceLocation(S->getExceptLoc());
1778 Record.AddStmt(S->getFilterExpr());
1779 Record.AddStmt(S->getBlock());
1780 Code = serialization::STMT_SEH_EXCEPT;
1783 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1785 Record.AddSourceLocation(S->getFinallyLoc());
1786 Record.AddStmt(S->getBlock());
1787 Code = serialization::STMT_SEH_FINALLY;
1790 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1792 Record.push_back(S->getIsCXXTry());
1793 Record.AddSourceLocation(S->getTryLoc());
1794 Record.AddStmt(S->getTryBlock());
1795 Record.AddStmt(S->getHandler());
1796 Code = serialization::STMT_SEH_TRY;
1799 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1801 Record.AddSourceLocation(S->getLeaveLoc());
1802 Code = serialization::STMT_SEH_LEAVE;
1805 //===----------------------------------------------------------------------===//
1807 //===----------------------------------------------------------------------===//
1810 class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> {
1811 ASTRecordWriter &Record;
1813 OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {}
1814 #define OPENMP_CLAUSE(Name, Class) \
1815 void Visit##Class(Class *S);
1816 #include "clang/Basic/OpenMPKinds.def"
1817 void writeClause(OMPClause *C);
1818 void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
1819 void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
1823 void OMPClauseWriter::writeClause(OMPClause *C) {
1824 Record.push_back(C->getClauseKind());
1826 Record.AddSourceLocation(C->getLocStart());
1827 Record.AddSourceLocation(C->getLocEnd());
1830 void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) {
1831 Record.push_back(C->getCaptureRegion());
1832 Record.AddStmt(C->getPreInitStmt());
1835 void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) {
1836 VisitOMPClauseWithPreInit(C);
1837 Record.AddStmt(C->getPostUpdateExpr());
1840 void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) {
1841 VisitOMPClauseWithPreInit(C);
1842 Record.push_back(C->getNameModifier());
1843 Record.AddSourceLocation(C->getNameModifierLoc());
1844 Record.AddSourceLocation(C->getColonLoc());
1845 Record.AddStmt(C->getCondition());
1846 Record.AddSourceLocation(C->getLParenLoc());
1849 void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) {
1850 Record.AddStmt(C->getCondition());
1851 Record.AddSourceLocation(C->getLParenLoc());
1854 void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
1855 VisitOMPClauseWithPreInit(C);
1856 Record.AddStmt(C->getNumThreads());
1857 Record.AddSourceLocation(C->getLParenLoc());
1860 void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) {
1861 Record.AddStmt(C->getSafelen());
1862 Record.AddSourceLocation(C->getLParenLoc());
1865 void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
1866 Record.AddStmt(C->getSimdlen());
1867 Record.AddSourceLocation(C->getLParenLoc());
1870 void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) {
1871 Record.AddStmt(C->getNumForLoops());
1872 Record.AddSourceLocation(C->getLParenLoc());
1875 void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
1876 Record.push_back(C->getDefaultKind());
1877 Record.AddSourceLocation(C->getLParenLoc());
1878 Record.AddSourceLocation(C->getDefaultKindKwLoc());
1881 void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
1882 Record.push_back(C->getProcBindKind());
1883 Record.AddSourceLocation(C->getLParenLoc());
1884 Record.AddSourceLocation(C->getProcBindKindKwLoc());
1887 void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
1888 VisitOMPClauseWithPreInit(C);
1889 Record.push_back(C->getScheduleKind());
1890 Record.push_back(C->getFirstScheduleModifier());
1891 Record.push_back(C->getSecondScheduleModifier());
1892 Record.AddStmt(C->getChunkSize());
1893 Record.AddSourceLocation(C->getLParenLoc());
1894 Record.AddSourceLocation(C->getFirstScheduleModifierLoc());
1895 Record.AddSourceLocation(C->getSecondScheduleModifierLoc());
1896 Record.AddSourceLocation(C->getScheduleKindLoc());
1897 Record.AddSourceLocation(C->getCommaLoc());
1900 void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) {
1901 Record.push_back(C->getLoopNumIterations().size());
1902 Record.AddStmt(C->getNumForLoops());
1903 for (Expr *NumIter : C->getLoopNumIterations())
1904 Record.AddStmt(NumIter);
1905 for (unsigned I = 0, E = C->getLoopNumIterations().size(); I <E; ++I)
1906 Record.AddStmt(C->getLoopCunter(I));
1907 Record.AddSourceLocation(C->getLParenLoc());
1910 void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {}
1912 void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}
1914 void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
1916 void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {}
1918 void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {}
1920 void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {}
1922 void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {}
1924 void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
1926 void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {}
1928 void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {}
1930 void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {}
1932 void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
1933 Record.push_back(C->varlist_size());
1934 Record.AddSourceLocation(C->getLParenLoc());
1935 for (auto *VE : C->varlists()) {
1938 for (auto *VE : C->private_copies()) {
1943 void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
1944 Record.push_back(C->varlist_size());
1945 VisitOMPClauseWithPreInit(C);
1946 Record.AddSourceLocation(C->getLParenLoc());
1947 for (auto *VE : C->varlists()) {
1950 for (auto *VE : C->private_copies()) {
1953 for (auto *VE : C->inits()) {
1958 void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
1959 Record.push_back(C->varlist_size());
1960 VisitOMPClauseWithPostUpdate(C);
1961 Record.AddSourceLocation(C->getLParenLoc());
1962 for (auto *VE : C->varlists())
1964 for (auto *E : C->private_copies())
1966 for (auto *E : C->source_exprs())
1968 for (auto *E : C->destination_exprs())
1970 for (auto *E : C->assignment_ops())
1974 void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {
1975 Record.push_back(C->varlist_size());
1976 Record.AddSourceLocation(C->getLParenLoc());
1977 for (auto *VE : C->varlists())
1981 void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) {
1982 Record.push_back(C->varlist_size());
1983 VisitOMPClauseWithPostUpdate(C);
1984 Record.AddSourceLocation(C->getLParenLoc());
1985 Record.AddSourceLocation(C->getColonLoc());
1986 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
1987 Record.AddDeclarationNameInfo(C->getNameInfo());
1988 for (auto *VE : C->varlists())
1990 for (auto *VE : C->privates())
1992 for (auto *E : C->lhs_exprs())
1994 for (auto *E : C->rhs_exprs())
1996 for (auto *E : C->reduction_ops())
2000 void OMPClauseWriter::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) {
2001 Record.push_back(C->varlist_size());
2002 VisitOMPClauseWithPostUpdate(C);
2003 Record.AddSourceLocation(C->getLParenLoc());
2004 Record.AddSourceLocation(C->getColonLoc());
2005 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
2006 Record.AddDeclarationNameInfo(C->getNameInfo());
2007 for (auto *VE : C->varlists())
2009 for (auto *VE : C->privates())
2011 for (auto *E : C->lhs_exprs())
2013 for (auto *E : C->rhs_exprs())
2015 for (auto *E : C->reduction_ops())
2019 void OMPClauseWriter::VisitOMPInReductionClause(OMPInReductionClause *C) {
2020 Record.push_back(C->varlist_size());
2021 VisitOMPClauseWithPostUpdate(C);
2022 Record.AddSourceLocation(C->getLParenLoc());
2023 Record.AddSourceLocation(C->getColonLoc());
2024 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
2025 Record.AddDeclarationNameInfo(C->getNameInfo());
2026 for (auto *VE : C->varlists())
2028 for (auto *VE : C->privates())
2030 for (auto *E : C->lhs_exprs())
2032 for (auto *E : C->rhs_exprs())
2034 for (auto *E : C->reduction_ops())
2036 for (auto *E : C->taskgroup_descriptors())
2040 void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) {
2041 Record.push_back(C->varlist_size());
2042 VisitOMPClauseWithPostUpdate(C);
2043 Record.AddSourceLocation(C->getLParenLoc());
2044 Record.AddSourceLocation(C->getColonLoc());
2045 Record.push_back(C->getModifier());
2046 Record.AddSourceLocation(C->getModifierLoc());
2047 for (auto *VE : C->varlists()) {
2050 for (auto *VE : C->privates()) {
2053 for (auto *VE : C->inits()) {
2056 for (auto *VE : C->updates()) {
2059 for (auto *VE : C->finals()) {
2062 Record.AddStmt(C->getStep());
2063 Record.AddStmt(C->getCalcStep());
2066 void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) {
2067 Record.push_back(C->varlist_size());
2068 Record.AddSourceLocation(C->getLParenLoc());
2069 Record.AddSourceLocation(C->getColonLoc());
2070 for (auto *VE : C->varlists())
2072 Record.AddStmt(C->getAlignment());
2075 void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) {
2076 Record.push_back(C->varlist_size());
2077 Record.AddSourceLocation(C->getLParenLoc());
2078 for (auto *VE : C->varlists())
2080 for (auto *E : C->source_exprs())
2082 for (auto *E : C->destination_exprs())
2084 for (auto *E : C->assignment_ops())
2088 void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
2089 Record.push_back(C->varlist_size());
2090 Record.AddSourceLocation(C->getLParenLoc());
2091 for (auto *VE : C->varlists())
2093 for (auto *E : C->source_exprs())
2095 for (auto *E : C->destination_exprs())
2097 for (auto *E : C->assignment_ops())
2101 void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) {
2102 Record.push_back(C->varlist_size());
2103 Record.AddSourceLocation(C->getLParenLoc());
2104 for (auto *VE : C->varlists())
2108 void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) {
2109 Record.push_back(C->varlist_size());
2110 Record.push_back(C->getNumLoops());
2111 Record.AddSourceLocation(C->getLParenLoc());
2112 Record.push_back(C->getDependencyKind());
2113 Record.AddSourceLocation(C->getDependencyLoc());
2114 Record.AddSourceLocation(C->getColonLoc());
2115 for (auto *VE : C->varlists())
2117 for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I)
2118 Record.AddStmt(C->getLoopData(I));
2121 void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) {
2122 VisitOMPClauseWithPreInit(C);
2123 Record.AddStmt(C->getDevice());
2124 Record.AddSourceLocation(C->getLParenLoc());
2127 void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) {
2128 Record.push_back(C->varlist_size());
2129 Record.push_back(C->getUniqueDeclarationsNum());
2130 Record.push_back(C->getTotalComponentListNum());
2131 Record.push_back(C->getTotalComponentsNum());
2132 Record.AddSourceLocation(C->getLParenLoc());
2133 Record.push_back(C->getMapTypeModifier());
2134 Record.push_back(C->getMapType());
2135 Record.AddSourceLocation(C->getMapLoc());
2136 Record.AddSourceLocation(C->getColonLoc());
2137 for (auto *E : C->varlists())
2139 for (auto *D : C->all_decls())
2140 Record.AddDeclRef(D);
2141 for (auto N : C->all_num_lists())
2142 Record.push_back(N);
2143 for (auto N : C->all_lists_sizes())
2144 Record.push_back(N);
2145 for (auto &M : C->all_components()) {
2146 Record.AddStmt(M.getAssociatedExpression());
2147 Record.AddDeclRef(M.getAssociatedDeclaration());
2151 void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
2152 VisitOMPClauseWithPreInit(C);
2153 Record.AddStmt(C->getNumTeams());
2154 Record.AddSourceLocation(C->getLParenLoc());
2157 void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
2158 VisitOMPClauseWithPreInit(C);
2159 Record.AddStmt(C->getThreadLimit());
2160 Record.AddSourceLocation(C->getLParenLoc());
2163 void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) {
2164 Record.AddStmt(C->getPriority());
2165 Record.AddSourceLocation(C->getLParenLoc());
2168 void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
2169 Record.AddStmt(C->getGrainsize());
2170 Record.AddSourceLocation(C->getLParenLoc());
2173 void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
2174 Record.AddStmt(C->getNumTasks());
2175 Record.AddSourceLocation(C->getLParenLoc());
2178 void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) {
2179 Record.AddStmt(C->getHint());
2180 Record.AddSourceLocation(C->getLParenLoc());
2183 void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) {
2184 VisitOMPClauseWithPreInit(C);
2185 Record.push_back(C->getDistScheduleKind());
2186 Record.AddStmt(C->getChunkSize());
2187 Record.AddSourceLocation(C->getLParenLoc());
2188 Record.AddSourceLocation(C->getDistScheduleKindLoc());
2189 Record.AddSourceLocation(C->getCommaLoc());
2192 void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
2193 Record.push_back(C->getDefaultmapKind());
2194 Record.push_back(C->getDefaultmapModifier());
2195 Record.AddSourceLocation(C->getLParenLoc());
2196 Record.AddSourceLocation(C->getDefaultmapModifierLoc());
2197 Record.AddSourceLocation(C->getDefaultmapKindLoc());
2200 void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) {
2201 Record.push_back(C->varlist_size());
2202 Record.push_back(C->getUniqueDeclarationsNum());
2203 Record.push_back(C->getTotalComponentListNum());
2204 Record.push_back(C->getTotalComponentsNum());
2205 Record.AddSourceLocation(C->getLParenLoc());
2206 for (auto *E : C->varlists())
2208 for (auto *D : C->all_decls())
2209 Record.AddDeclRef(D);
2210 for (auto N : C->all_num_lists())
2211 Record.push_back(N);
2212 for (auto N : C->all_lists_sizes())
2213 Record.push_back(N);
2214 for (auto &M : C->all_components()) {
2215 Record.AddStmt(M.getAssociatedExpression());
2216 Record.AddDeclRef(M.getAssociatedDeclaration());
2220 void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) {
2221 Record.push_back(C->varlist_size());
2222 Record.push_back(C->getUniqueDeclarationsNum());
2223 Record.push_back(C->getTotalComponentListNum());
2224 Record.push_back(C->getTotalComponentsNum());
2225 Record.AddSourceLocation(C->getLParenLoc());
2226 for (auto *E : C->varlists())
2228 for (auto *D : C->all_decls())
2229 Record.AddDeclRef(D);
2230 for (auto N : C->all_num_lists())
2231 Record.push_back(N);
2232 for (auto N : C->all_lists_sizes())
2233 Record.push_back(N);
2234 for (auto &M : C->all_components()) {
2235 Record.AddStmt(M.getAssociatedExpression());
2236 Record.AddDeclRef(M.getAssociatedDeclaration());
2240 void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
2241 Record.push_back(C->varlist_size());
2242 Record.push_back(C->getUniqueDeclarationsNum());
2243 Record.push_back(C->getTotalComponentListNum());
2244 Record.push_back(C->getTotalComponentsNum());
2245 Record.AddSourceLocation(C->getLParenLoc());
2246 for (auto *E : C->varlists())
2248 for (auto *VE : C->private_copies())
2250 for (auto *VE : C->inits())
2252 for (auto *D : C->all_decls())
2253 Record.AddDeclRef(D);
2254 for (auto N : C->all_num_lists())
2255 Record.push_back(N);
2256 for (auto N : C->all_lists_sizes())
2257 Record.push_back(N);
2258 for (auto &M : C->all_components()) {
2259 Record.AddStmt(M.getAssociatedExpression());
2260 Record.AddDeclRef(M.getAssociatedDeclaration());
2264 void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
2265 Record.push_back(C->varlist_size());
2266 Record.push_back(C->getUniqueDeclarationsNum());
2267 Record.push_back(C->getTotalComponentListNum());
2268 Record.push_back(C->getTotalComponentsNum());
2269 Record.AddSourceLocation(C->getLParenLoc());
2270 for (auto *E : C->varlists())
2272 for (auto *D : C->all_decls())
2273 Record.AddDeclRef(D);
2274 for (auto N : C->all_num_lists())
2275 Record.push_back(N);
2276 for (auto N : C->all_lists_sizes())
2277 Record.push_back(N);
2278 for (auto &M : C->all_components()) {
2279 Record.AddStmt(M.getAssociatedExpression());
2280 Record.AddDeclRef(M.getAssociatedDeclaration());
2284 //===----------------------------------------------------------------------===//
2285 // OpenMP Directives.
2286 //===----------------------------------------------------------------------===//
2287 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2288 Record.AddSourceLocation(E->getLocStart());
2289 Record.AddSourceLocation(E->getLocEnd());
2290 OMPClauseWriter ClauseWriter(Record);
2291 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
2292 ClauseWriter.writeClause(E->getClause(i));
2294 if (E->hasAssociatedStmt())
2295 Record.AddStmt(E->getAssociatedStmt());
2298 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
2300 Record.push_back(D->getNumClauses());
2301 Record.push_back(D->getCollapsedNumber());
2302 VisitOMPExecutableDirective(D);
2303 Record.AddStmt(D->getIterationVariable());
2304 Record.AddStmt(D->getLastIteration());
2305 Record.AddStmt(D->getCalcLastIteration());
2306 Record.AddStmt(D->getPreCond());
2307 Record.AddStmt(D->getCond());
2308 Record.AddStmt(D->getInit());
2309 Record.AddStmt(D->getInc());
2310 Record.AddStmt(D->getPreInits());
2311 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
2312 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
2313 isOpenMPDistributeDirective(D->getDirectiveKind())) {
2314 Record.AddStmt(D->getIsLastIterVariable());
2315 Record.AddStmt(D->getLowerBoundVariable());
2316 Record.AddStmt(D->getUpperBoundVariable());
2317 Record.AddStmt(D->getStrideVariable());
2318 Record.AddStmt(D->getEnsureUpperBound());
2319 Record.AddStmt(D->getNextLowerBound());
2320 Record.AddStmt(D->getNextUpperBound());
2321 Record.AddStmt(D->getNumIterations());
2323 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
2324 Record.AddStmt(D->getPrevLowerBoundVariable());
2325 Record.AddStmt(D->getPrevUpperBoundVariable());
2326 Record.AddStmt(D->getDistInc());
2327 Record.AddStmt(D->getPrevEnsureUpperBound());
2328 Record.AddStmt(D->getCombinedLowerBoundVariable());
2329 Record.AddStmt(D->getCombinedUpperBoundVariable());
2330 Record.AddStmt(D->getCombinedEnsureUpperBound());
2331 Record.AddStmt(D->getCombinedInit());
2332 Record.AddStmt(D->getCombinedCond());
2333 Record.AddStmt(D->getCombinedNextLowerBound());
2334 Record.AddStmt(D->getCombinedNextUpperBound());
2336 for (auto I : D->counters()) {
2339 for (auto I : D->private_counters()) {
2342 for (auto I : D->inits()) {
2345 for (auto I : D->updates()) {
2348 for (auto I : D->finals()) {
2353 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2355 Record.push_back(D->getNumClauses());
2356 VisitOMPExecutableDirective(D);
2357 Record.push_back(D->hasCancel() ? 1 : 0);
2358 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2361 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2362 VisitOMPLoopDirective(D);
2363 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2366 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2367 VisitOMPLoopDirective(D);
2368 Record.push_back(D->hasCancel() ? 1 : 0);
2369 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2372 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2373 VisitOMPLoopDirective(D);
2374 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2377 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2379 Record.push_back(D->getNumClauses());
2380 VisitOMPExecutableDirective(D);
2381 Record.push_back(D->hasCancel() ? 1 : 0);
2382 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2385 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2387 VisitOMPExecutableDirective(D);
2388 Record.push_back(D->hasCancel() ? 1 : 0);
2389 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2392 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2394 Record.push_back(D->getNumClauses());
2395 VisitOMPExecutableDirective(D);
2396 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2399 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2401 VisitOMPExecutableDirective(D);
2402 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2405 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2407 Record.push_back(D->getNumClauses());
2408 VisitOMPExecutableDirective(D);
2409 Record.AddDeclarationNameInfo(D->getDirectiveName());
2410 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2413 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2414 VisitOMPLoopDirective(D);
2415 Record.push_back(D->hasCancel() ? 1 : 0);
2416 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2419 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2420 OMPParallelForSimdDirective *D) {
2421 VisitOMPLoopDirective(D);
2422 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2425 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2426 OMPParallelSectionsDirective *D) {
2428 Record.push_back(D->getNumClauses());
2429 VisitOMPExecutableDirective(D);
2430 Record.push_back(D->hasCancel() ? 1 : 0);
2431 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2434 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2436 Record.push_back(D->getNumClauses());
2437 VisitOMPExecutableDirective(D);
2438 Record.push_back(D->hasCancel() ? 1 : 0);
2439 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2442 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2444 Record.push_back(D->getNumClauses());
2445 VisitOMPExecutableDirective(D);
2446 Record.AddStmt(D->getX());
2447 Record.AddStmt(D->getV());
2448 Record.AddStmt(D->getExpr());
2449 Record.AddStmt(D->getUpdateExpr());
2450 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
2451 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
2452 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2455 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2457 Record.push_back(D->getNumClauses());
2458 VisitOMPExecutableDirective(D);
2459 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2462 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2464 Record.push_back(D->getNumClauses());
2465 VisitOMPExecutableDirective(D);
2466 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2469 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2470 OMPTargetEnterDataDirective *D) {
2472 Record.push_back(D->getNumClauses());
2473 VisitOMPExecutableDirective(D);
2474 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2477 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2478 OMPTargetExitDataDirective *D) {
2480 Record.push_back(D->getNumClauses());
2481 VisitOMPExecutableDirective(D);
2482 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2485 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2486 OMPTargetParallelDirective *D) {
2488 Record.push_back(D->getNumClauses());
2489 VisitOMPExecutableDirective(D);
2490 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2493 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2494 OMPTargetParallelForDirective *D) {
2495 VisitOMPLoopDirective(D);
2496 Record.push_back(D->hasCancel() ? 1 : 0);
2497 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2500 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2502 VisitOMPExecutableDirective(D);
2503 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2506 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2508 VisitOMPExecutableDirective(D);
2509 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2512 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2514 VisitOMPExecutableDirective(D);
2515 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2518 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2520 Record.push_back(D->getNumClauses());
2521 VisitOMPExecutableDirective(D);
2522 Record.AddStmt(D->getReductionRef());
2523 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2526 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2528 Record.push_back(D->getNumClauses());
2529 VisitOMPExecutableDirective(D);
2530 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2533 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2535 Record.push_back(D->getNumClauses());
2536 VisitOMPExecutableDirective(D);
2537 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2540 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2542 Record.push_back(D->getNumClauses());
2543 VisitOMPExecutableDirective(D);
2544 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2547 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2548 OMPCancellationPointDirective *D) {
2550 VisitOMPExecutableDirective(D);
2551 Record.push_back(D->getCancelRegion());
2552 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2555 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2557 Record.push_back(D->getNumClauses());
2558 VisitOMPExecutableDirective(D);
2559 Record.push_back(D->getCancelRegion());
2560 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2563 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2564 VisitOMPLoopDirective(D);
2565 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2568 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2569 VisitOMPLoopDirective(D);
2570 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2573 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2574 VisitOMPLoopDirective(D);
2575 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2578 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2580 Record.push_back(D->getNumClauses());
2581 VisitOMPExecutableDirective(D);
2582 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2585 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2586 OMPDistributeParallelForDirective *D) {
2587 VisitOMPLoopDirective(D);
2588 Record.push_back(D->hasCancel() ? 1 : 0);
2589 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2592 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2593 OMPDistributeParallelForSimdDirective *D) {
2594 VisitOMPLoopDirective(D);
2595 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2598 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2599 OMPDistributeSimdDirective *D) {
2600 VisitOMPLoopDirective(D);
2601 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2604 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2605 OMPTargetParallelForSimdDirective *D) {
2606 VisitOMPLoopDirective(D);
2607 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2610 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2611 VisitOMPLoopDirective(D);
2612 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2615 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2616 OMPTeamsDistributeDirective *D) {
2617 VisitOMPLoopDirective(D);
2618 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2621 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2622 OMPTeamsDistributeSimdDirective *D) {
2623 VisitOMPLoopDirective(D);
2624 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2627 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2628 OMPTeamsDistributeParallelForSimdDirective *D) {
2629 VisitOMPLoopDirective(D);
2630 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2633 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2634 OMPTeamsDistributeParallelForDirective *D) {
2635 VisitOMPLoopDirective(D);
2636 Record.push_back(D->hasCancel() ? 1 : 0);
2637 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2640 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2642 Record.push_back(D->getNumClauses());
2643 VisitOMPExecutableDirective(D);
2644 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2647 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2648 OMPTargetTeamsDistributeDirective *D) {
2649 VisitOMPLoopDirective(D);
2650 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2653 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2654 OMPTargetTeamsDistributeParallelForDirective *D) {
2655 VisitOMPLoopDirective(D);
2656 Record.push_back(D->hasCancel() ? 1 : 0);
2657 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2660 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2661 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2662 VisitOMPLoopDirective(D);
2663 Code = serialization::
2664 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2667 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2668 OMPTargetTeamsDistributeSimdDirective *D) {
2669 VisitOMPLoopDirective(D);
2670 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2673 //===----------------------------------------------------------------------===//
2674 // ASTWriter Implementation
2675 //===----------------------------------------------------------------------===//
2677 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2678 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
2679 "SwitchCase recorded twice");
2680 unsigned NextID = SwitchCaseIDs.size();
2681 SwitchCaseIDs[S] = NextID;
2685 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2686 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
2687 "SwitchCase hasn't been seen yet");
2688 return SwitchCaseIDs[S];
2691 void ASTWriter::ClearSwitchCaseIDs() {
2692 SwitchCaseIDs.clear();
2695 /// Write the given substatement or subexpression to the
2697 void ASTWriter::WriteSubStmt(Stmt *S) {
2699 ASTStmtWriter Writer(*this, Record);
2703 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2707 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2708 if (I != SubStmtEntries.end()) {
2709 Record.push_back(I->second);
2710 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2715 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2717 struct ParentStmtInserterRAII {
2719 llvm::DenseSet<Stmt *> &ParentStmts;
2721 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2722 : S(S), ParentStmts(ParentStmts) {
2723 ParentStmts.insert(S);
2725 ~ParentStmtInserterRAII() {
2726 ParentStmts.erase(S);
2730 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2735 uint64_t Offset = Writer.Emit();
2736 SubStmtEntries[S] = Offset;
2739 /// Flush all of the statements that have been added to the
2740 /// queue via AddStmt().
2741 void ASTRecordWriter::FlushStmts() {
2742 // We expect to be the only consumer of the two temporary statement maps,
2743 // assert that they are empty.
2744 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2745 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2747 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2748 Writer->WriteSubStmt(StmtsToEmit[I]);
2750 assert(N == StmtsToEmit.size() && "record modified while being written!");
2752 // Note that we are at the end of a full expression. Any
2753 // expression records that follow this one are part of a different
2755 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2757 Writer->SubStmtEntries.clear();
2758 Writer->ParentStmts.clear();
2761 StmtsToEmit.clear();
2764 void ASTRecordWriter::FlushSubStmts() {
2765 // For a nested statement, write out the substatements in reverse order (so
2766 // that a simple stack machine can be used when loading), and don't emit a
2767 // STMT_STOP after each one.
2768 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2769 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
2770 assert(N == StmtsToEmit.size() && "record modified while being written!");
2773 StmtsToEmit.clear();