Make comparison IR ops layout agnostic
[hiphop-php.git] / hphp / runtime / base / tv-variant.h
blobc5e43c8c3814fe992f01ccbbfa29923b87993125
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_TV_VARIANT_H_
18 #define incl_HPHP_TV_VARIANT_H_
20 #include "hphp/runtime/base/typed-value.h"
21 #include "hphp/runtime/base/tv-val.h"
23 namespace HPHP {
25 struct Variant;
27 ///////////////////////////////////////////////////////////////////////////////
29 * The functions in this file serve as escape hatches that allow us to call
30 * into the Variant machinery.
32 * Ideally, we will use these as little as possible in the long term. The
33 * harsh reality is that we include this file pretty much everywhere.
35 * Except where noted, all of these functions assume that the TypedValue is
36 * live (i.e., contains a valid, refcount-supported value).
39 ALWAYS_INLINE Variant& tvAsVariant(TypedValue* tv) {
40 assertx(tv != nullptr);
41 assertx(tvIsPlausible(*tv));
42 return reinterpret_cast<Variant&>(*tv);
45 ALWAYS_INLINE Variant& tvAsUninitializedVariant(TypedValue* tv) {
46 // A special case, for use when constructing a variant and we don't assume
47 // initialization.
48 assertx(tv != nullptr);
49 return reinterpret_cast<Variant&>(*tv);
52 ALWAYS_INLINE const Variant& tvAsCVarRef(const TypedValue* tv) {
53 assertx(tv != nullptr);
54 assertx(tvIsPlausible(*tv));
55 return reinterpret_cast<const Variant&>(*tv);
58 ALWAYS_INLINE Variant& tvAsVariant(TypedValue& tv) {
59 assertx(tvIsPlausible(tv));
60 return reinterpret_cast<Variant&>(tv);
63 ALWAYS_INLINE const Variant& tvAsCVarRef(const TypedValue& tv) {
64 assertx(tvIsPlausible(tv));
65 return reinterpret_cast<const Variant&>(tv);
68 ///////////////////////////////////////////////////////////////////////////////
72 #endif