blob: 5beefd14f9f6397e4128265c1fff006f20d00c68 [file] [log] [blame]
Douglas Gregor41ef0c32009-07-28 00:33:38 +00001//===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt::Profile method, which builds a unique bit
Douglas Gregor00aa3a62009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor41ef0c32009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregor071f4eb2009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000017#include "clang/AST/DeclTemplate.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/ExprCXX.h"
20#include "clang/AST/ExprObjC.h"
21#include "clang/AST/StmtVisitor.h"
22#include "llvm/ADT/FoldingSet.h"
Douglas Gregor41ef0c32009-07-28 00:33:38 +000023using namespace clang;
24
25namespace {
Benjamin Kramer770b4a82009-11-28 19:03:38 +000026 class StmtProfiler : public StmtVisitor<StmtProfiler> {
Douglas Gregor41ef0c32009-07-28 00:33:38 +000027 llvm::FoldingSetNodeID &ID;
28 ASTContext &Context;
29 bool Canonical;
Mike Stump1eb44332009-09-09 15:08:12 +000030
Douglas Gregor41ef0c32009-07-28 00:33:38 +000031 public:
32 StmtProfiler(llvm::FoldingSetNodeID &ID, ASTContext &Context,
Mike Stump1eb44332009-09-09 15:08:12 +000033 bool Canonical)
Douglas Gregor41ef0c32009-07-28 00:33:38 +000034 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump1eb44332009-09-09 15:08:12 +000035
Douglas Gregor41ef0c32009-07-28 00:33:38 +000036 void VisitStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +000037
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000038#define STMT(Node, Base) void Visit##Node(Node *S);
Sean Hunt4bfe1962010-05-05 15:24:00 +000039#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +000040
Douglas Gregor41ef0c32009-07-28 00:33:38 +000041 /// \brief Visit a declaration that is referenced within an expression
42 /// or statement.
43 void VisitDecl(Decl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000044
45 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor41ef0c32009-07-28 00:33:38 +000046 /// statement.
47 void VisitType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +000048
Douglas Gregor41ef0c32009-07-28 00:33:38 +000049 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000051
Douglas Gregor41ef0c32009-07-28 00:33:38 +000052 /// \brief Visit a nested-name-specifier that occurs within an expression
53 /// or statement.
54 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump1eb44332009-09-09 15:08:12 +000055
Douglas Gregor41ef0c32009-07-28 00:33:38 +000056 /// \brief Visit a template name that occurs within an expression or
57 /// statement.
58 void VisitTemplateName(TemplateName Name);
Mike Stump1eb44332009-09-09 15:08:12 +000059
Douglas Gregor41ef0c32009-07-28 00:33:38 +000060 /// \brief Visit template arguments that occur within an expression or
61 /// statement.
John McCall833ca992009-10-29 08:12:44 +000062 void VisitTemplateArguments(const TemplateArgumentLoc *Args, unsigned NumArgs);
63
64 /// \brief Visit a single template argument.
65 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor41ef0c32009-07-28 00:33:38 +000066 };
67}
68
69void StmtProfiler::VisitStmt(Stmt *S) {
70 ID.AddInteger(S->getStmtClass());
71 for (Stmt::child_iterator C = S->child_begin(), CEnd = S->child_end();
72 C != CEnd; ++C)
73 Visit(*C);
74}
75
Douglas Gregor3fe81fc2009-07-28 15:27:13 +000076void StmtProfiler::VisitDeclStmt(DeclStmt *S) {
77 VisitStmt(S);
78 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
79 D != DEnd; ++D)
80 VisitDecl(*D);
81}
82
83void StmtProfiler::VisitNullStmt(NullStmt *S) {
84 VisitStmt(S);
85}
86
87void StmtProfiler::VisitCompoundStmt(CompoundStmt *S) {
88 VisitStmt(S);
89}
90
91void StmtProfiler::VisitSwitchCase(SwitchCase *S) {
92 VisitStmt(S);
93}
94
95void StmtProfiler::VisitCaseStmt(CaseStmt *S) {
96 VisitStmt(S);
97}
98
99void StmtProfiler::VisitDefaultStmt(DefaultStmt *S) {
100 VisitStmt(S);
101}
102
103void StmtProfiler::VisitLabelStmt(LabelStmt *S) {
104 VisitStmt(S);
105 VisitName(S->getID());
106}
107
108void StmtProfiler::VisitIfStmt(IfStmt *S) {
109 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000110 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000111}
112
Douglas Gregor828e2262009-07-29 16:09:57 +0000113void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
114 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000115 VisitDecl(S->getConditionVariable());
Douglas Gregor828e2262009-07-29 16:09:57 +0000116}
117
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000118void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
119 VisitStmt(S);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000120 VisitDecl(S->getConditionVariable());
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000121}
122
123void StmtProfiler::VisitDoStmt(DoStmt *S) {
124 VisitStmt(S);
125}
126
127void StmtProfiler::VisitForStmt(ForStmt *S) {
128 VisitStmt(S);
129}
130
131void StmtProfiler::VisitGotoStmt(GotoStmt *S) {
132 VisitStmt(S);
133 VisitName(S->getLabel()->getID());
134}
135
136void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
137 VisitStmt(S);
138}
139
140void StmtProfiler::VisitContinueStmt(ContinueStmt *S) {
141 VisitStmt(S);
142}
143
144void StmtProfiler::VisitBreakStmt(BreakStmt *S) {
145 VisitStmt(S);
146}
147
148void StmtProfiler::VisitReturnStmt(ReturnStmt *S) {
149 VisitStmt(S);
150}
151
152void StmtProfiler::VisitAsmStmt(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
172void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) {
173 VisitStmt(S);
174 VisitType(S->getCaughtType());
175}
176
177void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) {
178 VisitStmt(S);
179}
180
181void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
182 VisitStmt(S);
183}
184
185void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
186 VisitStmt(S);
187 ID.AddBoolean(S->hasEllipsis());
188 if (S->getCatchParamDecl())
189 VisitType(S->getCatchParamDecl()->getType());
190}
191
192void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
193 VisitStmt(S);
194}
195
196void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
197 VisitStmt(S);
198}
199
200void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
201 VisitStmt(S);
202}
203
204void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
205 VisitStmt(S);
206}
207
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000208void StmtProfiler::VisitExpr(Expr *S) {
209 VisitStmt(S);
210}
211
212void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) {
213 VisitExpr(S);
Douglas Gregor218f47f2010-07-13 08:37:11 +0000214 if (!Canonical)
215 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000216 VisitDecl(S->getDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000217 if (!Canonical)
218 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000219}
220
221void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) {
222 VisitExpr(S);
223 ID.AddInteger(S->getIdentType());
224}
225
226void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) {
227 VisitExpr(S);
228 S->getValue().Profile(ID);
229}
230
231void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) {
232 VisitExpr(S);
233 ID.AddBoolean(S->isWide());
234 ID.AddInteger(S->getValue());
235}
236
237void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) {
238 VisitExpr(S);
239 S->getValue().Profile(ID);
240 ID.AddBoolean(S->isExact());
241}
242
243void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
244 VisitExpr(S);
245}
246
247void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
248 VisitExpr(S);
Daniel Dunbar932eb6d2009-09-22 10:06:21 +0000249 ID.AddString(S->getString());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000250 ID.AddBoolean(S->isWide());
251}
252
253void StmtProfiler::VisitParenExpr(ParenExpr *S) {
254 VisitExpr(S);
255}
256
Nate Begeman2ef13e52009-08-10 23:49:36 +0000257void StmtProfiler::VisitParenListExpr(ParenListExpr *S) {
258 VisitExpr(S);
259}
260
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000261void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) {
262 VisitExpr(S);
263 ID.AddInteger(S->getOpcode());
264}
265
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000266void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
267 VisitType(S->getTypeSourceInfo()->getType());
268 unsigned n = S->getNumComponents();
269 for (unsigned i = 0; i < n; ++i) {
270 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
271 ID.AddInteger(ON.getKind());
272 switch (ON.getKind()) {
273 case OffsetOfExpr::OffsetOfNode::Array:
274 // Expressions handled below.
275 break;
276
277 case OffsetOfExpr::OffsetOfNode::Field:
278 VisitDecl(ON.getField());
279 break;
280
281 case OffsetOfExpr::OffsetOfNode::Identifier:
282 ID.AddPointer(ON.getFieldName());
283 break;
Sean Huntc3021132010-05-05 15:23:54 +0000284
Douglas Gregorcc8a5d52010-04-29 00:18:15 +0000285 case OffsetOfExpr::OffsetOfNode::Base:
286 // These nodes are implicit, and therefore don't need profiling.
287 break;
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000288 }
289 }
Sean Huntc3021132010-05-05 15:23:54 +0000290
Douglas Gregor8ecdb652010-04-28 22:16:22 +0000291 VisitExpr(S);
292}
293
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000294void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
295 VisitExpr(S);
296 ID.AddBoolean(S->isSizeOf());
297 if (S->isArgumentType())
298 VisitType(S->getArgumentType());
299}
300
301void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) {
302 VisitExpr(S);
303}
304
305void StmtProfiler::VisitCallExpr(CallExpr *S) {
306 VisitExpr(S);
307}
308
309void StmtProfiler::VisitMemberExpr(MemberExpr *S) {
310 VisitExpr(S);
311 VisitDecl(S->getMemberDecl());
Douglas Gregor218f47f2010-07-13 08:37:11 +0000312 if (!Canonical)
313 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000314 ID.AddBoolean(S->isArrow());
315}
316
317void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) {
318 VisitExpr(S);
319 ID.AddBoolean(S->isFileScope());
320}
321
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000322void StmtProfiler::VisitCastExpr(CastExpr *S) {
323 VisitExpr(S);
324}
325
326void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) {
327 VisitCastExpr(S);
Sebastian Redl906082e2010-07-20 04:20:21 +0000328 ID.AddInteger(S->getCategory());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000329}
330
331void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) {
332 VisitCastExpr(S);
333 VisitType(S->getTypeAsWritten());
334}
335
336void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) {
337 VisitExplicitCastExpr(S);
338}
339
340void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) {
341 VisitExpr(S);
342 ID.AddInteger(S->getOpcode());
343}
344
345void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) {
346 VisitBinaryOperator(S);
347}
348
349void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) {
350 VisitExpr(S);
351}
352
353void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) {
354 VisitExpr(S);
Douglas Gregor3fe81fc2009-07-28 15:27:13 +0000355 VisitName(S->getLabel()->getID());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000356}
357
358void StmtProfiler::VisitStmtExpr(StmtExpr *S) {
359 VisitExpr(S);
360}
361
362void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) {
363 VisitExpr(S);
364 VisitType(S->getArgType1());
365 VisitType(S->getArgType2());
366}
367
368void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) {
369 VisitExpr(S);
370}
371
372void StmtProfiler::VisitChooseExpr(ChooseExpr *S) {
373 VisitExpr(S);
374}
375
376void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
377 VisitExpr(S);
378}
379
Douglas Gregor828e2262009-07-29 16:09:57 +0000380void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
381 VisitExpr(S);
382}
383
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000384void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
385 if (S->getSyntacticForm()) {
386 VisitInitListExpr(S->getSyntacticForm());
387 return;
388 }
Mike Stump1eb44332009-09-09 15:08:12 +0000389
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000390 VisitExpr(S);
391}
392
393void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) {
394 VisitExpr(S);
395 ID.AddBoolean(S->usesGNUSyntax());
396 for (DesignatedInitExpr::designators_iterator D = S->designators_begin(),
397 DEnd = S->designators_end();
398 D != DEnd; ++D) {
399 if (D->isFieldDesignator()) {
400 ID.AddInteger(0);
401 VisitName(D->getFieldName());
402 continue;
403 }
Mike Stump1eb44332009-09-09 15:08:12 +0000404
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000405 if (D->isArrayDesignator()) {
406 ID.AddInteger(1);
407 } else {
408 assert(D->isArrayRangeDesignator());
409 ID.AddInteger(2);
410 }
411 ID.AddInteger(D->getFirstExprIndex());
412 }
413}
414
415void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) {
416 VisitExpr(S);
417}
418
419void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) {
420 VisitExpr(S);
421 VisitName(&S->getAccessor());
422}
423
424void StmtProfiler::VisitBlockExpr(BlockExpr *S) {
425 VisitExpr(S);
426 VisitDecl(S->getBlockDecl());
427}
428
429void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) {
430 VisitExpr(S);
431 VisitDecl(S->getDecl());
432 ID.AddBoolean(S->isByRef());
433 ID.AddBoolean(S->isConstQualAdded());
Fariborz Jahanian89f9d3a2010-06-04 19:06:53 +0000434 if (S->getCopyConstructorExpr())
435 Visit(S->getCopyConstructorExpr());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000436}
437
Douglas Gregora89064a2010-05-19 04:13:23 +0000438static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S,
439 UnaryOperator::Opcode &UnaryOp,
440 BinaryOperator::Opcode &BinaryOp) {
441 switch (S->getOperator()) {
442 case OO_None:
443 case OO_New:
444 case OO_Delete:
445 case OO_Array_New:
446 case OO_Array_Delete:
447 case OO_Arrow:
448 case OO_Call:
449 case OO_Conditional:
450 case NUM_OVERLOADED_OPERATORS:
451 llvm_unreachable("Invalid operator call kind");
452 return Stmt::ArraySubscriptExprClass;
453
454 case OO_Plus:
455 if (S->getNumArgs() == 1) {
456 UnaryOp = UnaryOperator::Plus;
457 return Stmt::UnaryOperatorClass;
458 }
459
460 BinaryOp = BinaryOperator::Add;
461 return Stmt::BinaryOperatorClass;
462
463 case OO_Minus:
464 if (S->getNumArgs() == 1) {
465 UnaryOp = UnaryOperator::Minus;
466 return Stmt::UnaryOperatorClass;
467 }
468
469 BinaryOp = BinaryOperator::Sub;
470 return Stmt::BinaryOperatorClass;
471
472 case OO_Star:
473 if (S->getNumArgs() == 1) {
474 UnaryOp = UnaryOperator::Minus;
475 return Stmt::UnaryOperatorClass;
476 }
477
478 BinaryOp = BinaryOperator::Sub;
479 return Stmt::BinaryOperatorClass;
480
481 case OO_Slash:
482 BinaryOp = BinaryOperator::Div;
483 return Stmt::BinaryOperatorClass;
484
485 case OO_Percent:
486 BinaryOp = BinaryOperator::Rem;
487 return Stmt::BinaryOperatorClass;
488
489 case OO_Caret:
490 BinaryOp = BinaryOperator::Xor;
491 return Stmt::BinaryOperatorClass;
492
493 case OO_Amp:
494 if (S->getNumArgs() == 1) {
495 UnaryOp = UnaryOperator::AddrOf;
496 return Stmt::UnaryOperatorClass;
497 }
498
499 BinaryOp = BinaryOperator::And;
500 return Stmt::BinaryOperatorClass;
501
502 case OO_Pipe:
503 BinaryOp = BinaryOperator::Or;
504 return Stmt::BinaryOperatorClass;
505
506 case OO_Tilde:
507 UnaryOp = UnaryOperator::Not;
508 return Stmt::UnaryOperatorClass;
509
510 case OO_Exclaim:
511 UnaryOp = UnaryOperator::LNot;
512 return Stmt::UnaryOperatorClass;
513
514 case OO_Equal:
515 BinaryOp = BinaryOperator::Assign;
516 return Stmt::BinaryOperatorClass;
517
518 case OO_Less:
519 BinaryOp = BinaryOperator::LT;
520 return Stmt::BinaryOperatorClass;
521
522 case OO_Greater:
523 BinaryOp = BinaryOperator::GT;
524 return Stmt::BinaryOperatorClass;
525
526 case OO_PlusEqual:
527 BinaryOp = BinaryOperator::AddAssign;
528 return Stmt::CompoundAssignOperatorClass;
529
530 case OO_MinusEqual:
531 BinaryOp = BinaryOperator::SubAssign;
532 return Stmt::CompoundAssignOperatorClass;
533
534 case OO_StarEqual:
535 BinaryOp = BinaryOperator::MulAssign;
536 return Stmt::CompoundAssignOperatorClass;
537
538 case OO_SlashEqual:
539 BinaryOp = BinaryOperator::DivAssign;
540 return Stmt::CompoundAssignOperatorClass;
541
542 case OO_PercentEqual:
543 BinaryOp = BinaryOperator::RemAssign;
544 return Stmt::CompoundAssignOperatorClass;
545
546 case OO_CaretEqual:
547 BinaryOp = BinaryOperator::XorAssign;
548 return Stmt::CompoundAssignOperatorClass;
549
550 case OO_AmpEqual:
551 BinaryOp = BinaryOperator::AndAssign;
552 return Stmt::CompoundAssignOperatorClass;
553
554 case OO_PipeEqual:
555 BinaryOp = BinaryOperator::OrAssign;
556 return Stmt::CompoundAssignOperatorClass;
557
558 case OO_LessLess:
559 BinaryOp = BinaryOperator::Shl;
560 return Stmt::BinaryOperatorClass;
561
562 case OO_GreaterGreater:
563 BinaryOp = BinaryOperator::Shr;
564 return Stmt::BinaryOperatorClass;
565
566 case OO_LessLessEqual:
567 BinaryOp = BinaryOperator::ShlAssign;
568 return Stmt::CompoundAssignOperatorClass;
569
570 case OO_GreaterGreaterEqual:
571 BinaryOp = BinaryOperator::ShrAssign;
572 return Stmt::CompoundAssignOperatorClass;
573
574 case OO_EqualEqual:
575 BinaryOp = BinaryOperator::EQ;
576 return Stmt::BinaryOperatorClass;
577
578 case OO_ExclaimEqual:
579 BinaryOp = BinaryOperator::NE;
580 return Stmt::BinaryOperatorClass;
581
582 case OO_LessEqual:
583 BinaryOp = BinaryOperator::LE;
584 return Stmt::BinaryOperatorClass;
585
586 case OO_GreaterEqual:
587 BinaryOp = BinaryOperator::GE;
588 return Stmt::BinaryOperatorClass;
589
590 case OO_AmpAmp:
591 BinaryOp = BinaryOperator::LAnd;
592 return Stmt::BinaryOperatorClass;
593
594 case OO_PipePipe:
595 BinaryOp = BinaryOperator::LOr;
596 return Stmt::BinaryOperatorClass;
597
598 case OO_PlusPlus:
599 UnaryOp = S->getNumArgs() == 1? UnaryOperator::PreInc
600 : UnaryOperator::PostInc;
601 return Stmt::UnaryOperatorClass;
602
603 case OO_MinusMinus:
604 UnaryOp = S->getNumArgs() == 1? UnaryOperator::PreDec
605 : UnaryOperator::PostDec;
606 return Stmt::UnaryOperatorClass;
607
608 case OO_Comma:
609 BinaryOp = BinaryOperator::Comma;
610 return Stmt::BinaryOperatorClass;
611
612
613 case OO_ArrowStar:
614 BinaryOp = BinaryOperator::PtrMemI;
615 return Stmt::BinaryOperatorClass;
616
617 case OO_Subscript:
618 return Stmt::ArraySubscriptExprClass;
619 }
620
621 llvm_unreachable("Invalid overloaded operator expression");
622}
623
624
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000625void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
Douglas Gregora89064a2010-05-19 04:13:23 +0000626 if (S->isTypeDependent()) {
627 // Type-dependent operator calls are profiled like their underlying
628 // syntactic operator.
Douglas Gregor8f43d522010-05-19 18:41:43 +0000629 UnaryOperator::Opcode UnaryOp = UnaryOperator::Extension;
630 BinaryOperator::Opcode BinaryOp = BinaryOperator::Comma;
Douglas Gregora89064a2010-05-19 04:13:23 +0000631 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
632
633 ID.AddInteger(SC);
634 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
635 Visit(S->getArg(I));
636 if (SC == Stmt::UnaryOperatorClass)
637 ID.AddInteger(UnaryOp);
638 else if (SC == Stmt::BinaryOperatorClass ||
639 SC == Stmt::CompoundAssignOperatorClass)
640 ID.AddInteger(BinaryOp);
641 else
642 assert(SC == Stmt::ArraySubscriptExprClass);
643
644 return;
645 }
646
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000647 VisitCallExpr(S);
648 ID.AddInteger(S->getOperator());
649}
650
651void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) {
652 VisitCallExpr(S);
653}
654
655void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) {
656 VisitExplicitCastExpr(S);
657}
658
659void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) {
660 VisitCXXNamedCastExpr(S);
661}
662
663void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) {
664 VisitCXXNamedCastExpr(S);
665}
666
667void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) {
668 VisitCXXNamedCastExpr(S);
669}
670
671void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) {
672 VisitCXXNamedCastExpr(S);
673}
674
675void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
676 VisitExpr(S);
677 ID.AddBoolean(S->getValue());
678}
679
Douglas Gregor828e2262009-07-29 16:09:57 +0000680void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
681 VisitExpr(S);
682}
683
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000684void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
685 VisitExpr(S);
686 if (S->isTypeOperand())
687 VisitType(S->getTypeOperand());
688}
689
690void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) {
691 VisitExpr(S);
692}
693
694void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) {
695 VisitExpr(S);
696}
697
698void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) {
699 VisitExpr(S);
700 VisitDecl(S->getParam());
701}
702
703void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
704 VisitExpr(S);
705 VisitDecl(
706 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
707}
708
Anders Carlssoneb60edf2010-01-29 02:39:32 +0000709void StmtProfiler::VisitCXXBindReferenceExpr(CXXBindReferenceExpr *S) {
710 VisitExpr(S);
711}
712
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000713void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
714 VisitExpr(S);
715 VisitDecl(S->getConstructor());
716 ID.AddBoolean(S->isElidable());
717}
718
719void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) {
720 VisitExplicitCastExpr(S);
721}
722
723void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) {
724 VisitCXXConstructExpr(S);
725}
726
Douglas Gregored8abf12010-07-08 06:14:04 +0000727void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000728 VisitExpr(S);
729}
730
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000731void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) {
732 VisitExpr(S);
733 ID.AddBoolean(S->isGlobalDelete());
734 ID.AddBoolean(S->isArrayForm());
735 VisitDecl(S->getOperatorDelete());
736}
737
738
739void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) {
740 VisitExpr(S);
741 VisitType(S->getAllocatedType());
742 VisitDecl(S->getOperatorNew());
743 VisitDecl(S->getOperatorDelete());
744 VisitDecl(S->getConstructor());
745 ID.AddBoolean(S->isArray());
746 ID.AddInteger(S->getNumPlacementArgs());
747 ID.AddBoolean(S->isGlobalNew());
748 ID.AddBoolean(S->isParenTypeId());
749 ID.AddBoolean(S->hasInitializer());
750 ID.AddInteger(S->getNumConstructorArgs());
751}
752
Douglas Gregora71d8192009-09-04 17:36:40 +0000753void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) {
754 VisitExpr(S);
755 ID.AddBoolean(S->isArrow());
756 VisitNestedNameSpecifier(S->getQualifier());
757 VisitType(S->getDestroyedType());
758}
759
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000760void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) {
John McCallf7a1a742009-11-24 19:00:30 +0000761 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000762 VisitName(S->getName());
John McCallf7a1a742009-11-24 19:00:30 +0000763 ID.AddBoolean(S->hasExplicitTemplateArgs());
764 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisc35919b2010-08-15 01:15:38 +0000765 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
766 S->getExplicitTemplateArgs().NumTemplateArgs);
767}
768
769void
770StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) {
771 VisitOverloadExpr(S);
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000772}
773
774void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) {
775 VisitExpr(S);
776 ID.AddInteger(S->getTrait());
777 VisitType(S->getQueriedType());
778}
779
John McCall865d4472009-11-19 22:55:06 +0000780void
781StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) {
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000782 VisitExpr(S);
783 VisitName(S->getDeclName());
784 VisitNestedNameSpecifier(S->getQualifier());
John McCallf7a1a742009-11-24 19:00:30 +0000785 ID.AddBoolean(S->hasExplicitTemplateArgs());
786 if (S->hasExplicitTemplateArgs())
787 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000788}
789
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000790void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) {
791 VisitExpr(S);
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000792 for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I)
793 VisitDecl(
794 const_cast<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor()));
795}
796
Mike Stump1eb44332009-09-09 15:08:12 +0000797void
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000798StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) {
799 VisitExpr(S);
800 VisitType(S->getTypeAsWritten());
801}
802
John McCall865d4472009-11-19 22:55:06 +0000803void
804StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000805 ID.AddBoolean(S->isImplicitAccess());
806 if (!S->isImplicitAccess()) {
807 VisitExpr(S);
808 ID.AddBoolean(S->isArrow());
809 }
Douglas Gregora38c6872009-09-03 16:14:30 +0000810 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000811 VisitName(S->getMember());
John McCallaa81e162009-12-01 22:10:20 +0000812 ID.AddBoolean(S->hasExplicitTemplateArgs());
813 if (S->hasExplicitTemplateArgs())
John McCall129e2df2009-11-30 22:42:35 +0000814 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
815}
816
817void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) {
John McCallaa81e162009-12-01 22:10:20 +0000818 ID.AddBoolean(S->isImplicitAccess());
819 if (!S->isImplicitAccess()) {
820 VisitExpr(S);
821 ID.AddBoolean(S->isArrow());
822 }
John McCall129e2df2009-11-30 22:42:35 +0000823 VisitNestedNameSpecifier(S->getQualifier());
824 VisitName(S->getMemberName());
825 ID.AddBoolean(S->hasExplicitTemplateArgs());
826 if (S->hasExplicitTemplateArgs())
827 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000828}
829
830void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) {
831 VisitExpr(S);
832}
833
834void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) {
835 VisitExpr(S);
836 VisitType(S->getEncodedType());
837}
838
839void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) {
840 VisitExpr(S);
841 VisitName(S->getSelector());
842}
843
844void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) {
845 VisitExpr(S);
846 VisitDecl(S->getProtocol());
847}
848
849void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) {
850 VisitExpr(S);
851 VisitDecl(S->getDecl());
852 ID.AddBoolean(S->isArrow());
853 ID.AddBoolean(S->isFreeIvar());
854}
855
856void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) {
857 VisitExpr(S);
858 VisitDecl(S->getProperty());
859}
860
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000861void StmtProfiler::VisitObjCImplicitSetterGetterRefExpr(
862 ObjCImplicitSetterGetterRefExpr *S) {
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000863 VisitExpr(S);
864 VisitDecl(S->getGetterMethod());
865 VisitDecl(S->getSetterMethod());
Fariborz Jahaniand2ae5aa2009-08-18 21:37:33 +0000866 VisitDecl(S->getInterfaceDecl());
Douglas Gregor071f4eb2009-07-28 14:44:31 +0000867}
868
869void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) {
870 VisitExpr(S);
871 VisitName(S->getSelector());
872 VisitDecl(S->getMethodDecl());
873}
874
875void StmtProfiler::VisitObjCSuperExpr(ObjCSuperExpr *S) {
876 VisitExpr(S);
877}
878
879void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) {
880 VisitExpr(S);
881 ID.AddBoolean(S->isArrow());
882}
883
Douglas Gregord584eb22009-07-28 15:32:17 +0000884void StmtProfiler::VisitDecl(Decl *D) {
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000885 ID.AddInteger(D? D->getKind() : 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000886
Douglas Gregorb1975722009-07-30 23:18:24 +0000887 if (Canonical && D) {
Douglas Gregor6ebd15e2009-07-31 05:24:01 +0000888 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord584eb22009-07-28 15:32:17 +0000889 ID.AddInteger(NTTP->getDepth());
890 ID.AddInteger(NTTP->getIndex());
Douglas Gregor828e2262009-07-29 16:09:57 +0000891 VisitType(NTTP->getType());
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000892 return;
893 }
Mike Stump1eb44332009-09-09 15:08:12 +0000894
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000895 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
896 // The Itanium C++ ABI uses the type of a parameter when mangling
897 // expressions that involve function parameters, so we will use the
898 // parameter's type for establishing function parameter identity. That
Mike Stump1eb44332009-09-09 15:08:12 +0000899 // way, our definition of "equivalent" (per C++ [temp.over.link])
Douglas Gregor4a3f7802009-07-31 15:45:02 +0000900 // matches the definition of "equivalent" used for name mangling.
901 VisitType(Parm->getType());
902 return;
903 }
Mike Stump1eb44332009-09-09 15:08:12 +0000904
Douglas Gregora2ffb982009-07-31 15:46:56 +0000905 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
906 ID.AddInteger(TTP->getDepth());
907 ID.AddInteger(TTP->getIndex());
908 return;
909 }
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000910 }
Mike Stump1eb44332009-09-09 15:08:12 +0000911
Douglas Gregord584eb22009-07-28 15:32:17 +0000912 ID.AddPointer(D? D->getCanonicalDecl() : 0);
913}
914
915void StmtProfiler::VisitType(QualType T) {
916 if (Canonical)
917 T = Context.getCanonicalType(T);
Mike Stump1eb44332009-09-09 15:08:12 +0000918
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000919 ID.AddPointer(T.getAsOpaquePtr());
920}
921
922void StmtProfiler::VisitName(DeclarationName Name) {
923 ID.AddPointer(Name.getAsOpaquePtr());
924}
925
926void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
927 if (Canonical)
928 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
929 ID.AddPointer(NNS);
930}
931
932void StmtProfiler::VisitTemplateName(TemplateName Name) {
933 if (Canonical)
934 Name = Context.getCanonicalTemplateName(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000935
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000936 Name.Profile(ID);
937}
938
John McCall833ca992009-10-29 08:12:44 +0000939void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000940 unsigned NumArgs) {
941 ID.AddInteger(NumArgs);
John McCall833ca992009-10-29 08:12:44 +0000942 for (unsigned I = 0; I != NumArgs; ++I)
943 VisitTemplateArgument(Args[I].getArgument());
944}
Mike Stump1eb44332009-09-09 15:08:12 +0000945
John McCall833ca992009-10-29 08:12:44 +0000946void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
947 // Mostly repetitive with TemplateArgument::Profile!
948 ID.AddInteger(Arg.getKind());
949 switch (Arg.getKind()) {
950 case TemplateArgument::Null:
951 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000952
John McCall833ca992009-10-29 08:12:44 +0000953 case TemplateArgument::Type:
954 VisitType(Arg.getAsType());
955 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000956
Douglas Gregor788cd062009-11-11 01:00:40 +0000957 case TemplateArgument::Template:
958 VisitTemplateName(Arg.getAsTemplate());
959 break;
Sean Huntc3021132010-05-05 15:23:54 +0000960
John McCall833ca992009-10-29 08:12:44 +0000961 case TemplateArgument::Declaration:
962 VisitDecl(Arg.getAsDecl());
963 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000964
John McCall833ca992009-10-29 08:12:44 +0000965 case TemplateArgument::Integral:
966 Arg.getAsIntegral()->Profile(ID);
967 VisitType(Arg.getIntegralType());
968 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000969
John McCall833ca992009-10-29 08:12:44 +0000970 case TemplateArgument::Expression:
971 Visit(Arg.getAsExpr());
972 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000973
John McCall833ca992009-10-29 08:12:44 +0000974 case TemplateArgument::Pack:
975 const TemplateArgument *Pack = Arg.pack_begin();
976 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
977 VisitTemplateArgument(Pack[i]);
978 break;
Douglas Gregor41ef0c32009-07-28 00:33:38 +0000979 }
980}
981
982void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
983 bool Canonical) {
984 StmtProfiler Profiler(ID, Context, Canonical);
985 Profiler.Visit(this);
986}