Ruby 4.1.0dev (2026-09-07 revision b57404b461ba8bf34e802d86b0db78388216e182)
static_literals.c
1#include "prism/internal/static_literals.h"
2
5
6#include "prism/internal/allocator.h"
7#include "prism/internal/buffer.h"
8#include "prism/internal/integer.h"
9#include "prism/internal/isinf.h"
10#include "prism/internal/stringy.h"
11
12#include <assert.h>
13#include <math.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17
23typedef struct {
26
28 const uint8_t *start;
29
31 int32_t start_line;
32
36
37static PRISM_INLINE uint32_t
38murmur_scramble(uint32_t value) {
39 value *= 0xcc9e2d51;
40 value = (value << 15) | (value >> 17);
41 value *= 0x1b873593;
42 return value;
43}
44
50static uint32_t
51murmur_hash(const uint8_t *key, size_t length) {
52 uint32_t hash = 0x9747b28c;
53 uint32_t segment;
54
55 for (size_t index = length >> 2; index; index--) {
56 memcpy(&segment, key, sizeof(uint32_t));
57 key += sizeof(uint32_t);
58 hash ^= murmur_scramble(segment);
59 hash = (hash << 13) | (hash >> 19);
60 hash = hash * 5 + 0xe6546b64;
61 }
62
63 segment = 0;
64 for (size_t index = length & 3; index; index--) {
65 segment <<= 8;
66 segment |= key[index - 1];
67 }
68
69 hash ^= murmur_scramble(segment);
70 hash ^= (uint32_t) length;
71 hash ^= hash >> 16;
72 hash *= 0x85ebca6b;
73 hash ^= hash >> 13;
74 hash *= 0xc2b2ae35;
75 hash ^= hash >> 16;
76 return hash;
77}
78
82static uint32_t
83integer_hash(const pm_integer_t *integer) {
84 uint32_t hash;
85 if (integer->values) {
86 hash = murmur_hash((const uint8_t *) integer->values, sizeof(uint32_t) * integer->length);
87 } else {
88 hash = murmur_hash((const uint8_t *) &integer->value, sizeof(uint32_t));
89 }
90
91 if (integer->negative) {
92 hash ^= murmur_scramble((uint32_t) 1);
93 }
94
95 return hash;
96}
97
108static pm_node_flags_t
109node_encoding_flags(const pm_static_literals_metadata_t *metadata, const pm_node_t *node) {
110 switch (PM_NODE_TYPE(node)) {
111 case PM_STRING_NODE: {
112 pm_node_flags_t mask = PM_STRING_FLAGS_FORCED_BINARY_ENCODING;
113 if (metadata->encoding != PM_ENCODING_UTF_8_ENTRY) mask |= PM_STRING_FLAGS_FORCED_UTF8_ENCODING;
114 return node->flags & mask;
115 }
116 case PM_SYMBOL_NODE: {
117 pm_node_flags_t mask = PM_SYMBOL_FLAGS_FORCED_BINARY_ENCODING | PM_SYMBOL_FLAGS_FORCED_US_ASCII_ENCODING;
118 if (metadata->encoding != PM_ENCODING_UTF_8_ENTRY) mask |= PM_SYMBOL_FLAGS_FORCED_UTF8_ENCODING;
119 return node->flags & mask;
120 }
121 case PM_SOURCE_FILE_NODE:
122 /* __FILE__ takes the encoding of the filepath, and every instance
123 * of it in a parse resolves the same way. */
124 return 0;
125 default:
126 assert(false && "unreachable");
127 return 0;
128 }
129}
130
136static uint32_t
137node_hash(const pm_static_literals_metadata_t *metadata, const pm_node_t *node) {
138 switch (PM_NODE_TYPE(node)) {
139 case PM_INTEGER_NODE: {
140 // Integers hash their value.
141 const pm_integer_node_t *cast = (const pm_integer_node_t *) node;
142 return integer_hash(&cast->value);
143 }
144 case PM_SOURCE_LINE_NODE: {
145 // Source lines hash their line number.
146 const pm_line_column_t line_column = pm_line_offset_list_line_column(metadata->line_offsets, node->location.start, metadata->start_line);
147 const int32_t *value = &line_column.line;
148 return murmur_hash((const uint8_t *) value, sizeof(int32_t));
149 }
150 case PM_FLOAT_NODE: {
151 // Floats hash their value.
152 const double *value = &((const pm_float_node_t *) node)->value;
153 return murmur_hash((const uint8_t *) value, sizeof(double));
154 }
155 case PM_RATIONAL_NODE: {
156 // Rationals hash their numerator and denominator.
157 const pm_rational_node_t *cast = (const pm_rational_node_t *) node;
158 return integer_hash(&cast->numerator) ^ integer_hash(&cast->denominator) ^ murmur_scramble((uint32_t) cast->base.type);
159 }
160 case PM_IMAGINARY_NODE: {
161 // Imaginaries hash their numeric value. Because their numeric value
162 // is stored as a subnode, we hash that node and then mix in the
163 // fact that this is an imaginary node.
164 const pm_node_t *numeric = ((const pm_imaginary_node_t *) node)->numeric;
165 return node_hash(metadata, numeric) ^ murmur_scramble((uint32_t) node->type);
166 }
167 case PM_STRING_NODE: {
168 // Strings hash their value and mix in their flags so that different
169 // encodings are not considered equal.
170 const pm_string_t *value = &((const pm_string_node_t *) node)->unescaped;
171 return murmur_hash(pm_string_source(value), pm_string_length(value) * sizeof(uint8_t)) ^ murmur_scramble((uint32_t) node_encoding_flags(metadata, node));
172 }
173 case PM_SOURCE_FILE_NODE: {
174 // Source files hash their value and mix in their flags so that
175 // different encodings are not considered equal.
176 const pm_string_t *value = &((const pm_source_file_node_t *) node)->filepath;
177 return murmur_hash(pm_string_source(value), pm_string_length(value) * sizeof(uint8_t));
178 }
179 case PM_REGULAR_EXPRESSION_NODE: {
180 // Regular expressions hash their value and mix in their flags so
181 // that different encodings are not considered equal.
182 const pm_string_t *value = &((const pm_regular_expression_node_t *) node)->unescaped;
183 return murmur_hash(pm_string_source(value), pm_string_length(value) * sizeof(uint8_t)) ^ murmur_scramble((uint32_t) node->flags);
184 }
185 case PM_SYMBOL_NODE: {
186 // Symbols hash their value and mix in their flags so that different
187 // encodings are not considered equal.
188 const pm_string_t *value = &((const pm_symbol_node_t *) node)->unescaped;
189 return murmur_hash(pm_string_source(value), pm_string_length(value) * sizeof(uint8_t)) ^ murmur_scramble((uint32_t) node_encoding_flags(metadata, node));
190 }
191 default:
192 assert(false && "unreachable");
193 return 0;
194 }
195}
196
203static pm_node_t *
204pm_node_hash_insert(pm_node_hash_t *hash, const pm_static_literals_metadata_t *metadata, pm_node_t *node, bool replace, int (*compare)(const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right)) {
205 // If we are out of space, we need to resize the hash. This will cause all
206 // of the nodes to be rehashed and reinserted into the new hash.
207 if (hash->size * 2 >= hash->capacity) {
208 // First, allocate space for the new node list.
209 uint32_t new_capacity = hash->capacity == 0 ? 4 : hash->capacity * 2;
210 pm_node_t **new_nodes = xcalloc(new_capacity, sizeof(pm_node_t *));
211 if (new_nodes == NULL) abort();
212
213 // It turns out to be more efficient to mask the hash value than to use
214 // the modulo operator. Because our capacities are always powers of two,
215 // we can use a bitwise AND to get the same result as the modulo
216 // operator.
217 uint32_t mask = new_capacity - 1;
218
219 // Now, rehash all of the nodes into the new list.
220 for (uint32_t index = 0; index < hash->capacity; index++) {
221 pm_node_t *node = hash->nodes[index];
222
223 if (node != NULL) {
224 uint32_t new_index = node_hash(metadata, node) & mask;
225 while (new_nodes[new_index] != NULL) {
226 new_index = (new_index + 1) & mask;
227 }
228 new_nodes[new_index] = node;
229 }
230 }
231
232 // Finally, free the old node list and update the hash.
233 xfree_sized(hash->nodes, hash->capacity * sizeof(pm_node_t *));
234 hash->nodes = new_nodes;
235 hash->capacity = new_capacity;
236 }
237
238 // Now, insert the node into the hash.
239 uint32_t mask = hash->capacity - 1;
240 uint32_t index = node_hash(metadata, node) & mask;
241
242 // We use linear probing to resolve collisions. This means that if the
243 // current index is occupied, we will move to the next index and try again.
244 // We are guaranteed that this will eventually find an empty slot because we
245 // resize the hash when it gets too full.
246 while (hash->nodes[index] != NULL) {
247 if (compare(metadata, hash->nodes[index], node) == 0) break;
248 index = (index + 1) & mask;
249 }
250
251 // If the current index is occupied, we need to return the node that was
252 // already in the hash. Otherwise, we can just increment the size and insert
253 // the new node.
254 pm_node_t *result = hash->nodes[index];
255
256 if (result == NULL) {
257 hash->size++;
258 hash->nodes[index] = node;
259 } else if (replace) {
260 hash->nodes[index] = node;
261 }
262
263 return result;
264}
265
269static void
270pm_node_hash_free(pm_node_hash_t *hash) {
271 if (hash->capacity > 0) xfree_sized(hash->nodes, hash->capacity * sizeof(pm_node_t *));
272}
273
277#define PM_NUMERIC_COMPARISON(left, right) ((left < right) ? -1 : (left > right) ? 1 : 0)
278
282static int64_t
283pm_int64_value(const pm_static_literals_metadata_t *metadata, const pm_node_t *node) {
284 switch (PM_NODE_TYPE(node)) {
285 case PM_INTEGER_NODE: {
286 const pm_integer_t *integer = &((const pm_integer_node_t *) node)->value;
287 if (integer->values) return integer->negative ? INT64_MIN : INT64_MAX;
288
289 int64_t value = (int64_t) integer->value;
290 return integer->negative ? -value : value;
291 }
292 case PM_SOURCE_LINE_NODE:
293 return (int64_t) pm_line_offset_list_line_column(metadata->line_offsets, node->location.start, metadata->start_line).line;
294 default:
295 assert(false && "unreachable");
296 return 0;
297 }
298}
299
304static int
305pm_compare_integer_nodes(const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
306 if (PM_NODE_TYPE_P(left, PM_SOURCE_LINE_NODE) || PM_NODE_TYPE_P(right, PM_SOURCE_LINE_NODE)) {
307 int64_t left_value = pm_int64_value(metadata, left);
308 int64_t right_value = pm_int64_value(metadata, right);
309 return PM_NUMERIC_COMPARISON(left_value, right_value);
310 }
311
312 const pm_integer_t *left_integer = &((const pm_integer_node_t *) left)->value;
313 const pm_integer_t *right_integer = &((const pm_integer_node_t *) right)->value;
314 return pm_integer_compare(left_integer, right_integer);
315}
316
320static int
321pm_compare_float_nodes(PRISM_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
322 const double left_value = ((const pm_float_node_t *) left)->value;
323 const double right_value = ((const pm_float_node_t *) right)->value;
324 return PM_NUMERIC_COMPARISON(left_value, right_value);
325}
326
330static int
331pm_compare_number_nodes(const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
332 if (PM_NODE_TYPE(left) != PM_NODE_TYPE(right)) {
333 return PM_NUMERIC_COMPARISON(PM_NODE_TYPE(left), PM_NODE_TYPE(right));
334 }
335
336 switch (PM_NODE_TYPE(left)) {
337 case PM_IMAGINARY_NODE:
338 return pm_compare_number_nodes(metadata, ((const pm_imaginary_node_t *) left)->numeric, ((const pm_imaginary_node_t *) right)->numeric);
339 case PM_RATIONAL_NODE: {
340 const pm_rational_node_t *left_rational = (const pm_rational_node_t *) left;
341 const pm_rational_node_t *right_rational = (const pm_rational_node_t *) right;
342
343 int result = pm_integer_compare(&left_rational->denominator, &right_rational->denominator);
344 if (result != 0) return result;
345
346 return pm_integer_compare(&left_rational->numerator, &right_rational->numerator);
347 }
348 case PM_INTEGER_NODE:
349 return pm_compare_integer_nodes(metadata, left, right);
350 case PM_FLOAT_NODE:
351 return pm_compare_float_nodes(metadata, left, right);
352 default:
353 assert(false && "unreachable");
354 return 0;
355 }
356}
357
361static const pm_string_t *
362pm_string_value(const pm_node_t *node) {
363 switch (PM_NODE_TYPE(node)) {
364 case PM_STRING_NODE:
365 return &((const pm_string_node_t *) node)->unescaped;
366 case PM_SOURCE_FILE_NODE:
367 return &((const pm_source_file_node_t *) node)->filepath;
368 case PM_SYMBOL_NODE:
369 return &((const pm_symbol_node_t *) node)->unescaped;
370 default:
371 assert(false && "unreachable");
372 return NULL;
373 }
374}
375
379static int
380pm_compare_string_nodes(const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
381 const pm_string_t *left_string = pm_string_value(left);
382 const pm_string_t *right_string = pm_string_value(right);
383
384 int result = pm_string_compare(left_string, right_string);
385 if (result != 0) return result;
386
387 /*
388 * Equal bytes are not enough. In a binary source file the two bytes written
389 * as `"\xC3\xA9"` stay BINARY while a `"\u00E9"` escape is forced to UTF-8,
390 * so those are distinct keys even though the bytes match.
391 */
392 pm_node_flags_t left_flags = node_encoding_flags(metadata, left);
393 pm_node_flags_t right_flags = node_encoding_flags(metadata, right);
394 return PM_NUMERIC_COMPARISON(left_flags, right_flags);
395}
396
400static int
401pm_compare_regular_expression_nodes(PRISM_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
402 const pm_regular_expression_node_t *left_regexp = (const pm_regular_expression_node_t *) left;
403 const pm_regular_expression_node_t *right_regexp = (const pm_regular_expression_node_t *) right;
404
405 int result = pm_string_compare(&left_regexp->unescaped, &right_regexp->unescaped);
406 if (result != 0) return result;
407
408 return PM_NUMERIC_COMPARISON(left_regexp->base.flags, right_regexp->base.flags);
409}
410
411#undef PM_NUMERIC_COMPARISON
412
416pm_node_t *
417pm_static_literals_add(const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, const pm_encoding_t *encoding, pm_static_literals_t *literals, pm_node_t *node, bool replace) {
418 switch (PM_NODE_TYPE(node)) {
419 case PM_INTEGER_NODE:
420 case PM_SOURCE_LINE_NODE:
421 return pm_node_hash_insert(
422 &literals->integer_nodes,
424 .line_offsets = line_offsets,
425 .start = start,
426 .start_line = start_line,
427 .encoding = encoding
428 },
429 node,
430 replace,
431 pm_compare_integer_nodes
432 );
433 case PM_FLOAT_NODE:
434 return pm_node_hash_insert(
435 &literals->float_nodes,
437 .line_offsets = line_offsets,
438 .start = start,
439 .start_line = start_line,
440 .encoding = encoding
441 },
442 node,
443 replace,
444 pm_compare_float_nodes
445 );
446 case PM_RATIONAL_NODE:
447 case PM_IMAGINARY_NODE:
448 return pm_node_hash_insert(
449 &literals->number_nodes,
451 .line_offsets = line_offsets,
452 .start = start,
453 .start_line = start_line,
454 .encoding = encoding
455 },
456 node,
457 replace,
458 pm_compare_number_nodes
459 );
460 case PM_STRING_NODE:
461 case PM_SOURCE_FILE_NODE:
462 return pm_node_hash_insert(
463 &literals->string_nodes,
465 .line_offsets = line_offsets,
466 .start = start,
467 .start_line = start_line,
468 .encoding = encoding
469 },
470 node,
471 replace,
472 pm_compare_string_nodes
473 );
474 case PM_REGULAR_EXPRESSION_NODE:
475 return pm_node_hash_insert(
476 &literals->regexp_nodes,
478 .line_offsets = line_offsets,
479 .start = start,
480 .start_line = start_line,
481 .encoding = encoding
482 },
483 node,
484 replace,
485 pm_compare_regular_expression_nodes
486 );
487 case PM_SYMBOL_NODE:
488 return pm_node_hash_insert(
489 &literals->symbol_nodes,
491 .line_offsets = line_offsets,
492 .start = start,
493 .start_line = start_line,
494 .encoding = encoding
495 },
496 node,
497 replace,
498 pm_compare_string_nodes
499 );
500 case PM_TRUE_NODE: {
501 pm_node_t *duplicated = literals->true_node;
502 if ((duplicated == NULL) || replace) literals->true_node = node;
503 return duplicated;
504 }
505 case PM_FALSE_NODE: {
506 pm_node_t *duplicated = literals->false_node;
507 if ((duplicated == NULL) || replace) literals->false_node = node;
508 return duplicated;
509 }
510 case PM_NIL_NODE: {
511 pm_node_t *duplicated = literals->nil_node;
512 if ((duplicated == NULL) || replace) literals->nil_node = node;
513 return duplicated;
514 }
515 case PM_SOURCE_ENCODING_NODE: {
516 pm_node_t *duplicated = literals->source_encoding_node;
517 if ((duplicated == NULL) || replace) literals->source_encoding_node = node;
518 return duplicated;
519 }
520 default:
521 return NULL;
522 }
523}
524
528void
529pm_static_literals_free(pm_static_literals_t *literals) {
530 pm_node_hash_free(&literals->integer_nodes);
531 pm_node_hash_free(&literals->float_nodes);
532 pm_node_hash_free(&literals->number_nodes);
533 pm_node_hash_free(&literals->string_nodes);
534 pm_node_hash_free(&literals->regexp_nodes);
535 pm_node_hash_free(&literals->symbol_nodes);
536}
537
542static bool
543pm_static_literal_positive_p(const pm_node_t *node) {
544 switch (PM_NODE_TYPE(node)) {
545 case PM_FLOAT_NODE:
546 return ((const pm_float_node_t *) node)->value > 0;
547 case PM_INTEGER_NODE:
548 return !((const pm_integer_node_t *) node)->value.negative;
549 case PM_RATIONAL_NODE:
550 return !((const pm_rational_node_t *) node)->numerator.negative;
551 case PM_IMAGINARY_NODE:
552 return pm_static_literal_positive_p(((const pm_imaginary_node_t *) node)->numeric);
553 default:
554 assert(false && "unreachable");
555 return false;
556 }
557}
558
562static PRISM_INLINE void
563pm_static_literal_inspect_node(pm_buffer_t *buffer, const pm_static_literals_metadata_t *metadata, const pm_node_t *node) {
564 switch (PM_NODE_TYPE(node)) {
565 case PM_FALSE_NODE:
566 pm_buffer_append_string(buffer, "false", 5);
567 break;
568 case PM_FLOAT_NODE: {
569 const double value = ((const pm_float_node_t *) node)->value;
570
571 if (PRISM_ISINF(value)) {
572 if (metadata->start[node->location.start] == '-') {
573 pm_buffer_append_byte(buffer, '-');
574 }
575 pm_buffer_append_string(buffer, "Infinity", 8);
576 } else if (value == 0.0) {
577 if (metadata->start[node->location.start] == '-') {
578 pm_buffer_append_byte(buffer, '-');
579 }
580 pm_buffer_append_string(buffer, "0.0", 3);
581 } else {
582 pm_buffer_append_format(buffer, "%g", value);
583
584 // %g will not insert a .0 for 1e100 (we'll get back 1e+100). So
585 // we check for the decimal point and add it in here if it's not
586 // present.
587 if (pm_buffer_index(buffer, '.') == SIZE_MAX) {
588 size_t exponent_index = pm_buffer_index(buffer, 'e');
589 size_t index = exponent_index == SIZE_MAX ? pm_buffer_length(buffer) : exponent_index;
590 pm_buffer_insert(buffer, index, ".0", 2);
591 }
592 }
593
594 break;
595 }
596 case PM_IMAGINARY_NODE: {
597 const pm_node_t *numeric = ((const pm_imaginary_node_t *) node)->numeric;
598 pm_buffer_append_string(buffer, "(0", 2);
599 if (pm_static_literal_positive_p(numeric)) pm_buffer_append_byte(buffer, '+');
600 pm_static_literal_inspect_node(buffer, metadata, numeric);
601 if (PM_NODE_TYPE_P(numeric, PM_RATIONAL_NODE)) {
602 pm_buffer_append_byte(buffer, '*');
603 }
604 pm_buffer_append_string(buffer, "i)", 2);
605 break;
606 }
607 case PM_INTEGER_NODE:
608 pm_integer_string(buffer, &((const pm_integer_node_t *) node)->value);
609 break;
610 case PM_NIL_NODE:
611 pm_buffer_append_string(buffer, "nil", 3);
612 break;
613 case PM_RATIONAL_NODE: {
614 const pm_rational_node_t *rational = (const pm_rational_node_t *) node;
615 pm_buffer_append_byte(buffer, '(');
616 pm_integer_string(buffer, &rational->numerator);
617 pm_buffer_append_byte(buffer, '/');
618 pm_integer_string(buffer, &rational->denominator);
619 pm_buffer_append_byte(buffer, ')');
620 break;
621 }
622 case PM_REGULAR_EXPRESSION_NODE: {
623 const pm_string_t *unescaped = &((const pm_regular_expression_node_t *) node)->unescaped;
624 pm_buffer_append_byte(buffer, '/');
625 pm_buffer_append_source(buffer, pm_string_source(unescaped), pm_string_length(unescaped), PM_BUFFER_ESCAPING_RUBY);
626 pm_buffer_append_byte(buffer, '/');
627
628 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE)) pm_buffer_append_string(buffer, "m", 1);
629 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE)) pm_buffer_append_string(buffer, "i", 1);
630 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EXTENDED)) pm_buffer_append_string(buffer, "x", 1);
631 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) pm_buffer_append_string(buffer, "n", 1);
632
633 break;
634 }
635 case PM_SOURCE_ENCODING_NODE:
636 pm_buffer_append_format(buffer, "#<Encoding:%s>", metadata->encoding->name);
637 break;
638 case PM_SOURCE_FILE_NODE: {
639 const pm_string_t *filepath = &((const pm_source_file_node_t *) node)->filepath;
640 pm_buffer_append_byte(buffer, '"');
641 pm_buffer_append_source(buffer, pm_string_source(filepath), pm_string_length(filepath), PM_BUFFER_ESCAPING_RUBY);
642 pm_buffer_append_byte(buffer, '"');
643 break;
644 }
645 case PM_SOURCE_LINE_NODE:
646 pm_buffer_append_format(buffer, "%d", pm_line_offset_list_line_column(metadata->line_offsets, node->location.start, metadata->start_line).line);
647 break;
648 case PM_STRING_NODE: {
649 const pm_string_t *unescaped = &((const pm_string_node_t *) node)->unescaped;
650 pm_buffer_append_byte(buffer, '"');
651 pm_buffer_append_source(buffer, pm_string_source(unescaped), pm_string_length(unescaped), PM_BUFFER_ESCAPING_RUBY);
652 pm_buffer_append_byte(buffer, '"');
653 break;
654 }
655 case PM_SYMBOL_NODE: {
656 const pm_string_t *unescaped = &((const pm_symbol_node_t *) node)->unescaped;
657 pm_buffer_append_byte(buffer, ':');
658 pm_buffer_append_source(buffer, pm_string_source(unescaped), pm_string_length(unescaped), PM_BUFFER_ESCAPING_RUBY);
659 break;
660 }
661 case PM_TRUE_NODE:
662 pm_buffer_append_string(buffer, "true", 4);
663 break;
664 default:
665 assert(false && "unreachable");
666 break;
667 }
668}
669
673void
674pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, const pm_encoding_t *encoding, const pm_node_t *node) {
675 pm_static_literal_inspect_node(
676 buffer,
678 .line_offsets = line_offsets,
679 .start = start,
680 .start_line = start_line,
681 .encoding = encoding
682 },
683 node
684 );
685}
#define xcalloc
Old name of ruby_xcalloc.
Definition xmalloc.h:55
#define PRISM_INLINE
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition inline.h:12
FloatNode.
Definition ast.h:3968
ImaginaryNode.
Definition ast.h:4637
IntegerNode.
Definition ast.h:5233
pm_integer_t value
IntegerNode::value.
Definition ast.h:5242
A structure represents an arbitrary-sized integer.
Definition integer.h:16
size_t length
The number of allocated values.
Definition integer.h:21
uint32_t value
Embedded value for small integer.
Definition integer.h:32
uint32_t * values
List of 32-bit integers.
Definition integer.h:26
bool negative
Whether or not the integer is negative.
Definition integer.h:38
A line and column in a string.
int32_t line
The line number.
A list of offsets of the start of lines in a string.
uint32_t start
The offset of the location from the start of the source.
Definition ast.h:574
This is the base structure that represents a node in the syntax tree.
Definition ast.h:1083
pm_node_type_t type
This represents the type of the node.
Definition ast.h:1088
pm_node_flags_t flags
This represents any flags on the node.
Definition ast.h:1094
pm_location_t location
This is the location of the node in the source.
Definition ast.h:1106
RationalNode.
Definition ast.h:6929
pm_node_t base
The embedded base node.
Definition ast.h:6931
pm_integer_t denominator
RationalNode::denominator.
Definition ast.h:6949
pm_integer_t numerator
RationalNode::numerator.
Definition ast.h:6940
RegularExpressionNode.
Definition ast.h:6994
pm_node_t base
The embedded base node.
Definition ast.h:6996
pm_string_t unescaped
RegularExpressionNode::unescaped.
Definition ast.h:7016
SourceFileNode.
Definition ast.h:7374
A small struct used for passing around a subset of the information that is stored on the parser.
const pm_encoding_t * encoding
The encoding that the parser is using.
const uint8_t * start
The start of the source being parsed.
const pm_line_offset_list_t * line_offsets
The list of newline offsets to use to calculate line numbers.
int32_t start_line
The line number that the parser starts on.
StringNode.
Definition ast.h:7476
A generic string type that can have various ownership semantics.
Definition stringy.h:18
SymbolNode.
Definition ast.h:7570
#define PRISM_UNUSED
GCC will warn if you specify a function or parameter that is unused at runtime.
Definition unused.h:13