Home | History | Annotate | Download | only in AST
      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
     11 // representation that identifies a statement/expression.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 #include "clang/AST/ASTContext.h"
     15 #include "clang/AST/DeclCXX.h"
     16 #include "clang/AST/DeclObjC.h"
     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 using namespace clang;
     24 
     25 namespace {
     26   class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
     27     llvm::FoldingSetNodeID &ID;
     28     const ASTContext &Context;
     29     bool Canonical;
     30 
     31   public:
     32     StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
     33                  bool Canonical)
     34       : ID(ID), Context(Context), Canonical(Canonical) { }
     35 
     36     void VisitStmt(const Stmt *S);
     37 
     38 #define STMT(Node, Base) void Visit##Node(const Node *S);
     39 #include "clang/AST/StmtNodes.inc"
     40 
     41     /// \brief Visit a declaration that is referenced within an expression
     42     /// or statement.
     43     void VisitDecl(const Decl *D);
     44 
     45     /// \brief Visit a type that is referenced within an expression or
     46     /// statement.
     47     void VisitType(QualType T);
     48 
     49     /// \brief Visit a name that occurs within an expression or statement.
     50     void VisitName(DeclarationName Name);
     51 
     52     /// \brief Visit a nested-name-specifier that occurs within an expression
     53     /// or statement.
     54     void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
     55 
     56     /// \brief Visit a template name that occurs within an expression or
     57     /// statement.
     58     void VisitTemplateName(TemplateName Name);
     59 
     60     /// \brief Visit template arguments that occur within an expression or
     61     /// statement.
     62     void VisitTemplateArguments(const TemplateArgumentLoc *Args,
     63                                 unsigned NumArgs);
     64 
     65     /// \brief Visit a single template argument.
     66     void VisitTemplateArgument(const TemplateArgument &Arg);
     67   };
     68 }
     69 
     70 void StmtProfiler::VisitStmt(const Stmt *S) {
     71   ID.AddInteger(S->getStmtClass());
     72   for (Stmt::const_child_range C = S->children(); C; ++C)
     73     Visit(*C);
     74 }
     75 
     76 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
     77   VisitStmt(S);
     78   for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
     79        D != DEnd; ++D)
     80     VisitDecl(*D);
     81 }
     82 
     83 void StmtProfiler::VisitNullStmt(const NullStmt *S) {
     84   VisitStmt(S);
     85 }
     86 
     87 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
     88   VisitStmt(S);
     89 }
     90 
     91 void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
     92   VisitStmt(S);
     93 }
     94 
     95 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
     96   VisitStmt(S);
     97 }
     98 
     99 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
    100   VisitStmt(S);
    101 }
    102 
    103 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
    104   VisitStmt(S);
    105   VisitDecl(S->getDecl());
    106 }
    107 
    108 void StmtProfiler::VisitIfStmt(const IfStmt *S) {
    109   VisitStmt(S);
    110   VisitDecl(S->getConditionVariable());
    111 }
    112 
    113 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
    114   VisitStmt(S);
    115   VisitDecl(S->getConditionVariable());
    116 }
    117 
    118 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
    119   VisitStmt(S);
    120   VisitDecl(S->getConditionVariable());
    121 }
    122 
    123 void StmtProfiler::VisitDoStmt(const DoStmt *S) {
    124   VisitStmt(S);
    125 }
    126 
    127 void StmtProfiler::VisitForStmt(const ForStmt *S) {
    128   VisitStmt(S);
    129 }
    130 
    131 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
    132   VisitStmt(S);
    133   VisitDecl(S->getLabel());
    134 }
    135 
    136 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
    137   VisitStmt(S);
    138 }
    139 
    140 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
    141   VisitStmt(S);
    142 }
    143 
    144 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
    145   VisitStmt(S);
    146 }
    147 
    148 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
    149   VisitStmt(S);
    150 }
    151 
    152 void StmtProfiler::VisitAsmStmt(const 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(const CXXCatchStmt *S) {
    173   VisitStmt(S);
    174   VisitType(S->getCaughtType());
    175 }
    176 
    177 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
    178   VisitStmt(S);
    179 }
    180 
    181 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
    182   VisitStmt(S);
    183 }
    184 
    185 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
    186   VisitStmt(S);
    187 }
    188 
    189 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
    190   VisitStmt(S);
    191 }
    192 
    193 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
    194   VisitStmt(S);
    195 }
    196 
    197 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
    198   VisitStmt(S);
    199 }
    200 
    201 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
    202   VisitStmt(S);
    203   ID.AddBoolean(S->hasEllipsis());
    204   if (S->getCatchParamDecl())
    205     VisitType(S->getCatchParamDecl()->getType());
    206 }
    207 
    208 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
    209   VisitStmt(S);
    210 }
    211 
    212 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
    213   VisitStmt(S);
    214 }
    215 
    216 void
    217 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
    218   VisitStmt(S);
    219 }
    220 
    221 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
    222   VisitStmt(S);
    223 }
    224 
    225 void
    226 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
    227   VisitStmt(S);
    228 }
    229 
    230 void StmtProfiler::VisitExpr(const Expr *S) {
    231   VisitStmt(S);
    232 }
    233 
    234 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
    235   VisitExpr(S);
    236   if (!Canonical)
    237     VisitNestedNameSpecifier(S->getQualifier());
    238   VisitDecl(S->getDecl());
    239   if (!Canonical)
    240     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
    241 }
    242 
    243 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
    244   VisitExpr(S);
    245   ID.AddInteger(S->getIdentType());
    246 }
    247 
    248 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
    249   VisitExpr(S);
    250   S->getValue().Profile(ID);
    251 }
    252 
    253 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
    254   VisitExpr(S);
    255   ID.AddInteger(S->getKind());
    256   ID.AddInteger(S->getValue());
    257 }
    258 
    259 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
    260   VisitExpr(S);
    261   S->getValue().Profile(ID);
    262   ID.AddBoolean(S->isExact());
    263 }
    264 
    265 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
    266   VisitExpr(S);
    267 }
    268 
    269 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
    270   VisitExpr(S);
    271   ID.AddString(S->getString());
    272   ID.AddInteger(S->getKind());
    273 }
    274 
    275 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
    276   VisitExpr(S);
    277 }
    278 
    279 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
    280   VisitExpr(S);
    281 }
    282 
    283 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
    284   VisitExpr(S);
    285   ID.AddInteger(S->getOpcode());
    286 }
    287 
    288 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
    289   VisitType(S->getTypeSourceInfo()->getType());
    290   unsigned n = S->getNumComponents();
    291   for (unsigned i = 0; i < n; ++i) {
    292     const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
    293     ID.AddInteger(ON.getKind());
    294     switch (ON.getKind()) {
    295     case OffsetOfExpr::OffsetOfNode::Array:
    296       // Expressions handled below.
    297       break;
    298 
    299     case OffsetOfExpr::OffsetOfNode::Field:
    300       VisitDecl(ON.getField());
    301       break;
    302 
    303     case OffsetOfExpr::OffsetOfNode::Identifier:
    304       ID.AddPointer(ON.getFieldName());
    305       break;
    306 
    307     case OffsetOfExpr::OffsetOfNode::Base:
    308       // These nodes are implicit, and therefore don't need profiling.
    309       break;
    310     }
    311   }
    312 
    313   VisitExpr(S);
    314 }
    315 
    316 void
    317 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
    318   VisitExpr(S);
    319   ID.AddInteger(S->getKind());
    320   if (S->isArgumentType())
    321     VisitType(S->getArgumentType());
    322 }
    323 
    324 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
    325   VisitExpr(S);
    326 }
    327 
    328 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
    329   VisitExpr(S);
    330 }
    331 
    332 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
    333   VisitExpr(S);
    334   VisitDecl(S->getMemberDecl());
    335   if (!Canonical)
    336     VisitNestedNameSpecifier(S->getQualifier());
    337   ID.AddBoolean(S->isArrow());
    338 }
    339 
    340 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
    341   VisitExpr(S);
    342   ID.AddBoolean(S->isFileScope());
    343 }
    344 
    345 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
    346   VisitExpr(S);
    347 }
    348 
    349 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
    350   VisitCastExpr(S);
    351   ID.AddInteger(S->getValueKind());
    352 }
    353 
    354 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
    355   VisitCastExpr(S);
    356   VisitType(S->getTypeAsWritten());
    357 }
    358 
    359 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
    360   VisitExplicitCastExpr(S);
    361 }
    362 
    363 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
    364   VisitExpr(S);
    365   ID.AddInteger(S->getOpcode());
    366 }
    367 
    368 void
    369 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
    370   VisitBinaryOperator(S);
    371 }
    372 
    373 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
    374   VisitExpr(S);
    375 }
    376 
    377 void StmtProfiler::VisitBinaryConditionalOperator(
    378     const BinaryConditionalOperator *S) {
    379   VisitExpr(S);
    380 }
    381 
    382 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
    383   VisitExpr(S);
    384   VisitDecl(S->getLabel());
    385 }
    386 
    387 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
    388   VisitExpr(S);
    389 }
    390 
    391 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
    392   VisitExpr(S);
    393 }
    394 
    395 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
    396   VisitExpr(S);
    397 }
    398 
    399 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
    400   VisitExpr(S);
    401 }
    402 
    403 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
    404   VisitExpr(S);
    405 }
    406 
    407 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
    408   if (S->getSyntacticForm()) {
    409     VisitInitListExpr(S->getSyntacticForm());
    410     return;
    411   }
    412 
    413   VisitExpr(S);
    414 }
    415 
    416 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
    417   VisitExpr(S);
    418   ID.AddBoolean(S->usesGNUSyntax());
    419   for (DesignatedInitExpr::const_designators_iterator D =
    420          S->designators_begin(), DEnd = S->designators_end();
    421        D != DEnd; ++D) {
    422     if (D->isFieldDesignator()) {
    423       ID.AddInteger(0);
    424       VisitName(D->getFieldName());
    425       continue;
    426     }
    427 
    428     if (D->isArrayDesignator()) {
    429       ID.AddInteger(1);
    430     } else {
    431       assert(D->isArrayRangeDesignator());
    432       ID.AddInteger(2);
    433     }
    434     ID.AddInteger(D->getFirstExprIndex());
    435   }
    436 }
    437 
    438 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
    439   VisitExpr(S);
    440 }
    441 
    442 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
    443   VisitExpr(S);
    444   VisitName(&S->getAccessor());
    445 }
    446 
    447 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
    448   VisitExpr(S);
    449   VisitDecl(S->getBlockDecl());
    450 }
    451 
    452 void StmtProfiler::VisitBlockDeclRefExpr(const BlockDeclRefExpr *S) {
    453   VisitExpr(S);
    454   VisitDecl(S->getDecl());
    455   ID.AddBoolean(S->isByRef());
    456   ID.AddBoolean(S->isConstQualAdded());
    457 }
    458 
    459 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
    460   VisitExpr(S);
    461   for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
    462     QualType T = S->getAssocType(i);
    463     if (T.isNull())
    464       ID.AddPointer(0);
    465     else
    466       VisitType(T);
    467     VisitExpr(S->getAssocExpr(i));
    468   }
    469 }
    470 
    471 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
    472   VisitExpr(S);
    473   ID.AddInteger(S->getOp());
    474 }
    475 
    476 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
    477                                           UnaryOperatorKind &UnaryOp,
    478                                           BinaryOperatorKind &BinaryOp) {
    479   switch (S->getOperator()) {
    480   case OO_None:
    481   case OO_New:
    482   case OO_Delete:
    483   case OO_Array_New:
    484   case OO_Array_Delete:
    485   case OO_Arrow:
    486   case OO_Call:
    487   case OO_Conditional:
    488   case NUM_OVERLOADED_OPERATORS:
    489     llvm_unreachable("Invalid operator call kind");
    490     return Stmt::ArraySubscriptExprClass;
    491 
    492   case OO_Plus:
    493     if (S->getNumArgs() == 1) {
    494       UnaryOp = UO_Plus;
    495       return Stmt::UnaryOperatorClass;
    496     }
    497 
    498     BinaryOp = BO_Add;
    499     return Stmt::BinaryOperatorClass;
    500 
    501   case OO_Minus:
    502     if (S->getNumArgs() == 1) {
    503       UnaryOp = UO_Minus;
    504       return Stmt::UnaryOperatorClass;
    505     }
    506 
    507     BinaryOp = BO_Sub;
    508     return Stmt::BinaryOperatorClass;
    509 
    510   case OO_Star:
    511     if (S->getNumArgs() == 1) {
    512       UnaryOp = UO_Minus;
    513       return Stmt::UnaryOperatorClass;
    514     }
    515 
    516     BinaryOp = BO_Sub;
    517     return Stmt::BinaryOperatorClass;
    518 
    519   case OO_Slash:
    520     BinaryOp = BO_Div;
    521     return Stmt::BinaryOperatorClass;
    522 
    523   case OO_Percent:
    524     BinaryOp = BO_Rem;
    525     return Stmt::BinaryOperatorClass;
    526 
    527   case OO_Caret:
    528     BinaryOp = BO_Xor;
    529     return Stmt::BinaryOperatorClass;
    530 
    531   case OO_Amp:
    532     if (S->getNumArgs() == 1) {
    533       UnaryOp = UO_AddrOf;
    534       return Stmt::UnaryOperatorClass;
    535     }
    536 
    537     BinaryOp = BO_And;
    538     return Stmt::BinaryOperatorClass;
    539 
    540   case OO_Pipe:
    541     BinaryOp = BO_Or;
    542     return Stmt::BinaryOperatorClass;
    543 
    544   case OO_Tilde:
    545     UnaryOp = UO_Not;
    546     return Stmt::UnaryOperatorClass;
    547 
    548   case OO_Exclaim:
    549     UnaryOp = UO_LNot;
    550     return Stmt::UnaryOperatorClass;
    551 
    552   case OO_Equal:
    553     BinaryOp = BO_Assign;
    554     return Stmt::BinaryOperatorClass;
    555 
    556   case OO_Less:
    557     BinaryOp = BO_LT;
    558     return Stmt::BinaryOperatorClass;
    559 
    560   case OO_Greater:
    561     BinaryOp = BO_GT;
    562     return Stmt::BinaryOperatorClass;
    563 
    564   case OO_PlusEqual:
    565     BinaryOp = BO_AddAssign;
    566     return Stmt::CompoundAssignOperatorClass;
    567 
    568   case OO_MinusEqual:
    569     BinaryOp = BO_SubAssign;
    570     return Stmt::CompoundAssignOperatorClass;
    571 
    572   case OO_StarEqual:
    573     BinaryOp = BO_MulAssign;
    574     return Stmt::CompoundAssignOperatorClass;
    575 
    576   case OO_SlashEqual:
    577     BinaryOp = BO_DivAssign;
    578     return Stmt::CompoundAssignOperatorClass;
    579 
    580   case OO_PercentEqual:
    581     BinaryOp = BO_RemAssign;
    582     return Stmt::CompoundAssignOperatorClass;
    583 
    584   case OO_CaretEqual:
    585     BinaryOp = BO_XorAssign;
    586     return Stmt::CompoundAssignOperatorClass;
    587 
    588   case OO_AmpEqual:
    589     BinaryOp = BO_AndAssign;
    590     return Stmt::CompoundAssignOperatorClass;
    591 
    592   case OO_PipeEqual:
    593     BinaryOp = BO_OrAssign;
    594     return Stmt::CompoundAssignOperatorClass;
    595 
    596   case OO_LessLess:
    597     BinaryOp = BO_Shl;
    598     return Stmt::BinaryOperatorClass;
    599 
    600   case OO_GreaterGreater:
    601     BinaryOp = BO_Shr;
    602     return Stmt::BinaryOperatorClass;
    603 
    604   case OO_LessLessEqual:
    605     BinaryOp = BO_ShlAssign;
    606     return Stmt::CompoundAssignOperatorClass;
    607 
    608   case OO_GreaterGreaterEqual:
    609     BinaryOp = BO_ShrAssign;
    610     return Stmt::CompoundAssignOperatorClass;
    611 
    612   case OO_EqualEqual:
    613     BinaryOp = BO_EQ;
    614     return Stmt::BinaryOperatorClass;
    615 
    616   case OO_ExclaimEqual:
    617     BinaryOp = BO_NE;
    618     return Stmt::BinaryOperatorClass;
    619 
    620   case OO_LessEqual:
    621     BinaryOp = BO_LE;
    622     return Stmt::BinaryOperatorClass;
    623 
    624   case OO_GreaterEqual:
    625     BinaryOp = BO_GE;
    626     return Stmt::BinaryOperatorClass;
    627 
    628   case OO_AmpAmp:
    629     BinaryOp = BO_LAnd;
    630     return Stmt::BinaryOperatorClass;
    631 
    632   case OO_PipePipe:
    633     BinaryOp = BO_LOr;
    634     return Stmt::BinaryOperatorClass;
    635 
    636   case OO_PlusPlus:
    637     UnaryOp = S->getNumArgs() == 1? UO_PreInc
    638                                   : UO_PostInc;
    639     return Stmt::UnaryOperatorClass;
    640 
    641   case OO_MinusMinus:
    642     UnaryOp = S->getNumArgs() == 1? UO_PreDec
    643                                   : UO_PostDec;
    644     return Stmt::UnaryOperatorClass;
    645 
    646   case OO_Comma:
    647     BinaryOp = BO_Comma;
    648     return Stmt::BinaryOperatorClass;
    649 
    650 
    651   case OO_ArrowStar:
    652     BinaryOp = BO_PtrMemI;
    653     return Stmt::BinaryOperatorClass;
    654 
    655   case OO_Subscript:
    656     return Stmt::ArraySubscriptExprClass;
    657   }
    658 
    659   llvm_unreachable("Invalid overloaded operator expression");
    660 }
    661 
    662 
    663 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
    664   if (S->isTypeDependent()) {
    665     // Type-dependent operator calls are profiled like their underlying
    666     // syntactic operator.
    667     UnaryOperatorKind UnaryOp = UO_Extension;
    668     BinaryOperatorKind BinaryOp = BO_Comma;
    669     Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
    670 
    671     ID.AddInteger(SC);
    672     for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
    673       Visit(S->getArg(I));
    674     if (SC == Stmt::UnaryOperatorClass)
    675       ID.AddInteger(UnaryOp);
    676     else if (SC == Stmt::BinaryOperatorClass ||
    677              SC == Stmt::CompoundAssignOperatorClass)
    678       ID.AddInteger(BinaryOp);
    679     else
    680       assert(SC == Stmt::ArraySubscriptExprClass);
    681 
    682     return;
    683   }
    684 
    685   VisitCallExpr(S);
    686   ID.AddInteger(S->getOperator());
    687 }
    688 
    689 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
    690   VisitCallExpr(S);
    691 }
    692 
    693 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
    694   VisitCallExpr(S);
    695 }
    696 
    697 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
    698   VisitExpr(S);
    699 }
    700 
    701 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
    702   VisitExplicitCastExpr(S);
    703 }
    704 
    705 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
    706   VisitCXXNamedCastExpr(S);
    707 }
    708 
    709 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
    710   VisitCXXNamedCastExpr(S);
    711 }
    712 
    713 void
    714 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
    715   VisitCXXNamedCastExpr(S);
    716 }
    717 
    718 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
    719   VisitCXXNamedCastExpr(S);
    720 }
    721 
    722 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
    723   VisitExpr(S);
    724   ID.AddBoolean(S->getValue());
    725 }
    726 
    727 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
    728   VisitExpr(S);
    729 }
    730 
    731 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
    732   VisitExpr(S);
    733   if (S->isTypeOperand())
    734     VisitType(S->getTypeOperand());
    735 }
    736 
    737 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
    738   VisitExpr(S);
    739   if (S->isTypeOperand())
    740     VisitType(S->getTypeOperand());
    741 }
    742 
    743 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
    744   VisitExpr(S);
    745 }
    746 
    747 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
    748   VisitExpr(S);
    749 }
    750 
    751 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
    752   VisitExpr(S);
    753   VisitDecl(S->getParam());
    754 }
    755 
    756 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
    757   VisitExpr(S);
    758   VisitDecl(
    759          const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
    760 }
    761 
    762 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
    763   VisitExpr(S);
    764   VisitDecl(S->getConstructor());
    765   ID.AddBoolean(S->isElidable());
    766 }
    767 
    768 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
    769   VisitExplicitCastExpr(S);
    770 }
    771 
    772 void
    773 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
    774   VisitCXXConstructExpr(S);
    775 }
    776 
    777 void
    778 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
    779   VisitExpr(S);
    780 }
    781 
    782 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
    783   VisitExpr(S);
    784   ID.AddBoolean(S->isGlobalDelete());
    785   ID.AddBoolean(S->isArrayForm());
    786   VisitDecl(S->getOperatorDelete());
    787 }
    788 
    789 
    790 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
    791   VisitExpr(S);
    792   VisitType(S->getAllocatedType());
    793   VisitDecl(S->getOperatorNew());
    794   VisitDecl(S->getOperatorDelete());
    795   VisitDecl(S->getConstructor());
    796   ID.AddBoolean(S->isArray());
    797   ID.AddInteger(S->getNumPlacementArgs());
    798   ID.AddBoolean(S->isGlobalNew());
    799   ID.AddBoolean(S->isParenTypeId());
    800   ID.AddBoolean(S->hasInitializer());
    801   ID.AddInteger(S->getNumConstructorArgs());
    802 }
    803 
    804 void
    805 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
    806   VisitExpr(S);
    807   ID.AddBoolean(S->isArrow());
    808   VisitNestedNameSpecifier(S->getQualifier());
    809   VisitType(S->getDestroyedType());
    810 }
    811 
    812 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
    813   VisitExpr(S);
    814   VisitNestedNameSpecifier(S->getQualifier());
    815   VisitName(S->getName());
    816   ID.AddBoolean(S->hasExplicitTemplateArgs());
    817   if (S->hasExplicitTemplateArgs())
    818     VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
    819                            S->getExplicitTemplateArgs().NumTemplateArgs);
    820 }
    821 
    822 void
    823 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
    824   VisitOverloadExpr(S);
    825 }
    826 
    827 void StmtProfiler::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *S) {
    828   VisitExpr(S);
    829   ID.AddInteger(S->getTrait());
    830   VisitType(S->getQueriedType());
    831 }
    832 
    833 void StmtProfiler::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *S) {
    834   VisitExpr(S);
    835   ID.AddInteger(S->getTrait());
    836   VisitType(S->getLhsType());
    837   VisitType(S->getRhsType());
    838 }
    839 
    840 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
    841   VisitExpr(S);
    842   ID.AddInteger(S->getTrait());
    843   VisitType(S->getQueriedType());
    844 }
    845 
    846 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
    847   VisitExpr(S);
    848   ID.AddInteger(S->getTrait());
    849   VisitExpr(S->getQueriedExpression());
    850 }
    851 
    852 void StmtProfiler::VisitDependentScopeDeclRefExpr(
    853     const DependentScopeDeclRefExpr *S) {
    854   VisitExpr(S);
    855   VisitName(S->getDeclName());
    856   VisitNestedNameSpecifier(S->getQualifier());
    857   ID.AddBoolean(S->hasExplicitTemplateArgs());
    858   if (S->hasExplicitTemplateArgs())
    859     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
    860 }
    861 
    862 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
    863   VisitExpr(S);
    864 }
    865 
    866 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
    867     const CXXUnresolvedConstructExpr *S) {
    868   VisitExpr(S);
    869   VisitType(S->getTypeAsWritten());
    870 }
    871 
    872 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
    873     const CXXDependentScopeMemberExpr *S) {
    874   ID.AddBoolean(S->isImplicitAccess());
    875   if (!S->isImplicitAccess()) {
    876     VisitExpr(S);
    877     ID.AddBoolean(S->isArrow());
    878   }
    879   VisitNestedNameSpecifier(S->getQualifier());
    880   VisitName(S->getMember());
    881   ID.AddBoolean(S->hasExplicitTemplateArgs());
    882   if (S->hasExplicitTemplateArgs())
    883     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
    884 }
    885 
    886 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
    887   ID.AddBoolean(S->isImplicitAccess());
    888   if (!S->isImplicitAccess()) {
    889     VisitExpr(S);
    890     ID.AddBoolean(S->isArrow());
    891   }
    892   VisitNestedNameSpecifier(S->getQualifier());
    893   VisitName(S->getMemberName());
    894   ID.AddBoolean(S->hasExplicitTemplateArgs());
    895   if (S->hasExplicitTemplateArgs())
    896     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
    897 }
    898 
    899 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
    900   VisitExpr(S);
    901 }
    902 
    903 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
    904   VisitExpr(S);
    905 }
    906 
    907 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
    908   VisitExpr(S);
    909   VisitDecl(S->getPack());
    910 }
    911 
    912 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
    913     const SubstNonTypeTemplateParmPackExpr *S) {
    914   VisitExpr(S);
    915   VisitDecl(S->getParameterPack());
    916   VisitTemplateArgument(S->getArgumentPack());
    917 }
    918 
    919 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
    920     const SubstNonTypeTemplateParmExpr *E) {
    921   // Profile exactly as the replacement expression.
    922   Visit(E->getReplacement());
    923 }
    924 
    925 void StmtProfiler::VisitMaterializeTemporaryExpr(
    926                                            const MaterializeTemporaryExpr *S) {
    927   VisitExpr(S);
    928 }
    929 
    930 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
    931   VisitExpr(E);
    932 }
    933 
    934 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
    935   VisitExpr(S);
    936 }
    937 
    938 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
    939   VisitExpr(S);
    940   VisitType(S->getEncodedType());
    941 }
    942 
    943 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
    944   VisitExpr(S);
    945   VisitName(S->getSelector());
    946 }
    947 
    948 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
    949   VisitExpr(S);
    950   VisitDecl(S->getProtocol());
    951 }
    952 
    953 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
    954   VisitExpr(S);
    955   VisitDecl(S->getDecl());
    956   ID.AddBoolean(S->isArrow());
    957   ID.AddBoolean(S->isFreeIvar());
    958 }
    959 
    960 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
    961   VisitExpr(S);
    962   if (S->isImplicitProperty()) {
    963     VisitDecl(S->getImplicitPropertyGetter());
    964     VisitDecl(S->getImplicitPropertySetter());
    965   } else {
    966     VisitDecl(S->getExplicitProperty());
    967   }
    968   if (S->isSuperReceiver()) {
    969     ID.AddBoolean(S->isSuperReceiver());
    970     VisitType(S->getSuperReceiverType());
    971   }
    972 }
    973 
    974 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
    975   VisitExpr(S);
    976   VisitName(S->getSelector());
    977   VisitDecl(S->getMethodDecl());
    978 }
    979 
    980 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
    981   VisitExpr(S);
    982   ID.AddBoolean(S->isArrow());
    983 }
    984 
    985 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
    986     const ObjCIndirectCopyRestoreExpr *S) {
    987   VisitExpr(S);
    988   ID.AddBoolean(S->shouldCopy());
    989 }
    990 
    991 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
    992   VisitExplicitCastExpr(S);
    993   ID.AddBoolean(S->getBridgeKind());
    994 }
    995 
    996 void StmtProfiler::VisitDecl(const Decl *D) {
    997   ID.AddInteger(D? D->getKind() : 0);
    998 
    999   if (Canonical && D) {
   1000     if (const NonTypeTemplateParmDecl *NTTP =
   1001           dyn_cast<NonTypeTemplateParmDecl>(D)) {
   1002       ID.AddInteger(NTTP->getDepth());
   1003       ID.AddInteger(NTTP->getIndex());
   1004       ID.AddBoolean(NTTP->isParameterPack());
   1005       VisitType(NTTP->getType());
   1006       return;
   1007     }
   1008 
   1009     if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
   1010       // The Itanium C++ ABI uses the type, scope depth, and scope
   1011       // index of a parameter when mangling expressions that involve
   1012       // function parameters, so we will use the parameter's type for
   1013       // establishing function parameter identity. That way, our
   1014       // definition of "equivalent" (per C++ [temp.over.link]) is at
   1015       // least as strong as the definition of "equivalent" used for
   1016       // name mangling.
   1017       VisitType(Parm->getType());
   1018       ID.AddInteger(Parm->getFunctionScopeDepth());
   1019       ID.AddInteger(Parm->getFunctionScopeIndex());
   1020       return;
   1021     }
   1022 
   1023     if (const TemplateTemplateParmDecl *TTP =
   1024           dyn_cast<TemplateTemplateParmDecl>(D)) {
   1025       ID.AddInteger(TTP->getDepth());
   1026       ID.AddInteger(TTP->getIndex());
   1027       ID.AddBoolean(TTP->isParameterPack());
   1028       return;
   1029     }
   1030   }
   1031 
   1032   ID.AddPointer(D? D->getCanonicalDecl() : 0);
   1033 }
   1034 
   1035 void StmtProfiler::VisitType(QualType T) {
   1036   if (Canonical)
   1037     T = Context.getCanonicalType(T);
   1038 
   1039   ID.AddPointer(T.getAsOpaquePtr());
   1040 }
   1041 
   1042 void StmtProfiler::VisitName(DeclarationName Name) {
   1043   ID.AddPointer(Name.getAsOpaquePtr());
   1044 }
   1045 
   1046 void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
   1047   if (Canonical)
   1048     NNS = Context.getCanonicalNestedNameSpecifier(NNS);
   1049   ID.AddPointer(NNS);
   1050 }
   1051 
   1052 void StmtProfiler::VisitTemplateName(TemplateName Name) {
   1053   if (Canonical)
   1054     Name = Context.getCanonicalTemplateName(Name);
   1055 
   1056   Name.Profile(ID);
   1057 }
   1058 
   1059 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
   1060                                           unsigned NumArgs) {
   1061   ID.AddInteger(NumArgs);
   1062   for (unsigned I = 0; I != NumArgs; ++I)
   1063     VisitTemplateArgument(Args[I].getArgument());
   1064 }
   1065 
   1066 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
   1067   // Mostly repetitive with TemplateArgument::Profile!
   1068   ID.AddInteger(Arg.getKind());
   1069   switch (Arg.getKind()) {
   1070   case TemplateArgument::Null:
   1071     break;
   1072 
   1073   case TemplateArgument::Type:
   1074     VisitType(Arg.getAsType());
   1075     break;
   1076 
   1077   case TemplateArgument::Template:
   1078   case TemplateArgument::TemplateExpansion:
   1079     VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
   1080     break;
   1081 
   1082   case TemplateArgument::Declaration:
   1083     VisitDecl(Arg.getAsDecl());
   1084     break;
   1085 
   1086   case TemplateArgument::Integral:
   1087     Arg.getAsIntegral()->Profile(ID);
   1088     VisitType(Arg.getIntegralType());
   1089     break;
   1090 
   1091   case TemplateArgument::Expression:
   1092     Visit(Arg.getAsExpr());
   1093     break;
   1094 
   1095   case TemplateArgument::Pack:
   1096     const TemplateArgument *Pack = Arg.pack_begin();
   1097     for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
   1098       VisitTemplateArgument(Pack[i]);
   1099     break;
   1100   }
   1101 }
   1102 
   1103 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
   1104                    bool Canonical) const {
   1105   StmtProfiler Profiler(ID, Context, Canonical);
   1106   Profiler.Visit(this);
   1107 }
   1108