Ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
method.h
Go to the documentation of this file.
1/**********************************************************************
2
3 method.h -
4
5 $Author$
6 created at: Wed Jul 15 20:02:33 2009
7
8 Copyright (C) 2009 Koichi Sasada
9
10**********************************************************************/
11#ifndef RUBY_METHOD_H
12#define RUBY_METHOD_H 1
13
14#include "internal.h"
15
16#ifndef END_OF_ENUMERATION
17# if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
18# define END_OF_ENUMERATION(key)
19# else
20# define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
21# endif
22#endif
23
24/* cref */
25
26typedef enum {
31
32 METHOD_VISI_MASK = 0x03
34
35typedef struct rb_scope_visi_struct {
37 unsigned int module_func : 1;
39
41typedef struct rb_cref_struct {
45 struct rb_cref_struct * next;
48
49/* method data type */
50
51typedef struct rb_method_entry_struct {
54 struct rb_method_definition_struct * const def;
58
59typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_entry_t */
61 const VALUE defined_class;
62 struct rb_method_definition_struct * const def;
64 const VALUE owner;
66
67#define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
68#define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
69#define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
70#define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags = (me)->flags | IMEMO_FL_USER3)
71
72static inline void
73METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
74{
75 VM_ASSERT((int)visi >= 0 && visi <= 3);
76 me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << (IMEMO_FL_USHIFT+0));
77}
78static inline void
79METHOD_ENTRY_BASIC_SET(rb_method_entry_t *me, unsigned int basic)
80{
81 VM_ASSERT(basic <= 1);
82 me->flags = (me->flags & ~(IMEMO_FL_USER2 )) | (basic << (IMEMO_FL_USHIFT+2));
83}
84static inline void
85METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, unsigned int basic)
86{
87 VM_ASSERT((int)visi >= 0 && visi <= 3);
88 VM_ASSERT(basic <= 1);
89 me->flags =
91 ((visi << (IMEMO_FL_USHIFT+0)) | (basic << (IMEMO_FL_USHIFT+2)));
92}
93static inline void
94METHOD_ENTRY_FLAGS_COPY(rb_method_entry_t *dst, const rb_method_entry_t *src)
95{
96 dst->flags =
99}
100
101typedef enum {
115 END_OF_ENUMERATION(VM_METHOD_TYPE)
117#define VM_METHOD_TYPE_MINIMUM_BITS 4
120
121#ifndef rb_iseq_t
123#define rb_iseq_t rb_iseq_t
124#endif
125
126typedef struct rb_method_iseq_struct {
128 rb_cref_t * cref;
129} rb_method_iseq_t; /* check rb_add_method_iseq() when modify the fields */
130
131typedef struct rb_method_cfunc_struct {
132 VALUE (*func)(ANYARGS);
133 VALUE (*invoker)(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS));
134 int argc;
136
137typedef struct rb_method_attr_struct {
138 ID id;
139 VALUE location; /* should be marked */
141
142typedef struct rb_method_alias_struct {
143 struct rb_method_entry_struct * original_me; /* original_me->klass is original owner */
145
146typedef struct rb_method_refined_struct {
148 VALUE owner;
150
151typedef struct rb_method_bmethod_struct {
152 VALUE proc; /* should be marked */
155
162
165 int alias_count : 28;
166 int complemented_count : 28;
167 unsigned int no_redef_warning: 1;
168
169 union {
176
179
182};
183
186
187#define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
188#define UNDEFINED_REFINED_METHOD_P(def) \
189 ((def)->type == VM_METHOD_TYPE_REFINED && \
190 UNDEFINED_METHOD_ENTRY_P((def)->body.refined.orig_me))
191
194void rb_add_refined_method_entry(VALUE refined_class, ID mid);
196
199
201
209
213
217
219
221
225
227
229
230#endif /* RUBY_METHOD_H */
const rb_method_entry_t * rb_method_entry_clone(const rb_method_entry_t *me)
Definition: vm_method.c:406
int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2)
Definition: vm_method.c:1493
const rb_callable_method_entry_t * rb_callable_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:948
struct rb_method_cfunc_struct rb_method_cfunc_t
const rb_method_entry_t * rb_method_entry(VALUE klass, ID id)
Definition: vm_method.c:854
int rb_method_entry_arity(const rb_method_entry_t *me)
Definition: proc.c:2555
const rb_callable_method_entry_t * rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:934
void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi)
Definition: vm_method.c:685
struct rb_method_attr_struct rb_method_attr_t
const rb_method_entry_t * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me)
Definition: vm_method.c:989
void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi)
Definition: vm_method.c:675
void rb_method_entry_copy(rb_method_entry_t *dst, const rb_method_entry_t *src)
Definition: vm_method.c:451
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
Definition: vm_method.c:491
struct rb_callable_method_entry_struct rb_callable_method_entry_t
void rb_free_method_entry(const rb_method_entry_t *me)
Definition: vm_method.c:174
struct rb_method_entry_struct rb_method_entry_t
rb_method_visibility_t
Definition: method.h:26
@ METHOD_VISI_PRIVATE
Definition: method.h:29
@ METHOD_VISI_MASK
Definition: method.h:32
@ METHOD_VISI_PROTECTED
Definition: method.h:30
@ METHOD_VISI_PUBLIC
Definition: method.h:28
@ METHOD_VISI_UNDEF
Definition: method.h:27
rb_method_entry_t * rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex)
Definition: vm_method.c:714
#define VM_METHOD_TYPE_MINIMUM_BITS
Definition: method.h:117
RUBY_SYMBOL_EXPORT_BEGIN const rb_method_entry_t * rb_resolve_me_location(const rb_method_entry_t *, VALUE[5])
Definition: thread.c:5399
struct rb_method_iseq_struct rb_method_iseq_t
rb_method_type_t
Definition: method.h:101
@ VM_METHOD_TYPE_ISEQ
Ruby method.
Definition: method.h:102
@ VM_METHOD_TYPE_ATTRSET
attr_writer or attr_accessor
Definition: method.h:104
@ VM_METHOD_TYPE_CFUNC
C method.
Definition: method.h:103
@ VM_METHOD_TYPE_OPTIMIZED
Kernel::send, Proc::call, etc.
Definition: method.h:111
@ VM_METHOD_TYPE_REFINED
refinement
Definition: method.h:113
@ VM_METHOD_TYPE_NOTIMPLEMENTED
Definition: method.h:110
@ VM_METHOD_TYPE_MISSING
wrapper for method_missing(id)
Definition: method.h:112
@ VM_METHOD_TYPE_BMETHOD
Definition: method.h:106
@ VM_METHOD_TYPE_IVAR
attr_reader or attr_accessor
Definition: method.h:105
@ VM_METHOD_TYPE_ZSUPER
Definition: method.h:107
@ VM_METHOD_TYPE_ALIAS
Definition: method.h:108
@ VM_METHOD_TYPE_UNDEF
Definition: method.h:109
@ OPTIMIZED_METHOD_TYPE_CALL
Definition: method.h:158
@ OPTIMIZED_METHOD_TYPE__MAX
Definition: method.h:160
@ OPTIMIZED_METHOD_TYPE_BLOCK_CALL
Definition: method.h:159
@ OPTIMIZED_METHOD_TYPE_SEND
Definition: method.h:157
VALUE rb_unnamed_parameters(int arity)
Definition: proc.c:1262
struct rb_scope_visi_struct rb_scope_visibility_t
const rb_method_entry_t * rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:928
RUBY_SYMBOL_EXPORT_END const rb_callable_method_entry_t * rb_callable_method_entry(VALUE klass, ID id)
Definition: vm_method.c:895
const rb_method_entry_t * rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:942
struct rb_method_bmethod_struct rb_method_bmethod_t
VALUE rb_method_entry_location(const rb_method_entry_t *me)
Definition: proc.c:2725
struct rb_method_refined_struct rb_method_refined_t
void rb_scope_visibility_set(rb_method_visibility_t)
Definition: vm_method.c:1155
const rb_method_entry_t * rb_method_entry_at(VALUE obj, ID id)
Definition: vm_method.c:767
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc, rb_method_visibility_t visi)
Definition: vm_method.c:134
const rb_callable_method_entry_t * rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID called_id, VALUE defined_class)
Definition: vm_method.c:415
STATIC_ASSERT(VM_METHOD_TYPE_MINIMUM_BITS, VM_METHOD_TYPE_REFINED<=(1<< VM_METHOD_TYPE_MINIMUM_BITS))
st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me)
Definition: vm_method.c:1592
struct rb_cref_struct rb_cref_t
CREF (Class REFerence)
rb_method_entry_t * rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, const rb_method_definition_t *def)
Definition: vm_method.c:397
#define END_OF_ENUMERATION(key)
Definition: method.h:20
struct rb_method_alias_struct rb_method_alias_t
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:39
#define IMEMO_FL_USER1
#define offsetof(TYPE, MEMBER)
const VALUE VALUE obj
const rb_callable_method_entry_t * me
#define VM_ASSERT(expr)
#define RUBY_SYMBOL_EXPORT_BEGIN
const char const char *typedef unsigned long VALUE
#define IMEMO_FL_USER0
__inline__ const void *__restrict__ src
#define IMEMO_FL_USHIFT
#define RUBY_SYMBOL_EXPORT_END
const rb_iseq_t * iseq
__uintptr_t uintptr_t
st_data_t st_index_t
const VALUE * argv
unsigned long ID
#define IMEMO_FL_USER2
#define ANYARGS
unsigned long VALUE
Definition: ruby.h:102
ID called_id
VALUE flags
struct rb_method_definition_struct *const def
const VALUE defined_class
const VALUE owner
CREF (Class REFerence)
const rb_scope_visibility_t scope_visi
struct rb_cref_struct * next
struct rb_method_entry_struct * original_me
struct rb_hook_list_struct * hooks
VALUE(* invoker)(VALUE recv, int argc, const VALUE *argv, VALUE(*func)())
BITFIELD(rb_method_type_t, type, VM_METHOD_TYPE_MINIMUM_BITS)
enum method_optimized_type optimize_type
union rb_method_definition_struct::@41 body
struct rb_method_definition_struct *const def
ID called_id
VALUE flags
VALUE defined_class
VALUE owner
rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
rb_cref_t * cref
class reference, should be marked
struct rb_method_entry_struct * orig_me
BITFIELD(rb_method_visibility_t, method_visi, 3)
rb_method_visibility_t method_visi