Prism Ruby parser
Loading...
Searching...
No Matches
pm_line_offset_list.h
Go to the documentation of this file.
1
14#ifndef PRISM_LINE_OFFSET_LIST_H
15#define PRISM_LINE_OFFSET_LIST_H
16
17#include "prism/defines.h"
18#include "prism/util/pm_arena.h"
19
20#include <assert.h>
21#include <stdbool.h>
22#include <stddef.h>
23#include <stdlib.h>
24
29typedef struct {
31 size_t size;
32
34 size_t capacity;
35
37 uint32_t *offsets;
39
43typedef struct {
45 int32_t line;
46
48 uint32_t column;
50
58void pm_line_offset_list_init(pm_arena_t *arena, pm_line_offset_list_t *list, size_t capacity);
59
66
74void pm_line_offset_list_append_slow(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor);
75
83static PRISM_FORCE_INLINE void
84pm_line_offset_list_append(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor) {
85 if (list->size < list->capacity) {
86 list->offsets[list->size++] = cursor;
87 } else {
88 pm_line_offset_list_append_slow(arena, list, cursor);
89 }
90}
91
101int32_t pm_line_offset_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line);
102
114
115#endif
Macro definitions used throughout the prism library.
#define PRISM_FORCE_INLINE
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition defines.h:103
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition defines.h:53
A bump allocator for the prism parser.
void pm_line_offset_list_clear(pm_line_offset_list_t *list)
Clear out the offsets that have been appended to the list.
Definition pm_line_offset_list.c:20
int32_t pm_line_offset_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line)
Returns the line of the given offset.
Definition pm_line_offset_list.c:46
void pm_line_offset_list_init(pm_arena_t *arena, pm_line_offset_list_t *list, size_t capacity)
Initialize a new line offset list with the given capacity.
Definition pm_line_offset_list.c:7
PRISM_EXPORTED_FUNCTION pm_line_column_t pm_line_offset_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line)
Returns the line and column of the given offset.
Definition pm_line_offset_list.c:73
void pm_line_offset_list_append_slow(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor)
Append a new offset to the list (slow path with resize).
Definition pm_line_offset_list.c:28
A bump allocator.
Definition pm_arena.h:39
A line and column in a string.
Definition pm_line_offset_list.h:43
uint32_t column
The column in bytes.
Definition pm_line_offset_list.h:48
int32_t line
The line number.
Definition pm_line_offset_list.h:45
A list of offsets of the start of lines in a string.
Definition pm_line_offset_list.h:29
uint32_t * offsets
The list of offsets.
Definition pm_line_offset_list.h:37
size_t size
The number of offsets in the list.
Definition pm_line_offset_list.h:31
size_t capacity
The capacity of the list that has been allocated.
Definition pm_line_offset_list.h:34