kanayago 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +15 -0
  3. data/.rubocop_todo.yml +23 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +79 -0
  6. data/Rakefile +182 -0
  7. data/ext/kanayago/ccan/check_type/check_type.h +63 -0
  8. data/ext/kanayago/ccan/container_of/container_of.h +142 -0
  9. data/ext/kanayago/ccan/list/list.h +791 -0
  10. data/ext/kanayago/ccan/str/str.h +17 -0
  11. data/ext/kanayago/constant.h +53 -0
  12. data/ext/kanayago/extconf.rb +21 -0
  13. data/ext/kanayago/id.h +347 -0
  14. data/ext/kanayago/id_table.h +39 -0
  15. data/ext/kanayago/internal/array.h +151 -0
  16. data/ext/kanayago/internal/basic_operators.h +64 -0
  17. data/ext/kanayago/internal/bignum.h +244 -0
  18. data/ext/kanayago/internal/bits.h +568 -0
  19. data/ext/kanayago/internal/compile.h +34 -0
  20. data/ext/kanayago/internal/compilers.h +107 -0
  21. data/ext/kanayago/internal/complex.h +29 -0
  22. data/ext/kanayago/internal/encoding.h +36 -0
  23. data/ext/kanayago/internal/error.h +218 -0
  24. data/ext/kanayago/internal/fixnum.h +184 -0
  25. data/ext/kanayago/internal/gc.h +322 -0
  26. data/ext/kanayago/internal/hash.h +191 -0
  27. data/ext/kanayago/internal/imemo.h +261 -0
  28. data/ext/kanayago/internal/io.h +140 -0
  29. data/ext/kanayago/internal/numeric.h +274 -0
  30. data/ext/kanayago/internal/parse.h +117 -0
  31. data/ext/kanayago/internal/rational.h +71 -0
  32. data/ext/kanayago/internal/re.h +28 -0
  33. data/ext/kanayago/internal/ruby_parser.h +125 -0
  34. data/ext/kanayago/internal/sanitizers.h +297 -0
  35. data/ext/kanayago/internal/serial.h +23 -0
  36. data/ext/kanayago/internal/static_assert.h +16 -0
  37. data/ext/kanayago/internal/string.h +186 -0
  38. data/ext/kanayago/internal/symbol.h +45 -0
  39. data/ext/kanayago/internal/thread.h +79 -0
  40. data/ext/kanayago/internal/variable.h +72 -0
  41. data/ext/kanayago/internal/vm.h +137 -0
  42. data/ext/kanayago/internal/warnings.h +16 -0
  43. data/ext/kanayago/internal.h +108 -0
  44. data/ext/kanayago/kanayago.c +420 -0
  45. data/ext/kanayago/kanayago.h +21 -0
  46. data/ext/kanayago/lex.c +302 -0
  47. data/ext/kanayago/method.h +255 -0
  48. data/ext/kanayago/node.c +440 -0
  49. data/ext/kanayago/node.h +111 -0
  50. data/ext/kanayago/node_name.inc +224 -0
  51. data/ext/kanayago/parse.c +26931 -0
  52. data/ext/kanayago/parse.h +244 -0
  53. data/ext/kanayago/parse.tmp.y +16145 -0
  54. data/ext/kanayago/parser_bits.h +564 -0
  55. data/ext/kanayago/parser_node.h +32 -0
  56. data/ext/kanayago/parser_st.c +164 -0
  57. data/ext/kanayago/parser_st.h +162 -0
  58. data/ext/kanayago/parser_value.h +106 -0
  59. data/ext/kanayago/probes.h +4 -0
  60. data/ext/kanayago/ruby_assert.h +14 -0
  61. data/ext/kanayago/ruby_atomic.h +23 -0
  62. data/ext/kanayago/ruby_parser.c +1165 -0
  63. data/ext/kanayago/rubyparser.h +1391 -0
  64. data/ext/kanayago/shape.h +234 -0
  65. data/ext/kanayago/st.c +2339 -0
  66. data/ext/kanayago/symbol.h +123 -0
  67. data/ext/kanayago/thread_pthread.h +168 -0
  68. data/ext/kanayago/universal_parser.c +230 -0
  69. data/ext/kanayago/vm_core.h +2215 -0
  70. data/ext/kanayago/vm_opts.h +67 -0
  71. data/lib/kanayago/version.rb +5 -0
  72. data/lib/kanayago.rb +11 -0
  73. data/sig/kanayago.rbs +4 -0
  74. metadata +116 -0
@@ -0,0 +1,1391 @@
1
+ #ifndef RUBY_RUBYPARSER_H
2
+ #define RUBY_RUBYPARSER_H 1
3
+ /*
4
+ * This is a header file for librubyparser interface
5
+ */
6
+
7
+ #include <stdarg.h> /* for va_list */
8
+ #include <assert.h>
9
+
10
+ #ifdef UNIVERSAL_PARSER
11
+
12
+ #define rb_encoding const void
13
+ #define OnigCodePoint unsigned int
14
+ #include "parser_st.h"
15
+ #ifndef RUBY_RUBY_H
16
+ #include "parser_value.h"
17
+ #endif
18
+
19
+ #else
20
+
21
+ #include "ruby/encoding.h"
22
+
23
+ #endif
24
+
25
+ #ifndef FLEX_ARY_LEN
26
+ /* From internal/compilers.h */
27
+ /* A macro for defining a flexible array, like: VALUE ary[FLEX_ARY_LEN]; */
28
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
29
+ # define FLEX_ARY_LEN /* VALUE ary[]; */
30
+ #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
31
+ # define FLEX_ARY_LEN 0 /* VALUE ary[0]; */
32
+ #else
33
+ # define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
34
+ #endif
35
+ #endif
36
+
37
+ #if defined(__GNUC__)
38
+ # if defined(__MINGW_PRINTF_FORMAT)
39
+ # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, argument_index)))
40
+ # else
41
+ # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index)))
42
+ # endif
43
+ #elif defined(__clang__)
44
+ # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
45
+ #else
46
+ # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index)
47
+ #endif
48
+
49
+ /*
50
+ * Parser String
51
+ */
52
+ enum rb_parser_string_coderange_type {
53
+ /** The object's coderange is unclear yet. */
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
58
+ };
59
+
60
+ typedef struct rb_parser_string {
61
+ enum rb_parser_string_coderange_type coderange;
62
+ rb_encoding *enc;
63
+ /* Length of the string, not including terminating NUL character. */
64
+ long len;
65
+ /* Pointer to the contents of the string. */
66
+ char *ptr;
67
+ } rb_parser_string_t;
68
+
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,
74
+ };
75
+
76
+ typedef void* rb_parser_input_data;
77
+
78
+ /*
79
+ * AST Node
80
+ */
81
+ enum node_type {
82
+ NODE_SCOPE,
83
+ NODE_BLOCK,
84
+ NODE_IF,
85
+ NODE_UNLESS,
86
+ NODE_CASE,
87
+ NODE_CASE2,
88
+ NODE_CASE3,
89
+ NODE_WHEN,
90
+ NODE_IN,
91
+ NODE_WHILE,
92
+ NODE_UNTIL,
93
+ NODE_ITER,
94
+ NODE_FOR,
95
+ NODE_FOR_MASGN,
96
+ NODE_BREAK,
97
+ NODE_NEXT,
98
+ NODE_REDO,
99
+ NODE_RETRY,
100
+ NODE_BEGIN,
101
+ NODE_RESCUE,
102
+ NODE_RESBODY,
103
+ NODE_ENSURE,
104
+ NODE_AND,
105
+ NODE_OR,
106
+ NODE_MASGN,
107
+ NODE_LASGN,
108
+ NODE_DASGN,
109
+ NODE_GASGN,
110
+ NODE_IASGN,
111
+ NODE_CDECL,
112
+ NODE_CVASGN,
113
+ NODE_OP_ASGN1,
114
+ NODE_OP_ASGN2,
115
+ NODE_OP_ASGN_AND,
116
+ NODE_OP_ASGN_OR,
117
+ NODE_OP_CDECL,
118
+ NODE_CALL,
119
+ NODE_OPCALL,
120
+ NODE_FCALL,
121
+ NODE_VCALL,
122
+ NODE_QCALL,
123
+ NODE_SUPER,
124
+ NODE_ZSUPER,
125
+ NODE_LIST,
126
+ NODE_ZLIST,
127
+ NODE_HASH,
128
+ NODE_RETURN,
129
+ NODE_YIELD,
130
+ NODE_LVAR,
131
+ NODE_DVAR,
132
+ NODE_GVAR,
133
+ NODE_IVAR,
134
+ NODE_CONST,
135
+ NODE_CVAR,
136
+ NODE_NTH_REF,
137
+ NODE_BACK_REF,
138
+ NODE_MATCH,
139
+ NODE_MATCH2,
140
+ NODE_MATCH3,
141
+ NODE_INTEGER,
142
+ NODE_FLOAT,
143
+ NODE_RATIONAL,
144
+ NODE_IMAGINARY,
145
+ NODE_STR,
146
+ NODE_DSTR,
147
+ NODE_XSTR,
148
+ NODE_DXSTR,
149
+ NODE_EVSTR,
150
+ NODE_REGX,
151
+ NODE_DREGX,
152
+ NODE_ONCE,
153
+ NODE_ARGS,
154
+ NODE_ARGS_AUX,
155
+ NODE_OPT_ARG,
156
+ NODE_KW_ARG,
157
+ NODE_POSTARG,
158
+ NODE_ARGSCAT,
159
+ NODE_ARGSPUSH,
160
+ NODE_SPLAT,
161
+ NODE_BLOCK_PASS,
162
+ NODE_DEFN,
163
+ NODE_DEFS,
164
+ NODE_ALIAS,
165
+ NODE_VALIAS,
166
+ NODE_UNDEF,
167
+ NODE_CLASS,
168
+ NODE_MODULE,
169
+ NODE_SCLASS,
170
+ NODE_COLON2,
171
+ NODE_COLON3,
172
+ NODE_DOT2,
173
+ NODE_DOT3,
174
+ NODE_FLIP2,
175
+ NODE_FLIP3,
176
+ NODE_SELF,
177
+ NODE_NIL,
178
+ NODE_TRUE,
179
+ NODE_FALSE,
180
+ NODE_ERRINFO,
181
+ NODE_DEFINED,
182
+ NODE_POSTEXE,
183
+ NODE_SYM,
184
+ NODE_DSYM,
185
+ NODE_ATTRASGN,
186
+ NODE_LAMBDA,
187
+ NODE_ARYPTN,
188
+ NODE_HSHPTN,
189
+ NODE_FNDPTN,
190
+ NODE_ERROR,
191
+ NODE_LINE,
192
+ NODE_FILE,
193
+ NODE_ENCODING,
194
+ NODE_LAST
195
+ };
196
+
197
+ typedef struct rb_ast_id_table {
198
+ int size;
199
+ ID ids[FLEX_ARY_LEN];
200
+ } rb_ast_id_table_t;
201
+
202
+ typedef struct rb_code_position_struct {
203
+ int lineno;
204
+ int column;
205
+ } rb_code_position_t;
206
+
207
+ typedef struct rb_code_location_struct {
208
+ rb_code_position_t beg_pos;
209
+ rb_code_position_t end_pos;
210
+ } rb_code_location_t;
211
+ #define YYLTYPE rb_code_location_t
212
+ #define YYLTYPE_IS_DECLARED 1
213
+
214
+ typedef struct rb_parser_ast_token {
215
+ int id;
216
+ const char *type_name;
217
+ rb_parser_string_t *str;
218
+ rb_code_location_t loc;
219
+ } rb_parser_ast_token_t;
220
+
221
+ /*
222
+ * Array-like object for parser
223
+ */
224
+ typedef void* rb_parser_ary_data;
225
+
226
+ enum rb_parser_ary_data_type {
227
+ PARSER_ARY_DATA_AST_TOKEN = 1,
228
+ PARSER_ARY_DATA_SCRIPT_LINE,
229
+ PARSER_ARY_DATA_NODE
230
+ };
231
+
232
+ typedef struct rb_parser_ary {
233
+ enum rb_parser_ary_data_type data_type;
234
+ rb_parser_ary_data *data;
235
+ long len; // current size
236
+ long capa; // capacity
237
+ } rb_parser_ary_t;
238
+
239
+ /* Header part of AST Node */
240
+ typedef struct RNode {
241
+ VALUE flags;
242
+ rb_code_location_t nd_loc;
243
+ int node_id;
244
+ } NODE;
245
+
246
+ typedef struct RNode_SCOPE {
247
+ NODE node;
248
+
249
+ rb_ast_id_table_t *nd_tbl;
250
+ struct RNode *nd_body;
251
+ struct RNode_ARGS *nd_args;
252
+ } rb_node_scope_t;
253
+
254
+ typedef struct RNode_BLOCK {
255
+ NODE node;
256
+
257
+ struct RNode *nd_head;
258
+ struct RNode *nd_end;
259
+ struct RNode *nd_next;
260
+ } rb_node_block_t;
261
+
262
+ typedef struct RNode_IF {
263
+ NODE node;
264
+
265
+ struct RNode *nd_cond;
266
+ struct RNode *nd_body;
267
+ struct RNode *nd_else;
268
+ } rb_node_if_t;
269
+
270
+ typedef struct RNode_UNLESS {
271
+ NODE node;
272
+
273
+ struct RNode *nd_cond;
274
+ struct RNode *nd_body;
275
+ struct RNode *nd_else;
276
+ rb_code_location_t keyword_loc;
277
+ rb_code_location_t then_keyword_loc;
278
+ rb_code_location_t end_keyword_loc;
279
+ } rb_node_unless_t;
280
+
281
+ typedef struct RNode_CASE {
282
+ NODE node;
283
+
284
+ struct RNode *nd_head;
285
+ struct RNode *nd_body;
286
+ } rb_node_case_t;
287
+
288
+ typedef struct RNode_CASE2 {
289
+ NODE node;
290
+
291
+ struct RNode *nd_head;
292
+ struct RNode *nd_body;
293
+ } rb_node_case2_t;
294
+
295
+ typedef struct RNode_CASE3 {
296
+ NODE node;
297
+
298
+ struct RNode *nd_head;
299
+ struct RNode *nd_body;
300
+ } rb_node_case3_t;
301
+
302
+ typedef struct RNode_WHEN {
303
+ NODE node;
304
+
305
+ struct RNode *nd_head;
306
+ struct RNode *nd_body;
307
+ struct RNode *nd_next;
308
+ } rb_node_when_t;
309
+
310
+ typedef struct RNode_IN {
311
+ NODE node;
312
+
313
+ struct RNode *nd_head;
314
+ struct RNode *nd_body;
315
+ struct RNode *nd_next;
316
+ } rb_node_in_t;
317
+
318
+ /* RNode_WHILE and RNode_UNTIL should be same structure */
319
+ typedef struct RNode_WHILE {
320
+ NODE node;
321
+
322
+ struct RNode *nd_cond;
323
+ struct RNode *nd_body;
324
+ long nd_state;
325
+ } rb_node_while_t;
326
+
327
+ typedef struct RNode_UNTIL {
328
+ NODE node;
329
+
330
+ struct RNode *nd_cond;
331
+ struct RNode *nd_body;
332
+ long nd_state;
333
+ } rb_node_until_t;
334
+
335
+ /* RNode_ITER and RNode_FOR should be same structure */
336
+ typedef struct RNode_ITER {
337
+ NODE node;
338
+
339
+ struct RNode *nd_body;
340
+ struct RNode *nd_iter;
341
+ } rb_node_iter_t;
342
+
343
+ typedef struct RNode_FOR {
344
+ NODE node;
345
+
346
+ struct RNode *nd_body;
347
+ struct RNode *nd_iter;
348
+ } rb_node_for_t;
349
+
350
+ typedef struct RNode_FOR_MASGN {
351
+ NODE node;
352
+
353
+ struct RNode *nd_var;
354
+ } rb_node_for_masgn_t;
355
+
356
+ /* RNode_BREAK, RNode_NEXT and RNode_REDO should be same structure */
357
+ typedef struct RNode_BREAK {
358
+ NODE node;
359
+
360
+ struct RNode *nd_chain;
361
+ struct RNode *nd_stts;
362
+ } rb_node_break_t;
363
+
364
+ typedef struct RNode_NEXT {
365
+ NODE node;
366
+
367
+ struct RNode *nd_chain;
368
+ struct RNode *nd_stts;
369
+ } rb_node_next_t;
370
+
371
+ typedef struct RNode_REDO {
372
+ NODE node;
373
+
374
+ struct RNode *nd_chain;
375
+ } rb_node_redo_t;
376
+
377
+ typedef struct RNode_RETRY {
378
+ NODE node;
379
+ } rb_node_retry_t;
380
+
381
+ typedef struct RNode_BEGIN {
382
+ NODE node;
383
+
384
+ struct RNode *nd_body;
385
+ } rb_node_begin_t;
386
+
387
+ typedef struct RNode_RESCUE {
388
+ NODE node;
389
+
390
+ struct RNode *nd_head;
391
+ struct RNode *nd_resq;
392
+ struct RNode *nd_else;
393
+ } rb_node_rescue_t;
394
+
395
+ typedef struct RNode_RESBODY {
396
+ NODE node;
397
+
398
+ struct RNode *nd_args;
399
+ struct RNode *nd_exc_var;
400
+ struct RNode *nd_body;
401
+ struct RNode *nd_next;
402
+ } rb_node_resbody_t;
403
+
404
+ typedef struct RNode_ENSURE {
405
+ NODE node;
406
+
407
+ struct RNode *nd_head;
408
+ struct RNode *nd_ensr;
409
+ } rb_node_ensure_t;
410
+
411
+ /* RNode_AND and RNode_OR should be same structure */
412
+ typedef struct RNode_AND {
413
+ NODE node;
414
+
415
+ struct RNode *nd_1st;
416
+ struct RNode *nd_2nd;
417
+ } rb_node_and_t;
418
+
419
+ typedef struct RNode_OR {
420
+ NODE node;
421
+
422
+ struct RNode *nd_1st;
423
+ struct RNode *nd_2nd;
424
+ } rb_node_or_t;
425
+
426
+ typedef struct RNode_MASGN {
427
+ NODE node;
428
+
429
+ struct RNode *nd_head;
430
+ struct RNode *nd_value;
431
+ struct RNode *nd_args;
432
+ } rb_node_masgn_t;
433
+
434
+ typedef struct RNode_LASGN {
435
+ NODE node;
436
+
437
+ ID nd_vid;
438
+ struct RNode *nd_value;
439
+ } rb_node_lasgn_t;
440
+
441
+ typedef struct RNode_DASGN {
442
+ NODE node;
443
+
444
+ ID nd_vid;
445
+ struct RNode *nd_value;
446
+ } rb_node_dasgn_t;
447
+
448
+ typedef struct RNode_GASGN {
449
+ NODE node;
450
+
451
+ ID nd_vid;
452
+ struct RNode *nd_value;
453
+ } rb_node_gasgn_t;
454
+
455
+ typedef struct RNode_IASGN {
456
+ NODE node;
457
+
458
+ ID nd_vid;
459
+ struct RNode *nd_value;
460
+ } rb_node_iasgn_t;
461
+
462
+ typedef struct RNode_CDECL {
463
+ NODE node;
464
+
465
+ ID nd_vid;
466
+ struct RNode *nd_value;
467
+ struct RNode *nd_else;
468
+ enum rb_parser_shareability shareability;
469
+ } rb_node_cdecl_t;
470
+
471
+ typedef struct RNode_CVASGN {
472
+ NODE node;
473
+
474
+ ID nd_vid;
475
+ struct RNode *nd_value;
476
+ } rb_node_cvasgn_t;
477
+
478
+ typedef struct RNode_OP_ASGN1 {
479
+ NODE node;
480
+
481
+ struct RNode *nd_recv;
482
+ ID nd_mid;
483
+ struct RNode *nd_index;
484
+ struct RNode *nd_rvalue;
485
+ } rb_node_op_asgn1_t;
486
+
487
+ typedef struct RNode_OP_ASGN2 {
488
+ NODE node;
489
+
490
+ struct RNode *nd_recv;
491
+ struct RNode *nd_value;
492
+ ID nd_vid;
493
+ ID nd_mid;
494
+ bool nd_aid;
495
+ } rb_node_op_asgn2_t;
496
+
497
+ typedef struct RNode_OP_ASGN_AND {
498
+ NODE node;
499
+
500
+ struct RNode *nd_head;
501
+ struct RNode *nd_value;
502
+ } rb_node_op_asgn_and_t;
503
+
504
+ typedef struct RNode_OP_ASGN_OR {
505
+ NODE node;
506
+
507
+ struct RNode *nd_head;
508
+ struct RNode *nd_value;
509
+ } rb_node_op_asgn_or_t;
510
+
511
+ typedef struct RNode_OP_CDECL {
512
+ NODE node;
513
+
514
+ struct RNode *nd_head;
515
+ struct RNode *nd_value;
516
+ ID nd_aid;
517
+ enum rb_parser_shareability shareability;
518
+ } rb_node_op_cdecl_t;
519
+
520
+ typedef struct RNode_CALL {
521
+ NODE node;
522
+
523
+ struct RNode *nd_recv;
524
+ ID nd_mid;
525
+ struct RNode *nd_args;
526
+ } rb_node_call_t;
527
+
528
+ typedef struct RNode_OPCALL {
529
+ NODE node;
530
+
531
+ struct RNode *nd_recv;
532
+ ID nd_mid;
533
+ struct RNode *nd_args;
534
+ } rb_node_opcall_t;
535
+
536
+ typedef struct RNode_FCALL {
537
+ NODE node;
538
+
539
+ ID nd_mid;
540
+ struct RNode *nd_args;
541
+ } rb_node_fcall_t;
542
+
543
+ typedef struct RNode_VCALL {
544
+ NODE node;
545
+
546
+ ID nd_mid;
547
+ } rb_node_vcall_t;
548
+
549
+ typedef struct RNode_QCALL {
550
+ NODE node;
551
+
552
+ struct RNode *nd_recv;
553
+ ID nd_mid;
554
+ struct RNode *nd_args;
555
+ } rb_node_qcall_t;
556
+
557
+ typedef struct RNode_SUPER {
558
+ NODE node;
559
+
560
+ struct RNode *nd_args;
561
+ } rb_node_super_t;
562
+
563
+ typedef struct RNode_ZSUPER {
564
+ NODE node;
565
+ } rb_node_zsuper_t;
566
+
567
+ /*
568
+
569
+ Structure of LIST:
570
+
571
+ LIST +--> LIST
572
+ * head --> element | * head
573
+ * alen (length of list) | * nd_end (point to the last LIST)
574
+ * next -----------------+ * next
575
+
576
+ */
577
+ typedef struct RNode_LIST {
578
+ NODE node;
579
+
580
+ struct RNode *nd_head; /* element */
581
+ union {
582
+ long nd_alen;
583
+ struct RNode *nd_end; /* Second list node has this structure */
584
+ } as;
585
+ struct RNode *nd_next; /* next list node */
586
+ } rb_node_list_t;
587
+
588
+ typedef struct RNode_ZLIST {
589
+ NODE node;
590
+ } rb_node_zlist_t;
591
+
592
+ typedef struct RNode_HASH {
593
+ NODE node;
594
+
595
+ struct RNode *nd_head;
596
+ long nd_brace;
597
+ } rb_node_hash_t;
598
+
599
+ typedef struct RNode_RETURN {
600
+ NODE node;
601
+
602
+ struct RNode *nd_stts;
603
+ } rb_node_return_t;
604
+
605
+ typedef struct RNode_YIELD {
606
+ NODE node;
607
+
608
+ struct RNode *nd_head;
609
+ } rb_node_yield_t;
610
+
611
+ typedef struct RNode_LVAR {
612
+ NODE node;
613
+
614
+ ID nd_vid;
615
+ } rb_node_lvar_t;
616
+
617
+ typedef struct RNode_DVAR {
618
+ NODE node;
619
+
620
+ ID nd_vid;
621
+ } rb_node_dvar_t;
622
+
623
+ typedef struct RNode_GVAR {
624
+ NODE node;
625
+
626
+ ID nd_vid;
627
+ } rb_node_gvar_t;
628
+
629
+ typedef struct RNode_IVAR {
630
+ NODE node;
631
+
632
+ ID nd_vid;
633
+ } rb_node_ivar_t;
634
+
635
+ typedef struct RNode_CONST {
636
+ NODE node;
637
+
638
+ ID nd_vid;
639
+ } rb_node_const_t;
640
+
641
+ typedef struct RNode_CVAR {
642
+ NODE node;
643
+
644
+ ID nd_vid;
645
+ } rb_node_cvar_t;
646
+
647
+ typedef struct RNode_NTH_REF {
648
+ NODE node;
649
+
650
+ long nd_nth;
651
+ } rb_node_nth_ref_t;
652
+
653
+ typedef struct RNode_BACK_REF {
654
+ NODE node;
655
+
656
+ long nd_nth;
657
+ } rb_node_back_ref_t;
658
+
659
+ /* RNode_MATCH and RNode_REGX should be same structure */
660
+ typedef struct RNode_MATCH {
661
+ NODE node;
662
+
663
+ struct rb_parser_string *string;
664
+ int options;
665
+ } rb_node_match_t;
666
+
667
+ typedef struct RNode_MATCH2 {
668
+ NODE node;
669
+
670
+ struct RNode *nd_recv;
671
+ struct RNode *nd_value;
672
+ struct RNode *nd_args;
673
+ } rb_node_match2_t;
674
+
675
+ typedef struct RNode_MATCH3 {
676
+ NODE node;
677
+
678
+ struct RNode *nd_recv;
679
+ struct RNode *nd_value;
680
+ } rb_node_match3_t;
681
+
682
+ typedef struct RNode_INTEGER {
683
+ NODE node;
684
+
685
+ char *val;
686
+ int minus;
687
+ int base;
688
+ } rb_node_integer_t;
689
+
690
+ typedef struct RNode_FLOAT {
691
+ NODE node;
692
+
693
+ char *val;
694
+ int minus;
695
+ } rb_node_float_t;
696
+
697
+ typedef struct RNode_RATIONAL {
698
+ NODE node;
699
+
700
+ char *val;
701
+ int minus;
702
+ int base;
703
+ int seen_point;
704
+ } rb_node_rational_t;
705
+
706
+ enum rb_numeric_type {
707
+ integer_literal,
708
+ float_literal,
709
+ rational_literal
710
+ };
711
+
712
+ typedef struct RNode_IMAGINARY {
713
+ NODE node;
714
+
715
+ char *val;
716
+ int minus;
717
+ int base;
718
+ int seen_point;
719
+ enum rb_numeric_type type;
720
+ } rb_node_imaginary_t;
721
+
722
+ /* RNode_STR and RNode_XSTR should be same structure */
723
+ typedef struct RNode_STR {
724
+ NODE node;
725
+
726
+ struct rb_parser_string *string;
727
+ } rb_node_str_t;
728
+
729
+ /* RNode_DSTR, RNode_DXSTR, RNode_DREGX and RNode_DSYM should be same structure */
730
+ typedef struct RNode_DSTR {
731
+ NODE node;
732
+
733
+ struct rb_parser_string *string;
734
+ union {
735
+ long nd_alen;
736
+ long nd_cflag;
737
+ struct RNode *nd_end; /* Second dstr node has this structure. See also RNode_LIST */
738
+ } as;
739
+ struct RNode_LIST *nd_next;
740
+ } rb_node_dstr_t;
741
+
742
+ typedef rb_node_str_t rb_node_xstr_t;
743
+
744
+ typedef rb_node_dstr_t rb_node_dxstr_t;
745
+
746
+ typedef struct RNode_EVSTR {
747
+ NODE node;
748
+
749
+ struct RNode *nd_body;
750
+ } rb_node_evstr_t;
751
+
752
+ typedef struct RNode_REGX {
753
+ NODE node;
754
+
755
+ struct rb_parser_string *string;
756
+ int options;
757
+ } rb_node_regx_t;
758
+
759
+ typedef rb_node_dstr_t rb_node_dregx_t;
760
+
761
+ typedef struct RNode_ONCE {
762
+ NODE node;
763
+
764
+ struct RNode *nd_body;
765
+ } rb_node_once_t;
766
+
767
+ struct rb_args_info {
768
+ NODE *pre_init;
769
+ NODE *post_init;
770
+
771
+ int pre_args_num; /* count of mandatory pre-arguments */
772
+ int post_args_num; /* count of mandatory post-arguments */
773
+
774
+ ID first_post_arg;
775
+
776
+ ID rest_arg;
777
+ ID block_arg;
778
+
779
+ struct RNode_KW_ARG *kw_args;
780
+ NODE *kw_rest_arg;
781
+
782
+ struct RNode_OPT_ARG *opt_args;
783
+ unsigned int no_kwarg: 1;
784
+ unsigned int ruby2_keywords: 1;
785
+ unsigned int forwarding: 1;
786
+ };
787
+
788
+ typedef struct RNode_ARGS {
789
+ NODE node;
790
+
791
+ struct rb_args_info nd_ainfo;
792
+ } rb_node_args_t;
793
+
794
+ typedef struct RNode_ARGS_AUX {
795
+ NODE node;
796
+
797
+ ID nd_pid;
798
+ int nd_plen;
799
+ struct RNode *nd_next;
800
+ } rb_node_args_aux_t;
801
+
802
+ typedef struct RNode_OPT_ARG {
803
+ NODE node;
804
+
805
+ struct RNode *nd_body;
806
+ struct RNode_OPT_ARG *nd_next;
807
+ } rb_node_opt_arg_t;
808
+
809
+ typedef struct RNode_KW_ARG {
810
+ NODE node;
811
+
812
+ struct RNode *nd_body;
813
+ struct RNode_KW_ARG *nd_next;
814
+ } rb_node_kw_arg_t;
815
+
816
+ typedef struct RNode_POSTARG {
817
+ NODE node;
818
+
819
+ struct RNode *nd_1st;
820
+ struct RNode *nd_2nd;
821
+ } rb_node_postarg_t;
822
+
823
+ typedef struct RNode_ARGSCAT {
824
+ NODE node;
825
+
826
+ struct RNode *nd_head;
827
+ struct RNode *nd_body;
828
+ } rb_node_argscat_t;
829
+
830
+ typedef struct RNode_ARGSPUSH {
831
+ NODE node;
832
+
833
+ struct RNode *nd_head;
834
+ struct RNode *nd_body;
835
+ } rb_node_argspush_t;
836
+
837
+ typedef struct RNode_SPLAT {
838
+ NODE node;
839
+
840
+ struct RNode *nd_head;
841
+ } rb_node_splat_t;
842
+
843
+ typedef struct RNode_BLOCK_PASS {
844
+ NODE node;
845
+
846
+ struct RNode *nd_head;
847
+ struct RNode *nd_body;
848
+ unsigned int forwarding: 1;
849
+ } rb_node_block_pass_t;
850
+
851
+ typedef struct RNode_DEFN {
852
+ NODE node;
853
+
854
+ ID nd_mid;
855
+ struct RNode *nd_defn;
856
+ } rb_node_defn_t;
857
+
858
+ typedef struct RNode_DEFS {
859
+ NODE node;
860
+
861
+ struct RNode *nd_recv;
862
+ ID nd_mid;
863
+ struct RNode *nd_defn;
864
+ } rb_node_defs_t;
865
+
866
+ typedef struct RNode_ALIAS {
867
+ NODE node;
868
+
869
+ struct RNode *nd_1st;
870
+ struct RNode *nd_2nd;
871
+ } rb_node_alias_t;
872
+
873
+ typedef struct RNode_VALIAS {
874
+ NODE node;
875
+
876
+ ID nd_alias;
877
+ ID nd_orig;
878
+ } rb_node_valias_t;
879
+
880
+ typedef struct RNode_UNDEF {
881
+ NODE node;
882
+
883
+ rb_parser_ary_t *nd_undefs;
884
+ } rb_node_undef_t;
885
+
886
+ typedef struct RNode_CLASS {
887
+ NODE node;
888
+
889
+ struct RNode *nd_cpath;
890
+ struct RNode *nd_body;
891
+ struct RNode *nd_super;
892
+ } rb_node_class_t;
893
+
894
+ typedef struct RNode_MODULE {
895
+ NODE node;
896
+
897
+ struct RNode *nd_cpath;
898
+ struct RNode *nd_body;
899
+ } rb_node_module_t;
900
+
901
+ typedef struct RNode_SCLASS {
902
+ NODE node;
903
+
904
+ struct RNode *nd_recv;
905
+ struct RNode *nd_body;
906
+ } rb_node_sclass_t;
907
+
908
+ typedef struct RNode_COLON2 {
909
+ NODE node;
910
+
911
+ struct RNode *nd_head;
912
+ ID nd_mid;
913
+ } rb_node_colon2_t;
914
+
915
+ typedef struct RNode_COLON3 {
916
+ NODE node;
917
+
918
+ ID nd_mid;
919
+ } rb_node_colon3_t;
920
+
921
+ /* RNode_DOT2, RNode_DOT3, RNode_FLIP2 and RNode_FLIP3 should be same structure */
922
+ typedef struct RNode_DOT2 {
923
+ NODE node;
924
+
925
+ struct RNode *nd_beg;
926
+ struct RNode *nd_end;
927
+ } rb_node_dot2_t;
928
+
929
+ typedef struct RNode_DOT3 {
930
+ NODE node;
931
+
932
+ struct RNode *nd_beg;
933
+ struct RNode *nd_end;
934
+ } rb_node_dot3_t;
935
+
936
+ typedef rb_node_dot2_t rb_node_flip2_t;
937
+ typedef rb_node_dot3_t rb_node_flip3_t;
938
+
939
+ typedef struct RNode_SELF {
940
+ NODE node;
941
+
942
+ long nd_state; /* Default 1. See NEW_SELF. */
943
+ } rb_node_self_t;
944
+
945
+ typedef struct RNode_NIL {
946
+ NODE node;
947
+ } rb_node_nil_t;
948
+
949
+ typedef struct RNode_TRUE {
950
+ NODE node;
951
+ } rb_node_true_t;
952
+
953
+ typedef struct RNode_FALSE {
954
+ NODE node;
955
+ } rb_node_false_t;
956
+
957
+ typedef struct RNode_ERRINFO {
958
+ NODE node;
959
+ } rb_node_errinfo_t;
960
+
961
+ typedef struct RNode_DEFINED {
962
+ NODE node;
963
+
964
+ struct RNode *nd_head;
965
+ } rb_node_defined_t;
966
+
967
+ typedef struct RNode_POSTEXE {
968
+ NODE node;
969
+
970
+ struct RNode *nd_body;
971
+ } rb_node_postexe_t;
972
+
973
+ typedef struct RNode_SYM {
974
+ NODE node;
975
+
976
+ struct rb_parser_string *string;
977
+ } rb_node_sym_t;
978
+
979
+ typedef rb_node_dstr_t rb_node_dsym_t;
980
+
981
+ typedef struct RNode_ATTRASGN {
982
+ NODE node;
983
+
984
+ struct RNode *nd_recv;
985
+ ID nd_mid;
986
+ struct RNode *nd_args;
987
+ } rb_node_attrasgn_t;
988
+
989
+ typedef struct RNode_LAMBDA {
990
+ NODE node;
991
+
992
+ struct RNode *nd_body;
993
+ } rb_node_lambda_t;
994
+
995
+ typedef struct RNode_ARYPTN {
996
+ NODE node;
997
+
998
+ struct RNode *nd_pconst;
999
+ NODE *pre_args;
1000
+ NODE *rest_arg;
1001
+ NODE *post_args;
1002
+ } rb_node_aryptn_t;
1003
+
1004
+ typedef struct RNode_HSHPTN {
1005
+ NODE node;
1006
+
1007
+ struct RNode *nd_pconst;
1008
+ struct RNode *nd_pkwargs;
1009
+ struct RNode *nd_pkwrestarg;
1010
+ } rb_node_hshptn_t;
1011
+
1012
+ typedef struct RNode_FNDPTN {
1013
+ NODE node;
1014
+
1015
+ struct RNode *nd_pconst;
1016
+ NODE *pre_rest_arg;
1017
+ NODE *args;
1018
+ NODE *post_rest_arg;
1019
+ } rb_node_fndptn_t;
1020
+
1021
+ typedef struct RNode_LINE {
1022
+ NODE node;
1023
+ } rb_node_line_t;
1024
+
1025
+ typedef struct RNode_FILE {
1026
+ NODE node;
1027
+
1028
+ struct rb_parser_string *path;
1029
+ } rb_node_file_t;
1030
+
1031
+ typedef struct RNode_ENCODING {
1032
+ NODE node;
1033
+ rb_encoding *enc;
1034
+ } rb_node_encoding_t;
1035
+
1036
+ typedef struct RNode_ERROR {
1037
+ NODE node;
1038
+ } rb_node_error_t;
1039
+
1040
+ #define RNODE(obj) ((NODE *)(obj))
1041
+
1042
+ #define RNODE_SCOPE(node) ((rb_node_scope_t *)(node))
1043
+ #define RNODE_BLOCK(node) ((rb_node_block_t *)(node))
1044
+ #define RNODE_IF(node) ((rb_node_if_t *)(node))
1045
+ #define RNODE_UNLESS(node) ((rb_node_unless_t *)(node))
1046
+ #define RNODE_CASE(node) ((rb_node_case_t *)(node))
1047
+ #define RNODE_CASE2(node) ((rb_node_case2_t *)(node))
1048
+ #define RNODE_CASE3(node) ((rb_node_case3_t *)(node))
1049
+ #define RNODE_WHEN(node) ((rb_node_when_t *)(node))
1050
+ #define RNODE_IN(node) ((rb_node_in_t *)(node))
1051
+ #define RNODE_WHILE(node) ((rb_node_while_t *)(node))
1052
+ #define RNODE_UNTIL(node) ((rb_node_until_t *)(node))
1053
+ #define RNODE_ITER(node) ((rb_node_iter_t *)(node))
1054
+ #define RNODE_FOR(node) ((rb_node_for_t *)(node))
1055
+ #define RNODE_FOR_MASGN(node) ((rb_node_for_masgn_t *)(node))
1056
+ #define RNODE_BREAK(node) ((rb_node_break_t *)(node))
1057
+ #define RNODE_NEXT(node) ((rb_node_next_t *)(node))
1058
+ #define RNODE_REDO(node) ((rb_node_redo_t *)(node))
1059
+ #define RNODE_RETRY(node) ((rb_node_retry_t *)(node))
1060
+ #define RNODE_BEGIN(node) ((rb_node_begin_t *)(node))
1061
+ #define RNODE_RESCUE(node) ((rb_node_rescue_t *)(node))
1062
+ #define RNODE_RESBODY(node) ((rb_node_resbody_t *)(node))
1063
+ #define RNODE_ENSURE(node) ((rb_node_ensure_t *)(node))
1064
+ #define RNODE_AND(node) ((rb_node_and_t *)(node))
1065
+ #define RNODE_OR(node) ((rb_node_or_t *)(node))
1066
+ #define RNODE_MASGN(node) ((rb_node_masgn_t *)(node))
1067
+ #define RNODE_LASGN(node) ((rb_node_lasgn_t *)(node))
1068
+ #define RNODE_DASGN(node) ((rb_node_dasgn_t *)(node))
1069
+ #define RNODE_GASGN(node) ((rb_node_gasgn_t *)(node))
1070
+ #define RNODE_IASGN(node) ((rb_node_iasgn_t *)(node))
1071
+ #define RNODE_CDECL(node) ((rb_node_cdecl_t *)(node))
1072
+ #define RNODE_CVASGN(node) ((rb_node_cvasgn_t *)(node))
1073
+ #define RNODE_OP_ASGN1(node) ((rb_node_op_asgn1_t *)(node))
1074
+ #define RNODE_OP_ASGN2(node) ((rb_node_op_asgn2_t *)(node))
1075
+ #define RNODE_OP_ASGN_AND(node) ((rb_node_op_asgn_and_t *)(node))
1076
+ #define RNODE_OP_ASGN_OR(node) ((rb_node_op_asgn_or_t *)(node))
1077
+ #define RNODE_OP_CDECL(node) ((rb_node_op_cdecl_t *)(node))
1078
+ #define RNODE_CALL(node) ((rb_node_call_t *)(node))
1079
+ #define RNODE_OPCALL(node) ((rb_node_opcall_t *)(node))
1080
+ #define RNODE_FCALL(node) ((rb_node_fcall_t *)(node))
1081
+ #define RNODE_VCALL(node) ((rb_node_vcall_t *)(node))
1082
+ #define RNODE_QCALL(node) ((rb_node_qcall_t *)(node))
1083
+ #define RNODE_SUPER(node) ((rb_node_super_t *)(node))
1084
+ #define RNODE_ZSUPER(node) ((rb_node_zsuper_t *)(node))
1085
+ #define RNODE_LIST(node) ((rb_node_list_t *)(node))
1086
+ #define RNODE_ZLIST(node) ((rb_node_zlist_t *)(node))
1087
+ #define RNODE_HASH(node) ((rb_node_hash_t *)(node))
1088
+ #define RNODE_RETURN(node) ((rb_node_return_t *)(node))
1089
+ #define RNODE_YIELD(node) ((rb_node_yield_t *)(node))
1090
+ #define RNODE_LVAR(node) ((rb_node_lvar_t *)(node))
1091
+ #define RNODE_DVAR(node) ((rb_node_dvar_t *)(node))
1092
+ #define RNODE_GVAR(node) ((rb_node_gvar_t *)(node))
1093
+ #define RNODE_IVAR(node) ((rb_node_ivar_t *)(node))
1094
+ #define RNODE_CONST(node) ((rb_node_const_t *)(node))
1095
+ #define RNODE_CVAR(node) ((rb_node_cvar_t *)(node))
1096
+ #define RNODE_NTH_REF(node) ((rb_node_nth_ref_t *)(node))
1097
+ #define RNODE_BACK_REF(node) ((rb_node_back_ref_t *)(node))
1098
+ #define RNODE_MATCH(node) ((rb_node_match_t *)(node))
1099
+ #define RNODE_MATCH2(node) ((rb_node_match2_t *)(node))
1100
+ #define RNODE_MATCH3(node) ((rb_node_match3_t *)(node))
1101
+ #define RNODE_INTEGER(node) ((rb_node_integer_t *)(node))
1102
+ #define RNODE_FLOAT(node) ((rb_node_float_t *)(node))
1103
+ #define RNODE_RATIONAL(node) ((rb_node_rational_t *)(node))
1104
+ #define RNODE_IMAGINARY(node) ((rb_node_imaginary_t *)(node))
1105
+ #define RNODE_STR(node) ((rb_node_str_t *)(node))
1106
+ #define RNODE_DSTR(node) ((rb_node_dstr_t *)(node))
1107
+ #define RNODE_XSTR(node) ((rb_node_xstr_t *)(node))
1108
+ #define RNODE_DXSTR(node) ((rb_node_dxstr_t *)(node))
1109
+ #define RNODE_EVSTR(node) ((rb_node_evstr_t *)(node))
1110
+ #define RNODE_REGX(node) ((rb_node_regx_t *)(node))
1111
+ #define RNODE_DREGX(node) ((rb_node_dregx_t *)(node))
1112
+ #define RNODE_ONCE(node) ((rb_node_once_t *)(node))
1113
+ #define RNODE_ARGS(node) ((rb_node_args_t *)(node))
1114
+ #define RNODE_ARGS_AUX(node) ((rb_node_args_aux_t *)(node))
1115
+ #define RNODE_OPT_ARG(node) ((rb_node_opt_arg_t *)(node))
1116
+ #define RNODE_KW_ARG(node) ((rb_node_kw_arg_t *)(node))
1117
+ #define RNODE_POSTARG(node) ((rb_node_postarg_t *)(node))
1118
+ #define RNODE_ARGSCAT(node) ((rb_node_argscat_t *)(node))
1119
+ #define RNODE_ARGSPUSH(node) ((rb_node_argspush_t *)(node))
1120
+ #define RNODE_SPLAT(node) ((rb_node_splat_t *)(node))
1121
+ #define RNODE_BLOCK_PASS(node) ((rb_node_block_pass_t *)(node))
1122
+ #define RNODE_DEFN(node) ((rb_node_defn_t *)(node))
1123
+ #define RNODE_DEFS(node) ((rb_node_defs_t *)(node))
1124
+ #define RNODE_ALIAS(node) ((rb_node_alias_t *)(node))
1125
+ #define RNODE_VALIAS(node) ((rb_node_valias_t *)(node))
1126
+ #define RNODE_UNDEF(node) ((rb_node_undef_t *)(node))
1127
+ #define RNODE_CLASS(node) ((rb_node_class_t *)(node))
1128
+ #define RNODE_MODULE(node) ((rb_node_module_t *)(node))
1129
+ #define RNODE_SCLASS(node) ((rb_node_sclass_t *)(node))
1130
+ #define RNODE_COLON2(node) ((rb_node_colon2_t *)(node))
1131
+ #define RNODE_COLON3(node) ((rb_node_colon3_t *)(node))
1132
+ #define RNODE_DOT2(node) ((rb_node_dot2_t *)(node))
1133
+ #define RNODE_DOT3(node) ((rb_node_dot3_t *)(node))
1134
+ #define RNODE_FLIP2(node) ((rb_node_flip2_t *)(node))
1135
+ #define RNODE_FLIP3(node) ((rb_node_flip3_t *)(node))
1136
+ #define RNODE_SELF(node) ((rb_node_self_t *)(node))
1137
+ #define RNODE_NIL(node) ((rb_node_nil_t *)(node))
1138
+ #define RNODE_TRUE(node) ((rb_node_true_t *)(node))
1139
+ #define RNODE_FALSE(node) ((rb_node_false_t *)(node))
1140
+ #define RNODE_ERRINFO(node) ((rb_node_errinfo_t *)(node))
1141
+ #define RNODE_DEFINED(node) ((rb_node_defined_t *)(node))
1142
+ #define RNODE_POSTEXE(node) ((rb_node_postexe_t *)(node))
1143
+ #define RNODE_SYM(node) ((rb_node_sym_t *)(node))
1144
+ #define RNODE_DSYM(node) ((rb_node_dsym_t *)(node))
1145
+ #define RNODE_ATTRASGN(node) ((rb_node_attrasgn_t *)(node))
1146
+ #define RNODE_LAMBDA(node) ((rb_node_lambda_t *)(node))
1147
+ #define RNODE_ARYPTN(node) ((rb_node_aryptn_t *)(node))
1148
+ #define RNODE_HSHPTN(node) ((rb_node_hshptn_t *)(node))
1149
+ #define RNODE_FNDPTN(node) ((rb_node_fndptn_t *)(node))
1150
+ #define RNODE_LINE(node) ((rb_node_line_t *)(node))
1151
+ #define RNODE_FILE(node) ((rb_node_file_t *)(node))
1152
+ #define RNODE_ENCODING(node) ((rb_node_encoding_t *)(node))
1153
+
1154
+ /* FL : 0..4: T_TYPES, 5: KEEP_WB, 6: PROMOTED, 7: FINALIZE, 8: UNUSED, 9: UNUSED, 10: EXIVAR, 11: FREEZE */
1155
+ /* NODE_FL: 0..4: UNUSED, 5: UNUSED, 6: UNUSED, 7: NODE_FL_NEWLINE,
1156
+ * 8..14: nd_type,
1157
+ * 15..: nd_line
1158
+ */
1159
+ #define NODE_FL_NEWLINE (((VALUE)1)<<7)
1160
+
1161
+ #define NODE_TYPESHIFT 8
1162
+ #define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT)
1163
+
1164
+ #define nd_fl_newline(n) ((n)->flags & NODE_FL_NEWLINE)
1165
+ #define nd_set_fl_newline(n) ((n)->flags |= NODE_FL_NEWLINE)
1166
+ #define nd_unset_fl_newline(n) ((n)->flags &= ~NODE_FL_NEWLINE)
1167
+
1168
+ #define nd_type(n) ((int) ((RNODE(n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
1169
+ #define nd_set_type(n,t) \
1170
+ rb_node_set_type(n, t)
1171
+ #define nd_init_type(n,t) \
1172
+ (n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK))
1173
+
1174
+ typedef struct node_buffer_struct node_buffer_t;
1175
+
1176
+ #ifdef UNIVERSAL_PARSER
1177
+ typedef struct rb_parser_config_struct rb_parser_config_t;
1178
+ #endif
1179
+
1180
+ typedef struct rb_ast_body_struct {
1181
+ const NODE *root;
1182
+ rb_parser_ary_t *script_lines;
1183
+ int line_count;
1184
+ signed int frozen_string_literal:2; /* -1: not specified, 0: false, 1: true */
1185
+ signed int coverage_enabled:2; /* -1: not specified, 0: false, 1: true */
1186
+ } rb_ast_body_t;
1187
+ typedef struct rb_ast_struct {
1188
+ node_buffer_t *node_buffer;
1189
+ rb_ast_body_t body;
1190
+ #ifdef UNIVERSAL_PARSER
1191
+ const rb_parser_config_t *config;
1192
+ #endif
1193
+ } rb_ast_t;
1194
+
1195
+
1196
+
1197
+ /*
1198
+ * Parser Interface
1199
+ */
1200
+
1201
+
1202
+ typedef struct parser_params rb_parser_t;
1203
+ #ifndef INTERNAL_IMEMO_H
1204
+ typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t;
1205
+ #endif
1206
+
1207
+ #ifdef UNIVERSAL_PARSER
1208
+ typedef struct rb_parser_config_struct {
1209
+ /* Memory */
1210
+ void *(*malloc)(size_t size);
1211
+ void *(*calloc)(size_t number, size_t size);
1212
+ void *(*realloc)(void *ptr, size_t newsiz);
1213
+ void (*free)(void *ptr);
1214
+ void *(*alloc_n)(size_t nelems, size_t elemsiz);
1215
+ void *(*alloc)(size_t elemsiz);
1216
+ void *(*realloc_n)(void *ptr, size_t newelems, size_t newsiz);
1217
+ void *(*zalloc)(size_t elemsiz);
1218
+ void *(*rb_memmove)(void *dest, const void *src, size_t t, size_t n);
1219
+ void *(*nonempty_memcpy)(void *dest, const void *src, size_t t, size_t n);
1220
+ void *(*xmalloc_mul_add)(size_t x, size_t y, size_t z);
1221
+
1222
+ // VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
1223
+ VALUE (*compile_callback)(VALUE (*func)(VALUE), VALUE arg);
1224
+ NODE *(*reg_named_capture_assign)(struct parser_params* p, VALUE regexp, const rb_code_location_t *loc);
1225
+
1226
+ /* Variable */
1227
+ VALUE (*attr_get)(VALUE obj, ID id);
1228
+
1229
+ /* Array */
1230
+ VALUE (*ary_new)(void);
1231
+ VALUE (*ary_push)(VALUE ary, VALUE elem);
1232
+ VALUE (*ary_new_from_args)(long n, ...);
1233
+ VALUE (*ary_unshift)(VALUE ary, VALUE item);
1234
+
1235
+ /* Symbol */
1236
+ ID (*make_temporary_id)(size_t n);
1237
+ int (*is_local_id)(ID);
1238
+ int (*is_attrset_id)(ID);
1239
+ int (*is_global_name_punct)(const int c);
1240
+ int (*id_type)(ID id);
1241
+ ID (*id_attrset)(ID);
1242
+ ID (*intern)(const char *name);
1243
+ ID (*intern2)(const char *name, long len);
1244
+ ID (*intern3)(const char *name, long len, rb_encoding *enc);
1245
+ ID (*intern_str)(VALUE str);
1246
+ int (*is_notop_id)(ID);
1247
+ int (*enc_symname_type)(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset);
1248
+ const char *(*id2name)(ID id);
1249
+ VALUE (*id2str)(ID id);
1250
+ VALUE (*id2sym)(ID x);
1251
+ ID (*sym2id)(VALUE sym);
1252
+
1253
+ /* String */
1254
+ RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
1255
+ VALUE (*str_catf)(VALUE str, const char *format, ...);
1256
+ VALUE (*str_cat_cstr)(VALUE str, const char *ptr);
1257
+ void (*str_modify)(VALUE str);
1258
+ void (*str_set_len)(VALUE str, long len);
1259
+ VALUE (*str_cat)(VALUE str, const char *ptr, long len);
1260
+ VALUE (*str_resize)(VALUE str, long len);
1261
+ VALUE (*str_new)(const char *ptr, long len);
1262
+ VALUE (*str_new_cstr)(const char *ptr);
1263
+ VALUE (*str_to_interned_str)(VALUE);
1264
+ int (*is_ascii_string)(VALUE str);
1265
+ VALUE (*enc_str_new)(const char *ptr, long len, rb_encoding *enc);
1266
+ RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0)
1267
+ VALUE (*str_vcatf)(VALUE str, const char *fmt, va_list ap);
1268
+ RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2)
1269
+ VALUE (*rb_sprintf)(const char *format, ...);
1270
+ char *(*rstring_ptr)(VALUE str);
1271
+ char *(*rstring_end)(VALUE str);
1272
+ long (*rstring_len)(VALUE str);
1273
+ VALUE (*obj_as_string)(VALUE);
1274
+
1275
+ /* Numeric */
1276
+ VALUE (*int2num)(int v);
1277
+
1278
+ /* IO */
1279
+ int (*stderr_tty_p)(void);
1280
+ void (*write_error_str)(VALUE mesg);
1281
+ VALUE (*io_write)(VALUE io, VALUE str);
1282
+ VALUE (*io_flush)(VALUE io);
1283
+ VALUE (*io_puts)(int argc, const VALUE *argv, VALUE out);
1284
+
1285
+ /* IO (Ractor) */
1286
+ VALUE (*debug_output_stdout)(void);
1287
+ VALUE (*debug_output_stderr)(void);
1288
+
1289
+ /* Encoding */
1290
+ int (*is_usascii_enc)(rb_encoding *enc);
1291
+ int (*enc_isalnum)(OnigCodePoint c, rb_encoding *enc);
1292
+ int (*enc_precise_mbclen)(const char *p, const char *e, rb_encoding *enc);
1293
+ int (*mbclen_charfound_p)(int len);
1294
+ int (*mbclen_charfound_len)(int len);
1295
+ const char *(*enc_name)(rb_encoding *enc);
1296
+ char *(*enc_prev_char)(const char *s, const char *p, const char *e, rb_encoding *enc);
1297
+ rb_encoding* (*enc_get)(VALUE obj);
1298
+ int (*enc_asciicompat)(rb_encoding *enc);
1299
+ rb_encoding *(*utf8_encoding)(void);
1300
+ VALUE (*enc_associate)(VALUE obj, rb_encoding *enc);
1301
+ rb_encoding *(*ascii8bit_encoding)(void);
1302
+ int (*enc_codelen)(int c, rb_encoding *enc);
1303
+ int (*enc_mbcput)(unsigned int c, void *buf, rb_encoding *enc);
1304
+ int (*enc_find_index)(const char *name);
1305
+ rb_encoding *(*enc_from_index)(int idx);
1306
+ int (*enc_isspace)(OnigCodePoint c, rb_encoding *enc);
1307
+ rb_encoding *(*usascii_encoding)(void);
1308
+ int (*enc_mbminlen)(rb_encoding *enc);
1309
+ bool (*enc_isascii)(OnigCodePoint c, rb_encoding *enc);
1310
+ OnigCodePoint (*enc_mbc_to_codepoint)(const char *p, const char *e, rb_encoding *enc);
1311
+
1312
+ /* Compile */
1313
+ // int rb_local_defined(ID id, const rb_iseq_t *iseq);
1314
+ int (*local_defined)(ID, const void*);
1315
+ // int rb_dvar_defined(ID id, const rb_iseq_t *iseq);
1316
+ int (*dvar_defined)(ID, const void*);
1317
+
1318
+ /* Error (Exception) */
1319
+ RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 6, 0)
1320
+ VALUE (*syntax_error_append)(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
1321
+ RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
1322
+ void (*raise)(VALUE exc, const char *fmt, ...);
1323
+ VALUE (*syntax_error_new)(void);
1324
+
1325
+ /* Eval */
1326
+ VALUE (*errinfo)(void);
1327
+ void (*set_errinfo)(VALUE err);
1328
+ void (*exc_raise)(VALUE mesg);
1329
+ VALUE (*make_exception)(int argc, const VALUE *argv);
1330
+
1331
+ /* GC */
1332
+ void (*sized_xfree)(void *x, size_t size);
1333
+ void *(*sized_realloc_n)(void *ptr, size_t new_count, size_t element_size, size_t old_count);
1334
+ void (*gc_guard)(VALUE);
1335
+ void (*gc_mark)(VALUE);
1336
+
1337
+ /* Re */
1338
+ VALUE (*reg_compile)(VALUE str, int options, const char *sourcefile, int sourceline);
1339
+ VALUE (*reg_check_preprocess)(VALUE str);
1340
+ int (*memcicmp)(const void *x, const void *y, long len);
1341
+
1342
+ /* Error */
1343
+ void (*compile_warn)(const char *file, int line, const char *fmt, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1344
+ void (*compile_warning)(const char *file, int line, const char *fmt, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1345
+ void (*bug)(const char *fmt, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1346
+ void (*fatal)(const char *fmt, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1347
+ VALUE (*verbose)(void);
1348
+ int *(*errno_ptr)(void);
1349
+
1350
+ /* VM */
1351
+ VALUE (*make_backtrace)(void);
1352
+
1353
+ /* Util */
1354
+ unsigned long (*scan_hex)(const char *start, size_t len, size_t *retlen);
1355
+ unsigned long (*scan_oct)(const char *start, size_t len, size_t *retlen);
1356
+ unsigned long (*scan_digits)(const char *str, ssize_t len, int base, size_t *retlen, int *overflow);
1357
+ double (*strtod)(const char *s00, char **se);
1358
+
1359
+ /* Misc */
1360
+ int (*rtest)(VALUE obj);
1361
+ int (*nil_p)(VALUE obj);
1362
+ VALUE qnil;
1363
+ VALUE qfalse;
1364
+ VALUE (*eArgError)(void);
1365
+ int (*long2int)(long);
1366
+
1367
+ /* For Ripper */
1368
+ int enc_coderange_7bit;
1369
+ int enc_coderange_unknown;
1370
+ VALUE (*static_id2sym)(ID id);
1371
+ long (*str_coderange_scan_restartable)(const char *s, const char *e, rb_encoding *enc, int *cr);
1372
+ } rb_parser_config_t;
1373
+
1374
+ #undef rb_encoding
1375
+ #undef OnigCodePoint
1376
+ #endif /* UNIVERSAL_PARSER */
1377
+
1378
+ RUBY_SYMBOL_EXPORT_BEGIN
1379
+ void rb_ruby_parser_free(void *ptr);
1380
+
1381
+ #ifdef UNIVERSAL_PARSER
1382
+ rb_parser_t *rb_ruby_parser_allocate(const rb_parser_config_t *config);
1383
+ rb_parser_t *rb_ruby_parser_new(const rb_parser_config_t *config);
1384
+ #endif
1385
+
1386
+ long rb_parser_string_length(rb_parser_string_t *str);
1387
+ char *rb_parser_string_pointer(rb_parser_string_t *str);
1388
+
1389
+ RUBY_SYMBOL_EXPORT_END
1390
+
1391
+ #endif /* RUBY_RUBYPARSER_H */