blob: 201724e8617b953dc3acbfa6ccb11fd813fe0eb0 [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);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000111 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000112}
113
Douglas Gregor828e2262009-07-29 16:09:57 +0000114void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
115 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000116 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000117}
118
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000119void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
120 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000121 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000122}
123
124void StmtProfiler::VisitDoStmt(DoStmt *S) {
125 VisitStmt(S);
126}
127
128void StmtProfiler::VisitForStmt(ForStmt *S) {
129 VisitStmt(S);
130}
131
132void StmtProfiler::VisitGotoStmt(GotoStmt *S) {
133 VisitStmt(S);
134 VisitName(S->getLabel()->getID());
135}
136
137void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
138 VisitStmt(S);
139}
140
141void StmtProfiler::VisitContinueStmt(ContinueStmt *S) {
142 VisitStmt(S);
143}
144
145void StmtProfiler::VisitBreakStmt(BreakStmt *S) {
146 VisitStmt(S);
147}
148
149void StmtProfiler::VisitReturnStmt(ReturnStmt *S) {
150 VisitStmt(S);
151}
152
153void StmtProfiler::VisitAsmStmt(AsmStmt *S) {
154 VisitStmt(S);
155 ID.AddBoolean(S->isVolatile());
156 ID.AddBoolean(S->isSimple());
157 VisitStringLiteral(S->getAsmString());
158 ID.AddInteger(S->getNumOutputs());
159 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
160 ID.AddString(S->getOutputName(I));
161 VisitStringLiteral(S->getOutputConstraintLiteral(I));
162 }
163 ID.AddInteger(S->getNumInputs());
164 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
165 ID.AddString(S->getInputName(I));
166 VisitStringLiteral(S->getInputConstraintLiteral(I));
167 }
168 ID.AddInteger(S->getNumClobbers());
169 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
170 VisitStringLiteral(S->getClobber(I));
171}
172
173void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) {
174 VisitStmt(S);
175 VisitType(S->getCaughtType());
176}
177
178void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) {
179 VisitStmt(S);
180}
181
182void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
183 VisitStmt(S);
184}
185
186void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
187 VisitStmt(S);
188 ID.AddBoolean(S->hasEllipsis());
189 if (S->getCatchParamDecl())
190 VisitType(S->getCatchParamDecl()->getType());
191}
192
193void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
194 VisitStmt(S);
195}
196
197void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
198 VisitStmt(S);
199}
200
201void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
202 VisitStmt(S);
203}
204
205void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
206 VisitStmt(S);
207}
208
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000209void StmtProfiler::VisitExpr(Expr *S) {
210 VisitStmt(S);
211}
212
213void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
214 VisitExpr(S);
Douglas Gregora2813ce2009-10-23 18:54:35 +0000215 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000216 VisitDecl(S->getDecl());
Douglas Gregora2813ce2009-10-23 18:54:35 +0000217 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
265void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
266 VisitExpr(S);
267 ID.AddBoolean(S->isSizeOf());
268 if (S->isArgumentType())
269 VisitType(S->getArgumentType());
270}
271
272void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
273 VisitExpr(S);
274}
275
276void StmtProfiler::VisitCallExpr(CallExpr *S) {
277 VisitExpr(S);
278}
279
280void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
281 VisitExpr(S);
282 VisitDecl(S->getMemberDecl());
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000283 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000284 ID.AddBoolean(S->isArrow());
285}
286
287void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
288 VisitExpr(S);
289 ID.AddBoolean(S->isFileScope());
290}
291
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000292void StmtProfiler::VisitCastExpr(CastExpr *S) {
293 VisitExpr(S);
294}
295
296void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
297 VisitCastExpr(S);
298 ID.AddBoolean(S->isLvalueCast());
299}
300
301void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
302 VisitCastExpr(S);
303 VisitType(S->getTypeAsWritten());
304}
305
306void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
307 VisitExplicitCastExpr(S);
308}
309
310void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
311 VisitExpr(S);
312 ID.AddInteger(S->getOpcode());
313}
314
315void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
316 VisitBinaryOperator(S);
317}
318
319void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
320 VisitExpr(S);
321}
322
323void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
324 VisitExpr(S);
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000325 VisitName(S->getLabel()->getID());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000326}
327
328void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
329 VisitExpr(S);
330}
331
332void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) {
333 VisitExpr(S);
334 VisitType(S->getArgType1());
335 VisitType(S->getArgType2());
336}
337
338void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
339 VisitExpr(S);
340}
341
342void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
343 VisitExpr(S);
344}
345
346void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
347 VisitExpr(S);
348}
349
Douglas Gregor828e2262009-07-29 16:09:57 +0000350void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
351 VisitExpr(S);
352}
353
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000354void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
355 if (S->getSyntacticForm()) {
356 VisitInitListExpr(S->getSyntacticForm());
357 return;
358 }
Mike Stump1eb44332009-09-09 15:08:12 +0000359
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000360 VisitExpr(S);
361}
362
363void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
364 VisitExpr(S);
365 ID.AddBoolean(S->usesGNUSyntax());
366 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
367 DEnd = S->designators_end();
368 D != DEnd; ++D) {
369 if (D->isFieldDesignator()) {
370 ID.AddInteger(0);
371 VisitName(D->getFieldName());
372 continue;
373 }
Mike Stump1eb44332009-09-09 15:08:12 +0000374
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000375 if (D->isArrayDesignator()) {
376 ID.AddInteger(1);
377 } else {
378 assert(D->isArrayRangeDesignator());
379 ID.AddInteger(2);
380 }
381 ID.AddInteger(D->getFirstExprIndex());
382 }
383}
384
385void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
386 VisitExpr(S);
387}
388
389void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
390 VisitExpr(S);
391 VisitName(&S->getAccessor());
392}
393
394void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
395 VisitExpr(S);
396 VisitDecl(S->getBlockDecl());
397}
398
399void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
400 VisitExpr(S);
401 VisitDecl(S->getDecl());
402 ID.AddBoolean(S->isByRef());
403 ID.AddBoolean(S->isConstQualAdded());
404}
405
406void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
407 VisitCallExpr(S);
408 ID.AddInteger(S->getOperator());
409}
410
411void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
412 VisitCallExpr(S);
413}
414
415void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
416 VisitExplicitCastExpr(S);
417}
418
419void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
420 VisitCXXNamedCastExpr(S);
421}
422
423void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
424 VisitCXXNamedCastExpr(S);
425}
426
427void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
428 VisitCXXNamedCastExpr(S);
429}
430
431void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
432 VisitCXXNamedCastExpr(S);
433}
434
435void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
436 VisitExpr(S);
437 ID.AddBoolean(S->getValue());
438}
439
Douglas Gregor828e2262009-07-29 16:09:57 +0000440void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
441 VisitExpr(S);
442}
443
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000444void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
445 VisitExpr(S);
446 if (S->isTypeOperand())
447 VisitType(S->getTypeOperand());
448}
449
450void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
451 VisitExpr(S);
452}
453
454void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
455 VisitExpr(S);
456}
457
458void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
459 VisitExpr(S);
460 VisitDecl(S->getParam());
461}
462
463void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
464 VisitExpr(S);
465 VisitDecl(
466 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
467}
468
469void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
470 VisitExpr(S);
471 VisitDecl(S->getConstructor());
472 ID.AddBoolean(S->isElidable());
473}
474
475void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
476 VisitExplicitCastExpr(S);
477}
478
479void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
480 VisitCXXConstructExpr(S);
481}
482
483void StmtProfiler::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *S) {
484 VisitExpr(S);
485}
486
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000487void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
488 VisitExpr(S);
489 ID.AddBoolean(S->isGlobalDelete());
490 ID.AddBoolean(S->isArrayForm());
491 VisitDecl(S->getOperatorDelete());
492}
493
494
495void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
496 VisitExpr(S);
497 VisitType(S->getAllocatedType());
498 VisitDecl(S->getOperatorNew());
499 VisitDecl(S->getOperatorDelete());
500 VisitDecl(S->getConstructor());
501 ID.AddBoolean(S->isArray());
502 ID.AddInteger(S->getNumPlacementArgs());
503 ID.AddBoolean(S->isGlobalNew());
504 ID.AddBoolean(S->isParenTypeId());
505 ID.AddBoolean(S->hasInitializer());
506 ID.AddInteger(S->getNumConstructorArgs());
507}
508
Douglas Gregora71d8192009-09-04 17:36:40 +0000509void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
510 VisitExpr(S);
511 ID.AddBoolean(S->isArrow());
512 VisitNestedNameSpecifier(S->getQualifier());
513 VisitType(S->getDestroyedType());
514}
515
Mike Stump1eb44332009-09-09 15:08:12 +0000516void
John McCallba135432009-11-21 08:51:07 +0000517StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000518 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000519 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000520 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000521 ID.AddBoolean(S->hasExplicitTemplateArgs());
522 if (S->hasExplicitTemplateArgs())
523 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000524}
525
526void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
527 VisitExpr(S);
528 ID.AddInteger(S->getTrait());
529 VisitType(S->getQueriedType());
530}
531
John McCall865d4472009-11-19 22:55:06 +0000532void
533StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000534 VisitExpr(S);
535 VisitName(S->getDeclName());
536 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000537 ID.AddBoolean(S->hasExplicitTemplateArgs());
538 if (S->hasExplicitTemplateArgs())
539 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000540}
541
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000542void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) {
543 VisitExpr(S);
544 ID.AddBoolean(S->shouldDestroyTemporaries());
545 for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I)
546 VisitDecl(
547 const_cast<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor()));
548}
549
Mike Stump1eb44332009-09-09 15:08:12 +0000550void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000551StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
552 VisitExpr(S);
553 VisitType(S->getTypeAsWritten());
554}
555
John McCall865d4472009-11-19 22:55:06 +0000556void
557StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000558 VisitExpr(S);
559 ID.AddBoolean(S->isArrow());
Douglas Gregora38c6872009-09-03 16:14:30 +0000560 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000561 VisitName(S->getMember());
562}
563
564void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
565 VisitExpr(S);
566}
567
568void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
569 VisitExpr(S);
570 VisitType(S->getEncodedType());
571}
572
573void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
574 VisitExpr(S);
575 VisitName(S->getSelector());
576}
577
578void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
579 VisitExpr(S);
580 VisitDecl(S->getProtocol());
581}
582
583void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
584 VisitExpr(S);
585 VisitDecl(S->getDecl());
586 ID.AddBoolean(S->isArrow());
587 ID.AddBoolean(S->isFreeIvar());
588}
589
590void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
591 VisitExpr(S);
592 VisitDecl(S->getProperty());
593}
594
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000595void StmtProfiler::VisitObjCImplicitSetterGetterRefExpr(
596 ObjCImplicitSetterGetterRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000597 VisitExpr(S);
598 VisitDecl(S->getGetterMethod());
599 VisitDecl(S->getSetterMethod());
Fariborz Jahaniand2ae5aa2009-08-18 21:37:33 +0000600 VisitDecl(S->getInterfaceDecl());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000601}
602
603void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
604 VisitExpr(S);
605 VisitName(S->getSelector());
606 VisitDecl(S->getMethodDecl());
607}
608
609void StmtProfiler::VisitObjCSuperExpr(ObjCSuperExpr *S) {
610 VisitExpr(S);
611}
612
613void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
614 VisitExpr(S);
615 ID.AddBoolean(S->isArrow());
616}
617
Douglas Gregord584eb22009-07-28 15:32:17 +0000618void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000619 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000620
Douglas Gregorb1975722009-07-30 23:18:24 +0000621 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000622 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000623 ID.AddInteger(NTTP->getDepth());
624 ID.AddInteger(NTTP->getIndex());
Douglas Gregor828e2262009-07-29 16:09:57 +0000625 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000626 return;
627 }
Mike Stump1eb44332009-09-09 15:08:12 +0000628
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000629 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
630 // The Itanium C++ ABI uses the type of a parameter when mangling
631 // expressions that involve function parameters, so we will use the
632 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000633 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000634 // matches the definition of "equivalent" used for name mangling.
635 VisitType(Parm->getType());
636 return;
637 }
Mike Stump1eb44332009-09-09 15:08:12 +0000638
Douglas Gregora2ffb982009-07-31 15:46:56 +0000639 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
640 ID.AddInteger(TTP->getDepth());
641 ID.AddInteger(TTP->getIndex());
642 return;
643 }
Mike Stump1eb44332009-09-09 15:08:12 +0000644
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000645 if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000646 // The Itanium C++ ABI mangles references to a set of overloaded
Douglas Gregor6f2c46b2009-07-31 16:07:31 +0000647 // functions using just the function name, so we do the same here.
648 VisitName(Ovl->getDeclName());
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000649 return;
650 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000651 }
Mike Stump1eb44332009-09-09 15:08:12 +0000652
Douglas Gregord584eb22009-07-28 15:32:17 +0000653 ID.AddPointer(D? D->getCanonicalDecl() : 0);
654}
655
656void StmtProfiler::VisitType(QualType T) {
657 if (Canonical)
658 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000659
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000660 ID.AddPointer(T.getAsOpaquePtr());
661}
662
663void StmtProfiler::VisitName(DeclarationName Name) {
664 ID.AddPointer(Name.getAsOpaquePtr());
665}
666
667void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
668 if (Canonical)
669 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
670 ID.AddPointer(NNS);
671}
672
673void StmtProfiler::VisitTemplateName(TemplateName Name) {
674 if (Canonical)
675 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000676
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000677 Name.Profile(ID);
678}
679
John McCall833ca992009-10-29 08:12:44 +0000680void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000681 unsigned NumArgs) {
682 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000683 for (unsigned I = 0; I != NumArgs; ++I)
684 VisitTemplateArgument(Args[I].getArgument());
685}
Mike Stump1eb44332009-09-09 15:08:12 +0000686
John McCall833ca992009-10-29 08:12:44 +0000687void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
688 // Mostly repetitive with TemplateArgument::Profile!
689 ID.AddInteger(Arg.getKind());
690 switch (Arg.getKind()) {
691 case TemplateArgument::Null:
692 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000693
John McCall833ca992009-10-29 08:12:44 +0000694 case TemplateArgument::Type:
695 VisitType(Arg.getAsType());
696 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor788cd062009-11-11 01:00:40 +0000698 case TemplateArgument::Template:
699 VisitTemplateName(Arg.getAsTemplate());
700 break;
701
John McCall833ca992009-10-29 08:12:44 +0000702 case TemplateArgument::Declaration:
703 VisitDecl(Arg.getAsDecl());
704 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000705
John McCall833ca992009-10-29 08:12:44 +0000706 case TemplateArgument::Integral:
707 Arg.getAsIntegral()->Profile(ID);
708 VisitType(Arg.getIntegralType());
709 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000710
John McCall833ca992009-10-29 08:12:44 +0000711 case TemplateArgument::Expression:
712 Visit(Arg.getAsExpr());
713 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000714
John McCall833ca992009-10-29 08:12:44 +0000715 case TemplateArgument::Pack:
716 const TemplateArgument *Pack = Arg.pack_begin();
717 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
718 VisitTemplateArgument(Pack[i]);
719 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000720 }
721}
722
723void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
724 bool Canonical) {
725 StmtProfiler Profiler(ID, Context, Canonical);
726 Profiler.Visit(this);
727}