blob: ff20299168434ea2cacec8aaae9010218feb825e [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"
23#include "llvm/Support/Compiler.h"
24using namespace clang;
25
26namespace {
27 class VISIBILITY_HIDDEN StmtProfiler : public StmtVisitor<StmtProfiler> {
28 llvm::FoldingSetNodeID &ID;
29 ASTContext &Context;
30 bool Canonical;
31
32 public:
33 StmtProfiler(llvm::FoldingSetNodeID &ID, ASTContext &Context,
34 bool Canonical)
35 : ID(ID), Context(Context), Canonical(Canonical) { }
36
Douglas Gregor41ef0c32009-07-28 00:33:38 +000037 void VisitStmt(Stmt *S);
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000038
39#define STMT(Node, Base) void Visit##Node(Node *S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +000040#include "clang/AST/StmtNodes.def"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000041
42 /// \brief Visit a declaration that is referenced within an expression
43 /// or statement.
44 void VisitDecl(Decl *D);
45
46 /// \brief Visit a type that is referenced within an expression or
47 /// statement.
48 void VisitType(QualType T);
49
50 /// \brief Visit a name that occurs within an expression or statement.
51 void VisitName(DeclarationName Name);
52
53 /// \brief Visit a nested-name-specifier that occurs within an expression
54 /// or statement.
55 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
56
57 /// \brief Visit a template name that occurs within an expression or
58 /// statement.
59 void VisitTemplateName(TemplateName Name);
60
61 /// \brief Visit template arguments that occur within an expression or
62 /// statement.
63 void VisitTemplateArguments(const TemplateArgument *Args, unsigned NumArgs);
64 };
65}
66
67void StmtProfiler::VisitStmt(Stmt *S) {
68 ID.AddInteger(S->getStmtClass());
69 for (Stmt::child_iterator C = S->child_begin(), CEnd = S->child_end();
70 C != CEnd; ++C)
71 Visit(*C);
72}
73
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000074void StmtProfiler::VisitDeclStmt(DeclStmt *S) {
75 VisitStmt(S);
76 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
77 D != DEnd; ++D)
78 VisitDecl(*D);
79}
80
81void StmtProfiler::VisitNullStmt(NullStmt *S) {
82 VisitStmt(S);
83}
84
85void StmtProfiler::VisitCompoundStmt(CompoundStmt *S) {
86 VisitStmt(S);
87}
88
89void StmtProfiler::VisitSwitchCase(SwitchCase *S) {
90 VisitStmt(S);
91}
92
93void StmtProfiler::VisitCaseStmt(CaseStmt *S) {
94 VisitStmt(S);
95}
96
97void StmtProfiler::VisitDefaultStmt(DefaultStmt *S) {
98 VisitStmt(S);
99}
100
101void StmtProfiler::VisitLabelStmt(LabelStmt *S) {
102 VisitStmt(S);
103 VisitName(S->getID());
104}
105
106void StmtProfiler::VisitIfStmt(IfStmt *S) {
107 VisitStmt(S);
108}
109
Douglas Gregor828e2262009-07-29 16:09:57 +0000110void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
111 VisitStmt(S);
112}
113
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000114void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
115 VisitStmt(S);
116}
117
118void StmtProfiler::VisitDoStmt(DoStmt *S) {
119 VisitStmt(S);
120}
121
122void StmtProfiler::VisitForStmt(ForStmt *S) {
123 VisitStmt(S);
124}
125
126void StmtProfiler::VisitGotoStmt(GotoStmt *S) {
127 VisitStmt(S);
128 VisitName(S->getLabel()->getID());
129}
130
131void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
132 VisitStmt(S);
133}
134
135void StmtProfiler::VisitContinueStmt(ContinueStmt *S) {
136 VisitStmt(S);
137}
138
139void StmtProfiler::VisitBreakStmt(BreakStmt *S) {
140 VisitStmt(S);
141}
142
143void StmtProfiler::VisitReturnStmt(ReturnStmt *S) {
144 VisitStmt(S);
145}
146
147void StmtProfiler::VisitAsmStmt(AsmStmt *S) {
148 VisitStmt(S);
149 ID.AddBoolean(S->isVolatile());
150 ID.AddBoolean(S->isSimple());
151 VisitStringLiteral(S->getAsmString());
152 ID.AddInteger(S->getNumOutputs());
153 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
154 ID.AddString(S->getOutputName(I));
155 VisitStringLiteral(S->getOutputConstraintLiteral(I));
156 }
157 ID.AddInteger(S->getNumInputs());
158 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
159 ID.AddString(S->getInputName(I));
160 VisitStringLiteral(S->getInputConstraintLiteral(I));
161 }
162 ID.AddInteger(S->getNumClobbers());
163 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
164 VisitStringLiteral(S->getClobber(I));
165}
166
167void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) {
168 VisitStmt(S);
169 VisitType(S->getCaughtType());
170}
171
172void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) {
173 VisitStmt(S);
174}
175
176void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
177 VisitStmt(S);
178}
179
180void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
181 VisitStmt(S);
182 ID.AddBoolean(S->hasEllipsis());
183 if (S->getCatchParamDecl())
184 VisitType(S->getCatchParamDecl()->getType());
185}
186
187void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
188 VisitStmt(S);
189}
190
191void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
192 VisitStmt(S);
193}
194
195void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
196 VisitStmt(S);
197}
198
199void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
200 VisitStmt(S);
201}
202
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000203void StmtProfiler::VisitExpr(Expr *S) {
204 VisitStmt(S);
205}
206
207void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
208 VisitExpr(S);
209 VisitDecl(S->getDecl());
210}
211
212void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
213 VisitExpr(S);
214 ID.AddInteger(S->getIdentType());
215}
216
217void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
218 VisitExpr(S);
219 S->getValue().Profile(ID);
220}
221
222void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
223 VisitExpr(S);
224 ID.AddBoolean(S->isWide());
225 ID.AddInteger(S->getValue());
226}
227
228void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
229 VisitExpr(S);
230 S->getValue().Profile(ID);
231 ID.AddBoolean(S->isExact());
232}
233
234void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
235 VisitExpr(S);
236}
237
238void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
239 VisitExpr(S);
240 ID.AddString(S->getStrData(), S->getStrData() + S->getByteLength());
241 ID.AddBoolean(S->isWide());
242}
243
244void StmtProfiler::VisitParenExpr(ParenExpr *S) {
245 VisitExpr(S);
246}
247
Nate Begeman2ef13e52009-08-10 23:49:36 +0000248void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
249 VisitExpr(S);
250}
251
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000252void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
253 VisitExpr(S);
254 ID.AddInteger(S->getOpcode());
255}
256
257void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
258 VisitExpr(S);
259 ID.AddBoolean(S->isSizeOf());
260 if (S->isArgumentType())
261 VisitType(S->getArgumentType());
262}
263
264void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
265 VisitExpr(S);
266}
267
268void StmtProfiler::VisitCallExpr(CallExpr *S) {
269 VisitExpr(S);
270}
271
272void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
273 VisitExpr(S);
274 VisitDecl(S->getMemberDecl());
275 ID.AddBoolean(S->isArrow());
276}
277
278void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
279 VisitExpr(S);
280 ID.AddBoolean(S->isFileScope());
281}
282
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000283void StmtProfiler::VisitCastExpr(CastExpr *S) {
284 VisitExpr(S);
285}
286
287void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
288 VisitCastExpr(S);
289 ID.AddBoolean(S->isLvalueCast());
290}
291
292void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
293 VisitCastExpr(S);
294 VisitType(S->getTypeAsWritten());
295}
296
297void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
298 VisitExplicitCastExpr(S);
299}
300
301void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
302 VisitExpr(S);
303 ID.AddInteger(S->getOpcode());
304}
305
306void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
307 VisitBinaryOperator(S);
308}
309
310void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
311 VisitExpr(S);
312}
313
314void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
315 VisitExpr(S);
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000316 VisitName(S->getLabel()->getID());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000317}
318
319void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
320 VisitExpr(S);
321}
322
323void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) {
324 VisitExpr(S);
325 VisitType(S->getArgType1());
326 VisitType(S->getArgType2());
327}
328
329void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
330 VisitExpr(S);
331}
332
333void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
334 VisitExpr(S);
335}
336
337void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
338 VisitExpr(S);
339}
340
Douglas Gregor828e2262009-07-29 16:09:57 +0000341void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
342 VisitExpr(S);
343}
344
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000345void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
346 if (S->getSyntacticForm()) {
347 VisitInitListExpr(S->getSyntacticForm());
348 return;
349 }
350
351 VisitExpr(S);
352}
353
354void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
355 VisitExpr(S);
356 ID.AddBoolean(S->usesGNUSyntax());
357 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
358 DEnd = S->designators_end();
359 D != DEnd; ++D) {
360 if (D->isFieldDesignator()) {
361 ID.AddInteger(0);
362 VisitName(D->getFieldName());
363 continue;
364 }
365
366 if (D->isArrayDesignator()) {
367 ID.AddInteger(1);
368 } else {
369 assert(D->isArrayRangeDesignator());
370 ID.AddInteger(2);
371 }
372 ID.AddInteger(D->getFirstExprIndex());
373 }
374}
375
376void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
377 VisitExpr(S);
378}
379
380void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
381 VisitExpr(S);
382 VisitName(&S->getAccessor());
383}
384
385void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
386 VisitExpr(S);
387 VisitDecl(S->getBlockDecl());
388}
389
390void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
391 VisitExpr(S);
392 VisitDecl(S->getDecl());
393 ID.AddBoolean(S->isByRef());
394 ID.AddBoolean(S->isConstQualAdded());
395}
396
397void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
398 VisitCallExpr(S);
399 ID.AddInteger(S->getOperator());
400}
401
402void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
403 VisitCallExpr(S);
404}
405
406void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
407 VisitExplicitCastExpr(S);
408}
409
410void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
411 VisitCXXNamedCastExpr(S);
412}
413
414void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
415 VisitCXXNamedCastExpr(S);
416}
417
418void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
419 VisitCXXNamedCastExpr(S);
420}
421
422void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
423 VisitCXXNamedCastExpr(S);
424}
425
426void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
427 VisitExpr(S);
428 ID.AddBoolean(S->getValue());
429}
430
Douglas Gregor828e2262009-07-29 16:09:57 +0000431void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
432 VisitExpr(S);
433}
434
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000435void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
436 VisitExpr(S);
437 if (S->isTypeOperand())
438 VisitType(S->getTypeOperand());
439}
440
441void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
442 VisitExpr(S);
443}
444
445void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
446 VisitExpr(S);
447}
448
449void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
450 VisitExpr(S);
451 VisitDecl(S->getParam());
452}
453
454void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
455 VisitExpr(S);
456 VisitDecl(
457 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
458}
459
460void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
461 VisitExpr(S);
462 VisitDecl(S->getConstructor());
463 ID.AddBoolean(S->isElidable());
464}
465
466void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
467 VisitExplicitCastExpr(S);
468}
469
470void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
471 VisitCXXConstructExpr(S);
472}
473
474void StmtProfiler::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *S) {
475 VisitExpr(S);
476}
477
478void StmtProfiler::VisitCXXConditionDeclExpr(CXXConditionDeclExpr *S) {
479 VisitDeclRefExpr(S);
480}
481
482void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
483 VisitExpr(S);
484 ID.AddBoolean(S->isGlobalDelete());
485 ID.AddBoolean(S->isArrayForm());
486 VisitDecl(S->getOperatorDelete());
487}
488
489
490void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
491 VisitExpr(S);
492 VisitType(S->getAllocatedType());
493 VisitDecl(S->getOperatorNew());
494 VisitDecl(S->getOperatorDelete());
495 VisitDecl(S->getConstructor());
496 ID.AddBoolean(S->isArray());
497 ID.AddInteger(S->getNumPlacementArgs());
498 ID.AddBoolean(S->isGlobalNew());
499 ID.AddBoolean(S->isParenTypeId());
500 ID.AddBoolean(S->hasInitializer());
501 ID.AddInteger(S->getNumConstructorArgs());
502}
503
504void
505StmtProfiler::VisitUnresolvedFunctionNameExpr(UnresolvedFunctionNameExpr *S) {
506 VisitExpr(S);
507 VisitName(S->getName());
508}
509
510void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
511 VisitExpr(S);
512 ID.AddInteger(S->getTrait());
513 VisitType(S->getQueriedType());
514}
515
516void StmtProfiler::VisitQualifiedDeclRefExpr(QualifiedDeclRefExpr *S) {
517 VisitDeclRefExpr(S);
518 VisitNestedNameSpecifier(S->getQualifier());
519}
520
521void StmtProfiler::VisitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *S) {
522 VisitExpr(S);
523 VisitName(S->getDeclName());
524 VisitNestedNameSpecifier(S->getQualifier());
525 ID.AddBoolean(S->isAddressOfOperand());
526}
527
528void StmtProfiler::VisitTemplateIdRefExpr(TemplateIdRefExpr *S) {
529 VisitExpr(S);
530 VisitNestedNameSpecifier(S->getQualifier());
531 VisitTemplateName(S->getTemplateName());
532 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
533}
534
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000535void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) {
536 VisitExpr(S);
537 ID.AddBoolean(S->shouldDestroyTemporaries());
538 for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I)
539 VisitDecl(
540 const_cast<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor()));
541}
542
543void
544StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
545 VisitExpr(S);
546 VisitType(S->getTypeAsWritten());
547}
548
549void StmtProfiler::VisitCXXUnresolvedMemberExpr(CXXUnresolvedMemberExpr *S) {
550 VisitExpr(S);
551 ID.AddBoolean(S->isArrow());
552 VisitName(S->getMember());
553}
554
555void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
556 VisitExpr(S);
557}
558
559void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
560 VisitExpr(S);
561 VisitType(S->getEncodedType());
562}
563
564void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
565 VisitExpr(S);
566 VisitName(S->getSelector());
567}
568
569void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
570 VisitExpr(S);
571 VisitDecl(S->getProtocol());
572}
573
574void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
575 VisitExpr(S);
576 VisitDecl(S->getDecl());
577 ID.AddBoolean(S->isArrow());
578 ID.AddBoolean(S->isFreeIvar());
579}
580
581void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
582 VisitExpr(S);
583 VisitDecl(S->getProperty());
584}
585
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000586void StmtProfiler::VisitObjCImplicitSetterGetterRefExpr(
587 ObjCImplicitSetterGetterRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000588 VisitExpr(S);
589 VisitDecl(S->getGetterMethod());
590 VisitDecl(S->getSetterMethod());
Fariborz Jahaniand2ae5aa2009-08-18 21:37:33 +0000591 VisitDecl(S->getInterfaceDecl());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000592}
593
594void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
595 VisitExpr(S);
596 VisitName(S->getSelector());
597 VisitDecl(S->getMethodDecl());
598}
599
600void StmtProfiler::VisitObjCSuperExpr(ObjCSuperExpr *S) {
601 VisitExpr(S);
602}
603
604void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
605 VisitExpr(S);
606 ID.AddBoolean(S->isArrow());
607}
608
Douglas Gregord584eb22009-07-28 15:32:17 +0000609void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000610 ID.AddInteger(D? D->getKind() : 0);
611
Douglas Gregorb1975722009-07-30 23:18:24 +0000612 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000613 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000614 ID.AddInteger(NTTP->getDepth());
615 ID.AddInteger(NTTP->getIndex());
Douglas Gregor828e2262009-07-29 16:09:57 +0000616 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000617 return;
618 }
619
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000620 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
621 // The Itanium C++ ABI uses the type of a parameter when mangling
622 // expressions that involve function parameters, so we will use the
623 // parameter's type for establishing function parameter identity. That
624 // way, our definition of "equivalent" (per C++ [temp.over.link])
625 // matches the definition of "equivalent" used for name mangling.
626 VisitType(Parm->getType());
627 return;
628 }
629
Douglas Gregora2ffb982009-07-31 15:46:56 +0000630 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
631 ID.AddInteger(TTP->getDepth());
632 ID.AddInteger(TTP->getIndex());
633 return;
634 }
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000635
636 if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) {
Douglas Gregor6f2c46b2009-07-31 16:07:31 +0000637 // The Itanium C++ ABI mangles references to a set of overloaded
638 // functions using just the function name, so we do the same here.
639 VisitName(Ovl->getDeclName());
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000640 return;
641 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000642 }
643
Douglas Gregord584eb22009-07-28 15:32:17 +0000644 ID.AddPointer(D? D->getCanonicalDecl() : 0);
645}
646
647void StmtProfiler::VisitType(QualType T) {
648 if (Canonical)
649 T = Context.getCanonicalType(T);
650
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000651 ID.AddPointer(T.getAsOpaquePtr());
652}
653
654void StmtProfiler::VisitName(DeclarationName Name) {
655 ID.AddPointer(Name.getAsOpaquePtr());
656}
657
658void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
659 if (Canonical)
660 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
661 ID.AddPointer(NNS);
662}
663
664void StmtProfiler::VisitTemplateName(TemplateName Name) {
665 if (Canonical)
666 Name = Context.getCanonicalTemplateName(Name);
667
668 Name.Profile(ID);
669}
670
671void StmtProfiler::VisitTemplateArguments(const TemplateArgument *Args,
672 unsigned NumArgs) {
673 ID.AddInteger(NumArgs);
674 for (unsigned I = 0; I != NumArgs; ++I) {
675 const TemplateArgument &Arg = Args[I];
676
677 // Mostly repetitive with TemplateArgument::Profile!
678 ID.AddInteger(Arg.getKind());
679 switch (Arg.getKind()) {
680 case TemplateArgument::Null:
681 break;
682
683 case TemplateArgument::Type:
684 VisitType(Arg.getAsType());
685 break;
686
687 case TemplateArgument::Declaration:
688 VisitDecl(Arg.getAsDecl());
689 break;
690
691 case TemplateArgument::Integral:
692 Arg.getAsIntegral()->Profile(ID);
693 VisitType(Arg.getIntegralType());
694 break;
695
696 case TemplateArgument::Expression:
697 Visit(Arg.getAsExpr());
698 break;
699
700 case TemplateArgument::Pack:
701 VisitTemplateArguments(Arg.pack_begin(), Arg.pack_size());
702 break;
703 }
704 }
705}
706
707void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
708 bool Canonical) {
709 StmtProfiler Profiler(ID, Context, Canonical);
710 Profiler.Visit(this);
711}