Remove the TS prefix from some internal type/function names
This commit is contained in:
parent
255bc2427c
commit
c9dcb29c6f
21 changed files with 313 additions and 313 deletions
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
TSStateId TS_TREE_STATE_NONE = USHRT_MAX;
|
||||
|
||||
TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size,
|
||||
Tree *ts_tree_make_leaf(TSSymbol sym, Length padding, Length size,
|
||||
TSSymbolMetadata metadata) {
|
||||
TSTree *result = ts_malloc(sizeof(TSTree));
|
||||
*result = (TSTree){
|
||||
Tree *result = ts_malloc(sizeof(Tree));
|
||||
*result = (Tree){
|
||||
.ref_count = 1,
|
||||
.symbol = sym,
|
||||
.size = size,
|
||||
|
|
@ -31,10 +31,10 @@ TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size,
|
|||
}
|
||||
|
||||
bool ts_tree_array_copy(TreeArray self, TreeArray *dest) {
|
||||
TSTree **contents = NULL;
|
||||
Tree **contents = NULL;
|
||||
if (self.capacity > 0) {
|
||||
contents = ts_calloc(self.capacity, sizeof(TSTree *));
|
||||
memcpy(contents, self.contents, self.size * sizeof(TSTree *));
|
||||
contents = ts_calloc(self.capacity, sizeof(Tree *));
|
||||
memcpy(contents, self.contents, self.size * sizeof(Tree *));
|
||||
for (size_t i = 0; i < self.size; i++)
|
||||
ts_tree_retain(contents[i]);
|
||||
}
|
||||
|
|
@ -54,15 +54,15 @@ void ts_tree_array_delete(TreeArray *self) {
|
|||
size_t ts_tree_array_essential_count(const TreeArray *self) {
|
||||
size_t result = 0;
|
||||
for (size_t i = 0; i < self->size; i++) {
|
||||
TSTree *tree = self->contents[i];
|
||||
Tree *tree = self->contents[i];
|
||||
if (!tree->extra && tree->symbol != ts_builtin_sym_error)
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_error(TSLength size, TSLength padding, char lookahead_char) {
|
||||
TSTree *result = ts_tree_make_leaf(ts_builtin_sym_error, padding, size,
|
||||
Tree *ts_tree_make_error(Length size, Length padding, char lookahead_char) {
|
||||
Tree *result = ts_tree_make_leaf(ts_builtin_sym_error, padding, size,
|
||||
(TSSymbolMetadata){
|
||||
.visible = true, .named = true,
|
||||
});
|
||||
|
|
@ -72,34 +72,34 @@ TSTree *ts_tree_make_error(TSLength size, TSLength padding, char lookahead_char)
|
|||
return result;
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_copy(TSTree *self) {
|
||||
TSTree *result = ts_malloc(sizeof(TSTree));
|
||||
Tree *ts_tree_make_copy(Tree *self) {
|
||||
Tree *result = ts_malloc(sizeof(Tree));
|
||||
*result = *self;
|
||||
result->ref_count = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ts_tree_assign_parents(TSTree *self, TreePath *path) {
|
||||
void ts_tree_assign_parents(Tree *self, TreePath *path) {
|
||||
array_clear(path);
|
||||
array_push(path, ((TreePathEntry){self, ts_length_zero(), 0}));
|
||||
array_push(path, ((TreePathEntry){self, length_zero(), 0}));
|
||||
while (path->size > 0) {
|
||||
TSTree *tree = array_pop(path).tree;
|
||||
TSLength offset = ts_length_zero();
|
||||
Tree *tree = array_pop(path).tree;
|
||||
Length offset = length_zero();
|
||||
for (size_t i = 0; i < tree->child_count; i++) {
|
||||
TSTree *child = tree->children[i];
|
||||
Tree *child = tree->children[i];
|
||||
if (child->context.parent != tree || child->context.index != i) {
|
||||
child->context.parent = tree;
|
||||
child->context.index = i;
|
||||
child->context.offset = offset;
|
||||
array_push(path, ((TreePathEntry){child, ts_length_zero(), 0}));
|
||||
array_push(path, ((TreePathEntry){child, length_zero(), 0}));
|
||||
}
|
||||
offset = ts_length_add(offset, ts_tree_total_size(child));
|
||||
offset = length_add(offset, ts_tree_total_size(child));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ts_tree_set_children(TSTree *self, size_t child_count, TSTree **children) {
|
||||
void ts_tree_set_children(Tree *self, size_t child_count, Tree **children) {
|
||||
if (self->child_count > 0)
|
||||
ts_free(self->children);
|
||||
|
||||
|
|
@ -110,13 +110,13 @@ void ts_tree_set_children(TSTree *self, size_t child_count, TSTree **children) {
|
|||
self->error_cost = 0;
|
||||
|
||||
for (size_t i = 0; i < child_count; i++) {
|
||||
TSTree *child = children[i];
|
||||
Tree *child = children[i];
|
||||
|
||||
if (i == 0) {
|
||||
self->padding = child->padding;
|
||||
self->size = child->size;
|
||||
} else {
|
||||
self->size = ts_length_add(self->size, ts_tree_total_size(child));
|
||||
self->size = length_add(self->size, ts_tree_total_size(child));
|
||||
}
|
||||
|
||||
self->error_cost += child->error_cost;
|
||||
|
|
@ -153,17 +153,17 @@ void ts_tree_set_children(TSTree *self, size_t child_count, TSTree **children) {
|
|||
}
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
|
||||
TSTree **children, TSSymbolMetadata metadata) {
|
||||
TSTree *result =
|
||||
ts_tree_make_leaf(symbol, ts_length_zero(), ts_length_zero(), metadata);
|
||||
Tree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
|
||||
Tree **children, TSSymbolMetadata metadata) {
|
||||
Tree *result =
|
||||
ts_tree_make_leaf(symbol, length_zero(), length_zero(), metadata);
|
||||
ts_tree_set_children(result, child_count, children);
|
||||
return result;
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_error_node(TreeArray *children) {
|
||||
Tree *ts_tree_make_error_node(TreeArray *children) {
|
||||
for (size_t i = 0; i < children->size; i++) {
|
||||
TSTree *child = children->contents[i];
|
||||
Tree *child = children->contents[i];
|
||||
if (child->symbol == ts_builtin_sym_error && child->child_count > 0) {
|
||||
array_splice(children, i, 1, child->child_count, child->children);
|
||||
i += child->child_count - 1;
|
||||
|
|
@ -173,7 +173,7 @@ TSTree *ts_tree_make_error_node(TreeArray *children) {
|
|||
}
|
||||
}
|
||||
|
||||
TSTree *result = ts_tree_make_node(
|
||||
Tree *result = ts_tree_make_node(
|
||||
ts_builtin_sym_error, children->size, children->contents,
|
||||
(TSSymbolMetadata){.extra = false, .visible = true, .named = true });
|
||||
|
||||
|
|
@ -182,12 +182,12 @@ TSTree *ts_tree_make_error_node(TreeArray *children) {
|
|||
return result;
|
||||
}
|
||||
|
||||
void ts_tree_retain(TSTree *self) {
|
||||
void ts_tree_retain(Tree *self) {
|
||||
assert(self->ref_count > 0);
|
||||
self->ref_count++;
|
||||
}
|
||||
|
||||
void ts_tree_release(TSTree *self) {
|
||||
void ts_tree_release(Tree *self) {
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ recur:
|
|||
if (self->child_count > 0) {
|
||||
for (size_t i = 0; i < self->child_count - 1; i++)
|
||||
ts_tree_release(self->children[i]);
|
||||
TSTree *last_child = self->children[self->child_count - 1];
|
||||
Tree *last_child = self->children[self->child_count - 1];
|
||||
ts_free(self->children);
|
||||
ts_free(self);
|
||||
|
||||
|
|
@ -211,11 +211,11 @@ recur:
|
|||
}
|
||||
}
|
||||
|
||||
size_t ts_tree_start_column(const TSTree *self) {
|
||||
size_t ts_tree_start_column(const Tree *self) {
|
||||
size_t column = self->padding.extent.column;
|
||||
if (self->padding.extent.row > 0)
|
||||
return column;
|
||||
for (const TSTree *tree = self; tree != NULL; tree = tree->context.parent) {
|
||||
for (const Tree *tree = self; tree != NULL; tree = tree->context.parent) {
|
||||
column += tree->context.offset.extent.column;
|
||||
if (tree->context.offset.extent.row > 0)
|
||||
break;
|
||||
|
|
@ -223,14 +223,14 @@ size_t ts_tree_start_column(const TSTree *self) {
|
|||
return column;
|
||||
}
|
||||
|
||||
size_t ts_tree_end_column(const TSTree *self) {
|
||||
size_t ts_tree_end_column(const Tree *self) {
|
||||
size_t result = self->size.extent.column;
|
||||
if (self->size.extent.row == 0)
|
||||
result += ts_tree_start_column(self);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ts_tree_eq(const TSTree *self, const TSTree *other) {
|
||||
bool ts_tree_eq(const Tree *self, const Tree *other) {
|
||||
if (self) {
|
||||
if (!other)
|
||||
return false;
|
||||
|
|
@ -258,7 +258,7 @@ bool ts_tree_eq(const TSTree *self, const TSTree *other) {
|
|||
return true;
|
||||
}
|
||||
|
||||
int ts_tree_compare(const TSTree *left, const TSTree *right) {
|
||||
int ts_tree_compare(const Tree *left, const Tree *right) {
|
||||
if (left->symbol < right->symbol)
|
||||
return -1;
|
||||
if (right->symbol < left->symbol)
|
||||
|
|
@ -268,8 +268,8 @@ int ts_tree_compare(const TSTree *left, const TSTree *right) {
|
|||
if (right->child_count < left->child_count)
|
||||
return 1;
|
||||
for (size_t i = 0; i < left->child_count; i++) {
|
||||
TSTree *left_child = left->children[i];
|
||||
TSTree *right_child = right->children[i];
|
||||
Tree *left_child = left->children[i];
|
||||
Tree *right_child = right->children[i];
|
||||
switch (ts_tree_compare(left_child, right_child)) {
|
||||
case -1:
|
||||
return -1;
|
||||
|
|
@ -287,70 +287,70 @@ static inline long min(long a, long b) {
|
|||
}
|
||||
|
||||
|
||||
void ts_tree_edit(TSTree *self, const TSInputEdit *edit) {
|
||||
void ts_tree_edit(Tree *self, const TSInputEdit *edit) {
|
||||
size_t old_end_byte = edit->start_byte + edit->bytes_removed;
|
||||
size_t new_end_byte = edit->start_byte + edit->bytes_added;
|
||||
TSPoint old_end_point = ts_point_add(edit->start_point, edit->extent_removed);
|
||||
TSPoint new_end_point = ts_point_add(edit->start_point, edit->extent_added);
|
||||
TSPoint old_end_point = point_add(edit->start_point, edit->extent_removed);
|
||||
TSPoint new_end_point = point_add(edit->start_point, edit->extent_added);
|
||||
|
||||
assert(old_end_byte <= ts_tree_total_bytes(self));
|
||||
|
||||
self->has_changes = true;
|
||||
|
||||
if (edit->start_byte < self->padding.bytes) {
|
||||
ts_length_set_unknown_chars(&self->padding);
|
||||
length_set_unknown_chars(&self->padding);
|
||||
if (self->padding.bytes >= old_end_byte) {
|
||||
size_t trailing_padding_bytes = self->padding.bytes - old_end_byte;
|
||||
TSPoint trailing_padding_extent = ts_point_sub(self->padding.extent, old_end_point);
|
||||
TSPoint trailing_padding_extent = point_sub(self->padding.extent, old_end_point);
|
||||
self->padding.bytes = new_end_byte + trailing_padding_bytes;
|
||||
self->padding.extent = ts_point_add(new_end_point, trailing_padding_extent);
|
||||
self->padding.extent = point_add(new_end_point, trailing_padding_extent);
|
||||
} else {
|
||||
ts_length_set_unknown_chars(&self->size);
|
||||
length_set_unknown_chars(&self->size);
|
||||
size_t removed_content_bytes = old_end_byte - self->padding.bytes;
|
||||
TSPoint removed_content_extent = ts_point_sub(old_end_point, self->padding.extent);
|
||||
TSPoint removed_content_extent = point_sub(old_end_point, self->padding.extent);
|
||||
self->size.bytes = self->size.bytes - removed_content_bytes;
|
||||
self->size.extent = ts_point_sub(self->size.extent, removed_content_extent);
|
||||
self->size.extent = point_sub(self->size.extent, removed_content_extent);
|
||||
self->padding.bytes = new_end_byte;
|
||||
self->padding.extent = new_end_point;
|
||||
}
|
||||
} else if (edit->start_byte == self->padding.bytes && edit->bytes_removed == 0) {
|
||||
ts_length_set_unknown_chars(&self->padding);
|
||||
length_set_unknown_chars(&self->padding);
|
||||
self->padding.bytes = self->padding.bytes + edit->bytes_added;
|
||||
self->padding.extent = ts_point_add(self->padding.extent, edit->extent_added);
|
||||
self->padding.extent = point_add(self->padding.extent, edit->extent_added);
|
||||
} else {
|
||||
ts_length_set_unknown_chars(&self->size);
|
||||
length_set_unknown_chars(&self->size);
|
||||
size_t trailing_content_bytes = ts_tree_total_bytes(self) - old_end_byte;
|
||||
TSPoint trailing_content_extent = ts_point_sub(ts_tree_total_extent(self), old_end_point);
|
||||
TSPoint trailing_content_extent = point_sub(ts_tree_total_extent(self), old_end_point);
|
||||
self->size.bytes = new_end_byte + trailing_content_bytes - self->padding.bytes;
|
||||
self->size.extent = ts_point_sub(ts_point_add(new_end_point, trailing_content_extent), self->padding.extent);
|
||||
self->size.extent = point_sub(point_add(new_end_point, trailing_content_extent), self->padding.extent);
|
||||
}
|
||||
|
||||
bool found_first_child = false;
|
||||
long remaining_bytes_to_delete = 0;
|
||||
TSPoint remaining_extent_to_delete = {0, 0};
|
||||
TSLength child_left, child_right = ts_length_zero();
|
||||
Length child_left, child_right = length_zero();
|
||||
for (size_t i = 0; i < self->child_count; i++) {
|
||||
TSTree *child = self->children[i];
|
||||
Tree *child = self->children[i];
|
||||
child_left = child_right;
|
||||
|
||||
if (!found_first_child) {
|
||||
child_right = ts_length_add(child_left, ts_tree_total_size(child));
|
||||
child_right = length_add(child_left, ts_tree_total_size(child));
|
||||
if (child_right.bytes >= edit->start_byte) {
|
||||
found_first_child = true;
|
||||
TSInputEdit child_edit = {
|
||||
.start_byte = edit->start_byte - child_left.bytes,
|
||||
.bytes_added = edit->bytes_added,
|
||||
.bytes_removed = edit->bytes_removed,
|
||||
.start_point = ts_point_sub(edit->start_point, child_left.extent),
|
||||
.start_point = point_sub(edit->start_point, child_left.extent),
|
||||
.extent_added = edit->extent_added,
|
||||
.extent_removed = edit->extent_removed,
|
||||
};
|
||||
|
||||
if (old_end_byte > child_right.bytes) {
|
||||
child_edit.bytes_removed = child_right.bytes - edit->start_byte;
|
||||
child_edit.extent_removed = ts_point_sub(child_right.extent, edit->start_point);
|
||||
child_edit.extent_removed = point_sub(child_right.extent, edit->start_point);
|
||||
remaining_bytes_to_delete = old_end_byte - child_right.bytes;
|
||||
remaining_extent_to_delete = ts_point_sub(old_end_point, child_right.extent);
|
||||
remaining_extent_to_delete = point_sub(old_end_point, child_right.extent);
|
||||
}
|
||||
|
||||
ts_tree_edit(child, &child_edit);
|
||||
|
|
@ -362,14 +362,14 @@ void ts_tree_edit(TSTree *self, const TSInputEdit *edit) {
|
|||
.bytes_removed = min(remaining_bytes_to_delete, ts_tree_total_bytes(child)),
|
||||
.start_point = {0, 0},
|
||||
.extent_added = {0, 0},
|
||||
.extent_removed = ts_point_min(remaining_extent_to_delete, ts_tree_total_size(child).extent),
|
||||
.extent_removed = point_min(remaining_extent_to_delete, ts_tree_total_size(child).extent),
|
||||
};
|
||||
remaining_bytes_to_delete -= child_edit.bytes_removed;
|
||||
remaining_extent_to_delete = ts_point_sub(remaining_extent_to_delete, child_edit.extent_removed);
|
||||
remaining_extent_to_delete = point_sub(remaining_extent_to_delete, child_edit.extent_removed);
|
||||
ts_tree_edit(child, &child_edit);
|
||||
}
|
||||
|
||||
child_right = ts_length_add(child_left, ts_tree_total_size(child));
|
||||
child_right = length_add(child_left, ts_tree_total_size(child));
|
||||
child->context.offset = child_left;
|
||||
}
|
||||
}
|
||||
|
|
@ -389,7 +389,7 @@ static size_t ts_tree__write_char_to_string(char *s, size_t n, int32_t c) {
|
|||
return snprintf(s, n, "%d", c);
|
||||
}
|
||||
|
||||
static size_t ts_tree__write_to_string(const TSTree *self,
|
||||
static size_t ts_tree__write_to_string(const Tree *self,
|
||||
const TSLanguage *language, char *string,
|
||||
size_t limit, bool is_root,
|
||||
bool include_all) {
|
||||
|
|
@ -416,7 +416,7 @@ static size_t ts_tree__write_to_string(const TSTree *self,
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < self->child_count; i++) {
|
||||
TSTree *child = self->children[i];
|
||||
Tree *child = self->children[i];
|
||||
cursor += ts_tree__write_to_string(child, language, *writer, limit, false,
|
||||
include_all);
|
||||
}
|
||||
|
|
@ -427,7 +427,7 @@ static size_t ts_tree__write_to_string(const TSTree *self,
|
|||
return cursor - string;
|
||||
}
|
||||
|
||||
char *ts_tree_string(const TSTree *self, const TSLanguage *language,
|
||||
char *ts_tree_string(const Tree *self, const TSLanguage *language,
|
||||
bool include_all) {
|
||||
static char SCRATCH[1];
|
||||
size_t size =
|
||||
|
|
@ -437,7 +437,7 @@ char *ts_tree_string(const TSTree *self, const TSLanguage *language,
|
|||
return result;
|
||||
}
|
||||
|
||||
void ts_tree__print_dot_graph(const TSTree *self, size_t byte_offset,
|
||||
void ts_tree__print_dot_graph(const Tree *self, size_t byte_offset,
|
||||
const TSLanguage *language, FILE *f) {
|
||||
fprintf(f, "tree_%p [label=\"%s\"", self,
|
||||
ts_language_symbol_name(language, self->symbol));
|
||||
|
|
@ -451,14 +451,14 @@ void ts_tree__print_dot_graph(const TSTree *self, size_t byte_offset,
|
|||
byte_offset, byte_offset + ts_tree_total_bytes(self), self->parse_state,
|
||||
self->error_cost);
|
||||
for (size_t i = 0; i < self->child_count; i++) {
|
||||
const TSTree *child = self->children[i];
|
||||
const Tree *child = self->children[i];
|
||||
ts_tree__print_dot_graph(child, byte_offset, language, f);
|
||||
fprintf(f, "tree_%p -> tree_%p [tooltip=%lu]\n", self, child, i);
|
||||
byte_offset += ts_tree_total_bytes(child);
|
||||
}
|
||||
}
|
||||
|
||||
void ts_tree_print_dot_graph(const TSTree *self, const TSLanguage *language,
|
||||
void ts_tree_print_dot_graph(const Tree *self, const TSLanguage *language,
|
||||
FILE *f) {
|
||||
fprintf(f, "digraph tree {\n");
|
||||
fprintf(f, "edge [arrowhead=none]\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue