Ruby
4.1.0dev (2026-11-18 revision 9de06831e37534f8a163e598cc0c6903c7687430)
prism
internal
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
*/
13
typedef
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;
19
}
pm_static_literals_entry_t
;
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
28
typedef
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. */
36
pm_static_literals_entry_t
*entries;
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;
43
}
pm_static_literals_t
;
44
45
/*
46
* Add a node to the set of static literals.
47
*/
48
pm_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
*/
53
void
pm_static_literals_free(
pm_static_literals_t
*literals);
54
55
/*
56
* Create a string-based representation of the given static literal.
57
*/
58
void
pm_static_literal_inspect(
pm_buffer_t
*buffer,
const
pm_parser_t
*parser,
const
pm_node_t *node);
59
60
#endif
parser.h
The parser used to parse Ruby source.
buffer.h
A wrapper around a contiguous block of allocated memory.
pm_buffer_t
Definition
buffer.h:14
pm_parser_t
Definition
parser.h:616
pm_static_literals_entry_t
Definition
static_literals.h:13
pm_static_literals_t
Definition
static_literals.h:28
Generated by
1.15.0