blob: 707cac4edfe915fcdb4d98705f2c2b90b945f622 [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());
71 for (Stmt::child_iterator C = S->child_begin(), CEnd = S->child_end();
72 C != CEnd; ++C)
73 Visit(*C);
74}
75
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000076void StmtProfiler::VisitDeclStmt(DeclStmt *S) {
77 VisitStmt(S);
78 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
79 D != DEnd; ++D)
80 VisitDecl(*D);
81}
82
83void StmtProfiler::VisitNullStmt(NullStmt *S) {
84 VisitStmt(S);
85}
86
87void StmtProfiler::VisitCompoundStmt(CompoundStmt *S) {
88 VisitStmt(S);
89}
90
91void StmtProfiler::VisitSwitchCase(SwitchCase *S) {
92 VisitStmt(S);
93}
94
95void StmtProfiler::VisitCaseStmt(CaseStmt *S) {
96 VisitStmt(S);
97}
98
99void StmtProfiler::VisitDefaultStmt(DefaultStmt *S) {
100 VisitStmt(S);
101}
102
103void StmtProfiler::VisitLabelStmt(LabelStmt *S) {
104 VisitStmt(S);
105 VisitName(S->getID());
106}
107
108void StmtProfiler::VisitIfStmt(IfStmt *S) {
109 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000110 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000111}
112
Douglas Gregor828e2262009-07-29 16:09:57 +0000113void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
114 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000115 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000116}
117
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000118void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
119 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000120 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000121}
122
123void StmtProfiler::VisitDoStmt(DoStmt *S) {
124 VisitStmt(S);
125}
126
127void StmtProfiler::VisitForStmt(ForStmt *S) {
128 VisitStmt(S);
129}
130
131void StmtProfiler::VisitGotoStmt(GotoStmt *S) {
132 VisitStmt(S);
133 VisitName(S->getLabel()->getID());
134}
135
136void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
137 VisitStmt(S);
138}
139
140void StmtProfiler::VisitContinueStmt(ContinueStmt *S) {
141 VisitStmt(S);
142}
143
144void StmtProfiler::VisitBreakStmt(BreakStmt *S) {
145 VisitStmt(S);
146}
147
148void StmtProfiler::VisitReturnStmt(ReturnStmt *S) {
149 VisitStmt(S);
150}
151
152void StmtProfiler::VisitAsmStmt(AsmStmt *S) {
153 VisitStmt(S);
154 ID.AddBoolean(S->isVolatile());
155 ID.AddBoolean(S->isSimple());
156 VisitStringLiteral(S->getAsmString());
157 ID.AddInteger(S->getNumOutputs());
158 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
159 ID.AddString(S->getOutputName(I));
160 VisitStringLiteral(S->getOutputConstraintLiteral(I));
161 }
162 ID.AddInteger(S->getNumInputs());
163 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
164 ID.AddString(S->getInputName(I));
165 VisitStringLiteral(S->getInputConstraintLiteral(I));
166 }
167 ID.AddInteger(S->getNumClobbers());
168 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
169 VisitStringLiteral(S->getClobber(I));
170}
171
172void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) {
173 VisitStmt(S);
174 VisitType(S->getCaughtType());
175}
176
177void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) {
178 VisitStmt(S);
179}
180
181void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
182 VisitStmt(S);
183}
184
185void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
186 VisitStmt(S);
187 ID.AddBoolean(S->hasEllipsis());
188 if (S->getCatchParamDecl())
189 VisitType(S->getCatchParamDecl()->getType());
190}
191
192void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
193 VisitStmt(S);
194}
195
196void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
197 VisitStmt(S);
198}
199
200void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
201 VisitStmt(S);
202}
203
204void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
205 VisitStmt(S);
206}
207
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000208void StmtProfiler::VisitExpr(Expr *S) {
209 VisitStmt(S);
210}
211
212void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
213 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000214 if (!Canonical)
215 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000216 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000217 if (!Canonical)
218 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000219}
220
221void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
222 VisitExpr(S);
223 ID.AddInteger(S->getIdentType());
224}
225
226void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
227 VisitExpr(S);
228 S->getValue().Profile(ID);
229}
230
231void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
232 VisitExpr(S);
233 ID.AddBoolean(S->isWide());
234 ID.AddInteger(S->getValue());
235}
236
237void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
238 VisitExpr(S);
239 S->getValue().Profile(ID);
240 ID.AddBoolean(S->isExact());
241}
242
243void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
244 VisitExpr(S);
245}
246
247void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
248 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000249 ID.AddString(S->getString());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000250 ID.AddBoolean(S->isWide());
251}
252
253void StmtProfiler::VisitParenExpr(ParenExpr *S) {
254 VisitExpr(S);
255}
256
Nate Begeman2ef13e52009-08-10 23:49:36 +0000257void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
258 VisitExpr(S);
259}
260
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000261void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
262 VisitExpr(S);
263 ID.AddInteger(S->getOpcode());
264}
265
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000266void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
267 VisitType(S->getTypeSourceInfo()->getType());
268 unsigned n = S->getNumComponents();
269 for (unsigned i = 0; i < n; ++i) {
270 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
271 ID.AddInteger(ON.getKind());
272 switch (ON.getKind()) {
273 case OffsetOfExpr::OffsetOfNode::Array:
274 // Expressions handled below.
275 break;
276
277 case OffsetOfExpr::OffsetOfNode::Field:
278 VisitDecl(ON.getField());
279 break;
280
281 case OffsetOfExpr::OffsetOfNode::Identifier:
282 ID.AddPointer(ON.getFieldName());
283 break;
Sean Huntc3021132010-05-05 15:23:54 +0000284
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000285 case OffsetOfExpr::OffsetOfNode::Base:
286 // These nodes are implicit, and therefore don't need profiling.
287 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000288 }
289 }
Sean Huntc3021132010-05-05 15:23:54 +0000290
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000291 VisitExpr(S);
292}
293
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000294void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
295 VisitExpr(S);
296 ID.AddBoolean(S->isSizeOf());
297 if (S->isArgumentType())
298 VisitType(S->getArgumentType());
299}
300
301void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
302 VisitExpr(S);
303}
304
305void StmtProfiler::VisitCallExpr(CallExpr *S) {
306 VisitExpr(S);
307}
308
309void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
310 VisitExpr(S);
311 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000312 if (!Canonical)
313 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000314 ID.AddBoolean(S->isArrow());
315}
316
317void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
318 VisitExpr(S);
319 ID.AddBoolean(S->isFileScope());
320}
321
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000322void StmtProfiler::VisitCastExpr(CastExpr *S) {
323 VisitExpr(S);
324}
325
326void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
327 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000328 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000329}
330
331void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
332 VisitCastExpr(S);
333 VisitType(S->getTypeAsWritten());
334}
335
336void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
337 VisitExplicitCastExpr(S);
338}
339
340void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
341 VisitExpr(S);
342 ID.AddInteger(S->getOpcode());
343}
344
345void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
346 VisitBinaryOperator(S);
347}
348
349void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
350 VisitExpr(S);
351}
352
353void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
354 VisitExpr(S);
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000355 VisitName(S->getLabel()->getID());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000356}
357
358void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
359 VisitExpr(S);
360}
361
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000362void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
363 VisitExpr(S);
364}
365
366void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
367 VisitExpr(S);
368}
369
370void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
371 VisitExpr(S);
372}
373
Douglas Gregor828e2262009-07-29 16:09:57 +0000374void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
375 VisitExpr(S);
376}
377
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000378void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
379 if (S->getSyntacticForm()) {
380 VisitInitListExpr(S->getSyntacticForm());
381 return;
382 }
Mike Stump1eb44332009-09-09 15:08:12 +0000383
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000384 VisitExpr(S);
385}
386
387void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
388 VisitExpr(S);
389 ID.AddBoolean(S->usesGNUSyntax());
390 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
391 DEnd = S->designators_end();
392 D != DEnd; ++D) {
393 if (D->isFieldDesignator()) {
394 ID.AddInteger(0);
395 VisitName(D->getFieldName());
396 continue;
397 }
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000399 if (D->isArrayDesignator()) {
400 ID.AddInteger(1);
401 } else {
402 assert(D->isArrayRangeDesignator());
403 ID.AddInteger(2);
404 }
405 ID.AddInteger(D->getFirstExprIndex());
406 }
407}
408
409void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
410 VisitExpr(S);
411}
412
413void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
414 VisitExpr(S);
415 VisitName(&S->getAccessor());
416}
417
418void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
419 VisitExpr(S);
420 VisitDecl(S->getBlockDecl());
421}
422
423void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
424 VisitExpr(S);
425 VisitDecl(S->getDecl());
426 ID.AddBoolean(S->isByRef());
427 ID.AddBoolean(S->isConstQualAdded());
428}
429
Douglas Gregora89064a2010-05-19 04:13:23 +0000430static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000431 UnaryOperatorKind &UnaryOp,
432 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000433 switch (S->getOperator()) {
434 case OO_None:
435 case OO_New:
436 case OO_Delete:
437 case OO_Array_New:
438 case OO_Array_Delete:
439 case OO_Arrow:
440 case OO_Call:
441 case OO_Conditional:
442 case NUM_OVERLOADED_OPERATORS:
443 llvm_unreachable("Invalid operator call kind");
444 return Stmt::ArraySubscriptExprClass;
445
446 case OO_Plus:
447 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000448 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000449 return Stmt::UnaryOperatorClass;
450 }
451
John McCall2de56d12010-08-25 11:45:40 +0000452 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000453 return Stmt::BinaryOperatorClass;
454
455 case OO_Minus:
456 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000457 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000458 return Stmt::UnaryOperatorClass;
459 }
460
John McCall2de56d12010-08-25 11:45:40 +0000461 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000462 return Stmt::BinaryOperatorClass;
463
464 case OO_Star:
465 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000466 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000467 return Stmt::UnaryOperatorClass;
468 }
469
John McCall2de56d12010-08-25 11:45:40 +0000470 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000471 return Stmt::BinaryOperatorClass;
472
473 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000474 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000475 return Stmt::BinaryOperatorClass;
476
477 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000478 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000479 return Stmt::BinaryOperatorClass;
480
481 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000482 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000483 return Stmt::BinaryOperatorClass;
484
485 case OO_Amp:
486 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000487 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000488 return Stmt::UnaryOperatorClass;
489 }
490
John McCall2de56d12010-08-25 11:45:40 +0000491 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000492 return Stmt::BinaryOperatorClass;
493
494 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000495 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000496 return Stmt::BinaryOperatorClass;
497
498 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000499 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000500 return Stmt::UnaryOperatorClass;
501
502 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000503 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000504 return Stmt::UnaryOperatorClass;
505
506 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000507 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000508 return Stmt::BinaryOperatorClass;
509
510 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000511 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000512 return Stmt::BinaryOperatorClass;
513
514 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000515 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000516 return Stmt::BinaryOperatorClass;
517
518 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000519 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000520 return Stmt::CompoundAssignOperatorClass;
521
522 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000523 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000524 return Stmt::CompoundAssignOperatorClass;
525
526 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000527 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000528 return Stmt::CompoundAssignOperatorClass;
529
530 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000531 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000532 return Stmt::CompoundAssignOperatorClass;
533
534 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000535 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000536 return Stmt::CompoundAssignOperatorClass;
537
538 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000539 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000540 return Stmt::CompoundAssignOperatorClass;
541
542 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000543 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000544 return Stmt::CompoundAssignOperatorClass;
545
546 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000547 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000548 return Stmt::CompoundAssignOperatorClass;
549
550 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000551 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000552 return Stmt::BinaryOperatorClass;
553
554 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000555 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000556 return Stmt::BinaryOperatorClass;
557
558 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000559 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000560 return Stmt::CompoundAssignOperatorClass;
561
562 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000563 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000564 return Stmt::CompoundAssignOperatorClass;
565
566 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000567 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000568 return Stmt::BinaryOperatorClass;
569
570 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000571 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000572 return Stmt::BinaryOperatorClass;
573
574 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000575 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000576 return Stmt::BinaryOperatorClass;
577
578 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000579 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000580 return Stmt::BinaryOperatorClass;
581
582 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000583 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000584 return Stmt::BinaryOperatorClass;
585
586 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000587 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000588 return Stmt::BinaryOperatorClass;
589
590 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000591 UnaryOp = S->getNumArgs() == 1? UO_PreInc
592 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000593 return Stmt::UnaryOperatorClass;
594
595 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000596 UnaryOp = S->getNumArgs() == 1? UO_PreDec
597 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000598 return Stmt::UnaryOperatorClass;
599
600 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000601 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000602 return Stmt::BinaryOperatorClass;
603
604
605 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000606 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000607 return Stmt::BinaryOperatorClass;
608
609 case OO_Subscript:
610 return Stmt::ArraySubscriptExprClass;
611 }
612
613 llvm_unreachable("Invalid overloaded operator expression");
614}
615
616
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000617void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000618 if (S->isTypeDependent()) {
619 // Type-dependent operator calls are profiled like their underlying
620 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000621 UnaryOperatorKind UnaryOp = UO_Extension;
622 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000623 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
624
625 ID.AddInteger(SC);
626 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
627 Visit(S->getArg(I));
628 if (SC == Stmt::UnaryOperatorClass)
629 ID.AddInteger(UnaryOp);
630 else if (SC == Stmt::BinaryOperatorClass ||
631 SC == Stmt::CompoundAssignOperatorClass)
632 ID.AddInteger(BinaryOp);
633 else
634 assert(SC == Stmt::ArraySubscriptExprClass);
635
636 return;
637 }
638
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000639 VisitCallExpr(S);
640 ID.AddInteger(S->getOperator());
641}
642
643void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
644 VisitCallExpr(S);
645}
646
Peter Collingbournee08ce652011-02-09 21:07:24 +0000647void StmtProfiler::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *S) {
648 VisitCallExpr(S);
649}
650
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000651void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
652 VisitExplicitCastExpr(S);
653}
654
655void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
656 VisitCXXNamedCastExpr(S);
657}
658
659void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
660 VisitCXXNamedCastExpr(S);
661}
662
663void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
664 VisitCXXNamedCastExpr(S);
665}
666
667void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
668 VisitCXXNamedCastExpr(S);
669}
670
671void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
672 VisitExpr(S);
673 ID.AddBoolean(S->getValue());
674}
675
Douglas Gregor828e2262009-07-29 16:09:57 +0000676void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
677 VisitExpr(S);
678}
679
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000680void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
681 VisitExpr(S);
682 if (S->isTypeOperand())
683 VisitType(S->getTypeOperand());
684}
685
Francois Pichet01b7c302010-09-08 12:20:18 +0000686void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
687 VisitExpr(S);
688 if (S->isTypeOperand())
689 VisitType(S->getTypeOperand());
690}
691
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000692void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
693 VisitExpr(S);
694}
695
696void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
697 VisitExpr(S);
698}
699
700void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
701 VisitExpr(S);
702 VisitDecl(S->getParam());
703}
704
705void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
706 VisitExpr(S);
707 VisitDecl(
708 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
709}
710
711void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
712 VisitExpr(S);
713 VisitDecl(S->getConstructor());
714 ID.AddBoolean(S->isElidable());
715}
716
717void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
718 VisitExplicitCastExpr(S);
719}
720
721void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
722 VisitCXXConstructExpr(S);
723}
724
Douglas Gregored8abf12010-07-08 06:14:04 +0000725void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000726 VisitExpr(S);
727}
728
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000729void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
730 VisitExpr(S);
731 ID.AddBoolean(S->isGlobalDelete());
732 ID.AddBoolean(S->isArrayForm());
733 VisitDecl(S->getOperatorDelete());
734}
735
736
737void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
738 VisitExpr(S);
739 VisitType(S->getAllocatedType());
740 VisitDecl(S->getOperatorNew());
741 VisitDecl(S->getOperatorDelete());
742 VisitDecl(S->getConstructor());
743 ID.AddBoolean(S->isArray());
744 ID.AddInteger(S->getNumPlacementArgs());
745 ID.AddBoolean(S->isGlobalNew());
746 ID.AddBoolean(S->isParenTypeId());
747 ID.AddBoolean(S->hasInitializer());
748 ID.AddInteger(S->getNumConstructorArgs());
749}
750
Douglas Gregora71d8192009-09-04 17:36:40 +0000751void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
752 VisitExpr(S);
753 ID.AddBoolean(S->isArrow());
754 VisitNestedNameSpecifier(S->getQualifier());
755 VisitType(S->getDestroyedType());
756}
757
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000758void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000759 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000760 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000761 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000762 ID.AddBoolean(S->hasExplicitTemplateArgs());
763 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000764 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
765 S->getExplicitTemplateArgs().NumTemplateArgs);
766}
767
768void
769StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
770 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000771}
772
773void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
774 VisitExpr(S);
775 ID.AddInteger(S->getTrait());
776 VisitType(S->getQueriedType());
777}
778
Francois Pichet6ad6f282010-12-07 00:08:36 +0000779void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
780 VisitExpr(S);
781 ID.AddInteger(S->getTrait());
782 VisitType(S->getLhsType());
783 VisitType(S->getRhsType());
784}
785
John McCall865d4472009-11-19 22:55:06 +0000786void
787StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000788 VisitExpr(S);
789 VisitName(S->getDeclName());
790 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000791 ID.AddBoolean(S->hasExplicitTemplateArgs());
792 if (S->hasExplicitTemplateArgs())
793 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000794}
795
John McCall4765fa02010-12-06 08:20:24 +0000796void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000797 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000798}
799
Mike Stump1eb44332009-09-09 15:08:12 +0000800void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000801StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
802 VisitExpr(S);
803 VisitType(S->getTypeAsWritten());
804}
805
John McCall865d4472009-11-19 22:55:06 +0000806void
807StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000808 ID.AddBoolean(S->isImplicitAccess());
809 if (!S->isImplicitAccess()) {
810 VisitExpr(S);
811 ID.AddBoolean(S->isArrow());
812 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000813 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000814 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000815 ID.AddBoolean(S->hasExplicitTemplateArgs());
816 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000817 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
818}
819
820void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000821 ID.AddBoolean(S->isImplicitAccess());
822 if (!S->isImplicitAccess()) {
823 VisitExpr(S);
824 ID.AddBoolean(S->isArrow());
825 }
John McCall129e2df2009-11-30 22:42:35 +0000826 VisitNestedNameSpecifier(S->getQualifier());
827 VisitName(S->getMemberName());
828 ID.AddBoolean(S->hasExplicitTemplateArgs());
829 if (S->hasExplicitTemplateArgs())
830 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000831}
832
Sebastian Redl2e156222010-09-10 20:55:43 +0000833void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
834 VisitExpr(S);
835}
836
Douglas Gregorbe230c32011-01-03 17:17:50 +0000837void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
838 VisitExpr(S);
839}
840
Douglas Gregoree8aff02011-01-04 17:33:58 +0000841void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
842 VisitExpr(S);
843 VisitDecl(S->getPack());
844}
845
Douglas Gregorc7793c72011-01-15 01:15:58 +0000846void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
847 SubstNonTypeTemplateParmPackExpr *S) {
848 VisitExpr(S);
849 VisitDecl(S->getParameterPack());
850 VisitTemplateArgument(S->getArgumentPack());
851}
852
John McCall7cd7d1a2010-11-15 23:31:06 +0000853void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
854 VisitExpr(E);
855}
856
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000857void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
858 VisitExpr(S);
859}
860
861void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
862 VisitExpr(S);
863 VisitType(S->getEncodedType());
864}
865
866void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
867 VisitExpr(S);
868 VisitName(S->getSelector());
869}
870
871void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
872 VisitExpr(S);
873 VisitDecl(S->getProtocol());
874}
875
876void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
877 VisitExpr(S);
878 VisitDecl(S->getDecl());
879 ID.AddBoolean(S->isArrow());
880 ID.AddBoolean(S->isFreeIvar());
881}
882
883void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
884 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +0000885 if (S->isImplicitProperty()) {
886 VisitDecl(S->getImplicitPropertyGetter());
887 VisitDecl(S->getImplicitPropertySetter());
888 } else {
889 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000890 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000891 if (S->isSuperReceiver()) {
892 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +0000893 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000894 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000895}
896
897void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
898 VisitExpr(S);
899 VisitName(S->getSelector());
900 VisitDecl(S->getMethodDecl());
901}
902
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000903void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
904 VisitExpr(S);
905 ID.AddBoolean(S->isArrow());
906}
907
Douglas Gregord584eb22009-07-28 15:32:17 +0000908void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000909 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000910
Douglas Gregorb1975722009-07-30 23:18:24 +0000911 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000912 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000913 ID.AddInteger(NTTP->getDepth());
914 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000915 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +0000916 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000917 return;
918 }
Mike Stump1eb44332009-09-09 15:08:12 +0000919
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000920 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
921 // The Itanium C++ ABI uses the type of a parameter when mangling
922 // expressions that involve function parameters, so we will use the
923 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000924 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000925 // matches the definition of "equivalent" used for name mangling.
926 VisitType(Parm->getType());
927 return;
928 }
Mike Stump1eb44332009-09-09 15:08:12 +0000929
Douglas Gregora2ffb982009-07-31 15:46:56 +0000930 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
931 ID.AddInteger(TTP->getDepth());
932 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000933 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +0000934 return;
935 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000936 }
Mike Stump1eb44332009-09-09 15:08:12 +0000937
Douglas Gregord584eb22009-07-28 15:32:17 +0000938 ID.AddPointer(D? D->getCanonicalDecl() : 0);
939}
940
941void StmtProfiler::VisitType(QualType T) {
942 if (Canonical)
943 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000944
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000945 ID.AddPointer(T.getAsOpaquePtr());
946}
947
948void StmtProfiler::VisitName(DeclarationName Name) {
949 ID.AddPointer(Name.getAsOpaquePtr());
950}
951
952void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
953 if (Canonical)
954 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
955 ID.AddPointer(NNS);
956}
957
958void StmtProfiler::VisitTemplateName(TemplateName Name) {
959 if (Canonical)
960 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000961
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000962 Name.Profile(ID);
963}
964
John McCall833ca992009-10-29 08:12:44 +0000965void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000966 unsigned NumArgs) {
967 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000968 for (unsigned I = 0; I != NumArgs; ++I)
969 VisitTemplateArgument(Args[I].getArgument());
970}
Mike Stump1eb44332009-09-09 15:08:12 +0000971
John McCall833ca992009-10-29 08:12:44 +0000972void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
973 // Mostly repetitive with TemplateArgument::Profile!
974 ID.AddInteger(Arg.getKind());
975 switch (Arg.getKind()) {
976 case TemplateArgument::Null:
977 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000978
John McCall833ca992009-10-29 08:12:44 +0000979 case TemplateArgument::Type:
980 VisitType(Arg.getAsType());
981 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000982
Douglas Gregor788cd062009-11-11 01:00:40 +0000983 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +0000984 case TemplateArgument::TemplateExpansion:
985 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +0000986 break;
Sean Huntc3021132010-05-05 15:23:54 +0000987
John McCall833ca992009-10-29 08:12:44 +0000988 case TemplateArgument::Declaration:
989 VisitDecl(Arg.getAsDecl());
990 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000991
John McCall833ca992009-10-29 08:12:44 +0000992 case TemplateArgument::Integral:
993 Arg.getAsIntegral()->Profile(ID);
994 VisitType(Arg.getIntegralType());
995 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000996
John McCall833ca992009-10-29 08:12:44 +0000997 case TemplateArgument::Expression:
998 Visit(Arg.getAsExpr());
999 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001000
John McCall833ca992009-10-29 08:12:44 +00001001 case TemplateArgument::Pack:
1002 const TemplateArgument *Pack = Arg.pack_begin();
1003 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1004 VisitTemplateArgument(Pack[i]);
1005 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001006 }
1007}
1008
Jay Foad4ba2a172011-01-12 09:06:06 +00001009void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001010 bool Canonical) {
1011 StmtProfiler Profiler(ID, Context, Canonical);
1012 Profiler.Visit(this);
1013}