19 # define SYMBOL_DEBUG 0 22 #define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK) 24 #define STATIC_SYM2ID(sym) RSHIFT((unsigned long)(sym), RUBY_SPECIAL_SHIFT) 27 static ID register_static_symid_str(
ID,
VALUE);
28 #define REGISTER_SYMID(id, name) register_static_symid((id), (name), strlen(name), enc) 31 #define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p))) 33 #define op_tbl_count numberof(op_tbl) 35 #define op_tbl_len(i) (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3) 43 for (i =
'!'; i <=
'~'; ++i) {
46 register_static_symid(i, &c, 1, enc);
54 static const int ID_ENTRY_UNIT = 512;
62 static struct symbols {
66 VALUE dsymbol_fstr_hash;
78 global_symbols.dsymbol_fstr_hash = dsym_fstrs;
123 if ((str = lookup_id_str(
id)) != 0) {
136 if (!(str = lookup_id_str(
id))) {
148 (
int)
sizeof(id_types[0]), id_types[scope], (
VALUE)
id);
152 sym = lookup_str_sym(str);
153 id = sym ?
rb_sym2id(sym) : intern_str(str, 1);
160 return attrsetname_to_attr(
rb_id2str(
id));
164 is_special_global_name(
const char *m,
const char *e,
rb_encoding *enc)
168 if (m >= e)
return 0;
169 if (is_global_name_punct(*m)) {
172 else if (*m ==
'-') {
173 if (++m >= e)
return 0;
184 }
while (m < e &&
ISDIGIT(*m));
186 return m == e ? mb + 1 : 0;
201 #define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST)) 202 #define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET)) 205 rb_enc_symname_type(
const char *name,
long len,
rb_encoding *enc,
unsigned int allowed_attrset)
207 const char *m =
name;
208 const char *e = m +
len;
212 if (!m || len <= 0)
return -1;
219 if (is_special_global_name(++m, e, enc))
return type;
232 case '<': ++m;
break;
233 case '=':
if (*++m ==
'>') ++m;
break;
240 case '>':
case '=': ++m;
break;
246 case '~': ++m;
break;
247 case '=':
if (*++m ==
'=') ++m;
break;
253 if (*++m ==
'*') ++m;
257 if (*++m ==
'@') ++m;
260 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
265 if (m[1] !=
']')
goto id;
267 if (*++m ==
'=') ++m;
273 case '=':
case '~': ++m;
break;
275 if (allowed_attrset & (1
U <<
ID_JUNK))
goto id;
284 if (len > 1 && *(e-1) ==
'=') {
285 type = rb_enc_symname_type(name, len-1, enc, allowed_attrset);
297 if (m + 1 < e || *m !=
'=')
break;
300 if (!(allowed_attrset & (1
U << type)))
return -1;
307 return m == e ? type : -1;
317 rb_str_symname_type(
VALUE name,
unsigned int allowed_attrset)
321 int type = rb_enc_symname_type(ptr, len,
rb_enc_get(name), allowed_attrset);
329 size_t idx = num / ID_ENTRY_UNIT;
330 VALUE ary, ids = global_symbols.ids;
343 if (num && num <= global_symbols.last_id) {
344 size_t idx = num / ID_ENTRY_UNIT;
345 VALUE ids = global_symbols.ids;
349 if (!
NIL_P(result))
return result;
357 __attribute__((unused))
388 register_sym_update_callback, (
st_data_t)sym);
407 return register_static_symid_str(
id, str);
411 register_static_symid_str(
ID id,
VALUE str)
421 register_sym(str, sym);
422 set_id_entry(num, str, sym);
428 sym_check_asciionly(
VALUE str)
449 must_be_dynamic_symbol(
VALUE x)
459 rb_bug(
"wrong argument: inappropriate Symbol (%p)", (
void *)x);
482 RSYMBOL(dsym)->hashval = RSHIFT((
long)hashval, 1);
484 register_sym(str, dsym);
493 dsymbol_check(
const VALUE sym)
500 unregister_sym(fstr, sym);
509 lookup_str_id(
VALUE str)
531 lookup_str_sym(
const VALUE str)
538 sym = dsymbol_check(sym);
561 sym = lookup_str_sym(str);
564 return intern_str(str, 1);
572 if (next_serial == 0) {
576 const size_t num = ++global_symbols.last_id;
582 intern_str(
VALUE str,
int mutable)
589 if (sym_check_asciionly(str)) {
593 if ((nid = next_id_base()) == (
ID)-1) {
600 return register_static_symid_str(
id, str);
619 VALUE sym = lookup_str_sym(str);
625 return intern_str(str, 0);
635 unregister_sym(str, sym);
669 VALUE sym = lookup_str_sym(str);
678 if (enc != ascii && sym_check_asciionly(str)) {
690 return dsymbol_alloc(
rb_cSymbol, str, enc, type);
692 id = intern_str(str, 0);
705 sym = dsymbol_check(sym);
709 ID num = next_id_base();
713 set_id_entry(rb_id_to_serial(num), fstr, sym);
747 return lookup_id_str(
id);
809 st_foreach(global_symbols.str_sym, symbols_i, ary);
816 return (
size_t)global_symbols.last_id;
942 sym_check_asciionly(name);
944 return lookup_str_id(name);
959 name = dsymbol_check(name);
974 sym_check_asciionly(name);
976 if ((sym = lookup_str_sym(name)) != 0) {
989 sym_check_asciionly(name);
991 return lookup_str_id(name);
1001 sym_check_asciionly(name);
1003 if ((sym = lookup_str_sym(name)) != 0) {
1010 #undef rb_sym_intern_cstr 1011 #undef rb_sym_intern_ascii_cstr 1048 attrsetname_to_attr_id(
VALUE name)
1058 if ((
id = lookup_str_id(localname)) != 0) {
1066 attrsetname_to_attr(
VALUE name)
1069 return attrsetname_to_attr_id(name);
1078 return rb_str_symname_type(name, 0) ==
ID_CONST;
1084 return rb_str_symname_type(name, 0) ==
ID_CLASS;
1090 return rb_str_symname_type(name, 0) ==
ID_GLOBAL;
1096 return rb_str_symname_type(name, 0) ==
ID_INSTANCE;
1108 return rb_str_symname_type(name, 0) ==
ID_LOCAL;
1114 switch (rb_str_symname_type(name, 0)) {
void rb_fatal(const char *fmt,...)
int rb_is_instance_id(ID id)
ID rb_intern2(const char *name, long len)
ID rb_check_id(volatile VALUE *namep)
Returns ID for the given name if it is interned already, or 0.
ID rb_make_internal_id(void)
void rb_bug(const char *fmt,...)
VALUE rb_ary_entry(VALUE ary, long offset)
size_t strlen(const char *)
VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc)
#define IDSET_ATTRSET_FOR_SYNTAX
#define is_const_sym(sym)
int rb_is_class_name(VALUE name)
VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc)
int rb_is_attrset_sym(VALUE sym)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_str_cat(VALUE, const char *, long)
VALUE rb_sym_intern_ascii(const char *ptr, long len)
#define is_local_sym(sym)
int rb_is_const_id(ID id)
VALUE rb_ary_push(VALUE ary, VALUE item)
ID rb_intern3(const char *name, long len, rb_encoding *enc)
int rb_is_local_name(VALUE name)
VALUE rb_ary_tmp_new(long capa)
int rb_enc_str_coderange(VALUE)
int rb_is_global_sym(VALUE sym)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
int rb_objspace_garbage_object_p(VALUE obj)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
st_index_t rb_str_hash(VALUE)
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
int rb_enc_symname_p(const char *name, rb_encoding *enc)
void rb_name_error(ID id, const char *fmt,...)
enum ruby_id_types id_types
int rb_is_method_name(VALUE name)
VALUE rb_check_symbol(volatile VALUE *namep)
#define ENC_CODERANGE_7BIT
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
#define is_attrset_sym(sym)
int rb_is_junk_sym(VALUE sym)
#define RB_TYPE_P(obj, type)
#define is_identchar(p, e, enc)
VALUE rb_sym_all_symbols(void)
int rb_is_junk_name(VALUE name)
#define is_global_sym(sym)
int rb_is_const_name(VALUE name)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
int rb_is_class_id(ID id)
int rb_is_global_name(VALUE name)
#define st_init_table_with_size
VALUE rb_hash_delete_entry(VALUE hash, VALUE key)
#define SYMBOL_PINNED_P(sym)
void rb_ary_store(VALUE ary, long idx, VALUE val)
#define is_instance_sym(sym)
char ary[RSTRING_EMBED_LEN_MAX+1]
int rb_is_class_sym(VALUE sym)
void rb_gc_register_mark_object(VALUE obj)
#define ENC_CODERANGE_BROKEN
#define is_attrset_id(id)
#define RUBY_DTRACE_CREATE_HOOK(name, arg)
void rb_name_error_str(VALUE str, const char *fmt,...)
int rb_is_local_sym(VALUE sym)
int rb_str_hash_cmp(VALUE, VALUE)
const char * rb_id2name(ID id)
int rb_is_instance_name(VALUE name)
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
#define STATIC_SYM2ID(sym)
VALUE rb_sym2str(VALUE sym)
ID rb_intern(const char *name)
rb_encoding * rb_usascii_encoding(void)
int rb_symname_p(const char *name)
#define IDSET_ATTRSET_FOR_INTERN
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
VALUE rb_sym_intern_ascii_cstr(const char *ptr)
#define rb_enc_asciicompat(enc)
VALUE rb_str_ellipsize(VALUE, long)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
void rb_gc_free_dsymbol(VALUE sym)
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
FUNC_MINIMIZED(VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc))
int rb_is_global_id(ID id)
int rb_is_const_sym(VALUE sym)
const char * rb_builtin_class_name(VALUE x)
register unsigned int len
#define RB_OBJ_WRITE(a, slot, b)
int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
rb_encoding * rb_enc_get(VALUE obj)
VALUE rb_sym_intern_cstr(const char *ptr, rb_encoding *enc)
VALUE rb_ident_hash_new(void)
int rb_is_instance_sym(VALUE sym)
#define is_instance_id(id)
VALUE rb_str_intern(VALUE str)
STATIC_ASSERT(op_tbl_name_size, sizeof(op_tbl[0].name)==3)
VALUE rb_newobj_of(VALUE klass, VALUE flags)
VALUE rb_check_string_type(VALUE)
int rb_is_attrset_name(VALUE name)
ID rb_intern_str(VALUE str)
#define STATIC_ID2SYM(id)
size_t rb_sym_immortal_count(void)
int rb_is_local_id(ID id)
#define is_class_sym(sym)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
int rb_is_attrset_id(ID id)
#define StringValuePtr(v)
VALUE rb_str_new_frozen(VALUE)
rb_encoding * rb_ascii8bit_encoding(void)
RUBY_EXTERN VALUE rb_cSymbol
WARN_UNUSED_RESULT(static VALUE dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding *const enc, const ID type))