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