Skip to content

Commit ee89e71

Browse files
committed
Use designated initializers
1 parent d437e12 commit ee89e71

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
@@ -244,9 +244,11 @@ void rbs_hash_set(rbs_hash_t *hash, rbs_node_t *key, rbs_node_t *value) {
244244
}
245245

246246
rbs_hash_node_t *new_node = rbs_alloc(hash->allocator, rbs_hash_node_t);
247-
new_node->key = key;
248-
new_node->value = value;
249-
new_node->next = NULL;
247+
*new_node = (rbs_hash_node_t) {
248+
.key = key,
249+
.value = value,
250+
.next = NULL,
251+
};
250252

251253
if (hash->tail == NULL) {
252254
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), 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
@@ -795,9 +795,12 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
795795
);
796796
}
797797

798-
(*result)->function = function;
799-
(*result)->block = block;
800-
(*result)->function_self_type = function_self_type;
798+
**result = (parse_function_result) {
799+
.function = function,
800+
.block = block,
801+
.function_self_type = function_self_type,
802+
};
803+
801804
return true;
802805
}
803806

@@ -1696,8 +1699,10 @@ static bool parse_method_name(rbs_parser_t *parser, rbs_range_t *range, rbs_ast_
16961699
case tULLIDENT:
16971700
KEYWORD_CASES
16981701
if (parser->next_token.type == pQUESTION && parser->current_token.range.end.byte_pos == parser->next_token.range.start.byte_pos) {
1699-
range->start = parser->current_token.range.start;
1700-
range->end = parser->next_token.range.end;
1702+
*range = (rbs_range_t) {
1703+
.start = parser->current_token.range.start,
1704+
.end = parser->next_token.range.end,
1705+
};
17011706
rbs_parser_advance(parser);
17021707

17031708
rbs_constant_id_t constant_id = rbs_constant_pool_insert_shared_with_encoding(
@@ -3462,9 +3467,11 @@ void rbs_parser_set_error(rbs_parser_t *parser, rbs_token_t tok, bool syntax_err
34623467
va_end(args);
34633468

34643469
parser->error = rbs_alloc(ALLOCATOR(), rbs_error_t);
3465-
parser->error->token = tok;
3466-
parser->error->message = message;
3467-
parser->error->syntax_error = syntax_error;
3470+
*parser->error = (rbs_error_t) {
3471+
.message = message,
3472+
.token = tok,
3473+
.syntax_error = syntax_error,
3474+
};
34683475
}
34693476

34703477
/*

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)