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" |
| 23 | #include "llvm/Support/Compiler.h" |
| 24 | using namespace clang; |
| 25 | |
| 26 | namespace { |
| 27 | class VISIBILITY_HIDDEN StmtProfiler : public StmtVisitor<StmtProfiler> { |
| 28 | llvm::FoldingSetNodeID &ID; |
| 29 | ASTContext &Context; |
| 30 | bool Canonical; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 31 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 32 | public: |
| 33 | StmtProfiler(llvm::FoldingSetNodeID &ID, ASTContext &Context, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | bool Canonical) |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 35 | : ID(ID), Context(Context), Canonical(Canonical) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 36 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 37 | void VisitStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | |
Douglas Gregor | 3fe81fc | 2009-07-28 15:27:13 +0000 | [diff] [blame] | 39 | #define STMT(Node, Base) void Visit##Node(Node *S); |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 40 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 42 | /// \brief Visit a declaration that is referenced within an expression |
| 43 | /// or statement. |
| 44 | void VisitDecl(Decl *D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 45 | |
| 46 | /// \brief Visit a type that is referenced within an expression or |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 47 | /// statement. |
| 48 | void VisitType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 49 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 50 | /// \brief Visit a name that occurs within an expression or statement. |
| 51 | void VisitName(DeclarationName Name); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 52 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 53 | /// \brief Visit a nested-name-specifier that occurs within an expression |
| 54 | /// or statement. |
| 55 | void VisitNestedNameSpecifier(NestedNameSpecifier *NNS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 57 | /// \brief Visit a template name that occurs within an expression or |
| 58 | /// statement. |
| 59 | void VisitTemplateName(TemplateName Name); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 60 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 61 | /// \brief Visit template arguments that occur within an expression or |
| 62 | /// statement. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 63 | void VisitTemplateArguments(const TemplateArgumentLoc *Args, unsigned NumArgs); |
| 64 | |
| 65 | /// \brief Visit a single template argument. |
| 66 | void VisitTemplateArgument(const TemplateArgument &Arg); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 67 | }; |
| 68 | } |
| 69 | |
| 70 | void StmtProfiler::VisitStmt(Stmt *S) { |
| 71 | ID.AddInteger(S->getStmtClass()); |
| 72 | for (Stmt::child_iterator C = S->child_begin(), CEnd = S->child_end(); |
| 73 | C != CEnd; ++C) |
| 74 | Visit(*C); |
| 75 | } |
| 76 | |
Douglas Gregor | 3fe81fc | 2009-07-28 15:27:13 +0000 | [diff] [blame] | 77 | void StmtProfiler::VisitDeclStmt(DeclStmt *S) { |
| 78 | VisitStmt(S); |
| 79 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 80 | D != DEnd; ++D) |
| 81 | VisitDecl(*D); |
| 82 | } |
| 83 | |
| 84 | void StmtProfiler::VisitNullStmt(NullStmt *S) { |
| 85 | VisitStmt(S); |
| 86 | } |
| 87 | |
| 88 | void StmtProfiler::VisitCompoundStmt(CompoundStmt *S) { |
| 89 | VisitStmt(S); |
| 90 | } |
| 91 | |
| 92 | void StmtProfiler::VisitSwitchCase(SwitchCase *S) { |
| 93 | VisitStmt(S); |
| 94 | } |
| 95 | |
| 96 | void StmtProfiler::VisitCaseStmt(CaseStmt *S) { |
| 97 | VisitStmt(S); |
| 98 | } |
| 99 | |
| 100 | void StmtProfiler::VisitDefaultStmt(DefaultStmt *S) { |
| 101 | VisitStmt(S); |
| 102 | } |
| 103 | |
| 104 | void StmtProfiler::VisitLabelStmt(LabelStmt *S) { |
| 105 | VisitStmt(S); |
| 106 | VisitName(S->getID()); |
| 107 | } |
| 108 | |
| 109 | void StmtProfiler::VisitIfStmt(IfStmt *S) { |
| 110 | VisitStmt(S); |
| 111 | } |
| 112 | |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 113 | void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) { |
| 114 | VisitStmt(S); |
| 115 | } |
| 116 | |
Douglas Gregor | 3fe81fc | 2009-07-28 15:27:13 +0000 | [diff] [blame] | 117 | void StmtProfiler::VisitWhileStmt(WhileStmt *S) { |
| 118 | VisitStmt(S); |
| 119 | } |
| 120 | |
| 121 | void StmtProfiler::VisitDoStmt(DoStmt *S) { |
| 122 | VisitStmt(S); |
| 123 | } |
| 124 | |
| 125 | void StmtProfiler::VisitForStmt(ForStmt *S) { |
| 126 | VisitStmt(S); |
| 127 | } |
| 128 | |
| 129 | void StmtProfiler::VisitGotoStmt(GotoStmt *S) { |
| 130 | VisitStmt(S); |
| 131 | VisitName(S->getLabel()->getID()); |
| 132 | } |
| 133 | |
| 134 | void StmtProfiler::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 135 | VisitStmt(S); |
| 136 | } |
| 137 | |
| 138 | void StmtProfiler::VisitContinueStmt(ContinueStmt *S) { |
| 139 | VisitStmt(S); |
| 140 | } |
| 141 | |
| 142 | void StmtProfiler::VisitBreakStmt(BreakStmt *S) { |
| 143 | VisitStmt(S); |
| 144 | } |
| 145 | |
| 146 | void StmtProfiler::VisitReturnStmt(ReturnStmt *S) { |
| 147 | VisitStmt(S); |
| 148 | } |
| 149 | |
| 150 | void StmtProfiler::VisitAsmStmt(AsmStmt *S) { |
| 151 | VisitStmt(S); |
| 152 | ID.AddBoolean(S->isVolatile()); |
| 153 | ID.AddBoolean(S->isSimple()); |
| 154 | VisitStringLiteral(S->getAsmString()); |
| 155 | ID.AddInteger(S->getNumOutputs()); |
| 156 | for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) { |
| 157 | ID.AddString(S->getOutputName(I)); |
| 158 | VisitStringLiteral(S->getOutputConstraintLiteral(I)); |
| 159 | } |
| 160 | ID.AddInteger(S->getNumInputs()); |
| 161 | for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) { |
| 162 | ID.AddString(S->getInputName(I)); |
| 163 | VisitStringLiteral(S->getInputConstraintLiteral(I)); |
| 164 | } |
| 165 | ID.AddInteger(S->getNumClobbers()); |
| 166 | for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) |
| 167 | VisitStringLiteral(S->getClobber(I)); |
| 168 | } |
| 169 | |
| 170 | void StmtProfiler::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 171 | VisitStmt(S); |
| 172 | VisitType(S->getCaughtType()); |
| 173 | } |
| 174 | |
| 175 | void StmtProfiler::VisitCXXTryStmt(CXXTryStmt *S) { |
| 176 | VisitStmt(S); |
| 177 | } |
| 178 | |
| 179 | void StmtProfiler::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 180 | VisitStmt(S); |
| 181 | } |
| 182 | |
| 183 | void StmtProfiler::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 184 | VisitStmt(S); |
| 185 | ID.AddBoolean(S->hasEllipsis()); |
| 186 | if (S->getCatchParamDecl()) |
| 187 | VisitType(S->getCatchParamDecl()->getType()); |
| 188 | } |
| 189 | |
| 190 | void StmtProfiler::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 191 | VisitStmt(S); |
| 192 | } |
| 193 | |
| 194 | void StmtProfiler::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 195 | VisitStmt(S); |
| 196 | } |
| 197 | |
| 198 | void StmtProfiler::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { |
| 199 | VisitStmt(S); |
| 200 | } |
| 201 | |
| 202 | void StmtProfiler::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 203 | VisitStmt(S); |
| 204 | } |
| 205 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 206 | void StmtProfiler::VisitExpr(Expr *S) { |
| 207 | VisitStmt(S); |
| 208 | } |
| 209 | |
| 210 | void StmtProfiler::VisitDeclRefExpr(DeclRefExpr *S) { |
| 211 | VisitExpr(S); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 212 | VisitNestedNameSpecifier(S->getQualifier()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 213 | VisitDecl(S->getDecl()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 214 | VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) { |
| 218 | VisitExpr(S); |
| 219 | ID.AddInteger(S->getIdentType()); |
| 220 | } |
| 221 | |
| 222 | void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) { |
| 223 | VisitExpr(S); |
| 224 | S->getValue().Profile(ID); |
| 225 | } |
| 226 | |
| 227 | void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) { |
| 228 | VisitExpr(S); |
| 229 | ID.AddBoolean(S->isWide()); |
| 230 | ID.AddInteger(S->getValue()); |
| 231 | } |
| 232 | |
| 233 | void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) { |
| 234 | VisitExpr(S); |
| 235 | S->getValue().Profile(ID); |
| 236 | ID.AddBoolean(S->isExact()); |
| 237 | } |
| 238 | |
| 239 | void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) { |
| 240 | VisitExpr(S); |
| 241 | } |
| 242 | |
| 243 | void StmtProfiler::VisitStringLiteral(StringLiteral *S) { |
| 244 | VisitExpr(S); |
Daniel Dunbar | 932eb6d | 2009-09-22 10:06:21 +0000 | [diff] [blame] | 245 | ID.AddString(S->getString()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 246 | ID.AddBoolean(S->isWide()); |
| 247 | } |
| 248 | |
| 249 | void StmtProfiler::VisitParenExpr(ParenExpr *S) { |
| 250 | VisitExpr(S); |
| 251 | } |
| 252 | |
Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 253 | void StmtProfiler::VisitParenListExpr(ParenListExpr *S) { |
| 254 | VisitExpr(S); |
| 255 | } |
| 256 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 257 | void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) { |
| 258 | VisitExpr(S); |
| 259 | ID.AddInteger(S->getOpcode()); |
| 260 | } |
| 261 | |
| 262 | void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) { |
| 263 | VisitExpr(S); |
| 264 | ID.AddBoolean(S->isSizeOf()); |
| 265 | if (S->isArgumentType()) |
| 266 | VisitType(S->getArgumentType()); |
| 267 | } |
| 268 | |
| 269 | void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) { |
| 270 | VisitExpr(S); |
| 271 | } |
| 272 | |
| 273 | void StmtProfiler::VisitCallExpr(CallExpr *S) { |
| 274 | VisitExpr(S); |
| 275 | } |
| 276 | |
| 277 | void StmtProfiler::VisitMemberExpr(MemberExpr *S) { |
| 278 | VisitExpr(S); |
| 279 | VisitDecl(S->getMemberDecl()); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 280 | VisitNestedNameSpecifier(S->getQualifier()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 281 | ID.AddBoolean(S->isArrow()); |
| 282 | } |
| 283 | |
| 284 | void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) { |
| 285 | VisitExpr(S); |
| 286 | ID.AddBoolean(S->isFileScope()); |
| 287 | } |
| 288 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 289 | void StmtProfiler::VisitCastExpr(CastExpr *S) { |
| 290 | VisitExpr(S); |
| 291 | } |
| 292 | |
| 293 | void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) { |
| 294 | VisitCastExpr(S); |
| 295 | ID.AddBoolean(S->isLvalueCast()); |
| 296 | } |
| 297 | |
| 298 | void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) { |
| 299 | VisitCastExpr(S); |
| 300 | VisitType(S->getTypeAsWritten()); |
| 301 | } |
| 302 | |
| 303 | void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) { |
| 304 | VisitExplicitCastExpr(S); |
| 305 | } |
| 306 | |
| 307 | void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) { |
| 308 | VisitExpr(S); |
| 309 | ID.AddInteger(S->getOpcode()); |
| 310 | } |
| 311 | |
| 312 | void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) { |
| 313 | VisitBinaryOperator(S); |
| 314 | } |
| 315 | |
| 316 | void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) { |
| 317 | VisitExpr(S); |
| 318 | } |
| 319 | |
| 320 | void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) { |
| 321 | VisitExpr(S); |
Douglas Gregor | 3fe81fc | 2009-07-28 15:27:13 +0000 | [diff] [blame] | 322 | VisitName(S->getLabel()->getID()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void StmtProfiler::VisitStmtExpr(StmtExpr *S) { |
| 326 | VisitExpr(S); |
| 327 | } |
| 328 | |
| 329 | void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) { |
| 330 | VisitExpr(S); |
| 331 | VisitType(S->getArgType1()); |
| 332 | VisitType(S->getArgType2()); |
| 333 | } |
| 334 | |
| 335 | void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) { |
| 336 | VisitExpr(S); |
| 337 | } |
| 338 | |
| 339 | void StmtProfiler::VisitChooseExpr(ChooseExpr *S) { |
| 340 | VisitExpr(S); |
| 341 | } |
| 342 | |
| 343 | void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) { |
| 344 | VisitExpr(S); |
| 345 | } |
| 346 | |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 347 | void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) { |
| 348 | VisitExpr(S); |
| 349 | } |
| 350 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 351 | void StmtProfiler::VisitInitListExpr(InitListExpr *S) { |
| 352 | if (S->getSyntacticForm()) { |
| 353 | VisitInitListExpr(S->getSyntacticForm()); |
| 354 | return; |
| 355 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 357 | VisitExpr(S); |
| 358 | } |
| 359 | |
| 360 | void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) { |
| 361 | VisitExpr(S); |
| 362 | ID.AddBoolean(S->usesGNUSyntax()); |
| 363 | for (DesignatedInitExpr::designators_iterator D = S->designators_begin(), |
| 364 | DEnd = S->designators_end(); |
| 365 | D != DEnd; ++D) { |
| 366 | if (D->isFieldDesignator()) { |
| 367 | ID.AddInteger(0); |
| 368 | VisitName(D->getFieldName()); |
| 369 | continue; |
| 370 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 372 | if (D->isArrayDesignator()) { |
| 373 | ID.AddInteger(1); |
| 374 | } else { |
| 375 | assert(D->isArrayRangeDesignator()); |
| 376 | ID.AddInteger(2); |
| 377 | } |
| 378 | ID.AddInteger(D->getFirstExprIndex()); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) { |
| 383 | VisitExpr(S); |
| 384 | } |
| 385 | |
| 386 | void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) { |
| 387 | VisitExpr(S); |
| 388 | VisitName(&S->getAccessor()); |
| 389 | } |
| 390 | |
| 391 | void StmtProfiler::VisitBlockExpr(BlockExpr *S) { |
| 392 | VisitExpr(S); |
| 393 | VisitDecl(S->getBlockDecl()); |
| 394 | } |
| 395 | |
| 396 | void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) { |
| 397 | VisitExpr(S); |
| 398 | VisitDecl(S->getDecl()); |
| 399 | ID.AddBoolean(S->isByRef()); |
| 400 | ID.AddBoolean(S->isConstQualAdded()); |
| 401 | } |
| 402 | |
| 403 | void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) { |
| 404 | VisitCallExpr(S); |
| 405 | ID.AddInteger(S->getOperator()); |
| 406 | } |
| 407 | |
| 408 | void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) { |
| 409 | VisitCallExpr(S); |
| 410 | } |
| 411 | |
| 412 | void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) { |
| 413 | VisitExplicitCastExpr(S); |
| 414 | } |
| 415 | |
| 416 | void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) { |
| 417 | VisitCXXNamedCastExpr(S); |
| 418 | } |
| 419 | |
| 420 | void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) { |
| 421 | VisitCXXNamedCastExpr(S); |
| 422 | } |
| 423 | |
| 424 | void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) { |
| 425 | VisitCXXNamedCastExpr(S); |
| 426 | } |
| 427 | |
| 428 | void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) { |
| 429 | VisitCXXNamedCastExpr(S); |
| 430 | } |
| 431 | |
| 432 | void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) { |
| 433 | VisitExpr(S); |
| 434 | ID.AddBoolean(S->getValue()); |
| 435 | } |
| 436 | |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 437 | void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) { |
| 438 | VisitExpr(S); |
| 439 | } |
| 440 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 441 | void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) { |
| 442 | VisitExpr(S); |
| 443 | if (S->isTypeOperand()) |
| 444 | VisitType(S->getTypeOperand()); |
| 445 | } |
| 446 | |
| 447 | void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) { |
| 448 | VisitExpr(S); |
| 449 | } |
| 450 | |
| 451 | void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) { |
| 452 | VisitExpr(S); |
| 453 | } |
| 454 | |
| 455 | void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) { |
| 456 | VisitExpr(S); |
| 457 | VisitDecl(S->getParam()); |
| 458 | } |
| 459 | |
| 460 | void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) { |
| 461 | VisitExpr(S); |
| 462 | VisitDecl( |
| 463 | const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor())); |
| 464 | } |
| 465 | |
| 466 | void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) { |
| 467 | VisitExpr(S); |
| 468 | VisitDecl(S->getConstructor()); |
| 469 | ID.AddBoolean(S->isElidable()); |
| 470 | } |
| 471 | |
| 472 | void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) { |
| 473 | VisitExplicitCastExpr(S); |
| 474 | } |
| 475 | |
| 476 | void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) { |
| 477 | VisitCXXConstructExpr(S); |
| 478 | } |
| 479 | |
| 480 | void StmtProfiler::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *S) { |
| 481 | VisitExpr(S); |
| 482 | } |
| 483 | |
| 484 | void StmtProfiler::VisitCXXConditionDeclExpr(CXXConditionDeclExpr *S) { |
| 485 | VisitDeclRefExpr(S); |
| 486 | } |
| 487 | |
| 488 | void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) { |
| 489 | VisitExpr(S); |
| 490 | ID.AddBoolean(S->isGlobalDelete()); |
| 491 | ID.AddBoolean(S->isArrayForm()); |
| 492 | VisitDecl(S->getOperatorDelete()); |
| 493 | } |
| 494 | |
| 495 | |
| 496 | void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) { |
| 497 | VisitExpr(S); |
| 498 | VisitType(S->getAllocatedType()); |
| 499 | VisitDecl(S->getOperatorNew()); |
| 500 | VisitDecl(S->getOperatorDelete()); |
| 501 | VisitDecl(S->getConstructor()); |
| 502 | ID.AddBoolean(S->isArray()); |
| 503 | ID.AddInteger(S->getNumPlacementArgs()); |
| 504 | ID.AddBoolean(S->isGlobalNew()); |
| 505 | ID.AddBoolean(S->isParenTypeId()); |
| 506 | ID.AddBoolean(S->hasInitializer()); |
| 507 | ID.AddInteger(S->getNumConstructorArgs()); |
| 508 | } |
| 509 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 510 | void StmtProfiler::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *S) { |
| 511 | VisitExpr(S); |
| 512 | ID.AddBoolean(S->isArrow()); |
| 513 | VisitNestedNameSpecifier(S->getQualifier()); |
| 514 | VisitType(S->getDestroyedType()); |
| 515 | } |
| 516 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 517 | void |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 518 | StmtProfiler::VisitUnresolvedFunctionNameExpr(UnresolvedFunctionNameExpr *S) { |
| 519 | VisitExpr(S); |
| 520 | VisitName(S->getName()); |
| 521 | } |
| 522 | |
| 523 | void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) { |
| 524 | VisitExpr(S); |
| 525 | ID.AddInteger(S->getTrait()); |
| 526 | VisitType(S->getQueriedType()); |
| 527 | } |
| 528 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 529 | void StmtProfiler::VisitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *S) { |
| 530 | VisitExpr(S); |
| 531 | VisitName(S->getDeclName()); |
| 532 | VisitNestedNameSpecifier(S->getQualifier()); |
| 533 | ID.AddBoolean(S->isAddressOfOperand()); |
| 534 | } |
| 535 | |
| 536 | void StmtProfiler::VisitTemplateIdRefExpr(TemplateIdRefExpr *S) { |
| 537 | VisitExpr(S); |
| 538 | VisitNestedNameSpecifier(S->getQualifier()); |
| 539 | VisitTemplateName(S->getTemplateName()); |
| 540 | VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); |
| 541 | } |
| 542 | |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 543 | void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) { |
| 544 | VisitExpr(S); |
| 545 | ID.AddBoolean(S->shouldDestroyTemporaries()); |
| 546 | for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I) |
| 547 | VisitDecl( |
| 548 | const_cast<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor())); |
| 549 | } |
| 550 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | void |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 552 | StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) { |
| 553 | VisitExpr(S); |
| 554 | VisitType(S->getTypeAsWritten()); |
| 555 | } |
| 556 | |
| 557 | void StmtProfiler::VisitCXXUnresolvedMemberExpr(CXXUnresolvedMemberExpr *S) { |
| 558 | VisitExpr(S); |
| 559 | ID.AddBoolean(S->isArrow()); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 560 | VisitNestedNameSpecifier(S->getQualifier()); |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 561 | VisitName(S->getMember()); |
| 562 | } |
| 563 | |
| 564 | void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) { |
| 565 | VisitExpr(S); |
| 566 | } |
| 567 | |
| 568 | void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) { |
| 569 | VisitExpr(S); |
| 570 | VisitType(S->getEncodedType()); |
| 571 | } |
| 572 | |
| 573 | void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) { |
| 574 | VisitExpr(S); |
| 575 | VisitName(S->getSelector()); |
| 576 | } |
| 577 | |
| 578 | void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) { |
| 579 | VisitExpr(S); |
| 580 | VisitDecl(S->getProtocol()); |
| 581 | } |
| 582 | |
| 583 | void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) { |
| 584 | VisitExpr(S); |
| 585 | VisitDecl(S->getDecl()); |
| 586 | ID.AddBoolean(S->isArrow()); |
| 587 | ID.AddBoolean(S->isFreeIvar()); |
| 588 | } |
| 589 | |
| 590 | void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) { |
| 591 | VisitExpr(S); |
| 592 | VisitDecl(S->getProperty()); |
| 593 | } |
| 594 | |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 595 | void StmtProfiler::VisitObjCImplicitSetterGetterRefExpr( |
| 596 | ObjCImplicitSetterGetterRefExpr *S) { |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 597 | VisitExpr(S); |
| 598 | VisitDecl(S->getGetterMethod()); |
| 599 | VisitDecl(S->getSetterMethod()); |
Fariborz Jahanian | d2ae5aa | 2009-08-18 21:37:33 +0000 | [diff] [blame] | 600 | VisitDecl(S->getInterfaceDecl()); |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) { |
| 604 | VisitExpr(S); |
| 605 | VisitName(S->getSelector()); |
| 606 | VisitDecl(S->getMethodDecl()); |
| 607 | } |
| 608 | |
| 609 | void StmtProfiler::VisitObjCSuperExpr(ObjCSuperExpr *S) { |
| 610 | VisitExpr(S); |
| 611 | } |
| 612 | |
| 613 | void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) { |
| 614 | VisitExpr(S); |
| 615 | ID.AddBoolean(S->isArrow()); |
| 616 | } |
| 617 | |
Douglas Gregor | d584eb2 | 2009-07-28 15:32:17 +0000 | [diff] [blame] | 618 | void StmtProfiler::VisitDecl(Decl *D) { |
Douglas Gregor | 4a3f780 | 2009-07-31 15:45:02 +0000 | [diff] [blame] | 619 | ID.AddInteger(D? D->getKind() : 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 620 | |
Douglas Gregor | b197572 | 2009-07-30 23:18:24 +0000 | [diff] [blame] | 621 | if (Canonical && D) { |
Douglas Gregor | 6ebd15e | 2009-07-31 05:24:01 +0000 | [diff] [blame] | 622 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { |
Douglas Gregor | d584eb2 | 2009-07-28 15:32:17 +0000 | [diff] [blame] | 623 | ID.AddInteger(NTTP->getDepth()); |
| 624 | ID.AddInteger(NTTP->getIndex()); |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 625 | VisitType(NTTP->getType()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 626 | return; |
| 627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 628 | |
Douglas Gregor | 4a3f780 | 2009-07-31 15:45:02 +0000 | [diff] [blame] | 629 | if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { |
| 630 | // The Itanium C++ ABI uses the type of a parameter when mangling |
| 631 | // expressions that involve function parameters, so we will use the |
| 632 | // parameter's type for establishing function parameter identity. That |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 633 | // way, our definition of "equivalent" (per C++ [temp.over.link]) |
Douglas Gregor | 4a3f780 | 2009-07-31 15:45:02 +0000 | [diff] [blame] | 634 | // matches the definition of "equivalent" used for name mangling. |
| 635 | VisitType(Parm->getType()); |
| 636 | return; |
| 637 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | |
Douglas Gregor | a2ffb98 | 2009-07-31 15:46:56 +0000 | [diff] [blame] | 639 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { |
| 640 | ID.AddInteger(TTP->getDepth()); |
| 641 | ID.AddInteger(TTP->getIndex()); |
| 642 | return; |
| 643 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 644 | |
Douglas Gregor | 6ebd15e | 2009-07-31 05:24:01 +0000 | [diff] [blame] | 645 | if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | // The Itanium C++ ABI mangles references to a set of overloaded |
Douglas Gregor | 6f2c46b | 2009-07-31 16:07:31 +0000 | [diff] [blame] | 647 | // functions using just the function name, so we do the same here. |
| 648 | VisitName(Ovl->getDeclName()); |
Douglas Gregor | 6ebd15e | 2009-07-31 05:24:01 +0000 | [diff] [blame] | 649 | return; |
| 650 | } |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 651 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 652 | |
Douglas Gregor | d584eb2 | 2009-07-28 15:32:17 +0000 | [diff] [blame] | 653 | ID.AddPointer(D? D->getCanonicalDecl() : 0); |
| 654 | } |
| 655 | |
| 656 | void StmtProfiler::VisitType(QualType T) { |
| 657 | if (Canonical) |
| 658 | T = Context.getCanonicalType(T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 659 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 660 | ID.AddPointer(T.getAsOpaquePtr()); |
| 661 | } |
| 662 | |
| 663 | void StmtProfiler::VisitName(DeclarationName Name) { |
| 664 | ID.AddPointer(Name.getAsOpaquePtr()); |
| 665 | } |
| 666 | |
| 667 | void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) { |
| 668 | if (Canonical) |
| 669 | NNS = Context.getCanonicalNestedNameSpecifier(NNS); |
| 670 | ID.AddPointer(NNS); |
| 671 | } |
| 672 | |
| 673 | void StmtProfiler::VisitTemplateName(TemplateName Name) { |
| 674 | if (Canonical) |
| 675 | Name = Context.getCanonicalTemplateName(Name); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 677 | Name.Profile(ID); |
| 678 | } |
| 679 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 680 | void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args, |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 681 | unsigned NumArgs) { |
| 682 | ID.AddInteger(NumArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 683 | for (unsigned I = 0; I != NumArgs; ++I) |
| 684 | VisitTemplateArgument(Args[I].getArgument()); |
| 685 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 686 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 687 | void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) { |
| 688 | // Mostly repetitive with TemplateArgument::Profile! |
| 689 | ID.AddInteger(Arg.getKind()); |
| 690 | switch (Arg.getKind()) { |
| 691 | case TemplateArgument::Null: |
| 692 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 693 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 694 | case TemplateArgument::Type: |
| 695 | VisitType(Arg.getAsType()); |
| 696 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 697 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 698 | case TemplateArgument::Template: |
| 699 | VisitTemplateName(Arg.getAsTemplate()); |
| 700 | break; |
| 701 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 702 | case TemplateArgument::Declaration: |
| 703 | VisitDecl(Arg.getAsDecl()); |
| 704 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 706 | case TemplateArgument::Integral: |
| 707 | Arg.getAsIntegral()->Profile(ID); |
| 708 | VisitType(Arg.getIntegralType()); |
| 709 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 711 | case TemplateArgument::Expression: |
| 712 | Visit(Arg.getAsExpr()); |
| 713 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 714 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 715 | case TemplateArgument::Pack: |
| 716 | const TemplateArgument *Pack = Arg.pack_begin(); |
| 717 | for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i) |
| 718 | VisitTemplateArgument(Pack[i]); |
| 719 | break; |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, |
| 724 | bool Canonical) { |
| 725 | StmtProfiler Profiler(ID, Context, Canonical); |
| 726 | Profiler.Visit(this); |
| 727 | } |