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; |
| 31 | |
| 32 | public: |
| 33 | StmtProfiler(llvm::FoldingSetNodeID &ID, ASTContext &Context, |
| 34 | bool Canonical) |
| 35 | : ID(ID), Context(Context), Canonical(Canonical) { } |
| 36 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 37 | void VisitStmt(Stmt *S); |
Douglas Gregor | 3fe81fc | 2009-07-28 15:27:13 +0000 | [diff] [blame] | 38 | |
| 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" |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 41 | |
| 42 | /// \brief Visit a declaration that is referenced within an expression |
| 43 | /// or statement. |
| 44 | void VisitDecl(Decl *D); |
| 45 | |
| 46 | /// \brief Visit a type that is referenced within an expression or |
| 47 | /// statement. |
| 48 | void VisitType(QualType T); |
| 49 | |
| 50 | /// \brief Visit a name that occurs within an expression or statement. |
| 51 | void VisitName(DeclarationName Name); |
| 52 | |
| 53 | /// \brief Visit a nested-name-specifier that occurs within an expression |
| 54 | /// or statement. |
| 55 | void VisitNestedNameSpecifier(NestedNameSpecifier *NNS); |
| 56 | |
| 57 | /// \brief Visit a template name that occurs within an expression or |
| 58 | /// statement. |
| 59 | void VisitTemplateName(TemplateName Name); |
| 60 | |
| 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); |
| 209 | VisitDecl(S->getDecl()); |
| 210 | } |
| 211 | |
| 212 | void StmtProfiler::VisitPredefinedExpr(PredefinedExpr *S) { |
| 213 | VisitExpr(S); |
| 214 | ID.AddInteger(S->getIdentType()); |
| 215 | } |
| 216 | |
| 217 | void StmtProfiler::VisitIntegerLiteral(IntegerLiteral *S) { |
| 218 | VisitExpr(S); |
| 219 | S->getValue().Profile(ID); |
| 220 | } |
| 221 | |
| 222 | void StmtProfiler::VisitCharacterLiteral(CharacterLiteral *S) { |
| 223 | VisitExpr(S); |
| 224 | ID.AddBoolean(S->isWide()); |
| 225 | ID.AddInteger(S->getValue()); |
| 226 | } |
| 227 | |
| 228 | void StmtProfiler::VisitFloatingLiteral(FloatingLiteral *S) { |
| 229 | VisitExpr(S); |
| 230 | S->getValue().Profile(ID); |
| 231 | ID.AddBoolean(S->isExact()); |
| 232 | } |
| 233 | |
| 234 | void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) { |
| 235 | VisitExpr(S); |
| 236 | } |
| 237 | |
| 238 | void StmtProfiler::VisitStringLiteral(StringLiteral *S) { |
| 239 | VisitExpr(S); |
| 240 | ID.AddString(S->getStrData(), S->getStrData() + S->getByteLength()); |
| 241 | ID.AddBoolean(S->isWide()); |
| 242 | } |
| 243 | |
| 244 | void StmtProfiler::VisitParenExpr(ParenExpr *S) { |
| 245 | VisitExpr(S); |
| 246 | } |
| 247 | |
Nate Begeman | 25b4fdb | 2009-08-09 17:55:44 +0000 | [diff] [blame] | 248 | void StmtProfiler::VisitParenListExpr(ParenListExpr *S) { |
| 249 | VisitExpr(S); |
| 250 | } |
| 251 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 252 | void StmtProfiler::VisitUnaryOperator(UnaryOperator *S) { |
| 253 | VisitExpr(S); |
| 254 | ID.AddInteger(S->getOpcode()); |
| 255 | } |
| 256 | |
| 257 | void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) { |
| 258 | VisitExpr(S); |
| 259 | ID.AddBoolean(S->isSizeOf()); |
| 260 | if (S->isArgumentType()) |
| 261 | VisitType(S->getArgumentType()); |
| 262 | } |
| 263 | |
| 264 | void StmtProfiler::VisitArraySubscriptExpr(ArraySubscriptExpr *S) { |
| 265 | VisitExpr(S); |
| 266 | } |
| 267 | |
| 268 | void StmtProfiler::VisitCallExpr(CallExpr *S) { |
| 269 | VisitExpr(S); |
| 270 | } |
| 271 | |
| 272 | void StmtProfiler::VisitMemberExpr(MemberExpr *S) { |
| 273 | VisitExpr(S); |
| 274 | VisitDecl(S->getMemberDecl()); |
| 275 | ID.AddBoolean(S->isArrow()); |
| 276 | } |
| 277 | |
| 278 | void StmtProfiler::VisitCompoundLiteralExpr(CompoundLiteralExpr *S) { |
| 279 | VisitExpr(S); |
| 280 | ID.AddBoolean(S->isFileScope()); |
| 281 | } |
| 282 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 283 | void StmtProfiler::VisitCastExpr(CastExpr *S) { |
| 284 | VisitExpr(S); |
| 285 | } |
| 286 | |
| 287 | void StmtProfiler::VisitImplicitCastExpr(ImplicitCastExpr *S) { |
| 288 | VisitCastExpr(S); |
| 289 | ID.AddBoolean(S->isLvalueCast()); |
| 290 | } |
| 291 | |
| 292 | void StmtProfiler::VisitExplicitCastExpr(ExplicitCastExpr *S) { |
| 293 | VisitCastExpr(S); |
| 294 | VisitType(S->getTypeAsWritten()); |
| 295 | } |
| 296 | |
| 297 | void StmtProfiler::VisitCStyleCastExpr(CStyleCastExpr *S) { |
| 298 | VisitExplicitCastExpr(S); |
| 299 | } |
| 300 | |
| 301 | void StmtProfiler::VisitBinaryOperator(BinaryOperator *S) { |
| 302 | VisitExpr(S); |
| 303 | ID.AddInteger(S->getOpcode()); |
| 304 | } |
| 305 | |
| 306 | void StmtProfiler::VisitCompoundAssignOperator(CompoundAssignOperator *S) { |
| 307 | VisitBinaryOperator(S); |
| 308 | } |
| 309 | |
| 310 | void StmtProfiler::VisitConditionalOperator(ConditionalOperator *S) { |
| 311 | VisitExpr(S); |
| 312 | } |
| 313 | |
| 314 | void StmtProfiler::VisitAddrLabelExpr(AddrLabelExpr *S) { |
| 315 | VisitExpr(S); |
Douglas Gregor | 3fe81fc | 2009-07-28 15:27:13 +0000 | [diff] [blame] | 316 | VisitName(S->getLabel()->getID()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void StmtProfiler::VisitStmtExpr(StmtExpr *S) { |
| 320 | VisitExpr(S); |
| 321 | } |
| 322 | |
| 323 | void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) { |
| 324 | VisitExpr(S); |
| 325 | VisitType(S->getArgType1()); |
| 326 | VisitType(S->getArgType2()); |
| 327 | } |
| 328 | |
| 329 | void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) { |
| 330 | VisitExpr(S); |
| 331 | } |
| 332 | |
| 333 | void StmtProfiler::VisitChooseExpr(ChooseExpr *S) { |
| 334 | VisitExpr(S); |
| 335 | } |
| 336 | |
| 337 | void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) { |
| 338 | VisitExpr(S); |
| 339 | } |
| 340 | |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 341 | void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) { |
| 342 | VisitExpr(S); |
| 343 | } |
| 344 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 345 | void StmtProfiler::VisitInitListExpr(InitListExpr *S) { |
| 346 | if (S->getSyntacticForm()) { |
| 347 | VisitInitListExpr(S->getSyntacticForm()); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | VisitExpr(S); |
| 352 | } |
| 353 | |
| 354 | void StmtProfiler::VisitDesignatedInitExpr(DesignatedInitExpr *S) { |
| 355 | VisitExpr(S); |
| 356 | ID.AddBoolean(S->usesGNUSyntax()); |
| 357 | for (DesignatedInitExpr::designators_iterator D = S->designators_begin(), |
| 358 | DEnd = S->designators_end(); |
| 359 | D != DEnd; ++D) { |
| 360 | if (D->isFieldDesignator()) { |
| 361 | ID.AddInteger(0); |
| 362 | VisitName(D->getFieldName()); |
| 363 | continue; |
| 364 | } |
| 365 | |
| 366 | if (D->isArrayDesignator()) { |
| 367 | ID.AddInteger(1); |
| 368 | } else { |
| 369 | assert(D->isArrayRangeDesignator()); |
| 370 | ID.AddInteger(2); |
| 371 | } |
| 372 | ID.AddInteger(D->getFirstExprIndex()); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | void StmtProfiler::VisitImplicitValueInitExpr(ImplicitValueInitExpr *S) { |
| 377 | VisitExpr(S); |
| 378 | } |
| 379 | |
| 380 | void StmtProfiler::VisitExtVectorElementExpr(ExtVectorElementExpr *S) { |
| 381 | VisitExpr(S); |
| 382 | VisitName(&S->getAccessor()); |
| 383 | } |
| 384 | |
| 385 | void StmtProfiler::VisitBlockExpr(BlockExpr *S) { |
| 386 | VisitExpr(S); |
| 387 | VisitDecl(S->getBlockDecl()); |
| 388 | } |
| 389 | |
| 390 | void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) { |
| 391 | VisitExpr(S); |
| 392 | VisitDecl(S->getDecl()); |
| 393 | ID.AddBoolean(S->isByRef()); |
| 394 | ID.AddBoolean(S->isConstQualAdded()); |
| 395 | } |
| 396 | |
| 397 | void StmtProfiler::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *S) { |
| 398 | VisitCallExpr(S); |
| 399 | ID.AddInteger(S->getOperator()); |
| 400 | } |
| 401 | |
| 402 | void StmtProfiler::VisitCXXMemberCallExpr(CXXMemberCallExpr *S) { |
| 403 | VisitCallExpr(S); |
| 404 | } |
| 405 | |
| 406 | void StmtProfiler::VisitCXXNamedCastExpr(CXXNamedCastExpr *S) { |
| 407 | VisitExplicitCastExpr(S); |
| 408 | } |
| 409 | |
| 410 | void StmtProfiler::VisitCXXStaticCastExpr(CXXStaticCastExpr *S) { |
| 411 | VisitCXXNamedCastExpr(S); |
| 412 | } |
| 413 | |
| 414 | void StmtProfiler::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *S) { |
| 415 | VisitCXXNamedCastExpr(S); |
| 416 | } |
| 417 | |
| 418 | void StmtProfiler::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *S) { |
| 419 | VisitCXXNamedCastExpr(S); |
| 420 | } |
| 421 | |
| 422 | void StmtProfiler::VisitCXXConstCastExpr(CXXConstCastExpr *S) { |
| 423 | VisitCXXNamedCastExpr(S); |
| 424 | } |
| 425 | |
| 426 | void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) { |
| 427 | VisitExpr(S); |
| 428 | ID.AddBoolean(S->getValue()); |
| 429 | } |
| 430 | |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 431 | void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) { |
| 432 | VisitExpr(S); |
| 433 | } |
| 434 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 435 | void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) { |
| 436 | VisitExpr(S); |
| 437 | if (S->isTypeOperand()) |
| 438 | VisitType(S->getTypeOperand()); |
| 439 | } |
| 440 | |
| 441 | void StmtProfiler::VisitCXXThisExpr(CXXThisExpr *S) { |
| 442 | VisitExpr(S); |
| 443 | } |
| 444 | |
| 445 | void StmtProfiler::VisitCXXThrowExpr(CXXThrowExpr *S) { |
| 446 | VisitExpr(S); |
| 447 | } |
| 448 | |
| 449 | void StmtProfiler::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *S) { |
| 450 | VisitExpr(S); |
| 451 | VisitDecl(S->getParam()); |
| 452 | } |
| 453 | |
| 454 | void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) { |
| 455 | VisitExpr(S); |
| 456 | VisitDecl( |
| 457 | const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor())); |
| 458 | } |
| 459 | |
| 460 | void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) { |
| 461 | VisitExpr(S); |
| 462 | VisitDecl(S->getConstructor()); |
| 463 | ID.AddBoolean(S->isElidable()); |
| 464 | } |
| 465 | |
| 466 | void StmtProfiler::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *S) { |
| 467 | VisitExplicitCastExpr(S); |
| 468 | } |
| 469 | |
| 470 | void StmtProfiler::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *S) { |
| 471 | VisitCXXConstructExpr(S); |
| 472 | } |
| 473 | |
| 474 | void StmtProfiler::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *S) { |
| 475 | VisitExpr(S); |
| 476 | } |
| 477 | |
| 478 | void StmtProfiler::VisitCXXConditionDeclExpr(CXXConditionDeclExpr *S) { |
| 479 | VisitDeclRefExpr(S); |
| 480 | } |
| 481 | |
| 482 | void StmtProfiler::VisitCXXDeleteExpr(CXXDeleteExpr *S) { |
| 483 | VisitExpr(S); |
| 484 | ID.AddBoolean(S->isGlobalDelete()); |
| 485 | ID.AddBoolean(S->isArrayForm()); |
| 486 | VisitDecl(S->getOperatorDelete()); |
| 487 | } |
| 488 | |
| 489 | |
| 490 | void StmtProfiler::VisitCXXNewExpr(CXXNewExpr *S) { |
| 491 | VisitExpr(S); |
| 492 | VisitType(S->getAllocatedType()); |
| 493 | VisitDecl(S->getOperatorNew()); |
| 494 | VisitDecl(S->getOperatorDelete()); |
| 495 | VisitDecl(S->getConstructor()); |
| 496 | ID.AddBoolean(S->isArray()); |
| 497 | ID.AddInteger(S->getNumPlacementArgs()); |
| 498 | ID.AddBoolean(S->isGlobalNew()); |
| 499 | ID.AddBoolean(S->isParenTypeId()); |
| 500 | ID.AddBoolean(S->hasInitializer()); |
| 501 | ID.AddInteger(S->getNumConstructorArgs()); |
| 502 | } |
| 503 | |
| 504 | void |
| 505 | StmtProfiler::VisitUnresolvedFunctionNameExpr(UnresolvedFunctionNameExpr *S) { |
| 506 | VisitExpr(S); |
| 507 | VisitName(S->getName()); |
| 508 | } |
| 509 | |
| 510 | void StmtProfiler::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *S) { |
| 511 | VisitExpr(S); |
| 512 | ID.AddInteger(S->getTrait()); |
| 513 | VisitType(S->getQueriedType()); |
| 514 | } |
| 515 | |
| 516 | void StmtProfiler::VisitQualifiedDeclRefExpr(QualifiedDeclRefExpr *S) { |
| 517 | VisitDeclRefExpr(S); |
| 518 | VisitNestedNameSpecifier(S->getQualifier()); |
| 519 | } |
| 520 | |
| 521 | void StmtProfiler::VisitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *S) { |
| 522 | VisitExpr(S); |
| 523 | VisitName(S->getDeclName()); |
| 524 | VisitNestedNameSpecifier(S->getQualifier()); |
| 525 | ID.AddBoolean(S->isAddressOfOperand()); |
| 526 | } |
| 527 | |
| 528 | void StmtProfiler::VisitTemplateIdRefExpr(TemplateIdRefExpr *S) { |
| 529 | VisitExpr(S); |
| 530 | VisitNestedNameSpecifier(S->getQualifier()); |
| 531 | VisitTemplateName(S->getTemplateName()); |
| 532 | VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); |
| 533 | } |
| 534 | |
Douglas Gregor | 071f4eb | 2009-07-28 14:44:31 +0000 | [diff] [blame] | 535 | void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) { |
| 536 | VisitExpr(S); |
| 537 | ID.AddBoolean(S->shouldDestroyTemporaries()); |
| 538 | for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I) |
| 539 | VisitDecl( |
| 540 | const_cast<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor())); |
| 541 | } |
| 542 | |
| 543 | void |
| 544 | StmtProfiler::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *S) { |
| 545 | VisitExpr(S); |
| 546 | VisitType(S->getTypeAsWritten()); |
| 547 | } |
| 548 | |
| 549 | void StmtProfiler::VisitCXXUnresolvedMemberExpr(CXXUnresolvedMemberExpr *S) { |
| 550 | VisitExpr(S); |
| 551 | ID.AddBoolean(S->isArrow()); |
| 552 | VisitName(S->getMember()); |
| 553 | } |
| 554 | |
| 555 | void StmtProfiler::VisitObjCStringLiteral(ObjCStringLiteral *S) { |
| 556 | VisitExpr(S); |
| 557 | } |
| 558 | |
| 559 | void StmtProfiler::VisitObjCEncodeExpr(ObjCEncodeExpr *S) { |
| 560 | VisitExpr(S); |
| 561 | VisitType(S->getEncodedType()); |
| 562 | } |
| 563 | |
| 564 | void StmtProfiler::VisitObjCSelectorExpr(ObjCSelectorExpr *S) { |
| 565 | VisitExpr(S); |
| 566 | VisitName(S->getSelector()); |
| 567 | } |
| 568 | |
| 569 | void StmtProfiler::VisitObjCProtocolExpr(ObjCProtocolExpr *S) { |
| 570 | VisitExpr(S); |
| 571 | VisitDecl(S->getProtocol()); |
| 572 | } |
| 573 | |
| 574 | void StmtProfiler::VisitObjCIvarRefExpr(ObjCIvarRefExpr *S) { |
| 575 | VisitExpr(S); |
| 576 | VisitDecl(S->getDecl()); |
| 577 | ID.AddBoolean(S->isArrow()); |
| 578 | ID.AddBoolean(S->isFreeIvar()); |
| 579 | } |
| 580 | |
| 581 | void StmtProfiler::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *S) { |
| 582 | VisitExpr(S); |
| 583 | VisitDecl(S->getProperty()); |
| 584 | } |
| 585 | |
| 586 | void StmtProfiler::VisitObjCKVCRefExpr(ObjCKVCRefExpr *S) { |
| 587 | VisitExpr(S); |
| 588 | VisitDecl(S->getGetterMethod()); |
| 589 | VisitDecl(S->getSetterMethod()); |
| 590 | VisitDecl(S->getClassProp()); |
| 591 | } |
| 592 | |
| 593 | void StmtProfiler::VisitObjCMessageExpr(ObjCMessageExpr *S) { |
| 594 | VisitExpr(S); |
| 595 | VisitName(S->getSelector()); |
| 596 | VisitDecl(S->getMethodDecl()); |
| 597 | } |
| 598 | |
| 599 | void StmtProfiler::VisitObjCSuperExpr(ObjCSuperExpr *S) { |
| 600 | VisitExpr(S); |
| 601 | } |
| 602 | |
| 603 | void StmtProfiler::VisitObjCIsaExpr(ObjCIsaExpr *S) { |
| 604 | VisitExpr(S); |
| 605 | ID.AddBoolean(S->isArrow()); |
| 606 | } |
| 607 | |
Douglas Gregor | d584eb2 | 2009-07-28 15:32:17 +0000 | [diff] [blame] | 608 | void StmtProfiler::VisitDecl(Decl *D) { |
Douglas Gregor | 4a3f780 | 2009-07-31 15:45:02 +0000 | [diff] [blame] | 609 | ID.AddInteger(D? D->getKind() : 0); |
| 610 | |
Douglas Gregor | b197572 | 2009-07-30 23:18:24 +0000 | [diff] [blame] | 611 | if (Canonical && D) { |
Douglas Gregor | 6ebd15e | 2009-07-31 05:24:01 +0000 | [diff] [blame] | 612 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { |
Douglas Gregor | d584eb2 | 2009-07-28 15:32:17 +0000 | [diff] [blame] | 613 | ID.AddInteger(NTTP->getDepth()); |
| 614 | ID.AddInteger(NTTP->getIndex()); |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 615 | VisitType(NTTP->getType()); |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 616 | return; |
| 617 | } |
| 618 | |
Douglas Gregor | 4a3f780 | 2009-07-31 15:45:02 +0000 | [diff] [blame] | 619 | if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { |
| 620 | // The Itanium C++ ABI uses the type of a parameter when mangling |
| 621 | // expressions that involve function parameters, so we will use the |
| 622 | // parameter's type for establishing function parameter identity. That |
| 623 | // way, our definition of "equivalent" (per C++ [temp.over.link]) |
| 624 | // matches the definition of "equivalent" used for name mangling. |
| 625 | VisitType(Parm->getType()); |
| 626 | return; |
| 627 | } |
| 628 | |
Douglas Gregor | a2ffb98 | 2009-07-31 15:46:56 +0000 | [diff] [blame] | 629 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { |
| 630 | ID.AddInteger(TTP->getDepth()); |
| 631 | ID.AddInteger(TTP->getIndex()); |
| 632 | return; |
| 633 | } |
Douglas Gregor | 6ebd15e | 2009-07-31 05:24:01 +0000 | [diff] [blame] | 634 | |
| 635 | if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) { |
Douglas Gregor | 6f2c46b | 2009-07-31 16:07:31 +0000 | [diff] [blame] | 636 | // The Itanium C++ ABI mangles references to a set of overloaded |
| 637 | // functions using just the function name, so we do the same here. |
| 638 | VisitName(Ovl->getDeclName()); |
Douglas Gregor | 6ebd15e | 2009-07-31 05:24:01 +0000 | [diff] [blame] | 639 | return; |
| 640 | } |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Douglas Gregor | d584eb2 | 2009-07-28 15:32:17 +0000 | [diff] [blame] | 643 | ID.AddPointer(D? D->getCanonicalDecl() : 0); |
| 644 | } |
| 645 | |
| 646 | void StmtProfiler::VisitType(QualType T) { |
| 647 | if (Canonical) |
| 648 | T = Context.getCanonicalType(T); |
| 649 | |
Douglas Gregor | 41ef0c3 | 2009-07-28 00:33:38 +0000 | [diff] [blame] | 650 | ID.AddPointer(T.getAsOpaquePtr()); |
| 651 | } |
| 652 | |
| 653 | void StmtProfiler::VisitName(DeclarationName Name) { |
| 654 | ID.AddPointer(Name.getAsOpaquePtr()); |
| 655 | } |
| 656 | |
| 657 | void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) { |
| 658 | if (Canonical) |
| 659 | NNS = Context.getCanonicalNestedNameSpecifier(NNS); |
| 660 | ID.AddPointer(NNS); |
| 661 | } |
| 662 | |
| 663 | void StmtProfiler::VisitTemplateName(TemplateName Name) { |
| 664 | if (Canonical) |
| 665 | Name = Context.getCanonicalTemplateName(Name); |
| 666 | |
| 667 | Name.Profile(ID); |
| 668 | } |
| 669 | |
| 670 | void StmtProfiler::VisitTemplateArguments(const TemplateArgument *Args, |
| 671 | unsigned NumArgs) { |
| 672 | ID.AddInteger(NumArgs); |
| 673 | for (unsigned I = 0; I != NumArgs; ++I) { |
| 674 | const TemplateArgument &Arg = Args[I]; |
| 675 | |
| 676 | // Mostly repetitive with TemplateArgument::Profile! |
| 677 | ID.AddInteger(Arg.getKind()); |
| 678 | switch (Arg.getKind()) { |
| 679 | case TemplateArgument::Null: |
| 680 | break; |
| 681 | |
| 682 | case TemplateArgument::Type: |
| 683 | VisitType(Arg.getAsType()); |
| 684 | break; |
| 685 | |
| 686 | case TemplateArgument::Declaration: |
| 687 | VisitDecl(Arg.getAsDecl()); |
| 688 | break; |
| 689 | |
| 690 | case TemplateArgument::Integral: |
| 691 | Arg.getAsIntegral()->Profile(ID); |
| 692 | VisitType(Arg.getIntegralType()); |
| 693 | break; |
| 694 | |
| 695 | case TemplateArgument::Expression: |
| 696 | Visit(Arg.getAsExpr()); |
| 697 | break; |
| 698 | |
| 699 | case TemplateArgument::Pack: |
| 700 | VisitTemplateArguments(Arg.pack_begin(), Arg.pack_size()); |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | void Stmt::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, |
| 707 | bool Canonical) { |
| 708 | StmtProfiler Profiler(ID, Context, Canonical); |
| 709 | Profiler.Visit(this); |
| 710 | } |