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; |
| 28 | ASTContext &Context; |
| 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: |
| 32 | StmtProfiler(llvm::FoldingSetNodeID &ID, 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()); |
Fariborz Jahanian | 89f9d3a | 2010-06-04 19:06:53 +0000 | [diff] [blame] | 428 | if (S->getCopyConstructorExpr()) |
| 429 | Visit(S->getCopyConstructorExpr()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 432 | static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 433 | UnaryOperatorKind &UnaryOp, |
| 434 | BinaryOperatorKind &BinaryOp) { |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 435 | switch (S->getOperator()) { |
| 436 | case OO_None: |
| 437 | case OO_New: |
| 438 | case OO_Delete: |
| 439 | case OO_Array_New: |
| 440 | case OO_Array_Delete: |
| 441 | case OO_Arrow: |
| 442 | case OO_Call: |
| 443 | case OO_Conditional: |
| 444 | case NUM_OVERLOADED_OPERATORS: |
| 445 | llvm_unreachable("Invalid operator call kind"); |
| 446 | return Stmt::ArraySubscriptExprClass; |
| 447 | |
| 448 | case OO_Plus: |
| 449 | if (S->getNumArgs() == 1) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 450 | UnaryOp = UO_Plus; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 451 | return Stmt::UnaryOperatorClass; |
| 452 | } |
| 453 | |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 454 | BinaryOp = BO_Add; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 455 | return Stmt::BinaryOperatorClass; |
| 456 | |
| 457 | case OO_Minus: |
| 458 | if (S->getNumArgs() == 1) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 459 | UnaryOp = UO_Minus; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 460 | return Stmt::UnaryOperatorClass; |
| 461 | } |
| 462 | |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 463 | BinaryOp = BO_Sub; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 464 | return Stmt::BinaryOperatorClass; |
| 465 | |
| 466 | case OO_Star: |
| 467 | if (S->getNumArgs() == 1) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 468 | UnaryOp = UO_Minus; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 469 | return Stmt::UnaryOperatorClass; |
| 470 | } |
| 471 | |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 472 | BinaryOp = BO_Sub; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 473 | return Stmt::BinaryOperatorClass; |
| 474 | |
| 475 | case OO_Slash: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 476 | BinaryOp = BO_Div; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 477 | return Stmt::BinaryOperatorClass; |
| 478 | |
| 479 | case OO_Percent: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 480 | BinaryOp = BO_Rem; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 481 | return Stmt::BinaryOperatorClass; |
| 482 | |
| 483 | case OO_Caret: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 484 | BinaryOp = BO_Xor; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 485 | return Stmt::BinaryOperatorClass; |
| 486 | |
| 487 | case OO_Amp: |
| 488 | if (S->getNumArgs() == 1) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 489 | UnaryOp = UO_AddrOf; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 490 | return Stmt::UnaryOperatorClass; |
| 491 | } |
| 492 | |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 493 | BinaryOp = BO_And; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 494 | return Stmt::BinaryOperatorClass; |
| 495 | |
| 496 | case OO_Pipe: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 497 | BinaryOp = BO_Or; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 498 | return Stmt::BinaryOperatorClass; |
| 499 | |
| 500 | case OO_Tilde: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 501 | UnaryOp = UO_Not; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 502 | return Stmt::UnaryOperatorClass; |
| 503 | |
| 504 | case OO_Exclaim: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 505 | UnaryOp = UO_LNot; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 506 | return Stmt::UnaryOperatorClass; |
| 507 | |
| 508 | case OO_Equal: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 509 | BinaryOp = BO_Assign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 510 | return Stmt::BinaryOperatorClass; |
| 511 | |
| 512 | case OO_Less: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 513 | BinaryOp = BO_LT; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 514 | return Stmt::BinaryOperatorClass; |
| 515 | |
| 516 | case OO_Greater: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 517 | BinaryOp = BO_GT; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 518 | return Stmt::BinaryOperatorClass; |
| 519 | |
| 520 | case OO_PlusEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 521 | BinaryOp = BO_AddAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 522 | return Stmt::CompoundAssignOperatorClass; |
| 523 | |
| 524 | case OO_MinusEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 525 | BinaryOp = BO_SubAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 526 | return Stmt::CompoundAssignOperatorClass; |
| 527 | |
| 528 | case OO_StarEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 529 | BinaryOp = BO_MulAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 530 | return Stmt::CompoundAssignOperatorClass; |
| 531 | |
| 532 | case OO_SlashEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 533 | BinaryOp = BO_DivAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 534 | return Stmt::CompoundAssignOperatorClass; |
| 535 | |
| 536 | case OO_PercentEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 537 | BinaryOp = BO_RemAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 538 | return Stmt::CompoundAssignOperatorClass; |
| 539 | |
| 540 | case OO_CaretEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 541 | BinaryOp = BO_XorAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 542 | return Stmt::CompoundAssignOperatorClass; |
| 543 | |
| 544 | case OO_AmpEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 545 | BinaryOp = BO_AndAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 546 | return Stmt::CompoundAssignOperatorClass; |
| 547 | |
| 548 | case OO_PipeEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 549 | BinaryOp = BO_OrAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 550 | return Stmt::CompoundAssignOperatorClass; |
| 551 | |
| 552 | case OO_LessLess: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 553 | BinaryOp = BO_Shl; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 554 | return Stmt::BinaryOperatorClass; |
| 555 | |
| 556 | case OO_GreaterGreater: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 557 | BinaryOp = BO_Shr; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 558 | return Stmt::BinaryOperatorClass; |
| 559 | |
| 560 | case OO_LessLessEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 561 | BinaryOp = BO_ShlAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 562 | return Stmt::CompoundAssignOperatorClass; |
| 563 | |
| 564 | case OO_GreaterGreaterEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 565 | BinaryOp = BO_ShrAssign; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 566 | return Stmt::CompoundAssignOperatorClass; |
| 567 | |
| 568 | case OO_EqualEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 569 | BinaryOp = BO_EQ; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 570 | return Stmt::BinaryOperatorClass; |
| 571 | |
| 572 | case OO_ExclaimEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 573 | BinaryOp = BO_NE; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 574 | return Stmt::BinaryOperatorClass; |
| 575 | |
| 576 | case OO_LessEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 577 | BinaryOp = BO_LE; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 578 | return Stmt::BinaryOperatorClass; |
| 579 | |
| 580 | case OO_GreaterEqual: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 581 | BinaryOp = BO_GE; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 582 | return Stmt::BinaryOperatorClass; |
| 583 | |
| 584 | case OO_AmpAmp: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 585 | BinaryOp = BO_LAnd; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 586 | return Stmt::BinaryOperatorClass; |
| 587 | |
| 588 | case OO_PipePipe: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 589 | BinaryOp = BO_LOr; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 590 | return Stmt::BinaryOperatorClass; |
| 591 | |
| 592 | case OO_PlusPlus: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 593 | UnaryOp = S->getNumArgs() == 1? UO_PreInc |
| 594 | : UO_PostInc; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 595 | return Stmt::UnaryOperatorClass; |
| 596 | |
| 597 | case OO_MinusMinus: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 598 | UnaryOp = S->getNumArgs() == 1? UO_PreDec |
| 599 | : UO_PostDec; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 600 | return Stmt::UnaryOperatorClass; |
| 601 | |
| 602 | case OO_Comma: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 603 | BinaryOp = BO_Comma; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 604 | return Stmt::BinaryOperatorClass; |
| 605 | |
| 606 | |
| 607 | case OO_ArrowStar: |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 608 | BinaryOp = BO_PtrMemI; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 609 | return Stmt::BinaryOperatorClass; |
| 610 | |
| 611 | case OO_Subscript: |
| 612 | return Stmt::ArraySubscriptExprClass; |
| 613 | } |
| 614 | |
| 615 | llvm_unreachable("Invalid overloaded operator expression"); |
| 616 | } |
| 617 | |
| 618 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 619 | void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) { |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 620 | if (S->isTypeDependent()) { |
| 621 | // Type-dependent operator calls are profiled like their underlying |
| 622 | // syntactic operator. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 623 | UnaryOperatorKind UnaryOp = UO_Extension; |
| 624 | BinaryOperatorKind BinaryOp = BO_Comma; |
Douglas Gregor | a89064a | 2010-05-19 04:13:23 +0000 | [diff] [blame] | 625 | Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp); |
| 626 | |
| 627 | ID.AddInteger(SC); |
| 628 | for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) |
| 629 | Visit(S->getArg(I)); |
| 630 | if (SC == Stmt::UnaryOperatorClass) |
| 631 | ID.AddInteger(UnaryOp); |
| 632 | else if (SC == Stmt::BinaryOperatorClass || |
| 633 | SC == Stmt::CompoundAssignOperatorClass) |
| 634 | ID.AddInteger(BinaryOp); |
| 635 | else |
| 636 | assert(SC == Stmt::ArraySubscriptExprClass); |
| 637 | |
| 638 | return; |
| 639 | } |
| 640 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 641 | VisitCallExpr(S); |
| 642 | ID.AddInteger(S->getOperator()); |
| 643 | } |
| 644 | |
| 645 | void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) { |
| 646 | VisitCallExpr(S); |
| 647 | } |
| 648 | |
| 649 | void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) { |
| 650 | VisitExplicitCastExpr(S); |
| 651 | } |
| 652 | |
| 653 | void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) { |
| 654 | VisitCXXNamedCastExpr(S); |
| 655 | } |
| 656 | |
| 657 | void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) { |
| 658 | VisitCXXNamedCastExpr(S); |
| 659 | } |
| 660 | |
| 661 | void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) { |
| 662 | VisitCXXNamedCastExpr(S); |
| 663 | } |
| 664 | |
| 665 | void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) { |
| 666 | VisitCXXNamedCastExpr(S); |
| 667 | } |
| 668 | |
| 669 | void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) { |
| 670 | VisitExpr(S); |
| 671 | ID.AddBoolean(S->getValue()); |
| 672 | } |
| 673 | |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 674 | void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) { |
| 675 | VisitExpr(S); |
| 676 | } |
| 677 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 678 | void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) { |
| 679 | VisitExpr(S); |
| 680 | if (S->isTypeOperand()) |
| 681 | VisitType(S->getTypeOperand()); |
| 682 | } |
| 683 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 684 | void StmtProfiler::VisitCXXUuidofExpr(CXXUuidofExpr *S) { |
| 685 | VisitExpr(S); |
| 686 | if (S->isTypeOperand()) |
| 687 | VisitType(S->getTypeOperand()); |
| 688 | } |
| 689 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 690 | void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) { |
| 691 | VisitExpr(S); |
| 692 | } |
| 693 | |
| 694 | void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) { |
| 695 | VisitExpr(S); |
| 696 | } |
| 697 | |
| 698 | void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) { |
| 699 | VisitExpr(S); |
| 700 | VisitDecl(S->getParam()); |
| 701 | } |
| 702 | |
| 703 | void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) { |
| 704 | VisitExpr(S); |
| 705 | VisitDecl( |
| 706 | const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor())); |
| 707 | } |
| 708 | |
| 709 | void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) { |
| 710 | VisitExpr(S); |
| 711 | VisitDecl(S->getConstructor()); |
| 712 | ID.AddBoolean(S->isElidable()); |
| 713 | } |
| 714 | |
| 715 | void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) { |
| 716 | VisitExplicitCastExpr(S); |
| 717 | } |
| 718 | |
| 719 | void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) { |
| 720 | VisitCXXConstructExpr(S); |
| 721 | } |
| 722 | |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 723 | void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) { |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 724 | VisitExpr(S); |
| 725 | } |
| 726 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 727 | void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) { |
| 728 | VisitExpr(S); |
| 729 | ID.AddBoolean(S->isGlobalDelete()); |
| 730 | ID.AddBoolean(S->isArrayForm()); |
| 731 | VisitDecl(S->getOperatorDelete()); |
| 732 | } |
| 733 | |
| 734 | |
| 735 | void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) { |
| 736 | VisitExpr(S); |
| 737 | VisitType(S->getAllocatedType()); |
| 738 | VisitDecl(S->getOperatorNew()); |
| 739 | VisitDecl(S->getOperatorDelete()); |
| 740 | VisitDecl(S->getConstructor()); |
| 741 | ID.AddBoolean(S->isArray()); |
| 742 | ID.AddInteger(S->getNumPlacementArgs()); |
| 743 | ID.AddBoolean(S->isGlobalNew()); |
| 744 | ID.AddBoolean(S->isParenTypeId()); |
| 745 | ID.AddBoolean(S->hasInitializer()); |
| 746 | ID.AddInteger(S->getNumConstructorArgs()); |
| 747 | } |
| 748 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 749 | void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) { |
| 750 | VisitExpr(S); |
| 751 | ID.AddBoolean(S->isArrow()); |
| 752 | VisitNestedNameSpecifier(S->getQualifier()); |
| 753 | VisitType(S->getDestroyedType()); |
| 754 | } |
| 755 | |
Argyrios Kyrtzidis | c35919b | 2010-08-15 01:15:38 +0000 | [diff] [blame] | 756 | void StmtProfiler::VisitOverloadExpr(OverloadExpr *S) { |
Argyrios Kyrtzidis | 7b3e3f6 | 2010-08-15 20:53:20 +0000 | [diff] [blame] | 757 | VisitExpr(S); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 758 | VisitNestedNameSpecifier(S->getQualifier()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 759 | VisitName(S->getName()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 760 | ID.AddBoolean(S->hasExplicitTemplateArgs()); |
| 761 | if (S->hasExplicitTemplateArgs()) |
Argyrios Kyrtzidis | c35919b | 2010-08-15 01:15:38 +0000 | [diff] [blame] | 762 | VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(), |
| 763 | S->getExplicitTemplateArgs().NumTemplateArgs); |
| 764 | } |
| 765 | |
| 766 | void |
| 767 | StmtProfiler::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *S) { |
| 768 | VisitOverloadExpr(S); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) { |
| 772 | VisitExpr(S); |
| 773 | ID.AddInteger(S->getTrait()); |
| 774 | VisitType(S->getQueriedType()); |
| 775 | } |
| 776 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 777 | void StmtProfiler::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *S) { |
| 778 | VisitExpr(S); |
| 779 | ID.AddInteger(S->getTrait()); |
| 780 | VisitType(S->getLhsType()); |
| 781 | VisitType(S->getRhsType()); |
| 782 | } |
| 783 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 784 | void |
| 785 | StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) { |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 786 | VisitExpr(S); |
| 787 | VisitName(S->getDeclName()); |
| 788 | VisitNestedNameSpecifier(S->getQualifier()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 789 | ID.AddBoolean(S->hasExplicitTemplateArgs()); |
| 790 | if (S->hasExplicitTemplateArgs()) |
| 791 | VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 792 | } |
| 793 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 794 | void StmtProfiler::VisitExprWithCleanups(ExprWithCleanups *S) { |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 795 | VisitExpr(S); |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | void |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 799 | StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) { |
| 800 | VisitExpr(S); |
| 801 | VisitType(S->getTypeAsWritten()); |
| 802 | } |
| 803 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 804 | void |
| 805 | StmtProfiler::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *S) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 806 | ID.AddBoolean(S->isImplicitAccess()); |
| 807 | if (!S->isImplicitAccess()) { |
| 808 | VisitExpr(S); |
| 809 | ID.AddBoolean(S->isArrow()); |
| 810 | } |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 811 | VisitNestedNameSpecifier(S->getQualifier()); |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 812 | VisitName(S->getMember()); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 813 | ID.AddBoolean(S->hasExplicitTemplateArgs()); |
| 814 | if (S->hasExplicitTemplateArgs()) |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 815 | VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); |
| 816 | } |
| 817 | |
| 818 | void StmtProfiler::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *S) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 819 | ID.AddBoolean(S->isImplicitAccess()); |
| 820 | if (!S->isImplicitAccess()) { |
| 821 | VisitExpr(S); |
| 822 | ID.AddBoolean(S->isArrow()); |
| 823 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 824 | VisitNestedNameSpecifier(S->getQualifier()); |
| 825 | VisitName(S->getMemberName()); |
| 826 | ID.AddBoolean(S->hasExplicitTemplateArgs()); |
| 827 | if (S->hasExplicitTemplateArgs()) |
| 828 | VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 831 | void StmtProfiler::VisitCXXNoexceptExpr(CXXNoexceptExpr *S) { |
| 832 | VisitExpr(S); |
| 833 | } |
| 834 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 835 | void StmtProfiler::VisitPackExpansionExpr(PackExpansionExpr *S) { |
| 836 | VisitExpr(S); |
| 837 | } |
| 838 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame^] | 839 | void StmtProfiler::VisitSizeOfPackExpr(SizeOfPackExpr *S) { |
| 840 | VisitExpr(S); |
| 841 | VisitDecl(S->getPack()); |
| 842 | } |
| 843 | |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 844 | void StmtProfiler::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 845 | VisitExpr(E); |
| 846 | } |
| 847 | |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 848 | void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) { |
| 849 | VisitExpr(S); |
| 850 | } |
| 851 | |
| 852 | void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) { |
| 853 | VisitExpr(S); |
| 854 | VisitType(S->getEncodedType()); |
| 855 | } |
| 856 | |
| 857 | void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) { |
| 858 | VisitExpr(S); |
| 859 | VisitName(S->getSelector()); |
| 860 | } |
| 861 | |
| 862 | void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) { |
| 863 | VisitExpr(S); |
| 864 | VisitDecl(S->getProtocol()); |
| 865 | } |
| 866 | |
| 867 | void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) { |
| 868 | VisitExpr(S); |
| 869 | VisitDecl(S->getDecl()); |
| 870 | ID.AddBoolean(S->isArrow()); |
| 871 | ID.AddBoolean(S->isFreeIvar()); |
| 872 | } |
| 873 | |
| 874 | void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) { |
| 875 | VisitExpr(S); |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 876 | if (S->isImplicitProperty()) { |
| 877 | VisitDecl(S->getImplicitPropertyGetter()); |
| 878 | VisitDecl(S->getImplicitPropertySetter()); |
| 879 | } else { |
| 880 | VisitDecl(S->getExplicitProperty()); |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 881 | } |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 882 | if (S->isSuperReceiver()) { |
| 883 | ID.AddBoolean(S->isSuperReceiver()); |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 884 | VisitType(S->getSuperReceiverType()); |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 885 | } |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) { |
| 889 | VisitExpr(S); |
| 890 | VisitName(S->getSelector()); |
| 891 | VisitDecl(S->getMethodDecl()); |
| 892 | } |
| 893 | |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 894 | void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) { |
| 895 | VisitExpr(S); |
| 896 | ID.AddBoolean(S->isArrow()); |
| 897 | } |
| 898 | |
Douglas Gregor | d584eb2 | 2009-07-28 15:32:17 +0000 | [diff] [blame] | 899 | void StmtProfiler::VisitDecl(Decl *D) { |
Douglas Gregor | 4a3f780 | 2009-07-31 15:45:02 +0000 | [diff] [blame] | 900 | ID.AddInteger(D? D->getKind() : 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 901 | |
Douglas Gregor | b197572 | 2009-07-30 23:18:24 +0000 | [diff] [blame] | 902 | if (Canonical && D) { |
Douglas Gregor | 6ebd15e | 2009-07-31 05:24:01 +0000 | [diff] [blame] | 903 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { |
Douglas Gregor | d584eb2 | 2009-07-28 15:32:17 +0000 | [diff] [blame] | 904 | ID.AddInteger(NTTP->getDepth()); |
| 905 | ID.AddInteger(NTTP->getIndex()); |
Douglas Gregor | 56bc983 | 2010-12-24 00:15:10 +0000 | [diff] [blame] | 906 | ID.AddInteger(NTTP->isParameterPack()); |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 907 | VisitType(NTTP->getType()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 908 | return; |
| 909 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 910 | |
Douglas Gregor | 4a3f780 | 2009-07-31 15:45:02 +0000 | [diff] [blame] | 911 | if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { |
| 912 | // The Itanium C++ ABI uses the type of a parameter when mangling |
| 913 | // expressions that involve function parameters, so we will use the |
| 914 | // parameter's type for establishing function parameter identity. That |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 915 | // way, our definition of "equivalent" (per C++ [temp.over.link]) |
Douglas Gregor | 4a3f780 | 2009-07-31 15:45:02 +0000 | [diff] [blame] | 916 | // matches the definition of "equivalent" used for name mangling. |
| 917 | VisitType(Parm->getType()); |
| 918 | return; |
| 919 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 920 | |
Douglas Gregor | a2ffb98 | 2009-07-31 15:46:56 +0000 | [diff] [blame] | 921 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { |
| 922 | ID.AddInteger(TTP->getDepth()); |
| 923 | ID.AddInteger(TTP->getIndex()); |
| 924 | return; |
| 925 | } |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 926 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | d584eb2 | 2009-07-28 15:32:17 +0000 | [diff] [blame] | 928 | ID.AddPointer(D? D->getCanonicalDecl() : 0); |
| 929 | } |
| 930 | |
| 931 | void StmtProfiler::VisitType(QualType T) { |
| 932 | if (Canonical) |
| 933 | T = Context.getCanonicalType(T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 935 | ID.AddPointer(T.getAsOpaquePtr()); |
| 936 | } |
| 937 | |
| 938 | void StmtProfiler::VisitName(DeclarationName Name) { |
| 939 | ID.AddPointer(Name.getAsOpaquePtr()); |
| 940 | } |
| 941 | |
| 942 | void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) { |
| 943 | if (Canonical) |
| 944 | NNS = Context.getCanonicalNestedNameSpecifier(NNS); |
| 945 | ID.AddPointer(NNS); |
| 946 | } |
| 947 | |
| 948 | void StmtProfiler::VisitTemplateName(TemplateName Name) { |
| 949 | if (Canonical) |
| 950 | Name = Context.getCanonicalTemplateName(Name); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 952 | Name.Profile(ID); |
| 953 | } |
| 954 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 955 | void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args, |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 956 | unsigned NumArgs) { |
| 957 | ID.AddInteger(NumArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 958 | for (unsigned I = 0; I != NumArgs; ++I) |
| 959 | VisitTemplateArgument(Args[I].getArgument()); |
| 960 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 961 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 962 | void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) { |
| 963 | // Mostly repetitive with TemplateArgument::Profile! |
| 964 | ID.AddInteger(Arg.getKind()); |
| 965 | switch (Arg.getKind()) { |
| 966 | case TemplateArgument::Null: |
| 967 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 968 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 969 | case TemplateArgument::Type: |
| 970 | VisitType(Arg.getAsType()); |
| 971 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 972 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 973 | case TemplateArgument::Template: |
| 974 | VisitTemplateName(Arg.getAsTemplate()); |
| 975 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 976 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 977 | case TemplateArgument::Declaration: |
| 978 | VisitDecl(Arg.getAsDecl()); |
| 979 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 980 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 981 | case TemplateArgument::Integral: |
| 982 | Arg.getAsIntegral()->Profile(ID); |
| 983 | VisitType(Arg.getIntegralType()); |
| 984 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 986 | case TemplateArgument::Expression: |
| 987 | Visit(Arg.getAsExpr()); |
| 988 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 989 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 990 | case TemplateArgument::Pack: |
| 991 | const TemplateArgument *Pack = Arg.pack_begin(); |
| 992 | for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i) |
| 993 | VisitTemplateArgument(Pack[i]); |
| 994 | break; |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | |
| 998 | void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, |
| 999 | bool Canonical) { |
| 1000 | StmtProfiler Profiler(ID, Context, Canonical); |
| 1001 | Profiler.Visit(this); |
| 1002 | } |