blob: e75c274015c0e5f096125b40ce1df0e0fce052f1 [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());
Fariborz Jahanian89f9d3a2010-06-04 19:06:53 +0000428 if (S->getCopyConstructorExpr())
429 Visit(S->getCopyConstructorExpr());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000430}
431
Douglas Gregora89064a2010-05-19 04:13:23 +0000432static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000433 UnaryOperatorKind &UnaryOp,
434 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000435 switch (S->getOperator()) {
436 case OO_None:
437 case OO_New:
438 case OO_Delete:
439 case OO_Array_New:
440 case OO_Array_Delete:
441 case OO_Arrow:
442 case OO_Call:
443 case OO_Conditional:
444 case NUM_OVERLOADED_OPERATORS:
445 llvm_unreachable("Invalid operator call kind");
446 return Stmt::ArraySubscriptExprClass;
447
448 case OO_Plus:
449 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000450 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000451 return Stmt::UnaryOperatorClass;
452 }
453
John McCall2de56d12010-08-25 11:45:40 +0000454 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000455 return Stmt::BinaryOperatorClass;
456
457 case OO_Minus:
458 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000459 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000460 return Stmt::UnaryOperatorClass;
461 }
462
John McCall2de56d12010-08-25 11:45:40 +0000463 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000464 return Stmt::BinaryOperatorClass;
465
466 case OO_Star:
467 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000468 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000469 return Stmt::UnaryOperatorClass;
470 }
471
John McCall2de56d12010-08-25 11:45:40 +0000472 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000473 return Stmt::BinaryOperatorClass;
474
475 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000476 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000477 return Stmt::BinaryOperatorClass;
478
479 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000480 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000481 return Stmt::BinaryOperatorClass;
482
483 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000484 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000485 return Stmt::BinaryOperatorClass;
486
487 case OO_Amp:
488 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000489 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000490 return Stmt::UnaryOperatorClass;
491 }
492
John McCall2de56d12010-08-25 11:45:40 +0000493 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000494 return Stmt::BinaryOperatorClass;
495
496 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000497 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000498 return Stmt::BinaryOperatorClass;
499
500 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000501 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000502 return Stmt::UnaryOperatorClass;
503
504 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000505 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000506 return Stmt::UnaryOperatorClass;
507
508 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000509 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000510 return Stmt::BinaryOperatorClass;
511
512 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000513 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000514 return Stmt::BinaryOperatorClass;
515
516 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000517 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000518 return Stmt::BinaryOperatorClass;
519
520 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000521 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000522 return Stmt::CompoundAssignOperatorClass;
523
524 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000525 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000526 return Stmt::CompoundAssignOperatorClass;
527
528 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000529 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000530 return Stmt::CompoundAssignOperatorClass;
531
532 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000533 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000534 return Stmt::CompoundAssignOperatorClass;
535
536 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000537 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000538 return Stmt::CompoundAssignOperatorClass;
539
540 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000541 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000542 return Stmt::CompoundAssignOperatorClass;
543
544 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000545 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000546 return Stmt::CompoundAssignOperatorClass;
547
548 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000549 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000550 return Stmt::CompoundAssignOperatorClass;
551
552 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000553 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000554 return Stmt::BinaryOperatorClass;
555
556 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000557 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000558 return Stmt::BinaryOperatorClass;
559
560 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000561 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000562 return Stmt::CompoundAssignOperatorClass;
563
564 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000565 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000566 return Stmt::CompoundAssignOperatorClass;
567
568 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000569 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000570 return Stmt::BinaryOperatorClass;
571
572 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000573 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000574 return Stmt::BinaryOperatorClass;
575
576 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000577 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000578 return Stmt::BinaryOperatorClass;
579
580 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000581 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000582 return Stmt::BinaryOperatorClass;
583
584 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000585 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000586 return Stmt::BinaryOperatorClass;
587
588 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000589 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000590 return Stmt::BinaryOperatorClass;
591
592 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000593 UnaryOp = S->getNumArgs() == 1? UO_PreInc
594 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000595 return Stmt::UnaryOperatorClass;
596
597 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000598 UnaryOp = S->getNumArgs() == 1? UO_PreDec
599 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000600 return Stmt::UnaryOperatorClass;
601
602 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000603 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000604 return Stmt::BinaryOperatorClass;
605
606
607 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000608 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000609 return Stmt::BinaryOperatorClass;
610
611 case OO_Subscript:
612 return Stmt::ArraySubscriptExprClass;
613 }
614
615 llvm_unreachable("Invalid overloaded operator expression");
616}
617
618
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000619void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000620 if (S->isTypeDependent()) {
621 // Type-dependent operator calls are profiled like their underlying
622 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000623 UnaryOperatorKind UnaryOp = UO_Extension;
624 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000625 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
626
627 ID.AddInteger(SC);
628 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
629 Visit(S->getArg(I));
630 if (SC == Stmt::UnaryOperatorClass)
631 ID.AddInteger(UnaryOp);
632 else if (SC == Stmt::BinaryOperatorClass ||
633 SC == Stmt::CompoundAssignOperatorClass)
634 ID.AddInteger(BinaryOp);
635 else
636 assert(SC == Stmt::ArraySubscriptExprClass);
637
638 return;
639 }
640
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000641 VisitCallExpr(S);
642 ID.AddInteger(S->getOperator());
643}
644
645void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
646 VisitCallExpr(S);
647}
648
649void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
650 VisitExplicitCastExpr(S);
651}
652
653void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
654 VisitCXXNamedCastExpr(S);
655}
656
657void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
658 VisitCXXNamedCastExpr(S);
659}
660
661void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
662 VisitCXXNamedCastExpr(S);
663}
664
665void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
666 VisitCXXNamedCastExpr(S);
667}
668
669void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
670 VisitExpr(S);
671 ID.AddBoolean(S->getValue());
672}
673
Douglas Gregor828e2262009-07-29 16:09:57 +0000674void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
675 VisitExpr(S);
676}
677
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000678void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
679 VisitExpr(S);
680 if (S->isTypeOperand())
681 VisitType(S->getTypeOperand());
682}
683
Francois Pichet01b7c302010-09-08 12:20:18 +0000684void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
685 VisitExpr(S);
686 if (S->isTypeOperand())
687 VisitType(S->getTypeOperand());
688}
689
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000690void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
691 VisitExpr(S);
692}
693
694void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
695 VisitExpr(S);
696}
697
698void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
699 VisitExpr(S);
700 VisitDecl(S->getParam());
701}
702
703void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
704 VisitExpr(S);
705 VisitDecl(
706 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
707}
708
709void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
710 VisitExpr(S);
711 VisitDecl(S->getConstructor());
712 ID.AddBoolean(S->isElidable());
713}
714
715void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
716 VisitExplicitCastExpr(S);
717}
718
719void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
720 VisitCXXConstructExpr(S);
721}
722
Douglas Gregored8abf12010-07-08 06:14:04 +0000723void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000724 VisitExpr(S);
725}
726
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000727void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
728 VisitExpr(S);
729 ID.AddBoolean(S->isGlobalDelete());
730 ID.AddBoolean(S->isArrayForm());
731 VisitDecl(S->getOperatorDelete());
732}
733
734
735void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
736 VisitExpr(S);
737 VisitType(S->getAllocatedType());
738 VisitDecl(S->getOperatorNew());
739 VisitDecl(S->getOperatorDelete());
740 VisitDecl(S->getConstructor());
741 ID.AddBoolean(S->isArray());
742 ID.AddInteger(S->getNumPlacementArgs());
743 ID.AddBoolean(S->isGlobalNew());
744 ID.AddBoolean(S->isParenTypeId());
745 ID.AddBoolean(S->hasInitializer());
746 ID.AddInteger(S->getNumConstructorArgs());
747}
748
Douglas Gregora71d8192009-09-04 17:36:40 +0000749void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
750 VisitExpr(S);
751 ID.AddBoolean(S->isArrow());
752 VisitNestedNameSpecifier(S->getQualifier());
753 VisitType(S->getDestroyedType());
754}
755
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000756void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000757 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000758 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000759 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000760 ID.AddBoolean(S->hasExplicitTemplateArgs());
761 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000762 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
763 S->getExplicitTemplateArgs().NumTemplateArgs);
764}
765
766void
767StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
768 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000769}
770
771void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
772 VisitExpr(S);
773 ID.AddInteger(S->getTrait());
774 VisitType(S->getQueriedType());
775}
776
Francois Pichet6ad6f282010-12-07 00:08:36 +0000777void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
778 VisitExpr(S);
779 ID.AddInteger(S->getTrait());
780 VisitType(S->getLhsType());
781 VisitType(S->getRhsType());
782}
783
John McCall865d4472009-11-19 22:55:06 +0000784void
785StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000786 VisitExpr(S);
787 VisitName(S->getDeclName());
788 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000789 ID.AddBoolean(S->hasExplicitTemplateArgs());
790 if (S->hasExplicitTemplateArgs())
791 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000792}
793
John McCall4765fa02010-12-06 08:20:24 +0000794void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000795 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000796}
797
Mike Stump1eb44332009-09-09 15:08:12 +0000798void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000799StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
800 VisitExpr(S);
801 VisitType(S->getTypeAsWritten());
802}
803
John McCall865d4472009-11-19 22:55:06 +0000804void
805StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000806 ID.AddBoolean(S->isImplicitAccess());
807 if (!S->isImplicitAccess()) {
808 VisitExpr(S);
809 ID.AddBoolean(S->isArrow());
810 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000811 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000812 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000813 ID.AddBoolean(S->hasExplicitTemplateArgs());
814 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000815 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
816}
817
818void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000819 ID.AddBoolean(S->isImplicitAccess());
820 if (!S->isImplicitAccess()) {
821 VisitExpr(S);
822 ID.AddBoolean(S->isArrow());
823 }
John McCall129e2df2009-11-30 22:42:35 +0000824 VisitNestedNameSpecifier(S->getQualifier());
825 VisitName(S->getMemberName());
826 ID.AddBoolean(S->hasExplicitTemplateArgs());
827 if (S->hasExplicitTemplateArgs())
828 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000829}
830
Sebastian Redl2e156222010-09-10 20:55:43 +0000831void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
832 VisitExpr(S);
833}
834
Douglas Gregorbe230c32011-01-03 17:17:50 +0000835void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
836 VisitExpr(S);
837}
838
Douglas Gregoree8aff02011-01-04 17:33:58 +0000839void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
840 VisitExpr(S);
841 VisitDecl(S->getPack());
842}
843
Douglas Gregorc7793c72011-01-15 01:15:58 +0000844void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
845 SubstNonTypeTemplateParmPackExpr *S) {
846 VisitExpr(S);
847 VisitDecl(S->getParameterPack());
848 VisitTemplateArgument(S->getArgumentPack());
849}
850
John McCall7cd7d1a2010-11-15 23:31:06 +0000851void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
852 VisitExpr(E);
853}
854
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000855void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
856 VisitExpr(S);
857}
858
859void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
860 VisitExpr(S);
861 VisitType(S->getEncodedType());
862}
863
864void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
865 VisitExpr(S);
866 VisitName(S->getSelector());
867}
868
869void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
870 VisitExpr(S);
871 VisitDecl(S->getProtocol());
872}
873
874void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
875 VisitExpr(S);
876 VisitDecl(S->getDecl());
877 ID.AddBoolean(S->isArrow());
878 ID.AddBoolean(S->isFreeIvar());
879}
880
881void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
882 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +0000883 if (S->isImplicitProperty()) {
884 VisitDecl(S->getImplicitPropertyGetter());
885 VisitDecl(S->getImplicitPropertySetter());
886 } else {
887 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000888 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000889 if (S->isSuperReceiver()) {
890 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +0000891 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000892 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000893}
894
895void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
896 VisitExpr(S);
897 VisitName(S->getSelector());
898 VisitDecl(S->getMethodDecl());
899}
900
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000901void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
902 VisitExpr(S);
903 ID.AddBoolean(S->isArrow());
904}
905
Douglas Gregord584eb22009-07-28 15:32:17 +0000906void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000907 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000908
Douglas Gregorb1975722009-07-30 23:18:24 +0000909 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000910 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000911 ID.AddInteger(NTTP->getDepth());
912 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000913 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +0000914 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000915 return;
916 }
Mike Stump1eb44332009-09-09 15:08:12 +0000917
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000918 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
919 // The Itanium C++ ABI uses the type of a parameter when mangling
920 // expressions that involve function parameters, so we will use the
921 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000922 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000923 // matches the definition of "equivalent" used for name mangling.
924 VisitType(Parm->getType());
925 return;
926 }
Mike Stump1eb44332009-09-09 15:08:12 +0000927
Douglas Gregora2ffb982009-07-31 15:46:56 +0000928 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
929 ID.AddInteger(TTP->getDepth());
930 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000931 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +0000932 return;
933 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000934 }
Mike Stump1eb44332009-09-09 15:08:12 +0000935
Douglas Gregord584eb22009-07-28 15:32:17 +0000936 ID.AddPointer(D? D->getCanonicalDecl() : 0);
937}
938
939void StmtProfiler::VisitType(QualType T) {
940 if (Canonical)
941 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000942
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000943 ID.AddPointer(T.getAsOpaquePtr());
944}
945
946void StmtProfiler::VisitName(DeclarationName Name) {
947 ID.AddPointer(Name.getAsOpaquePtr());
948}
949
950void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
951 if (Canonical)
952 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
953 ID.AddPointer(NNS);
954}
955
956void StmtProfiler::VisitTemplateName(TemplateName Name) {
957 if (Canonical)
958 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000959
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000960 Name.Profile(ID);
961}
962
John McCall833ca992009-10-29 08:12:44 +0000963void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000964 unsigned NumArgs) {
965 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000966 for (unsigned I = 0; I != NumArgs; ++I)
967 VisitTemplateArgument(Args[I].getArgument());
968}
Mike Stump1eb44332009-09-09 15:08:12 +0000969
John McCall833ca992009-10-29 08:12:44 +0000970void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
971 // Mostly repetitive with TemplateArgument::Profile!
972 ID.AddInteger(Arg.getKind());
973 switch (Arg.getKind()) {
974 case TemplateArgument::Null:
975 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000976
John McCall833ca992009-10-29 08:12:44 +0000977 case TemplateArgument::Type:
978 VisitType(Arg.getAsType());
979 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000980
Douglas Gregor788cd062009-11-11 01:00:40 +0000981 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +0000982 case TemplateArgument::TemplateExpansion:
983 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +0000984 break;
Sean Huntc3021132010-05-05 15:23:54 +0000985
John McCall833ca992009-10-29 08:12:44 +0000986 case TemplateArgument::Declaration:
987 VisitDecl(Arg.getAsDecl());
988 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000989
John McCall833ca992009-10-29 08:12:44 +0000990 case TemplateArgument::Integral:
991 Arg.getAsIntegral()->Profile(ID);
992 VisitType(Arg.getIntegralType());
993 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000994
John McCall833ca992009-10-29 08:12:44 +0000995 case TemplateArgument::Expression:
996 Visit(Arg.getAsExpr());
997 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000998
John McCall833ca992009-10-29 08:12:44 +0000999 case TemplateArgument::Pack:
1000 const TemplateArgument *Pack = Arg.pack_begin();
1001 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1002 VisitTemplateArgument(Pack[i]);
1003 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001004 }
1005}
1006
Jay Foad4ba2a172011-01-12 09:06:06 +00001007void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001008 bool Canonical) {
1009 StmtProfiler Profiler(ID, Context, Canonical);
1010 Profiler.Visit(this);
1011}