1 //===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
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 //===----------------------------------------------------------------------===//
10 // This file implements the Stmt::Profile method, which builds a unique bit
11 // representation that identifies a statement/expression.
13 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/AST/DeclObjC.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/ExprCXX.h"
20 #include "clang/AST/ExprObjC.h"
21 #include "clang/AST/StmtVisitor.h"
22 #include "llvm/ADT/FoldingSet.h"
23 using namespace clang;
26 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
27 llvm::FoldingSetNodeID &ID;
28 const ASTContext &Context;
32 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
34 : ID(ID), Context(Context), Canonical(Canonical) { }
36 void VisitStmt(const Stmt *S);
38 #define STMT(Node, Base) void Visit##Node(const Node *S);
39 #include "clang/AST/StmtNodes.inc"
41 /// \brief Visit a declaration that is referenced within an expression
43 void VisitDecl(const Decl *D);
45 /// \brief Visit a type that is referenced within an expression or
47 void VisitType(QualType T);
49 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
52 /// \brief Visit a nested-name-specifier that occurs within an expression
54 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
56 /// \brief Visit a template name that occurs within an expression or
58 void VisitTemplateName(TemplateName Name);
60 /// \brief Visit template arguments that occur within an expression or
62 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
65 /// \brief Visit a single template argument.
66 void VisitTemplateArgument(const TemplateArgument &Arg);
70 void StmtProfiler::VisitStmt(const Stmt *S) {
71 ID.AddInteger(S->getStmtClass());
72 for (Stmt::const_child_range C = S->children(); C; ++C) {
80 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
82 for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
87 void StmtProfiler::VisitNullStmt(const NullStmt *S) {
91 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
95 void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
99 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
103 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
107 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
109 VisitDecl(S->getDecl());
112 void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
114 // TODO: maybe visit attributes?
117 void StmtProfiler::VisitIfStmt(const IfStmt *S) {
119 VisitDecl(S->getConditionVariable());
122 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
124 VisitDecl(S->getConditionVariable());
127 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
129 VisitDecl(S->getConditionVariable());
132 void StmtProfiler::VisitDoStmt(const DoStmt *S) {
136 void StmtProfiler::VisitForStmt(const ForStmt *S) {
140 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
142 VisitDecl(S->getLabel());
145 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
149 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
153 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
157 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
161 void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
163 ID.AddBoolean(S->isVolatile());
164 ID.AddBoolean(S->isSimple());
165 VisitStringLiteral(S->getAsmString());
166 ID.AddInteger(S->getNumOutputs());
167 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
168 ID.AddString(S->getOutputName(I));
169 VisitStringLiteral(S->getOutputConstraintLiteral(I));
171 ID.AddInteger(S->getNumInputs());
172 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
173 ID.AddString(S->getInputName(I));
174 VisitStringLiteral(S->getInputConstraintLiteral(I));
176 ID.AddInteger(S->getNumClobbers());
177 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
178 VisitStringLiteral(S->getClobberStringLiteral(I));
181 void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
182 // FIXME: Implement MS style inline asm statement profiler.
186 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
188 VisitType(S->getCaughtType());
191 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
195 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
199 void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
201 ID.AddBoolean(S->isIfExists());
202 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
203 VisitName(S->getNameInfo().getName());
206 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
210 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
214 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
218 void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
222 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
226 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
228 ID.AddBoolean(S->hasEllipsis());
229 if (S->getCatchParamDecl())
230 VisitType(S->getCatchParamDecl()->getType());
233 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
237 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
242 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
246 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
251 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
256 class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
257 StmtProfiler *Profiler;
258 /// \brief Process clauses with list of variables.
259 template <typename T>
260 void VisitOMPClauseList(T *Node);
262 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
263 #define OPENMP_CLAUSE(Name, Class) \
264 void Visit##Class(const Class *C);
265 #include "clang/Basic/OpenMPKinds.def"
268 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
271 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
272 for (typename T::varlist_const_iterator I = Node->varlist_begin(),
273 E = Node->varlist_end();
275 Profiler->VisitStmt(*I);
278 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
279 VisitOMPClauseList(C);
281 void OMPClauseProfiler::VisitOMPFirstprivateClause(
282 const OMPFirstprivateClause *C) {
283 VisitOMPClauseList(C);
285 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
286 VisitOMPClauseList(C);
291 StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
293 OMPClauseProfiler P(this);
294 ArrayRef<OMPClause *> Clauses = S->clauses();
295 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
301 void StmtProfiler::VisitExpr(const Expr *S) {
305 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
308 VisitNestedNameSpecifier(S->getQualifier());
309 VisitDecl(S->getDecl());
311 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
314 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
316 ID.AddInteger(S->getIdentType());
319 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
321 S->getValue().Profile(ID);
324 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
326 ID.AddInteger(S->getKind());
327 ID.AddInteger(S->getValue());
330 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
332 S->getValue().Profile(ID);
333 ID.AddBoolean(S->isExact());
336 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
340 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
342 ID.AddString(S->getBytes());
343 ID.AddInteger(S->getKind());
346 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
350 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
354 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
356 ID.AddInteger(S->getOpcode());
359 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
360 VisitType(S->getTypeSourceInfo()->getType());
361 unsigned n = S->getNumComponents();
362 for (unsigned i = 0; i < n; ++i) {
363 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
364 ID.AddInteger(ON.getKind());
365 switch (ON.getKind()) {
366 case OffsetOfExpr::OffsetOfNode::Array:
367 // Expressions handled below.
370 case OffsetOfExpr::OffsetOfNode::Field:
371 VisitDecl(ON.getField());
374 case OffsetOfExpr::OffsetOfNode::Identifier:
375 ID.AddPointer(ON.getFieldName());
378 case OffsetOfExpr::OffsetOfNode::Base:
379 // These nodes are implicit, and therefore don't need profiling.
388 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
390 ID.AddInteger(S->getKind());
391 if (S->isArgumentType())
392 VisitType(S->getArgumentType());
395 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
399 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
403 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
405 VisitDecl(S->getMemberDecl());
407 VisitNestedNameSpecifier(S->getQualifier());
408 ID.AddBoolean(S->isArrow());
411 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
413 ID.AddBoolean(S->isFileScope());
416 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
420 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
422 ID.AddInteger(S->getValueKind());
425 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
427 VisitType(S->getTypeAsWritten());
430 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
431 VisitExplicitCastExpr(S);
434 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
436 ID.AddInteger(S->getOpcode());
440 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
441 VisitBinaryOperator(S);
444 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
448 void StmtProfiler::VisitBinaryConditionalOperator(
449 const BinaryConditionalOperator *S) {
453 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
455 VisitDecl(S->getLabel());
458 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
462 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
466 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
470 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
474 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
478 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
482 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
483 if (S->getSyntacticForm()) {
484 VisitInitListExpr(S->getSyntacticForm());
491 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
493 ID.AddBoolean(S->usesGNUSyntax());
494 for (DesignatedInitExpr::const_designators_iterator D =
495 S->designators_begin(), DEnd = S->designators_end();
497 if (D->isFieldDesignator()) {
499 VisitName(D->getFieldName());
503 if (D->isArrayDesignator()) {
506 assert(D->isArrayRangeDesignator());
509 ID.AddInteger(D->getFirstExprIndex());
513 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
517 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
519 VisitName(&S->getAccessor());
522 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
524 VisitDecl(S->getBlockDecl());
527 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
529 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
530 QualType T = S->getAssocType(i);
535 VisitExpr(S->getAssocExpr(i));
539 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
541 for (PseudoObjectExpr::const_semantics_iterator
542 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
543 // Normally, we would not profile the source expressions of OVEs.
544 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
545 Visit(OVE->getSourceExpr());
548 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
550 ID.AddInteger(S->getOp());
553 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
554 UnaryOperatorKind &UnaryOp,
555 BinaryOperatorKind &BinaryOp) {
556 switch (S->getOperator()) {
561 case OO_Array_Delete:
565 case NUM_OVERLOADED_OPERATORS:
566 llvm_unreachable("Invalid operator call kind");
569 if (S->getNumArgs() == 1) {
571 return Stmt::UnaryOperatorClass;
575 return Stmt::BinaryOperatorClass;
578 if (S->getNumArgs() == 1) {
580 return Stmt::UnaryOperatorClass;
584 return Stmt::BinaryOperatorClass;
587 if (S->getNumArgs() == 1) {
589 return Stmt::UnaryOperatorClass;
593 return Stmt::BinaryOperatorClass;
597 return Stmt::BinaryOperatorClass;
601 return Stmt::BinaryOperatorClass;
605 return Stmt::BinaryOperatorClass;
608 if (S->getNumArgs() == 1) {
610 return Stmt::UnaryOperatorClass;
614 return Stmt::BinaryOperatorClass;
618 return Stmt::BinaryOperatorClass;
622 return Stmt::UnaryOperatorClass;
626 return Stmt::UnaryOperatorClass;
629 BinaryOp = BO_Assign;
630 return Stmt::BinaryOperatorClass;
634 return Stmt::BinaryOperatorClass;
638 return Stmt::BinaryOperatorClass;
641 BinaryOp = BO_AddAssign;
642 return Stmt::CompoundAssignOperatorClass;
645 BinaryOp = BO_SubAssign;
646 return Stmt::CompoundAssignOperatorClass;
649 BinaryOp = BO_MulAssign;
650 return Stmt::CompoundAssignOperatorClass;
653 BinaryOp = BO_DivAssign;
654 return Stmt::CompoundAssignOperatorClass;
656 case OO_PercentEqual:
657 BinaryOp = BO_RemAssign;
658 return Stmt::CompoundAssignOperatorClass;
661 BinaryOp = BO_XorAssign;
662 return Stmt::CompoundAssignOperatorClass;
665 BinaryOp = BO_AndAssign;
666 return Stmt::CompoundAssignOperatorClass;
669 BinaryOp = BO_OrAssign;
670 return Stmt::CompoundAssignOperatorClass;
674 return Stmt::BinaryOperatorClass;
676 case OO_GreaterGreater:
678 return Stmt::BinaryOperatorClass;
680 case OO_LessLessEqual:
681 BinaryOp = BO_ShlAssign;
682 return Stmt::CompoundAssignOperatorClass;
684 case OO_GreaterGreaterEqual:
685 BinaryOp = BO_ShrAssign;
686 return Stmt::CompoundAssignOperatorClass;
690 return Stmt::BinaryOperatorClass;
692 case OO_ExclaimEqual:
694 return Stmt::BinaryOperatorClass;
698 return Stmt::BinaryOperatorClass;
700 case OO_GreaterEqual:
702 return Stmt::BinaryOperatorClass;
706 return Stmt::BinaryOperatorClass;
710 return Stmt::BinaryOperatorClass;
713 UnaryOp = S->getNumArgs() == 1? UO_PreInc
715 return Stmt::UnaryOperatorClass;
718 UnaryOp = S->getNumArgs() == 1? UO_PreDec
720 return Stmt::UnaryOperatorClass;
724 return Stmt::BinaryOperatorClass;
728 BinaryOp = BO_PtrMemI;
729 return Stmt::BinaryOperatorClass;
732 return Stmt::ArraySubscriptExprClass;
735 llvm_unreachable("Invalid overloaded operator expression");
739 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
740 if (S->isTypeDependent()) {
741 // Type-dependent operator calls are profiled like their underlying
742 // syntactic operator.
743 UnaryOperatorKind UnaryOp = UO_Extension;
744 BinaryOperatorKind BinaryOp = BO_Comma;
745 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
748 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
750 if (SC == Stmt::UnaryOperatorClass)
751 ID.AddInteger(UnaryOp);
752 else if (SC == Stmt::BinaryOperatorClass ||
753 SC == Stmt::CompoundAssignOperatorClass)
754 ID.AddInteger(BinaryOp);
756 assert(SC == Stmt::ArraySubscriptExprClass);
762 ID.AddInteger(S->getOperator());
765 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
769 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
773 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
777 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
778 VisitExplicitCastExpr(S);
781 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
782 VisitCXXNamedCastExpr(S);
785 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
786 VisitCXXNamedCastExpr(S);
790 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
791 VisitCXXNamedCastExpr(S);
794 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
795 VisitCXXNamedCastExpr(S);
798 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
802 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
804 ID.AddBoolean(S->getValue());
807 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
811 void StmtProfiler::VisitCXXStdInitializerListExpr(
812 const CXXStdInitializerListExpr *S) {
816 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
818 if (S->isTypeOperand())
819 VisitType(S->getTypeOperandSourceInfo()->getType());
822 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
824 if (S->isTypeOperand())
825 VisitType(S->getTypeOperandSourceInfo()->getType());
828 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
830 VisitDecl(S->getPropertyDecl());
833 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
835 ID.AddBoolean(S->isImplicit());
838 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
842 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
844 VisitDecl(S->getParam());
847 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
849 VisitDecl(S->getField());
852 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
855 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
858 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
860 VisitDecl(S->getConstructor());
861 ID.AddBoolean(S->isElidable());
864 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
865 VisitExplicitCastExpr(S);
869 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
870 VisitCXXConstructExpr(S);
874 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
876 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
877 CEnd = S->explicit_capture_end();
879 ID.AddInteger(C->getCaptureKind());
880 switch (C->getCaptureKind()) {
885 VisitDecl(C->getCapturedVar());
886 ID.AddBoolean(C->isPackExpansion());
890 // Note: If we actually needed to be able to match lambda
891 // expressions, we would have to consider parameters and return type
892 // here, among other things.
893 VisitStmt(S->getBody());
897 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
901 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
903 ID.AddBoolean(S->isGlobalDelete());
904 ID.AddBoolean(S->isArrayForm());
905 VisitDecl(S->getOperatorDelete());
909 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
911 VisitType(S->getAllocatedType());
912 VisitDecl(S->getOperatorNew());
913 VisitDecl(S->getOperatorDelete());
914 ID.AddBoolean(S->isArray());
915 ID.AddInteger(S->getNumPlacementArgs());
916 ID.AddBoolean(S->isGlobalNew());
917 ID.AddBoolean(S->isParenTypeId());
918 ID.AddInteger(S->getInitializationStyle());
922 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
924 ID.AddBoolean(S->isArrow());
925 VisitNestedNameSpecifier(S->getQualifier());
926 ID.AddBoolean(S->getScopeTypeInfo() != 0);
927 if (S->getScopeTypeInfo())
928 VisitType(S->getScopeTypeInfo()->getType());
929 ID.AddBoolean(S->getDestroyedTypeInfo() != 0);
930 if (S->getDestroyedTypeInfo())
931 VisitType(S->getDestroyedType());
933 ID.AddPointer(S->getDestroyedTypeIdentifier());
936 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
938 VisitNestedNameSpecifier(S->getQualifier());
939 VisitName(S->getName());
940 ID.AddBoolean(S->hasExplicitTemplateArgs());
941 if (S->hasExplicitTemplateArgs())
942 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
943 S->getExplicitTemplateArgs().NumTemplateArgs);
947 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
948 VisitOverloadExpr(S);
951 void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
953 ID.AddInteger(S->getTrait());
954 VisitType(S->getQueriedType());
957 void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
959 ID.AddInteger(S->getTrait());
960 VisitType(S->getLhsType());
961 VisitType(S->getRhsType());
964 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
966 ID.AddInteger(S->getTrait());
967 ID.AddInteger(S->getNumArgs());
968 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
969 VisitType(S->getArg(I)->getType());
972 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
974 ID.AddInteger(S->getTrait());
975 VisitType(S->getQueriedType());
978 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
980 ID.AddInteger(S->getTrait());
981 VisitExpr(S->getQueriedExpression());
984 void StmtProfiler::VisitDependentScopeDeclRefExpr(
985 const DependentScopeDeclRefExpr *S) {
987 VisitName(S->getDeclName());
988 VisitNestedNameSpecifier(S->getQualifier());
989 ID.AddBoolean(S->hasExplicitTemplateArgs());
990 if (S->hasExplicitTemplateArgs())
991 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
994 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
998 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
999 const CXXUnresolvedConstructExpr *S) {
1001 VisitType(S->getTypeAsWritten());
1004 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1005 const CXXDependentScopeMemberExpr *S) {
1006 ID.AddBoolean(S->isImplicitAccess());
1007 if (!S->isImplicitAccess()) {
1009 ID.AddBoolean(S->isArrow());
1011 VisitNestedNameSpecifier(S->getQualifier());
1012 VisitName(S->getMember());
1013 ID.AddBoolean(S->hasExplicitTemplateArgs());
1014 if (S->hasExplicitTemplateArgs())
1015 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1018 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
1019 ID.AddBoolean(S->isImplicitAccess());
1020 if (!S->isImplicitAccess()) {
1022 ID.AddBoolean(S->isArrow());
1024 VisitNestedNameSpecifier(S->getQualifier());
1025 VisitName(S->getMemberName());
1026 ID.AddBoolean(S->hasExplicitTemplateArgs());
1027 if (S->hasExplicitTemplateArgs())
1028 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1031 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
1035 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
1039 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
1041 VisitDecl(S->getPack());
1044 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
1045 const SubstNonTypeTemplateParmPackExpr *S) {
1047 VisitDecl(S->getParameterPack());
1048 VisitTemplateArgument(S->getArgumentPack());
1051 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1052 const SubstNonTypeTemplateParmExpr *E) {
1053 // Profile exactly as the replacement expression.
1054 Visit(E->getReplacement());
1057 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1059 VisitDecl(S->getParameterPack());
1060 ID.AddInteger(S->getNumExpansions());
1061 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1065 void StmtProfiler::VisitMaterializeTemporaryExpr(
1066 const MaterializeTemporaryExpr *S) {
1070 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
1074 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
1078 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
1082 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1086 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1090 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
1092 VisitType(S->getEncodedType());
1095 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
1097 VisitName(S->getSelector());
1100 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
1102 VisitDecl(S->getProtocol());
1105 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
1107 VisitDecl(S->getDecl());
1108 ID.AddBoolean(S->isArrow());
1109 ID.AddBoolean(S->isFreeIvar());
1112 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
1114 if (S->isImplicitProperty()) {
1115 VisitDecl(S->getImplicitPropertyGetter());
1116 VisitDecl(S->getImplicitPropertySetter());
1118 VisitDecl(S->getExplicitProperty());
1120 if (S->isSuperReceiver()) {
1121 ID.AddBoolean(S->isSuperReceiver());
1122 VisitType(S->getSuperReceiverType());
1126 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1128 VisitDecl(S->getAtIndexMethodDecl());
1129 VisitDecl(S->setAtIndexMethodDecl());
1132 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
1134 VisitName(S->getSelector());
1135 VisitDecl(S->getMethodDecl());
1138 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
1140 ID.AddBoolean(S->isArrow());
1143 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1145 ID.AddBoolean(S->getValue());
1148 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1149 const ObjCIndirectCopyRestoreExpr *S) {
1151 ID.AddBoolean(S->shouldCopy());
1154 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
1155 VisitExplicitCastExpr(S);
1156 ID.AddBoolean(S->getBridgeKind());
1159 void StmtProfiler::VisitDecl(const Decl *D) {
1160 ID.AddInteger(D? D->getKind() : 0);
1162 if (Canonical && D) {
1163 if (const NonTypeTemplateParmDecl *NTTP =
1164 dyn_cast<NonTypeTemplateParmDecl>(D)) {
1165 ID.AddInteger(NTTP->getDepth());
1166 ID.AddInteger(NTTP->getIndex());
1167 ID.AddBoolean(NTTP->isParameterPack());
1168 VisitType(NTTP->getType());
1172 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
1173 // The Itanium C++ ABI uses the type, scope depth, and scope
1174 // index of a parameter when mangling expressions that involve
1175 // function parameters, so we will use the parameter's type for
1176 // establishing function parameter identity. That way, our
1177 // definition of "equivalent" (per C++ [temp.over.link]) is at
1178 // least as strong as the definition of "equivalent" used for
1180 VisitType(Parm->getType());
1181 ID.AddInteger(Parm->getFunctionScopeDepth());
1182 ID.AddInteger(Parm->getFunctionScopeIndex());
1186 if (const TemplateTypeParmDecl *TTP =
1187 dyn_cast<TemplateTypeParmDecl>(D)) {
1188 ID.AddInteger(TTP->getDepth());
1189 ID.AddInteger(TTP->getIndex());
1190 ID.AddBoolean(TTP->isParameterPack());
1194 if (const TemplateTemplateParmDecl *TTP =
1195 dyn_cast<TemplateTemplateParmDecl>(D)) {
1196 ID.AddInteger(TTP->getDepth());
1197 ID.AddInteger(TTP->getIndex());
1198 ID.AddBoolean(TTP->isParameterPack());
1203 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1206 void StmtProfiler::VisitType(QualType T) {
1208 T = Context.getCanonicalType(T);
1210 ID.AddPointer(T.getAsOpaquePtr());
1213 void StmtProfiler::VisitName(DeclarationName Name) {
1214 ID.AddPointer(Name.getAsOpaquePtr());
1217 void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1219 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1223 void StmtProfiler::VisitTemplateName(TemplateName Name) {
1225 Name = Context.getCanonicalTemplateName(Name);
1230 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
1232 ID.AddInteger(NumArgs);
1233 for (unsigned I = 0; I != NumArgs; ++I)
1234 VisitTemplateArgument(Args[I].getArgument());
1237 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1238 // Mostly repetitive with TemplateArgument::Profile!
1239 ID.AddInteger(Arg.getKind());
1240 switch (Arg.getKind()) {
1241 case TemplateArgument::Null:
1244 case TemplateArgument::Type:
1245 VisitType(Arg.getAsType());
1248 case TemplateArgument::Template:
1249 case TemplateArgument::TemplateExpansion:
1250 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
1253 case TemplateArgument::Declaration:
1254 VisitDecl(Arg.getAsDecl());
1257 case TemplateArgument::NullPtr:
1258 VisitType(Arg.getNullPtrType());
1261 case TemplateArgument::Integral:
1262 Arg.getAsIntegral().Profile(ID);
1263 VisitType(Arg.getIntegralType());
1266 case TemplateArgument::Expression:
1267 Visit(Arg.getAsExpr());
1270 case TemplateArgument::Pack:
1271 const TemplateArgument *Pack = Arg.pack_begin();
1272 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1273 VisitTemplateArgument(Pack[i]);
1278 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1279 bool Canonical) const {
1280 StmtProfiler Profiler(ID, Context, Canonical);
1281 Profiler.Visit(this);