]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/lib/AST/StmtProfile.cpp
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / lib / AST / StmtProfile.cpp
1 //===---- 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
11 // representation that identifies a statement/expression.
12 //
13 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/AST/DeclObjC.h"
17 #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"
23 using namespace clang;
24
25 namespace {
26   class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
27     llvm::FoldingSetNodeID &ID;
28     const ASTContext &Context;
29     bool Canonical;
30
31   public:
32     StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
33                  bool Canonical)
34       : ID(ID), Context(Context), Canonical(Canonical) { }
35
36     void VisitStmt(const Stmt *S);
37
38 #define STMT(Node, Base) void Visit##Node(const Node *S);
39 #include "clang/AST/StmtNodes.inc"
40
41     /// \brief Visit a declaration that is referenced within an expression
42     /// or statement.
43     void VisitDecl(const Decl *D);
44
45     /// \brief Visit a type that is referenced within an expression or
46     /// statement.
47     void VisitType(QualType T);
48
49     /// \brief Visit a name that occurs within an expression or statement.
50     void VisitName(DeclarationName Name);
51
52     /// \brief Visit a nested-name-specifier that occurs within an expression
53     /// or statement.
54     void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
55
56     /// \brief Visit a template name that occurs within an expression or
57     /// statement.
58     void VisitTemplateName(TemplateName Name);
59
60     /// \brief Visit template arguments that occur within an expression or
61     /// statement.
62     void VisitTemplateArguments(const TemplateArgumentLoc *Args,
63                                 unsigned NumArgs);
64
65     /// \brief Visit a single template argument.
66     void VisitTemplateArgument(const TemplateArgument &Arg);
67   };
68 }
69
70 void StmtProfiler::VisitStmt(const Stmt *S) {
71   ID.AddInteger(S->getStmtClass());
72   for (Stmt::const_child_range C = S->children(); C; ++C)
73     Visit(*C);
74 }
75
76 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
77   VisitStmt(S);
78   for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
79        D != DEnd; ++D)
80     VisitDecl(*D);
81 }
82
83 void StmtProfiler::VisitNullStmt(const NullStmt *S) {
84   VisitStmt(S);
85 }
86
87 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
88   VisitStmt(S);
89 }
90
91 void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
92   VisitStmt(S);
93 }
94
95 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
96   VisitStmt(S);
97 }
98
99 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
100   VisitStmt(S);
101 }
102
103 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
104   VisitStmt(S);
105   VisitDecl(S->getDecl());
106 }
107
108 void StmtProfiler::VisitIfStmt(const IfStmt *S) {
109   VisitStmt(S);
110   VisitDecl(S->getConditionVariable());
111 }
112
113 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
114   VisitStmt(S);
115   VisitDecl(S->getConditionVariable());
116 }
117
118 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
119   VisitStmt(S);
120   VisitDecl(S->getConditionVariable());
121 }
122
123 void StmtProfiler::VisitDoStmt(const DoStmt *S) {
124   VisitStmt(S);
125 }
126
127 void StmtProfiler::VisitForStmt(const ForStmt *S) {
128   VisitStmt(S);
129 }
130
131 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
132   VisitStmt(S);
133   VisitDecl(S->getLabel());
134 }
135
136 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
137   VisitStmt(S);
138 }
139
140 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
141   VisitStmt(S);
142 }
143
144 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
145   VisitStmt(S);
146 }
147
148 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
149   VisitStmt(S);
150 }
151
152 void StmtProfiler::VisitAsmStmt(const AsmStmt *S) {
153   VisitStmt(S);
154   ID.AddBoolean(S->isVolatile());
155   ID.AddBoolean(S->isSimple());
156   VisitStringLiteral(S->getAsmString());
157   ID.AddInteger(S->getNumOutputs());
158   for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
159     ID.AddString(S->getOutputName(I));
160     VisitStringLiteral(S->getOutputConstraintLiteral(I));
161   }
162   ID.AddInteger(S->getNumInputs());
163   for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
164     ID.AddString(S->getInputName(I));
165     VisitStringLiteral(S->getInputConstraintLiteral(I));
166   }
167   ID.AddInteger(S->getNumClobbers());
168   for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
169     VisitStringLiteral(S->getClobber(I));
170 }
171
172 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
173   VisitStmt(S);
174   VisitType(S->getCaughtType());
175 }
176
177 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
178   VisitStmt(S);
179 }
180
181 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
182   VisitStmt(S);
183 }
184
185 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
186   VisitStmt(S);
187 }
188
189 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
190   VisitStmt(S);
191 }
192
193 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
194   VisitStmt(S);
195 }
196
197 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
198   VisitStmt(S);
199 }
200
201 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
202   VisitStmt(S);
203   ID.AddBoolean(S->hasEllipsis());
204   if (S->getCatchParamDecl())
205     VisitType(S->getCatchParamDecl()->getType());
206 }
207
208 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
209   VisitStmt(S);
210 }
211
212 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
213   VisitStmt(S);
214 }
215
216 void
217 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
218   VisitStmt(S);
219 }
220
221 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
222   VisitStmt(S);
223 }
224
225 void
226 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
227   VisitStmt(S);
228 }
229
230 void StmtProfiler::VisitExpr(const Expr *S) {
231   VisitStmt(S);
232 }
233
234 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
235   VisitExpr(S);
236   if (!Canonical)
237     VisitNestedNameSpecifier(S->getQualifier());
238   VisitDecl(S->getDecl());
239   if (!Canonical)
240     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
241 }
242
243 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
244   VisitExpr(S);
245   ID.AddInteger(S->getIdentType());
246 }
247
248 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
249   VisitExpr(S);
250   S->getValue().Profile(ID);
251 }
252
253 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
254   VisitExpr(S);
255   ID.AddBoolean(S->isWide());
256   ID.AddInteger(S->getValue());
257 }
258
259 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
260   VisitExpr(S);
261   S->getValue().Profile(ID);
262   ID.AddBoolean(S->isExact());
263 }
264
265 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
266   VisitExpr(S);
267 }
268
269 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
270   VisitExpr(S);
271   ID.AddString(S->getString());
272   ID.AddBoolean(S->isWide());
273 }
274
275 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
276   VisitExpr(S);
277 }
278
279 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
280   VisitExpr(S);
281 }
282
283 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
284   VisitExpr(S);
285   ID.AddInteger(S->getOpcode());
286 }
287
288 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
289   VisitType(S->getTypeSourceInfo()->getType());
290   unsigned n = S->getNumComponents();
291   for (unsigned i = 0; i < n; ++i) {
292     const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
293     ID.AddInteger(ON.getKind());
294     switch (ON.getKind()) {
295     case OffsetOfExpr::OffsetOfNode::Array:
296       // Expressions handled below.
297       break;
298
299     case OffsetOfExpr::OffsetOfNode::Field:
300       VisitDecl(ON.getField());
301       break;
302
303     case OffsetOfExpr::OffsetOfNode::Identifier:
304       ID.AddPointer(ON.getFieldName());
305       break;
306         
307     case OffsetOfExpr::OffsetOfNode::Base:
308       // These nodes are implicit, and therefore don't need profiling.
309       break;
310     }
311   }
312   
313   VisitExpr(S);
314 }
315
316 void
317 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
318   VisitExpr(S);
319   ID.AddInteger(S->getKind());
320   if (S->isArgumentType())
321     VisitType(S->getArgumentType());
322 }
323
324 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
325   VisitExpr(S);
326 }
327
328 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
329   VisitExpr(S);
330 }
331
332 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
333   VisitExpr(S);
334   VisitDecl(S->getMemberDecl());
335   if (!Canonical)
336     VisitNestedNameSpecifier(S->getQualifier());
337   ID.AddBoolean(S->isArrow());
338 }
339
340 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
341   VisitExpr(S);
342   ID.AddBoolean(S->isFileScope());
343 }
344
345 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
346   VisitExpr(S);
347 }
348
349 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
350   VisitCastExpr(S);
351   ID.AddInteger(S->getValueKind());
352 }
353
354 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
355   VisitCastExpr(S);
356   VisitType(S->getTypeAsWritten());
357 }
358
359 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
360   VisitExplicitCastExpr(S);
361 }
362
363 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
364   VisitExpr(S);
365   ID.AddInteger(S->getOpcode());
366 }
367
368 void
369 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
370   VisitBinaryOperator(S);
371 }
372
373 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
374   VisitExpr(S);
375 }
376
377 void StmtProfiler::VisitBinaryConditionalOperator(
378     const BinaryConditionalOperator *S) {
379   VisitExpr(S);
380 }
381
382 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
383   VisitExpr(S);
384   VisitDecl(S->getLabel());
385 }
386
387 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
388   VisitExpr(S);
389 }
390
391 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
392   VisitExpr(S);
393 }
394
395 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
396   VisitExpr(S);
397 }
398
399 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
400   VisitExpr(S);
401 }
402
403 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
404   VisitExpr(S);
405 }
406
407 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
408   if (S->getSyntacticForm()) {
409     VisitInitListExpr(S->getSyntacticForm());
410     return;
411   }
412
413   VisitExpr(S);
414 }
415
416 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
417   VisitExpr(S);
418   ID.AddBoolean(S->usesGNUSyntax());
419   for (DesignatedInitExpr::const_designators_iterator D =
420          S->designators_begin(), DEnd = S->designators_end();
421        D != DEnd; ++D) {
422     if (D->isFieldDesignator()) {
423       ID.AddInteger(0);
424       VisitName(D->getFieldName());
425       continue;
426     }
427
428     if (D->isArrayDesignator()) {
429       ID.AddInteger(1);
430     } else {
431       assert(D->isArrayRangeDesignator());
432       ID.AddInteger(2);
433     }
434     ID.AddInteger(D->getFirstExprIndex());
435   }
436 }
437
438 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
439   VisitExpr(S);
440 }
441
442 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
443   VisitExpr(S);
444   VisitName(&S->getAccessor());
445 }
446
447 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
448   VisitExpr(S);
449   VisitDecl(S->getBlockDecl());
450 }
451
452 void StmtProfiler::VisitBlockDeclRefExpr(const BlockDeclRefExpr *S) {
453   VisitExpr(S);
454   VisitDecl(S->getDecl());
455   ID.AddBoolean(S->isByRef());
456   ID.AddBoolean(S->isConstQualAdded());
457 }
458
459 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
460   VisitExpr(S);
461   for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
462     QualType T = S->getAssocType(i);
463     if (T.isNull())
464       ID.AddPointer(0);
465     else
466       VisitType(T);
467     VisitExpr(S->getAssocExpr(i));
468   }
469 }
470
471 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
472                                           UnaryOperatorKind &UnaryOp,
473                                           BinaryOperatorKind &BinaryOp) {
474   switch (S->getOperator()) {
475   case OO_None:
476   case OO_New:
477   case OO_Delete:
478   case OO_Array_New:
479   case OO_Array_Delete:
480   case OO_Arrow:
481   case OO_Call:
482   case OO_Conditional:
483   case NUM_OVERLOADED_OPERATORS:
484     llvm_unreachable("Invalid operator call kind");
485     return Stmt::ArraySubscriptExprClass;
486       
487   case OO_Plus:
488     if (S->getNumArgs() == 1) {
489       UnaryOp = UO_Plus;
490       return Stmt::UnaryOperatorClass;
491     }
492     
493     BinaryOp = BO_Add;
494     return Stmt::BinaryOperatorClass;
495       
496   case OO_Minus:
497     if (S->getNumArgs() == 1) {
498       UnaryOp = UO_Minus;
499       return Stmt::UnaryOperatorClass;
500     }
501     
502     BinaryOp = BO_Sub;
503     return Stmt::BinaryOperatorClass;
504
505   case OO_Star:
506     if (S->getNumArgs() == 1) {
507       UnaryOp = UO_Minus;
508       return Stmt::UnaryOperatorClass;
509     }
510     
511     BinaryOp = BO_Sub;
512     return Stmt::BinaryOperatorClass;
513
514   case OO_Slash:
515     BinaryOp = BO_Div;
516     return Stmt::BinaryOperatorClass;
517       
518   case OO_Percent:
519     BinaryOp = BO_Rem;
520     return Stmt::BinaryOperatorClass;
521
522   case OO_Caret:
523     BinaryOp = BO_Xor;
524     return Stmt::BinaryOperatorClass;
525
526   case OO_Amp:
527     if (S->getNumArgs() == 1) {
528       UnaryOp = UO_AddrOf;
529       return Stmt::UnaryOperatorClass;
530     }
531     
532     BinaryOp = BO_And;
533     return Stmt::BinaryOperatorClass;
534       
535   case OO_Pipe:
536     BinaryOp = BO_Or;
537     return Stmt::BinaryOperatorClass;
538
539   case OO_Tilde:
540     UnaryOp = UO_Not;
541     return Stmt::UnaryOperatorClass;
542
543   case OO_Exclaim:
544     UnaryOp = UO_LNot;
545     return Stmt::UnaryOperatorClass;
546
547   case OO_Equal:
548     BinaryOp = BO_Assign;
549     return Stmt::BinaryOperatorClass;
550
551   case OO_Less:
552     BinaryOp = BO_LT;
553     return Stmt::BinaryOperatorClass;
554
555   case OO_Greater:
556     BinaryOp = BO_GT;
557     return Stmt::BinaryOperatorClass;
558       
559   case OO_PlusEqual:
560     BinaryOp = BO_AddAssign;
561     return Stmt::CompoundAssignOperatorClass;
562
563   case OO_MinusEqual:
564     BinaryOp = BO_SubAssign;
565     return Stmt::CompoundAssignOperatorClass;
566
567   case OO_StarEqual:
568     BinaryOp = BO_MulAssign;
569     return Stmt::CompoundAssignOperatorClass;
570
571   case OO_SlashEqual:
572     BinaryOp = BO_DivAssign;
573     return Stmt::CompoundAssignOperatorClass;
574
575   case OO_PercentEqual:
576     BinaryOp = BO_RemAssign;
577     return Stmt::CompoundAssignOperatorClass;
578
579   case OO_CaretEqual:
580     BinaryOp = BO_XorAssign;
581     return Stmt::CompoundAssignOperatorClass;
582     
583   case OO_AmpEqual:
584     BinaryOp = BO_AndAssign;
585     return Stmt::CompoundAssignOperatorClass;
586     
587   case OO_PipeEqual:
588     BinaryOp = BO_OrAssign;
589     return Stmt::CompoundAssignOperatorClass;
590       
591   case OO_LessLess:
592     BinaryOp = BO_Shl;
593     return Stmt::BinaryOperatorClass;
594     
595   case OO_GreaterGreater:
596     BinaryOp = BO_Shr;
597     return Stmt::BinaryOperatorClass;
598
599   case OO_LessLessEqual:
600     BinaryOp = BO_ShlAssign;
601     return Stmt::CompoundAssignOperatorClass;
602     
603   case OO_GreaterGreaterEqual:
604     BinaryOp = BO_ShrAssign;
605     return Stmt::CompoundAssignOperatorClass;
606
607   case OO_EqualEqual:
608     BinaryOp = BO_EQ;
609     return Stmt::BinaryOperatorClass;
610     
611   case OO_ExclaimEqual:
612     BinaryOp = BO_NE;
613     return Stmt::BinaryOperatorClass;
614       
615   case OO_LessEqual:
616     BinaryOp = BO_LE;
617     return Stmt::BinaryOperatorClass;
618     
619   case OO_GreaterEqual:
620     BinaryOp = BO_GE;
621     return Stmt::BinaryOperatorClass;
622       
623   case OO_AmpAmp:
624     BinaryOp = BO_LAnd;
625     return Stmt::BinaryOperatorClass;
626     
627   case OO_PipePipe:
628     BinaryOp = BO_LOr;
629     return Stmt::BinaryOperatorClass;
630
631   case OO_PlusPlus:
632     UnaryOp = S->getNumArgs() == 1? UO_PreInc 
633                                   : UO_PostInc;
634     return Stmt::UnaryOperatorClass;
635
636   case OO_MinusMinus:
637     UnaryOp = S->getNumArgs() == 1? UO_PreDec
638                                   : UO_PostDec;
639     return Stmt::UnaryOperatorClass;
640
641   case OO_Comma:
642     BinaryOp = BO_Comma;
643     return Stmt::BinaryOperatorClass;
644
645
646   case OO_ArrowStar:
647     BinaryOp = BO_PtrMemI;
648     return Stmt::BinaryOperatorClass;
649       
650   case OO_Subscript:
651     return Stmt::ArraySubscriptExprClass;
652   }
653   
654   llvm_unreachable("Invalid overloaded operator expression");
655 }
656                                
657
658 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
659   if (S->isTypeDependent()) {
660     // Type-dependent operator calls are profiled like their underlying
661     // syntactic operator.
662     UnaryOperatorKind UnaryOp = UO_Extension;
663     BinaryOperatorKind BinaryOp = BO_Comma;
664     Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
665     
666     ID.AddInteger(SC);
667     for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
668       Visit(S->getArg(I));
669     if (SC == Stmt::UnaryOperatorClass)
670       ID.AddInteger(UnaryOp);
671     else if (SC == Stmt::BinaryOperatorClass || 
672              SC == Stmt::CompoundAssignOperatorClass)
673       ID.AddInteger(BinaryOp);
674     else
675       assert(SC == Stmt::ArraySubscriptExprClass);
676                     
677     return;
678   }
679   
680   VisitCallExpr(S);
681   ID.AddInteger(S->getOperator());
682 }
683
684 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
685   VisitCallExpr(S);
686 }
687
688 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
689   VisitCallExpr(S);
690 }
691
692 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
693   VisitExpr(S);
694 }
695
696 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
697   VisitExplicitCastExpr(S);
698 }
699
700 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
701   VisitCXXNamedCastExpr(S);
702 }
703
704 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
705   VisitCXXNamedCastExpr(S);
706 }
707
708 void
709 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
710   VisitCXXNamedCastExpr(S);
711 }
712
713 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
714   VisitCXXNamedCastExpr(S);
715 }
716
717 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
718   VisitExpr(S);
719   ID.AddBoolean(S->getValue());
720 }
721
722 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
723   VisitExpr(S);
724 }
725
726 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
727   VisitExpr(S);
728   if (S->isTypeOperand())
729     VisitType(S->getTypeOperand());
730 }
731
732 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
733   VisitExpr(S);
734   if (S->isTypeOperand())
735     VisitType(S->getTypeOperand());
736 }
737
738 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
739   VisitExpr(S);
740 }
741
742 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
743   VisitExpr(S);
744 }
745
746 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
747   VisitExpr(S);
748   VisitDecl(S->getParam());
749 }
750
751 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
752   VisitExpr(S);
753   VisitDecl(
754          const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
755 }
756
757 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
758   VisitExpr(S);
759   VisitDecl(S->getConstructor());
760   ID.AddBoolean(S->isElidable());
761 }
762
763 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
764   VisitExplicitCastExpr(S);
765 }
766
767 void
768 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
769   VisitCXXConstructExpr(S);
770 }
771
772 void
773 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
774   VisitExpr(S);
775 }
776
777 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
778   VisitExpr(S);
779   ID.AddBoolean(S->isGlobalDelete());
780   ID.AddBoolean(S->isArrayForm());
781   VisitDecl(S->getOperatorDelete());
782 }
783
784
785 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
786   VisitExpr(S);
787   VisitType(S->getAllocatedType());
788   VisitDecl(S->getOperatorNew());
789   VisitDecl(S->getOperatorDelete());
790   VisitDecl(S->getConstructor());
791   ID.AddBoolean(S->isArray());
792   ID.AddInteger(S->getNumPlacementArgs());
793   ID.AddBoolean(S->isGlobalNew());
794   ID.AddBoolean(S->isParenTypeId());
795   ID.AddBoolean(S->hasInitializer());
796   ID.AddInteger(S->getNumConstructorArgs());
797 }
798
799 void
800 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
801   VisitExpr(S);
802   ID.AddBoolean(S->isArrow());
803   VisitNestedNameSpecifier(S->getQualifier());
804   VisitType(S->getDestroyedType());
805 }
806
807 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
808   VisitExpr(S);
809   VisitNestedNameSpecifier(S->getQualifier());
810   VisitName(S->getName());
811   ID.AddBoolean(S->hasExplicitTemplateArgs());
812   if (S->hasExplicitTemplateArgs())
813     VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
814                            S->getExplicitTemplateArgs().NumTemplateArgs);
815 }
816
817 void
818 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
819   VisitOverloadExpr(S);
820 }
821
822 void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
823   VisitExpr(S);
824   ID.AddInteger(S->getTrait());
825   VisitType(S->getQueriedType());
826 }
827
828 void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
829   VisitExpr(S);
830   ID.AddInteger(S->getTrait());
831   VisitType(S->getLhsType());
832   VisitType(S->getRhsType());
833 }
834
835 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
836   VisitExpr(S);
837   ID.AddInteger(S->getTrait());
838   VisitType(S->getQueriedType());
839 }
840
841 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
842   VisitExpr(S);
843   ID.AddInteger(S->getTrait());
844   VisitExpr(S->getQueriedExpression());
845 }
846
847 void StmtProfiler::VisitDependentScopeDeclRefExpr(
848     const DependentScopeDeclRefExpr *S) {
849   VisitExpr(S);
850   VisitName(S->getDeclName());
851   VisitNestedNameSpecifier(S->getQualifier());
852   ID.AddBoolean(S->hasExplicitTemplateArgs());
853   if (S->hasExplicitTemplateArgs())
854     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
855 }
856
857 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
858   VisitExpr(S);
859 }
860
861 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
862     const CXXUnresolvedConstructExpr *S) {
863   VisitExpr(S);
864   VisitType(S->getTypeAsWritten());
865 }
866
867 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
868     const CXXDependentScopeMemberExpr *S) {
869   ID.AddBoolean(S->isImplicitAccess());
870   if (!S->isImplicitAccess()) {
871     VisitExpr(S);
872     ID.AddBoolean(S->isArrow());
873   }
874   VisitNestedNameSpecifier(S->getQualifier());
875   VisitName(S->getMember());
876   ID.AddBoolean(S->hasExplicitTemplateArgs());
877   if (S->hasExplicitTemplateArgs())
878     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
879 }
880
881 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
882   ID.AddBoolean(S->isImplicitAccess());
883   if (!S->isImplicitAccess()) {
884     VisitExpr(S);
885     ID.AddBoolean(S->isArrow());
886   }
887   VisitNestedNameSpecifier(S->getQualifier());
888   VisitName(S->getMemberName());
889   ID.AddBoolean(S->hasExplicitTemplateArgs());
890   if (S->hasExplicitTemplateArgs())
891     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
892 }
893
894 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
895   VisitExpr(S);
896 }
897
898 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
899   VisitExpr(S);
900 }
901
902 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
903   VisitExpr(S);
904   VisitDecl(S->getPack());
905 }
906
907 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
908     const SubstNonTypeTemplateParmPackExpr *S) {
909   VisitExpr(S);
910   VisitDecl(S->getParameterPack());
911   VisitTemplateArgument(S->getArgumentPack());
912 }
913
914 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
915     const SubstNonTypeTemplateParmExpr *E) {
916   // Profile exactly as the replacement expression.
917   Visit(E->getReplacement());
918 }
919
920 void StmtProfiler::VisitMaterializeTemporaryExpr(
921                                            const MaterializeTemporaryExpr *S) {
922   VisitExpr(S);
923 }
924
925 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
926   VisitExpr(E);  
927 }
928
929 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
930   VisitExpr(S);
931 }
932
933 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
934   VisitExpr(S);
935   VisitType(S->getEncodedType());
936 }
937
938 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
939   VisitExpr(S);
940   VisitName(S->getSelector());
941 }
942
943 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
944   VisitExpr(S);
945   VisitDecl(S->getProtocol());
946 }
947
948 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
949   VisitExpr(S);
950   VisitDecl(S->getDecl());
951   ID.AddBoolean(S->isArrow());
952   ID.AddBoolean(S->isFreeIvar());
953 }
954
955 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
956   VisitExpr(S);
957   if (S->isImplicitProperty()) {
958     VisitDecl(S->getImplicitPropertyGetter());
959     VisitDecl(S->getImplicitPropertySetter());
960   } else {
961     VisitDecl(S->getExplicitProperty());
962   }
963   if (S->isSuperReceiver()) {
964     ID.AddBoolean(S->isSuperReceiver());
965     VisitType(S->getSuperReceiverType());
966   }
967 }
968
969 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
970   VisitExpr(S);
971   VisitName(S->getSelector());
972   VisitDecl(S->getMethodDecl());
973 }
974
975 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
976   VisitExpr(S);
977   ID.AddBoolean(S->isArrow());
978 }
979
980 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
981     const ObjCIndirectCopyRestoreExpr *S) {
982   VisitExpr(S);
983   ID.AddBoolean(S->shouldCopy());
984 }
985
986 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
987   VisitExplicitCastExpr(S);
988   ID.AddBoolean(S->getBridgeKind());
989 }
990
991 void StmtProfiler::VisitDecl(const Decl *D) {
992   ID.AddInteger(D? D->getKind() : 0);
993
994   if (Canonical && D) {
995     if (const NonTypeTemplateParmDecl *NTTP =
996           dyn_cast<NonTypeTemplateParmDecl>(D)) {
997       ID.AddInteger(NTTP->getDepth());
998       ID.AddInteger(NTTP->getIndex());
999       ID.AddBoolean(NTTP->isParameterPack());
1000       VisitType(NTTP->getType());
1001       return;
1002     }
1003
1004     if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
1005       // The Itanium C++ ABI uses the type, scope depth, and scope
1006       // index of a parameter when mangling expressions that involve
1007       // function parameters, so we will use the parameter's type for
1008       // establishing function parameter identity. That way, our
1009       // definition of "equivalent" (per C++ [temp.over.link]) is at
1010       // least as strong as the definition of "equivalent" used for
1011       // name mangling.
1012       VisitType(Parm->getType());
1013       ID.AddInteger(Parm->getFunctionScopeDepth());
1014       ID.AddInteger(Parm->getFunctionScopeIndex());
1015       return;
1016     }
1017
1018     if (const TemplateTemplateParmDecl *TTP =
1019           dyn_cast<TemplateTemplateParmDecl>(D)) {
1020       ID.AddInteger(TTP->getDepth());
1021       ID.AddInteger(TTP->getIndex());
1022       ID.AddBoolean(TTP->isParameterPack());
1023       return;
1024     }
1025   }
1026
1027   ID.AddPointer(D? D->getCanonicalDecl() : 0);
1028 }
1029
1030 void StmtProfiler::VisitType(QualType T) {
1031   if (Canonical)
1032     T = Context.getCanonicalType(T);
1033
1034   ID.AddPointer(T.getAsOpaquePtr());
1035 }
1036
1037 void StmtProfiler::VisitName(DeclarationName Name) {
1038   ID.AddPointer(Name.getAsOpaquePtr());
1039 }
1040
1041 void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1042   if (Canonical)
1043     NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1044   ID.AddPointer(NNS);
1045 }
1046
1047 void StmtProfiler::VisitTemplateName(TemplateName Name) {
1048   if (Canonical)
1049     Name = Context.getCanonicalTemplateName(Name);
1050
1051   Name.Profile(ID);
1052 }
1053
1054 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
1055                                           unsigned NumArgs) {
1056   ID.AddInteger(NumArgs);
1057   for (unsigned I = 0; I != NumArgs; ++I)
1058     VisitTemplateArgument(Args[I].getArgument());
1059 }
1060
1061 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1062   // Mostly repetitive with TemplateArgument::Profile!
1063   ID.AddInteger(Arg.getKind());
1064   switch (Arg.getKind()) {
1065   case TemplateArgument::Null:
1066     break;
1067
1068   case TemplateArgument::Type:
1069     VisitType(Arg.getAsType());
1070     break;
1071
1072   case TemplateArgument::Template:
1073   case TemplateArgument::TemplateExpansion:
1074     VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
1075     break;
1076       
1077   case TemplateArgument::Declaration:
1078     VisitDecl(Arg.getAsDecl());
1079     break;
1080
1081   case TemplateArgument::Integral:
1082     Arg.getAsIntegral()->Profile(ID);
1083     VisitType(Arg.getIntegralType());
1084     break;
1085
1086   case TemplateArgument::Expression:
1087     Visit(Arg.getAsExpr());
1088     break;
1089
1090   case TemplateArgument::Pack:
1091     const TemplateArgument *Pack = Arg.pack_begin();
1092     for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1093       VisitTemplateArgument(Pack[i]);
1094     break;
1095   }
1096 }
1097
1098 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1099                    bool Canonical) const {
1100   StmtProfiler Profiler(ID, Context, Canonical);
1101   Profiler.Visit(this);
1102 }