xref: /PHP-8.2/Zend/zend_enum.h (revision 423fc811)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) Zend Technologies Ltd. (http://www.zend.com)           |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend 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.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Authors: Ilija Tovilo <ilutov@php.net>                               |
16    +----------------------------------------------------------------------+
17 */
18 
19 #ifndef ZEND_ENUM_H
20 #define ZEND_ENUM_H
21 
22 #include "zend.h"
23 #include "zend_types.h"
24 
25 BEGIN_EXTERN_C()
26 
27 extern ZEND_API zend_class_entry *zend_ce_unit_enum;
28 extern ZEND_API zend_class_entry *zend_ce_backed_enum;
29 
30 void zend_register_enum_ce(void);
31 void zend_enum_add_interfaces(zend_class_entry *ce);
32 zend_result zend_enum_build_backed_enum_table(zend_class_entry *ce);
33 zend_object *zend_enum_new(zval *result, zend_class_entry *ce, zend_string *case_name, zval *backing_value_zv);
34 void zend_verify_enum(zend_class_entry *ce);
35 void zend_enum_register_funcs(zend_class_entry *ce);
36 void zend_enum_register_props(zend_class_entry *ce);
37 
38 ZEND_API zend_class_entry *zend_register_internal_enum(
39 	const char *name, zend_uchar type, const zend_function_entry *functions);
40 ZEND_API void zend_enum_add_case(zend_class_entry *ce, zend_string *case_name, zval *value);
41 ZEND_API void zend_enum_add_case_cstr(zend_class_entry *ce, const char *name, zval *value);
42 ZEND_API zend_object *zend_enum_get_case(zend_class_entry *ce, zend_string *name);
43 ZEND_API zend_object *zend_enum_get_case_cstr(zend_class_entry *ce, const char *name);
44 ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_class_entry *ce, zend_long long_key, zend_string *string_key, bool try_from);
45 
zend_enum_fetch_case_name(zend_object * zobj)46 static zend_always_inline zval *zend_enum_fetch_case_name(zend_object *zobj)
47 {
48 	ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM);
49 	return OBJ_PROP_NUM(zobj, 0);
50 }
51 
zend_enum_fetch_case_value(zend_object * zobj)52 static zend_always_inline zval *zend_enum_fetch_case_value(zend_object *zobj)
53 {
54 	ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM);
55 	ZEND_ASSERT(zobj->ce->enum_backing_type != IS_UNDEF);
56 	return OBJ_PROP_NUM(zobj, 1);
57 }
58 
59 END_EXTERN_C()
60 
61 #endif /* ZEND_ENUM_H */
62