2 #define RUBY_SYMBOL_H 1
3 /**********************************************************************
8 created at: Tue Jul 8 15:49:54 JST 2014
10 Copyright (C) 2014 Yukihiro Matsumoto
12 **********************************************************************/
15 #include "ruby/encoding.h"
17 #define DYNAMIC_ID_P(id) (!(id&ID_STATIC_SYM)&&id>tLAST_OP_ID)
18 #define STATIC_ID2SYM(id) (((VALUE)(id)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
20 #ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
21 #define rb_id2sym(id) \
22 RB_GNUC_EXTENSION_BLOCK(__builtin_constant_p(id) && !DYNAMIC_ID_P(id) ? \
23 STATIC_ID2SYM(id) : rb_id2sym(id))
33 #define RSYMBOL(obj) ((struct RSymbol *)(obj))
35 #define is_notop_id(id) ((id)>tLAST_OP_ID)
36 #define is_local_id(id) (id_type(id)==ID_LOCAL)
37 #define is_global_id(id) (id_type(id)==ID_GLOBAL)
38 #define is_instance_id(id) (id_type(id)==ID_INSTANCE)
39 #define is_attrset_id(id) ((id)==idASET||id_type(id)==ID_ATTRSET)
40 #define is_const_id(id) (id_type(id)==ID_CONST)
41 #define is_class_id(id) (id_type(id)==ID_CLASS)
42 #define is_junk_id(id) (id_type(id)==ID_JUNK)
47 if (is_notop_id(id
)) {
48 return (int)(id
&ID_SCOPE_MASK
);
55 typedef uint32_t rb_id_serial_t
;
56 static const uint32_t RB_ID_SERIAL_MAX
= /* 256M on LP32 */
58 ((sizeof(ID
)-sizeof(rb_id_serial_t
))*CHAR_BIT
< RUBY_ID_SCOPE_SHIFT
?
59 RUBY_ID_SCOPE_SHIFT
: 0);
62 rb_id_serial_t last_id
;
65 VALUE dsymbol_fstr_hash
;
68 static inline rb_id_serial_t
69 rb_id_to_serial(ID id
)
71 if (is_notop_id(id
)) {
72 return (rb_id_serial_t
)(id
>> ID_SCOPE_SHIFT
);
75 return (rb_id_serial_t
)id
;
83 if (STATIC_SYM_P(sym
)) {
84 id
= RSHIFT(sym
, RUBY_SPECIAL_SHIFT
);
85 if (id
<=tLAST_OP_ID
) {
90 id
= RSYMBOL(sym
)->id
;
92 return (int)(id
&ID_SCOPE_MASK
);
95 #define is_local_sym(sym) (sym_type(sym)==ID_LOCAL)
96 #define is_global_sym(sym) (sym_type(sym)==ID_GLOBAL)
97 #define is_instance_sym(sym) (sym_type(sym)==ID_INSTANCE)
98 #define is_attrset_sym(sym) (sym_type(sym)==ID_ATTRSET)
99 #define is_const_sym(sym) (sym_type(sym)==ID_CONST)
100 #define is_class_sym(sym) (sym_type(sym)==ID_CLASS)
101 #define is_junk_sym(sym) (sym_type(sym)==ID_JUNK)
103 RUBY_FUNC_EXPORTED
const uint_least32_t ruby_global_name_punct_bits
[(0x7e - 0x20 + 31) / 32];
106 is_global_name_punct(const int c
)
108 if (c
<= 0x20 || 0x7e < c
) return 0;
109 return (ruby_global_name_punct_bits
[(c
- 0x20) / 32] >> (c
% 32)) & 1;
112 RUBY_SYMBOL_EXPORT_BEGIN
114 int rb_enc_symname_type(const char *name
, long len
, rb_encoding
*enc
, unsigned int allowed_attrset
);
115 size_t rb_sym_immortal_count(void);
117 RUBY_SYMBOL_EXPORT_END