blob: 2ffb807abcd2c84c0e0e3c45a5e9c17cff13f1f2 [file] [log] [blame]
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001//===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt::Profile method, which builds a unique bit
Douglas Gregor00aa3a62009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor41ef0c32009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregor071f4eb2009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000017#include "clang/AST/DeclTemplate.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/ExprCXX.h"
20#include "clang/AST/ExprObjC.h"
21#include "clang/AST/StmtVisitor.h"
22#include "llvm/ADT/FoldingSet.h"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000023using namespace clang;
24
25namespace {
Benjamin Kramer770b4a82009-11-28 19:03:38 +000026 class StmtProfiler : public StmtVisitor<StmtProfiler> {
Douglas Gregor41ef0c32009-07-28 00:33:38 +000027 llvm::FoldingSetNodeID &ID;
Jay Foad4ba2a172011-01-12 09:06:06 +000028 const ASTContext &Context;
Douglas Gregor41ef0c32009-07-28 00:33:38 +000029 bool Canonical;
Mike Stump1eb44332009-09-09 15:08:12 +000030
Douglas Gregor41ef0c32009-07-28 00:33:38 +000031 public:
Jay Foad4ba2a172011-01-12 09:06:06 +000032 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump1eb44332009-09-09 15:08:12 +000033 bool Canonical)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000034 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump1eb44332009-09-09 15:08:12 +000035
Douglas Gregor41ef0c32009-07-28 00:33:38 +000036 void VisitStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +000037
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000038#define STMT(Node, Base) void Visit##Node(Node *S);
Sean Hunt4bfe1962010-05-05 15:24:00 +000039#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +000040
Douglas Gregor41ef0c32009-07-28 00:33:38 +000041 /// \brief Visit a declaration that is referenced within an expression
42 /// or statement.
43 void VisitDecl(Decl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000044
45 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor41ef0c32009-07-28 00:33:38 +000046 /// statement.
47 void VisitType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +000048
Douglas Gregor41ef0c32009-07-28 00:33:38 +000049 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000051
Douglas Gregor41ef0c32009-07-28 00:33:38 +000052 /// \brief Visit a nested-name-specifier that occurs within an expression
53 /// or statement.
54 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump1eb44332009-09-09 15:08:12 +000055
Douglas Gregor41ef0c32009-07-28 00:33:38 +000056 /// \brief Visit a template name that occurs within an expression or
57 /// statement.
58 void VisitTemplateName(TemplateName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000059
Douglas Gregor41ef0c32009-07-28 00:33:38 +000060 /// \brief Visit template arguments that occur within an expression or
61 /// statement.
John McCall833ca992009-10-29 08:12:44 +000062 void VisitTemplateArguments(const TemplateArgumentLoc *Args, unsigned NumArgs);
63
64 /// \brief Visit a single template argument.
65 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor41ef0c32009-07-28 00:33:38 +000066 };
67}
68
69void StmtProfiler::VisitStmt(Stmt *S) {
70 ID.AddInteger(S->getStmtClass());
John McCall7502c1d2011-02-13 04:07:26 +000071 for (Stmt::child_range C = S->children(); C; ++C)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000072 Visit(*C);
73}
74
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000075void StmtProfiler::VisitDeclStmt(DeclStmt *S) {
76 VisitStmt(S);
77 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
78 D != DEnd; ++D)
79 VisitDecl(*D);
80}
81
82void StmtProfiler::VisitNullStmt(NullStmt *S) {
83 VisitStmt(S);
84}
85
86void StmtProfiler::VisitCompoundStmt(CompoundStmt *S) {
87 VisitStmt(S);
88}
89
90void StmtProfiler::VisitSwitchCase(SwitchCase *S) {
91 VisitStmt(S);
92}
93
94void StmtProfiler::VisitCaseStmt(CaseStmt *S) {
95 VisitStmt(S);
96}
97
98void StmtProfiler::VisitDefaultStmt(DefaultStmt *S) {
99 VisitStmt(S);
100}
101
102void StmtProfiler::VisitLabelStmt(LabelStmt *S) {
103 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000104 VisitDecl(S->getDecl());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000105}
106
107void StmtProfiler::VisitIfStmt(IfStmt *S) {
108 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000109 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000110}
111
Douglas Gregor828e2262009-07-29 16:09:57 +0000112void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
113 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000114 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000115}
116
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000117void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
118 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000119 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000120}
121
122void StmtProfiler::VisitDoStmt(DoStmt *S) {
123 VisitStmt(S);
124}
125
126void StmtProfiler::VisitForStmt(ForStmt *S) {
127 VisitStmt(S);
128}
129
130void StmtProfiler::VisitGotoStmt(GotoStmt *S) {
131 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000132 VisitDecl(S->getLabel());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000133}
134
135void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
136 VisitStmt(S);
137}
138
139void StmtProfiler::VisitContinueStmt(ContinueStmt *S) {
140 VisitStmt(S);
141}
142
143void StmtProfiler::VisitBreakStmt(BreakStmt *S) {
144 VisitStmt(S);
145}
146
147void StmtProfiler::VisitReturnStmt(ReturnStmt *S) {
148 VisitStmt(S);
149}
150
151void StmtProfiler::VisitAsmStmt(AsmStmt *S) {
152 VisitStmt(S);
153 ID.AddBoolean(S->isVolatile());
154 ID.AddBoolean(S->isSimple());
155 VisitStringLiteral(S->getAsmString());
156 ID.AddInteger(S->getNumOutputs());
157 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
158 ID.AddString(S->getOutputName(I));
159 VisitStringLiteral(S->getOutputConstraintLiteral(I));
160 }
161 ID.AddInteger(S->getNumInputs());
162 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
163 ID.AddString(S->getInputName(I));
164 VisitStringLiteral(S->getInputConstraintLiteral(I));
165 }
166 ID.AddInteger(S->getNumClobbers());
167 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
168 VisitStringLiteral(S->getClobber(I));
169}
170
171void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) {
172 VisitStmt(S);
173 VisitType(S->getCaughtType());
174}
175
176void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) {
177 VisitStmt(S);
178}
179
180void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
181 VisitStmt(S);
182}
183
184void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
185 VisitStmt(S);
186 ID.AddBoolean(S->hasEllipsis());
187 if (S->getCatchParamDecl())
188 VisitType(S->getCatchParamDecl()->getType());
189}
190
191void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
192 VisitStmt(S);
193}
194
195void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
196 VisitStmt(S);
197}
198
199void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
200 VisitStmt(S);
201}
202
203void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
204 VisitStmt(S);
205}
206
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000207void StmtProfiler::VisitExpr(Expr *S) {
208 VisitStmt(S);
209}
210
211void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
212 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000213 if (!Canonical)
214 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000215 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000216 if (!Canonical)
217 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000218}
219
220void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
221 VisitExpr(S);
222 ID.AddInteger(S->getIdentType());
223}
224
225void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
226 VisitExpr(S);
227 S->getValue().Profile(ID);
228}
229
230void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
231 VisitExpr(S);
232 ID.AddBoolean(S->isWide());
233 ID.AddInteger(S->getValue());
234}
235
236void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
237 VisitExpr(S);
238 S->getValue().Profile(ID);
239 ID.AddBoolean(S->isExact());
240}
241
242void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
243 VisitExpr(S);
244}
245
246void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
247 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000248 ID.AddString(S->getString());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000249 ID.AddBoolean(S->isWide());
250}
251
252void StmtProfiler::VisitParenExpr(ParenExpr *S) {
253 VisitExpr(S);
254}
255
Nate Begeman2ef13e52009-08-10 23:49:36 +0000256void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
257 VisitExpr(S);
258}
259
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000260void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
261 VisitExpr(S);
262 ID.AddInteger(S->getOpcode());
263}
264
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000265void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
266 VisitType(S->getTypeSourceInfo()->getType());
267 unsigned n = S->getNumComponents();
268 for (unsigned i = 0; i < n; ++i) {
269 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
270 ID.AddInteger(ON.getKind());
271 switch (ON.getKind()) {
272 case OffsetOfExpr::OffsetOfNode::Array:
273 // Expressions handled below.
274 break;
275
276 case OffsetOfExpr::OffsetOfNode::Field:
277 VisitDecl(ON.getField());
278 break;
279
280 case OffsetOfExpr::OffsetOfNode::Identifier:
281 ID.AddPointer(ON.getFieldName());
282 break;
Sean Huntc3021132010-05-05 15:23:54 +0000283
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000284 case OffsetOfExpr::OffsetOfNode::Base:
285 // These nodes are implicit, and therefore don't need profiling.
286 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000287 }
288 }
Sean Huntc3021132010-05-05 15:23:54 +0000289
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000290 VisitExpr(S);
291}
292
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000293void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
294 VisitExpr(S);
295 ID.AddBoolean(S->isSizeOf());
296 if (S->isArgumentType())
297 VisitType(S->getArgumentType());
298}
299
300void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
301 VisitExpr(S);
302}
303
304void StmtProfiler::VisitCallExpr(CallExpr *S) {
305 VisitExpr(S);
306}
307
308void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
309 VisitExpr(S);
310 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000311 if (!Canonical)
312 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000313 ID.AddBoolean(S->isArrow());
314}
315
316void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
317 VisitExpr(S);
318 ID.AddBoolean(S->isFileScope());
319}
320
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000321void StmtProfiler::VisitCastExpr(CastExpr *S) {
322 VisitExpr(S);
323}
324
325void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
326 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000327 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000328}
329
330void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
331 VisitCastExpr(S);
332 VisitType(S->getTypeAsWritten());
333}
334
335void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
336 VisitExplicitCastExpr(S);
337}
338
339void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
340 VisitExpr(S);
341 ID.AddInteger(S->getOpcode());
342}
343
344void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
345 VisitBinaryOperator(S);
346}
347
348void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
349 VisitExpr(S);
350}
351
352void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
353 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000354 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000355}
356
357void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
358 VisitExpr(S);
359}
360
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000361void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
362 VisitExpr(S);
363}
364
365void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
366 VisitExpr(S);
367}
368
369void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
370 VisitExpr(S);
371}
372
Douglas Gregor828e2262009-07-29 16:09:57 +0000373void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
374 VisitExpr(S);
375}
376
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000377void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
378 if (S->getSyntacticForm()) {
379 VisitInitListExpr(S->getSyntacticForm());
380 return;
381 }
Mike Stump1eb44332009-09-09 15:08:12 +0000382
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000383 VisitExpr(S);
384}
385
386void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
387 VisitExpr(S);
388 ID.AddBoolean(S->usesGNUSyntax());
389 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
390 DEnd = S->designators_end();
391 D != DEnd; ++D) {
392 if (D->isFieldDesignator()) {
393 ID.AddInteger(0);
394 VisitName(D->getFieldName());
395 continue;
396 }
Mike Stump1eb44332009-09-09 15:08:12 +0000397
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000398 if (D->isArrayDesignator()) {
399 ID.AddInteger(1);
400 } else {
401 assert(D->isArrayRangeDesignator());
402 ID.AddInteger(2);
403 }
404 ID.AddInteger(D->getFirstExprIndex());
405 }
406}
407
408void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
409 VisitExpr(S);
410}
411
412void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
413 VisitExpr(S);
414 VisitName(&S->getAccessor());
415}
416
417void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
418 VisitExpr(S);
419 VisitDecl(S->getBlockDecl());
420}
421
422void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
423 VisitExpr(S);
424 VisitDecl(S->getDecl());
425 ID.AddBoolean(S->isByRef());
426 ID.AddBoolean(S->isConstQualAdded());
427}
428
Douglas Gregora89064a2010-05-19 04:13:23 +0000429static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000430 UnaryOperatorKind &UnaryOp,
431 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000432 switch (S->getOperator()) {
433 case OO_None:
434 case OO_New:
435 case OO_Delete:
436 case OO_Array_New:
437 case OO_Array_Delete:
438 case OO_Arrow:
439 case OO_Call:
440 case OO_Conditional:
441 case NUM_OVERLOADED_OPERATORS:
442 llvm_unreachable("Invalid operator call kind");
443 return Stmt::ArraySubscriptExprClass;
444
445 case OO_Plus:
446 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000447 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000448 return Stmt::UnaryOperatorClass;
449 }
450
John McCall2de56d12010-08-25 11:45:40 +0000451 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000452 return Stmt::BinaryOperatorClass;
453
454 case OO_Minus:
455 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000456 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000457 return Stmt::UnaryOperatorClass;
458 }
459
John McCall2de56d12010-08-25 11:45:40 +0000460 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000461 return Stmt::BinaryOperatorClass;
462
463 case OO_Star:
464 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000465 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000466 return Stmt::UnaryOperatorClass;
467 }
468
John McCall2de56d12010-08-25 11:45:40 +0000469 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000470 return Stmt::BinaryOperatorClass;
471
472 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000473 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000474 return Stmt::BinaryOperatorClass;
475
476 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000477 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000478 return Stmt::BinaryOperatorClass;
479
480 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000481 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000482 return Stmt::BinaryOperatorClass;
483
484 case OO_Amp:
485 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000486 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000487 return Stmt::UnaryOperatorClass;
488 }
489
John McCall2de56d12010-08-25 11:45:40 +0000490 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000491 return Stmt::BinaryOperatorClass;
492
493 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000494 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000495 return Stmt::BinaryOperatorClass;
496
497 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000498 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000499 return Stmt::UnaryOperatorClass;
500
501 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000502 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000503 return Stmt::UnaryOperatorClass;
504
505 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000506 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000507 return Stmt::BinaryOperatorClass;
508
509 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000510 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000511 return Stmt::BinaryOperatorClass;
512
513 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000514 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000515 return Stmt::BinaryOperatorClass;
516
517 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000518 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000519 return Stmt::CompoundAssignOperatorClass;
520
521 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000522 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000523 return Stmt::CompoundAssignOperatorClass;
524
525 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000526 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000527 return Stmt::CompoundAssignOperatorClass;
528
529 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000530 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000531 return Stmt::CompoundAssignOperatorClass;
532
533 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000534 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000535 return Stmt::CompoundAssignOperatorClass;
536
537 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000538 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000539 return Stmt::CompoundAssignOperatorClass;
540
541 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000542 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000543 return Stmt::CompoundAssignOperatorClass;
544
545 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000546 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000547 return Stmt::CompoundAssignOperatorClass;
548
549 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000550 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000551 return Stmt::BinaryOperatorClass;
552
553 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000554 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000555 return Stmt::BinaryOperatorClass;
556
557 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000558 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000559 return Stmt::CompoundAssignOperatorClass;
560
561 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000562 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000563 return Stmt::CompoundAssignOperatorClass;
564
565 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000566 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000567 return Stmt::BinaryOperatorClass;
568
569 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000570 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000571 return Stmt::BinaryOperatorClass;
572
573 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000574 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000575 return Stmt::BinaryOperatorClass;
576
577 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000578 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000579 return Stmt::BinaryOperatorClass;
580
581 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000582 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000583 return Stmt::BinaryOperatorClass;
584
585 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000586 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000587 return Stmt::BinaryOperatorClass;
588
589 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000590 UnaryOp = S->getNumArgs() == 1? UO_PreInc
591 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000592 return Stmt::UnaryOperatorClass;
593
594 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000595 UnaryOp = S->getNumArgs() == 1? UO_PreDec
596 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000597 return Stmt::UnaryOperatorClass;
598
599 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000600 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000601 return Stmt::BinaryOperatorClass;
602
603
604 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000605 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000606 return Stmt::BinaryOperatorClass;
607
608 case OO_Subscript:
609 return Stmt::ArraySubscriptExprClass;
610 }
611
612 llvm_unreachable("Invalid overloaded operator expression");
613}
614
615
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000616void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000617 if (S->isTypeDependent()) {
618 // Type-dependent operator calls are profiled like their underlying
619 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000620 UnaryOperatorKind UnaryOp = UO_Extension;
621 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000622 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
623
624 ID.AddInteger(SC);
625 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
626 Visit(S->getArg(I));
627 if (SC == Stmt::UnaryOperatorClass)
628 ID.AddInteger(UnaryOp);
629 else if (SC == Stmt::BinaryOperatorClass ||
630 SC == Stmt::CompoundAssignOperatorClass)
631 ID.AddInteger(BinaryOp);
632 else
633 assert(SC == Stmt::ArraySubscriptExprClass);
634
635 return;
636 }
637
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000638 VisitCallExpr(S);
639 ID.AddInteger(S->getOperator());
640}
641
642void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
643 VisitCallExpr(S);
644}
645
Peter Collingbournee08ce652011-02-09 21:07:24 +0000646void StmtProfiler::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *S) {
647 VisitCallExpr(S);
648}
649
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000650void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
651 VisitExplicitCastExpr(S);
652}
653
654void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
655 VisitCXXNamedCastExpr(S);
656}
657
658void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
659 VisitCXXNamedCastExpr(S);
660}
661
662void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
663 VisitCXXNamedCastExpr(S);
664}
665
666void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
667 VisitCXXNamedCastExpr(S);
668}
669
670void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
671 VisitExpr(S);
672 ID.AddBoolean(S->getValue());
673}
674
Douglas Gregor828e2262009-07-29 16:09:57 +0000675void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
676 VisitExpr(S);
677}
678
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000679void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
680 VisitExpr(S);
681 if (S->isTypeOperand())
682 VisitType(S->getTypeOperand());
683}
684
Francois Pichet01b7c302010-09-08 12:20:18 +0000685void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
686 VisitExpr(S);
687 if (S->isTypeOperand())
688 VisitType(S->getTypeOperand());
689}
690
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000691void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
692 VisitExpr(S);
693}
694
695void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
696 VisitExpr(S);
697}
698
699void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
700 VisitExpr(S);
701 VisitDecl(S->getParam());
702}
703
704void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
705 VisitExpr(S);
706 VisitDecl(
707 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
708}
709
710void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
711 VisitExpr(S);
712 VisitDecl(S->getConstructor());
713 ID.AddBoolean(S->isElidable());
714}
715
716void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
717 VisitExplicitCastExpr(S);
718}
719
720void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
721 VisitCXXConstructExpr(S);
722}
723
Douglas Gregored8abf12010-07-08 06:14:04 +0000724void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000725 VisitExpr(S);
726}
727
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000728void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
729 VisitExpr(S);
730 ID.AddBoolean(S->isGlobalDelete());
731 ID.AddBoolean(S->isArrayForm());
732 VisitDecl(S->getOperatorDelete());
733}
734
735
736void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
737 VisitExpr(S);
738 VisitType(S->getAllocatedType());
739 VisitDecl(S->getOperatorNew());
740 VisitDecl(S->getOperatorDelete());
741 VisitDecl(S->getConstructor());
742 ID.AddBoolean(S->isArray());
743 ID.AddInteger(S->getNumPlacementArgs());
744 ID.AddBoolean(S->isGlobalNew());
745 ID.AddBoolean(S->isParenTypeId());
746 ID.AddBoolean(S->hasInitializer());
747 ID.AddInteger(S->getNumConstructorArgs());
748}
749
Douglas Gregora71d8192009-09-04 17:36:40 +0000750void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
751 VisitExpr(S);
752 ID.AddBoolean(S->isArrow());
753 VisitNestedNameSpecifier(S->getQualifier());
754 VisitType(S->getDestroyedType());
755}
756
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000757void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000758 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000759 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000760 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000761 ID.AddBoolean(S->hasExplicitTemplateArgs());
762 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000763 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
764 S->getExplicitTemplateArgs().NumTemplateArgs);
765}
766
767void
768StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
769 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000770}
771
772void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
773 VisitExpr(S);
774 ID.AddInteger(S->getTrait());
775 VisitType(S->getQueriedType());
776}
777
Francois Pichet6ad6f282010-12-07 00:08:36 +0000778void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
779 VisitExpr(S);
780 ID.AddInteger(S->getTrait());
781 VisitType(S->getLhsType());
782 VisitType(S->getRhsType());
783}
784
John McCall865d4472009-11-19 22:55:06 +0000785void
786StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000787 VisitExpr(S);
788 VisitName(S->getDeclName());
789 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000790 ID.AddBoolean(S->hasExplicitTemplateArgs());
791 if (S->hasExplicitTemplateArgs())
792 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000793}
794
John McCall4765fa02010-12-06 08:20:24 +0000795void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000796 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000797}
798
Mike Stump1eb44332009-09-09 15:08:12 +0000799void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000800StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
801 VisitExpr(S);
802 VisitType(S->getTypeAsWritten());
803}
804
John McCall865d4472009-11-19 22:55:06 +0000805void
806StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000807 ID.AddBoolean(S->isImplicitAccess());
808 if (!S->isImplicitAccess()) {
809 VisitExpr(S);
810 ID.AddBoolean(S->isArrow());
811 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000812 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000813 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000814 ID.AddBoolean(S->hasExplicitTemplateArgs());
815 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000816 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
817}
818
819void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000820 ID.AddBoolean(S->isImplicitAccess());
821 if (!S->isImplicitAccess()) {
822 VisitExpr(S);
823 ID.AddBoolean(S->isArrow());
824 }
John McCall129e2df2009-11-30 22:42:35 +0000825 VisitNestedNameSpecifier(S->getQualifier());
826 VisitName(S->getMemberName());
827 ID.AddBoolean(S->hasExplicitTemplateArgs());
828 if (S->hasExplicitTemplateArgs())
829 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000830}
831
Sebastian Redl2e156222010-09-10 20:55:43 +0000832void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
833 VisitExpr(S);
834}
835
Douglas Gregorbe230c32011-01-03 17:17:50 +0000836void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
837 VisitExpr(S);
838}
839
Douglas Gregoree8aff02011-01-04 17:33:58 +0000840void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
841 VisitExpr(S);
842 VisitDecl(S->getPack());
843}
844
Douglas Gregorc7793c72011-01-15 01:15:58 +0000845void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
846 SubstNonTypeTemplateParmPackExpr *S) {
847 VisitExpr(S);
848 VisitDecl(S->getParameterPack());
849 VisitTemplateArgument(S->getArgumentPack());
850}
851
John McCall7cd7d1a2010-11-15 23:31:06 +0000852void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
853 VisitExpr(E);
854}
855
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000856void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
857 VisitExpr(S);
858}
859
860void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
861 VisitExpr(S);
862 VisitType(S->getEncodedType());
863}
864
865void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
866 VisitExpr(S);
867 VisitName(S->getSelector());
868}
869
870void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
871 VisitExpr(S);
872 VisitDecl(S->getProtocol());
873}
874
875void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
876 VisitExpr(S);
877 VisitDecl(S->getDecl());
878 ID.AddBoolean(S->isArrow());
879 ID.AddBoolean(S->isFreeIvar());
880}
881
882void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
883 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +0000884 if (S->isImplicitProperty()) {
885 VisitDecl(S->getImplicitPropertyGetter());
886 VisitDecl(S->getImplicitPropertySetter());
887 } else {
888 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000889 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000890 if (S->isSuperReceiver()) {
891 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +0000892 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000893 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000894}
895
896void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
897 VisitExpr(S);
898 VisitName(S->getSelector());
899 VisitDecl(S->getMethodDecl());
900}
901
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000902void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
903 VisitExpr(S);
904 ID.AddBoolean(S->isArrow());
905}
906
Douglas Gregord584eb22009-07-28 15:32:17 +0000907void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000908 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000909
Douglas Gregorb1975722009-07-30 23:18:24 +0000910 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000911 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000912 ID.AddInteger(NTTP->getDepth());
913 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000914 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +0000915 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000916 return;
917 }
Mike Stump1eb44332009-09-09 15:08:12 +0000918
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000919 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
920 // The Itanium C++ ABI uses the type of a parameter when mangling
921 // expressions that involve function parameters, so we will use the
922 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000923 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000924 // matches the definition of "equivalent" used for name mangling.
925 VisitType(Parm->getType());
926 return;
927 }
Mike Stump1eb44332009-09-09 15:08:12 +0000928
Douglas Gregora2ffb982009-07-31 15:46:56 +0000929 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
930 ID.AddInteger(TTP->getDepth());
931 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000932 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +0000933 return;
934 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000935 }
Mike Stump1eb44332009-09-09 15:08:12 +0000936
Douglas Gregord584eb22009-07-28 15:32:17 +0000937 ID.AddPointer(D? D->getCanonicalDecl() : 0);
938}
939
940void StmtProfiler::VisitType(QualType T) {
941 if (Canonical)
942 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000943
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000944 ID.AddPointer(T.getAsOpaquePtr());
945}
946
947void StmtProfiler::VisitName(DeclarationName Name) {
948 ID.AddPointer(Name.getAsOpaquePtr());
949}
950
951void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
952 if (Canonical)
953 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
954 ID.AddPointer(NNS);
955}
956
957void StmtProfiler::VisitTemplateName(TemplateName Name) {
958 if (Canonical)
959 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000960
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000961 Name.Profile(ID);
962}
963
John McCall833ca992009-10-29 08:12:44 +0000964void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000965 unsigned NumArgs) {
966 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000967 for (unsigned I = 0; I != NumArgs; ++I)
968 VisitTemplateArgument(Args[I].getArgument());
969}
Mike Stump1eb44332009-09-09 15:08:12 +0000970
John McCall833ca992009-10-29 08:12:44 +0000971void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
972 // Mostly repetitive with TemplateArgument::Profile!
973 ID.AddInteger(Arg.getKind());
974 switch (Arg.getKind()) {
975 case TemplateArgument::Null:
976 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000977
John McCall833ca992009-10-29 08:12:44 +0000978 case TemplateArgument::Type:
979 VisitType(Arg.getAsType());
980 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000981
Douglas Gregor788cd062009-11-11 01:00:40 +0000982 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +0000983 case TemplateArgument::TemplateExpansion:
984 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +0000985 break;
Sean Huntc3021132010-05-05 15:23:54 +0000986
John McCall833ca992009-10-29 08:12:44 +0000987 case TemplateArgument::Declaration:
988 VisitDecl(Arg.getAsDecl());
989 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000990
John McCall833ca992009-10-29 08:12:44 +0000991 case TemplateArgument::Integral:
992 Arg.getAsIntegral()->Profile(ID);
993 VisitType(Arg.getIntegralType());
994 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000995
John McCall833ca992009-10-29 08:12:44 +0000996 case TemplateArgument::Expression:
997 Visit(Arg.getAsExpr());
998 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000999
John McCall833ca992009-10-29 08:12:44 +00001000 case TemplateArgument::Pack:
1001 const TemplateArgument *Pack = Arg.pack_begin();
1002 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1003 VisitTemplateArgument(Pack[i]);
1004 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001005 }
1006}
1007
Jay Foad4ba2a172011-01-12 09:06:06 +00001008void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001009 bool Canonical) {
1010 StmtProfiler Profiler(ID, Context, Canonical);
1011 Profiler.Visit(this);
1012}