Add sub-controls for Hack array compat runtime checks
[hiphop-php.git] / hphp / runtime / base / array-helpers.h
blob819734f84888b17fc8ef7144ecc115512add35fa
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_ARRAY_HELPERS_H_
18 #define incl_HPHP_ARRAY_HELPERS_H_
20 #include "hphp/runtime/base/datatype.h"
21 #include "hphp/runtime/base/tv-mutate.h"
22 #include "hphp/runtime/base/typed-value.h"
24 namespace HPHP {
26 ///////////////////////////////////////////////////////////////////////////////
29 * Initialize a new array element.
31 ALWAYS_INLINE void initElem(TypedValue& elem, Cell v) {
32 cellDup(v, elem);
33 if (UNLIKELY(elem.m_type == KindOfUninit)) {
34 elem.m_type = KindOfNull;
39 * Modify an array element, with semantics like those in tv-mutate.h.
41 * These functions all promote uninit null values to init null values, except
42 * for setElemWithRef() which asserts that `v' is init instead.
44 ALWAYS_INLINE void setElemNoRef(Cell& elem, Cell v) {
45 if (UNLIKELY(v.m_type == KindOfUninit)) {
46 v.m_type = KindOfNull;
48 cellSet(v, elem);
50 ALWAYS_INLINE void setElem(TypedValue& elem, Cell v) {
51 setElemNoRef(*tvToCell(&elem), v);
54 ALWAYS_INLINE void setElemWithRef(TypedValue& elem, TypedValue v) {
55 assertx(UNLIKELY(v.m_type != KindOfUninit));
56 tvSetWithRef(v, elem);
59 ///////////////////////////////////////////////////////////////////////////////
63 #endif