2 +----------------------------------------------------------------------+
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_TYPE_ALIAS_H_
18 #define incl_HPHP_TYPE_ALIAS_H_
20 #include "hphp/runtime/base/annot-type.h"
21 #include "hphp/runtime/base/array-data.h"
22 #include "hphp/runtime/base/attr.h"
23 #include "hphp/runtime/base/datatype.h"
24 #include "hphp/runtime/base/type-array.h"
25 #include "hphp/runtime/base/typed-value.h"
26 #include "hphp/runtime/base/types.h"
27 #include "hphp/runtime/base/user-attributes.h"
30 ///////////////////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////////
39 * This is the runtime representation of a type alias. Type aliases are only
40 * allowed when HipHop extensions are enabled.
42 * The `type' field is Object whenever the type alias is basically just a
43 * name. At runtime we still might resolve this name to another type alias,
44 * becoming a type alias for KindOfArray or something in that request.
46 * For the per-request struct, see TypeAliasReq below.
53 bool nullable
; // null is allowed; for ?Foo aliases
54 UserAttributeMap userAttrs
;
55 Array typeStructure
{Array::Create()};
58 typename
std::enable_if
<!SerDe::deserializing
>::type
67 TypedValue tv
= make_tv
<KindOfArray
>(typeStructure
.get());
72 typename
std::enable_if
<SerDe::deserializing
>::type
84 assert(isArrayType(tv
.m_type
));
85 typeStructure
= tv
.m_data
.parr
;
91 ///////////////////////////////////////////////////////////////////////////////
94 * In a given request, a defined type alias is turned into a TypeAliasReq
95 * struct. This contains the information needed to validate parameter type
96 * hints for a type alias at runtime.
100 /////////////////////////////////////////////////////////////////////////////
101 // Static constructors.
103 static TypeAliasReq
Invalid();
104 static TypeAliasReq
From(const TypeAlias
& alias
);
105 static TypeAliasReq
From(TypeAliasReq req
, const TypeAlias
& alias
);
108 /////////////////////////////////////////////////////////////////////////////
111 bool same(const TypeAliasReq
& req
) const;
112 bool compat(const TypeAlias
& alias
) const;
115 /////////////////////////////////////////////////////////////////////////////
119 AnnotType type
{AnnotType::Uninit
};
120 // Overrides `type' if the alias is invalid (e.g., for a nonexistent class).
122 // For option types, like ?Foo.
123 bool nullable
{false};
124 // Aliased Class; nullptr if type != Object.
125 LowPtr
<Class
> klass
{nullptr};
126 // Needed for error messages; nullptr if not defined.
127 LowStringPtr name
{nullptr};
128 Array typeStructure
{Array::Create()};
129 UserAttributeMap userAttrs
;
132 bool operator==(const TypeAliasReq
& l
, const TypeAliasReq
& r
);
133 bool operator!=(const TypeAliasReq
& l
, const TypeAliasReq
& r
);
135 ///////////////////////////////////////////////////////////////////////////////
138 #define incl_HPHP_TYPE_ALIAS_INL_H_
139 #include "hphp/runtime/vm/type-alias-inl.h"
140 #undef incl_HPHP_TYPE_ALIAS_INL_H_