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