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 *S) {
304 // FIXME: Implement coroutine serialization.
305 llvm_unreachable("unimplemented");
308 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
309 // FIXME: Implement coroutine serialization.
310 llvm_unreachable("unimplemented");
313 void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *S) {
314 // FIXME: Implement coroutine serialization.
315 llvm_unreachable("unimplemented");
318 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *S) {
319 // FIXME: Implement coroutine serialization.
320 llvm_unreachable("unimplemented");
323 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
326 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
328 // CapturedDecl and captured region kind
329 Record.AddDeclRef(S->getCapturedDecl());
330 Record.push_back(S->getCapturedRegionKind());
332 Record.AddDeclRef(S->getCapturedRecordDecl());
335 for (auto *I : S->capture_inits())
339 Record.AddStmt(S->getCapturedStmt());
342 for (const auto &I : S->captures()) {
343 if (I.capturesThis() || I.capturesVariableArrayType())
344 Record.AddDeclRef(nullptr);
346 Record.AddDeclRef(I.getCapturedVar());
347 Record.push_back(I.getCaptureKind());
348 Record.AddSourceLocation(I.getLocation());
351 Code = serialization::STMT_CAPTURED;
354 void ASTStmtWriter::VisitExpr(Expr *E) {
356 Record.AddTypeRef(E->getType());
357 Record.push_back(E->isTypeDependent());
358 Record.push_back(E->isValueDependent());
359 Record.push_back(E->isInstantiationDependent());
360 Record.push_back(E->containsUnexpandedParameterPack());
361 Record.push_back(E->getValueKind());
362 Record.push_back(E->getObjectKind());
365 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
367 Record.AddSourceLocation(E->getLocation());
368 Record.push_back(E->getIdentType()); // FIXME: stable encoding
369 Record.AddStmt(E->getFunctionName());
370 Code = serialization::EXPR_PREDEFINED;
373 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
376 Record.push_back(E->hasQualifier());
377 Record.push_back(E->getDecl() != E->getFoundDecl());
378 Record.push_back(E->hasTemplateKWAndArgsInfo());
379 Record.push_back(E->hadMultipleCandidates());
380 Record.push_back(E->refersToEnclosingVariableOrCapture());
382 if (E->hasTemplateKWAndArgsInfo()) {
383 unsigned NumTemplateArgs = E->getNumTemplateArgs();
384 Record.push_back(NumTemplateArgs);
387 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
389 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
390 (E->getDecl() == E->getFoundDecl()) &&
391 nk == DeclarationName::Identifier) {
392 AbbrevToUse = Writer.getDeclRefExprAbbrev();
395 if (E->hasQualifier())
396 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
398 if (E->getDecl() != E->getFoundDecl())
399 Record.AddDeclRef(E->getFoundDecl());
401 if (E->hasTemplateKWAndArgsInfo())
402 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
403 E->getTrailingObjects<TemplateArgumentLoc>());
405 Record.AddDeclRef(E->getDecl());
406 Record.AddSourceLocation(E->getLocation());
407 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
408 Code = serialization::EXPR_DECL_REF;
411 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
413 Record.AddSourceLocation(E->getLocation());
414 Record.AddAPInt(E->getValue());
416 if (E->getValue().getBitWidth() == 32) {
417 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
420 Code = serialization::EXPR_INTEGER_LITERAL;
423 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
425 Record.push_back(E->getRawSemantics());
426 Record.push_back(E->isExact());
427 Record.AddAPFloat(E->getValue());
428 Record.AddSourceLocation(E->getLocation());
429 Code = serialization::EXPR_FLOATING_LITERAL;
432 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
434 Record.AddStmt(E->getSubExpr());
435 Code = serialization::EXPR_IMAGINARY_LITERAL;
438 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
440 Record.push_back(E->getByteLength());
441 Record.push_back(E->getNumConcatenated());
442 Record.push_back(E->getKind());
443 Record.push_back(E->isPascal());
444 // FIXME: String data should be stored as a blob at the end of the
445 // StringLiteral. However, we can't do so now because we have no
446 // provision for coping with abbreviations when we're jumping around
447 // the AST file during deserialization.
448 Record.append(E->getBytes().begin(), E->getBytes().end());
449 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
450 Record.AddSourceLocation(E->getStrTokenLoc(I));
451 Code = serialization::EXPR_STRING_LITERAL;
454 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
456 Record.push_back(E->getValue());
457 Record.AddSourceLocation(E->getLocation());
458 Record.push_back(E->getKind());
460 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
462 Code = serialization::EXPR_CHARACTER_LITERAL;
465 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
467 Record.AddSourceLocation(E->getLParen());
468 Record.AddSourceLocation(E->getRParen());
469 Record.AddStmt(E->getSubExpr());
470 Code = serialization::EXPR_PAREN;
473 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
475 Record.push_back(E->NumExprs);
476 for (unsigned i=0; i != E->NumExprs; ++i)
477 Record.AddStmt(E->Exprs[i]);
478 Record.AddSourceLocation(E->LParenLoc);
479 Record.AddSourceLocation(E->RParenLoc);
480 Code = serialization::EXPR_PAREN_LIST;
483 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
485 Record.AddStmt(E->getSubExpr());
486 Record.push_back(E->getOpcode()); // FIXME: stable encoding
487 Record.AddSourceLocation(E->getOperatorLoc());
488 Code = serialization::EXPR_UNARY_OPERATOR;
491 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
493 Record.push_back(E->getNumComponents());
494 Record.push_back(E->getNumExpressions());
495 Record.AddSourceLocation(E->getOperatorLoc());
496 Record.AddSourceLocation(E->getRParenLoc());
497 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
498 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
499 const OffsetOfNode &ON = E->getComponent(I);
500 Record.push_back(ON.getKind()); // FIXME: Stable encoding
501 Record.AddSourceLocation(ON.getSourceRange().getBegin());
502 Record.AddSourceLocation(ON.getSourceRange().getEnd());
503 switch (ON.getKind()) {
504 case OffsetOfNode::Array:
505 Record.push_back(ON.getArrayExprIndex());
508 case OffsetOfNode::Field:
509 Record.AddDeclRef(ON.getField());
512 case OffsetOfNode::Identifier:
513 Record.AddIdentifierRef(ON.getFieldName());
516 case OffsetOfNode::Base:
517 Record.AddCXXBaseSpecifier(*ON.getBase());
521 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
522 Record.AddStmt(E->getIndexExpr(I));
523 Code = serialization::EXPR_OFFSETOF;
526 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
528 Record.push_back(E->getKind());
529 if (E->isArgumentType())
530 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
533 Record.AddStmt(E->getArgumentExpr());
535 Record.AddSourceLocation(E->getOperatorLoc());
536 Record.AddSourceLocation(E->getRParenLoc());
537 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
540 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
542 Record.AddStmt(E->getLHS());
543 Record.AddStmt(E->getRHS());
544 Record.AddSourceLocation(E->getRBracketLoc());
545 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
548 void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
550 Record.AddStmt(E->getBase());
551 Record.AddStmt(E->getLowerBound());
552 Record.AddStmt(E->getLength());
553 Record.AddSourceLocation(E->getColonLoc());
554 Record.AddSourceLocation(E->getRBracketLoc());
555 Code = serialization::EXPR_OMP_ARRAY_SECTION;
558 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
560 Record.push_back(E->getNumArgs());
561 Record.AddSourceLocation(E->getRParenLoc());
562 Record.AddStmt(E->getCallee());
563 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
564 Arg != ArgEnd; ++Arg)
565 Record.AddStmt(*Arg);
566 Code = serialization::EXPR_CALL;
569 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
570 // Don't call VisitExpr, we'll write everything here.
572 Record.push_back(E->hasQualifier());
573 if (E->hasQualifier())
574 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
576 Record.push_back(E->HasTemplateKWAndArgsInfo);
577 if (E->HasTemplateKWAndArgsInfo) {
578 Record.AddSourceLocation(E->getTemplateKeywordLoc());
579 unsigned NumTemplateArgs = E->getNumTemplateArgs();
580 Record.push_back(NumTemplateArgs);
581 Record.AddSourceLocation(E->getLAngleLoc());
582 Record.AddSourceLocation(E->getRAngleLoc());
583 for (unsigned i=0; i != NumTemplateArgs; ++i)
584 Record.AddTemplateArgumentLoc(E->getTemplateArgs()[i]);
587 Record.push_back(E->hadMultipleCandidates());
589 DeclAccessPair FoundDecl = E->getFoundDecl();
590 Record.AddDeclRef(FoundDecl.getDecl());
591 Record.push_back(FoundDecl.getAccess());
593 Record.AddTypeRef(E->getType());
594 Record.push_back(E->getValueKind());
595 Record.push_back(E->getObjectKind());
596 Record.AddStmt(E->getBase());
597 Record.AddDeclRef(E->getMemberDecl());
598 Record.AddSourceLocation(E->getMemberLoc());
599 Record.push_back(E->isArrow());
600 Record.AddSourceLocation(E->getOperatorLoc());
601 Record.AddDeclarationNameLoc(E->MemberDNLoc,
602 E->getMemberDecl()->getDeclName());
603 Code = serialization::EXPR_MEMBER;
606 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
608 Record.AddStmt(E->getBase());
609 Record.AddSourceLocation(E->getIsaMemberLoc());
610 Record.AddSourceLocation(E->getOpLoc());
611 Record.push_back(E->isArrow());
612 Code = serialization::EXPR_OBJC_ISA;
616 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
618 Record.AddStmt(E->getSubExpr());
619 Record.push_back(E->shouldCopy());
620 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
623 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
624 VisitExplicitCastExpr(E);
625 Record.AddSourceLocation(E->getLParenLoc());
626 Record.AddSourceLocation(E->getBridgeKeywordLoc());
627 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
628 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
631 void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
633 Record.push_back(E->path_size());
634 Record.AddStmt(E->getSubExpr());
635 Record.push_back(E->getCastKind()); // FIXME: stable encoding
637 for (CastExpr::path_iterator
638 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
639 Record.AddCXXBaseSpecifier(**PI);
642 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
644 Record.AddStmt(E->getLHS());
645 Record.AddStmt(E->getRHS());
646 Record.push_back(E->getOpcode()); // FIXME: stable encoding
647 Record.AddSourceLocation(E->getOperatorLoc());
648 Record.push_back(E->isFPContractable());
649 Code = serialization::EXPR_BINARY_OPERATOR;
652 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
653 VisitBinaryOperator(E);
654 Record.AddTypeRef(E->getComputationLHSType());
655 Record.AddTypeRef(E->getComputationResultType());
656 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
659 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
661 Record.AddStmt(E->getCond());
662 Record.AddStmt(E->getLHS());
663 Record.AddStmt(E->getRHS());
664 Record.AddSourceLocation(E->getQuestionLoc());
665 Record.AddSourceLocation(E->getColonLoc());
666 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
670 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
672 Record.AddStmt(E->getOpaqueValue());
673 Record.AddStmt(E->getCommon());
674 Record.AddStmt(E->getCond());
675 Record.AddStmt(E->getTrueExpr());
676 Record.AddStmt(E->getFalseExpr());
677 Record.AddSourceLocation(E->getQuestionLoc());
678 Record.AddSourceLocation(E->getColonLoc());
679 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
682 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
685 if (E->path_size() == 0)
686 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
688 Code = serialization::EXPR_IMPLICIT_CAST;
691 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
693 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
696 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
697 VisitExplicitCastExpr(E);
698 Record.AddSourceLocation(E->getLParenLoc());
699 Record.AddSourceLocation(E->getRParenLoc());
700 Code = serialization::EXPR_CSTYLE_CAST;
703 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
705 Record.AddSourceLocation(E->getLParenLoc());
706 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
707 Record.AddStmt(E->getInitializer());
708 Record.push_back(E->isFileScope());
709 Code = serialization::EXPR_COMPOUND_LITERAL;
712 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
714 Record.AddStmt(E->getBase());
715 Record.AddIdentifierRef(&E->getAccessor());
716 Record.AddSourceLocation(E->getAccessorLoc());
717 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
720 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
722 // NOTE: only add the (possibly null) syntactic form.
723 // No need to serialize the isSemanticForm flag and the semantic form.
724 Record.AddStmt(E->getSyntacticForm());
725 Record.AddSourceLocation(E->getLBraceLoc());
726 Record.AddSourceLocation(E->getRBraceLoc());
727 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
728 Record.push_back(isArrayFiller);
730 Record.AddStmt(E->getArrayFiller());
732 Record.AddDeclRef(E->getInitializedFieldInUnion());
733 Record.push_back(E->hadArrayRangeDesignator());
734 Record.push_back(E->getNumInits());
736 // ArrayFiller may have filled "holes" due to designated initializer.
737 // Replace them by 0 to indicate that the filler goes in that place.
738 Expr *filler = E->getArrayFiller();
739 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
740 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
742 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
743 Record.AddStmt(E->getInit(I));
745 Code = serialization::EXPR_INIT_LIST;
748 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
750 Record.push_back(E->getNumSubExprs());
751 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
752 Record.AddStmt(E->getSubExpr(I));
753 Record.AddSourceLocation(E->getEqualOrColonLoc());
754 Record.push_back(E->usesGNUSyntax());
755 for (const DesignatedInitExpr::Designator &D : E->designators()) {
756 if (D.isFieldDesignator()) {
757 if (FieldDecl *Field = D.getField()) {
758 Record.push_back(serialization::DESIG_FIELD_DECL);
759 Record.AddDeclRef(Field);
761 Record.push_back(serialization::DESIG_FIELD_NAME);
762 Record.AddIdentifierRef(D.getFieldName());
764 Record.AddSourceLocation(D.getDotLoc());
765 Record.AddSourceLocation(D.getFieldLoc());
766 } else if (D.isArrayDesignator()) {
767 Record.push_back(serialization::DESIG_ARRAY);
768 Record.push_back(D.getFirstExprIndex());
769 Record.AddSourceLocation(D.getLBracketLoc());
770 Record.AddSourceLocation(D.getRBracketLoc());
772 assert(D.isArrayRangeDesignator() && "Unknown designator");
773 Record.push_back(serialization::DESIG_ARRAY_RANGE);
774 Record.push_back(D.getFirstExprIndex());
775 Record.AddSourceLocation(D.getLBracketLoc());
776 Record.AddSourceLocation(D.getEllipsisLoc());
777 Record.AddSourceLocation(D.getRBracketLoc());
780 Code = serialization::EXPR_DESIGNATED_INIT;
783 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
785 Record.AddStmt(E->getBase());
786 Record.AddStmt(E->getUpdater());
787 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
790 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
792 Code = serialization::EXPR_NO_INIT;
795 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
797 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
800 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
802 Record.AddStmt(E->getSubExpr());
803 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
804 Record.AddSourceLocation(E->getBuiltinLoc());
805 Record.AddSourceLocation(E->getRParenLoc());
806 Record.push_back(E->isMicrosoftABI());
807 Code = serialization::EXPR_VA_ARG;
810 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
812 Record.AddSourceLocation(E->getAmpAmpLoc());
813 Record.AddSourceLocation(E->getLabelLoc());
814 Record.AddDeclRef(E->getLabel());
815 Code = serialization::EXPR_ADDR_LABEL;
818 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
820 Record.AddStmt(E->getSubStmt());
821 Record.AddSourceLocation(E->getLParenLoc());
822 Record.AddSourceLocation(E->getRParenLoc());
823 Code = serialization::EXPR_STMT;
826 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
828 Record.AddStmt(E->getCond());
829 Record.AddStmt(E->getLHS());
830 Record.AddStmt(E->getRHS());
831 Record.AddSourceLocation(E->getBuiltinLoc());
832 Record.AddSourceLocation(E->getRParenLoc());
833 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
834 Code = serialization::EXPR_CHOOSE;
837 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
839 Record.AddSourceLocation(E->getTokenLocation());
840 Code = serialization::EXPR_GNU_NULL;
843 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
845 Record.push_back(E->getNumSubExprs());
846 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
847 Record.AddStmt(E->getExpr(I));
848 Record.AddSourceLocation(E->getBuiltinLoc());
849 Record.AddSourceLocation(E->getRParenLoc());
850 Code = serialization::EXPR_SHUFFLE_VECTOR;
853 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
855 Record.AddSourceLocation(E->getBuiltinLoc());
856 Record.AddSourceLocation(E->getRParenLoc());
857 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
858 Record.AddStmt(E->getSrcExpr());
859 Code = serialization::EXPR_CONVERT_VECTOR;
862 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
864 Record.AddDeclRef(E->getBlockDecl());
865 Code = serialization::EXPR_BLOCK;
868 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
870 Record.push_back(E->getNumAssocs());
872 Record.AddStmt(E->getControllingExpr());
873 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
874 Record.AddTypeSourceInfo(E->getAssocTypeSourceInfo(I));
875 Record.AddStmt(E->getAssocExpr(I));
877 Record.push_back(E->isResultDependent() ? -1U : E->getResultIndex());
879 Record.AddSourceLocation(E->getGenericLoc());
880 Record.AddSourceLocation(E->getDefaultLoc());
881 Record.AddSourceLocation(E->getRParenLoc());
882 Code = serialization::EXPR_GENERIC_SELECTION;
885 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
887 Record.push_back(E->getNumSemanticExprs());
889 // Push the result index. Currently, this needs to exactly match
890 // the encoding used internally for ResultIndex.
891 unsigned result = E->getResultExprIndex();
892 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
893 Record.push_back(result);
895 Record.AddStmt(E->getSyntacticForm());
896 for (PseudoObjectExpr::semantics_iterator
897 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
900 Code = serialization::EXPR_PSEUDO_OBJECT;
903 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
905 Record.push_back(E->getOp());
906 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
907 Record.AddStmt(E->getSubExprs()[I]);
908 Record.AddSourceLocation(E->getBuiltinLoc());
909 Record.AddSourceLocation(E->getRParenLoc());
910 Code = serialization::EXPR_ATOMIC;
913 //===----------------------------------------------------------------------===//
914 // Objective-C Expressions and Statements.
915 //===----------------------------------------------------------------------===//
917 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
919 Record.AddStmt(E->getString());
920 Record.AddSourceLocation(E->getAtLoc());
921 Code = serialization::EXPR_OBJC_STRING_LITERAL;
924 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
926 Record.AddStmt(E->getSubExpr());
927 Record.AddDeclRef(E->getBoxingMethod());
928 Record.AddSourceRange(E->getSourceRange());
929 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
932 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
934 Record.push_back(E->getNumElements());
935 for (unsigned i = 0; i < E->getNumElements(); i++)
936 Record.AddStmt(E->getElement(i));
937 Record.AddDeclRef(E->getArrayWithObjectsMethod());
938 Record.AddSourceRange(E->getSourceRange());
939 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
942 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
944 Record.push_back(E->getNumElements());
945 Record.push_back(E->HasPackExpansions);
946 for (unsigned i = 0; i < E->getNumElements(); i++) {
947 ObjCDictionaryElement Element = E->getKeyValueElement(i);
948 Record.AddStmt(Element.Key);
949 Record.AddStmt(Element.Value);
950 if (E->HasPackExpansions) {
951 Record.AddSourceLocation(Element.EllipsisLoc);
952 unsigned NumExpansions = 0;
953 if (Element.NumExpansions)
954 NumExpansions = *Element.NumExpansions + 1;
955 Record.push_back(NumExpansions);
959 Record.AddDeclRef(E->getDictWithObjectsMethod());
960 Record.AddSourceRange(E->getSourceRange());
961 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
964 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
966 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
967 Record.AddSourceLocation(E->getAtLoc());
968 Record.AddSourceLocation(E->getRParenLoc());
969 Code = serialization::EXPR_OBJC_ENCODE;
972 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
974 Record.AddSelectorRef(E->getSelector());
975 Record.AddSourceLocation(E->getAtLoc());
976 Record.AddSourceLocation(E->getRParenLoc());
977 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
980 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
982 Record.AddDeclRef(E->getProtocol());
983 Record.AddSourceLocation(E->getAtLoc());
984 Record.AddSourceLocation(E->ProtoLoc);
985 Record.AddSourceLocation(E->getRParenLoc());
986 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
989 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
991 Record.AddDeclRef(E->getDecl());
992 Record.AddSourceLocation(E->getLocation());
993 Record.AddSourceLocation(E->getOpLoc());
994 Record.AddStmt(E->getBase());
995 Record.push_back(E->isArrow());
996 Record.push_back(E->isFreeIvar());
997 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
1000 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1002 Record.push_back(E->SetterAndMethodRefFlags.getInt());
1003 Record.push_back(E->isImplicitProperty());
1004 if (E->isImplicitProperty()) {
1005 Record.AddDeclRef(E->getImplicitPropertyGetter());
1006 Record.AddDeclRef(E->getImplicitPropertySetter());
1008 Record.AddDeclRef(E->getExplicitProperty());
1010 Record.AddSourceLocation(E->getLocation());
1011 Record.AddSourceLocation(E->getReceiverLocation());
1012 if (E->isObjectReceiver()) {
1013 Record.push_back(0);
1014 Record.AddStmt(E->getBase());
1015 } else if (E->isSuperReceiver()) {
1016 Record.push_back(1);
1017 Record.AddTypeRef(E->getSuperReceiverType());
1019 Record.push_back(2);
1020 Record.AddDeclRef(E->getClassReceiver());
1023 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
1026 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1028 Record.AddSourceLocation(E->getRBracket());
1029 Record.AddStmt(E->getBaseExpr());
1030 Record.AddStmt(E->getKeyExpr());
1031 Record.AddDeclRef(E->getAtIndexMethodDecl());
1032 Record.AddDeclRef(E->setAtIndexMethodDecl());
1034 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1037 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1039 Record.push_back(E->getNumArgs());
1040 Record.push_back(E->getNumStoredSelLocs());
1041 Record.push_back(E->SelLocsKind);
1042 Record.push_back(E->isDelegateInitCall());
1043 Record.push_back(E->IsImplicit);
1044 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1045 switch (E->getReceiverKind()) {
1046 case ObjCMessageExpr::Instance:
1047 Record.AddStmt(E->getInstanceReceiver());
1050 case ObjCMessageExpr::Class:
1051 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
1054 case ObjCMessageExpr::SuperClass:
1055 case ObjCMessageExpr::SuperInstance:
1056 Record.AddTypeRef(E->getSuperType());
1057 Record.AddSourceLocation(E->getSuperLoc());
1061 if (E->getMethodDecl()) {
1062 Record.push_back(1);
1063 Record.AddDeclRef(E->getMethodDecl());
1065 Record.push_back(0);
1066 Record.AddSelectorRef(E->getSelector());
1069 Record.AddSourceLocation(E->getLeftLoc());
1070 Record.AddSourceLocation(E->getRightLoc());
1072 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1073 Arg != ArgEnd; ++Arg)
1074 Record.AddStmt(*Arg);
1076 SourceLocation *Locs = E->getStoredSelLocs();
1077 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1078 Record.AddSourceLocation(Locs[i]);
1080 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1083 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1085 Record.AddStmt(S->getElement());
1086 Record.AddStmt(S->getCollection());
1087 Record.AddStmt(S->getBody());
1088 Record.AddSourceLocation(S->getForLoc());
1089 Record.AddSourceLocation(S->getRParenLoc());
1090 Code = serialization::STMT_OBJC_FOR_COLLECTION;
1093 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1094 Record.AddStmt(S->getCatchBody());
1095 Record.AddDeclRef(S->getCatchParamDecl());
1096 Record.AddSourceLocation(S->getAtCatchLoc());
1097 Record.AddSourceLocation(S->getRParenLoc());
1098 Code = serialization::STMT_OBJC_CATCH;
1101 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1102 Record.AddStmt(S->getFinallyBody());
1103 Record.AddSourceLocation(S->getAtFinallyLoc());
1104 Code = serialization::STMT_OBJC_FINALLY;
1107 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1108 Record.AddStmt(S->getSubStmt());
1109 Record.AddSourceLocation(S->getAtLoc());
1110 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1113 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1114 Record.push_back(S->getNumCatchStmts());
1115 Record.push_back(S->getFinallyStmt() != nullptr);
1116 Record.AddStmt(S->getTryBody());
1117 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1118 Record.AddStmt(S->getCatchStmt(I));
1119 if (S->getFinallyStmt())
1120 Record.AddStmt(S->getFinallyStmt());
1121 Record.AddSourceLocation(S->getAtTryLoc());
1122 Code = serialization::STMT_OBJC_AT_TRY;
1125 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1126 Record.AddStmt(S->getSynchExpr());
1127 Record.AddStmt(S->getSynchBody());
1128 Record.AddSourceLocation(S->getAtSynchronizedLoc());
1129 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1132 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1133 Record.AddStmt(S->getThrowExpr());
1134 Record.AddSourceLocation(S->getThrowLoc());
1135 Code = serialization::STMT_OBJC_AT_THROW;
1138 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1140 Record.push_back(E->getValue());
1141 Record.AddSourceLocation(E->getLocation());
1142 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1145 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1147 Record.AddSourceRange(E->getSourceRange());
1148 Record.AddVersionTuple(E->getVersion());
1149 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1152 //===----------------------------------------------------------------------===//
1153 // C++ Expressions and Statements.
1154 //===----------------------------------------------------------------------===//
1156 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1158 Record.AddSourceLocation(S->getCatchLoc());
1159 Record.AddDeclRef(S->getExceptionDecl());
1160 Record.AddStmt(S->getHandlerBlock());
1161 Code = serialization::STMT_CXX_CATCH;
1164 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1166 Record.push_back(S->getNumHandlers());
1167 Record.AddSourceLocation(S->getTryLoc());
1168 Record.AddStmt(S->getTryBlock());
1169 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1170 Record.AddStmt(S->getHandler(i));
1171 Code = serialization::STMT_CXX_TRY;
1174 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1176 Record.AddSourceLocation(S->getForLoc());
1177 Record.AddSourceLocation(S->getCoawaitLoc());
1178 Record.AddSourceLocation(S->getColonLoc());
1179 Record.AddSourceLocation(S->getRParenLoc());
1180 Record.AddStmt(S->getRangeStmt());
1181 Record.AddStmt(S->getBeginStmt());
1182 Record.AddStmt(S->getEndStmt());
1183 Record.AddStmt(S->getCond());
1184 Record.AddStmt(S->getInc());
1185 Record.AddStmt(S->getLoopVarStmt());
1186 Record.AddStmt(S->getBody());
1187 Code = serialization::STMT_CXX_FOR_RANGE;
1190 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1192 Record.AddSourceLocation(S->getKeywordLoc());
1193 Record.push_back(S->isIfExists());
1194 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1195 Record.AddDeclarationNameInfo(S->getNameInfo());
1196 Record.AddStmt(S->getSubStmt());
1197 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1200 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1202 Record.push_back(E->getOperator());
1203 Record.AddSourceRange(E->Range);
1204 Record.push_back(E->isFPContractable());
1205 Code = serialization::EXPR_CXX_OPERATOR_CALL;
1208 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1210 Code = serialization::EXPR_CXX_MEMBER_CALL;
1213 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1215 Record.push_back(E->getNumArgs());
1216 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1217 Record.AddStmt(E->getArg(I));
1218 Record.AddDeclRef(E->getConstructor());
1219 Record.AddSourceLocation(E->getLocation());
1220 Record.push_back(E->isElidable());
1221 Record.push_back(E->hadMultipleCandidates());
1222 Record.push_back(E->isListInitialization());
1223 Record.push_back(E->isStdInitListInitialization());
1224 Record.push_back(E->requiresZeroInitialization());
1225 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
1226 Record.AddSourceRange(E->getParenOrBraceRange());
1227 Code = serialization::EXPR_CXX_CONSTRUCT;
1230 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1232 Record.AddDeclRef(E->getConstructor());
1233 Record.AddSourceLocation(E->getLocation());
1234 Record.push_back(E->constructsVBase());
1235 Record.push_back(E->inheritedFromVBase());
1236 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1239 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1240 VisitCXXConstructExpr(E);
1241 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1242 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1245 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1247 Record.push_back(E->NumCaptures);
1248 unsigned NumArrayIndexVars = 0;
1249 if (E->HasArrayIndexVars)
1250 NumArrayIndexVars = E->getArrayIndexStarts()[E->NumCaptures];
1251 Record.push_back(NumArrayIndexVars);
1252 Record.AddSourceRange(E->IntroducerRange);
1253 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
1254 Record.AddSourceLocation(E->CaptureDefaultLoc);
1255 Record.push_back(E->ExplicitParams);
1256 Record.push_back(E->ExplicitResultType);
1257 Record.AddSourceLocation(E->ClosingBrace);
1259 // Add capture initializers.
1260 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1261 CEnd = E->capture_init_end();
1266 // Add array index variables, if any.
1267 if (NumArrayIndexVars) {
1268 Record.append(E->getArrayIndexStarts(),
1269 E->getArrayIndexStarts() + E->NumCaptures + 1);
1270 VarDecl **ArrayIndexVars = E->getArrayIndexVars();
1271 for (unsigned I = 0; I != NumArrayIndexVars; ++I)
1272 Record.AddDeclRef(ArrayIndexVars[I]);
1275 Code = serialization::EXPR_LAMBDA;
1278 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1280 Record.AddStmt(E->getSubExpr());
1281 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1284 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1285 VisitExplicitCastExpr(E);
1286 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1287 Record.AddSourceRange(E->getAngleBrackets());
1290 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1291 VisitCXXNamedCastExpr(E);
1292 Code = serialization::EXPR_CXX_STATIC_CAST;
1295 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1296 VisitCXXNamedCastExpr(E);
1297 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1300 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1301 VisitCXXNamedCastExpr(E);
1302 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1305 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1306 VisitCXXNamedCastExpr(E);
1307 Code = serialization::EXPR_CXX_CONST_CAST;
1310 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1311 VisitExplicitCastExpr(E);
1312 Record.AddSourceLocation(E->getLParenLoc());
1313 Record.AddSourceLocation(E->getRParenLoc());
1314 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1317 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1319 Record.AddSourceLocation(E->UDSuffixLoc);
1320 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1323 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1325 Record.push_back(E->getValue());
1326 Record.AddSourceLocation(E->getLocation());
1327 Code = serialization::EXPR_CXX_BOOL_LITERAL;
1330 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1332 Record.AddSourceLocation(E->getLocation());
1333 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1336 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1338 Record.AddSourceRange(E->getSourceRange());
1339 if (E->isTypeOperand()) {
1340 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1341 Code = serialization::EXPR_CXX_TYPEID_TYPE;
1343 Record.AddStmt(E->getExprOperand());
1344 Code = serialization::EXPR_CXX_TYPEID_EXPR;
1348 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1350 Record.AddSourceLocation(E->getLocation());
1351 Record.push_back(E->isImplicit());
1352 Code = serialization::EXPR_CXX_THIS;
1355 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1357 Record.AddSourceLocation(E->getThrowLoc());
1358 Record.AddStmt(E->getSubExpr());
1359 Record.push_back(E->isThrownVariableInScope());
1360 Code = serialization::EXPR_CXX_THROW;
1363 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1365 Record.AddDeclRef(E->getParam());
1366 Record.AddSourceLocation(E->getUsedLocation());
1367 Code = serialization::EXPR_CXX_DEFAULT_ARG;
1370 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1372 Record.AddDeclRef(E->getField());
1373 Record.AddSourceLocation(E->getExprLoc());
1374 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1377 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1379 Record.AddCXXTemporary(E->getTemporary());
1380 Record.AddStmt(E->getSubExpr());
1381 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1384 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1386 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1387 Record.AddSourceLocation(E->getRParenLoc());
1388 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1391 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1393 Record.push_back(E->isGlobalNew());
1394 Record.push_back(E->isArray());
1395 Record.push_back(E->doesUsualArrayDeleteWantSize());
1396 Record.push_back(E->getNumPlacementArgs());
1397 Record.push_back(E->StoredInitializationStyle);
1398 Record.AddDeclRef(E->getOperatorNew());
1399 Record.AddDeclRef(E->getOperatorDelete());
1400 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1401 Record.AddSourceRange(E->getTypeIdParens());
1402 Record.AddSourceRange(E->getSourceRange());
1403 Record.AddSourceRange(E->getDirectInitRange());
1404 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
1408 Code = serialization::EXPR_CXX_NEW;
1411 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1413 Record.push_back(E->isGlobalDelete());
1414 Record.push_back(E->isArrayForm());
1415 Record.push_back(E->isArrayFormAsWritten());
1416 Record.push_back(E->doesUsualArrayDeleteWantSize());
1417 Record.AddDeclRef(E->getOperatorDelete());
1418 Record.AddStmt(E->getArgument());
1419 Record.AddSourceLocation(E->getSourceRange().getBegin());
1421 Code = serialization::EXPR_CXX_DELETE;
1424 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1427 Record.AddStmt(E->getBase());
1428 Record.push_back(E->isArrow());
1429 Record.AddSourceLocation(E->getOperatorLoc());
1430 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1431 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1432 Record.AddSourceLocation(E->getColonColonLoc());
1433 Record.AddSourceLocation(E->getTildeLoc());
1435 // PseudoDestructorTypeStorage.
1436 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
1437 if (E->getDestroyedTypeIdentifier())
1438 Record.AddSourceLocation(E->getDestroyedTypeLoc());
1440 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
1442 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1445 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1447 Record.push_back(E->getNumObjects());
1448 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
1449 Record.AddDeclRef(E->getObject(i));
1451 Record.push_back(E->cleanupsHaveSideEffects());
1452 Record.AddStmt(E->getSubExpr());
1453 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1457 ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
1460 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1463 Record.push_back(E->HasTemplateKWAndArgsInfo);
1464 if (E->HasTemplateKWAndArgsInfo) {
1465 const ASTTemplateKWAndArgsInfo &ArgInfo =
1466 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1467 Record.push_back(ArgInfo.NumTemplateArgs);
1468 AddTemplateKWAndArgsInfo(ArgInfo,
1469 E->getTrailingObjects<TemplateArgumentLoc>());
1472 if (!E->isImplicitAccess())
1473 Record.AddStmt(E->getBase());
1475 Record.AddStmt(nullptr);
1476 Record.AddTypeRef(E->getBaseType());
1477 Record.push_back(E->isArrow());
1478 Record.AddSourceLocation(E->getOperatorLoc());
1479 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1480 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1481 Record.AddDeclarationNameInfo(E->MemberNameInfo);
1482 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
1486 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1489 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1492 Record.push_back(E->HasTemplateKWAndArgsInfo);
1493 if (E->HasTemplateKWAndArgsInfo) {
1494 const ASTTemplateKWAndArgsInfo &ArgInfo =
1495 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1496 Record.push_back(ArgInfo.NumTemplateArgs);
1497 AddTemplateKWAndArgsInfo(ArgInfo,
1498 E->getTrailingObjects<TemplateArgumentLoc>());
1501 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1502 Record.AddDeclarationNameInfo(E->NameInfo);
1503 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
1507 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1509 Record.push_back(E->arg_size());
1510 for (CXXUnresolvedConstructExpr::arg_iterator
1511 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
1512 Record.AddStmt(*ArgI);
1513 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1514 Record.AddSourceLocation(E->getLParenLoc());
1515 Record.AddSourceLocation(E->getRParenLoc());
1516 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
1519 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *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->getTrailingASTTemplateKWAndArgsInfo();
1529 Record.push_back(ArgInfo.NumTemplateArgs);
1530 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
1533 Record.push_back(E->getNumDecls());
1534 for (OverloadExpr::decls_iterator
1535 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
1536 Record.AddDeclRef(OvI.getDecl());
1537 Record.push_back(OvI.getAccess());
1540 Record.AddDeclarationNameInfo(E->NameInfo);
1541 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1544 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1545 VisitOverloadExpr(E);
1546 Record.push_back(E->isArrow());
1547 Record.push_back(E->hasUnresolvedUsing());
1548 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1549 Record.AddTypeRef(E->getBaseType());
1550 Record.AddSourceLocation(E->getOperatorLoc());
1551 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
1554 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1555 VisitOverloadExpr(E);
1556 Record.push_back(E->requiresADL());
1557 Record.push_back(E->isOverloaded());
1558 Record.AddDeclRef(E->getNamingClass());
1559 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
1562 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1564 Record.push_back(E->TypeTraitExprBits.NumArgs);
1565 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1566 Record.push_back(E->TypeTraitExprBits.Value);
1567 Record.AddSourceRange(E->getSourceRange());
1568 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1569 Record.AddTypeSourceInfo(E->getArg(I));
1570 Code = serialization::EXPR_TYPE_TRAIT;
1573 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1575 Record.push_back(E->getTrait());
1576 Record.push_back(E->getValue());
1577 Record.AddSourceRange(E->getSourceRange());
1578 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
1579 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1582 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1584 Record.push_back(E->getTrait());
1585 Record.push_back(E->getValue());
1586 Record.AddSourceRange(E->getSourceRange());
1587 Record.AddStmt(E->getQueriedExpression());
1588 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1591 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1593 Record.push_back(E->getValue());
1594 Record.AddSourceRange(E->getSourceRange());
1595 Record.AddStmt(E->getOperand());
1596 Code = serialization::EXPR_CXX_NOEXCEPT;
1599 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1601 Record.AddSourceLocation(E->getEllipsisLoc());
1602 Record.push_back(E->NumExpansions);
1603 Record.AddStmt(E->getPattern());
1604 Code = serialization::EXPR_PACK_EXPANSION;
1607 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1609 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1611 Record.AddSourceLocation(E->OperatorLoc);
1612 Record.AddSourceLocation(E->PackLoc);
1613 Record.AddSourceLocation(E->RParenLoc);
1614 Record.AddDeclRef(E->Pack);
1615 if (E->isPartiallySubstituted()) {
1616 for (const auto &TA : E->getPartialArguments())
1617 Record.AddTemplateArgument(TA);
1618 } else if (!E->isValueDependent()) {
1619 Record.push_back(E->getPackLength());
1621 Code = serialization::EXPR_SIZEOF_PACK;
1624 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1625 SubstNonTypeTemplateParmExpr *E) {
1627 Record.AddDeclRef(E->getParameter());
1628 Record.AddSourceLocation(E->getNameLoc());
1629 Record.AddStmt(E->getReplacement());
1630 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1633 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1634 SubstNonTypeTemplateParmPackExpr *E) {
1636 Record.AddDeclRef(E->getParameterPack());
1637 Record.AddTemplateArgument(E->getArgumentPack());
1638 Record.AddSourceLocation(E->getParameterPackLocation());
1639 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1642 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1644 Record.push_back(E->getNumExpansions());
1645 Record.AddDeclRef(E->getParameterPack());
1646 Record.AddSourceLocation(E->getParameterPackLocation());
1647 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1649 Record.AddDeclRef(*I);
1650 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1653 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1655 Record.AddStmt(E->getTemporary());
1656 Record.AddDeclRef(E->getExtendingDecl());
1657 Record.push_back(E->getManglingNumber());
1658 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1661 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1663 Record.AddSourceLocation(E->LParenLoc);
1664 Record.AddSourceLocation(E->EllipsisLoc);
1665 Record.AddSourceLocation(E->RParenLoc);
1666 Record.AddStmt(E->SubExprs[0]);
1667 Record.AddStmt(E->SubExprs[1]);
1668 Record.push_back(E->Opcode);
1669 Code = serialization::EXPR_CXX_FOLD;
1672 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1674 Record.AddStmt(E->getSourceExpr());
1675 Record.AddSourceLocation(E->getLocation());
1676 Code = serialization::EXPR_OPAQUE_VALUE;
1679 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1681 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
1682 llvm_unreachable("Cannot write TypoExpr nodes");
1685 //===----------------------------------------------------------------------===//
1686 // CUDA Expressions and Statements.
1687 //===----------------------------------------------------------------------===//
1689 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1691 Record.AddStmt(E->getConfig());
1692 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1695 //===----------------------------------------------------------------------===//
1696 // OpenCL Expressions and Statements.
1697 //===----------------------------------------------------------------------===//
1698 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1700 Record.AddSourceLocation(E->getBuiltinLoc());
1701 Record.AddSourceLocation(E->getRParenLoc());
1702 Record.AddStmt(E->getSrcExpr());
1703 Code = serialization::EXPR_ASTYPE;
1706 //===----------------------------------------------------------------------===//
1707 // Microsoft Expressions and Statements.
1708 //===----------------------------------------------------------------------===//
1709 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1711 Record.push_back(E->isArrow());
1712 Record.AddStmt(E->getBaseExpr());
1713 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1714 Record.AddSourceLocation(E->getMemberLoc());
1715 Record.AddDeclRef(E->getPropertyDecl());
1716 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1719 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1721 Record.AddStmt(E->getBase());
1722 Record.AddStmt(E->getIdx());
1723 Record.AddSourceLocation(E->getRBracketLoc());
1724 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1727 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1729 Record.AddSourceRange(E->getSourceRange());
1730 Record.AddString(E->getUuidStr());
1731 if (E->isTypeOperand()) {
1732 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1733 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1735 Record.AddStmt(E->getExprOperand());
1736 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1740 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1742 Record.AddSourceLocation(S->getExceptLoc());
1743 Record.AddStmt(S->getFilterExpr());
1744 Record.AddStmt(S->getBlock());
1745 Code = serialization::STMT_SEH_EXCEPT;
1748 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1750 Record.AddSourceLocation(S->getFinallyLoc());
1751 Record.AddStmt(S->getBlock());
1752 Code = serialization::STMT_SEH_FINALLY;
1755 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1757 Record.push_back(S->getIsCXXTry());
1758 Record.AddSourceLocation(S->getTryLoc());
1759 Record.AddStmt(S->getTryBlock());
1760 Record.AddStmt(S->getHandler());
1761 Code = serialization::STMT_SEH_TRY;
1764 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1766 Record.AddSourceLocation(S->getLeaveLoc());
1767 Code = serialization::STMT_SEH_LEAVE;
1770 //===----------------------------------------------------------------------===//
1772 //===----------------------------------------------------------------------===//
1775 class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> {
1776 ASTRecordWriter &Record;
1778 OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {}
1779 #define OPENMP_CLAUSE(Name, Class) \
1780 void Visit##Class(Class *S);
1781 #include "clang/Basic/OpenMPKinds.def"
1782 void writeClause(OMPClause *C);
1783 void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
1784 void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
1788 void OMPClauseWriter::writeClause(OMPClause *C) {
1789 Record.push_back(C->getClauseKind());
1791 Record.AddSourceLocation(C->getLocStart());
1792 Record.AddSourceLocation(C->getLocEnd());
1795 void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) {
1796 Record.AddStmt(C->getPreInitStmt());
1799 void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) {
1800 VisitOMPClauseWithPreInit(C);
1801 Record.AddStmt(C->getPostUpdateExpr());
1804 void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) {
1805 Record.push_back(C->getNameModifier());
1806 Record.AddSourceLocation(C->getNameModifierLoc());
1807 Record.AddSourceLocation(C->getColonLoc());
1808 Record.AddStmt(C->getCondition());
1809 Record.AddSourceLocation(C->getLParenLoc());
1812 void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) {
1813 Record.AddStmt(C->getCondition());
1814 Record.AddSourceLocation(C->getLParenLoc());
1817 void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
1818 Record.AddStmt(C->getNumThreads());
1819 Record.AddSourceLocation(C->getLParenLoc());
1822 void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) {
1823 Record.AddStmt(C->getSafelen());
1824 Record.AddSourceLocation(C->getLParenLoc());
1827 void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
1828 Record.AddStmt(C->getSimdlen());
1829 Record.AddSourceLocation(C->getLParenLoc());
1832 void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) {
1833 Record.AddStmt(C->getNumForLoops());
1834 Record.AddSourceLocation(C->getLParenLoc());
1837 void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
1838 Record.push_back(C->getDefaultKind());
1839 Record.AddSourceLocation(C->getLParenLoc());
1840 Record.AddSourceLocation(C->getDefaultKindKwLoc());
1843 void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
1844 Record.push_back(C->getProcBindKind());
1845 Record.AddSourceLocation(C->getLParenLoc());
1846 Record.AddSourceLocation(C->getProcBindKindKwLoc());
1849 void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
1850 VisitOMPClauseWithPreInit(C);
1851 Record.push_back(C->getScheduleKind());
1852 Record.push_back(C->getFirstScheduleModifier());
1853 Record.push_back(C->getSecondScheduleModifier());
1854 Record.AddStmt(C->getChunkSize());
1855 Record.AddSourceLocation(C->getLParenLoc());
1856 Record.AddSourceLocation(C->getFirstScheduleModifierLoc());
1857 Record.AddSourceLocation(C->getSecondScheduleModifierLoc());
1858 Record.AddSourceLocation(C->getScheduleKindLoc());
1859 Record.AddSourceLocation(C->getCommaLoc());
1862 void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) {
1863 Record.AddStmt(C->getNumForLoops());
1864 Record.AddSourceLocation(C->getLParenLoc());
1867 void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {}
1869 void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}
1871 void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
1873 void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {}
1875 void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {}
1877 void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {}
1879 void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {}
1881 void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
1883 void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {}
1885 void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {}
1887 void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {}
1889 void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
1890 Record.push_back(C->varlist_size());
1891 Record.AddSourceLocation(C->getLParenLoc());
1892 for (auto *VE : C->varlists()) {
1895 for (auto *VE : C->private_copies()) {
1900 void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
1901 Record.push_back(C->varlist_size());
1902 VisitOMPClauseWithPreInit(C);
1903 Record.AddSourceLocation(C->getLParenLoc());
1904 for (auto *VE : C->varlists()) {
1907 for (auto *VE : C->private_copies()) {
1910 for (auto *VE : C->inits()) {
1915 void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
1916 Record.push_back(C->varlist_size());
1917 VisitOMPClauseWithPostUpdate(C);
1918 Record.AddSourceLocation(C->getLParenLoc());
1919 for (auto *VE : C->varlists())
1921 for (auto *E : C->private_copies())
1923 for (auto *E : C->source_exprs())
1925 for (auto *E : C->destination_exprs())
1927 for (auto *E : C->assignment_ops())
1931 void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {
1932 Record.push_back(C->varlist_size());
1933 Record.AddSourceLocation(C->getLParenLoc());
1934 for (auto *VE : C->varlists())
1938 void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) {
1939 Record.push_back(C->varlist_size());
1940 VisitOMPClauseWithPostUpdate(C);
1941 Record.AddSourceLocation(C->getLParenLoc());
1942 Record.AddSourceLocation(C->getColonLoc());
1943 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
1944 Record.AddDeclarationNameInfo(C->getNameInfo());
1945 for (auto *VE : C->varlists())
1947 for (auto *VE : C->privates())
1949 for (auto *E : C->lhs_exprs())
1951 for (auto *E : C->rhs_exprs())
1953 for (auto *E : C->reduction_ops())
1957 void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) {
1958 Record.push_back(C->varlist_size());
1959 VisitOMPClauseWithPostUpdate(C);
1960 Record.AddSourceLocation(C->getLParenLoc());
1961 Record.AddSourceLocation(C->getColonLoc());
1962 Record.push_back(C->getModifier());
1963 Record.AddSourceLocation(C->getModifierLoc());
1964 for (auto *VE : C->varlists()) {
1967 for (auto *VE : C->privates()) {
1970 for (auto *VE : C->inits()) {
1973 for (auto *VE : C->updates()) {
1976 for (auto *VE : C->finals()) {
1979 Record.AddStmt(C->getStep());
1980 Record.AddStmt(C->getCalcStep());
1983 void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) {
1984 Record.push_back(C->varlist_size());
1985 Record.AddSourceLocation(C->getLParenLoc());
1986 Record.AddSourceLocation(C->getColonLoc());
1987 for (auto *VE : C->varlists())
1989 Record.AddStmt(C->getAlignment());
1992 void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) {
1993 Record.push_back(C->varlist_size());
1994 Record.AddSourceLocation(C->getLParenLoc());
1995 for (auto *VE : C->varlists())
1997 for (auto *E : C->source_exprs())
1999 for (auto *E : C->destination_exprs())
2001 for (auto *E : C->assignment_ops())
2005 void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
2006 Record.push_back(C->varlist_size());
2007 Record.AddSourceLocation(C->getLParenLoc());
2008 for (auto *VE : C->varlists())
2010 for (auto *E : C->source_exprs())
2012 for (auto *E : C->destination_exprs())
2014 for (auto *E : C->assignment_ops())
2018 void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) {
2019 Record.push_back(C->varlist_size());
2020 Record.AddSourceLocation(C->getLParenLoc());
2021 for (auto *VE : C->varlists())
2025 void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) {
2026 Record.push_back(C->varlist_size());
2027 Record.AddSourceLocation(C->getLParenLoc());
2028 Record.push_back(C->getDependencyKind());
2029 Record.AddSourceLocation(C->getDependencyLoc());
2030 Record.AddSourceLocation(C->getColonLoc());
2031 for (auto *VE : C->varlists())
2033 Record.AddStmt(C->getCounterValue());
2036 void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) {
2037 Record.AddStmt(C->getDevice());
2038 Record.AddSourceLocation(C->getLParenLoc());
2041 void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) {
2042 Record.push_back(C->varlist_size());
2043 Record.push_back(C->getUniqueDeclarationsNum());
2044 Record.push_back(C->getTotalComponentListNum());
2045 Record.push_back(C->getTotalComponentsNum());
2046 Record.AddSourceLocation(C->getLParenLoc());
2047 Record.push_back(C->getMapTypeModifier());
2048 Record.push_back(C->getMapType());
2049 Record.AddSourceLocation(C->getMapLoc());
2050 Record.AddSourceLocation(C->getColonLoc());
2051 for (auto *E : C->varlists())
2053 for (auto *D : C->all_decls())
2054 Record.AddDeclRef(D);
2055 for (auto N : C->all_num_lists())
2056 Record.push_back(N);
2057 for (auto N : C->all_lists_sizes())
2058 Record.push_back(N);
2059 for (auto &M : C->all_components()) {
2060 Record.AddStmt(M.getAssociatedExpression());
2061 Record.AddDeclRef(M.getAssociatedDeclaration());
2065 void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
2066 Record.AddStmt(C->getNumTeams());
2067 Record.AddSourceLocation(C->getLParenLoc());
2070 void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
2071 Record.AddStmt(C->getThreadLimit());
2072 Record.AddSourceLocation(C->getLParenLoc());
2075 void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) {
2076 Record.AddStmt(C->getPriority());
2077 Record.AddSourceLocation(C->getLParenLoc());
2080 void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
2081 Record.AddStmt(C->getGrainsize());
2082 Record.AddSourceLocation(C->getLParenLoc());
2085 void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
2086 Record.AddStmt(C->getNumTasks());
2087 Record.AddSourceLocation(C->getLParenLoc());
2090 void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) {
2091 Record.AddStmt(C->getHint());
2092 Record.AddSourceLocation(C->getLParenLoc());
2095 void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) {
2096 VisitOMPClauseWithPreInit(C);
2097 Record.push_back(C->getDistScheduleKind());
2098 Record.AddStmt(C->getChunkSize());
2099 Record.AddSourceLocation(C->getLParenLoc());
2100 Record.AddSourceLocation(C->getDistScheduleKindLoc());
2101 Record.AddSourceLocation(C->getCommaLoc());
2104 void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
2105 Record.push_back(C->getDefaultmapKind());
2106 Record.push_back(C->getDefaultmapModifier());
2107 Record.AddSourceLocation(C->getLParenLoc());
2108 Record.AddSourceLocation(C->getDefaultmapModifierLoc());
2109 Record.AddSourceLocation(C->getDefaultmapKindLoc());
2112 void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) {
2113 Record.push_back(C->varlist_size());
2114 Record.push_back(C->getUniqueDeclarationsNum());
2115 Record.push_back(C->getTotalComponentListNum());
2116 Record.push_back(C->getTotalComponentsNum());
2117 Record.AddSourceLocation(C->getLParenLoc());
2118 for (auto *E : C->varlists())
2120 for (auto *D : C->all_decls())
2121 Record.AddDeclRef(D);
2122 for (auto N : C->all_num_lists())
2123 Record.push_back(N);
2124 for (auto N : C->all_lists_sizes())
2125 Record.push_back(N);
2126 for (auto &M : C->all_components()) {
2127 Record.AddStmt(M.getAssociatedExpression());
2128 Record.AddDeclRef(M.getAssociatedDeclaration());
2132 void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) {
2133 Record.push_back(C->varlist_size());
2134 Record.push_back(C->getUniqueDeclarationsNum());
2135 Record.push_back(C->getTotalComponentListNum());
2136 Record.push_back(C->getTotalComponentsNum());
2137 Record.AddSourceLocation(C->getLParenLoc());
2138 for (auto *E : C->varlists())
2140 for (auto *D : C->all_decls())
2141 Record.AddDeclRef(D);
2142 for (auto N : C->all_num_lists())
2143 Record.push_back(N);
2144 for (auto N : C->all_lists_sizes())
2145 Record.push_back(N);
2146 for (auto &M : C->all_components()) {
2147 Record.AddStmt(M.getAssociatedExpression());
2148 Record.AddDeclRef(M.getAssociatedDeclaration());
2152 void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
2153 Record.push_back(C->varlist_size());
2154 Record.AddSourceLocation(C->getLParenLoc());
2155 for (auto *VE : C->varlists()) {
2160 void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
2161 Record.push_back(C->varlist_size());
2162 Record.AddSourceLocation(C->getLParenLoc());
2163 for (auto *VE : C->varlists()) {
2168 //===----------------------------------------------------------------------===//
2169 // OpenMP Directives.
2170 //===----------------------------------------------------------------------===//
2171 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2172 Record.AddSourceLocation(E->getLocStart());
2173 Record.AddSourceLocation(E->getLocEnd());
2174 OMPClauseWriter ClauseWriter(Record);
2175 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
2176 ClauseWriter.writeClause(E->getClause(i));
2178 if (E->hasAssociatedStmt())
2179 Record.AddStmt(E->getAssociatedStmt());
2182 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
2184 Record.push_back(D->getNumClauses());
2185 Record.push_back(D->getCollapsedNumber());
2186 VisitOMPExecutableDirective(D);
2187 Record.AddStmt(D->getIterationVariable());
2188 Record.AddStmt(D->getLastIteration());
2189 Record.AddStmt(D->getCalcLastIteration());
2190 Record.AddStmt(D->getPreCond());
2191 Record.AddStmt(D->getCond());
2192 Record.AddStmt(D->getInit());
2193 Record.AddStmt(D->getInc());
2194 Record.AddStmt(D->getPreInits());
2195 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
2196 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
2197 isOpenMPDistributeDirective(D->getDirectiveKind())) {
2198 Record.AddStmt(D->getIsLastIterVariable());
2199 Record.AddStmt(D->getLowerBoundVariable());
2200 Record.AddStmt(D->getUpperBoundVariable());
2201 Record.AddStmt(D->getStrideVariable());
2202 Record.AddStmt(D->getEnsureUpperBound());
2203 Record.AddStmt(D->getNextLowerBound());
2204 Record.AddStmt(D->getNextUpperBound());
2205 Record.AddStmt(D->getNumIterations());
2207 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
2208 Record.AddStmt(D->getPrevLowerBoundVariable());
2209 Record.AddStmt(D->getPrevUpperBoundVariable());
2211 for (auto I : D->counters()) {
2214 for (auto I : D->private_counters()) {
2217 for (auto I : D->inits()) {
2220 for (auto I : D->updates()) {
2223 for (auto I : D->finals()) {
2228 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2230 Record.push_back(D->getNumClauses());
2231 VisitOMPExecutableDirective(D);
2232 Record.push_back(D->hasCancel() ? 1 : 0);
2233 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2236 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2237 VisitOMPLoopDirective(D);
2238 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2241 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2242 VisitOMPLoopDirective(D);
2243 Record.push_back(D->hasCancel() ? 1 : 0);
2244 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2247 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2248 VisitOMPLoopDirective(D);
2249 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2252 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2254 Record.push_back(D->getNumClauses());
2255 VisitOMPExecutableDirective(D);
2256 Record.push_back(D->hasCancel() ? 1 : 0);
2257 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2260 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2262 VisitOMPExecutableDirective(D);
2263 Record.push_back(D->hasCancel() ? 1 : 0);
2264 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2267 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2269 Record.push_back(D->getNumClauses());
2270 VisitOMPExecutableDirective(D);
2271 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2274 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2276 VisitOMPExecutableDirective(D);
2277 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2280 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2282 Record.push_back(D->getNumClauses());
2283 VisitOMPExecutableDirective(D);
2284 Record.AddDeclarationNameInfo(D->getDirectiveName());
2285 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2288 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2289 VisitOMPLoopDirective(D);
2290 Record.push_back(D->hasCancel() ? 1 : 0);
2291 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2294 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2295 OMPParallelForSimdDirective *D) {
2296 VisitOMPLoopDirective(D);
2297 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2300 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2301 OMPParallelSectionsDirective *D) {
2303 Record.push_back(D->getNumClauses());
2304 VisitOMPExecutableDirective(D);
2305 Record.push_back(D->hasCancel() ? 1 : 0);
2306 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2309 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2311 Record.push_back(D->getNumClauses());
2312 VisitOMPExecutableDirective(D);
2313 Record.push_back(D->hasCancel() ? 1 : 0);
2314 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2317 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2319 Record.push_back(D->getNumClauses());
2320 VisitOMPExecutableDirective(D);
2321 Record.AddStmt(D->getX());
2322 Record.AddStmt(D->getV());
2323 Record.AddStmt(D->getExpr());
2324 Record.AddStmt(D->getUpdateExpr());
2325 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
2326 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
2327 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2330 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2332 Record.push_back(D->getNumClauses());
2333 VisitOMPExecutableDirective(D);
2334 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2337 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2339 Record.push_back(D->getNumClauses());
2340 VisitOMPExecutableDirective(D);
2341 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2344 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2345 OMPTargetEnterDataDirective *D) {
2347 Record.push_back(D->getNumClauses());
2348 VisitOMPExecutableDirective(D);
2349 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2352 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2353 OMPTargetExitDataDirective *D) {
2355 Record.push_back(D->getNumClauses());
2356 VisitOMPExecutableDirective(D);
2357 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2360 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2361 OMPTargetParallelDirective *D) {
2363 Record.push_back(D->getNumClauses());
2364 VisitOMPExecutableDirective(D);
2365 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2368 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2369 OMPTargetParallelForDirective *D) {
2370 VisitOMPLoopDirective(D);
2371 Record.push_back(D->hasCancel() ? 1 : 0);
2372 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2375 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2377 VisitOMPExecutableDirective(D);
2378 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2381 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2383 VisitOMPExecutableDirective(D);
2384 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2387 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2389 VisitOMPExecutableDirective(D);
2390 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2393 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2395 VisitOMPExecutableDirective(D);
2396 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2399 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2401 Record.push_back(D->getNumClauses());
2402 VisitOMPExecutableDirective(D);
2403 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2406 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2408 Record.push_back(D->getNumClauses());
2409 VisitOMPExecutableDirective(D);
2410 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2413 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2415 Record.push_back(D->getNumClauses());
2416 VisitOMPExecutableDirective(D);
2417 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2420 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2421 OMPCancellationPointDirective *D) {
2423 VisitOMPExecutableDirective(D);
2424 Record.push_back(D->getCancelRegion());
2425 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2428 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2430 Record.push_back(D->getNumClauses());
2431 VisitOMPExecutableDirective(D);
2432 Record.push_back(D->getCancelRegion());
2433 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2436 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2437 VisitOMPLoopDirective(D);
2438 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2441 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2442 VisitOMPLoopDirective(D);
2443 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2446 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2447 VisitOMPLoopDirective(D);
2448 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2451 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2453 Record.push_back(D->getNumClauses());
2454 VisitOMPExecutableDirective(D);
2455 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2458 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2459 OMPDistributeParallelForDirective *D) {
2460 VisitOMPLoopDirective(D);
2461 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2464 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2465 OMPDistributeParallelForSimdDirective *D) {
2466 VisitOMPLoopDirective(D);
2467 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2470 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2471 OMPDistributeSimdDirective *D) {
2472 VisitOMPLoopDirective(D);
2473 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2476 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2477 OMPTargetParallelForSimdDirective *D) {
2478 VisitOMPLoopDirective(D);
2479 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2482 //===----------------------------------------------------------------------===//
2483 // ASTWriter Implementation
2484 //===----------------------------------------------------------------------===//
2486 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2487 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
2488 "SwitchCase recorded twice");
2489 unsigned NextID = SwitchCaseIDs.size();
2490 SwitchCaseIDs[S] = NextID;
2494 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2495 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
2496 "SwitchCase hasn't been seen yet");
2497 return SwitchCaseIDs[S];
2500 void ASTWriter::ClearSwitchCaseIDs() {
2501 SwitchCaseIDs.clear();
2504 /// \brief Write the given substatement or subexpression to the
2506 void ASTWriter::WriteSubStmt(Stmt *S) {
2508 ASTStmtWriter Writer(*this, Record);
2512 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2516 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2517 if (I != SubStmtEntries.end()) {
2518 Record.push_back(I->second);
2519 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2524 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2526 struct ParentStmtInserterRAII {
2528 llvm::DenseSet<Stmt *> &ParentStmts;
2530 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2531 : S(S), ParentStmts(ParentStmts) {
2532 ParentStmts.insert(S);
2534 ~ParentStmtInserterRAII() {
2535 ParentStmts.erase(S);
2539 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2544 uint64_t Offset = Writer.Emit();
2545 SubStmtEntries[S] = Offset;
2548 /// \brief Flush all of the statements that have been added to the
2549 /// queue via AddStmt().
2550 void ASTRecordWriter::FlushStmts() {
2551 // We expect to be the only consumer of the two temporary statement maps,
2552 // assert that they are empty.
2553 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2554 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2556 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2557 Writer->WriteSubStmt(StmtsToEmit[I]);
2559 assert(N == StmtsToEmit.size() && "record modified while being written!");
2561 // Note that we are at the end of a full expression. Any
2562 // expression records that follow this one are part of a different
2564 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2566 Writer->SubStmtEntries.clear();
2567 Writer->ParentStmts.clear();
2570 StmtsToEmit.clear();
2573 void ASTRecordWriter::FlushSubStmts() {
2574 // For a nested statement, write out the substatements in reverse order (so
2575 // that a simple stack machine can be used when loading), and don't emit a
2576 // STMT_STOP after each one.
2577 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2578 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
2579 assert(N == StmtsToEmit.size() && "record modified while being written!");
2582 StmtsToEmit.clear();