Add a capi conversion no-op method to thrift python structs/unions
[hiphop-php.git] / hphp / hhbbc / class-util.h
blob445351ddd41a1a94ce53320055d912416dde2ab5
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 #pragma once
18 #include "hphp/runtime/base/typed-value.h"
19 #include "hphp/runtime/base/attr.h"
21 #include "hphp/hhbbc/misc.h"
22 #include "hphp/hhbbc/representation.h"
24 namespace HPHP {
26 struct UserAttributeMap;
28 namespace HHBBC {
30 namespace res { struct Class; }
31 struct Type;
33 //////////////////////////////////////////////////////////////////////
36 * Returns whether a res::Class refers to a collection class.
38 bool is_collection(res::Class);
41 * Returns whether a php::Class is the base class for all closures.
43 bool is_closure_base(const php::Class&);
44 bool is_closure_base(SString);
47 * Returns whether a php::Class is a closure.
49 bool is_closure(const php::Class&);
52 * Whether the given name is that of a closure.
54 bool is_closure_name(SString);
57 * Returns whether a clsName is a class with a magic toBoolean method.
59 bool has_magic_bool_conversion(SString clsName);
62 * Returns method named "name" if it exists.
64 php::Func* find_method(const php::Class*, SString name);
67 * Returns true if `name' is the name of an internal VM special class
68 * method. (Not callable directly by php code.)
70 bool is_special_method_name(SString name);
73 * Whether a method by this name should get a "name-only" func family
74 * entry.
76 bool has_name_only_func_family(SString);
79 * Returns true if a class has the __MockClass user attribute. This
80 * attribute allows final methods and final classes to be overridden.
82 bool is_mock_class(const php::Class*);
85 * Returns true if the given trait class has the __NoFlatten user attribute.
86 * This can be used to forcibly disable flattening for the given trait.
87 * Asserts that the class passed in is a trait.
89 bool is_noflatten_trait(const php::Class*);
92 * Returns true if cls is a trait which will not be imported into any
93 * classes at runtime (probably because it was flattened into them).
95 bool is_unused_trait(const php::Class& cls);
98 * Returns true if cls is a trait which could be imported into a class
99 * at runtime.
101 bool is_used_trait(const php::Class& cls);
104 * Returns true if the given class is "regular". That is, not an
105 * interface, enum, trait, or abstract class. Those types of classes
106 * cannot be instantiated (but can be interacted with statically).
108 inline bool is_regular_class(Attr attrs) {
109 return
110 !(attrs & (AttrInterface | AttrTrait |
111 AttrAbstract | AttrEnum |
112 AttrEnumClass));
114 inline bool is_regular_class(const php::Class& c) {
115 return is_regular_class(c.attrs);
118 Type get_type_of_reified_list(const UserAttributeMap& ua);
120 TypedValue get_default_value_of_reified_list(const UserAttributeMap& ua);
123 * Given a type representing a prop with name "name" on the class
124 * "ctx", loosen the type appropriately to represent any possible
125 * deserializing of the prop. Generally, this discards any special
126 * inferred array structure or known values.
128 Type loosen_this_prop_for_serialization(const php::Class& ctx,
129 SString name,
130 Type type);
132 //////////////////////////////////////////////////////////////////////