blob: 1b6b022901e90d66ec411bfbb312b65cbbc9c2d9 [file] [log] [blame]
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001//===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt::Profile method, which builds a unique bit
Douglas Gregor00aa3a62009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor41ef0c32009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregor071f4eb2009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000017#include "clang/AST/DeclTemplate.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/ExprCXX.h"
20#include "clang/AST/ExprObjC.h"
21#include "clang/AST/StmtVisitor.h"
22#include "llvm/ADT/FoldingSet.h"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000023using namespace clang;
24
25namespace {
Benjamin Kramer770b4a82009-11-28 19:03:38 +000026 class StmtProfiler : public StmtVisitor<StmtProfiler> {
Douglas Gregor41ef0c32009-07-28 00:33:38 +000027 llvm::FoldingSetNodeID &ID;
28 ASTContext &Context;
29 bool Canonical;
Mike Stump1eb44332009-09-09 15:08:12 +000030
Douglas Gregor41ef0c32009-07-28 00:33:38 +000031 public:
32 StmtProfiler(llvm::FoldingSetNodeID &ID, ASTContext &Context,
Mike Stump1eb44332009-09-09 15:08:12 +000033 bool Canonical)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000034 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump1eb44332009-09-09 15:08:12 +000035
Douglas Gregor41ef0c32009-07-28 00:33:38 +000036 void VisitStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +000037
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000038#define STMT(Node, Base) void Visit##Node(Node *S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +000039#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +000040
Douglas Gregor41ef0c32009-07-28 00:33:38 +000041 /// \brief Visit a declaration that is referenced within an expression
42 /// or statement.
43 void VisitDecl(Decl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000044
45 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor41ef0c32009-07-28 00:33:38 +000046 /// statement.
47 void VisitType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +000048
Douglas Gregor41ef0c32009-07-28 00:33:38 +000049 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000051
Douglas Gregor41ef0c32009-07-28 00:33:38 +000052 /// \brief Visit a nested-name-specifier that occurs within an expression
53 /// or statement.
54 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump1eb44332009-09-09 15:08:12 +000055
Douglas Gregor41ef0c32009-07-28 00:33:38 +000056 /// \brief Visit a template name that occurs within an expression or
57 /// statement.
58 void VisitTemplateName(TemplateName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000059
Douglas Gregor41ef0c32009-07-28 00:33:38 +000060 /// \brief Visit template arguments that occur within an expression or
61 /// statement.
John McCall833ca992009-10-29 08:12:44 +000062 void VisitTemplateArguments(const TemplateArgumentLoc *Args, unsigned NumArgs);
63
64 /// \brief Visit a single template argument.
65 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor41ef0c32009-07-28 00:33:38 +000066 };
67}
68
69void StmtProfiler::VisitStmt(Stmt *S) {
70 ID.AddInteger(S->getStmtClass());
71 for (Stmt::child_iterator C = S->child_begin(), CEnd = S->child_end();
72 C != CEnd; ++C)
73 Visit(*C);
74}
75
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000076void StmtProfiler::VisitDeclStmt(DeclStmt *S) {
77 VisitStmt(S);
78 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
79 D != DEnd; ++D)
80 VisitDecl(*D);
81}
82
83void StmtProfiler::VisitNullStmt(NullStmt *S) {
84 VisitStmt(S);
85}
86
87void StmtProfiler::VisitCompoundStmt(CompoundStmt *S) {
88 VisitStmt(S);
89}
90
91void StmtProfiler::VisitSwitchCase(SwitchCase *S) {
92 VisitStmt(S);
93}
94
95void StmtProfiler::VisitCaseStmt(CaseStmt *S) {
96 VisitStmt(S);
97}
98
99void StmtProfiler::VisitDefaultStmt(DefaultStmt *S) {
100 VisitStmt(S);
101}
102
103void StmtProfiler::VisitLabelStmt(LabelStmt *S) {
104 VisitStmt(S);
105 VisitName(S->getID());
106}
107
108void StmtProfiler::VisitIfStmt(IfStmt *S) {
109 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000110 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000111}
112
Douglas Gregor828e2262009-07-29 16:09:57 +0000113void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
114 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000115 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000116}
117
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000118void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
119 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000120 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000121}
122
123void StmtProfiler::VisitDoStmt(DoStmt *S) {
124 VisitStmt(S);
125}
126
127void StmtProfiler::VisitForStmt(ForStmt *S) {
128 VisitStmt(S);
129}
130
131void StmtProfiler::VisitGotoStmt(GotoStmt *S) {
132 VisitStmt(S);
133 VisitName(S->getLabel()->getID());
134}
135
136void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
137 VisitStmt(S);
138}
139
140void StmtProfiler::VisitContinueStmt(ContinueStmt *S) {
141 VisitStmt(S);
142}
143
144void StmtProfiler::VisitBreakStmt(BreakStmt *S) {
145 VisitStmt(S);
146}
147
148void StmtProfiler::VisitReturnStmt(ReturnStmt *S) {
149 VisitStmt(S);
150}
151
152void StmtProfiler::VisitAsmStmt(AsmStmt *S) {
153 VisitStmt(S);
154 ID.AddBoolean(S->isVolatile());
155 ID.AddBoolean(S->isSimple());
156 VisitStringLiteral(S->getAsmString());
157 ID.AddInteger(S->getNumOutputs());
158 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
159 ID.AddString(S->getOutputName(I));
160 VisitStringLiteral(S->getOutputConstraintLiteral(I));
161 }
162 ID.AddInteger(S->getNumInputs());
163 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
164 ID.AddString(S->getInputName(I));
165 VisitStringLiteral(S->getInputConstraintLiteral(I));
166 }
167 ID.AddInteger(S->getNumClobbers());
168 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
169 VisitStringLiteral(S->getClobber(I));
170}
171
172void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) {
173 VisitStmt(S);
174 VisitType(S->getCaughtType());
175}
176
177void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) {
178 VisitStmt(S);
179}
180
181void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
182 VisitStmt(S);
183}
184
185void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
186 VisitStmt(S);
187 ID.AddBoolean(S->hasEllipsis());
188 if (S->getCatchParamDecl())
189 VisitType(S->getCatchParamDecl()->getType());
190}
191
192void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
193 VisitStmt(S);
194}
195
196void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
197 VisitStmt(S);
198}
199
200void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
201 VisitStmt(S);
202}
203
204void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
205 VisitStmt(S);
206}
207
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000208void StmtProfiler::VisitExpr(Expr *S) {
209 VisitStmt(S);
210}
211
212void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
213 VisitExpr(S);
Douglas Gregora2813ce2009-10-23 18:54:35 +0000214 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000215 VisitDecl(S->getDecl());
Douglas Gregora2813ce2009-10-23 18:54:35 +0000216 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000217}
218
219void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
220 VisitExpr(S);
221 ID.AddInteger(S->getIdentType());
222}
223
224void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
225 VisitExpr(S);
226 S->getValue().Profile(ID);
227}
228
229void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
230 VisitExpr(S);
231 ID.AddBoolean(S->isWide());
232 ID.AddInteger(S->getValue());
233}
234
235void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
236 VisitExpr(S);
237 S->getValue().Profile(ID);
238 ID.AddBoolean(S->isExact());
239}
240
241void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
242 VisitExpr(S);
243}
244
245void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
246 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000247 ID.AddString(S->getString());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000248 ID.AddBoolean(S->isWide());
249}
250
251void StmtProfiler::VisitParenExpr(ParenExpr *S) {
252 VisitExpr(S);
253}
254
Nate Begeman2ef13e52009-08-10 23:49:36 +0000255void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
256 VisitExpr(S);
257}
258
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000259void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
260 VisitExpr(S);
261 ID.AddInteger(S->getOpcode());
262}
263
264void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
265 VisitExpr(S);
266 ID.AddBoolean(S->isSizeOf());
267 if (S->isArgumentType())
268 VisitType(S->getArgumentType());
269}
270
271void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
272 VisitExpr(S);
273}
274
275void StmtProfiler::VisitCallExpr(CallExpr *S) {
276 VisitExpr(S);
277}
278
279void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
280 VisitExpr(S);
281 VisitDecl(S->getMemberDecl());
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000282 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000283 ID.AddBoolean(S->isArrow());
284}
285
286void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
287 VisitExpr(S);
288 ID.AddBoolean(S->isFileScope());
289}
290
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000291void StmtProfiler::VisitCastExpr(CastExpr *S) {
292 VisitExpr(S);
293}
294
295void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
296 VisitCastExpr(S);
297 ID.AddBoolean(S->isLvalueCast());
298}
299
300void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
301 VisitCastExpr(S);
302 VisitType(S->getTypeAsWritten());
303}
304
305void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
306 VisitExplicitCastExpr(S);
307}
308
309void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
310 VisitExpr(S);
311 ID.AddInteger(S->getOpcode());
312}
313
314void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
315 VisitBinaryOperator(S);
316}
317
318void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
319 VisitExpr(S);
320}
321
322void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
323 VisitExpr(S);
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000324 VisitName(S->getLabel()->getID());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000325}
326
327void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
328 VisitExpr(S);
329}
330
331void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) {
332 VisitExpr(S);
333 VisitType(S->getArgType1());
334 VisitType(S->getArgType2());
335}
336
337void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
338 VisitExpr(S);
339}
340
341void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
342 VisitExpr(S);
343}
344
345void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
346 VisitExpr(S);
347}
348
Douglas Gregor828e2262009-07-29 16:09:57 +0000349void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
350 VisitExpr(S);
351}
352
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000353void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
354 if (S->getSyntacticForm()) {
355 VisitInitListExpr(S->getSyntacticForm());
356 return;
357 }
Mike Stump1eb44332009-09-09 15:08:12 +0000358
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000359 VisitExpr(S);
360}
361
362void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
363 VisitExpr(S);
364 ID.AddBoolean(S->usesGNUSyntax());
365 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
366 DEnd = S->designators_end();
367 D != DEnd; ++D) {
368 if (D->isFieldDesignator()) {
369 ID.AddInteger(0);
370 VisitName(D->getFieldName());
371 continue;
372 }
Mike Stump1eb44332009-09-09 15:08:12 +0000373
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000374 if (D->isArrayDesignator()) {
375 ID.AddInteger(1);
376 } else {
377 assert(D->isArrayRangeDesignator());
378 ID.AddInteger(2);
379 }
380 ID.AddInteger(D->getFirstExprIndex());
381 }
382}
383
384void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
385 VisitExpr(S);
386}
387
388void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
389 VisitExpr(S);
390 VisitName(&S->getAccessor());
391}
392
393void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
394 VisitExpr(S);
395 VisitDecl(S->getBlockDecl());
396}
397
398void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
399 VisitExpr(S);
400 VisitDecl(S->getDecl());
401 ID.AddBoolean(S->isByRef());
402 ID.AddBoolean(S->isConstQualAdded());
403}
404
405void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
406 VisitCallExpr(S);
407 ID.AddInteger(S->getOperator());
408}
409
410void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
411 VisitCallExpr(S);
412}
413
414void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
415 VisitExplicitCastExpr(S);
416}
417
418void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
419 VisitCXXNamedCastExpr(S);
420}
421
422void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
423 VisitCXXNamedCastExpr(S);
424}
425
426void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
427 VisitCXXNamedCastExpr(S);
428}
429
430void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
431 VisitCXXNamedCastExpr(S);
432}
433
434void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
435 VisitExpr(S);
436 ID.AddBoolean(S->getValue());
437}
438
Douglas Gregor828e2262009-07-29 16:09:57 +0000439void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
440 VisitExpr(S);
441}
442
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000443void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
444 VisitExpr(S);
445 if (S->isTypeOperand())
446 VisitType(S->getTypeOperand());
447}
448
449void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
450 VisitExpr(S);
451}
452
453void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
454 VisitExpr(S);
455}
456
457void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
458 VisitExpr(S);
459 VisitDecl(S->getParam());
460}
461
462void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
463 VisitExpr(S);
464 VisitDecl(
465 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
466}
467
468void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
469 VisitExpr(S);
470 VisitDecl(S->getConstructor());
471 ID.AddBoolean(S->isElidable());
472}
473
474void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
475 VisitExplicitCastExpr(S);
476}
477
478void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
479 VisitCXXConstructExpr(S);
480}
481
482void StmtProfiler::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *S) {
483 VisitExpr(S);
484}
485
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000486void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
487 VisitExpr(S);
488 ID.AddBoolean(S->isGlobalDelete());
489 ID.AddBoolean(S->isArrayForm());
490 VisitDecl(S->getOperatorDelete());
491}
492
493
494void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
495 VisitExpr(S);
496 VisitType(S->getAllocatedType());
497 VisitDecl(S->getOperatorNew());
498 VisitDecl(S->getOperatorDelete());
499 VisitDecl(S->getConstructor());
500 ID.AddBoolean(S->isArray());
501 ID.AddInteger(S->getNumPlacementArgs());
502 ID.AddBoolean(S->isGlobalNew());
503 ID.AddBoolean(S->isParenTypeId());
504 ID.AddBoolean(S->hasInitializer());
505 ID.AddInteger(S->getNumConstructorArgs());
506}
507
Douglas Gregora71d8192009-09-04 17:36:40 +0000508void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
509 VisitExpr(S);
510 ID.AddBoolean(S->isArrow());
511 VisitNestedNameSpecifier(S->getQualifier());
512 VisitType(S->getDestroyedType());
513}
514
Mike Stump1eb44332009-09-09 15:08:12 +0000515void
John McCallba135432009-11-21 08:51:07 +0000516StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000517 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000518 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000519 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000520 ID.AddBoolean(S->hasExplicitTemplateArgs());
521 if (S->hasExplicitTemplateArgs())
522 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000523}
524
525void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
526 VisitExpr(S);
527 ID.AddInteger(S->getTrait());
528 VisitType(S->getQueriedType());
529}
530
John McCall865d4472009-11-19 22:55:06 +0000531void
532StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000533 VisitExpr(S);
534 VisitName(S->getDeclName());
535 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000536 ID.AddBoolean(S->hasExplicitTemplateArgs());
537 if (S->hasExplicitTemplateArgs())
538 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000539}
540
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000541void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) {
542 VisitExpr(S);
543 ID.AddBoolean(S->shouldDestroyTemporaries());
544 for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I)
545 VisitDecl(
546 const_cast<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor()));
547}
548
Mike Stump1eb44332009-09-09 15:08:12 +0000549void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000550StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
551 VisitExpr(S);
552 VisitType(S->getTypeAsWritten());
553}
554
John McCall865d4472009-11-19 22:55:06 +0000555void
556StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000557 ID.AddBoolean(S->isImplicitAccess());
558 if (!S->isImplicitAccess()) {
559 VisitExpr(S);
560 ID.AddBoolean(S->isArrow());
561 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000562 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000563 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000564 ID.AddBoolean(S->hasExplicitTemplateArgs());
565 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000566 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
567}
568
569void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000570 ID.AddBoolean(S->isImplicitAccess());
571 if (!S->isImplicitAccess()) {
572 VisitExpr(S);
573 ID.AddBoolean(S->isArrow());
574 }
John McCall129e2df2009-11-30 22:42:35 +0000575 VisitNestedNameSpecifier(S->getQualifier());
576 VisitName(S->getMemberName());
577 ID.AddBoolean(S->hasExplicitTemplateArgs());
578 if (S->hasExplicitTemplateArgs())
579 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000580}
581
582void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
583 VisitExpr(S);
584}
585
586void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
587 VisitExpr(S);
588 VisitType(S->getEncodedType());
589}
590
591void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
592 VisitExpr(S);
593 VisitName(S->getSelector());
594}
595
596void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
597 VisitExpr(S);
598 VisitDecl(S->getProtocol());
599}
600
601void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
602 VisitExpr(S);
603 VisitDecl(S->getDecl());
604 ID.AddBoolean(S->isArrow());
605 ID.AddBoolean(S->isFreeIvar());
606}
607
608void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
609 VisitExpr(S);
610 VisitDecl(S->getProperty());
611}
612
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000613void StmtProfiler::VisitObjCImplicitSetterGetterRefExpr(
614 ObjCImplicitSetterGetterRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000615 VisitExpr(S);
616 VisitDecl(S->getGetterMethod());
617 VisitDecl(S->getSetterMethod());
Fariborz Jahaniand2ae5aa2009-08-18 21:37:33 +0000618 VisitDecl(S->getInterfaceDecl());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000619}
620
621void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
622 VisitExpr(S);
623 VisitName(S->getSelector());
624 VisitDecl(S->getMethodDecl());
625}
626
627void StmtProfiler::VisitObjCSuperExpr(ObjCSuperExpr *S) {
628 VisitExpr(S);
629}
630
631void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
632 VisitExpr(S);
633 ID.AddBoolean(S->isArrow());
634}
635
Douglas Gregord584eb22009-07-28 15:32:17 +0000636void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000637 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000638
Douglas Gregorb1975722009-07-30 23:18:24 +0000639 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000640 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000641 ID.AddInteger(NTTP->getDepth());
642 ID.AddInteger(NTTP->getIndex());
Douglas Gregor828e2262009-07-29 16:09:57 +0000643 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000644 return;
645 }
Mike Stump1eb44332009-09-09 15:08:12 +0000646
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000647 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
648 // The Itanium C++ ABI uses the type of a parameter when mangling
649 // expressions that involve function parameters, so we will use the
650 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000651 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000652 // matches the definition of "equivalent" used for name mangling.
653 VisitType(Parm->getType());
654 return;
655 }
Mike Stump1eb44332009-09-09 15:08:12 +0000656
Douglas Gregora2ffb982009-07-31 15:46:56 +0000657 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
658 ID.AddInteger(TTP->getDepth());
659 ID.AddInteger(TTP->getIndex());
660 return;
661 }
Mike Stump1eb44332009-09-09 15:08:12 +0000662
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000663 if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000664 // The Itanium C++ ABI mangles references to a set of overloaded
Douglas Gregor6f2c46b2009-07-31 16:07:31 +0000665 // functions using just the function name, so we do the same here.
666 VisitName(Ovl->getDeclName());
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000667 return;
668 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000669 }
Mike Stump1eb44332009-09-09 15:08:12 +0000670
Douglas Gregord584eb22009-07-28 15:32:17 +0000671 ID.AddPointer(D? D->getCanonicalDecl() : 0);
672}
673
674void StmtProfiler::VisitType(QualType T) {
675 if (Canonical)
676 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000677
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000678 ID.AddPointer(T.getAsOpaquePtr());
679}
680
681void StmtProfiler::VisitName(DeclarationName Name) {
682 ID.AddPointer(Name.getAsOpaquePtr());
683}
684
685void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
686 if (Canonical)
687 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
688 ID.AddPointer(NNS);
689}
690
691void StmtProfiler::VisitTemplateName(TemplateName Name) {
692 if (Canonical)
693 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000694
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000695 Name.Profile(ID);
696}
697
John McCall833ca992009-10-29 08:12:44 +0000698void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000699 unsigned NumArgs) {
700 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000701 for (unsigned I = 0; I != NumArgs; ++I)
702 VisitTemplateArgument(Args[I].getArgument());
703}
Mike Stump1eb44332009-09-09 15:08:12 +0000704
John McCall833ca992009-10-29 08:12:44 +0000705void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
706 // Mostly repetitive with TemplateArgument::Profile!
707 ID.AddInteger(Arg.getKind());
708 switch (Arg.getKind()) {
709 case TemplateArgument::Null:
710 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000711
John McCall833ca992009-10-29 08:12:44 +0000712 case TemplateArgument::Type:
713 VisitType(Arg.getAsType());
714 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000715
Douglas Gregor788cd062009-11-11 01:00:40 +0000716 case TemplateArgument::Template:
717 VisitTemplateName(Arg.getAsTemplate());
718 break;
719
John McCall833ca992009-10-29 08:12:44 +0000720 case TemplateArgument::Declaration:
721 VisitDecl(Arg.getAsDecl());
722 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000723
John McCall833ca992009-10-29 08:12:44 +0000724 case TemplateArgument::Integral:
725 Arg.getAsIntegral()->Profile(ID);
726 VisitType(Arg.getIntegralType());
727 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000728
John McCall833ca992009-10-29 08:12:44 +0000729 case TemplateArgument::Expression:
730 Visit(Arg.getAsExpr());
731 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000732
John McCall833ca992009-10-29 08:12:44 +0000733 case TemplateArgument::Pack:
734 const TemplateArgument *Pack = Arg.pack_begin();
735 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
736 VisitTemplateArgument(Pack[i]);
737 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000738 }
739}
740
741void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
742 bool Canonical) {
743 StmtProfiler Profiler(ID, Context, Canonical);
744 Profiler.Visit(this);
745}