Skip to content

Commit c661045

Browse files
committed
Move list out of utils
1 parent 60e105f commit c661045

File tree

10 files changed

+43
-104
lines changed

10 files changed

+43
-104
lines changed

include/prism/internal/diagnostic.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "prism/diagnostic.h"
1010
#include "prism/arena.h"
11-
#include "prism/util/pm_list.h"
1211

1312
/**
1413
* Append a diagnostic to the given list of diagnostics that is using shared
Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/**
2-
* @file pm_list.h
2+
* @file list.h
33
*
44
* An abstract linked list.
55
*/
66
#ifndef PRISM_LIST_H
77
#define PRISM_LIST_H
88

9-
#include "prism/defines.h"
10-
11-
#include <stdbool.h>
129
#include <stddef.h>
13-
#include <stdint.h>
14-
#include <stdlib.h>
1510

1611
/**
1712
* This struct represents an abstract linked list that provides common
@@ -63,25 +58,13 @@ typedef struct {
6358
pm_list_node_t *tail;
6459
} pm_list_t;
6560

66-
/**
67-
* Returns true if the given list is empty.
68-
*
69-
* @param list The list to check.
70-
* @return True if the given list is empty, otherwise false.
71-
*
72-
* \public \memberof pm_list_t
73-
*/
74-
PRISM_EXPORTED_FUNCTION bool pm_list_empty_p(pm_list_t *list);
75-
7661
/**
7762
* Returns the size of the list.
7863
*
7964
* @param list The list to check.
8065
* @return The size of the list.
81-
*
82-
* \public \memberof pm_list_t
8366
*/
84-
PRISM_EXPORTED_FUNCTION size_t pm_list_size(pm_list_t *list);
67+
size_t pm_list_size(pm_list_t *list);
8568

8669
/**
8770
* Append a node to the given list.
@@ -91,13 +74,4 @@ PRISM_EXPORTED_FUNCTION size_t pm_list_size(pm_list_t *list);
9174
*/
9275
void pm_list_append(pm_list_t *list, pm_list_node_t *node);
9376

94-
/**
95-
* Deallocate the internal state of the given list.
96-
*
97-
* @param list The list to free.
98-
*
99-
* \public \memberof pm_list_t
100-
*/
101-
PRISM_EXPORTED_FUNCTION void pm_list_free(pm_list_t *list);
102-
10377
#endif

include/prism/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#include "prism/constant_pool.h"
1313
#include "prism/encoding.h"
1414
#include "prism/line_offset_list.h"
15+
#include "prism/list.h"
1516
#include "prism/options.h"
1617
#include "prism/static_literals.h"
1718
#include "prism/strings.h"
18-
#include "prism/util/pm_list.h"
1919

2020
#include <stdbool.h>
2121

prism.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Gem::Specification.new do |spec|
6464
"include/prism/files.h",
6565
"include/prism/integer.h",
6666
"include/prism/line_offset_list.h",
67+
"include/prism/list.h",
6768
"include/prism/node.h",
6869
"include/prism/node_new.h",
6970
"include/prism/options.h",
@@ -85,7 +86,6 @@ Gem::Specification.new do |spec|
8586
"include/prism/internal/strncasecmp.h",
8687
"include/prism/internal/strings.h",
8788
"include/prism/internal/strpbrk.h",
88-
"include/prism/util/pm_list.h",
8989
"include/prism/version.h",
9090
"lib/prism.rb",
9191
"lib/prism/compiler.rb",
@@ -183,6 +183,7 @@ Gem::Specification.new do |spec|
183183
"src/encoding.c",
184184
"src/integer.c",
185185
"src/line_offset_list.c",
186+
"src/list.c",
186187
"src/memchr.c",
187188
"src/node.c",
188189
"src/options.c",
@@ -194,8 +195,7 @@ Gem::Specification.new do |spec|
194195
"src/strings.c",
195196
"src/strncasecmp.c",
196197
"src/strpbrk.c",
197-
"src/token_type.c",
198-
"src/util/pm_list.c"
198+
"src/token_type.c"
199199
]
200200

201201
spec.extensions = ["ext/prism/extconf.rb"]

rust/ruby-prism-sys/build/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ fn generate_bindings(ruby_include_path: &Path) -> bindgen::Bindings {
149149
// Functions
150150
.allowlist_function("pm_arena_free")
151151
.allowlist_function("pm_line_offset_list_line_column")
152-
.allowlist_function("pm_list_empty_p")
153-
.allowlist_function("pm_list_free")
154152
.allowlist_function("pm_options_command_line_set")
155153
.allowlist_function("pm_options_encoding_locked_set")
156154
.allowlist_function("pm_options_encoding_set")

rust/ruby-prism-sys/tests/utils_tests.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::{
2-
ffi::{CStr, CString},
3-
mem::MaybeUninit,
4-
};
1+
use std::ffi::{CStr, CString};
52

63
#[test]
74
fn version_test() {
@@ -15,21 +12,6 @@ fn version_test() {
1512
assert_eq!(&cstring.to_string_lossy(), "1.9.0");
1613
}
1714

18-
#[test]
19-
fn list_test() {
20-
use ruby_prism_sys::{pm_list_empty_p, pm_list_free, pm_list_t};
21-
22-
let mut list = MaybeUninit::<pm_list_t>::zeroed();
23-
24-
unsafe {
25-
let list = list.assume_init_mut();
26-
27-
assert!(pm_list_empty_p(list));
28-
29-
pm_list_free(list);
30-
}
31-
}
32-
3315
mod string {
3416
use ruby_prism_sys::{
3517
pm_string_free, pm_string_length, pm_string_source, pm_string_t, pm_string_t__bindgen_ty_1, PM_STRING_CONSTANT,

src/list.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "prism/list.h"
2+
3+
/**
4+
* Returns the size of the list.
5+
*/
6+
size_t
7+
pm_list_size(pm_list_t *list) {
8+
return list->size;
9+
}
10+
11+
/**
12+
* Append a node to the given list.
13+
*/
14+
void
15+
pm_list_append(pm_list_t *list, pm_list_node_t *node) {
16+
if (list->head == NULL) {
17+
list->head = node;
18+
} else {
19+
list->tail->next = node;
20+
}
21+
22+
list->tail = node;
23+
list->size++;
24+
}

src/util/pm_list.c

Lines changed: 0 additions & 49 deletions
This file was deleted.

templates/include/prism/diagnostic.h.erb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#ifndef PRISM_DIAGNOSTIC_H
77
#define PRISM_DIAGNOSTIC_H
88

9+
#include "prism/attribute/exported.h"
910
#include "prism/ast.h"
10-
#include "prism/util/pm_list.h"
11+
#include "prism/list.h"
1112

1213
/**
1314
* The diagnostic IDs of all of the diagnostics, used to communicate the types
@@ -75,4 +76,12 @@ typedef enum {
7576
PM_WARNING_LEVEL_VERBOSE = 1
7677
} pm_warning_level_t;
7778

79+
/**
80+
* Get the human-readable name of the given diagnostic ID.
81+
*
82+
* @param diag_id The diagnostic ID to get the name of.
83+
* @returns The human-readable name of the given diagnostic ID.
84+
*/
85+
PRISM_EXPORTED_FUNCTION const char * pm_diagnostic_id_human(pm_diagnostic_id_t diag_id);
86+
7887
#endif

templates/src/node.c.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "prism/internal/constant_pool.h"
55
#include "prism/internal/integer.h"
66

7+
#include <stdlib.h>
8+
79
/**
810
* Attempts to grow the node list to the next size. If there is already
911
* capacity in the list, this function does nothing. Otherwise it allocates a

0 commit comments

Comments
 (0)