Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3175,20 +3175,18 @@ static rbs_comment_t *comment_get_comment(rbs_comment_t *com, int line) {
}

static void comment_insert_new_line(rbs_allocator_t *allocator, rbs_comment_t *com, rbs_token_t comment_token) {
if (com->line_count == 0) {
com->start = comment_token.range.start;
}

if (com->line_count == com->line_size) {
com->line_size += 10;

if (com->tokens) {
rbs_token_t *p = com->tokens;
com->tokens = rbs_allocator_calloc(allocator, com->line_size, rbs_token_t);
memcpy(com->tokens, p, sizeof(rbs_token_t) * com->line_count);
} else {
com->tokens = rbs_allocator_calloc(allocator, com->line_size, rbs_token_t);
}
size_t old_size = com->line_size;
size_t new_size = old_size * 2;
com->line_size = new_size;

com->tokens = rbs_allocator_realloc(
allocator,
com->tokens,
sizeof(rbs_token_t) * old_size,
sizeof(rbs_token_t) * new_size,
rbs_token_t
);
}

com->tokens[com->line_count++] = comment_token;
Expand All @@ -3198,19 +3196,22 @@ static void comment_insert_new_line(rbs_allocator_t *allocator, rbs_comment_t *c
static rbs_comment_t *alloc_comment(rbs_allocator_t *allocator, rbs_token_t comment_token, rbs_comment_t *last_comment) {
rbs_comment_t *new_comment = rbs_allocator_alloc(allocator, rbs_comment_t);

size_t initial_line_size = 10;

rbs_token_t *tokens = rbs_allocator_calloc(allocator, initial_line_size, rbs_token_t);
tokens[0] = comment_token;

*new_comment = (rbs_comment_t) {
.start = comment_token.range.start,
.end = comment_token.range.end,

.line_size = 0,
.line_count = 0,
.tokens = NULL,
.line_size = initial_line_size,
.line_count = 1,
.tokens = tokens,

.next_comment = last_comment,
};

comment_insert_new_line(allocator, new_comment, comment_token);

return new_comment;
}

Expand Down