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_VM_PRECLASS_INL_H_
18 #error "preclass-inl.h should only be included by preclass.h"
22 ///////////////////////////////////////////////////////////////////////////////
24 inline bool PreClass::isPersistent() const {
25 return m_attrs
& AttrPersistent
;
28 inline bool PreClass::isBuiltin() const {
29 return m_attrs
& AttrBuiltin
;
32 inline bool PreClass::hasConstant(const StringData
* cnsName
) const {
33 return m_constants
.contains(cnsName
);
36 inline bool PreClass::hasMethod(const StringData
* methName
) const {
37 return m_methods
.contains(methName
);
40 inline bool PreClass::hasProp(const StringData
* propName
) const {
41 return m_properties
.contains(propName
);
44 inline const PreClass::Const
*
45 PreClass::lookupConstant(const StringData
* cnsName
) const {
46 Slot s
= m_constants
.findIndex(cnsName
);
47 assertx(s
!= kInvalidSlot
);
48 return &m_constants
[s
];
51 inline Func
* PreClass::lookupMethod(const StringData
* methName
) const {
52 Func
* f
= m_methods
.lookupDefault(methName
, nullptr);
53 assertx(f
!= nullptr);
57 inline const PreClass::Prop
*
58 PreClass::lookupProp(const StringData
* propName
) const {
59 Slot s
= m_properties
.findIndex(propName
);
60 assertx(s
!= kInvalidSlot
);
61 return &m_properties
[s
];
64 ///////////////////////////////////////////////////////////////////////////////
65 // PreClass::TraitPrecRule.
68 PreClass::TraitPrecRule::TraitPrecRule()
69 : m_methodName(nullptr)
70 , m_selectedTraitName(nullptr)
74 PreClass::TraitPrecRule::TraitPrecRule(const StringData
* selectedTraitName
,
75 const StringData
* methodName
)
76 : m_methodName(methodName
)
77 , m_selectedTraitName(selectedTraitName
)
81 PreClass::TraitPrecRule::addOtherTraitName(const StringData
* traitName
) {
82 m_otherTraitNames
.insert(traitName
);
85 ///////////////////////////////////////////////////////////////////////////////
86 // PreClass::TraitAliasRule.
89 PreClass::TraitAliasRule::TraitAliasRule()
90 : m_traitName(nullptr)
91 , m_origMethodName(nullptr)
92 , m_newMethodName(nullptr)
93 , m_modifiers(AttrNone
)
97 PreClass::TraitAliasRule::TraitAliasRule(const StringData
* traitName
,
98 const StringData
* origMethodName
,
99 const StringData
* newMethodName
,
101 : m_traitName(traitName
)
102 , m_origMethodName(origMethodName
)
103 , m_newMethodName(newMethodName
)
104 , m_modifiers(modifiers
)
107 ///////////////////////////////////////////////////////////////////////////////
108 // PreClass::ClassRequirement.
111 uintptr_t packCR(const StringData
* req
, bool isExtends
) {
112 auto reqPtr
= reinterpret_cast<uintptr_t>(req
);
113 return isExtends
? (reqPtr
| 0x1) : reqPtr
;
118 PreClass::ClassRequirement::ClassRequirement()
123 PreClass::ClassRequirement::ClassRequirement(const StringData
* req
,
125 : m_word(packCR(req
, isExtends
))
131 inline const StringData
* PreClass::ClassRequirement::name() const {
132 return reinterpret_cast<const StringData
*>(m_word
& ~0x1);
135 inline bool PreClass::ClassRequirement::is_extends() const {
139 inline bool PreClass::ClassRequirement::is_implements() const {
140 return !is_extends();
143 inline bool PreClass::ClassRequirement::is_same(
144 const ClassRequirement
* other
) const {
145 return m_word
== other
->m_word
;
148 inline size_t PreClass::ClassRequirement::hash() const {
155 template<class SerDe
>
156 typename
std::enable_if
<SerDe::deserializing
>::type
157 PreClass::ClassRequirement::serde(SerDe
& sd
) {
158 const StringData
* sd_name
;
160 sd(sd_name
)(sd_is_extends
);
161 m_word
= packCR(sd_name
, sd_is_extends
);
167 template<class SerDe
>
168 typename
std::enable_if
<!SerDe::deserializing
>::type
169 PreClass::ClassRequirement::serde(SerDe
& sd
) {
170 sd(name())(is_extends());
173 ///////////////////////////////////////////////////////////////////////////////
177 * Ser(ialization)-De(serialization).
179 template<class SerDe
>
180 inline void PreClass::Const::serde(SerDe
& sd
) {
181 TypedValue sd_tv
= m_val
;
182 auto sd_modifiers
= m_val
.constModifiers();
188 if (SerDe::deserializing
) {
189 // tvCopy inlined here to avoid header dependency issues
190 m_val
.m_data
.num
= sd_tv
.m_data
.num
;
191 m_val
.m_type
= sd_tv
.m_type
;
192 m_val
.constModifiers() = sd_modifiers
;
196 ///////////////////////////////////////////////////////////////////////////////