blob: b54001167b42d916e22990b19d41a2debe3844ef [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 {
Benjamin Kramer770b4a82009-11-28 19:03:38 +000026 class StmtProfiler : public StmtVisitor<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
Douglas Gregor41ef0c32009-07-28 00:33:38 +000036 void VisitStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +000037
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000038#define STMT(Node, Base) void Visit##Node(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.
43 void VisitDecl(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.
John McCall833ca992009-10-29 08:12:44 +000062 void VisitTemplateArguments(const TemplateArgumentLoc *Args, unsigned NumArgs);
63
64 /// \brief Visit a single template argument.
65 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor41ef0c32009-07-28 00:33:38 +000066 };
67}
68
69void StmtProfiler::VisitStmt(Stmt *S) {
70 ID.AddInteger(S->getStmtClass());
John McCall7502c1d2011-02-13 04:07:26 +000071 for (Stmt::child_range C = S->children(); C; ++C)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000072 Visit(*C);
73}
74
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000075void StmtProfiler::VisitDeclStmt(DeclStmt *S) {
76 VisitStmt(S);
77 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
78 D != DEnd; ++D)
79 VisitDecl(*D);
80}
81
82void StmtProfiler::VisitNullStmt(NullStmt *S) {
83 VisitStmt(S);
84}
85
86void StmtProfiler::VisitCompoundStmt(CompoundStmt *S) {
87 VisitStmt(S);
88}
89
90void StmtProfiler::VisitSwitchCase(SwitchCase *S) {
91 VisitStmt(S);
92}
93
94void StmtProfiler::VisitCaseStmt(CaseStmt *S) {
95 VisitStmt(S);
96}
97
98void StmtProfiler::VisitDefaultStmt(DefaultStmt *S) {
99 VisitStmt(S);
100}
101
102void StmtProfiler::VisitLabelStmt(LabelStmt *S) {
103 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000104 VisitDecl(S->getDecl());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000105}
106
107void StmtProfiler::VisitIfStmt(IfStmt *S) {
108 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000109 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000110}
111
Douglas Gregor828e2262009-07-29 16:09:57 +0000112void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
113 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000114 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000115}
116
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000117void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
118 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000119 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000120}
121
122void StmtProfiler::VisitDoStmt(DoStmt *S) {
123 VisitStmt(S);
124}
125
126void StmtProfiler::VisitForStmt(ForStmt *S) {
127 VisitStmt(S);
128}
129
130void StmtProfiler::VisitGotoStmt(GotoStmt *S) {
131 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000132 VisitDecl(S->getLabel());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000133}
134
135void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
136 VisitStmt(S);
137}
138
139void StmtProfiler::VisitContinueStmt(ContinueStmt *S) {
140 VisitStmt(S);
141}
142
143void StmtProfiler::VisitBreakStmt(BreakStmt *S) {
144 VisitStmt(S);
145}
146
147void StmtProfiler::VisitReturnStmt(ReturnStmt *S) {
148 VisitStmt(S);
149}
150
151void StmtProfiler::VisitAsmStmt(AsmStmt *S) {
152 VisitStmt(S);
153 ID.AddBoolean(S->isVolatile());
154 ID.AddBoolean(S->isSimple());
155 VisitStringLiteral(S->getAsmString());
156 ID.AddInteger(S->getNumOutputs());
157 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
158 ID.AddString(S->getOutputName(I));
159 VisitStringLiteral(S->getOutputConstraintLiteral(I));
160 }
161 ID.AddInteger(S->getNumInputs());
162 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
163 ID.AddString(S->getInputName(I));
164 VisitStringLiteral(S->getInputConstraintLiteral(I));
165 }
166 ID.AddInteger(S->getNumClobbers());
167 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
168 VisitStringLiteral(S->getClobber(I));
169}
170
171void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) {
172 VisitStmt(S);
173 VisitType(S->getCaughtType());
174}
175
176void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) {
177 VisitStmt(S);
178}
179
180void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
181 VisitStmt(S);
182}
183
184void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
185 VisitStmt(S);
186 ID.AddBoolean(S->hasEllipsis());
187 if (S->getCatchParamDecl())
188 VisitType(S->getCatchParamDecl()->getType());
189}
190
191void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
192 VisitStmt(S);
193}
194
195void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
196 VisitStmt(S);
197}
198
199void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
200 VisitStmt(S);
201}
202
203void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
204 VisitStmt(S);
205}
206
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000207void StmtProfiler::VisitExpr(Expr *S) {
208 VisitStmt(S);
209}
210
211void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
212 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000213 if (!Canonical)
214 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000215 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000216 if (!Canonical)
217 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000218}
219
220void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
221 VisitExpr(S);
222 ID.AddInteger(S->getIdentType());
223}
224
225void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
226 VisitExpr(S);
227 S->getValue().Profile(ID);
228}
229
230void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
231 VisitExpr(S);
232 ID.AddBoolean(S->isWide());
233 ID.AddInteger(S->getValue());
234}
235
236void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
237 VisitExpr(S);
238 S->getValue().Profile(ID);
239 ID.AddBoolean(S->isExact());
240}
241
242void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
243 VisitExpr(S);
244}
245
246void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
247 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000248 ID.AddString(S->getString());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000249 ID.AddBoolean(S->isWide());
250}
251
252void StmtProfiler::VisitParenExpr(ParenExpr *S) {
253 VisitExpr(S);
254}
255
Nate Begeman2ef13e52009-08-10 23:49:36 +0000256void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
257 VisitExpr(S);
258}
259
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000260void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
261 VisitExpr(S);
262 ID.AddInteger(S->getOpcode());
263}
264
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000265void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
266 VisitType(S->getTypeSourceInfo()->getType());
267 unsigned n = S->getNumComponents();
268 for (unsigned i = 0; i < n; ++i) {
269 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
270 ID.AddInteger(ON.getKind());
271 switch (ON.getKind()) {
272 case OffsetOfExpr::OffsetOfNode::Array:
273 // Expressions handled below.
274 break;
275
276 case OffsetOfExpr::OffsetOfNode::Field:
277 VisitDecl(ON.getField());
278 break;
279
280 case OffsetOfExpr::OffsetOfNode::Identifier:
281 ID.AddPointer(ON.getFieldName());
282 break;
Sean Huntc3021132010-05-05 15:23:54 +0000283
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000284 case OffsetOfExpr::OffsetOfNode::Base:
285 // These nodes are implicit, and therefore don't need profiling.
286 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000287 }
288 }
Sean Huntc3021132010-05-05 15:23:54 +0000289
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000290 VisitExpr(S);
291}
292
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000293void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
294 VisitExpr(S);
295 ID.AddBoolean(S->isSizeOf());
296 if (S->isArgumentType())
297 VisitType(S->getArgumentType());
298}
299
300void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
301 VisitExpr(S);
302}
303
304void StmtProfiler::VisitCallExpr(CallExpr *S) {
305 VisitExpr(S);
306}
307
308void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
309 VisitExpr(S);
310 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000311 if (!Canonical)
312 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000313 ID.AddBoolean(S->isArrow());
314}
315
316void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
317 VisitExpr(S);
318 ID.AddBoolean(S->isFileScope());
319}
320
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000321void StmtProfiler::VisitCastExpr(CastExpr *S) {
322 VisitExpr(S);
323}
324
325void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
326 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000327 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000328}
329
330void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
331 VisitCastExpr(S);
332 VisitType(S->getTypeAsWritten());
333}
334
335void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
336 VisitExplicitCastExpr(S);
337}
338
339void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
340 VisitExpr(S);
341 ID.AddInteger(S->getOpcode());
342}
343
344void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
345 VisitBinaryOperator(S);
346}
347
348void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
349 VisitExpr(S);
350}
351
John McCall56ca35d2011-02-17 10:25:35 +0000352void StmtProfiler::VisitBinaryConditionalOperator(BinaryConditionalOperator *S){
353 VisitExpr(S);
354}
355
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000356void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
357 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000358 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000359}
360
361void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
362 VisitExpr(S);
363}
364
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000365void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
366 VisitExpr(S);
367}
368
369void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
370 VisitExpr(S);
371}
372
373void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
374 VisitExpr(S);
375}
376
Douglas Gregor828e2262009-07-29 16:09:57 +0000377void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
378 VisitExpr(S);
379}
380
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000381void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
382 if (S->getSyntacticForm()) {
383 VisitInitListExpr(S->getSyntacticForm());
384 return;
385 }
Mike Stump1eb44332009-09-09 15:08:12 +0000386
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000387 VisitExpr(S);
388}
389
390void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
391 VisitExpr(S);
392 ID.AddBoolean(S->usesGNUSyntax());
393 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
394 DEnd = S->designators_end();
395 D != DEnd; ++D) {
396 if (D->isFieldDesignator()) {
397 ID.AddInteger(0);
398 VisitName(D->getFieldName());
399 continue;
400 }
Mike Stump1eb44332009-09-09 15:08:12 +0000401
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000402 if (D->isArrayDesignator()) {
403 ID.AddInteger(1);
404 } else {
405 assert(D->isArrayRangeDesignator());
406 ID.AddInteger(2);
407 }
408 ID.AddInteger(D->getFirstExprIndex());
409 }
410}
411
412void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
413 VisitExpr(S);
414}
415
416void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
417 VisitExpr(S);
418 VisitName(&S->getAccessor());
419}
420
421void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
422 VisitExpr(S);
423 VisitDecl(S->getBlockDecl());
424}
425
426void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
427 VisitExpr(S);
428 VisitDecl(S->getDecl());
429 ID.AddBoolean(S->isByRef());
430 ID.AddBoolean(S->isConstQualAdded());
431}
432
Douglas Gregora89064a2010-05-19 04:13:23 +0000433static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000434 UnaryOperatorKind &UnaryOp,
435 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000436 switch (S->getOperator()) {
437 case OO_None:
438 case OO_New:
439 case OO_Delete:
440 case OO_Array_New:
441 case OO_Array_Delete:
442 case OO_Arrow:
443 case OO_Call:
444 case OO_Conditional:
445 case NUM_OVERLOADED_OPERATORS:
446 llvm_unreachable("Invalid operator call kind");
447 return Stmt::ArraySubscriptExprClass;
448
449 case OO_Plus:
450 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000451 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000452 return Stmt::UnaryOperatorClass;
453 }
454
John McCall2de56d12010-08-25 11:45:40 +0000455 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000456 return Stmt::BinaryOperatorClass;
457
458 case OO_Minus:
459 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000460 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000461 return Stmt::UnaryOperatorClass;
462 }
463
John McCall2de56d12010-08-25 11:45:40 +0000464 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000465 return Stmt::BinaryOperatorClass;
466
467 case OO_Star:
468 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000469 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000470 return Stmt::UnaryOperatorClass;
471 }
472
John McCall2de56d12010-08-25 11:45:40 +0000473 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000474 return Stmt::BinaryOperatorClass;
475
476 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000477 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000478 return Stmt::BinaryOperatorClass;
479
480 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000481 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000482 return Stmt::BinaryOperatorClass;
483
484 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000485 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000486 return Stmt::BinaryOperatorClass;
487
488 case OO_Amp:
489 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000490 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000491 return Stmt::UnaryOperatorClass;
492 }
493
John McCall2de56d12010-08-25 11:45:40 +0000494 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000495 return Stmt::BinaryOperatorClass;
496
497 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000498 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000499 return Stmt::BinaryOperatorClass;
500
501 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000502 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000503 return Stmt::UnaryOperatorClass;
504
505 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000506 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000507 return Stmt::UnaryOperatorClass;
508
509 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000510 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000511 return Stmt::BinaryOperatorClass;
512
513 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000514 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000515 return Stmt::BinaryOperatorClass;
516
517 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000518 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000519 return Stmt::BinaryOperatorClass;
520
521 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000522 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000523 return Stmt::CompoundAssignOperatorClass;
524
525 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000526 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000527 return Stmt::CompoundAssignOperatorClass;
528
529 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000530 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000531 return Stmt::CompoundAssignOperatorClass;
532
533 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000534 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000535 return Stmt::CompoundAssignOperatorClass;
536
537 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000538 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000539 return Stmt::CompoundAssignOperatorClass;
540
541 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000542 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000543 return Stmt::CompoundAssignOperatorClass;
544
545 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000546 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000547 return Stmt::CompoundAssignOperatorClass;
548
549 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000550 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000551 return Stmt::CompoundAssignOperatorClass;
552
553 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000554 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000555 return Stmt::BinaryOperatorClass;
556
557 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000558 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000559 return Stmt::BinaryOperatorClass;
560
561 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000562 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000563 return Stmt::CompoundAssignOperatorClass;
564
565 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000566 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000567 return Stmt::CompoundAssignOperatorClass;
568
569 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000570 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000571 return Stmt::BinaryOperatorClass;
572
573 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000574 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000575 return Stmt::BinaryOperatorClass;
576
577 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000578 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000579 return Stmt::BinaryOperatorClass;
580
581 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000582 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000583 return Stmt::BinaryOperatorClass;
584
585 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000586 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000587 return Stmt::BinaryOperatorClass;
588
589 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000590 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000591 return Stmt::BinaryOperatorClass;
592
593 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000594 UnaryOp = S->getNumArgs() == 1? UO_PreInc
595 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000596 return Stmt::UnaryOperatorClass;
597
598 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000599 UnaryOp = S->getNumArgs() == 1? UO_PreDec
600 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000601 return Stmt::UnaryOperatorClass;
602
603 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000604 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000605 return Stmt::BinaryOperatorClass;
606
607
608 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000609 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000610 return Stmt::BinaryOperatorClass;
611
612 case OO_Subscript:
613 return Stmt::ArraySubscriptExprClass;
614 }
615
616 llvm_unreachable("Invalid overloaded operator expression");
617}
618
619
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000620void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000621 if (S->isTypeDependent()) {
622 // Type-dependent operator calls are profiled like their underlying
623 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000624 UnaryOperatorKind UnaryOp = UO_Extension;
625 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000626 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
627
628 ID.AddInteger(SC);
629 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
630 Visit(S->getArg(I));
631 if (SC == Stmt::UnaryOperatorClass)
632 ID.AddInteger(UnaryOp);
633 else if (SC == Stmt::BinaryOperatorClass ||
634 SC == Stmt::CompoundAssignOperatorClass)
635 ID.AddInteger(BinaryOp);
636 else
637 assert(SC == Stmt::ArraySubscriptExprClass);
638
639 return;
640 }
641
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000642 VisitCallExpr(S);
643 ID.AddInteger(S->getOperator());
644}
645
646void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
647 VisitCallExpr(S);
648}
649
Peter Collingbournee08ce652011-02-09 21:07:24 +0000650void StmtProfiler::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *S) {
651 VisitCallExpr(S);
652}
653
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000654void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
655 VisitExplicitCastExpr(S);
656}
657
658void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
659 VisitCXXNamedCastExpr(S);
660}
661
662void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
663 VisitCXXNamedCastExpr(S);
664}
665
666void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
667 VisitCXXNamedCastExpr(S);
668}
669
670void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
671 VisitCXXNamedCastExpr(S);
672}
673
674void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
675 VisitExpr(S);
676 ID.AddBoolean(S->getValue());
677}
678
Douglas Gregor828e2262009-07-29 16:09:57 +0000679void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
680 VisitExpr(S);
681}
682
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000683void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
684 VisitExpr(S);
685 if (S->isTypeOperand())
686 VisitType(S->getTypeOperand());
687}
688
Francois Pichet01b7c302010-09-08 12:20:18 +0000689void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
690 VisitExpr(S);
691 if (S->isTypeOperand())
692 VisitType(S->getTypeOperand());
693}
694
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000695void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
696 VisitExpr(S);
697}
698
699void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
700 VisitExpr(S);
701}
702
703void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
704 VisitExpr(S);
705 VisitDecl(S->getParam());
706}
707
708void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
709 VisitExpr(S);
710 VisitDecl(
711 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
712}
713
714void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
715 VisitExpr(S);
716 VisitDecl(S->getConstructor());
717 ID.AddBoolean(S->isElidable());
718}
719
720void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
721 VisitExplicitCastExpr(S);
722}
723
724void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
725 VisitCXXConstructExpr(S);
726}
727
Douglas Gregored8abf12010-07-08 06:14:04 +0000728void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000729 VisitExpr(S);
730}
731
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000732void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
733 VisitExpr(S);
734 ID.AddBoolean(S->isGlobalDelete());
735 ID.AddBoolean(S->isArrayForm());
736 VisitDecl(S->getOperatorDelete());
737}
738
739
740void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
741 VisitExpr(S);
742 VisitType(S->getAllocatedType());
743 VisitDecl(S->getOperatorNew());
744 VisitDecl(S->getOperatorDelete());
745 VisitDecl(S->getConstructor());
746 ID.AddBoolean(S->isArray());
747 ID.AddInteger(S->getNumPlacementArgs());
748 ID.AddBoolean(S->isGlobalNew());
749 ID.AddBoolean(S->isParenTypeId());
750 ID.AddBoolean(S->hasInitializer());
751 ID.AddInteger(S->getNumConstructorArgs());
752}
753
Douglas Gregora71d8192009-09-04 17:36:40 +0000754void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
755 VisitExpr(S);
756 ID.AddBoolean(S->isArrow());
757 VisitNestedNameSpecifier(S->getQualifier());
758 VisitType(S->getDestroyedType());
759}
760
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000761void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000762 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000763 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000764 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000765 ID.AddBoolean(S->hasExplicitTemplateArgs());
766 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000767 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
768 S->getExplicitTemplateArgs().NumTemplateArgs);
769}
770
771void
772StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
773 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000774}
775
776void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
777 VisitExpr(S);
778 ID.AddInteger(S->getTrait());
779 VisitType(S->getQueriedType());
780}
781
Francois Pichet6ad6f282010-12-07 00:08:36 +0000782void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
783 VisitExpr(S);
784 ID.AddInteger(S->getTrait());
785 VisitType(S->getLhsType());
786 VisitType(S->getRhsType());
787}
788
John McCall865d4472009-11-19 22:55:06 +0000789void
790StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000791 VisitExpr(S);
792 VisitName(S->getDeclName());
793 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000794 ID.AddBoolean(S->hasExplicitTemplateArgs());
795 if (S->hasExplicitTemplateArgs())
796 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000797}
798
John McCall4765fa02010-12-06 08:20:24 +0000799void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000800 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000801}
802
Mike Stump1eb44332009-09-09 15:08:12 +0000803void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000804StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
805 VisitExpr(S);
806 VisitType(S->getTypeAsWritten());
807}
808
John McCall865d4472009-11-19 22:55:06 +0000809void
810StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000811 ID.AddBoolean(S->isImplicitAccess());
812 if (!S->isImplicitAccess()) {
813 VisitExpr(S);
814 ID.AddBoolean(S->isArrow());
815 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000816 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000817 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000818 ID.AddBoolean(S->hasExplicitTemplateArgs());
819 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000820 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
821}
822
823void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000824 ID.AddBoolean(S->isImplicitAccess());
825 if (!S->isImplicitAccess()) {
826 VisitExpr(S);
827 ID.AddBoolean(S->isArrow());
828 }
John McCall129e2df2009-11-30 22:42:35 +0000829 VisitNestedNameSpecifier(S->getQualifier());
830 VisitName(S->getMemberName());
831 ID.AddBoolean(S->hasExplicitTemplateArgs());
832 if (S->hasExplicitTemplateArgs())
833 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000834}
835
Sebastian Redl2e156222010-09-10 20:55:43 +0000836void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
837 VisitExpr(S);
838}
839
Douglas Gregorbe230c32011-01-03 17:17:50 +0000840void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
841 VisitExpr(S);
842}
843
Douglas Gregoree8aff02011-01-04 17:33:58 +0000844void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
845 VisitExpr(S);
846 VisitDecl(S->getPack());
847}
848
Douglas Gregorc7793c72011-01-15 01:15:58 +0000849void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
850 SubstNonTypeTemplateParmPackExpr *S) {
851 VisitExpr(S);
852 VisitDecl(S->getParameterPack());
853 VisitTemplateArgument(S->getArgumentPack());
854}
855
John McCall7cd7d1a2010-11-15 23:31:06 +0000856void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
857 VisitExpr(E);
858}
859
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000860void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
861 VisitExpr(S);
862}
863
864void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
865 VisitExpr(S);
866 VisitType(S->getEncodedType());
867}
868
869void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
870 VisitExpr(S);
871 VisitName(S->getSelector());
872}
873
874void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
875 VisitExpr(S);
876 VisitDecl(S->getProtocol());
877}
878
879void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
880 VisitExpr(S);
881 VisitDecl(S->getDecl());
882 ID.AddBoolean(S->isArrow());
883 ID.AddBoolean(S->isFreeIvar());
884}
885
886void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
887 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +0000888 if (S->isImplicitProperty()) {
889 VisitDecl(S->getImplicitPropertyGetter());
890 VisitDecl(S->getImplicitPropertySetter());
891 } else {
892 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000893 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000894 if (S->isSuperReceiver()) {
895 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +0000896 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000897 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000898}
899
900void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
901 VisitExpr(S);
902 VisitName(S->getSelector());
903 VisitDecl(S->getMethodDecl());
904}
905
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000906void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
907 VisitExpr(S);
908 ID.AddBoolean(S->isArrow());
909}
910
Douglas Gregord584eb22009-07-28 15:32:17 +0000911void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000912 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000913
Douglas Gregorb1975722009-07-30 23:18:24 +0000914 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000915 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000916 ID.AddInteger(NTTP->getDepth());
917 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000918 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +0000919 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000920 return;
921 }
Mike Stump1eb44332009-09-09 15:08:12 +0000922
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000923 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
924 // The Itanium C++ ABI uses the type of a parameter when mangling
925 // expressions that involve function parameters, so we will use the
926 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000927 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000928 // matches the definition of "equivalent" used for name mangling.
929 VisitType(Parm->getType());
930 return;
931 }
Mike Stump1eb44332009-09-09 15:08:12 +0000932
Douglas Gregora2ffb982009-07-31 15:46:56 +0000933 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
934 ID.AddInteger(TTP->getDepth());
935 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000936 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +0000937 return;
938 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000939 }
Mike Stump1eb44332009-09-09 15:08:12 +0000940
Douglas Gregord584eb22009-07-28 15:32:17 +0000941 ID.AddPointer(D? D->getCanonicalDecl() : 0);
942}
943
944void StmtProfiler::VisitType(QualType T) {
945 if (Canonical)
946 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000947
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000948 ID.AddPointer(T.getAsOpaquePtr());
949}
950
951void StmtProfiler::VisitName(DeclarationName Name) {
952 ID.AddPointer(Name.getAsOpaquePtr());
953}
954
955void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
956 if (Canonical)
957 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
958 ID.AddPointer(NNS);
959}
960
961void StmtProfiler::VisitTemplateName(TemplateName Name) {
962 if (Canonical)
963 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000964
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000965 Name.Profile(ID);
966}
967
John McCall833ca992009-10-29 08:12:44 +0000968void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000969 unsigned NumArgs) {
970 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000971 for (unsigned I = 0; I != NumArgs; ++I)
972 VisitTemplateArgument(Args[I].getArgument());
973}
Mike Stump1eb44332009-09-09 15:08:12 +0000974
John McCall833ca992009-10-29 08:12:44 +0000975void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
976 // Mostly repetitive with TemplateArgument::Profile!
977 ID.AddInteger(Arg.getKind());
978 switch (Arg.getKind()) {
979 case TemplateArgument::Null:
980 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000981
John McCall833ca992009-10-29 08:12:44 +0000982 case TemplateArgument::Type:
983 VisitType(Arg.getAsType());
984 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregor788cd062009-11-11 01:00:40 +0000986 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +0000987 case TemplateArgument::TemplateExpansion:
988 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +0000989 break;
Sean Huntc3021132010-05-05 15:23:54 +0000990
John McCall833ca992009-10-29 08:12:44 +0000991 case TemplateArgument::Declaration:
992 VisitDecl(Arg.getAsDecl());
993 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000994
John McCall833ca992009-10-29 08:12:44 +0000995 case TemplateArgument::Integral:
996 Arg.getAsIntegral()->Profile(ID);
997 VisitType(Arg.getIntegralType());
998 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000999
John McCall833ca992009-10-29 08:12:44 +00001000 case TemplateArgument::Expression:
1001 Visit(Arg.getAsExpr());
1002 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001003
John McCall833ca992009-10-29 08:12:44 +00001004 case TemplateArgument::Pack:
1005 const TemplateArgument *Pack = Arg.pack_begin();
1006 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1007 VisitTemplateArgument(Pack[i]);
1008 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001009 }
1010}
1011
Jay Foad4ba2a172011-01-12 09:06:06 +00001012void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001013 bool Canonical) {
1014 StmtProfiler Profiler(ID, Context, Canonical);
1015 Profiler.Visit(this);
1016}