blob: 8ade242d56d959417217f158e0447a13e2cf7306 [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
Richard Smith534986f2012-04-14 00:33:13 +0000112void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
113 VisitStmt(S);
114 // TODO: maybe visit attributes?
115}
116
Chandler Carruthb1138242011-06-16 06:47:06 +0000117void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000118 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000119 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000120}
121
Chandler Carruthb1138242011-06-16 06:47:06 +0000122void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000123 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000124 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000125}
126
Chandler Carruthb1138242011-06-16 06:47:06 +0000127void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000128 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000129 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000130}
131
Chandler Carruthb1138242011-06-16 06:47:06 +0000132void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000133 VisitStmt(S);
134}
135
Chandler Carruthb1138242011-06-16 06:47:06 +0000136void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000137 VisitStmt(S);
138}
139
Chandler Carruthb1138242011-06-16 06:47:06 +0000140void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000141 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000142 VisitDecl(S->getLabel());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000143}
144
Chandler Carruthb1138242011-06-16 06:47:06 +0000145void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000146 VisitStmt(S);
147}
148
Chandler Carruthb1138242011-06-16 06:47:06 +0000149void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000150 VisitStmt(S);
151}
152
Chandler Carruthb1138242011-06-16 06:47:06 +0000153void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000154 VisitStmt(S);
155}
156
Chandler Carruthb1138242011-06-16 06:47:06 +0000157void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000158 VisitStmt(S);
159}
160
Chad Rosierdf5faf52012-08-25 00:11:56 +0000161void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000162 VisitStmt(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));
170 }
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));
175 }
176 ID.AddInteger(S->getNumClobbers());
177 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +0000178 VisitStringLiteral(S->getClobberStringLiteral(I));
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000179}
180
Chad Rosier8cd64b42012-06-11 20:47:18 +0000181void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
182 // FIXME: Implement MS style inline asm statement profiler.
183 VisitStmt(S);
184}
185
Chandler Carruthb1138242011-06-16 06:47:06 +0000186void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000187 VisitStmt(S);
188 VisitType(S->getCaughtType());
189}
190
Chandler Carruthb1138242011-06-16 06:47:06 +0000191void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000192 VisitStmt(S);
193}
194
Chandler Carruthb1138242011-06-16 06:47:06 +0000195void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smithad762fc2011-04-14 22:09:26 +0000196 VisitStmt(S);
197}
198
Douglas Gregorba0513d2011-10-25 01:33:02 +0000199void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
200 VisitStmt(S);
201 ID.AddBoolean(S->isIfExists());
202 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
203 VisitName(S->getNameInfo().getName());
204}
205
Chandler Carruthb1138242011-06-16 06:47:06 +0000206void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000207 VisitStmt(S);
208}
209
Chandler Carruthb1138242011-06-16 06:47:06 +0000210void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000211 VisitStmt(S);
212}
213
Chandler Carruthb1138242011-06-16 06:47:06 +0000214void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000215 VisitStmt(S);
216}
217
Tareq A. Siraj051303c2013-04-16 18:53:08 +0000218void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
219 VisitStmt(S);
220}
221
Chandler Carruthb1138242011-06-16 06:47:06 +0000222void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000223 VisitStmt(S);
224}
225
Chandler Carruthb1138242011-06-16 06:47:06 +0000226void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000227 VisitStmt(S);
228 ID.AddBoolean(S->hasEllipsis());
229 if (S->getCatchParamDecl())
230 VisitType(S->getCatchParamDecl()->getType());
231}
232
Chandler Carruthb1138242011-06-16 06:47:06 +0000233void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000234 VisitStmt(S);
235}
236
Chandler Carruthb1138242011-06-16 06:47:06 +0000237void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000238 VisitStmt(S);
239}
240
Chandler Carruthb1138242011-06-16 06:47:06 +0000241void
242StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000243 VisitStmt(S);
244}
245
Chandler Carruthb1138242011-06-16 06:47:06 +0000246void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000247 VisitStmt(S);
248}
249
Chandler Carruthb1138242011-06-16 06:47:06 +0000250void
251StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCallf85e1932011-06-15 23:02:42 +0000252 VisitStmt(S);
253}
254
Chandler Carruthb1138242011-06-16 06:47:06 +0000255void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000256 VisitStmt(S);
257}
258
Chandler Carruthb1138242011-06-16 06:47:06 +0000259void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000260 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000261 if (!Canonical)
262 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000263 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000264 if (!Canonical)
265 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000266}
267
Chandler Carruthb1138242011-06-16 06:47:06 +0000268void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000269 VisitExpr(S);
270 ID.AddInteger(S->getIdentType());
271}
272
Chandler Carruthb1138242011-06-16 06:47:06 +0000273void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000274 VisitExpr(S);
275 S->getValue().Profile(ID);
276}
277
Chandler Carruthb1138242011-06-16 06:47:06 +0000278void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000279 VisitExpr(S);
Douglas Gregor5cee1192011-07-27 05:40:30 +0000280 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000281 ID.AddInteger(S->getValue());
282}
283
Chandler Carruthb1138242011-06-16 06:47:06 +0000284void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000285 VisitExpr(S);
286 S->getValue().Profile(ID);
287 ID.AddBoolean(S->isExact());
288}
289
Chandler Carruthb1138242011-06-16 06:47:06 +0000290void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000291 VisitExpr(S);
292}
293
Chandler Carruthb1138242011-06-16 06:47:06 +0000294void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000295 VisitExpr(S);
Douglas Gregor38738fc2011-11-02 17:26:05 +0000296 ID.AddString(S->getBytes());
Douglas Gregor5cee1192011-07-27 05:40:30 +0000297 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000298}
299
Chandler Carruthb1138242011-06-16 06:47:06 +0000300void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000301 VisitExpr(S);
302}
303
Chandler Carruthb1138242011-06-16 06:47:06 +0000304void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman2ef13e52009-08-10 23:49:36 +0000305 VisitExpr(S);
306}
307
Chandler Carruthb1138242011-06-16 06:47:06 +0000308void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000309 VisitExpr(S);
310 ID.AddInteger(S->getOpcode());
311}
312
Chandler Carruthb1138242011-06-16 06:47:06 +0000313void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000314 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.
322 break;
323
324 case OffsetOfExpr::OffsetOfNode::Field:
325 VisitDecl(ON.getField());
326 break;
327
328 case OffsetOfExpr::OffsetOfNode::Identifier:
329 ID.AddPointer(ON.getFieldName());
330 break;
Sean Huntc3021132010-05-05 15:23:54 +0000331
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000332 case OffsetOfExpr::OffsetOfNode::Base:
333 // These nodes are implicit, and therefore don't need profiling.
334 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000335 }
336 }
Sean Huntc3021132010-05-05 15:23:54 +0000337
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000338 VisitExpr(S);
339}
340
Chandler Carruthb1138242011-06-16 06:47:06 +0000341void
342StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000343 VisitExpr(S);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000344 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000345 if (S->isArgumentType())
346 VisitType(S->getArgumentType());
347}
348
Chandler Carruthb1138242011-06-16 06:47:06 +0000349void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000350 VisitExpr(S);
351}
352
Chandler Carruthb1138242011-06-16 06:47:06 +0000353void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000354 VisitExpr(S);
355}
356
Chandler Carruthb1138242011-06-16 06:47:06 +0000357void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000358 VisitExpr(S);
359 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000360 if (!Canonical)
361 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000362 ID.AddBoolean(S->isArrow());
363}
364
Chandler Carruthb1138242011-06-16 06:47:06 +0000365void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000366 VisitExpr(S);
367 ID.AddBoolean(S->isFileScope());
368}
369
Chandler Carruthb1138242011-06-16 06:47:06 +0000370void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000371 VisitExpr(S);
372}
373
Chandler Carruthb1138242011-06-16 06:47:06 +0000374void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000375 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000376 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000377}
378
Chandler Carruthb1138242011-06-16 06:47:06 +0000379void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000380 VisitCastExpr(S);
381 VisitType(S->getTypeAsWritten());
382}
383
Chandler Carruthb1138242011-06-16 06:47:06 +0000384void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000385 VisitExplicitCastExpr(S);
386}
387
Chandler Carruthb1138242011-06-16 06:47:06 +0000388void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000389 VisitExpr(S);
390 ID.AddInteger(S->getOpcode());
391}
392
Chandler Carruthb1138242011-06-16 06:47:06 +0000393void
394StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000395 VisitBinaryOperator(S);
396}
397
Chandler Carruthb1138242011-06-16 06:47:06 +0000398void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000399 VisitExpr(S);
400}
401
Chandler Carruthb1138242011-06-16 06:47:06 +0000402void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruth08949762011-06-21 23:26:32 +0000403 const BinaryConditionalOperator *S) {
John McCall56ca35d2011-02-17 10:25:35 +0000404 VisitExpr(S);
405}
406
Chandler Carruthb1138242011-06-16 06:47:06 +0000407void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000408 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000409 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000410}
411
Chandler Carruthb1138242011-06-16 06:47:06 +0000412void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000413 VisitExpr(S);
414}
415
Chandler Carruthb1138242011-06-16 06:47:06 +0000416void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000417 VisitExpr(S);
418}
419
Chandler Carruthb1138242011-06-16 06:47:06 +0000420void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000421 VisitExpr(S);
422}
423
Chandler Carruthb1138242011-06-16 06:47:06 +0000424void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000425 VisitExpr(S);
426}
427
Chandler Carruthb1138242011-06-16 06:47:06 +0000428void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000429 VisitExpr(S);
430}
431
Chandler Carruthb1138242011-06-16 06:47:06 +0000432void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000433 if (S->getSyntacticForm()) {
434 VisitInitListExpr(S->getSyntacticForm());
435 return;
436 }
Mike Stump1eb44332009-09-09 15:08:12 +0000437
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000438 VisitExpr(S);
439}
440
Chandler Carruthb1138242011-06-16 06:47:06 +0000441void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000442 VisitExpr(S);
443 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruthb1138242011-06-16 06:47:06 +0000444 for (DesignatedInitExpr::const_designators_iterator D =
445 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000446 D != DEnd; ++D) {
447 if (D->isFieldDesignator()) {
448 ID.AddInteger(0);
449 VisitName(D->getFieldName());
450 continue;
451 }
Mike Stump1eb44332009-09-09 15:08:12 +0000452
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000453 if (D->isArrayDesignator()) {
454 ID.AddInteger(1);
455 } else {
456 assert(D->isArrayRangeDesignator());
457 ID.AddInteger(2);
458 }
459 ID.AddInteger(D->getFirstExprIndex());
460 }
461}
462
Chandler Carruthb1138242011-06-16 06:47:06 +0000463void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000464 VisitExpr(S);
465}
466
Chandler Carruthb1138242011-06-16 06:47:06 +0000467void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000468 VisitExpr(S);
469 VisitName(&S->getAccessor());
470}
471
Chandler Carruthb1138242011-06-16 06:47:06 +0000472void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000473 VisitExpr(S);
474 VisitDecl(S->getBlockDecl());
475}
476
Chandler Carruthb1138242011-06-16 06:47:06 +0000477void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbournef111d932011-04-15 00:35:48 +0000478 VisitExpr(S);
479 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
480 QualType T = S->getAssocType(i);
481 if (T.isNull())
482 ID.AddPointer(0);
483 else
484 VisitType(T);
485 VisitExpr(S->getAssocExpr(i));
486 }
487}
488
John McCall4b9c2d22011-11-06 09:01:30 +0000489void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
490 VisitExpr(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());
496}
497
Eli Friedman276b0612011-10-11 02:20:01 +0000498void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
499 VisitExpr(S);
Eli Friedman2be46072011-10-14 20:59:01 +0000500 ID.AddInteger(S->getOp());
Eli Friedman276b0612011-10-11 02:20:01 +0000501}
502
Chandler Carruthb1138242011-06-16 06:47:06 +0000503static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000504 UnaryOperatorKind &UnaryOp,
505 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000506 switch (S->getOperator()) {
507 case OO_None:
508 case OO_New:
509 case OO_Delete:
510 case OO_Array_New:
511 case OO_Array_Delete:
512 case OO_Arrow:
513 case OO_Call:
514 case OO_Conditional:
515 case NUM_OVERLOADED_OPERATORS:
516 llvm_unreachable("Invalid operator call kind");
Douglas Gregora89064a2010-05-19 04:13:23 +0000517
518 case OO_Plus:
519 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000520 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000521 return Stmt::UnaryOperatorClass;
522 }
523
John McCall2de56d12010-08-25 11:45:40 +0000524 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000525 return Stmt::BinaryOperatorClass;
526
527 case OO_Minus:
528 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000529 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000530 return Stmt::UnaryOperatorClass;
531 }
532
John McCall2de56d12010-08-25 11:45:40 +0000533 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000534 return Stmt::BinaryOperatorClass;
535
536 case OO_Star:
537 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000538 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000539 return Stmt::UnaryOperatorClass;
540 }
541
John McCall2de56d12010-08-25 11:45:40 +0000542 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000543 return Stmt::BinaryOperatorClass;
544
545 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000546 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000547 return Stmt::BinaryOperatorClass;
548
549 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000550 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000551 return Stmt::BinaryOperatorClass;
552
553 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000554 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000555 return Stmt::BinaryOperatorClass;
556
557 case OO_Amp:
558 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000559 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000560 return Stmt::UnaryOperatorClass;
561 }
562
John McCall2de56d12010-08-25 11:45:40 +0000563 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000564 return Stmt::BinaryOperatorClass;
565
566 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000567 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000568 return Stmt::BinaryOperatorClass;
569
570 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000571 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000572 return Stmt::UnaryOperatorClass;
573
574 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000575 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000576 return Stmt::UnaryOperatorClass;
577
578 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000579 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000580 return Stmt::BinaryOperatorClass;
581
582 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000583 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000584 return Stmt::BinaryOperatorClass;
585
586 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000587 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000588 return Stmt::BinaryOperatorClass;
589
590 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000591 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000592 return Stmt::CompoundAssignOperatorClass;
593
594 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000595 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000596 return Stmt::CompoundAssignOperatorClass;
597
598 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000599 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000600 return Stmt::CompoundAssignOperatorClass;
601
602 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000603 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000604 return Stmt::CompoundAssignOperatorClass;
605
606 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000607 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000608 return Stmt::CompoundAssignOperatorClass;
609
610 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000611 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000612 return Stmt::CompoundAssignOperatorClass;
613
614 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000615 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000616 return Stmt::CompoundAssignOperatorClass;
617
618 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000619 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000620 return Stmt::CompoundAssignOperatorClass;
621
622 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000623 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000624 return Stmt::BinaryOperatorClass;
625
626 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000627 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000628 return Stmt::BinaryOperatorClass;
629
630 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000631 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000632 return Stmt::CompoundAssignOperatorClass;
633
634 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000635 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000636 return Stmt::CompoundAssignOperatorClass;
637
638 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000639 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000640 return Stmt::BinaryOperatorClass;
641
642 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000643 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000644 return Stmt::BinaryOperatorClass;
645
646 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000647 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000648 return Stmt::BinaryOperatorClass;
649
650 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000651 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000652 return Stmt::BinaryOperatorClass;
653
654 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000655 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000656 return Stmt::BinaryOperatorClass;
657
658 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000659 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000660 return Stmt::BinaryOperatorClass;
661
662 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000663 UnaryOp = S->getNumArgs() == 1? UO_PreInc
664 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000665 return Stmt::UnaryOperatorClass;
666
667 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000668 UnaryOp = S->getNumArgs() == 1? UO_PreDec
669 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000670 return Stmt::UnaryOperatorClass;
671
672 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000673 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000674 return Stmt::BinaryOperatorClass;
675
676
677 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000678 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000679 return Stmt::BinaryOperatorClass;
680
681 case OO_Subscript:
682 return Stmt::ArraySubscriptExprClass;
683 }
684
685 llvm_unreachable("Invalid overloaded operator expression");
686}
687
688
Chandler Carruthb1138242011-06-16 06:47:06 +0000689void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000690 if (S->isTypeDependent()) {
691 // Type-dependent operator calls are profiled like their underlying
692 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000693 UnaryOperatorKind UnaryOp = UO_Extension;
694 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000695 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
696
697 ID.AddInteger(SC);
698 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
699 Visit(S->getArg(I));
700 if (SC == Stmt::UnaryOperatorClass)
701 ID.AddInteger(UnaryOp);
702 else if (SC == Stmt::BinaryOperatorClass ||
703 SC == Stmt::CompoundAssignOperatorClass)
704 ID.AddInteger(BinaryOp);
705 else
706 assert(SC == Stmt::ArraySubscriptExprClass);
707
708 return;
709 }
710
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000711 VisitCallExpr(S);
712 ID.AddInteger(S->getOperator());
713}
714
Chandler Carruthb1138242011-06-16 06:47:06 +0000715void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000716 VisitCallExpr(S);
717}
718
Chandler Carruthb1138242011-06-16 06:47:06 +0000719void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbournee08ce652011-02-09 21:07:24 +0000720 VisitCallExpr(S);
721}
722
Chandler Carruthb1138242011-06-16 06:47:06 +0000723void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner61eee0c2011-06-04 00:47:47 +0000724 VisitExpr(S);
725}
726
Chandler Carruthb1138242011-06-16 06:47:06 +0000727void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000728 VisitExplicitCastExpr(S);
729}
730
Chandler Carruthb1138242011-06-16 06:47:06 +0000731void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000732 VisitCXXNamedCastExpr(S);
733}
734
Chandler Carruthb1138242011-06-16 06:47:06 +0000735void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000736 VisitCXXNamedCastExpr(S);
737}
738
Chandler Carruthb1138242011-06-16 06:47:06 +0000739void
740StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000741 VisitCXXNamedCastExpr(S);
742}
743
Chandler Carruthb1138242011-06-16 06:47:06 +0000744void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000745 VisitCXXNamedCastExpr(S);
746}
747
Richard Smith9fcce652012-03-07 08:35:16 +0000748void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
749 VisitCallExpr(S);
750}
751
Chandler Carruthb1138242011-06-16 06:47:06 +0000752void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000753 VisitExpr(S);
754 ID.AddBoolean(S->getValue());
755}
756
Chandler Carruthb1138242011-06-16 06:47:06 +0000757void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000758 VisitExpr(S);
759}
760
Chandler Carruthb1138242011-06-16 06:47:06 +0000761void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000762 VisitExpr(S);
763 if (S->isTypeOperand())
764 VisitType(S->getTypeOperand());
765}
766
Chandler Carruthb1138242011-06-16 06:47:06 +0000767void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet01b7c302010-09-08 12:20:18 +0000768 VisitExpr(S);
769 if (S->isTypeOperand())
770 VisitType(S->getTypeOperand());
771}
772
John McCall76da55d2013-04-16 07:28:30 +0000773void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
774 VisitExpr(S);
775 VisitDecl(S->getPropertyDecl());
776}
777
Chandler Carruthb1138242011-06-16 06:47:06 +0000778void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000779 VisitExpr(S);
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000780 ID.AddBoolean(S->isImplicit());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000781}
782
Chandler Carruthb1138242011-06-16 06:47:06 +0000783void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000784 VisitExpr(S);
785}
786
Chandler Carruthb1138242011-06-16 06:47:06 +0000787void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000788 VisitExpr(S);
789 VisitDecl(S->getParam());
790}
791
Richard Smithc3bf52c2013-04-20 22:23:05 +0000792void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
793 VisitExpr(S);
794 VisitDecl(S->getField());
795}
796
Chandler Carruthb1138242011-06-16 06:47:06 +0000797void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000798 VisitExpr(S);
799 VisitDecl(
800 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
801}
802
Chandler Carruthb1138242011-06-16 06:47:06 +0000803void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000804 VisitExpr(S);
805 VisitDecl(S->getConstructor());
806 ID.AddBoolean(S->isElidable());
807}
808
Chandler Carruthb1138242011-06-16 06:47:06 +0000809void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000810 VisitExplicitCastExpr(S);
811}
812
Chandler Carruthb1138242011-06-16 06:47:06 +0000813void
814StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000815 VisitCXXConstructExpr(S);
816}
817
Chandler Carruthb1138242011-06-16 06:47:06 +0000818void
Douglas Gregor01d08012012-02-07 10:09:13 +0000819StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
820 VisitExpr(S);
821 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
822 CEnd = S->explicit_capture_end();
823 C != CEnd; ++C) {
824 ID.AddInteger(C->getCaptureKind());
825 if (C->capturesVariable()) {
826 VisitDecl(C->getCapturedVar());
827 ID.AddBoolean(C->isPackExpansion());
828 }
829 }
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());
834}
835
836void
Chandler Carruthb1138242011-06-16 06:47:06 +0000837StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000838 VisitExpr(S);
839}
840
Chandler Carruthb1138242011-06-16 06:47:06 +0000841void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000842 VisitExpr(S);
843 ID.AddBoolean(S->isGlobalDelete());
844 ID.AddBoolean(S->isArrayForm());
845 VisitDecl(S->getOperatorDelete());
846}
847
848
Chandler Carruthb1138242011-06-16 06:47:06 +0000849void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000850 VisitExpr(S);
851 VisitType(S->getAllocatedType());
852 VisitDecl(S->getOperatorNew());
853 VisitDecl(S->getOperatorDelete());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000854 ID.AddBoolean(S->isArray());
855 ID.AddInteger(S->getNumPlacementArgs());
856 ID.AddBoolean(S->isGlobalNew());
857 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000858 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000859}
860
Chandler Carruthb1138242011-06-16 06:47:06 +0000861void
862StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregora71d8192009-09-04 17:36:40 +0000863 VisitExpr(S);
864 ID.AddBoolean(S->isArrow());
865 VisitNestedNameSpecifier(S->getQualifier());
866 VisitType(S->getDestroyedType());
867}
868
Chandler Carruthb1138242011-06-16 06:47:06 +0000869void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000870 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000871 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000872 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000873 ID.AddBoolean(S->hasExplicitTemplateArgs());
874 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000875 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
876 S->getExplicitTemplateArgs().NumTemplateArgs);
877}
878
879void
Chandler Carruthb1138242011-06-16 06:47:06 +0000880StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000881 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000882}
883
Chandler Carruthb1138242011-06-16 06:47:06 +0000884void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000885 VisitExpr(S);
886 ID.AddInteger(S->getTrait());
887 VisitType(S->getQueriedType());
888}
889
Chandler Carruthb1138242011-06-16 06:47:06 +0000890void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
Francois Pichet6ad6f282010-12-07 00:08:36 +0000891 VisitExpr(S);
892 ID.AddInteger(S->getTrait());
893 VisitType(S->getLhsType());
894 VisitType(S->getRhsType());
895}
896
Douglas Gregor4ca8ac22012-02-24 07:38:34 +0000897void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
898 VisitExpr(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());
903}
904
Chandler Carruthb1138242011-06-16 06:47:06 +0000905void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley21ff2e52011-04-28 00:16:57 +0000906 VisitExpr(S);
907 ID.AddInteger(S->getTrait());
908 VisitType(S->getQueriedType());
909}
910
Chandler Carruthb1138242011-06-16 06:47:06 +0000911void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegley55262202011-04-25 06:54:41 +0000912 VisitExpr(S);
913 ID.AddInteger(S->getTrait());
914 VisitExpr(S->getQueriedExpression());
915}
916
Chandler Carruthb1138242011-06-16 06:47:06 +0000917void StmtProfiler::VisitDependentScopeDeclRefExpr(
918 const DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000919 VisitExpr(S);
920 VisitName(S->getDeclName());
921 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000922 ID.AddBoolean(S->hasExplicitTemplateArgs());
923 if (S->hasExplicitTemplateArgs())
924 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000925}
926
Chandler Carruthb1138242011-06-16 06:47:06 +0000927void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000928 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000929}
930
Chandler Carruthb1138242011-06-16 06:47:06 +0000931void StmtProfiler::VisitCXXUnresolvedConstructExpr(
932 const CXXUnresolvedConstructExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000933 VisitExpr(S);
934 VisitType(S->getTypeAsWritten());
935}
936
Chandler Carruthb1138242011-06-16 06:47:06 +0000937void StmtProfiler::VisitCXXDependentScopeMemberExpr(
938 const CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000939 ID.AddBoolean(S->isImplicitAccess());
940 if (!S->isImplicitAccess()) {
941 VisitExpr(S);
942 ID.AddBoolean(S->isArrow());
943 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000944 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000945 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000946 ID.AddBoolean(S->hasExplicitTemplateArgs());
947 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000948 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
949}
950
Chandler Carruthb1138242011-06-16 06:47:06 +0000951void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000952 ID.AddBoolean(S->isImplicitAccess());
953 if (!S->isImplicitAccess()) {
954 VisitExpr(S);
955 ID.AddBoolean(S->isArrow());
956 }
John McCall129e2df2009-11-30 22:42:35 +0000957 VisitNestedNameSpecifier(S->getQualifier());
958 VisitName(S->getMemberName());
959 ID.AddBoolean(S->hasExplicitTemplateArgs());
960 if (S->hasExplicitTemplateArgs())
961 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000962}
963
Chandler Carruthb1138242011-06-16 06:47:06 +0000964void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl2e156222010-09-10 20:55:43 +0000965 VisitExpr(S);
966}
967
Chandler Carruthb1138242011-06-16 06:47:06 +0000968void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregorbe230c32011-01-03 17:17:50 +0000969 VisitExpr(S);
970}
971
Chandler Carruthb1138242011-06-16 06:47:06 +0000972void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregoree8aff02011-01-04 17:33:58 +0000973 VisitExpr(S);
974 VisitDecl(S->getPack());
975}
976
Douglas Gregorc7793c72011-01-15 01:15:58 +0000977void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruthb1138242011-06-16 06:47:06 +0000978 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorc7793c72011-01-15 01:15:58 +0000979 VisitExpr(S);
980 VisitDecl(S->getParameterPack());
981 VisitTemplateArgument(S->getArgumentPack());
982}
983
John McCall91a57552011-07-15 05:09:51 +0000984void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
985 const SubstNonTypeTemplateParmExpr *E) {
986 // Profile exactly as the replacement expression.
987 Visit(E->getReplacement());
988}
989
Richard Smith9a4db032012-09-12 00:56:43 +0000990void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
991 VisitExpr(S);
992 VisitDecl(S->getParameterPack());
993 ID.AddInteger(S->getNumExpansions());
994 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
995 VisitDecl(*I);
996}
997
Douglas Gregor03e80032011-06-21 17:03:29 +0000998void StmtProfiler::VisitMaterializeTemporaryExpr(
999 const MaterializeTemporaryExpr *S) {
1000 VisitExpr(S);
1001}
1002
Chandler Carruthb1138242011-06-16 06:47:06 +00001003void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall7cd7d1a2010-11-15 23:31:06 +00001004 VisitExpr(E);
1005}
1006
Chandler Carruthb1138242011-06-16 06:47:06 +00001007void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001008 VisitExpr(S);
1009}
1010
Patrick Beardeb382ec2012-04-19 00:25:12 +00001011void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001012 VisitExpr(E);
1013}
1014
1015void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1016 VisitExpr(E);
1017}
1018
1019void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1020 VisitExpr(E);
1021}
1022
Chandler Carruthb1138242011-06-16 06:47:06 +00001023void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001024 VisitExpr(S);
1025 VisitType(S->getEncodedType());
1026}
1027
Chandler Carruthb1138242011-06-16 06:47:06 +00001028void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001029 VisitExpr(S);
1030 VisitName(S->getSelector());
1031}
1032
Chandler Carruthb1138242011-06-16 06:47:06 +00001033void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001034 VisitExpr(S);
1035 VisitDecl(S->getProtocol());
1036}
1037
Chandler Carruthb1138242011-06-16 06:47:06 +00001038void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001039 VisitExpr(S);
1040 VisitDecl(S->getDecl());
1041 ID.AddBoolean(S->isArrow());
1042 ID.AddBoolean(S->isFreeIvar());
1043}
1044
Chandler Carruthb1138242011-06-16 06:47:06 +00001045void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001046 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +00001047 if (S->isImplicitProperty()) {
1048 VisitDecl(S->getImplicitPropertyGetter());
1049 VisitDecl(S->getImplicitPropertySetter());
1050 } else {
1051 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001052 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001053 if (S->isSuperReceiver()) {
1054 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +00001055 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001056 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001057}
1058
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001059void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1060 VisitExpr(S);
1061 VisitDecl(S->getAtIndexMethodDecl());
1062 VisitDecl(S->setAtIndexMethodDecl());
1063}
1064
Chandler Carruthb1138242011-06-16 06:47:06 +00001065void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001066 VisitExpr(S);
1067 VisitName(S->getSelector());
1068 VisitDecl(S->getMethodDecl());
1069}
1070
Chandler Carruthb1138242011-06-16 06:47:06 +00001071void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001072 VisitExpr(S);
1073 ID.AddBoolean(S->isArrow());
1074}
1075
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001076void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1077 VisitExpr(S);
1078 ID.AddBoolean(S->getValue());
1079}
1080
Chandler Carruthb1138242011-06-16 06:47:06 +00001081void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1082 const ObjCIndirectCopyRestoreExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +00001083 VisitExpr(S);
1084 ID.AddBoolean(S->shouldCopy());
1085}
1086
Chandler Carruthb1138242011-06-16 06:47:06 +00001087void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +00001088 VisitExplicitCastExpr(S);
1089 ID.AddBoolean(S->getBridgeKind());
1090}
1091
Chandler Carruthb1138242011-06-16 06:47:06 +00001092void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001093 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +00001094
Douglas Gregorb1975722009-07-30 23:18:24 +00001095 if (Canonical && D) {
Chandler Carruthb1138242011-06-16 06:47:06 +00001096 if (const NonTypeTemplateParmDecl *NTTP =
1097 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +00001098 ID.AddInteger(NTTP->getDepth());
1099 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +00001100 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +00001101 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001102 return;
1103 }
Mike Stump1eb44332009-09-09 15:08:12 +00001104
Chandler Carruthb1138242011-06-16 06:47:06 +00001105 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCallfb44de92011-05-01 22:35:37 +00001106 // 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
1112 // name mangling.
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001113 VisitType(Parm->getType());
John McCallfb44de92011-05-01 22:35:37 +00001114 ID.AddInteger(Parm->getFunctionScopeDepth());
1115 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001116 return;
1117 }
Mike Stump1eb44332009-09-09 15:08:12 +00001118
Richard Smith0f6931a2012-04-02 18:53:24 +00001119 if (const TemplateTypeParmDecl *TTP =
1120 dyn_cast<TemplateTypeParmDecl>(D)) {
1121 ID.AddInteger(TTP->getDepth());
1122 ID.AddInteger(TTP->getIndex());
1123 ID.AddBoolean(TTP->isParameterPack());
1124 return;
1125 }
1126
Chandler Carruthb1138242011-06-16 06:47:06 +00001127 if (const TemplateTemplateParmDecl *TTP =
1128 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregora2ffb982009-07-31 15:46:56 +00001129 ID.AddInteger(TTP->getDepth());
1130 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +00001131 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +00001132 return;
1133 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001134 }
Mike Stump1eb44332009-09-09 15:08:12 +00001135
Douglas Gregord584eb22009-07-28 15:32:17 +00001136 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1137}
1138
1139void StmtProfiler::VisitType(QualType T) {
1140 if (Canonical)
1141 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +00001142
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001143 ID.AddPointer(T.getAsOpaquePtr());
1144}
1145
1146void StmtProfiler::VisitName(DeclarationName Name) {
1147 ID.AddPointer(Name.getAsOpaquePtr());
1148}
1149
1150void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1151 if (Canonical)
1152 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1153 ID.AddPointer(NNS);
1154}
1155
1156void StmtProfiler::VisitTemplateName(TemplateName Name) {
1157 if (Canonical)
1158 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +00001159
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001160 Name.Profile(ID);
1161}
1162
John McCall833ca992009-10-29 08:12:44 +00001163void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001164 unsigned NumArgs) {
1165 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +00001166 for (unsigned I = 0; I != NumArgs; ++I)
1167 VisitTemplateArgument(Args[I].getArgument());
1168}
Mike Stump1eb44332009-09-09 15:08:12 +00001169
John McCall833ca992009-10-29 08:12:44 +00001170void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1171 // Mostly repetitive with TemplateArgument::Profile!
1172 ID.AddInteger(Arg.getKind());
1173 switch (Arg.getKind()) {
1174 case TemplateArgument::Null:
1175 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001176
John McCall833ca992009-10-29 08:12:44 +00001177 case TemplateArgument::Type:
1178 VisitType(Arg.getAsType());
1179 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001180
Douglas Gregor788cd062009-11-11 01:00:40 +00001181 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00001182 case TemplateArgument::TemplateExpansion:
1183 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +00001184 break;
Sean Huntc3021132010-05-05 15:23:54 +00001185
John McCall833ca992009-10-29 08:12:44 +00001186 case TemplateArgument::Declaration:
1187 VisitDecl(Arg.getAsDecl());
1188 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001189
Eli Friedmand7a6b162012-09-26 02:36:12 +00001190 case TemplateArgument::NullPtr:
1191 VisitType(Arg.getNullPtrType());
1192 break;
1193
John McCall833ca992009-10-29 08:12:44 +00001194 case TemplateArgument::Integral:
Benjamin Kramer85524372012-06-07 15:09:51 +00001195 Arg.getAsIntegral().Profile(ID);
John McCall833ca992009-10-29 08:12:44 +00001196 VisitType(Arg.getIntegralType());
1197 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001198
John McCall833ca992009-10-29 08:12:44 +00001199 case TemplateArgument::Expression:
1200 Visit(Arg.getAsExpr());
1201 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001202
John McCall833ca992009-10-29 08:12:44 +00001203 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]);
1207 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001208 }
1209}
1210
Jay Foad4ba2a172011-01-12 09:06:06 +00001211void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruthb1138242011-06-16 06:47:06 +00001212 bool Canonical) const {
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001213 StmtProfiler Profiler(ID, Context, Canonical);
1214 Profiler.Visit(this);
1215}