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