blob: 92292cea719418b898d53591f2de5c98eab07d44 [file] [log] [blame]
Douglas Gregor5c193b92009-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 Gregor32615a12009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor5c193b92009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregora7095092009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor5c193b92009-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 Gregor5c193b92009-07-28 00:33:38 +000023using namespace clang;
24
25namespace {
Benjamin Kramer26222b62009-11-28 19:03:38 +000026 class StmtProfiler : public StmtVisitor<StmtProfiler> {
Douglas Gregor5c193b92009-07-28 00:33:38 +000027 llvm::FoldingSetNodeID &ID;
Jay Foad39c79802011-01-12 09:06:06 +000028 const ASTContext &Context;
Douglas Gregor5c193b92009-07-28 00:33:38 +000029 bool Canonical;
Mike Stump11289f42009-09-09 15:08:12 +000030
Douglas Gregor5c193b92009-07-28 00:33:38 +000031 public:
Jay Foad39c79802011-01-12 09:06:06 +000032 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump11289f42009-09-09 15:08:12 +000033 bool Canonical)
Douglas Gregor5c193b92009-07-28 00:33:38 +000034 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump11289f42009-09-09 15:08:12 +000035
Douglas Gregor5c193b92009-07-28 00:33:38 +000036 void VisitStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000037
Douglas Gregor44882592009-07-28 15:27:13 +000038#define STMT(Node, Base) void Visit##Node(Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000039#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000040
Douglas Gregor5c193b92009-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 Stump11289f42009-09-09 15:08:12 +000044
45 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000046 /// statement.
47 void VisitType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +000048
Douglas Gregor5c193b92009-07-28 00:33:38 +000049 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
Mike Stump11289f42009-09-09 15:08:12 +000051
Douglas Gregor5c193b92009-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 Stump11289f42009-09-09 15:08:12 +000055
Douglas Gregor5c193b92009-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 Stump11289f42009-09-09 15:08:12 +000059
Douglas Gregor5c193b92009-07-28 00:33:38 +000060 /// \brief Visit template arguments that occur within an expression or
61 /// statement.
John McCall0ad16662009-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 Gregor5c193b92009-07-28 00:33:38 +000066 };
67}
68
69void StmtProfiler::VisitStmt(Stmt *S) {
70 ID.AddInteger(S->getStmtClass());
John McCall8322c3a2011-02-13 04:07:26 +000071 for (Stmt::child_range C = S->children(); C; ++C)
Douglas Gregor5c193b92009-07-28 00:33:38 +000072 Visit(*C);
73}
74
Douglas Gregor44882592009-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 Lattnerc8e630e2011-02-17 07:39:24 +0000104 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000105}
106
107void StmtProfiler::VisitIfStmt(IfStmt *S) {
108 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000109 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000110}
111
Douglas Gregor00044172009-07-29 16:09:57 +0000112void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
113 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000114 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000115}
116
Douglas Gregor44882592009-07-28 15:27:13 +0000117void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
118 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000119 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-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 Lattnerc8e630e2011-02-17 07:39:24 +0000132 VisitDecl(S->getLabel());
Douglas Gregor44882592009-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 Smith02e85f32011-04-14 22:09:26 +0000180void StmtProfiler::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
181 VisitStmt(S);
182}
183
Douglas Gregor44882592009-07-28 15:27:13 +0000184void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
185 VisitStmt(S);
186}
187
188void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
189 VisitStmt(S);
190 ID.AddBoolean(S->hasEllipsis());
191 if (S->getCatchParamDecl())
192 VisitType(S->getCatchParamDecl()->getType());
193}
194
195void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
196 VisitStmt(S);
197}
198
199void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
200 VisitStmt(S);
201}
202
203void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
204 VisitStmt(S);
205}
206
207void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
208 VisitStmt(S);
209}
210
Douglas Gregor5c193b92009-07-28 00:33:38 +0000211void StmtProfiler::VisitExpr(Expr *S) {
212 VisitStmt(S);
213}
214
215void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
216 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000217 if (!Canonical)
218 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000219 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000220 if (!Canonical)
221 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000222}
223
224void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
225 VisitExpr(S);
226 ID.AddInteger(S->getIdentType());
227}
228
229void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
230 VisitExpr(S);
231 S->getValue().Profile(ID);
232}
233
234void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
235 VisitExpr(S);
236 ID.AddBoolean(S->isWide());
237 ID.AddInteger(S->getValue());
238}
239
240void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
241 VisitExpr(S);
242 S->getValue().Profile(ID);
243 ID.AddBoolean(S->isExact());
244}
245
246void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
247 VisitExpr(S);
248}
249
250void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
251 VisitExpr(S);
Daniel Dunbar95d5a1d2009-09-22 10:06:21 +0000252 ID.AddString(S->getString());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000253 ID.AddBoolean(S->isWide());
254}
255
256void StmtProfiler::VisitParenExpr(ParenExpr *S) {
257 VisitExpr(S);
258}
259
Nate Begeman5ec4b312009-08-10 23:49:36 +0000260void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
261 VisitExpr(S);
262}
263
Douglas Gregor5c193b92009-07-28 00:33:38 +0000264void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
265 VisitExpr(S);
266 ID.AddInteger(S->getOpcode());
267}
268
Douglas Gregor882211c2010-04-28 22:16:22 +0000269void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
270 VisitType(S->getTypeSourceInfo()->getType());
271 unsigned n = S->getNumComponents();
272 for (unsigned i = 0; i < n; ++i) {
273 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
274 ID.AddInteger(ON.getKind());
275 switch (ON.getKind()) {
276 case OffsetOfExpr::OffsetOfNode::Array:
277 // Expressions handled below.
278 break;
279
280 case OffsetOfExpr::OffsetOfNode::Field:
281 VisitDecl(ON.getField());
282 break;
283
284 case OffsetOfExpr::OffsetOfNode::Identifier:
285 ID.AddPointer(ON.getFieldName());
286 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000287
Douglas Gregord1702062010-04-29 00:18:15 +0000288 case OffsetOfExpr::OffsetOfNode::Base:
289 // These nodes are implicit, and therefore don't need profiling.
290 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000291 }
292 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000293
Douglas Gregor882211c2010-04-28 22:16:22 +0000294 VisitExpr(S);
295}
296
Peter Collingbournee190dee2011-03-11 19:24:49 +0000297void StmtProfiler::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000298 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000299 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000300 if (S->isArgumentType())
301 VisitType(S->getArgumentType());
302}
303
304void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
305 VisitExpr(S);
306}
307
308void StmtProfiler::VisitCallExpr(CallExpr *S) {
309 VisitExpr(S);
310}
311
312void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
313 VisitExpr(S);
314 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000315 if (!Canonical)
316 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000317 ID.AddBoolean(S->isArrow());
318}
319
320void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
321 VisitExpr(S);
322 ID.AddBoolean(S->isFileScope());
323}
324
Douglas Gregor5c193b92009-07-28 00:33:38 +0000325void StmtProfiler::VisitCastExpr(CastExpr *S) {
326 VisitExpr(S);
327}
328
329void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
330 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000331 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000332}
333
334void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
335 VisitCastExpr(S);
336 VisitType(S->getTypeAsWritten());
337}
338
339void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
340 VisitExplicitCastExpr(S);
341}
342
343void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
344 VisitExpr(S);
345 ID.AddInteger(S->getOpcode());
346}
347
348void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
349 VisitBinaryOperator(S);
350}
351
352void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
353 VisitExpr(S);
354}
355
John McCallc07a0c72011-02-17 10:25:35 +0000356void StmtProfiler::VisitBinaryConditionalOperator(BinaryConditionalOperator *S){
357 VisitExpr(S);
358}
359
Douglas Gregor5c193b92009-07-28 00:33:38 +0000360void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
361 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000362 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000363}
364
365void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
366 VisitExpr(S);
367}
368
Douglas Gregor5c193b92009-07-28 00:33:38 +0000369void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
370 VisitExpr(S);
371}
372
373void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
374 VisitExpr(S);
375}
376
377void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
378 VisitExpr(S);
379}
380
Douglas Gregor00044172009-07-29 16:09:57 +0000381void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
382 VisitExpr(S);
383}
384
Douglas Gregor5c193b92009-07-28 00:33:38 +0000385void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
386 if (S->getSyntacticForm()) {
387 VisitInitListExpr(S->getSyntacticForm());
388 return;
389 }
Mike Stump11289f42009-09-09 15:08:12 +0000390
Douglas Gregor5c193b92009-07-28 00:33:38 +0000391 VisitExpr(S);
392}
393
394void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
395 VisitExpr(S);
396 ID.AddBoolean(S->usesGNUSyntax());
397 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
398 DEnd = S->designators_end();
399 D != DEnd; ++D) {
400 if (D->isFieldDesignator()) {
401 ID.AddInteger(0);
402 VisitName(D->getFieldName());
403 continue;
404 }
Mike Stump11289f42009-09-09 15:08:12 +0000405
Douglas Gregor5c193b92009-07-28 00:33:38 +0000406 if (D->isArrayDesignator()) {
407 ID.AddInteger(1);
408 } else {
409 assert(D->isArrayRangeDesignator());
410 ID.AddInteger(2);
411 }
412 ID.AddInteger(D->getFirstExprIndex());
413 }
414}
415
416void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
417 VisitExpr(S);
418}
419
420void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
421 VisitExpr(S);
422 VisitName(&S->getAccessor());
423}
424
425void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
426 VisitExpr(S);
427 VisitDecl(S->getBlockDecl());
428}
429
430void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
431 VisitExpr(S);
432 VisitDecl(S->getDecl());
433 ID.AddBoolean(S->isByRef());
434 ID.AddBoolean(S->isConstQualAdded());
435}
436
Douglas Gregore9ceb312010-05-19 04:13:23 +0000437static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000438 UnaryOperatorKind &UnaryOp,
439 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000440 switch (S->getOperator()) {
441 case OO_None:
442 case OO_New:
443 case OO_Delete:
444 case OO_Array_New:
445 case OO_Array_Delete:
446 case OO_Arrow:
447 case OO_Call:
448 case OO_Conditional:
449 case NUM_OVERLOADED_OPERATORS:
450 llvm_unreachable("Invalid operator call kind");
451 return Stmt::ArraySubscriptExprClass;
452
453 case OO_Plus:
454 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000455 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000456 return Stmt::UnaryOperatorClass;
457 }
458
John McCalle3027922010-08-25 11:45:40 +0000459 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000460 return Stmt::BinaryOperatorClass;
461
462 case OO_Minus:
463 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000464 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000465 return Stmt::UnaryOperatorClass;
466 }
467
John McCalle3027922010-08-25 11:45:40 +0000468 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000469 return Stmt::BinaryOperatorClass;
470
471 case OO_Star:
472 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000473 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000474 return Stmt::UnaryOperatorClass;
475 }
476
John McCalle3027922010-08-25 11:45:40 +0000477 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000478 return Stmt::BinaryOperatorClass;
479
480 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000481 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000482 return Stmt::BinaryOperatorClass;
483
484 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000485 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000486 return Stmt::BinaryOperatorClass;
487
488 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000489 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000490 return Stmt::BinaryOperatorClass;
491
492 case OO_Amp:
493 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000494 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000495 return Stmt::UnaryOperatorClass;
496 }
497
John McCalle3027922010-08-25 11:45:40 +0000498 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000499 return Stmt::BinaryOperatorClass;
500
501 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000502 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000503 return Stmt::BinaryOperatorClass;
504
505 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000506 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000507 return Stmt::UnaryOperatorClass;
508
509 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000510 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000511 return Stmt::UnaryOperatorClass;
512
513 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000514 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000515 return Stmt::BinaryOperatorClass;
516
517 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000518 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000519 return Stmt::BinaryOperatorClass;
520
521 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000522 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000523 return Stmt::BinaryOperatorClass;
524
525 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000526 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000527 return Stmt::CompoundAssignOperatorClass;
528
529 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000530 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000531 return Stmt::CompoundAssignOperatorClass;
532
533 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000534 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000535 return Stmt::CompoundAssignOperatorClass;
536
537 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000538 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000539 return Stmt::CompoundAssignOperatorClass;
540
541 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000542 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000543 return Stmt::CompoundAssignOperatorClass;
544
545 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000546 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000547 return Stmt::CompoundAssignOperatorClass;
548
549 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000550 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000551 return Stmt::CompoundAssignOperatorClass;
552
553 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000554 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000555 return Stmt::CompoundAssignOperatorClass;
556
557 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000558 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000559 return Stmt::BinaryOperatorClass;
560
561 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000562 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000563 return Stmt::BinaryOperatorClass;
564
565 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000566 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000567 return Stmt::CompoundAssignOperatorClass;
568
569 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000570 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000571 return Stmt::CompoundAssignOperatorClass;
572
573 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000574 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000575 return Stmt::BinaryOperatorClass;
576
577 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000578 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000579 return Stmt::BinaryOperatorClass;
580
581 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000582 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000583 return Stmt::BinaryOperatorClass;
584
585 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000586 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000587 return Stmt::BinaryOperatorClass;
588
589 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000590 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000591 return Stmt::BinaryOperatorClass;
592
593 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000594 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000595 return Stmt::BinaryOperatorClass;
596
597 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000598 UnaryOp = S->getNumArgs() == 1? UO_PreInc
599 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000600 return Stmt::UnaryOperatorClass;
601
602 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000603 UnaryOp = S->getNumArgs() == 1? UO_PreDec
604 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000605 return Stmt::UnaryOperatorClass;
606
607 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000608 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000609 return Stmt::BinaryOperatorClass;
610
611
612 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000613 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000614 return Stmt::BinaryOperatorClass;
615
616 case OO_Subscript:
617 return Stmt::ArraySubscriptExprClass;
618 }
619
620 llvm_unreachable("Invalid overloaded operator expression");
621}
622
623
Douglas Gregor5c193b92009-07-28 00:33:38 +0000624void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000625 if (S->isTypeDependent()) {
626 // Type-dependent operator calls are profiled like their underlying
627 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000628 UnaryOperatorKind UnaryOp = UO_Extension;
629 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000630 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
631
632 ID.AddInteger(SC);
633 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
634 Visit(S->getArg(I));
635 if (SC == Stmt::UnaryOperatorClass)
636 ID.AddInteger(UnaryOp);
637 else if (SC == Stmt::BinaryOperatorClass ||
638 SC == Stmt::CompoundAssignOperatorClass)
639 ID.AddInteger(BinaryOp);
640 else
641 assert(SC == Stmt::ArraySubscriptExprClass);
642
643 return;
644 }
645
Douglas Gregor5c193b92009-07-28 00:33:38 +0000646 VisitCallExpr(S);
647 ID.AddInteger(S->getOperator());
648}
649
650void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
651 VisitCallExpr(S);
652}
653
Peter Collingbourne41f85462011-02-09 21:07:24 +0000654void StmtProfiler::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *S) {
655 VisitCallExpr(S);
656}
657
Douglas Gregor5c193b92009-07-28 00:33:38 +0000658void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
659 VisitExplicitCastExpr(S);
660}
661
662void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
663 VisitCXXNamedCastExpr(S);
664}
665
666void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
667 VisitCXXNamedCastExpr(S);
668}
669
670void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
671 VisitCXXNamedCastExpr(S);
672}
673
674void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
675 VisitCXXNamedCastExpr(S);
676}
677
678void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
679 VisitExpr(S);
680 ID.AddBoolean(S->getValue());
681}
682
Douglas Gregor00044172009-07-29 16:09:57 +0000683void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
684 VisitExpr(S);
685}
686
Douglas Gregor5c193b92009-07-28 00:33:38 +0000687void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
688 VisitExpr(S);
689 if (S->isTypeOperand())
690 VisitType(S->getTypeOperand());
691}
692
Francois Pichet9f4f2072010-09-08 12:20:18 +0000693void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
694 VisitExpr(S);
695 if (S->isTypeOperand())
696 VisitType(S->getTypeOperand());
697}
698
Douglas Gregor5c193b92009-07-28 00:33:38 +0000699void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
700 VisitExpr(S);
701}
702
703void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
704 VisitExpr(S);
705}
706
707void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
708 VisitExpr(S);
709 VisitDecl(S->getParam());
710}
711
712void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
713 VisitExpr(S);
714 VisitDecl(
715 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
716}
717
718void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
719 VisitExpr(S);
720 VisitDecl(S->getConstructor());
721 ID.AddBoolean(S->isElidable());
722}
723
724void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
725 VisitExplicitCastExpr(S);
726}
727
728void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
729 VisitCXXConstructExpr(S);
730}
731
Douglas Gregor747eb782010-07-08 06:14:04 +0000732void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000733 VisitExpr(S);
734}
735
Douglas Gregor5c193b92009-07-28 00:33:38 +0000736void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
737 VisitExpr(S);
738 ID.AddBoolean(S->isGlobalDelete());
739 ID.AddBoolean(S->isArrayForm());
740 VisitDecl(S->getOperatorDelete());
741}
742
743
744void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
745 VisitExpr(S);
746 VisitType(S->getAllocatedType());
747 VisitDecl(S->getOperatorNew());
748 VisitDecl(S->getOperatorDelete());
749 VisitDecl(S->getConstructor());
750 ID.AddBoolean(S->isArray());
751 ID.AddInteger(S->getNumPlacementArgs());
752 ID.AddBoolean(S->isGlobalNew());
753 ID.AddBoolean(S->isParenTypeId());
754 ID.AddBoolean(S->hasInitializer());
755 ID.AddInteger(S->getNumConstructorArgs());
756}
757
Douglas Gregorad8a3362009-09-04 17:36:40 +0000758void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
759 VisitExpr(S);
760 ID.AddBoolean(S->isArrow());
761 VisitNestedNameSpecifier(S->getQualifier());
762 VisitType(S->getDestroyedType());
763}
764
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000765void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000766 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000767 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000768 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +0000769 ID.AddBoolean(S->hasExplicitTemplateArgs());
770 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000771 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
772 S->getExplicitTemplateArgs().NumTemplateArgs);
773}
774
775void
776StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
777 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +0000778}
779
780void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
781 VisitExpr(S);
782 ID.AddInteger(S->getTrait());
783 VisitType(S->getQueriedType());
784}
785
Francois Pichet9dfa3ce2010-12-07 00:08:36 +0000786void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
787 VisitExpr(S);
788 ID.AddInteger(S->getTrait());
789 VisitType(S->getLhsType());
790 VisitType(S->getRhsType());
791}
792
John McCall8cd78132009-11-19 22:55:06 +0000793void
794StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000795 VisitExpr(S);
796 VisitName(S->getDeclName());
797 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +0000798 ID.AddBoolean(S->hasExplicitTemplateArgs());
799 if (S->hasExplicitTemplateArgs())
800 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000801}
802
John McCall5d413782010-12-06 08:20:24 +0000803void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +0000804 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +0000805}
806
Mike Stump11289f42009-09-09 15:08:12 +0000807void
Douglas Gregora7095092009-07-28 14:44:31 +0000808StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
809 VisitExpr(S);
810 VisitType(S->getTypeAsWritten());
811}
812
John McCall8cd78132009-11-19 22:55:06 +0000813void
814StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +0000815 ID.AddBoolean(S->isImplicitAccess());
816 if (!S->isImplicitAccess()) {
817 VisitExpr(S);
818 ID.AddBoolean(S->isArrow());
819 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000820 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +0000821 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +0000822 ID.AddBoolean(S->hasExplicitTemplateArgs());
823 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +0000824 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
825}
826
827void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +0000828 ID.AddBoolean(S->isImplicitAccess());
829 if (!S->isImplicitAccess()) {
830 VisitExpr(S);
831 ID.AddBoolean(S->isArrow());
832 }
John McCall10eae182009-11-30 22:42:35 +0000833 VisitNestedNameSpecifier(S->getQualifier());
834 VisitName(S->getMemberName());
835 ID.AddBoolean(S->hasExplicitTemplateArgs());
836 if (S->hasExplicitTemplateArgs())
837 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +0000838}
839
Sebastian Redl4202c0f2010-09-10 20:55:43 +0000840void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
841 VisitExpr(S);
842}
843
Douglas Gregore8e9dd62011-01-03 17:17:50 +0000844void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
845 VisitExpr(S);
846}
847
Douglas Gregor820ba7b2011-01-04 17:33:58 +0000848void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
849 VisitExpr(S);
850 VisitDecl(S->getPack());
851}
852
Douglas Gregorcdbc5392011-01-15 01:15:58 +0000853void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
854 SubstNonTypeTemplateParmPackExpr *S) {
855 VisitExpr(S);
856 VisitDecl(S->getParameterPack());
857 VisitTemplateArgument(S->getArgumentPack());
858}
859
John McCall8d69a212010-11-15 23:31:06 +0000860void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
861 VisitExpr(E);
862}
863
Douglas Gregora7095092009-07-28 14:44:31 +0000864void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
865 VisitExpr(S);
866}
867
868void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
869 VisitExpr(S);
870 VisitType(S->getEncodedType());
871}
872
873void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
874 VisitExpr(S);
875 VisitName(S->getSelector());
876}
877
878void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
879 VisitExpr(S);
880 VisitDecl(S->getProtocol());
881}
882
883void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
884 VisitExpr(S);
885 VisitDecl(S->getDecl());
886 ID.AddBoolean(S->isArrow());
887 ID.AddBoolean(S->isFreeIvar());
888}
889
890void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
891 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +0000892 if (S->isImplicitProperty()) {
893 VisitDecl(S->getImplicitPropertyGetter());
894 VisitDecl(S->getImplicitPropertySetter());
895 } else {
896 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000897 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000898 if (S->isSuperReceiver()) {
899 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +0000900 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000901 }
Douglas Gregora7095092009-07-28 14:44:31 +0000902}
903
904void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
905 VisitExpr(S);
906 VisitName(S->getSelector());
907 VisitDecl(S->getMethodDecl());
908}
909
Douglas Gregora7095092009-07-28 14:44:31 +0000910void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
911 VisitExpr(S);
912 ID.AddBoolean(S->isArrow());
913}
914
Douglas Gregord9aedfa2009-07-28 15:32:17 +0000915void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +0000916 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +0000917
Douglas Gregora5dd9f82009-07-30 23:18:24 +0000918 if (Canonical && D) {
Douglas Gregor802a0302009-07-31 05:24:01 +0000919 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +0000920 ID.AddInteger(NTTP->getDepth());
921 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +0000922 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +0000923 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000924 return;
925 }
Mike Stump11289f42009-09-09 15:08:12 +0000926
Douglas Gregor70317122009-07-31 15:45:02 +0000927 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
928 // The Itanium C++ ABI uses the type of a parameter when mangling
929 // expressions that involve function parameters, so we will use the
930 // parameter's type for establishing function parameter identity. That
Mike Stump11289f42009-09-09 15:08:12 +0000931 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor70317122009-07-31 15:45:02 +0000932 // matches the definition of "equivalent" used for name mangling.
933 VisitType(Parm->getType());
934 return;
935 }
Mike Stump11289f42009-09-09 15:08:12 +0000936
Douglas Gregorc97f09f2009-07-31 15:46:56 +0000937 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
938 ID.AddInteger(TTP->getDepth());
939 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +0000940 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +0000941 return;
942 }
Douglas Gregor5c193b92009-07-28 00:33:38 +0000943 }
Mike Stump11289f42009-09-09 15:08:12 +0000944
Douglas Gregord9aedfa2009-07-28 15:32:17 +0000945 ID.AddPointer(D? D->getCanonicalDecl() : 0);
946}
947
948void StmtProfiler::VisitType(QualType T) {
949 if (Canonical)
950 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +0000951
Douglas Gregor5c193b92009-07-28 00:33:38 +0000952 ID.AddPointer(T.getAsOpaquePtr());
953}
954
955void StmtProfiler::VisitName(DeclarationName Name) {
956 ID.AddPointer(Name.getAsOpaquePtr());
957}
958
959void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
960 if (Canonical)
961 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
962 ID.AddPointer(NNS);
963}
964
965void StmtProfiler::VisitTemplateName(TemplateName Name) {
966 if (Canonical)
967 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +0000968
Douglas Gregor5c193b92009-07-28 00:33:38 +0000969 Name.Profile(ID);
970}
971
John McCall0ad16662009-10-29 08:12:44 +0000972void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +0000973 unsigned NumArgs) {
974 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +0000975 for (unsigned I = 0; I != NumArgs; ++I)
976 VisitTemplateArgument(Args[I].getArgument());
977}
Mike Stump11289f42009-09-09 15:08:12 +0000978
John McCall0ad16662009-10-29 08:12:44 +0000979void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
980 // Mostly repetitive with TemplateArgument::Profile!
981 ID.AddInteger(Arg.getKind());
982 switch (Arg.getKind()) {
983 case TemplateArgument::Null:
984 break;
Mike Stump11289f42009-09-09 15:08:12 +0000985
John McCall0ad16662009-10-29 08:12:44 +0000986 case TemplateArgument::Type:
987 VisitType(Arg.getAsType());
988 break;
Mike Stump11289f42009-09-09 15:08:12 +0000989
Douglas Gregor9167f8b2009-11-11 01:00:40 +0000990 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +0000991 case TemplateArgument::TemplateExpansion:
992 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +0000993 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000994
John McCall0ad16662009-10-29 08:12:44 +0000995 case TemplateArgument::Declaration:
996 VisitDecl(Arg.getAsDecl());
997 break;
Mike Stump11289f42009-09-09 15:08:12 +0000998
John McCall0ad16662009-10-29 08:12:44 +0000999 case TemplateArgument::Integral:
1000 Arg.getAsIntegral()->Profile(ID);
1001 VisitType(Arg.getIntegralType());
1002 break;
Mike Stump11289f42009-09-09 15:08:12 +00001003
John McCall0ad16662009-10-29 08:12:44 +00001004 case TemplateArgument::Expression:
1005 Visit(Arg.getAsExpr());
1006 break;
Mike Stump11289f42009-09-09 15:08:12 +00001007
John McCall0ad16662009-10-29 08:12:44 +00001008 case TemplateArgument::Pack:
1009 const TemplateArgument *Pack = Arg.pack_begin();
1010 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1011 VisitTemplateArgument(Pack[i]);
1012 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001013 }
1014}
1015
Jay Foad39c79802011-01-12 09:06:06 +00001016void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001017 bool Canonical) {
1018 StmtProfiler Profiler(ID, Context, Canonical);
1019 Profiler.Visit(this);
1020}