blob: d96a6116ae9470f5810e30d4ed2d379620032c4b [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
Alexander Musman8bd31e62014-05-27 15:12:19 +0000282void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
283 if (C->getNumForLoops())
284 Profiler->VisitStmt(C->getNumForLoops());
285}
286
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000287void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000288
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000289void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
290
Alexey Bataev756c1962013-09-24 03:17:45 +0000291template<typename T>
292void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Aaron Ballman2205d2a2014-03-14 15:55:35 +0000293 for (auto *I : Node->varlists())
294 Profiler->VisitStmt(I);
Alexey Bataev756c1962013-09-24 03:17:45 +0000295}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000296
297void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000298 VisitOMPClauseList(C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000299}
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000300void OMPClauseProfiler::VisitOMPFirstprivateClause(
301 const OMPFirstprivateClause *C) {
302 VisitOMPClauseList(C);
303}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000304void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000305 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000306}
Alexander Musman8dba6642014-04-22 13:09:42 +0000307void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
308 VisitOMPClauseList(C);
309 Profiler->VisitStmt(C->getStep());
310}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000311void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
312 VisitOMPClauseList(C);
313 Profiler->VisitStmt(C->getAlignment());
314}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000315void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
316 VisitOMPClauseList(C);
317}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000318}
319
320void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000321StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000322 VisitStmt(S);
323 OMPClauseProfiler P(this);
324 ArrayRef<OMPClause *> Clauses = S->clauses();
325 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
326 I != E; ++I)
327 if (*I)
328 P.Visit(*I);
329}
330
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000331void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
332 VisitOMPExecutableDirective(S);
333}
334
335void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
336 VisitOMPExecutableDirective(S);
337}
338
Chandler Carruth631abd92011-06-16 06:47:06 +0000339void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000340 VisitStmt(S);
341}
342
Chandler Carruth631abd92011-06-16 06:47:06 +0000343void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000344 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000345 if (!Canonical)
346 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000347 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000348 if (!Canonical)
349 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000350}
351
Chandler Carruth631abd92011-06-16 06:47:06 +0000352void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000353 VisitExpr(S);
354 ID.AddInteger(S->getIdentType());
355}
356
Chandler Carruth631abd92011-06-16 06:47:06 +0000357void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000358 VisitExpr(S);
359 S->getValue().Profile(ID);
360}
361
Chandler Carruth631abd92011-06-16 06:47:06 +0000362void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000363 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000364 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000365 ID.AddInteger(S->getValue());
366}
367
Chandler Carruth631abd92011-06-16 06:47:06 +0000368void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000369 VisitExpr(S);
370 S->getValue().Profile(ID);
371 ID.AddBoolean(S->isExact());
372}
373
Chandler Carruth631abd92011-06-16 06:47:06 +0000374void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000375 VisitExpr(S);
376}
377
Chandler Carruth631abd92011-06-16 06:47:06 +0000378void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000379 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000380 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000381 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000382}
383
Chandler Carruth631abd92011-06-16 06:47:06 +0000384void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000385 VisitExpr(S);
386}
387
Chandler Carruth631abd92011-06-16 06:47:06 +0000388void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000389 VisitExpr(S);
390}
391
Chandler Carruth631abd92011-06-16 06:47:06 +0000392void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000393 VisitExpr(S);
394 ID.AddInteger(S->getOpcode());
395}
396
Chandler Carruth631abd92011-06-16 06:47:06 +0000397void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000398 VisitType(S->getTypeSourceInfo()->getType());
399 unsigned n = S->getNumComponents();
400 for (unsigned i = 0; i < n; ++i) {
401 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
402 ID.AddInteger(ON.getKind());
403 switch (ON.getKind()) {
404 case OffsetOfExpr::OffsetOfNode::Array:
405 // Expressions handled below.
406 break;
407
408 case OffsetOfExpr::OffsetOfNode::Field:
409 VisitDecl(ON.getField());
410 break;
411
412 case OffsetOfExpr::OffsetOfNode::Identifier:
413 ID.AddPointer(ON.getFieldName());
414 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000415
Douglas Gregord1702062010-04-29 00:18:15 +0000416 case OffsetOfExpr::OffsetOfNode::Base:
417 // These nodes are implicit, and therefore don't need profiling.
418 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000419 }
420 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000421
Douglas Gregor882211c2010-04-28 22:16:22 +0000422 VisitExpr(S);
423}
424
Chandler Carruth631abd92011-06-16 06:47:06 +0000425void
426StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000427 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000428 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000429 if (S->isArgumentType())
430 VisitType(S->getArgumentType());
431}
432
Chandler Carruth631abd92011-06-16 06:47:06 +0000433void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000434 VisitExpr(S);
435}
436
Chandler Carruth631abd92011-06-16 06:47:06 +0000437void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000438 VisitExpr(S);
439}
440
Chandler Carruth631abd92011-06-16 06:47:06 +0000441void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000442 VisitExpr(S);
443 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000444 if (!Canonical)
445 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000446 ID.AddBoolean(S->isArrow());
447}
448
Chandler Carruth631abd92011-06-16 06:47:06 +0000449void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000450 VisitExpr(S);
451 ID.AddBoolean(S->isFileScope());
452}
453
Chandler Carruth631abd92011-06-16 06:47:06 +0000454void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000455 VisitExpr(S);
456}
457
Chandler Carruth631abd92011-06-16 06:47:06 +0000458void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000459 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000460 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000461}
462
Chandler Carruth631abd92011-06-16 06:47:06 +0000463void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000464 VisitCastExpr(S);
465 VisitType(S->getTypeAsWritten());
466}
467
Chandler Carruth631abd92011-06-16 06:47:06 +0000468void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000469 VisitExplicitCastExpr(S);
470}
471
Chandler Carruth631abd92011-06-16 06:47:06 +0000472void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000473 VisitExpr(S);
474 ID.AddInteger(S->getOpcode());
475}
476
Chandler Carruth631abd92011-06-16 06:47:06 +0000477void
478StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000479 VisitBinaryOperator(S);
480}
481
Chandler Carruth631abd92011-06-16 06:47:06 +0000482void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000483 VisitExpr(S);
484}
485
Chandler Carruth631abd92011-06-16 06:47:06 +0000486void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000487 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000488 VisitExpr(S);
489}
490
Chandler Carruth631abd92011-06-16 06:47:06 +0000491void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000492 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000493 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000494}
495
Chandler Carruth631abd92011-06-16 06:47:06 +0000496void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000497 VisitExpr(S);
498}
499
Chandler Carruth631abd92011-06-16 06:47:06 +0000500void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000501 VisitExpr(S);
502}
503
Hal Finkelc4d7c822013-09-18 03:29:45 +0000504void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
505 VisitExpr(S);
506}
507
Chandler Carruth631abd92011-06-16 06:47:06 +0000508void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000509 VisitExpr(S);
510}
511
Chandler Carruth631abd92011-06-16 06:47:06 +0000512void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000513 VisitExpr(S);
514}
515
Chandler Carruth631abd92011-06-16 06:47:06 +0000516void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000517 VisitExpr(S);
518}
519
Chandler Carruth631abd92011-06-16 06:47:06 +0000520void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000521 if (S->getSyntacticForm()) {
522 VisitInitListExpr(S->getSyntacticForm());
523 return;
524 }
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregor5c193b92009-07-28 00:33:38 +0000526 VisitExpr(S);
527}
528
Chandler Carruth631abd92011-06-16 06:47:06 +0000529void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000530 VisitExpr(S);
531 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000532 for (DesignatedInitExpr::const_designators_iterator D =
533 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000534 D != DEnd; ++D) {
535 if (D->isFieldDesignator()) {
536 ID.AddInteger(0);
537 VisitName(D->getFieldName());
538 continue;
539 }
Mike Stump11289f42009-09-09 15:08:12 +0000540
Douglas Gregor5c193b92009-07-28 00:33:38 +0000541 if (D->isArrayDesignator()) {
542 ID.AddInteger(1);
543 } else {
544 assert(D->isArrayRangeDesignator());
545 ID.AddInteger(2);
546 }
547 ID.AddInteger(D->getFirstExprIndex());
548 }
549}
550
Chandler Carruth631abd92011-06-16 06:47:06 +0000551void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000552 VisitExpr(S);
553}
554
Chandler Carruth631abd92011-06-16 06:47:06 +0000555void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000556 VisitExpr(S);
557 VisitName(&S->getAccessor());
558}
559
Chandler Carruth631abd92011-06-16 06:47:06 +0000560void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000561 VisitExpr(S);
562 VisitDecl(S->getBlockDecl());
563}
564
Chandler Carruth631abd92011-06-16 06:47:06 +0000565void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000566 VisitExpr(S);
567 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
568 QualType T = S->getAssocType(i);
569 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000570 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000571 else
572 VisitType(T);
573 VisitExpr(S->getAssocExpr(i));
574 }
575}
576
John McCallfe96e0b2011-11-06 09:01:30 +0000577void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
578 VisitExpr(S);
579 for (PseudoObjectExpr::const_semantics_iterator
580 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
581 // Normally, we would not profile the source expressions of OVEs.
582 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
583 Visit(OVE->getSourceExpr());
584}
585
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000586void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
587 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000588 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000589}
590
Chandler Carruth631abd92011-06-16 06:47:06 +0000591static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000592 UnaryOperatorKind &UnaryOp,
593 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000594 switch (S->getOperator()) {
595 case OO_None:
596 case OO_New:
597 case OO_Delete:
598 case OO_Array_New:
599 case OO_Array_Delete:
600 case OO_Arrow:
601 case OO_Call:
602 case OO_Conditional:
603 case NUM_OVERLOADED_OPERATORS:
604 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000605
606 case OO_Plus:
607 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000608 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000609 return Stmt::UnaryOperatorClass;
610 }
611
John McCalle3027922010-08-25 11:45:40 +0000612 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000613 return Stmt::BinaryOperatorClass;
614
615 case OO_Minus:
616 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000617 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000618 return Stmt::UnaryOperatorClass;
619 }
620
John McCalle3027922010-08-25 11:45:40 +0000621 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000622 return Stmt::BinaryOperatorClass;
623
624 case OO_Star:
625 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000626 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000627 return Stmt::UnaryOperatorClass;
628 }
629
John McCalle3027922010-08-25 11:45:40 +0000630 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000631 return Stmt::BinaryOperatorClass;
632
633 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000634 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000635 return Stmt::BinaryOperatorClass;
636
637 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000638 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000639 return Stmt::BinaryOperatorClass;
640
641 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000642 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000643 return Stmt::BinaryOperatorClass;
644
645 case OO_Amp:
646 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000647 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000648 return Stmt::UnaryOperatorClass;
649 }
650
John McCalle3027922010-08-25 11:45:40 +0000651 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000652 return Stmt::BinaryOperatorClass;
653
654 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000655 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000656 return Stmt::BinaryOperatorClass;
657
658 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000659 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000660 return Stmt::UnaryOperatorClass;
661
662 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000663 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000664 return Stmt::UnaryOperatorClass;
665
666 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000667 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000668 return Stmt::BinaryOperatorClass;
669
670 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000671 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000672 return Stmt::BinaryOperatorClass;
673
674 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000675 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000676 return Stmt::BinaryOperatorClass;
677
678 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000679 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000680 return Stmt::CompoundAssignOperatorClass;
681
682 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000683 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000684 return Stmt::CompoundAssignOperatorClass;
685
686 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000687 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000688 return Stmt::CompoundAssignOperatorClass;
689
690 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000691 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000692 return Stmt::CompoundAssignOperatorClass;
693
694 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000695 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000696 return Stmt::CompoundAssignOperatorClass;
697
698 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000699 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000700 return Stmt::CompoundAssignOperatorClass;
701
702 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000703 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000704 return Stmt::CompoundAssignOperatorClass;
705
706 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000707 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000708 return Stmt::CompoundAssignOperatorClass;
709
710 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000711 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000712 return Stmt::BinaryOperatorClass;
713
714 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000715 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000716 return Stmt::BinaryOperatorClass;
717
718 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000719 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000720 return Stmt::CompoundAssignOperatorClass;
721
722 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000723 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000724 return Stmt::CompoundAssignOperatorClass;
725
726 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000727 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000728 return Stmt::BinaryOperatorClass;
729
730 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000731 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000732 return Stmt::BinaryOperatorClass;
733
734 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000735 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000736 return Stmt::BinaryOperatorClass;
737
738 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000739 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000740 return Stmt::BinaryOperatorClass;
741
742 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000743 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000744 return Stmt::BinaryOperatorClass;
745
746 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000747 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000748 return Stmt::BinaryOperatorClass;
749
750 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000751 UnaryOp = S->getNumArgs() == 1? UO_PreInc
752 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000753 return Stmt::UnaryOperatorClass;
754
755 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000756 UnaryOp = S->getNumArgs() == 1? UO_PreDec
757 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000758 return Stmt::UnaryOperatorClass;
759
760 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000761 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000762 return Stmt::BinaryOperatorClass;
763
764
765 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000766 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000767 return Stmt::BinaryOperatorClass;
768
769 case OO_Subscript:
770 return Stmt::ArraySubscriptExprClass;
771 }
772
773 llvm_unreachable("Invalid overloaded operator expression");
774}
775
776
Chandler Carruth631abd92011-06-16 06:47:06 +0000777void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000778 if (S->isTypeDependent()) {
779 // Type-dependent operator calls are profiled like their underlying
780 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000781 UnaryOperatorKind UnaryOp = UO_Extension;
782 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000783 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
784
785 ID.AddInteger(SC);
786 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
787 Visit(S->getArg(I));
788 if (SC == Stmt::UnaryOperatorClass)
789 ID.AddInteger(UnaryOp);
790 else if (SC == Stmt::BinaryOperatorClass ||
791 SC == Stmt::CompoundAssignOperatorClass)
792 ID.AddInteger(BinaryOp);
793 else
794 assert(SC == Stmt::ArraySubscriptExprClass);
795
796 return;
797 }
798
Douglas Gregor5c193b92009-07-28 00:33:38 +0000799 VisitCallExpr(S);
800 ID.AddInteger(S->getOperator());
801}
802
Chandler Carruth631abd92011-06-16 06:47:06 +0000803void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000804 VisitCallExpr(S);
805}
806
Chandler Carruth631abd92011-06-16 06:47:06 +0000807void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000808 VisitCallExpr(S);
809}
810
Chandler Carruth631abd92011-06-16 06:47:06 +0000811void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000812 VisitExpr(S);
813}
814
Chandler Carruth631abd92011-06-16 06:47:06 +0000815void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000816 VisitExplicitCastExpr(S);
817}
818
Chandler Carruth631abd92011-06-16 06:47:06 +0000819void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000820 VisitCXXNamedCastExpr(S);
821}
822
Chandler Carruth631abd92011-06-16 06:47:06 +0000823void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000824 VisitCXXNamedCastExpr(S);
825}
826
Chandler Carruth631abd92011-06-16 06:47:06 +0000827void
828StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000829 VisitCXXNamedCastExpr(S);
830}
831
Chandler Carruth631abd92011-06-16 06:47:06 +0000832void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000833 VisitCXXNamedCastExpr(S);
834}
835
Richard Smithc67fdd42012-03-07 08:35:16 +0000836void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
837 VisitCallExpr(S);
838}
839
Chandler Carruth631abd92011-06-16 06:47:06 +0000840void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000841 VisitExpr(S);
842 ID.AddBoolean(S->getValue());
843}
844
Chandler Carruth631abd92011-06-16 06:47:06 +0000845void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000846 VisitExpr(S);
847}
848
Richard Smithcc1b96d2013-06-12 22:31:48 +0000849void StmtProfiler::VisitCXXStdInitializerListExpr(
850 const CXXStdInitializerListExpr *S) {
851 VisitExpr(S);
852}
853
Chandler Carruth631abd92011-06-16 06:47:06 +0000854void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000855 VisitExpr(S);
856 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000857 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000858}
859
Chandler Carruth631abd92011-06-16 06:47:06 +0000860void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000861 VisitExpr(S);
862 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000863 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000864}
865
John McCall5e77d762013-04-16 07:28:30 +0000866void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
867 VisitExpr(S);
868 VisitDecl(S->getPropertyDecl());
869}
870
Chandler Carruth631abd92011-06-16 06:47:06 +0000871void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000872 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000873 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000874}
875
Chandler Carruth631abd92011-06-16 06:47:06 +0000876void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000877 VisitExpr(S);
878}
879
Chandler Carruth631abd92011-06-16 06:47:06 +0000880void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000881 VisitExpr(S);
882 VisitDecl(S->getParam());
883}
884
Richard Smith852c9db2013-04-20 22:23:05 +0000885void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
886 VisitExpr(S);
887 VisitDecl(S->getField());
888}
889
Chandler Carruth631abd92011-06-16 06:47:06 +0000890void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000891 VisitExpr(S);
892 VisitDecl(
893 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
894}
895
Chandler Carruth631abd92011-06-16 06:47:06 +0000896void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000897 VisitExpr(S);
898 VisitDecl(S->getConstructor());
899 ID.AddBoolean(S->isElidable());
900}
901
Chandler Carruth631abd92011-06-16 06:47:06 +0000902void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000903 VisitExplicitCastExpr(S);
904}
905
Chandler Carruth631abd92011-06-16 06:47:06 +0000906void
907StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000908 VisitCXXConstructExpr(S);
909}
910
Chandler Carruth631abd92011-06-16 06:47:06 +0000911void
Douglas Gregore31e6062012-02-07 10:09:13 +0000912StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
913 VisitExpr(S);
914 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
915 CEnd = S->explicit_capture_end();
916 C != CEnd; ++C) {
917 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +0000918 switch (C->getCaptureKind()) {
919 case LCK_This:
920 break;
921 case LCK_ByRef:
922 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +0000923 VisitDecl(C->getCapturedVar());
924 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +0000925 break;
Douglas Gregore31e6062012-02-07 10:09:13 +0000926 }
927 }
928 // Note: If we actually needed to be able to match lambda
929 // expressions, we would have to consider parameters and return type
930 // here, among other things.
931 VisitStmt(S->getBody());
932}
933
934void
Chandler Carruth631abd92011-06-16 06:47:06 +0000935StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000936 VisitExpr(S);
937}
938
Chandler Carruth631abd92011-06-16 06:47:06 +0000939void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000940 VisitExpr(S);
941 ID.AddBoolean(S->isGlobalDelete());
942 ID.AddBoolean(S->isArrayForm());
943 VisitDecl(S->getOperatorDelete());
944}
945
946
Chandler Carruth631abd92011-06-16 06:47:06 +0000947void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000948 VisitExpr(S);
949 VisitType(S->getAllocatedType());
950 VisitDecl(S->getOperatorNew());
951 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000952 ID.AddBoolean(S->isArray());
953 ID.AddInteger(S->getNumPlacementArgs());
954 ID.AddBoolean(S->isGlobalNew());
955 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +0000956 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000957}
958
Chandler Carruth631abd92011-06-16 06:47:06 +0000959void
960StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +0000961 VisitExpr(S);
962 ID.AddBoolean(S->isArrow());
963 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +0000964 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +0000965 if (S->getScopeTypeInfo())
966 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +0000967 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +0000968 if (S->getDestroyedTypeInfo())
969 VisitType(S->getDestroyedType());
970 else
971 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +0000972}
973
Chandler Carruth631abd92011-06-16 06:47:06 +0000974void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000975 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000976 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000977 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +0000978 ID.AddBoolean(S->hasExplicitTemplateArgs());
979 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000980 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
981 S->getExplicitTemplateArgs().NumTemplateArgs);
982}
983
984void
Chandler Carruth631abd92011-06-16 06:47:06 +0000985StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000986 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +0000987}
988
Douglas Gregor29c42f22012-02-24 07:38:34 +0000989void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
990 VisitExpr(S);
991 ID.AddInteger(S->getTrait());
992 ID.AddInteger(S->getNumArgs());
993 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
994 VisitType(S->getArg(I)->getType());
995}
996
Chandler Carruth631abd92011-06-16 06:47:06 +0000997void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +0000998 VisitExpr(S);
999 ID.AddInteger(S->getTrait());
1000 VisitType(S->getQueriedType());
1001}
1002
Chandler Carruth631abd92011-06-16 06:47:06 +00001003void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001004 VisitExpr(S);
1005 ID.AddInteger(S->getTrait());
1006 VisitExpr(S->getQueriedExpression());
1007}
1008
Chandler Carruth631abd92011-06-16 06:47:06 +00001009void StmtProfiler::VisitDependentScopeDeclRefExpr(
1010 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001011 VisitExpr(S);
1012 VisitName(S->getDeclName());
1013 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001014 ID.AddBoolean(S->hasExplicitTemplateArgs());
1015 if (S->hasExplicitTemplateArgs())
1016 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001017}
1018
Chandler Carruth631abd92011-06-16 06:47:06 +00001019void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001020 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001021}
1022
Chandler Carruth631abd92011-06-16 06:47:06 +00001023void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1024 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001025 VisitExpr(S);
1026 VisitType(S->getTypeAsWritten());
1027}
1028
Chandler Carruth631abd92011-06-16 06:47:06 +00001029void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1030 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001031 ID.AddBoolean(S->isImplicitAccess());
1032 if (!S->isImplicitAccess()) {
1033 VisitExpr(S);
1034 ID.AddBoolean(S->isArrow());
1035 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001036 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001037 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001038 ID.AddBoolean(S->hasExplicitTemplateArgs());
1039 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001040 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1041}
1042
Chandler Carruth631abd92011-06-16 06:47:06 +00001043void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001044 ID.AddBoolean(S->isImplicitAccess());
1045 if (!S->isImplicitAccess()) {
1046 VisitExpr(S);
1047 ID.AddBoolean(S->isArrow());
1048 }
John McCall10eae182009-11-30 22:42:35 +00001049 VisitNestedNameSpecifier(S->getQualifier());
1050 VisitName(S->getMemberName());
1051 ID.AddBoolean(S->hasExplicitTemplateArgs());
1052 if (S->hasExplicitTemplateArgs())
1053 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001054}
1055
Chandler Carruth631abd92011-06-16 06:47:06 +00001056void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001057 VisitExpr(S);
1058}
1059
Chandler Carruth631abd92011-06-16 06:47:06 +00001060void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001061 VisitExpr(S);
1062}
1063
Chandler Carruth631abd92011-06-16 06:47:06 +00001064void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001065 VisitExpr(S);
1066 VisitDecl(S->getPack());
1067}
1068
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001069void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001070 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001071 VisitExpr(S);
1072 VisitDecl(S->getParameterPack());
1073 VisitTemplateArgument(S->getArgumentPack());
1074}
1075
John McCall7c454bb2011-07-15 05:09:51 +00001076void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1077 const SubstNonTypeTemplateParmExpr *E) {
1078 // Profile exactly as the replacement expression.
1079 Visit(E->getReplacement());
1080}
1081
Richard Smithb15fe3a2012-09-12 00:56:43 +00001082void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1083 VisitExpr(S);
1084 VisitDecl(S->getParameterPack());
1085 ID.AddInteger(S->getNumExpansions());
1086 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1087 VisitDecl(*I);
1088}
1089
Douglas Gregorfe314812011-06-21 17:03:29 +00001090void StmtProfiler::VisitMaterializeTemporaryExpr(
1091 const MaterializeTemporaryExpr *S) {
1092 VisitExpr(S);
1093}
1094
Chandler Carruth631abd92011-06-16 06:47:06 +00001095void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001096 VisitExpr(E);
1097}
1098
Chandler Carruth631abd92011-06-16 06:47:06 +00001099void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001100 VisitExpr(S);
1101}
1102
Patrick Beard0caa3942012-04-19 00:25:12 +00001103void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001104 VisitExpr(E);
1105}
1106
1107void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1108 VisitExpr(E);
1109}
1110
1111void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1112 VisitExpr(E);
1113}
1114
Chandler Carruth631abd92011-06-16 06:47:06 +00001115void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001116 VisitExpr(S);
1117 VisitType(S->getEncodedType());
1118}
1119
Chandler Carruth631abd92011-06-16 06:47:06 +00001120void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001121 VisitExpr(S);
1122 VisitName(S->getSelector());
1123}
1124
Chandler Carruth631abd92011-06-16 06:47:06 +00001125void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001126 VisitExpr(S);
1127 VisitDecl(S->getProtocol());
1128}
1129
Chandler Carruth631abd92011-06-16 06:47:06 +00001130void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001131 VisitExpr(S);
1132 VisitDecl(S->getDecl());
1133 ID.AddBoolean(S->isArrow());
1134 ID.AddBoolean(S->isFreeIvar());
1135}
1136
Chandler Carruth631abd92011-06-16 06:47:06 +00001137void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001138 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001139 if (S->isImplicitProperty()) {
1140 VisitDecl(S->getImplicitPropertyGetter());
1141 VisitDecl(S->getImplicitPropertySetter());
1142 } else {
1143 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001144 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001145 if (S->isSuperReceiver()) {
1146 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001147 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001148 }
Douglas Gregora7095092009-07-28 14:44:31 +00001149}
1150
Ted Kremeneke65b0862012-03-06 20:05:56 +00001151void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1152 VisitExpr(S);
1153 VisitDecl(S->getAtIndexMethodDecl());
1154 VisitDecl(S->setAtIndexMethodDecl());
1155}
1156
Chandler Carruth631abd92011-06-16 06:47:06 +00001157void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001158 VisitExpr(S);
1159 VisitName(S->getSelector());
1160 VisitDecl(S->getMethodDecl());
1161}
1162
Chandler Carruth631abd92011-06-16 06:47:06 +00001163void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001164 VisitExpr(S);
1165 ID.AddBoolean(S->isArrow());
1166}
1167
Ted Kremeneke65b0862012-03-06 20:05:56 +00001168void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1169 VisitExpr(S);
1170 ID.AddBoolean(S->getValue());
1171}
1172
Chandler Carruth631abd92011-06-16 06:47:06 +00001173void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1174 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001175 VisitExpr(S);
1176 ID.AddBoolean(S->shouldCopy());
1177}
1178
Chandler Carruth631abd92011-06-16 06:47:06 +00001179void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001180 VisitExplicitCastExpr(S);
1181 ID.AddBoolean(S->getBridgeKind());
1182}
1183
Chandler Carruth631abd92011-06-16 06:47:06 +00001184void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001185 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001186
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001187 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001188 if (const NonTypeTemplateParmDecl *NTTP =
1189 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001190 ID.AddInteger(NTTP->getDepth());
1191 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001192 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001193 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001194 return;
1195 }
Mike Stump11289f42009-09-09 15:08:12 +00001196
Chandler Carruth631abd92011-06-16 06:47:06 +00001197 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001198 // The Itanium C++ ABI uses the type, scope depth, and scope
1199 // index of a parameter when mangling expressions that involve
1200 // function parameters, so we will use the parameter's type for
1201 // establishing function parameter identity. That way, our
1202 // definition of "equivalent" (per C++ [temp.over.link]) is at
1203 // least as strong as the definition of "equivalent" used for
1204 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001205 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001206 ID.AddInteger(Parm->getFunctionScopeDepth());
1207 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001208 return;
1209 }
Mike Stump11289f42009-09-09 15:08:12 +00001210
Richard Smithd9a1cd82012-04-02 18:53:24 +00001211 if (const TemplateTypeParmDecl *TTP =
1212 dyn_cast<TemplateTypeParmDecl>(D)) {
1213 ID.AddInteger(TTP->getDepth());
1214 ID.AddInteger(TTP->getIndex());
1215 ID.AddBoolean(TTP->isParameterPack());
1216 return;
1217 }
1218
Chandler Carruth631abd92011-06-16 06:47:06 +00001219 if (const TemplateTemplateParmDecl *TTP =
1220 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001221 ID.AddInteger(TTP->getDepth());
1222 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001223 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001224 return;
1225 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001226 }
Mike Stump11289f42009-09-09 15:08:12 +00001227
Craig Topper36250ad2014-05-12 05:36:57 +00001228 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001229}
1230
1231void StmtProfiler::VisitType(QualType T) {
1232 if (Canonical)
1233 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001234
Douglas Gregor5c193b92009-07-28 00:33:38 +00001235 ID.AddPointer(T.getAsOpaquePtr());
1236}
1237
1238void StmtProfiler::VisitName(DeclarationName Name) {
1239 ID.AddPointer(Name.getAsOpaquePtr());
1240}
1241
1242void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1243 if (Canonical)
1244 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1245 ID.AddPointer(NNS);
1246}
1247
1248void StmtProfiler::VisitTemplateName(TemplateName Name) {
1249 if (Canonical)
1250 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregor5c193b92009-07-28 00:33:38 +00001252 Name.Profile(ID);
1253}
1254
John McCall0ad16662009-10-29 08:12:44 +00001255void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001256 unsigned NumArgs) {
1257 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001258 for (unsigned I = 0; I != NumArgs; ++I)
1259 VisitTemplateArgument(Args[I].getArgument());
1260}
Mike Stump11289f42009-09-09 15:08:12 +00001261
John McCall0ad16662009-10-29 08:12:44 +00001262void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1263 // Mostly repetitive with TemplateArgument::Profile!
1264 ID.AddInteger(Arg.getKind());
1265 switch (Arg.getKind()) {
1266 case TemplateArgument::Null:
1267 break;
Mike Stump11289f42009-09-09 15:08:12 +00001268
John McCall0ad16662009-10-29 08:12:44 +00001269 case TemplateArgument::Type:
1270 VisitType(Arg.getAsType());
1271 break;
Mike Stump11289f42009-09-09 15:08:12 +00001272
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001273 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001274 case TemplateArgument::TemplateExpansion:
1275 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001276 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001277
John McCall0ad16662009-10-29 08:12:44 +00001278 case TemplateArgument::Declaration:
1279 VisitDecl(Arg.getAsDecl());
1280 break;
Mike Stump11289f42009-09-09 15:08:12 +00001281
Eli Friedmanb826a002012-09-26 02:36:12 +00001282 case TemplateArgument::NullPtr:
1283 VisitType(Arg.getNullPtrType());
1284 break;
1285
John McCall0ad16662009-10-29 08:12:44 +00001286 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001287 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001288 VisitType(Arg.getIntegralType());
1289 break;
Mike Stump11289f42009-09-09 15:08:12 +00001290
John McCall0ad16662009-10-29 08:12:44 +00001291 case TemplateArgument::Expression:
1292 Visit(Arg.getAsExpr());
1293 break;
Mike Stump11289f42009-09-09 15:08:12 +00001294
John McCall0ad16662009-10-29 08:12:44 +00001295 case TemplateArgument::Pack:
1296 const TemplateArgument *Pack = Arg.pack_begin();
1297 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1298 VisitTemplateArgument(Pack[i]);
1299 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001300 }
1301}
1302
Jay Foad39c79802011-01-12 09:06:06 +00001303void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001304 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001305 StmtProfiler Profiler(ID, Context, Canonical);
1306 Profiler.Visit(this);
1307}