blob: 44818e8c0847cc29cb1db3a201be57e9c438d049 [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
Douglas Gregor5c193b92009-07-28 00:33:38 +0000682void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
683 VisitExplicitCastExpr(S);
684}
685
686void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
687 VisitCXXNamedCastExpr(S);
688}
689
690void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
691 VisitCXXNamedCastExpr(S);
692}
693
694void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
695 VisitCXXNamedCastExpr(S);
696}
697
698void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
699 VisitCXXNamedCastExpr(S);
700}
701
702void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
703 VisitExpr(S);
704 ID.AddBoolean(S->getValue());
705}
706
Douglas Gregor00044172009-07-29 16:09:57 +0000707void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
708 VisitExpr(S);
709}
710
Douglas Gregor5c193b92009-07-28 00:33:38 +0000711void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
712 VisitExpr(S);
713 if (S->isTypeOperand())
714 VisitType(S->getTypeOperand());
715}
716
Francois Pichet9f4f2072010-09-08 12:20:18 +0000717void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) {
718 VisitExpr(S);
719 if (S->isTypeOperand())
720 VisitType(S->getTypeOperand());
721}
722
Douglas Gregor5c193b92009-07-28 00:33:38 +0000723void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
724 VisitExpr(S);
725}
726
727void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
728 VisitExpr(S);
729}
730
731void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
732 VisitExpr(S);
733 VisitDecl(S->getParam());
734}
735
736void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
737 VisitExpr(S);
738 VisitDecl(
739 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
740}
741
742void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
743 VisitExpr(S);
744 VisitDecl(S->getConstructor());
745 ID.AddBoolean(S->isElidable());
746}
747
748void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
749 VisitExplicitCastExpr(S);
750}
751
752void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
753 VisitCXXConstructExpr(S);
754}
755
Douglas Gregor747eb782010-07-08 06:14:04 +0000756void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000757 VisitExpr(S);
758}
759
Douglas Gregor5c193b92009-07-28 00:33:38 +0000760void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
761 VisitExpr(S);
762 ID.AddBoolean(S->isGlobalDelete());
763 ID.AddBoolean(S->isArrayForm());
764 VisitDecl(S->getOperatorDelete());
765}
766
767
768void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
769 VisitExpr(S);
770 VisitType(S->getAllocatedType());
771 VisitDecl(S->getOperatorNew());
772 VisitDecl(S->getOperatorDelete());
773 VisitDecl(S->getConstructor());
774 ID.AddBoolean(S->isArray());
775 ID.AddInteger(S->getNumPlacementArgs());
776 ID.AddBoolean(S->isGlobalNew());
777 ID.AddBoolean(S->isParenTypeId());
778 ID.AddBoolean(S->hasInitializer());
779 ID.AddInteger(S->getNumConstructorArgs());
780}
781
Douglas Gregorad8a3362009-09-04 17:36:40 +0000782void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
783 VisitExpr(S);
784 ID.AddBoolean(S->isArrow());
785 VisitNestedNameSpecifier(S->getQualifier());
786 VisitType(S->getDestroyedType());
787}
788
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000789void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000790 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000791 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000792 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +0000793 ID.AddBoolean(S->hasExplicitTemplateArgs());
794 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000795 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
796 S->getExplicitTemplateArgs().NumTemplateArgs);
797}
798
799void
800StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
801 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +0000802}
803
804void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
805 VisitExpr(S);
806 ID.AddInteger(S->getTrait());
807 VisitType(S->getQueriedType());
808}
809
Francois Pichet9dfa3ce2010-12-07 00:08:36 +0000810void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) {
811 VisitExpr(S);
812 ID.AddInteger(S->getTrait());
813 VisitType(S->getLhsType());
814 VisitType(S->getRhsType());
815}
816
John Wiegley6242b6a2011-04-28 00:16:57 +0000817void StmtProfiler::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *S) {
818 VisitExpr(S);
819 ID.AddInteger(S->getTrait());
820 VisitType(S->getQueriedType());
821}
822
John Wiegleyf9f65842011-04-25 06:54:41 +0000823void StmtProfiler::VisitExpressionTraitExpr(ExpressionTraitExpr *S) {
824 VisitExpr(S);
825 ID.AddInteger(S->getTrait());
826 VisitExpr(S->getQueriedExpression());
827}
828
John McCall8cd78132009-11-19 22:55:06 +0000829void
830StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000831 VisitExpr(S);
832 VisitName(S->getDeclName());
833 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +0000834 ID.AddBoolean(S->hasExplicitTemplateArgs());
835 if (S->hasExplicitTemplateArgs())
836 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000837}
838
John McCall5d413782010-12-06 08:20:24 +0000839void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +0000840 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +0000841}
842
Mike Stump11289f42009-09-09 15:08:12 +0000843void
Douglas Gregora7095092009-07-28 14:44:31 +0000844StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
845 VisitExpr(S);
846 VisitType(S->getTypeAsWritten());
847}
848
John McCall8cd78132009-11-19 22:55:06 +0000849void
850StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +0000851 ID.AddBoolean(S->isImplicitAccess());
852 if (!S->isImplicitAccess()) {
853 VisitExpr(S);
854 ID.AddBoolean(S->isArrow());
855 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000856 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +0000857 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +0000858 ID.AddBoolean(S->hasExplicitTemplateArgs());
859 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +0000860 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
861}
862
863void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +0000864 ID.AddBoolean(S->isImplicitAccess());
865 if (!S->isImplicitAccess()) {
866 VisitExpr(S);
867 ID.AddBoolean(S->isArrow());
868 }
John McCall10eae182009-11-30 22:42:35 +0000869 VisitNestedNameSpecifier(S->getQualifier());
870 VisitName(S->getMemberName());
871 ID.AddBoolean(S->hasExplicitTemplateArgs());
872 if (S->hasExplicitTemplateArgs())
873 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +0000874}
875
Sebastian Redl4202c0f2010-09-10 20:55:43 +0000876void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) {
877 VisitExpr(S);
878}
879
Douglas Gregore8e9dd62011-01-03 17:17:50 +0000880void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) {
881 VisitExpr(S);
882}
883
Douglas Gregor820ba7b2011-01-04 17:33:58 +0000884void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) {
885 VisitExpr(S);
886 VisitDecl(S->getPack());
887}
888
Douglas Gregorcdbc5392011-01-15 01:15:58 +0000889void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
890 SubstNonTypeTemplateParmPackExpr *S) {
891 VisitExpr(S);
892 VisitDecl(S->getParameterPack());
893 VisitTemplateArgument(S->getArgumentPack());
894}
895
John McCall8d69a212010-11-15 23:31:06 +0000896void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
897 VisitExpr(E);
898}
899
Douglas Gregora7095092009-07-28 14:44:31 +0000900void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
901 VisitExpr(S);
902}
903
904void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
905 VisitExpr(S);
906 VisitType(S->getEncodedType());
907}
908
909void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
910 VisitExpr(S);
911 VisitName(S->getSelector());
912}
913
914void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
915 VisitExpr(S);
916 VisitDecl(S->getProtocol());
917}
918
919void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
920 VisitExpr(S);
921 VisitDecl(S->getDecl());
922 ID.AddBoolean(S->isArrow());
923 ID.AddBoolean(S->isFreeIvar());
924}
925
926void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
927 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +0000928 if (S->isImplicitProperty()) {
929 VisitDecl(S->getImplicitPropertyGetter());
930 VisitDecl(S->getImplicitPropertySetter());
931 } else {
932 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000933 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000934 if (S->isSuperReceiver()) {
935 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +0000936 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000937 }
Douglas Gregora7095092009-07-28 14:44:31 +0000938}
939
940void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
941 VisitExpr(S);
942 VisitName(S->getSelector());
943 VisitDecl(S->getMethodDecl());
944}
945
Douglas Gregora7095092009-07-28 14:44:31 +0000946void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
947 VisitExpr(S);
948 ID.AddBoolean(S->isArrow());
949}
950
Douglas Gregord9aedfa2009-07-28 15:32:17 +0000951void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +0000952 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +0000953
Douglas Gregora5dd9f82009-07-30 23:18:24 +0000954 if (Canonical && D) {
Douglas Gregor802a0302009-07-31 05:24:01 +0000955 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +0000956 ID.AddInteger(NTTP->getDepth());
957 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +0000958 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +0000959 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000960 return;
961 }
Mike Stump11289f42009-09-09 15:08:12 +0000962
Douglas Gregor70317122009-07-31 15:45:02 +0000963 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +0000964 // The Itanium C++ ABI uses the type, scope depth, and scope
965 // index of a parameter when mangling expressions that involve
966 // function parameters, so we will use the parameter's type for
967 // establishing function parameter identity. That way, our
968 // definition of "equivalent" (per C++ [temp.over.link]) is at
969 // least as strong as the definition of "equivalent" used for
970 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +0000971 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +0000972 ID.AddInteger(Parm->getFunctionScopeDepth());
973 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +0000974 return;
975 }
Mike Stump11289f42009-09-09 15:08:12 +0000976
Douglas Gregorc97f09f2009-07-31 15:46:56 +0000977 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
978 ID.AddInteger(TTP->getDepth());
979 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +0000980 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +0000981 return;
982 }
Douglas Gregor5c193b92009-07-28 00:33:38 +0000983 }
Mike Stump11289f42009-09-09 15:08:12 +0000984
Douglas Gregord9aedfa2009-07-28 15:32:17 +0000985 ID.AddPointer(D? D->getCanonicalDecl() : 0);
986}
987
988void StmtProfiler::VisitType(QualType T) {
989 if (Canonical)
990 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +0000991
Douglas Gregor5c193b92009-07-28 00:33:38 +0000992 ID.AddPointer(T.getAsOpaquePtr());
993}
994
995void StmtProfiler::VisitName(DeclarationName Name) {
996 ID.AddPointer(Name.getAsOpaquePtr());
997}
998
999void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1000 if (Canonical)
1001 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1002 ID.AddPointer(NNS);
1003}
1004
1005void StmtProfiler::VisitTemplateName(TemplateName Name) {
1006 if (Canonical)
1007 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregor5c193b92009-07-28 00:33:38 +00001009 Name.Profile(ID);
1010}
1011
John McCall0ad16662009-10-29 08:12:44 +00001012void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001013 unsigned NumArgs) {
1014 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001015 for (unsigned I = 0; I != NumArgs; ++I)
1016 VisitTemplateArgument(Args[I].getArgument());
1017}
Mike Stump11289f42009-09-09 15:08:12 +00001018
John McCall0ad16662009-10-29 08:12:44 +00001019void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1020 // Mostly repetitive with TemplateArgument::Profile!
1021 ID.AddInteger(Arg.getKind());
1022 switch (Arg.getKind()) {
1023 case TemplateArgument::Null:
1024 break;
Mike Stump11289f42009-09-09 15:08:12 +00001025
John McCall0ad16662009-10-29 08:12:44 +00001026 case TemplateArgument::Type:
1027 VisitType(Arg.getAsType());
1028 break;
Mike Stump11289f42009-09-09 15:08:12 +00001029
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001030 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001031 case TemplateArgument::TemplateExpansion:
1032 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001033 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001034
John McCall0ad16662009-10-29 08:12:44 +00001035 case TemplateArgument::Declaration:
1036 VisitDecl(Arg.getAsDecl());
1037 break;
Mike Stump11289f42009-09-09 15:08:12 +00001038
John McCall0ad16662009-10-29 08:12:44 +00001039 case TemplateArgument::Integral:
1040 Arg.getAsIntegral()->Profile(ID);
1041 VisitType(Arg.getIntegralType());
1042 break;
Mike Stump11289f42009-09-09 15:08:12 +00001043
John McCall0ad16662009-10-29 08:12:44 +00001044 case TemplateArgument::Expression:
1045 Visit(Arg.getAsExpr());
1046 break;
Mike Stump11289f42009-09-09 15:08:12 +00001047
John McCall0ad16662009-10-29 08:12:44 +00001048 case TemplateArgument::Pack:
1049 const TemplateArgument *Pack = Arg.pack_begin();
1050 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1051 VisitTemplateArgument(Pack[i]);
1052 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001053 }
1054}
1055
Jay Foad39c79802011-01-12 09:06:06 +00001056void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001057 bool Canonical) {
1058 StmtProfiler Profiler(ID, Context, Canonical);
1059 Profiler.Visit(this);
1060}