blob: 5a6b771b9a8e6462e0a3980afb00c9ff7e94a01b [file] [log] [blame]
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001//===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt::Profile method, which builds a unique bit
Douglas Gregor00aa3a62009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor41ef0c32009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregor071f4eb2009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000017#include "clang/AST/DeclTemplate.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/ExprCXX.h"
20#include "clang/AST/ExprObjC.h"
21#include "clang/AST/StmtVisitor.h"
22#include "llvm/ADT/FoldingSet.h"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000023using namespace clang;
24
25namespace {
Chandler Carruthb1138242011-06-16 06:47:06 +000026 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Douglas Gregor41ef0c32009-07-28 00:33:38 +000027 llvm::FoldingSetNodeID &ID;
Jay Foad4ba2a172011-01-12 09:06:06 +000028 const ASTContext &Context;
Douglas Gregor41ef0c32009-07-28 00:33:38 +000029 bool Canonical;
Mike Stump1eb44332009-09-09 15:08:12 +000030
Douglas Gregor41ef0c32009-07-28 00:33:38 +000031 public:
Jay Foad4ba2a172011-01-12 09:06:06 +000032 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump1eb44332009-09-09 15:08:12 +000033 bool Canonical)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000034 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump1eb44332009-09-09 15:08:12 +000035
Chandler Carruthb1138242011-06-16 06:47:06 +000036 void VisitStmt(const Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +000037
Chandler Carruthb1138242011-06-16 06:47:06 +000038#define STMT(Node, Base) void Visit##Node(const Node *S);
Sean Hunt4bfe1962010-05-05 15:24:00 +000039#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +000040
Douglas Gregor41ef0c32009-07-28 00:33:38 +000041 /// \brief Visit a declaration that is referenced within an expression
42 /// or statement.
Chandler Carruthb1138242011-06-16 06:47:06 +000043 void VisitDecl(const Decl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000044
45 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor41ef0c32009-07-28 00:33:38 +000046 /// statement.
47 void VisitType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +000048
Douglas Gregor41ef0c32009-07-28 00:33:38 +000049 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000051
Douglas Gregor41ef0c32009-07-28 00:33:38 +000052 /// \brief Visit a nested-name-specifier that occurs within an expression
53 /// or statement.
54 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump1eb44332009-09-09 15:08:12 +000055
Douglas Gregor41ef0c32009-07-28 00:33:38 +000056 /// \brief Visit a template name that occurs within an expression or
57 /// statement.
58 void VisitTemplateName(TemplateName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000059
Douglas Gregor41ef0c32009-07-28 00:33:38 +000060 /// \brief Visit template arguments that occur within an expression or
61 /// statement.
Chandler Carruthb1138242011-06-16 06:47:06 +000062 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
63 unsigned NumArgs);
John McCall833ca992009-10-29 08:12:44 +000064
65 /// \brief Visit a single template argument.
66 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor41ef0c32009-07-28 00:33:38 +000067 };
68}
69
Chandler Carruthb1138242011-06-16 06:47:06 +000070void StmtProfiler::VisitStmt(const Stmt *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +000071 ID.AddInteger(S->getStmtClass());
Chandler Carruthb1138242011-06-16 06:47:06 +000072 for (Stmt::const_child_range C = S->children(); C; ++C)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000073 Visit(*C);
74}
75
Chandler Carruthb1138242011-06-16 06:47:06 +000076void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000077 VisitStmt(S);
Chandler Carruthb1138242011-06-16 06:47:06 +000078 for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000079 D != DEnd; ++D)
80 VisitDecl(*D);
81}
82
Chandler Carruthb1138242011-06-16 06:47:06 +000083void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000084 VisitStmt(S);
85}
86
Chandler Carruthb1138242011-06-16 06:47:06 +000087void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000088 VisitStmt(S);
89}
90
Chandler Carruthb1138242011-06-16 06:47:06 +000091void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000092 VisitStmt(S);
93}
94
Chandler Carruthb1138242011-06-16 06:47:06 +000095void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000096 VisitStmt(S);
97}
98
Chandler Carruthb1138242011-06-16 06:47:06 +000099void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000100 VisitStmt(S);
101}
102
Chandler Carruthb1138242011-06-16 06:47:06 +0000103void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000104 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000105 VisitDecl(S->getDecl());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000106}
107
Chandler Carruthb1138242011-06-16 06:47:06 +0000108void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000109 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000110 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000111}
112
Chandler Carruthb1138242011-06-16 06:47:06 +0000113void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000114 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000115 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000116}
117
Chandler Carruthb1138242011-06-16 06:47:06 +0000118void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000119 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000120 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000121}
122
Chandler Carruthb1138242011-06-16 06:47:06 +0000123void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000124 VisitStmt(S);
125}
126
Chandler Carruthb1138242011-06-16 06:47:06 +0000127void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000128 VisitStmt(S);
129}
130
Chandler Carruthb1138242011-06-16 06:47:06 +0000131void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000132 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000133 VisitDecl(S->getLabel());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000134}
135
Chandler Carruthb1138242011-06-16 06:47:06 +0000136void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000137 VisitStmt(S);
138}
139
Chandler Carruthb1138242011-06-16 06:47:06 +0000140void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000141 VisitStmt(S);
142}
143
Chandler Carruthb1138242011-06-16 06:47:06 +0000144void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000145 VisitStmt(S);
146}
147
Chandler Carruthb1138242011-06-16 06:47:06 +0000148void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000149 VisitStmt(S);
150}
151
Chandler Carruthb1138242011-06-16 06:47:06 +0000152void StmtProfiler::VisitAsmStmt(const AsmStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000153 VisitStmt(S);
154 ID.AddBoolean(S->isVolatile());
155 ID.AddBoolean(S->isSimple());
156 VisitStringLiteral(S->getAsmString());
157 ID.AddInteger(S->getNumOutputs());
158 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
159 ID.AddString(S->getOutputName(I));
160 VisitStringLiteral(S->getOutputConstraintLiteral(I));
161 }
162 ID.AddInteger(S->getNumInputs());
163 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
164 ID.AddString(S->getInputName(I));
165 VisitStringLiteral(S->getInputConstraintLiteral(I));
166 }
167 ID.AddInteger(S->getNumClobbers());
168 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
169 VisitStringLiteral(S->getClobber(I));
170}
171
Chandler Carruthb1138242011-06-16 06:47:06 +0000172void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000173 VisitStmt(S);
174 VisitType(S->getCaughtType());
175}
176
Chandler Carruthb1138242011-06-16 06:47:06 +0000177void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000178 VisitStmt(S);
179}
180
Chandler Carruthb1138242011-06-16 06:47:06 +0000181void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smithad762fc2011-04-14 22:09:26 +0000182 VisitStmt(S);
183}
184
Douglas Gregorba0513d2011-10-25 01:33:02 +0000185void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
186 VisitStmt(S);
187 ID.AddBoolean(S->isIfExists());
188 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
189 VisitName(S->getNameInfo().getName());
190}
191
Chandler Carruthb1138242011-06-16 06:47:06 +0000192void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000193 VisitStmt(S);
194}
195
Chandler Carruthb1138242011-06-16 06:47:06 +0000196void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000197 VisitStmt(S);
198}
199
Chandler Carruthb1138242011-06-16 06:47:06 +0000200void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000201 VisitStmt(S);
202}
203
Chandler Carruthb1138242011-06-16 06:47:06 +0000204void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000205 VisitStmt(S);
206}
207
Chandler Carruthb1138242011-06-16 06:47:06 +0000208void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000209 VisitStmt(S);
210 ID.AddBoolean(S->hasEllipsis());
211 if (S->getCatchParamDecl())
212 VisitType(S->getCatchParamDecl()->getType());
213}
214
Chandler Carruthb1138242011-06-16 06:47:06 +0000215void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000216 VisitStmt(S);
217}
218
Chandler Carruthb1138242011-06-16 06:47:06 +0000219void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000220 VisitStmt(S);
221}
222
Chandler Carruthb1138242011-06-16 06:47:06 +0000223void
224StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000225 VisitStmt(S);
226}
227
Chandler Carruthb1138242011-06-16 06:47:06 +0000228void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000229 VisitStmt(S);
230}
231
Chandler Carruthb1138242011-06-16 06:47:06 +0000232void
233StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCallf85e1932011-06-15 23:02:42 +0000234 VisitStmt(S);
235}
236
Chandler Carruthb1138242011-06-16 06:47:06 +0000237void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000238 VisitStmt(S);
239}
240
Chandler Carruthb1138242011-06-16 06:47:06 +0000241void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000242 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000243 if (!Canonical)
244 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000245 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000246 if (!Canonical)
247 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000248}
249
Chandler Carruthb1138242011-06-16 06:47:06 +0000250void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000251 VisitExpr(S);
252 ID.AddInteger(S->getIdentType());
253}
254
Chandler Carruthb1138242011-06-16 06:47:06 +0000255void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000256 VisitExpr(S);
257 S->getValue().Profile(ID);
258}
259
Chandler Carruthb1138242011-06-16 06:47:06 +0000260void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000261 VisitExpr(S);
Douglas Gregor5cee1192011-07-27 05:40:30 +0000262 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000263 ID.AddInteger(S->getValue());
264}
265
Chandler Carruthb1138242011-06-16 06:47:06 +0000266void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000267 VisitExpr(S);
268 S->getValue().Profile(ID);
269 ID.AddBoolean(S->isExact());
270}
271
Chandler Carruthb1138242011-06-16 06:47:06 +0000272void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000273 VisitExpr(S);
274}
275
Chandler Carruthb1138242011-06-16 06:47:06 +0000276void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000277 VisitExpr(S);
Douglas Gregor38738fc2011-11-02 17:26:05 +0000278 ID.AddString(S->getBytes());
Douglas Gregor5cee1192011-07-27 05:40:30 +0000279 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000280}
281
Chandler Carruthb1138242011-06-16 06:47:06 +0000282void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000283 VisitExpr(S);
284}
285
Chandler Carruthb1138242011-06-16 06:47:06 +0000286void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman2ef13e52009-08-10 23:49:36 +0000287 VisitExpr(S);
288}
289
Chandler Carruthb1138242011-06-16 06:47:06 +0000290void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000291 VisitExpr(S);
292 ID.AddInteger(S->getOpcode());
293}
294
Chandler Carruthb1138242011-06-16 06:47:06 +0000295void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000296 VisitType(S->getTypeSourceInfo()->getType());
297 unsigned n = S->getNumComponents();
298 for (unsigned i = 0; i < n; ++i) {
299 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
300 ID.AddInteger(ON.getKind());
301 switch (ON.getKind()) {
302 case OffsetOfExpr::OffsetOfNode::Array:
303 // Expressions handled below.
304 break;
305
306 case OffsetOfExpr::OffsetOfNode::Field:
307 VisitDecl(ON.getField());
308 break;
309
310 case OffsetOfExpr::OffsetOfNode::Identifier:
311 ID.AddPointer(ON.getFieldName());
312 break;
Sean Huntc3021132010-05-05 15:23:54 +0000313
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000314 case OffsetOfExpr::OffsetOfNode::Base:
315 // These nodes are implicit, and therefore don't need profiling.
316 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000317 }
318 }
Sean Huntc3021132010-05-05 15:23:54 +0000319
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000320 VisitExpr(S);
321}
322
Chandler Carruthb1138242011-06-16 06:47:06 +0000323void
324StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000325 VisitExpr(S);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000326 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000327 if (S->isArgumentType())
328 VisitType(S->getArgumentType());
329}
330
Chandler Carruthb1138242011-06-16 06:47:06 +0000331void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000332 VisitExpr(S);
333}
334
Chandler Carruthb1138242011-06-16 06:47:06 +0000335void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000336 VisitExpr(S);
337}
338
Chandler Carruthb1138242011-06-16 06:47:06 +0000339void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000340 VisitExpr(S);
341 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000342 if (!Canonical)
343 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000344 ID.AddBoolean(S->isArrow());
345}
346
Chandler Carruthb1138242011-06-16 06:47:06 +0000347void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000348 VisitExpr(S);
349 ID.AddBoolean(S->isFileScope());
350}
351
Chandler Carruthb1138242011-06-16 06:47:06 +0000352void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000353 VisitExpr(S);
354}
355
Chandler Carruthb1138242011-06-16 06:47:06 +0000356void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000357 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000358 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000359}
360
Chandler Carruthb1138242011-06-16 06:47:06 +0000361void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000362 VisitCastExpr(S);
363 VisitType(S->getTypeAsWritten());
364}
365
Chandler Carruthb1138242011-06-16 06:47:06 +0000366void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000367 VisitExplicitCastExpr(S);
368}
369
Chandler Carruthb1138242011-06-16 06:47:06 +0000370void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000371 VisitExpr(S);
372 ID.AddInteger(S->getOpcode());
373}
374
Chandler Carruthb1138242011-06-16 06:47:06 +0000375void
376StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000377 VisitBinaryOperator(S);
378}
379
Chandler Carruthb1138242011-06-16 06:47:06 +0000380void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000381 VisitExpr(S);
382}
383
Chandler Carruthb1138242011-06-16 06:47:06 +0000384void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruth08949762011-06-21 23:26:32 +0000385 const BinaryConditionalOperator *S) {
John McCall56ca35d2011-02-17 10:25:35 +0000386 VisitExpr(S);
387}
388
Chandler Carruthb1138242011-06-16 06:47:06 +0000389void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000390 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000391 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000392}
393
Chandler Carruthb1138242011-06-16 06:47:06 +0000394void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000395 VisitExpr(S);
396}
397
Chandler Carruthb1138242011-06-16 06:47:06 +0000398void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000399 VisitExpr(S);
400}
401
Chandler Carruthb1138242011-06-16 06:47:06 +0000402void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000403 VisitExpr(S);
404}
405
Chandler Carruthb1138242011-06-16 06:47:06 +0000406void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000407 VisitExpr(S);
408}
409
Chandler Carruthb1138242011-06-16 06:47:06 +0000410void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000411 VisitExpr(S);
412}
413
Chandler Carruthb1138242011-06-16 06:47:06 +0000414void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000415 if (S->getSyntacticForm()) {
416 VisitInitListExpr(S->getSyntacticForm());
417 return;
418 }
Mike Stump1eb44332009-09-09 15:08:12 +0000419
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000420 VisitExpr(S);
421}
422
Chandler Carruthb1138242011-06-16 06:47:06 +0000423void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000424 VisitExpr(S);
425 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruthb1138242011-06-16 06:47:06 +0000426 for (DesignatedInitExpr::const_designators_iterator D =
427 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000428 D != DEnd; ++D) {
429 if (D->isFieldDesignator()) {
430 ID.AddInteger(0);
431 VisitName(D->getFieldName());
432 continue;
433 }
Mike Stump1eb44332009-09-09 15:08:12 +0000434
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000435 if (D->isArrayDesignator()) {
436 ID.AddInteger(1);
437 } else {
438 assert(D->isArrayRangeDesignator());
439 ID.AddInteger(2);
440 }
441 ID.AddInteger(D->getFirstExprIndex());
442 }
443}
444
Chandler Carruthb1138242011-06-16 06:47:06 +0000445void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000446 VisitExpr(S);
447}
448
Chandler Carruthb1138242011-06-16 06:47:06 +0000449void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000450 VisitExpr(S);
451 VisitName(&S->getAccessor());
452}
453
Chandler Carruthb1138242011-06-16 06:47:06 +0000454void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000455 VisitExpr(S);
456 VisitDecl(S->getBlockDecl());
457}
458
Chandler Carruthb1138242011-06-16 06:47:06 +0000459void StmtProfiler::VisitBlockDeclRefExpr(const BlockDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000460 VisitExpr(S);
461 VisitDecl(S->getDecl());
462 ID.AddBoolean(S->isByRef());
463 ID.AddBoolean(S->isConstQualAdded());
464}
465
Chandler Carruthb1138242011-06-16 06:47:06 +0000466void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbournef111d932011-04-15 00:35:48 +0000467 VisitExpr(S);
468 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
469 QualType T = S->getAssocType(i);
470 if (T.isNull())
471 ID.AddPointer(0);
472 else
473 VisitType(T);
474 VisitExpr(S->getAssocExpr(i));
475 }
476}
477
John McCall4b9c2d22011-11-06 09:01:30 +0000478void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
479 VisitExpr(S);
480 for (PseudoObjectExpr::const_semantics_iterator
481 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
482 // Normally, we would not profile the source expressions of OVEs.
483 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
484 Visit(OVE->getSourceExpr());
485}
486
Eli Friedman276b0612011-10-11 02:20:01 +0000487void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
488 VisitExpr(S);
Eli Friedman2be46072011-10-14 20:59:01 +0000489 ID.AddInteger(S->getOp());
Eli Friedman276b0612011-10-11 02:20:01 +0000490}
491
Chandler Carruthb1138242011-06-16 06:47:06 +0000492static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000493 UnaryOperatorKind &UnaryOp,
494 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000495 switch (S->getOperator()) {
496 case OO_None:
497 case OO_New:
498 case OO_Delete:
499 case OO_Array_New:
500 case OO_Array_Delete:
501 case OO_Arrow:
502 case OO_Call:
503 case OO_Conditional:
504 case NUM_OVERLOADED_OPERATORS:
505 llvm_unreachable("Invalid operator call kind");
506 return Stmt::ArraySubscriptExprClass;
507
508 case OO_Plus:
509 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000510 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000511 return Stmt::UnaryOperatorClass;
512 }
513
John McCall2de56d12010-08-25 11:45:40 +0000514 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000515 return Stmt::BinaryOperatorClass;
516
517 case OO_Minus:
518 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000519 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000520 return Stmt::UnaryOperatorClass;
521 }
522
John McCall2de56d12010-08-25 11:45:40 +0000523 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000524 return Stmt::BinaryOperatorClass;
525
526 case OO_Star:
527 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000528 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000529 return Stmt::UnaryOperatorClass;
530 }
531
John McCall2de56d12010-08-25 11:45:40 +0000532 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000533 return Stmt::BinaryOperatorClass;
534
535 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000536 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000537 return Stmt::BinaryOperatorClass;
538
539 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000540 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000541 return Stmt::BinaryOperatorClass;
542
543 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000544 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000545 return Stmt::BinaryOperatorClass;
546
547 case OO_Amp:
548 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000549 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000550 return Stmt::UnaryOperatorClass;
551 }
552
John McCall2de56d12010-08-25 11:45:40 +0000553 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000554 return Stmt::BinaryOperatorClass;
555
556 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000557 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000558 return Stmt::BinaryOperatorClass;
559
560 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000561 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000562 return Stmt::UnaryOperatorClass;
563
564 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000565 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000566 return Stmt::UnaryOperatorClass;
567
568 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000569 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000570 return Stmt::BinaryOperatorClass;
571
572 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000573 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000574 return Stmt::BinaryOperatorClass;
575
576 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000577 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000578 return Stmt::BinaryOperatorClass;
579
580 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000581 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000582 return Stmt::CompoundAssignOperatorClass;
583
584 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000585 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000586 return Stmt::CompoundAssignOperatorClass;
587
588 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000589 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000590 return Stmt::CompoundAssignOperatorClass;
591
592 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000593 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000594 return Stmt::CompoundAssignOperatorClass;
595
596 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000597 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000598 return Stmt::CompoundAssignOperatorClass;
599
600 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000601 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000602 return Stmt::CompoundAssignOperatorClass;
603
604 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000605 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000606 return Stmt::CompoundAssignOperatorClass;
607
608 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000609 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000610 return Stmt::CompoundAssignOperatorClass;
611
612 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000613 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000614 return Stmt::BinaryOperatorClass;
615
616 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000617 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000618 return Stmt::BinaryOperatorClass;
619
620 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000621 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000622 return Stmt::CompoundAssignOperatorClass;
623
624 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000625 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000626 return Stmt::CompoundAssignOperatorClass;
627
628 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000629 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000630 return Stmt::BinaryOperatorClass;
631
632 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000633 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000634 return Stmt::BinaryOperatorClass;
635
636 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000637 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000638 return Stmt::BinaryOperatorClass;
639
640 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000641 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000642 return Stmt::BinaryOperatorClass;
643
644 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000645 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000646 return Stmt::BinaryOperatorClass;
647
648 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000649 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000650 return Stmt::BinaryOperatorClass;
651
652 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000653 UnaryOp = S->getNumArgs() == 1? UO_PreInc
654 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000655 return Stmt::UnaryOperatorClass;
656
657 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000658 UnaryOp = S->getNumArgs() == 1? UO_PreDec
659 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000660 return Stmt::UnaryOperatorClass;
661
662 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000663 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000664 return Stmt::BinaryOperatorClass;
665
666
667 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000668 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000669 return Stmt::BinaryOperatorClass;
670
671 case OO_Subscript:
672 return Stmt::ArraySubscriptExprClass;
673 }
674
675 llvm_unreachable("Invalid overloaded operator expression");
676}
677
678
Chandler Carruthb1138242011-06-16 06:47:06 +0000679void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000680 if (S->isTypeDependent()) {
681 // Type-dependent operator calls are profiled like their underlying
682 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000683 UnaryOperatorKind UnaryOp = UO_Extension;
684 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000685 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
686
687 ID.AddInteger(SC);
688 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
689 Visit(S->getArg(I));
690 if (SC == Stmt::UnaryOperatorClass)
691 ID.AddInteger(UnaryOp);
692 else if (SC == Stmt::BinaryOperatorClass ||
693 SC == Stmt::CompoundAssignOperatorClass)
694 ID.AddInteger(BinaryOp);
695 else
696 assert(SC == Stmt::ArraySubscriptExprClass);
697
698 return;
699 }
700
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000701 VisitCallExpr(S);
702 ID.AddInteger(S->getOperator());
703}
704
Chandler Carruthb1138242011-06-16 06:47:06 +0000705void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000706 VisitCallExpr(S);
707}
708
Chandler Carruthb1138242011-06-16 06:47:06 +0000709void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbournee08ce652011-02-09 21:07:24 +0000710 VisitCallExpr(S);
711}
712
Chandler Carruthb1138242011-06-16 06:47:06 +0000713void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner61eee0c2011-06-04 00:47:47 +0000714 VisitExpr(S);
715}
716
Chandler Carruthb1138242011-06-16 06:47:06 +0000717void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000718 VisitExplicitCastExpr(S);
719}
720
Chandler Carruthb1138242011-06-16 06:47:06 +0000721void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000722 VisitCXXNamedCastExpr(S);
723}
724
Chandler Carruthb1138242011-06-16 06:47:06 +0000725void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000726 VisitCXXNamedCastExpr(S);
727}
728
Chandler Carruthb1138242011-06-16 06:47:06 +0000729void
730StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000731 VisitCXXNamedCastExpr(S);
732}
733
Chandler Carruthb1138242011-06-16 06:47:06 +0000734void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000735 VisitCXXNamedCastExpr(S);
736}
737
Chandler Carruthb1138242011-06-16 06:47:06 +0000738void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000739 VisitExpr(S);
740 ID.AddBoolean(S->getValue());
741}
742
Chandler Carruthb1138242011-06-16 06:47:06 +0000743void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000744 VisitExpr(S);
745}
746
Chandler Carruthb1138242011-06-16 06:47:06 +0000747void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000748 VisitExpr(S);
749 if (S->isTypeOperand())
750 VisitType(S->getTypeOperand());
751}
752
Chandler Carruthb1138242011-06-16 06:47:06 +0000753void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet01b7c302010-09-08 12:20:18 +0000754 VisitExpr(S);
755 if (S->isTypeOperand())
756 VisitType(S->getTypeOperand());
757}
758
Chandler Carruthb1138242011-06-16 06:47:06 +0000759void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000760 VisitExpr(S);
761}
762
Chandler Carruthb1138242011-06-16 06:47:06 +0000763void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000764 VisitExpr(S);
765}
766
Chandler Carruthb1138242011-06-16 06:47:06 +0000767void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000768 VisitExpr(S);
769 VisitDecl(S->getParam());
770}
771
Chandler Carruthb1138242011-06-16 06:47:06 +0000772void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000773 VisitExpr(S);
774 VisitDecl(
775 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
776}
777
Chandler Carruthb1138242011-06-16 06:47:06 +0000778void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000779 VisitExpr(S);
780 VisitDecl(S->getConstructor());
781 ID.AddBoolean(S->isElidable());
782}
783
Chandler Carruthb1138242011-06-16 06:47:06 +0000784void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000785 VisitExplicitCastExpr(S);
786}
787
Chandler Carruthb1138242011-06-16 06:47:06 +0000788void
789StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000790 VisitCXXConstructExpr(S);
791}
792
Chandler Carruthb1138242011-06-16 06:47:06 +0000793void
794StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000795 VisitExpr(S);
796}
797
Chandler Carruthb1138242011-06-16 06:47:06 +0000798void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000799 VisitExpr(S);
800 ID.AddBoolean(S->isGlobalDelete());
801 ID.AddBoolean(S->isArrayForm());
802 VisitDecl(S->getOperatorDelete());
803}
804
805
Chandler Carruthb1138242011-06-16 06:47:06 +0000806void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000807 VisitExpr(S);
808 VisitType(S->getAllocatedType());
809 VisitDecl(S->getOperatorNew());
810 VisitDecl(S->getOperatorDelete());
811 VisitDecl(S->getConstructor());
812 ID.AddBoolean(S->isArray());
813 ID.AddInteger(S->getNumPlacementArgs());
814 ID.AddBoolean(S->isGlobalNew());
815 ID.AddBoolean(S->isParenTypeId());
816 ID.AddBoolean(S->hasInitializer());
817 ID.AddInteger(S->getNumConstructorArgs());
818}
819
Chandler Carruthb1138242011-06-16 06:47:06 +0000820void
821StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregora71d8192009-09-04 17:36:40 +0000822 VisitExpr(S);
823 ID.AddBoolean(S->isArrow());
824 VisitNestedNameSpecifier(S->getQualifier());
825 VisitType(S->getDestroyedType());
826}
827
Chandler Carruthb1138242011-06-16 06:47:06 +0000828void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000829 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000830 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000831 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000832 ID.AddBoolean(S->hasExplicitTemplateArgs());
833 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000834 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
835 S->getExplicitTemplateArgs().NumTemplateArgs);
836}
837
838void
Chandler Carruthb1138242011-06-16 06:47:06 +0000839StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000840 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000841}
842
Chandler Carruthb1138242011-06-16 06:47:06 +0000843void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000844 VisitExpr(S);
845 ID.AddInteger(S->getTrait());
846 VisitType(S->getQueriedType());
847}
848
Chandler Carruthb1138242011-06-16 06:47:06 +0000849void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
Francois Pichet6ad6f282010-12-07 00:08:36 +0000850 VisitExpr(S);
851 ID.AddInteger(S->getTrait());
852 VisitType(S->getLhsType());
853 VisitType(S->getRhsType());
854}
855
Chandler Carruthb1138242011-06-16 06:47:06 +0000856void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley21ff2e52011-04-28 00:16:57 +0000857 VisitExpr(S);
858 ID.AddInteger(S->getTrait());
859 VisitType(S->getQueriedType());
860}
861
Chandler Carruthb1138242011-06-16 06:47:06 +0000862void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegley55262202011-04-25 06:54:41 +0000863 VisitExpr(S);
864 ID.AddInteger(S->getTrait());
865 VisitExpr(S->getQueriedExpression());
866}
867
Chandler Carruthb1138242011-06-16 06:47:06 +0000868void StmtProfiler::VisitDependentScopeDeclRefExpr(
869 const DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000870 VisitExpr(S);
871 VisitName(S->getDeclName());
872 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000873 ID.AddBoolean(S->hasExplicitTemplateArgs());
874 if (S->hasExplicitTemplateArgs())
875 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000876}
877
Chandler Carruthb1138242011-06-16 06:47:06 +0000878void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000879 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000880}
881
Chandler Carruthb1138242011-06-16 06:47:06 +0000882void StmtProfiler::VisitCXXUnresolvedConstructExpr(
883 const CXXUnresolvedConstructExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000884 VisitExpr(S);
885 VisitType(S->getTypeAsWritten());
886}
887
Chandler Carruthb1138242011-06-16 06:47:06 +0000888void StmtProfiler::VisitCXXDependentScopeMemberExpr(
889 const CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000890 ID.AddBoolean(S->isImplicitAccess());
891 if (!S->isImplicitAccess()) {
892 VisitExpr(S);
893 ID.AddBoolean(S->isArrow());
894 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000895 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000896 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000897 ID.AddBoolean(S->hasExplicitTemplateArgs());
898 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000899 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
900}
901
Chandler Carruthb1138242011-06-16 06:47:06 +0000902void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000903 ID.AddBoolean(S->isImplicitAccess());
904 if (!S->isImplicitAccess()) {
905 VisitExpr(S);
906 ID.AddBoolean(S->isArrow());
907 }
John McCall129e2df2009-11-30 22:42:35 +0000908 VisitNestedNameSpecifier(S->getQualifier());
909 VisitName(S->getMemberName());
910 ID.AddBoolean(S->hasExplicitTemplateArgs());
911 if (S->hasExplicitTemplateArgs())
912 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000913}
914
Chandler Carruthb1138242011-06-16 06:47:06 +0000915void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl2e156222010-09-10 20:55:43 +0000916 VisitExpr(S);
917}
918
Chandler Carruthb1138242011-06-16 06:47:06 +0000919void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregorbe230c32011-01-03 17:17:50 +0000920 VisitExpr(S);
921}
922
Chandler Carruthb1138242011-06-16 06:47:06 +0000923void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregoree8aff02011-01-04 17:33:58 +0000924 VisitExpr(S);
925 VisitDecl(S->getPack());
926}
927
Douglas Gregorc7793c72011-01-15 01:15:58 +0000928void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruthb1138242011-06-16 06:47:06 +0000929 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorc7793c72011-01-15 01:15:58 +0000930 VisitExpr(S);
931 VisitDecl(S->getParameterPack());
932 VisitTemplateArgument(S->getArgumentPack());
933}
934
John McCall91a57552011-07-15 05:09:51 +0000935void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
936 const SubstNonTypeTemplateParmExpr *E) {
937 // Profile exactly as the replacement expression.
938 Visit(E->getReplacement());
939}
940
Douglas Gregor03e80032011-06-21 17:03:29 +0000941void StmtProfiler::VisitMaterializeTemporaryExpr(
942 const MaterializeTemporaryExpr *S) {
943 VisitExpr(S);
944}
945
Chandler Carruthb1138242011-06-16 06:47:06 +0000946void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall7cd7d1a2010-11-15 23:31:06 +0000947 VisitExpr(E);
948}
949
Chandler Carruthb1138242011-06-16 06:47:06 +0000950void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000951 VisitExpr(S);
952}
953
Chandler Carruthb1138242011-06-16 06:47:06 +0000954void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000955 VisitExpr(S);
956 VisitType(S->getEncodedType());
957}
958
Chandler Carruthb1138242011-06-16 06:47:06 +0000959void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000960 VisitExpr(S);
961 VisitName(S->getSelector());
962}
963
Chandler Carruthb1138242011-06-16 06:47:06 +0000964void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000965 VisitExpr(S);
966 VisitDecl(S->getProtocol());
967}
968
Chandler Carruthb1138242011-06-16 06:47:06 +0000969void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000970 VisitExpr(S);
971 VisitDecl(S->getDecl());
972 ID.AddBoolean(S->isArrow());
973 ID.AddBoolean(S->isFreeIvar());
974}
975
Chandler Carruthb1138242011-06-16 06:47:06 +0000976void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000977 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +0000978 if (S->isImplicitProperty()) {
979 VisitDecl(S->getImplicitPropertyGetter());
980 VisitDecl(S->getImplicitPropertySetter());
981 } else {
982 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000983 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000984 if (S->isSuperReceiver()) {
985 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +0000986 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000987 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000988}
989
Chandler Carruthb1138242011-06-16 06:47:06 +0000990void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000991 VisitExpr(S);
992 VisitName(S->getSelector());
993 VisitDecl(S->getMethodDecl());
994}
995
Chandler Carruthb1138242011-06-16 06:47:06 +0000996void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000997 VisitExpr(S);
998 ID.AddBoolean(S->isArrow());
999}
1000
Chandler Carruthb1138242011-06-16 06:47:06 +00001001void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1002 const ObjCIndirectCopyRestoreExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +00001003 VisitExpr(S);
1004 ID.AddBoolean(S->shouldCopy());
1005}
1006
Chandler Carruthb1138242011-06-16 06:47:06 +00001007void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +00001008 VisitExplicitCastExpr(S);
1009 ID.AddBoolean(S->getBridgeKind());
1010}
1011
Chandler Carruthb1138242011-06-16 06:47:06 +00001012void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001013 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +00001014
Douglas Gregorb1975722009-07-30 23:18:24 +00001015 if (Canonical && D) {
Chandler Carruthb1138242011-06-16 06:47:06 +00001016 if (const NonTypeTemplateParmDecl *NTTP =
1017 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +00001018 ID.AddInteger(NTTP->getDepth());
1019 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +00001020 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +00001021 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001022 return;
1023 }
Mike Stump1eb44332009-09-09 15:08:12 +00001024
Chandler Carruthb1138242011-06-16 06:47:06 +00001025 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCallfb44de92011-05-01 22:35:37 +00001026 // The Itanium C++ ABI uses the type, scope depth, and scope
1027 // index of a parameter when mangling expressions that involve
1028 // function parameters, so we will use the parameter's type for
1029 // establishing function parameter identity. That way, our
1030 // definition of "equivalent" (per C++ [temp.over.link]) is at
1031 // least as strong as the definition of "equivalent" used for
1032 // name mangling.
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001033 VisitType(Parm->getType());
John McCallfb44de92011-05-01 22:35:37 +00001034 ID.AddInteger(Parm->getFunctionScopeDepth());
1035 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001036 return;
1037 }
Mike Stump1eb44332009-09-09 15:08:12 +00001038
Chandler Carruthb1138242011-06-16 06:47:06 +00001039 if (const TemplateTemplateParmDecl *TTP =
1040 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregora2ffb982009-07-31 15:46:56 +00001041 ID.AddInteger(TTP->getDepth());
1042 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +00001043 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +00001044 return;
1045 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001046 }
Mike Stump1eb44332009-09-09 15:08:12 +00001047
Douglas Gregord584eb22009-07-28 15:32:17 +00001048 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1049}
1050
1051void StmtProfiler::VisitType(QualType T) {
1052 if (Canonical)
1053 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001055 ID.AddPointer(T.getAsOpaquePtr());
1056}
1057
1058void StmtProfiler::VisitName(DeclarationName Name) {
1059 ID.AddPointer(Name.getAsOpaquePtr());
1060}
1061
1062void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1063 if (Canonical)
1064 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1065 ID.AddPointer(NNS);
1066}
1067
1068void StmtProfiler::VisitTemplateName(TemplateName Name) {
1069 if (Canonical)
1070 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +00001071
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001072 Name.Profile(ID);
1073}
1074
John McCall833ca992009-10-29 08:12:44 +00001075void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001076 unsigned NumArgs) {
1077 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +00001078 for (unsigned I = 0; I != NumArgs; ++I)
1079 VisitTemplateArgument(Args[I].getArgument());
1080}
Mike Stump1eb44332009-09-09 15:08:12 +00001081
John McCall833ca992009-10-29 08:12:44 +00001082void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1083 // Mostly repetitive with TemplateArgument::Profile!
1084 ID.AddInteger(Arg.getKind());
1085 switch (Arg.getKind()) {
1086 case TemplateArgument::Null:
1087 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001088
John McCall833ca992009-10-29 08:12:44 +00001089 case TemplateArgument::Type:
1090 VisitType(Arg.getAsType());
1091 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001092
Douglas Gregor788cd062009-11-11 01:00:40 +00001093 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00001094 case TemplateArgument::TemplateExpansion:
1095 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +00001096 break;
Sean Huntc3021132010-05-05 15:23:54 +00001097
John McCall833ca992009-10-29 08:12:44 +00001098 case TemplateArgument::Declaration:
1099 VisitDecl(Arg.getAsDecl());
1100 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001101
John McCall833ca992009-10-29 08:12:44 +00001102 case TemplateArgument::Integral:
1103 Arg.getAsIntegral()->Profile(ID);
1104 VisitType(Arg.getIntegralType());
1105 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001106
John McCall833ca992009-10-29 08:12:44 +00001107 case TemplateArgument::Expression:
1108 Visit(Arg.getAsExpr());
1109 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001110
John McCall833ca992009-10-29 08:12:44 +00001111 case TemplateArgument::Pack:
1112 const TemplateArgument *Pack = Arg.pack_begin();
1113 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1114 VisitTemplateArgument(Pack[i]);
1115 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001116 }
1117}
1118
Jay Foad4ba2a172011-01-12 09:06:06 +00001119void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruthb1138242011-06-16 06:47:06 +00001120 bool Canonical) const {
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001121 StmtProfiler Profiler(ID, Context, Canonical);
1122 Profiler.Visit(this);
1123}