StmtDataCollectors.td 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. class Stmt {
  2. code Code = [{
  3. addData(S->getStmtClass());
  4. // This ensures that non-macro-generated code isn't identical to
  5. // macro-generated code.
  6. addData(data_collection::getMacroStack(S->getBeginLoc(), Context));
  7. addData(data_collection::getMacroStack(S->getEndLoc(), Context));
  8. }];
  9. }
  10. class Expr {
  11. code Code = [{
  12. addData(S->getType());
  13. }];
  14. }
  15. //--- Builtin functionality ----------------------------------------------//
  16. class ArrayTypeTraitExpr {
  17. code Code = [{
  18. addData(S->getTrait());
  19. }];
  20. }
  21. class ExpressionTraitExpr {
  22. code Code = [{
  23. addData(S->getTrait());
  24. }];
  25. }
  26. class PredefinedExpr {
  27. code Code = [{
  28. addData(S->getIdentKind());
  29. }];
  30. }
  31. class TypeTraitExpr {
  32. code Code = [{
  33. addData(S->getTrait());
  34. for (unsigned i = 0; i < S->getNumArgs(); ++i)
  35. addData(S->getArg(i)->getType());
  36. }];
  37. }
  38. //--- Calls --------------------------------------------------------------//
  39. class CallExpr {
  40. code Code = [{
  41. // Function pointers don't have a callee and we just skip hashing it.
  42. if (const FunctionDecl *D = S->getDirectCallee()) {
  43. // If the function is a template specialization, we also need to handle
  44. // the template arguments as they are not included in the qualified name.
  45. if (auto Args = D->getTemplateSpecializationArgs()) {
  46. std::string ArgString;
  47. // Print all template arguments into ArgString
  48. llvm::raw_string_ostream OS(ArgString);
  49. for (unsigned i = 0; i < Args->size(); ++i) {
  50. Args->get(i).print(Context.getLangOpts(), OS, /*IncludeType*/ true);
  51. // Add a padding character so that 'foo<X, XX>()' != 'foo<XX, X>()'.
  52. OS << '\n';
  53. }
  54. OS.flush();
  55. addData(ArgString);
  56. }
  57. addData(D->getQualifiedNameAsString());
  58. }
  59. }];
  60. }
  61. //--- Value references ---------------------------------------------------//
  62. class DeclRefExpr {
  63. code Code = [{
  64. addData(S->getDecl()->getQualifiedNameAsString());
  65. }];
  66. }
  67. class MemberExpr {
  68. code Code = [{
  69. addData(S->getMemberDecl()->getName());
  70. }];
  71. }
  72. //--- Literals -----------------------------------------------------------//
  73. class IntegerLiteral {
  74. code Code = [{
  75. addData(llvm::hash_value(S->getValue()));
  76. }];
  77. }
  78. class FloatingLiteral {
  79. code Code = [{
  80. addData(llvm::hash_value(S->getValue()));
  81. }];
  82. }
  83. class StringLiteral {
  84. code Code = [{
  85. addData(S->getString());
  86. }];
  87. }
  88. class CXXBoolLiteralExpr {
  89. code Code = [{
  90. addData(S->getValue());
  91. }];
  92. }
  93. class CharacterLiteral {
  94. code Code = [{
  95. addData(S->getValue());
  96. }];
  97. }
  98. //--- Exceptions ---------------------------------------------------------//
  99. class CXXCatchStmt {
  100. code Code = [{
  101. addData(S->getCaughtType());
  102. }];
  103. }
  104. //--- C++ OOP Stmts ------------------------------------------------------//
  105. class CXXDeleteExpr {
  106. code Code = [{
  107. addData(S->isArrayFormAsWritten()); addData(S->isGlobalDelete());
  108. }];
  109. }
  110. //--- Casts --------------------------------------------------------------//
  111. class ObjCBridgedCastExpr {
  112. code Code = [{
  113. addData(S->getBridgeKind());
  114. }];
  115. }
  116. //--- Miscellaneous Exprs ------------------------------------------------//
  117. class BinaryOperator {
  118. code Code = [{
  119. addData(S->getOpcode());
  120. }];
  121. }
  122. class UnaryOperator {
  123. code Code = [{
  124. addData(S->getOpcode());
  125. }];
  126. }
  127. //--- Control flow -------------------------------------------------------//
  128. class GotoStmt {
  129. code Code = [{
  130. addData(S->getLabel()->getName());
  131. }];
  132. }
  133. class IndirectGotoStmt {
  134. code Code = [{
  135. if (S->getConstantTarget())
  136. addData(S->getConstantTarget()->getName());
  137. }];
  138. }
  139. class LabelStmt {
  140. code Code = [{
  141. addData(S->getDecl()->getName());
  142. }];
  143. }
  144. class MSDependentExistsStmt {
  145. code Code = [{
  146. addData(S->isIfExists());
  147. }];
  148. }
  149. class AddrLabelExpr {
  150. code Code = [{
  151. addData(S->getLabel()->getName());
  152. }];
  153. }
  154. //--- Objective-C --------------------------------------------------------//
  155. class ObjCIndirectCopyRestoreExpr {
  156. code Code = [{
  157. addData(S->shouldCopy());
  158. }];
  159. }
  160. class ObjCPropertyRefExpr {
  161. code Code = [{
  162. addData(S->isSuperReceiver()); addData(S->isImplicitProperty());
  163. }];
  164. }
  165. class ObjCAtCatchStmt {
  166. code Code = [{
  167. addData(S->hasEllipsis());
  168. }];
  169. }
  170. //--- Miscellaneous Stmts ------------------------------------------------//
  171. class CXXFoldExpr {
  172. code Code = [{
  173. addData(S->isRightFold()); addData(S->getOperator());
  174. }];
  175. }
  176. class GenericSelectionExpr {
  177. code Code = [{
  178. for (const GenericSelectionExpr::ConstAssociation Assoc : S->associations()) {
  179. addData(Assoc.getType());
  180. }
  181. }];
  182. }
  183. class LambdaExpr {
  184. code Code = [{
  185. for (const LambdaCapture &C : S->captures()) {
  186. addData(C.isPackExpansion());
  187. addData(C.getCaptureKind());
  188. if (C.capturesVariable())
  189. addData(C.getCapturedVar()->getType());
  190. }
  191. addData(S->isGenericLambda());
  192. addData(S->isMutable());
  193. }];
  194. }
  195. class DeclStmt {
  196. code Code = [{
  197. auto numDecls = std::distance(S->decl_begin(), S->decl_end());
  198. addData(static_cast<unsigned>(numDecls));
  199. for (const Decl *D : S->decls()) {
  200. if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
  201. addData(VD->getType());
  202. }
  203. }
  204. }];
  205. }
  206. class AsmStmt {
  207. code Code = [{
  208. addData(S->isSimple());
  209. addData(S->isVolatile());
  210. addData(S->generateAsmString(Context));
  211. for (unsigned i = 0; i < S->getNumInputs(); ++i) {
  212. addData(S->getInputConstraint(i));
  213. }
  214. for (unsigned i = 0; i < S->getNumOutputs(); ++i) {
  215. addData(S->getOutputConstraint(i));
  216. }
  217. for (unsigned i = 0; i < S->getNumClobbers(); ++i) {
  218. addData(S->getClobber(i));
  219. }
  220. }];
  221. }
  222. class AttributedStmt {
  223. code Code = [{
  224. for (const Attr *A : S->getAttrs()) {
  225. addData(std::string(A->getSpelling()));
  226. }
  227. }];
  228. }