blob: 12321ef0d6f25b48ce745c8b5dbe044926dcf3e5 [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
Chandler Carruthb1138242011-06-16 06:47:06 +0000185void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000186 VisitStmt(S);
187}
188
Chandler Carruthb1138242011-06-16 06:47:06 +0000189void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000190 VisitStmt(S);
191}
192
Chandler Carruthb1138242011-06-16 06:47:06 +0000193void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +0000194 VisitStmt(S);
195}
196
Chandler Carruthb1138242011-06-16 06:47:06 +0000197void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000198 VisitStmt(S);
199}
200
Chandler Carruthb1138242011-06-16 06:47:06 +0000201void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000202 VisitStmt(S);
203 ID.AddBoolean(S->hasEllipsis());
204 if (S->getCatchParamDecl())
205 VisitType(S->getCatchParamDecl()->getType());
206}
207
Chandler Carruthb1138242011-06-16 06:47:06 +0000208void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000209 VisitStmt(S);
210}
211
Chandler Carruthb1138242011-06-16 06:47:06 +0000212void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000213 VisitStmt(S);
214}
215
Chandler Carruthb1138242011-06-16 06:47:06 +0000216void
217StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000218 VisitStmt(S);
219}
220
Chandler Carruthb1138242011-06-16 06:47:06 +0000221void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000222 VisitStmt(S);
223}
224
Chandler Carruthb1138242011-06-16 06:47:06 +0000225void
226StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCallf85e1932011-06-15 23:02:42 +0000227 VisitStmt(S);
228}
229
Chandler Carruthb1138242011-06-16 06:47:06 +0000230void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000231 VisitStmt(S);
232}
233
Chandler Carruthb1138242011-06-16 06:47:06 +0000234void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000235 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000236 if (!Canonical)
237 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000238 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000239 if (!Canonical)
240 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000241}
242
Chandler Carruthb1138242011-06-16 06:47:06 +0000243void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000244 VisitExpr(S);
245 ID.AddInteger(S->getIdentType());
246}
247
Chandler Carruthb1138242011-06-16 06:47:06 +0000248void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000249 VisitExpr(S);
250 S->getValue().Profile(ID);
251}
252
Chandler Carruthb1138242011-06-16 06:47:06 +0000253void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000254 VisitExpr(S);
Douglas Gregor5cee1192011-07-27 05:40:30 +0000255 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000256 ID.AddInteger(S->getValue());
257}
258
Chandler Carruthb1138242011-06-16 06:47:06 +0000259void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000260 VisitExpr(S);
261 S->getValue().Profile(ID);
262 ID.AddBoolean(S->isExact());
263}
264
Chandler Carruthb1138242011-06-16 06:47:06 +0000265void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000266 VisitExpr(S);
267}
268
Chandler Carruthb1138242011-06-16 06:47:06 +0000269void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000270 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000271 ID.AddString(S->getString());
Douglas Gregor5cee1192011-07-27 05:40:30 +0000272 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000273}
274
Chandler Carruthb1138242011-06-16 06:47:06 +0000275void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000276 VisitExpr(S);
277}
278
Chandler Carruthb1138242011-06-16 06:47:06 +0000279void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman2ef13e52009-08-10 23:49:36 +0000280 VisitExpr(S);
281}
282
Chandler Carruthb1138242011-06-16 06:47:06 +0000283void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000284 VisitExpr(S);
285 ID.AddInteger(S->getOpcode());
286}
287
Chandler Carruthb1138242011-06-16 06:47:06 +0000288void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000289 VisitType(S->getTypeSourceInfo()->getType());
290 unsigned n = S->getNumComponents();
291 for (unsigned i = 0; i < n; ++i) {
292 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
293 ID.AddInteger(ON.getKind());
294 switch (ON.getKind()) {
295 case OffsetOfExpr::OffsetOfNode::Array:
296 // Expressions handled below.
297 break;
298
299 case OffsetOfExpr::OffsetOfNode::Field:
300 VisitDecl(ON.getField());
301 break;
302
303 case OffsetOfExpr::OffsetOfNode::Identifier:
304 ID.AddPointer(ON.getFieldName());
305 break;
Sean Huntc3021132010-05-05 15:23:54 +0000306
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000307 case OffsetOfExpr::OffsetOfNode::Base:
308 // These nodes are implicit, and therefore don't need profiling.
309 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000310 }
311 }
Sean Huntc3021132010-05-05 15:23:54 +0000312
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000313 VisitExpr(S);
314}
315
Chandler Carruthb1138242011-06-16 06:47:06 +0000316void
317StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000318 VisitExpr(S);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000319 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000320 if (S->isArgumentType())
321 VisitType(S->getArgumentType());
322}
323
Chandler Carruthb1138242011-06-16 06:47:06 +0000324void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000325 VisitExpr(S);
326}
327
Chandler Carruthb1138242011-06-16 06:47:06 +0000328void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000329 VisitExpr(S);
330}
331
Chandler Carruthb1138242011-06-16 06:47:06 +0000332void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000333 VisitExpr(S);
334 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000335 if (!Canonical)
336 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000337 ID.AddBoolean(S->isArrow());
338}
339
Chandler Carruthb1138242011-06-16 06:47:06 +0000340void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000341 VisitExpr(S);
342 ID.AddBoolean(S->isFileScope());
343}
344
Chandler Carruthb1138242011-06-16 06:47:06 +0000345void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000346 VisitExpr(S);
347}
348
Chandler Carruthb1138242011-06-16 06:47:06 +0000349void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000350 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000351 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000352}
353
Chandler Carruthb1138242011-06-16 06:47:06 +0000354void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000355 VisitCastExpr(S);
356 VisitType(S->getTypeAsWritten());
357}
358
Chandler Carruthb1138242011-06-16 06:47:06 +0000359void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000360 VisitExplicitCastExpr(S);
361}
362
Chandler Carruthb1138242011-06-16 06:47:06 +0000363void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000364 VisitExpr(S);
365 ID.AddInteger(S->getOpcode());
366}
367
Chandler Carruthb1138242011-06-16 06:47:06 +0000368void
369StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000370 VisitBinaryOperator(S);
371}
372
Chandler Carruthb1138242011-06-16 06:47:06 +0000373void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000374 VisitExpr(S);
375}
376
Chandler Carruthb1138242011-06-16 06:47:06 +0000377void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruth08949762011-06-21 23:26:32 +0000378 const BinaryConditionalOperator *S) {
John McCall56ca35d2011-02-17 10:25:35 +0000379 VisitExpr(S);
380}
381
Chandler Carruthb1138242011-06-16 06:47:06 +0000382void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000383 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000384 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000385}
386
Chandler Carruthb1138242011-06-16 06:47:06 +0000387void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000388 VisitExpr(S);
389}
390
Chandler Carruthb1138242011-06-16 06:47:06 +0000391void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000392 VisitExpr(S);
393}
394
Chandler Carruthb1138242011-06-16 06:47:06 +0000395void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000396 VisitExpr(S);
397}
398
Chandler Carruthb1138242011-06-16 06:47:06 +0000399void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000400 VisitExpr(S);
401}
402
Chandler Carruthb1138242011-06-16 06:47:06 +0000403void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000404 VisitExpr(S);
405}
406
Chandler Carruthb1138242011-06-16 06:47:06 +0000407void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000408 if (S->getSyntacticForm()) {
409 VisitInitListExpr(S->getSyntacticForm());
410 return;
411 }
Mike Stump1eb44332009-09-09 15:08:12 +0000412
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000413 VisitExpr(S);
414}
415
Chandler Carruthb1138242011-06-16 06:47:06 +0000416void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000417 VisitExpr(S);
418 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruthb1138242011-06-16 06:47:06 +0000419 for (DesignatedInitExpr::const_designators_iterator D =
420 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000421 D != DEnd; ++D) {
422 if (D->isFieldDesignator()) {
423 ID.AddInteger(0);
424 VisitName(D->getFieldName());
425 continue;
426 }
Mike Stump1eb44332009-09-09 15:08:12 +0000427
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000428 if (D->isArrayDesignator()) {
429 ID.AddInteger(1);
430 } else {
431 assert(D->isArrayRangeDesignator());
432 ID.AddInteger(2);
433 }
434 ID.AddInteger(D->getFirstExprIndex());
435 }
436}
437
Chandler Carruthb1138242011-06-16 06:47:06 +0000438void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000439 VisitExpr(S);
440}
441
Chandler Carruthb1138242011-06-16 06:47:06 +0000442void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000443 VisitExpr(S);
444 VisitName(&S->getAccessor());
445}
446
Chandler Carruthb1138242011-06-16 06:47:06 +0000447void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000448 VisitExpr(S);
449 VisitDecl(S->getBlockDecl());
450}
451
Chandler Carruthb1138242011-06-16 06:47:06 +0000452void StmtProfiler::VisitBlockDeclRefExpr(const BlockDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000453 VisitExpr(S);
454 VisitDecl(S->getDecl());
455 ID.AddBoolean(S->isByRef());
456 ID.AddBoolean(S->isConstQualAdded());
457}
458
Chandler Carruthb1138242011-06-16 06:47:06 +0000459void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbournef111d932011-04-15 00:35:48 +0000460 VisitExpr(S);
461 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
462 QualType T = S->getAssocType(i);
463 if (T.isNull())
464 ID.AddPointer(0);
465 else
466 VisitType(T);
467 VisitExpr(S->getAssocExpr(i));
468 }
469}
470
Chandler Carruthb1138242011-06-16 06:47:06 +0000471static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000472 UnaryOperatorKind &UnaryOp,
473 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000474 switch (S->getOperator()) {
475 case OO_None:
476 case OO_New:
477 case OO_Delete:
478 case OO_Array_New:
479 case OO_Array_Delete:
480 case OO_Arrow:
481 case OO_Call:
482 case OO_Conditional:
483 case NUM_OVERLOADED_OPERATORS:
484 llvm_unreachable("Invalid operator call kind");
485 return Stmt::ArraySubscriptExprClass;
486
487 case OO_Plus:
488 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000489 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000490 return Stmt::UnaryOperatorClass;
491 }
492
John McCall2de56d12010-08-25 11:45:40 +0000493 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000494 return Stmt::BinaryOperatorClass;
495
496 case OO_Minus:
497 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000498 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000499 return Stmt::UnaryOperatorClass;
500 }
501
John McCall2de56d12010-08-25 11:45:40 +0000502 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000503 return Stmt::BinaryOperatorClass;
504
505 case OO_Star:
506 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000507 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000508 return Stmt::UnaryOperatorClass;
509 }
510
John McCall2de56d12010-08-25 11:45:40 +0000511 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000512 return Stmt::BinaryOperatorClass;
513
514 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000515 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000516 return Stmt::BinaryOperatorClass;
517
518 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000519 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000520 return Stmt::BinaryOperatorClass;
521
522 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000523 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000524 return Stmt::BinaryOperatorClass;
525
526 case OO_Amp:
527 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000528 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000529 return Stmt::UnaryOperatorClass;
530 }
531
John McCall2de56d12010-08-25 11:45:40 +0000532 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000533 return Stmt::BinaryOperatorClass;
534
535 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000536 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000537 return Stmt::BinaryOperatorClass;
538
539 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000540 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000541 return Stmt::UnaryOperatorClass;
542
543 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000544 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000545 return Stmt::UnaryOperatorClass;
546
547 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000548 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000549 return Stmt::BinaryOperatorClass;
550
551 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000552 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000553 return Stmt::BinaryOperatorClass;
554
555 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000556 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000557 return Stmt::BinaryOperatorClass;
558
559 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000560 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000561 return Stmt::CompoundAssignOperatorClass;
562
563 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000564 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000565 return Stmt::CompoundAssignOperatorClass;
566
567 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000568 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000569 return Stmt::CompoundAssignOperatorClass;
570
571 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000572 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000573 return Stmt::CompoundAssignOperatorClass;
574
575 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000576 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000577 return Stmt::CompoundAssignOperatorClass;
578
579 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000580 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000581 return Stmt::CompoundAssignOperatorClass;
582
583 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000584 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000585 return Stmt::CompoundAssignOperatorClass;
586
587 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000588 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000589 return Stmt::CompoundAssignOperatorClass;
590
591 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000592 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000593 return Stmt::BinaryOperatorClass;
594
595 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000596 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000597 return Stmt::BinaryOperatorClass;
598
599 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000600 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000601 return Stmt::CompoundAssignOperatorClass;
602
603 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000604 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000605 return Stmt::CompoundAssignOperatorClass;
606
607 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000608 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000609 return Stmt::BinaryOperatorClass;
610
611 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000612 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000613 return Stmt::BinaryOperatorClass;
614
615 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000616 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000617 return Stmt::BinaryOperatorClass;
618
619 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000620 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000621 return Stmt::BinaryOperatorClass;
622
623 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000624 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000625 return Stmt::BinaryOperatorClass;
626
627 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000628 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000629 return Stmt::BinaryOperatorClass;
630
631 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000632 UnaryOp = S->getNumArgs() == 1? UO_PreInc
633 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000634 return Stmt::UnaryOperatorClass;
635
636 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000637 UnaryOp = S->getNumArgs() == 1? UO_PreDec
638 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000639 return Stmt::UnaryOperatorClass;
640
641 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000642 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000643 return Stmt::BinaryOperatorClass;
644
645
646 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000647 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000648 return Stmt::BinaryOperatorClass;
649
650 case OO_Subscript:
651 return Stmt::ArraySubscriptExprClass;
652 }
653
654 llvm_unreachable("Invalid overloaded operator expression");
655}
656
657
Chandler Carruthb1138242011-06-16 06:47:06 +0000658void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000659 if (S->isTypeDependent()) {
660 // Type-dependent operator calls are profiled like their underlying
661 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000662 UnaryOperatorKind UnaryOp = UO_Extension;
663 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000664 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
665
666 ID.AddInteger(SC);
667 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
668 Visit(S->getArg(I));
669 if (SC == Stmt::UnaryOperatorClass)
670 ID.AddInteger(UnaryOp);
671 else if (SC == Stmt::BinaryOperatorClass ||
672 SC == Stmt::CompoundAssignOperatorClass)
673 ID.AddInteger(BinaryOp);
674 else
675 assert(SC == Stmt::ArraySubscriptExprClass);
676
677 return;
678 }
679
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000680 VisitCallExpr(S);
681 ID.AddInteger(S->getOperator());
682}
683
Chandler Carruthb1138242011-06-16 06:47:06 +0000684void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000685 VisitCallExpr(S);
686}
687
Chandler Carruthb1138242011-06-16 06:47:06 +0000688void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbournee08ce652011-02-09 21:07:24 +0000689 VisitCallExpr(S);
690}
691
Chandler Carruthb1138242011-06-16 06:47:06 +0000692void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner61eee0c2011-06-04 00:47:47 +0000693 VisitExpr(S);
694}
695
Chandler Carruthb1138242011-06-16 06:47:06 +0000696void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000697 VisitExplicitCastExpr(S);
698}
699
Chandler Carruthb1138242011-06-16 06:47:06 +0000700void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000701 VisitCXXNamedCastExpr(S);
702}
703
Chandler Carruthb1138242011-06-16 06:47:06 +0000704void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000705 VisitCXXNamedCastExpr(S);
706}
707
Chandler Carruthb1138242011-06-16 06:47:06 +0000708void
709StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000710 VisitCXXNamedCastExpr(S);
711}
712
Chandler Carruthb1138242011-06-16 06:47:06 +0000713void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000714 VisitCXXNamedCastExpr(S);
715}
716
Chandler Carruthb1138242011-06-16 06:47:06 +0000717void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000718 VisitExpr(S);
719 ID.AddBoolean(S->getValue());
720}
721
Chandler Carruthb1138242011-06-16 06:47:06 +0000722void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor828e2262009-07-29 16:09:57 +0000723 VisitExpr(S);
724}
725
Chandler Carruthb1138242011-06-16 06:47:06 +0000726void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000727 VisitExpr(S);
728 if (S->isTypeOperand())
729 VisitType(S->getTypeOperand());
730}
731
Chandler Carruthb1138242011-06-16 06:47:06 +0000732void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet01b7c302010-09-08 12:20:18 +0000733 VisitExpr(S);
734 if (S->isTypeOperand())
735 VisitType(S->getTypeOperand());
736}
737
Chandler Carruthb1138242011-06-16 06:47:06 +0000738void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000739 VisitExpr(S);
740}
741
Chandler Carruthb1138242011-06-16 06:47:06 +0000742void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000743 VisitExpr(S);
744}
745
Chandler Carruthb1138242011-06-16 06:47:06 +0000746void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000747 VisitExpr(S);
748 VisitDecl(S->getParam());
749}
750
Chandler Carruthb1138242011-06-16 06:47:06 +0000751void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000752 VisitExpr(S);
753 VisitDecl(
754 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
755}
756
Chandler Carruthb1138242011-06-16 06:47:06 +0000757void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000758 VisitExpr(S);
759 VisitDecl(S->getConstructor());
760 ID.AddBoolean(S->isElidable());
761}
762
Chandler Carruthb1138242011-06-16 06:47:06 +0000763void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000764 VisitExplicitCastExpr(S);
765}
766
Chandler Carruthb1138242011-06-16 06:47:06 +0000767void
768StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000769 VisitCXXConstructExpr(S);
770}
771
Chandler Carruthb1138242011-06-16 06:47:06 +0000772void
773StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000774 VisitExpr(S);
775}
776
Chandler Carruthb1138242011-06-16 06:47:06 +0000777void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000778 VisitExpr(S);
779 ID.AddBoolean(S->isGlobalDelete());
780 ID.AddBoolean(S->isArrayForm());
781 VisitDecl(S->getOperatorDelete());
782}
783
784
Chandler Carruthb1138242011-06-16 06:47:06 +0000785void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000786 VisitExpr(S);
787 VisitType(S->getAllocatedType());
788 VisitDecl(S->getOperatorNew());
789 VisitDecl(S->getOperatorDelete());
790 VisitDecl(S->getConstructor());
791 ID.AddBoolean(S->isArray());
792 ID.AddInteger(S->getNumPlacementArgs());
793 ID.AddBoolean(S->isGlobalNew());
794 ID.AddBoolean(S->isParenTypeId());
795 ID.AddBoolean(S->hasInitializer());
796 ID.AddInteger(S->getNumConstructorArgs());
797}
798
Chandler Carruthb1138242011-06-16 06:47:06 +0000799void
800StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregora71d8192009-09-04 17:36:40 +0000801 VisitExpr(S);
802 ID.AddBoolean(S->isArrow());
803 VisitNestedNameSpecifier(S->getQualifier());
804 VisitType(S->getDestroyedType());
805}
806
Chandler Carruthb1138242011-06-16 06:47:06 +0000807void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000808 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000809 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000810 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000811 ID.AddBoolean(S->hasExplicitTemplateArgs());
812 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000813 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
814 S->getExplicitTemplateArgs().NumTemplateArgs);
815}
816
817void
Chandler Carruthb1138242011-06-16 06:47:06 +0000818StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000819 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000820}
821
Chandler Carruthb1138242011-06-16 06:47:06 +0000822void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000823 VisitExpr(S);
824 ID.AddInteger(S->getTrait());
825 VisitType(S->getQueriedType());
826}
827
Chandler Carruthb1138242011-06-16 06:47:06 +0000828void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
Francois Pichet6ad6f282010-12-07 00:08:36 +0000829 VisitExpr(S);
830 ID.AddInteger(S->getTrait());
831 VisitType(S->getLhsType());
832 VisitType(S->getRhsType());
833}
834
Chandler Carruthb1138242011-06-16 06:47:06 +0000835void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley21ff2e52011-04-28 00:16:57 +0000836 VisitExpr(S);
837 ID.AddInteger(S->getTrait());
838 VisitType(S->getQueriedType());
839}
840
Chandler Carruthb1138242011-06-16 06:47:06 +0000841void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegley55262202011-04-25 06:54:41 +0000842 VisitExpr(S);
843 ID.AddInteger(S->getTrait());
844 VisitExpr(S->getQueriedExpression());
845}
846
Chandler Carruthb1138242011-06-16 06:47:06 +0000847void StmtProfiler::VisitDependentScopeDeclRefExpr(
848 const DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000849 VisitExpr(S);
850 VisitName(S->getDeclName());
851 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000852 ID.AddBoolean(S->hasExplicitTemplateArgs());
853 if (S->hasExplicitTemplateArgs())
854 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000855}
856
Chandler Carruthb1138242011-06-16 06:47:06 +0000857void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000858 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000859}
860
Chandler Carruthb1138242011-06-16 06:47:06 +0000861void StmtProfiler::VisitCXXUnresolvedConstructExpr(
862 const CXXUnresolvedConstructExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000863 VisitExpr(S);
864 VisitType(S->getTypeAsWritten());
865}
866
Chandler Carruthb1138242011-06-16 06:47:06 +0000867void StmtProfiler::VisitCXXDependentScopeMemberExpr(
868 const CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000869 ID.AddBoolean(S->isImplicitAccess());
870 if (!S->isImplicitAccess()) {
871 VisitExpr(S);
872 ID.AddBoolean(S->isArrow());
873 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000874 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000875 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000876 ID.AddBoolean(S->hasExplicitTemplateArgs());
877 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000878 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
879}
880
Chandler Carruthb1138242011-06-16 06:47:06 +0000881void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000882 ID.AddBoolean(S->isImplicitAccess());
883 if (!S->isImplicitAccess()) {
884 VisitExpr(S);
885 ID.AddBoolean(S->isArrow());
886 }
John McCall129e2df2009-11-30 22:42:35 +0000887 VisitNestedNameSpecifier(S->getQualifier());
888 VisitName(S->getMemberName());
889 ID.AddBoolean(S->hasExplicitTemplateArgs());
890 if (S->hasExplicitTemplateArgs())
891 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000892}
893
Chandler Carruthb1138242011-06-16 06:47:06 +0000894void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl2e156222010-09-10 20:55:43 +0000895 VisitExpr(S);
896}
897
Chandler Carruthb1138242011-06-16 06:47:06 +0000898void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregorbe230c32011-01-03 17:17:50 +0000899 VisitExpr(S);
900}
901
Chandler Carruthb1138242011-06-16 06:47:06 +0000902void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregoree8aff02011-01-04 17:33:58 +0000903 VisitExpr(S);
904 VisitDecl(S->getPack());
905}
906
Douglas Gregorc7793c72011-01-15 01:15:58 +0000907void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruthb1138242011-06-16 06:47:06 +0000908 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorc7793c72011-01-15 01:15:58 +0000909 VisitExpr(S);
910 VisitDecl(S->getParameterPack());
911 VisitTemplateArgument(S->getArgumentPack());
912}
913
John McCall91a57552011-07-15 05:09:51 +0000914void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
915 const SubstNonTypeTemplateParmExpr *E) {
916 // Profile exactly as the replacement expression.
917 Visit(E->getReplacement());
918}
919
Douglas Gregor03e80032011-06-21 17:03:29 +0000920void StmtProfiler::VisitMaterializeTemporaryExpr(
921 const MaterializeTemporaryExpr *S) {
922 VisitExpr(S);
923}
924
Chandler Carruthb1138242011-06-16 06:47:06 +0000925void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall7cd7d1a2010-11-15 23:31:06 +0000926 VisitExpr(E);
927}
928
Chandler Carruthb1138242011-06-16 06:47:06 +0000929void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000930 VisitExpr(S);
931}
932
Chandler Carruthb1138242011-06-16 06:47:06 +0000933void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000934 VisitExpr(S);
935 VisitType(S->getEncodedType());
936}
937
Chandler Carruthb1138242011-06-16 06:47:06 +0000938void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000939 VisitExpr(S);
940 VisitName(S->getSelector());
941}
942
Chandler Carruthb1138242011-06-16 06:47:06 +0000943void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000944 VisitExpr(S);
945 VisitDecl(S->getProtocol());
946}
947
Chandler Carruthb1138242011-06-16 06:47:06 +0000948void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000949 VisitExpr(S);
950 VisitDecl(S->getDecl());
951 ID.AddBoolean(S->isArrow());
952 ID.AddBoolean(S->isFreeIvar());
953}
954
Chandler Carruthb1138242011-06-16 06:47:06 +0000955void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000956 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +0000957 if (S->isImplicitProperty()) {
958 VisitDecl(S->getImplicitPropertyGetter());
959 VisitDecl(S->getImplicitPropertySetter());
960 } else {
961 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000962 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000963 if (S->isSuperReceiver()) {
964 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +0000965 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000966 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000967}
968
Chandler Carruthb1138242011-06-16 06:47:06 +0000969void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000970 VisitExpr(S);
971 VisitName(S->getSelector());
972 VisitDecl(S->getMethodDecl());
973}
974
Chandler Carruthb1138242011-06-16 06:47:06 +0000975void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000976 VisitExpr(S);
977 ID.AddBoolean(S->isArrow());
978}
979
Chandler Carruthb1138242011-06-16 06:47:06 +0000980void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
981 const ObjCIndirectCopyRestoreExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +0000982 VisitExpr(S);
983 ID.AddBoolean(S->shouldCopy());
984}
985
Chandler Carruthb1138242011-06-16 06:47:06 +0000986void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCallf85e1932011-06-15 23:02:42 +0000987 VisitExplicitCastExpr(S);
988 ID.AddBoolean(S->getBridgeKind());
989}
990
Chandler Carruthb1138242011-06-16 06:47:06 +0000991void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000992 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000993
Douglas Gregorb1975722009-07-30 23:18:24 +0000994 if (Canonical && D) {
Chandler Carruthb1138242011-06-16 06:47:06 +0000995 if (const NonTypeTemplateParmDecl *NTTP =
996 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000997 ID.AddInteger(NTTP->getDepth());
998 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000999 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +00001000 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001001 return;
1002 }
Mike Stump1eb44332009-09-09 15:08:12 +00001003
Chandler Carruthb1138242011-06-16 06:47:06 +00001004 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCallfb44de92011-05-01 22:35:37 +00001005 // The Itanium C++ ABI uses the type, scope depth, and scope
1006 // index of a parameter when mangling expressions that involve
1007 // function parameters, so we will use the parameter's type for
1008 // establishing function parameter identity. That way, our
1009 // definition of "equivalent" (per C++ [temp.over.link]) is at
1010 // least as strong as the definition of "equivalent" used for
1011 // name mangling.
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001012 VisitType(Parm->getType());
John McCallfb44de92011-05-01 22:35:37 +00001013 ID.AddInteger(Parm->getFunctionScopeDepth());
1014 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor4a3f7802009-07-31 15:45:02 +00001015 return;
1016 }
Mike Stump1eb44332009-09-09 15:08:12 +00001017
Chandler Carruthb1138242011-06-16 06:47:06 +00001018 if (const TemplateTemplateParmDecl *TTP =
1019 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregora2ffb982009-07-31 15:46:56 +00001020 ID.AddInteger(TTP->getDepth());
1021 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +00001022 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +00001023 return;
1024 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001025 }
Mike Stump1eb44332009-09-09 15:08:12 +00001026
Douglas Gregord584eb22009-07-28 15:32:17 +00001027 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1028}
1029
1030void StmtProfiler::VisitType(QualType T) {
1031 if (Canonical)
1032 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +00001033
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001034 ID.AddPointer(T.getAsOpaquePtr());
1035}
1036
1037void StmtProfiler::VisitName(DeclarationName Name) {
1038 ID.AddPointer(Name.getAsOpaquePtr());
1039}
1040
1041void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1042 if (Canonical)
1043 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1044 ID.AddPointer(NNS);
1045}
1046
1047void StmtProfiler::VisitTemplateName(TemplateName Name) {
1048 if (Canonical)
1049 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +00001050
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001051 Name.Profile(ID);
1052}
1053
John McCall833ca992009-10-29 08:12:44 +00001054void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001055 unsigned NumArgs) {
1056 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +00001057 for (unsigned I = 0; I != NumArgs; ++I)
1058 VisitTemplateArgument(Args[I].getArgument());
1059}
Mike Stump1eb44332009-09-09 15:08:12 +00001060
John McCall833ca992009-10-29 08:12:44 +00001061void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1062 // Mostly repetitive with TemplateArgument::Profile!
1063 ID.AddInteger(Arg.getKind());
1064 switch (Arg.getKind()) {
1065 case TemplateArgument::Null:
1066 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001067
John McCall833ca992009-10-29 08:12:44 +00001068 case TemplateArgument::Type:
1069 VisitType(Arg.getAsType());
1070 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001071
Douglas Gregor788cd062009-11-11 01:00:40 +00001072 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00001073 case TemplateArgument::TemplateExpansion:
1074 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +00001075 break;
Sean Huntc3021132010-05-05 15:23:54 +00001076
John McCall833ca992009-10-29 08:12:44 +00001077 case TemplateArgument::Declaration:
1078 VisitDecl(Arg.getAsDecl());
1079 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001080
John McCall833ca992009-10-29 08:12:44 +00001081 case TemplateArgument::Integral:
1082 Arg.getAsIntegral()->Profile(ID);
1083 VisitType(Arg.getIntegralType());
1084 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001085
John McCall833ca992009-10-29 08:12:44 +00001086 case TemplateArgument::Expression:
1087 Visit(Arg.getAsExpr());
1088 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001089
John McCall833ca992009-10-29 08:12:44 +00001090 case TemplateArgument::Pack:
1091 const TemplateArgument *Pack = Arg.pack_begin();
1092 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1093 VisitTemplateArgument(Pack[i]);
1094 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001095 }
1096}
1097
Jay Foad4ba2a172011-01-12 09:06:06 +00001098void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruthb1138242011-06-16 06:47:06 +00001099 bool Canonical) const {
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001100 StmtProfiler Profiler(ID, Context, Canonical);
1101 Profiler.Visit(this);
1102}