Ruby
3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
|
A data structure that stores a set of strings. More...
#include "prism/defines.h"
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | pm_constant_id_list_t |
A list of constant IDs. More... | |
struct | pm_constant_pool_bucket_t |
A bucket in the hash map. More... | |
struct | pm_constant_t |
A constant in the pool which effectively stores a string. More... | |
struct | pm_constant_pool_t |
The overall constant pool, which stores constants found while parsing. More... | |
Macros | |
#define | PM_CONSTANT_ID_UNSET 0 |
When we allocate constants into the pool, we reserve 0 to mean that the slot is not yet filled. More... | |
Typedefs | |
typedef uint32_t | pm_constant_id_t |
A constant id is a unique identifier for a constant in the constant pool. More... | |
typedef unsigned int | pm_constant_pool_bucket_type_t |
The type of bucket in the constant pool hash map. More... | |
Functions | |
void | pm_constant_id_list_init (pm_constant_id_list_t *list) |
Initialize a list of constant ids. More... | |
void | pm_constant_id_list_init_capacity (pm_constant_id_list_t *list, size_t capacity) |
Initialize a list of constant ids with a given capacity. More... | |
bool | pm_constant_id_list_append (pm_constant_id_list_t *list, pm_constant_id_t id) |
Append a constant id to a list of constant ids. More... | |
void | pm_constant_id_list_insert (pm_constant_id_list_t *list, size_t index, pm_constant_id_t id) |
Insert a constant id into a list of constant ids at the specified index. More... | |
bool | pm_constant_id_list_includes (pm_constant_id_list_t *list, pm_constant_id_t id) |
Checks if the current constant id list includes the given constant id. More... | |
void | pm_constant_id_list_free (pm_constant_id_list_t *list) |
Free the memory associated with a list of constant ids. More... | |
bool | pm_constant_pool_init (pm_constant_pool_t *pool, uint32_t capacity) |
Initialize a new constant pool with a given capacity. More... | |
pm_constant_t * | pm_constant_pool_id_to_constant (const pm_constant_pool_t *pool, pm_constant_id_t constant_id) |
Return a pointer to the constant indicated by the given constant id. More... | |
pm_constant_id_t | pm_constant_pool_find (const pm_constant_pool_t *pool, const uint8_t *start, size_t length) |
Find a constant in a constant pool. More... | |
pm_constant_id_t | pm_constant_pool_insert_shared (pm_constant_pool_t *pool, const uint8_t *start, size_t length) |
Insert a constant into a constant pool that is a slice of a source string. More... | |
pm_constant_id_t | pm_constant_pool_insert_owned (pm_constant_pool_t *pool, uint8_t *start, size_t length) |
Insert a constant into a constant pool from memory that is now owned by the constant pool. More... | |
pm_constant_id_t | pm_constant_pool_insert_constant (pm_constant_pool_t *pool, const uint8_t *start, size_t length) |
Insert a constant into a constant pool from memory that is constant. More... | |
void | pm_constant_pool_free (pm_constant_pool_t *pool) |
Free the memory associated with a constant pool. More... | |
Variables | |
static const pm_constant_pool_bucket_type_t | PM_CONSTANT_POOL_BUCKET_DEFAULT = 0 |
By default, each constant is a slice of the source. More... | |
static const pm_constant_pool_bucket_type_t | PM_CONSTANT_POOL_BUCKET_OWNED = 1 |
An owned constant is one for which memory has been allocated. More... | |
static const pm_constant_pool_bucket_type_t | PM_CONSTANT_POOL_BUCKET_CONSTANT = 2 |
A constant constant is known at compile time. More... | |
A data structure that stores a set of strings.
Each string is assigned a unique id, which can be used to compare strings for equality. This comparison ends up being much faster than strcmp, since it only requires a single integer comparison.
Definition in file pm_constant_pool.h.
#define PM_CONSTANT_ID_UNSET 0 |
When we allocate constants into the pool, we reserve 0 to mean that the slot is not yet filled.
This constant is reused in other places to indicate the lack of a constant id.
Definition at line 26 of file pm_constant_pool.h.
typedef uint32_t pm_constant_id_t |
A constant id is a unique identifier for a constant in the constant pool.
Definition at line 31 of file pm_constant_pool.h.
typedef unsigned int pm_constant_pool_bucket_type_t |
The type of bucket in the constant pool hash map.
This determines how the bucket should be freed.
Definition at line 101 of file pm_constant_pool.h.
bool pm_constant_id_list_append | ( | pm_constant_id_list_t * | list, |
pm_constant_id_t | id | ||
) |
Append a constant id to a list of constant ids.
Returns false if any potential reallocations fail.
list | The list to append to. |
id | The id to append. |
Returns false if any potential reallocations fail.
Definition at line 30 of file pm_constant_pool.c.
void pm_constant_id_list_free | ( | pm_constant_id_list_t * | list | ) |
Free the memory associated with a list of constant ids.
list | The list to free. |
Definition at line 68 of file pm_constant_pool.c.
Referenced by pm_node_destroy().
bool pm_constant_id_list_includes | ( | pm_constant_id_list_t * | list, |
pm_constant_id_t | id | ||
) |
Checks if the current constant id list includes the given constant id.
list | The list to check. |
id | The id to check for. |
Definition at line 57 of file pm_constant_pool.c.
void pm_constant_id_list_init | ( | pm_constant_id_list_t * | list | ) |
Initialize a list of constant ids.
list | The list to initialize. |
Definition at line 7 of file pm_constant_pool.c.
void pm_constant_id_list_init_capacity | ( | pm_constant_id_list_t * | list, |
size_t | capacity | ||
) |
Initialize a list of constant ids with a given capacity.
list | The list to initialize. |
capacity | The initial capacity of the list. |
Definition at line 17 of file pm_constant_pool.c.
void pm_constant_id_list_insert | ( | pm_constant_id_list_t * | list, |
size_t | index, | ||
pm_constant_id_t | id | ||
) |
Insert a constant id into a list of constant ids at the specified index.
list | The list to insert into. |
index | The index at which to insert. |
id | The id to insert. |
Definition at line 45 of file pm_constant_pool.c.
pm_constant_id_t pm_constant_pool_find | ( | const pm_constant_pool_t * | pool, |
const uint8_t * | start, | ||
size_t | length | ||
) |
Find a constant in a constant pool.
Returns the id of the constant, or 0 if the constant is not found.
pool | The pool to find the constant in. |
start | A pointer to the start of the constant. |
length | The length of the constant. |
Returns the id of the constant, or 0 if the constant is not found.
Definition at line 205 of file pm_constant_pool.c.
void pm_constant_pool_free | ( | pm_constant_pool_t * | pool | ) |
Free the memory associated with a constant pool.
pool | The pool to free. |
Definition at line 324 of file pm_constant_pool.c.
Referenced by pm_parser_free().
pm_constant_t* pm_constant_pool_id_to_constant | ( | const pm_constant_pool_t * | pool, |
pm_constant_id_t | constant_id | ||
) |
Return a pointer to the constant indicated by the given constant id.
pool | The pool to get the constant from. |
constant_id | The id of the constant to get. |
Definition at line 195 of file pm_constant_pool.c.
bool pm_constant_pool_init | ( | pm_constant_pool_t * | pool, |
uint32_t | capacity | ||
) |
Initialize a new constant pool with a given capacity.
pool | The pool to initialize. |
capacity | The initial capacity of the pool. |
Definition at line 175 of file pm_constant_pool.c.
pm_constant_id_t pm_constant_pool_insert_constant | ( | pm_constant_pool_t * | pool, |
const uint8_t * | start, | ||
size_t | length | ||
) |
Insert a constant into a constant pool from memory that is constant.
Returns the id of the constant, or 0 if any potential calls to resize fail.
pool | The pool to insert the constant into. |
start | A pointer to the start of the constant. |
length | The length of the constant. |
Returns the id of the constant, or PM_CONSTANT_ID_UNSET if any potential calls to resize fail.
Definition at line 316 of file pm_constant_pool.c.
pm_constant_id_t pm_constant_pool_insert_owned | ( | pm_constant_pool_t * | pool, |
uint8_t * | start, | ||
size_t | length | ||
) |
Insert a constant into a constant pool from memory that is now owned by the constant pool.
Returns the id of the constant, or 0 if any potential calls to resize fail.
pool | The pool to insert the constant into. |
start | A pointer to the start of the constant. |
length | The length of the constant. |
Returns the id of the constant, or PM_CONSTANT_ID_UNSET if any potential calls to resize fail.
Definition at line 306 of file pm_constant_pool.c.
pm_constant_id_t pm_constant_pool_insert_shared | ( | pm_constant_pool_t * | pool, |
const uint8_t * | start, | ||
size_t | length | ||
) |
Insert a constant into a constant pool that is a slice of a source string.
Returns the id of the constant, or 0 if any potential calls to resize fail.
pool | The pool to insert the constant into. |
start | A pointer to the start of the constant. |
length | The length of the constant. |
Insert a constant into a constant pool that is a slice of a source string.
Returns the id of the constant, or PM_CONSTANT_ID_UNSET if any potential calls to resize fail.
Definition at line 296 of file pm_constant_pool.c.
|
static |
A constant constant is known at compile time.
Definition at line 110 of file pm_constant_pool.h.
Referenced by pm_constant_pool_insert_constant(), and pm_serialize_content().
|
static |
By default, each constant is a slice of the source.
Definition at line 104 of file pm_constant_pool.h.
Referenced by pm_constant_pool_insert_shared().
|
static |
An owned constant is one for which memory has been allocated.
Definition at line 107 of file pm_constant_pool.h.
Referenced by pm_constant_pool_free(), pm_constant_pool_insert_owned(), and pm_serialize_content().