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) {
255 void StmtProfiler::VisitExpr(const Expr *S) {
259 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
262 VisitNestedNameSpecifier(S->getQualifier());
263 VisitDecl(S->getDecl());
265 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
268 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
270 ID.AddInteger(S->getIdentType());
273 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
275 S->getValue().Profile(ID);
278 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
280 ID.AddInteger(S->getKind());
281 ID.AddInteger(S->getValue());
284 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
286 S->getValue().Profile(ID);
287 ID.AddBoolean(S->isExact());
290 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
294 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
296 ID.AddString(S->getBytes());
297 ID.AddInteger(S->getKind());
300 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
304 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
308 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
310 ID.AddInteger(S->getOpcode());
313 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
314 VisitType(S->getTypeSourceInfo()->getType());
315 unsigned n = S->getNumComponents();
316 for (unsigned i = 0; i < n; ++i) {
317 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
318 ID.AddInteger(ON.getKind());
319 switch (ON.getKind()) {
320 case OffsetOfExpr::OffsetOfNode::Array:
321 // Expressions handled below.
324 case OffsetOfExpr::OffsetOfNode::Field:
325 VisitDecl(ON.getField());
328 case OffsetOfExpr::OffsetOfNode::Identifier:
329 ID.AddPointer(ON.getFieldName());
332 case OffsetOfExpr::OffsetOfNode::Base:
333 // These nodes are implicit, and therefore don't need profiling.
342 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
344 ID.AddInteger(S->getKind());
345 if (S->isArgumentType())
346 VisitType(S->getArgumentType());
349 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
353 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
357 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
359 VisitDecl(S->getMemberDecl());
361 VisitNestedNameSpecifier(S->getQualifier());
362 ID.AddBoolean(S->isArrow());
365 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
367 ID.AddBoolean(S->isFileScope());
370 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
374 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
376 ID.AddInteger(S->getValueKind());
379 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
381 VisitType(S->getTypeAsWritten());
384 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
385 VisitExplicitCastExpr(S);
388 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
390 ID.AddInteger(S->getOpcode());
394 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
395 VisitBinaryOperator(S);
398 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
402 void StmtProfiler::VisitBinaryConditionalOperator(
403 const BinaryConditionalOperator *S) {
407 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
409 VisitDecl(S->getLabel());
412 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
416 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
420 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
424 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
428 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
432 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
433 if (S->getSyntacticForm()) {
434 VisitInitListExpr(S->getSyntacticForm());
441 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
443 ID.AddBoolean(S->usesGNUSyntax());
444 for (DesignatedInitExpr::const_designators_iterator D =
445 S->designators_begin(), DEnd = S->designators_end();
447 if (D->isFieldDesignator()) {
449 VisitName(D->getFieldName());
453 if (D->isArrayDesignator()) {
456 assert(D->isArrayRangeDesignator());
459 ID.AddInteger(D->getFirstExprIndex());
463 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
467 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
469 VisitName(&S->getAccessor());
472 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
474 VisitDecl(S->getBlockDecl());
477 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
479 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
480 QualType T = S->getAssocType(i);
485 VisitExpr(S->getAssocExpr(i));
489 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
491 for (PseudoObjectExpr::const_semantics_iterator
492 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
493 // Normally, we would not profile the source expressions of OVEs.
494 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
495 Visit(OVE->getSourceExpr());
498 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
500 ID.AddInteger(S->getOp());
503 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
504 UnaryOperatorKind &UnaryOp,
505 BinaryOperatorKind &BinaryOp) {
506 switch (S->getOperator()) {
511 case OO_Array_Delete:
515 case NUM_OVERLOADED_OPERATORS:
516 llvm_unreachable("Invalid operator call kind");
519 if (S->getNumArgs() == 1) {
521 return Stmt::UnaryOperatorClass;
525 return Stmt::BinaryOperatorClass;
528 if (S->getNumArgs() == 1) {
530 return Stmt::UnaryOperatorClass;
534 return Stmt::BinaryOperatorClass;
537 if (S->getNumArgs() == 1) {
539 return Stmt::UnaryOperatorClass;
543 return Stmt::BinaryOperatorClass;
547 return Stmt::BinaryOperatorClass;
551 return Stmt::BinaryOperatorClass;
555 return Stmt::BinaryOperatorClass;
558 if (S->getNumArgs() == 1) {
560 return Stmt::UnaryOperatorClass;
564 return Stmt::BinaryOperatorClass;
568 return Stmt::BinaryOperatorClass;
572 return Stmt::UnaryOperatorClass;
576 return Stmt::UnaryOperatorClass;
579 BinaryOp = BO_Assign;
580 return Stmt::BinaryOperatorClass;
584 return Stmt::BinaryOperatorClass;
588 return Stmt::BinaryOperatorClass;
591 BinaryOp = BO_AddAssign;
592 return Stmt::CompoundAssignOperatorClass;
595 BinaryOp = BO_SubAssign;
596 return Stmt::CompoundAssignOperatorClass;
599 BinaryOp = BO_MulAssign;
600 return Stmt::CompoundAssignOperatorClass;
603 BinaryOp = BO_DivAssign;
604 return Stmt::CompoundAssignOperatorClass;
606 case OO_PercentEqual:
607 BinaryOp = BO_RemAssign;
608 return Stmt::CompoundAssignOperatorClass;
611 BinaryOp = BO_XorAssign;
612 return Stmt::CompoundAssignOperatorClass;
615 BinaryOp = BO_AndAssign;
616 return Stmt::CompoundAssignOperatorClass;
619 BinaryOp = BO_OrAssign;
620 return Stmt::CompoundAssignOperatorClass;
624 return Stmt::BinaryOperatorClass;
626 case OO_GreaterGreater:
628 return Stmt::BinaryOperatorClass;
630 case OO_LessLessEqual:
631 BinaryOp = BO_ShlAssign;
632 return Stmt::CompoundAssignOperatorClass;
634 case OO_GreaterGreaterEqual:
635 BinaryOp = BO_ShrAssign;
636 return Stmt::CompoundAssignOperatorClass;
640 return Stmt::BinaryOperatorClass;
642 case OO_ExclaimEqual:
644 return Stmt::BinaryOperatorClass;
648 return Stmt::BinaryOperatorClass;
650 case OO_GreaterEqual:
652 return Stmt::BinaryOperatorClass;
656 return Stmt::BinaryOperatorClass;
660 return Stmt::BinaryOperatorClass;
663 UnaryOp = S->getNumArgs() == 1? UO_PreInc
665 return Stmt::UnaryOperatorClass;
668 UnaryOp = S->getNumArgs() == 1? UO_PreDec
670 return Stmt::UnaryOperatorClass;
674 return Stmt::BinaryOperatorClass;
678 BinaryOp = BO_PtrMemI;
679 return Stmt::BinaryOperatorClass;
682 return Stmt::ArraySubscriptExprClass;
685 llvm_unreachable("Invalid overloaded operator expression");
689 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
690 if (S->isTypeDependent()) {
691 // Type-dependent operator calls are profiled like their underlying
692 // syntactic operator.
693 UnaryOperatorKind UnaryOp = UO_Extension;
694 BinaryOperatorKind BinaryOp = BO_Comma;
695 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
698 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
700 if (SC == Stmt::UnaryOperatorClass)
701 ID.AddInteger(UnaryOp);
702 else if (SC == Stmt::BinaryOperatorClass ||
703 SC == Stmt::CompoundAssignOperatorClass)
704 ID.AddInteger(BinaryOp);
706 assert(SC == Stmt::ArraySubscriptExprClass);
712 ID.AddInteger(S->getOperator());
715 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
719 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
723 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
727 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
728 VisitExplicitCastExpr(S);
731 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
732 VisitCXXNamedCastExpr(S);
735 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
736 VisitCXXNamedCastExpr(S);
740 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
741 VisitCXXNamedCastExpr(S);
744 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
745 VisitCXXNamedCastExpr(S);
748 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
752 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
754 ID.AddBoolean(S->getValue());
757 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
761 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
763 if (S->isTypeOperand())
764 VisitType(S->getTypeOperand());
767 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
769 if (S->isTypeOperand())
770 VisitType(S->getTypeOperand());
773 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
775 VisitDecl(S->getPropertyDecl());
778 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
780 ID.AddBoolean(S->isImplicit());
783 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
787 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
789 VisitDecl(S->getParam());
792 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
794 VisitDecl(S->getField());
797 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
800 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
803 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
805 VisitDecl(S->getConstructor());
806 ID.AddBoolean(S->isElidable());
809 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
810 VisitExplicitCastExpr(S);
814 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
815 VisitCXXConstructExpr(S);
819 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
821 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
822 CEnd = S->explicit_capture_end();
824 ID.AddInteger(C->getCaptureKind());
825 if (C->capturesVariable()) {
826 VisitDecl(C->getCapturedVar());
827 ID.AddBoolean(C->isPackExpansion());
830 // Note: If we actually needed to be able to match lambda
831 // expressions, we would have to consider parameters and return type
832 // here, among other things.
833 VisitStmt(S->getBody());
837 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
841 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
843 ID.AddBoolean(S->isGlobalDelete());
844 ID.AddBoolean(S->isArrayForm());
845 VisitDecl(S->getOperatorDelete());
849 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
851 VisitType(S->getAllocatedType());
852 VisitDecl(S->getOperatorNew());
853 VisitDecl(S->getOperatorDelete());
854 ID.AddBoolean(S->isArray());
855 ID.AddInteger(S->getNumPlacementArgs());
856 ID.AddBoolean(S->isGlobalNew());
857 ID.AddBoolean(S->isParenTypeId());
858 ID.AddInteger(S->getInitializationStyle());
862 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
864 ID.AddBoolean(S->isArrow());
865 VisitNestedNameSpecifier(S->getQualifier());
866 VisitType(S->getDestroyedType());
869 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
871 VisitNestedNameSpecifier(S->getQualifier());
872 VisitName(S->getName());
873 ID.AddBoolean(S->hasExplicitTemplateArgs());
874 if (S->hasExplicitTemplateArgs())
875 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
876 S->getExplicitTemplateArgs().NumTemplateArgs);
880 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
881 VisitOverloadExpr(S);
884 void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
886 ID.AddInteger(S->getTrait());
887 VisitType(S->getQueriedType());
890 void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
892 ID.AddInteger(S->getTrait());
893 VisitType(S->getLhsType());
894 VisitType(S->getRhsType());
897 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
899 ID.AddInteger(S->getTrait());
900 ID.AddInteger(S->getNumArgs());
901 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
902 VisitType(S->getArg(I)->getType());
905 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
907 ID.AddInteger(S->getTrait());
908 VisitType(S->getQueriedType());
911 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
913 ID.AddInteger(S->getTrait());
914 VisitExpr(S->getQueriedExpression());
917 void StmtProfiler::VisitDependentScopeDeclRefExpr(
918 const DependentScopeDeclRefExpr *S) {
920 VisitName(S->getDeclName());
921 VisitNestedNameSpecifier(S->getQualifier());
922 ID.AddBoolean(S->hasExplicitTemplateArgs());
923 if (S->hasExplicitTemplateArgs())
924 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
927 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
931 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
932 const CXXUnresolvedConstructExpr *S) {
934 VisitType(S->getTypeAsWritten());
937 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
938 const CXXDependentScopeMemberExpr *S) {
939 ID.AddBoolean(S->isImplicitAccess());
940 if (!S->isImplicitAccess()) {
942 ID.AddBoolean(S->isArrow());
944 VisitNestedNameSpecifier(S->getQualifier());
945 VisitName(S->getMember());
946 ID.AddBoolean(S->hasExplicitTemplateArgs());
947 if (S->hasExplicitTemplateArgs())
948 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
951 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
952 ID.AddBoolean(S->isImplicitAccess());
953 if (!S->isImplicitAccess()) {
955 ID.AddBoolean(S->isArrow());
957 VisitNestedNameSpecifier(S->getQualifier());
958 VisitName(S->getMemberName());
959 ID.AddBoolean(S->hasExplicitTemplateArgs());
960 if (S->hasExplicitTemplateArgs())
961 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
964 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
968 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
972 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
974 VisitDecl(S->getPack());
977 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
978 const SubstNonTypeTemplateParmPackExpr *S) {
980 VisitDecl(S->getParameterPack());
981 VisitTemplateArgument(S->getArgumentPack());
984 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
985 const SubstNonTypeTemplateParmExpr *E) {
986 // Profile exactly as the replacement expression.
987 Visit(E->getReplacement());
990 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
992 VisitDecl(S->getParameterPack());
993 ID.AddInteger(S->getNumExpansions());
994 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
998 void StmtProfiler::VisitMaterializeTemporaryExpr(
999 const MaterializeTemporaryExpr *S) {
1003 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
1007 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
1011 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
1015 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1019 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1023 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
1025 VisitType(S->getEncodedType());
1028 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
1030 VisitName(S->getSelector());
1033 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
1035 VisitDecl(S->getProtocol());
1038 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
1040 VisitDecl(S->getDecl());
1041 ID.AddBoolean(S->isArrow());
1042 ID.AddBoolean(S->isFreeIvar());
1045 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
1047 if (S->isImplicitProperty()) {
1048 VisitDecl(S->getImplicitPropertyGetter());
1049 VisitDecl(S->getImplicitPropertySetter());
1051 VisitDecl(S->getExplicitProperty());
1053 if (S->isSuperReceiver()) {
1054 ID.AddBoolean(S->isSuperReceiver());
1055 VisitType(S->getSuperReceiverType());
1059 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1061 VisitDecl(S->getAtIndexMethodDecl());
1062 VisitDecl(S->setAtIndexMethodDecl());
1065 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
1067 VisitName(S->getSelector());
1068 VisitDecl(S->getMethodDecl());
1071 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
1073 ID.AddBoolean(S->isArrow());
1076 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1078 ID.AddBoolean(S->getValue());
1081 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1082 const ObjCIndirectCopyRestoreExpr *S) {
1084 ID.AddBoolean(S->shouldCopy());
1087 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
1088 VisitExplicitCastExpr(S);
1089 ID.AddBoolean(S->getBridgeKind());
1092 void StmtProfiler::VisitDecl(const Decl *D) {
1093 ID.AddInteger(D? D->getKind() : 0);
1095 if (Canonical && D) {
1096 if (const NonTypeTemplateParmDecl *NTTP =
1097 dyn_cast<NonTypeTemplateParmDecl>(D)) {
1098 ID.AddInteger(NTTP->getDepth());
1099 ID.AddInteger(NTTP->getIndex());
1100 ID.AddBoolean(NTTP->isParameterPack());
1101 VisitType(NTTP->getType());
1105 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
1106 // The Itanium C++ ABI uses the type, scope depth, and scope
1107 // index of a parameter when mangling expressions that involve
1108 // function parameters, so we will use the parameter's type for
1109 // establishing function parameter identity. That way, our
1110 // definition of "equivalent" (per C++ [temp.over.link]) is at
1111 // least as strong as the definition of "equivalent" used for
1113 VisitType(Parm->getType());
1114 ID.AddInteger(Parm->getFunctionScopeDepth());
1115 ID.AddInteger(Parm->getFunctionScopeIndex());
1119 if (const TemplateTypeParmDecl *TTP =
1120 dyn_cast<TemplateTypeParmDecl>(D)) {
1121 ID.AddInteger(TTP->getDepth());
1122 ID.AddInteger(TTP->getIndex());
1123 ID.AddBoolean(TTP->isParameterPack());
1127 if (const TemplateTemplateParmDecl *TTP =
1128 dyn_cast<TemplateTemplateParmDecl>(D)) {
1129 ID.AddInteger(TTP->getDepth());
1130 ID.AddInteger(TTP->getIndex());
1131 ID.AddBoolean(TTP->isParameterPack());
1136 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1139 void StmtProfiler::VisitType(QualType T) {
1141 T = Context.getCanonicalType(T);
1143 ID.AddPointer(T.getAsOpaquePtr());
1146 void StmtProfiler::VisitName(DeclarationName Name) {
1147 ID.AddPointer(Name.getAsOpaquePtr());
1150 void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1152 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1156 void StmtProfiler::VisitTemplateName(TemplateName Name) {
1158 Name = Context.getCanonicalTemplateName(Name);
1163 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
1165 ID.AddInteger(NumArgs);
1166 for (unsigned I = 0; I != NumArgs; ++I)
1167 VisitTemplateArgument(Args[I].getArgument());
1170 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1171 // Mostly repetitive with TemplateArgument::Profile!
1172 ID.AddInteger(Arg.getKind());
1173 switch (Arg.getKind()) {
1174 case TemplateArgument::Null:
1177 case TemplateArgument::Type:
1178 VisitType(Arg.getAsType());
1181 case TemplateArgument::Template:
1182 case TemplateArgument::TemplateExpansion:
1183 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
1186 case TemplateArgument::Declaration:
1187 VisitDecl(Arg.getAsDecl());
1190 case TemplateArgument::NullPtr:
1191 VisitType(Arg.getNullPtrType());
1194 case TemplateArgument::Integral:
1195 Arg.getAsIntegral().Profile(ID);
1196 VisitType(Arg.getIntegralType());
1199 case TemplateArgument::Expression:
1200 Visit(Arg.getAsExpr());
1203 case TemplateArgument::Pack:
1204 const TemplateArgument *Pack = Arg.pack_begin();
1205 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1206 VisitTemplateArgument(Pack[i]);
1211 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1212 bool Canonical) const {
1213 StmtProfiler Profiler(ID, Context, Canonical);
1214 Profiler.Visit(this);