From 94ed1b696488e76a2b1380361372bd2a5de12553 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 6 Apr 2018 13:28:32 -0700 Subject: [PATCH] Make array_splice take an array, not a pointer and length --- src/runtime/array.h | 8 ++++---- src/runtime/parser.c | 17 ++++++++--------- src/runtime/tree.c | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/runtime/array.h b/src/runtime/array.h index e4e7ff0f..a0492526 100644 --- a/src/runtime/array.h +++ b/src/runtime/array.h @@ -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]) diff --git a/src/runtime/parser.c b/src/runtime/parser.c index a377c42a..0977a077 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -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; } diff --git a/src/runtime/tree.c b/src/runtime/tree.c index 06828f3b..f6dc542f 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -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]);