blob: 35f37ddaa798293745ee3fc6bc300bd6397397bf [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);
Chandler Carruth631abd92011-06-16 06:47:06 +000082 for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
Douglas Gregor44882592009-07-28 15:27:13 +000083 D != DEnd; ++D)
84 VisitDecl(*D);
85}
86
Chandler Carruth631abd92011-06-16 06:47:06 +000087void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000088 VisitStmt(S);
89}
90
Chandler Carruth631abd92011-06-16 06:47:06 +000091void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000092 VisitStmt(S);
93}
94
Chandler Carruth631abd92011-06-16 06:47:06 +000095void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000096 VisitStmt(S);
97}
98
Chandler Carruth631abd92011-06-16 06:47:06 +000099void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000100 VisitStmt(S);
101}
102
Chandler Carruth631abd92011-06-16 06:47:06 +0000103void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000104 VisitStmt(S);
105}
106
Chandler Carruth631abd92011-06-16 06:47:06 +0000107void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000108 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000109 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000110}
111
Richard Smithc202b282012-04-14 00:33:13 +0000112void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
113 VisitStmt(S);
114 // TODO: maybe visit attributes?
115}
116
Chandler Carruth631abd92011-06-16 06:47:06 +0000117void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000118 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000119 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000120}
121
Chandler Carruth631abd92011-06-16 06:47:06 +0000122void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000123 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000124 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000125}
126
Chandler Carruth631abd92011-06-16 06:47:06 +0000127void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000128 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000129 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000130}
131
Chandler Carruth631abd92011-06-16 06:47:06 +0000132void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000133 VisitStmt(S);
134}
135
Chandler Carruth631abd92011-06-16 06:47:06 +0000136void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000137 VisitStmt(S);
138}
139
Chandler Carruth631abd92011-06-16 06:47:06 +0000140void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000141 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000142 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000143}
144
Chandler Carruth631abd92011-06-16 06:47:06 +0000145void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000146 VisitStmt(S);
147}
148
Chandler Carruth631abd92011-06-16 06:47:06 +0000149void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000150 VisitStmt(S);
151}
152
Chandler Carruth631abd92011-06-16 06:47:06 +0000153void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000154 VisitStmt(S);
155}
156
Chandler Carruth631abd92011-06-16 06:47:06 +0000157void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000158 VisitStmt(S);
159}
160
Chad Rosierde70e0e2012-08-25 00:11:56 +0000161void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000162 VisitStmt(S);
163 ID.AddBoolean(S->isVolatile());
164 ID.AddBoolean(S->isSimple());
165 VisitStringLiteral(S->getAsmString());
166 ID.AddInteger(S->getNumOutputs());
167 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
168 ID.AddString(S->getOutputName(I));
169 VisitStringLiteral(S->getOutputConstraintLiteral(I));
170 }
171 ID.AddInteger(S->getNumInputs());
172 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
173 ID.AddString(S->getInputName(I));
174 VisitStringLiteral(S->getInputConstraintLiteral(I));
175 }
176 ID.AddInteger(S->getNumClobbers());
177 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000178 VisitStringLiteral(S->getClobberStringLiteral(I));
Douglas Gregor44882592009-07-28 15:27:13 +0000179}
180
Chad Rosier32503022012-06-11 20:47:18 +0000181void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
182 // FIXME: Implement MS style inline asm statement profiler.
183 VisitStmt(S);
184}
185
Chandler Carruth631abd92011-06-16 06:47:06 +0000186void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000187 VisitStmt(S);
188 VisitType(S->getCaughtType());
189}
190
Chandler Carruth631abd92011-06-16 06:47:06 +0000191void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000192 VisitStmt(S);
193}
194
Chandler Carruth631abd92011-06-16 06:47:06 +0000195void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000196 VisitStmt(S);
197}
198
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000199void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
200 VisitStmt(S);
201 ID.AddBoolean(S->isIfExists());
202 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
203 VisitName(S->getNameInfo().getName());
204}
205
Chandler Carruth631abd92011-06-16 06:47:06 +0000206void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000207 VisitStmt(S);
208}
209
Chandler Carruth631abd92011-06-16 06:47:06 +0000210void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000211 VisitStmt(S);
212}
213
Chandler Carruth631abd92011-06-16 06:47:06 +0000214void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000215 VisitStmt(S);
216}
217
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000218void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
219 VisitStmt(S);
220}
221
Chandler Carruth631abd92011-06-16 06:47:06 +0000222void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000223 VisitStmt(S);
224}
225
Chandler Carruth631abd92011-06-16 06:47:06 +0000226void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000227 VisitStmt(S);
228 ID.AddBoolean(S->hasEllipsis());
229 if (S->getCatchParamDecl())
230 VisitType(S->getCatchParamDecl()->getType());
231}
232
Chandler Carruth631abd92011-06-16 06:47:06 +0000233void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000234 VisitStmt(S);
235}
236
Chandler Carruth631abd92011-06-16 06:47:06 +0000237void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000238 VisitStmt(S);
239}
240
Chandler Carruth631abd92011-06-16 06:47:06 +0000241void
242StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000243 VisitStmt(S);
244}
245
Chandler Carruth631abd92011-06-16 06:47:06 +0000246void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000247 VisitStmt(S);
248}
249
Chandler Carruth631abd92011-06-16 06:47:06 +0000250void
251StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000252 VisitStmt(S);
253}
254
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000255namespace {
256class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
257 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000258 /// \brief Process clauses with list of variables.
259 template <typename T>
260 void VisitOMPClauseList(T *Node);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000261public:
262 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
263#define OPENMP_CLAUSE(Name, Class) \
264 void Visit##Class(const Class *C);
265#include "clang/Basic/OpenMPKinds.def"
266};
267
268void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000269
270template<typename T>
271void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
272 for (typename T::varlist_const_iterator I = Node->varlist_begin(),
273 E = Node->varlist_end();
274 I != E; ++I)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000275 Profiler->VisitStmt(*I);
Alexey Bataev756c1962013-09-24 03:17:45 +0000276}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000277
278void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000279 VisitOMPClauseList(C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000280}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000281void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000282 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000283}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000284}
285
286void
287StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
288 VisitStmt(S);
289 OMPClauseProfiler P(this);
290 ArrayRef<OMPClause *> Clauses = S->clauses();
291 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
292 I != E; ++I)
293 if (*I)
294 P.Visit(*I);
295}
296
Chandler Carruth631abd92011-06-16 06:47:06 +0000297void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000298 VisitStmt(S);
299}
300
Chandler Carruth631abd92011-06-16 06:47:06 +0000301void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000302 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000303 if (!Canonical)
304 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000305 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000306 if (!Canonical)
307 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000308}
309
Chandler Carruth631abd92011-06-16 06:47:06 +0000310void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000311 VisitExpr(S);
312 ID.AddInteger(S->getIdentType());
313}
314
Chandler Carruth631abd92011-06-16 06:47:06 +0000315void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000316 VisitExpr(S);
317 S->getValue().Profile(ID);
318}
319
Chandler Carruth631abd92011-06-16 06:47:06 +0000320void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000321 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000322 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000323 ID.AddInteger(S->getValue());
324}
325
Chandler Carruth631abd92011-06-16 06:47:06 +0000326void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000327 VisitExpr(S);
328 S->getValue().Profile(ID);
329 ID.AddBoolean(S->isExact());
330}
331
Chandler Carruth631abd92011-06-16 06:47:06 +0000332void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000333 VisitExpr(S);
334}
335
Chandler Carruth631abd92011-06-16 06:47:06 +0000336void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000337 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000338 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000339 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000340}
341
Chandler Carruth631abd92011-06-16 06:47:06 +0000342void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000343 VisitExpr(S);
344}
345
Chandler Carruth631abd92011-06-16 06:47:06 +0000346void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000347 VisitExpr(S);
348}
349
Chandler Carruth631abd92011-06-16 06:47:06 +0000350void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000351 VisitExpr(S);
352 ID.AddInteger(S->getOpcode());
353}
354
Chandler Carruth631abd92011-06-16 06:47:06 +0000355void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000356 VisitType(S->getTypeSourceInfo()->getType());
357 unsigned n = S->getNumComponents();
358 for (unsigned i = 0; i < n; ++i) {
359 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
360 ID.AddInteger(ON.getKind());
361 switch (ON.getKind()) {
362 case OffsetOfExpr::OffsetOfNode::Array:
363 // Expressions handled below.
364 break;
365
366 case OffsetOfExpr::OffsetOfNode::Field:
367 VisitDecl(ON.getField());
368 break;
369
370 case OffsetOfExpr::OffsetOfNode::Identifier:
371 ID.AddPointer(ON.getFieldName());
372 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000373
Douglas Gregord1702062010-04-29 00:18:15 +0000374 case OffsetOfExpr::OffsetOfNode::Base:
375 // These nodes are implicit, and therefore don't need profiling.
376 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000377 }
378 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000379
Douglas Gregor882211c2010-04-28 22:16:22 +0000380 VisitExpr(S);
381}
382
Chandler Carruth631abd92011-06-16 06:47:06 +0000383void
384StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000385 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000386 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000387 if (S->isArgumentType())
388 VisitType(S->getArgumentType());
389}
390
Chandler Carruth631abd92011-06-16 06:47:06 +0000391void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000392 VisitExpr(S);
393}
394
Chandler Carruth631abd92011-06-16 06:47:06 +0000395void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000396 VisitExpr(S);
397}
398
Chandler Carruth631abd92011-06-16 06:47:06 +0000399void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000400 VisitExpr(S);
401 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000402 if (!Canonical)
403 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000404 ID.AddBoolean(S->isArrow());
405}
406
Chandler Carruth631abd92011-06-16 06:47:06 +0000407void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000408 VisitExpr(S);
409 ID.AddBoolean(S->isFileScope());
410}
411
Chandler Carruth631abd92011-06-16 06:47:06 +0000412void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000413 VisitExpr(S);
414}
415
Chandler Carruth631abd92011-06-16 06:47:06 +0000416void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000417 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000418 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000419}
420
Chandler Carruth631abd92011-06-16 06:47:06 +0000421void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000422 VisitCastExpr(S);
423 VisitType(S->getTypeAsWritten());
424}
425
Chandler Carruth631abd92011-06-16 06:47:06 +0000426void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000427 VisitExplicitCastExpr(S);
428}
429
Chandler Carruth631abd92011-06-16 06:47:06 +0000430void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000431 VisitExpr(S);
432 ID.AddInteger(S->getOpcode());
433}
434
Chandler Carruth631abd92011-06-16 06:47:06 +0000435void
436StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000437 VisitBinaryOperator(S);
438}
439
Chandler Carruth631abd92011-06-16 06:47:06 +0000440void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000441 VisitExpr(S);
442}
443
Chandler Carruth631abd92011-06-16 06:47:06 +0000444void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000445 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000446 VisitExpr(S);
447}
448
Chandler Carruth631abd92011-06-16 06:47:06 +0000449void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000450 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000451 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000452}
453
Chandler Carruth631abd92011-06-16 06:47:06 +0000454void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000455 VisitExpr(S);
456}
457
Chandler Carruth631abd92011-06-16 06:47:06 +0000458void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000459 VisitExpr(S);
460}
461
Hal Finkelc4d7c822013-09-18 03:29:45 +0000462void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
463 VisitExpr(S);
464}
465
Chandler Carruth631abd92011-06-16 06:47:06 +0000466void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000467 VisitExpr(S);
468}
469
Chandler Carruth631abd92011-06-16 06:47:06 +0000470void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000471 VisitExpr(S);
472}
473
Chandler Carruth631abd92011-06-16 06:47:06 +0000474void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000475 VisitExpr(S);
476}
477
Chandler Carruth631abd92011-06-16 06:47:06 +0000478void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000479 if (S->getSyntacticForm()) {
480 VisitInitListExpr(S->getSyntacticForm());
481 return;
482 }
Mike Stump11289f42009-09-09 15:08:12 +0000483
Douglas Gregor5c193b92009-07-28 00:33:38 +0000484 VisitExpr(S);
485}
486
Chandler Carruth631abd92011-06-16 06:47:06 +0000487void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000488 VisitExpr(S);
489 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000490 for (DesignatedInitExpr::const_designators_iterator D =
491 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000492 D != DEnd; ++D) {
493 if (D->isFieldDesignator()) {
494 ID.AddInteger(0);
495 VisitName(D->getFieldName());
496 continue;
497 }
Mike Stump11289f42009-09-09 15:08:12 +0000498
Douglas Gregor5c193b92009-07-28 00:33:38 +0000499 if (D->isArrayDesignator()) {
500 ID.AddInteger(1);
501 } else {
502 assert(D->isArrayRangeDesignator());
503 ID.AddInteger(2);
504 }
505 ID.AddInteger(D->getFirstExprIndex());
506 }
507}
508
Chandler Carruth631abd92011-06-16 06:47:06 +0000509void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000510 VisitExpr(S);
511}
512
Chandler Carruth631abd92011-06-16 06:47:06 +0000513void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000514 VisitExpr(S);
515 VisitName(&S->getAccessor());
516}
517
Chandler Carruth631abd92011-06-16 06:47:06 +0000518void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000519 VisitExpr(S);
520 VisitDecl(S->getBlockDecl());
521}
522
Chandler Carruth631abd92011-06-16 06:47:06 +0000523void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000524 VisitExpr(S);
525 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
526 QualType T = S->getAssocType(i);
527 if (T.isNull())
528 ID.AddPointer(0);
529 else
530 VisitType(T);
531 VisitExpr(S->getAssocExpr(i));
532 }
533}
534
John McCallfe96e0b2011-11-06 09:01:30 +0000535void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
536 VisitExpr(S);
537 for (PseudoObjectExpr::const_semantics_iterator
538 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
539 // Normally, we would not profile the source expressions of OVEs.
540 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
541 Visit(OVE->getSourceExpr());
542}
543
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000544void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
545 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000546 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000547}
548
Chandler Carruth631abd92011-06-16 06:47:06 +0000549static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000550 UnaryOperatorKind &UnaryOp,
551 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000552 switch (S->getOperator()) {
553 case OO_None:
554 case OO_New:
555 case OO_Delete:
556 case OO_Array_New:
557 case OO_Array_Delete:
558 case OO_Arrow:
559 case OO_Call:
560 case OO_Conditional:
561 case NUM_OVERLOADED_OPERATORS:
562 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000563
564 case OO_Plus:
565 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000566 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000567 return Stmt::UnaryOperatorClass;
568 }
569
John McCalle3027922010-08-25 11:45:40 +0000570 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000571 return Stmt::BinaryOperatorClass;
572
573 case OO_Minus:
574 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000575 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000576 return Stmt::UnaryOperatorClass;
577 }
578
John McCalle3027922010-08-25 11:45:40 +0000579 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000580 return Stmt::BinaryOperatorClass;
581
582 case OO_Star:
583 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000584 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000585 return Stmt::UnaryOperatorClass;
586 }
587
John McCalle3027922010-08-25 11:45:40 +0000588 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000589 return Stmt::BinaryOperatorClass;
590
591 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000592 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000593 return Stmt::BinaryOperatorClass;
594
595 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000596 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000597 return Stmt::BinaryOperatorClass;
598
599 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000600 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000601 return Stmt::BinaryOperatorClass;
602
603 case OO_Amp:
604 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000605 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000606 return Stmt::UnaryOperatorClass;
607 }
608
John McCalle3027922010-08-25 11:45:40 +0000609 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000610 return Stmt::BinaryOperatorClass;
611
612 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000613 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000614 return Stmt::BinaryOperatorClass;
615
616 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000617 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000618 return Stmt::UnaryOperatorClass;
619
620 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000621 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000622 return Stmt::UnaryOperatorClass;
623
624 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000625 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000626 return Stmt::BinaryOperatorClass;
627
628 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000629 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000630 return Stmt::BinaryOperatorClass;
631
632 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000633 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000634 return Stmt::BinaryOperatorClass;
635
636 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000637 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000638 return Stmt::CompoundAssignOperatorClass;
639
640 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000641 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000642 return Stmt::CompoundAssignOperatorClass;
643
644 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000645 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000646 return Stmt::CompoundAssignOperatorClass;
647
648 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000649 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000650 return Stmt::CompoundAssignOperatorClass;
651
652 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000653 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000654 return Stmt::CompoundAssignOperatorClass;
655
656 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000657 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000658 return Stmt::CompoundAssignOperatorClass;
659
660 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000661 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000662 return Stmt::CompoundAssignOperatorClass;
663
664 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000665 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000666 return Stmt::CompoundAssignOperatorClass;
667
668 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000669 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000670 return Stmt::BinaryOperatorClass;
671
672 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000673 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000674 return Stmt::BinaryOperatorClass;
675
676 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000677 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000678 return Stmt::CompoundAssignOperatorClass;
679
680 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000681 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000682 return Stmt::CompoundAssignOperatorClass;
683
684 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000685 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000686 return Stmt::BinaryOperatorClass;
687
688 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000689 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000690 return Stmt::BinaryOperatorClass;
691
692 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000693 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000694 return Stmt::BinaryOperatorClass;
695
696 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000697 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000698 return Stmt::BinaryOperatorClass;
699
700 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000701 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000702 return Stmt::BinaryOperatorClass;
703
704 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000705 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000706 return Stmt::BinaryOperatorClass;
707
708 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000709 UnaryOp = S->getNumArgs() == 1? UO_PreInc
710 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000711 return Stmt::UnaryOperatorClass;
712
713 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000714 UnaryOp = S->getNumArgs() == 1? UO_PreDec
715 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000716 return Stmt::UnaryOperatorClass;
717
718 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000719 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000720 return Stmt::BinaryOperatorClass;
721
722
723 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000724 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000725 return Stmt::BinaryOperatorClass;
726
727 case OO_Subscript:
728 return Stmt::ArraySubscriptExprClass;
729 }
730
731 llvm_unreachable("Invalid overloaded operator expression");
732}
733
734
Chandler Carruth631abd92011-06-16 06:47:06 +0000735void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000736 if (S->isTypeDependent()) {
737 // Type-dependent operator calls are profiled like their underlying
738 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000739 UnaryOperatorKind UnaryOp = UO_Extension;
740 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000741 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
742
743 ID.AddInteger(SC);
744 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
745 Visit(S->getArg(I));
746 if (SC == Stmt::UnaryOperatorClass)
747 ID.AddInteger(UnaryOp);
748 else if (SC == Stmt::BinaryOperatorClass ||
749 SC == Stmt::CompoundAssignOperatorClass)
750 ID.AddInteger(BinaryOp);
751 else
752 assert(SC == Stmt::ArraySubscriptExprClass);
753
754 return;
755 }
756
Douglas Gregor5c193b92009-07-28 00:33:38 +0000757 VisitCallExpr(S);
758 ID.AddInteger(S->getOperator());
759}
760
Chandler Carruth631abd92011-06-16 06:47:06 +0000761void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000762 VisitCallExpr(S);
763}
764
Chandler Carruth631abd92011-06-16 06:47:06 +0000765void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000766 VisitCallExpr(S);
767}
768
Chandler Carruth631abd92011-06-16 06:47:06 +0000769void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000770 VisitExpr(S);
771}
772
Chandler Carruth631abd92011-06-16 06:47:06 +0000773void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000774 VisitExplicitCastExpr(S);
775}
776
Chandler Carruth631abd92011-06-16 06:47:06 +0000777void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000778 VisitCXXNamedCastExpr(S);
779}
780
Chandler Carruth631abd92011-06-16 06:47:06 +0000781void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000782 VisitCXXNamedCastExpr(S);
783}
784
Chandler Carruth631abd92011-06-16 06:47:06 +0000785void
786StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000787 VisitCXXNamedCastExpr(S);
788}
789
Chandler Carruth631abd92011-06-16 06:47:06 +0000790void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000791 VisitCXXNamedCastExpr(S);
792}
793
Richard Smithc67fdd42012-03-07 08:35:16 +0000794void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
795 VisitCallExpr(S);
796}
797
Chandler Carruth631abd92011-06-16 06:47:06 +0000798void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000799 VisitExpr(S);
800 ID.AddBoolean(S->getValue());
801}
802
Chandler Carruth631abd92011-06-16 06:47:06 +0000803void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000804 VisitExpr(S);
805}
806
Richard Smithcc1b96d2013-06-12 22:31:48 +0000807void StmtProfiler::VisitCXXStdInitializerListExpr(
808 const CXXStdInitializerListExpr *S) {
809 VisitExpr(S);
810}
811
Chandler Carruth631abd92011-06-16 06:47:06 +0000812void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000813 VisitExpr(S);
814 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000815 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000816}
817
Chandler Carruth631abd92011-06-16 06:47:06 +0000818void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000819 VisitExpr(S);
820 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000821 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000822}
823
John McCall5e77d762013-04-16 07:28:30 +0000824void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
825 VisitExpr(S);
826 VisitDecl(S->getPropertyDecl());
827}
828
Chandler Carruth631abd92011-06-16 06:47:06 +0000829void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000830 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000831 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000832}
833
Chandler Carruth631abd92011-06-16 06:47:06 +0000834void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000835 VisitExpr(S);
836}
837
Chandler Carruth631abd92011-06-16 06:47:06 +0000838void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000839 VisitExpr(S);
840 VisitDecl(S->getParam());
841}
842
Richard Smith852c9db2013-04-20 22:23:05 +0000843void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
844 VisitExpr(S);
845 VisitDecl(S->getField());
846}
847
Chandler Carruth631abd92011-06-16 06:47:06 +0000848void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000849 VisitExpr(S);
850 VisitDecl(
851 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
852}
853
Chandler Carruth631abd92011-06-16 06:47:06 +0000854void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000855 VisitExpr(S);
856 VisitDecl(S->getConstructor());
857 ID.AddBoolean(S->isElidable());
858}
859
Chandler Carruth631abd92011-06-16 06:47:06 +0000860void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000861 VisitExplicitCastExpr(S);
862}
863
Chandler Carruth631abd92011-06-16 06:47:06 +0000864void
865StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000866 VisitCXXConstructExpr(S);
867}
868
Chandler Carruth631abd92011-06-16 06:47:06 +0000869void
Douglas Gregore31e6062012-02-07 10:09:13 +0000870StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
871 VisitExpr(S);
872 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
873 CEnd = S->explicit_capture_end();
874 C != CEnd; ++C) {
875 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +0000876 switch (C->getCaptureKind()) {
877 case LCK_This:
878 break;
879 case LCK_ByRef:
880 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +0000881 VisitDecl(C->getCapturedVar());
882 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +0000883 break;
Douglas Gregore31e6062012-02-07 10:09:13 +0000884 }
885 }
886 // Note: If we actually needed to be able to match lambda
887 // expressions, we would have to consider parameters and return type
888 // here, among other things.
889 VisitStmt(S->getBody());
890}
891
892void
Chandler Carruth631abd92011-06-16 06:47:06 +0000893StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000894 VisitExpr(S);
895}
896
Chandler Carruth631abd92011-06-16 06:47:06 +0000897void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000898 VisitExpr(S);
899 ID.AddBoolean(S->isGlobalDelete());
900 ID.AddBoolean(S->isArrayForm());
901 VisitDecl(S->getOperatorDelete());
902}
903
904
Chandler Carruth631abd92011-06-16 06:47:06 +0000905void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000906 VisitExpr(S);
907 VisitType(S->getAllocatedType());
908 VisitDecl(S->getOperatorNew());
909 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000910 ID.AddBoolean(S->isArray());
911 ID.AddInteger(S->getNumPlacementArgs());
912 ID.AddBoolean(S->isGlobalNew());
913 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +0000914 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000915}
916
Chandler Carruth631abd92011-06-16 06:47:06 +0000917void
918StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +0000919 VisitExpr(S);
920 ID.AddBoolean(S->isArrow());
921 VisitNestedNameSpecifier(S->getQualifier());
Eli Friedman85641392013-08-09 23:37:05 +0000922 ID.AddBoolean(S->getScopeTypeInfo() != 0);
923 if (S->getScopeTypeInfo())
924 VisitType(S->getScopeTypeInfo()->getType());
925 ID.AddBoolean(S->getDestroyedTypeInfo() != 0);
926 if (S->getDestroyedTypeInfo())
927 VisitType(S->getDestroyedType());
928 else
929 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +0000930}
931
Chandler Carruth631abd92011-06-16 06:47:06 +0000932void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000933 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000934 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000935 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +0000936 ID.AddBoolean(S->hasExplicitTemplateArgs());
937 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000938 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
939 S->getExplicitTemplateArgs().NumTemplateArgs);
940}
941
942void
Chandler Carruth631abd92011-06-16 06:47:06 +0000943StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000944 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +0000945}
946
Chandler Carruth631abd92011-06-16 06:47:06 +0000947void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000948 VisitExpr(S);
949 ID.AddInteger(S->getTrait());
950 VisitType(S->getQueriedType());
951}
952
Chandler Carruth631abd92011-06-16 06:47:06 +0000953void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
Francois Pichet9dfa3ce2010-12-07 00:08:36 +0000954 VisitExpr(S);
955 ID.AddInteger(S->getTrait());
956 VisitType(S->getLhsType());
957 VisitType(S->getRhsType());
958}
959
Douglas Gregor29c42f22012-02-24 07:38:34 +0000960void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
961 VisitExpr(S);
962 ID.AddInteger(S->getTrait());
963 ID.AddInteger(S->getNumArgs());
964 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
965 VisitType(S->getArg(I)->getType());
966}
967
Chandler Carruth631abd92011-06-16 06:47:06 +0000968void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +0000969 VisitExpr(S);
970 ID.AddInteger(S->getTrait());
971 VisitType(S->getQueriedType());
972}
973
Chandler Carruth631abd92011-06-16 06:47:06 +0000974void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +0000975 VisitExpr(S);
976 ID.AddInteger(S->getTrait());
977 VisitExpr(S->getQueriedExpression());
978}
979
Chandler Carruth631abd92011-06-16 06:47:06 +0000980void StmtProfiler::VisitDependentScopeDeclRefExpr(
981 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000982 VisitExpr(S);
983 VisitName(S->getDeclName());
984 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +0000985 ID.AddBoolean(S->hasExplicitTemplateArgs());
986 if (S->hasExplicitTemplateArgs())
987 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000988}
989
Chandler Carruth631abd92011-06-16 06:47:06 +0000990void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +0000991 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +0000992}
993
Chandler Carruth631abd92011-06-16 06:47:06 +0000994void StmtProfiler::VisitCXXUnresolvedConstructExpr(
995 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +0000996 VisitExpr(S);
997 VisitType(S->getTypeAsWritten());
998}
999
Chandler Carruth631abd92011-06-16 06:47:06 +00001000void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1001 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001002 ID.AddBoolean(S->isImplicitAccess());
1003 if (!S->isImplicitAccess()) {
1004 VisitExpr(S);
1005 ID.AddBoolean(S->isArrow());
1006 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001007 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001008 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001009 ID.AddBoolean(S->hasExplicitTemplateArgs());
1010 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001011 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1012}
1013
Chandler Carruth631abd92011-06-16 06:47:06 +00001014void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001015 ID.AddBoolean(S->isImplicitAccess());
1016 if (!S->isImplicitAccess()) {
1017 VisitExpr(S);
1018 ID.AddBoolean(S->isArrow());
1019 }
John McCall10eae182009-11-30 22:42:35 +00001020 VisitNestedNameSpecifier(S->getQualifier());
1021 VisitName(S->getMemberName());
1022 ID.AddBoolean(S->hasExplicitTemplateArgs());
1023 if (S->hasExplicitTemplateArgs())
1024 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001025}
1026
Chandler Carruth631abd92011-06-16 06:47:06 +00001027void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001028 VisitExpr(S);
1029}
1030
Chandler Carruth631abd92011-06-16 06:47:06 +00001031void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001032 VisitExpr(S);
1033}
1034
Chandler Carruth631abd92011-06-16 06:47:06 +00001035void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001036 VisitExpr(S);
1037 VisitDecl(S->getPack());
1038}
1039
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001040void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001041 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001042 VisitExpr(S);
1043 VisitDecl(S->getParameterPack());
1044 VisitTemplateArgument(S->getArgumentPack());
1045}
1046
John McCall7c454bb2011-07-15 05:09:51 +00001047void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1048 const SubstNonTypeTemplateParmExpr *E) {
1049 // Profile exactly as the replacement expression.
1050 Visit(E->getReplacement());
1051}
1052
Richard Smithb15fe3a2012-09-12 00:56:43 +00001053void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1054 VisitExpr(S);
1055 VisitDecl(S->getParameterPack());
1056 ID.AddInteger(S->getNumExpansions());
1057 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1058 VisitDecl(*I);
1059}
1060
Douglas Gregorfe314812011-06-21 17:03:29 +00001061void StmtProfiler::VisitMaterializeTemporaryExpr(
1062 const MaterializeTemporaryExpr *S) {
1063 VisitExpr(S);
1064}
1065
Chandler Carruth631abd92011-06-16 06:47:06 +00001066void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001067 VisitExpr(E);
1068}
1069
Chandler Carruth631abd92011-06-16 06:47:06 +00001070void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001071 VisitExpr(S);
1072}
1073
Patrick Beard0caa3942012-04-19 00:25:12 +00001074void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001075 VisitExpr(E);
1076}
1077
1078void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1079 VisitExpr(E);
1080}
1081
1082void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1083 VisitExpr(E);
1084}
1085
Chandler Carruth631abd92011-06-16 06:47:06 +00001086void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001087 VisitExpr(S);
1088 VisitType(S->getEncodedType());
1089}
1090
Chandler Carruth631abd92011-06-16 06:47:06 +00001091void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001092 VisitExpr(S);
1093 VisitName(S->getSelector());
1094}
1095
Chandler Carruth631abd92011-06-16 06:47:06 +00001096void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001097 VisitExpr(S);
1098 VisitDecl(S->getProtocol());
1099}
1100
Chandler Carruth631abd92011-06-16 06:47:06 +00001101void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001102 VisitExpr(S);
1103 VisitDecl(S->getDecl());
1104 ID.AddBoolean(S->isArrow());
1105 ID.AddBoolean(S->isFreeIvar());
1106}
1107
Chandler Carruth631abd92011-06-16 06:47:06 +00001108void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001109 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001110 if (S->isImplicitProperty()) {
1111 VisitDecl(S->getImplicitPropertyGetter());
1112 VisitDecl(S->getImplicitPropertySetter());
1113 } else {
1114 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001115 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001116 if (S->isSuperReceiver()) {
1117 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001118 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001119 }
Douglas Gregora7095092009-07-28 14:44:31 +00001120}
1121
Ted Kremeneke65b0862012-03-06 20:05:56 +00001122void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1123 VisitExpr(S);
1124 VisitDecl(S->getAtIndexMethodDecl());
1125 VisitDecl(S->setAtIndexMethodDecl());
1126}
1127
Chandler Carruth631abd92011-06-16 06:47:06 +00001128void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001129 VisitExpr(S);
1130 VisitName(S->getSelector());
1131 VisitDecl(S->getMethodDecl());
1132}
1133
Chandler Carruth631abd92011-06-16 06:47:06 +00001134void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001135 VisitExpr(S);
1136 ID.AddBoolean(S->isArrow());
1137}
1138
Ted Kremeneke65b0862012-03-06 20:05:56 +00001139void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1140 VisitExpr(S);
1141 ID.AddBoolean(S->getValue());
1142}
1143
Chandler Carruth631abd92011-06-16 06:47:06 +00001144void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1145 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001146 VisitExpr(S);
1147 ID.AddBoolean(S->shouldCopy());
1148}
1149
Chandler Carruth631abd92011-06-16 06:47:06 +00001150void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001151 VisitExplicitCastExpr(S);
1152 ID.AddBoolean(S->getBridgeKind());
1153}
1154
Chandler Carruth631abd92011-06-16 06:47:06 +00001155void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001156 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001157
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001158 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001159 if (const NonTypeTemplateParmDecl *NTTP =
1160 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001161 ID.AddInteger(NTTP->getDepth());
1162 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001163 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001164 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001165 return;
1166 }
Mike Stump11289f42009-09-09 15:08:12 +00001167
Chandler Carruth631abd92011-06-16 06:47:06 +00001168 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001169 // The Itanium C++ ABI uses the type, scope depth, and scope
1170 // index of a parameter when mangling expressions that involve
1171 // function parameters, so we will use the parameter's type for
1172 // establishing function parameter identity. That way, our
1173 // definition of "equivalent" (per C++ [temp.over.link]) is at
1174 // least as strong as the definition of "equivalent" used for
1175 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001176 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001177 ID.AddInteger(Parm->getFunctionScopeDepth());
1178 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001179 return;
1180 }
Mike Stump11289f42009-09-09 15:08:12 +00001181
Richard Smithd9a1cd82012-04-02 18:53:24 +00001182 if (const TemplateTypeParmDecl *TTP =
1183 dyn_cast<TemplateTypeParmDecl>(D)) {
1184 ID.AddInteger(TTP->getDepth());
1185 ID.AddInteger(TTP->getIndex());
1186 ID.AddBoolean(TTP->isParameterPack());
1187 return;
1188 }
1189
Chandler Carruth631abd92011-06-16 06:47:06 +00001190 if (const TemplateTemplateParmDecl *TTP =
1191 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001192 ID.AddInteger(TTP->getDepth());
1193 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001194 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001195 return;
1196 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001197 }
Mike Stump11289f42009-09-09 15:08:12 +00001198
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001199 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1200}
1201
1202void StmtProfiler::VisitType(QualType T) {
1203 if (Canonical)
1204 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001205
Douglas Gregor5c193b92009-07-28 00:33:38 +00001206 ID.AddPointer(T.getAsOpaquePtr());
1207}
1208
1209void StmtProfiler::VisitName(DeclarationName Name) {
1210 ID.AddPointer(Name.getAsOpaquePtr());
1211}
1212
1213void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1214 if (Canonical)
1215 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1216 ID.AddPointer(NNS);
1217}
1218
1219void StmtProfiler::VisitTemplateName(TemplateName Name) {
1220 if (Canonical)
1221 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001222
Douglas Gregor5c193b92009-07-28 00:33:38 +00001223 Name.Profile(ID);
1224}
1225
John McCall0ad16662009-10-29 08:12:44 +00001226void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001227 unsigned NumArgs) {
1228 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001229 for (unsigned I = 0; I != NumArgs; ++I)
1230 VisitTemplateArgument(Args[I].getArgument());
1231}
Mike Stump11289f42009-09-09 15:08:12 +00001232
John McCall0ad16662009-10-29 08:12:44 +00001233void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1234 // Mostly repetitive with TemplateArgument::Profile!
1235 ID.AddInteger(Arg.getKind());
1236 switch (Arg.getKind()) {
1237 case TemplateArgument::Null:
1238 break;
Mike Stump11289f42009-09-09 15:08:12 +00001239
John McCall0ad16662009-10-29 08:12:44 +00001240 case TemplateArgument::Type:
1241 VisitType(Arg.getAsType());
1242 break;
Mike Stump11289f42009-09-09 15:08:12 +00001243
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001244 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001245 case TemplateArgument::TemplateExpansion:
1246 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001247 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001248
John McCall0ad16662009-10-29 08:12:44 +00001249 case TemplateArgument::Declaration:
1250 VisitDecl(Arg.getAsDecl());
1251 break;
Mike Stump11289f42009-09-09 15:08:12 +00001252
Eli Friedmanb826a002012-09-26 02:36:12 +00001253 case TemplateArgument::NullPtr:
1254 VisitType(Arg.getNullPtrType());
1255 break;
1256
John McCall0ad16662009-10-29 08:12:44 +00001257 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001258 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001259 VisitType(Arg.getIntegralType());
1260 break;
Mike Stump11289f42009-09-09 15:08:12 +00001261
John McCall0ad16662009-10-29 08:12:44 +00001262 case TemplateArgument::Expression:
1263 Visit(Arg.getAsExpr());
1264 break;
Mike Stump11289f42009-09-09 15:08:12 +00001265
John McCall0ad16662009-10-29 08:12:44 +00001266 case TemplateArgument::Pack:
1267 const TemplateArgument *Pack = Arg.pack_begin();
1268 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1269 VisitTemplateArgument(Pack[i]);
1270 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001271 }
1272}
1273
Jay Foad39c79802011-01-12 09:06:06 +00001274void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001275 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001276 StmtProfiler Profiler(ID, Context, Canonical);
1277 Profiler.Visit(this);
1278}