Use custom AssemblyAnnotationWriter to improve vasm/llvm printing
[hiphop-php.git] / hphp / runtime / vm / type-alias.h
blob0ee9279f8aed6dc6d3b58c65ab782c2abd20d58e
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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/types.h"
21 #include "hphp/runtime/base/attr.h"
22 #include "hphp/runtime/base/datatype.h"
24 namespace HPHP {
25 ///////////////////////////////////////////////////////////////////////////////
27 struct Class;
28 struct StringData;
30 ///////////////////////////////////////////////////////////////////////////////
33 * This is the runtime representation of a type alias. Type aliases are only
34 * allowed when HipHop extensions are enabled.
36 * The m_kind field is KindOfObject whenever the type alias is basically just a
37 * name. At runtime we still might resolve this name to another type alias,
38 * becoming a type alias for KindOfArray or something in that request.
40 * For the per-request struct, see TypeAliasReq below.
42 struct TypeAlias {
43 LowStringPtr name;
44 LowStringPtr value;
45 DataType kind;
46 bool any; // overrides `kind' for mixed aliases
47 bool nullable; // null is allowed; for ?Foo aliases
48 Attr attrs;
50 template<class SerDe> void serde(SerDe& sd) {
51 sd(name)
52 (value)
53 (kind)
54 (any)
55 (nullable)
56 (attrs)
62 ///////////////////////////////////////////////////////////////////////////////
65 * In a given request, a defined type alias is turned into a TypeAliasReq
66 * struct. This contains the information needed to validate parameter type
67 * hints for a type alias at runtime.
69 struct TypeAliasReq {
71 /////////////////////////////////////////////////////////////////////////////
72 // Static constructors.
74 static TypeAliasReq Invalid();
75 static TypeAliasReq From(const TypeAlias& alias);
76 static TypeAliasReq From(TypeAliasReq req, const TypeAlias& alias);
79 /////////////////////////////////////////////////////////////////////////////
80 // Comparison.
82 bool same(const TypeAliasReq& req) const;
83 bool compat(const TypeAlias& alias) const;
86 /////////////////////////////////////////////////////////////////////////////
87 // Data members.
89 // The alised type.
90 DataType kind{KindOfUninit};
91 // Overrides `kind' if the alias is invalid (e.g., for a nonexistent class).
92 bool invalid{false};
93 // Overrides `kind' for "HH\\mixed".
94 bool any{false};
95 // For option types, like ?Foo.
96 bool nullable{false};
97 // Aliased Class; nullptr if kind != KindOfObject.
98 LowClassPtr klass{nullptr};
99 // Needed for error messages; nullptr if not defined.
100 LowStringPtr name{nullptr};
103 bool operator==(const TypeAliasReq& l, const TypeAliasReq& r);
104 bool operator!=(const TypeAliasReq& l, const TypeAliasReq& r);
106 ///////////////////////////////////////////////////////////////////////////////
109 #define incl_HPHP_TYPE_ALIAS_INL_H_
110 #include "hphp/runtime/vm/type-alias-inl.h"
111 #undef incl_HPHP_TYPE_ALIAS_INL_H_
113 #endif