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_API.h"
24
25 #include <stdint.h>
26
27 BEGIN_EXTERN_C()
28
29 extern ZEND_API zend_class_entry *zend_ce_unit_enum;
30 extern ZEND_API zend_class_entry *zend_ce_backed_enum;
31 extern ZEND_API zend_object_handlers zend_enum_object_handlers;
32
33 void zend_register_enum_ce(void);
34 void zend_enum_add_interfaces(zend_class_entry *ce);
35 zend_result zend_enum_build_backed_enum_table(zend_class_entry *ce);
36 zend_object *zend_enum_new(zval *result, zend_class_entry *ce, zend_string *case_name, zval *backing_value_zv);
37 void zend_verify_enum(const zend_class_entry *ce);
38 void zend_enum_register_funcs(zend_class_entry *ce);
39 void zend_enum_register_props(zend_class_entry *ce);
40
41 ZEND_API zend_class_entry *zend_register_internal_enum(
42 const char *name, uint8_t type, const zend_function_entry *functions);
43 ZEND_API void zend_enum_add_case(zend_class_entry *ce, zend_string *case_name, zval *value);
44 ZEND_API void zend_enum_add_case_cstr(zend_class_entry *ce, const char *name, zval *value);
45 ZEND_API zend_object *zend_enum_get_case(zend_class_entry *ce, zend_string *name);
46 ZEND_API zend_object *zend_enum_get_case_cstr(zend_class_entry *ce, const char *name);
47 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);
48
zend_enum_fetch_case_name(zend_object * zobj)49 static zend_always_inline zval *zend_enum_fetch_case_name(zend_object *zobj)
50 {
51 ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM);
52 return OBJ_PROP_NUM(zobj, 0);
53 }
54
zend_enum_fetch_case_value(zend_object * zobj)55 static zend_always_inline zval *zend_enum_fetch_case_value(zend_object *zobj)
56 {
57 ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM);
58 ZEND_ASSERT(zobj->ce->enum_backing_type != IS_UNDEF);
59 return OBJ_PROP_NUM(zobj, 1);
60 }
61
62 END_EXTERN_C()
63
64 #endif /* ZEND_ENUM_H */
65