Ruby 4.1.0dev (2026-03-06 revision d5d144c149d3beabbfb262e3994f60552469181b)
static_literals.c
2
8typedef struct {
11
13 const uint8_t *start;
14
16 int32_t start_line;
17
19 const char *encoding_name;
21
22static inline uint32_t
23murmur_scramble(uint32_t value) {
24 value *= 0xcc9e2d51;
25 value = (value << 15) | (value >> 17);
26 value *= 0x1b873593;
27 return value;
28}
29
35static uint32_t
36murmur_hash(const uint8_t *key, size_t length) {
37 uint32_t hash = 0x9747b28c;
38 uint32_t segment;
39
40 for (size_t index = length >> 2; index; index--) {
41 memcpy(&segment, key, sizeof(uint32_t));
42 key += sizeof(uint32_t);
43 hash ^= murmur_scramble(segment);
44 hash = (hash << 13) | (hash >> 19);
45 hash = hash * 5 + 0xe6546b64;
46 }
47
48 segment = 0;
49 for (size_t index = length & 3; index; index--) {
50 segment <<= 8;
51 segment |= key[index - 1];
52 }
53
54 hash ^= murmur_scramble(segment);
55 hash ^= (uint32_t) length;
56 hash ^= hash >> 16;
57 hash *= 0x85ebca6b;
58 hash ^= hash >> 13;
59 hash *= 0xc2b2ae35;
60 hash ^= hash >> 16;
61 return hash;
62}
63
67static uint32_t
68integer_hash(const pm_integer_t *integer) {
69 uint32_t hash;
70 if (integer->values) {
71 hash = murmur_hash((const uint8_t *) integer->values, sizeof(uint32_t) * integer->length);
72 } else {
73 hash = murmur_hash((const uint8_t *) &integer->value, sizeof(uint32_t));
74 }
75
76 if (integer->negative) {
77 hash ^= murmur_scramble((uint32_t) 1);
78 }
79
80 return hash;
81}
82
88static uint32_t
89node_hash(const pm_static_literals_metadata_t *metadata, const pm_node_t *node) {
90 switch (PM_NODE_TYPE(node)) {
91 case PM_INTEGER_NODE: {
92 // Integers hash their value.
93 const pm_integer_node_t *cast = (const pm_integer_node_t *) node;
94 return integer_hash(&cast->value);
95 }
96 case PM_SOURCE_LINE_NODE: {
97 // Source lines hash their line number.
98 const pm_line_column_t line_column = pm_line_offset_list_line_column(metadata->line_offsets, node->location.start, metadata->start_line);
99 const int32_t *value = &line_column.line;
100 return murmur_hash((const uint8_t *) value, sizeof(int32_t));
101 }
102 case PM_FLOAT_NODE: {
103 // Floats hash their value.
104 const double *value = &((const pm_float_node_t *) node)->value;
105 return murmur_hash((const uint8_t *) value, sizeof(double));
106 }
107 case PM_RATIONAL_NODE: {
108 // Rationals hash their numerator and denominator.
109 const pm_rational_node_t *cast = (const pm_rational_node_t *) node;
110 return integer_hash(&cast->numerator) ^ integer_hash(&cast->denominator) ^ murmur_scramble((uint32_t) cast->base.type);
111 }
112 case PM_IMAGINARY_NODE: {
113 // Imaginaries hash their numeric value. Because their numeric value
114 // is stored as a subnode, we hash that node and then mix in the
115 // fact that this is an imaginary node.
116 const pm_node_t *numeric = ((const pm_imaginary_node_t *) node)->numeric;
117 return node_hash(metadata, numeric) ^ murmur_scramble((uint32_t) node->type);
118 }
119 case PM_STRING_NODE: {
120 // Strings hash their value and mix in their flags so that different
121 // encodings are not considered equal.
122 const pm_string_t *value = &((const pm_string_node_t *) node)->unescaped;
123
124 pm_node_flags_t flags = node->flags;
125 flags &= (PM_STRING_FLAGS_FORCED_BINARY_ENCODING | PM_STRING_FLAGS_FORCED_UTF8_ENCODING);
126
127 return murmur_hash(pm_string_source(value), pm_string_length(value) * sizeof(uint8_t)) ^ murmur_scramble((uint32_t) flags);
128 }
129 case PM_SOURCE_FILE_NODE: {
130 // Source files hash their value and mix in their flags so that
131 // different encodings are not considered equal.
132 const pm_string_t *value = &((const pm_source_file_node_t *) node)->filepath;
133 return murmur_hash(pm_string_source(value), pm_string_length(value) * sizeof(uint8_t));
134 }
135 case PM_REGULAR_EXPRESSION_NODE: {
136 // Regular expressions hash their value and mix in their flags so
137 // that different encodings are not considered equal.
138 const pm_string_t *value = &((const pm_regular_expression_node_t *) node)->unescaped;
139 return murmur_hash(pm_string_source(value), pm_string_length(value) * sizeof(uint8_t)) ^ murmur_scramble((uint32_t) node->flags);
140 }
141 case PM_SYMBOL_NODE: {
142 // Symbols hash their value and mix in their flags so that different
143 // encodings are not considered equal.
144 const pm_string_t *value = &((const pm_symbol_node_t *) node)->unescaped;
145 return murmur_hash(pm_string_source(value), pm_string_length(value) * sizeof(uint8_t)) ^ murmur_scramble((uint32_t) node->flags);
146 }
147 default:
148 assert(false && "unreachable");
149 return 0;
150 }
151}
152
159static pm_node_t *
160pm_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)) {
161 // If we are out of space, we need to resize the hash. This will cause all
162 // of the nodes to be rehashed and reinserted into the new hash.
163 if (hash->size * 2 >= hash->capacity) {
164 // First, allocate space for the new node list.
165 uint32_t new_capacity = hash->capacity == 0 ? 4 : hash->capacity * 2;
166 pm_node_t **new_nodes = xcalloc(new_capacity, sizeof(pm_node_t *));
167 if (new_nodes == NULL) return NULL;
168
169 // It turns out to be more efficient to mask the hash value than to use
170 // the modulo operator. Because our capacities are always powers of two,
171 // we can use a bitwise AND to get the same result as the modulo
172 // operator.
173 uint32_t mask = new_capacity - 1;
174
175 // Now, rehash all of the nodes into the new list.
176 for (uint32_t index = 0; index < hash->capacity; index++) {
177 pm_node_t *node = hash->nodes[index];
178
179 if (node != NULL) {
180 uint32_t index = node_hash(metadata, node) & mask;
181 new_nodes[index] = node;
182 }
183 }
184
185 // Finally, free the old node list and update the hash.
186 xfree_sized(hash->nodes, hash->capacity * sizeof(pm_node_t *));
187 hash->nodes = new_nodes;
188 hash->capacity = new_capacity;
189 }
190
191 // Now, insert the node into the hash.
192 uint32_t mask = hash->capacity - 1;
193 uint32_t index = node_hash(metadata, node) & mask;
194
195 // We use linear probing to resolve collisions. This means that if the
196 // current index is occupied, we will move to the next index and try again.
197 // We are guaranteed that this will eventually find an empty slot because we
198 // resize the hash when it gets too full.
199 while (hash->nodes[index] != NULL) {
200 if (compare(metadata, hash->nodes[index], node) == 0) break;
201 index = (index + 1) & mask;
202 }
203
204 // If the current index is occupied, we need to return the node that was
205 // already in the hash. Otherwise, we can just increment the size and insert
206 // the new node.
207 pm_node_t *result = hash->nodes[index];
208
209 if (result == NULL) {
210 hash->size++;
211 hash->nodes[index] = node;
212 } else if (replace) {
213 hash->nodes[index] = node;
214 }
215
216 return result;
217}
218
222static void
223pm_node_hash_free(pm_node_hash_t *hash) {
224 if (hash->capacity > 0) xfree_sized(hash->nodes, hash->capacity * sizeof(pm_node_t *));
225}
226
230#define PM_NUMERIC_COMPARISON(left, right) ((left < right) ? -1 : (left > right) ? 1 : 0)
231
235static int64_t
236pm_int64_value(const pm_static_literals_metadata_t *metadata, const pm_node_t *node) {
237 switch (PM_NODE_TYPE(node)) {
238 case PM_INTEGER_NODE: {
239 const pm_integer_t *integer = &((const pm_integer_node_t *) node)->value;
240 if (integer->values) return integer->negative ? INT64_MIN : INT64_MAX;
241
242 int64_t value = (int64_t) integer->value;
243 return integer->negative ? -value : value;
244 }
245 case PM_SOURCE_LINE_NODE:
246 return (int64_t) pm_line_offset_list_line_column(metadata->line_offsets, node->location.start, metadata->start_line).line;
247 default:
248 assert(false && "unreachable");
249 return 0;
250 }
251}
252
257static int
258pm_compare_integer_nodes(const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
259 if (PM_NODE_TYPE_P(left, PM_SOURCE_LINE_NODE) || PM_NODE_TYPE_P(right, PM_SOURCE_LINE_NODE)) {
260 int64_t left_value = pm_int64_value(metadata, left);
261 int64_t right_value = pm_int64_value(metadata, right);
262 return PM_NUMERIC_COMPARISON(left_value, right_value);
263 }
264
265 const pm_integer_t *left_integer = &((const pm_integer_node_t *) left)->value;
266 const pm_integer_t *right_integer = &((const pm_integer_node_t *) right)->value;
267 return pm_integer_compare(left_integer, right_integer);
268}
269
273static int
274pm_compare_float_nodes(PRISM_ATTRIBUTE_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
275 const double left_value = ((const pm_float_node_t *) left)->value;
276 const double right_value = ((const pm_float_node_t *) right)->value;
277 return PM_NUMERIC_COMPARISON(left_value, right_value);
278}
279
283static int
284pm_compare_number_nodes(const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
285 if (PM_NODE_TYPE(left) != PM_NODE_TYPE(right)) {
286 return PM_NUMERIC_COMPARISON(PM_NODE_TYPE(left), PM_NODE_TYPE(right));
287 }
288
289 switch (PM_NODE_TYPE(left)) {
290 case PM_IMAGINARY_NODE:
291 return pm_compare_number_nodes(metadata, ((const pm_imaginary_node_t *) left)->numeric, ((const pm_imaginary_node_t *) right)->numeric);
292 case PM_RATIONAL_NODE: {
293 const pm_rational_node_t *left_rational = (const pm_rational_node_t *) left;
294 const pm_rational_node_t *right_rational = (const pm_rational_node_t *) right;
295
296 int result = pm_integer_compare(&left_rational->denominator, &right_rational->denominator);
297 if (result != 0) return result;
298
299 return pm_integer_compare(&left_rational->numerator, &right_rational->numerator);
300 }
301 case PM_INTEGER_NODE:
302 return pm_compare_integer_nodes(metadata, left, right);
303 case PM_FLOAT_NODE:
304 return pm_compare_float_nodes(metadata, left, right);
305 default:
306 assert(false && "unreachable");
307 return 0;
308 }
309}
310
314static const pm_string_t *
315pm_string_value(const pm_node_t *node) {
316 switch (PM_NODE_TYPE(node)) {
317 case PM_STRING_NODE:
318 return &((const pm_string_node_t *) node)->unescaped;
319 case PM_SOURCE_FILE_NODE:
320 return &((const pm_source_file_node_t *) node)->filepath;
321 case PM_SYMBOL_NODE:
322 return &((const pm_symbol_node_t *) node)->unescaped;
323 default:
324 assert(false && "unreachable");
325 return NULL;
326 }
327}
328
332static int
333pm_compare_string_nodes(PRISM_ATTRIBUTE_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
334 const pm_string_t *left_string = pm_string_value(left);
335 const pm_string_t *right_string = pm_string_value(right);
336 return pm_string_compare(left_string, right_string);
337}
338
342static int
343pm_compare_regular_expression_nodes(PRISM_ATTRIBUTE_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
344 const pm_regular_expression_node_t *left_regexp = (const pm_regular_expression_node_t *) left;
345 const pm_regular_expression_node_t *right_regexp = (const pm_regular_expression_node_t *) right;
346
347 int result = pm_string_compare(&left_regexp->unescaped, &right_regexp->unescaped);
348 if (result != 0) return result;
349
350 return PM_NUMERIC_COMPARISON(left_regexp->base.flags, right_regexp->base.flags);
351}
352
353#undef PM_NUMERIC_COMPARISON
354
358pm_node_t *
359pm_static_literals_add(const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace) {
360 switch (PM_NODE_TYPE(node)) {
361 case PM_INTEGER_NODE:
362 case PM_SOURCE_LINE_NODE:
363 return pm_node_hash_insert(
364 &literals->integer_nodes,
366 .line_offsets = line_offsets,
367 .start = start,
368 .start_line = start_line,
369 .encoding_name = NULL
370 },
371 node,
372 replace,
373 pm_compare_integer_nodes
374 );
375 case PM_FLOAT_NODE:
376 return pm_node_hash_insert(
377 &literals->float_nodes,
379 .line_offsets = line_offsets,
380 .start = start,
381 .start_line = start_line,
382 .encoding_name = NULL
383 },
384 node,
385 replace,
386 pm_compare_float_nodes
387 );
388 case PM_RATIONAL_NODE:
389 case PM_IMAGINARY_NODE:
390 return pm_node_hash_insert(
391 &literals->number_nodes,
393 .line_offsets = line_offsets,
394 .start = start,
395 .start_line = start_line,
396 .encoding_name = NULL
397 },
398 node,
399 replace,
400 pm_compare_number_nodes
401 );
402 case PM_STRING_NODE:
403 case PM_SOURCE_FILE_NODE:
404 return pm_node_hash_insert(
405 &literals->string_nodes,
407 .line_offsets = line_offsets,
408 .start = start,
409 .start_line = start_line,
410 .encoding_name = NULL
411 },
412 node,
413 replace,
414 pm_compare_string_nodes
415 );
416 case PM_REGULAR_EXPRESSION_NODE:
417 return pm_node_hash_insert(
418 &literals->regexp_nodes,
420 .line_offsets = line_offsets,
421 .start = start,
422 .start_line = start_line,
423 .encoding_name = NULL
424 },
425 node,
426 replace,
427 pm_compare_regular_expression_nodes
428 );
429 case PM_SYMBOL_NODE:
430 return pm_node_hash_insert(
431 &literals->symbol_nodes,
433 .line_offsets = line_offsets,
434 .start = start,
435 .start_line = start_line,
436 .encoding_name = NULL
437 },
438 node,
439 replace,
440 pm_compare_string_nodes
441 );
442 case PM_TRUE_NODE: {
443 pm_node_t *duplicated = literals->true_node;
444 if ((duplicated == NULL) || replace) literals->true_node = node;
445 return duplicated;
446 }
447 case PM_FALSE_NODE: {
448 pm_node_t *duplicated = literals->false_node;
449 if ((duplicated == NULL) || replace) literals->false_node = node;
450 return duplicated;
451 }
452 case PM_NIL_NODE: {
453 pm_node_t *duplicated = literals->nil_node;
454 if ((duplicated == NULL) || replace) literals->nil_node = node;
455 return duplicated;
456 }
457 case PM_SOURCE_ENCODING_NODE: {
458 pm_node_t *duplicated = literals->source_encoding_node;
459 if ((duplicated == NULL) || replace) literals->source_encoding_node = node;
460 return duplicated;
461 }
462 default:
463 return NULL;
464 }
465}
466
470void
471pm_static_literals_free(pm_static_literals_t *literals) {
472 pm_node_hash_free(&literals->integer_nodes);
473 pm_node_hash_free(&literals->float_nodes);
474 pm_node_hash_free(&literals->number_nodes);
475 pm_node_hash_free(&literals->string_nodes);
476 pm_node_hash_free(&literals->regexp_nodes);
477 pm_node_hash_free(&literals->symbol_nodes);
478}
479
484static bool
485pm_static_literal_positive_p(const pm_node_t *node) {
486 switch (PM_NODE_TYPE(node)) {
487 case PM_FLOAT_NODE:
488 return ((const pm_float_node_t *) node)->value > 0;
489 case PM_INTEGER_NODE:
490 return !((const pm_integer_node_t *) node)->value.negative;
491 case PM_RATIONAL_NODE:
492 return !((const pm_rational_node_t *) node)->numerator.negative;
493 case PM_IMAGINARY_NODE:
494 return pm_static_literal_positive_p(((const pm_imaginary_node_t *) node)->numeric);
495 default:
496 assert(false && "unreachable");
497 return false;
498 }
499}
500
504static inline void
505pm_static_literal_inspect_node(pm_buffer_t *buffer, const pm_static_literals_metadata_t *metadata, const pm_node_t *node) {
506 switch (PM_NODE_TYPE(node)) {
507 case PM_FALSE_NODE:
508 pm_buffer_append_string(buffer, "false", 5);
509 break;
510 case PM_FLOAT_NODE: {
511 const double value = ((const pm_float_node_t *) node)->value;
512
513 if (PRISM_ISINF(value)) {
514 if (metadata->start[node->location.start] == '-') {
515 pm_buffer_append_byte(buffer, '-');
516 }
517 pm_buffer_append_string(buffer, "Infinity", 8);
518 } else if (value == 0.0) {
519 if (metadata->start[node->location.start] == '-') {
520 pm_buffer_append_byte(buffer, '-');
521 }
522 pm_buffer_append_string(buffer, "0.0", 3);
523 } else {
524 pm_buffer_append_format(buffer, "%g", value);
525
526 // %g will not insert a .0 for 1e100 (we'll get back 1e+100). So
527 // we check for the decimal point and add it in here if it's not
528 // present.
529 if (pm_buffer_index(buffer, '.') == SIZE_MAX) {
530 size_t exponent_index = pm_buffer_index(buffer, 'e');
531 size_t index = exponent_index == SIZE_MAX ? pm_buffer_length(buffer) : exponent_index;
532 pm_buffer_insert(buffer, index, ".0", 2);
533 }
534 }
535
536 break;
537 }
538 case PM_IMAGINARY_NODE: {
539 const pm_node_t *numeric = ((const pm_imaginary_node_t *) node)->numeric;
540 pm_buffer_append_string(buffer, "(0", 2);
541 if (pm_static_literal_positive_p(numeric)) pm_buffer_append_byte(buffer, '+');
542 pm_static_literal_inspect_node(buffer, metadata, numeric);
543 if (PM_NODE_TYPE_P(numeric, PM_RATIONAL_NODE)) {
544 pm_buffer_append_byte(buffer, '*');
545 }
546 pm_buffer_append_string(buffer, "i)", 2);
547 break;
548 }
549 case PM_INTEGER_NODE:
550 pm_integer_string(buffer, &((const pm_integer_node_t *) node)->value);
551 break;
552 case PM_NIL_NODE:
553 pm_buffer_append_string(buffer, "nil", 3);
554 break;
555 case PM_RATIONAL_NODE: {
556 const pm_rational_node_t *rational = (const pm_rational_node_t *) node;
557 pm_buffer_append_byte(buffer, '(');
558 pm_integer_string(buffer, &rational->numerator);
559 pm_buffer_append_byte(buffer, '/');
560 pm_integer_string(buffer, &rational->denominator);
561 pm_buffer_append_byte(buffer, ')');
562 break;
563 }
564 case PM_REGULAR_EXPRESSION_NODE: {
565 const pm_string_t *unescaped = &((const pm_regular_expression_node_t *) node)->unescaped;
566 pm_buffer_append_byte(buffer, '/');
567 pm_buffer_append_source(buffer, pm_string_source(unescaped), pm_string_length(unescaped), PM_BUFFER_ESCAPING_RUBY);
568 pm_buffer_append_byte(buffer, '/');
569
570 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE)) pm_buffer_append_string(buffer, "m", 1);
571 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE)) pm_buffer_append_string(buffer, "i", 1);
572 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EXTENDED)) pm_buffer_append_string(buffer, "x", 1);
573 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) pm_buffer_append_string(buffer, "n", 1);
574
575 break;
576 }
577 case PM_SOURCE_ENCODING_NODE:
578 pm_buffer_append_format(buffer, "#<Encoding:%s>", metadata->encoding_name);
579 break;
580 case PM_SOURCE_FILE_NODE: {
581 const pm_string_t *filepath = &((const pm_source_file_node_t *) node)->filepath;
582 pm_buffer_append_byte(buffer, '"');
583 pm_buffer_append_source(buffer, pm_string_source(filepath), pm_string_length(filepath), PM_BUFFER_ESCAPING_RUBY);
584 pm_buffer_append_byte(buffer, '"');
585 break;
586 }
587 case PM_SOURCE_LINE_NODE:
588 pm_buffer_append_format(buffer, "%d", pm_line_offset_list_line_column(metadata->line_offsets, node->location.start, metadata->start_line).line);
589 break;
590 case PM_STRING_NODE: {
591 const pm_string_t *unescaped = &((const pm_string_node_t *) node)->unescaped;
592 pm_buffer_append_byte(buffer, '"');
593 pm_buffer_append_source(buffer, pm_string_source(unescaped), pm_string_length(unescaped), PM_BUFFER_ESCAPING_RUBY);
594 pm_buffer_append_byte(buffer, '"');
595 break;
596 }
597 case PM_SYMBOL_NODE: {
598 const pm_string_t *unescaped = &((const pm_symbol_node_t *) node)->unescaped;
599 pm_buffer_append_byte(buffer, ':');
600 pm_buffer_append_source(buffer, pm_string_source(unescaped), pm_string_length(unescaped), PM_BUFFER_ESCAPING_RUBY);
601 break;
602 }
603 case PM_TRUE_NODE:
604 pm_buffer_append_string(buffer, "true", 4);
605 break;
606 default:
607 assert(false && "unreachable");
608 break;
609 }
610}
611
615void
616pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, const char *encoding_name, const pm_node_t *node) {
617 pm_static_literal_inspect_node(
618 buffer,
620 .line_offsets = line_offsets,
621 .start = start,
622 .start_line = start_line,
623 .encoding_name = encoding_name
624 },
625 node
626 );
627}
#define xcalloc
Old name of ruby_xcalloc.
Definition xmalloc.h:55
size_t pm_buffer_length(const pm_buffer_t *buffer)
Return the length of the buffer.
Definition pm_buffer.c:43
PRISM_EXPORTED_FUNCTION void pm_integer_string(pm_buffer_t *buffer, const pm_integer_t *integer)
Convert an integer to a decimal string.
Definition pm_integer.c:608
PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string)
Returns the length associated with the string.
Definition pm_string.c:352
PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string)
Returns the start pointer associated with the string.
Definition pm_string.c:360
#define PRISM_ATTRIBUTE_UNUSED
GCC will warn if you specify a function or parameter that is unused at runtime.
Definition defines.h:81
#define PRISM_ISINF(x)
isinf on POSIX systems it accepts a float, a double, or a long double.
Definition defines.h:151
A set of static literal nodes that can be checked for duplicates.
A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory.
Definition pm_buffer.h:22
FloatNode.
Definition ast.h:3915
ImaginaryNode.
Definition ast.h:4573
IntegerNode.
Definition ast.h:5169
pm_integer_t value
IntegerNode::value.
Definition ast.h:5178
A structure represents an arbitrary-sized integer.
Definition pm_integer.h:20
size_t length
The number of allocated values.
Definition pm_integer.h:25
uint32_t value
Embedded value for small integer.
Definition pm_integer.h:36
uint32_t * values
List of 32-bit integers.
Definition pm_integer.h:30
bool negative
Whether or not the integer is negative.
Definition pm_integer.h:42
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:542
An internal hash table for a set of nodes.
pm_node_t ** nodes
The array of nodes in the hash table.
uint32_t size
The size of the hash table.
uint32_t capacity
The space that has been allocated in the hash table.
This is the base structure that represents a node in the syntax tree.
Definition ast.h:1051
pm_node_type_t type
This represents the type of the node.
Definition ast.h:1056
pm_node_flags_t flags
This represents any flags on the node.
Definition ast.h:1062
pm_location_t location
This is the location of the node in the source.
Definition ast.h:1074
RationalNode.
Definition ast.h:6879
pm_node_t base
The embedded base node.
Definition ast.h:6881
pm_integer_t denominator
RationalNode::denominator.
Definition ast.h:6899
pm_integer_t numerator
RationalNode::numerator.
Definition ast.h:6890
RegularExpressionNode.
Definition ast.h:6944
pm_node_t base
The embedded base node.
Definition ast.h:6946
pm_string_t unescaped
RegularExpressionNode::unescaped.
Definition ast.h:6966
SourceFileNode.
Definition ast.h:7324
A small struct used for passing around a subset of the information that is stored on the parser.
const char * encoding_name
The name of 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.
Certain sets of nodes (hash keys and when clauses) check for duplicate nodes to alert the user of pot...
pm_node_hash_t string_nodes
This is the set of StringNode and SourceFileNode instances.
pm_node_t * false_node
A pointer to the last FalseNode instance that was inserted, or NULL.
pm_node_hash_t regexp_nodes
This is the set of RegularExpressionNode instances.
pm_node_t * source_encoding_node
A pointer to the last SourceEncodingNode instance that was inserted, or NULL.
pm_node_t * nil_node
A pointer to the last NilNode instance that was inserted, or NULL.
pm_node_hash_t number_nodes
This is the set of RationalNode and ImaginaryNode instances.
pm_node_t * true_node
A pointer to the last TrueNode instance that was inserted, or NULL.
pm_node_hash_t symbol_nodes
This is the set of SymbolNode instances.
pm_node_hash_t float_nodes
This is the set of FloatNode instances.
pm_node_hash_t integer_nodes
This is the set of IntegerNode and SourceLineNode instances.
StringNode.
Definition ast.h:7426
A generic string type that can have various ownership semantics.
Definition pm_string.h:33
SymbolNode.
Definition ast.h:7520