summaryrefslogtreecommitdiff
path: root/symbol.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-07-21 09:23:58 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2022-07-21 09:42:04 -0700
commit5b21e94bebed90180d8ff63dad03b8b948361089 (patch)
treef9f7196d84b51b7a3a8001658e4391a63b71c396 /symbol.c
parent3ff53c8e04ecc91e0190de6d5950ecce2a2ea188 (diff)
downloadruby-5b21e94bebed90180d8ff63dad03b8b948361089.tar.gz
Expand tabs [ci skip]
[Misc #18891]
Diffstat (limited to 'symbol.c')
-rw-r--r--symbol.c336
1 files changed, 168 insertions, 168 deletions
diff --git a/symbol.c b/symbol.c
index 94fa09d19c..e89879982f 100644
--- a/symbol.c
+++ b/symbol.c
@@ -55,13 +55,13 @@ Init_op_tbl(void)
rb_encoding *const enc = rb_usascii_encoding();
for (i = '!'; i <= '~'; ++i) {
- if (!ISALNUM(i) && i != '_') {
- char c = (char)i;
- register_static_symid(i, &c, 1, enc);
- }
+ if (!ISALNUM(i) && i != '_') {
+ char c = (char)i;
+ register_static_symid(i, &c, 1, enc);
+ }
}
for (i = 0; i < op_tbl_count; ++i) {
- register_static_symid(op_tbl[i].token, op_tbl[i].name, op_tbl_len(i), enc);
+ register_static_symid(op_tbl[i].token, op_tbl[i].name, op_tbl_len(i), enc);
}
}
@@ -116,49 +116,49 @@ rb_id_attrset(ID id)
int scope;
if (!is_notop_id(id)) {
- switch (id) {
- case tAREF: case tASET:
- return tASET; /* only exception */
- }
- rb_name_error(id, "cannot make operator ID :%"PRIsVALUE" attrset",
- rb_id2str(id));
+ switch (id) {
+ case tAREF: case tASET:
+ return tASET; /* only exception */
+ }
+ rb_name_error(id, "cannot make operator ID :%"PRIsVALUE" attrset",
+ rb_id2str(id));
}
else {
- scope = id_type(id);
- switch (scope) {
- case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL:
- case ID_CONST: case ID_CLASS: case ID_JUNK:
- break;
- case ID_ATTRSET:
- return id;
- default:
- {
- if ((str = lookup_id_str(id)) != 0) {
- rb_name_error(id, "cannot make unknown type ID %d:%"PRIsVALUE" attrset",
- scope, str);
- }
- else {
- rb_name_error_str(Qnil, "cannot make unknown type anonymous ID %d:%"PRIxVALUE" attrset",
- scope, (VALUE)id);
- }
- }
- }
+ scope = id_type(id);
+ switch (scope) {
+ case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL:
+ case ID_CONST: case ID_CLASS: case ID_JUNK:
+ break;
+ case ID_ATTRSET:
+ return id;
+ default:
+ {
+ if ((str = lookup_id_str(id)) != 0) {
+ rb_name_error(id, "cannot make unknown type ID %d:%"PRIsVALUE" attrset",
+ scope, str);
+ }
+ else {
+ rb_name_error_str(Qnil, "cannot make unknown type anonymous ID %d:%"PRIxVALUE" attrset",
+ scope, (VALUE)id);
+ }
+ }
+ }
}
/* make new symbol and ID */
if (!(str = lookup_id_str(id))) {
- static const char id_types[][8] = {
- "local",
- "instance",
- "invalid",
- "global",
- "attrset",
- "const",
- "class",
- "junk",
- };
- rb_name_error(id, "cannot make anonymous %.*s ID %"PRIxVALUE" attrset",
- (int)sizeof(id_types[0]), id_types[scope], (VALUE)id);
+ static const char id_types[][8] = {
+ "local",
+ "instance",
+ "invalid",
+ "global",
+ "attrset",
+ "const",
+ "class",
+ "junk",
+ };
+ rb_name_error(id, "cannot make anonymous %.*s ID %"PRIxVALUE" attrset",
+ (int)sizeof(id_types[0]), id_types[scope], (VALUE)id);
}
str = rb_str_dup(str);
rb_str_cat(str, "=", 1);
@@ -174,21 +174,21 @@ is_special_global_name(const char *m, const char *e, rb_encoding *enc)
if (m >= e) return 0;
if (is_global_name_punct(*m)) {
- ++m;
+ ++m;
}
else if (*m == '-') {
- if (++m >= e) return 0;
- if (is_identchar(m, e, enc)) {
- if (!ISASCII(*m)) mb = 1;
- m += rb_enc_mbclen(m, e, enc);
- }
+ if (++m >= e) return 0;
+ if (is_identchar(m, e, enc)) {
+ if (!ISASCII(*m)) mb = 1;
+ m += rb_enc_mbclen(m, e, enc);
+ }
}
else {
- if (!ISDIGIT(*m)) return 0;
- do {
- if (!ISASCII(*m)) mb = 1;
- ++m;
- } while (m < e && ISDIGIT(*m));
+ if (!ISDIGIT(*m)) return 0;
+ do {
+ if (!ISASCII(*m)) mb = 1;
+ ++m;
+ } while (m < e && ISDIGIT(*m));
}
return m == e ? mb + 1 : 0;
}
@@ -218,25 +218,25 @@ rb_sym_constant_char_p(const char *name, long nlen, rb_encoding *enc)
len = MBCLEN_CHARFOUND_LEN(c);
c = rb_enc_mbc_to_codepoint(name, end, enc);
if (ONIGENC_IS_UNICODE(enc)) {
- static int ctype_titlecase = 0;
- if (rb_enc_isupper(c, enc)) return TRUE;
- if (rb_enc_islower(c, enc)) return FALSE;
- if (!ctype_titlecase) {
- static const UChar cname[] = "titlecaseletter";
- static const UChar *const end = cname + sizeof(cname) - 1;
- ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
- }
- if (rb_enc_isctype(c, ctype_titlecase, enc)) return TRUE;
+ static int ctype_titlecase = 0;
+ if (rb_enc_isupper(c, enc)) return TRUE;
+ if (rb_enc_islower(c, enc)) return FALSE;
+ if (!ctype_titlecase) {
+ static const UChar cname[] = "titlecaseletter";
+ static const UChar *const end = cname + sizeof(cname) - 1;
+ ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
+ }
+ if (rb_enc_isctype(c, ctype_titlecase, enc)) return TRUE;
}
else {
- /* fallback to case-folding */
- OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
- const OnigUChar *beg = (const OnigUChar *)name;
- int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
- &beg, (const OnigUChar *)end,
- fold, enc);
- if (r > 0 && (r != len || memcmp(fold, name, r)))
- return TRUE;
+ /* fallback to case-folding */
+ OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
+ const OnigUChar *beg = (const OnigUChar *)name;
+ int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
+ &beg, (const OnigUChar *)end,
+ fold, enc);
+ if (r > 0 && (r != len || memcmp(fold, name, r)))
+ return TRUE;
}
return FALSE;
}
@@ -286,7 +286,7 @@ enc_synmane_type_leading_chars(const char *name, long len, rb_encoding *enc, int
}
case '<':
- switch (*++m) {
+ switch (*++m) {
default: return (t) { stophere, ID_JUNK, 1, };
case '<': return (t) { stophere, ID_JUNK, 2, };
case '=':
@@ -294,16 +294,16 @@ enc_synmane_type_leading_chars(const char *name, long len, rb_encoding *enc, int
default: return (t) { stophere, ID_JUNK, 2, };
case '>': return (t) { stophere, ID_JUNK, 3, };
}
- }
+ }
case '>':
- switch (*++m) {
+ switch (*++m) {
default: return (t) { stophere, ID_JUNK, 1, };
case '>': case '=': return (t) { stophere, ID_JUNK, 2, };
- }
+ }
case '=':
- switch (*++m) {
+ switch (*++m) {
default: return (t) { invalid, 0, 1, };
case '~': return (t) { stophere, ID_JUNK, 2, };
case '=':
@@ -311,7 +311,7 @@ enc_synmane_type_leading_chars(const char *name, long len, rb_encoding *enc, int
default: return (t) { stophere, ID_JUNK, 2, };
case '=': return (t) { stophere, ID_JUNK, 3, };
}
- }
+ }
case '*':
switch (*++m) {
@@ -339,16 +339,16 @@ enc_synmane_type_leading_chars(const char *name, long len, rb_encoding *enc, int
}
case '!':
- switch (*++m) {
+ switch (*++m) {
case '=': case '~': return (t) { stophere, ID_JUNK, 2, };
- default:
+ default:
if (allowed_attrset & (1U << ID_JUNK)) {
return (t) { needmore, ID_JUNK, 1, };
}
else {
return (t) { stophere, ID_JUNK, 1, };
}
- }
+ }
default:
if (rb_sym_constant_char_p(name, len, enc)) {
@@ -426,8 +426,8 @@ set_id_entry(rb_symbols_t *symbols, rb_id_serial_t num, VALUE str, VALUE sym)
VALUE ary, ids = symbols->ids;
if (idx >= (size_t)RARRAY_LEN(ids) || NIL_P(ary = rb_ary_entry(ids, (long)idx))) {
- ary = rb_ary_tmp_new(ID_ENTRY_UNIT * ID_ENTRY_SIZE);
- rb_ary_store(ids, (long)idx, ary);
+ ary = rb_ary_tmp_new(ID_ENTRY_UNIT * ID_ENTRY_SIZE);
+ rb_ary_store(ids, (long)idx, ary);
}
idx = (num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
rb_ary_store(ary, (long)idx + ID_ENTRY_STR, str);
@@ -492,11 +492,11 @@ rb_id_serial_to_id(rb_id_serial_t num)
{
if (is_notop_id((ID)num)) {
VALUE sym = get_id_serial_entry(num, 0, ID_ENTRY_SYM);
- if (sym) return SYM2ID(sym);
- return ((ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
+ if (sym) return SYM2ID(sym);
+ return ((ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
}
else {
- return (ID)num;
+ return (ID)num;
}
}
@@ -505,8 +505,8 @@ static int
register_sym_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
{
if (existing) {
- rb_fatal("symbol :% "PRIsVALUE" is already registered with %"PRIxVALUE,
- (VALUE)*key, (VALUE)*value);
+ rb_fatal("symbol :% "PRIsVALUE" is already registered with %"PRIxVALUE,
+ (VALUE)*key, (VALUE)*value);
}
*value = arg;
return ST_CONTINUE;
@@ -571,10 +571,10 @@ sym_check_asciionly(VALUE str)
if (!rb_enc_asciicompat(rb_enc_get(str))) return FALSE;
switch (rb_enc_str_coderange(str)) {
case ENC_CODERANGE_BROKEN:
- rb_raise(rb_eEncodingError, "invalid symbol in encoding %s :%+"PRIsVALUE,
- rb_enc_name(rb_enc_get(str)), str);
+ rb_raise(rb_eEncodingError, "invalid symbol in encoding %s :%+"PRIsVALUE,
+ rb_enc_name(rb_enc_get(str)), str);
case ENC_CODERANGE_7BIT:
- return TRUE;
+ return TRUE;
}
return FALSE;
}
@@ -590,19 +590,19 @@ static inline void
must_be_dynamic_symbol(VALUE x)
{
if (UNLIKELY(!DYNAMIC_SYM_P(x))) {
- if (STATIC_SYM_P(x)) {
- VALUE str = lookup_id_str(RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT));
-
- if (str) {
- rb_bug("wrong argument: %s (inappropriate Symbol)", RSTRING_PTR(str));
- }
- else {
- rb_bug("wrong argument: inappropriate Symbol (%p)", (void *)x);
- }
- }
- else {
- rb_bug("wrong argument type %s (expected Symbol)", rb_builtin_class_name(x));
- }
+ if (STATIC_SYM_P(x)) {
+ VALUE str = lookup_id_str(RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT));
+
+ if (str) {
+ rb_bug("wrong argument: %s (inappropriate Symbol)", RSTRING_PTR(str));
+ }
+ else {
+ rb_bug("wrong argument: inappropriate Symbol (%p)", (void *)x);
+ }
+ }
+ else {
+ rb_bug("wrong argument type %s (expected Symbol)", rb_builtin_class_name(x));
+ }
}
}
#endif
@@ -636,14 +636,14 @@ dsymbol_check(rb_symbols_t *symbols, const VALUE sym)
ASSERT_vm_locking();
if (UNLIKELY(rb_objspace_garbage_object_p(sym))) {
- const VALUE fstr = RSYMBOL(sym)->fstr;
- const ID type = RSYMBOL(sym)->id & ID_SCOPE_MASK;
- RSYMBOL(sym)->fstr = 0;
+ const VALUE fstr = RSYMBOL(sym)->fstr;
+ const ID type = RSYMBOL(sym)->id & ID_SCOPE_MASK;
+ RSYMBOL(sym)->fstr = 0;
unregister_sym(symbols, fstr, sym);
return dsymbol_alloc(symbols, rb_cSymbol, fstr, rb_enc_get(fstr), type);
}
else {
- return sym;
+ return sym;
}
}
@@ -660,19 +660,19 @@ lookup_str_id(VALUE str)
GLOBAL_SYMBOLS_LEAVE();
if (found) {
- const VALUE sym = (VALUE)sym_data;
-
- if (STATIC_SYM_P(sym)) {
- return STATIC_SYM2ID(sym);
- }
- else if (DYNAMIC_SYM_P(sym)) {
- ID id = RSYMBOL(sym)->id;
- if (id & ~ID_SCOPE_MASK) return id;
- }
- else {
- rb_bug("non-symbol object %s:%"PRIxVALUE" for %"PRIsVALUE" in symbol table",
- rb_builtin_class_name(sym), sym, str);
- }
+ const VALUE sym = (VALUE)sym_data;
+
+ if (STATIC_SYM_P(sym)) {
+ return STATIC_SYM2ID(sym);
+ }
+ else if (DYNAMIC_SYM_P(sym)) {
+ ID id = RSYMBOL(sym)->id;
+ if (id & ~ID_SCOPE_MASK) return id;
+ }
+ else {
+ rb_bug("non-symbol object %s:%"PRIxVALUE" for %"PRIsVALUE" in symbol table",
+ rb_builtin_class_name(sym), sym, str);
+ }
}
return (ID)0;
}
@@ -764,13 +764,13 @@ intern_str(VALUE str, int mutable)
id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
if (id == (ID)-1) id = ID_JUNK;
if (sym_check_asciionly(str)) {
- if (!mutable) str = rb_str_dup(str);
- rb_enc_associate(str, rb_usascii_encoding());
+ if (!mutable) str = rb_str_dup(str);
+ rb_enc_associate(str, rb_usascii_encoding());
}
if ((nid = next_id_base()) == (ID)-1) {
- str = rb_str_ellipsize(str, 20);
- rb_raise(rb_eRuntimeError, "symbol table overflow (symbol %"PRIsVALUE")",
- str);
+ str = rb_str_ellipsize(str, 20);
+ rb_raise(rb_eRuntimeError, "symbol table overflow (symbol %"PRIsVALUE")",
+ str);
}
id |= nid;
id |= ID_STATIC_SYM;
@@ -796,7 +796,7 @@ rb_intern_str(VALUE str)
VALUE sym = lookup_str_sym(str);
if (sym) {
- return SYM2ID(sym);
+ return SYM2ID(sym);
}
return intern_str(str, 0);
@@ -808,7 +808,7 @@ rb_gc_free_dsymbol(VALUE sym)
VALUE str = RSYMBOL(sym)->fstr;
if (str) {
- RSYMBOL(sym)->fstr = 0;
+ RSYMBOL(sym)->fstr = 0;
GLOBAL_SYMBOLS_ENTER(symbols);
{
@@ -889,7 +889,7 @@ rb_sym2id(VALUE sym)
{
ID id;
if (STATIC_SYM_P(sym)) {
- id = STATIC_SYM2ID(sym);
+ id = STATIC_SYM2ID(sym);
}
else if (DYNAMIC_SYM_P(sym)) {
GLOBAL_SYMBOLS_ENTER(symbols);
@@ -907,12 +907,12 @@ rb_sym2id(VALUE sym)
set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
rb_hash_delete_entry(symbols->dsymbol_fstr_hash, fstr);
}
- }
+ }
GLOBAL_SYMBOLS_LEAVE();
}
else {
- rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol)",
- rb_builtin_class_name(sym));
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol)",
+ rb_builtin_class_name(sym));
}
return id;
}
@@ -941,10 +941,10 @@ VALUE
rb_sym2str(VALUE sym)
{
if (DYNAMIC_SYM_P(sym)) {
- return RSYMBOL(sym)->fstr;
+ return RSYMBOL(sym)->fstr;
}
else {
- return rb_id2str(STATIC_SYM2ID(sym));
+ return rb_id2str(STATIC_SYM2ID(sym));
}
}
@@ -975,7 +975,7 @@ rb_make_temporary_id(size_t n)
const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
const ID id = max_id - (ID)n;
if (id <= ruby_global_symbols.last_id) {
- rb_raise(rb_eRuntimeError, "too big to make temporary ID: %" PRIdSIZE, n);
+ rb_raise(rb_eRuntimeError, "too big to make temporary ID: %" PRIdSIZE, n);
}
return (id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
}
@@ -987,19 +987,19 @@ symbols_i(st_data_t key, st_data_t value, st_data_t arg)
VALUE sym = (VALUE)value;
if (STATIC_SYM_P(sym)) {
- rb_ary_push(ary, sym);
- return ST_CONTINUE;
+ rb_ary_push(ary, sym);
+ return ST_CONTINUE;
}
else if (!DYNAMIC_SYM_P(sym)) {
- rb_bug("invalid symbol: %s", RSTRING_PTR((VALUE)key));
+ rb_bug("invalid symbol: %s", RSTRING_PTR((VALUE)key));
}
else if (!SYMBOL_PINNED_P(sym) && rb_objspace_garbage_object_p(sym)) {
- RSYMBOL(sym)->fstr = 0;
- return ST_DELETE;
+ RSYMBOL(sym)->fstr = 0;
+ return ST_DELETE;
}
else {
- rb_ary_push(ary, sym);
- return ST_CONTINUE;
+ rb_ary_push(ary, sym);
+ return ST_CONTINUE;
}
}
@@ -1086,25 +1086,25 @@ rb_check_id(volatile VALUE *namep)
VALUE name = *namep;
if (STATIC_SYM_P(name)) {
- return STATIC_SYM2ID(name);
+ return STATIC_SYM2ID(name);
}
else if (DYNAMIC_SYM_P(name)) {
- if (SYMBOL_PINNED_P(name)) {
- return RSYMBOL(name)->id;
- }
- else {
- *namep = RSYMBOL(name)->fstr;
- return 0;
- }
+ if (SYMBOL_PINNED_P(name)) {
+ return RSYMBOL(name)->id;
+ }
+ else {
+ *namep = RSYMBOL(name)->fstr;
+ return 0;
+ }
}
else if (!RB_TYPE_P(name, T_STRING)) {
- tmp = rb_check_string_type(name);
- if (NIL_P(tmp)) {
- rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string",
- name);
- }
- name = tmp;
- *namep = name;
+ tmp = rb_check_string_type(name);
+ if (NIL_P(tmp)) {
+ rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string",
+ name);
+ }
+ name = tmp;
+ *namep = name;
}
sym_check_asciionly(name);
@@ -1120,10 +1120,10 @@ rb_check_symbol(volatile VALUE *namep)
VALUE name = *namep;
if (STATIC_SYM_P(name)) {
- return name;
+ return name;
}
else if (DYNAMIC_SYM_P(name)) {
- if (!SYMBOL_PINNED_P(name)) {
+ if (!SYMBOL_PINNED_P(name)) {
GLOBAL_SYMBOLS_ENTER(symbols);
{
name = dsymbol_check(symbols, name);
@@ -1131,23 +1131,23 @@ rb_check_symbol(volatile VALUE *namep)
GLOBAL_SYMBOLS_LEAVE();
*namep = name;
- }
- return name;
+ }
+ return name;
}
else if (!RB_TYPE_P(name, T_STRING)) {
- tmp = rb_check_string_type(name);
- if (NIL_P(tmp)) {
- rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string",
- name);
- }
- name = tmp;
- *namep = name;
+ tmp = rb_check_string_type(name);
+ if (NIL_P(tmp)) {
+ rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string",
+ name);
+ }
+ name = tmp;
+ *namep = name;
}
sym_check_asciionly(name);
if ((sym = lookup_str_sym(name)) != 0) {
- return sym;
+ return sym;
}
return Qnil;
@@ -1174,7 +1174,7 @@ rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
sym_check_asciionly(name);
if ((sym = lookup_str_sym(name)) != 0) {
- return sym;
+ return sym;
}
return Qnil;