adding tests to the semdiff test suite
[hiphop-php.git] / hphp / hhbbc / class-util.cpp
blob230f1302e8a3768b69cf909c11eebd708b8e1641
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 +----------------------------------------------------------------------+
16 #include "hphp/hhbbc/class-util.h"
18 #include "hphp/runtime/base/collections.h"
19 #include "hphp/hhbbc/representation.h"
20 #include "hphp/hhbbc/index.h"
21 #include "hphp/hhbbc/type-system.h"
23 namespace HPHP { namespace HHBBC {
25 //////////////////////////////////////////////////////////////////////
27 namespace {
29 const StaticString
30 s_SimpleXMLElement("SimpleXMLElement"),
31 s_Closure("Closure"),
32 s_86pinit("86pinit"),
33 s_86sinit("86sinit"),
34 s_MockClass("__MockClass");
37 //////////////////////////////////////////////////////////////////////
39 bool has_magic_bool_conversion(SString clsName) {
40 return
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 borrowed_ptr<php::Func> find_method(borrowed_ptr<const php::Class> cls,
51 SString name) {
52 for (auto& m : cls->methods) {
53 if (m->name->isame(name)) {
54 return borrow(m);
57 return nullptr;
60 bool is_special_method_name(SString name) {
61 auto const p = name->data();
62 return p && p[0] == '8' && p[1] == '6';
65 bool is_mock_class(borrowed_ptr<const php::Class> cls) {
66 return cls->userAttributes.count(s_MockClass.get());
69 bool is_closure(const php::Class& c) {
70 return c.parentName && c.parentName->isame(s_Closure.get());
73 //////////////////////////////////////////////////////////////////////