Ruby 2.1.5p273(2014-11-13revision48405)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

method.h
Go to the documentation of this file.
1 /**********************************************************************
2
3 method.h -
4
5 $Author: tmm1 $
6 created at: Wed Jul 15 20:02:33 2009
7
8 Copyright (C) 2009 Koichi Sasada
9
10 **********************************************************************/
11 #ifndef METHOD_H
12 #define METHOD_H
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 typedef enum {
25 NOEX_PUBLIC = 0x00,
26 NOEX_NOSUPER = 0x01,
27 NOEX_PRIVATE = 0x02,
28 NOEX_PROTECTED = 0x04,
29 NOEX_MASK = 0x06,
30 NOEX_BASIC = 0x08,
31 NOEX_UNDEF = NOEX_NOSUPER,
32 NOEX_MODFUNC = 0x12,
33 NOEX_SUPER = 0x20,
34 NOEX_VCALL = 0x40,
35 NOEX_RESPONDS = 0x80,
36
37 NOEX_BIT_WIDTH = 8,
38 NOEX_SAFE_SHIFT_OFFSET = ((NOEX_BIT_WIDTH+3)/4)*4 /* round up to nibble */
39 } rb_method_flag_t;
40
41 #define NOEX_SAFE(n) ((int)((n) >> NOEX_SAFE_SHIFT_OFFSET) & 0x0F)
42 #define NOEX_WITH(n, s) (((s) << NOEX_SAFE_SHIFT_OFFSET) | (n) | (ruby_running ? 0 : NOEX_BASIC))
43 #define NOEX_WITH_SAFE(n) NOEX_WITH((n), rb_safe_level())
44
45 /* method data type */
46
47 typedef enum {
48 VM_METHOD_TYPE_ISEQ,
49 VM_METHOD_TYPE_CFUNC,
50 VM_METHOD_TYPE_ATTRSET,
51 VM_METHOD_TYPE_IVAR,
52 VM_METHOD_TYPE_BMETHOD,
53 VM_METHOD_TYPE_ZSUPER,
54 VM_METHOD_TYPE_UNDEF,
55 VM_METHOD_TYPE_NOTIMPLEMENTED,
56 VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
57 VM_METHOD_TYPE_MISSING, /* wrapper for method_missing(id) */
58 VM_METHOD_TYPE_REFINED,
59
60 END_OF_ENUMERATION(VM_METHOD_TYPE)
61 } rb_method_type_t;
62
63 struct rb_call_info_struct;
64
65 typedef struct rb_method_cfunc_struct {
66 VALUE (*func)(ANYARGS);
67 VALUE (*invoker)(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv);
68 int argc;
69 } rb_method_cfunc_t;
70
71 typedef struct rb_method_attr_struct {
72 ID id;
73 const VALUE location;
74 } rb_method_attr_t;
75
76 typedef struct rb_iseq_struct rb_iseq_t;
77
78 typedef struct rb_method_definition_struct {
79 rb_method_type_t type; /* method type */
80 ID original_id;
81 union {
82 rb_iseq_t * const iseq; /* should be mark */
83 rb_method_cfunc_t cfunc;
84 rb_method_attr_t attr;
85 const VALUE proc; /* should be mark */
86 enum method_optimized_type {
87 OPTIMIZED_METHOD_TYPE_SEND,
88 OPTIMIZED_METHOD_TYPE_CALL,
89
90 OPTIMIZED_METHOD_TYPE__MAX
91 } optimize_type;
92 struct rb_method_entry_struct *orig_me;
93 } body;
94 int alias_count;
95 } rb_method_definition_t;
96
97 typedef struct rb_method_entry_struct {
98 rb_method_flag_t flag;
99 char mark;
100 rb_method_definition_t *def;
101 ID called_id;
102 VALUE klass; /* should be mark */
103 } rb_method_entry_t;
104
105 struct unlinked_method_entry_list_entry {
106 struct unlinked_method_entry_list_entry *next;
107 rb_method_entry_t *me;
108 };
109
110 #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
111
112 void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex);
113 rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex);
114 rb_method_entry_t *rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr);
115 rb_method_entry_t *rb_method_entry_at(VALUE obj, ID id);
116 void rb_add_refined_method_entry(VALUE refined_class, ID mid);
117 rb_method_entry_t *rb_resolve_refined_method(VALUE refinements,
118 const rb_method_entry_t *me,
119 VALUE *defined_class_ptr);
120 rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id,
121 VALUE *defined_class_ptr);
122 rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id,
123 VALUE *defined_class_ptr);
124
125 rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *define_class_ptr);
126 rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);
127
128 int rb_method_entry_arity(const rb_method_entry_t *me);
129 int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
130 st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
131
132 VALUE rb_method_entry_location(rb_method_entry_t *me);
133 VALUE rb_mod_method_location(VALUE mod, ID id);
134 VALUE rb_obj_method_location(VALUE obj, ID id);
135
136 void rb_mark_method_entry(const rb_method_entry_t *me);
137 void rb_free_method_entry(rb_method_entry_t *me);
138 void rb_sweep_method_entry(void *vm);
139 void rb_free_m_tbl(st_table *tbl);
140 void rb_free_m_tbl_wrapper(struct method_table_wrapper *wrapper);
141
142 #endif /* METHOD_H */
method_table_wrapper
Definition: internal.h:282
unlinked_method_entry_list_entry::next
struct unlinked_method_entry_list_entry * next
Definition: method.h:106
rb_method_entry_struct::mark
char mark
Definition: method.h:99
VM_METHOD_TYPE_MISSING
Definition: method.h:57
rb_method_definition_struct
Definition: method.h:78
rb_method_attr_struct
Definition: method.h:71
NOEX_RESPONDS
Definition: method.h:35
rb_method_definition_struct::type
rb_method_type_t type
Definition: method.h:79
rb_method_definition_struct::attr
rb_method_attr_t attr
Definition: method.h:84
st_table
Definition: st.h:69
rb_method_definition_struct::OPTIMIZED_METHOD_TYPE_CALL
Definition: method.h:88
rb_method_attr_struct::location
const VALUE location
Definition: method.h:73
rb_method_entry_struct::flag
rb_method_flag_t flag
Definition: method.h:98
NOEX_SUPER
Definition: method.h:33
rb_mod_method_location
VALUE rb_mod_method_location(VALUE mod, ID id)
Definition: proc.c:2160
rb_method_entry_without_refinements
rb_method_entry_t * rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class_ptr)
Definition: vm_method.c:701
rb_method_definition_struct::orig_me
struct rb_method_entry_struct * orig_me
Definition: method.h:92
rb_method_attr_t
struct rb_method_attr_struct rb_method_attr_t
VM_METHOD_TYPE_ISEQ
Definition: method.h:48
rb_method_flag_t
rb_method_flag_t
Definition: method.h:24
rb_mark_method_entry
void rb_mark_method_entry(const rb_method_entry_t *me)
Definition: gc.c:3417
NOEX_MODFUNC
Definition: method.h:32
rb_method_entry_struct::called_id
ID called_id
Definition: method.h:101
rb_sweep_method_entry
void rb_sweep_method_entry(void *vm)
Definition: vm_method.c:137
rb_method_definition_struct::proc
const VALUE proc
Definition: method.h:85
rb_method_definition_struct::body
union rb_method_definition_struct::@126 body
rb_method_entry_t
struct rb_method_entry_struct rb_method_entry_t
st_index_t
st_data_t st_index_t
Definition: st.h:48
NOEX_BASIC
Definition: method.h:30
VM_METHOD_TYPE_BMETHOD
Definition: method.h:52
rb_method_attr_struct::id
ID id
Definition: method.h:72
rb_method_cfunc_struct::argc
int argc
Definition: method.h:68
rb_method_definition_t
struct rb_method_definition_struct rb_method_definition_t
rb_method_entry_eq
int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2)
Definition: vm_method.c:1156
VM_METHOD_TYPE_REFINED
Definition: method.h:58
rb_method_definition_struct::original_id
ID original_id
Definition: method.h:80
NOEX_MASK
Definition: method.h:29
rb_method_definition_struct::cfunc
rb_method_cfunc_t cfunc
Definition: method.h:83
rb_method_entry_get_without_cache
rb_method_entry_t * rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *define_class_ptr)
Definition: vm_method.c:564
rb_method_definition_struct::OPTIMIZED_METHOD_TYPE__MAX
Definition: method.h:90
VM_METHOD_TYPE_UNDEF
Definition: method.h:54
rb_free_method_entry
void rb_free_method_entry(rb_method_entry_t *me)
Definition: vm_method.c:178
rb_method_definition_struct::optimize_type
enum rb_method_definition_struct::@126::method_optimized_type optimize_type
rb_free_m_tbl_wrapper
void rb_free_m_tbl_wrapper(struct method_table_wrapper *wrapper)
Definition: gc.c:1450
rb_method_entry_arity
int rb_method_entry_arity(const rb_method_entry_t *me)
Definition: proc.c:2020
argc
int argc
Definition: ruby.c:131
rb_method_entry_struct
Definition: method.h:97
rb_resolve_refined_method
rb_method_entry_t * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me, VALUE *defined_class_ptr)
Definition: vm_method.c:655
rb_method_entry
rb_method_entry_t * rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr)
Definition: vm_method.c:617
rb_method_cfunc_struct::func
VALUE(* func)(ANYARGS)
Definition: method.h:66
rb_method_entry_struct::klass
VALUE klass
Definition: method.h:102
VM_METHOD_TYPE_NOTIMPLEMENTED
Definition: method.h:55
rb_method_type_t
rb_method_type_t
Definition: method.h:47
rb_method_cfunc_struct
Definition: method.h:65
VM_METHOD_TYPE_ATTRSET
Definition: method.h:50
rb_method_entry_with_refinements
rb_method_entry_t * rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class_ptr)
Definition: vm_method.c:683
rb_method_definition_struct::iseq
rb_iseq_t *const iseq
Definition: method.h:82
func
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
rb_add_method
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex)
Definition: vm_method.c:428
NOEX_SAFE_SHIFT_OFFSET
Definition: method.h:38
internal.h
ID
unsigned long ID
Definition: ruby.h:89
rb_hash_method_entry
st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me)
Definition: vm_method.c:1238
type
int type
Definition: tcltklib.c:112
VALUE
unsigned long VALUE
Definition: ruby.h:88
NOEX_PROTECTED
Definition: method.h:28
rb_method_cfunc_struct::invoker
VALUE(* invoker)(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
Definition: method.h:67
VM_METHOD_TYPE_OPTIMIZED
Definition: method.h:56
rb_method_cfunc_t
struct rb_method_cfunc_struct rb_method_cfunc_t
rb_method_entry_location
VALUE rb_method_entry_location(rb_method_entry_t *me)
Definition: proc.c:2153
rb_method_entry_at
rb_method_entry_t * rb_method_entry_at(VALUE obj, ID id)
Definition: vm_method.c:552
END_OF_ENUMERATION
#define END_OF_ENUMERATION(key)
Definition: method.h:20
rb_method_entry_struct::def
rb_method_definition_t * def
Definition: method.h:100
ANYARGS
#define ANYARGS
Definition: defines.h:98
rb_call_info_struct
Definition: vm_core.h:155
rb_method_definition_struct::OPTIMIZED_METHOD_TYPE_SEND
Definition: method.h:87
rb_add_refined_method_entry
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
Definition: vm_method.c:221
hash
static unsigned int hash(const char *str, unsigned int len)
Definition: lex.c:56
rb_iseq_struct
Definition: vm_core.h:206
NOEX_BIT_WIDTH
Definition: method.h:37
unlinked_method_entry_list_entry::me
rb_method_entry_t * me
Definition: method.h:107
rb_method_definition_struct::alias_count
int alias_count
Definition: method.h:94
VM_METHOD_TYPE_CFUNC
Definition: method.h:49
rb_method_entry_set
rb_method_entry_t * rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex)
Definition: vm_method.c:504
NOEX_PUBLIC
Definition: method.h:25
mod
#define mod(x, y)
Definition: date_strftime.c:28
rb_add_method_cfunc
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc, rb_method_flag_t noex)
Definition: vm_method.c:99
VM_METHOD_TYPE_IVAR
Definition: method.h:51
NOEX_UNDEF
Definition: method.h:31
NOEX_VCALL
Definition: method.h:34
NOEX_PRIVATE
Definition: method.h:27
rb_obj_method_location
VALUE rb_obj_method_location(VALUE obj, ID id)
Definition: proc.c:2167
unlinked_method_entry_list_entry
Definition: method.h:105
VM_METHOD_TYPE_ZSUPER
Definition: method.h:53
argv
char ** argv
Definition: ruby.c:132
NOEX_NOSUPER
Definition: method.h:26
rb_free_m_tbl
void rb_free_m_tbl(st_table *tbl)
Definition: gc.c:1443