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 +----------------------------------------------------------------------+
16 #include "hphp/hhbbc/class-util.h"
18 #include "hphp/hhbbc/index.h"
19 #include "hphp/hhbbc/representation.h"
20 #include "hphp/hhbbc/type-system.h"
22 #include "hphp/runtime/base/collections.h"
23 #include "hphp/runtime/vm/preclass-emitter.h"
25 namespace HPHP
{ namespace HHBBC
{
27 //////////////////////////////////////////////////////////////////////
32 s_SimpleXMLElement("SimpleXMLElement"),
34 s_MockClass("__MockClass");
37 //////////////////////////////////////////////////////////////////////
39 bool has_magic_bool_conversion(SString clsName
) {
41 collections::isTypeName(clsName
) ||
42 clsName
->isame(s_SimpleXMLElement
.get());
45 bool is_collection(res::Class cls
) {
46 auto const name
= cls
.name();
47 return collections::isTypeName(name
);
50 php::Func
* find_method(const php::Class
* cls
, SString name
) {
51 for (auto& m
: cls
->methods
) {
52 if (m
->name
->isame(name
)) {
59 bool is_special_method_name(SString name
) {
60 auto const p
= name
->data();
61 return p
&& p
[0] == '8' && p
[1] == '6';
64 bool is_mock_class(const php::Class
* cls
) {
65 return cls
->userAttributes
.count(s_MockClass
.get());
68 bool is_closure(const php::Class
& c
) {
69 return c
.parentName
&& c
.parentName
->isame(s_Closure
.get());
72 bool is_unused_trait(const php::Class
& c
) {
74 (c
.attrs
& (AttrTrait
| AttrNoOverride
)) == (AttrTrait
| AttrNoOverride
);
77 bool is_used_trait(const php::Class
& c
) {
79 (c
.attrs
& (AttrTrait
| AttrNoOverride
)) == AttrTrait
;
82 std::string
normalized_class_name(const php::Class
& cls
) {
83 auto const name
= cls
.name
->toCppString();
84 if (!PreClassEmitter::IsAnonymousClassName(name
)) return name
;
85 return name
.substr(0, name
.find_last_of(';'));
88 //////////////////////////////////////////////////////////////////////
92 //////////////////////////////////////////////////////////////////////
94 ClassBase::ClassBase(const ClassBase
& other
) {
95 for (auto& m
: other
.methods
) {
96 methods
.push_back(std::make_unique
<php::Func
>(*m
));
100 //////////////////////////////////////////////////////////////////////
104 //////////////////////////////////////////////////////////////////////