blob: e9f6cee11562b66def74a7f546200cc61cc26015 [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;
Mike Stump1eb44332009-09-09 15:08:12 +000031
Douglas Gregor41ef0c32009-07-28 00:33:38 +000032 public:
33 StmtProfiler(llvm::FoldingSetNodeID &ID, ASTContext &Context,
Mike Stump1eb44332009-09-09 15:08:12 +000034 bool Canonical)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000035 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump1eb44332009-09-09 15:08:12 +000036
Douglas Gregor41ef0c32009-07-28 00:33:38 +000037 void VisitStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +000038
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000039#define STMT(Node, Base) void Visit##Node(Node *S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +000040#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor41ef0c32009-07-28 00:33:38 +000042 /// \brief Visit a declaration that is referenced within an expression
43 /// or statement.
44 void VisitDecl(Decl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000045
46 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor41ef0c32009-07-28 00:33:38 +000047 /// statement.
48 void VisitType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +000049
Douglas Gregor41ef0c32009-07-28 00:33:38 +000050 /// \brief Visit a name that occurs within an expression or statement.
51 void VisitName(DeclarationName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000052
Douglas Gregor41ef0c32009-07-28 00:33:38 +000053 /// \brief Visit a nested-name-specifier that occurs within an expression
54 /// or statement.
55 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump1eb44332009-09-09 15:08:12 +000056
Douglas Gregor41ef0c32009-07-28 00:33:38 +000057 /// \brief Visit a template name that occurs within an expression or
58 /// statement.
59 void VisitTemplateName(TemplateName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000060
Douglas Gregor41ef0c32009-07-28 00:33:38 +000061 /// \brief Visit template arguments that occur within an expression or
62 /// statement.
John McCall833ca992009-10-29 08:12:44 +000063 void VisitTemplateArguments(const TemplateArgumentLoc *Args, unsigned NumArgs);
64
65 /// \brief Visit a single template argument.
66 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor41ef0c32009-07-28 00:33:38 +000067 };
68}
69
70void StmtProfiler::VisitStmt(Stmt *S) {
71 ID.AddInteger(S->getStmtClass());
72 for (Stmt::child_iterator C = S->child_begin(), CEnd = S->child_end();
73 C != CEnd; ++C)
74 Visit(*C);
75}
76
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000077void StmtProfiler::VisitDeclStmt(DeclStmt *S) {
78 VisitStmt(S);
79 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
80 D != DEnd; ++D)
81 VisitDecl(*D);
82}
83
84void StmtProfiler::VisitNullStmt(NullStmt *S) {
85 VisitStmt(S);
86}
87
88void StmtProfiler::VisitCompoundStmt(CompoundStmt *S) {
89 VisitStmt(S);
90}
91
92void StmtProfiler::VisitSwitchCase(SwitchCase *S) {
93 VisitStmt(S);
94}
95
96void StmtProfiler::VisitCaseStmt(CaseStmt *S) {
97 VisitStmt(S);
98}
99
100void StmtProfiler::VisitDefaultStmt(DefaultStmt *S) {
101 VisitStmt(S);
102}
103
104void StmtProfiler::VisitLabelStmt(LabelStmt *S) {
105 VisitStmt(S);
106 VisitName(S->getID());
107}
108
109void StmtProfiler::VisitIfStmt(IfStmt *S) {
110 VisitStmt(S);
111}
112
Douglas Gregor828e2262009-07-29 16:09:57 +0000113void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
114 VisitStmt(S);
115}
116
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000117void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
118 VisitStmt(S);
119}
120
121void StmtProfiler::VisitDoStmt(DoStmt *S) {
122 VisitStmt(S);
123}
124
125void StmtProfiler::VisitForStmt(ForStmt *S) {
126 VisitStmt(S);
127}
128
129void StmtProfiler::VisitGotoStmt(GotoStmt *S) {
130 VisitStmt(S);
131 VisitName(S->getLabel()->getID());
132}
133
134void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
135 VisitStmt(S);
136}
137
138void StmtProfiler::VisitContinueStmt(ContinueStmt *S) {
139 VisitStmt(S);
140}
141
142void StmtProfiler::VisitBreakStmt(BreakStmt *S) {
143 VisitStmt(S);
144}
145
146void StmtProfiler::VisitReturnStmt(ReturnStmt *S) {
147 VisitStmt(S);
148}
149
150void StmtProfiler::VisitAsmStmt(AsmStmt *S) {
151 VisitStmt(S);
152 ID.AddBoolean(S->isVolatile());
153 ID.AddBoolean(S->isSimple());
154 VisitStringLiteral(S->getAsmString());
155 ID.AddInteger(S->getNumOutputs());
156 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
157 ID.AddString(S->getOutputName(I));
158 VisitStringLiteral(S->getOutputConstraintLiteral(I));
159 }
160 ID.AddInteger(S->getNumInputs());
161 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
162 ID.AddString(S->getInputName(I));
163 VisitStringLiteral(S->getInputConstraintLiteral(I));
164 }
165 ID.AddInteger(S->getNumClobbers());
166 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
167 VisitStringLiteral(S->getClobber(I));
168}
169
170void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) {
171 VisitStmt(S);
172 VisitType(S->getCaughtType());
173}
174
175void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) {
176 VisitStmt(S);
177}
178
179void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
180 VisitStmt(S);
181}
182
183void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
184 VisitStmt(S);
185 ID.AddBoolean(S->hasEllipsis());
186 if (S->getCatchParamDecl())
187 VisitType(S->getCatchParamDecl()->getType());
188}
189
190void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
191 VisitStmt(S);
192}
193
194void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
195 VisitStmt(S);
196}
197
198void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
199 VisitStmt(S);
200}
201
202void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
203 VisitStmt(S);
204}
205
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000206void StmtProfiler::VisitExpr(Expr *S) {
207 VisitStmt(S);
208}
209
210void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
211 VisitExpr(S);
Douglas Gregora2813ce2009-10-23 18:54:35 +0000212 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000213 VisitDecl(S->getDecl());
Douglas Gregora2813ce2009-10-23 18:54:35 +0000214 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000215}
216
217void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
218 VisitExpr(S);
219 ID.AddInteger(S->getIdentType());
220}
221
222void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
223 VisitExpr(S);
224 S->getValue().Profile(ID);
225}
226
227void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
228 VisitExpr(S);
229 ID.AddBoolean(S->isWide());
230 ID.AddInteger(S->getValue());
231}
232
233void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
234 VisitExpr(S);
235 S->getValue().Profile(ID);
236 ID.AddBoolean(S->isExact());
237}
238
239void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
240 VisitExpr(S);
241}
242
243void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
244 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000245 ID.AddString(S->getString());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000246 ID.AddBoolean(S->isWide());
247}
248
249void StmtProfiler::VisitParenExpr(ParenExpr *S) {
250 VisitExpr(S);
251}
252
Nate Begeman2ef13e52009-08-10 23:49:36 +0000253void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
254 VisitExpr(S);
255}
256
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000257void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
258 VisitExpr(S);
259 ID.AddInteger(S->getOpcode());
260}
261
262void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
263 VisitExpr(S);
264 ID.AddBoolean(S->isSizeOf());
265 if (S->isArgumentType())
266 VisitType(S->getArgumentType());
267}
268
269void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
270 VisitExpr(S);
271}
272
273void StmtProfiler::VisitCallExpr(CallExpr *S) {
274 VisitExpr(S);
275}
276
277void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
278 VisitExpr(S);
279 VisitDecl(S->getMemberDecl());
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000280 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000281 ID.AddBoolean(S->isArrow());
282}
283
284void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
285 VisitExpr(S);
286 ID.AddBoolean(S->isFileScope());
287}
288
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000289void StmtProfiler::VisitCastExpr(CastExpr *S) {
290 VisitExpr(S);
291}
292
293void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
294 VisitCastExpr(S);
295 ID.AddBoolean(S->isLvalueCast());
296}
297
298void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
299 VisitCastExpr(S);
300 VisitType(S->getTypeAsWritten());
301}
302
303void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
304 VisitExplicitCastExpr(S);
305}
306
307void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
308 VisitExpr(S);
309 ID.AddInteger(S->getOpcode());
310}
311
312void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
313 VisitBinaryOperator(S);
314}
315
316void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
317 VisitExpr(S);
318}
319
320void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
321 VisitExpr(S);
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000322 VisitName(S->getLabel()->getID());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000323}
324
325void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
326 VisitExpr(S);
327}
328
329void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) {
330 VisitExpr(S);
331 VisitType(S->getArgType1());
332 VisitType(S->getArgType2());
333}
334
335void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
336 VisitExpr(S);
337}
338
339void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
340 VisitExpr(S);
341}
342
343void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
344 VisitExpr(S);
345}
346
Douglas Gregor828e2262009-07-29 16:09:57 +0000347void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
348 VisitExpr(S);
349}
350
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000351void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
352 if (S->getSyntacticForm()) {
353 VisitInitListExpr(S->getSyntacticForm());
354 return;
355 }
Mike Stump1eb44332009-09-09 15:08:12 +0000356
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000357 VisitExpr(S);
358}
359
360void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
361 VisitExpr(S);
362 ID.AddBoolean(S->usesGNUSyntax());
363 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
364 DEnd = S->designators_end();
365 D != DEnd; ++D) {
366 if (D->isFieldDesignator()) {
367 ID.AddInteger(0);
368 VisitName(D->getFieldName());
369 continue;
370 }
Mike Stump1eb44332009-09-09 15:08:12 +0000371
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000372 if (D->isArrayDesignator()) {
373 ID.AddInteger(1);
374 } else {
375 assert(D->isArrayRangeDesignator());
376 ID.AddInteger(2);
377 }
378 ID.AddInteger(D->getFirstExprIndex());
379 }
380}
381
382void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
383 VisitExpr(S);
384}
385
386void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
387 VisitExpr(S);
388 VisitName(&S->getAccessor());
389}
390
391void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
392 VisitExpr(S);
393 VisitDecl(S->getBlockDecl());
394}
395
396void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
397 VisitExpr(S);
398 VisitDecl(S->getDecl());
399 ID.AddBoolean(S->isByRef());
400 ID.AddBoolean(S->isConstQualAdded());
401}
402
403void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
404 VisitCallExpr(S);
405 ID.AddInteger(S->getOperator());
406}
407
408void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
409 VisitCallExpr(S);
410}
411
412void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
413 VisitExplicitCastExpr(S);
414}
415
416void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
417 VisitCXXNamedCastExpr(S);
418}
419
420void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
421 VisitCXXNamedCastExpr(S);
422}
423
424void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
425 VisitCXXNamedCastExpr(S);
426}
427
428void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
429 VisitCXXNamedCastExpr(S);
430}
431
432void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
433 VisitExpr(S);
434 ID.AddBoolean(S->getValue());
435}
436
Douglas Gregor828e2262009-07-29 16:09:57 +0000437void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
438 VisitExpr(S);
439}
440
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000441void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
442 VisitExpr(S);
443 if (S->isTypeOperand())
444 VisitType(S->getTypeOperand());
445}
446
447void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
448 VisitExpr(S);
449}
450
451void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
452 VisitExpr(S);
453}
454
455void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
456 VisitExpr(S);
457 VisitDecl(S->getParam());
458}
459
460void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
461 VisitExpr(S);
462 VisitDecl(
463 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
464}
465
466void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
467 VisitExpr(S);
468 VisitDecl(S->getConstructor());
469 ID.AddBoolean(S->isElidable());
470}
471
472void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
473 VisitExplicitCastExpr(S);
474}
475
476void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
477 VisitCXXConstructExpr(S);
478}
479
480void StmtProfiler::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *S) {
481 VisitExpr(S);
482}
483
484void StmtProfiler::VisitCXXConditionDeclExpr(CXXConditionDeclExpr *S) {
485 VisitDeclRefExpr(S);
486}
487
488void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
489 VisitExpr(S);
490 ID.AddBoolean(S->isGlobalDelete());
491 ID.AddBoolean(S->isArrayForm());
492 VisitDecl(S->getOperatorDelete());
493}
494
495
496void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
497 VisitExpr(S);
498 VisitType(S->getAllocatedType());
499 VisitDecl(S->getOperatorNew());
500 VisitDecl(S->getOperatorDelete());
501 VisitDecl(S->getConstructor());
502 ID.AddBoolean(S->isArray());
503 ID.AddInteger(S->getNumPlacementArgs());
504 ID.AddBoolean(S->isGlobalNew());
505 ID.AddBoolean(S->isParenTypeId());
506 ID.AddBoolean(S->hasInitializer());
507 ID.AddInteger(S->getNumConstructorArgs());
508}
509
Douglas Gregora71d8192009-09-04 17:36:40 +0000510void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
511 VisitExpr(S);
512 ID.AddBoolean(S->isArrow());
513 VisitNestedNameSpecifier(S->getQualifier());
514 VisitType(S->getDestroyedType());
515}
516
Mike Stump1eb44332009-09-09 15:08:12 +0000517void
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000518StmtProfiler::VisitUnresolvedFunctionNameExpr(UnresolvedFunctionNameExpr *S) {
519 VisitExpr(S);
520 VisitName(S->getName());
521}
522
523void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
524 VisitExpr(S);
525 ID.AddInteger(S->getTrait());
526 VisitType(S->getQueriedType());
527}
528
John McCall865d4472009-11-19 22:55:06 +0000529void
530StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000531 VisitExpr(S);
532 VisitName(S->getDeclName());
533 VisitNestedNameSpecifier(S->getQualifier());
534 ID.AddBoolean(S->isAddressOfOperand());
535}
536
537void StmtProfiler::VisitTemplateIdRefExpr(TemplateIdRefExpr *S) {
538 VisitExpr(S);
539 VisitNestedNameSpecifier(S->getQualifier());
540 VisitTemplateName(S->getTemplateName());
541 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
542}
543
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000544void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) {
545 VisitExpr(S);
546 ID.AddBoolean(S->shouldDestroyTemporaries());
547 for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I)
548 VisitDecl(
549 const_cast<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor()));
550}
551
Mike Stump1eb44332009-09-09 15:08:12 +0000552void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000553StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
554 VisitExpr(S);
555 VisitType(S->getTypeAsWritten());
556}
557
John McCall865d4472009-11-19 22:55:06 +0000558void
559StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000560 VisitExpr(S);
561 ID.AddBoolean(S->isArrow());
Douglas Gregora38c6872009-09-03 16:14:30 +0000562 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000563 VisitName(S->getMember());
564}
565
566void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
567 VisitExpr(S);
568}
569
570void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
571 VisitExpr(S);
572 VisitType(S->getEncodedType());
573}
574
575void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
576 VisitExpr(S);
577 VisitName(S->getSelector());
578}
579
580void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
581 VisitExpr(S);
582 VisitDecl(S->getProtocol());
583}
584
585void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
586 VisitExpr(S);
587 VisitDecl(S->getDecl());
588 ID.AddBoolean(S->isArrow());
589 ID.AddBoolean(S->isFreeIvar());
590}
591
592void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
593 VisitExpr(S);
594 VisitDecl(S->getProperty());
595}
596
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000597void StmtProfiler::VisitObjCImplicitSetterGetterRefExpr(
598 ObjCImplicitSetterGetterRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000599 VisitExpr(S);
600 VisitDecl(S->getGetterMethod());
601 VisitDecl(S->getSetterMethod());
Fariborz Jahaniand2ae5aa2009-08-18 21:37:33 +0000602 VisitDecl(S->getInterfaceDecl());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000603}
604
605void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
606 VisitExpr(S);
607 VisitName(S->getSelector());
608 VisitDecl(S->getMethodDecl());
609}
610
611void StmtProfiler::VisitObjCSuperExpr(ObjCSuperExpr *S) {
612 VisitExpr(S);
613}
614
615void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
616 VisitExpr(S);
617 ID.AddBoolean(S->isArrow());
618}
619
Douglas Gregord584eb22009-07-28 15:32:17 +0000620void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000621 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000622
Douglas Gregorb1975722009-07-30 23:18:24 +0000623 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000624 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000625 ID.AddInteger(NTTP->getDepth());
626 ID.AddInteger(NTTP->getIndex());
Douglas Gregor828e2262009-07-29 16:09:57 +0000627 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000628 return;
629 }
Mike Stump1eb44332009-09-09 15:08:12 +0000630
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000631 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
632 // The Itanium C++ ABI uses the type of a parameter when mangling
633 // expressions that involve function parameters, so we will use the
634 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000635 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000636 // matches the definition of "equivalent" used for name mangling.
637 VisitType(Parm->getType());
638 return;
639 }
Mike Stump1eb44332009-09-09 15:08:12 +0000640
Douglas Gregora2ffb982009-07-31 15:46:56 +0000641 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
642 ID.AddInteger(TTP->getDepth());
643 ID.AddInteger(TTP->getIndex());
644 return;
645 }
Mike Stump1eb44332009-09-09 15:08:12 +0000646
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000647 if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000648 // The Itanium C++ ABI mangles references to a set of overloaded
Douglas Gregor6f2c46b2009-07-31 16:07:31 +0000649 // functions using just the function name, so we do the same here.
650 VisitName(Ovl->getDeclName());
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000651 return;
652 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000653 }
Mike Stump1eb44332009-09-09 15:08:12 +0000654
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);
Mike Stump1eb44332009-09-09 15:08:12 +0000661
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);
Mike Stump1eb44332009-09-09 15:08:12 +0000678
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000679 Name.Profile(ID);
680}
681
John McCall833ca992009-10-29 08:12:44 +0000682void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000683 unsigned NumArgs) {
684 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000685 for (unsigned I = 0; I != NumArgs; ++I)
686 VisitTemplateArgument(Args[I].getArgument());
687}
Mike Stump1eb44332009-09-09 15:08:12 +0000688
John McCall833ca992009-10-29 08:12:44 +0000689void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
690 // Mostly repetitive with TemplateArgument::Profile!
691 ID.AddInteger(Arg.getKind());
692 switch (Arg.getKind()) {
693 case TemplateArgument::Null:
694 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000695
John McCall833ca992009-10-29 08:12:44 +0000696 case TemplateArgument::Type:
697 VisitType(Arg.getAsType());
698 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000699
Douglas Gregor788cd062009-11-11 01:00:40 +0000700 case TemplateArgument::Template:
701 VisitTemplateName(Arg.getAsTemplate());
702 break;
703
John McCall833ca992009-10-29 08:12:44 +0000704 case TemplateArgument::Declaration:
705 VisitDecl(Arg.getAsDecl());
706 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000707
John McCall833ca992009-10-29 08:12:44 +0000708 case TemplateArgument::Integral:
709 Arg.getAsIntegral()->Profile(ID);
710 VisitType(Arg.getIntegralType());
711 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000712
John McCall833ca992009-10-29 08:12:44 +0000713 case TemplateArgument::Expression:
714 Visit(Arg.getAsExpr());
715 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000716
John McCall833ca992009-10-29 08:12:44 +0000717 case TemplateArgument::Pack:
718 const TemplateArgument *Pack = Arg.pack_begin();
719 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
720 VisitTemplateArgument(Pack[i]);
721 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000722 }
723}
724
725void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
726 bool Canonical) {
727 StmtProfiler Profiler(ID, Context, Canonical);
728 Profiler.Visit(this);
729}