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