2020-04-10 01:11:40 -04:00
|
|
|
#ifndef RUBY_SYMBOL_H
|
|
|
|
#define RUBY_SYMBOL_H 1
|
2014-07-09 04:07:32 -04:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
symbol.h -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Tue Jul 8 15:49:54 JST 2014
|
|
|
|
|
|
|
|
Copyright (C) 2014 Yukihiro Matsumoto
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#include "id.h"
|
2019-12-04 03:16:30 -05:00
|
|
|
#include "ruby/encoding.h"
|
2014-07-09 04:07:32 -04:00
|
|
|
|
2014-10-27 02:16:16 -04:00
|
|
|
#define DYNAMIC_ID_P(id) (!(id&ID_STATIC_SYM)&&id>tLAST_OP_ID)
|
|
|
|
#define STATIC_ID2SYM(id) (((VALUE)(id)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
|
|
|
|
|
2016-05-20 09:33:10 -04:00
|
|
|
#ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
|
2014-10-27 02:16:16 -04:00
|
|
|
#define rb_id2sym(id) \
|
2016-05-20 09:33:10 -04:00
|
|
|
RB_GNUC_EXTENSION_BLOCK(__builtin_constant_p(id) && !DYNAMIC_ID_P(id) ? \
|
|
|
|
STATIC_ID2SYM(id) : rb_id2sym(id))
|
2014-10-27 02:16:16 -04:00
|
|
|
#endif
|
|
|
|
|
2014-10-06 09:36:45 -04:00
|
|
|
struct RSymbol {
|
|
|
|
struct RBasic basic;
|
2015-07-27 18:25:30 -04:00
|
|
|
st_index_t hashval;
|
2014-10-06 09:36:45 -04:00
|
|
|
VALUE fstr;
|
2014-10-14 03:23:08 -04:00
|
|
|
ID id;
|
2014-10-06 09:36:45 -04:00
|
|
|
};
|
|
|
|
|
2014-07-31 05:58:01 -04:00
|
|
|
#define RSYMBOL(obj) (R_CAST(RSymbol)(obj))
|
2014-07-09 04:07:32 -04:00
|
|
|
|
|
|
|
#define is_notop_id(id) ((id)>tLAST_OP_ID)
|
|
|
|
#define is_local_id(id) (id_type(id)==ID_LOCAL)
|
|
|
|
#define is_global_id(id) (id_type(id)==ID_GLOBAL)
|
|
|
|
#define is_instance_id(id) (id_type(id)==ID_INSTANCE)
|
2016-01-09 04:26:23 -05:00
|
|
|
#define is_attrset_id(id) ((id)==idASET||id_type(id)==ID_ATTRSET)
|
2014-07-09 04:07:32 -04:00
|
|
|
#define is_const_id(id) (id_type(id)==ID_CONST)
|
|
|
|
#define is_class_id(id) (id_type(id)==ID_CLASS)
|
|
|
|
#define is_junk_id(id) (id_type(id)==ID_JUNK)
|
|
|
|
|
2015-08-12 04:43:55 -04:00
|
|
|
static inline int
|
|
|
|
id_type(ID id)
|
|
|
|
{
|
|
|
|
if (is_notop_id(id)) {
|
|
|
|
return (int)(id&ID_SCOPE_MASK);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef uint32_t rb_id_serial_t;
|
2019-04-25 00:22:06 -04:00
|
|
|
static const uint32_t RB_ID_SERIAL_MAX = /* 256M on LP32 */
|
|
|
|
UINT32_MAX >>
|
|
|
|
((sizeof(ID)-sizeof(rb_id_serial_t))*CHAR_BIT < RUBY_ID_SCOPE_SHIFT ?
|
|
|
|
RUBY_ID_SCOPE_SHIFT : 0);
|
2015-08-12 04:43:55 -04:00
|
|
|
|
2019-04-19 21:19:47 -04:00
|
|
|
typedef struct {
|
|
|
|
rb_id_serial_t last_id;
|
|
|
|
st_table *str_sym;
|
|
|
|
VALUE ids;
|
|
|
|
VALUE dsymbol_fstr_hash;
|
|
|
|
} rb_symbols_t;
|
|
|
|
|
2015-08-12 04:43:55 -04:00
|
|
|
static inline rb_id_serial_t
|
|
|
|
rb_id_to_serial(ID id)
|
|
|
|
{
|
|
|
|
if (is_notop_id(id)) {
|
|
|
|
return (rb_id_serial_t)(id >> ID_SCOPE_SHIFT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (rb_id_serial_t)id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 03:23:08 -04:00
|
|
|
static inline int
|
|
|
|
sym_type(VALUE sym)
|
|
|
|
{
|
|
|
|
ID id;
|
|
|
|
if (STATIC_SYM_P(sym)) {
|
|
|
|
id = RSHIFT(sym, RUBY_SPECIAL_SHIFT);
|
|
|
|
if (id<=tLAST_OP_ID) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
id = RSYMBOL(sym)->id;
|
|
|
|
}
|
|
|
|
return (int)(id&ID_SCOPE_MASK);
|
|
|
|
}
|
|
|
|
|
2014-11-17 13:20:22 -05:00
|
|
|
#define is_local_sym(sym) (sym_type(sym)==ID_LOCAL)
|
|
|
|
#define is_global_sym(sym) (sym_type(sym)==ID_GLOBAL)
|
|
|
|
#define is_instance_sym(sym) (sym_type(sym)==ID_INSTANCE)
|
|
|
|
#define is_attrset_sym(sym) (sym_type(sym)==ID_ATTRSET)
|
|
|
|
#define is_const_sym(sym) (sym_type(sym)==ID_CONST)
|
|
|
|
#define is_class_sym(sym) (sym_type(sym)==ID_CLASS)
|
|
|
|
#define is_junk_sym(sym) (sym_type(sym)==ID_JUNK)
|
2014-10-14 03:23:08 -04:00
|
|
|
|
2014-07-09 04:07:32 -04:00
|
|
|
RUBY_FUNC_EXPORTED const unsigned int ruby_global_name_punct_bits[(0x7e - 0x20 + 31) / 32];
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
is_global_name_punct(const int c)
|
|
|
|
{
|
|
|
|
if (c <= 0x20 || 0x7e < c) return 0;
|
|
|
|
return (ruby_global_name_punct_bits[(c - 0x20) / 32] >> (c % 32)) & 1;
|
|
|
|
}
|
|
|
|
|
2018-12-20 00:43:15 -05:00
|
|
|
int rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset);
|
|
|
|
|
2015-08-21 07:30:24 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
|
|
|
|
|
|
|
size_t rb_sym_immortal_count(void);
|
|
|
|
|
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2014-07-09 04:07:32 -04:00
|
|
|
#endif
|