blob: b117cd9a525face025636224eb709f5aa1ca7a44 [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
John Wiegley1c0675e2011-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 Gregor44882592009-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
Douglas Gregor5c193b92009-07-28 00:33:38 +0000223void StmtProfiler::VisitExpr(Expr *S) {
224 VisitStmt(S);
225}
226
227void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
228 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000229 if (!Canonical)
230 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000231 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000232 if (!Canonical)
233 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000234}
235
236void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
237 VisitExpr(S);
238 ID.AddInteger(S->getIdentType());
239}
240
241void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
242 VisitExpr(S);
243 S->getValue().Profile(ID);
244}
245
246void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
247 VisitExpr(S);
248 ID.AddBoolean(S->isWide());
249 ID.AddInteger(S->getValue());
250}
251
252void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
253 VisitExpr(S);
254 S->getValue().Profile(ID);
255 ID.AddBoolean(S->isExact());
256}
257
258void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
259 VisitExpr(S);
260}
261
262void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
263 VisitExpr(S);
Daniel Dunbar95d5a1d2009-09-22 10:06:21 +0000264 ID.AddString(S->getString());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000265 ID.AddBoolean(S->isWide());
266}
267
268void StmtProfiler::VisitParenExpr(ParenExpr *S) {
269 VisitExpr(S);
270}
271
Nate Begeman5ec4b312009-08-10 23:49:36 +0000272void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
273 VisitExpr(S);
274}
275
Douglas Gregor5c193b92009-07-28 00:33:38 +0000276void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
277 VisitExpr(S);
278 ID.AddInteger(S->getOpcode());
279}
280
Douglas Gregor882211c2010-04-28 22:16:22 +0000281void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
282 VisitType(S->getTypeSourceInfo()->getType());
283 unsigned n = S->getNumComponents();
284 for (unsigned i = 0; i < n; ++i) {
285 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
286 ID.AddInteger(ON.getKind());
287 switch (ON.getKind()) {
288 case OffsetOfExpr::OffsetOfNode::Array:
289 // Expressions handled below.
290 break;
291
292 case OffsetOfExpr::OffsetOfNode::Field:
293 VisitDecl(ON.getField());
294 break;
295
296 case OffsetOfExpr::OffsetOfNode::Identifier:
297 ID.AddPointer(ON.getFieldName());
298 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000299
Douglas Gregord1702062010-04-29 00:18:15 +0000300 case OffsetOfExpr::OffsetOfNode::Base:
301 // These nodes are implicit, and therefore don't need profiling.
302 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000303 }
304 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000305
Douglas Gregor882211c2010-04-28 22:16:22 +0000306 VisitExpr(S);
307}
308
Peter Collingbournee190dee2011-03-11 19:24:49 +0000309void StmtProfiler::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000310 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000311 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000312 if (S->isArgumentType())
313 VisitType(S->getArgumentType());
314}
315
316void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
317 VisitExpr(S);
318}
319
320void StmtProfiler::VisitCallExpr(CallExpr *S) {
321 VisitExpr(S);
322}
323
324void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
325 VisitExpr(S);
326 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000327 if (!Canonical)
328 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000329 ID.AddBoolean(S->isArrow());
330}
331
332void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
333 VisitExpr(S);
334 ID.AddBoolean(S->isFileScope());
335}
336
Douglas Gregor5c193b92009-07-28 00:33:38 +0000337void StmtProfiler::VisitCastExpr(CastExpr *S) {
338 VisitExpr(S);
339}
340
341void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
342 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000343 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000344}
345
346void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
347 VisitCastExpr(S);
348 VisitType(S->getTypeAsWritten());
349}
350
351void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
352 VisitExplicitCastExpr(S);
353}
354
355void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
356 VisitExpr(S);
357 ID.AddInteger(S->getOpcode());
358}
359
360void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
361 VisitBinaryOperator(S);
362}
363
364void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
365 VisitExpr(S);
366}
367
John McCallc07a0c72011-02-17 10:25:35 +0000368void StmtProfiler::VisitBinaryConditionalOperator(BinaryConditionalOperator *S){
369 VisitExpr(S);
370}
371
Douglas Gregor5c193b92009-07-28 00:33:38 +0000372void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
373 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000374 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000375}
376
377void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
378 VisitExpr(S);
379}
380
Douglas Gregor5c193b92009-07-28 00:33:38 +0000381void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
382 VisitExpr(S);
383}
384
385void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
386 VisitExpr(S);
387}
388
389void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
390 VisitExpr(S);
391}
392
Douglas Gregor00044172009-07-29 16:09:57 +0000393void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
394 VisitExpr(S);
395}
396
Douglas Gregor5c193b92009-07-28 00:33:38 +0000397void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
398 if (S->getSyntacticForm()) {
399 VisitInitListExpr(S->getSyntacticForm());
400 return;
401 }
Mike Stump11289f42009-09-09 15:08:12 +0000402
Douglas Gregor5c193b92009-07-28 00:33:38 +0000403 VisitExpr(S);
404}
405
406void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
407 VisitExpr(S);
408 ID.AddBoolean(S->usesGNUSyntax());
409 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
410 DEnd = S->designators_end();
411 D != DEnd; ++D) {
412 if (D->isFieldDesignator()) {
413 ID.AddInteger(0);
414 VisitName(D->getFieldName());
415 continue;
416 }
Mike Stump11289f42009-09-09 15:08:12 +0000417
Douglas Gregor5c193b92009-07-28 00:33:38 +0000418 if (D->isArrayDesignator()) {
419 ID.AddInteger(1);
420 } else {
421 assert(D->isArrayRangeDesignator());
422 ID.AddInteger(2);
423 }
424 ID.AddInteger(D->getFirstExprIndex());
425 }
426}
427
428void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
429 VisitExpr(S);
430}
431
432void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
433 VisitExpr(S);
434 VisitName(&S->getAccessor());
435}
436
437void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
438 VisitExpr(S);
439 VisitDecl(S->getBlockDecl());
440}
441
442void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
443 VisitExpr(S);
444 VisitDecl(S->getDecl());
445 ID.AddBoolean(S->isByRef());
446 ID.AddBoolean(S->isConstQualAdded());
447}
448
Peter Collingbourne91147592011-04-15 00:35:48 +0000449void StmtProfiler::VisitGenericSelectionExpr(GenericSelectionExpr *S) {
450 VisitExpr(S);
451 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
452 QualType T = S->getAssocType(i);
453 if (T.isNull())
454 ID.AddPointer(0);
455 else
456 VisitType(T);
457 VisitExpr(S->getAssocExpr(i));
458 }
459}
460
Douglas Gregore9ceb312010-05-19 04:13:23 +0000461static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000462 UnaryOperatorKind &UnaryOp,
463 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000464 switch (S->getOperator()) {
465 case OO_None:
466 case OO_New:
467 case OO_Delete:
468 case OO_Array_New:
469 case OO_Array_Delete:
470 case OO_Arrow:
471 case OO_Call:
472 case OO_Conditional:
473 case NUM_OVERLOADED_OPERATORS:
474 llvm_unreachable("Invalid operator call kind");
475 return Stmt::ArraySubscriptExprClass;
476
477 case OO_Plus:
478 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000479 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000480 return Stmt::UnaryOperatorClass;
481 }
482
John McCalle3027922010-08-25 11:45:40 +0000483 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000484 return Stmt::BinaryOperatorClass;
485
486 case OO_Minus:
487 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000488 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000489 return Stmt::UnaryOperatorClass;
490 }
491
John McCalle3027922010-08-25 11:45:40 +0000492 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000493 return Stmt::BinaryOperatorClass;
494
495 case OO_Star:
496 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000497 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000498 return Stmt::UnaryOperatorClass;
499 }
500
John McCalle3027922010-08-25 11:45:40 +0000501 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000502 return Stmt::BinaryOperatorClass;
503
504 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000505 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000506 return Stmt::BinaryOperatorClass;
507
508 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000509 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000510 return Stmt::BinaryOperatorClass;
511
512 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000513 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000514 return Stmt::BinaryOperatorClass;
515
516 case OO_Amp:
517 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000518 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000519 return Stmt::UnaryOperatorClass;
520 }
521
John McCalle3027922010-08-25 11:45:40 +0000522 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000523 return Stmt::BinaryOperatorClass;
524
525 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000526 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000527 return Stmt::BinaryOperatorClass;
528
529 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000530 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000531 return Stmt::UnaryOperatorClass;
532
533 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000534 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000535 return Stmt::UnaryOperatorClass;
536
537 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000538 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000539 return Stmt::BinaryOperatorClass;
540
541 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000542 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000543 return Stmt::BinaryOperatorClass;
544
545 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000546 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000547 return Stmt::BinaryOperatorClass;
548
549 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000550 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000551 return Stmt::CompoundAssignOperatorClass;
552
553 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000554 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000555 return Stmt::CompoundAssignOperatorClass;
556
557 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000558 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000559 return Stmt::CompoundAssignOperatorClass;
560
561 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000562 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000563 return Stmt::CompoundAssignOperatorClass;
564
565 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000566 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000567 return Stmt::CompoundAssignOperatorClass;
568
569 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000570 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000571 return Stmt::CompoundAssignOperatorClass;
572
573 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000574 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000575 return Stmt::CompoundAssignOperatorClass;
576
577 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000578 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000579 return Stmt::CompoundAssignOperatorClass;
580
581 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000582 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000583 return Stmt::BinaryOperatorClass;
584
585 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000586 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000587 return Stmt::BinaryOperatorClass;
588
589 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000590 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000591 return Stmt::CompoundAssignOperatorClass;
592
593 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000594 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000595 return Stmt::CompoundAssignOperatorClass;
596
597 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000598 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000599 return Stmt::BinaryOperatorClass;
600
601 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000602 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000603 return Stmt::BinaryOperatorClass;
604
605 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000606 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000607 return Stmt::BinaryOperatorClass;
608
609 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000610 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000611 return Stmt::BinaryOperatorClass;
612
613 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000614 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000615 return Stmt::BinaryOperatorClass;
616
617 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000618 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000619 return Stmt::BinaryOperatorClass;
620
621 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000622 UnaryOp = S->getNumArgs() == 1? UO_PreInc
623 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000624 return Stmt::UnaryOperatorClass;
625
626 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000627 UnaryOp = S->getNumArgs() == 1? UO_PreDec
628 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000629 return Stmt::UnaryOperatorClass;
630
631 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000632 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000633 return Stmt::BinaryOperatorClass;
634
635
636 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000637 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000638 return Stmt::BinaryOperatorClass;
639
640 case OO_Subscript:
641 return Stmt::ArraySubscriptExprClass;
642 }
643
644 llvm_unreachable("Invalid overloaded operator expression");
645}
646
647
Douglas Gregor5c193b92009-07-28 00:33:38 +0000648void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000649 if (S->isTypeDependent()) {
650 // Type-dependent operator calls are profiled like their underlying
651 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000652 UnaryOperatorKind UnaryOp = UO_Extension;
653 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000654 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
655
656 ID.AddInteger(SC);
657 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
658 Visit(S->getArg(I));
659 if (SC == Stmt::UnaryOperatorClass)
660 ID.AddInteger(UnaryOp);
661 else if (SC == Stmt::BinaryOperatorClass ||
662 SC == Stmt::CompoundAssignOperatorClass)
663 ID.AddInteger(BinaryOp);
664 else
665 assert(SC == Stmt::ArraySubscriptExprClass);
666
667 return;
668 }
669
Douglas Gregor5c193b92009-07-28 00:33:38 +0000670 VisitCallExpr(S);
671 ID.AddInteger(S->getOperator());
672}
673
674void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
675 VisitCallExpr(S);
676}
677
Peter Collingbourne41f85462011-02-09 21:07:24 +0000678void StmtProfiler::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *S) {
679 VisitCallExpr(S);
680}
681
Tanya Lattner55808c12011-06-04 00:47:47 +0000682void StmtProfiler::VisitAsTypeExpr(AsTypeExpr *S) {
683 VisitExpr(S);
684}
685
Douglas Gregor5c193b92009-07-28 00:33:38 +0000686void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
687 VisitExplicitCastExpr(S);
688}
689
690void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
691 VisitCXXNamedCastExpr(S);
692}
693
694void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
695 VisitCXXNamedCastExpr(S);
696}
697
698void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
699 VisitCXXNamedCastExpr(S);
700}
701
702void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
703 VisitCXXNamedCastExpr(S);
704}
705
706void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
707 VisitExpr(S);
708 ID.AddBoolean(S->getValue());
709}
710
Douglas Gregor00044172009-07-29 16:09:57 +0000711void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
712 VisitExpr(S);
713}
714
Douglas Gregor5c193b92009-07-28 00:33:38 +0000715void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
716 VisitExpr(S);
717 if (S->isTypeOperand())
718 VisitType(S->getTypeOperand());
719}
720
Francois Pichet9f4f2072010-09-08 12:20:18 +0000721void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
722 VisitExpr(S);
723 if (S->isTypeOperand())
724 VisitType(S->getTypeOperand());
725}
726
Douglas Gregor5c193b92009-07-28 00:33:38 +0000727void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
728 VisitExpr(S);
729}
730
731void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
732 VisitExpr(S);
733}
734
735void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
736 VisitExpr(S);
737 VisitDecl(S->getParam());
738}
739
740void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
741 VisitExpr(S);
742 VisitDecl(
743 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
744}
745
746void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
747 VisitExpr(S);
748 VisitDecl(S->getConstructor());
749 ID.AddBoolean(S->isElidable());
750}
751
752void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
753 VisitExplicitCastExpr(S);
754}
755
756void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
757 VisitCXXConstructExpr(S);
758}
759
Douglas Gregor747eb782010-07-08 06:14:04 +0000760void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000761 VisitExpr(S);
762}
763
Douglas Gregor5c193b92009-07-28 00:33:38 +0000764void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
765 VisitExpr(S);
766 ID.AddBoolean(S->isGlobalDelete());
767 ID.AddBoolean(S->isArrayForm());
768 VisitDecl(S->getOperatorDelete());
769}
770
771
772void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
773 VisitExpr(S);
774 VisitType(S->getAllocatedType());
775 VisitDecl(S->getOperatorNew());
776 VisitDecl(S->getOperatorDelete());
777 VisitDecl(S->getConstructor());
778 ID.AddBoolean(S->isArray());
779 ID.AddInteger(S->getNumPlacementArgs());
780 ID.AddBoolean(S->isGlobalNew());
781 ID.AddBoolean(S->isParenTypeId());
782 ID.AddBoolean(S->hasInitializer());
783 ID.AddInteger(S->getNumConstructorArgs());
784}
785
Douglas Gregorad8a3362009-09-04 17:36:40 +0000786void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
787 VisitExpr(S);
788 ID.AddBoolean(S->isArrow());
789 VisitNestedNameSpecifier(S->getQualifier());
790 VisitType(S->getDestroyedType());
791}
792
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000793void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000794 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000795 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000796 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +0000797 ID.AddBoolean(S->hasExplicitTemplateArgs());
798 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000799 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
800 S->getExplicitTemplateArgs().NumTemplateArgs);
801}
802
803void
804StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
805 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +0000806}
807
808void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
809 VisitExpr(S);
810 ID.AddInteger(S->getTrait());
811 VisitType(S->getQueriedType());
812}
813
Francois Pichet9dfa3ce2010-12-07 00:08:36 +0000814void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
815 VisitExpr(S);
816 ID.AddInteger(S->getTrait());
817 VisitType(S->getLhsType());
818 VisitType(S->getRhsType());
819}
820
John Wiegley6242b6a2011-04-28 00:16:57 +0000821void StmtProfiler::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *S) {
822 VisitExpr(S);
823 ID.AddInteger(S->getTrait());
824 VisitType(S->getQueriedType());
825}
826
John Wiegleyf9f65842011-04-25 06:54:41 +0000827void StmtProfiler::VisitExpressionTraitExpr(ExpressionTraitExpr *S) {
828 VisitExpr(S);
829 ID.AddInteger(S->getTrait());
830 VisitExpr(S->getQueriedExpression());
831}
832
John McCall8cd78132009-11-19 22:55:06 +0000833void
834StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000835 VisitExpr(S);
836 VisitName(S->getDeclName());
837 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +0000838 ID.AddBoolean(S->hasExplicitTemplateArgs());
839 if (S->hasExplicitTemplateArgs())
840 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000841}
842
John McCall5d413782010-12-06 08:20:24 +0000843void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +0000844 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +0000845}
846
Mike Stump11289f42009-09-09 15:08:12 +0000847void
Douglas Gregora7095092009-07-28 14:44:31 +0000848StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
849 VisitExpr(S);
850 VisitType(S->getTypeAsWritten());
851}
852
John McCall8cd78132009-11-19 22:55:06 +0000853void
854StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +0000855 ID.AddBoolean(S->isImplicitAccess());
856 if (!S->isImplicitAccess()) {
857 VisitExpr(S);
858 ID.AddBoolean(S->isArrow());
859 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000860 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +0000861 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +0000862 ID.AddBoolean(S->hasExplicitTemplateArgs());
863 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +0000864 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
865}
866
867void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +0000868 ID.AddBoolean(S->isImplicitAccess());
869 if (!S->isImplicitAccess()) {
870 VisitExpr(S);
871 ID.AddBoolean(S->isArrow());
872 }
John McCall10eae182009-11-30 22:42:35 +0000873 VisitNestedNameSpecifier(S->getQualifier());
874 VisitName(S->getMemberName());
875 ID.AddBoolean(S->hasExplicitTemplateArgs());
876 if (S->hasExplicitTemplateArgs())
877 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +0000878}
879
Sebastian Redl4202c0f2010-09-10 20:55:43 +0000880void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
881 VisitExpr(S);
882}
883
Douglas Gregore8e9dd62011-01-03 17:17:50 +0000884void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
885 VisitExpr(S);
886}
887
Douglas Gregor820ba7b2011-01-04 17:33:58 +0000888void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
889 VisitExpr(S);
890 VisitDecl(S->getPack());
891}
892
Douglas Gregorcdbc5392011-01-15 01:15:58 +0000893void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
894 SubstNonTypeTemplateParmPackExpr *S) {
895 VisitExpr(S);
896 VisitDecl(S->getParameterPack());
897 VisitTemplateArgument(S->getArgumentPack());
898}
899
John McCall8d69a212010-11-15 23:31:06 +0000900void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
901 VisitExpr(E);
902}
903
Douglas Gregora7095092009-07-28 14:44:31 +0000904void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
905 VisitExpr(S);
906}
907
908void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
909 VisitExpr(S);
910 VisitType(S->getEncodedType());
911}
912
913void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
914 VisitExpr(S);
915 VisitName(S->getSelector());
916}
917
918void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
919 VisitExpr(S);
920 VisitDecl(S->getProtocol());
921}
922
923void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
924 VisitExpr(S);
925 VisitDecl(S->getDecl());
926 ID.AddBoolean(S->isArrow());
927 ID.AddBoolean(S->isFreeIvar());
928}
929
930void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
931 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +0000932 if (S->isImplicitProperty()) {
933 VisitDecl(S->getImplicitPropertyGetter());
934 VisitDecl(S->getImplicitPropertySetter());
935 } else {
936 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000937 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000938 if (S->isSuperReceiver()) {
939 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +0000940 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000941 }
Douglas Gregora7095092009-07-28 14:44:31 +0000942}
943
944void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
945 VisitExpr(S);
946 VisitName(S->getSelector());
947 VisitDecl(S->getMethodDecl());
948}
949
Douglas Gregora7095092009-07-28 14:44:31 +0000950void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
951 VisitExpr(S);
952 ID.AddBoolean(S->isArrow());
953}
954
Douglas Gregord9aedfa2009-07-28 15:32:17 +0000955void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +0000956 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +0000957
Douglas Gregora5dd9f82009-07-30 23:18:24 +0000958 if (Canonical && D) {
Douglas Gregor802a0302009-07-31 05:24:01 +0000959 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +0000960 ID.AddInteger(NTTP->getDepth());
961 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +0000962 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +0000963 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000964 return;
965 }
Mike Stump11289f42009-09-09 15:08:12 +0000966
Douglas Gregor70317122009-07-31 15:45:02 +0000967 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +0000968 // The Itanium C++ ABI uses the type, scope depth, and scope
969 // index of a parameter when mangling expressions that involve
970 // function parameters, so we will use the parameter's type for
971 // establishing function parameter identity. That way, our
972 // definition of "equivalent" (per C++ [temp.over.link]) is at
973 // least as strong as the definition of "equivalent" used for
974 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +0000975 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +0000976 ID.AddInteger(Parm->getFunctionScopeDepth());
977 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +0000978 return;
979 }
Mike Stump11289f42009-09-09 15:08:12 +0000980
Douglas Gregorc97f09f2009-07-31 15:46:56 +0000981 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
982 ID.AddInteger(TTP->getDepth());
983 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +0000984 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +0000985 return;
986 }
Douglas Gregor5c193b92009-07-28 00:33:38 +0000987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregord9aedfa2009-07-28 15:32:17 +0000989 ID.AddPointer(D? D->getCanonicalDecl() : 0);
990}
991
992void StmtProfiler::VisitType(QualType T) {
993 if (Canonical)
994 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +0000995
Douglas Gregor5c193b92009-07-28 00:33:38 +0000996 ID.AddPointer(T.getAsOpaquePtr());
997}
998
999void StmtProfiler::VisitName(DeclarationName Name) {
1000 ID.AddPointer(Name.getAsOpaquePtr());
1001}
1002
1003void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1004 if (Canonical)
1005 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1006 ID.AddPointer(NNS);
1007}
1008
1009void StmtProfiler::VisitTemplateName(TemplateName Name) {
1010 if (Canonical)
1011 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001012
Douglas Gregor5c193b92009-07-28 00:33:38 +00001013 Name.Profile(ID);
1014}
1015
John McCall0ad16662009-10-29 08:12:44 +00001016void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001017 unsigned NumArgs) {
1018 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001019 for (unsigned I = 0; I != NumArgs; ++I)
1020 VisitTemplateArgument(Args[I].getArgument());
1021}
Mike Stump11289f42009-09-09 15:08:12 +00001022
John McCall0ad16662009-10-29 08:12:44 +00001023void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1024 // Mostly repetitive with TemplateArgument::Profile!
1025 ID.AddInteger(Arg.getKind());
1026 switch (Arg.getKind()) {
1027 case TemplateArgument::Null:
1028 break;
Mike Stump11289f42009-09-09 15:08:12 +00001029
John McCall0ad16662009-10-29 08:12:44 +00001030 case TemplateArgument::Type:
1031 VisitType(Arg.getAsType());
1032 break;
Mike Stump11289f42009-09-09 15:08:12 +00001033
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001034 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001035 case TemplateArgument::TemplateExpansion:
1036 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001037 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001038
John McCall0ad16662009-10-29 08:12:44 +00001039 case TemplateArgument::Declaration:
1040 VisitDecl(Arg.getAsDecl());
1041 break;
Mike Stump11289f42009-09-09 15:08:12 +00001042
John McCall0ad16662009-10-29 08:12:44 +00001043 case TemplateArgument::Integral:
1044 Arg.getAsIntegral()->Profile(ID);
1045 VisitType(Arg.getIntegralType());
1046 break;
Mike Stump11289f42009-09-09 15:08:12 +00001047
John McCall0ad16662009-10-29 08:12:44 +00001048 case TemplateArgument::Expression:
1049 Visit(Arg.getAsExpr());
1050 break;
Mike Stump11289f42009-09-09 15:08:12 +00001051
John McCall0ad16662009-10-29 08:12:44 +00001052 case TemplateArgument::Pack:
1053 const TemplateArgument *Pack = Arg.pack_begin();
1054 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1055 VisitTemplateArgument(Pack[i]);
1056 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001057 }
1058}
1059
Jay Foad39c79802011-01-12 09:06:06 +00001060void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001061 bool Canonical) {
1062 StmtProfiler Profiler(ID, Context, Canonical);
1063 Profiler.Visit(this);
1064}