blob: c70c87a7240d6b4c7108595db061b179f1e24fef [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;
Jay Foad4ba2a172011-01-12 09:06:06 +000028 const ASTContext &Context;
Douglas Gregor41ef0c32009-07-28 00:33:38 +000029 bool Canonical;
Mike Stump1eb44332009-09-09 15:08:12 +000030
Douglas Gregor41ef0c32009-07-28 00:33:38 +000031 public:
Jay Foad4ba2a172011-01-12 09:06:06 +000032 StmtProfiler(llvm::FoldingSetNodeID &ID, const 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());
John McCall7502c1d2011-02-13 04:07:26 +000071 for (Stmt::child_range C = S->children(); C; ++C)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000072 Visit(*C);
73}
74
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000075void StmtProfiler::VisitDeclStmt(DeclStmt *S) {
76 VisitStmt(S);
77 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
78 D != DEnd; ++D)
79 VisitDecl(*D);
80}
81
82void StmtProfiler::VisitNullStmt(NullStmt *S) {
83 VisitStmt(S);
84}
85
86void StmtProfiler::VisitCompoundStmt(CompoundStmt *S) {
87 VisitStmt(S);
88}
89
90void StmtProfiler::VisitSwitchCase(SwitchCase *S) {
91 VisitStmt(S);
92}
93
94void StmtProfiler::VisitCaseStmt(CaseStmt *S) {
95 VisitStmt(S);
96}
97
98void StmtProfiler::VisitDefaultStmt(DefaultStmt *S) {
99 VisitStmt(S);
100}
101
102void StmtProfiler::VisitLabelStmt(LabelStmt *S) {
103 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000104 VisitDecl(S->getDecl());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000105}
106
107void StmtProfiler::VisitIfStmt(IfStmt *S) {
108 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000109 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000110}
111
Douglas Gregor828e2262009-07-29 16:09:57 +0000112void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
113 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000114 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000115}
116
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000117void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
118 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000119 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000120}
121
122void StmtProfiler::VisitDoStmt(DoStmt *S) {
123 VisitStmt(S);
124}
125
126void StmtProfiler::VisitForStmt(ForStmt *S) {
127 VisitStmt(S);
128}
129
130void StmtProfiler::VisitGotoStmt(GotoStmt *S) {
131 VisitStmt(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000132 VisitDecl(S->getLabel());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000133}
134
135void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
136 VisitStmt(S);
137}
138
139void StmtProfiler::VisitContinueStmt(ContinueStmt *S) {
140 VisitStmt(S);
141}
142
143void StmtProfiler::VisitBreakStmt(BreakStmt *S) {
144 VisitStmt(S);
145}
146
147void StmtProfiler::VisitReturnStmt(ReturnStmt *S) {
148 VisitStmt(S);
149}
150
151void StmtProfiler::VisitAsmStmt(AsmStmt *S) {
152 VisitStmt(S);
153 ID.AddBoolean(S->isVolatile());
154 ID.AddBoolean(S->isSimple());
155 VisitStringLiteral(S->getAsmString());
156 ID.AddInteger(S->getNumOutputs());
157 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
158 ID.AddString(S->getOutputName(I));
159 VisitStringLiteral(S->getOutputConstraintLiteral(I));
160 }
161 ID.AddInteger(S->getNumInputs());
162 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
163 ID.AddString(S->getInputName(I));
164 VisitStringLiteral(S->getInputConstraintLiteral(I));
165 }
166 ID.AddInteger(S->getNumClobbers());
167 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
168 VisitStringLiteral(S->getClobber(I));
169}
170
171void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) {
172 VisitStmt(S);
173 VisitType(S->getCaughtType());
174}
175
176void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) {
177 VisitStmt(S);
178}
179
Richard Smithad762fc2011-04-14 22:09:26 +0000180void StmtProfiler::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
181 VisitStmt(S);
182}
183
John Wiegley28bbe4b2011-04-28 01:08:34 +0000184void StmtProfiler::VisitSEHTryStmt(SEHTryStmt *S) {
185 VisitStmt(S);
186}
187
188void StmtProfiler::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
189 VisitStmt(S);
190}
191
192void StmtProfiler::VisitSEHExceptStmt(SEHExceptStmt *S) {
193 VisitStmt(S);
194}
195
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000196void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
197 VisitStmt(S);
198}
199
200void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
201 VisitStmt(S);
202 ID.AddBoolean(S->hasEllipsis());
203 if (S->getCatchParamDecl())
204 VisitType(S->getCatchParamDecl()->getType());
205}
206
207void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
208 VisitStmt(S);
209}
210
211void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
212 VisitStmt(S);
213}
214
215void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
216 VisitStmt(S);
217}
218
219void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
220 VisitStmt(S);
221}
222
John McCallf85e1932011-06-15 23:02:42 +0000223void StmtProfiler::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
224 VisitStmt(S);
225}
226
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000227void StmtProfiler::VisitExpr(Expr *S) {
228 VisitStmt(S);
229}
230
231void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
232 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000233 if (!Canonical)
234 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000235 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000236 if (!Canonical)
237 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000238}
239
240void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
241 VisitExpr(S);
242 ID.AddInteger(S->getIdentType());
243}
244
245void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
246 VisitExpr(S);
247 S->getValue().Profile(ID);
248}
249
250void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
251 VisitExpr(S);
252 ID.AddBoolean(S->isWide());
253 ID.AddInteger(S->getValue());
254}
255
256void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
257 VisitExpr(S);
258 S->getValue().Profile(ID);
259 ID.AddBoolean(S->isExact());
260}
261
262void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
263 VisitExpr(S);
264}
265
266void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
267 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000268 ID.AddString(S->getString());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000269 ID.AddBoolean(S->isWide());
270}
271
272void StmtProfiler::VisitParenExpr(ParenExpr *S) {
273 VisitExpr(S);
274}
275
Nate Begeman2ef13e52009-08-10 23:49:36 +0000276void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
277 VisitExpr(S);
278}
279
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000280void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
281 VisitExpr(S);
282 ID.AddInteger(S->getOpcode());
283}
284
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000285void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
286 VisitType(S->getTypeSourceInfo()->getType());
287 unsigned n = S->getNumComponents();
288 for (unsigned i = 0; i < n; ++i) {
289 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
290 ID.AddInteger(ON.getKind());
291 switch (ON.getKind()) {
292 case OffsetOfExpr::OffsetOfNode::Array:
293 // Expressions handled below.
294 break;
295
296 case OffsetOfExpr::OffsetOfNode::Field:
297 VisitDecl(ON.getField());
298 break;
299
300 case OffsetOfExpr::OffsetOfNode::Identifier:
301 ID.AddPointer(ON.getFieldName());
302 break;
Sean Huntc3021132010-05-05 15:23:54 +0000303
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000304 case OffsetOfExpr::OffsetOfNode::Base:
305 // These nodes are implicit, and therefore don't need profiling.
306 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000307 }
308 }
Sean Huntc3021132010-05-05 15:23:54 +0000309
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000310 VisitExpr(S);
311}
312
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000313void StmtProfiler::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000314 VisitExpr(S);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000315 ID.AddInteger(S->getKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000316 if (S->isArgumentType())
317 VisitType(S->getArgumentType());
318}
319
320void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
321 VisitExpr(S);
322}
323
324void StmtProfiler::VisitCallExpr(CallExpr *S) {
325 VisitExpr(S);
326}
327
328void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
329 VisitExpr(S);
330 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000331 if (!Canonical)
332 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000333 ID.AddBoolean(S->isArrow());
334}
335
336void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
337 VisitExpr(S);
338 ID.AddBoolean(S->isFileScope());
339}
340
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000341void StmtProfiler::VisitCastExpr(CastExpr *S) {
342 VisitExpr(S);
343}
344
345void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
346 VisitCastExpr(S);
John McCall5baba9d2010-08-25 10:28:54 +0000347 ID.AddInteger(S->getValueKind());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000348}
349
350void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
351 VisitCastExpr(S);
352 VisitType(S->getTypeAsWritten());
353}
354
355void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
356 VisitExplicitCastExpr(S);
357}
358
359void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
360 VisitExpr(S);
361 ID.AddInteger(S->getOpcode());
362}
363
364void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
365 VisitBinaryOperator(S);
366}
367
368void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
369 VisitExpr(S);
370}
371
John McCall56ca35d2011-02-17 10:25:35 +0000372void StmtProfiler::VisitBinaryConditionalOperator(BinaryConditionalOperator *S){
373 VisitExpr(S);
374}
375
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000376void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
377 VisitExpr(S);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000378 VisitDecl(S->getLabel());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000379}
380
381void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
382 VisitExpr(S);
383}
384
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000385void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
386 VisitExpr(S);
387}
388
389void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
390 VisitExpr(S);
391}
392
393void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
394 VisitExpr(S);
395}
396
Douglas Gregor828e2262009-07-29 16:09:57 +0000397void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
398 VisitExpr(S);
399}
400
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000401void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
402 if (S->getSyntacticForm()) {
403 VisitInitListExpr(S->getSyntacticForm());
404 return;
405 }
Mike Stump1eb44332009-09-09 15:08:12 +0000406
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000407 VisitExpr(S);
408}
409
410void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
411 VisitExpr(S);
412 ID.AddBoolean(S->usesGNUSyntax());
413 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
414 DEnd = S->designators_end();
415 D != DEnd; ++D) {
416 if (D->isFieldDesignator()) {
417 ID.AddInteger(0);
418 VisitName(D->getFieldName());
419 continue;
420 }
Mike Stump1eb44332009-09-09 15:08:12 +0000421
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000422 if (D->isArrayDesignator()) {
423 ID.AddInteger(1);
424 } else {
425 assert(D->isArrayRangeDesignator());
426 ID.AddInteger(2);
427 }
428 ID.AddInteger(D->getFirstExprIndex());
429 }
430}
431
432void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
433 VisitExpr(S);
434}
435
436void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
437 VisitExpr(S);
438 VisitName(&S->getAccessor());
439}
440
441void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
442 VisitExpr(S);
443 VisitDecl(S->getBlockDecl());
444}
445
446void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
447 VisitExpr(S);
448 VisitDecl(S->getDecl());
449 ID.AddBoolean(S->isByRef());
450 ID.AddBoolean(S->isConstQualAdded());
451}
452
Peter Collingbournef111d932011-04-15 00:35:48 +0000453void StmtProfiler::VisitGenericSelectionExpr(GenericSelectionExpr *S) {
454 VisitExpr(S);
455 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
456 QualType T = S->getAssocType(i);
457 if (T.isNull())
458 ID.AddPointer(0);
459 else
460 VisitType(T);
461 VisitExpr(S->getAssocExpr(i));
462 }
463}
464
Douglas Gregora89064a2010-05-19 04:13:23 +0000465static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
John McCall2de56d12010-08-25 11:45:40 +0000466 UnaryOperatorKind &UnaryOp,
467 BinaryOperatorKind &BinaryOp) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000468 switch (S->getOperator()) {
469 case OO_None:
470 case OO_New:
471 case OO_Delete:
472 case OO_Array_New:
473 case OO_Array_Delete:
474 case OO_Arrow:
475 case OO_Call:
476 case OO_Conditional:
477 case NUM_OVERLOADED_OPERATORS:
478 llvm_unreachable("Invalid operator call kind");
479 return Stmt::ArraySubscriptExprClass;
480
481 case OO_Plus:
482 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000483 UnaryOp = UO_Plus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000484 return Stmt::UnaryOperatorClass;
485 }
486
John McCall2de56d12010-08-25 11:45:40 +0000487 BinaryOp = BO_Add;
Douglas Gregora89064a2010-05-19 04:13:23 +0000488 return Stmt::BinaryOperatorClass;
489
490 case OO_Minus:
491 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000492 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000493 return Stmt::UnaryOperatorClass;
494 }
495
John McCall2de56d12010-08-25 11:45:40 +0000496 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000497 return Stmt::BinaryOperatorClass;
498
499 case OO_Star:
500 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000501 UnaryOp = UO_Minus;
Douglas Gregora89064a2010-05-19 04:13:23 +0000502 return Stmt::UnaryOperatorClass;
503 }
504
John McCall2de56d12010-08-25 11:45:40 +0000505 BinaryOp = BO_Sub;
Douglas Gregora89064a2010-05-19 04:13:23 +0000506 return Stmt::BinaryOperatorClass;
507
508 case OO_Slash:
John McCall2de56d12010-08-25 11:45:40 +0000509 BinaryOp = BO_Div;
Douglas Gregora89064a2010-05-19 04:13:23 +0000510 return Stmt::BinaryOperatorClass;
511
512 case OO_Percent:
John McCall2de56d12010-08-25 11:45:40 +0000513 BinaryOp = BO_Rem;
Douglas Gregora89064a2010-05-19 04:13:23 +0000514 return Stmt::BinaryOperatorClass;
515
516 case OO_Caret:
John McCall2de56d12010-08-25 11:45:40 +0000517 BinaryOp = BO_Xor;
Douglas Gregora89064a2010-05-19 04:13:23 +0000518 return Stmt::BinaryOperatorClass;
519
520 case OO_Amp:
521 if (S->getNumArgs() == 1) {
John McCall2de56d12010-08-25 11:45:40 +0000522 UnaryOp = UO_AddrOf;
Douglas Gregora89064a2010-05-19 04:13:23 +0000523 return Stmt::UnaryOperatorClass;
524 }
525
John McCall2de56d12010-08-25 11:45:40 +0000526 BinaryOp = BO_And;
Douglas Gregora89064a2010-05-19 04:13:23 +0000527 return Stmt::BinaryOperatorClass;
528
529 case OO_Pipe:
John McCall2de56d12010-08-25 11:45:40 +0000530 BinaryOp = BO_Or;
Douglas Gregora89064a2010-05-19 04:13:23 +0000531 return Stmt::BinaryOperatorClass;
532
533 case OO_Tilde:
John McCall2de56d12010-08-25 11:45:40 +0000534 UnaryOp = UO_Not;
Douglas Gregora89064a2010-05-19 04:13:23 +0000535 return Stmt::UnaryOperatorClass;
536
537 case OO_Exclaim:
John McCall2de56d12010-08-25 11:45:40 +0000538 UnaryOp = UO_LNot;
Douglas Gregora89064a2010-05-19 04:13:23 +0000539 return Stmt::UnaryOperatorClass;
540
541 case OO_Equal:
John McCall2de56d12010-08-25 11:45:40 +0000542 BinaryOp = BO_Assign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000543 return Stmt::BinaryOperatorClass;
544
545 case OO_Less:
John McCall2de56d12010-08-25 11:45:40 +0000546 BinaryOp = BO_LT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000547 return Stmt::BinaryOperatorClass;
548
549 case OO_Greater:
John McCall2de56d12010-08-25 11:45:40 +0000550 BinaryOp = BO_GT;
Douglas Gregora89064a2010-05-19 04:13:23 +0000551 return Stmt::BinaryOperatorClass;
552
553 case OO_PlusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000554 BinaryOp = BO_AddAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000555 return Stmt::CompoundAssignOperatorClass;
556
557 case OO_MinusEqual:
John McCall2de56d12010-08-25 11:45:40 +0000558 BinaryOp = BO_SubAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000559 return Stmt::CompoundAssignOperatorClass;
560
561 case OO_StarEqual:
John McCall2de56d12010-08-25 11:45:40 +0000562 BinaryOp = BO_MulAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000563 return Stmt::CompoundAssignOperatorClass;
564
565 case OO_SlashEqual:
John McCall2de56d12010-08-25 11:45:40 +0000566 BinaryOp = BO_DivAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000567 return Stmt::CompoundAssignOperatorClass;
568
569 case OO_PercentEqual:
John McCall2de56d12010-08-25 11:45:40 +0000570 BinaryOp = BO_RemAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000571 return Stmt::CompoundAssignOperatorClass;
572
573 case OO_CaretEqual:
John McCall2de56d12010-08-25 11:45:40 +0000574 BinaryOp = BO_XorAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000575 return Stmt::CompoundAssignOperatorClass;
576
577 case OO_AmpEqual:
John McCall2de56d12010-08-25 11:45:40 +0000578 BinaryOp = BO_AndAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000579 return Stmt::CompoundAssignOperatorClass;
580
581 case OO_PipeEqual:
John McCall2de56d12010-08-25 11:45:40 +0000582 BinaryOp = BO_OrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000583 return Stmt::CompoundAssignOperatorClass;
584
585 case OO_LessLess:
John McCall2de56d12010-08-25 11:45:40 +0000586 BinaryOp = BO_Shl;
Douglas Gregora89064a2010-05-19 04:13:23 +0000587 return Stmt::BinaryOperatorClass;
588
589 case OO_GreaterGreater:
John McCall2de56d12010-08-25 11:45:40 +0000590 BinaryOp = BO_Shr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000591 return Stmt::BinaryOperatorClass;
592
593 case OO_LessLessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000594 BinaryOp = BO_ShlAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000595 return Stmt::CompoundAssignOperatorClass;
596
597 case OO_GreaterGreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000598 BinaryOp = BO_ShrAssign;
Douglas Gregora89064a2010-05-19 04:13:23 +0000599 return Stmt::CompoundAssignOperatorClass;
600
601 case OO_EqualEqual:
John McCall2de56d12010-08-25 11:45:40 +0000602 BinaryOp = BO_EQ;
Douglas Gregora89064a2010-05-19 04:13:23 +0000603 return Stmt::BinaryOperatorClass;
604
605 case OO_ExclaimEqual:
John McCall2de56d12010-08-25 11:45:40 +0000606 BinaryOp = BO_NE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000607 return Stmt::BinaryOperatorClass;
608
609 case OO_LessEqual:
John McCall2de56d12010-08-25 11:45:40 +0000610 BinaryOp = BO_LE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000611 return Stmt::BinaryOperatorClass;
612
613 case OO_GreaterEqual:
John McCall2de56d12010-08-25 11:45:40 +0000614 BinaryOp = BO_GE;
Douglas Gregora89064a2010-05-19 04:13:23 +0000615 return Stmt::BinaryOperatorClass;
616
617 case OO_AmpAmp:
John McCall2de56d12010-08-25 11:45:40 +0000618 BinaryOp = BO_LAnd;
Douglas Gregora89064a2010-05-19 04:13:23 +0000619 return Stmt::BinaryOperatorClass;
620
621 case OO_PipePipe:
John McCall2de56d12010-08-25 11:45:40 +0000622 BinaryOp = BO_LOr;
Douglas Gregora89064a2010-05-19 04:13:23 +0000623 return Stmt::BinaryOperatorClass;
624
625 case OO_PlusPlus:
John McCall2de56d12010-08-25 11:45:40 +0000626 UnaryOp = S->getNumArgs() == 1? UO_PreInc
627 : UO_PostInc;
Douglas Gregora89064a2010-05-19 04:13:23 +0000628 return Stmt::UnaryOperatorClass;
629
630 case OO_MinusMinus:
John McCall2de56d12010-08-25 11:45:40 +0000631 UnaryOp = S->getNumArgs() == 1? UO_PreDec
632 : UO_PostDec;
Douglas Gregora89064a2010-05-19 04:13:23 +0000633 return Stmt::UnaryOperatorClass;
634
635 case OO_Comma:
John McCall2de56d12010-08-25 11:45:40 +0000636 BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000637 return Stmt::BinaryOperatorClass;
638
639
640 case OO_ArrowStar:
John McCall2de56d12010-08-25 11:45:40 +0000641 BinaryOp = BO_PtrMemI;
Douglas Gregora89064a2010-05-19 04:13:23 +0000642 return Stmt::BinaryOperatorClass;
643
644 case OO_Subscript:
645 return Stmt::ArraySubscriptExprClass;
646 }
647
648 llvm_unreachable("Invalid overloaded operator expression");
649}
650
651
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000652void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000653 if (S->isTypeDependent()) {
654 // Type-dependent operator calls are profiled like their underlying
655 // syntactic operator.
John McCall2de56d12010-08-25 11:45:40 +0000656 UnaryOperatorKind UnaryOp = UO_Extension;
657 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000658 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
659
660 ID.AddInteger(SC);
661 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
662 Visit(S->getArg(I));
663 if (SC == Stmt::UnaryOperatorClass)
664 ID.AddInteger(UnaryOp);
665 else if (SC == Stmt::BinaryOperatorClass ||
666 SC == Stmt::CompoundAssignOperatorClass)
667 ID.AddInteger(BinaryOp);
668 else
669 assert(SC == Stmt::ArraySubscriptExprClass);
670
671 return;
672 }
673
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000674 VisitCallExpr(S);
675 ID.AddInteger(S->getOperator());
676}
677
678void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
679 VisitCallExpr(S);
680}
681
Peter Collingbournee08ce652011-02-09 21:07:24 +0000682void StmtProfiler::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *S) {
683 VisitCallExpr(S);
684}
685
Tanya Lattner61eee0c2011-06-04 00:47:47 +0000686void StmtProfiler::VisitAsTypeExpr(AsTypeExpr *S) {
687 VisitExpr(S);
688}
689
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000690void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
691 VisitExplicitCastExpr(S);
692}
693
694void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
695 VisitCXXNamedCastExpr(S);
696}
697
698void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
699 VisitCXXNamedCastExpr(S);
700}
701
702void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
703 VisitCXXNamedCastExpr(S);
704}
705
706void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
707 VisitCXXNamedCastExpr(S);
708}
709
710void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
711 VisitExpr(S);
712 ID.AddBoolean(S->getValue());
713}
714
Douglas Gregor828e2262009-07-29 16:09:57 +0000715void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
716 VisitExpr(S);
717}
718
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000719void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
720 VisitExpr(S);
721 if (S->isTypeOperand())
722 VisitType(S->getTypeOperand());
723}
724
Francois Pichet01b7c302010-09-08 12:20:18 +0000725void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
726 VisitExpr(S);
727 if (S->isTypeOperand())
728 VisitType(S->getTypeOperand());
729}
730
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000731void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
732 VisitExpr(S);
733}
734
735void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
736 VisitExpr(S);
737}
738
739void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
740 VisitExpr(S);
741 VisitDecl(S->getParam());
742}
743
744void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
745 VisitExpr(S);
746 VisitDecl(
747 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
748}
749
750void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
751 VisitExpr(S);
752 VisitDecl(S->getConstructor());
753 ID.AddBoolean(S->isElidable());
754}
755
756void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
757 VisitExplicitCastExpr(S);
758}
759
760void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
761 VisitCXXConstructExpr(S);
762}
763
Douglas Gregored8abf12010-07-08 06:14:04 +0000764void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000765 VisitExpr(S);
766}
767
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000768void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
769 VisitExpr(S);
770 ID.AddBoolean(S->isGlobalDelete());
771 ID.AddBoolean(S->isArrayForm());
772 VisitDecl(S->getOperatorDelete());
773}
774
775
776void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
777 VisitExpr(S);
778 VisitType(S->getAllocatedType());
779 VisitDecl(S->getOperatorNew());
780 VisitDecl(S->getOperatorDelete());
781 VisitDecl(S->getConstructor());
782 ID.AddBoolean(S->isArray());
783 ID.AddInteger(S->getNumPlacementArgs());
784 ID.AddBoolean(S->isGlobalNew());
785 ID.AddBoolean(S->isParenTypeId());
786 ID.AddBoolean(S->hasInitializer());
787 ID.AddInteger(S->getNumConstructorArgs());
788}
789
Douglas Gregora71d8192009-09-04 17:36:40 +0000790void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
791 VisitExpr(S);
792 ID.AddBoolean(S->isArrow());
793 VisitNestedNameSpecifier(S->getQualifier());
794 VisitType(S->getDestroyedType());
795}
796
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000797void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidis7b3e3f62010-08-15 20:53:20 +0000798 VisitExpr(S);
John McCallf7a1a742009-11-24 19:00:30 +0000799 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000800 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000801 ID.AddBoolean(S->hasExplicitTemplateArgs());
802 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000803 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
804 S->getExplicitTemplateArgs().NumTemplateArgs);
805}
806
807void
808StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
809 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000810}
811
812void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
813 VisitExpr(S);
814 ID.AddInteger(S->getTrait());
815 VisitType(S->getQueriedType());
816}
817
Francois Pichet6ad6f282010-12-07 00:08:36 +0000818void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
819 VisitExpr(S);
820 ID.AddInteger(S->getTrait());
821 VisitType(S->getLhsType());
822 VisitType(S->getRhsType());
823}
824
John Wiegley21ff2e52011-04-28 00:16:57 +0000825void StmtProfiler::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *S) {
826 VisitExpr(S);
827 ID.AddInteger(S->getTrait());
828 VisitType(S->getQueriedType());
829}
830
John Wiegley55262202011-04-25 06:54:41 +0000831void StmtProfiler::VisitExpressionTraitExpr(ExpressionTraitExpr *S) {
832 VisitExpr(S);
833 ID.AddInteger(S->getTrait());
834 VisitExpr(S->getQueriedExpression());
835}
836
John McCall865d4472009-11-19 22:55:06 +0000837void
838StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000839 VisitExpr(S);
840 VisitName(S->getDeclName());
841 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000842 ID.AddBoolean(S->hasExplicitTemplateArgs());
843 if (S->hasExplicitTemplateArgs())
844 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000845}
846
John McCall4765fa02010-12-06 08:20:24 +0000847void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000848 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000849}
850
Mike Stump1eb44332009-09-09 15:08:12 +0000851void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000852StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
853 VisitExpr(S);
854 VisitType(S->getTypeAsWritten());
855}
856
John McCall865d4472009-11-19 22:55:06 +0000857void
858StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000859 ID.AddBoolean(S->isImplicitAccess());
860 if (!S->isImplicitAccess()) {
861 VisitExpr(S);
862 ID.AddBoolean(S->isArrow());
863 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000864 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000865 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000866 ID.AddBoolean(S->hasExplicitTemplateArgs());
867 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000868 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
869}
870
871void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000872 ID.AddBoolean(S->isImplicitAccess());
873 if (!S->isImplicitAccess()) {
874 VisitExpr(S);
875 ID.AddBoolean(S->isArrow());
876 }
John McCall129e2df2009-11-30 22:42:35 +0000877 VisitNestedNameSpecifier(S->getQualifier());
878 VisitName(S->getMemberName());
879 ID.AddBoolean(S->hasExplicitTemplateArgs());
880 if (S->hasExplicitTemplateArgs())
881 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000882}
883
Sebastian Redl2e156222010-09-10 20:55:43 +0000884void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
885 VisitExpr(S);
886}
887
Douglas Gregorbe230c32011-01-03 17:17:50 +0000888void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
889 VisitExpr(S);
890}
891
Douglas Gregoree8aff02011-01-04 17:33:58 +0000892void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
893 VisitExpr(S);
894 VisitDecl(S->getPack());
895}
896
Douglas Gregorc7793c72011-01-15 01:15:58 +0000897void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
898 SubstNonTypeTemplateParmPackExpr *S) {
899 VisitExpr(S);
900 VisitDecl(S->getParameterPack());
901 VisitTemplateArgument(S->getArgumentPack());
902}
903
John McCall7cd7d1a2010-11-15 23:31:06 +0000904void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
905 VisitExpr(E);
906}
907
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000908void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
909 VisitExpr(S);
910}
911
912void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
913 VisitExpr(S);
914 VisitType(S->getEncodedType());
915}
916
917void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
918 VisitExpr(S);
919 VisitName(S->getSelector());
920}
921
922void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
923 VisitExpr(S);
924 VisitDecl(S->getProtocol());
925}
926
927void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
928 VisitExpr(S);
929 VisitDecl(S->getDecl());
930 ID.AddBoolean(S->isArrow());
931 ID.AddBoolean(S->isFreeIvar());
932}
933
934void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
935 VisitExpr(S);
John McCall12f78a62010-12-02 01:19:52 +0000936 if (S->isImplicitProperty()) {
937 VisitDecl(S->getImplicitPropertyGetter());
938 VisitDecl(S->getImplicitPropertySetter());
939 } else {
940 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000941 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000942 if (S->isSuperReceiver()) {
943 ID.AddBoolean(S->isSuperReceiver());
John McCall12f78a62010-12-02 01:19:52 +0000944 VisitType(S->getSuperReceiverType());
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000945 }
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000946}
947
948void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
949 VisitExpr(S);
950 VisitName(S->getSelector());
951 VisitDecl(S->getMethodDecl());
952}
953
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000954void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
955 VisitExpr(S);
956 ID.AddBoolean(S->isArrow());
957}
958
John McCallf85e1932011-06-15 23:02:42 +0000959void
960StmtProfiler::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *S) {
961 VisitExpr(S);
962 ID.AddBoolean(S->shouldCopy());
963}
964
965void StmtProfiler::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *S) {
966 VisitExplicitCastExpr(S);
967 ID.AddBoolean(S->getBridgeKind());
968}
969
Douglas Gregord584eb22009-07-28 15:32:17 +0000970void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000971 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000972
Douglas Gregorb1975722009-07-30 23:18:24 +0000973 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000974 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000975 ID.AddInteger(NTTP->getDepth());
976 ID.AddInteger(NTTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000977 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor828e2262009-07-29 16:09:57 +0000978 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000979 return;
980 }
Mike Stump1eb44332009-09-09 15:08:12 +0000981
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000982 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCallfb44de92011-05-01 22:35:37 +0000983 // The Itanium C++ ABI uses the type, scope depth, and scope
984 // index of a parameter when mangling expressions that involve
985 // function parameters, so we will use the parameter's type for
986 // establishing function parameter identity. That way, our
987 // definition of "equivalent" (per C++ [temp.over.link]) is at
988 // least as strong as the definition of "equivalent" used for
989 // name mangling.
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000990 VisitType(Parm->getType());
John McCallfb44de92011-05-01 22:35:37 +0000991 ID.AddInteger(Parm->getFunctionScopeDepth());
992 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000993 return;
994 }
Mike Stump1eb44332009-09-09 15:08:12 +0000995
Douglas Gregora2ffb982009-07-31 15:46:56 +0000996 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
997 ID.AddInteger(TTP->getDepth());
998 ID.AddInteger(TTP->getIndex());
Douglas Gregor61c4d282011-01-05 15:48:55 +0000999 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregora2ffb982009-07-31 15:46:56 +00001000 return;
1001 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001002 }
Mike Stump1eb44332009-09-09 15:08:12 +00001003
Douglas Gregord584eb22009-07-28 15:32:17 +00001004 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1005}
1006
1007void StmtProfiler::VisitType(QualType T) {
1008 if (Canonical)
1009 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +00001010
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001011 ID.AddPointer(T.getAsOpaquePtr());
1012}
1013
1014void StmtProfiler::VisitName(DeclarationName Name) {
1015 ID.AddPointer(Name.getAsOpaquePtr());
1016}
1017
1018void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1019 if (Canonical)
1020 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1021 ID.AddPointer(NNS);
1022}
1023
1024void StmtProfiler::VisitTemplateName(TemplateName Name) {
1025 if (Canonical)
1026 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +00001027
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001028 Name.Profile(ID);
1029}
1030
John McCall833ca992009-10-29 08:12:44 +00001031void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001032 unsigned NumArgs) {
1033 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +00001034 for (unsigned I = 0; I != NumArgs; ++I)
1035 VisitTemplateArgument(Args[I].getArgument());
1036}
Mike Stump1eb44332009-09-09 15:08:12 +00001037
John McCall833ca992009-10-29 08:12:44 +00001038void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1039 // Mostly repetitive with TemplateArgument::Profile!
1040 ID.AddInteger(Arg.getKind());
1041 switch (Arg.getKind()) {
1042 case TemplateArgument::Null:
1043 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001044
John McCall833ca992009-10-29 08:12:44 +00001045 case TemplateArgument::Type:
1046 VisitType(Arg.getAsType());
1047 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001048
Douglas Gregor788cd062009-11-11 01:00:40 +00001049 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00001050 case TemplateArgument::TemplateExpansion:
1051 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor788cd062009-11-11 01:00:40 +00001052 break;
Sean Huntc3021132010-05-05 15:23:54 +00001053
John McCall833ca992009-10-29 08:12:44 +00001054 case TemplateArgument::Declaration:
1055 VisitDecl(Arg.getAsDecl());
1056 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001057
John McCall833ca992009-10-29 08:12:44 +00001058 case TemplateArgument::Integral:
1059 Arg.getAsIntegral()->Profile(ID);
1060 VisitType(Arg.getIntegralType());
1061 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001062
John McCall833ca992009-10-29 08:12:44 +00001063 case TemplateArgument::Expression:
1064 Visit(Arg.getAsExpr());
1065 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001066
John McCall833ca992009-10-29 08:12:44 +00001067 case TemplateArgument::Pack:
1068 const TemplateArgument *Pack = Arg.pack_begin();
1069 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1070 VisitTemplateArgument(Pack[i]);
1071 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001072 }
1073}
1074
Jay Foad4ba2a172011-01-12 09:06:06 +00001075void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001076 bool Canonical) {
1077 StmtProfiler Profiler(ID, Context, Canonical);
1078 Profiler.Visit(this);
1079}