blob: 6938d71df484157832ce2091d7a88c56ff264b03 [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);
Sean Hunt4bfe1962010-05-05 15:24:00 +000039#include "clang/AST/StmtNodes.inc"
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
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000264void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
265 VisitType(S->getTypeSourceInfo()->getType());
266 unsigned n = S->getNumComponents();
267 for (unsigned i = 0; i < n; ++i) {
268 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
269 ID.AddInteger(ON.getKind());
270 switch (ON.getKind()) {
271 case OffsetOfExpr::OffsetOfNode::Array:
272 // Expressions handled below.
273 break;
274
275 case OffsetOfExpr::OffsetOfNode::Field:
276 VisitDecl(ON.getField());
277 break;
278
279 case OffsetOfExpr::OffsetOfNode::Identifier:
280 ID.AddPointer(ON.getFieldName());
281 break;
Sean Huntc3021132010-05-05 15:23:54 +0000282
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000283 case OffsetOfExpr::OffsetOfNode::Base:
284 // These nodes are implicit, and therefore don't need profiling.
285 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000286 }
287 }
Sean Huntc3021132010-05-05 15:23:54 +0000288
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000289 VisitExpr(S);
290}
291
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000292void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
293 VisitExpr(S);
294 ID.AddBoolean(S->isSizeOf());
295 if (S->isArgumentType())
296 VisitType(S->getArgumentType());
297}
298
299void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
300 VisitExpr(S);
301}
302
303void StmtProfiler::VisitCallExpr(CallExpr *S) {
304 VisitExpr(S);
305}
306
307void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
308 VisitExpr(S);
309 VisitDecl(S->getMemberDecl());
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000310 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000311 ID.AddBoolean(S->isArrow());
312}
313
314void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
315 VisitExpr(S);
316 ID.AddBoolean(S->isFileScope());
317}
318
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000319void StmtProfiler::VisitCastExpr(CastExpr *S) {
320 VisitExpr(S);
321}
322
323void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
324 VisitCastExpr(S);
325 ID.AddBoolean(S->isLvalueCast());
326}
327
328void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
329 VisitCastExpr(S);
330 VisitType(S->getTypeAsWritten());
331}
332
333void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
334 VisitExplicitCastExpr(S);
335}
336
337void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
338 VisitExpr(S);
339 ID.AddInteger(S->getOpcode());
340}
341
342void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
343 VisitBinaryOperator(S);
344}
345
346void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
347 VisitExpr(S);
348}
349
350void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
351 VisitExpr(S);
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000352 VisitName(S->getLabel()->getID());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000353}
354
355void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
356 VisitExpr(S);
357}
358
359void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) {
360 VisitExpr(S);
361 VisitType(S->getArgType1());
362 VisitType(S->getArgType2());
363}
364
365void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
366 VisitExpr(S);
367}
368
369void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
370 VisitExpr(S);
371}
372
373void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
374 VisitExpr(S);
375}
376
Douglas Gregor828e2262009-07-29 16:09:57 +0000377void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
378 VisitExpr(S);
379}
380
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000381void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
382 if (S->getSyntacticForm()) {
383 VisitInitListExpr(S->getSyntacticForm());
384 return;
385 }
Mike Stump1eb44332009-09-09 15:08:12 +0000386
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000387 VisitExpr(S);
388}
389
390void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
391 VisitExpr(S);
392 ID.AddBoolean(S->usesGNUSyntax());
393 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
394 DEnd = S->designators_end();
395 D != DEnd; ++D) {
396 if (D->isFieldDesignator()) {
397 ID.AddInteger(0);
398 VisitName(D->getFieldName());
399 continue;
400 }
Mike Stump1eb44332009-09-09 15:08:12 +0000401
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000402 if (D->isArrayDesignator()) {
403 ID.AddInteger(1);
404 } else {
405 assert(D->isArrayRangeDesignator());
406 ID.AddInteger(2);
407 }
408 ID.AddInteger(D->getFirstExprIndex());
409 }
410}
411
412void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
413 VisitExpr(S);
414}
415
416void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
417 VisitExpr(S);
418 VisitName(&S->getAccessor());
419}
420
421void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
422 VisitExpr(S);
423 VisitDecl(S->getBlockDecl());
424}
425
426void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
427 VisitExpr(S);
428 VisitDecl(S->getDecl());
429 ID.AddBoolean(S->isByRef());
430 ID.AddBoolean(S->isConstQualAdded());
431}
432
433void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
434 VisitCallExpr(S);
435 ID.AddInteger(S->getOperator());
436}
437
438void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
439 VisitCallExpr(S);
440}
441
442void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
443 VisitExplicitCastExpr(S);
444}
445
446void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
447 VisitCXXNamedCastExpr(S);
448}
449
450void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
451 VisitCXXNamedCastExpr(S);
452}
453
454void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
455 VisitCXXNamedCastExpr(S);
456}
457
458void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
459 VisitCXXNamedCastExpr(S);
460}
461
462void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
463 VisitExpr(S);
464 ID.AddBoolean(S->getValue());
465}
466
Douglas Gregor828e2262009-07-29 16:09:57 +0000467void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
468 VisitExpr(S);
469}
470
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000471void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
472 VisitExpr(S);
473 if (S->isTypeOperand())
474 VisitType(S->getTypeOperand());
475}
476
477void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
478 VisitExpr(S);
479}
480
481void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
482 VisitExpr(S);
483}
484
485void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
486 VisitExpr(S);
487 VisitDecl(S->getParam());
488}
489
490void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
491 VisitExpr(S);
492 VisitDecl(
493 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
494}
495
Anders Carlssoneb60edf2010-01-29 02:39:32 +0000496void StmtProfiler::VisitCXXBindReferenceExpr(CXXBindReferenceExpr *S) {
497 VisitExpr(S);
498}
499
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000500void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
501 VisitExpr(S);
502 VisitDecl(S->getConstructor());
503 ID.AddBoolean(S->isElidable());
504}
505
506void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
507 VisitExplicitCastExpr(S);
508}
509
510void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
511 VisitCXXConstructExpr(S);
512}
513
514void StmtProfiler::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *S) {
515 VisitExpr(S);
516}
517
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000518void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
519 VisitExpr(S);
520 ID.AddBoolean(S->isGlobalDelete());
521 ID.AddBoolean(S->isArrayForm());
522 VisitDecl(S->getOperatorDelete());
523}
524
525
526void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
527 VisitExpr(S);
528 VisitType(S->getAllocatedType());
529 VisitDecl(S->getOperatorNew());
530 VisitDecl(S->getOperatorDelete());
531 VisitDecl(S->getConstructor());
532 ID.AddBoolean(S->isArray());
533 ID.AddInteger(S->getNumPlacementArgs());
534 ID.AddBoolean(S->isGlobalNew());
535 ID.AddBoolean(S->isParenTypeId());
536 ID.AddBoolean(S->hasInitializer());
537 ID.AddInteger(S->getNumConstructorArgs());
538}
539
Douglas Gregora71d8192009-09-04 17:36:40 +0000540void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
541 VisitExpr(S);
542 ID.AddBoolean(S->isArrow());
543 VisitNestedNameSpecifier(S->getQualifier());
544 VisitType(S->getDestroyedType());
545}
546
Mike Stump1eb44332009-09-09 15:08:12 +0000547void
John McCallba135432009-11-21 08:51:07 +0000548StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000549 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000550 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000551 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000552 ID.AddBoolean(S->hasExplicitTemplateArgs());
553 if (S->hasExplicitTemplateArgs())
554 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000555}
556
557void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
558 VisitExpr(S);
559 ID.AddInteger(S->getTrait());
560 VisitType(S->getQueriedType());
561}
562
John McCall865d4472009-11-19 22:55:06 +0000563void
564StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000565 VisitExpr(S);
566 VisitName(S->getDeclName());
567 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000568 ID.AddBoolean(S->hasExplicitTemplateArgs());
569 if (S->hasExplicitTemplateArgs())
570 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000571}
572
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000573void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) {
574 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000575 for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I)
576 VisitDecl(
577 const_cast<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor()));
578}
579
Mike Stump1eb44332009-09-09 15:08:12 +0000580void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000581StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
582 VisitExpr(S);
583 VisitType(S->getTypeAsWritten());
584}
585
John McCall865d4472009-11-19 22:55:06 +0000586void
587StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000588 ID.AddBoolean(S->isImplicitAccess());
589 if (!S->isImplicitAccess()) {
590 VisitExpr(S);
591 ID.AddBoolean(S->isArrow());
592 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000593 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000594 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000595 ID.AddBoolean(S->hasExplicitTemplateArgs());
596 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000597 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
598}
599
600void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000601 ID.AddBoolean(S->isImplicitAccess());
602 if (!S->isImplicitAccess()) {
603 VisitExpr(S);
604 ID.AddBoolean(S->isArrow());
605 }
John McCall129e2df2009-11-30 22:42:35 +0000606 VisitNestedNameSpecifier(S->getQualifier());
607 VisitName(S->getMemberName());
608 ID.AddBoolean(S->hasExplicitTemplateArgs());
609 if (S->hasExplicitTemplateArgs())
610 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000611}
612
613void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
614 VisitExpr(S);
615}
616
617void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
618 VisitExpr(S);
619 VisitType(S->getEncodedType());
620}
621
622void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
623 VisitExpr(S);
624 VisitName(S->getSelector());
625}
626
627void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
628 VisitExpr(S);
629 VisitDecl(S->getProtocol());
630}
631
632void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
633 VisitExpr(S);
634 VisitDecl(S->getDecl());
635 ID.AddBoolean(S->isArrow());
636 ID.AddBoolean(S->isFreeIvar());
637}
638
639void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
640 VisitExpr(S);
641 VisitDecl(S->getProperty());
642}
643
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000644void StmtProfiler::VisitObjCImplicitSetterGetterRefExpr(
645 ObjCImplicitSetterGetterRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000646 VisitExpr(S);
647 VisitDecl(S->getGetterMethod());
648 VisitDecl(S->getSetterMethod());
Fariborz Jahaniand2ae5aa2009-08-18 21:37:33 +0000649 VisitDecl(S->getInterfaceDecl());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000650}
651
652void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
653 VisitExpr(S);
654 VisitName(S->getSelector());
655 VisitDecl(S->getMethodDecl());
656}
657
658void StmtProfiler::VisitObjCSuperExpr(ObjCSuperExpr *S) {
659 VisitExpr(S);
660}
661
662void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
663 VisitExpr(S);
664 ID.AddBoolean(S->isArrow());
665}
666
Douglas Gregord584eb22009-07-28 15:32:17 +0000667void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000668 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000669
Douglas Gregorb1975722009-07-30 23:18:24 +0000670 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000671 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000672 ID.AddInteger(NTTP->getDepth());
673 ID.AddInteger(NTTP->getIndex());
Douglas Gregor828e2262009-07-29 16:09:57 +0000674 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000675 return;
676 }
Mike Stump1eb44332009-09-09 15:08:12 +0000677
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000678 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
679 // The Itanium C++ ABI uses the type of a parameter when mangling
680 // expressions that involve function parameters, so we will use the
681 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000682 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000683 // matches the definition of "equivalent" used for name mangling.
684 VisitType(Parm->getType());
685 return;
686 }
Mike Stump1eb44332009-09-09 15:08:12 +0000687
Douglas Gregora2ffb982009-07-31 15:46:56 +0000688 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
689 ID.AddInteger(TTP->getDepth());
690 ID.AddInteger(TTP->getIndex());
691 return;
692 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000693 }
Mike Stump1eb44332009-09-09 15:08:12 +0000694
Douglas Gregord584eb22009-07-28 15:32:17 +0000695 ID.AddPointer(D? D->getCanonicalDecl() : 0);
696}
697
698void StmtProfiler::VisitType(QualType T) {
699 if (Canonical)
700 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000702 ID.AddPointer(T.getAsOpaquePtr());
703}
704
705void StmtProfiler::VisitName(DeclarationName Name) {
706 ID.AddPointer(Name.getAsOpaquePtr());
707}
708
709void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
710 if (Canonical)
711 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
712 ID.AddPointer(NNS);
713}
714
715void StmtProfiler::VisitTemplateName(TemplateName Name) {
716 if (Canonical)
717 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000718
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000719 Name.Profile(ID);
720}
721
John McCall833ca992009-10-29 08:12:44 +0000722void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000723 unsigned NumArgs) {
724 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000725 for (unsigned I = 0; I != NumArgs; ++I)
726 VisitTemplateArgument(Args[I].getArgument());
727}
Mike Stump1eb44332009-09-09 15:08:12 +0000728
John McCall833ca992009-10-29 08:12:44 +0000729void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
730 // Mostly repetitive with TemplateArgument::Profile!
731 ID.AddInteger(Arg.getKind());
732 switch (Arg.getKind()) {
733 case TemplateArgument::Null:
734 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000735
John McCall833ca992009-10-29 08:12:44 +0000736 case TemplateArgument::Type:
737 VisitType(Arg.getAsType());
738 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000739
Douglas Gregor788cd062009-11-11 01:00:40 +0000740 case TemplateArgument::Template:
741 VisitTemplateName(Arg.getAsTemplate());
742 break;
Sean Huntc3021132010-05-05 15:23:54 +0000743
John McCall833ca992009-10-29 08:12:44 +0000744 case TemplateArgument::Declaration:
745 VisitDecl(Arg.getAsDecl());
746 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000747
John McCall833ca992009-10-29 08:12:44 +0000748 case TemplateArgument::Integral:
749 Arg.getAsIntegral()->Profile(ID);
750 VisitType(Arg.getIntegralType());
751 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000752
John McCall833ca992009-10-29 08:12:44 +0000753 case TemplateArgument::Expression:
754 Visit(Arg.getAsExpr());
755 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000756
John McCall833ca992009-10-29 08:12:44 +0000757 case TemplateArgument::Pack:
758 const TemplateArgument *Pack = Arg.pack_begin();
759 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
760 VisitTemplateArgument(Pack[i]);
761 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000762 }
763}
764
765void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
766 bool Canonical) {
767 StmtProfiler Profiler(ID, Context, Canonical);
768 Profiler.Visit(this);
769}