blob: 7a3fc5417c463b2260b4afe317c1e59518e2d4f3 [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
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000184void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
185 VisitStmt(S);
186}
187
188void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
189 VisitStmt(S);
190 ID.AddBoolean(S->hasEllipsis());
191 if (S->getCatchParamDecl())
192 VisitType(S->getCatchParamDecl()->getType());
193}
194
195void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
196 VisitStmt(S);
197}
198
199void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
200 VisitStmt(S);
201}
202
203void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
204 VisitStmt(S);
205}
206
207void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
208 VisitStmt(S);
209}
210
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000211void StmtProfiler::VisitExpr(Expr *S) {
212 VisitStmt(S);
213}
214
215void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
216 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000217 if (!Canonical)
218 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000219 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000220 if (!Canonical)
221 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000222}
223
224void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
225 VisitExpr(S);
226 ID.AddInteger(S->getIdentType());
227}
228
229void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
230 VisitExpr(S);
231 S->getValue().Profile(ID);
232}
233
234void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
235 VisitExpr(S);
236 ID.AddBoolean(S->isWide());
237 ID.AddInteger(S->getValue());
238}
239
240void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
241 VisitExpr(S);
242 S->getValue().Profile(ID);
243 ID.AddBoolean(S->isExact());
244}
245
246void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
247 VisitExpr(S);
248}
249
250void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
251 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000252 ID.AddString(S->getString());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000253 ID.AddBoolean(S->isWide());
254}
255
256void StmtProfiler::VisitParenExpr(ParenExpr *S) {
257 VisitExpr(S);
258}
259
Nate Begeman2ef13e52009-08-10 23:49:36 +0000260void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
261 VisitExpr(S);
262}
263
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000264void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
265 VisitExpr(S);
266 ID.AddInteger(S->getOpcode());
267}
268
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000269void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
270 VisitType(S->getTypeSourceInfo()->getType());
271 unsigned n = S->getNumComponents();
272 for (unsigned i = 0; i < n; ++i) {
273 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
274 ID.AddInteger(ON.getKind());
275 switch (ON.getKind()) {
276 case OffsetOfExpr::OffsetOfNode::Array:
277 // Expressions handled below.
278 break;
279
280 case OffsetOfExpr::OffsetOfNode::Field:
281 VisitDecl(ON.getField());
282 break;
283
284 case OffsetOfExpr::OffsetOfNode::Identifier:
285 ID.AddPointer(ON.getFieldName());
286 break;
Sean Huntc3021132010-05-05 15:23:54 +0000287
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000288 case OffsetOfExpr::OffsetOfNode::Base:
289 // These nodes are implicit, and therefore don't need profiling.
290 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000291 }
292 }
Sean Huntc3021132010-05-05 15:23:54 +0000293
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000294 VisitExpr(S);
295}
296
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000297void StmtProfiler::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000298 VisitExpr(S);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000299 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000300 if (S->isArgumentType())
301 VisitType(S->getArgumentType());
302}
303
304void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
305 VisitExpr(S);
306}
307
308void StmtProfiler::VisitCallExpr(CallExpr *S) {
309 VisitExpr(S);
310}
311
312void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
313 VisitExpr(S);
314 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000315 if (!Canonical)
316 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000317 ID.AddBoolean(S->isArrow());
318}
319
320void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
321 VisitExpr(S);
322 ID.AddBoolean(S->isFileScope());
323}
324
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000325void StmtProfiler::VisitCastExpr(CastExpr *S) {
326 VisitExpr(S);
327}
328
329void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
330 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000331 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000332}
333
334void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
335 VisitCastExpr(S);
336 VisitType(S->getTypeAsWritten());
337}
338
339void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
340 VisitExplicitCastExpr(S);
341}
342
343void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
344 VisitExpr(S);
345 ID.AddInteger(S->getOpcode());
346}
347
348void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
349 VisitBinaryOperator(S);
350}
351
352void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
353 VisitExpr(S);
354}
355
John McCall56ca35d2011-02-17 10:25:35 +0000356void StmtProfiler::VisitBinaryConditionalOperator(BinaryConditionalOperator *S){
357 VisitExpr(S);
358}
359
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000360void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
361 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000362 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000363}
364
365void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
366 VisitExpr(S);
367}
368
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000369void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
370 VisitExpr(S);
371}
372
373void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
374 VisitExpr(S);
375}
376
377void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
378 VisitExpr(S);
379}
380
Douglas Gregor828e2262009-07-29 16:09:57 +0000381void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
382 VisitExpr(S);
383}
384
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000385void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
386 if (S->getSyntacticForm()) {
387 VisitInitListExpr(S->getSyntacticForm());
388 return;
389 }
Mike Stump1eb44332009-09-09 15:08:12 +0000390
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000391 VisitExpr(S);
392}
393
394void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
395 VisitExpr(S);
396 ID.AddBoolean(S->usesGNUSyntax());
397 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
398 DEnd = S->designators_end();
399 D != DEnd; ++D) {
400 if (D->isFieldDesignator()) {
401 ID.AddInteger(0);
402 VisitName(D->getFieldName());
403 continue;
404 }
Mike Stump1eb44332009-09-09 15:08:12 +0000405
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000406 if (D->isArrayDesignator()) {
407 ID.AddInteger(1);
408 } else {
409 assert(D->isArrayRangeDesignator());
410 ID.AddInteger(2);
411 }
412 ID.AddInteger(D->getFirstExprIndex());
413 }
414}
415
416void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
417 VisitExpr(S);
418}
419
420void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
421 VisitExpr(S);
422 VisitName(&S->getAccessor());
423}
424
425void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
426 VisitExpr(S);
427 VisitDecl(S->getBlockDecl());
428}
429
430void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
431 VisitExpr(S);
432 VisitDecl(S->getDecl());
433 ID.AddBoolean(S->isByRef());
434 ID.AddBoolean(S->isConstQualAdded());
435}
436
Peter Collingbournef111d932011-04-15 00:35:48 +0000437void StmtProfiler::VisitGenericSelectionExpr(GenericSelectionExpr *S) {
438 VisitExpr(S);
439 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
440 QualType T = S->getAssocType(i);
441 if (T.isNull())
442 ID.AddPointer(0);
443 else
444 VisitType(T);
445 VisitExpr(S->getAssocExpr(i));
446 }
447}
448
Douglas Gregora89064a2010-05-19 04:13:23 +0000449static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000450 UnaryOperatorKind &UnaryOp,
451 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000452 switch (S->getOperator()) {
453 case OO_None:
454 case OO_New:
455 case OO_Delete:
456 case OO_Array_New:
457 case OO_Array_Delete:
458 case OO_Arrow:
459 case OO_Call:
460 case OO_Conditional:
461 case NUM_OVERLOADED_OPERATORS:
462 llvm_unreachable("Invalid operator call kind");
463 return Stmt::ArraySubscriptExprClass;
464
465 case OO_Plus:
466 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000467 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000468 return Stmt::UnaryOperatorClass;
469 }
470
John McCall2de56d12010-08-25 11:45:40 +0000471 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000472 return Stmt::BinaryOperatorClass;
473
474 case OO_Minus:
475 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000476 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000477 return Stmt::UnaryOperatorClass;
478 }
479
John McCall2de56d12010-08-25 11:45:40 +0000480 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000481 return Stmt::BinaryOperatorClass;
482
483 case OO_Star:
484 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000485 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000486 return Stmt::UnaryOperatorClass;
487 }
488
John McCall2de56d12010-08-25 11:45:40 +0000489 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000490 return Stmt::BinaryOperatorClass;
491
492 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000493 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000494 return Stmt::BinaryOperatorClass;
495
496 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000497 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000498 return Stmt::BinaryOperatorClass;
499
500 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000501 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000502 return Stmt::BinaryOperatorClass;
503
504 case OO_Amp:
505 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000506 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000507 return Stmt::UnaryOperatorClass;
508 }
509
John McCall2de56d12010-08-25 11:45:40 +0000510 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000511 return Stmt::BinaryOperatorClass;
512
513 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000514 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000515 return Stmt::BinaryOperatorClass;
516
517 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000518 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000519 return Stmt::UnaryOperatorClass;
520
521 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000522 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000523 return Stmt::UnaryOperatorClass;
524
525 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000526 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000527 return Stmt::BinaryOperatorClass;
528
529 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000530 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000531 return Stmt::BinaryOperatorClass;
532
533 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000534 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000535 return Stmt::BinaryOperatorClass;
536
537 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000538 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000539 return Stmt::CompoundAssignOperatorClass;
540
541 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000542 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000543 return Stmt::CompoundAssignOperatorClass;
544
545 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000546 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000547 return Stmt::CompoundAssignOperatorClass;
548
549 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000550 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000551 return Stmt::CompoundAssignOperatorClass;
552
553 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000554 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000555 return Stmt::CompoundAssignOperatorClass;
556
557 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000558 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000559 return Stmt::CompoundAssignOperatorClass;
560
561 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000562 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000563 return Stmt::CompoundAssignOperatorClass;
564
565 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000566 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000567 return Stmt::CompoundAssignOperatorClass;
568
569 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000570 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000571 return Stmt::BinaryOperatorClass;
572
573 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000574 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000575 return Stmt::BinaryOperatorClass;
576
577 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000578 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000579 return Stmt::CompoundAssignOperatorClass;
580
581 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000582 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000583 return Stmt::CompoundAssignOperatorClass;
584
585 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000586 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000587 return Stmt::BinaryOperatorClass;
588
589 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000590 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000591 return Stmt::BinaryOperatorClass;
592
593 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000594 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000595 return Stmt::BinaryOperatorClass;
596
597 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000598 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000599 return Stmt::BinaryOperatorClass;
600
601 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000602 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000603 return Stmt::BinaryOperatorClass;
604
605 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000606 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000607 return Stmt::BinaryOperatorClass;
608
609 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000610 UnaryOp = S->getNumArgs() == 1? UO_PreInc
611 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000612 return Stmt::UnaryOperatorClass;
613
614 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000615 UnaryOp = S->getNumArgs() == 1? UO_PreDec
616 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000617 return Stmt::UnaryOperatorClass;
618
619 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000620 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000621 return Stmt::BinaryOperatorClass;
622
623
624 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000625 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000626 return Stmt::BinaryOperatorClass;
627
628 case OO_Subscript:
629 return Stmt::ArraySubscriptExprClass;
630 }
631
632 llvm_unreachable("Invalid overloaded operator expression");
633}
634
635
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000636void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000637 if (S->isTypeDependent()) {
638 // Type-dependent operator calls are profiled like their underlying
639 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000640 UnaryOperatorKind UnaryOp = UO_Extension;
641 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000642 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
643
644 ID.AddInteger(SC);
645 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
646 Visit(S->getArg(I));
647 if (SC == Stmt::UnaryOperatorClass)
648 ID.AddInteger(UnaryOp);
649 else if (SC == Stmt::BinaryOperatorClass ||
650 SC == Stmt::CompoundAssignOperatorClass)
651 ID.AddInteger(BinaryOp);
652 else
653 assert(SC == Stmt::ArraySubscriptExprClass);
654
655 return;
656 }
657
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000658 VisitCallExpr(S);
659 ID.AddInteger(S->getOperator());
660}
661
662void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
663 VisitCallExpr(S);
664}
665
Peter Collingbournee08ce652011-02-09 21:07:24 +0000666void StmtProfiler::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *S) {
667 VisitCallExpr(S);
668}
669
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000670void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
671 VisitExplicitCastExpr(S);
672}
673
674void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
675 VisitCXXNamedCastExpr(S);
676}
677
678void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
679 VisitCXXNamedCastExpr(S);
680}
681
682void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
683 VisitCXXNamedCastExpr(S);
684}
685
686void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
687 VisitCXXNamedCastExpr(S);
688}
689
690void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
691 VisitExpr(S);
692 ID.AddBoolean(S->getValue());
693}
694
Douglas Gregor828e2262009-07-29 16:09:57 +0000695void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
696 VisitExpr(S);
697}
698
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000699void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
700 VisitExpr(S);
701 if (S->isTypeOperand())
702 VisitType(S->getTypeOperand());
703}
704
Francois Pichet01b7c302010-09-08 12:20:18 +0000705void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
706 VisitExpr(S);
707 if (S->isTypeOperand())
708 VisitType(S->getTypeOperand());
709}
710
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000711void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
712 VisitExpr(S);
713}
714
715void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
716 VisitExpr(S);
717}
718
719void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
720 VisitExpr(S);
721 VisitDecl(S->getParam());
722}
723
724void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
725 VisitExpr(S);
726 VisitDecl(
727 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
728}
729
730void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
731 VisitExpr(S);
732 VisitDecl(S->getConstructor());
733 ID.AddBoolean(S->isElidable());
734}
735
736void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
737 VisitExplicitCastExpr(S);
738}
739
740void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
741 VisitCXXConstructExpr(S);
742}
743
Douglas Gregored8abf12010-07-08 06:14:04 +0000744void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000745 VisitExpr(S);
746}
747
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000748void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
749 VisitExpr(S);
750 ID.AddBoolean(S->isGlobalDelete());
751 ID.AddBoolean(S->isArrayForm());
752 VisitDecl(S->getOperatorDelete());
753}
754
755
756void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
757 VisitExpr(S);
758 VisitType(S->getAllocatedType());
759 VisitDecl(S->getOperatorNew());
760 VisitDecl(S->getOperatorDelete());
761 VisitDecl(S->getConstructor());
762 ID.AddBoolean(S->isArray());
763 ID.AddInteger(S->getNumPlacementArgs());
764 ID.AddBoolean(S->isGlobalNew());
765 ID.AddBoolean(S->isParenTypeId());
766 ID.AddBoolean(S->hasInitializer());
767 ID.AddInteger(S->getNumConstructorArgs());
768}
769
Douglas Gregora71d8192009-09-04 17:36:40 +0000770void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
771 VisitExpr(S);
772 ID.AddBoolean(S->isArrow());
773 VisitNestedNameSpecifier(S->getQualifier());
774 VisitType(S->getDestroyedType());
775}
776
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000777void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000778 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000779 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000780 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000781 ID.AddBoolean(S->hasExplicitTemplateArgs());
782 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000783 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
784 S->getExplicitTemplateArgs().NumTemplateArgs);
785}
786
787void
788StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
789 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000790}
791
792void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
793 VisitExpr(S);
794 ID.AddInteger(S->getTrait());
795 VisitType(S->getQueriedType());
796}
797
Francois Pichet6ad6f282010-12-07 00:08:36 +0000798void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
799 VisitExpr(S);
800 ID.AddInteger(S->getTrait());
801 VisitType(S->getLhsType());
802 VisitType(S->getRhsType());
803}
804
John Wiegley21ff2e52011-04-28 00:16:57 +0000805void StmtProfiler::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *S) {
806 VisitExpr(S);
807 ID.AddInteger(S->getTrait());
808 VisitType(S->getQueriedType());
809}
810
John Wiegley55262202011-04-25 06:54:41 +0000811void StmtProfiler::VisitExpressionTraitExpr(ExpressionTraitExpr *S) {
812 VisitExpr(S);
813 ID.AddInteger(S->getTrait());
814 VisitExpr(S->getQueriedExpression());
815}
816
John McCall865d4472009-11-19 22:55:06 +0000817void
818StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000819 VisitExpr(S);
820 VisitName(S->getDeclName());
821 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000822 ID.AddBoolean(S->hasExplicitTemplateArgs());
823 if (S->hasExplicitTemplateArgs())
824 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000825}
826
John McCall4765fa02010-12-06 08:20:24 +0000827void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000828 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000829}
830
Mike Stump1eb44332009-09-09 15:08:12 +0000831void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000832StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
833 VisitExpr(S);
834 VisitType(S->getTypeAsWritten());
835}
836
John McCall865d4472009-11-19 22:55:06 +0000837void
838StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000839 ID.AddBoolean(S->isImplicitAccess());
840 if (!S->isImplicitAccess()) {
841 VisitExpr(S);
842 ID.AddBoolean(S->isArrow());
843 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000844 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000845 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000846 ID.AddBoolean(S->hasExplicitTemplateArgs());
847 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000848 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
849}
850
851void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000852 ID.AddBoolean(S->isImplicitAccess());
853 if (!S->isImplicitAccess()) {
854 VisitExpr(S);
855 ID.AddBoolean(S->isArrow());
856 }
John McCall129e2df2009-11-30 22:42:35 +0000857 VisitNestedNameSpecifier(S->getQualifier());
858 VisitName(S->getMemberName());
859 ID.AddBoolean(S->hasExplicitTemplateArgs());
860 if (S->hasExplicitTemplateArgs())
861 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000862}
863
Sebastian Redl2e156222010-09-10 20:55:43 +0000864void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
865 VisitExpr(S);
866}
867
Douglas Gregorbe230c32011-01-03 17:17:50 +0000868void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
869 VisitExpr(S);
870}
871
Douglas Gregoree8aff02011-01-04 17:33:58 +0000872void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
873 VisitExpr(S);
874 VisitDecl(S->getPack());
875}
876
Douglas Gregorc7793c72011-01-15 01:15:58 +0000877void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
878 SubstNonTypeTemplateParmPackExpr *S) {
879 VisitExpr(S);
880 VisitDecl(S->getParameterPack());
881 VisitTemplateArgument(S->getArgumentPack());
882}
883
John McCall7cd7d1a2010-11-15 23:31:06 +0000884void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
885 VisitExpr(E);
886}
887
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000888void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
889 VisitExpr(S);
890}
891
892void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
893 VisitExpr(S);
894 VisitType(S->getEncodedType());
895}
896
897void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
898 VisitExpr(S);
899 VisitName(S->getSelector());
900}
901
902void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
903 VisitExpr(S);
904 VisitDecl(S->getProtocol());
905}
906
907void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
908 VisitExpr(S);
909 VisitDecl(S->getDecl());
910 ID.AddBoolean(S->isArrow());
911 ID.AddBoolean(S->isFreeIvar());
912}
913
914void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
915 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +0000916 if (S->isImplicitProperty()) {
917 VisitDecl(S->getImplicitPropertyGetter());
918 VisitDecl(S->getImplicitPropertySetter());
919 } else {
920 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000921 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000922 if (S->isSuperReceiver()) {
923 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +0000924 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000925 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000926}
927
928void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
929 VisitExpr(S);
930 VisitName(S->getSelector());
931 VisitDecl(S->getMethodDecl());
932}
933
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000934void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
935 VisitExpr(S);
936 ID.AddBoolean(S->isArrow());
937}
938
Douglas Gregord584eb22009-07-28 15:32:17 +0000939void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000940 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000941
Douglas Gregorb1975722009-07-30 23:18:24 +0000942 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000943 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000944 ID.AddInteger(NTTP->getDepth());
945 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000946 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +0000947 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000948 return;
949 }
Mike Stump1eb44332009-09-09 15:08:12 +0000950
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000951 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
952 // The Itanium C++ ABI uses the type of a parameter when mangling
953 // expressions that involve function parameters, so we will use the
954 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000955 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000956 // matches the definition of "equivalent" used for name mangling.
957 VisitType(Parm->getType());
958 return;
959 }
Mike Stump1eb44332009-09-09 15:08:12 +0000960
Douglas Gregora2ffb982009-07-31 15:46:56 +0000961 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
962 ID.AddInteger(TTP->getDepth());
963 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000964 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +0000965 return;
966 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000967 }
Mike Stump1eb44332009-09-09 15:08:12 +0000968
Douglas Gregord584eb22009-07-28 15:32:17 +0000969 ID.AddPointer(D? D->getCanonicalDecl() : 0);
970}
971
972void StmtProfiler::VisitType(QualType T) {
973 if (Canonical)
974 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000975
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000976 ID.AddPointer(T.getAsOpaquePtr());
977}
978
979void StmtProfiler::VisitName(DeclarationName Name) {
980 ID.AddPointer(Name.getAsOpaquePtr());
981}
982
983void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
984 if (Canonical)
985 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
986 ID.AddPointer(NNS);
987}
988
989void StmtProfiler::VisitTemplateName(TemplateName Name) {
990 if (Canonical)
991 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000992
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000993 Name.Profile(ID);
994}
995
John McCall833ca992009-10-29 08:12:44 +0000996void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000997 unsigned NumArgs) {
998 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000999 for (unsigned I = 0; I != NumArgs; ++I)
1000 VisitTemplateArgument(Args[I].getArgument());
1001}
Mike Stump1eb44332009-09-09 15:08:12 +00001002
John McCall833ca992009-10-29 08:12:44 +00001003void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1004 // Mostly repetitive with TemplateArgument::Profile!
1005 ID.AddInteger(Arg.getKind());
1006 switch (Arg.getKind()) {
1007 case TemplateArgument::Null:
1008 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001009
John McCall833ca992009-10-29 08:12:44 +00001010 case TemplateArgument::Type:
1011 VisitType(Arg.getAsType());
1012 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001013
Douglas Gregor788cd062009-11-11 01:00:40 +00001014 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00001015 case TemplateArgument::TemplateExpansion:
1016 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +00001017 break;
Sean Huntc3021132010-05-05 15:23:54 +00001018
John McCall833ca992009-10-29 08:12:44 +00001019 case TemplateArgument::Declaration:
1020 VisitDecl(Arg.getAsDecl());
1021 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001022
John McCall833ca992009-10-29 08:12:44 +00001023 case TemplateArgument::Integral:
1024 Arg.getAsIntegral()->Profile(ID);
1025 VisitType(Arg.getIntegralType());
1026 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001027
John McCall833ca992009-10-29 08:12:44 +00001028 case TemplateArgument::Expression:
1029 Visit(Arg.getAsExpr());
1030 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001031
John McCall833ca992009-10-29 08:12:44 +00001032 case TemplateArgument::Pack:
1033 const TemplateArgument *Pack = Arg.pack_begin();
1034 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1035 VisitTemplateArgument(Pack[i]);
1036 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001037 }
1038}
1039
Jay Foad4ba2a172011-01-12 09:06:06 +00001040void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001041 bool Canonical) {
1042 StmtProfiler Profiler(ID, Context, Canonical);
1043 Profiler.Visit(this);
1044}