Skip to content

Commit 5407a45

Browse files
committed
Use designated initializers
1 parent ecc51f7 commit 5407a45

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

src/ast.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,11 @@ void rbs_hash_set(rbs_hash_t *hash, rbs_node_t *key, rbs_node_t *value) {
252252
}
253253

254254
rbs_hash_node_t *new_node = rbs_alloc(hash->allocator, rbs_hash_node_t);
255-
new_node->key = key;
256-
new_node->value = value;
257-
new_node->next = NULL;
255+
*new_node = (rbs_hash_node_t) {
256+
.key = key,
257+
.value = value,
258+
.next = NULL,
259+
};
258260

259261
if (hash->tail == NULL) {
260262
hash->head = new_node;

src/location.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@ void rbs_loc_alloc_children(rbs_allocator_t *allocator, rbs_location_t *loc, siz
1010

1111
loc->children = rbs_allocator_malloc_impl(allocator, RBS_LOC_CHILDREN_SIZE(capacity), rbs_alignof(rbs_loc_children));
1212

13-
loc->children->len = 0;
14-
loc->children->required_p = 0;
15-
loc->children->cap = capacity;
13+
*loc->children = (rbs_loc_children) {
14+
.len = 0,
15+
.cap = capacity,
16+
.required_p = 0,
17+
.entries = { 0 },
18+
};
1619
}
1720

1821
void rbs_loc_add_optional_child(rbs_location_t *loc, rbs_constant_id_t name, rbs_range_t r) {
1922
rbs_assert(loc->children != NULL, "All children should have been pre-allocated with rbs_loc_alloc_children()");
2023
rbs_assert((loc->children->len + 1 <= loc->children->cap), "Not enough space was pre-allocated for the children. Children: %hu, Capacity: %hu", loc->children->len, loc->children->cap);
2124

2225
unsigned short i = loc->children->len++;
23-
loc->children->entries[i].name = name;
24-
loc->children->entries[i].rg = (rbs_loc_range) { r.start.char_pos, r.end.char_pos };
26+
27+
loc->children->entries[i] = (rbs_loc_entry) {
28+
.name = name,
29+
.rg = (rbs_loc_range) { r.start.char_pos, r.end.char_pos },
30+
};
2531
}
2632

2733
void rbs_loc_add_required_child(rbs_location_t *loc, rbs_constant_id_t name, rbs_range_t r) {

src/parser.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,12 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
837837
);
838838
}
839839

840-
(*result)->function = function;
841-
(*result)->block = block;
842-
(*result)->function_self_type = function_self_type;
840+
**result = (parse_function_result) {
841+
.function = function,
842+
.block = block,
843+
.function_self_type = function_self_type,
844+
};
845+
843846
return true;
844847
}
845848

@@ -1787,8 +1790,10 @@ static bool parse_method_name(rbs_parser_t *parser, rbs_range_t *range, rbs_ast_
17871790
case tULLIDENT:
17881791
KEYWORD_CASES
17891792
if (parser->next_token.type == pQUESTION && parser->current_token.range.end.byte_pos == parser->next_token.range.start.byte_pos) {
1790-
range->start = parser->current_token.range.start;
1791-
range->end = parser->next_token.range.end;
1793+
*range = (rbs_range_t) {
1794+
.start = parser->current_token.range.start,
1795+
.end = parser->next_token.range.end,
1796+
};
17921797
rbs_parser_advance(parser);
17931798

17941799
rbs_constant_id_t constant_id = rbs_constant_pool_insert_shared_with_encoding(
@@ -3554,9 +3559,11 @@ void rbs_parser_set_error(rbs_parser_t *parser, rbs_token_t tok, bool syntax_err
35543559
va_end(args);
35553560

35563561
parser->error = rbs_alloc(ALLOCATOR(), rbs_error_t);
3557-
parser->error->token = tok;
3558-
parser->error->message = message;
3559-
parser->error->syntax_error = syntax_error;
3562+
*parser->error = (rbs_error_t) {
3563+
.message = message,
3564+
.token = tok,
3565+
.syntax_error = syntax_error,
3566+
};
35603567
}
35613568

35623569
/*

templates/src/ast.c.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ void rbs_hash_set(rbs_hash_t *hash, rbs_node_t *key, rbs_node_t *value) {
105105
}
106106

107107
rbs_hash_node_t *new_node = rbs_alloc(hash->allocator, rbs_hash_node_t);
108-
new_node->key = key;
109-
new_node->value = value;
110-
new_node->next = NULL;
108+
*new_node = (rbs_hash_node_t) {
109+
.key = key,
110+
.value = value,
111+
.next = NULL,
112+
};
111113

112114
if (hash->tail == NULL) {
113115
hash->head = new_node;

0 commit comments

Comments
 (0)