blob: 5a04df04065ace2b7ad7e654b5e67c504d51440d [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
248void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
249 VisitExpr(S);
250 ID.AddInteger(S->getOpcode());
251}
252
253void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
254 VisitExpr(S);
255 ID.AddBoolean(S->isSizeOf());
256 if (S->isArgumentType())
257 VisitType(S->getArgumentType());
258}
259
260void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
261 VisitExpr(S);
262}
263
264void StmtProfiler::VisitCallExpr(CallExpr *S) {
265 VisitExpr(S);
266}
267
268void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
269 VisitExpr(S);
270 VisitDecl(S->getMemberDecl());
271 ID.AddBoolean(S->isArrow());
272}
273
274void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
275 VisitExpr(S);
276 ID.AddBoolean(S->isFileScope());
277}
278
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000279void StmtProfiler::VisitCastExpr(CastExpr *S) {
280 VisitExpr(S);
281}
282
283void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
284 VisitCastExpr(S);
285 ID.AddBoolean(S->isLvalueCast());
286}
287
288void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
289 VisitCastExpr(S);
290 VisitType(S->getTypeAsWritten());
291}
292
293void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
294 VisitExplicitCastExpr(S);
295}
296
297void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
298 VisitExpr(S);
299 ID.AddInteger(S->getOpcode());
300}
301
302void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
303 VisitBinaryOperator(S);
304}
305
306void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
307 VisitExpr(S);
308}
309
310void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
311 VisitExpr(S);
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000312 VisitName(S->getLabel()->getID());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000313}
314
315void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
316 VisitExpr(S);
317}
318
319void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) {
320 VisitExpr(S);
321 VisitType(S->getArgType1());
322 VisitType(S->getArgType2());
323}
324
325void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
326 VisitExpr(S);
327}
328
329void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
330 VisitExpr(S);
331}
332
333void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
334 VisitExpr(S);
335}
336
Douglas Gregor828e2262009-07-29 16:09:57 +0000337void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
338 VisitExpr(S);
339}
340
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000341void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
342 if (S->getSyntacticForm()) {
343 VisitInitListExpr(S->getSyntacticForm());
344 return;
345 }
346
347 VisitExpr(S);
348}
349
350void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
351 VisitExpr(S);
352 ID.AddBoolean(S->usesGNUSyntax());
353 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
354 DEnd = S->designators_end();
355 D != DEnd; ++D) {
356 if (D->isFieldDesignator()) {
357 ID.AddInteger(0);
358 VisitName(D->getFieldName());
359 continue;
360 }
361
362 if (D->isArrayDesignator()) {
363 ID.AddInteger(1);
364 } else {
365 assert(D->isArrayRangeDesignator());
366 ID.AddInteger(2);
367 }
368 ID.AddInteger(D->getFirstExprIndex());
369 }
370}
371
372void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
373 VisitExpr(S);
374}
375
376void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
377 VisitExpr(S);
378 VisitName(&S->getAccessor());
379}
380
381void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
382 VisitExpr(S);
383 VisitDecl(S->getBlockDecl());
384}
385
386void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
387 VisitExpr(S);
388 VisitDecl(S->getDecl());
389 ID.AddBoolean(S->isByRef());
390 ID.AddBoolean(S->isConstQualAdded());
391}
392
393void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
394 VisitCallExpr(S);
395 ID.AddInteger(S->getOperator());
396}
397
398void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
399 VisitCallExpr(S);
400}
401
402void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
403 VisitExplicitCastExpr(S);
404}
405
406void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
407 VisitCXXNamedCastExpr(S);
408}
409
410void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
411 VisitCXXNamedCastExpr(S);
412}
413
414void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
415 VisitCXXNamedCastExpr(S);
416}
417
418void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
419 VisitCXXNamedCastExpr(S);
420}
421
422void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
423 VisitExpr(S);
424 ID.AddBoolean(S->getValue());
425}
426
Douglas Gregor828e2262009-07-29 16:09:57 +0000427void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
428 VisitExpr(S);
429}
430
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000431void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
432 VisitExpr(S);
433 if (S->isTypeOperand())
434 VisitType(S->getTypeOperand());
435}
436
437void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
438 VisitExpr(S);
439}
440
441void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
442 VisitExpr(S);
443}
444
445void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
446 VisitExpr(S);
447 VisitDecl(S->getParam());
448}
449
450void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
451 VisitExpr(S);
452 VisitDecl(
453 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
454}
455
456void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
457 VisitExpr(S);
458 VisitDecl(S->getConstructor());
459 ID.AddBoolean(S->isElidable());
460}
461
462void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
463 VisitExplicitCastExpr(S);
464}
465
466void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
467 VisitCXXConstructExpr(S);
468}
469
470void StmtProfiler::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *S) {
471 VisitExpr(S);
472}
473
474void StmtProfiler::VisitCXXConditionDeclExpr(CXXConditionDeclExpr *S) {
475 VisitDeclRefExpr(S);
476}
477
478void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
479 VisitExpr(S);
480 ID.AddBoolean(S->isGlobalDelete());
481 ID.AddBoolean(S->isArrayForm());
482 VisitDecl(S->getOperatorDelete());
483}
484
485
486void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
487 VisitExpr(S);
488 VisitType(S->getAllocatedType());
489 VisitDecl(S->getOperatorNew());
490 VisitDecl(S->getOperatorDelete());
491 VisitDecl(S->getConstructor());
492 ID.AddBoolean(S->isArray());
493 ID.AddInteger(S->getNumPlacementArgs());
494 ID.AddBoolean(S->isGlobalNew());
495 ID.AddBoolean(S->isParenTypeId());
496 ID.AddBoolean(S->hasInitializer());
497 ID.AddInteger(S->getNumConstructorArgs());
498}
499
500void
501StmtProfiler::VisitUnresolvedFunctionNameExpr(UnresolvedFunctionNameExpr *S) {
502 VisitExpr(S);
503 VisitName(S->getName());
504}
505
506void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
507 VisitExpr(S);
508 ID.AddInteger(S->getTrait());
509 VisitType(S->getQueriedType());
510}
511
512void StmtProfiler::VisitQualifiedDeclRefExpr(QualifiedDeclRefExpr *S) {
513 VisitDeclRefExpr(S);
514 VisitNestedNameSpecifier(S->getQualifier());
515}
516
517void StmtProfiler::VisitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *S) {
518 VisitExpr(S);
519 VisitName(S->getDeclName());
520 VisitNestedNameSpecifier(S->getQualifier());
521 ID.AddBoolean(S->isAddressOfOperand());
522}
523
524void StmtProfiler::VisitTemplateIdRefExpr(TemplateIdRefExpr *S) {
525 VisitExpr(S);
526 VisitNestedNameSpecifier(S->getQualifier());
527 VisitTemplateName(S->getTemplateName());
528 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
529}
530
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000531void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) {
532 VisitExpr(S);
533 ID.AddBoolean(S->shouldDestroyTemporaries());
534 for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I)
535 VisitDecl(
536 const_cast<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor()));
537}
538
539void
540StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
541 VisitExpr(S);
542 VisitType(S->getTypeAsWritten());
543}
544
545void StmtProfiler::VisitCXXUnresolvedMemberExpr(CXXUnresolvedMemberExpr *S) {
546 VisitExpr(S);
547 ID.AddBoolean(S->isArrow());
548 VisitName(S->getMember());
549}
550
551void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
552 VisitExpr(S);
553}
554
555void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
556 VisitExpr(S);
557 VisitType(S->getEncodedType());
558}
559
560void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
561 VisitExpr(S);
562 VisitName(S->getSelector());
563}
564
565void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
566 VisitExpr(S);
567 VisitDecl(S->getProtocol());
568}
569
570void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
571 VisitExpr(S);
572 VisitDecl(S->getDecl());
573 ID.AddBoolean(S->isArrow());
574 ID.AddBoolean(S->isFreeIvar());
575}
576
577void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
578 VisitExpr(S);
579 VisitDecl(S->getProperty());
580}
581
582void StmtProfiler::VisitObjCKVCRefExpr(ObjCKVCRefExpr *S) {
583 VisitExpr(S);
584 VisitDecl(S->getGetterMethod());
585 VisitDecl(S->getSetterMethod());
586 VisitDecl(S->getClassProp());
587}
588
589void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
590 VisitExpr(S);
591 VisitName(S->getSelector());
592 VisitDecl(S->getMethodDecl());
593}
594
595void StmtProfiler::VisitObjCSuperExpr(ObjCSuperExpr *S) {
596 VisitExpr(S);
597}
598
599void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
600 VisitExpr(S);
601 ID.AddBoolean(S->isArrow());
602}
603
Douglas Gregord584eb22009-07-28 15:32:17 +0000604void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000605 ID.AddInteger(D? D->getKind() : 0);
606
Douglas Gregorb1975722009-07-30 23:18:24 +0000607 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000608 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000609 ID.AddInteger(NTTP->getDepth());
610 ID.AddInteger(NTTP->getIndex());
Douglas Gregor828e2262009-07-29 16:09:57 +0000611 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000612 return;
613 }
614
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000615 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
616 // The Itanium C++ ABI uses the type of a parameter when mangling
617 // expressions that involve function parameters, so we will use the
618 // parameter's type for establishing function parameter identity. That
619 // way, our definition of "equivalent" (per C++ [temp.over.link])
620 // matches the definition of "equivalent" used for name mangling.
621 VisitType(Parm->getType());
622 return;
623 }
624
Douglas Gregora2ffb982009-07-31 15:46:56 +0000625 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
626 ID.AddInteger(TTP->getDepth());
627 ID.AddInteger(TTP->getIndex());
628 return;
629 }
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000630
631 if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) {
632 // Canonicalize all of the function declarations within the overload
633 // set.
634 llvm::SmallVector<Decl *, 4> Functions;
635 for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(),
636 FEnd = Ovl->function_end();
637 F != FEnd; ++F)
638 Functions.push_back(F->get()->getCanonicalDecl());
639
640 // Sorting the functions based on the point means that the ID generated
641 // will be different from one execution of the compiler to another.
642 // Since these IDs don't persist over time, the change in ordering will
643 // not affect compilation.
644 std::sort(Functions.begin(), Functions.end());
645
646 for (llvm::SmallVector<Decl *, 4>::iterator F = Functions.begin(),
647 FEnd = Functions.end();
648 F != FEnd; ++F)
649 VisitDecl(*F);
650
651 return;
652 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000653 }
654
Douglas Gregord584eb22009-07-28 15:32:17 +0000655 ID.AddPointer(D? D->getCanonicalDecl() : 0);
656}
657
658void StmtProfiler::VisitType(QualType T) {
659 if (Canonical)
660 T = Context.getCanonicalType(T);
661
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000662 ID.AddPointer(T.getAsOpaquePtr());
663}
664
665void StmtProfiler::VisitName(DeclarationName Name) {
666 ID.AddPointer(Name.getAsOpaquePtr());
667}
668
669void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
670 if (Canonical)
671 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
672 ID.AddPointer(NNS);
673}
674
675void StmtProfiler::VisitTemplateName(TemplateName Name) {
676 if (Canonical)
677 Name = Context.getCanonicalTemplateName(Name);
678
679 Name.Profile(ID);
680}
681
682void StmtProfiler::VisitTemplateArguments(const TemplateArgument *Args,
683 unsigned NumArgs) {
684 ID.AddInteger(NumArgs);
685 for (unsigned I = 0; I != NumArgs; ++I) {
686 const TemplateArgument &Arg = Args[I];
687
688 // Mostly repetitive with TemplateArgument::Profile!
689 ID.AddInteger(Arg.getKind());
690 switch (Arg.getKind()) {
691 case TemplateArgument::Null:
692 break;
693
694 case TemplateArgument::Type:
695 VisitType(Arg.getAsType());
696 break;
697
698 case TemplateArgument::Declaration:
699 VisitDecl(Arg.getAsDecl());
700 break;
701
702 case TemplateArgument::Integral:
703 Arg.getAsIntegral()->Profile(ID);
704 VisitType(Arg.getIntegralType());
705 break;
706
707 case TemplateArgument::Expression:
708 Visit(Arg.getAsExpr());
709 break;
710
711 case TemplateArgument::Pack:
712 VisitTemplateArguments(Arg.pack_begin(), Arg.pack_size());
713 break;
714 }
715 }
716}
717
718void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
719 bool Canonical) {
720 StmtProfiler Profiler(ID, Context, Canonical);
721 Profiler.Visit(this);
722}