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::VisitDependentCoawaitExpr(DependentCoawaitExpr *S) {
319 // FIXME: Implement coroutine serialization.
320 llvm_unreachable("unimplemented");
323 void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *S) {
324 // FIXME: Implement coroutine serialization.
325 llvm_unreachable("unimplemented");
328 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
331 Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
333 // CapturedDecl and captured region kind
334 Record.AddDeclRef(S->getCapturedDecl());
335 Record.push_back(S->getCapturedRegionKind());
337 Record.AddDeclRef(S->getCapturedRecordDecl());
340 for (auto *I : S->capture_inits())
344 Record.AddStmt(S->getCapturedStmt());
347 for (const auto &I : S->captures()) {
348 if (I.capturesThis() || I.capturesVariableArrayType())
349 Record.AddDeclRef(nullptr);
351 Record.AddDeclRef(I.getCapturedVar());
352 Record.push_back(I.getCaptureKind());
353 Record.AddSourceLocation(I.getLocation());
356 Code = serialization::STMT_CAPTURED;
359 void ASTStmtWriter::VisitExpr(Expr *E) {
361 Record.AddTypeRef(E->getType());
362 Record.push_back(E->isTypeDependent());
363 Record.push_back(E->isValueDependent());
364 Record.push_back(E->isInstantiationDependent());
365 Record.push_back(E->containsUnexpandedParameterPack());
366 Record.push_back(E->getValueKind());
367 Record.push_back(E->getObjectKind());
370 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
372 Record.AddSourceLocation(E->getLocation());
373 Record.push_back(E->getIdentType()); // FIXME: stable encoding
374 Record.AddStmt(E->getFunctionName());
375 Code = serialization::EXPR_PREDEFINED;
378 void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
381 Record.push_back(E->hasQualifier());
382 Record.push_back(E->getDecl() != E->getFoundDecl());
383 Record.push_back(E->hasTemplateKWAndArgsInfo());
384 Record.push_back(E->hadMultipleCandidates());
385 Record.push_back(E->refersToEnclosingVariableOrCapture());
387 if (E->hasTemplateKWAndArgsInfo()) {
388 unsigned NumTemplateArgs = E->getNumTemplateArgs();
389 Record.push_back(NumTemplateArgs);
392 DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
394 if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
395 (E->getDecl() == E->getFoundDecl()) &&
396 nk == DeclarationName::Identifier) {
397 AbbrevToUse = Writer.getDeclRefExprAbbrev();
400 if (E->hasQualifier())
401 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
403 if (E->getDecl() != E->getFoundDecl())
404 Record.AddDeclRef(E->getFoundDecl());
406 if (E->hasTemplateKWAndArgsInfo())
407 AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
408 E->getTrailingObjects<TemplateArgumentLoc>());
410 Record.AddDeclRef(E->getDecl());
411 Record.AddSourceLocation(E->getLocation());
412 Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
413 Code = serialization::EXPR_DECL_REF;
416 void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
418 Record.AddSourceLocation(E->getLocation());
419 Record.AddAPInt(E->getValue());
421 if (E->getValue().getBitWidth() == 32) {
422 AbbrevToUse = Writer.getIntegerLiteralAbbrev();
425 Code = serialization::EXPR_INTEGER_LITERAL;
428 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
430 Record.push_back(E->getRawSemantics());
431 Record.push_back(E->isExact());
432 Record.AddAPFloat(E->getValue());
433 Record.AddSourceLocation(E->getLocation());
434 Code = serialization::EXPR_FLOATING_LITERAL;
437 void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
439 Record.AddStmt(E->getSubExpr());
440 Code = serialization::EXPR_IMAGINARY_LITERAL;
443 void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
445 Record.push_back(E->getByteLength());
446 Record.push_back(E->getNumConcatenated());
447 Record.push_back(E->getKind());
448 Record.push_back(E->isPascal());
449 // FIXME: String data should be stored as a blob at the end of the
450 // StringLiteral. However, we can't do so now because we have no
451 // provision for coping with abbreviations when we're jumping around
452 // the AST file during deserialization.
453 Record.append(E->getBytes().begin(), E->getBytes().end());
454 for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
455 Record.AddSourceLocation(E->getStrTokenLoc(I));
456 Code = serialization::EXPR_STRING_LITERAL;
459 void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
461 Record.push_back(E->getValue());
462 Record.AddSourceLocation(E->getLocation());
463 Record.push_back(E->getKind());
465 AbbrevToUse = Writer.getCharacterLiteralAbbrev();
467 Code = serialization::EXPR_CHARACTER_LITERAL;
470 void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
472 Record.AddSourceLocation(E->getLParen());
473 Record.AddSourceLocation(E->getRParen());
474 Record.AddStmt(E->getSubExpr());
475 Code = serialization::EXPR_PAREN;
478 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
480 Record.push_back(E->NumExprs);
481 for (unsigned i=0; i != E->NumExprs; ++i)
482 Record.AddStmt(E->Exprs[i]);
483 Record.AddSourceLocation(E->LParenLoc);
484 Record.AddSourceLocation(E->RParenLoc);
485 Code = serialization::EXPR_PAREN_LIST;
488 void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
490 Record.AddStmt(E->getSubExpr());
491 Record.push_back(E->getOpcode()); // FIXME: stable encoding
492 Record.AddSourceLocation(E->getOperatorLoc());
493 Code = serialization::EXPR_UNARY_OPERATOR;
496 void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
498 Record.push_back(E->getNumComponents());
499 Record.push_back(E->getNumExpressions());
500 Record.AddSourceLocation(E->getOperatorLoc());
501 Record.AddSourceLocation(E->getRParenLoc());
502 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
503 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
504 const OffsetOfNode &ON = E->getComponent(I);
505 Record.push_back(ON.getKind()); // FIXME: Stable encoding
506 Record.AddSourceLocation(ON.getSourceRange().getBegin());
507 Record.AddSourceLocation(ON.getSourceRange().getEnd());
508 switch (ON.getKind()) {
509 case OffsetOfNode::Array:
510 Record.push_back(ON.getArrayExprIndex());
513 case OffsetOfNode::Field:
514 Record.AddDeclRef(ON.getField());
517 case OffsetOfNode::Identifier:
518 Record.AddIdentifierRef(ON.getFieldName());
521 case OffsetOfNode::Base:
522 Record.AddCXXBaseSpecifier(*ON.getBase());
526 for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
527 Record.AddStmt(E->getIndexExpr(I));
528 Code = serialization::EXPR_OFFSETOF;
531 void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
533 Record.push_back(E->getKind());
534 if (E->isArgumentType())
535 Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
538 Record.AddStmt(E->getArgumentExpr());
540 Record.AddSourceLocation(E->getOperatorLoc());
541 Record.AddSourceLocation(E->getRParenLoc());
542 Code = serialization::EXPR_SIZEOF_ALIGN_OF;
545 void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
547 Record.AddStmt(E->getLHS());
548 Record.AddStmt(E->getRHS());
549 Record.AddSourceLocation(E->getRBracketLoc());
550 Code = serialization::EXPR_ARRAY_SUBSCRIPT;
553 void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
555 Record.AddStmt(E->getBase());
556 Record.AddStmt(E->getLowerBound());
557 Record.AddStmt(E->getLength());
558 Record.AddSourceLocation(E->getColonLoc());
559 Record.AddSourceLocation(E->getRBracketLoc());
560 Code = serialization::EXPR_OMP_ARRAY_SECTION;
563 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
565 Record.push_back(E->getNumArgs());
566 Record.AddSourceLocation(E->getRParenLoc());
567 Record.AddStmt(E->getCallee());
568 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
569 Arg != ArgEnd; ++Arg)
570 Record.AddStmt(*Arg);
571 Code = serialization::EXPR_CALL;
574 void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
575 // Don't call VisitExpr, we'll write everything here.
577 Record.push_back(E->hasQualifier());
578 if (E->hasQualifier())
579 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
581 Record.push_back(E->HasTemplateKWAndArgsInfo);
582 if (E->HasTemplateKWAndArgsInfo) {
583 Record.AddSourceLocation(E->getTemplateKeywordLoc());
584 unsigned NumTemplateArgs = E->getNumTemplateArgs();
585 Record.push_back(NumTemplateArgs);
586 Record.AddSourceLocation(E->getLAngleLoc());
587 Record.AddSourceLocation(E->getRAngleLoc());
588 for (unsigned i=0; i != NumTemplateArgs; ++i)
589 Record.AddTemplateArgumentLoc(E->getTemplateArgs()[i]);
592 Record.push_back(E->hadMultipleCandidates());
594 DeclAccessPair FoundDecl = E->getFoundDecl();
595 Record.AddDeclRef(FoundDecl.getDecl());
596 Record.push_back(FoundDecl.getAccess());
598 Record.AddTypeRef(E->getType());
599 Record.push_back(E->getValueKind());
600 Record.push_back(E->getObjectKind());
601 Record.AddStmt(E->getBase());
602 Record.AddDeclRef(E->getMemberDecl());
603 Record.AddSourceLocation(E->getMemberLoc());
604 Record.push_back(E->isArrow());
605 Record.AddSourceLocation(E->getOperatorLoc());
606 Record.AddDeclarationNameLoc(E->MemberDNLoc,
607 E->getMemberDecl()->getDeclName());
608 Code = serialization::EXPR_MEMBER;
611 void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
613 Record.AddStmt(E->getBase());
614 Record.AddSourceLocation(E->getIsaMemberLoc());
615 Record.AddSourceLocation(E->getOpLoc());
616 Record.push_back(E->isArrow());
617 Code = serialization::EXPR_OBJC_ISA;
621 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
623 Record.AddStmt(E->getSubExpr());
624 Record.push_back(E->shouldCopy());
625 Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
628 void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
629 VisitExplicitCastExpr(E);
630 Record.AddSourceLocation(E->getLParenLoc());
631 Record.AddSourceLocation(E->getBridgeKeywordLoc());
632 Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
633 Code = serialization::EXPR_OBJC_BRIDGED_CAST;
636 void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
638 Record.push_back(E->path_size());
639 Record.AddStmt(E->getSubExpr());
640 Record.push_back(E->getCastKind()); // FIXME: stable encoding
642 for (CastExpr::path_iterator
643 PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
644 Record.AddCXXBaseSpecifier(**PI);
647 void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
649 Record.AddStmt(E->getLHS());
650 Record.AddStmt(E->getRHS());
651 Record.push_back(E->getOpcode()); // FIXME: stable encoding
652 Record.AddSourceLocation(E->getOperatorLoc());
653 Record.push_back(E->getFPFeatures().getInt());
654 Code = serialization::EXPR_BINARY_OPERATOR;
657 void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
658 VisitBinaryOperator(E);
659 Record.AddTypeRef(E->getComputationLHSType());
660 Record.AddTypeRef(E->getComputationResultType());
661 Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
664 void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
666 Record.AddStmt(E->getCond());
667 Record.AddStmt(E->getLHS());
668 Record.AddStmt(E->getRHS());
669 Record.AddSourceLocation(E->getQuestionLoc());
670 Record.AddSourceLocation(E->getColonLoc());
671 Code = serialization::EXPR_CONDITIONAL_OPERATOR;
675 ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
677 Record.AddStmt(E->getOpaqueValue());
678 Record.AddStmt(E->getCommon());
679 Record.AddStmt(E->getCond());
680 Record.AddStmt(E->getTrueExpr());
681 Record.AddStmt(E->getFalseExpr());
682 Record.AddSourceLocation(E->getQuestionLoc());
683 Record.AddSourceLocation(E->getColonLoc());
684 Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
687 void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
690 if (E->path_size() == 0)
691 AbbrevToUse = Writer.getExprImplicitCastAbbrev();
693 Code = serialization::EXPR_IMPLICIT_CAST;
696 void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
698 Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
701 void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
702 VisitExplicitCastExpr(E);
703 Record.AddSourceLocation(E->getLParenLoc());
704 Record.AddSourceLocation(E->getRParenLoc());
705 Code = serialization::EXPR_CSTYLE_CAST;
708 void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
710 Record.AddSourceLocation(E->getLParenLoc());
711 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
712 Record.AddStmt(E->getInitializer());
713 Record.push_back(E->isFileScope());
714 Code = serialization::EXPR_COMPOUND_LITERAL;
717 void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
719 Record.AddStmt(E->getBase());
720 Record.AddIdentifierRef(&E->getAccessor());
721 Record.AddSourceLocation(E->getAccessorLoc());
722 Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
725 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
727 // NOTE: only add the (possibly null) syntactic form.
728 // No need to serialize the isSemanticForm flag and the semantic form.
729 Record.AddStmt(E->getSyntacticForm());
730 Record.AddSourceLocation(E->getLBraceLoc());
731 Record.AddSourceLocation(E->getRBraceLoc());
732 bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
733 Record.push_back(isArrayFiller);
735 Record.AddStmt(E->getArrayFiller());
737 Record.AddDeclRef(E->getInitializedFieldInUnion());
738 Record.push_back(E->hadArrayRangeDesignator());
739 Record.push_back(E->getNumInits());
741 // ArrayFiller may have filled "holes" due to designated initializer.
742 // Replace them by 0 to indicate that the filler goes in that place.
743 Expr *filler = E->getArrayFiller();
744 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
745 Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
747 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
748 Record.AddStmt(E->getInit(I));
750 Code = serialization::EXPR_INIT_LIST;
753 void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
755 Record.push_back(E->getNumSubExprs());
756 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
757 Record.AddStmt(E->getSubExpr(I));
758 Record.AddSourceLocation(E->getEqualOrColonLoc());
759 Record.push_back(E->usesGNUSyntax());
760 for (const DesignatedInitExpr::Designator &D : E->designators()) {
761 if (D.isFieldDesignator()) {
762 if (FieldDecl *Field = D.getField()) {
763 Record.push_back(serialization::DESIG_FIELD_DECL);
764 Record.AddDeclRef(Field);
766 Record.push_back(serialization::DESIG_FIELD_NAME);
767 Record.AddIdentifierRef(D.getFieldName());
769 Record.AddSourceLocation(D.getDotLoc());
770 Record.AddSourceLocation(D.getFieldLoc());
771 } else if (D.isArrayDesignator()) {
772 Record.push_back(serialization::DESIG_ARRAY);
773 Record.push_back(D.getFirstExprIndex());
774 Record.AddSourceLocation(D.getLBracketLoc());
775 Record.AddSourceLocation(D.getRBracketLoc());
777 assert(D.isArrayRangeDesignator() && "Unknown designator");
778 Record.push_back(serialization::DESIG_ARRAY_RANGE);
779 Record.push_back(D.getFirstExprIndex());
780 Record.AddSourceLocation(D.getLBracketLoc());
781 Record.AddSourceLocation(D.getEllipsisLoc());
782 Record.AddSourceLocation(D.getRBracketLoc());
785 Code = serialization::EXPR_DESIGNATED_INIT;
788 void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
790 Record.AddStmt(E->getBase());
791 Record.AddStmt(E->getUpdater());
792 Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
795 void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
797 Code = serialization::EXPR_NO_INIT;
800 void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
802 Record.AddStmt(E->SubExprs[0]);
803 Record.AddStmt(E->SubExprs[1]);
804 Code = serialization::EXPR_ARRAY_INIT_LOOP;
807 void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
809 Code = serialization::EXPR_ARRAY_INIT_INDEX;
812 void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
814 Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
817 void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
819 Record.AddStmt(E->getSubExpr());
820 Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
821 Record.AddSourceLocation(E->getBuiltinLoc());
822 Record.AddSourceLocation(E->getRParenLoc());
823 Record.push_back(E->isMicrosoftABI());
824 Code = serialization::EXPR_VA_ARG;
827 void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
829 Record.AddSourceLocation(E->getAmpAmpLoc());
830 Record.AddSourceLocation(E->getLabelLoc());
831 Record.AddDeclRef(E->getLabel());
832 Code = serialization::EXPR_ADDR_LABEL;
835 void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
837 Record.AddStmt(E->getSubStmt());
838 Record.AddSourceLocation(E->getLParenLoc());
839 Record.AddSourceLocation(E->getRParenLoc());
840 Code = serialization::EXPR_STMT;
843 void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
845 Record.AddStmt(E->getCond());
846 Record.AddStmt(E->getLHS());
847 Record.AddStmt(E->getRHS());
848 Record.AddSourceLocation(E->getBuiltinLoc());
849 Record.AddSourceLocation(E->getRParenLoc());
850 Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
851 Code = serialization::EXPR_CHOOSE;
854 void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
856 Record.AddSourceLocation(E->getTokenLocation());
857 Code = serialization::EXPR_GNU_NULL;
860 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
862 Record.push_back(E->getNumSubExprs());
863 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
864 Record.AddStmt(E->getExpr(I));
865 Record.AddSourceLocation(E->getBuiltinLoc());
866 Record.AddSourceLocation(E->getRParenLoc());
867 Code = serialization::EXPR_SHUFFLE_VECTOR;
870 void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
872 Record.AddSourceLocation(E->getBuiltinLoc());
873 Record.AddSourceLocation(E->getRParenLoc());
874 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
875 Record.AddStmt(E->getSrcExpr());
876 Code = serialization::EXPR_CONVERT_VECTOR;
879 void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
881 Record.AddDeclRef(E->getBlockDecl());
882 Code = serialization::EXPR_BLOCK;
885 void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
887 Record.push_back(E->getNumAssocs());
889 Record.AddStmt(E->getControllingExpr());
890 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
891 Record.AddTypeSourceInfo(E->getAssocTypeSourceInfo(I));
892 Record.AddStmt(E->getAssocExpr(I));
894 Record.push_back(E->isResultDependent() ? -1U : E->getResultIndex());
896 Record.AddSourceLocation(E->getGenericLoc());
897 Record.AddSourceLocation(E->getDefaultLoc());
898 Record.AddSourceLocation(E->getRParenLoc());
899 Code = serialization::EXPR_GENERIC_SELECTION;
902 void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
904 Record.push_back(E->getNumSemanticExprs());
906 // Push the result index. Currently, this needs to exactly match
907 // the encoding used internally for ResultIndex.
908 unsigned result = E->getResultExprIndex();
909 result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
910 Record.push_back(result);
912 Record.AddStmt(E->getSyntacticForm());
913 for (PseudoObjectExpr::semantics_iterator
914 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
917 Code = serialization::EXPR_PSEUDO_OBJECT;
920 void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
922 Record.push_back(E->getOp());
923 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
924 Record.AddStmt(E->getSubExprs()[I]);
925 Record.AddSourceLocation(E->getBuiltinLoc());
926 Record.AddSourceLocation(E->getRParenLoc());
927 Code = serialization::EXPR_ATOMIC;
930 //===----------------------------------------------------------------------===//
931 // Objective-C Expressions and Statements.
932 //===----------------------------------------------------------------------===//
934 void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
936 Record.AddStmt(E->getString());
937 Record.AddSourceLocation(E->getAtLoc());
938 Code = serialization::EXPR_OBJC_STRING_LITERAL;
941 void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
943 Record.AddStmt(E->getSubExpr());
944 Record.AddDeclRef(E->getBoxingMethod());
945 Record.AddSourceRange(E->getSourceRange());
946 Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
949 void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
951 Record.push_back(E->getNumElements());
952 for (unsigned i = 0; i < E->getNumElements(); i++)
953 Record.AddStmt(E->getElement(i));
954 Record.AddDeclRef(E->getArrayWithObjectsMethod());
955 Record.AddSourceRange(E->getSourceRange());
956 Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
959 void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
961 Record.push_back(E->getNumElements());
962 Record.push_back(E->HasPackExpansions);
963 for (unsigned i = 0; i < E->getNumElements(); i++) {
964 ObjCDictionaryElement Element = E->getKeyValueElement(i);
965 Record.AddStmt(Element.Key);
966 Record.AddStmt(Element.Value);
967 if (E->HasPackExpansions) {
968 Record.AddSourceLocation(Element.EllipsisLoc);
969 unsigned NumExpansions = 0;
970 if (Element.NumExpansions)
971 NumExpansions = *Element.NumExpansions + 1;
972 Record.push_back(NumExpansions);
976 Record.AddDeclRef(E->getDictWithObjectsMethod());
977 Record.AddSourceRange(E->getSourceRange());
978 Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
981 void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
983 Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
984 Record.AddSourceLocation(E->getAtLoc());
985 Record.AddSourceLocation(E->getRParenLoc());
986 Code = serialization::EXPR_OBJC_ENCODE;
989 void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
991 Record.AddSelectorRef(E->getSelector());
992 Record.AddSourceLocation(E->getAtLoc());
993 Record.AddSourceLocation(E->getRParenLoc());
994 Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
997 void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
999 Record.AddDeclRef(E->getProtocol());
1000 Record.AddSourceLocation(E->getAtLoc());
1001 Record.AddSourceLocation(E->ProtoLoc);
1002 Record.AddSourceLocation(E->getRParenLoc());
1003 Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
1006 void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1008 Record.AddDeclRef(E->getDecl());
1009 Record.AddSourceLocation(E->getLocation());
1010 Record.AddSourceLocation(E->getOpLoc());
1011 Record.AddStmt(E->getBase());
1012 Record.push_back(E->isArrow());
1013 Record.push_back(E->isFreeIvar());
1014 Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
1017 void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1019 Record.push_back(E->SetterAndMethodRefFlags.getInt());
1020 Record.push_back(E->isImplicitProperty());
1021 if (E->isImplicitProperty()) {
1022 Record.AddDeclRef(E->getImplicitPropertyGetter());
1023 Record.AddDeclRef(E->getImplicitPropertySetter());
1025 Record.AddDeclRef(E->getExplicitProperty());
1027 Record.AddSourceLocation(E->getLocation());
1028 Record.AddSourceLocation(E->getReceiverLocation());
1029 if (E->isObjectReceiver()) {
1030 Record.push_back(0);
1031 Record.AddStmt(E->getBase());
1032 } else if (E->isSuperReceiver()) {
1033 Record.push_back(1);
1034 Record.AddTypeRef(E->getSuperReceiverType());
1036 Record.push_back(2);
1037 Record.AddDeclRef(E->getClassReceiver());
1040 Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
1043 void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1045 Record.AddSourceLocation(E->getRBracket());
1046 Record.AddStmt(E->getBaseExpr());
1047 Record.AddStmt(E->getKeyExpr());
1048 Record.AddDeclRef(E->getAtIndexMethodDecl());
1049 Record.AddDeclRef(E->setAtIndexMethodDecl());
1051 Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
1054 void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1056 Record.push_back(E->getNumArgs());
1057 Record.push_back(E->getNumStoredSelLocs());
1058 Record.push_back(E->SelLocsKind);
1059 Record.push_back(E->isDelegateInitCall());
1060 Record.push_back(E->IsImplicit);
1061 Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
1062 switch (E->getReceiverKind()) {
1063 case ObjCMessageExpr::Instance:
1064 Record.AddStmt(E->getInstanceReceiver());
1067 case ObjCMessageExpr::Class:
1068 Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
1071 case ObjCMessageExpr::SuperClass:
1072 case ObjCMessageExpr::SuperInstance:
1073 Record.AddTypeRef(E->getSuperType());
1074 Record.AddSourceLocation(E->getSuperLoc());
1078 if (E->getMethodDecl()) {
1079 Record.push_back(1);
1080 Record.AddDeclRef(E->getMethodDecl());
1082 Record.push_back(0);
1083 Record.AddSelectorRef(E->getSelector());
1086 Record.AddSourceLocation(E->getLeftLoc());
1087 Record.AddSourceLocation(E->getRightLoc());
1089 for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
1090 Arg != ArgEnd; ++Arg)
1091 Record.AddStmt(*Arg);
1093 SourceLocation *Locs = E->getStoredSelLocs();
1094 for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
1095 Record.AddSourceLocation(Locs[i]);
1097 Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
1100 void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1102 Record.AddStmt(S->getElement());
1103 Record.AddStmt(S->getCollection());
1104 Record.AddStmt(S->getBody());
1105 Record.AddSourceLocation(S->getForLoc());
1106 Record.AddSourceLocation(S->getRParenLoc());
1107 Code = serialization::STMT_OBJC_FOR_COLLECTION;
1110 void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1111 Record.AddStmt(S->getCatchBody());
1112 Record.AddDeclRef(S->getCatchParamDecl());
1113 Record.AddSourceLocation(S->getAtCatchLoc());
1114 Record.AddSourceLocation(S->getRParenLoc());
1115 Code = serialization::STMT_OBJC_CATCH;
1118 void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1119 Record.AddStmt(S->getFinallyBody());
1120 Record.AddSourceLocation(S->getAtFinallyLoc());
1121 Code = serialization::STMT_OBJC_FINALLY;
1124 void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1125 Record.AddStmt(S->getSubStmt());
1126 Record.AddSourceLocation(S->getAtLoc());
1127 Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
1130 void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1131 Record.push_back(S->getNumCatchStmts());
1132 Record.push_back(S->getFinallyStmt() != nullptr);
1133 Record.AddStmt(S->getTryBody());
1134 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1135 Record.AddStmt(S->getCatchStmt(I));
1136 if (S->getFinallyStmt())
1137 Record.AddStmt(S->getFinallyStmt());
1138 Record.AddSourceLocation(S->getAtTryLoc());
1139 Code = serialization::STMT_OBJC_AT_TRY;
1142 void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1143 Record.AddStmt(S->getSynchExpr());
1144 Record.AddStmt(S->getSynchBody());
1145 Record.AddSourceLocation(S->getAtSynchronizedLoc());
1146 Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
1149 void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1150 Record.AddStmt(S->getThrowExpr());
1151 Record.AddSourceLocation(S->getThrowLoc());
1152 Code = serialization::STMT_OBJC_AT_THROW;
1155 void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1157 Record.push_back(E->getValue());
1158 Record.AddSourceLocation(E->getLocation());
1159 Code = serialization::EXPR_OBJC_BOOL_LITERAL;
1162 void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1164 Record.AddSourceRange(E->getSourceRange());
1165 Record.AddVersionTuple(E->getVersion());
1166 Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
1169 //===----------------------------------------------------------------------===//
1170 // C++ Expressions and Statements.
1171 //===----------------------------------------------------------------------===//
1173 void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
1175 Record.AddSourceLocation(S->getCatchLoc());
1176 Record.AddDeclRef(S->getExceptionDecl());
1177 Record.AddStmt(S->getHandlerBlock());
1178 Code = serialization::STMT_CXX_CATCH;
1181 void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
1183 Record.push_back(S->getNumHandlers());
1184 Record.AddSourceLocation(S->getTryLoc());
1185 Record.AddStmt(S->getTryBlock());
1186 for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1187 Record.AddStmt(S->getHandler(i));
1188 Code = serialization::STMT_CXX_TRY;
1191 void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1193 Record.AddSourceLocation(S->getForLoc());
1194 Record.AddSourceLocation(S->getCoawaitLoc());
1195 Record.AddSourceLocation(S->getColonLoc());
1196 Record.AddSourceLocation(S->getRParenLoc());
1197 Record.AddStmt(S->getRangeStmt());
1198 Record.AddStmt(S->getBeginStmt());
1199 Record.AddStmt(S->getEndStmt());
1200 Record.AddStmt(S->getCond());
1201 Record.AddStmt(S->getInc());
1202 Record.AddStmt(S->getLoopVarStmt());
1203 Record.AddStmt(S->getBody());
1204 Code = serialization::STMT_CXX_FOR_RANGE;
1207 void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1209 Record.AddSourceLocation(S->getKeywordLoc());
1210 Record.push_back(S->isIfExists());
1211 Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
1212 Record.AddDeclarationNameInfo(S->getNameInfo());
1213 Record.AddStmt(S->getSubStmt());
1214 Code = serialization::STMT_MS_DEPENDENT_EXISTS;
1217 void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1219 Record.push_back(E->getOperator());
1220 Record.AddSourceRange(E->Range);
1221 Record.push_back(E->getFPFeatures().getInt());
1222 Code = serialization::EXPR_CXX_OPERATOR_CALL;
1225 void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1227 Code = serialization::EXPR_CXX_MEMBER_CALL;
1230 void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1232 Record.push_back(E->getNumArgs());
1233 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1234 Record.AddStmt(E->getArg(I));
1235 Record.AddDeclRef(E->getConstructor());
1236 Record.AddSourceLocation(E->getLocation());
1237 Record.push_back(E->isElidable());
1238 Record.push_back(E->hadMultipleCandidates());
1239 Record.push_back(E->isListInitialization());
1240 Record.push_back(E->isStdInitListInitialization());
1241 Record.push_back(E->requiresZeroInitialization());
1242 Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
1243 Record.AddSourceRange(E->getParenOrBraceRange());
1244 Code = serialization::EXPR_CXX_CONSTRUCT;
1247 void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1249 Record.AddDeclRef(E->getConstructor());
1250 Record.AddSourceLocation(E->getLocation());
1251 Record.push_back(E->constructsVBase());
1252 Record.push_back(E->inheritedFromVBase());
1253 Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
1256 void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1257 VisitCXXConstructExpr(E);
1258 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1259 Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
1262 void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
1264 Record.push_back(E->NumCaptures);
1265 Record.AddSourceRange(E->IntroducerRange);
1266 Record.push_back(E->CaptureDefault); // FIXME: stable encoding
1267 Record.AddSourceLocation(E->CaptureDefaultLoc);
1268 Record.push_back(E->ExplicitParams);
1269 Record.push_back(E->ExplicitResultType);
1270 Record.AddSourceLocation(E->ClosingBrace);
1272 // Add capture initializers.
1273 for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1274 CEnd = E->capture_init_end();
1279 Code = serialization::EXPR_LAMBDA;
1282 void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1284 Record.AddStmt(E->getSubExpr());
1285 Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
1288 void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1289 VisitExplicitCastExpr(E);
1290 Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
1291 Record.AddSourceRange(E->getAngleBrackets());
1294 void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1295 VisitCXXNamedCastExpr(E);
1296 Code = serialization::EXPR_CXX_STATIC_CAST;
1299 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1300 VisitCXXNamedCastExpr(E);
1301 Code = serialization::EXPR_CXX_DYNAMIC_CAST;
1304 void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1305 VisitCXXNamedCastExpr(E);
1306 Code = serialization::EXPR_CXX_REINTERPRET_CAST;
1309 void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1310 VisitCXXNamedCastExpr(E);
1311 Code = serialization::EXPR_CXX_CONST_CAST;
1314 void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1315 VisitExplicitCastExpr(E);
1316 Record.AddSourceLocation(E->getLParenLoc());
1317 Record.AddSourceLocation(E->getRParenLoc());
1318 Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
1321 void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1323 Record.AddSourceLocation(E->UDSuffixLoc);
1324 Code = serialization::EXPR_USER_DEFINED_LITERAL;
1327 void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1329 Record.push_back(E->getValue());
1330 Record.AddSourceLocation(E->getLocation());
1331 Code = serialization::EXPR_CXX_BOOL_LITERAL;
1334 void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1336 Record.AddSourceLocation(E->getLocation());
1337 Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
1340 void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1342 Record.AddSourceRange(E->getSourceRange());
1343 if (E->isTypeOperand()) {
1344 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1345 Code = serialization::EXPR_CXX_TYPEID_TYPE;
1347 Record.AddStmt(E->getExprOperand());
1348 Code = serialization::EXPR_CXX_TYPEID_EXPR;
1352 void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
1354 Record.AddSourceLocation(E->getLocation());
1355 Record.push_back(E->isImplicit());
1356 Code = serialization::EXPR_CXX_THIS;
1359 void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
1361 Record.AddSourceLocation(E->getThrowLoc());
1362 Record.AddStmt(E->getSubExpr());
1363 Record.push_back(E->isThrownVariableInScope());
1364 Code = serialization::EXPR_CXX_THROW;
1367 void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1369 Record.AddDeclRef(E->getParam());
1370 Record.AddSourceLocation(E->getUsedLocation());
1371 Code = serialization::EXPR_CXX_DEFAULT_ARG;
1374 void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1376 Record.AddDeclRef(E->getField());
1377 Record.AddSourceLocation(E->getExprLoc());
1378 Code = serialization::EXPR_CXX_DEFAULT_INIT;
1381 void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1383 Record.AddCXXTemporary(E->getTemporary());
1384 Record.AddStmt(E->getSubExpr());
1385 Code = serialization::EXPR_CXX_BIND_TEMPORARY;
1388 void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1390 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1391 Record.AddSourceLocation(E->getRParenLoc());
1392 Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
1395 void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
1397 Record.push_back(E->isGlobalNew());
1398 Record.push_back(E->isArray());
1399 Record.push_back(E->passAlignment());
1400 Record.push_back(E->doesUsualArrayDeleteWantSize());
1401 Record.push_back(E->getNumPlacementArgs());
1402 Record.push_back(E->StoredInitializationStyle);
1403 Record.AddDeclRef(E->getOperatorNew());
1404 Record.AddDeclRef(E->getOperatorDelete());
1405 Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
1406 Record.AddSourceRange(E->getTypeIdParens());
1407 Record.AddSourceRange(E->getSourceRange());
1408 Record.AddSourceRange(E->getDirectInitRange());
1409 for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
1413 Code = serialization::EXPR_CXX_NEW;
1416 void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1418 Record.push_back(E->isGlobalDelete());
1419 Record.push_back(E->isArrayForm());
1420 Record.push_back(E->isArrayFormAsWritten());
1421 Record.push_back(E->doesUsualArrayDeleteWantSize());
1422 Record.AddDeclRef(E->getOperatorDelete());
1423 Record.AddStmt(E->getArgument());
1424 Record.AddSourceLocation(E->getSourceRange().getBegin());
1426 Code = serialization::EXPR_CXX_DELETE;
1429 void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1432 Record.AddStmt(E->getBase());
1433 Record.push_back(E->isArrow());
1434 Record.AddSourceLocation(E->getOperatorLoc());
1435 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1436 Record.AddTypeSourceInfo(E->getScopeTypeInfo());
1437 Record.AddSourceLocation(E->getColonColonLoc());
1438 Record.AddSourceLocation(E->getTildeLoc());
1440 // PseudoDestructorTypeStorage.
1441 Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
1442 if (E->getDestroyedTypeIdentifier())
1443 Record.AddSourceLocation(E->getDestroyedTypeLoc());
1445 Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
1447 Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
1450 void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
1452 Record.push_back(E->getNumObjects());
1453 for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
1454 Record.AddDeclRef(E->getObject(i));
1456 Record.push_back(E->cleanupsHaveSideEffects());
1457 Record.AddStmt(E->getSubExpr());
1458 Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
1462 ASTStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
1465 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1468 Record.push_back(E->HasTemplateKWAndArgsInfo);
1469 if (E->HasTemplateKWAndArgsInfo) {
1470 const ASTTemplateKWAndArgsInfo &ArgInfo =
1471 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1472 Record.push_back(ArgInfo.NumTemplateArgs);
1473 AddTemplateKWAndArgsInfo(ArgInfo,
1474 E->getTrailingObjects<TemplateArgumentLoc>());
1477 if (!E->isImplicitAccess())
1478 Record.AddStmt(E->getBase());
1480 Record.AddStmt(nullptr);
1481 Record.AddTypeRef(E->getBaseType());
1482 Record.push_back(E->isArrow());
1483 Record.AddSourceLocation(E->getOperatorLoc());
1484 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1485 Record.AddDeclRef(E->getFirstQualifierFoundInScope());
1486 Record.AddDeclarationNameInfo(E->MemberNameInfo);
1487 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
1491 ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1494 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1497 Record.push_back(E->HasTemplateKWAndArgsInfo);
1498 if (E->HasTemplateKWAndArgsInfo) {
1499 const ASTTemplateKWAndArgsInfo &ArgInfo =
1500 *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
1501 Record.push_back(ArgInfo.NumTemplateArgs);
1502 AddTemplateKWAndArgsInfo(ArgInfo,
1503 E->getTrailingObjects<TemplateArgumentLoc>());
1506 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1507 Record.AddDeclarationNameInfo(E->NameInfo);
1508 Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
1512 ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1514 Record.push_back(E->arg_size());
1515 for (CXXUnresolvedConstructExpr::arg_iterator
1516 ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
1517 Record.AddStmt(*ArgI);
1518 Record.AddTypeSourceInfo(E->getTypeSourceInfo());
1519 Record.AddSourceLocation(E->getLParenLoc());
1520 Record.AddSourceLocation(E->getRParenLoc());
1521 Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
1524 void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
1527 // Don't emit anything here, HasTemplateKWAndArgsInfo must be
1530 Record.push_back(E->HasTemplateKWAndArgsInfo);
1531 if (E->HasTemplateKWAndArgsInfo) {
1532 const ASTTemplateKWAndArgsInfo &ArgInfo =
1533 *E->getTrailingASTTemplateKWAndArgsInfo();
1534 Record.push_back(ArgInfo.NumTemplateArgs);
1535 AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
1538 Record.push_back(E->getNumDecls());
1539 for (OverloadExpr::decls_iterator
1540 OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
1541 Record.AddDeclRef(OvI.getDecl());
1542 Record.push_back(OvI.getAccess());
1545 Record.AddDeclarationNameInfo(E->NameInfo);
1546 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1549 void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
1550 VisitOverloadExpr(E);
1551 Record.push_back(E->isArrow());
1552 Record.push_back(E->hasUnresolvedUsing());
1553 Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
1554 Record.AddTypeRef(E->getBaseType());
1555 Record.AddSourceLocation(E->getOperatorLoc());
1556 Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
1559 void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
1560 VisitOverloadExpr(E);
1561 Record.push_back(E->requiresADL());
1562 Record.push_back(E->isOverloaded());
1563 Record.AddDeclRef(E->getNamingClass());
1564 Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
1567 void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1569 Record.push_back(E->TypeTraitExprBits.NumArgs);
1570 Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
1571 Record.push_back(E->TypeTraitExprBits.Value);
1572 Record.AddSourceRange(E->getSourceRange());
1573 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1574 Record.AddTypeSourceInfo(E->getArg(I));
1575 Code = serialization::EXPR_TYPE_TRAIT;
1578 void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1580 Record.push_back(E->getTrait());
1581 Record.push_back(E->getValue());
1582 Record.AddSourceRange(E->getSourceRange());
1583 Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
1584 Record.AddStmt(E->getDimensionExpression());
1585 Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
1588 void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1590 Record.push_back(E->getTrait());
1591 Record.push_back(E->getValue());
1592 Record.AddSourceRange(E->getSourceRange());
1593 Record.AddStmt(E->getQueriedExpression());
1594 Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
1597 void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1599 Record.push_back(E->getValue());
1600 Record.AddSourceRange(E->getSourceRange());
1601 Record.AddStmt(E->getOperand());
1602 Code = serialization::EXPR_CXX_NOEXCEPT;
1605 void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1607 Record.AddSourceLocation(E->getEllipsisLoc());
1608 Record.push_back(E->NumExpansions);
1609 Record.AddStmt(E->getPattern());
1610 Code = serialization::EXPR_PACK_EXPANSION;
1613 void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1615 Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
1617 Record.AddSourceLocation(E->OperatorLoc);
1618 Record.AddSourceLocation(E->PackLoc);
1619 Record.AddSourceLocation(E->RParenLoc);
1620 Record.AddDeclRef(E->Pack);
1621 if (E->isPartiallySubstituted()) {
1622 for (const auto &TA : E->getPartialArguments())
1623 Record.AddTemplateArgument(TA);
1624 } else if (!E->isValueDependent()) {
1625 Record.push_back(E->getPackLength());
1627 Code = serialization::EXPR_SIZEOF_PACK;
1630 void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
1631 SubstNonTypeTemplateParmExpr *E) {
1633 Record.AddDeclRef(E->getParameter());
1634 Record.AddSourceLocation(E->getNameLoc());
1635 Record.AddStmt(E->getReplacement());
1636 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
1639 void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
1640 SubstNonTypeTemplateParmPackExpr *E) {
1642 Record.AddDeclRef(E->getParameterPack());
1643 Record.AddTemplateArgument(E->getArgumentPack());
1644 Record.AddSourceLocation(E->getParameterPackLocation());
1645 Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
1648 void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1650 Record.push_back(E->getNumExpansions());
1651 Record.AddDeclRef(E->getParameterPack());
1652 Record.AddSourceLocation(E->getParameterPackLocation());
1653 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1655 Record.AddDeclRef(*I);
1656 Code = serialization::EXPR_FUNCTION_PARM_PACK;
1659 void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
1661 Record.AddStmt(E->getTemporary());
1662 Record.AddDeclRef(E->getExtendingDecl());
1663 Record.push_back(E->getManglingNumber());
1664 Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
1667 void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
1669 Record.AddSourceLocation(E->LParenLoc);
1670 Record.AddSourceLocation(E->EllipsisLoc);
1671 Record.AddSourceLocation(E->RParenLoc);
1672 Record.AddStmt(E->SubExprs[0]);
1673 Record.AddStmt(E->SubExprs[1]);
1674 Record.push_back(E->Opcode);
1675 Code = serialization::EXPR_CXX_FOLD;
1678 void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
1680 Record.AddStmt(E->getSourceExpr());
1681 Record.AddSourceLocation(E->getLocation());
1682 Code = serialization::EXPR_OPAQUE_VALUE;
1685 void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
1687 // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
1688 llvm_unreachable("Cannot write TypoExpr nodes");
1691 //===----------------------------------------------------------------------===//
1692 // CUDA Expressions and Statements.
1693 //===----------------------------------------------------------------------===//
1695 void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
1697 Record.AddStmt(E->getConfig());
1698 Code = serialization::EXPR_CUDA_KERNEL_CALL;
1701 //===----------------------------------------------------------------------===//
1702 // OpenCL Expressions and Statements.
1703 //===----------------------------------------------------------------------===//
1704 void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
1706 Record.AddSourceLocation(E->getBuiltinLoc());
1707 Record.AddSourceLocation(E->getRParenLoc());
1708 Record.AddStmt(E->getSrcExpr());
1709 Code = serialization::EXPR_ASTYPE;
1712 //===----------------------------------------------------------------------===//
1713 // Microsoft Expressions and Statements.
1714 //===----------------------------------------------------------------------===//
1715 void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
1717 Record.push_back(E->isArrow());
1718 Record.AddStmt(E->getBaseExpr());
1719 Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
1720 Record.AddSourceLocation(E->getMemberLoc());
1721 Record.AddDeclRef(E->getPropertyDecl());
1722 Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
1725 void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
1727 Record.AddStmt(E->getBase());
1728 Record.AddStmt(E->getIdx());
1729 Record.AddSourceLocation(E->getRBracketLoc());
1730 Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
1733 void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
1735 Record.AddSourceRange(E->getSourceRange());
1736 Record.AddString(E->getUuidStr());
1737 if (E->isTypeOperand()) {
1738 Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
1739 Code = serialization::EXPR_CXX_UUIDOF_TYPE;
1741 Record.AddStmt(E->getExprOperand());
1742 Code = serialization::EXPR_CXX_UUIDOF_EXPR;
1746 void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
1748 Record.AddSourceLocation(S->getExceptLoc());
1749 Record.AddStmt(S->getFilterExpr());
1750 Record.AddStmt(S->getBlock());
1751 Code = serialization::STMT_SEH_EXCEPT;
1754 void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
1756 Record.AddSourceLocation(S->getFinallyLoc());
1757 Record.AddStmt(S->getBlock());
1758 Code = serialization::STMT_SEH_FINALLY;
1761 void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
1763 Record.push_back(S->getIsCXXTry());
1764 Record.AddSourceLocation(S->getTryLoc());
1765 Record.AddStmt(S->getTryBlock());
1766 Record.AddStmt(S->getHandler());
1767 Code = serialization::STMT_SEH_TRY;
1770 void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
1772 Record.AddSourceLocation(S->getLeaveLoc());
1773 Code = serialization::STMT_SEH_LEAVE;
1776 //===----------------------------------------------------------------------===//
1778 //===----------------------------------------------------------------------===//
1781 class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> {
1782 ASTRecordWriter &Record;
1784 OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {}
1785 #define OPENMP_CLAUSE(Name, Class) \
1786 void Visit##Class(Class *S);
1787 #include "clang/Basic/OpenMPKinds.def"
1788 void writeClause(OMPClause *C);
1789 void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
1790 void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
1794 void OMPClauseWriter::writeClause(OMPClause *C) {
1795 Record.push_back(C->getClauseKind());
1797 Record.AddSourceLocation(C->getLocStart());
1798 Record.AddSourceLocation(C->getLocEnd());
1801 void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) {
1802 Record.push_back(C->getCaptureRegion());
1803 Record.AddStmt(C->getPreInitStmt());
1806 void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) {
1807 VisitOMPClauseWithPreInit(C);
1808 Record.AddStmt(C->getPostUpdateExpr());
1811 void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) {
1812 VisitOMPClauseWithPreInit(C);
1813 Record.push_back(C->getNameModifier());
1814 Record.AddSourceLocation(C->getNameModifierLoc());
1815 Record.AddSourceLocation(C->getColonLoc());
1816 Record.AddStmt(C->getCondition());
1817 Record.AddSourceLocation(C->getLParenLoc());
1820 void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) {
1821 Record.AddStmt(C->getCondition());
1822 Record.AddSourceLocation(C->getLParenLoc());
1825 void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
1826 VisitOMPClauseWithPreInit(C);
1827 Record.AddStmt(C->getNumThreads());
1828 Record.AddSourceLocation(C->getLParenLoc());
1831 void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) {
1832 Record.AddStmt(C->getSafelen());
1833 Record.AddSourceLocation(C->getLParenLoc());
1836 void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
1837 Record.AddStmt(C->getSimdlen());
1838 Record.AddSourceLocation(C->getLParenLoc());
1841 void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) {
1842 Record.AddStmt(C->getNumForLoops());
1843 Record.AddSourceLocation(C->getLParenLoc());
1846 void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
1847 Record.push_back(C->getDefaultKind());
1848 Record.AddSourceLocation(C->getLParenLoc());
1849 Record.AddSourceLocation(C->getDefaultKindKwLoc());
1852 void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
1853 Record.push_back(C->getProcBindKind());
1854 Record.AddSourceLocation(C->getLParenLoc());
1855 Record.AddSourceLocation(C->getProcBindKindKwLoc());
1858 void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
1859 VisitOMPClauseWithPreInit(C);
1860 Record.push_back(C->getScheduleKind());
1861 Record.push_back(C->getFirstScheduleModifier());
1862 Record.push_back(C->getSecondScheduleModifier());
1863 Record.AddStmt(C->getChunkSize());
1864 Record.AddSourceLocation(C->getLParenLoc());
1865 Record.AddSourceLocation(C->getFirstScheduleModifierLoc());
1866 Record.AddSourceLocation(C->getSecondScheduleModifierLoc());
1867 Record.AddSourceLocation(C->getScheduleKindLoc());
1868 Record.AddSourceLocation(C->getCommaLoc());
1871 void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) {
1872 Record.AddStmt(C->getNumForLoops());
1873 Record.AddSourceLocation(C->getLParenLoc());
1876 void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {}
1878 void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}
1880 void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
1882 void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {}
1884 void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {}
1886 void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {}
1888 void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {}
1890 void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {}
1892 void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {}
1894 void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {}
1896 void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {}
1898 void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
1899 Record.push_back(C->varlist_size());
1900 Record.AddSourceLocation(C->getLParenLoc());
1901 for (auto *VE : C->varlists()) {
1904 for (auto *VE : C->private_copies()) {
1909 void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) {
1910 Record.push_back(C->varlist_size());
1911 VisitOMPClauseWithPreInit(C);
1912 Record.AddSourceLocation(C->getLParenLoc());
1913 for (auto *VE : C->varlists()) {
1916 for (auto *VE : C->private_copies()) {
1919 for (auto *VE : C->inits()) {
1924 void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) {
1925 Record.push_back(C->varlist_size());
1926 VisitOMPClauseWithPostUpdate(C);
1927 Record.AddSourceLocation(C->getLParenLoc());
1928 for (auto *VE : C->varlists())
1930 for (auto *E : C->private_copies())
1932 for (auto *E : C->source_exprs())
1934 for (auto *E : C->destination_exprs())
1936 for (auto *E : C->assignment_ops())
1940 void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {
1941 Record.push_back(C->varlist_size());
1942 Record.AddSourceLocation(C->getLParenLoc());
1943 for (auto *VE : C->varlists())
1947 void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) {
1948 Record.push_back(C->varlist_size());
1949 VisitOMPClauseWithPostUpdate(C);
1950 Record.AddSourceLocation(C->getLParenLoc());
1951 Record.AddSourceLocation(C->getColonLoc());
1952 Record.AddNestedNameSpecifierLoc(C->getQualifierLoc());
1953 Record.AddDeclarationNameInfo(C->getNameInfo());
1954 for (auto *VE : C->varlists())
1956 for (auto *VE : C->privates())
1958 for (auto *E : C->lhs_exprs())
1960 for (auto *E : C->rhs_exprs())
1962 for (auto *E : C->reduction_ops())
1966 void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) {
1967 Record.push_back(C->varlist_size());
1968 VisitOMPClauseWithPostUpdate(C);
1969 Record.AddSourceLocation(C->getLParenLoc());
1970 Record.AddSourceLocation(C->getColonLoc());
1971 Record.push_back(C->getModifier());
1972 Record.AddSourceLocation(C->getModifierLoc());
1973 for (auto *VE : C->varlists()) {
1976 for (auto *VE : C->privates()) {
1979 for (auto *VE : C->inits()) {
1982 for (auto *VE : C->updates()) {
1985 for (auto *VE : C->finals()) {
1988 Record.AddStmt(C->getStep());
1989 Record.AddStmt(C->getCalcStep());
1992 void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) {
1993 Record.push_back(C->varlist_size());
1994 Record.AddSourceLocation(C->getLParenLoc());
1995 Record.AddSourceLocation(C->getColonLoc());
1996 for (auto *VE : C->varlists())
1998 Record.AddStmt(C->getAlignment());
2001 void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) {
2002 Record.push_back(C->varlist_size());
2003 Record.AddSourceLocation(C->getLParenLoc());
2004 for (auto *VE : C->varlists())
2006 for (auto *E : C->source_exprs())
2008 for (auto *E : C->destination_exprs())
2010 for (auto *E : C->assignment_ops())
2014 void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) {
2015 Record.push_back(C->varlist_size());
2016 Record.AddSourceLocation(C->getLParenLoc());
2017 for (auto *VE : C->varlists())
2019 for (auto *E : C->source_exprs())
2021 for (auto *E : C->destination_exprs())
2023 for (auto *E : C->assignment_ops())
2027 void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) {
2028 Record.push_back(C->varlist_size());
2029 Record.AddSourceLocation(C->getLParenLoc());
2030 for (auto *VE : C->varlists())
2034 void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) {
2035 Record.push_back(C->varlist_size());
2036 Record.AddSourceLocation(C->getLParenLoc());
2037 Record.push_back(C->getDependencyKind());
2038 Record.AddSourceLocation(C->getDependencyLoc());
2039 Record.AddSourceLocation(C->getColonLoc());
2040 for (auto *VE : C->varlists())
2042 Record.AddStmt(C->getCounterValue());
2045 void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) {
2046 Record.AddStmt(C->getDevice());
2047 Record.AddSourceLocation(C->getLParenLoc());
2050 void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) {
2051 Record.push_back(C->varlist_size());
2052 Record.push_back(C->getUniqueDeclarationsNum());
2053 Record.push_back(C->getTotalComponentListNum());
2054 Record.push_back(C->getTotalComponentsNum());
2055 Record.AddSourceLocation(C->getLParenLoc());
2056 Record.push_back(C->getMapTypeModifier());
2057 Record.push_back(C->getMapType());
2058 Record.AddSourceLocation(C->getMapLoc());
2059 Record.AddSourceLocation(C->getColonLoc());
2060 for (auto *E : C->varlists())
2062 for (auto *D : C->all_decls())
2063 Record.AddDeclRef(D);
2064 for (auto N : C->all_num_lists())
2065 Record.push_back(N);
2066 for (auto N : C->all_lists_sizes())
2067 Record.push_back(N);
2068 for (auto &M : C->all_components()) {
2069 Record.AddStmt(M.getAssociatedExpression());
2070 Record.AddDeclRef(M.getAssociatedDeclaration());
2074 void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
2075 VisitOMPClauseWithPreInit(C);
2076 Record.AddStmt(C->getNumTeams());
2077 Record.AddSourceLocation(C->getLParenLoc());
2080 void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
2081 VisitOMPClauseWithPreInit(C);
2082 Record.AddStmt(C->getThreadLimit());
2083 Record.AddSourceLocation(C->getLParenLoc());
2086 void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) {
2087 Record.AddStmt(C->getPriority());
2088 Record.AddSourceLocation(C->getLParenLoc());
2091 void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
2092 Record.AddStmt(C->getGrainsize());
2093 Record.AddSourceLocation(C->getLParenLoc());
2096 void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
2097 Record.AddStmt(C->getNumTasks());
2098 Record.AddSourceLocation(C->getLParenLoc());
2101 void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) {
2102 Record.AddStmt(C->getHint());
2103 Record.AddSourceLocation(C->getLParenLoc());
2106 void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) {
2107 VisitOMPClauseWithPreInit(C);
2108 Record.push_back(C->getDistScheduleKind());
2109 Record.AddStmt(C->getChunkSize());
2110 Record.AddSourceLocation(C->getLParenLoc());
2111 Record.AddSourceLocation(C->getDistScheduleKindLoc());
2112 Record.AddSourceLocation(C->getCommaLoc());
2115 void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
2116 Record.push_back(C->getDefaultmapKind());
2117 Record.push_back(C->getDefaultmapModifier());
2118 Record.AddSourceLocation(C->getLParenLoc());
2119 Record.AddSourceLocation(C->getDefaultmapModifierLoc());
2120 Record.AddSourceLocation(C->getDefaultmapKindLoc());
2123 void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) {
2124 Record.push_back(C->varlist_size());
2125 Record.push_back(C->getUniqueDeclarationsNum());
2126 Record.push_back(C->getTotalComponentListNum());
2127 Record.push_back(C->getTotalComponentsNum());
2128 Record.AddSourceLocation(C->getLParenLoc());
2129 for (auto *E : C->varlists())
2131 for (auto *D : C->all_decls())
2132 Record.AddDeclRef(D);
2133 for (auto N : C->all_num_lists())
2134 Record.push_back(N);
2135 for (auto N : C->all_lists_sizes())
2136 Record.push_back(N);
2137 for (auto &M : C->all_components()) {
2138 Record.AddStmt(M.getAssociatedExpression());
2139 Record.AddDeclRef(M.getAssociatedDeclaration());
2143 void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) {
2144 Record.push_back(C->varlist_size());
2145 Record.push_back(C->getUniqueDeclarationsNum());
2146 Record.push_back(C->getTotalComponentListNum());
2147 Record.push_back(C->getTotalComponentsNum());
2148 Record.AddSourceLocation(C->getLParenLoc());
2149 for (auto *E : C->varlists())
2151 for (auto *D : C->all_decls())
2152 Record.AddDeclRef(D);
2153 for (auto N : C->all_num_lists())
2154 Record.push_back(N);
2155 for (auto N : C->all_lists_sizes())
2156 Record.push_back(N);
2157 for (auto &M : C->all_components()) {
2158 Record.AddStmt(M.getAssociatedExpression());
2159 Record.AddDeclRef(M.getAssociatedDeclaration());
2163 void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) {
2164 Record.push_back(C->varlist_size());
2165 Record.push_back(C->getUniqueDeclarationsNum());
2166 Record.push_back(C->getTotalComponentListNum());
2167 Record.push_back(C->getTotalComponentsNum());
2168 Record.AddSourceLocation(C->getLParenLoc());
2169 for (auto *E : C->varlists())
2171 for (auto *VE : C->private_copies())
2173 for (auto *VE : C->inits())
2175 for (auto *D : C->all_decls())
2176 Record.AddDeclRef(D);
2177 for (auto N : C->all_num_lists())
2178 Record.push_back(N);
2179 for (auto N : C->all_lists_sizes())
2180 Record.push_back(N);
2181 for (auto &M : C->all_components()) {
2182 Record.AddStmt(M.getAssociatedExpression());
2183 Record.AddDeclRef(M.getAssociatedDeclaration());
2187 void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
2188 Record.push_back(C->varlist_size());
2189 Record.push_back(C->getUniqueDeclarationsNum());
2190 Record.push_back(C->getTotalComponentListNum());
2191 Record.push_back(C->getTotalComponentsNum());
2192 Record.AddSourceLocation(C->getLParenLoc());
2193 for (auto *E : C->varlists())
2195 for (auto *D : C->all_decls())
2196 Record.AddDeclRef(D);
2197 for (auto N : C->all_num_lists())
2198 Record.push_back(N);
2199 for (auto N : C->all_lists_sizes())
2200 Record.push_back(N);
2201 for (auto &M : C->all_components()) {
2202 Record.AddStmt(M.getAssociatedExpression());
2203 Record.AddDeclRef(M.getAssociatedDeclaration());
2207 //===----------------------------------------------------------------------===//
2208 // OpenMP Directives.
2209 //===----------------------------------------------------------------------===//
2210 void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2211 Record.AddSourceLocation(E->getLocStart());
2212 Record.AddSourceLocation(E->getLocEnd());
2213 OMPClauseWriter ClauseWriter(Record);
2214 for (unsigned i = 0; i < E->getNumClauses(); ++i) {
2215 ClauseWriter.writeClause(E->getClause(i));
2217 if (E->hasAssociatedStmt())
2218 Record.AddStmt(E->getAssociatedStmt());
2221 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
2223 Record.push_back(D->getNumClauses());
2224 Record.push_back(D->getCollapsedNumber());
2225 VisitOMPExecutableDirective(D);
2226 Record.AddStmt(D->getIterationVariable());
2227 Record.AddStmt(D->getLastIteration());
2228 Record.AddStmt(D->getCalcLastIteration());
2229 Record.AddStmt(D->getPreCond());
2230 Record.AddStmt(D->getCond());
2231 Record.AddStmt(D->getInit());
2232 Record.AddStmt(D->getInc());
2233 Record.AddStmt(D->getPreInits());
2234 if (isOpenMPWorksharingDirective(D->getDirectiveKind()) ||
2235 isOpenMPTaskLoopDirective(D->getDirectiveKind()) ||
2236 isOpenMPDistributeDirective(D->getDirectiveKind())) {
2237 Record.AddStmt(D->getIsLastIterVariable());
2238 Record.AddStmt(D->getLowerBoundVariable());
2239 Record.AddStmt(D->getUpperBoundVariable());
2240 Record.AddStmt(D->getStrideVariable());
2241 Record.AddStmt(D->getEnsureUpperBound());
2242 Record.AddStmt(D->getNextLowerBound());
2243 Record.AddStmt(D->getNextUpperBound());
2244 Record.AddStmt(D->getNumIterations());
2246 if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) {
2247 Record.AddStmt(D->getPrevLowerBoundVariable());
2248 Record.AddStmt(D->getPrevUpperBoundVariable());
2249 Record.AddStmt(D->getDistInc());
2250 Record.AddStmt(D->getPrevEnsureUpperBound());
2251 Record.AddStmt(D->getCombinedLowerBoundVariable());
2252 Record.AddStmt(D->getCombinedUpperBoundVariable());
2253 Record.AddStmt(D->getCombinedEnsureUpperBound());
2254 Record.AddStmt(D->getCombinedInit());
2255 Record.AddStmt(D->getCombinedCond());
2256 Record.AddStmt(D->getCombinedNextLowerBound());
2257 Record.AddStmt(D->getCombinedNextUpperBound());
2259 for (auto I : D->counters()) {
2262 for (auto I : D->private_counters()) {
2265 for (auto I : D->inits()) {
2268 for (auto I : D->updates()) {
2271 for (auto I : D->finals()) {
2276 void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
2278 Record.push_back(D->getNumClauses());
2279 VisitOMPExecutableDirective(D);
2280 Record.push_back(D->hasCancel() ? 1 : 0);
2281 Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
2284 void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
2285 VisitOMPLoopDirective(D);
2286 Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
2289 void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
2290 VisitOMPLoopDirective(D);
2291 Record.push_back(D->hasCancel() ? 1 : 0);
2292 Code = serialization::STMT_OMP_FOR_DIRECTIVE;
2295 void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2296 VisitOMPLoopDirective(D);
2297 Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
2300 void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2302 Record.push_back(D->getNumClauses());
2303 VisitOMPExecutableDirective(D);
2304 Record.push_back(D->hasCancel() ? 1 : 0);
2305 Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
2308 void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
2310 VisitOMPExecutableDirective(D);
2311 Record.push_back(D->hasCancel() ? 1 : 0);
2312 Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
2315 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
2317 Record.push_back(D->getNumClauses());
2318 VisitOMPExecutableDirective(D);
2319 Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
2322 void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
2324 VisitOMPExecutableDirective(D);
2325 Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
2328 void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2330 Record.push_back(D->getNumClauses());
2331 VisitOMPExecutableDirective(D);
2332 Record.AddDeclarationNameInfo(D->getDirectiveName());
2333 Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
2336 void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2337 VisitOMPLoopDirective(D);
2338 Record.push_back(D->hasCancel() ? 1 : 0);
2339 Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
2342 void ASTStmtWriter::VisitOMPParallelForSimdDirective(
2343 OMPParallelForSimdDirective *D) {
2344 VisitOMPLoopDirective(D);
2345 Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
2348 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
2349 OMPParallelSectionsDirective *D) {
2351 Record.push_back(D->getNumClauses());
2352 VisitOMPExecutableDirective(D);
2353 Record.push_back(D->hasCancel() ? 1 : 0);
2354 Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
2357 void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
2359 Record.push_back(D->getNumClauses());
2360 VisitOMPExecutableDirective(D);
2361 Record.push_back(D->hasCancel() ? 1 : 0);
2362 Code = serialization::STMT_OMP_TASK_DIRECTIVE;
2365 void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2367 Record.push_back(D->getNumClauses());
2368 VisitOMPExecutableDirective(D);
2369 Record.AddStmt(D->getX());
2370 Record.AddStmt(D->getV());
2371 Record.AddStmt(D->getExpr());
2372 Record.AddStmt(D->getUpdateExpr());
2373 Record.push_back(D->isXLHSInRHSPart() ? 1 : 0);
2374 Record.push_back(D->isPostfixUpdate() ? 1 : 0);
2375 Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
2378 void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
2380 Record.push_back(D->getNumClauses());
2381 VisitOMPExecutableDirective(D);
2382 Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
2385 void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2387 Record.push_back(D->getNumClauses());
2388 VisitOMPExecutableDirective(D);
2389 Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
2392 void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
2393 OMPTargetEnterDataDirective *D) {
2395 Record.push_back(D->getNumClauses());
2396 VisitOMPExecutableDirective(D);
2397 Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
2400 void ASTStmtWriter::VisitOMPTargetExitDataDirective(
2401 OMPTargetExitDataDirective *D) {
2403 Record.push_back(D->getNumClauses());
2404 VisitOMPExecutableDirective(D);
2405 Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
2408 void ASTStmtWriter::VisitOMPTargetParallelDirective(
2409 OMPTargetParallelDirective *D) {
2411 Record.push_back(D->getNumClauses());
2412 VisitOMPExecutableDirective(D);
2413 Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
2416 void ASTStmtWriter::VisitOMPTargetParallelForDirective(
2417 OMPTargetParallelForDirective *D) {
2418 VisitOMPLoopDirective(D);
2419 Record.push_back(D->hasCancel() ? 1 : 0);
2420 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
2423 void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2425 VisitOMPExecutableDirective(D);
2426 Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
2429 void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2431 VisitOMPExecutableDirective(D);
2432 Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
2435 void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2437 VisitOMPExecutableDirective(D);
2438 Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
2441 void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2443 VisitOMPExecutableDirective(D);
2444 Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
2447 void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
2449 Record.push_back(D->getNumClauses());
2450 VisitOMPExecutableDirective(D);
2451 Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
2454 void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2456 Record.push_back(D->getNumClauses());
2457 VisitOMPExecutableDirective(D);
2458 Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
2461 void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2463 Record.push_back(D->getNumClauses());
2464 VisitOMPExecutableDirective(D);
2465 Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
2468 void ASTStmtWriter::VisitOMPCancellationPointDirective(
2469 OMPCancellationPointDirective *D) {
2471 VisitOMPExecutableDirective(D);
2472 Record.push_back(D->getCancelRegion());
2473 Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
2476 void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
2478 Record.push_back(D->getNumClauses());
2479 VisitOMPExecutableDirective(D);
2480 Record.push_back(D->getCancelRegion());
2481 Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
2484 void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2485 VisitOMPLoopDirective(D);
2486 Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
2489 void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2490 VisitOMPLoopDirective(D);
2491 Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
2494 void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2495 VisitOMPLoopDirective(D);
2496 Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
2499 void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2501 Record.push_back(D->getNumClauses());
2502 VisitOMPExecutableDirective(D);
2503 Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
2506 void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
2507 OMPDistributeParallelForDirective *D) {
2508 VisitOMPLoopDirective(D);
2509 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2512 void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
2513 OMPDistributeParallelForSimdDirective *D) {
2514 VisitOMPLoopDirective(D);
2515 Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2518 void ASTStmtWriter::VisitOMPDistributeSimdDirective(
2519 OMPDistributeSimdDirective *D) {
2520 VisitOMPLoopDirective(D);
2521 Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
2524 void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
2525 OMPTargetParallelForSimdDirective *D) {
2526 VisitOMPLoopDirective(D);
2527 Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
2530 void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2531 VisitOMPLoopDirective(D);
2532 Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
2535 void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
2536 OMPTeamsDistributeDirective *D) {
2537 VisitOMPLoopDirective(D);
2538 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
2541 void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
2542 OMPTeamsDistributeSimdDirective *D) {
2543 VisitOMPLoopDirective(D);
2544 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2547 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
2548 OMPTeamsDistributeParallelForSimdDirective *D) {
2549 VisitOMPLoopDirective(D);
2550 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2553 void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
2554 OMPTeamsDistributeParallelForDirective *D) {
2555 VisitOMPLoopDirective(D);
2556 Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2559 void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2561 Record.push_back(D->getNumClauses());
2562 VisitOMPExecutableDirective(D);
2563 Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
2566 void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
2567 OMPTargetTeamsDistributeDirective *D) {
2568 VisitOMPLoopDirective(D);
2569 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
2572 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
2573 OMPTargetTeamsDistributeParallelForDirective *D) {
2574 VisitOMPLoopDirective(D);
2575 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
2578 void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2579 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2580 VisitOMPLoopDirective(D);
2581 Code = serialization::
2582 STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
2585 void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
2586 OMPTargetTeamsDistributeSimdDirective *D) {
2587 VisitOMPLoopDirective(D);
2588 Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
2591 //===----------------------------------------------------------------------===//
2592 // ASTWriter Implementation
2593 //===----------------------------------------------------------------------===//
2595 unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
2596 assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
2597 "SwitchCase recorded twice");
2598 unsigned NextID = SwitchCaseIDs.size();
2599 SwitchCaseIDs[S] = NextID;
2603 unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
2604 assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
2605 "SwitchCase hasn't been seen yet");
2606 return SwitchCaseIDs[S];
2609 void ASTWriter::ClearSwitchCaseIDs() {
2610 SwitchCaseIDs.clear();
2613 /// \brief Write the given substatement or subexpression to the
2615 void ASTWriter::WriteSubStmt(Stmt *S) {
2617 ASTStmtWriter Writer(*this, Record);
2621 Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
2625 llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
2626 if (I != SubStmtEntries.end()) {
2627 Record.push_back(I->second);
2628 Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
2633 assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
2635 struct ParentStmtInserterRAII {
2637 llvm::DenseSet<Stmt *> &ParentStmts;
2639 ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
2640 : S(S), ParentStmts(ParentStmts) {
2641 ParentStmts.insert(S);
2643 ~ParentStmtInserterRAII() {
2644 ParentStmts.erase(S);
2648 ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
2653 uint64_t Offset = Writer.Emit();
2654 SubStmtEntries[S] = Offset;
2657 /// \brief Flush all of the statements that have been added to the
2658 /// queue via AddStmt().
2659 void ASTRecordWriter::FlushStmts() {
2660 // We expect to be the only consumer of the two temporary statement maps,
2661 // assert that they are empty.
2662 assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
2663 assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
2665 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2666 Writer->WriteSubStmt(StmtsToEmit[I]);
2668 assert(N == StmtsToEmit.size() && "record modified while being written!");
2670 // Note that we are at the end of a full expression. Any
2671 // expression records that follow this one are part of a different
2673 Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
2675 Writer->SubStmtEntries.clear();
2676 Writer->ParentStmts.clear();
2679 StmtsToEmit.clear();
2682 void ASTRecordWriter::FlushSubStmts() {
2683 // For a nested statement, write out the substatements in reverse order (so
2684 // that a simple stack machine can be used when loading), and don't emit a
2685 // STMT_STOP after each one.
2686 for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
2687 Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
2688 assert(N == StmtsToEmit.size() && "record modified while being written!");
2691 StmtsToEmit.clear();