PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/ext/array/ext_array.h

https://gitlab.com/iranjith4/hhvm
C Header | 318 lines | 284 code | 14 blank | 20 comment | 10 complexity | 812aa6a52e9b0aa19077893e96e69b2f MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | HipHop for PHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2010-2016 Facebook, Inc. (http://www.facebook.com) |
  6. | Copyright (c) 1997-2010 The PHP Group |
  7. +----------------------------------------------------------------------+
  8. | This source file is subject to version 3.01 of the PHP license, |
  9. | that is bundled with this package in the file LICENSE, and is |
  10. | available through the world-wide-web at the following url: |
  11. | http://www.php.net/license/3_01.txt |
  12. | If you did not receive a copy of the PHP license and are unable to |
  13. | obtain it through the world-wide-web, please send a note to |
  14. | license@php.net so we can mail you a copy immediately. |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifndef incl_HPHP_EXT_ARRAY_H_
  18. #define incl_HPHP_EXT_ARRAY_H_
  19. #include "hphp/runtime/ext/extension.h"
  20. #include "hphp/runtime/base/array-util.h"
  21. #include "hphp/runtime/base/zend-collator.h"
  22. namespace HPHP {
  23. ///////////////////////////////////////////////////////////////////////////////
  24. TypedValue HHVM_FUNCTION(array_chunk,
  25. const Variant& input,
  26. int size,
  27. bool preserve_keys = false);
  28. TypedValue HHVM_FUNCTION(array_combine,
  29. const Variant& keys,
  30. const Variant& values);
  31. TypedValue HHVM_FUNCTION(array_fill_keys,
  32. const Variant& keys,
  33. const Variant& value);
  34. TypedValue HHVM_FUNCTION(array_fill,
  35. int start_index,
  36. int num,
  37. const Variant& value);
  38. TypedValue HHVM_FUNCTION(array_flip,
  39. const Variant& trans);
  40. bool HHVM_FUNCTION(array_key_exists,
  41. const Variant& key,
  42. const Variant& search);
  43. bool HHVM_FUNCTION(key_exists,
  44. const Variant& key,
  45. const Variant& search);
  46. Variant array_keys_helper(const Variant& input,
  47. const Variant& search_value = null_variant,
  48. bool strict = false);
  49. TypedValue HHVM_FUNCTION(array_map,
  50. const Variant& callback,
  51. const Variant& arr1,
  52. const Array& _argv = null_array);
  53. TypedValue HHVM_FUNCTION(array_merge_recursive,
  54. int64_t numArgs,
  55. const Variant& array1,
  56. const Variant& array2 = null_variant,
  57. const Array& args = null_array);
  58. TypedValue HHVM_FUNCTION(array_replace_recursive,
  59. const Variant& array1,
  60. const Variant& array2 = null_variant,
  61. const Array& args = null_array);
  62. TypedValue HHVM_FUNCTION(array_replace,
  63. const Variant& array1,
  64. const Variant& array2 = null_variant,
  65. const Array& args = null_array);
  66. TypedValue HHVM_FUNCTION(array_pad,
  67. const Variant& input,
  68. int pad_size,
  69. const Variant& pad_value);
  70. TypedValue HHVM_FUNCTION(array_product,
  71. const Variant& array);
  72. TypedValue HHVM_FUNCTION(array_push,
  73. VRefParam container,
  74. const Variant& var,
  75. const Array& args = null_array);
  76. TypedValue HHVM_FUNCTION(array_rand,
  77. const Variant& input,
  78. int num_req = 1);
  79. TypedValue HHVM_FUNCTION(array_search,
  80. const Variant& needle,
  81. const Variant& haystack,
  82. bool strict = false);
  83. TypedValue HHVM_FUNCTION(array_shift,
  84. VRefParam array);
  85. TypedValue HHVM_FUNCTION(array_splice,
  86. VRefParam input,
  87. int offset,
  88. const Variant& length = null_variant,
  89. const Variant& replacement = null_variant);
  90. TypedValue HHVM_FUNCTION(array_sum,
  91. const Variant& array);
  92. TypedValue HHVM_FUNCTION(array_unique,
  93. const Variant& array,
  94. int sort_flags = 2);
  95. TypedValue HHVM_FUNCTION(array_unshift,
  96. VRefParam array,
  97. const Variant& var,
  98. const Array& args = null_array);
  99. TypedValue HHVM_FUNCTION(array_values,
  100. const Variant& input);
  101. bool HHVM_FUNCTION(array_walk_recursive,
  102. VRefParam input,
  103. const Variant& funcname,
  104. const Variant& userdata = null_variant);
  105. bool HHVM_FUNCTION(array_walk,
  106. VRefParam input,
  107. const Variant& funcname,
  108. const Variant& userdata = null_variant);
  109. Array HHVM_FUNCTION(compact,
  110. const Variant& varname,
  111. const Array& args = null_array);
  112. // __SystemLib\\compact_sl
  113. Array HHVM_FUNCTION(__SystemLib_compact_sl,
  114. const Variant& varname,
  115. const Array& args = null_array);
  116. bool HHVM_FUNCTION(shuffle,
  117. VRefParam array);
  118. int64_t HHVM_FUNCTION(count,
  119. const Variant& var,
  120. int64_t mode = 0);
  121. int64_t HHVM_FUNCTION(sizeof,
  122. const Variant& var,
  123. int64_t mode = 0);
  124. Variant HHVM_FUNCTION(each,
  125. VRefParam array);
  126. Variant HHVM_FUNCTION(current,
  127. VRefParam array);
  128. Variant HHVM_FUNCTION(pos,
  129. VRefParam array);
  130. Variant HHVM_FUNCTION(key,
  131. VRefParam array);
  132. Variant HHVM_FUNCTION(next,
  133. VRefParam array);
  134. Variant HHVM_FUNCTION(prev,
  135. VRefParam array);
  136. Variant HHVM_FUNCTION(reset,
  137. VRefParam array);
  138. Variant HHVM_FUNCTION(end,
  139. VRefParam array);
  140. bool HHVM_FUNCTION(in_array,
  141. const Variant& needle,
  142. const Variant& haystack,
  143. bool strict = false);
  144. TypedValue HHVM_FUNCTION(range,
  145. const Variant& low,
  146. const Variant& high,
  147. const Variant& step = 1);
  148. TypedValue HHVM_FUNCTION(array_diff,
  149. const Variant& container1,
  150. const Variant& container2,
  151. const Array& args = null_array);
  152. TypedValue HHVM_FUNCTION(array_diff_key,
  153. const Variant& container1,
  154. const Variant& container2,
  155. const Array& args = null_array);
  156. TypedValue HHVM_FUNCTION(array_udiff,
  157. const Variant& array1,
  158. const Variant& array2,
  159. const Variant& data_compare_func,
  160. const Array& args = null_array);
  161. TypedValue HHVM_FUNCTION(array_diff_assoc,
  162. const Variant& array1,
  163. const Variant& array2,
  164. const Array& args = null_array);
  165. TypedValue HHVM_FUNCTION(array_diff_uassoc,
  166. const Variant& array1,
  167. const Variant& array2,
  168. const Variant& key_compare_func,
  169. const Array& args = null_array);
  170. TypedValue HHVM_FUNCTION(array_udiff_assoc,
  171. const Variant& array1,
  172. const Variant& array2,
  173. const Variant& data_compare_func,
  174. const Array& args = null_array);
  175. TypedValue HHVM_FUNCTION(array_udiff_uassoc,
  176. const Variant& array1,
  177. const Variant& array2,
  178. const Variant& data_compare_func,
  179. const Variant& key_compare_func,
  180. const Array& args = null_array);
  181. TypedValue HHVM_FUNCTION(array_diff_ukey,
  182. const Variant& array1,
  183. const Variant& array2,
  184. const Variant& key_compare_func,
  185. const Array& args = null_array);
  186. TypedValue HHVM_FUNCTION(array_intersect,
  187. const Variant& container1,
  188. const Variant& container2,
  189. const Array& args = null_array);
  190. TypedValue HHVM_FUNCTION(array_intersect_key,
  191. const Variant& container1,
  192. const Variant& container2,
  193. const Array& args = null_array);
  194. TypedValue HHVM_FUNCTION(array_uintersect,
  195. const Variant& array1,
  196. const Variant& array2,
  197. const Variant& data_compare_func,
  198. const Array& args = null_array);
  199. TypedValue HHVM_FUNCTION(array_intersect_assoc,
  200. const Variant& array1,
  201. const Variant& array2,
  202. const Array& args = null_array);
  203. TypedValue HHVM_FUNCTION(array_intersect_uassoc,
  204. const Variant& array1,
  205. const Variant& array2,
  206. const Variant& key_compare_func,
  207. const Array& args = null_array);
  208. TypedValue HHVM_FUNCTION(array_uintersect_assoc,
  209. const Variant& array1,
  210. const Variant& array2,
  211. const Variant& data_compare_func,
  212. const Array& args = null_array);
  213. TypedValue HHVM_FUNCTION(array_uintersect_uassoc,
  214. const Variant& array1,
  215. const Variant& array2,
  216. const Variant& data_compare_func,
  217. const Variant& key_compare_func,
  218. const Array& args = null_array);
  219. TypedValue HHVM_FUNCTION(array_intersect_ukey,
  220. const Variant& array1,
  221. const Variant& array2,
  222. const Variant& key_compare_func,
  223. const Array& args = null_array);
  224. bool HHVM_FUNCTION(sort,
  225. VRefParam array,
  226. int sort_flags = 0);
  227. bool HHVM_FUNCTION(rsort,
  228. VRefParam array,
  229. int sort_flags = 0);
  230. bool HHVM_FUNCTION(asort,
  231. VRefParam array,
  232. int sort_flags = 0);
  233. bool HHVM_FUNCTION(arsort,
  234. VRefParam array,
  235. int sort_flags = 0);
  236. bool HHVM_FUNCTION(ksort,
  237. VRefParam array,
  238. int sort_flags = 0);
  239. bool HHVM_FUNCTION(krsort,
  240. VRefParam array,
  241. int sort_flags = 0);
  242. bool HHVM_FUNCTION(usort,
  243. VRefParam array,
  244. const Variant& cmp_function);
  245. bool HHVM_FUNCTION(uasort,
  246. VRefParam array,
  247. const Variant& cmp_function);
  248. bool HHVM_FUNCTION(uksort,
  249. VRefParam array,
  250. const Variant& cmp_function);
  251. bool HHVM_FUNCTION(natsort,
  252. VRefParam array);
  253. bool HHVM_FUNCTION(natcasesort,
  254. VRefParam array);
  255. String HHVM_FUNCTION(i18n_loc_get_default);
  256. bool HHVM_FUNCTION(i18n_loc_set_default,
  257. const String& locale);
  258. bool HHVM_FUNCTION(i18n_loc_set_attribute,
  259. int64_t attr,
  260. int64_t val);
  261. bool HHVM_FUNCTION(i18n_loc_set_strength,
  262. int64_t strength);
  263. Variant HHVM_FUNCTION(i18n_loc_get_error_code);
  264. TypedValue HHVM_FUNCTION(hphp_array_idx,
  265. const Variant& search,
  266. const Variant& key,
  267. const Variant& def);
  268. TypedValue* HHVM_FN(array_multisort)(ActRec* ar);
  269. ///////////////////////////////////////////////////////////////////////////////
  270. inline int64_t countHelper(TypedValue tv) {
  271. return HHVM_FN(count)(tvAsVariant(&tv));
  272. }
  273. ///////////////////////////////////////////////////////////////////////////////
  274. #define getCheckedArrayRet(input, fail) \
  275. auto const cell_##input = static_cast<const Variant&>(input).asCell(); \
  276. if (UNLIKELY(!isArrayType(cell_##input->m_type))) { \
  277. throw_expected_array_exception(); \
  278. return fail; \
  279. } \
  280. ArrNR arrNR_##input(cell_##input->m_data.parr); \
  281. const Array& arr_##input = arrNR_##input.asArray();
  282. #define getCheckedArrayColumnRet(input, fail) \
  283. auto const cell_##input = static_cast<const Variant&>(input).asCell(); \
  284. if (UNLIKELY(!isArrayType(cell_##input->m_type))) { \
  285. if (cell_##input->m_type == KindOfString || \
  286. cell_##input->m_type == KindOfPersistentString) { \
  287. throw_bad_type_exception("array_column() expects parameter" \
  288. " 1 to be array, string given"); \
  289. } else if (cell_##input->m_type == KindOfInt64) { \
  290. throw_bad_type_exception("array_column() expects parameter" \
  291. " 1 to be array, integer given"); \
  292. } else { \
  293. throw_expected_array_exception(); \
  294. } \
  295. return fail; \
  296. } \
  297. ArrNR arrNR_##input(cell_##input->m_data.parr); \
  298. Array arr_##input = arrNR_##input.asArray();
  299. #define getCheckedArray(input) \
  300. getCheckedArrayRet(input, make_tv<KindOfNull>())
  301. #define getCheckedArrayVariant(input) \
  302. getCheckedArrayRet(input, init_null())
  303. }
  304. #endif // incl_HPHP_EXT_ARRAY_H_