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_object *zend_enum_new(zval *result, zend_class_entry *ce, zend_string *case_name, zval *backing_value_zv);
33 void zend_verify_enum(zend_class_entry *ce);
34 void zend_enum_register_funcs(zend_class_entry *ce);
35 void zend_enum_register_props(zend_class_entry *ce);
36 
37 ZEND_API zend_class_entry *zend_register_internal_enum(
38 	const char *name, zend_uchar type, const zend_function_entry *functions);
39 ZEND_API void zend_enum_add_case(zend_class_entry *ce, zend_string *case_name, zval *value);
40 ZEND_API void zend_enum_add_case_cstr(zend_class_entry *ce, const char *name, zval *value);
41 ZEND_API zend_object *zend_enum_get_case(zend_class_entry *ce, zend_string *name);
42 ZEND_API zend_object *zend_enum_get_case_cstr(zend_class_entry *ce, const char *name);
43 
zend_enum_fetch_case_name(zend_object * zobj)44 static zend_always_inline zval *zend_enum_fetch_case_name(zend_object *zobj)
45 {
46 	ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM);
47 	return OBJ_PROP_NUM(zobj, 0);
48 }
49 
zend_enum_fetch_case_value(zend_object * zobj)50 static zend_always_inline zval *zend_enum_fetch_case_value(zend_object *zobj)
51 {
52 	ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM);
53 	ZEND_ASSERT(zobj->ce->enum_backing_type != IS_UNDEF);
54 	return OBJ_PROP_NUM(zobj, 1);
55 }
56 
57 END_EXTERN_C()
58 
59 #endif /* ZEND_ENUM_H */
60