blob: a626f68aa588d9612119e73c11609d4462e7a1b5 [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
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000255namespace {
256class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
257 StmtProfiler *Profiler;
258public:
259 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
260#define OPENMP_CLAUSE(Name, Class) \
261 void Visit##Class(const Class *C);
262#include "clang/Basic/OpenMPKinds.def"
263};
264
265void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
266#define PROCESS_OMP_CLAUSE_LIST(Class, Node) \
267 for (OMPVarList<Class>::varlist_const_iterator I = Node->varlist_begin(), \
268 E = Node->varlist_end(); \
269 I != E; ++I) \
270 Profiler->VisitStmt(*I);
271
272void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
273 PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)
274}
275#undef PROCESS_OMP_CLAUSE_LIST
276}
277
278void
279StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
280 VisitStmt(S);
281 OMPClauseProfiler P(this);
282 ArrayRef<OMPClause *> Clauses = S->clauses();
283 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
284 I != E; ++I)
285 if (*I)
286 P.Visit(*I);
287}
288
Chandler Carruthb1138242011-06-16 06:47:06 +0000289void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000290 VisitStmt(S);
291}
292
Chandler Carruthb1138242011-06-16 06:47:06 +0000293void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000294 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000295 if (!Canonical)
296 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000297 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000298 if (!Canonical)
299 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000300}
301
Chandler Carruthb1138242011-06-16 06:47:06 +0000302void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000303 VisitExpr(S);
304 ID.AddInteger(S->getIdentType());
305}
306
Chandler Carruthb1138242011-06-16 06:47:06 +0000307void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000308 VisitExpr(S);
309 S->getValue().Profile(ID);
310}
311
Chandler Carruthb1138242011-06-16 06:47:06 +0000312void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000313 VisitExpr(S);
Douglas Gregor5cee1192011-07-27 05:40:30 +0000314 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000315 ID.AddInteger(S->getValue());
316}
317
Chandler Carruthb1138242011-06-16 06:47:06 +0000318void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000319 VisitExpr(S);
320 S->getValue().Profile(ID);
321 ID.AddBoolean(S->isExact());
322}
323
Chandler Carruthb1138242011-06-16 06:47:06 +0000324void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000325 VisitExpr(S);
326}
327
Chandler Carruthb1138242011-06-16 06:47:06 +0000328void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000329 VisitExpr(S);
Douglas Gregor38738fc2011-11-02 17:26:05 +0000330 ID.AddString(S->getBytes());
Douglas Gregor5cee1192011-07-27 05:40:30 +0000331 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000332}
333
Chandler Carruthb1138242011-06-16 06:47:06 +0000334void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000335 VisitExpr(S);
336}
337
Chandler Carruthb1138242011-06-16 06:47:06 +0000338void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman2ef13e52009-08-10 23:49:36 +0000339 VisitExpr(S);
340}
341
Chandler Carruthb1138242011-06-16 06:47:06 +0000342void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000343 VisitExpr(S);
344 ID.AddInteger(S->getOpcode());
345}
346
Chandler Carruthb1138242011-06-16 06:47:06 +0000347void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000348 VisitType(S->getTypeSourceInfo()->getType());
349 unsigned n = S->getNumComponents();
350 for (unsigned i = 0; i < n; ++i) {
351 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
352 ID.AddInteger(ON.getKind());
353 switch (ON.getKind()) {
354 case OffsetOfExpr::OffsetOfNode::Array:
355 // Expressions handled below.
356 break;
357
358 case OffsetOfExpr::OffsetOfNode::Field:
359 VisitDecl(ON.getField());
360 break;
361
362 case OffsetOfExpr::OffsetOfNode::Identifier:
363 ID.AddPointer(ON.getFieldName());
364 break;
Sean Huntc3021132010-05-05 15:23:54 +0000365
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000366 case OffsetOfExpr::OffsetOfNode::Base:
367 // These nodes are implicit, and therefore don't need profiling.
368 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000369 }
370 }
Sean Huntc3021132010-05-05 15:23:54 +0000371
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000372 VisitExpr(S);
373}
374
Chandler Carruthb1138242011-06-16 06:47:06 +0000375void
376StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000377 VisitExpr(S);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000378 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000379 if (S->isArgumentType())
380 VisitType(S->getArgumentType());
381}
382
Chandler Carruthb1138242011-06-16 06:47:06 +0000383void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000384 VisitExpr(S);
385}
386
Chandler Carruthb1138242011-06-16 06:47:06 +0000387void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000388 VisitExpr(S);
389}
390
Chandler Carruthb1138242011-06-16 06:47:06 +0000391void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000392 VisitExpr(S);
393 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000394 if (!Canonical)
395 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000396 ID.AddBoolean(S->isArrow());
397}
398
Chandler Carruthb1138242011-06-16 06:47:06 +0000399void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000400 VisitExpr(S);
401 ID.AddBoolean(S->isFileScope());
402}
403
Chandler Carruthb1138242011-06-16 06:47:06 +0000404void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000405 VisitExpr(S);
406}
407
Chandler Carruthb1138242011-06-16 06:47:06 +0000408void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000409 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000410 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000411}
412
Chandler Carruthb1138242011-06-16 06:47:06 +0000413void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000414 VisitCastExpr(S);
415 VisitType(S->getTypeAsWritten());
416}
417
Chandler Carruthb1138242011-06-16 06:47:06 +0000418void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000419 VisitExplicitCastExpr(S);
420}
421
Chandler Carruthb1138242011-06-16 06:47:06 +0000422void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000423 VisitExpr(S);
424 ID.AddInteger(S->getOpcode());
425}
426
Chandler Carruthb1138242011-06-16 06:47:06 +0000427void
428StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000429 VisitBinaryOperator(S);
430}
431
Chandler Carruthb1138242011-06-16 06:47:06 +0000432void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000433 VisitExpr(S);
434}
435
Chandler Carruthb1138242011-06-16 06:47:06 +0000436void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruth08949762011-06-21 23:26:32 +0000437 const BinaryConditionalOperator *S) {
John McCall56ca35d2011-02-17 10:25:35 +0000438 VisitExpr(S);
439}
440
Chandler Carruthb1138242011-06-16 06:47:06 +0000441void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000442 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000443 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000444}
445
Chandler Carruthb1138242011-06-16 06:47:06 +0000446void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000447 VisitExpr(S);
448}
449
Chandler Carruthb1138242011-06-16 06:47:06 +0000450void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000451 VisitExpr(S);
452}
453
Chandler Carruthb1138242011-06-16 06:47:06 +0000454void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000455 VisitExpr(S);
456}
457
Chandler Carruthb1138242011-06-16 06:47:06 +0000458void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000459 VisitExpr(S);
460}
461
Chandler Carruthb1138242011-06-16 06:47:06 +0000462void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000463 VisitExpr(S);
464}
465
Chandler Carruthb1138242011-06-16 06:47:06 +0000466void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000467 if (S->getSyntacticForm()) {
468 VisitInitListExpr(S->getSyntacticForm());
469 return;
470 }
Mike Stump1eb44332009-09-09 15:08:12 +0000471
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000472 VisitExpr(S);
473}
474
Chandler Carruthb1138242011-06-16 06:47:06 +0000475void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000476 VisitExpr(S);
477 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruthb1138242011-06-16 06:47:06 +0000478 for (DesignatedInitExpr::const_designators_iterator D =
479 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000480 D != DEnd; ++D) {
481 if (D->isFieldDesignator()) {
482 ID.AddInteger(0);
483 VisitName(D->getFieldName());
484 continue;
485 }
Mike Stump1eb44332009-09-09 15:08:12 +0000486
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000487 if (D->isArrayDesignator()) {
488 ID.AddInteger(1);
489 } else {
490 assert(D->isArrayRangeDesignator());
491 ID.AddInteger(2);
492 }
493 ID.AddInteger(D->getFirstExprIndex());
494 }
495}
496
Chandler Carruthb1138242011-06-16 06:47:06 +0000497void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000498 VisitExpr(S);
499}
500
Chandler Carruthb1138242011-06-16 06:47:06 +0000501void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000502 VisitExpr(S);
503 VisitName(&S->getAccessor());
504}
505
Chandler Carruthb1138242011-06-16 06:47:06 +0000506void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000507 VisitExpr(S);
508 VisitDecl(S->getBlockDecl());
509}
510
Chandler Carruthb1138242011-06-16 06:47:06 +0000511void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbournef111d932011-04-15 00:35:48 +0000512 VisitExpr(S);
513 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
514 QualType T = S->getAssocType(i);
515 if (T.isNull())
516 ID.AddPointer(0);
517 else
518 VisitType(T);
519 VisitExpr(S->getAssocExpr(i));
520 }
521}
522
John McCall4b9c2d22011-11-06 09:01:30 +0000523void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
524 VisitExpr(S);
525 for (PseudoObjectExpr::const_semantics_iterator
526 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
527 // Normally, we would not profile the source expressions of OVEs.
528 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
529 Visit(OVE->getSourceExpr());
530}
531
Eli Friedman276b0612011-10-11 02:20:01 +0000532void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
533 VisitExpr(S);
Eli Friedman2be46072011-10-14 20:59:01 +0000534 ID.AddInteger(S->getOp());
Eli Friedman276b0612011-10-11 02:20:01 +0000535}
536
Chandler Carruthb1138242011-06-16 06:47:06 +0000537static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000538 UnaryOperatorKind &UnaryOp,
539 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000540 switch (S->getOperator()) {
541 case OO_None:
542 case OO_New:
543 case OO_Delete:
544 case OO_Array_New:
545 case OO_Array_Delete:
546 case OO_Arrow:
547 case OO_Call:
548 case OO_Conditional:
549 case NUM_OVERLOADED_OPERATORS:
550 llvm_unreachable("Invalid operator call kind");
Douglas Gregora89064a2010-05-19 04:13:23 +0000551
552 case OO_Plus:
553 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000554 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000555 return Stmt::UnaryOperatorClass;
556 }
557
John McCall2de56d12010-08-25 11:45:40 +0000558 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000559 return Stmt::BinaryOperatorClass;
560
561 case OO_Minus:
562 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000563 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000564 return Stmt::UnaryOperatorClass;
565 }
566
John McCall2de56d12010-08-25 11:45:40 +0000567 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000568 return Stmt::BinaryOperatorClass;
569
570 case OO_Star:
571 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000572 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000573 return Stmt::UnaryOperatorClass;
574 }
575
John McCall2de56d12010-08-25 11:45:40 +0000576 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000577 return Stmt::BinaryOperatorClass;
578
579 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000580 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000581 return Stmt::BinaryOperatorClass;
582
583 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000584 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000585 return Stmt::BinaryOperatorClass;
586
587 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000588 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000589 return Stmt::BinaryOperatorClass;
590
591 case OO_Amp:
592 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000593 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000594 return Stmt::UnaryOperatorClass;
595 }
596
John McCall2de56d12010-08-25 11:45:40 +0000597 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000598 return Stmt::BinaryOperatorClass;
599
600 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000601 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000602 return Stmt::BinaryOperatorClass;
603
604 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000605 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000606 return Stmt::UnaryOperatorClass;
607
608 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000609 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000610 return Stmt::UnaryOperatorClass;
611
612 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000613 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000614 return Stmt::BinaryOperatorClass;
615
616 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000617 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000618 return Stmt::BinaryOperatorClass;
619
620 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000621 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000622 return Stmt::BinaryOperatorClass;
623
624 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000625 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000626 return Stmt::CompoundAssignOperatorClass;
627
628 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000629 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000630 return Stmt::CompoundAssignOperatorClass;
631
632 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000633 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000634 return Stmt::CompoundAssignOperatorClass;
635
636 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000637 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000638 return Stmt::CompoundAssignOperatorClass;
639
640 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000641 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000642 return Stmt::CompoundAssignOperatorClass;
643
644 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000645 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000646 return Stmt::CompoundAssignOperatorClass;
647
648 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000649 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000650 return Stmt::CompoundAssignOperatorClass;
651
652 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000653 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000654 return Stmt::CompoundAssignOperatorClass;
655
656 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000657 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000658 return Stmt::BinaryOperatorClass;
659
660 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000661 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000662 return Stmt::BinaryOperatorClass;
663
664 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000665 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000666 return Stmt::CompoundAssignOperatorClass;
667
668 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000669 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000670 return Stmt::CompoundAssignOperatorClass;
671
672 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000673 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000674 return Stmt::BinaryOperatorClass;
675
676 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000677 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000678 return Stmt::BinaryOperatorClass;
679
680 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000681 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000682 return Stmt::BinaryOperatorClass;
683
684 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000685 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000686 return Stmt::BinaryOperatorClass;
687
688 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000689 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000690 return Stmt::BinaryOperatorClass;
691
692 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000693 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000694 return Stmt::BinaryOperatorClass;
695
696 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000697 UnaryOp = S->getNumArgs() == 1? UO_PreInc
698 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000699 return Stmt::UnaryOperatorClass;
700
701 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000702 UnaryOp = S->getNumArgs() == 1? UO_PreDec
703 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000704 return Stmt::UnaryOperatorClass;
705
706 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000707 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000708 return Stmt::BinaryOperatorClass;
709
710
711 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000712 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000713 return Stmt::BinaryOperatorClass;
714
715 case OO_Subscript:
716 return Stmt::ArraySubscriptExprClass;
717 }
718
719 llvm_unreachable("Invalid overloaded operator expression");
720}
721
722
Chandler Carruthb1138242011-06-16 06:47:06 +0000723void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000724 if (S->isTypeDependent()) {
725 // Type-dependent operator calls are profiled like their underlying
726 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000727 UnaryOperatorKind UnaryOp = UO_Extension;
728 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000729 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
730
731 ID.AddInteger(SC);
732 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
733 Visit(S->getArg(I));
734 if (SC == Stmt::UnaryOperatorClass)
735 ID.AddInteger(UnaryOp);
736 else if (SC == Stmt::BinaryOperatorClass ||
737 SC == Stmt::CompoundAssignOperatorClass)
738 ID.AddInteger(BinaryOp);
739 else
740 assert(SC == Stmt::ArraySubscriptExprClass);
741
742 return;
743 }
744
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000745 VisitCallExpr(S);
746 ID.AddInteger(S->getOperator());
747}
748
Chandler Carruthb1138242011-06-16 06:47:06 +0000749void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000750 VisitCallExpr(S);
751}
752
Chandler Carruthb1138242011-06-16 06:47:06 +0000753void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbournee08ce652011-02-09 21:07:24 +0000754 VisitCallExpr(S);
755}
756
Chandler Carruthb1138242011-06-16 06:47:06 +0000757void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner61eee0c2011-06-04 00:47:47 +0000758 VisitExpr(S);
759}
760
Chandler Carruthb1138242011-06-16 06:47:06 +0000761void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000762 VisitExplicitCastExpr(S);
763}
764
Chandler Carruthb1138242011-06-16 06:47:06 +0000765void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000766 VisitCXXNamedCastExpr(S);
767}
768
Chandler Carruthb1138242011-06-16 06:47:06 +0000769void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000770 VisitCXXNamedCastExpr(S);
771}
772
Chandler Carruthb1138242011-06-16 06:47:06 +0000773void
774StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000775 VisitCXXNamedCastExpr(S);
776}
777
Chandler Carruthb1138242011-06-16 06:47:06 +0000778void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000779 VisitCXXNamedCastExpr(S);
780}
781
Richard Smith9fcce652012-03-07 08:35:16 +0000782void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
783 VisitCallExpr(S);
784}
785
Chandler Carruthb1138242011-06-16 06:47:06 +0000786void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000787 VisitExpr(S);
788 ID.AddBoolean(S->getValue());
789}
790
Chandler Carruthb1138242011-06-16 06:47:06 +0000791void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000792 VisitExpr(S);
793}
794
Richard Smith7c3e6152013-06-12 22:31:48 +0000795void StmtProfiler::VisitCXXStdInitializerListExpr(
796 const CXXStdInitializerListExpr *S) {
797 VisitExpr(S);
798}
799
Chandler Carruthb1138242011-06-16 06:47:06 +0000800void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000801 VisitExpr(S);
802 if (S->isTypeOperand())
803 VisitType(S->getTypeOperand());
804}
805
Chandler Carruthb1138242011-06-16 06:47:06 +0000806void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet01b7c302010-09-08 12:20:18 +0000807 VisitExpr(S);
808 if (S->isTypeOperand())
809 VisitType(S->getTypeOperand());
810}
811
John McCall76da55d2013-04-16 07:28:30 +0000812void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
813 VisitExpr(S);
814 VisitDecl(S->getPropertyDecl());
815}
816
Chandler Carruthb1138242011-06-16 06:47:06 +0000817void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000818 VisitExpr(S);
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000819 ID.AddBoolean(S->isImplicit());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000820}
821
Chandler Carruthb1138242011-06-16 06:47:06 +0000822void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000823 VisitExpr(S);
824}
825
Chandler Carruthb1138242011-06-16 06:47:06 +0000826void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000827 VisitExpr(S);
828 VisitDecl(S->getParam());
829}
830
Richard Smithc3bf52c2013-04-20 22:23:05 +0000831void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
832 VisitExpr(S);
833 VisitDecl(S->getField());
834}
835
Chandler Carruthb1138242011-06-16 06:47:06 +0000836void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000837 VisitExpr(S);
838 VisitDecl(
839 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
840}
841
Chandler Carruthb1138242011-06-16 06:47:06 +0000842void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000843 VisitExpr(S);
844 VisitDecl(S->getConstructor());
845 ID.AddBoolean(S->isElidable());
846}
847
Chandler Carruthb1138242011-06-16 06:47:06 +0000848void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000849 VisitExplicitCastExpr(S);
850}
851
Chandler Carruthb1138242011-06-16 06:47:06 +0000852void
853StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000854 VisitCXXConstructExpr(S);
855}
856
Chandler Carruthb1138242011-06-16 06:47:06 +0000857void
Douglas Gregor01d08012012-02-07 10:09:13 +0000858StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
859 VisitExpr(S);
860 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
861 CEnd = S->explicit_capture_end();
862 C != CEnd; ++C) {
863 ID.AddInteger(C->getCaptureKind());
Richard Smith0d8e9642013-05-16 06:20:58 +0000864 switch (C->getCaptureKind()) {
865 case LCK_This:
866 break;
867 case LCK_ByRef:
868 case LCK_ByCopy:
Douglas Gregor01d08012012-02-07 10:09:13 +0000869 VisitDecl(C->getCapturedVar());
870 ID.AddBoolean(C->isPackExpansion());
Richard Smith0d8e9642013-05-16 06:20:58 +0000871 break;
872 case LCK_Init:
873 VisitDecl(C->getInitCaptureField());
874 break;
Douglas Gregor01d08012012-02-07 10:09:13 +0000875 }
876 }
877 // Note: If we actually needed to be able to match lambda
878 // expressions, we would have to consider parameters and return type
879 // here, among other things.
880 VisitStmt(S->getBody());
881}
882
883void
Chandler Carruthb1138242011-06-16 06:47:06 +0000884StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000885 VisitExpr(S);
886}
887
Chandler Carruthb1138242011-06-16 06:47:06 +0000888void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000889 VisitExpr(S);
890 ID.AddBoolean(S->isGlobalDelete());
891 ID.AddBoolean(S->isArrayForm());
892 VisitDecl(S->getOperatorDelete());
893}
894
895
Chandler Carruthb1138242011-06-16 06:47:06 +0000896void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000897 VisitExpr(S);
898 VisitType(S->getAllocatedType());
899 VisitDecl(S->getOperatorNew());
900 VisitDecl(S->getOperatorDelete());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000901 ID.AddBoolean(S->isArray());
902 ID.AddInteger(S->getNumPlacementArgs());
903 ID.AddBoolean(S->isGlobalNew());
904 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000905 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000906}
907
Chandler Carruthb1138242011-06-16 06:47:06 +0000908void
909StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregora71d8192009-09-04 17:36:40 +0000910 VisitExpr(S);
911 ID.AddBoolean(S->isArrow());
912 VisitNestedNameSpecifier(S->getQualifier());
913 VisitType(S->getDestroyedType());
914}
915
Chandler Carruthb1138242011-06-16 06:47:06 +0000916void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000917 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000918 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000919 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000920 ID.AddBoolean(S->hasExplicitTemplateArgs());
921 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000922 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
923 S->getExplicitTemplateArgs().NumTemplateArgs);
924}
925
926void
Chandler Carruthb1138242011-06-16 06:47:06 +0000927StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000928 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000929}
930
Chandler Carruthb1138242011-06-16 06:47:06 +0000931void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000932 VisitExpr(S);
933 ID.AddInteger(S->getTrait());
934 VisitType(S->getQueriedType());
935}
936
Chandler Carruthb1138242011-06-16 06:47:06 +0000937void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
Francois Pichet6ad6f282010-12-07 00:08:36 +0000938 VisitExpr(S);
939 ID.AddInteger(S->getTrait());
940 VisitType(S->getLhsType());
941 VisitType(S->getRhsType());
942}
943
Douglas Gregor4ca8ac22012-02-24 07:38:34 +0000944void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
945 VisitExpr(S);
946 ID.AddInteger(S->getTrait());
947 ID.AddInteger(S->getNumArgs());
948 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
949 VisitType(S->getArg(I)->getType());
950}
951
Chandler Carruthb1138242011-06-16 06:47:06 +0000952void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley21ff2e52011-04-28 00:16:57 +0000953 VisitExpr(S);
954 ID.AddInteger(S->getTrait());
955 VisitType(S->getQueriedType());
956}
957
Chandler Carruthb1138242011-06-16 06:47:06 +0000958void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegley55262202011-04-25 06:54:41 +0000959 VisitExpr(S);
960 ID.AddInteger(S->getTrait());
961 VisitExpr(S->getQueriedExpression());
962}
963
Chandler Carruthb1138242011-06-16 06:47:06 +0000964void StmtProfiler::VisitDependentScopeDeclRefExpr(
965 const DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000966 VisitExpr(S);
967 VisitName(S->getDeclName());
968 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000969 ID.AddBoolean(S->hasExplicitTemplateArgs());
970 if (S->hasExplicitTemplateArgs())
971 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000972}
973
Chandler Carruthb1138242011-06-16 06:47:06 +0000974void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000975 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000976}
977
Chandler Carruthb1138242011-06-16 06:47:06 +0000978void StmtProfiler::VisitCXXUnresolvedConstructExpr(
979 const CXXUnresolvedConstructExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000980 VisitExpr(S);
981 VisitType(S->getTypeAsWritten());
982}
983
Chandler Carruthb1138242011-06-16 06:47:06 +0000984void StmtProfiler::VisitCXXDependentScopeMemberExpr(
985 const CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000986 ID.AddBoolean(S->isImplicitAccess());
987 if (!S->isImplicitAccess()) {
988 VisitExpr(S);
989 ID.AddBoolean(S->isArrow());
990 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000991 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000992 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000993 ID.AddBoolean(S->hasExplicitTemplateArgs());
994 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000995 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
996}
997
Chandler Carruthb1138242011-06-16 06:47:06 +0000998void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000999 ID.AddBoolean(S->isImplicitAccess());
1000 if (!S->isImplicitAccess()) {
1001 VisitExpr(S);
1002 ID.AddBoolean(S->isArrow());
1003 }
John McCall129e2df2009-11-30 22:42:35 +00001004 VisitNestedNameSpecifier(S->getQualifier());
1005 VisitName(S->getMemberName());
1006 ID.AddBoolean(S->hasExplicitTemplateArgs());
1007 if (S->hasExplicitTemplateArgs())
1008 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001009}
1010
Chandler Carruthb1138242011-06-16 06:47:06 +00001011void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl2e156222010-09-10 20:55:43 +00001012 VisitExpr(S);
1013}
1014
Chandler Carruthb1138242011-06-16 06:47:06 +00001015void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregorbe230c32011-01-03 17:17:50 +00001016 VisitExpr(S);
1017}
1018
Chandler Carruthb1138242011-06-16 06:47:06 +00001019void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregoree8aff02011-01-04 17:33:58 +00001020 VisitExpr(S);
1021 VisitDecl(S->getPack());
1022}
1023
Douglas Gregorc7793c72011-01-15 01:15:58 +00001024void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruthb1138242011-06-16 06:47:06 +00001025 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorc7793c72011-01-15 01:15:58 +00001026 VisitExpr(S);
1027 VisitDecl(S->getParameterPack());
1028 VisitTemplateArgument(S->getArgumentPack());
1029}
1030
John McCall91a57552011-07-15 05:09:51 +00001031void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1032 const SubstNonTypeTemplateParmExpr *E) {
1033 // Profile exactly as the replacement expression.
1034 Visit(E->getReplacement());
1035}
1036
Richard Smith9a4db032012-09-12 00:56:43 +00001037void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1038 VisitExpr(S);
1039 VisitDecl(S->getParameterPack());
1040 ID.AddInteger(S->getNumExpansions());
1041 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1042 VisitDecl(*I);
1043}
1044
Douglas Gregor03e80032011-06-21 17:03:29 +00001045void StmtProfiler::VisitMaterializeTemporaryExpr(
1046 const MaterializeTemporaryExpr *S) {
1047 VisitExpr(S);
1048}
1049
Chandler Carruthb1138242011-06-16 06:47:06 +00001050void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall7cd7d1a2010-11-15 23:31:06 +00001051 VisitExpr(E);
1052}
1053
Chandler Carruthb1138242011-06-16 06:47:06 +00001054void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001055 VisitExpr(S);
1056}
1057
Patrick Beardeb382ec2012-04-19 00:25:12 +00001058void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001059 VisitExpr(E);
1060}
1061
1062void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1063 VisitExpr(E);
1064}
1065
1066void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1067 VisitExpr(E);
1068}
1069
Chandler Carruthb1138242011-06-16 06:47:06 +00001070void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001071 VisitExpr(S);
1072 VisitType(S->getEncodedType());
1073}
1074
Chandler Carruthb1138242011-06-16 06:47:06 +00001075void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001076 VisitExpr(S);
1077 VisitName(S->getSelector());
1078}
1079
Chandler Carruthb1138242011-06-16 06:47:06 +00001080void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001081 VisitExpr(S);
1082 VisitDecl(S->getProtocol());
1083}
1084
Chandler Carruthb1138242011-06-16 06:47:06 +00001085void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001086 VisitExpr(S);
1087 VisitDecl(S->getDecl());
1088 ID.AddBoolean(S->isArrow());
1089 ID.AddBoolean(S->isFreeIvar());
1090}
1091
Chandler Carruthb1138242011-06-16 06:47:06 +00001092void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001093 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +00001094 if (S->isImplicitProperty()) {
1095 VisitDecl(S->getImplicitPropertyGetter());
1096 VisitDecl(S->getImplicitPropertySetter());
1097 } else {
1098 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001099 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001100 if (S->isSuperReceiver()) {
1101 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +00001102 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001103 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001104}
1105
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001106void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1107 VisitExpr(S);
1108 VisitDecl(S->getAtIndexMethodDecl());
1109 VisitDecl(S->setAtIndexMethodDecl());
1110}
1111
Chandler Carruthb1138242011-06-16 06:47:06 +00001112void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001113 VisitExpr(S);
1114 VisitName(S->getSelector());
1115 VisitDecl(S->getMethodDecl());
1116}
1117
Chandler Carruthb1138242011-06-16 06:47:06 +00001118void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +00001119 VisitExpr(S);
1120 ID.AddBoolean(S->isArrow());
1121}
1122
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001123void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1124 VisitExpr(S);
1125 ID.AddBoolean(S->getValue());
1126}
1127
Chandler Carruthb1138242011-06-16 06:47:06 +00001128void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1129 const ObjCIndirectCopyRestoreExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +00001130 VisitExpr(S);
1131 ID.AddBoolean(S->shouldCopy());
1132}
1133
Chandler Carruthb1138242011-06-16 06:47:06 +00001134void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +00001135 VisitExplicitCastExpr(S);
1136 ID.AddBoolean(S->getBridgeKind());
1137}
1138
Chandler Carruthb1138242011-06-16 06:47:06 +00001139void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001140 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Douglas Gregorb1975722009-07-30 23:18:24 +00001142 if (Canonical && D) {
Chandler Carruthb1138242011-06-16 06:47:06 +00001143 if (const NonTypeTemplateParmDecl *NTTP =
1144 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +00001145 ID.AddInteger(NTTP->getDepth());
1146 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +00001147 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +00001148 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001149 return;
1150 }
Mike Stump1eb44332009-09-09 15:08:12 +00001151
Chandler Carruthb1138242011-06-16 06:47:06 +00001152 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCallfb44de92011-05-01 22:35:37 +00001153 // The Itanium C++ ABI uses the type, scope depth, and scope
1154 // index of a parameter when mangling expressions that involve
1155 // function parameters, so we will use the parameter's type for
1156 // establishing function parameter identity. That way, our
1157 // definition of "equivalent" (per C++ [temp.over.link]) is at
1158 // least as strong as the definition of "equivalent" used for
1159 // name mangling.
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001160 VisitType(Parm->getType());
John McCallfb44de92011-05-01 22:35:37 +00001161 ID.AddInteger(Parm->getFunctionScopeDepth());
1162 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001163 return;
1164 }
Mike Stump1eb44332009-09-09 15:08:12 +00001165
Richard Smith0f6931a2012-04-02 18:53:24 +00001166 if (const TemplateTypeParmDecl *TTP =
1167 dyn_cast<TemplateTypeParmDecl>(D)) {
1168 ID.AddInteger(TTP->getDepth());
1169 ID.AddInteger(TTP->getIndex());
1170 ID.AddBoolean(TTP->isParameterPack());
1171 return;
1172 }
1173
Chandler Carruthb1138242011-06-16 06:47:06 +00001174 if (const TemplateTemplateParmDecl *TTP =
1175 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregora2ffb982009-07-31 15:46:56 +00001176 ID.AddInteger(TTP->getDepth());
1177 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +00001178 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +00001179 return;
1180 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001181 }
Mike Stump1eb44332009-09-09 15:08:12 +00001182
Douglas Gregord584eb22009-07-28 15:32:17 +00001183 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1184}
1185
1186void StmtProfiler::VisitType(QualType T) {
1187 if (Canonical)
1188 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +00001189
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001190 ID.AddPointer(T.getAsOpaquePtr());
1191}
1192
1193void StmtProfiler::VisitName(DeclarationName Name) {
1194 ID.AddPointer(Name.getAsOpaquePtr());
1195}
1196
1197void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1198 if (Canonical)
1199 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1200 ID.AddPointer(NNS);
1201}
1202
1203void StmtProfiler::VisitTemplateName(TemplateName Name) {
1204 if (Canonical)
1205 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +00001206
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001207 Name.Profile(ID);
1208}
1209
John McCall833ca992009-10-29 08:12:44 +00001210void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001211 unsigned NumArgs) {
1212 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +00001213 for (unsigned I = 0; I != NumArgs; ++I)
1214 VisitTemplateArgument(Args[I].getArgument());
1215}
Mike Stump1eb44332009-09-09 15:08:12 +00001216
John McCall833ca992009-10-29 08:12:44 +00001217void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1218 // Mostly repetitive with TemplateArgument::Profile!
1219 ID.AddInteger(Arg.getKind());
1220 switch (Arg.getKind()) {
1221 case TemplateArgument::Null:
1222 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001223
John McCall833ca992009-10-29 08:12:44 +00001224 case TemplateArgument::Type:
1225 VisitType(Arg.getAsType());
1226 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001227
Douglas Gregor788cd062009-11-11 01:00:40 +00001228 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00001229 case TemplateArgument::TemplateExpansion:
1230 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +00001231 break;
Sean Huntc3021132010-05-05 15:23:54 +00001232
John McCall833ca992009-10-29 08:12:44 +00001233 case TemplateArgument::Declaration:
1234 VisitDecl(Arg.getAsDecl());
1235 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001236
Eli Friedmand7a6b162012-09-26 02:36:12 +00001237 case TemplateArgument::NullPtr:
1238 VisitType(Arg.getNullPtrType());
1239 break;
1240
John McCall833ca992009-10-29 08:12:44 +00001241 case TemplateArgument::Integral:
Benjamin Kramer85524372012-06-07 15:09:51 +00001242 Arg.getAsIntegral().Profile(ID);
John McCall833ca992009-10-29 08:12:44 +00001243 VisitType(Arg.getIntegralType());
1244 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001245
John McCall833ca992009-10-29 08:12:44 +00001246 case TemplateArgument::Expression:
1247 Visit(Arg.getAsExpr());
1248 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001249
John McCall833ca992009-10-29 08:12:44 +00001250 case TemplateArgument::Pack:
1251 const TemplateArgument *Pack = Arg.pack_begin();
1252 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1253 VisitTemplateArgument(Pack[i]);
1254 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001255 }
1256}
1257
Jay Foad4ba2a172011-01-12 09:06:06 +00001258void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruthb1138242011-06-16 06:47:06 +00001259 bool Canonical) const {
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001260 StmtProfiler Profiler(ID, Context, Canonical);
1261 Profiler.Visit(this);
1262}