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