GCC Code Coverage Report


./
File: mruby/include/mruby/class.h
Date: 2024-05-21 01:02:25
Lines:
3/20
15.0%
Functions:
1/1
100.0%
Branches:
2/13
15.4%

Line Branch Exec Source
1 /**
2 ** @file mruby/class.h - Class class
3 **
4 ** See Copyright Notice in mruby.h
5 */
6
7 #ifndef MRUBY_CLASS_H
8 #define MRUBY_CLASS_H
9
10 #include "common.h"
11
12 /**
13 * Class class
14 */
15 MRB_BEGIN_DECL
16
17 struct RClass {
18 MRB_OBJECT_HEADER;
19 struct iv_tbl *iv;
20 struct mt_tbl *mt;
21 struct RClass *super;
22 };
23
24 #define mrb_class_ptr(v) ((struct RClass*)(mrb_ptr(v)))
25
26 MRB_INLINE struct RClass*
27 47 mrb_class(mrb_state *mrb, mrb_value v)
28 {
29
2/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
47 if (!mrb_immediate_p(v)) {
30 47 return mrb_obj_ptr(v)->c;
31 }
32
33 switch (mrb_type(v)) {
34 case MRB_TT_FALSE:
35 if (mrb_fixnum(v))
36 return mrb->false_class;
37 return mrb->nil_class;
38 case MRB_TT_TRUE:
39 return mrb->true_class;
40 case MRB_TT_SYMBOL:
41 return mrb->symbol_class;
42 case MRB_TT_INTEGER:
43 return mrb->integer_class;
44 #ifndef MRB_NO_FLOAT
45 case MRB_TT_FLOAT:
46 return mrb->float_class;
47 #endif
48 case MRB_TT_CPTR:
49 return mrb->object_class;
50 default:
51 return NULL;
52 }
53 }
54
55 /* flags:
56 20: frozen
57 19: is_prepended
58 18: is_origin
59 17: is_inherited (used by method cache)
60 7-16: unused
61 6: prohibit Class#allocate
62 0-5: instance type
63 */
64 #define MRB_FL_CLASS_IS_PREPENDED (1 << 19)
65 #define MRB_FL_CLASS_IS_ORIGIN (1 << 18)
66 #define MRB_CLASS_ORIGIN(c) do {\
67 if ((c)->flags & MRB_FL_CLASS_IS_PREPENDED) {\
68 (c) = (c)->super;\
69 while (!((c)->flags & MRB_FL_CLASS_IS_ORIGIN)) {\
70 (c) = (c)->super;\
71 }\
72 }\
73 } while (0)
74 #define MRB_FL_CLASS_IS_INHERITED (1 << 17)
75 #define MRB_INSTANCE_TT_MASK (0x1F)
76 #define MRB_SET_INSTANCE_TT(c, tt) ((c)->flags = (((c)->flags & ~MRB_INSTANCE_TT_MASK) | (char)(tt)))
77 #define MRB_INSTANCE_TT(c) (enum mrb_vtype)((c)->flags & MRB_INSTANCE_TT_MASK)
78 #define MRB_FL_UNDEF_ALLOCATE (1 << 6)
79 #define MRB_UNDEF_ALLOCATOR(c) (mrb_assert((c)->tt == MRB_TT_CLASS), (c)->flags |= MRB_FL_UNDEF_ALLOCATE)
80 #define MRB_UNDEF_ALLOCATOR_P(c) ((c)->flags & MRB_FL_UNDEF_ALLOCATE)
81 #define MRB_DEFINE_ALLOCATOR(c) ((c)->flags &= ~MRB_FL_UNDEF_ALLOCATE)
82
83 MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, mrb_method_t);
84 MRB_API void mrb_alias_method(mrb_state*, struct RClass *c, mrb_sym a, mrb_sym b);
85 MRB_API void mrb_remove_method(mrb_state *mrb, struct RClass *c, mrb_sym sym);
86
87 MRB_API mrb_method_t mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym);
88 MRB_API mrb_method_t mrb_method_search(mrb_state*, struct RClass*, mrb_sym);
89
90 MRB_API struct RClass* mrb_class_real(struct RClass* cl);
91
92 #ifndef MRB_NO_METHOD_CACHE
93 void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c);
94 #else
95 #define mrb_mc_clear_by_class(mrb,c)
96 #endif
97
98 /* return non zero to break the loop */
99 typedef int (mrb_mt_foreach_func)(mrb_state*,mrb_sym,mrb_method_t,void*);
100 MRB_API void mrb_mt_foreach(mrb_state*, struct RClass*, mrb_mt_foreach_func*, void*);
101
102 MRB_END_DECL
103
104 #endif /* MRUBY_CLASS_H */
105