convert ***sort builtins to use inout instead of references
[hiphop-php.git] / hphp / runtime / ext / array / ext_array.h
blob859cba3b316971ecbad77ed478b592c627c7da63
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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 +----------------------------------------------------------------------+
18 #ifndef incl_HPHP_EXT_ARRAY_H_
19 #define incl_HPHP_EXT_ARRAY_H_
21 #include "hphp/runtime/ext/extension.h"
22 #include "hphp/runtime/base/array-util.h"
23 #include "hphp/runtime/base/zend-collator.h"
25 namespace HPHP {
27 ///////////////////////////////////////////////////////////////////////////////
29 TypedValue HHVM_FUNCTION(array_chunk,
30 const Variant& input,
31 int size,
32 bool preserve_keys = false);
33 TypedValue HHVM_FUNCTION(array_combine,
34 const Variant& keys,
35 const Variant& values);
36 TypedValue HHVM_FUNCTION(array_fill_keys,
37 const Variant& keys,
38 const Variant& value);
39 TypedValue HHVM_FUNCTION(array_fill,
40 int start_index,
41 int num,
42 const Variant& value);
43 TypedValue HHVM_FUNCTION(array_flip,
44 const Variant& trans);
45 bool HHVM_FUNCTION(array_key_exists,
46 const Variant& key,
47 const Variant& search);
48 bool HHVM_FUNCTION(key_exists,
49 const Variant& key,
50 const Variant& search);
51 TypedValue HHVM_FUNCTION(array_keys,
52 TypedValue input);
53 TypedValue HHVM_FUNCTION(array_map,
54 const Variant& callback,
55 const Variant& arr1,
56 const Array& _argv = null_array);
57 TypedValue HHVM_FUNCTION(array_replace_recursive,
58 const Variant& array1,
59 const Variant& array2 = uninit_variant,
60 const Array& args = null_array);
61 TypedValue HHVM_FUNCTION(array_replace,
62 const Variant& array1,
63 const Variant& array2 = uninit_variant,
64 const Array& args = null_array);
65 TypedValue HHVM_FUNCTION(array_pad,
66 const Variant& input,
67 int pad_size,
68 const Variant& pad_value);
69 TypedValue HHVM_FUNCTION(array_product,
70 const Variant& array);
71 TypedValue HHVM_FUNCTION(array_push,
72 VRefParam container,
73 const Variant& var,
74 const Array& args = null_array);
75 TypedValue HHVM_FUNCTION(array_rand,
76 const Variant& input,
77 int num_req = 1);
78 TypedValue HHVM_FUNCTION(array_search,
79 const Variant& needle,
80 const Variant& haystack,
81 bool strict = false);
82 TypedValue HHVM_FUNCTION(array_shift,
83 VRefParam array);
84 TypedValue HHVM_FUNCTION(array_splice,
85 VRefParam input,
86 int offset,
87 const Variant& length = uninit_variant,
88 const Variant& replacement = uninit_variant);
89 TypedValue HHVM_FUNCTION(array_sum,
90 const Variant& array);
91 TypedValue HHVM_FUNCTION(array_unique,
92 const Variant& array,
93 int sort_flags = 2);
94 TypedValue HHVM_FUNCTION(array_unshift,
95 VRefParam array,
96 const Variant& var,
97 const Array& args = null_array);
98 TypedValue HHVM_FUNCTION(array_values,
99 const Variant& input);
100 bool HHVM_FUNCTION(shuffle,
101 VRefParam array);
102 int64_t HHVM_FUNCTION(count,
103 const Variant& var,
104 int64_t mode = 0);
105 int64_t HHVM_FUNCTION(sizeof,
106 const Variant& var);
107 Variant HHVM_FUNCTION(each,
108 Variant& array);
109 Variant HHVM_FUNCTION(current,
110 const Variant& array);
111 Variant HHVM_FUNCTION(key,
112 const Variant& array);
113 Variant HHVM_FUNCTION(next,
114 Variant& array);
115 Variant HHVM_FUNCTION(prev,
116 Variant& array);
117 Variant HHVM_FUNCTION(reset,
118 Variant& array);
119 Variant HHVM_FUNCTION(end,
120 Variant& array);
121 bool HHVM_FUNCTION(in_array,
122 const Variant& needle,
123 const Variant& haystack,
124 bool strict = false);
125 TypedValue HHVM_FUNCTION(range,
126 const Variant& low,
127 const Variant& high,
128 const Variant& step = 1);
129 TypedValue HHVM_FUNCTION(array_diff,
130 const Variant& container1,
131 const Variant& container2,
132 const Array& args = null_array);
133 TypedValue HHVM_FUNCTION(array_diff_key,
134 const Variant& container1,
135 const Variant& container2,
136 const Array& args = null_array);
137 TypedValue HHVM_FUNCTION(array_udiff,
138 const Variant& array1,
139 const Variant& array2,
140 const Variant& data_compare_func,
141 const Array& args = null_array);
142 TypedValue HHVM_FUNCTION(array_diff_assoc,
143 const Variant& array1,
144 const Variant& array2,
145 const Array& args = null_array);
146 TypedValue HHVM_FUNCTION(array_diff_uassoc,
147 const Variant& array1,
148 const Variant& array2,
149 const Variant& key_compare_func,
150 const Array& args = null_array);
151 TypedValue HHVM_FUNCTION(array_udiff_assoc,
152 const Variant& array1,
153 const Variant& array2,
154 const Variant& data_compare_func,
155 const Array& args = null_array);
156 TypedValue HHVM_FUNCTION(array_udiff_uassoc,
157 const Variant& array1,
158 const Variant& array2,
159 const Variant& data_compare_func,
160 const Variant& key_compare_func,
161 const Array& args = null_array);
162 TypedValue HHVM_FUNCTION(array_diff_ukey,
163 const Variant& array1,
164 const Variant& array2,
165 const Variant& key_compare_func,
166 const Array& args = null_array);
167 TypedValue HHVM_FUNCTION(array_intersect,
168 const Variant& container1,
169 const Variant& container2,
170 const Array& args = null_array);
171 TypedValue HHVM_FUNCTION(array_intersect_key,
172 const Variant& container1,
173 const Variant& container2,
174 const Array& args = null_array);
175 TypedValue HHVM_FUNCTION(array_uintersect,
176 const Variant& array1,
177 const Variant& array2,
178 const Variant& data_compare_func,
179 const Array& args = null_array);
180 TypedValue HHVM_FUNCTION(array_intersect_assoc,
181 const Variant& array1,
182 const Variant& array2,
183 const Array& args = null_array);
184 TypedValue HHVM_FUNCTION(array_intersect_uassoc,
185 const Variant& array1,
186 const Variant& array2,
187 const Variant& key_compare_func,
188 const Array& args = null_array);
189 TypedValue HHVM_FUNCTION(array_uintersect_assoc,
190 const Variant& array1,
191 const Variant& array2,
192 const Variant& data_compare_func,
193 const Array& args = null_array);
194 TypedValue HHVM_FUNCTION(array_uintersect_uassoc,
195 const Variant& array1,
196 const Variant& array2,
197 const Variant& data_compare_func,
198 const Variant& key_compare_func,
199 const Array& args = null_array);
200 TypedValue HHVM_FUNCTION(array_intersect_ukey,
201 const Variant& array1,
202 const Variant& array2,
203 const Variant& key_compare_func,
204 const Array& args = null_array);
205 bool HHVM_FUNCTION(sort,
206 Variant& array,
207 int sort_flags = 0);
208 bool HHVM_FUNCTION(rsort,
209 Variant& array,
210 int sort_flags = 0);
211 bool HHVM_FUNCTION(asort,
212 Variant& array,
213 int sort_flags = 0);
214 bool HHVM_FUNCTION(arsort,
215 Variant& array,
216 int sort_flags = 0);
217 bool HHVM_FUNCTION(ksort,
218 Variant& array,
219 int sort_flags = 0);
220 bool HHVM_FUNCTION(krsort,
221 Variant& array,
222 int sort_flags = 0);
223 bool HHVM_FUNCTION(usort,
224 Variant& array,
225 const Variant& cmp_function);
226 bool HHVM_FUNCTION(uasort,
227 Variant& array,
228 const Variant& cmp_function);
229 bool HHVM_FUNCTION(uksort,
230 Variant& array,
231 const Variant& cmp_function);
232 bool HHVM_FUNCTION(natsort,
233 Variant& array);
234 bool HHVM_FUNCTION(natcasesort,
235 Variant& array);
236 String HHVM_FUNCTION(i18n_loc_get_default);
237 bool HHVM_FUNCTION(i18n_loc_set_default,
238 const String& locale);
239 bool HHVM_FUNCTION(i18n_loc_set_attribute,
240 int64_t attr,
241 int64_t val);
242 bool HHVM_FUNCTION(i18n_loc_set_strength,
243 int64_t strength);
244 Variant HHVM_FUNCTION(i18n_loc_get_error_code);
245 TypedValue HHVM_FUNCTION(hphp_array_idx,
246 const Variant& search,
247 const Variant& key,
248 const Variant& def);
250 ///////////////////////////////////////////////////////////////////////////////
252 inline int64_t countHelper(TypedValue tv) {
253 return HHVM_FN(count)(tvAsVariant(&tv));
256 ///////////////////////////////////////////////////////////////////////////////
258 #define getCheckedArrayRet(input, fail) \
259 auto const cell_##input = static_cast<const Variant&>(input).toCell(); \
260 if (UNLIKELY(!isArrayLikeType(cell_##input->m_type) && \
261 !isClsMethType(cell_##input->m_type))) { \
262 throw_expected_array_exception(); \
263 return fail; \
265 if (isClsMethType(cell_##input->m_type)) raiseClsMethToVecWarningHelper(); \
266 ArrNR arrNR_##input{isClsMethType(cell_##input->m_type) ? \
267 clsMethToVecHelper(cell_##input->m_data.pclsmeth).detach() : \
268 cell_##input->m_data.parr}; \
269 const Array& arr_##input = arrNR_##input.asArray();
271 #define getCheckedContainer(input) \
272 if (UNLIKELY(!isContainer(input) && !input.isClsMeth())) { \
273 throw_expected_array_or_collection_exception(); \
274 return make_tv<KindOfNull>(); \
276 Variant var_##input(input); \
277 tvCastToArrayInPlace<TypedValue*, IntishCast::Cast>( \
278 var_##input.asTypedValue() \
279 ); \
280 assertx(var_##input.isArray()); \
281 auto arr_##input = var_##input.toArray<IntishCast::Cast>();
283 #define getCheckedArray(input) \
284 getCheckedArrayRet(input, make_tv<KindOfNull>())
285 #define getCheckedArrayVariant(input) \
286 getCheckedArrayRet(input, init_null())
290 #endif // incl_HPHP_EXT_ARRAY_H_