Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 108 lines (89 sloc) 3.31 kB
311a41b rewrote class flags to not use the version field anymore, better typi…
Laurent Sansonetti authored
1 /*
2 * This file is covered by the Ruby license. See COPYING for more details.
3 *
4 * Copyright (C) 2010, Apple Inc. All rights reserved.
5 */
6
7 #ifndef __CLASS_H_
8 #define __CLASS_H_
9
10 #if defined(__cplusplus)
11 extern "C" {
12 #endif
13
8c55086 better ivar slot system for RubyObject + misc fixes/cleanup
Laurent Sansonetti authored
14 #define RCLASS_IS_OBJECT_SUBCLASS (1<<1) /* class is a true RubyObject subclass */
311a41b rewrote class flags to not use the version field anymore, better typi…
Laurent Sansonetti authored
15 #define RCLASS_IS_RUBY_CLASS (1<<2) /* class was created from Ruby */
16 #define RCLASS_IS_MODULE (1<<3) /* class represents a Ruby Module */
17 #define RCLASS_IS_SINGLETON (1<<4) /* class represents a singleton */
18 #define RCLASS_IS_FROZEN (1<<5) /* class is frozen */
19 #define RCLASS_IS_TAINTED (1<<6) /* class is tainted */
20 #define RCLASS_IS_INCLUDED (1<<10) /* module is included */
21 #define RCLASS_HAS_ROBJECT_ALLOC (1<<11) /* class uses the default RObject alloc */
22 #define RCLASS_SCOPE_PRIVATE (1<<12) /* class opened for private methods */
23 #define RCLASS_SCOPE_PROTECTED (1<<13) /* class opened for protected methods */
24 #define RCLASS_SCOPE_MOD_FUNC (1<<14) /* class opened for module_function methods */
25 #define RCLASS_KVO_CHECK_DONE (1<<15) /* class created by KVO and flags merged */
26
27 unsigned long rb_class_get_flags(Class k);
28 void rb_class_set_flags(Class k, unsigned long flags);
29
30 #define RCLASS_VERSION(m) (rb_class_get_flags((Class)m))
31 #define RCLASS_SET_VERSION(m,f) (rb_class_set_flags((Class)m, (unsigned long)f))
32 #define RCLASS_SET_VERSION_FLAG(m,f) (RCLASS_SET_VERSION((Class)m, (RCLASS_VERSION(m) | f)))
33
34 #define RCLASS_RUBY(m) ((RCLASS_VERSION(m) & RCLASS_IS_RUBY_CLASS) == RCLASS_IS_RUBY_CLASS)
35 #define RCLASS_MODULE(m) ((RCLASS_VERSION(m) & RCLASS_IS_MODULE) == RCLASS_IS_MODULE)
36 #define RCLASS_SINGLETON(m) ((RCLASS_VERSION(m) & RCLASS_IS_SINGLETON) == RCLASS_IS_SINGLETON)
37
38 CFMutableDictionaryRef rb_class_ivar_dict(VALUE);
39 CFMutableDictionaryRef rb_class_ivar_dict_or_create(VALUE);
40 void rb_class_ivar_set_dict(VALUE, CFMutableDictionaryRef);
41
002ed5d now compile some of the VM primitives into bitcode that will be added…
Laurent Sansonetti authored
42 typedef enum {
43 SCOPE_DEFAULT = 0, // public for everything but Object
44 SCOPE_PUBLIC,
45 SCOPE_PRIVATE,
46 SCOPE_PROTECTED,
47 SCOPE_MODULE_FUNC,
48 } rb_vm_scope_t;
49
50 static inline void
51 rb_vm_check_if_module(VALUE mod)
52 {
53 switch (TYPE(mod)) {
54 case T_CLASS:
55 case T_MODULE:
56 break;
57
58 default:
59 rb_raise(rb_eTypeError, "%s is not a class/module",
60 RSTRING_PTR(rb_inspect(mod)));
61 }
62 }
63
64 static inline void
65 rb_vm_set_current_scope(VALUE mod, rb_vm_scope_t scope)
66 {
67 if (scope == SCOPE_DEFAULT) {
68 scope = mod == rb_cObject ? SCOPE_PRIVATE : SCOPE_PUBLIC;
69 }
70 long v = RCLASS_VERSION(mod);
71 switch (scope) {
72 case SCOPE_PUBLIC:
73 v &= ~RCLASS_SCOPE_PRIVATE;
74 v &= ~RCLASS_SCOPE_PROTECTED;
75 v &= ~RCLASS_SCOPE_MOD_FUNC;
76 break;
77
78 case SCOPE_PRIVATE:
79 v |= RCLASS_SCOPE_PRIVATE;
80 v &= ~RCLASS_SCOPE_PROTECTED;
81 v &= ~RCLASS_SCOPE_MOD_FUNC;
82 break;
83
84 case SCOPE_PROTECTED:
85 v &= ~RCLASS_SCOPE_PRIVATE;
86 v |= RCLASS_SCOPE_PROTECTED;
87 v &= ~RCLASS_SCOPE_MOD_FUNC;
88 break;
89
90 case SCOPE_MODULE_FUNC:
91 v &= ~RCLASS_SCOPE_PRIVATE;
92 v &= ~RCLASS_SCOPE_PROTECTED;
93 v |= RCLASS_SCOPE_MOD_FUNC;
94 break;
95
96 case SCOPE_DEFAULT:
97 abort(); // handled earlier
98 }
99
100 RCLASS_SET_VERSION(mod, v);
101 }
102
311a41b rewrote class flags to not use the version field anymore, better typi…
Laurent Sansonetti authored
103 #if defined(__cplusplus)
104 } // extern "C"
105 #endif
106
107 #endif // __CLASS_H_
Something went wrong with that request. Please try again.