Ruby  2.5.0dev(2017-10-22revision60238)
symbol.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  symbol.h -
4 
5  $Author$
6  created at: Tue Jul 8 15:49:54 JST 2014
7 
8  Copyright (C) 2014 Yukihiro Matsumoto
9 
10 **********************************************************************/
11 
12 #ifndef RUBY_SYMBOL_H
13 #define RUBY_SYMBOL_H 1
14 
15 #include "id.h"
16 
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)
19 
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))
24 #endif
25 
26 struct RSymbol {
27  struct RBasic basic;
30  ID id;
31 };
32 
33 #define RSYMBOL(obj) (R_CAST(RSymbol)(obj))
34 
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)
43 
44 static inline int
45 id_type(ID id)
46 {
47  if (is_notop_id(id)) {
48  return (int)(id&ID_SCOPE_MASK);
49  }
50  else {
51  return -1;
52  }
53 }
54 
56 
57 static inline rb_id_serial_t
58 rb_id_to_serial(ID id)
59 {
60  if (is_notop_id(id)) {
61  return (rb_id_serial_t)(id >> ID_SCOPE_SHIFT);
62  }
63  else {
64  return (rb_id_serial_t)id;
65  }
66 }
67 
68 static inline int
69 sym_type(VALUE sym)
70 {
71  ID id;
72  if (STATIC_SYM_P(sym)) {
73  id = RSHIFT(sym, RUBY_SPECIAL_SHIFT);
74  if (id<=tLAST_OP_ID) {
75  return -1;
76  }
77  }
78  else {
79  id = RSYMBOL(sym)->id;
80  }
81  return (int)(id&ID_SCOPE_MASK);
82 }
83 
84 #define is_local_sym(sym) (sym_type(sym)==ID_LOCAL)
85 #define is_global_sym(sym) (sym_type(sym)==ID_GLOBAL)
86 #define is_instance_sym(sym) (sym_type(sym)==ID_INSTANCE)
87 #define is_attrset_sym(sym) (sym_type(sym)==ID_ATTRSET)
88 #define is_const_sym(sym) (sym_type(sym)==ID_CONST)
89 #define is_class_sym(sym) (sym_type(sym)==ID_CLASS)
90 #define is_junk_sym(sym) (sym_type(sym)==ID_JUNK)
91 
92 RUBY_FUNC_EXPORTED const unsigned int ruby_global_name_punct_bits[(0x7e - 0x20 + 31) / 32];
93 
94 static inline int
95 is_global_name_punct(const int c)
96 {
97  if (c <= 0x20 || 0x7e < c) return 0;
98  return (ruby_global_name_punct_bits[(c - 0x20) / 32] >> (c % 32)) & 1;
99 }
100 
101 ID rb_intern_cstr_without_pindown(const char *, long, rb_encoding *);
102 
104 
105 size_t rb_sym_immortal_count(void);
106 
108 #endif
st_data_t st_index_t
Definition: st.h:50
#define sym(x)
Definition: date_core.c:3721
#define ID_SCOPE_MASK
Definition: id.h:32
Definition: ruby.h:854
#define RSYMBOL(obj)
Definition: symbol.h:33
#define ID_SCOPE_SHIFT
Definition: id.h:31
RUBY_SYMBOL_EXPORT_BEGIN size_t rb_sym_immortal_count(void)
Definition: symbol.c:814
#define RUBY_FUNC_EXPORTED
Definition: defines.h:263
ID id
Definition: symbol.h:30
RUBY_FUNC_EXPORTED const unsigned int ruby_global_name_punct_bits[(0x7e - 0x20+31)/32]
Definition: symbol.h:92
struct RBasic basic
Definition: symbol.h:27
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
unsigned long ID
Definition: ruby.h:86
unsigned long VALUE
Definition: ruby.h:85
#define STATIC_SYM_P(x)
Definition: ruby.h:380
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
unsigned int uint32_t
Definition: sha2.h:101
VALUE fstr
Definition: symbol.h:29
Definition: symbol.h:26
st_index_t hashval
Definition: symbol.h:28
ID rb_intern_cstr_without_pindown(const char *, long, rb_encoding *)
#define is_notop_id(id)
Definition: symbol.h:35
uint32_t rb_id_serial_t
Definition: symbol.h:55