blob: 07ed86a91cd8bd613064a1aceca704420741fa18 [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 Bataevd48bcd82014-03-31 03:36:38 +0000300void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
301 VisitOMPClauseList(C);
302}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000303}
304
305void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000306StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000307 VisitStmt(S);
308 OMPClauseProfiler P(this);
309 ArrayRef<OMPClause *> Clauses = S->clauses();
310 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
311 I != E; ++I)
312 if (*I)
313 P.Visit(*I);
314}
315
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000316void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
317 VisitOMPExecutableDirective(S);
318}
319
320void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
321 VisitOMPExecutableDirective(S);
322}
323
Chandler Carruth631abd92011-06-16 06:47:06 +0000324void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000325 VisitStmt(S);
326}
327
Chandler Carruth631abd92011-06-16 06:47:06 +0000328void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000329 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000330 if (!Canonical)
331 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000332 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000333 if (!Canonical)
334 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000335}
336
Chandler Carruth631abd92011-06-16 06:47:06 +0000337void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000338 VisitExpr(S);
339 ID.AddInteger(S->getIdentType());
340}
341
Chandler Carruth631abd92011-06-16 06:47:06 +0000342void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000343 VisitExpr(S);
344 S->getValue().Profile(ID);
345}
346
Chandler Carruth631abd92011-06-16 06:47:06 +0000347void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000348 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000349 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000350 ID.AddInteger(S->getValue());
351}
352
Chandler Carruth631abd92011-06-16 06:47:06 +0000353void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000354 VisitExpr(S);
355 S->getValue().Profile(ID);
356 ID.AddBoolean(S->isExact());
357}
358
Chandler Carruth631abd92011-06-16 06:47:06 +0000359void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000360 VisitExpr(S);
361}
362
Chandler Carruth631abd92011-06-16 06:47:06 +0000363void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000364 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000365 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000366 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000367}
368
Chandler Carruth631abd92011-06-16 06:47:06 +0000369void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000370 VisitExpr(S);
371}
372
Chandler Carruth631abd92011-06-16 06:47:06 +0000373void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000374 VisitExpr(S);
375}
376
Chandler Carruth631abd92011-06-16 06:47:06 +0000377void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000378 VisitExpr(S);
379 ID.AddInteger(S->getOpcode());
380}
381
Chandler Carruth631abd92011-06-16 06:47:06 +0000382void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000383 VisitType(S->getTypeSourceInfo()->getType());
384 unsigned n = S->getNumComponents();
385 for (unsigned i = 0; i < n; ++i) {
386 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
387 ID.AddInteger(ON.getKind());
388 switch (ON.getKind()) {
389 case OffsetOfExpr::OffsetOfNode::Array:
390 // Expressions handled below.
391 break;
392
393 case OffsetOfExpr::OffsetOfNode::Field:
394 VisitDecl(ON.getField());
395 break;
396
397 case OffsetOfExpr::OffsetOfNode::Identifier:
398 ID.AddPointer(ON.getFieldName());
399 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000400
Douglas Gregord1702062010-04-29 00:18:15 +0000401 case OffsetOfExpr::OffsetOfNode::Base:
402 // These nodes are implicit, and therefore don't need profiling.
403 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000404 }
405 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000406
Douglas Gregor882211c2010-04-28 22:16:22 +0000407 VisitExpr(S);
408}
409
Chandler Carruth631abd92011-06-16 06:47:06 +0000410void
411StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000412 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000413 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000414 if (S->isArgumentType())
415 VisitType(S->getArgumentType());
416}
417
Chandler Carruth631abd92011-06-16 06:47:06 +0000418void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000419 VisitExpr(S);
420}
421
Chandler Carruth631abd92011-06-16 06:47:06 +0000422void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000423 VisitExpr(S);
424}
425
Chandler Carruth631abd92011-06-16 06:47:06 +0000426void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000427 VisitExpr(S);
428 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000429 if (!Canonical)
430 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000431 ID.AddBoolean(S->isArrow());
432}
433
Chandler Carruth631abd92011-06-16 06:47:06 +0000434void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000435 VisitExpr(S);
436 ID.AddBoolean(S->isFileScope());
437}
438
Chandler Carruth631abd92011-06-16 06:47:06 +0000439void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000440 VisitExpr(S);
441}
442
Chandler Carruth631abd92011-06-16 06:47:06 +0000443void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000444 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000445 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000446}
447
Chandler Carruth631abd92011-06-16 06:47:06 +0000448void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000449 VisitCastExpr(S);
450 VisitType(S->getTypeAsWritten());
451}
452
Chandler Carruth631abd92011-06-16 06:47:06 +0000453void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000454 VisitExplicitCastExpr(S);
455}
456
Chandler Carruth631abd92011-06-16 06:47:06 +0000457void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000458 VisitExpr(S);
459 ID.AddInteger(S->getOpcode());
460}
461
Chandler Carruth631abd92011-06-16 06:47:06 +0000462void
463StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000464 VisitBinaryOperator(S);
465}
466
Chandler Carruth631abd92011-06-16 06:47:06 +0000467void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000468 VisitExpr(S);
469}
470
Chandler Carruth631abd92011-06-16 06:47:06 +0000471void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000472 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000473 VisitExpr(S);
474}
475
Chandler Carruth631abd92011-06-16 06:47:06 +0000476void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000477 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000478 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000479}
480
Chandler Carruth631abd92011-06-16 06:47:06 +0000481void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000482 VisitExpr(S);
483}
484
Chandler Carruth631abd92011-06-16 06:47:06 +0000485void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000486 VisitExpr(S);
487}
488
Hal Finkelc4d7c822013-09-18 03:29:45 +0000489void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
490 VisitExpr(S);
491}
492
Chandler Carruth631abd92011-06-16 06:47:06 +0000493void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000494 VisitExpr(S);
495}
496
Chandler Carruth631abd92011-06-16 06:47:06 +0000497void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000498 VisitExpr(S);
499}
500
Chandler Carruth631abd92011-06-16 06:47:06 +0000501void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000502 VisitExpr(S);
503}
504
Chandler Carruth631abd92011-06-16 06:47:06 +0000505void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000506 if (S->getSyntacticForm()) {
507 VisitInitListExpr(S->getSyntacticForm());
508 return;
509 }
Mike Stump11289f42009-09-09 15:08:12 +0000510
Douglas Gregor5c193b92009-07-28 00:33:38 +0000511 VisitExpr(S);
512}
513
Chandler Carruth631abd92011-06-16 06:47:06 +0000514void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000515 VisitExpr(S);
516 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000517 for (DesignatedInitExpr::const_designators_iterator D =
518 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000519 D != DEnd; ++D) {
520 if (D->isFieldDesignator()) {
521 ID.AddInteger(0);
522 VisitName(D->getFieldName());
523 continue;
524 }
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregor5c193b92009-07-28 00:33:38 +0000526 if (D->isArrayDesignator()) {
527 ID.AddInteger(1);
528 } else {
529 assert(D->isArrayRangeDesignator());
530 ID.AddInteger(2);
531 }
532 ID.AddInteger(D->getFirstExprIndex());
533 }
534}
535
Chandler Carruth631abd92011-06-16 06:47:06 +0000536void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000537 VisitExpr(S);
538}
539
Chandler Carruth631abd92011-06-16 06:47:06 +0000540void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000541 VisitExpr(S);
542 VisitName(&S->getAccessor());
543}
544
Chandler Carruth631abd92011-06-16 06:47:06 +0000545void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000546 VisitExpr(S);
547 VisitDecl(S->getBlockDecl());
548}
549
Chandler Carruth631abd92011-06-16 06:47:06 +0000550void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000551 VisitExpr(S);
552 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
553 QualType T = S->getAssocType(i);
554 if (T.isNull())
555 ID.AddPointer(0);
556 else
557 VisitType(T);
558 VisitExpr(S->getAssocExpr(i));
559 }
560}
561
John McCallfe96e0b2011-11-06 09:01:30 +0000562void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
563 VisitExpr(S);
564 for (PseudoObjectExpr::const_semantics_iterator
565 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
566 // Normally, we would not profile the source expressions of OVEs.
567 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
568 Visit(OVE->getSourceExpr());
569}
570
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000571void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
572 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000573 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000574}
575
Chandler Carruth631abd92011-06-16 06:47:06 +0000576static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000577 UnaryOperatorKind &UnaryOp,
578 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000579 switch (S->getOperator()) {
580 case OO_None:
581 case OO_New:
582 case OO_Delete:
583 case OO_Array_New:
584 case OO_Array_Delete:
585 case OO_Arrow:
586 case OO_Call:
587 case OO_Conditional:
588 case NUM_OVERLOADED_OPERATORS:
589 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000590
591 case OO_Plus:
592 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000593 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000594 return Stmt::UnaryOperatorClass;
595 }
596
John McCalle3027922010-08-25 11:45:40 +0000597 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000598 return Stmt::BinaryOperatorClass;
599
600 case OO_Minus:
601 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000602 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000603 return Stmt::UnaryOperatorClass;
604 }
605
John McCalle3027922010-08-25 11:45:40 +0000606 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000607 return Stmt::BinaryOperatorClass;
608
609 case OO_Star:
610 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000611 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000612 return Stmt::UnaryOperatorClass;
613 }
614
John McCalle3027922010-08-25 11:45:40 +0000615 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000616 return Stmt::BinaryOperatorClass;
617
618 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000619 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000620 return Stmt::BinaryOperatorClass;
621
622 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000623 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000624 return Stmt::BinaryOperatorClass;
625
626 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000627 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000628 return Stmt::BinaryOperatorClass;
629
630 case OO_Amp:
631 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000632 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000633 return Stmt::UnaryOperatorClass;
634 }
635
John McCalle3027922010-08-25 11:45:40 +0000636 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000637 return Stmt::BinaryOperatorClass;
638
639 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000640 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000641 return Stmt::BinaryOperatorClass;
642
643 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000644 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000645 return Stmt::UnaryOperatorClass;
646
647 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000648 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000649 return Stmt::UnaryOperatorClass;
650
651 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000652 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000653 return Stmt::BinaryOperatorClass;
654
655 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000656 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000657 return Stmt::BinaryOperatorClass;
658
659 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000660 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000661 return Stmt::BinaryOperatorClass;
662
663 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000664 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000665 return Stmt::CompoundAssignOperatorClass;
666
667 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000668 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000669 return Stmt::CompoundAssignOperatorClass;
670
671 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000672 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000673 return Stmt::CompoundAssignOperatorClass;
674
675 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000676 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000677 return Stmt::CompoundAssignOperatorClass;
678
679 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000680 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000681 return Stmt::CompoundAssignOperatorClass;
682
683 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000684 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000685 return Stmt::CompoundAssignOperatorClass;
686
687 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000688 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000689 return Stmt::CompoundAssignOperatorClass;
690
691 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000692 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000693 return Stmt::CompoundAssignOperatorClass;
694
695 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000696 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000697 return Stmt::BinaryOperatorClass;
698
699 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000700 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000701 return Stmt::BinaryOperatorClass;
702
703 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000704 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000705 return Stmt::CompoundAssignOperatorClass;
706
707 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000708 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000709 return Stmt::CompoundAssignOperatorClass;
710
711 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000712 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000713 return Stmt::BinaryOperatorClass;
714
715 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000716 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000717 return Stmt::BinaryOperatorClass;
718
719 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000720 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000721 return Stmt::BinaryOperatorClass;
722
723 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000724 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000725 return Stmt::BinaryOperatorClass;
726
727 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000728 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000729 return Stmt::BinaryOperatorClass;
730
731 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000732 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000733 return Stmt::BinaryOperatorClass;
734
735 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000736 UnaryOp = S->getNumArgs() == 1? UO_PreInc
737 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000738 return Stmt::UnaryOperatorClass;
739
740 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000741 UnaryOp = S->getNumArgs() == 1? UO_PreDec
742 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000743 return Stmt::UnaryOperatorClass;
744
745 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000746 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000747 return Stmt::BinaryOperatorClass;
748
749
750 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000751 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000752 return Stmt::BinaryOperatorClass;
753
754 case OO_Subscript:
755 return Stmt::ArraySubscriptExprClass;
756 }
757
758 llvm_unreachable("Invalid overloaded operator expression");
759}
760
761
Chandler Carruth631abd92011-06-16 06:47:06 +0000762void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000763 if (S->isTypeDependent()) {
764 // Type-dependent operator calls are profiled like their underlying
765 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000766 UnaryOperatorKind UnaryOp = UO_Extension;
767 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000768 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
769
770 ID.AddInteger(SC);
771 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
772 Visit(S->getArg(I));
773 if (SC == Stmt::UnaryOperatorClass)
774 ID.AddInteger(UnaryOp);
775 else if (SC == Stmt::BinaryOperatorClass ||
776 SC == Stmt::CompoundAssignOperatorClass)
777 ID.AddInteger(BinaryOp);
778 else
779 assert(SC == Stmt::ArraySubscriptExprClass);
780
781 return;
782 }
783
Douglas Gregor5c193b92009-07-28 00:33:38 +0000784 VisitCallExpr(S);
785 ID.AddInteger(S->getOperator());
786}
787
Chandler Carruth631abd92011-06-16 06:47:06 +0000788void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000789 VisitCallExpr(S);
790}
791
Chandler Carruth631abd92011-06-16 06:47:06 +0000792void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000793 VisitCallExpr(S);
794}
795
Chandler Carruth631abd92011-06-16 06:47:06 +0000796void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000797 VisitExpr(S);
798}
799
Chandler Carruth631abd92011-06-16 06:47:06 +0000800void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000801 VisitExplicitCastExpr(S);
802}
803
Chandler Carruth631abd92011-06-16 06:47:06 +0000804void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000805 VisitCXXNamedCastExpr(S);
806}
807
Chandler Carruth631abd92011-06-16 06:47:06 +0000808void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000809 VisitCXXNamedCastExpr(S);
810}
811
Chandler Carruth631abd92011-06-16 06:47:06 +0000812void
813StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000814 VisitCXXNamedCastExpr(S);
815}
816
Chandler Carruth631abd92011-06-16 06:47:06 +0000817void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000818 VisitCXXNamedCastExpr(S);
819}
820
Richard Smithc67fdd42012-03-07 08:35:16 +0000821void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
822 VisitCallExpr(S);
823}
824
Chandler Carruth631abd92011-06-16 06:47:06 +0000825void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000826 VisitExpr(S);
827 ID.AddBoolean(S->getValue());
828}
829
Chandler Carruth631abd92011-06-16 06:47:06 +0000830void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000831 VisitExpr(S);
832}
833
Richard Smithcc1b96d2013-06-12 22:31:48 +0000834void StmtProfiler::VisitCXXStdInitializerListExpr(
835 const CXXStdInitializerListExpr *S) {
836 VisitExpr(S);
837}
838
Chandler Carruth631abd92011-06-16 06:47:06 +0000839void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000840 VisitExpr(S);
841 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000842 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000843}
844
Chandler Carruth631abd92011-06-16 06:47:06 +0000845void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000846 VisitExpr(S);
847 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000848 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000849}
850
John McCall5e77d762013-04-16 07:28:30 +0000851void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
852 VisitExpr(S);
853 VisitDecl(S->getPropertyDecl());
854}
855
Chandler Carruth631abd92011-06-16 06:47:06 +0000856void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000857 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000858 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000859}
860
Chandler Carruth631abd92011-06-16 06:47:06 +0000861void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000862 VisitExpr(S);
863}
864
Chandler Carruth631abd92011-06-16 06:47:06 +0000865void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000866 VisitExpr(S);
867 VisitDecl(S->getParam());
868}
869
Richard Smith852c9db2013-04-20 22:23:05 +0000870void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
871 VisitExpr(S);
872 VisitDecl(S->getField());
873}
874
Chandler Carruth631abd92011-06-16 06:47:06 +0000875void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000876 VisitExpr(S);
877 VisitDecl(
878 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
879}
880
Chandler Carruth631abd92011-06-16 06:47:06 +0000881void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000882 VisitExpr(S);
883 VisitDecl(S->getConstructor());
884 ID.AddBoolean(S->isElidable());
885}
886
Chandler Carruth631abd92011-06-16 06:47:06 +0000887void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000888 VisitExplicitCastExpr(S);
889}
890
Chandler Carruth631abd92011-06-16 06:47:06 +0000891void
892StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000893 VisitCXXConstructExpr(S);
894}
895
Chandler Carruth631abd92011-06-16 06:47:06 +0000896void
Douglas Gregore31e6062012-02-07 10:09:13 +0000897StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
898 VisitExpr(S);
899 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
900 CEnd = S->explicit_capture_end();
901 C != CEnd; ++C) {
902 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +0000903 switch (C->getCaptureKind()) {
904 case LCK_This:
905 break;
906 case LCK_ByRef:
907 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +0000908 VisitDecl(C->getCapturedVar());
909 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +0000910 break;
Douglas Gregore31e6062012-02-07 10:09:13 +0000911 }
912 }
913 // Note: If we actually needed to be able to match lambda
914 // expressions, we would have to consider parameters and return type
915 // here, among other things.
916 VisitStmt(S->getBody());
917}
918
919void
Chandler Carruth631abd92011-06-16 06:47:06 +0000920StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000921 VisitExpr(S);
922}
923
Chandler Carruth631abd92011-06-16 06:47:06 +0000924void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000925 VisitExpr(S);
926 ID.AddBoolean(S->isGlobalDelete());
927 ID.AddBoolean(S->isArrayForm());
928 VisitDecl(S->getOperatorDelete());
929}
930
931
Chandler Carruth631abd92011-06-16 06:47:06 +0000932void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000933 VisitExpr(S);
934 VisitType(S->getAllocatedType());
935 VisitDecl(S->getOperatorNew());
936 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000937 ID.AddBoolean(S->isArray());
938 ID.AddInteger(S->getNumPlacementArgs());
939 ID.AddBoolean(S->isGlobalNew());
940 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +0000941 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000942}
943
Chandler Carruth631abd92011-06-16 06:47:06 +0000944void
945StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +0000946 VisitExpr(S);
947 ID.AddBoolean(S->isArrow());
948 VisitNestedNameSpecifier(S->getQualifier());
Eli Friedman85641392013-08-09 23:37:05 +0000949 ID.AddBoolean(S->getScopeTypeInfo() != 0);
950 if (S->getScopeTypeInfo())
951 VisitType(S->getScopeTypeInfo()->getType());
952 ID.AddBoolean(S->getDestroyedTypeInfo() != 0);
953 if (S->getDestroyedTypeInfo())
954 VisitType(S->getDestroyedType());
955 else
956 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +0000957}
958
Chandler Carruth631abd92011-06-16 06:47:06 +0000959void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000960 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000961 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000962 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +0000963 ID.AddBoolean(S->hasExplicitTemplateArgs());
964 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000965 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
966 S->getExplicitTemplateArgs().NumTemplateArgs);
967}
968
969void
Chandler Carruth631abd92011-06-16 06:47:06 +0000970StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000971 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +0000972}
973
Douglas Gregor29c42f22012-02-24 07:38:34 +0000974void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
975 VisitExpr(S);
976 ID.AddInteger(S->getTrait());
977 ID.AddInteger(S->getNumArgs());
978 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
979 VisitType(S->getArg(I)->getType());
980}
981
Chandler Carruth631abd92011-06-16 06:47:06 +0000982void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +0000983 VisitExpr(S);
984 ID.AddInteger(S->getTrait());
985 VisitType(S->getQueriedType());
986}
987
Chandler Carruth631abd92011-06-16 06:47:06 +0000988void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +0000989 VisitExpr(S);
990 ID.AddInteger(S->getTrait());
991 VisitExpr(S->getQueriedExpression());
992}
993
Chandler Carruth631abd92011-06-16 06:47:06 +0000994void StmtProfiler::VisitDependentScopeDeclRefExpr(
995 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000996 VisitExpr(S);
997 VisitName(S->getDeclName());
998 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +0000999 ID.AddBoolean(S->hasExplicitTemplateArgs());
1000 if (S->hasExplicitTemplateArgs())
1001 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001002}
1003
Chandler Carruth631abd92011-06-16 06:47:06 +00001004void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001005 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001006}
1007
Chandler Carruth631abd92011-06-16 06:47:06 +00001008void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1009 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001010 VisitExpr(S);
1011 VisitType(S->getTypeAsWritten());
1012}
1013
Chandler Carruth631abd92011-06-16 06:47:06 +00001014void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1015 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001016 ID.AddBoolean(S->isImplicitAccess());
1017 if (!S->isImplicitAccess()) {
1018 VisitExpr(S);
1019 ID.AddBoolean(S->isArrow());
1020 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001021 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001022 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001023 ID.AddBoolean(S->hasExplicitTemplateArgs());
1024 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001025 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1026}
1027
Chandler Carruth631abd92011-06-16 06:47:06 +00001028void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001029 ID.AddBoolean(S->isImplicitAccess());
1030 if (!S->isImplicitAccess()) {
1031 VisitExpr(S);
1032 ID.AddBoolean(S->isArrow());
1033 }
John McCall10eae182009-11-30 22:42:35 +00001034 VisitNestedNameSpecifier(S->getQualifier());
1035 VisitName(S->getMemberName());
1036 ID.AddBoolean(S->hasExplicitTemplateArgs());
1037 if (S->hasExplicitTemplateArgs())
1038 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001039}
1040
Chandler Carruth631abd92011-06-16 06:47:06 +00001041void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001042 VisitExpr(S);
1043}
1044
Chandler Carruth631abd92011-06-16 06:47:06 +00001045void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001046 VisitExpr(S);
1047}
1048
Chandler Carruth631abd92011-06-16 06:47:06 +00001049void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001050 VisitExpr(S);
1051 VisitDecl(S->getPack());
1052}
1053
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001054void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001055 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001056 VisitExpr(S);
1057 VisitDecl(S->getParameterPack());
1058 VisitTemplateArgument(S->getArgumentPack());
1059}
1060
John McCall7c454bb2011-07-15 05:09:51 +00001061void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1062 const SubstNonTypeTemplateParmExpr *E) {
1063 // Profile exactly as the replacement expression.
1064 Visit(E->getReplacement());
1065}
1066
Richard Smithb15fe3a2012-09-12 00:56:43 +00001067void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1068 VisitExpr(S);
1069 VisitDecl(S->getParameterPack());
1070 ID.AddInteger(S->getNumExpansions());
1071 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1072 VisitDecl(*I);
1073}
1074
Douglas Gregorfe314812011-06-21 17:03:29 +00001075void StmtProfiler::VisitMaterializeTemporaryExpr(
1076 const MaterializeTemporaryExpr *S) {
1077 VisitExpr(S);
1078}
1079
Chandler Carruth631abd92011-06-16 06:47:06 +00001080void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001081 VisitExpr(E);
1082}
1083
Chandler Carruth631abd92011-06-16 06:47:06 +00001084void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001085 VisitExpr(S);
1086}
1087
Patrick Beard0caa3942012-04-19 00:25:12 +00001088void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001089 VisitExpr(E);
1090}
1091
1092void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1093 VisitExpr(E);
1094}
1095
1096void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1097 VisitExpr(E);
1098}
1099
Chandler Carruth631abd92011-06-16 06:47:06 +00001100void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001101 VisitExpr(S);
1102 VisitType(S->getEncodedType());
1103}
1104
Chandler Carruth631abd92011-06-16 06:47:06 +00001105void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001106 VisitExpr(S);
1107 VisitName(S->getSelector());
1108}
1109
Chandler Carruth631abd92011-06-16 06:47:06 +00001110void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001111 VisitExpr(S);
1112 VisitDecl(S->getProtocol());
1113}
1114
Chandler Carruth631abd92011-06-16 06:47:06 +00001115void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001116 VisitExpr(S);
1117 VisitDecl(S->getDecl());
1118 ID.AddBoolean(S->isArrow());
1119 ID.AddBoolean(S->isFreeIvar());
1120}
1121
Chandler Carruth631abd92011-06-16 06:47:06 +00001122void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001123 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001124 if (S->isImplicitProperty()) {
1125 VisitDecl(S->getImplicitPropertyGetter());
1126 VisitDecl(S->getImplicitPropertySetter());
1127 } else {
1128 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001129 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001130 if (S->isSuperReceiver()) {
1131 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001132 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001133 }
Douglas Gregora7095092009-07-28 14:44:31 +00001134}
1135
Ted Kremeneke65b0862012-03-06 20:05:56 +00001136void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1137 VisitExpr(S);
1138 VisitDecl(S->getAtIndexMethodDecl());
1139 VisitDecl(S->setAtIndexMethodDecl());
1140}
1141
Chandler Carruth631abd92011-06-16 06:47:06 +00001142void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001143 VisitExpr(S);
1144 VisitName(S->getSelector());
1145 VisitDecl(S->getMethodDecl());
1146}
1147
Chandler Carruth631abd92011-06-16 06:47:06 +00001148void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001149 VisitExpr(S);
1150 ID.AddBoolean(S->isArrow());
1151}
1152
Ted Kremeneke65b0862012-03-06 20:05:56 +00001153void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1154 VisitExpr(S);
1155 ID.AddBoolean(S->getValue());
1156}
1157
Chandler Carruth631abd92011-06-16 06:47:06 +00001158void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1159 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001160 VisitExpr(S);
1161 ID.AddBoolean(S->shouldCopy());
1162}
1163
Chandler Carruth631abd92011-06-16 06:47:06 +00001164void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001165 VisitExplicitCastExpr(S);
1166 ID.AddBoolean(S->getBridgeKind());
1167}
1168
Chandler Carruth631abd92011-06-16 06:47:06 +00001169void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001170 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001172 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001173 if (const NonTypeTemplateParmDecl *NTTP =
1174 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001175 ID.AddInteger(NTTP->getDepth());
1176 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001177 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001178 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001179 return;
1180 }
Mike Stump11289f42009-09-09 15:08:12 +00001181
Chandler Carruth631abd92011-06-16 06:47:06 +00001182 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001183 // The Itanium C++ ABI uses the type, scope depth, and scope
1184 // index of a parameter when mangling expressions that involve
1185 // function parameters, so we will use the parameter's type for
1186 // establishing function parameter identity. That way, our
1187 // definition of "equivalent" (per C++ [temp.over.link]) is at
1188 // least as strong as the definition of "equivalent" used for
1189 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001190 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001191 ID.AddInteger(Parm->getFunctionScopeDepth());
1192 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001193 return;
1194 }
Mike Stump11289f42009-09-09 15:08:12 +00001195
Richard Smithd9a1cd82012-04-02 18:53:24 +00001196 if (const TemplateTypeParmDecl *TTP =
1197 dyn_cast<TemplateTypeParmDecl>(D)) {
1198 ID.AddInteger(TTP->getDepth());
1199 ID.AddInteger(TTP->getIndex());
1200 ID.AddBoolean(TTP->isParameterPack());
1201 return;
1202 }
1203
Chandler Carruth631abd92011-06-16 06:47:06 +00001204 if (const TemplateTemplateParmDecl *TTP =
1205 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001206 ID.AddInteger(TTP->getDepth());
1207 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001208 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001209 return;
1210 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001211 }
Mike Stump11289f42009-09-09 15:08:12 +00001212
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001213 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1214}
1215
1216void StmtProfiler::VisitType(QualType T) {
1217 if (Canonical)
1218 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregor5c193b92009-07-28 00:33:38 +00001220 ID.AddPointer(T.getAsOpaquePtr());
1221}
1222
1223void StmtProfiler::VisitName(DeclarationName Name) {
1224 ID.AddPointer(Name.getAsOpaquePtr());
1225}
1226
1227void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1228 if (Canonical)
1229 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1230 ID.AddPointer(NNS);
1231}
1232
1233void StmtProfiler::VisitTemplateName(TemplateName Name) {
1234 if (Canonical)
1235 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001236
Douglas Gregor5c193b92009-07-28 00:33:38 +00001237 Name.Profile(ID);
1238}
1239
John McCall0ad16662009-10-29 08:12:44 +00001240void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001241 unsigned NumArgs) {
1242 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001243 for (unsigned I = 0; I != NumArgs; ++I)
1244 VisitTemplateArgument(Args[I].getArgument());
1245}
Mike Stump11289f42009-09-09 15:08:12 +00001246
John McCall0ad16662009-10-29 08:12:44 +00001247void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1248 // Mostly repetitive with TemplateArgument::Profile!
1249 ID.AddInteger(Arg.getKind());
1250 switch (Arg.getKind()) {
1251 case TemplateArgument::Null:
1252 break;
Mike Stump11289f42009-09-09 15:08:12 +00001253
John McCall0ad16662009-10-29 08:12:44 +00001254 case TemplateArgument::Type:
1255 VisitType(Arg.getAsType());
1256 break;
Mike Stump11289f42009-09-09 15:08:12 +00001257
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001258 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001259 case TemplateArgument::TemplateExpansion:
1260 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001261 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001262
John McCall0ad16662009-10-29 08:12:44 +00001263 case TemplateArgument::Declaration:
1264 VisitDecl(Arg.getAsDecl());
1265 break;
Mike Stump11289f42009-09-09 15:08:12 +00001266
Eli Friedmanb826a002012-09-26 02:36:12 +00001267 case TemplateArgument::NullPtr:
1268 VisitType(Arg.getNullPtrType());
1269 break;
1270
John McCall0ad16662009-10-29 08:12:44 +00001271 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001272 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001273 VisitType(Arg.getIntegralType());
1274 break;
Mike Stump11289f42009-09-09 15:08:12 +00001275
John McCall0ad16662009-10-29 08:12:44 +00001276 case TemplateArgument::Expression:
1277 Visit(Arg.getAsExpr());
1278 break;
Mike Stump11289f42009-09-09 15:08:12 +00001279
John McCall0ad16662009-10-29 08:12:44 +00001280 case TemplateArgument::Pack:
1281 const TemplateArgument *Pack = Arg.pack_begin();
1282 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1283 VisitTemplateArgument(Pack[i]);
1284 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001285 }
1286}
1287
Jay Foad39c79802011-01-12 09:06:06 +00001288void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001289 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001290 StmtProfiler Profiler(ID, Context, Canonical);
1291 Profiler.Visit(this);
1292}