blob: 9fc4c77e2c567d7db7f302f69b2c064a045f28ad [file] [log] [blame]
Douglas Gregor5c193b92009-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 Gregor32615a12009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor5c193b92009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregora7095092009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor5c193b92009-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 Gregor5c193b92009-07-28 00:33:38 +000023using namespace clang;
24
25namespace {
Chandler Carruth631abd92011-06-16 06:47:06 +000026 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Douglas Gregor5c193b92009-07-28 00:33:38 +000027 llvm::FoldingSetNodeID &ID;
Jay Foad39c79802011-01-12 09:06:06 +000028 const ASTContext &Context;
Douglas Gregor5c193b92009-07-28 00:33:38 +000029 bool Canonical;
Mike Stump11289f42009-09-09 15:08:12 +000030
Douglas Gregor5c193b92009-07-28 00:33:38 +000031 public:
Jay Foad39c79802011-01-12 09:06:06 +000032 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump11289f42009-09-09 15:08:12 +000033 bool Canonical)
Douglas Gregor5c193b92009-07-28 00:33:38 +000034 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump11289f42009-09-09 15:08:12 +000035
Chandler Carruth631abd92011-06-16 06:47:06 +000036 void VisitStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000037
Chandler Carruth631abd92011-06-16 06:47:06 +000038#define STMT(Node, Base) void Visit##Node(const Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000039#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000040
Douglas Gregor5c193b92009-07-28 00:33:38 +000041 /// \brief Visit a declaration that is referenced within an expression
42 /// or statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000043 void VisitDecl(const Decl *D);
Mike Stump11289f42009-09-09 15:08:12 +000044
45 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000046 /// statement.
47 void VisitType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +000048
Douglas Gregor5c193b92009-07-28 00:33:38 +000049 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
Mike Stump11289f42009-09-09 15:08:12 +000051
Douglas Gregor5c193b92009-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 Stump11289f42009-09-09 15:08:12 +000055
Douglas Gregor5c193b92009-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 Stump11289f42009-09-09 15:08:12 +000059
Douglas Gregor5c193b92009-07-28 00:33:38 +000060 /// \brief Visit template arguments that occur within an expression or
61 /// statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000062 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
63 unsigned NumArgs);
John McCall0ad16662009-10-29 08:12:44 +000064
65 /// \brief Visit a single template argument.
66 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor5c193b92009-07-28 00:33:38 +000067 };
68}
69
Chandler Carruth631abd92011-06-16 06:47:06 +000070void StmtProfiler::VisitStmt(const Stmt *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +000071 ID.AddInteger(S->getStmtClass());
Peter Collingbournecdb9f302012-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 Gregor5c193b92009-07-28 00:33:38 +000078}
79
Chandler Carruth631abd92011-06-16 06:47:06 +000080void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000081 VisitStmt(S);
Aaron Ballman535bbcc2014-03-14 17:01:24 +000082 for (const auto *D : S->decls())
83 VisitDecl(D);
Douglas Gregor44882592009-07-28 15:27:13 +000084}
85
Chandler Carruth631abd92011-06-16 06:47:06 +000086void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000087 VisitStmt(S);
88}
89
Chandler Carruth631abd92011-06-16 06:47:06 +000090void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000091 VisitStmt(S);
92}
93
Chandler Carruth631abd92011-06-16 06:47:06 +000094void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000095 VisitStmt(S);
96}
97
Chandler Carruth631abd92011-06-16 06:47:06 +000098void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000099 VisitStmt(S);
100}
101
Chandler Carruth631abd92011-06-16 06:47:06 +0000102void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000103 VisitStmt(S);
104}
105
Chandler Carruth631abd92011-06-16 06:47:06 +0000106void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000107 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000108 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000109}
110
Richard Smithc202b282012-04-14 00:33:13 +0000111void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
112 VisitStmt(S);
113 // TODO: maybe visit attributes?
114}
115
Chandler Carruth631abd92011-06-16 06:47:06 +0000116void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000117 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000118 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000119}
120
Chandler Carruth631abd92011-06-16 06:47:06 +0000121void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000122 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000123 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000124}
125
Chandler Carruth631abd92011-06-16 06:47:06 +0000126void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000127 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000128 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000129}
130
Chandler Carruth631abd92011-06-16 06:47:06 +0000131void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000132 VisitStmt(S);
133}
134
Chandler Carruth631abd92011-06-16 06:47:06 +0000135void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000136 VisitStmt(S);
137}
138
Chandler Carruth631abd92011-06-16 06:47:06 +0000139void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000140 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000141 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000142}
143
Chandler Carruth631abd92011-06-16 06:47:06 +0000144void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000145 VisitStmt(S);
146}
147
Chandler Carruth631abd92011-06-16 06:47:06 +0000148void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000149 VisitStmt(S);
150}
151
Chandler Carruth631abd92011-06-16 06:47:06 +0000152void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000153 VisitStmt(S);
154}
155
Chandler Carruth631abd92011-06-16 06:47:06 +0000156void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000157 VisitStmt(S);
158}
159
Chad Rosierde70e0e2012-08-25 00:11:56 +0000160void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000161 VisitStmt(S);
162 ID.AddBoolean(S->isVolatile());
163 ID.AddBoolean(S->isSimple());
164 VisitStringLiteral(S->getAsmString());
165 ID.AddInteger(S->getNumOutputs());
166 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
167 ID.AddString(S->getOutputName(I));
168 VisitStringLiteral(S->getOutputConstraintLiteral(I));
169 }
170 ID.AddInteger(S->getNumInputs());
171 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
172 ID.AddString(S->getInputName(I));
173 VisitStringLiteral(S->getInputConstraintLiteral(I));
174 }
175 ID.AddInteger(S->getNumClobbers());
176 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000177 VisitStringLiteral(S->getClobberStringLiteral(I));
Douglas Gregor44882592009-07-28 15:27:13 +0000178}
179
Chad Rosier32503022012-06-11 20:47:18 +0000180void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
181 // FIXME: Implement MS style inline asm statement profiler.
182 VisitStmt(S);
183}
184
Chandler Carruth631abd92011-06-16 06:47:06 +0000185void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000186 VisitStmt(S);
187 VisitType(S->getCaughtType());
188}
189
Chandler Carruth631abd92011-06-16 06:47:06 +0000190void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000191 VisitStmt(S);
192}
193
Chandler Carruth631abd92011-06-16 06:47:06 +0000194void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000195 VisitStmt(S);
196}
197
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000198void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
199 VisitStmt(S);
200 ID.AddBoolean(S->isIfExists());
201 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
202 VisitName(S->getNameInfo().getName());
203}
204
Chandler Carruth631abd92011-06-16 06:47:06 +0000205void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000206 VisitStmt(S);
207}
208
Chandler Carruth631abd92011-06-16 06:47:06 +0000209void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000210 VisitStmt(S);
211}
212
Chandler Carruth631abd92011-06-16 06:47:06 +0000213void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000214 VisitStmt(S);
215}
216
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000217void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
218 VisitStmt(S);
219}
220
Chandler Carruth631abd92011-06-16 06:47:06 +0000221void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000222 VisitStmt(S);
223}
224
Chandler Carruth631abd92011-06-16 06:47:06 +0000225void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000226 VisitStmt(S);
227 ID.AddBoolean(S->hasEllipsis());
228 if (S->getCatchParamDecl())
229 VisitType(S->getCatchParamDecl()->getType());
230}
231
Chandler Carruth631abd92011-06-16 06:47:06 +0000232void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000233 VisitStmt(S);
234}
235
Chandler Carruth631abd92011-06-16 06:47:06 +0000236void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000237 VisitStmt(S);
238}
239
Chandler Carruth631abd92011-06-16 06:47:06 +0000240void
241StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000242 VisitStmt(S);
243}
244
Chandler Carruth631abd92011-06-16 06:47:06 +0000245void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000246 VisitStmt(S);
247}
248
Chandler Carruth631abd92011-06-16 06:47:06 +0000249void
250StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000251 VisitStmt(S);
252}
253
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000254namespace {
255class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
256 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000257 /// \brief Process clauses with list of variables.
258 template <typename T>
259 void VisitOMPClauseList(T *Node);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000260public:
261 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
262#define OPENMP_CLAUSE(Name, Class) \
263 void Visit##Class(const Class *C);
264#include "clang/Basic/OpenMPKinds.def"
265};
266
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000267void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
268 if (C->getCondition())
269 Profiler->VisitStmt(C->getCondition());
270}
271
Alexey Bataev568a8332014-03-06 06:15:19 +0000272void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
273 if (C->getNumThreads())
274 Profiler->VisitStmt(C->getNumThreads());
275}
276
Alexey Bataev62c87d22014-03-21 04:51:18 +0000277void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
278 if (C->getSafelen())
279 Profiler->VisitStmt(C->getSafelen());
280}
281
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000282void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000283
284template<typename T>
285void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Aaron Ballman2205d2a2014-03-14 15:55:35 +0000286 for (auto *I : Node->varlists())
287 Profiler->VisitStmt(I);
Alexey Bataev756c1962013-09-24 03:17:45 +0000288}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000289
290void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000291 VisitOMPClauseList(C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000292}
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000293void OMPClauseProfiler::VisitOMPFirstprivateClause(
294 const OMPFirstprivateClause *C) {
295 VisitOMPClauseList(C);
296}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000297void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000298 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000299}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000300}
301
302void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000303StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000304 VisitStmt(S);
305 OMPClauseProfiler P(this);
306 ArrayRef<OMPClause *> Clauses = S->clauses();
307 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
308 I != E; ++I)
309 if (*I)
310 P.Visit(*I);
311}
312
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000313void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
314 VisitOMPExecutableDirective(S);
315}
316
317void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
318 VisitOMPExecutableDirective(S);
319}
320
Chandler Carruth631abd92011-06-16 06:47:06 +0000321void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000322 VisitStmt(S);
323}
324
Chandler Carruth631abd92011-06-16 06:47:06 +0000325void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000326 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000327 if (!Canonical)
328 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000329 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000330 if (!Canonical)
331 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000332}
333
Chandler Carruth631abd92011-06-16 06:47:06 +0000334void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000335 VisitExpr(S);
336 ID.AddInteger(S->getIdentType());
337}
338
Chandler Carruth631abd92011-06-16 06:47:06 +0000339void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000340 VisitExpr(S);
341 S->getValue().Profile(ID);
342}
343
Chandler Carruth631abd92011-06-16 06:47:06 +0000344void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000345 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000346 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000347 ID.AddInteger(S->getValue());
348}
349
Chandler Carruth631abd92011-06-16 06:47:06 +0000350void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000351 VisitExpr(S);
352 S->getValue().Profile(ID);
353 ID.AddBoolean(S->isExact());
354}
355
Chandler Carruth631abd92011-06-16 06:47:06 +0000356void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000357 VisitExpr(S);
358}
359
Chandler Carruth631abd92011-06-16 06:47:06 +0000360void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000361 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000362 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000363 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000364}
365
Chandler Carruth631abd92011-06-16 06:47:06 +0000366void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000367 VisitExpr(S);
368}
369
Chandler Carruth631abd92011-06-16 06:47:06 +0000370void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000371 VisitExpr(S);
372}
373
Chandler Carruth631abd92011-06-16 06:47:06 +0000374void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000375 VisitExpr(S);
376 ID.AddInteger(S->getOpcode());
377}
378
Chandler Carruth631abd92011-06-16 06:47:06 +0000379void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000380 VisitType(S->getTypeSourceInfo()->getType());
381 unsigned n = S->getNumComponents();
382 for (unsigned i = 0; i < n; ++i) {
383 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
384 ID.AddInteger(ON.getKind());
385 switch (ON.getKind()) {
386 case OffsetOfExpr::OffsetOfNode::Array:
387 // Expressions handled below.
388 break;
389
390 case OffsetOfExpr::OffsetOfNode::Field:
391 VisitDecl(ON.getField());
392 break;
393
394 case OffsetOfExpr::OffsetOfNode::Identifier:
395 ID.AddPointer(ON.getFieldName());
396 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000397
Douglas Gregord1702062010-04-29 00:18:15 +0000398 case OffsetOfExpr::OffsetOfNode::Base:
399 // These nodes are implicit, and therefore don't need profiling.
400 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000401 }
402 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000403
Douglas Gregor882211c2010-04-28 22:16:22 +0000404 VisitExpr(S);
405}
406
Chandler Carruth631abd92011-06-16 06:47:06 +0000407void
408StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000409 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000410 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000411 if (S->isArgumentType())
412 VisitType(S->getArgumentType());
413}
414
Chandler Carruth631abd92011-06-16 06:47:06 +0000415void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000416 VisitExpr(S);
417}
418
Chandler Carruth631abd92011-06-16 06:47:06 +0000419void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000420 VisitExpr(S);
421}
422
Chandler Carruth631abd92011-06-16 06:47:06 +0000423void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000424 VisitExpr(S);
425 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000426 if (!Canonical)
427 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000428 ID.AddBoolean(S->isArrow());
429}
430
Chandler Carruth631abd92011-06-16 06:47:06 +0000431void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000432 VisitExpr(S);
433 ID.AddBoolean(S->isFileScope());
434}
435
Chandler Carruth631abd92011-06-16 06:47:06 +0000436void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000437 VisitExpr(S);
438}
439
Chandler Carruth631abd92011-06-16 06:47:06 +0000440void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000441 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000442 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000443}
444
Chandler Carruth631abd92011-06-16 06:47:06 +0000445void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000446 VisitCastExpr(S);
447 VisitType(S->getTypeAsWritten());
448}
449
Chandler Carruth631abd92011-06-16 06:47:06 +0000450void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000451 VisitExplicitCastExpr(S);
452}
453
Chandler Carruth631abd92011-06-16 06:47:06 +0000454void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000455 VisitExpr(S);
456 ID.AddInteger(S->getOpcode());
457}
458
Chandler Carruth631abd92011-06-16 06:47:06 +0000459void
460StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000461 VisitBinaryOperator(S);
462}
463
Chandler Carruth631abd92011-06-16 06:47:06 +0000464void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000465 VisitExpr(S);
466}
467
Chandler Carruth631abd92011-06-16 06:47:06 +0000468void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000469 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000470 VisitExpr(S);
471}
472
Chandler Carruth631abd92011-06-16 06:47:06 +0000473void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000474 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000475 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000476}
477
Chandler Carruth631abd92011-06-16 06:47:06 +0000478void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000479 VisitExpr(S);
480}
481
Chandler Carruth631abd92011-06-16 06:47:06 +0000482void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000483 VisitExpr(S);
484}
485
Hal Finkelc4d7c822013-09-18 03:29:45 +0000486void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
487 VisitExpr(S);
488}
489
Chandler Carruth631abd92011-06-16 06:47:06 +0000490void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000491 VisitExpr(S);
492}
493
Chandler Carruth631abd92011-06-16 06:47:06 +0000494void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000495 VisitExpr(S);
496}
497
Chandler Carruth631abd92011-06-16 06:47:06 +0000498void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000499 VisitExpr(S);
500}
501
Chandler Carruth631abd92011-06-16 06:47:06 +0000502void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000503 if (S->getSyntacticForm()) {
504 VisitInitListExpr(S->getSyntacticForm());
505 return;
506 }
Mike Stump11289f42009-09-09 15:08:12 +0000507
Douglas Gregor5c193b92009-07-28 00:33:38 +0000508 VisitExpr(S);
509}
510
Chandler Carruth631abd92011-06-16 06:47:06 +0000511void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000512 VisitExpr(S);
513 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000514 for (DesignatedInitExpr::const_designators_iterator D =
515 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000516 D != DEnd; ++D) {
517 if (D->isFieldDesignator()) {
518 ID.AddInteger(0);
519 VisitName(D->getFieldName());
520 continue;
521 }
Mike Stump11289f42009-09-09 15:08:12 +0000522
Douglas Gregor5c193b92009-07-28 00:33:38 +0000523 if (D->isArrayDesignator()) {
524 ID.AddInteger(1);
525 } else {
526 assert(D->isArrayRangeDesignator());
527 ID.AddInteger(2);
528 }
529 ID.AddInteger(D->getFirstExprIndex());
530 }
531}
532
Chandler Carruth631abd92011-06-16 06:47:06 +0000533void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000534 VisitExpr(S);
535}
536
Chandler Carruth631abd92011-06-16 06:47:06 +0000537void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000538 VisitExpr(S);
539 VisitName(&S->getAccessor());
540}
541
Chandler Carruth631abd92011-06-16 06:47:06 +0000542void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000543 VisitExpr(S);
544 VisitDecl(S->getBlockDecl());
545}
546
Chandler Carruth631abd92011-06-16 06:47:06 +0000547void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000548 VisitExpr(S);
549 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
550 QualType T = S->getAssocType(i);
551 if (T.isNull())
552 ID.AddPointer(0);
553 else
554 VisitType(T);
555 VisitExpr(S->getAssocExpr(i));
556 }
557}
558
John McCallfe96e0b2011-11-06 09:01:30 +0000559void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
560 VisitExpr(S);
561 for (PseudoObjectExpr::const_semantics_iterator
562 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
563 // Normally, we would not profile the source expressions of OVEs.
564 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
565 Visit(OVE->getSourceExpr());
566}
567
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000568void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
569 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000570 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000571}
572
Chandler Carruth631abd92011-06-16 06:47:06 +0000573static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000574 UnaryOperatorKind &UnaryOp,
575 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000576 switch (S->getOperator()) {
577 case OO_None:
578 case OO_New:
579 case OO_Delete:
580 case OO_Array_New:
581 case OO_Array_Delete:
582 case OO_Arrow:
583 case OO_Call:
584 case OO_Conditional:
585 case NUM_OVERLOADED_OPERATORS:
586 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000587
588 case OO_Plus:
589 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000590 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000591 return Stmt::UnaryOperatorClass;
592 }
593
John McCalle3027922010-08-25 11:45:40 +0000594 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000595 return Stmt::BinaryOperatorClass;
596
597 case OO_Minus:
598 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000599 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000600 return Stmt::UnaryOperatorClass;
601 }
602
John McCalle3027922010-08-25 11:45:40 +0000603 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000604 return Stmt::BinaryOperatorClass;
605
606 case OO_Star:
607 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000608 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000609 return Stmt::UnaryOperatorClass;
610 }
611
John McCalle3027922010-08-25 11:45:40 +0000612 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000613 return Stmt::BinaryOperatorClass;
614
615 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000616 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000617 return Stmt::BinaryOperatorClass;
618
619 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000620 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000621 return Stmt::BinaryOperatorClass;
622
623 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000624 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000625 return Stmt::BinaryOperatorClass;
626
627 case OO_Amp:
628 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000629 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000630 return Stmt::UnaryOperatorClass;
631 }
632
John McCalle3027922010-08-25 11:45:40 +0000633 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000634 return Stmt::BinaryOperatorClass;
635
636 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000637 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000638 return Stmt::BinaryOperatorClass;
639
640 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000641 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000642 return Stmt::UnaryOperatorClass;
643
644 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000645 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000646 return Stmt::UnaryOperatorClass;
647
648 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000649 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000650 return Stmt::BinaryOperatorClass;
651
652 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000653 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000654 return Stmt::BinaryOperatorClass;
655
656 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000657 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000658 return Stmt::BinaryOperatorClass;
659
660 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000661 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000662 return Stmt::CompoundAssignOperatorClass;
663
664 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000665 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000666 return Stmt::CompoundAssignOperatorClass;
667
668 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000669 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000670 return Stmt::CompoundAssignOperatorClass;
671
672 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000673 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000674 return Stmt::CompoundAssignOperatorClass;
675
676 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000677 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000678 return Stmt::CompoundAssignOperatorClass;
679
680 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000681 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000682 return Stmt::CompoundAssignOperatorClass;
683
684 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000685 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000686 return Stmt::CompoundAssignOperatorClass;
687
688 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000689 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000690 return Stmt::CompoundAssignOperatorClass;
691
692 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000693 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000694 return Stmt::BinaryOperatorClass;
695
696 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000697 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000698 return Stmt::BinaryOperatorClass;
699
700 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000701 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000702 return Stmt::CompoundAssignOperatorClass;
703
704 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000705 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000706 return Stmt::CompoundAssignOperatorClass;
707
708 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000709 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000710 return Stmt::BinaryOperatorClass;
711
712 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000713 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000714 return Stmt::BinaryOperatorClass;
715
716 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000717 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000718 return Stmt::BinaryOperatorClass;
719
720 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000721 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000722 return Stmt::BinaryOperatorClass;
723
724 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000725 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000726 return Stmt::BinaryOperatorClass;
727
728 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000729 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000730 return Stmt::BinaryOperatorClass;
731
732 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000733 UnaryOp = S->getNumArgs() == 1? UO_PreInc
734 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000735 return Stmt::UnaryOperatorClass;
736
737 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000738 UnaryOp = S->getNumArgs() == 1? UO_PreDec
739 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000740 return Stmt::UnaryOperatorClass;
741
742 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000743 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000744 return Stmt::BinaryOperatorClass;
745
746
747 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000748 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000749 return Stmt::BinaryOperatorClass;
750
751 case OO_Subscript:
752 return Stmt::ArraySubscriptExprClass;
753 }
754
755 llvm_unreachable("Invalid overloaded operator expression");
756}
757
758
Chandler Carruth631abd92011-06-16 06:47:06 +0000759void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000760 if (S->isTypeDependent()) {
761 // Type-dependent operator calls are profiled like their underlying
762 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000763 UnaryOperatorKind UnaryOp = UO_Extension;
764 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000765 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
766
767 ID.AddInteger(SC);
768 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
769 Visit(S->getArg(I));
770 if (SC == Stmt::UnaryOperatorClass)
771 ID.AddInteger(UnaryOp);
772 else if (SC == Stmt::BinaryOperatorClass ||
773 SC == Stmt::CompoundAssignOperatorClass)
774 ID.AddInteger(BinaryOp);
775 else
776 assert(SC == Stmt::ArraySubscriptExprClass);
777
778 return;
779 }
780
Douglas Gregor5c193b92009-07-28 00:33:38 +0000781 VisitCallExpr(S);
782 ID.AddInteger(S->getOperator());
783}
784
Chandler Carruth631abd92011-06-16 06:47:06 +0000785void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000786 VisitCallExpr(S);
787}
788
Chandler Carruth631abd92011-06-16 06:47:06 +0000789void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000790 VisitCallExpr(S);
791}
792
Chandler Carruth631abd92011-06-16 06:47:06 +0000793void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000794 VisitExpr(S);
795}
796
Chandler Carruth631abd92011-06-16 06:47:06 +0000797void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000798 VisitExplicitCastExpr(S);
799}
800
Chandler Carruth631abd92011-06-16 06:47:06 +0000801void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000802 VisitCXXNamedCastExpr(S);
803}
804
Chandler Carruth631abd92011-06-16 06:47:06 +0000805void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000806 VisitCXXNamedCastExpr(S);
807}
808
Chandler Carruth631abd92011-06-16 06:47:06 +0000809void
810StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000811 VisitCXXNamedCastExpr(S);
812}
813
Chandler Carruth631abd92011-06-16 06:47:06 +0000814void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000815 VisitCXXNamedCastExpr(S);
816}
817
Richard Smithc67fdd42012-03-07 08:35:16 +0000818void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
819 VisitCallExpr(S);
820}
821
Chandler Carruth631abd92011-06-16 06:47:06 +0000822void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000823 VisitExpr(S);
824 ID.AddBoolean(S->getValue());
825}
826
Chandler Carruth631abd92011-06-16 06:47:06 +0000827void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000828 VisitExpr(S);
829}
830
Richard Smithcc1b96d2013-06-12 22:31:48 +0000831void StmtProfiler::VisitCXXStdInitializerListExpr(
832 const CXXStdInitializerListExpr *S) {
833 VisitExpr(S);
834}
835
Chandler Carruth631abd92011-06-16 06:47:06 +0000836void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000837 VisitExpr(S);
838 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000839 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000840}
841
Chandler Carruth631abd92011-06-16 06:47:06 +0000842void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000843 VisitExpr(S);
844 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000845 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000846}
847
John McCall5e77d762013-04-16 07:28:30 +0000848void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
849 VisitExpr(S);
850 VisitDecl(S->getPropertyDecl());
851}
852
Chandler Carruth631abd92011-06-16 06:47:06 +0000853void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000854 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000855 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000856}
857
Chandler Carruth631abd92011-06-16 06:47:06 +0000858void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000859 VisitExpr(S);
860}
861
Chandler Carruth631abd92011-06-16 06:47:06 +0000862void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000863 VisitExpr(S);
864 VisitDecl(S->getParam());
865}
866
Richard Smith852c9db2013-04-20 22:23:05 +0000867void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
868 VisitExpr(S);
869 VisitDecl(S->getField());
870}
871
Chandler Carruth631abd92011-06-16 06:47:06 +0000872void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000873 VisitExpr(S);
874 VisitDecl(
875 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
876}
877
Chandler Carruth631abd92011-06-16 06:47:06 +0000878void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000879 VisitExpr(S);
880 VisitDecl(S->getConstructor());
881 ID.AddBoolean(S->isElidable());
882}
883
Chandler Carruth631abd92011-06-16 06:47:06 +0000884void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000885 VisitExplicitCastExpr(S);
886}
887
Chandler Carruth631abd92011-06-16 06:47:06 +0000888void
889StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000890 VisitCXXConstructExpr(S);
891}
892
Chandler Carruth631abd92011-06-16 06:47:06 +0000893void
Douglas Gregore31e6062012-02-07 10:09:13 +0000894StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
895 VisitExpr(S);
896 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
897 CEnd = S->explicit_capture_end();
898 C != CEnd; ++C) {
899 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +0000900 switch (C->getCaptureKind()) {
901 case LCK_This:
902 break;
903 case LCK_ByRef:
904 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +0000905 VisitDecl(C->getCapturedVar());
906 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +0000907 break;
Douglas Gregore31e6062012-02-07 10:09:13 +0000908 }
909 }
910 // Note: If we actually needed to be able to match lambda
911 // expressions, we would have to consider parameters and return type
912 // here, among other things.
913 VisitStmt(S->getBody());
914}
915
916void
Chandler Carruth631abd92011-06-16 06:47:06 +0000917StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000918 VisitExpr(S);
919}
920
Chandler Carruth631abd92011-06-16 06:47:06 +0000921void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000922 VisitExpr(S);
923 ID.AddBoolean(S->isGlobalDelete());
924 ID.AddBoolean(S->isArrayForm());
925 VisitDecl(S->getOperatorDelete());
926}
927
928
Chandler Carruth631abd92011-06-16 06:47:06 +0000929void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000930 VisitExpr(S);
931 VisitType(S->getAllocatedType());
932 VisitDecl(S->getOperatorNew());
933 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000934 ID.AddBoolean(S->isArray());
935 ID.AddInteger(S->getNumPlacementArgs());
936 ID.AddBoolean(S->isGlobalNew());
937 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +0000938 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000939}
940
Chandler Carruth631abd92011-06-16 06:47:06 +0000941void
942StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +0000943 VisitExpr(S);
944 ID.AddBoolean(S->isArrow());
945 VisitNestedNameSpecifier(S->getQualifier());
Eli Friedman85641392013-08-09 23:37:05 +0000946 ID.AddBoolean(S->getScopeTypeInfo() != 0);
947 if (S->getScopeTypeInfo())
948 VisitType(S->getScopeTypeInfo()->getType());
949 ID.AddBoolean(S->getDestroyedTypeInfo() != 0);
950 if (S->getDestroyedTypeInfo())
951 VisitType(S->getDestroyedType());
952 else
953 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +0000954}
955
Chandler Carruth631abd92011-06-16 06:47:06 +0000956void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000957 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000958 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000959 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +0000960 ID.AddBoolean(S->hasExplicitTemplateArgs());
961 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000962 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
963 S->getExplicitTemplateArgs().NumTemplateArgs);
964}
965
966void
Chandler Carruth631abd92011-06-16 06:47:06 +0000967StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000968 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +0000969}
970
Douglas Gregor29c42f22012-02-24 07:38:34 +0000971void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
972 VisitExpr(S);
973 ID.AddInteger(S->getTrait());
974 ID.AddInteger(S->getNumArgs());
975 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
976 VisitType(S->getArg(I)->getType());
977}
978
Chandler Carruth631abd92011-06-16 06:47:06 +0000979void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +0000980 VisitExpr(S);
981 ID.AddInteger(S->getTrait());
982 VisitType(S->getQueriedType());
983}
984
Chandler Carruth631abd92011-06-16 06:47:06 +0000985void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +0000986 VisitExpr(S);
987 ID.AddInteger(S->getTrait());
988 VisitExpr(S->getQueriedExpression());
989}
990
Chandler Carruth631abd92011-06-16 06:47:06 +0000991void StmtProfiler::VisitDependentScopeDeclRefExpr(
992 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000993 VisitExpr(S);
994 VisitName(S->getDeclName());
995 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +0000996 ID.AddBoolean(S->hasExplicitTemplateArgs());
997 if (S->hasExplicitTemplateArgs())
998 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000999}
1000
Chandler Carruth631abd92011-06-16 06:47:06 +00001001void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001002 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001003}
1004
Chandler Carruth631abd92011-06-16 06:47:06 +00001005void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1006 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001007 VisitExpr(S);
1008 VisitType(S->getTypeAsWritten());
1009}
1010
Chandler Carruth631abd92011-06-16 06:47:06 +00001011void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1012 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001013 ID.AddBoolean(S->isImplicitAccess());
1014 if (!S->isImplicitAccess()) {
1015 VisitExpr(S);
1016 ID.AddBoolean(S->isArrow());
1017 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001018 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001019 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001020 ID.AddBoolean(S->hasExplicitTemplateArgs());
1021 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001022 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1023}
1024
Chandler Carruth631abd92011-06-16 06:47:06 +00001025void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001026 ID.AddBoolean(S->isImplicitAccess());
1027 if (!S->isImplicitAccess()) {
1028 VisitExpr(S);
1029 ID.AddBoolean(S->isArrow());
1030 }
John McCall10eae182009-11-30 22:42:35 +00001031 VisitNestedNameSpecifier(S->getQualifier());
1032 VisitName(S->getMemberName());
1033 ID.AddBoolean(S->hasExplicitTemplateArgs());
1034 if (S->hasExplicitTemplateArgs())
1035 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001036}
1037
Chandler Carruth631abd92011-06-16 06:47:06 +00001038void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001039 VisitExpr(S);
1040}
1041
Chandler Carruth631abd92011-06-16 06:47:06 +00001042void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001043 VisitExpr(S);
1044}
1045
Chandler Carruth631abd92011-06-16 06:47:06 +00001046void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001047 VisitExpr(S);
1048 VisitDecl(S->getPack());
1049}
1050
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001051void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001052 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001053 VisitExpr(S);
1054 VisitDecl(S->getParameterPack());
1055 VisitTemplateArgument(S->getArgumentPack());
1056}
1057
John McCall7c454bb2011-07-15 05:09:51 +00001058void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1059 const SubstNonTypeTemplateParmExpr *E) {
1060 // Profile exactly as the replacement expression.
1061 Visit(E->getReplacement());
1062}
1063
Richard Smithb15fe3a2012-09-12 00:56:43 +00001064void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1065 VisitExpr(S);
1066 VisitDecl(S->getParameterPack());
1067 ID.AddInteger(S->getNumExpansions());
1068 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1069 VisitDecl(*I);
1070}
1071
Douglas Gregorfe314812011-06-21 17:03:29 +00001072void StmtProfiler::VisitMaterializeTemporaryExpr(
1073 const MaterializeTemporaryExpr *S) {
1074 VisitExpr(S);
1075}
1076
Chandler Carruth631abd92011-06-16 06:47:06 +00001077void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001078 VisitExpr(E);
1079}
1080
Chandler Carruth631abd92011-06-16 06:47:06 +00001081void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001082 VisitExpr(S);
1083}
1084
Patrick Beard0caa3942012-04-19 00:25:12 +00001085void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001086 VisitExpr(E);
1087}
1088
1089void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1090 VisitExpr(E);
1091}
1092
1093void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1094 VisitExpr(E);
1095}
1096
Chandler Carruth631abd92011-06-16 06:47:06 +00001097void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001098 VisitExpr(S);
1099 VisitType(S->getEncodedType());
1100}
1101
Chandler Carruth631abd92011-06-16 06:47:06 +00001102void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001103 VisitExpr(S);
1104 VisitName(S->getSelector());
1105}
1106
Chandler Carruth631abd92011-06-16 06:47:06 +00001107void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001108 VisitExpr(S);
1109 VisitDecl(S->getProtocol());
1110}
1111
Chandler Carruth631abd92011-06-16 06:47:06 +00001112void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001113 VisitExpr(S);
1114 VisitDecl(S->getDecl());
1115 ID.AddBoolean(S->isArrow());
1116 ID.AddBoolean(S->isFreeIvar());
1117}
1118
Chandler Carruth631abd92011-06-16 06:47:06 +00001119void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001120 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001121 if (S->isImplicitProperty()) {
1122 VisitDecl(S->getImplicitPropertyGetter());
1123 VisitDecl(S->getImplicitPropertySetter());
1124 } else {
1125 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001126 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001127 if (S->isSuperReceiver()) {
1128 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001129 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001130 }
Douglas Gregora7095092009-07-28 14:44:31 +00001131}
1132
Ted Kremeneke65b0862012-03-06 20:05:56 +00001133void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1134 VisitExpr(S);
1135 VisitDecl(S->getAtIndexMethodDecl());
1136 VisitDecl(S->setAtIndexMethodDecl());
1137}
1138
Chandler Carruth631abd92011-06-16 06:47:06 +00001139void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001140 VisitExpr(S);
1141 VisitName(S->getSelector());
1142 VisitDecl(S->getMethodDecl());
1143}
1144
Chandler Carruth631abd92011-06-16 06:47:06 +00001145void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001146 VisitExpr(S);
1147 ID.AddBoolean(S->isArrow());
1148}
1149
Ted Kremeneke65b0862012-03-06 20:05:56 +00001150void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1151 VisitExpr(S);
1152 ID.AddBoolean(S->getValue());
1153}
1154
Chandler Carruth631abd92011-06-16 06:47:06 +00001155void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1156 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001157 VisitExpr(S);
1158 ID.AddBoolean(S->shouldCopy());
1159}
1160
Chandler Carruth631abd92011-06-16 06:47:06 +00001161void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001162 VisitExplicitCastExpr(S);
1163 ID.AddBoolean(S->getBridgeKind());
1164}
1165
Chandler Carruth631abd92011-06-16 06:47:06 +00001166void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001167 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001168
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001169 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001170 if (const NonTypeTemplateParmDecl *NTTP =
1171 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001172 ID.AddInteger(NTTP->getDepth());
1173 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001174 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001175 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001176 return;
1177 }
Mike Stump11289f42009-09-09 15:08:12 +00001178
Chandler Carruth631abd92011-06-16 06:47:06 +00001179 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001180 // The Itanium C++ ABI uses the type, scope depth, and scope
1181 // index of a parameter when mangling expressions that involve
1182 // function parameters, so we will use the parameter's type for
1183 // establishing function parameter identity. That way, our
1184 // definition of "equivalent" (per C++ [temp.over.link]) is at
1185 // least as strong as the definition of "equivalent" used for
1186 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001187 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001188 ID.AddInteger(Parm->getFunctionScopeDepth());
1189 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001190 return;
1191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Richard Smithd9a1cd82012-04-02 18:53:24 +00001193 if (const TemplateTypeParmDecl *TTP =
1194 dyn_cast<TemplateTypeParmDecl>(D)) {
1195 ID.AddInteger(TTP->getDepth());
1196 ID.AddInteger(TTP->getIndex());
1197 ID.AddBoolean(TTP->isParameterPack());
1198 return;
1199 }
1200
Chandler Carruth631abd92011-06-16 06:47:06 +00001201 if (const TemplateTemplateParmDecl *TTP =
1202 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001203 ID.AddInteger(TTP->getDepth());
1204 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001205 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001206 return;
1207 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001210 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1211}
1212
1213void StmtProfiler::VisitType(QualType T) {
1214 if (Canonical)
1215 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001216
Douglas Gregor5c193b92009-07-28 00:33:38 +00001217 ID.AddPointer(T.getAsOpaquePtr());
1218}
1219
1220void StmtProfiler::VisitName(DeclarationName Name) {
1221 ID.AddPointer(Name.getAsOpaquePtr());
1222}
1223
1224void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1225 if (Canonical)
1226 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1227 ID.AddPointer(NNS);
1228}
1229
1230void StmtProfiler::VisitTemplateName(TemplateName Name) {
1231 if (Canonical)
1232 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001233
Douglas Gregor5c193b92009-07-28 00:33:38 +00001234 Name.Profile(ID);
1235}
1236
John McCall0ad16662009-10-29 08:12:44 +00001237void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001238 unsigned NumArgs) {
1239 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001240 for (unsigned I = 0; I != NumArgs; ++I)
1241 VisitTemplateArgument(Args[I].getArgument());
1242}
Mike Stump11289f42009-09-09 15:08:12 +00001243
John McCall0ad16662009-10-29 08:12:44 +00001244void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1245 // Mostly repetitive with TemplateArgument::Profile!
1246 ID.AddInteger(Arg.getKind());
1247 switch (Arg.getKind()) {
1248 case TemplateArgument::Null:
1249 break;
Mike Stump11289f42009-09-09 15:08:12 +00001250
John McCall0ad16662009-10-29 08:12:44 +00001251 case TemplateArgument::Type:
1252 VisitType(Arg.getAsType());
1253 break;
Mike Stump11289f42009-09-09 15:08:12 +00001254
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001255 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001256 case TemplateArgument::TemplateExpansion:
1257 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001258 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001259
John McCall0ad16662009-10-29 08:12:44 +00001260 case TemplateArgument::Declaration:
1261 VisitDecl(Arg.getAsDecl());
1262 break;
Mike Stump11289f42009-09-09 15:08:12 +00001263
Eli Friedmanb826a002012-09-26 02:36:12 +00001264 case TemplateArgument::NullPtr:
1265 VisitType(Arg.getNullPtrType());
1266 break;
1267
John McCall0ad16662009-10-29 08:12:44 +00001268 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001269 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001270 VisitType(Arg.getIntegralType());
1271 break;
Mike Stump11289f42009-09-09 15:08:12 +00001272
John McCall0ad16662009-10-29 08:12:44 +00001273 case TemplateArgument::Expression:
1274 Visit(Arg.getAsExpr());
1275 break;
Mike Stump11289f42009-09-09 15:08:12 +00001276
John McCall0ad16662009-10-29 08:12:44 +00001277 case TemplateArgument::Pack:
1278 const TemplateArgument *Pack = Arg.pack_begin();
1279 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1280 VisitTemplateArgument(Pack[i]);
1281 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001282 }
1283}
1284
Jay Foad39c79802011-01-12 09:06:06 +00001285void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001286 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001287 StmtProfiler Profiler(ID, Context, Canonical);
1288 Profiler.Visit(this);
1289}