GULOriginalIMPConvenienceMacros.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright 2018 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * GULOriginalIMPConvenienceMacros.h
  18. *
  19. * This header contains convenience macros for invoking the original IMP of a swizzled method.
  20. */
  21. /**
  22. * Invokes original IMP when the original selector takes no arguments.
  23. *
  24. * @param __receivingObject The object on which the IMP is invoked.
  25. * @param __swizzledSEL The selector used for swizzling.
  26. * @param __returnType The return type of the original implementation.
  27. * @param __originalIMP The original IMP.
  28. */
  29. #define GUL_INVOKE_ORIGINAL_IMP0(__receivingObject, __swizzledSEL, __returnType, __originalIMP) \
  30. ((__returnType(*)(id, SEL))__originalIMP)(__receivingObject, __swizzledSEL)
  31. /**
  32. * Invokes original IMP when the original selector takes 1 argument.
  33. *
  34. * @param __receivingObject The object on which the IMP is invoked.
  35. * @param __swizzledSEL The selector used for swizzling.
  36. * @param __returnType The return type of the original implementation.
  37. * @param __originalIMP The original IMP.
  38. * @param __arg1 The first argument.
  39. */
  40. #define GUL_INVOKE_ORIGINAL_IMP1(__receivingObject, __swizzledSEL, __returnType, __originalIMP, \
  41. __arg1) \
  42. ((__returnType(*)(id, SEL, __typeof__(__arg1)))__originalIMP)(__receivingObject, __swizzledSEL, \
  43. __arg1)
  44. /**
  45. * Invokes original IMP when the original selector takes 2 arguments.
  46. *
  47. * @param __receivingObject The object on which the IMP is invoked.
  48. * @param __swizzledSEL The selector used for swizzling.
  49. * @param __returnType The return type of the original implementation.
  50. * @param __originalIMP The original IMP.
  51. * @param __arg1 The first argument.
  52. * @param __arg2 The second argument.
  53. */
  54. #define GUL_INVOKE_ORIGINAL_IMP2(__receivingObject, __swizzledSEL, __returnType, __originalIMP, \
  55. __arg1, __arg2) \
  56. ((__returnType(*)(id, SEL, __typeof__(__arg1), __typeof__(__arg2)))__originalIMP)( \
  57. __receivingObject, __swizzledSEL, __arg1, __arg2)
  58. /**
  59. * Invokes original IMP when the original selector takes 3 arguments.
  60. *
  61. * @param __receivingObject The object on which the IMP is invoked.
  62. * @param __swizzledSEL The selector used for swizzling.
  63. * @param __returnType The return type of the original implementation.
  64. * @param __originalIMP The original IMP.
  65. * @param __arg1 The first argument.
  66. * @param __arg2 The second argument.
  67. * @param __arg3 The third argument.
  68. */
  69. #define GUL_INVOKE_ORIGINAL_IMP3(__receivingObject, __swizzledSEL, __returnType, __originalIMP, \
  70. __arg1, __arg2, __arg3) \
  71. ((__returnType(*)(id, SEL, __typeof__(__arg1), __typeof__(__arg2), \
  72. __typeof__(__arg3)))__originalIMP)(__receivingObject, __swizzledSEL, __arg1, \
  73. __arg2, __arg3)
  74. /**
  75. * Invokes original IMP when the original selector takes 4 arguments.
  76. *
  77. * @param __receivingObject The object on which the IMP is invoked.
  78. * @param __swizzledSEL The selector used for swizzling.
  79. * @param __returnType The return type of the original implementation.
  80. * @param __originalIMP The original IMP.
  81. * @param __arg1 The first argument.
  82. * @param __arg2 The second argument.
  83. * @param __arg3 The third argument.
  84. * @param __arg4 The fourth argument.
  85. */
  86. #define GUL_INVOKE_ORIGINAL_IMP4(__receivingObject, __swizzledSEL, __returnType, __originalIMP, \
  87. __arg1, __arg2, __arg3, __arg4) \
  88. ((__returnType(*)(id, SEL, __typeof__(__arg1), __typeof__(__arg2), __typeof__(__arg3), \
  89. __typeof__(__arg4)))__originalIMP)(__receivingObject, __swizzledSEL, __arg1, \
  90. __arg2, __arg3, __arg4)
  91. /**
  92. * Invokes original IMP when the original selector takes 5 arguments.
  93. *
  94. * @param __receivingObject The object on which the IMP is invoked.
  95. * @param __swizzledSEL The selector used for swizzling.
  96. * @param __returnType The return type of the original implementation.
  97. * @param __originalIMP The original IMP.
  98. * @param __arg1 The first argument.
  99. * @param __arg2 The second argument.
  100. * @param __arg3 The third argument.
  101. * @param __arg4 The fourth argument.
  102. * @param __arg5 The fifth argument.
  103. */
  104. #define GUL_INVOKE_ORIGINAL_IMP5(__receivingObject, __swizzledSEL, __returnType, __originalIMP, \
  105. __arg1, __arg2, __arg3, __arg4, __arg5) \
  106. ((__returnType(*)(id, SEL, __typeof__(__arg1), __typeof__(__arg2), __typeof__(__arg3), \
  107. __typeof__(__arg4), __typeof__(__arg5)))__originalIMP)( \
  108. __receivingObject, __swizzledSEL, __arg1, __arg2, __arg3, __arg4, __arg5)
  109. /**
  110. * Invokes original IMP when the original selector takes 6 arguments.
  111. *
  112. * @param __receivingObject The object on which the IMP is invoked.
  113. * @param __swizzledSEL The selector used for swizzling.
  114. * @param __returnType The return type of the original implementation.
  115. * @param __originalIMP The original IMP.
  116. * @param __arg1 The first argument.
  117. * @param __arg2 The second argument.
  118. * @param __arg3 The third argument.
  119. * @param __arg4 The fourth argument.
  120. * @param __arg5 The fifth argument.
  121. * @param __arg6 The sixth argument.
  122. */
  123. #define GUL_INVOKE_ORIGINAL_IMP6(__receivingObject, __swizzledSEL, __returnType, __originalIMP, \
  124. __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
  125. ((__returnType(*)(id, SEL, __typeof__(__arg1), __typeof__(__arg2), __typeof__(__arg3), \
  126. __typeof__(__arg4), __typeof__(__arg5), __typeof__(__arg6)))__originalIMP)( \
  127. __receivingObject, __swizzledSEL, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6)
  128. /**
  129. * Invokes original IMP when the original selector takes 7 arguments.
  130. *
  131. * @param __receivingObject The object on which the IMP is invoked.
  132. * @param __swizzledSEL The selector used for swizzling.
  133. * @param __returnType The return type of the original implementation.
  134. * @param __originalIMP The original IMP.
  135. * @param __arg1 The first argument.
  136. * @param __arg2 The second argument.
  137. * @param __arg3 The third argument.
  138. * @param __arg4 The fourth argument.
  139. * @param __arg5 The fifth argument.
  140. * @param __arg6 The sixth argument.
  141. * @param __arg7 The seventh argument.
  142. */
  143. #define GUL_INVOKE_ORIGINAL_IMP7(__receivingObject, __swizzledSEL, __returnType, __originalIMP, \
  144. __arg1, __arg2, __arg3, __arg4, __arg5, __arg6, __arg7) \
  145. ((__returnType(*)(id, SEL, __typeof__(__arg1), __typeof__(__arg2), __typeof__(__arg3), \
  146. __typeof__(__arg4), __typeof__(__arg5), __typeof__(__arg6), \
  147. __typeof__(__arg7)))__originalIMP)( \
  148. __receivingObject, __swizzledSEL, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6, __arg7)
  149. /**
  150. * Invokes original IMP when the original selector takes 8 arguments.
  151. *
  152. * @param __receivingObject The object on which the IMP is invoked.
  153. * @param __swizzledSEL The selector used for swizzling.
  154. * @param __returnType The return type of the original implementation.
  155. * @param __originalIMP The original IMP.
  156. * @param __arg1 The first argument.
  157. * @param __arg2 The second argument.
  158. * @param __arg3 The third argument.
  159. * @param __arg4 The fourth argument.
  160. * @param __arg5 The fifth argument.
  161. * @param __arg6 The sixth argument.
  162. * @param __arg7 The seventh argument.
  163. * @param __arg8 The eighth argument.
  164. */
  165. #define GUL_INVOKE_ORIGINAL_IMP8(__receivingObject, __swizzledSEL, __returnType, __originalIMP, \
  166. __arg1, __arg2, __arg3, __arg4, __arg5, __arg6, __arg7, __arg8) \
  167. ((__returnType(*)(id, SEL, __typeof__(__arg1), __typeof__(__arg2), __typeof__(__arg3), \
  168. __typeof__(__arg4), __typeof__(__arg5), __typeof__(__arg6), \
  169. __typeof__(__arg7), __typeof__(__arg8)))__originalIMP)( \
  170. __receivingObject, __swizzledSEL, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6, __arg7, \
  171. __arg8)
  172. /**
  173. * Invokes original IMP when the original selector takes 9 arguments.
  174. *
  175. * @param __receivingObject The object on which the IMP is invoked.
  176. * @param __swizzledSEL The selector used for swizzling.
  177. * @param __returnType The return type of the original implementation.
  178. * @param __originalIMP The original IMP.
  179. * @param __arg1 The first argument.
  180. * @param __arg2 The second argument.
  181. * @param __arg3 The third argument.
  182. * @param __arg4 The fourth argument.
  183. * @param __arg5 The fifth argument.
  184. * @param __arg6 The sixth argument.
  185. * @param __arg7 The seventh argument.
  186. * @param __arg8 The eighth argument.
  187. * @param __arg9 The ninth argument.
  188. */
  189. #define GUL_INVOKE_ORIGINAL_IMP9(__receivingObject, __swizzledSEL, __returnType, __originalIMP, \
  190. __arg1, __arg2, __arg3, __arg4, __arg5, __arg6, __arg7, __arg8, \
  191. __arg9) \
  192. ((__returnType(*)(id, SEL, __typeof__(__arg1), __typeof__(__arg2), __typeof__(__arg3), \
  193. __typeof__(__arg4), __typeof__(__arg5), __typeof__(__arg6), \
  194. __typeof__(__arg7), __typeof__(__arg8), __typeof__(__arg9)))__originalIMP)( \
  195. __receivingObject, __swizzledSEL, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6, __arg7, \
  196. __arg8, __arg9)