blob: d996925906283ca071d2bf4c3db1ccc0c98ba1c9 [file] [log] [blame]
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001//===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt::Profile method, which builds a unique bit
Douglas Gregor00aa3a62009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor41ef0c32009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregor071f4eb2009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000017#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"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000023using namespace clang;
24
25namespace {
Chandler Carruthb1138242011-06-16 06:47:06 +000026 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Douglas Gregor41ef0c32009-07-28 00:33:38 +000027 llvm::FoldingSetNodeID &ID;
Jay Foad4ba2a172011-01-12 09:06:06 +000028 const ASTContext &Context;
Douglas Gregor41ef0c32009-07-28 00:33:38 +000029 bool Canonical;
Mike Stump1eb44332009-09-09 15:08:12 +000030
Douglas Gregor41ef0c32009-07-28 00:33:38 +000031 public:
Jay Foad4ba2a172011-01-12 09:06:06 +000032 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump1eb44332009-09-09 15:08:12 +000033 bool Canonical)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000034 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump1eb44332009-09-09 15:08:12 +000035
Chandler Carruthb1138242011-06-16 06:47:06 +000036 void VisitStmt(const Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +000037
Chandler Carruthb1138242011-06-16 06:47:06 +000038#define STMT(Node, Base) void Visit##Node(const Node *S);
Sean Hunt4bfe1962010-05-05 15:24:00 +000039#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +000040
Douglas Gregor41ef0c32009-07-28 00:33:38 +000041 /// \brief Visit a declaration that is referenced within an expression
42 /// or statement.
Chandler Carruthb1138242011-06-16 06:47:06 +000043 void VisitDecl(const Decl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000044
45 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor41ef0c32009-07-28 00:33:38 +000046 /// statement.
47 void VisitType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +000048
Douglas Gregor41ef0c32009-07-28 00:33:38 +000049 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000051
Douglas Gregor41ef0c32009-07-28 00:33:38 +000052 /// \brief Visit a nested-name-specifier that occurs within an expression
53 /// or statement.
54 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump1eb44332009-09-09 15:08:12 +000055
Douglas Gregor41ef0c32009-07-28 00:33:38 +000056 /// \brief Visit a template name that occurs within an expression or
57 /// statement.
58 void VisitTemplateName(TemplateName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000059
Douglas Gregor41ef0c32009-07-28 00:33:38 +000060 /// \brief Visit template arguments that occur within an expression or
61 /// statement.
Chandler Carruthb1138242011-06-16 06:47:06 +000062 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
63 unsigned NumArgs);
John McCall833ca992009-10-29 08:12:44 +000064
65 /// \brief Visit a single template argument.
66 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor41ef0c32009-07-28 00:33:38 +000067 };
68}
69
Chandler Carruthb1138242011-06-16 06:47:06 +000070void StmtProfiler::VisitStmt(const Stmt *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +000071 ID.AddInteger(S->getStmtClass());
Peter Collingbournedca17612012-03-01 16:34:31 +000072 for (Stmt::const_child_range C = S->children(); C; ++C) {
73 if (*C)
74 Visit(*C);
75 else
76 ID.AddInteger(0);
77 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +000078}
79
Chandler Carruthb1138242011-06-16 06:47:06 +000080void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000081 VisitStmt(S);
Chandler Carruthb1138242011-06-16 06:47:06 +000082 for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000083 D != DEnd; ++D)
84 VisitDecl(*D);
85}
86
Chandler Carruthb1138242011-06-16 06:47:06 +000087void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000088 VisitStmt(S);
89}
90
Chandler Carruthb1138242011-06-16 06:47:06 +000091void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000092 VisitStmt(S);
93}
94
Chandler Carruthb1138242011-06-16 06:47:06 +000095void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000096 VisitStmt(S);
97}
98
Chandler Carruthb1138242011-06-16 06:47:06 +000099void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000100 VisitStmt(S);
101}
102
Chandler Carruthb1138242011-06-16 06:47:06 +0000103void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000104 VisitStmt(S);
105}
106
Chandler Carruthb1138242011-06-16 06:47:06 +0000107void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000108 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000109 VisitDecl(S->getDecl());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000110}
111
Chandler Carruthb1138242011-06-16 06:47:06 +0000112void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000113 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000114 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000115}
116
Chandler Carruthb1138242011-06-16 06:47:06 +0000117void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000118 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000119 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000120}
121
Chandler Carruthb1138242011-06-16 06:47:06 +0000122void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000123 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000124 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000125}
126
Chandler Carruthb1138242011-06-16 06:47:06 +0000127void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000128 VisitStmt(S);
129}
130
Chandler Carruthb1138242011-06-16 06:47:06 +0000131void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000132 VisitStmt(S);
133}
134
Chandler Carruthb1138242011-06-16 06:47:06 +0000135void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000136 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000137 VisitDecl(S->getLabel());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000138}
139
Chandler Carruthb1138242011-06-16 06:47:06 +0000140void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000141 VisitStmt(S);
142}
143
Chandler Carruthb1138242011-06-16 06:47:06 +0000144void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000145 VisitStmt(S);
146}
147
Chandler Carruthb1138242011-06-16 06:47:06 +0000148void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000149 VisitStmt(S);
150}
151
Chandler Carruthb1138242011-06-16 06:47:06 +0000152void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000153 VisitStmt(S);
154}
155
Chandler Carruthb1138242011-06-16 06:47:06 +0000156void StmtProfiler::VisitAsmStmt(const AsmStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000157 VisitStmt(S);
158 ID.AddBoolean(S->isVolatile());
159 ID.AddBoolean(S->isSimple());
160 VisitStringLiteral(S->getAsmString());
161 ID.AddInteger(S->getNumOutputs());
162 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
163 ID.AddString(S->getOutputName(I));
164 VisitStringLiteral(S->getOutputConstraintLiteral(I));
165 }
166 ID.AddInteger(S->getNumInputs());
167 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
168 ID.AddString(S->getInputName(I));
169 VisitStringLiteral(S->getInputConstraintLiteral(I));
170 }
171 ID.AddInteger(S->getNumClobbers());
172 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
173 VisitStringLiteral(S->getClobber(I));
174}
175
Chandler Carruthb1138242011-06-16 06:47:06 +0000176void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000177 VisitStmt(S);
178 VisitType(S->getCaughtType());
179}
180
Chandler Carruthb1138242011-06-16 06:47:06 +0000181void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000182 VisitStmt(S);
183}
184
Chandler Carruthb1138242011-06-16 06:47:06 +0000185void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smithad762fc2011-04-14 22:09:26 +0000186 VisitStmt(S);
187}
188
Douglas Gregorba0513d2011-10-25 01:33:02 +0000189void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
190 VisitStmt(S);
191 ID.AddBoolean(S->isIfExists());
192 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
193 VisitName(S->getNameInfo().getName());
194}
195
Chandler Carruthb1138242011-06-16 06:47:06 +0000196void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000197 VisitStmt(S);
198}
199
Chandler Carruthb1138242011-06-16 06:47:06 +0000200void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000201 VisitStmt(S);
202}
203
Chandler Carruthb1138242011-06-16 06:47:06 +0000204void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000205 VisitStmt(S);
206}
207
Chandler Carruthb1138242011-06-16 06:47:06 +0000208void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000209 VisitStmt(S);
210}
211
Chandler Carruthb1138242011-06-16 06:47:06 +0000212void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000213 VisitStmt(S);
214 ID.AddBoolean(S->hasEllipsis());
215 if (S->getCatchParamDecl())
216 VisitType(S->getCatchParamDecl()->getType());
217}
218
Chandler Carruthb1138242011-06-16 06:47:06 +0000219void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000220 VisitStmt(S);
221}
222
Chandler Carruthb1138242011-06-16 06:47:06 +0000223void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000224 VisitStmt(S);
225}
226
Chandler Carruthb1138242011-06-16 06:47:06 +0000227void
228StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000229 VisitStmt(S);
230}
231
Chandler Carruthb1138242011-06-16 06:47:06 +0000232void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000233 VisitStmt(S);
234}
235
Chandler Carruthb1138242011-06-16 06:47:06 +0000236void
237StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCallf85e1932011-06-15 23:02:42 +0000238 VisitStmt(S);
239}
240
Chandler Carruthb1138242011-06-16 06:47:06 +0000241void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000242 VisitStmt(S);
243}
244
Chandler Carruthb1138242011-06-16 06:47:06 +0000245void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000246 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000247 if (!Canonical)
248 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000249 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000250 if (!Canonical)
251 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000252}
253
Chandler Carruthb1138242011-06-16 06:47:06 +0000254void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000255 VisitExpr(S);
256 ID.AddInteger(S->getIdentType());
257}
258
Chandler Carruthb1138242011-06-16 06:47:06 +0000259void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000260 VisitExpr(S);
261 S->getValue().Profile(ID);
262}
263
Chandler Carruthb1138242011-06-16 06:47:06 +0000264void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000265 VisitExpr(S);
Douglas Gregor5cee1192011-07-27 05:40:30 +0000266 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000267 ID.AddInteger(S->getValue());
268}
269
Chandler Carruthb1138242011-06-16 06:47:06 +0000270void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000271 VisitExpr(S);
272 S->getValue().Profile(ID);
273 ID.AddBoolean(S->isExact());
274}
275
Chandler Carruthb1138242011-06-16 06:47:06 +0000276void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000277 VisitExpr(S);
278}
279
Chandler Carruthb1138242011-06-16 06:47:06 +0000280void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000281 VisitExpr(S);
Douglas Gregor38738fc2011-11-02 17:26:05 +0000282 ID.AddString(S->getBytes());
Douglas Gregor5cee1192011-07-27 05:40:30 +0000283 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000284}
285
Chandler Carruthb1138242011-06-16 06:47:06 +0000286void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000287 VisitExpr(S);
288}
289
Chandler Carruthb1138242011-06-16 06:47:06 +0000290void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman2ef13e52009-08-10 23:49:36 +0000291 VisitExpr(S);
292}
293
Chandler Carruthb1138242011-06-16 06:47:06 +0000294void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000295 VisitExpr(S);
296 ID.AddInteger(S->getOpcode());
297}
298
Chandler Carruthb1138242011-06-16 06:47:06 +0000299void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000300 VisitType(S->getTypeSourceInfo()->getType());
301 unsigned n = S->getNumComponents();
302 for (unsigned i = 0; i < n; ++i) {
303 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
304 ID.AddInteger(ON.getKind());
305 switch (ON.getKind()) {
306 case OffsetOfExpr::OffsetOfNode::Array:
307 // Expressions handled below.
308 break;
309
310 case OffsetOfExpr::OffsetOfNode::Field:
311 VisitDecl(ON.getField());
312 break;
313
314 case OffsetOfExpr::OffsetOfNode::Identifier:
315 ID.AddPointer(ON.getFieldName());
316 break;
Sean Huntc3021132010-05-05 15:23:54 +0000317
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000318 case OffsetOfExpr::OffsetOfNode::Base:
319 // These nodes are implicit, and therefore don't need profiling.
320 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000321 }
322 }
Sean Huntc3021132010-05-05 15:23:54 +0000323
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000324 VisitExpr(S);
325}
326
Chandler Carruthb1138242011-06-16 06:47:06 +0000327void
328StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000329 VisitExpr(S);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000330 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000331 if (S->isArgumentType())
332 VisitType(S->getArgumentType());
333}
334
Chandler Carruthb1138242011-06-16 06:47:06 +0000335void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000336 VisitExpr(S);
337}
338
Chandler Carruthb1138242011-06-16 06:47:06 +0000339void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000340 VisitExpr(S);
341}
342
Chandler Carruthb1138242011-06-16 06:47:06 +0000343void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000344 VisitExpr(S);
345 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000346 if (!Canonical)
347 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000348 ID.AddBoolean(S->isArrow());
349}
350
Chandler Carruthb1138242011-06-16 06:47:06 +0000351void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000352 VisitExpr(S);
353 ID.AddBoolean(S->isFileScope());
354}
355
Chandler Carruthb1138242011-06-16 06:47:06 +0000356void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000357 VisitExpr(S);
358}
359
Chandler Carruthb1138242011-06-16 06:47:06 +0000360void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000361 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000362 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000363}
364
Chandler Carruthb1138242011-06-16 06:47:06 +0000365void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000366 VisitCastExpr(S);
367 VisitType(S->getTypeAsWritten());
368}
369
Chandler Carruthb1138242011-06-16 06:47:06 +0000370void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000371 VisitExplicitCastExpr(S);
372}
373
Chandler Carruthb1138242011-06-16 06:47:06 +0000374void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000375 VisitExpr(S);
376 ID.AddInteger(S->getOpcode());
377}
378
Chandler Carruthb1138242011-06-16 06:47:06 +0000379void
380StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000381 VisitBinaryOperator(S);
382}
383
Chandler Carruthb1138242011-06-16 06:47:06 +0000384void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000385 VisitExpr(S);
386}
387
Chandler Carruthb1138242011-06-16 06:47:06 +0000388void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruth08949762011-06-21 23:26:32 +0000389 const BinaryConditionalOperator *S) {
John McCall56ca35d2011-02-17 10:25:35 +0000390 VisitExpr(S);
391}
392
Chandler Carruthb1138242011-06-16 06:47:06 +0000393void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000394 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000395 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000396}
397
Chandler Carruthb1138242011-06-16 06:47:06 +0000398void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000399 VisitExpr(S);
400}
401
Chandler Carruthb1138242011-06-16 06:47:06 +0000402void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000403 VisitExpr(S);
404}
405
Chandler Carruthb1138242011-06-16 06:47:06 +0000406void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000407 VisitExpr(S);
408}
409
Chandler Carruthb1138242011-06-16 06:47:06 +0000410void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000411 VisitExpr(S);
412}
413
Chandler Carruthb1138242011-06-16 06:47:06 +0000414void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000415 VisitExpr(S);
416}
417
Chandler Carruthb1138242011-06-16 06:47:06 +0000418void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000419 if (S->getSyntacticForm()) {
420 VisitInitListExpr(S->getSyntacticForm());
421 return;
422 }
Mike Stump1eb44332009-09-09 15:08:12 +0000423
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000424 VisitExpr(S);
425}
426
Chandler Carruthb1138242011-06-16 06:47:06 +0000427void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000428 VisitExpr(S);
429 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruthb1138242011-06-16 06:47:06 +0000430 for (DesignatedInitExpr::const_designators_iterator D =
431 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000432 D != DEnd; ++D) {
433 if (D->isFieldDesignator()) {
434 ID.AddInteger(0);
435 VisitName(D->getFieldName());
436 continue;
437 }
Mike Stump1eb44332009-09-09 15:08:12 +0000438
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000439 if (D->isArrayDesignator()) {
440 ID.AddInteger(1);
441 } else {
442 assert(D->isArrayRangeDesignator());
443 ID.AddInteger(2);
444 }
445 ID.AddInteger(D->getFirstExprIndex());
446 }
447}
448
Chandler Carruthb1138242011-06-16 06:47:06 +0000449void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000450 VisitExpr(S);
451}
452
Chandler Carruthb1138242011-06-16 06:47:06 +0000453void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000454 VisitExpr(S);
455 VisitName(&S->getAccessor());
456}
457
Chandler Carruthb1138242011-06-16 06:47:06 +0000458void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000459 VisitExpr(S);
460 VisitDecl(S->getBlockDecl());
461}
462
Chandler Carruthb1138242011-06-16 06:47:06 +0000463void StmtProfiler::VisitBlockDeclRefExpr(const BlockDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000464 VisitExpr(S);
465 VisitDecl(S->getDecl());
466 ID.AddBoolean(S->isByRef());
467 ID.AddBoolean(S->isConstQualAdded());
468}
469
Chandler Carruthb1138242011-06-16 06:47:06 +0000470void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbournef111d932011-04-15 00:35:48 +0000471 VisitExpr(S);
472 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
473 QualType T = S->getAssocType(i);
474 if (T.isNull())
475 ID.AddPointer(0);
476 else
477 VisitType(T);
478 VisitExpr(S->getAssocExpr(i));
479 }
480}
481
John McCall4b9c2d22011-11-06 09:01:30 +0000482void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
483 VisitExpr(S);
484 for (PseudoObjectExpr::const_semantics_iterator
485 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
486 // Normally, we would not profile the source expressions of OVEs.
487 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
488 Visit(OVE->getSourceExpr());
489}
490
Eli Friedman276b0612011-10-11 02:20:01 +0000491void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
492 VisitExpr(S);
Eli Friedman2be46072011-10-14 20:59:01 +0000493 ID.AddInteger(S->getOp());
Eli Friedman276b0612011-10-11 02:20:01 +0000494}
495
Chandler Carruthb1138242011-06-16 06:47:06 +0000496static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000497 UnaryOperatorKind &UnaryOp,
498 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000499 switch (S->getOperator()) {
500 case OO_None:
501 case OO_New:
502 case OO_Delete:
503 case OO_Array_New:
504 case OO_Array_Delete:
505 case OO_Arrow:
506 case OO_Call:
507 case OO_Conditional:
508 case NUM_OVERLOADED_OPERATORS:
509 llvm_unreachable("Invalid operator call kind");
Douglas Gregora89064a2010-05-19 04:13:23 +0000510
511 case OO_Plus:
512 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000513 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000514 return Stmt::UnaryOperatorClass;
515 }
516
John McCall2de56d12010-08-25 11:45:40 +0000517 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000518 return Stmt::BinaryOperatorClass;
519
520 case OO_Minus:
521 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000522 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000523 return Stmt::UnaryOperatorClass;
524 }
525
John McCall2de56d12010-08-25 11:45:40 +0000526 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000527 return Stmt::BinaryOperatorClass;
528
529 case OO_Star:
530 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000531 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000532 return Stmt::UnaryOperatorClass;
533 }
534
John McCall2de56d12010-08-25 11:45:40 +0000535 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000536 return Stmt::BinaryOperatorClass;
537
538 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000539 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000540 return Stmt::BinaryOperatorClass;
541
542 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000543 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000544 return Stmt::BinaryOperatorClass;
545
546 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000547 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000548 return Stmt::BinaryOperatorClass;
549
550 case OO_Amp:
551 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000552 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000553 return Stmt::UnaryOperatorClass;
554 }
555
John McCall2de56d12010-08-25 11:45:40 +0000556 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000557 return Stmt::BinaryOperatorClass;
558
559 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000560 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000561 return Stmt::BinaryOperatorClass;
562
563 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000564 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000565 return Stmt::UnaryOperatorClass;
566
567 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000568 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000569 return Stmt::UnaryOperatorClass;
570
571 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000572 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000573 return Stmt::BinaryOperatorClass;
574
575 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000576 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000577 return Stmt::BinaryOperatorClass;
578
579 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000580 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000581 return Stmt::BinaryOperatorClass;
582
583 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000584 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000585 return Stmt::CompoundAssignOperatorClass;
586
587 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000588 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000589 return Stmt::CompoundAssignOperatorClass;
590
591 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000592 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000593 return Stmt::CompoundAssignOperatorClass;
594
595 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000596 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000597 return Stmt::CompoundAssignOperatorClass;
598
599 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000600 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000601 return Stmt::CompoundAssignOperatorClass;
602
603 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000604 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000605 return Stmt::CompoundAssignOperatorClass;
606
607 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000608 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000609 return Stmt::CompoundAssignOperatorClass;
610
611 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000612 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000613 return Stmt::CompoundAssignOperatorClass;
614
615 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000616 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000617 return Stmt::BinaryOperatorClass;
618
619 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000620 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000621 return Stmt::BinaryOperatorClass;
622
623 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000624 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000625 return Stmt::CompoundAssignOperatorClass;
626
627 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000628 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000629 return Stmt::CompoundAssignOperatorClass;
630
631 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000632 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000633 return Stmt::BinaryOperatorClass;
634
635 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000636 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000637 return Stmt::BinaryOperatorClass;
638
639 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000640 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000641 return Stmt::BinaryOperatorClass;
642
643 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000644 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000645 return Stmt::BinaryOperatorClass;
646
647 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000648 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000649 return Stmt::BinaryOperatorClass;
650
651 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000652 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000653 return Stmt::BinaryOperatorClass;
654
655 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000656 UnaryOp = S->getNumArgs() == 1? UO_PreInc
657 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000658 return Stmt::UnaryOperatorClass;
659
660 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000661 UnaryOp = S->getNumArgs() == 1? UO_PreDec
662 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000663 return Stmt::UnaryOperatorClass;
664
665 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000666 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000667 return Stmt::BinaryOperatorClass;
668
669
670 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000671 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000672 return Stmt::BinaryOperatorClass;
673
674 case OO_Subscript:
675 return Stmt::ArraySubscriptExprClass;
676 }
677
678 llvm_unreachable("Invalid overloaded operator expression");
679}
680
681
Chandler Carruthb1138242011-06-16 06:47:06 +0000682void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000683 if (S->isTypeDependent()) {
684 // Type-dependent operator calls are profiled like their underlying
685 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000686 UnaryOperatorKind UnaryOp = UO_Extension;
687 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000688 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
689
690 ID.AddInteger(SC);
691 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
692 Visit(S->getArg(I));
693 if (SC == Stmt::UnaryOperatorClass)
694 ID.AddInteger(UnaryOp);
695 else if (SC == Stmt::BinaryOperatorClass ||
696 SC == Stmt::CompoundAssignOperatorClass)
697 ID.AddInteger(BinaryOp);
698 else
699 assert(SC == Stmt::ArraySubscriptExprClass);
700
701 return;
702 }
703
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000704 VisitCallExpr(S);
705 ID.AddInteger(S->getOperator());
706}
707
Chandler Carruthb1138242011-06-16 06:47:06 +0000708void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000709 VisitCallExpr(S);
710}
711
Chandler Carruthb1138242011-06-16 06:47:06 +0000712void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbournee08ce652011-02-09 21:07:24 +0000713 VisitCallExpr(S);
714}
715
Chandler Carruthb1138242011-06-16 06:47:06 +0000716void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner61eee0c2011-06-04 00:47:47 +0000717 VisitExpr(S);
718}
719
Chandler Carruthb1138242011-06-16 06:47:06 +0000720void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000721 VisitExplicitCastExpr(S);
722}
723
Chandler Carruthb1138242011-06-16 06:47:06 +0000724void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000725 VisitCXXNamedCastExpr(S);
726}
727
Chandler Carruthb1138242011-06-16 06:47:06 +0000728void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000729 VisitCXXNamedCastExpr(S);
730}
731
Chandler Carruthb1138242011-06-16 06:47:06 +0000732void
733StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000734 VisitCXXNamedCastExpr(S);
735}
736
Chandler Carruthb1138242011-06-16 06:47:06 +0000737void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000738 VisitCXXNamedCastExpr(S);
739}
740
Chandler Carruthb1138242011-06-16 06:47:06 +0000741void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000742 VisitExpr(S);
743 ID.AddBoolean(S->getValue());
744}
745
Chandler Carruthb1138242011-06-16 06:47:06 +0000746void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000747 VisitExpr(S);
748}
749
Chandler Carruthb1138242011-06-16 06:47:06 +0000750void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000751 VisitExpr(S);
752 if (S->isTypeOperand())
753 VisitType(S->getTypeOperand());
754}
755
Chandler Carruthb1138242011-06-16 06:47:06 +0000756void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet01b7c302010-09-08 12:20:18 +0000757 VisitExpr(S);
758 if (S->isTypeOperand())
759 VisitType(S->getTypeOperand());
760}
761
Chandler Carruthb1138242011-06-16 06:47:06 +0000762void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000763 VisitExpr(S);
764}
765
Chandler Carruthb1138242011-06-16 06:47:06 +0000766void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000767 VisitExpr(S);
768}
769
Chandler Carruthb1138242011-06-16 06:47:06 +0000770void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000771 VisitExpr(S);
772 VisitDecl(S->getParam());
773}
774
Chandler Carruthb1138242011-06-16 06:47:06 +0000775void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000776 VisitExpr(S);
777 VisitDecl(
778 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
779}
780
Chandler Carruthb1138242011-06-16 06:47:06 +0000781void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000782 VisitExpr(S);
783 VisitDecl(S->getConstructor());
784 ID.AddBoolean(S->isElidable());
785}
786
Chandler Carruthb1138242011-06-16 06:47:06 +0000787void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000788 VisitExplicitCastExpr(S);
789}
790
Chandler Carruthb1138242011-06-16 06:47:06 +0000791void
792StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000793 VisitCXXConstructExpr(S);
794}
795
Chandler Carruthb1138242011-06-16 06:47:06 +0000796void
Douglas Gregor01d08012012-02-07 10:09:13 +0000797StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
798 VisitExpr(S);
799 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
800 CEnd = S->explicit_capture_end();
801 C != CEnd; ++C) {
802 ID.AddInteger(C->getCaptureKind());
803 if (C->capturesVariable()) {
804 VisitDecl(C->getCapturedVar());
805 ID.AddBoolean(C->isPackExpansion());
806 }
807 }
808 // Note: If we actually needed to be able to match lambda
809 // expressions, we would have to consider parameters and return type
810 // here, among other things.
811 VisitStmt(S->getBody());
812}
813
814void
Chandler Carruthb1138242011-06-16 06:47:06 +0000815StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000816 VisitExpr(S);
817}
818
Chandler Carruthb1138242011-06-16 06:47:06 +0000819void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000820 VisitExpr(S);
821 ID.AddBoolean(S->isGlobalDelete());
822 ID.AddBoolean(S->isArrayForm());
823 VisitDecl(S->getOperatorDelete());
824}
825
826
Chandler Carruthb1138242011-06-16 06:47:06 +0000827void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000828 VisitExpr(S);
829 VisitType(S->getAllocatedType());
830 VisitDecl(S->getOperatorNew());
831 VisitDecl(S->getOperatorDelete());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000832 ID.AddBoolean(S->isArray());
833 ID.AddInteger(S->getNumPlacementArgs());
834 ID.AddBoolean(S->isGlobalNew());
835 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000836 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000837}
838
Chandler Carruthb1138242011-06-16 06:47:06 +0000839void
840StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregora71d8192009-09-04 17:36:40 +0000841 VisitExpr(S);
842 ID.AddBoolean(S->isArrow());
843 VisitNestedNameSpecifier(S->getQualifier());
844 VisitType(S->getDestroyedType());
845}
846
Chandler Carruthb1138242011-06-16 06:47:06 +0000847void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000848 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000849 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000850 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000851 ID.AddBoolean(S->hasExplicitTemplateArgs());
852 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000853 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
854 S->getExplicitTemplateArgs().NumTemplateArgs);
855}
856
857void
Chandler Carruthb1138242011-06-16 06:47:06 +0000858StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000859 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000860}
861
Chandler Carruthb1138242011-06-16 06:47:06 +0000862void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000863 VisitExpr(S);
864 ID.AddInteger(S->getTrait());
865 VisitType(S->getQueriedType());
866}
867
Chandler Carruthb1138242011-06-16 06:47:06 +0000868void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
Francois Pichet6ad6f282010-12-07 00:08:36 +0000869 VisitExpr(S);
870 ID.AddInteger(S->getTrait());
871 VisitType(S->getLhsType());
872 VisitType(S->getRhsType());
873}
874
Douglas Gregor4ca8ac22012-02-24 07:38:34 +0000875void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
876 VisitExpr(S);
877 ID.AddInteger(S->getTrait());
878 ID.AddInteger(S->getNumArgs());
879 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
880 VisitType(S->getArg(I)->getType());
881}
882
Chandler Carruthb1138242011-06-16 06:47:06 +0000883void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley21ff2e52011-04-28 00:16:57 +0000884 VisitExpr(S);
885 ID.AddInteger(S->getTrait());
886 VisitType(S->getQueriedType());
887}
888
Chandler Carruthb1138242011-06-16 06:47:06 +0000889void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegley55262202011-04-25 06:54:41 +0000890 VisitExpr(S);
891 ID.AddInteger(S->getTrait());
892 VisitExpr(S->getQueriedExpression());
893}
894
Chandler Carruthb1138242011-06-16 06:47:06 +0000895void StmtProfiler::VisitDependentScopeDeclRefExpr(
896 const DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000897 VisitExpr(S);
898 VisitName(S->getDeclName());
899 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000900 ID.AddBoolean(S->hasExplicitTemplateArgs());
901 if (S->hasExplicitTemplateArgs())
902 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000903}
904
Chandler Carruthb1138242011-06-16 06:47:06 +0000905void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000906 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000907}
908
Chandler Carruthb1138242011-06-16 06:47:06 +0000909void StmtProfiler::VisitCXXUnresolvedConstructExpr(
910 const CXXUnresolvedConstructExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000911 VisitExpr(S);
912 VisitType(S->getTypeAsWritten());
913}
914
Chandler Carruthb1138242011-06-16 06:47:06 +0000915void StmtProfiler::VisitCXXDependentScopeMemberExpr(
916 const CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000917 ID.AddBoolean(S->isImplicitAccess());
918 if (!S->isImplicitAccess()) {
919 VisitExpr(S);
920 ID.AddBoolean(S->isArrow());
921 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000922 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000923 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000924 ID.AddBoolean(S->hasExplicitTemplateArgs());
925 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000926 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
927}
928
Chandler Carruthb1138242011-06-16 06:47:06 +0000929void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000930 ID.AddBoolean(S->isImplicitAccess());
931 if (!S->isImplicitAccess()) {
932 VisitExpr(S);
933 ID.AddBoolean(S->isArrow());
934 }
John McCall129e2df2009-11-30 22:42:35 +0000935 VisitNestedNameSpecifier(S->getQualifier());
936 VisitName(S->getMemberName());
937 ID.AddBoolean(S->hasExplicitTemplateArgs());
938 if (S->hasExplicitTemplateArgs())
939 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000940}
941
Chandler Carruthb1138242011-06-16 06:47:06 +0000942void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl2e156222010-09-10 20:55:43 +0000943 VisitExpr(S);
944}
945
Chandler Carruthb1138242011-06-16 06:47:06 +0000946void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregorbe230c32011-01-03 17:17:50 +0000947 VisitExpr(S);
948}
949
Chandler Carruthb1138242011-06-16 06:47:06 +0000950void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregoree8aff02011-01-04 17:33:58 +0000951 VisitExpr(S);
952 VisitDecl(S->getPack());
953}
954
Douglas Gregorc7793c72011-01-15 01:15:58 +0000955void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruthb1138242011-06-16 06:47:06 +0000956 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorc7793c72011-01-15 01:15:58 +0000957 VisitExpr(S);
958 VisitDecl(S->getParameterPack());
959 VisitTemplateArgument(S->getArgumentPack());
960}
961
John McCall91a57552011-07-15 05:09:51 +0000962void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
963 const SubstNonTypeTemplateParmExpr *E) {
964 // Profile exactly as the replacement expression.
965 Visit(E->getReplacement());
966}
967
Douglas Gregor03e80032011-06-21 17:03:29 +0000968void StmtProfiler::VisitMaterializeTemporaryExpr(
969 const MaterializeTemporaryExpr *S) {
970 VisitExpr(S);
971}
972
Chandler Carruthb1138242011-06-16 06:47:06 +0000973void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall7cd7d1a2010-11-15 23:31:06 +0000974 VisitExpr(E);
975}
976
Chandler Carruthb1138242011-06-16 06:47:06 +0000977void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000978 VisitExpr(S);
979}
980
Chandler Carruthb1138242011-06-16 06:47:06 +0000981void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000982 VisitExpr(S);
983 VisitType(S->getEncodedType());
984}
985
Chandler Carruthb1138242011-06-16 06:47:06 +0000986void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000987 VisitExpr(S);
988 VisitName(S->getSelector());
989}
990
Chandler Carruthb1138242011-06-16 06:47:06 +0000991void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000992 VisitExpr(S);
993 VisitDecl(S->getProtocol());
994}
995
Chandler Carruthb1138242011-06-16 06:47:06 +0000996void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000997 VisitExpr(S);
998 VisitDecl(S->getDecl());
999 ID.AddBoolean(S->isArrow());
1000 ID.AddBoolean(S->isFreeIvar());
1001}
1002
Chandler Carruthb1138242011-06-16 06:47:06 +00001003void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001004 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +00001005 if (S->isImplicitProperty()) {
1006 VisitDecl(S->getImplicitPropertyGetter());
1007 VisitDecl(S->getImplicitPropertySetter());
1008 } else {
1009 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001010 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001011 if (S->isSuperReceiver()) {
1012 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +00001013 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001014 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001015}
1016
Chandler Carruthb1138242011-06-16 06:47:06 +00001017void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001018 VisitExpr(S);
1019 VisitName(S->getSelector());
1020 VisitDecl(S->getMethodDecl());
1021}
1022
Chandler Carruthb1138242011-06-16 06:47:06 +00001023void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001024 VisitExpr(S);
1025 ID.AddBoolean(S->isArrow());
1026}
1027
Chandler Carruthb1138242011-06-16 06:47:06 +00001028void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1029 const ObjCIndirectCopyRestoreExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +00001030 VisitExpr(S);
1031 ID.AddBoolean(S->shouldCopy());
1032}
1033
Chandler Carruthb1138242011-06-16 06:47:06 +00001034void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +00001035 VisitExplicitCastExpr(S);
1036 ID.AddBoolean(S->getBridgeKind());
1037}
1038
Chandler Carruthb1138242011-06-16 06:47:06 +00001039void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001040 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +00001041
Douglas Gregorb1975722009-07-30 23:18:24 +00001042 if (Canonical && D) {
Chandler Carruthb1138242011-06-16 06:47:06 +00001043 if (const NonTypeTemplateParmDecl *NTTP =
1044 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +00001045 ID.AddInteger(NTTP->getDepth());
1046 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +00001047 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +00001048 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001049 return;
1050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Chandler Carruthb1138242011-06-16 06:47:06 +00001052 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCallfb44de92011-05-01 22:35:37 +00001053 // The Itanium C++ ABI uses the type, scope depth, and scope
1054 // index of a parameter when mangling expressions that involve
1055 // function parameters, so we will use the parameter's type for
1056 // establishing function parameter identity. That way, our
1057 // definition of "equivalent" (per C++ [temp.over.link]) is at
1058 // least as strong as the definition of "equivalent" used for
1059 // name mangling.
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001060 VisitType(Parm->getType());
John McCallfb44de92011-05-01 22:35:37 +00001061 ID.AddInteger(Parm->getFunctionScopeDepth());
1062 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001063 return;
1064 }
Mike Stump1eb44332009-09-09 15:08:12 +00001065
Chandler Carruthb1138242011-06-16 06:47:06 +00001066 if (const TemplateTemplateParmDecl *TTP =
1067 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregora2ffb982009-07-31 15:46:56 +00001068 ID.AddInteger(TTP->getDepth());
1069 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +00001070 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +00001071 return;
1072 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregord584eb22009-07-28 15:32:17 +00001075 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1076}
1077
1078void StmtProfiler::VisitType(QualType T) {
1079 if (Canonical)
1080 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001082 ID.AddPointer(T.getAsOpaquePtr());
1083}
1084
1085void StmtProfiler::VisitName(DeclarationName Name) {
1086 ID.AddPointer(Name.getAsOpaquePtr());
1087}
1088
1089void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1090 if (Canonical)
1091 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1092 ID.AddPointer(NNS);
1093}
1094
1095void StmtProfiler::VisitTemplateName(TemplateName Name) {
1096 if (Canonical)
1097 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +00001098
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001099 Name.Profile(ID);
1100}
1101
John McCall833ca992009-10-29 08:12:44 +00001102void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001103 unsigned NumArgs) {
1104 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +00001105 for (unsigned I = 0; I != NumArgs; ++I)
1106 VisitTemplateArgument(Args[I].getArgument());
1107}
Mike Stump1eb44332009-09-09 15:08:12 +00001108
John McCall833ca992009-10-29 08:12:44 +00001109void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1110 // Mostly repetitive with TemplateArgument::Profile!
1111 ID.AddInteger(Arg.getKind());
1112 switch (Arg.getKind()) {
1113 case TemplateArgument::Null:
1114 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001115
John McCall833ca992009-10-29 08:12:44 +00001116 case TemplateArgument::Type:
1117 VisitType(Arg.getAsType());
1118 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001119
Douglas Gregor788cd062009-11-11 01:00:40 +00001120 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00001121 case TemplateArgument::TemplateExpansion:
1122 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +00001123 break;
Sean Huntc3021132010-05-05 15:23:54 +00001124
John McCall833ca992009-10-29 08:12:44 +00001125 case TemplateArgument::Declaration:
1126 VisitDecl(Arg.getAsDecl());
1127 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001128
John McCall833ca992009-10-29 08:12:44 +00001129 case TemplateArgument::Integral:
1130 Arg.getAsIntegral()->Profile(ID);
1131 VisitType(Arg.getIntegralType());
1132 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001133
John McCall833ca992009-10-29 08:12:44 +00001134 case TemplateArgument::Expression:
1135 Visit(Arg.getAsExpr());
1136 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001137
John McCall833ca992009-10-29 08:12:44 +00001138 case TemplateArgument::Pack:
1139 const TemplateArgument *Pack = Arg.pack_begin();
1140 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1141 VisitTemplateArgument(Pack[i]);
1142 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001143 }
1144}
1145
Jay Foad4ba2a172011-01-12 09:06:06 +00001146void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruthb1138242011-06-16 06:47:06 +00001147 bool Canonical) const {
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001148 StmtProfiler Profiler(ID, Context, Canonical);
1149 Profiler.Visit(this);
1150}