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 /// \brief 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::VisitFloatingLiteral(FloatingLiteral *E) {
449 Record.push_back(E->getRawSemantics());
450 Record.push_back(E->isExact());
451 Record.AddAPFloat(E->getValue());
452 Record.AddSourceLocation(E->getLocation());
453 Code = serialization::EXPR_FLOATING_LITERAL;
456 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
458 Record.AddStmt(E->getSubExpr());
459 Code = serialization::EXPR_IMAGINARY_LITERAL;
462 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
464 Record.push_back(E->getByteLength());
465 Record.push_back(E->getNumConcatenated());
466 Record.push_back(E->getKind());
467 Record.push_back(E->isPascal());
468 // FIXME: String data should be stored as a blob at the end of the
469 // StringLiteral. However, we can't do so now because we have no
470 // provision for coping with abbreviations when we're jumping around
471 // the AST file during deserialization.
472 Record.append(E->getBytes().begin(), E->getBytes().end());
473 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
474 Record.AddSourceLocation(E->getStrTokenLoc(I));
475 Code = serialization::EXPR_STRING_LITERAL;
478 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
480 Record.push_back(E->getValue());
481 Record.AddSourceLocation(E->getLocation());
482 Record.push_back(E->getKind());
484 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
486 Code = serialization::EXPR_CHARACTER_LITERAL;
489 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
491 Record.AddSourceLocation(E->getLParen());
492 Record.AddSourceLocation(E->getRParen());
493 Record.AddStmt(E->getSubExpr());
494 Code = serialization::EXPR_PAREN;
497 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
499 Record.push_back(E->NumExprs);
500 for (unsigned i=0; i != E->NumExprs; ++i)
501 Record.AddStmt(E->Exprs[i]);
502 Record.AddSourceLocation(E->LParenLoc);
503 Record.AddSourceLocation(E->RParenLoc);
504 Code = serialization::EXPR_PAREN_LIST;
507 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
509 Record.AddStmt(E->getSubExpr());
510 Record.push_back(E->getOpcode()); // FIXME: stable encoding
511 Record.AddSourceLocation(E->getOperatorLoc());
512 Code = serialization::EXPR_UNARY_OPERATOR;
515 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
517 Record.push_back(E->getNumComponents());
518 Record.push_back(E->getNumExpressions());
519 Record.AddSourceLocation(E->getOperatorLoc());
520 Record.AddSourceLocation(E->getRParenLoc());
521 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
522 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
523 const OffsetOfNode &ON = E->getComponent(I);
524 Record.push_back(ON.getKind()); // FIXME: Stable encoding
525 Record.AddSourceLocation(ON.getSourceRange().getBegin());
526 Record.AddSourceLocation(ON.getSourceRange().getEnd());
527 switch (ON.getKind()) {
528 case OffsetOfNode::Array:
529 Record.push_back(ON.getArrayExprIndex());
532 case OffsetOfNode::Field:
533 Record.AddDeclRef(ON.getField());
536 case OffsetOfNode::Identifier:
537 Record.AddIdentifierRef(ON.getFieldName());
540 case OffsetOfNode::Base:
541 Record.AddCXXBaseSpecifier(*ON.getBase());
545 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
546 Record.AddStmt(E->getIndexExpr(I));
547 Code = serialization::EXPR_OFFSETOF;
550 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
552 Record.push_back(E->getKind());
553 if (E->isArgumentType())
554 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
557 Record.AddStmt(E->getArgumentExpr());
559 Record.AddSourceLocation(E->getOperatorLoc());
560 Record.AddSourceLocation(E->getRParenLoc());
561 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
564 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
566 Record.AddStmt(E->getLHS());
567 Record.AddStmt(E->getRHS());
568 Record.AddSourceLocation(E->getRBracketLoc());
569 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
572 void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
574 Record.AddStmt(E->getBase());
575 Record.AddStmt(E->getLowerBound());
576 Record.AddStmt(E->getLength());
577 Record.AddSourceLocation(E->getColonLoc());
578 Record.AddSourceLocation(E->getRBracketLoc());
579 Code = serialization::EXPR_OMP_ARRAY_SECTION;
582 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
584 Record.push_back(E->getNumArgs());
585 Record.AddSourceLocation(E->getRParenLoc());
586 Record.AddStmt(E->getCallee());
587 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
588 Arg != ArgEnd; ++Arg)
589 Record.AddStmt(*Arg);
590 Code = serialization::EXPR_CALL;
593 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
594 // Don't call VisitExpr, we'll write everything here.
596 Record.push_back(E->hasQualifier());
597 if (E->hasQualifier())
598 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
600 Record.push_back(E->HasTemplateKWAndArgsInfo);
601 if (E->HasTemplateKWAndArgsInfo) {
602 Record.AddSourceLocation(E->getTemplateKeywordLoc());
603 unsigned NumTemplateArgs = E->getNumTemplateArgs();
604 Record.push_back(NumTemplateArgs);
605 Record.AddSourceLocation(E->getLAngleLoc());
606 Record.AddSourceLocation(E->getRAngleLoc());
607 for (unsigned i=0; i != NumTemplateArgs; ++i)
608 Record.AddTemplateArgumentLoc(E->getTemplateArgs()[i]);
611 Record.push_back(E->hadMultipleCandidates());
613 DeclAccessPair FoundDecl = E->getFoundDecl();
614 Record.AddDeclRef(FoundDecl.getDecl());
615 Record.push_back(FoundDecl.getAccess());
617 Record.AddTypeRef(E->getType());
618 Record.push_back(E->getValueKind());
619 Record.push_back(E->getObjectKind());
620 Record.AddStmt(E->getBase());
621 Record.AddDeclRef(E->getMemberDecl());
622 Record.AddSourceLocation(E->getMemberLoc());
623 Record.push_back(E->isArrow());
624 Record.AddSourceLocation(E->getOperatorLoc());
625 Record.AddDeclarationNameLoc(E->MemberDNLoc,
626 E->getMemberDecl()->getDeclName());
627 Code = serialization::EXPR_MEMBER;
630 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
632 Record.AddStmt(E->getBase());
633 Record.AddSourceLocation(E->getIsaMemberLoc());
634 Record.AddSourceLocation(E->getOpLoc());
635 Record.push_back(E->isArrow());
636 Code = serialization::EXPR_OBJC_ISA;
640 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
642 Record.AddStmt(E->getSubExpr());
643 Record.push_back(E->shouldCopy());
644 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
647 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
648 VisitExplicitCastExpr(E);
649 Record.AddSourceLocation(E->getLParenLoc());
650 Record.AddSourceLocation(E->getBridgeKeywordLoc());
651 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
652 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
655 void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
657 Record.push_back(E->path_size());
658 Record.AddStmt(E->getSubExpr());
659 Record.push_back(E->getCastKind()); // FIXME: stable encoding
661 for (CastExpr::path_iterator
662 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
663 Record.AddCXXBaseSpecifier(**PI);
666 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
668 Record.AddStmt(E->getLHS());
669 Record.AddStmt(E->getRHS());
670 Record.push_back(E->getOpcode()); // FIXME: stable encoding
671 Record.AddSourceLocation(E->getOperatorLoc());
672 Record.push_back(E->getFPFeatures().getInt());
673 Code = serialization::EXPR_BINARY_OPERATOR;
676 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
677 VisitBinaryOperator(E);
678 Record.AddTypeRef(E->getComputationLHSType());
679 Record.AddTypeRef(E->getComputationResultType());
680 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
683 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
685 Record.AddStmt(E->getCond());
686 Record.AddStmt(E->getLHS());
687 Record.AddStmt(E->getRHS());
688 Record.AddSourceLocation(E->getQuestionLoc());
689 Record.AddSourceLocation(E->getColonLoc());
690 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
694 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
696 Record.AddStmt(E->getOpaqueValue());
697 Record.AddStmt(E->getCommon());
698 Record.AddStmt(E->getCond());
699 Record.AddStmt(E->getTrueExpr());
700 Record.AddStmt(E->getFalseExpr());
701 Record.AddSourceLocation(E->getQuestionLoc());
702 Record.AddSourceLocation(E->getColonLoc());
703 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
706 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
709 if (E->path_size() == 0)
710 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
712 Code = serialization::EXPR_IMPLICIT_CAST;
715 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
717 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
720 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
721 VisitExplicitCastExpr(E);
722 Record.AddSourceLocation(E->getLParenLoc());
723 Record.AddSourceLocation(E->getRParenLoc());
724 Code = serialization::EXPR_CSTYLE_CAST;
727 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
729 Record.AddSourceLocation(E->getLParenLoc());
730 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
731 Record.AddStmt(E->getInitializer());
732 Record.push_back(E->isFileScope());
733 Code = serialization::EXPR_COMPOUND_LITERAL;
736 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
738 Record.AddStmt(E->getBase());
739 Record.AddIdentifierRef(&E->getAccessor());
740 Record.AddSourceLocation(E->getAccessorLoc());
741 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
744 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
746 // NOTE: only add the (possibly null) syntactic form.
747 // No need to serialize the isSemanticForm flag and the semantic form.
748 Record.AddStmt(E->getSyntacticForm());
749 Record.AddSourceLocation(E->getLBraceLoc());
750 Record.AddSourceLocation(E->getRBraceLoc());
751 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
752 Record.push_back(isArrayFiller);
754 Record.AddStmt(E->getArrayFiller());
756 Record.AddDeclRef(E->getInitializedFieldInUnion());
757 Record.push_back(E->hadArrayRangeDesignator());
758 Record.push_back(E->getNumInits());
760 // ArrayFiller may have filled "holes" due to designated initializer.
761 // Replace them by 0 to indicate that the filler goes in that place.
762 Expr *filler = E->getArrayFiller();
763 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
764 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
766 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
767 Record.AddStmt(E->getInit(I));
769 Code = serialization::EXPR_INIT_LIST;
772 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
774 Record.push_back(E->getNumSubExprs());
775 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
776 Record.AddStmt(E->getSubExpr(I));
777 Record.AddSourceLocation(E->getEqualOrColonLoc());
778 Record.push_back(E->usesGNUSyntax());
779 for (const DesignatedInitExpr::Designator &D : E->designators()) {
780 if (D.isFieldDesignator()) {
781 if (FieldDecl *Field = D.getField()) {
782 Record.push_back(serialization::DESIG_FIELD_DECL);
783 Record.AddDeclRef(Field);
785 Record.push_back(serialization::DESIG_FIELD_NAME);
786 Record.AddIdentifierRef(D.getFieldName());
788 Record.AddSourceLocation(D.getDotLoc());
789 Record.AddSourceLocation(D.getFieldLoc());
790 } else if (D.isArrayDesignator()) {
791 Record.push_back(serialization::DESIG_ARRAY);
792 Record.push_back(D.getFirstExprIndex());
793 Record.AddSourceLocation(D.getLBracketLoc());
794 Record.AddSourceLocation(D.getRBracketLoc());
796 assert(D.isArrayRangeDesignator() && "Unknown designator");
797 Record.push_back(serialization::DESIG_ARRAY_RANGE);
798 Record.push_back(D.getFirstExprIndex());
799 Record.AddSourceLocation(D.getLBracketLoc());
800 Record.AddSourceLocation(D.getEllipsisLoc());
801 Record.AddSourceLocation(D.getRBracketLoc());
804 Code = serialization::EXPR_DESIGNATED_INIT;
807 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
809 Record.AddStmt(E->getBase());
810 Record.AddStmt(E->getUpdater());
811 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
814 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
816 Code = serialization::EXPR_NO_INIT;
819 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
821 Record.AddStmt(E->SubExprs[0]);
822 Record.AddStmt(E->SubExprs[1]);
823 Code = serialization::EXPR_ARRAY_INIT_LOOP;
826 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
828 Code = serialization::EXPR_ARRAY_INIT_INDEX;
831 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
833 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
836 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
838 Record.AddStmt(E->getSubExpr());
839 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
840 Record.AddSourceLocation(E->getBuiltinLoc());
841 Record.AddSourceLocation(E->getRParenLoc());
842 Record.push_back(E->isMicrosoftABI());
843 Code = serialization::EXPR_VA_ARG;
846 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
848 Record.AddSourceLocation(E->getAmpAmpLoc());
849 Record.AddSourceLocation(E->getLabelLoc());
850 Record.AddDeclRef(E->getLabel());
851 Code = serialization::EXPR_ADDR_LABEL;
854 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
856 Record.AddStmt(E->getSubStmt());
857 Record.AddSourceLocation(E->getLParenLoc());
858 Record.AddSourceLocation(E->getRParenLoc());
859 Code = serialization::EXPR_STMT;
862 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
864 Record.AddStmt(E->getCond());
865 Record.AddStmt(E->getLHS());
866 Record.AddStmt(E->getRHS());
867 Record.AddSourceLocation(E->getBuiltinLoc());
868 Record.AddSourceLocation(E->getRParenLoc());
869 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
870 Code = serialization::EXPR_CHOOSE;
873 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
875 Record.AddSourceLocation(E->getTokenLocation());
876 Code = serialization::EXPR_GNU_NULL;
879 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
881 Record.push_back(E->getNumSubExprs());
882 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
883 Record.AddStmt(E->getExpr(I));
884 Record.AddSourceLocation(E->getBuiltinLoc());
885 Record.AddSourceLocation(E->getRParenLoc());
886 Code = serialization::EXPR_SHUFFLE_VECTOR;
889 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
891 Record.AddSourceLocation(E->getBuiltinLoc());
892 Record.AddSourceLocation(E->getRParenLoc());
893 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
894 Record.AddStmt(E->getSrcExpr());
895 Code = serialization::EXPR_CONVERT_VECTOR;
898 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
900 Record.AddDeclRef(E->getBlockDecl());
901 Code = serialization::EXPR_BLOCK;
904 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
906 Record.push_back(E->getNumAssocs());
908 Record.AddStmt(E->getControllingExpr());
909 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
910 Record.AddTypeSourceInfo(E->getAssocTypeSourceInfo(I));
911 Record.AddStmt(E->getAssocExpr(I));
913 Record.push_back(E->isResultDependent() ? -1U : E->getResultIndex());
915 Record.AddSourceLocation(E->getGenericLoc());
916 Record.AddSourceLocation(E->getDefaultLoc());
917 Record.AddSourceLocation(E->getRParenLoc());
918 Code = serialization::EXPR_GENERIC_SELECTION;
921 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
923 Record.push_back(E->getNumSemanticExprs());
925 // Push the result index. Currently, this needs to exactly match
926 // the encoding used internally for ResultIndex.
927 unsigned result = E->getResultExprIndex();
928 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
929 Record.push_back(result);
931 Record.AddStmt(E->getSyntacticForm());
932 for (PseudoObjectExpr::semantics_iterator
933 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
936 Code = serialization::EXPR_PSEUDO_OBJECT;
939 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
941 Record.push_back(E->getOp());
942 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
943 Record.AddStmt(E->getSubExprs()[I]);
944 Record.AddSourceLocation(E->getBuiltinLoc());
945 Record.AddSourceLocation(E->getRParenLoc());
946 Code = serialization::EXPR_ATOMIC;
949 //===----------------------------------------------------------------------===//
950 // Objective-C Expressions and Statements.
951 //===----------------------------------------------------------------------===//
953 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
955 Record.AddStmt(E->getString());
956 Record.AddSourceLocation(E->getAtLoc());
957 Code = serialization::EXPR_OBJC_STRING_LITERAL;
960 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
962 Record.AddStmt(E->getSubExpr());
963 Record.AddDeclRef(E->getBoxingMethod());
964 Record.AddSourceRange(E->getSourceRange());
965 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
968 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
970 Record.push_back(E->getNumElements());
971 for (unsigned i = 0; i < E->getNumElements(); i++)
972 Record.AddStmt(E->getElement(i));
973 Record.AddDeclRef(E->getArrayWithObjectsMethod());
974 Record.AddSourceRange(E->getSourceRange());
975 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
978 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
980 Record.push_back(E->getNumElements());
981 Record.push_back(E->HasPackExpansions);
982 for (unsigned i = 0; i < E->getNumElements(); i++) {
983 ObjCDictionaryElement Element = E->getKeyValueElement(i);
984 Record.AddStmt(Element.Key);
985 Record.AddStmt(Element.Value);
986 if (E->HasPackExpansions) {
987 Record.AddSourceLocation(Element.EllipsisLoc);
988 unsigned NumExpansions = 0;
989 if (Element.NumExpansions)
990 NumExpansions = *Element.NumExpansions + 1;
991 Record.push_back(NumExpansions);
995 Record.AddDeclRef(E->getDictWithObjectsMethod());
996 Record.AddSourceRange(E->getSourceRange());
997 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
1000 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
1002 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
1003 Record.AddSourceLocation(E->getAtLoc());
1004 Record.AddSourceLocation(E->getRParenLoc());
1005 Code = serialization::EXPR_OBJC_ENCODE;
1008 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
1010 Record.AddSelectorRef(E->getSelector());
1011 Record.AddSourceLocation(E->getAtLoc());
1012 Record.AddSourceLocation(E->getRParenLoc());
1013 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
1016 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
1018 Record.AddDeclRef(E->getProtocol());
1019 Record.AddSourceLocation(E->getAtLoc());
1020 Record.AddSourceLocation(E->ProtoLoc);
1021 Record.AddSourceLocation(E->getRParenLoc());
1022 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
1025 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1027 Record.AddDeclRef(E->getDecl());
1028 Record.AddSourceLocation(E->getLocation());
1029 Record.AddSourceLocation(E->getOpLoc());
1030 Record.AddStmt(E->getBase());
1031 Record.push_back(E->isArrow());
1032 Record.push_back(E->isFreeIvar());
1033 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
1036 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1038 Record.push_back(E->SetterAndMethodRefFlags.getInt());
1039 Record.push_back(E->isImplicitProperty());
1040 if (E->isImplicitProperty()) {
1041 Record.AddDeclRef(E->getImplicitPropertyGetter());
1042 Record.AddDeclRef(E->getImplicitPropertySetter());
1044 Record.AddDeclRef(E->getExplicitProperty());
1046 Record.AddSourceLocation(E->getLocation());
1047 Record.AddSourceLocation(E->getReceiverLocation());
1048 if (E->isObjectReceiver()) {
1049 Record.push_back(0);
1050 Record.AddStmt(E->getBase());
1051 } else if (E->isSuperReceiver()) {
1052 Record.push_back(1);
1053 Record.AddTypeRef(E->getSuperReceiverType());
1055 Record.push_back(2);
1056 Record.AddDeclRef(E->getClassReceiver());
1059 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
1062 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1064 Record.AddSourceLocation(E->getRBracket());
1065 Record.AddStmt(E->getBaseExpr());
1066 Record.AddStmt(E->getKeyExpr());
1067 Record.AddDeclRef(E->getAtIndexMethodDecl());
1068 Record.AddDeclRef(E->setAtIndexMethodDecl());
1070 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1073 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1075 Record.push_back(E->getNumArgs());
1076 Record.push_back(E->getNumStoredSelLocs());
1077 Record.push_back(E->SelLocsKind);
1078 Record.push_back(E->isDelegateInitCall());
1079 Record.push_back(E->IsImplicit);
1080 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1081 switch (E->getReceiverKind()) {
1082 case ObjCMessageExpr::Instance:
1083 Record.AddStmt(E->getInstanceReceiver());
1086 case ObjCMessageExpr::Class:
1087 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
1090 case ObjCMessageExpr::SuperClass:
1091 case ObjCMessageExpr::SuperInstance:
1092 Record.AddTypeRef(E->getSuperType());
1093 Record.AddSourceLocation(E->getSuperLoc());
1097 if (E->getMethodDecl()) {
1098 Record.push_back(1);
1099 Record.AddDeclRef(E->getMethodDecl());
1101 Record.push_back(0);
1102 Record.AddSelectorRef(E->getSelector());
1105 Record.AddSourceLocation(E->getLeftLoc());
1106 Record.AddSourceLocation(E->getRightLoc());
1108 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1109 Arg != ArgEnd; ++Arg)
1110 Record.AddStmt(*Arg);
1112 SourceLocation *Locs = E->getStoredSelLocs();
1113 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1114 Record.AddSourceLocation(Locs[i]);
1116 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1119 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1121 Record.AddStmt(S->getElement());
1122 Record.AddStmt(S->getCollection());
1123 Record.AddStmt(S->getBody());
1124 Record.AddSourceLocation(S->getForLoc());
1125 Record.AddSourceLocation(S->getRParenLoc());
1126 Code = serialization::STMT_OBJC_FOR_COLLECTION;
1129 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1130 Record.AddStmt(S->getCatchBody());
1131 Record.AddDeclRef(S->getCatchParamDecl());
1132 Record.AddSourceLocation(S->getAtCatchLoc());
1133 Record.AddSourceLocation(S->getRParenLoc());
1134 Code = serialization::STMT_OBJC_CATCH;
1137 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1138 Record.AddStmt(S->getFinallyBody());
1139 Record.AddSourceLocation(S->getAtFinallyLoc());
1140 Code = serialization::STMT_OBJC_FINALLY;
1143 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1144 Record.AddStmt(S->getSubStmt());
1145 Record.AddSourceLocation(S->getAtLoc());
1146 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1149 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1150 Record.push_back(S->getNumCatchStmts());
1151 Record.push_back(S->getFinallyStmt() != nullptr);
1152 Record.AddStmt(S->getTryBody());
1153 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1154 Record.AddStmt(S->getCatchStmt(I));
1155 if (S->getFinallyStmt())
1156 Record.AddStmt(S->getFinallyStmt());
1157 Record.AddSourceLocation(S->getAtTryLoc());
1158 Code = serialization::STMT_OBJC_AT_TRY;
1161 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1162 Record.AddStmt(S->getSynchExpr());
1163 Record.AddStmt(S->getSynchBody());
1164 Record.AddSourceLocation(S->getAtSynchronizedLoc());
1165 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1168 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1169 Record.AddStmt(S->getThrowExpr());
1170 Record.AddSourceLocation(S->getThrowLoc());
1171 Code = serialization::STMT_OBJC_AT_THROW;
1174 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1176 Record.push_back(E->getValue());
1177 Record.AddSourceLocation(E->getLocation());
1178 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1181 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1183 Record.AddSourceRange(E->getSourceRange());
1184 Record.AddVersionTuple(E->getVersion());
1185 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1188 //===----------------------------------------------------------------------===//
1189 // C++ Expressions and Statements.
1190 //===----------------------------------------------------------------------===//
1192 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1194 Record.AddSourceLocation(S->getCatchLoc());
1195 Record.AddDeclRef(S->getExceptionDecl());
1196 Record.AddStmt(S->getHandlerBlock());
1197 Code = serialization::STMT_CXX_CATCH;
1200 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1202 Record.push_back(S->getNumHandlers());
1203 Record.AddSourceLocation(S->getTryLoc());
1204 Record.AddStmt(S->getTryBlock());
1205 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1206 Record.AddStmt(S->getHandler(i));
1207 Code = serialization::STMT_CXX_TRY;
1210 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1212 Record.AddSourceLocation(S->getForLoc());
1213 Record.AddSourceLocation(S->getCoawaitLoc());
1214 Record.AddSourceLocation(S->getColonLoc());
1215 Record.AddSourceLocation(S->getRParenLoc());
1216 Record.AddStmt(S->getRangeStmt());
1217 Record.AddStmt(S->getBeginStmt());
1218 Record.AddStmt(S->getEndStmt());
1219 Record.AddStmt(S->getCond());
1220 Record.AddStmt(S->getInc());
1221 Record.AddStmt(S->getLoopVarStmt());
1222 Record.AddStmt(S->getBody());
1223 Code = serialization::STMT_CXX_FOR_RANGE;
1226 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1228 Record.AddSourceLocation(S->getKeywordLoc());
1229 Record.push_back(S->isIfExists());
1230 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1231 Record.AddDeclarationNameInfo(S->getNameInfo());
1232 Record.AddStmt(S->getSubStmt());
1233 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1236 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1238 Record.push_back(E->getOperator());
1239 Record.AddSourceRange(E->Range);
1240 Record.push_back(E->getFPFeatures().getInt());
1241 Code = serialization::EXPR_CXX_OPERATOR_CALL;
1244 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1246 Code = serialization::EXPR_CXX_MEMBER_CALL;
1249 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1251 Record.push_back(E->getNumArgs());
1252 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1253 Record.AddStmt(E->getArg(I));
1254 Record.AddDeclRef(E->getConstructor());
1255 Record.AddSourceLocation(E->getLocation());
1256 Record.push_back(E->isElidable());
1257 Record.push_back(E->hadMultipleCandidates());
1258 Record.push_back(E->isListInitialization());
1259 Record.push_back(E->isStdInitListInitialization());
1260 Record.push_back(E->requiresZeroInitialization());
1261 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
1262 Record.AddSourceRange(E->getParenOrBraceRange());
1263 Code = serialization::EXPR_CXX_CONSTRUCT;
1266 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1268 Record.AddDeclRef(E->getConstructor());
1269 Record.AddSourceLocation(E->getLocation());
1270 Record.push_back(E->constructsVBase());
1271 Record.push_back(E->inheritedFromVBase());
1272 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1275 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1276 VisitCXXConstructExpr(E);
1277 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1278 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1281 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1283 Record.push_back(E->NumCaptures);
1284 Record.AddSourceRange(E->IntroducerRange);
1285 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
1286 Record.AddSourceLocation(E->CaptureDefaultLoc);
1287 Record.push_back(E->ExplicitParams);
1288 Record.push_back(E->ExplicitResultType);
1289 Record.AddSourceLocation(E->ClosingBrace);
1291 // Add capture initializers.
1292 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1293 CEnd = E->capture_init_end();
1298 Code = serialization::EXPR_LAMBDA;
1301 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1303 Record.AddStmt(E->getSubExpr());
1304 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1307 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1308 VisitExplicitCastExpr(E);
1309 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1310 Record.AddSourceRange(E->getAngleBrackets());
1313 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1314 VisitCXXNamedCastExpr(E);
1315 Code = serialization::EXPR_CXX_STATIC_CAST;
1318 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1319 VisitCXXNamedCastExpr(E);
1320 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1323 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1324 VisitCXXNamedCastExpr(E);
1325 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1328 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1329 VisitCXXNamedCastExpr(E);
1330 Code = serialization::EXPR_CXX_CONST_CAST;
1333 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1334 VisitExplicitCastExpr(E);
1335 Record.AddSourceLocation(E->getLParenLoc());
1336 Record.AddSourceLocation(E->getRParenLoc());
1337 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1340 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1342 Record.AddSourceLocation(E->UDSuffixLoc);
1343 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1346 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1348 Record.push_back(E->getValue());
1349 Record.AddSourceLocation(E->getLocation());
1350 Code = serialization::EXPR_CXX_BOOL_LITERAL;
1353 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1355 Record.AddSourceLocation(E->getLocation());
1356 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1359 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1361 Record.AddSourceRange(E->getSourceRange());
1362 if (E->isTypeOperand()) {
1363 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1364 Code = serialization::EXPR_CXX_TYPEID_TYPE;
1366 Record.AddStmt(E->getExprOperand());
1367 Code = serialization::EXPR_CXX_TYPEID_EXPR;
1371 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1373 Record.AddSourceLocation(E->getLocation());
1374 Record.push_back(E->isImplicit());
1375 Code = serialization::EXPR_CXX_THIS;
1378 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1380 Record.AddSourceLocation(E->getThrowLoc());
1381 Record.AddStmt(E->getSubExpr());
1382 Record.push_back(E->isThrownVariableInScope());
1383 Code = serialization::EXPR_CXX_THROW;
1386 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1388 Record.AddDeclRef(E->getParam());
1389 Record.AddSourceLocation(E->getUsedLocation());
1390 Code = serialization::EXPR_CXX_DEFAULT_ARG;
1393 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1395 Record.AddDeclRef(E->getField());
1396 Record.AddSourceLocation(E->getExprLoc());
1397 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1400 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1402 Record.AddCXXTemporary(E->getTemporary());
1403 Record.AddStmt(E->getSubExpr());
1404 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1407 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1409 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1410 Record.AddSourceLocation(E->getRParenLoc());
1411 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1414 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1416 Record.push_back(E->isGlobalNew());
1417 Record.push_back(E->isArray());
1418 Record.push_back(E->passAlignment());
1419 Record.push_back(E->doesUsualArrayDeleteWantSize());
1420 Record.push_back(E->getNumPlacementArgs());
1421 Record.push_back(E->StoredInitializationStyle);
1422 Record.AddDeclRef(E->getOperatorNew());
1423 Record.AddDeclRef(E->getOperatorDelete());
1424 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1425 Record.AddSourceRange(E->getTypeIdParens());
1426 Record.AddSourceRange(E->getSourceRange());
1427 Record.AddSourceRange(E->getDirectInitRange());
1428 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
1432 Code = serialization::EXPR_CXX_NEW;
1435 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1437 Record.push_back(E->isGlobalDelete());
1438 Record.push_back(E->isArrayForm());
1439 Record.push_back(E->isArrayFormAsWritten());
1440 Record.push_back(E->doesUsualArrayDeleteWantSize());
1441 Record.AddDeclRef(E->getOperatorDelete());
1442 Record.AddStmt(E->getArgument());
1443 Record.AddSourceLocation(E->getSourceRange().getBegin());
1445 Code = serialization::EXPR_CXX_DELETE;
1448 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1451 Record.AddStmt(E->getBase());
1452 Record.push_back(E->isArrow());
1453 Record.AddSourceLocation(E->getOperatorLoc());
1454 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1455 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1456 Record.AddSourceLocation(E->getColonColonLoc());
1457 Record.AddSourceLocation(E->getTildeLoc());
1459 // PseudoDestructorTypeStorage.
1460 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
1461 if (E->getDestroyedTypeIdentifier())
1462 Record.AddSourceLocation(E->getDestroyedTypeLoc());
1464 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
1466 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1469 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1471 Record.push_back(E->getNumObjects());
1472 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
1473 Record.AddDeclRef(E->getObject(i));
1475 Record.push_back(E->cleanupsHaveSideEffects());
1476 Record.AddStmt(E->getSubExpr());
1477 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1481 ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
1484 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1487 Record.push_back(E->HasTemplateKWAndArgsInfo);
1488 if (E->HasTemplateKWAndArgsInfo) {
1489 const ASTTemplateKWAndArgsInfo &ArgInfo =
1490 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1491 Record.push_back(ArgInfo.NumTemplateArgs);
1492 AddTemplateKWAndArgsInfo(ArgInfo,
1493 E->getTrailingObjects<TemplateArgumentLoc>());
1496 if (!E->isImplicitAccess())
1497 Record.AddStmt(E->getBase());
1499 Record.AddStmt(nullptr);
1500 Record.AddTypeRef(E->getBaseType());
1501 Record.push_back(E->isArrow());
1502 Record.AddSourceLocation(E->getOperatorLoc());
1503 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1504 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1505 Record.AddDeclarationNameInfo(E->MemberNameInfo);
1506 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
1510 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1513 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1516 Record.push_back(E->HasTemplateKWAndArgsInfo);
1517 if (E->HasTemplateKWAndArgsInfo) {
1518 const ASTTemplateKWAndArgsInfo &ArgInfo =
1519 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1520 Record.push_back(ArgInfo.NumTemplateArgs);
1521 AddTemplateKWAndArgsInfo(ArgInfo,
1522 E->getTrailingObjects<TemplateArgumentLoc>());
1525 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1526 Record.AddDeclarationNameInfo(E->NameInfo);
1527 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
1531 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1533 Record.push_back(E->arg_size());
1534 for (CXXUnresolvedConstructExpr::arg_iterator
1535 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
1536 Record.AddStmt(*ArgI);
1537 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1538 Record.AddSourceLocation(E->getLParenLoc());
1539 Record.AddSourceLocation(E->getRParenLoc());
1540 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
1543 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
1546 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1549 Record.push_back(E->HasTemplateKWAndArgsInfo);
1550 if (E->HasTemplateKWAndArgsInfo) {
1551 const ASTTemplateKWAndArgsInfo &ArgInfo =
1552 *E->getTrailingASTTemplateKWAndArgsInfo();
1553 Record.push_back(ArgInfo.NumTemplateArgs);
1554 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
1557 Record.push_back(E->getNumDecls());
1558 for (OverloadExpr::decls_iterator
1559 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
1560 Record.AddDeclRef(OvI.getDecl());
1561 Record.push_back(OvI.getAccess());
1564 Record.AddDeclarationNameInfo(E->NameInfo);
1565 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1568 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1569 VisitOverloadExpr(E);
1570 Record.push_back(E->isArrow());
1571 Record.push_back(E->hasUnresolvedUsing());
1572 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1573 Record.AddTypeRef(E->getBaseType());
1574 Record.AddSourceLocation(E->getOperatorLoc());
1575 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
1578 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1579 VisitOverloadExpr(E);
1580 Record.push_back(E->requiresADL());
1581 Record.push_back(E->isOverloaded());
1582 Record.AddDeclRef(E->getNamingClass());
1583 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
1586 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1588 Record.push_back(E->TypeTraitExprBits.NumArgs);
1589 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1590 Record.push_back(E->TypeTraitExprBits.Value);
1591 Record.AddSourceRange(E->getSourceRange());
1592 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1593 Record.AddTypeSourceInfo(E->getArg(I));
1594 Code = serialization::EXPR_TYPE_TRAIT;
1597 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1599 Record.push_back(E->getTrait());
1600 Record.push_back(E->getValue());
1601 Record.AddSourceRange(E->getSourceRange());
1602 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
1603 Record.AddStmt(E->getDimensionExpression());
1604 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1607 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1609 Record.push_back(E->getTrait());
1610 Record.push_back(E->getValue());
1611 Record.AddSourceRange(E->getSourceRange());
1612 Record.AddStmt(E->getQueriedExpression());
1613 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1616 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1618 Record.push_back(E->getValue());
1619 Record.AddSourceRange(E->getSourceRange());
1620 Record.AddStmt(E->getOperand());
1621 Code = serialization::EXPR_CXX_NOEXCEPT;
1624 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1626 Record.AddSourceLocation(E->getEllipsisLoc());
1627 Record.push_back(E->NumExpansions);
1628 Record.AddStmt(E->getPattern());
1629 Code = serialization::EXPR_PACK_EXPANSION;
1632 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1634 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1636 Record.AddSourceLocation(E->OperatorLoc);
1637 Record.AddSourceLocation(E->PackLoc);
1638 Record.AddSourceLocation(E->RParenLoc);
1639 Record.AddDeclRef(E->Pack);
1640 if (E->isPartiallySubstituted()) {
1641 for (const auto &TA : E->getPartialArguments())
1642 Record.AddTemplateArgument(TA);
1643 } else if (!E->isValueDependent()) {
1644 Record.push_back(E->getPackLength());
1646 Code = serialization::EXPR_SIZEOF_PACK;
1649 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1650 SubstNonTypeTemplateParmExpr *E) {
1652 Record.AddDeclRef(E->getParameter());
1653 Record.AddSourceLocation(E->getNameLoc());
1654 Record.AddStmt(E->getReplacement());
1655 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1658 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1659 SubstNonTypeTemplateParmPackExpr *E) {
1661 Record.AddDeclRef(E->getParameterPack());
1662 Record.AddTemplateArgument(E->getArgumentPack());
1663 Record.AddSourceLocation(E->getParameterPackLocation());
1664 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1667 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1669 Record.push_back(E->getNumExpansions());
1670 Record.AddDeclRef(E->getParameterPack());
1671 Record.AddSourceLocation(E->getParameterPackLocation());
1672 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1674 Record.AddDeclRef(*I);
1675 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1678 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1680 Record.AddStmt(E->getTemporary());
1681 Record.AddDeclRef(E->getExtendingDecl());
1682 Record.push_back(E->getManglingNumber());
1683 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1686 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1688 Record.AddSourceLocation(E->LParenLoc);
1689 Record.AddSourceLocation(E->EllipsisLoc);
1690 Record.AddSourceLocation(E->RParenLoc);
1691 Record.AddStmt(E->SubExprs[0]);
1692 Record.AddStmt(E->SubExprs[1]);
1693 Record.push_back(E->Opcode);
1694 Code = serialization::EXPR_CXX_FOLD;
1697 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1699 Record.AddStmt(E->getSourceExpr());
1700 Record.AddSourceLocation(E->getLocation());
1701 Code = serialization::EXPR_OPAQUE_VALUE;
1704 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1706 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
1707 llvm_unreachable("Cannot write TypoExpr nodes");
1710 //===----------------------------------------------------------------------===//
1711 // CUDA Expressions and Statements.
1712 //===----------------------------------------------------------------------===//
1714 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1716 Record.AddStmt(E->getConfig());
1717 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1720 //===----------------------------------------------------------------------===//
1721 // OpenCL Expressions and Statements.
1722 //===----------------------------------------------------------------------===//
1723 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1725 Record.AddSourceLocation(E->getBuiltinLoc());
1726 Record.AddSourceLocation(E->getRParenLoc());
1727 Record.AddStmt(E->getSrcExpr());
1728 Code = serialization::EXPR_ASTYPE;
1731 //===----------------------------------------------------------------------===//
1732 // Microsoft Expressions and Statements.
1733 //===----------------------------------------------------------------------===//
1734 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1736 Record.push_back(E->isArrow());
1737 Record.AddStmt(E->getBaseExpr());
1738 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1739 Record.AddSourceLocation(E->getMemberLoc());
1740 Record.AddDeclRef(E->getPropertyDecl());
1741 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1744 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1746 Record.AddStmt(E->getBase());
1747 Record.AddStmt(E->getIdx());
1748 Record.AddSourceLocation(E->getRBracketLoc());
1749 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1752 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1754 Record.AddSourceRange(E->getSourceRange());
1755 Record.AddString(E->getUuidStr());
1756 if (E->isTypeOperand()) {
1757 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1758 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1760 Record.AddStmt(E->getExprOperand());
1761 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1765 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1767 Record.AddSourceLocation(S->getExceptLoc());
1768 Record.AddStmt(S->getFilterExpr());
1769 Record.AddStmt(S->getBlock());
1770 Code = serialization::STMT_SEH_EXCEPT;
1773 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1775 Record.AddSourceLocation(S->getFinallyLoc());
1776 Record.AddStmt(S->getBlock());
1777 Code = serialization::STMT_SEH_FINALLY;
1780 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1782 Record.push_back(S->getIsCXXTry());
1783 Record.AddSourceLocation(S->getTryLoc());
1784 Record.AddStmt(S->getTryBlock());
1785 Record.AddStmt(S->getHandler());
1786 Code = serialization::STMT_SEH_TRY;
1789 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1791 Record.AddSourceLocation(S->getLeaveLoc());
1792 Code = serialization::STMT_SEH_LEAVE;
1795 //===----------------------------------------------------------------------===//
1797 //===----------------------------------------------------------------------===//
1800 class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> {
1801 ASTRecordWriter &Record;
1803 OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {}
1804 #define OPENMP_CLAUSE(Name, Class) \
1805 void Visit##Class(Class *S);
1806 #include "clang/Basic/OpenMPKinds.def"
1807 void writeClause(OMPClause *C);
1808 void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
1809 void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
1813 void OMPClauseWriter::writeClause(OMPClause *C) {
1814 Record.push_back(C->getClauseKind());
1816 Record.AddSourceLocation(C->getLocStart());
1817 Record.AddSourceLocation(C->getLocEnd());
1820 void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) {
1821 Record.push_back(C->getCaptureRegion());
1822 Record.AddStmt(C->getPreInitStmt());
1825 void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) {
1826 VisitOMPClauseWithPreInit(C);
1827 Record.AddStmt(C->getPostUpdateExpr());
1830 void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) {
1831 VisitOMPClauseWithPreInit(C);
1832 Record.push_back(C->getNameModifier());
1833 Record.AddSourceLocation(C->getNameModifierLoc());
1834 Record.AddSourceLocation(C->getColonLoc());
1835 Record.AddStmt(C->getCondition());
1836 Record.AddSourceLocation(C->getLParenLoc());
1839 void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) {
1840 Record.AddStmt(C->getCondition());
1841 Record.AddSourceLocation(C->getLParenLoc());
1844 void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
1845 VisitOMPClauseWithPreInit(C);
1846 Record.AddStmt(C->getNumThreads());
1847 Record.AddSourceLocation(C->getLParenLoc());
1850 void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) {
1851 Record.AddStmt(C->getSafelen());
1852 Record.AddSourceLocation(C->getLParenLoc());
1855 void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
1856 Record.AddStmt(C->getSimdlen());
1857 Record.AddSourceLocation(C->getLParenLoc());
1860 void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) {
1861 Record.AddStmt(C->getNumForLoops());
1862 Record.AddSourceLocation(C->getLParenLoc());
1865 void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
1866 Record.push_back(C->getDefaultKind());
1867 Record.AddSourceLocation(C->getLParenLoc());
1868 Record.AddSourceLocation(C->getDefaultKindKwLoc());
1871 void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
1872 Record.push_back(C->getProcBindKind());
1873 Record.AddSourceLocation(C->getLParenLoc());
1874 Record.AddSourceLocation(C->getProcBindKindKwLoc());
1877 void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
1878 VisitOMPClauseWithPreInit(C);
1879 Record.push_back(C->getScheduleKind());
1880 Record.push_back(C->getFirstScheduleModifier());
1881 Record.push_back(C->getSecondScheduleModifier());
1882 Record.AddStmt(C->getChunkSize());
1883 Record.AddSourceLocation(C->getLParenLoc());
1884 Record.AddSourceLocation(C->getFirstScheduleModifierLoc());
1885 Record.AddSourceLocation(C->getSecondScheduleModifierLoc());
1886 Record.AddSourceLocation(C->getScheduleKindLoc());
1887 Record.AddSourceLocation(C->getCommaLoc());
1890 void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) {
1891 Record.AddStmt(C->getNumForLoops());
1892 Record.AddSourceLocation(C->getLParenLoc());
1895 void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {}
1897 void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}
1899 void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
1901 void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {}
1903 void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {}
1905 void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {}
1907 void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {}
1909 void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
1911 void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {}
1913 void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {}
1915 void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {}
1917 void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
1918 Record.push_back(C->varlist_size());
1919 Record.AddSourceLocation(C->getLParenLoc());
1920 for (auto *VE : C->varlists()) {
1923 for (auto *VE : C->private_copies()) {
1928 void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
1929 Record.push_back(C->varlist_size());
1930 VisitOMPClauseWithPreInit(C);
1931 Record.AddSourceLocation(C->getLParenLoc());
1932 for (auto *VE : C->varlists()) {
1935 for (auto *VE : C->private_copies()) {
1938 for (auto *VE : C->inits()) {
1943 void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
1944 Record.push_back(C->varlist_size());
1945 VisitOMPClauseWithPostUpdate(C);
1946 Record.AddSourceLocation(C->getLParenLoc());
1947 for (auto *VE : C->varlists())
1949 for (auto *E : C->private_copies())
1951 for (auto *E : C->source_exprs())
1953 for (auto *E : C->destination_exprs())
1955 for (auto *E : C->assignment_ops())
1959 void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {
1960 Record.push_back(C->varlist_size());
1961 Record.AddSourceLocation(C->getLParenLoc());
1962 for (auto *VE : C->varlists())
1966 void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) {
1967 Record.push_back(C->varlist_size());
1968 VisitOMPClauseWithPostUpdate(C);
1969 Record.AddSourceLocation(C->getLParenLoc());
1970 Record.AddSourceLocation(C->getColonLoc());
1971 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
1972 Record.AddDeclarationNameInfo(C->getNameInfo());
1973 for (auto *VE : C->varlists())
1975 for (auto *VE : C->privates())
1977 for (auto *E : C->lhs_exprs())
1979 for (auto *E : C->rhs_exprs())
1981 for (auto *E : C->reduction_ops())
1985 void OMPClauseWriter::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) {
1986 Record.push_back(C->varlist_size());
1987 VisitOMPClauseWithPostUpdate(C);
1988 Record.AddSourceLocation(C->getLParenLoc());
1989 Record.AddSourceLocation(C->getColonLoc());
1990 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
1991 Record.AddDeclarationNameInfo(C->getNameInfo());
1992 for (auto *VE : C->varlists())
1994 for (auto *VE : C->privates())
1996 for (auto *E : C->lhs_exprs())
1998 for (auto *E : C->rhs_exprs())
2000 for (auto *E : C->reduction_ops())
2004 void OMPClauseWriter::VisitOMPInReductionClause(OMPInReductionClause *C) {
2005 Record.push_back(C->varlist_size());
2006 VisitOMPClauseWithPostUpdate(C);
2007 Record.AddSourceLocation(C->getLParenLoc());
2008 Record.AddSourceLocation(C->getColonLoc());
2009 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
2010 Record.AddDeclarationNameInfo(C->getNameInfo());
2011 for (auto *VE : C->varlists())
2013 for (auto *VE : C->privates())
2015 for (auto *E : C->lhs_exprs())
2017 for (auto *E : C->rhs_exprs())
2019 for (auto *E : C->reduction_ops())
2021 for (auto *E : C->taskgroup_descriptors())
2025 void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) {
2026 Record.push_back(C->varlist_size());
2027 VisitOMPClauseWithPostUpdate(C);
2028 Record.AddSourceLocation(C->getLParenLoc());
2029 Record.AddSourceLocation(C->getColonLoc());
2030 Record.push_back(C->getModifier());
2031 Record.AddSourceLocation(C->getModifierLoc());
2032 for (auto *VE : C->varlists()) {
2035 for (auto *VE : C->privates()) {
2038 for (auto *VE : C->inits()) {
2041 for (auto *VE : C->updates()) {
2044 for (auto *VE : C->finals()) {
2047 Record.AddStmt(C->getStep());
2048 Record.AddStmt(C->getCalcStep());
2051 void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) {
2052 Record.push_back(C->varlist_size());
2053 Record.AddSourceLocation(C->getLParenLoc());
2054 Record.AddSourceLocation(C->getColonLoc());
2055 for (auto *VE : C->varlists())
2057 Record.AddStmt(C->getAlignment());
2060 void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) {
2061 Record.push_back(C->varlist_size());
2062 Record.AddSourceLocation(C->getLParenLoc());
2063 for (auto *VE : C->varlists())
2065 for (auto *E : C->source_exprs())
2067 for (auto *E : C->destination_exprs())
2069 for (auto *E : C->assignment_ops())
2073 void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
2074 Record.push_back(C->varlist_size());
2075 Record.AddSourceLocation(C->getLParenLoc());
2076 for (auto *VE : C->varlists())
2078 for (auto *E : C->source_exprs())
2080 for (auto *E : C->destination_exprs())
2082 for (auto *E : C->assignment_ops())
2086 void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) {
2087 Record.push_back(C->varlist_size());
2088 Record.AddSourceLocation(C->getLParenLoc());
2089 for (auto *VE : C->varlists())
2093 void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) {
2094 Record.push_back(C->varlist_size());
2095 Record.AddSourceLocation(C->getLParenLoc());
2096 Record.push_back(C->getDependencyKind());
2097 Record.AddSourceLocation(C->getDependencyLoc());
2098 Record.AddSourceLocation(C->getColonLoc());
2099 for (auto *VE : C->varlists())
2101 Record.AddStmt(C->getCounterValue());
2104 void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) {
2105 VisitOMPClauseWithPreInit(C);
2106 Record.AddStmt(C->getDevice());
2107 Record.AddSourceLocation(C->getLParenLoc());
2110 void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) {
2111 Record.push_back(C->varlist_size());
2112 Record.push_back(C->getUniqueDeclarationsNum());
2113 Record.push_back(C->getTotalComponentListNum());
2114 Record.push_back(C->getTotalComponentsNum());
2115 Record.AddSourceLocation(C->getLParenLoc());
2116 Record.push_back(C->getMapTypeModifier());
2117 Record.push_back(C->getMapType());
2118 Record.AddSourceLocation(C->getMapLoc());
2119 Record.AddSourceLocation(C->getColonLoc());
2120 for (auto *E : C->varlists())
2122 for (auto *D : C->all_decls())
2123 Record.AddDeclRef(D);
2124 for (auto N : C->all_num_lists())
2125 Record.push_back(N);
2126 for (auto N : C->all_lists_sizes())
2127 Record.push_back(N);
2128 for (auto &M : C->all_components()) {
2129 Record.AddStmt(M.getAssociatedExpression());
2130 Record.AddDeclRef(M.getAssociatedDeclaration());
2134 void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
2135 VisitOMPClauseWithPreInit(C);
2136 Record.AddStmt(C->getNumTeams());
2137 Record.AddSourceLocation(C->getLParenLoc());
2140 void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
2141 VisitOMPClauseWithPreInit(C);
2142 Record.AddStmt(C->getThreadLimit());
2143 Record.AddSourceLocation(C->getLParenLoc());
2146 void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) {
2147 Record.AddStmt(C->getPriority());
2148 Record.AddSourceLocation(C->getLParenLoc());
2151 void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
2152 Record.AddStmt(C->getGrainsize());
2153 Record.AddSourceLocation(C->getLParenLoc());
2156 void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
2157 Record.AddStmt(C->getNumTasks());
2158 Record.AddSourceLocation(C->getLParenLoc());
2161 void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) {
2162 Record.AddStmt(C->getHint());
2163 Record.AddSourceLocation(C->getLParenLoc());
2166 void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) {
2167 VisitOMPClauseWithPreInit(C);
2168 Record.push_back(C->getDistScheduleKind());
2169 Record.AddStmt(C->getChunkSize());
2170 Record.AddSourceLocation(C->getLParenLoc());
2171 Record.AddSourceLocation(C->getDistScheduleKindLoc());
2172 Record.AddSourceLocation(C->getCommaLoc());
2175 void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
2176 Record.push_back(C->getDefaultmapKind());
2177 Record.push_back(C->getDefaultmapModifier());
2178 Record.AddSourceLocation(C->getLParenLoc());
2179 Record.AddSourceLocation(C->getDefaultmapModifierLoc());
2180 Record.AddSourceLocation(C->getDefaultmapKindLoc());
2183 void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) {
2184 Record.push_back(C->varlist_size());
2185 Record.push_back(C->getUniqueDeclarationsNum());
2186 Record.push_back(C->getTotalComponentListNum());
2187 Record.push_back(C->getTotalComponentsNum());
2188 Record.AddSourceLocation(C->getLParenLoc());
2189 for (auto *E : C->varlists())
2191 for (auto *D : C->all_decls())
2192 Record.AddDeclRef(D);
2193 for (auto N : C->all_num_lists())
2194 Record.push_back(N);
2195 for (auto N : C->all_lists_sizes())
2196 Record.push_back(N);
2197 for (auto &M : C->all_components()) {
2198 Record.AddStmt(M.getAssociatedExpression());
2199 Record.AddDeclRef(M.getAssociatedDeclaration());
2203 void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) {
2204 Record.push_back(C->varlist_size());
2205 Record.push_back(C->getUniqueDeclarationsNum());
2206 Record.push_back(C->getTotalComponentListNum());
2207 Record.push_back(C->getTotalComponentsNum());
2208 Record.AddSourceLocation(C->getLParenLoc());
2209 for (auto *E : C->varlists())
2211 for (auto *D : C->all_decls())
2212 Record.AddDeclRef(D);
2213 for (auto N : C->all_num_lists())
2214 Record.push_back(N);
2215 for (auto N : C->all_lists_sizes())
2216 Record.push_back(N);
2217 for (auto &M : C->all_components()) {
2218 Record.AddStmt(M.getAssociatedExpression());
2219 Record.AddDeclRef(M.getAssociatedDeclaration());
2223 void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
2224 Record.push_back(C->varlist_size());
2225 Record.push_back(C->getUniqueDeclarationsNum());
2226 Record.push_back(C->getTotalComponentListNum());
2227 Record.push_back(C->getTotalComponentsNum());
2228 Record.AddSourceLocation(C->getLParenLoc());
2229 for (auto *E : C->varlists())
2231 for (auto *VE : C->private_copies())
2233 for (auto *VE : C->inits())
2235 for (auto *D : C->all_decls())
2236 Record.AddDeclRef(D);
2237 for (auto N : C->all_num_lists())
2238 Record.push_back(N);
2239 for (auto N : C->all_lists_sizes())
2240 Record.push_back(N);
2241 for (auto &M : C->all_components()) {
2242 Record.AddStmt(M.getAssociatedExpression());
2243 Record.AddDeclRef(M.getAssociatedDeclaration());
2247 void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
2248 Record.push_back(C->varlist_size());
2249 Record.push_back(C->getUniqueDeclarationsNum());
2250 Record.push_back(C->getTotalComponentListNum());
2251 Record.push_back(C->getTotalComponentsNum());
2252 Record.AddSourceLocation(C->getLParenLoc());
2253 for (auto *E : C->varlists())
2255 for (auto *D : C->all_decls())
2256 Record.AddDeclRef(D);
2257 for (auto N : C->all_num_lists())
2258 Record.push_back(N);
2259 for (auto N : C->all_lists_sizes())
2260 Record.push_back(N);
2261 for (auto &M : C->all_components()) {
2262 Record.AddStmt(M.getAssociatedExpression());
2263 Record.AddDeclRef(M.getAssociatedDeclaration());
2267 //===----------------------------------------------------------------------===//
2268 // OpenMP Directives.
2269 //===----------------------------------------------------------------------===//
2270 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2271 Record.AddSourceLocation(E->getLocStart());
2272 Record.AddSourceLocation(E->getLocEnd());
2273 OMPClauseWriter ClauseWriter(Record);
2274 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
2275 ClauseWriter.writeClause(E->getClause(i));
2277 if (E->hasAssociatedStmt())
2278 Record.AddStmt(E->getAssociatedStmt());
2281 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
2283 Record.push_back(D->getNumClauses());
2284 Record.push_back(D->getCollapsedNumber());
2285 VisitOMPExecutableDirective(D);
2286 Record.AddStmt(D->getIterationVariable());
2287 Record.AddStmt(D->getLastIteration());
2288 Record.AddStmt(D->getCalcLastIteration());
2289 Record.AddStmt(D->getPreCond());
2290 Record.AddStmt(D->getCond());
2291 Record.AddStmt(D->getInit());
2292 Record.AddStmt(D->getInc());
2293 Record.AddStmt(D->getPreInits());
2294 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
2295 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
2296 isOpenMPDistributeDirective(D->getDirectiveKind())) {
2297 Record.AddStmt(D->getIsLastIterVariable());
2298 Record.AddStmt(D->getLowerBoundVariable());
2299 Record.AddStmt(D->getUpperBoundVariable());
2300 Record.AddStmt(D->getStrideVariable());
2301 Record.AddStmt(D->getEnsureUpperBound());
2302 Record.AddStmt(D->getNextLowerBound());
2303 Record.AddStmt(D->getNextUpperBound());
2304 Record.AddStmt(D->getNumIterations());
2306 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
2307 Record.AddStmt(D->getPrevLowerBoundVariable());
2308 Record.AddStmt(D->getPrevUpperBoundVariable());
2309 Record.AddStmt(D->getDistInc());
2310 Record.AddStmt(D->getPrevEnsureUpperBound());
2311 Record.AddStmt(D->getCombinedLowerBoundVariable());
2312 Record.AddStmt(D->getCombinedUpperBoundVariable());
2313 Record.AddStmt(D->getCombinedEnsureUpperBound());
2314 Record.AddStmt(D->getCombinedInit());
2315 Record.AddStmt(D->getCombinedCond());
2316 Record.AddStmt(D->getCombinedNextLowerBound());
2317 Record.AddStmt(D->getCombinedNextUpperBound());
2319 for (auto I : D->counters()) {
2322 for (auto I : D->private_counters()) {
2325 for (auto I : D->inits()) {
2328 for (auto I : D->updates()) {
2331 for (auto I : D->finals()) {
2336 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2338 Record.push_back(D->getNumClauses());
2339 VisitOMPExecutableDirective(D);
2340 Record.push_back(D->hasCancel() ? 1 : 0);
2341 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2344 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2345 VisitOMPLoopDirective(D);
2346 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2349 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2350 VisitOMPLoopDirective(D);
2351 Record.push_back(D->hasCancel() ? 1 : 0);
2352 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2355 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2356 VisitOMPLoopDirective(D);
2357 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2360 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2362 Record.push_back(D->getNumClauses());
2363 VisitOMPExecutableDirective(D);
2364 Record.push_back(D->hasCancel() ? 1 : 0);
2365 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2368 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2370 VisitOMPExecutableDirective(D);
2371 Record.push_back(D->hasCancel() ? 1 : 0);
2372 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2375 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2377 Record.push_back(D->getNumClauses());
2378 VisitOMPExecutableDirective(D);
2379 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2382 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2384 VisitOMPExecutableDirective(D);
2385 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2388 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2390 Record.push_back(D->getNumClauses());
2391 VisitOMPExecutableDirective(D);
2392 Record.AddDeclarationNameInfo(D->getDirectiveName());
2393 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2396 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2397 VisitOMPLoopDirective(D);
2398 Record.push_back(D->hasCancel() ? 1 : 0);
2399 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2402 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2403 OMPParallelForSimdDirective *D) {
2404 VisitOMPLoopDirective(D);
2405 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2408 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2409 OMPParallelSectionsDirective *D) {
2411 Record.push_back(D->getNumClauses());
2412 VisitOMPExecutableDirective(D);
2413 Record.push_back(D->hasCancel() ? 1 : 0);
2414 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2417 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2419 Record.push_back(D->getNumClauses());
2420 VisitOMPExecutableDirective(D);
2421 Record.push_back(D->hasCancel() ? 1 : 0);
2422 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2425 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2427 Record.push_back(D->getNumClauses());
2428 VisitOMPExecutableDirective(D);
2429 Record.AddStmt(D->getX());
2430 Record.AddStmt(D->getV());
2431 Record.AddStmt(D->getExpr());
2432 Record.AddStmt(D->getUpdateExpr());
2433 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
2434 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
2435 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2438 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2440 Record.push_back(D->getNumClauses());
2441 VisitOMPExecutableDirective(D);
2442 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2445 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2447 Record.push_back(D->getNumClauses());
2448 VisitOMPExecutableDirective(D);
2449 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2452 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2453 OMPTargetEnterDataDirective *D) {
2455 Record.push_back(D->getNumClauses());
2456 VisitOMPExecutableDirective(D);
2457 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2460 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2461 OMPTargetExitDataDirective *D) {
2463 Record.push_back(D->getNumClauses());
2464 VisitOMPExecutableDirective(D);
2465 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2468 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2469 OMPTargetParallelDirective *D) {
2471 Record.push_back(D->getNumClauses());
2472 VisitOMPExecutableDirective(D);
2473 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2476 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2477 OMPTargetParallelForDirective *D) {
2478 VisitOMPLoopDirective(D);
2479 Record.push_back(D->hasCancel() ? 1 : 0);
2480 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2483 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2485 VisitOMPExecutableDirective(D);
2486 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2489 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2491 VisitOMPExecutableDirective(D);
2492 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2495 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2497 VisitOMPExecutableDirective(D);
2498 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2501 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2503 Record.push_back(D->getNumClauses());
2504 VisitOMPExecutableDirective(D);
2505 Record.AddStmt(D->getReductionRef());
2506 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2509 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2511 Record.push_back(D->getNumClauses());
2512 VisitOMPExecutableDirective(D);
2513 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2516 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2518 Record.push_back(D->getNumClauses());
2519 VisitOMPExecutableDirective(D);
2520 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2523 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2525 Record.push_back(D->getNumClauses());
2526 VisitOMPExecutableDirective(D);
2527 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2530 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2531 OMPCancellationPointDirective *D) {
2533 VisitOMPExecutableDirective(D);
2534 Record.push_back(D->getCancelRegion());
2535 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2538 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2540 Record.push_back(D->getNumClauses());
2541 VisitOMPExecutableDirective(D);
2542 Record.push_back(D->getCancelRegion());
2543 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2546 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2547 VisitOMPLoopDirective(D);
2548 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2551 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2552 VisitOMPLoopDirective(D);
2553 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2556 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2557 VisitOMPLoopDirective(D);
2558 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2561 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2563 Record.push_back(D->getNumClauses());
2564 VisitOMPExecutableDirective(D);
2565 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2568 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2569 OMPDistributeParallelForDirective *D) {
2570 VisitOMPLoopDirective(D);
2571 Record.push_back(D->hasCancel() ? 1 : 0);
2572 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2575 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2576 OMPDistributeParallelForSimdDirective *D) {
2577 VisitOMPLoopDirective(D);
2578 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2581 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2582 OMPDistributeSimdDirective *D) {
2583 VisitOMPLoopDirective(D);
2584 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2587 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2588 OMPTargetParallelForSimdDirective *D) {
2589 VisitOMPLoopDirective(D);
2590 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2593 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2594 VisitOMPLoopDirective(D);
2595 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2598 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2599 OMPTeamsDistributeDirective *D) {
2600 VisitOMPLoopDirective(D);
2601 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2604 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2605 OMPTeamsDistributeSimdDirective *D) {
2606 VisitOMPLoopDirective(D);
2607 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2610 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2611 OMPTeamsDistributeParallelForSimdDirective *D) {
2612 VisitOMPLoopDirective(D);
2613 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2616 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2617 OMPTeamsDistributeParallelForDirective *D) {
2618 VisitOMPLoopDirective(D);
2619 Record.push_back(D->hasCancel() ? 1 : 0);
2620 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2623 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2625 Record.push_back(D->getNumClauses());
2626 VisitOMPExecutableDirective(D);
2627 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2630 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2631 OMPTargetTeamsDistributeDirective *D) {
2632 VisitOMPLoopDirective(D);
2633 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2636 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2637 OMPTargetTeamsDistributeParallelForDirective *D) {
2638 VisitOMPLoopDirective(D);
2639 Record.push_back(D->hasCancel() ? 1 : 0);
2640 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2643 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2644 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2645 VisitOMPLoopDirective(D);
2646 Code = serialization::
2647 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2650 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2651 OMPTargetTeamsDistributeSimdDirective *D) {
2652 VisitOMPLoopDirective(D);
2653 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2656 //===----------------------------------------------------------------------===//
2657 // ASTWriter Implementation
2658 //===----------------------------------------------------------------------===//
2660 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2661 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
2662 "SwitchCase recorded twice");
2663 unsigned NextID = SwitchCaseIDs.size();
2664 SwitchCaseIDs[S] = NextID;
2668 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2669 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
2670 "SwitchCase hasn't been seen yet");
2671 return SwitchCaseIDs[S];
2674 void ASTWriter::ClearSwitchCaseIDs() {
2675 SwitchCaseIDs.clear();
2678 /// \brief Write the given substatement or subexpression to the
2680 void ASTWriter::WriteSubStmt(Stmt *S) {
2682 ASTStmtWriter Writer(*this, Record);
2686 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2690 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2691 if (I != SubStmtEntries.end()) {
2692 Record.push_back(I->second);
2693 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2698 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2700 struct ParentStmtInserterRAII {
2702 llvm::DenseSet<Stmt *> &ParentStmts;
2704 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2705 : S(S), ParentStmts(ParentStmts) {
2706 ParentStmts.insert(S);
2708 ~ParentStmtInserterRAII() {
2709 ParentStmts.erase(S);
2713 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2718 uint64_t Offset = Writer.Emit();
2719 SubStmtEntries[S] = Offset;
2722 /// \brief Flush all of the statements that have been added to the
2723 /// queue via AddStmt().
2724 void ASTRecordWriter::FlushStmts() {
2725 // We expect to be the only consumer of the two temporary statement maps,
2726 // assert that they are empty.
2727 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2728 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2730 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2731 Writer->WriteSubStmt(StmtsToEmit[I]);
2733 assert(N == StmtsToEmit.size() && "record modified while being written!");
2735 // Note that we are at the end of a full expression. Any
2736 // expression records that follow this one are part of a different
2738 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2740 Writer->SubStmtEntries.clear();
2741 Writer->ParentStmts.clear();
2744 StmtsToEmit.clear();
2747 void ASTRecordWriter::FlushSubStmts() {
2748 // For a nested statement, write out the substatements in reverse order (so
2749 // that a simple stack machine can be used when loading), and don't emit a
2750 // STMT_STOP after each one.
2751 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2752 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
2753 assert(N == StmtsToEmit.size() && "record modified while being written!");
2756 StmtsToEmit.clear();