blob: 17383c137a25a5027f0d27b436db1d3aafbfc2ed [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
Richard Smithad762fc2011-04-14 22:09:26 +0000180void StmtProfiler::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
181 VisitStmt(S);
182}
183
John Wiegley28bbe4b2011-04-28 01:08:34 +0000184void StmtProfiler::VisitSEHTryStmt(SEHTryStmt *S) {
185 VisitStmt(S);
186}
187
188void StmtProfiler::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
189 VisitStmt(S);
190}
191
192void StmtProfiler::VisitSEHExceptStmt(SEHExceptStmt *S) {
193 VisitStmt(S);
194}
195
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000196void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
197 VisitStmt(S);
198}
199
200void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
201 VisitStmt(S);
202 ID.AddBoolean(S->hasEllipsis());
203 if (S->getCatchParamDecl())
204 VisitType(S->getCatchParamDecl()->getType());
205}
206
207void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
208 VisitStmt(S);
209}
210
211void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
212 VisitStmt(S);
213}
214
215void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
216 VisitStmt(S);
217}
218
219void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
220 VisitStmt(S);
221}
222
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000223void StmtProfiler::VisitExpr(Expr *S) {
224 VisitStmt(S);
225}
226
227void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
228 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000229 if (!Canonical)
230 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000231 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000232 if (!Canonical)
233 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000234}
235
236void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
237 VisitExpr(S);
238 ID.AddInteger(S->getIdentType());
239}
240
241void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
242 VisitExpr(S);
243 S->getValue().Profile(ID);
244}
245
246void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
247 VisitExpr(S);
248 ID.AddBoolean(S->isWide());
249 ID.AddInteger(S->getValue());
250}
251
252void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
253 VisitExpr(S);
254 S->getValue().Profile(ID);
255 ID.AddBoolean(S->isExact());
256}
257
258void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
259 VisitExpr(S);
260}
261
262void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
263 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000264 ID.AddString(S->getString());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000265 ID.AddBoolean(S->isWide());
266}
267
268void StmtProfiler::VisitParenExpr(ParenExpr *S) {
269 VisitExpr(S);
270}
271
Nate Begeman2ef13e52009-08-10 23:49:36 +0000272void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
273 VisitExpr(S);
274}
275
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000276void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
277 VisitExpr(S);
278 ID.AddInteger(S->getOpcode());
279}
280
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000281void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
282 VisitType(S->getTypeSourceInfo()->getType());
283 unsigned n = S->getNumComponents();
284 for (unsigned i = 0; i < n; ++i) {
285 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
286 ID.AddInteger(ON.getKind());
287 switch (ON.getKind()) {
288 case OffsetOfExpr::OffsetOfNode::Array:
289 // Expressions handled below.
290 break;
291
292 case OffsetOfExpr::OffsetOfNode::Field:
293 VisitDecl(ON.getField());
294 break;
295
296 case OffsetOfExpr::OffsetOfNode::Identifier:
297 ID.AddPointer(ON.getFieldName());
298 break;
Sean Huntc3021132010-05-05 15:23:54 +0000299
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000300 case OffsetOfExpr::OffsetOfNode::Base:
301 // These nodes are implicit, and therefore don't need profiling.
302 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000303 }
304 }
Sean Huntc3021132010-05-05 15:23:54 +0000305
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000306 VisitExpr(S);
307}
308
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000309void StmtProfiler::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000310 VisitExpr(S);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000311 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000312 if (S->isArgumentType())
313 VisitType(S->getArgumentType());
314}
315
316void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
317 VisitExpr(S);
318}
319
320void StmtProfiler::VisitCallExpr(CallExpr *S) {
321 VisitExpr(S);
322}
323
324void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
325 VisitExpr(S);
326 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000327 if (!Canonical)
328 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000329 ID.AddBoolean(S->isArrow());
330}
331
332void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
333 VisitExpr(S);
334 ID.AddBoolean(S->isFileScope());
335}
336
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000337void StmtProfiler::VisitCastExpr(CastExpr *S) {
338 VisitExpr(S);
339}
340
341void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
342 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000343 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000344}
345
346void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
347 VisitCastExpr(S);
348 VisitType(S->getTypeAsWritten());
349}
350
351void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
352 VisitExplicitCastExpr(S);
353}
354
355void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
356 VisitExpr(S);
357 ID.AddInteger(S->getOpcode());
358}
359
360void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
361 VisitBinaryOperator(S);
362}
363
364void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
365 VisitExpr(S);
366}
367
John McCall56ca35d2011-02-17 10:25:35 +0000368void StmtProfiler::VisitBinaryConditionalOperator(BinaryConditionalOperator *S){
369 VisitExpr(S);
370}
371
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000372void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
373 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000374 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000375}
376
377void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
378 VisitExpr(S);
379}
380
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000381void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
382 VisitExpr(S);
383}
384
385void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
386 VisitExpr(S);
387}
388
389void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
390 VisitExpr(S);
391}
392
Douglas Gregor828e2262009-07-29 16:09:57 +0000393void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
394 VisitExpr(S);
395}
396
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000397void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
398 if (S->getSyntacticForm()) {
399 VisitInitListExpr(S->getSyntacticForm());
400 return;
401 }
Mike Stump1eb44332009-09-09 15:08:12 +0000402
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000403 VisitExpr(S);
404}
405
406void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
407 VisitExpr(S);
408 ID.AddBoolean(S->usesGNUSyntax());
409 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
410 DEnd = S->designators_end();
411 D != DEnd; ++D) {
412 if (D->isFieldDesignator()) {
413 ID.AddInteger(0);
414 VisitName(D->getFieldName());
415 continue;
416 }
Mike Stump1eb44332009-09-09 15:08:12 +0000417
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000418 if (D->isArrayDesignator()) {
419 ID.AddInteger(1);
420 } else {
421 assert(D->isArrayRangeDesignator());
422 ID.AddInteger(2);
423 }
424 ID.AddInteger(D->getFirstExprIndex());
425 }
426}
427
428void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
429 VisitExpr(S);
430}
431
432void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
433 VisitExpr(S);
434 VisitName(&S->getAccessor());
435}
436
437void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
438 VisitExpr(S);
439 VisitDecl(S->getBlockDecl());
440}
441
442void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
443 VisitExpr(S);
444 VisitDecl(S->getDecl());
445 ID.AddBoolean(S->isByRef());
446 ID.AddBoolean(S->isConstQualAdded());
447}
448
Peter Collingbournef111d932011-04-15 00:35:48 +0000449void StmtProfiler::VisitGenericSelectionExpr(GenericSelectionExpr *S) {
450 VisitExpr(S);
451 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
452 QualType T = S->getAssocType(i);
453 if (T.isNull())
454 ID.AddPointer(0);
455 else
456 VisitType(T);
457 VisitExpr(S->getAssocExpr(i));
458 }
459}
460
Douglas Gregora89064a2010-05-19 04:13:23 +0000461static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000462 UnaryOperatorKind &UnaryOp,
463 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000464 switch (S->getOperator()) {
465 case OO_None:
466 case OO_New:
467 case OO_Delete:
468 case OO_Array_New:
469 case OO_Array_Delete:
470 case OO_Arrow:
471 case OO_Call:
472 case OO_Conditional:
473 case NUM_OVERLOADED_OPERATORS:
474 llvm_unreachable("Invalid operator call kind");
475 return Stmt::ArraySubscriptExprClass;
476
477 case OO_Plus:
478 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000479 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000480 return Stmt::UnaryOperatorClass;
481 }
482
John McCall2de56d12010-08-25 11:45:40 +0000483 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000484 return Stmt::BinaryOperatorClass;
485
486 case OO_Minus:
487 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000488 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000489 return Stmt::UnaryOperatorClass;
490 }
491
John McCall2de56d12010-08-25 11:45:40 +0000492 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000493 return Stmt::BinaryOperatorClass;
494
495 case OO_Star:
496 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000497 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000498 return Stmt::UnaryOperatorClass;
499 }
500
John McCall2de56d12010-08-25 11:45:40 +0000501 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000502 return Stmt::BinaryOperatorClass;
503
504 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000505 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000506 return Stmt::BinaryOperatorClass;
507
508 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000509 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000510 return Stmt::BinaryOperatorClass;
511
512 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000513 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000514 return Stmt::BinaryOperatorClass;
515
516 case OO_Amp:
517 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000518 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000519 return Stmt::UnaryOperatorClass;
520 }
521
John McCall2de56d12010-08-25 11:45:40 +0000522 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000523 return Stmt::BinaryOperatorClass;
524
525 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000526 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000527 return Stmt::BinaryOperatorClass;
528
529 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000530 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000531 return Stmt::UnaryOperatorClass;
532
533 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000534 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000535 return Stmt::UnaryOperatorClass;
536
537 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000538 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000539 return Stmt::BinaryOperatorClass;
540
541 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000542 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000543 return Stmt::BinaryOperatorClass;
544
545 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000546 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000547 return Stmt::BinaryOperatorClass;
548
549 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000550 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000551 return Stmt::CompoundAssignOperatorClass;
552
553 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000554 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000555 return Stmt::CompoundAssignOperatorClass;
556
557 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000558 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000559 return Stmt::CompoundAssignOperatorClass;
560
561 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000562 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000563 return Stmt::CompoundAssignOperatorClass;
564
565 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000566 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000567 return Stmt::CompoundAssignOperatorClass;
568
569 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000570 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000571 return Stmt::CompoundAssignOperatorClass;
572
573 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000574 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000575 return Stmt::CompoundAssignOperatorClass;
576
577 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000578 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000579 return Stmt::CompoundAssignOperatorClass;
580
581 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000582 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000583 return Stmt::BinaryOperatorClass;
584
585 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000586 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000587 return Stmt::BinaryOperatorClass;
588
589 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000590 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000591 return Stmt::CompoundAssignOperatorClass;
592
593 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000594 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000595 return Stmt::CompoundAssignOperatorClass;
596
597 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000598 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000599 return Stmt::BinaryOperatorClass;
600
601 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000602 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000603 return Stmt::BinaryOperatorClass;
604
605 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000606 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000607 return Stmt::BinaryOperatorClass;
608
609 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000610 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000611 return Stmt::BinaryOperatorClass;
612
613 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000614 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000615 return Stmt::BinaryOperatorClass;
616
617 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000618 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000619 return Stmt::BinaryOperatorClass;
620
621 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000622 UnaryOp = S->getNumArgs() == 1? UO_PreInc
623 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000624 return Stmt::UnaryOperatorClass;
625
626 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000627 UnaryOp = S->getNumArgs() == 1? UO_PreDec
628 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000629 return Stmt::UnaryOperatorClass;
630
631 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000632 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000633 return Stmt::BinaryOperatorClass;
634
635
636 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000637 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000638 return Stmt::BinaryOperatorClass;
639
640 case OO_Subscript:
641 return Stmt::ArraySubscriptExprClass;
642 }
643
644 llvm_unreachable("Invalid overloaded operator expression");
645}
646
647
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000648void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000649 if (S->isTypeDependent()) {
650 // Type-dependent operator calls are profiled like their underlying
651 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000652 UnaryOperatorKind UnaryOp = UO_Extension;
653 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000654 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
655
656 ID.AddInteger(SC);
657 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
658 Visit(S->getArg(I));
659 if (SC == Stmt::UnaryOperatorClass)
660 ID.AddInteger(UnaryOp);
661 else if (SC == Stmt::BinaryOperatorClass ||
662 SC == Stmt::CompoundAssignOperatorClass)
663 ID.AddInteger(BinaryOp);
664 else
665 assert(SC == Stmt::ArraySubscriptExprClass);
666
667 return;
668 }
669
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000670 VisitCallExpr(S);
671 ID.AddInteger(S->getOperator());
672}
673
674void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
675 VisitCallExpr(S);
676}
677
Peter Collingbournee08ce652011-02-09 21:07:24 +0000678void StmtProfiler::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *S) {
679 VisitCallExpr(S);
680}
681
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000682void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
683 VisitExplicitCastExpr(S);
684}
685
686void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
687 VisitCXXNamedCastExpr(S);
688}
689
690void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
691 VisitCXXNamedCastExpr(S);
692}
693
694void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
695 VisitCXXNamedCastExpr(S);
696}
697
698void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
699 VisitCXXNamedCastExpr(S);
700}
701
702void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
703 VisitExpr(S);
704 ID.AddBoolean(S->getValue());
705}
706
Douglas Gregor828e2262009-07-29 16:09:57 +0000707void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
708 VisitExpr(S);
709}
710
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000711void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
712 VisitExpr(S);
713 if (S->isTypeOperand())
714 VisitType(S->getTypeOperand());
715}
716
Francois Pichet01b7c302010-09-08 12:20:18 +0000717void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
718 VisitExpr(S);
719 if (S->isTypeOperand())
720 VisitType(S->getTypeOperand());
721}
722
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000723void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
724 VisitExpr(S);
725}
726
727void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
728 VisitExpr(S);
729}
730
731void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
732 VisitExpr(S);
733 VisitDecl(S->getParam());
734}
735
736void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
737 VisitExpr(S);
738 VisitDecl(
739 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
740}
741
742void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
743 VisitExpr(S);
744 VisitDecl(S->getConstructor());
745 ID.AddBoolean(S->isElidable());
746}
747
748void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
749 VisitExplicitCastExpr(S);
750}
751
752void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
753 VisitCXXConstructExpr(S);
754}
755
Douglas Gregored8abf12010-07-08 06:14:04 +0000756void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000757 VisitExpr(S);
758}
759
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000760void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
761 VisitExpr(S);
762 ID.AddBoolean(S->isGlobalDelete());
763 ID.AddBoolean(S->isArrayForm());
764 VisitDecl(S->getOperatorDelete());
765}
766
767
768void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
769 VisitExpr(S);
770 VisitType(S->getAllocatedType());
771 VisitDecl(S->getOperatorNew());
772 VisitDecl(S->getOperatorDelete());
773 VisitDecl(S->getConstructor());
774 ID.AddBoolean(S->isArray());
775 ID.AddInteger(S->getNumPlacementArgs());
776 ID.AddBoolean(S->isGlobalNew());
777 ID.AddBoolean(S->isParenTypeId());
778 ID.AddBoolean(S->hasInitializer());
779 ID.AddInteger(S->getNumConstructorArgs());
780}
781
Douglas Gregora71d8192009-09-04 17:36:40 +0000782void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
783 VisitExpr(S);
784 ID.AddBoolean(S->isArrow());
785 VisitNestedNameSpecifier(S->getQualifier());
786 VisitType(S->getDestroyedType());
787}
788
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000789void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000790 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000791 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000792 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000793 ID.AddBoolean(S->hasExplicitTemplateArgs());
794 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000795 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
796 S->getExplicitTemplateArgs().NumTemplateArgs);
797}
798
799void
800StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
801 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000802}
803
804void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
805 VisitExpr(S);
806 ID.AddInteger(S->getTrait());
807 VisitType(S->getQueriedType());
808}
809
Francois Pichet6ad6f282010-12-07 00:08:36 +0000810void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
811 VisitExpr(S);
812 ID.AddInteger(S->getTrait());
813 VisitType(S->getLhsType());
814 VisitType(S->getRhsType());
815}
816
John Wiegley21ff2e52011-04-28 00:16:57 +0000817void StmtProfiler::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *S) {
818 VisitExpr(S);
819 ID.AddInteger(S->getTrait());
820 VisitType(S->getQueriedType());
821}
822
John Wiegley55262202011-04-25 06:54:41 +0000823void StmtProfiler::VisitExpressionTraitExpr(ExpressionTraitExpr *S) {
824 VisitExpr(S);
825 ID.AddInteger(S->getTrait());
826 VisitExpr(S->getQueriedExpression());
827}
828
John McCall865d4472009-11-19 22:55:06 +0000829void
830StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000831 VisitExpr(S);
832 VisitName(S->getDeclName());
833 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000834 ID.AddBoolean(S->hasExplicitTemplateArgs());
835 if (S->hasExplicitTemplateArgs())
836 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000837}
838
John McCall4765fa02010-12-06 08:20:24 +0000839void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000840 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000841}
842
Mike Stump1eb44332009-09-09 15:08:12 +0000843void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000844StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
845 VisitExpr(S);
846 VisitType(S->getTypeAsWritten());
847}
848
John McCall865d4472009-11-19 22:55:06 +0000849void
850StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000851 ID.AddBoolean(S->isImplicitAccess());
852 if (!S->isImplicitAccess()) {
853 VisitExpr(S);
854 ID.AddBoolean(S->isArrow());
855 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000856 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000857 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000858 ID.AddBoolean(S->hasExplicitTemplateArgs());
859 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000860 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
861}
862
863void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000864 ID.AddBoolean(S->isImplicitAccess());
865 if (!S->isImplicitAccess()) {
866 VisitExpr(S);
867 ID.AddBoolean(S->isArrow());
868 }
John McCall129e2df2009-11-30 22:42:35 +0000869 VisitNestedNameSpecifier(S->getQualifier());
870 VisitName(S->getMemberName());
871 ID.AddBoolean(S->hasExplicitTemplateArgs());
872 if (S->hasExplicitTemplateArgs())
873 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000874}
875
Sebastian Redl2e156222010-09-10 20:55:43 +0000876void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
877 VisitExpr(S);
878}
879
Douglas Gregorbe230c32011-01-03 17:17:50 +0000880void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
881 VisitExpr(S);
882}
883
Douglas Gregoree8aff02011-01-04 17:33:58 +0000884void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
885 VisitExpr(S);
886 VisitDecl(S->getPack());
887}
888
Douglas Gregorc7793c72011-01-15 01:15:58 +0000889void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
890 SubstNonTypeTemplateParmPackExpr *S) {
891 VisitExpr(S);
892 VisitDecl(S->getParameterPack());
893 VisitTemplateArgument(S->getArgumentPack());
894}
895
John McCall7cd7d1a2010-11-15 23:31:06 +0000896void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
897 VisitExpr(E);
898}
899
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000900void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
901 VisitExpr(S);
902}
903
904void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
905 VisitExpr(S);
906 VisitType(S->getEncodedType());
907}
908
909void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
910 VisitExpr(S);
911 VisitName(S->getSelector());
912}
913
914void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
915 VisitExpr(S);
916 VisitDecl(S->getProtocol());
917}
918
919void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
920 VisitExpr(S);
921 VisitDecl(S->getDecl());
922 ID.AddBoolean(S->isArrow());
923 ID.AddBoolean(S->isFreeIvar());
924}
925
926void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
927 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +0000928 if (S->isImplicitProperty()) {
929 VisitDecl(S->getImplicitPropertyGetter());
930 VisitDecl(S->getImplicitPropertySetter());
931 } else {
932 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000933 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000934 if (S->isSuperReceiver()) {
935 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +0000936 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000937 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000938}
939
940void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
941 VisitExpr(S);
942 VisitName(S->getSelector());
943 VisitDecl(S->getMethodDecl());
944}
945
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000946void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
947 VisitExpr(S);
948 ID.AddBoolean(S->isArrow());
949}
950
Douglas Gregord584eb22009-07-28 15:32:17 +0000951void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000952 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000953
Douglas Gregorb1975722009-07-30 23:18:24 +0000954 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000955 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000956 ID.AddInteger(NTTP->getDepth());
957 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000958 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +0000959 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000960 return;
961 }
Mike Stump1eb44332009-09-09 15:08:12 +0000962
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000963 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
964 // The Itanium C++ ABI uses the type of a parameter when mangling
965 // expressions that involve function parameters, so we will use the
966 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000967 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000968 // matches the definition of "equivalent" used for name mangling.
969 VisitType(Parm->getType());
970 return;
971 }
Mike Stump1eb44332009-09-09 15:08:12 +0000972
Douglas Gregora2ffb982009-07-31 15:46:56 +0000973 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
974 ID.AddInteger(TTP->getDepth());
975 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000976 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +0000977 return;
978 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000979 }
Mike Stump1eb44332009-09-09 15:08:12 +0000980
Douglas Gregord584eb22009-07-28 15:32:17 +0000981 ID.AddPointer(D? D->getCanonicalDecl() : 0);
982}
983
984void StmtProfiler::VisitType(QualType T) {
985 if (Canonical)
986 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000987
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000988 ID.AddPointer(T.getAsOpaquePtr());
989}
990
991void StmtProfiler::VisitName(DeclarationName Name) {
992 ID.AddPointer(Name.getAsOpaquePtr());
993}
994
995void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
996 if (Canonical)
997 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
998 ID.AddPointer(NNS);
999}
1000
1001void StmtProfiler::VisitTemplateName(TemplateName Name) {
1002 if (Canonical)
1003 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +00001004
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001005 Name.Profile(ID);
1006}
1007
John McCall833ca992009-10-29 08:12:44 +00001008void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001009 unsigned NumArgs) {
1010 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +00001011 for (unsigned I = 0; I != NumArgs; ++I)
1012 VisitTemplateArgument(Args[I].getArgument());
1013}
Mike Stump1eb44332009-09-09 15:08:12 +00001014
John McCall833ca992009-10-29 08:12:44 +00001015void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1016 // Mostly repetitive with TemplateArgument::Profile!
1017 ID.AddInteger(Arg.getKind());
1018 switch (Arg.getKind()) {
1019 case TemplateArgument::Null:
1020 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001021
John McCall833ca992009-10-29 08:12:44 +00001022 case TemplateArgument::Type:
1023 VisitType(Arg.getAsType());
1024 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001025
Douglas Gregor788cd062009-11-11 01:00:40 +00001026 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00001027 case TemplateArgument::TemplateExpansion:
1028 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +00001029 break;
Sean Huntc3021132010-05-05 15:23:54 +00001030
John McCall833ca992009-10-29 08:12:44 +00001031 case TemplateArgument::Declaration:
1032 VisitDecl(Arg.getAsDecl());
1033 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001034
John McCall833ca992009-10-29 08:12:44 +00001035 case TemplateArgument::Integral:
1036 Arg.getAsIntegral()->Profile(ID);
1037 VisitType(Arg.getIntegralType());
1038 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001039
John McCall833ca992009-10-29 08:12:44 +00001040 case TemplateArgument::Expression:
1041 Visit(Arg.getAsExpr());
1042 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001043
John McCall833ca992009-10-29 08:12:44 +00001044 case TemplateArgument::Pack:
1045 const TemplateArgument *Pack = Arg.pack_begin();
1046 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1047 VisitTemplateArgument(Pack[i]);
1048 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001049 }
1050}
1051
Jay Foad4ba2a172011-01-12 09:06:06 +00001052void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001053 bool Canonical) {
1054 StmtProfiler Profiler(ID, Context, Canonical);
1055 Profiler.Visit(this);
1056}