Ruby 4.1.0dev (2026-11-10 revision d9bbf7af11227361911849907728f055a9e49db0)
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"
6#include "prism/parser.h"
7
8/*
9 * Certain sets of nodes (hash keys and when clauses) check for duplicate nodes
10 * to alert the user of potential issues. To do this, we keep a set of the nodes
11 * that have been seen so far, and compare whenever we find a new node.
12 */
13typedef struct {
14 /* The node stored in this slot, or NULL if the slot is empty. */
15 pm_node_t *node;
16
17 /* The hash of the node, kept so that it is never recomputed. */
18 uint64_t hash;
20
21/*
22 * The number of nodes a set holds directly before it moves them into a hash
23 * table. Most sets are this small, so they are searched linearly without
24 * hashing their nodes or allocating any memory.
25 */
26#define PM_STATIC_LITERALS_INLINE_CAPACITY 4
27
28typedef struct {
29 /*
30 * The nodes in the set while it has no hash table. Once the set outgrows
31 * this array, its nodes move into the hash table and this is unused.
32 */
33 pm_node_t *nodes[PM_STATIC_LITERALS_INLINE_CAPACITY];
34
35 /* The array of entries in the hash table, or NULL if there is none. */
37
38 /* The number of nodes in the set. */
39 uint32_t size;
40
41 /* The number of entries allocated in the hash table, or 0 if there is none. */
42 uint32_t capacity;
44
45/*
46 * Add a node to the set of static literals.
47 */
48pm_node_t * pm_static_literals_add(const pm_parser_t *parser, pm_static_literals_t *literals, pm_node_t *node, bool replace);
49
50/*
51 * Free the internal memory associated with the given static literals set.
52 */
53void pm_static_literals_free(pm_static_literals_t *literals);
54
55/*
56 * Create a string-based representation of the given static literal.
57 */
58void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_parser_t *parser, const pm_node_t *node);
59
60#endif
The parser used to parse Ruby source.
A wrapper around a contiguous block of allocated memory.
This is the base structure that represents a node in the syntax tree.
Definition ast.h:1090