Ruby
2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
|
Go to the documentation of this file.
20 # define SYMBOL_DEBUG 0
22 #ifndef CHECK_ID_SERIAL
23 # define CHECK_ID_SERIAL SYMBOL_DEBUG
26 #define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
28 #define STATIC_SYM2ID(sym) RSHIFT((unsigned long)(sym), RUBY_SPECIAL_SHIFT)
31 static ID register_static_symid_str(
ID,
VALUE);
32 #define REGISTER_SYMID(id, name) register_static_symid((id), (name), strlen(name), enc)
35 #define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
37 #define op_tbl_count numberof(op_tbl)
39 #define op_tbl_len(i) (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3)
47 for (
i =
'!';
i <=
'~'; ++
i) {
50 register_static_symid(
i, &c, 1, enc);
58 static const int ID_ENTRY_UNIT = 512;
67 #define global_symbols ruby_global_symbols
121 if ((
str = lookup_id_str(
id)) != 0) {
134 if (!(
str = lookup_id_str(
id))) {
150 sym = lookup_str_sym(
str);
156 is_special_global_name(
const char *m,
const char *e,
rb_encoding *enc)
160 if (m >= e)
return 0;
161 if (is_global_name_punct(*m)) {
164 else if (*m ==
'-') {
165 if (++m >= e)
return 0;
176 }
while (m < e &&
ISDIGIT(*m));
178 return m == e ? mb + 1 : 0;
197 const char *end =
name + nlen;
199 if (nlen < 1)
return FALSE;
206 static int ctype_titlecase = 0;
209 if (!ctype_titlecase) {
210 static const UChar cname[] =
"titlecaseletter";
211 static const UChar *
const end = cname +
sizeof(cname) - 1;
229 #define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
230 #define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
235 const char *m =
name;
236 const char *e = m +
len;
240 if (!m ||
len <= 0)
return -1;
247 if (is_special_global_name(++m, e, enc))
return type;
260 case '<': ++m;
break;
261 case '=':
if (*++m ==
'>') ++m;
break;
268 case '>':
case '=': ++m;
break;
274 case '~': ++m;
break;
275 case '=':
if (*++m ==
'=') ++m;
break;
281 if (*++m ==
'*') ++m;
285 if (*++m ==
'@') ++m;
288 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
293 if (m[1] !=
']')
goto id;
295 if (*++m ==
'=') ++m;
301 case '=':
case '~': ++m;
break;
303 if (allowed_attrset & (1
U <<
ID_JUNK))
goto id;
312 if (
len > 1 && *(e-1) ==
'=') {
325 if (m + 1 < e || *m !=
'=')
break;
328 if (!(allowed_attrset & (1
U <<
type)))
return -1;
335 return m == e ?
type : -1;
345 rb_str_symname_type(
VALUE name,
unsigned int allowed_attrset)
357 size_t idx = num / ID_ENTRY_UNIT;
372 size_t idx = num / ID_ENTRY_UNIT;
378 if (
NIL_P(result))
return 0;
401 return get_id_serial_entry(rb_id_to_serial(
id),
id, t);
456 return register_static_symid_str(
id,
str);
471 set_id_entry(num,
str,
sym);
498 must_be_dynamic_symbol(
VALUE x)
508 rb_bug(
"wrong argument: inappropriate Symbol (%p)", (
void *)x);
533 register_sym(
str, dsym);
549 unregister_sym(fstr,
sym);
610 sym = lookup_str_sym(
str);
613 return intern_str(
str, 1);
621 if (next_serial == 0) {
638 if (sym_check_asciionly(
str)) {
642 if ((
nid = next_id_base()) == (
ID)-1) {
649 return register_static_symid_str(
id,
str);
674 return intern_str(
str, 0);
727 if (enc != ascii && sym_check_asciionly(
str)) {
742 id = intern_str(
str, 0);
759 ID num = next_id_base();
763 set_id_entry(rb_id_to_serial(num), fstr,
sym);
797 return lookup_id_str(
id);
946 sym_check_asciionly(
name);
948 return lookup_str_id(
name);
978 sym_check_asciionly(
name);
980 if ((
sym = lookup_str_sym(
name)) != 0) {
993 sym_check_asciionly(
name);
995 return lookup_str_id(
name);
1005 sym_check_asciionly(
name);
1007 if ((
sym = lookup_str_sym(
name)) != 0) {
1014 #undef rb_sym_intern_ascii_cstr
VALUE rb_check_symbol(volatile VALUE *namep)
unsigned int UINT8 __attribute__((__mode__(__QI__)))
ID rb_make_internal_id(void)
VALUE rb_str_ellipsize(VALUE, long)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
STATIC_ASSERT(op_tbl_name_size, sizeof(op_tbl[0].name)==3)
const char * rb_id2name(ID id)
int rb_is_const_id(ID id)
ID rb_check_id(volatile VALUE *namep)
Returns ID for the given name if it is interned already, or 0.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
#define rb_enc_mbc_to_codepoint(p, e, enc)
st_index_t rb_str_hash(VALUE)
int rb_is_class_name(VALUE name)
VALUE rb_ident_hash_new(void)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
void rb_gc_register_mark_object(VALUE obj)
VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc)
ID rb_intern(const char *name)
void rb_gc_free_dsymbol(VALUE sym)
void rb_ary_store(VALUE ary, long idx, VALUE val)
int st_delete(st_table *tab, st_data_t *key, st_data_t *value)
#define RB_TYPE_P(obj, type)
rb_encoding * rb_enc_get(VALUE obj)
void st_add_direct(st_table *tab, st_data_t key, st_data_t value)
#define rb_enc_asciicompat(enc)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
#define RUBY_DTRACE_CREATE_HOOK(name, arg)
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
int rb_is_local_name(VALUE name)
enum ruby_id_types id_types
int rb_is_attrset_sym(VALUE sym)
VALUE rb_check_string_type(VALUE)
void rb_name_error(ID id, const char *fmt,...)
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
int rb_is_attrset_id(ID id)
#define SYMBOL_PINNED_P(sym)
void rb_fatal(const char *fmt,...)
size_t strlen(const char *)
char ary[RSTRING_EMBED_LEN_MAX+1]
int rb_enc_symname_p(const char *name, rb_encoding *enc)
int rb_is_class_id(ID id)
#define IDSET_ATTRSET_FOR_SYNTAX
#define is_const_sym(sym)
#define is_attrset_sym(sym)
st_table * st_init_table_with_size(const struct st_hash_type *type, st_index_t size)
VALUE rb_hash_delete_entry(VALUE hash, VALUE key)
void rb_raise(VALUE exc, const char *fmt,...)
int rb_str_hash_cmp(VALUE, VALUE)
VALUE rb_ary_entry(VALUE ary, long offset)
VALUE rb_sym_intern_ascii(const char *ptr, long len)
#define is_attrset_id(id)
ID rb_intern3(const char *name, long len, rb_encoding *enc)
rb_encoding * rb_ascii8bit_encoding(void)
#define MBCLEN_CHARFOUND_LEN(ret)
const typedef OnigEncodingType rb_encoding
int rb_is_instance_name(VALUE name)
VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc)
VALUE rb_convert_type_with_id(VALUE, int, const char *, ID)
int rb_is_const_name(VALUE name)
VALUE rb_ary_tmp_new(long capa)
RUBY_EXTERN VALUE rb_cSymbol
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
VALUE rb_ary_push(VALUE ary, VALUE item)
int rb_enc_to_index(rb_encoding *enc)
int rb_is_global_id(ID id)
VALUE rb_str_intern(VALUE str)
void rb_enc_set_index(VALUE obj, int idx)
VALUE rb_newobj_of(VALUE klass, VALUE flags)
#define StringValuePtr(v)
int rb_is_instance_id(ID id)
int memcmp(const void *s1, const void *s2, size_t len)
#define RB_OBJ_WRITE(a, slot, b)
int st_update(st_table *tab, st_data_t key, st_update_callback_func *func, st_data_t arg)
#define ENC_CODERANGE_BROKEN
VALUE rb_sym_all_symbols(void)
#define rb_enc_isupper(c, enc)
#define ONIGENC_IS_UNICODE(enc)
int rb_symname_p(const char *name)
#define MBCLEN_CHARFOUND_P(ret)
int st_foreach(st_table *tab, st_foreach_callback_func *func, st_data_t arg)
ID rb_intern2(const char *name, long len)
int rb_enc_str_coderange(VALUE)
void rb_bug(const char *fmt,...)
size_t rb_sym_immortal_count(void)
int rb_objspace_garbage_object_p(VALUE obj)
WARN_UNUSED_RESULT(static VALUE dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding *const enc, const ID type))
char str[HTML_ESCAPE_MAX_LEN+1]
#define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, p, end)
#define STATIC_ID2SYM(id)
int rb_is_const_sym(VALUE sym)
#define rb_enc_islower(c, enc)
#define is_instance_id(id)
int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
#define ENC_CODERANGE_7BIT
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
VALUE rb_sym_intern_ascii_cstr(const char *ptr)
rb_symbols_t ruby_global_symbols
#define STATIC_SYM2ID(sym)
void rb_name_error_str(VALUE str, const char *fmt,...)
int rb_is_local_id(ID id)
#define ONIGENC_CASE_FOLD
int rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset)
VALUE rb_sym2str(VALUE sym)
#define rb_enc_isctype(c, t, enc)
const char * rb_builtin_class_name(VALUE x)
#define is_identchar(p, e, enc)
#define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM
FUNC_MINIMIZED(VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc))
int st_lookup(st_table *tab, st_data_t key, st_data_t *value)
ID rb_intern_str(VALUE str)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
VALUE rb_str_cat(VALUE, const char *, long)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
VALUE type(ANYARGS)
ANYARGS-ed function type.
VALUE rb_to_symbol_type(VALUE obj)
rb_encoding * rb_usascii_encoding(void)
#define IDSET_ATTRSET_FOR_INTERN