Ruby 4.1.0dev (2026-09-07 revision b57404b461ba8bf34e802d86b0db78388216e182)
static_literals.h
1#ifndef PRISM_INTERNAL_STATIC_LITERALS_H
2#define PRISM_INTERNAL_STATIC_LITERALS_H
3
4#include "prism/internal/encoding.h"
5
6#include "prism/ast.h"
7#include "prism/buffer.h"
9
10/*
11 * An internal hash table for a set of nodes.
12 */
13typedef struct {
14 /* The array of nodes in the hash table. */
15 pm_node_t **nodes;
16
17 /* The size of the hash table. */
18 uint32_t size;
19
20 /* The space that has been allocated in the hash table. */
21 uint32_t capacity;
23
24/*
25 * Certain sets of nodes (hash keys and when clauses) check for duplicate nodes
26 * to alert the user of potential issues. To do this, we keep a set of the nodes
27 * that have been seen so far, and compare whenever we find a new node.
28 *
29 * We bucket the nodes based on their type to minimize the number of comparisons
30 * that need to be performed.
31 */
32typedef struct {
33 /*
34 * This is the set of IntegerNode and SourceLineNode instances.
35 */
36 pm_node_hash_t integer_nodes;
37
38 /*
39 * This is the set of FloatNode instances.
40 */
41 pm_node_hash_t float_nodes;
42
43 /*
44 * This is the set of RationalNode and ImaginaryNode instances.
45 */
46 pm_node_hash_t number_nodes;
47
48 /*
49 * This is the set of StringNode and SourceFileNode instances.
50 */
51 pm_node_hash_t string_nodes;
52
53 /*
54 * This is the set of RegularExpressionNode instances.
55 */
56 pm_node_hash_t regexp_nodes;
57
58 /*
59 * This is the set of SymbolNode instances.
60 */
61 pm_node_hash_t symbol_nodes;
62
63 /*
64 * A pointer to the last TrueNode instance that was inserted, or NULL.
65 */
66 pm_node_t *true_node;
67
68 /*
69 * A pointer to the last FalseNode instance that was inserted, or NULL.
70 */
71 pm_node_t *false_node;
72
73 /*
74 * A pointer to the last NilNode instance that was inserted, or NULL.
75 */
76 pm_node_t *nil_node;
77
78 /*
79 * A pointer to the last SourceEncodingNode instance that was inserted, or
80 * NULL.
81 */
82 pm_node_t *source_encoding_node;
84
85/*
86 * Add a node to the set of static literals.
87 */
88pm_node_t * pm_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);
89
90/*
91 * Free the internal memory associated with the given static literals set.
92 */
93void pm_static_literals_free(pm_static_literals_t *literals);
94
95/*
96 * Create a string-based representation of the given static literal.
97 */
98void pm_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);
99
100#endif
A list of byte offsets of newlines in a string.
A wrapper around a contiguous block of allocated memory.
A list of offsets of the start of lines in a string.
This is the base structure that represents a node in the syntax tree.
Definition ast.h:1083