1 #ifndef RUBY_RUBYPARSER_H
2 #define RUBY_RUBYPARSER_H 1
10 #ifdef UNIVERSAL_PARSER
12 #define rb_encoding const void
13 #define OnigCodePoint unsigned int
14 #include "parser_st.h"
16 #include "parser_value.h"
28 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
30 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
31 # define FLEX_ARY_LEN 0
33 # define FLEX_ARY_LEN 1
38 # if defined(__MINGW_PRINTF_FORMAT)
39 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, argument_index)))
41 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index)))
43 #elif defined(__clang__)
44 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
46 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index)
52 enum rb_parser_string_coderange_type {
54 RB_PARSER_ENC_CODERANGE_UNKNOWN = 0,
55 RB_PARSER_ENC_CODERANGE_7BIT = 1,
56 RB_PARSER_ENC_CODERANGE_VALID = 2,
57 RB_PARSER_ENC_CODERANGE_BROKEN = 3
61 enum rb_parser_string_coderange_type coderange;
69 enum rb_parser_shareability {
70 rb_parser_shareable_none,
71 rb_parser_shareable_literal,
72 rb_parser_shareable_copy,
73 rb_parser_shareable_everything,
76 typedef void* rb_parser_input_data;
199 ID ids[FLEX_ARY_LEN];
211 #define YYLTYPE rb_code_location_t
212 #define YYLTYPE_IS_DECLARED 1
216 const char *type_name;
224 typedef void* rb_parser_ary_data;
226 enum rb_parser_ary_data_type {
227 PARSER_ARY_DATA_AST_TOKEN = 1,
228 PARSER_ARY_DATA_SCRIPT_LINE,
233 enum rb_parser_ary_data_type data_type;
234 rb_parser_ary_data *data;
250 struct RNode *nd_body;
257 struct RNode *nd_head;
258 struct RNode *nd_end;
259 struct RNode *nd_next;
265 struct RNode *nd_cond;
266 struct RNode *nd_body;
267 struct RNode *nd_else;
273 struct RNode *nd_cond;
274 struct RNode *nd_body;
275 struct RNode *nd_else;
284 struct RNode *nd_head;
285 struct RNode *nd_body;
293 struct RNode *nd_head;
294 struct RNode *nd_body;
302 struct RNode *nd_head;
303 struct RNode *nd_body;
311 struct RNode *nd_head;
312 struct RNode *nd_body;
313 struct RNode *nd_next;
321 struct RNode *nd_head;
322 struct RNode *nd_body;
323 struct RNode *nd_next;
329 struct RNode *nd_cond;
330 struct RNode *nd_body;
339 struct RNode *nd_body;
340 struct RNode *nd_iter;
346 struct RNode *nd_var;
352 struct RNode *nd_chain;
353 struct RNode *nd_stts;
364 struct RNode *nd_body;
370 struct RNode *nd_head;
371 struct RNode *nd_resq;
372 struct RNode *nd_else;
378 struct RNode *nd_args;
379 struct RNode *nd_exc_var;
380 struct RNode *nd_body;
381 struct RNode *nd_next;
387 struct RNode *nd_head;
388 struct RNode *nd_ensr;
394 struct RNode *nd_1st;
395 struct RNode *nd_2nd;
402 struct RNode *nd_head;
403 struct RNode *nd_value;
404 struct RNode *nd_args;
411 struct RNode *nd_value;
418 struct RNode *nd_value;
425 struct RNode *nd_value;
432 struct RNode *nd_value;
439 struct RNode *nd_value;
440 struct RNode *nd_else;
441 enum rb_parser_shareability shareability;
448 struct RNode *nd_value;
454 struct RNode *nd_recv;
456 struct RNode *nd_index;
457 struct RNode *nd_rvalue;
467 struct RNode *nd_recv;
468 struct RNode *nd_value;
480 struct RNode *nd_head;
481 struct RNode *nd_value;
487 struct RNode *nd_head;
488 struct RNode *nd_value;
494 struct RNode *nd_head;
495 struct RNode *nd_value;
497 enum rb_parser_shareability shareability;
503 struct RNode *nd_recv;
505 struct RNode *nd_args;
511 struct RNode *nd_recv;
513 struct RNode *nd_args;
520 struct RNode *nd_args;
532 struct RNode *nd_recv;
534 struct RNode *nd_args;
540 struct RNode *nd_args;
560 struct RNode *nd_head;
563 struct RNode *nd_end;
565 struct RNode *nd_next;
575 struct RNode *nd_head;
582 struct RNode *nd_stts;
589 struct RNode *nd_head;
643 struct RNode *nd_recv;
644 struct RNode *nd_value;
645 struct RNode *nd_args;
651 struct RNode *nd_recv;
652 struct RNode *nd_value;
679 enum rb_numeric_type {
692 enum rb_numeric_type type;
709 struct RNode *nd_end;
721 struct RNode *nd_body;
736 struct RNode *nd_body;
755 unsigned int no_kwarg: 1;
756 unsigned int ruby2_keywords: 1;
757 unsigned int forwarding: 1;
771 struct RNode *nd_next;
777 struct RNode *nd_body;
784 struct RNode *nd_body;
791 struct RNode *nd_1st;
792 struct RNode *nd_2nd;
798 struct RNode *nd_head;
799 struct RNode *nd_body;
805 struct RNode *nd_head;
806 struct RNode *nd_body;
812 struct RNode *nd_head;
819 struct RNode *nd_head;
820 struct RNode *nd_body;
821 unsigned int forwarding: 1;
829 struct RNode *nd_defn;
835 struct RNode *nd_recv;
837 struct RNode *nd_defn;
843 struct RNode *nd_1st;
844 struct RNode *nd_2nd;
866 struct RNode *nd_cpath;
867 struct RNode *nd_body;
868 struct RNode *nd_super;
874 struct RNode *nd_cpath;
875 struct RNode *nd_body;
881 struct RNode *nd_recv;
882 struct RNode *nd_body;
888 struct RNode *nd_head;
902 struct RNode *nd_beg;
903 struct RNode *nd_end;
931 struct RNode *nd_head;
937 struct RNode *nd_body;
951 struct RNode *nd_recv;
953 struct RNode *nd_args;
959 struct RNode *nd_body;
965 struct RNode *nd_pconst;
974 struct RNode *nd_pconst;
975 struct RNode *nd_pkwargs;
976 struct RNode *nd_pkwrestarg;
982 struct RNode *nd_pconst;
1007 #define RNODE(obj) ((NODE *)(obj))
1009 #define RNODE_SCOPE(node) ((rb_node_scope_t *)(node))
1010 #define RNODE_BLOCK(node) ((rb_node_block_t *)(node))
1011 #define RNODE_IF(node) ((rb_node_if_t *)(node))
1012 #define RNODE_UNLESS(node) ((rb_node_unless_t *)(node))
1013 #define RNODE_CASE(node) ((rb_node_case_t *)(node))
1014 #define RNODE_CASE2(node) ((rb_node_case2_t *)(node))
1015 #define RNODE_CASE3(node) ((rb_node_case3_t *)(node))
1016 #define RNODE_WHEN(node) ((rb_node_when_t *)(node))
1017 #define RNODE_IN(node) ((rb_node_in_t *)(node))
1018 #define RNODE_WHILE(node) ((rb_node_while_t *)(node))
1019 #define RNODE_UNTIL(node) ((rb_node_until_t *)(node))
1020 #define RNODE_ITER(node) ((rb_node_iter_t *)(node))
1021 #define RNODE_FOR(node) ((rb_node_for_t *)(node))
1022 #define RNODE_FOR_MASGN(node) ((rb_node_for_masgn_t *)(node))
1023 #define RNODE_BREAK(node) ((rb_node_break_t *)(node))
1024 #define RNODE_NEXT(node) ((rb_node_next_t *)(node))
1025 #define RNODE_REDO(node) ((rb_node_redo_t *)(node))
1026 #define RNODE_RETRY(node) ((rb_node_retry_t *)(node))
1027 #define RNODE_BEGIN(node) ((rb_node_begin_t *)(node))
1028 #define RNODE_RESCUE(node) ((rb_node_rescue_t *)(node))
1029 #define RNODE_RESBODY(node) ((rb_node_resbody_t *)(node))
1030 #define RNODE_ENSURE(node) ((rb_node_ensure_t *)(node))
1031 #define RNODE_AND(node) ((rb_node_and_t *)(node))
1032 #define RNODE_OR(node) ((rb_node_or_t *)(node))
1033 #define RNODE_MASGN(node) ((rb_node_masgn_t *)(node))
1034 #define RNODE_LASGN(node) ((rb_node_lasgn_t *)(node))
1035 #define RNODE_DASGN(node) ((rb_node_dasgn_t *)(node))
1036 #define RNODE_GASGN(node) ((rb_node_gasgn_t *)(node))
1037 #define RNODE_IASGN(node) ((rb_node_iasgn_t *)(node))
1038 #define RNODE_CDECL(node) ((rb_node_cdecl_t *)(node))
1039 #define RNODE_CVASGN(node) ((rb_node_cvasgn_t *)(node))
1040 #define RNODE_OP_ASGN1(node) ((rb_node_op_asgn1_t *)(node))
1041 #define RNODE_OP_ASGN2(node) ((rb_node_op_asgn2_t *)(node))
1042 #define RNODE_OP_ASGN_AND(node) ((rb_node_op_asgn_and_t *)(node))
1043 #define RNODE_OP_ASGN_OR(node) ((rb_node_op_asgn_or_t *)(node))
1044 #define RNODE_OP_CDECL(node) ((rb_node_op_cdecl_t *)(node))
1045 #define RNODE_CALL(node) ((rb_node_call_t *)(node))
1046 #define RNODE_OPCALL(node) ((rb_node_opcall_t *)(node))
1047 #define RNODE_FCALL(node) ((rb_node_fcall_t *)(node))
1048 #define RNODE_VCALL(node) ((rb_node_vcall_t *)(node))
1049 #define RNODE_QCALL(node) ((rb_node_qcall_t *)(node))
1050 #define RNODE_SUPER(node) ((rb_node_super_t *)(node))
1051 #define RNODE_ZSUPER(node) ((rb_node_zsuper_t *)(node))
1052 #define RNODE_LIST(node) ((rb_node_list_t *)(node))
1053 #define RNODE_ZLIST(node) ((rb_node_zlist_t *)(node))
1054 #define RNODE_HASH(node) ((rb_node_hash_t *)(node))
1055 #define RNODE_RETURN(node) ((rb_node_return_t *)(node))
1056 #define RNODE_YIELD(node) ((rb_node_yield_t *)(node))
1057 #define RNODE_LVAR(node) ((rb_node_lvar_t *)(node))
1058 #define RNODE_DVAR(node) ((rb_node_dvar_t *)(node))
1059 #define RNODE_GVAR(node) ((rb_node_gvar_t *)(node))
1060 #define RNODE_IVAR(node) ((rb_node_ivar_t *)(node))
1061 #define RNODE_CONST(node) ((rb_node_const_t *)(node))
1062 #define RNODE_CVAR(node) ((rb_node_cvar_t *)(node))
1063 #define RNODE_NTH_REF(node) ((rb_node_nth_ref_t *)(node))
1064 #define RNODE_BACK_REF(node) ((rb_node_back_ref_t *)(node))
1065 #define RNODE_MATCH(node) ((rb_node_match_t *)(node))
1066 #define RNODE_MATCH2(node) ((rb_node_match2_t *)(node))
1067 #define RNODE_MATCH3(node) ((rb_node_match3_t *)(node))
1068 #define RNODE_INTEGER(node) ((rb_node_integer_t *)(node))
1069 #define RNODE_FLOAT(node) ((rb_node_float_t *)(node))
1070 #define RNODE_RATIONAL(node) ((rb_node_rational_t *)(node))
1071 #define RNODE_IMAGINARY(node) ((rb_node_imaginary_t *)(node))
1072 #define RNODE_STR(node) ((rb_node_str_t *)(node))
1073 #define RNODE_DSTR(node) ((rb_node_dstr_t *)(node))
1074 #define RNODE_XSTR(node) ((rb_node_xstr_t *)(node))
1075 #define RNODE_DXSTR(node) ((rb_node_dxstr_t *)(node))
1076 #define RNODE_EVSTR(node) ((rb_node_evstr_t *)(node))
1077 #define RNODE_REGX(node) ((rb_node_regx_t *)(node))
1078 #define RNODE_DREGX(node) ((rb_node_dregx_t *)(node))
1079 #define RNODE_ONCE(node) ((rb_node_once_t *)(node))
1080 #define RNODE_ARGS(node) ((rb_node_args_t *)(node))
1081 #define RNODE_ARGS_AUX(node) ((rb_node_args_aux_t *)(node))
1082 #define RNODE_OPT_ARG(node) ((rb_node_opt_arg_t *)(node))
1083 #define RNODE_KW_ARG(node) ((rb_node_kw_arg_t *)(node))
1084 #define RNODE_POSTARG(node) ((rb_node_postarg_t *)(node))
1085 #define RNODE_ARGSCAT(node) ((rb_node_argscat_t *)(node))
1086 #define RNODE_ARGSPUSH(node) ((rb_node_argspush_t *)(node))
1087 #define RNODE_SPLAT(node) ((rb_node_splat_t *)(node))
1088 #define RNODE_BLOCK_PASS(node) ((rb_node_block_pass_t *)(node))
1089 #define RNODE_DEFN(node) ((rb_node_defn_t *)(node))
1090 #define RNODE_DEFS(node) ((rb_node_defs_t *)(node))
1091 #define RNODE_ALIAS(node) ((rb_node_alias_t *)(node))
1092 #define RNODE_VALIAS(node) ((rb_node_valias_t *)(node))
1093 #define RNODE_UNDEF(node) ((rb_node_undef_t *)(node))
1094 #define RNODE_CLASS(node) ((rb_node_class_t *)(node))
1095 #define RNODE_MODULE(node) ((rb_node_module_t *)(node))
1096 #define RNODE_SCLASS(node) ((rb_node_sclass_t *)(node))
1097 #define RNODE_COLON2(node) ((rb_node_colon2_t *)(node))
1098 #define RNODE_COLON3(node) ((rb_node_colon3_t *)(node))
1099 #define RNODE_DOT2(node) ((rb_node_dot2_t *)(node))
1100 #define RNODE_DOT3(node) ((rb_node_dot3_t *)(node))
1101 #define RNODE_FLIP2(node) ((rb_node_flip2_t *)(node))
1102 #define RNODE_FLIP3(node) ((rb_node_flip3_t *)(node))
1103 #define RNODE_SELF(node) ((rb_node_self_t *)(node))
1104 #define RNODE_NIL(node) ((rb_node_nil_t *)(node))
1105 #define RNODE_TRUE(node) ((rb_node_true_t *)(node))
1106 #define RNODE_FALSE(node) ((rb_node_false_t *)(node))
1107 #define RNODE_ERRINFO(node) ((rb_node_errinfo_t *)(node))
1108 #define RNODE_DEFINED(node) ((rb_node_defined_t *)(node))
1109 #define RNODE_POSTEXE(node) ((rb_node_postexe_t *)(node))
1110 #define RNODE_SYM(node) ((rb_node_sym_t *)(node))
1111 #define RNODE_DSYM(node) ((rb_node_dsym_t *)(node))
1112 #define RNODE_ATTRASGN(node) ((rb_node_attrasgn_t *)(node))
1113 #define RNODE_LAMBDA(node) ((rb_node_lambda_t *)(node))
1114 #define RNODE_ARYPTN(node) ((rb_node_aryptn_t *)(node))
1115 #define RNODE_HSHPTN(node) ((rb_node_hshptn_t *)(node))
1116 #define RNODE_FNDPTN(node) ((rb_node_fndptn_t *)(node))
1117 #define RNODE_LINE(node) ((rb_node_line_t *)(node))
1118 #define RNODE_FILE(node) ((rb_node_file_t *)(node))
1119 #define RNODE_ENCODING(node) ((rb_node_encoding_t *)(node))
1126 #define NODE_FL_NEWLINE (((VALUE)1)<<7)
1128 #define NODE_TYPESHIFT 8
1129 #define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT)
1131 #define nd_fl_newline(n) ((n)->flags & NODE_FL_NEWLINE)
1132 #define nd_set_fl_newline(n) ((n)->flags |= NODE_FL_NEWLINE)
1133 #define nd_unset_fl_newline(n) ((n)->flags &= ~NODE_FL_NEWLINE)
1135 #define nd_type(n) ((int) ((RNODE(n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
1136 #define nd_set_type(n,t) \
1137 rb_node_set_type(n, t)
1138 #define nd_init_type(n,t) \
1139 (n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK))
1143 #ifdef UNIVERSAL_PARSER
1144 typedef struct rb_parser_config_struct rb_parser_config_t;
1151 signed int frozen_string_literal:2;
1152 signed int coverage_enabled:2;
1157 #ifdef UNIVERSAL_PARSER
1158 const rb_parser_config_t *config;
1170 #ifndef INTERNAL_IMEMO_H
1174 #ifdef UNIVERSAL_PARSER
1175 typedef struct rb_parser_config_struct {
1177 void *(*malloc)(
size_t size);
1178 void *(*calloc)(
size_t number,
size_t size);
1179 void *(*realloc)(
void *
ptr,
size_t newsiz);
1180 void (*free)(
void *
ptr);
1181 void *(*alloc_n)(
size_t nelems,
size_t elemsiz);
1182 void *(*alloc)(
size_t elemsiz);
1183 void *(*realloc_n)(
void *
ptr,
size_t newelems,
size_t newsiz);
1184 void *(*zalloc)(
size_t elemsiz);
1185 void *(*rb_memmove)(
void *dest,
const void *src,
size_t t,
size_t n);
1186 void *(*nonempty_memcpy)(
void *dest,
const void *src,
size_t t,
size_t n);
1187 void *(*xmalloc_mul_add)(
size_t x,
size_t y,
size_t z);
1198 VALUE (*ary_new_from_args)(
long n, ...);
1202 ID (*make_temporary_id)(
size_t n);
1203 int (*is_local_id)(
ID);
1204 int (*is_attrset_id)(
ID);
1205 int (*is_global_name_punct)(
const int c);
1206 int (*id_type)(
ID id);
1207 ID (*id_attrset)(
ID);
1208 ID (*intern)(
const char *name);
1209 ID (*intern2)(
const char *name,
long len);
1212 int (*is_notop_id)(
ID);
1213 int (*enc_symname_type)(
const char *name,
long len,
rb_encoding *enc,
unsigned int allowed_attrset);
1214 const char *(*id2name)(
ID id);
1221 VALUE (*str_catf)(
VALUE str, const
char *format, ...);
1225 VALUE (*str_new_cstr)(const
char *
ptr);
1229 VALUE (*str_vcatf)(
VALUE str, const
char *fmt, va_list ap);
1232 char *(*rstring_ptr)(
VALUE str);
1233 long (*rstring_len)(
VALUE str);
1237 VALUE (*int2num)(
int v);
1240 int (*stderr_tty_p)(
void);
1241 void (*write_error_str)(
VALUE mesg);
1247 VALUE (*debug_output_stdout)(
void);
1248 VALUE (*debug_output_stderr)(
void);
1252 int (*enc_isalnum)(OnigCodePoint c,
rb_encoding *enc);
1253 int (*enc_precise_mbclen)(const
char *p, const
char *e,
rb_encoding *enc);
1254 int (*mbclen_charfound_p)(
int len);
1255 int (*mbclen_charfound_len)(
int len);
1257 char *(*enc_prev_char)(const
char *s, const
char *p, const
char *e,
rb_encoding *enc);
1264 int (*enc_mbcput)(
unsigned int c,
void *buf,
rb_encoding *enc);
1265 int (*enc_find_index)(const
char *name);
1267 int (*enc_isspace)(OnigCodePoint c,
rb_encoding *enc);
1270 bool (*enc_isascii)(OnigCodePoint c,
rb_encoding *enc);
1271 OnigCodePoint (*enc_mbc_to_codepoint)(const
char *p, const
char *e,
rb_encoding *enc);
1275 int (*local_defined)(
ID, const
void*);
1277 int (*dvar_defined)(
ID, const
void*);
1283 void (*raise)(
VALUE exc, const
char *fmt, ...);
1284 VALUE (*syntax_error_new)(
void);
1287 VALUE (*errinfo)(
void);
1288 void (*set_errinfo)(
VALUE err);
1289 void (*exc_raise)(
VALUE mesg);
1290 VALUE (*make_exception)(
int argc, const
VALUE *argv);
1293 void (*sized_xfree)(
void *x,
size_t size);
1294 void *(*sized_realloc_n)(
void *
ptr,
size_t new_count,
size_t element_size,
size_t old_count);
1295 void (*gc_guard)(
VALUE);
1296 void (*gc_mark)(
VALUE);
1299 VALUE (*reg_compile)(
VALUE str,
int options, const
char *sourcefile,
int sourceline);
1301 int (*memcicmp)(const
void *x, const
void *y,
long len);
1304 void (*compile_warn)(const
char *file,
int line, const
char *fmt, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1305 void (*compile_warning)(const
char *file,
int line, const
char *fmt, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1306 void (*bug)(const
char *fmt, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1307 void (*fatal)(const
char *fmt, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1308 VALUE (*verbose)(
void);
1309 int *(*errno_ptr)(
void);
1312 VALUE (*make_backtrace)(
void);
1315 unsigned long (*
scan_hex)(const
char *start,
size_t len,
size_t *retlen);
1316 unsigned long (*
scan_oct)(const
char *start,
size_t len,
size_t *retlen);
1317 unsigned long (*scan_digits)(const
char *str, ssize_t
len,
int base,
size_t *retlen,
int *overflow);
1318 double (*
strtod)(const
char *s00,
char **se);
1321 int (*rtest)(
VALUE obj);
1322 int (*nil_p)(
VALUE obj);
1325 VALUE (*eArgError)(
void);
1326 int (*long2int)(
long);
1329 int enc_coderange_7bit;
1330 int enc_coderange_unknown;
1331 VALUE (*static_id2sym)(
ID id);
1332 long (*str_coderange_scan_restartable)(const
char *s, const
char *e,
rb_encoding *enc,
int *cr);
1333 } rb_parser_config_t;
1336 #undef OnigCodePoint
1339 RUBY_SYMBOL_EXPORT_BEGIN
1340 void rb_ruby_parser_free(
void *
ptr);
1342 #ifdef UNIVERSAL_PARSER
1343 rb_parser_t *rb_ruby_parser_allocate(
const rb_parser_config_t *config);
1344 rb_parser_t *rb_ruby_parser_new(
const rb_parser_config_t *config);
1347 RUBY_SYMBOL_EXPORT_END
#define scan_hex(s, l, e)
Old name of ruby_scan_hex.
#define scan_oct(s, l, e)
Old name of ruby_scan_oct.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
int len
Length of the buffer.
#define strtod(s, e)
Just another name of ruby_strtod.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.