Make array_splice take an array, not a pointer and length

This commit is contained in:
Max Brunsfeld 2018-04-06 13:28:32 -07:00
parent 09be0b6ef5
commit 94ed1b6964
3 changed files with 13 additions and 14 deletions

View file

@ -47,14 +47,14 @@ extern "C" {
(self)->contents[(self)->size++] = (element))
#define array_push_all(self, other) \
array_splice((self), (self)->size, 0, (other)->size, (other)->contents)
array_splice((self), (self)->size, 0, (other))
#define array_splice(self, index, old_count, new_count, new_elements) \
#define array_splice(self, index, old_count, new_array) \
array__splice((VoidArray *)(self), array__elem_size(self), index, old_count, \
new_count, (new_elements))
(new_array)->size, (new_array)->contents)
#define array_insert(self, index, element) \
array_splice(self, index, 0, 1, &(element))
array__splice((VoidArray *)(self), array__elem_size(self), index, 0, 1, &element)
#define array_pop(self) ((self)->contents[--(self)->size])

View file

@ -672,29 +672,28 @@ static void parser__start(Parser *self, TSInput input, Tree *previous_tree) {
self->in_ambiguity = false;
}
static void parser__accept(Parser *self, StackVersion version,
Tree *lookahead) {
static void parser__accept(Parser *self, StackVersion version, Tree *lookahead) {
lookahead->extra = true;
assert(lookahead->symbol == ts_builtin_sym_end);
ts_tree_retain(lookahead);
ts_stack_push(self->stack, version, lookahead, false, 1);
StackSliceArray pop = ts_stack_pop_all(self->stack, version);
StackSliceArray pop = ts_stack_pop_all(self->stack, version);
for (uint32_t i = 0; i < pop.size; i++) {
StackSlice slice = pop.contents[i];
TreeArray trees = slice.trees;
TreeArray trees = pop.contents[i].trees;
Tree *root = NULL;
for (uint32_t j = trees.size - 1; j + 1 > 0; j--) {
Tree *child = trees.contents[j];
if (!child->extra) {
root = ts_tree_make_copy(&self->tree_pool, child);
root->children.size = 0;
for (uint32_t k = 0; k < child->children.size; k++) {
ts_tree_retain(child->children.contents[k]);
}
array_splice(&trees, j, 1, child->children.size, child->children.contents);
ts_tree_set_children(root, &trees, self->language);
array_splice(&trees, j, 1, &child->children);
root = ts_tree_make_node(
&self->tree_pool, child->symbol, &trees,
child->alias_sequence_id, self->language
);
ts_tree_release(&self->tree_pool, child);
break;
}

View file

@ -395,7 +395,7 @@ Tree *ts_tree_make_error_node(TreePool *pool, TreeArray *children, const TSLangu
for (uint32_t i = 0; i < children->size; i++) {
Tree *child = children->contents[i];
if (child->symbol == ts_builtin_sym_error && child->children.size > 0) {
array_splice(children, i, 1, child->children.size, child->children.contents);
array_splice(children, i, 1, &child->children);
i += child->children.size - 1;
for (uint32_t j = 0; j < child->children.size; j++)
ts_tree_retain(child->children.contents[j]);