diff --git a/Makefile b/Makefile index c3039410..8fa67b87 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/08/19 14:00:31 by maiboyer ### ########.fr # +# Updated: 2024/08/22 16:39:40 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -48,13 +48,14 @@ endif # TODO: REMOVE THIS WHEN FINISHING THIS: CFLAGS_ADDITIONAL += -O0 -CFLAGS_ADDITIONAL += -Wno-cpp -Wno-type-limits +CFLAGS_ADDITIONAL += -Wno-cpp -Wno-type-limits -Wno-unused-command-line-argument CFLAGS_ADDITIONAL += -gcolumn-info -g3 CFLAGS_ADDITIONAL += '-DERROR=((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)' CFLAGS_ADDITIONAL += '-Dinline=' -Wno-unused-function +CFLAGS_ADDITIONAL += '-Dstatic=' -Wno-unused-function #CFLAGS_ADDITIONAL += -O2 # CFLAGS_ADDITIONAL += -fuse-ld=gold -Wl,--print-symbol-counts -Wl,/tmp/symbols_count.log -CFLAGS_ADDITIONAL += -fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-O0 +CFLAGS_ADDITIONAL += -fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-O3 -Wl,--allow-multiple-definition export CFLAGS_ADDITIONAL export CC diff --git a/flake.nix b/flake.nix index 00f0704b..c2afc839 100644 --- a/flake.nix +++ b/flake.nix @@ -4,48 +4,32 @@ inputs.nixpkgs.url = "github:nixos/nixpkgs"; inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.generic_c.url = "github:Maix0/generic_c"; - # inputs.c_formatter_42.url = "github:Maix0/c_formatter_42-flake"; - # inputs.rust-overlay.url = "github:oxalica/rust-overlay"; outputs = { self, nixpkgs, flake-utils, generic_c, - # c_formatter_42, - # rust-overlay, }: flake-utils.lib.eachDefaultSystem ( system: let pkgs = nixpkgs.legacyPackages.${system}; - /* - import nixpkgs { - inherit system; - overlays = [ - (import rust-overlay) - (final: prev: { - clang-analyzer = prev.clang-analyzer.override { - clang = final.llvmPackages_18.clang; - llvmPackages = final.llvmPackages_18; - }; - }) - ]; - }; - */ in { devShell = pkgs.mkShell { packages = with pkgs; [ - clang-analyzer + (clang-analyzer.override { + clang = pkgs.llvmPackages_18.clang; + llvmPackages = pkgs.llvmPackages_18; + }) clang gnumake + llvmPackages_18.bintools + tokei + norminette + coreutils generic_c.packages.${system}.default - # c_formatter_42.packages.${system}.default - llvmPackages.bintools - # norminette - # tokei - # coreutils - #]; + python312 ] ++ ( if system == "x86_64-linux" diff --git a/line/src/line_globals.c b/line/src/line_globals.c index ae089a8f..1e7e2099 100644 --- a/line/src/line_globals.c +++ b/line/src/line_globals.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/10 15:47:12 by maiboyer #+# #+# */ -/* Updated: 2024/07/10 15:56:48 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:26:35 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,11 @@ #include "line/_line_structs.h" #include "me/mem/mem.h" + +#ifdef static +# undef static +#endif + t_const_str get_unfinished_str(void) { return ("If you see this," diff --git a/parser/include/parser/api.h b/parser/include/parser/api.h index e565ab7b..2d217cca 100644 --- a/parser/include/parser/api.h +++ b/parser/include/parser/api.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/22 13:54:54 by maiboyer #+# #+# */ -/* Updated: 2024/08/19 14:21:45 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 15:22:06 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -113,16 +113,19 @@ typedef struct TSInputEdit typedef struct TSNode { - t_u32 context[4]; + t_u32 start_byte; + t_u32 start_row; + t_u32 start_col; + t_u32 alias; const void *id; const TSTree *tree; } TSNode; -typedef TSNode t_parse_node; -typedef TSSymbol t_symbol; -typedef TSParser t_first_parser; +typedef TSNode t_parse_node; +typedef TSSymbol t_symbol; +typedef TSParser t_first_parser; typedef TSLanguage t_language; -typedef TSTree t_first_tree; +typedef TSTree t_first_tree; typedef struct TSTreeCursor { diff --git a/parser/include/parser/subtree.h b/parser/include/parser/subtree.h index daef0f20..ce7db052 100644 --- a/parser/include/parser/subtree.h +++ b/parser/include/parser/subtree.h @@ -13,7 +13,7 @@ #define TS_BIG_ENDIAN 0 #define TS_PTR_SIZE 64 #define TS_TREE_STATE_NONE USHRT_MAX -#define NULL_SUBTREE ((Subtree){.ptr = NULL}) +#define NULL_SUBTREE ((Subtree)NULL) struct ExternalScannerState { @@ -40,7 +40,9 @@ typedef struct ExternalScannerState ExternalScannerState; // This representation is used for parent nodes, external tokens, // errors, and other leaf nodes whose data is too large to fit into // the inline representation. -typedef struct SubtreeHeapData +typedef struct SubtreeHeapData SubtreeHeapData; + +struct SubtreeHeapData { t_u32 ref_count; Length padding; @@ -86,96 +88,83 @@ typedef struct SubtreeHeapData // Error terminal subtrees (`child_count == 0 && symbol == ts_builtin_sym_error`) t_i32 lookahead_char; }; -} SubtreeHeapData; +}; // The fundamental building block of a syntax tree. -typedef union Subtree { - const SubtreeHeapData *ptr; -} Subtree; +typedef const SubtreeHeapData *Subtree; // Like Subtree, but mutable. -typedef union MutableSubtree { - SubtreeHeapData *ptr; -} MutableSubtree; +typedef SubtreeHeapData *MutableSubtree; typedef Array(Subtree) SubtreeArray; typedef Array(MutableSubtree) MutableSubtreeArray; -typedef struct SubtreePool -{ - MutableSubtreeArray free_trees; - MutableSubtreeArray tree_stack; -} SubtreePool_; - void ts_external_scanner_state_init(ExternalScannerState *, const t_u8 *, t_u32); const t_u8 *ts_external_scanner_state_data(const ExternalScannerState *); bool ts_external_scanner_state_eq(const ExternalScannerState *self, const t_u8 *, t_u32); void ts_external_scanner_state_delete(ExternalScannerState *self); void ts_subtree_array_copy(SubtreeArray, SubtreeArray *); -void ts_subtree_array_clear(/*SubtreePool *,*/ SubtreeArray *); -void ts_subtree_array_delete(/*SubtreePool *,*/ SubtreeArray *); +void ts_subtree_array_clear(SubtreeArray *); +void ts_subtree_array_delete(SubtreeArray *); void ts_subtree_array_remove_trailing_extras(SubtreeArray *, SubtreeArray *); void ts_subtree_array_reverse(SubtreeArray *); -// SubtreePool ts_subtree_pool_new(t_u32 capacity); -// void ts_subtree_pool_delete(SubtreePool *); - -Subtree ts_subtree_new_leaf(/*SubtreePool *,*/ TSSymbol, Length, Length, t_u32, TSStateId, bool, bool, bool, const TSLanguage *); -Subtree ts_subtree_new_error(/*SubtreePool *,*/ t_i32, Length, Length, t_u32, TSStateId, const TSLanguage *); -MutableSubtree ts_subtree_new_node(TSSymbol, SubtreeArray *, t_u32, const TSLanguage *); -Subtree ts_subtree_new_error_node(SubtreeArray *, bool, const TSLanguage *); -Subtree ts_subtree_new_missing_leaf(/*SubtreePool *,*/ TSSymbol, Length, t_u32, const TSLanguage *); -MutableSubtree ts_subtree_make_mut(/*SubtreePool *,*/ Subtree); -void ts_subtree_retain(Subtree); -void ts_subtree_release(/*SubtreePool *,*/ Subtree); -int ts_subtree_compare(Subtree, Subtree /*, SubtreePool **/); -void ts_subtree_set_symbol(MutableSubtree *, TSSymbol, const TSLanguage *); -void ts_subtree_summarize(MutableSubtree, const Subtree *, t_u32, const TSLanguage *); -void ts_subtree_summarize_children(MutableSubtree, const TSLanguage *); -void ts_subtree_balance(Subtree, /*SubtreePool *,*/ const TSLanguage *); -Subtree ts_subtree_edit(Subtree, const TSInputEdit *edit /*, SubtreePool **/); -char *ts_subtree_string(Subtree, TSSymbol, bool, const TSLanguage *, bool include_all); -void ts_subtree_print_dot_graph(Subtree, const TSLanguage *, FILE *); -Subtree ts_subtree_last_external_token(Subtree); +Subtree ts_subtree_new_leaf(TSSymbol, Length, Length, t_u32, TSStateId, bool, bool, bool, const TSLanguage *); +Subtree ts_subtree_new_error(t_i32, Length, Length, t_u32, TSStateId, const TSLanguage *); +MutableSubtree ts_subtree_new_node(TSSymbol, SubtreeArray *, t_u32, const TSLanguage *); +Subtree ts_subtree_new_error_node(SubtreeArray *, bool, const TSLanguage *); +Subtree ts_subtree_new_missing_leaf(TSSymbol, Length, t_u32, const TSLanguage *); +MutableSubtree ts_subtree_make_mut(Subtree); +void ts_subtree_retain(Subtree); +void ts_subtree_release(Subtree); +int ts_subtree_compare(Subtree, Subtree); +void ts_subtree_set_symbol(MutableSubtree *, TSSymbol, const TSLanguage *); +void ts_subtree_summarize(MutableSubtree, const Subtree *, t_u32, const TSLanguage *); +void ts_subtree_summarize_children(MutableSubtree, const TSLanguage *); +void ts_subtree_balance(Subtree, const TSLanguage *); +Subtree ts_subtree_edit(Subtree, const TSInputEdit *edit); +char *ts_subtree_string(Subtree, TSSymbol, bool, const TSLanguage *, bool include_all); +void ts_subtree_print_dot_graph(Subtree, const TSLanguage *, FILE *); +Subtree ts_subtree_last_external_token(Subtree); const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self); bool ts_subtree_external_scanner_state_eq(Subtree, Subtree); static inline TSSymbol ts_subtree_symbol(Subtree self) { - return ((self).ptr->symbol); + return ((self)->symbol); } static inline bool ts_subtree_visible(Subtree self) { - return ((self).ptr->visible); + return ((self)->visible); } static inline bool ts_subtree_named(Subtree self) { - return ((self).ptr->named); + return ((self)->named); } static inline bool ts_subtree_extra(Subtree self) { - return ((self).ptr->extra); + return ((self)->extra); } static inline bool ts_subtree_has_changes(Subtree self) { - return ((self).ptr->has_changes); + return ((self)->has_changes); } static inline bool ts_subtree_missing(Subtree self) { - return ((self).ptr->is_missing); + return ((self)->is_missing); } static inline bool ts_subtree_is_keyword(Subtree self) { - return ((self).ptr->is_keyword); + return ((self)->is_keyword); } static inline TSStateId ts_subtree_parse_state(Subtree self) { - return ((self).ptr->parse_state); + return ((self)->parse_state); } static inline t_u32 ts_subtree_lookahead_bytes(Subtree self) { - return ((self).ptr->lookahead_bytes); + return ((self)->lookahead_bytes); } // Get the size needed to store a heap-allocated subtree with the given @@ -187,35 +176,35 @@ static inline size_t ts_subtree_alloc_size(t_u32 child_count) // Get a subtree's children, which are allocated immediately before the // tree's own heap data. -#define ts_subtree_children(self) ((Subtree *)((self).ptr) - (self).ptr->child_count) +#define ts_subtree_children(self) ((Subtree *)((self)) - (self)->child_count) static inline void ts_subtree_set_extra(MutableSubtree *self, bool is_extra) { - self->ptr->extra = is_extra; + (*self)->extra = is_extra; } static inline TSSymbol ts_subtree_leaf_symbol(Subtree self) { - if (self.ptr->child_count == 0) - return self.ptr->symbol; - return self.ptr->first_leaf.symbol; + if (self->child_count == 0) + return self->symbol; + return self->first_leaf.symbol; } static inline TSStateId ts_subtree_leaf_parse_state(Subtree self) { - if (self.ptr->child_count == 0) - return self.ptr->parse_state; - return self.ptr->first_leaf.parse_state; + if (self->child_count == 0) + return self->parse_state; + return self->first_leaf.parse_state; } static inline Length ts_subtree_padding(Subtree self) { - return self.ptr->padding; + return self->padding; } static inline Length ts_subtree_size(Subtree self) { - return self.ptr->size; + return self->size; } static inline Length ts_subtree_total_size(Subtree self) @@ -230,17 +219,17 @@ static inline t_u32 ts_subtree_total_bytes(Subtree self) static inline t_u32 ts_subtree_child_count(Subtree self) { - return (self.ptr->child_count); + return (self->child_count); } static inline t_u32 ts_subtree_repeat_depth(Subtree self) { - return (self.ptr->repeat_depth); + return (self->repeat_depth); } static inline t_u32 ts_subtree_visible_descendant_count(Subtree self) { - return ((self.ptr->child_count == 0) ? 0 : self.ptr->visible_descendant_count); + return ((self->child_count == 0) ? 0 : self->visible_descendant_count); } static inline t_u32 ts_subtree_error_cost(Subtree self) @@ -248,37 +237,37 @@ static inline t_u32 ts_subtree_error_cost(Subtree self) if (ts_subtree_missing(self)) return (ERROR_COST_PER_MISSING_TREE + ERROR_COST_PER_RECOVERY); else - return (self.ptr->error_cost); + return (self->error_cost); } static inline t_i32 ts_subtree_dynamic_precedence(Subtree self) { - return ((self.ptr->child_count == 0) ? 0 : self.ptr->dynamic_precedence); + return ((self->child_count == 0) ? 0 : self->dynamic_precedence); } static inline bool ts_subtree_fragile_left(Subtree self) { - return (self.ptr->fragile_left); + return (self->fragile_left); } static inline bool ts_subtree_fragile_right(Subtree self) { - return (self.ptr->fragile_right); + return (self->fragile_right); } static inline bool ts_subtree_has_external_tokens(Subtree self) { - return (self.ptr->has_external_tokens); + return (self->has_external_tokens); } static inline bool ts_subtree_has_external_scanner_state_change(Subtree self) { - return (self.ptr->has_external_scanner_state_change); + return (self->has_external_scanner_state_change); } static inline bool ts_subtree_depends_on_column(Subtree self) { - return (self.ptr->depends_on_column); + return (self->depends_on_column); } static inline bool ts_subtree_is_error(Subtree self) @@ -293,18 +282,12 @@ static inline bool ts_subtree_is_eof(Subtree self) static inline Subtree ts_subtree_from_mut(MutableSubtree self) { - Subtree result; - - result.ptr = self.ptr; - return (result); + return (self); } static inline MutableSubtree ts_subtree_to_mut_unsafe(Subtree self) { - MutableSubtree result; - - result.ptr = (void *)self.ptr; - return (result); + return ((MutableSubtree)self); } #endif // SUBTREE_H diff --git a/parser/src/create_language.c b/parser/src/create_language.c index 58e510b3..6c3330de 100644 --- a/parser/src/create_language.c +++ b/parser/src/create_language.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/25 16:13:52 by maiboyer #+# #+# */ -/* Updated: 2024/08/04 14:12:49 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:57 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,11 @@ #include "parser/parser.h" #include "me/types.h" + +#ifdef static +# undef static +#endif + // bool lex_keywords_main(TSLexer *lexer, TSStateId state); // bool lex_normal_main(TSLexer *lexer, TSStateId state); bool tree_sitter_sh_external_scanner_scan(void *ctx, TSLexer *lexer, const bool *ret); diff --git a/parser/src/node.c b/parser/src/node.c index 3a47df1c..a0f158da 100644 --- a/parser/src/node.c +++ b/parser/src/node.c @@ -1,9 +1,9 @@ +#include "me/types.h" #include "parser/api.h" #include "parser/language.h" +#include "parser/point.h" #include "parser/subtree.h" #include "parser/tree.h" -#include "parser/point.h" -#include "me/types.h" typedef struct NodeChildIterator { @@ -20,9 +20,7 @@ typedef struct NodeChildIterator TSNode ts_node_new(const TSTree *tree, const Subtree *subtree, Length position, TSSymbol alias) { return (TSNode){ - {position.bytes, position.extent.row, position.extent.column, alias}, - subtree, - tree, + position.bytes, position.extent.row, position.extent.column, alias, subtree, tree, }; } @@ -35,17 +33,22 @@ static inline TSNode ts_node__null(void) t_u32 ts_node_start_byte(TSNode self) { - return self.context[0]; + return self.start_byte; +} + +const TSLanguage *ts_node_language(TSNode self) +{ + return self.tree->language; } TSPoint ts_node_start_point(TSNode self) { - return (TSPoint){self.context[1], self.context[2]}; + return (TSPoint){self.start_row, self.start_col}; } static inline t_u32 ts_node__alias(const TSNode *self) { - return self->context[3]; + return self->alias; } static inline Subtree ts_node__subtree(TSNode self) @@ -62,7 +65,7 @@ static inline NodeChildIterator ts_node_iterate_children(const TSNode *node) { return (NodeChildIterator){NULL_SUBTREE, node->tree, length_zero(), 0, 0, NULL}; } - const TSSymbol *alias_sequence = ts_language_alias_sequence(node->tree->language, subtree.ptr->production_id); + const TSSymbol *alias_sequence = ts_language_alias_sequence(node->tree->language, subtree->production_id); return (NodeChildIterator){ .tree = node->tree, .parent = subtree, @@ -75,12 +78,12 @@ static inline NodeChildIterator ts_node_iterate_children(const TSNode *node) static inline bool ts_node_child_iterator_done(NodeChildIterator *self) { - return self->child_index == self->parent.ptr->child_count; + return self->child_index == self->parent->child_count; } static inline bool ts_node_child_iterator_next(NodeChildIterator *self, TSNode *result) { - if (!self->parent.ptr || ts_node_child_iterator_done(self)) + if (!self->parent || ts_node_child_iterator_done(self)) return false; const Subtree *child = &ts_subtree_children(self->parent)[self->child_index]; TSSymbol alias_symbol = 0; @@ -132,11 +135,11 @@ static inline t_u32 ts_node__relevant_child_count(TSNode self, bool include_anon { if (include_anonymous) { - return tree.ptr->visible_child_count; + return tree->visible_child_count; } else { - return tree.ptr->named_child_count; + return tree->named_child_count; } } else @@ -173,6 +176,7 @@ static inline TSNode ts_node__child(TSNode self, t_u32 child_index, bool include t_u32 grandchild_count = ts_node__relevant_child_count(child, include_anonymous); if (grandchild_index < grandchild_count) { + printf("did_descend\n"); did_descend = true; result = child; child_index = grandchild_index; @@ -186,271 +190,6 @@ static inline TSNode ts_node__child(TSNode self, t_u32 child_index, bool include return ts_node__null(); } - -/* static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous) */ -/* { */ -/* Subtree self_subtree = ts_node__subtree(self); */ -/* bool self_is_empty = ts_subtree_total_bytes(self_subtree) == 0; */ -/* t_u32 target_end_byte = ts_node_end_byte(self); */ -/**/ -/* TSNode node = ts_node_parent(self); */ -/* TSNode earlier_node = ts_node__null(); */ -/* bool earlier_node_is_relevant = false; */ -/**/ -/* while (!ts_node_is_null(node)) */ -/* { */ -/* TSNode earlier_child = ts_node__null(); */ -/* bool earlier_child_is_relevant = false; */ -/* bool found_child_containing_target = false; */ -/**/ -/* TSNode child; */ -/* NodeChildIterator iterator = ts_node_iterate_children(&node); */ -/* while (ts_node_child_iterator_next(&iterator, &child)) */ -/* { */ -/* if (child.id == self.id) */ -/* break; */ -/* if (iterator.position.bytes > target_end_byte) */ -/* { */ -/* found_child_containing_target = true; */ -/* break; */ -/* } */ -/**/ -/* if (iterator.position.bytes == target_end_byte && */ -/* (!self_is_empty || ts_subtree_has_trailing_empty_descendant(ts_node__subtree(child), self_subtree))) */ -/* { */ -/* found_child_containing_target = true; */ -/* break; */ -/* } */ -/**/ -/* if (ts_node__is_relevant(child, include_anonymous)) */ -/* { */ -/* earlier_child = child; */ -/* earlier_child_is_relevant = true; */ -/* } */ -/* else if (ts_node__relevant_child_count(child, include_anonymous) > 0) */ -/* { */ -/* earlier_child = child; */ -/* earlier_child_is_relevant = false; */ -/* } */ -/* } */ -/**/ -/* if (found_child_containing_target) */ -/* { */ -/* if (!ts_node_is_null(earlier_child)) */ -/* { */ -/* earlier_node = earlier_child; */ -/* earlier_node_is_relevant = earlier_child_is_relevant; */ -/* } */ -/* node = child; */ -/* } */ -/* else if (earlier_child_is_relevant) */ -/* { */ -/* return earlier_child; */ -/* } */ -/* else if (!ts_node_is_null(earlier_child)) */ -/* { */ -/* node = earlier_child; */ -/* } */ -/* else if (earlier_node_is_relevant) */ -/* { */ -/* return earlier_node; */ -/* } */ -/* else */ -/* { */ -/* node = earlier_node; */ -/* earlier_node = ts_node__null(); */ -/* earlier_node_is_relevant = false; */ -/* } */ -/* } */ -/**/ -/* return ts_node__null(); */ -/* } */ -/**/ -/* static inline TSNode ts_node__next_sibling(TSNode self, bool include_anonymous) */ -/* { */ -/* t_u32 target_end_byte = ts_node_end_byte(self); */ -/**/ -/* TSNode node = ts_node_parent(self); */ -/* TSNode later_node = ts_node__null(); */ -/* bool later_node_is_relevant = false; */ -/**/ -/* while (!ts_node_is_null(node)) */ -/* { */ -/* TSNode later_child = ts_node__null(); */ -/* bool later_child_is_relevant = false; */ -/* TSNode child_containing_target = ts_node__null(); */ -/**/ -/* TSNode child; */ -/* NodeChildIterator iterator = ts_node_iterate_children(&node); */ -/* while (ts_node_child_iterator_next(&iterator, &child)) */ -/* { */ -/* if (iterator.position.bytes < target_end_byte) */ -/* continue; */ -/* if (ts_node_start_byte(child) <= ts_node_start_byte(self)) */ -/* { */ -/* if (ts_node__subtree(child).ptr != ts_node__subtree(self).ptr) */ -/* { */ -/* child_containing_target = child; */ -/* } */ -/* } */ -/* else if (ts_node__is_relevant(child, include_anonymous)) */ -/* { */ -/* later_child = child; */ -/* later_child_is_relevant = true; */ -/* break; */ -/* } */ -/* else if (ts_node__relevant_child_count(child, include_anonymous) > 0) */ -/* { */ -/* later_child = child; */ -/* later_child_is_relevant = false; */ -/* break; */ -/* } */ -/* } */ -/**/ -/* if (!ts_node_is_null(child_containing_target)) */ -/* { */ -/* if (!ts_node_is_null(later_child)) */ -/* { */ -/* later_node = later_child; */ -/* later_node_is_relevant = later_child_is_relevant; */ -/* } */ -/* node = child_containing_target; */ -/* } */ -/* else if (later_child_is_relevant) */ -/* { */ -/* return later_child; */ -/* } */ -/* else if (!ts_node_is_null(later_child)) */ -/* { */ -/* node = later_child; */ -/* } */ -/* else if (later_node_is_relevant) */ -/* { */ -/* return later_node; */ -/* } */ -/* else */ -/* { */ -/* node = later_node; */ -/* } */ -/* } */ -/**/ -/* return ts_node__null(); */ -/* } */ -/**/ -/* static inline TSNode ts_node__first_child_for_byte(TSNode self, t_u32 goal, bool include_anonymous) */ -/* { */ -/* TSNode node = self; */ -/* bool did_descend = true; */ -/**/ -/* while (did_descend) */ -/* { */ -/* did_descend = false; */ -/**/ -/* TSNode child; */ -/* NodeChildIterator iterator = ts_node_iterate_children(&node); */ -/* while (ts_node_child_iterator_next(&iterator, &child)) */ -/* { */ -/* if (ts_node_end_byte(child) > goal) */ -/* { */ -/* if (ts_node__is_relevant(child, include_anonymous)) */ -/* { */ -/* return child; */ -/* } */ -/* else if (ts_node_child_count(child) > 0) */ -/* { */ -/* did_descend = true; */ -/* node = child; */ -/* break; */ -/* } */ -/* } */ -/* } */ -/* } */ -/**/ -/* return ts_node__null(); */ -/* } */ -/**/ -/* static inline TSNode ts_node__descendant_for_byte_range(TSNode self, t_u32 range_start, t_u32 range_end, bool include_anonymous) */ -/* { */ -/* TSNode node = self; */ -/* TSNode last_visible_node = self; */ -/**/ -/* bool did_descend = true; */ -/* while (did_descend) */ -/* { */ -/* did_descend = false; */ -/**/ -/* TSNode child; */ -/* NodeChildIterator iterator = ts_node_iterate_children(&node); */ -/* while (ts_node_child_iterator_next(&iterator, &child)) */ -/* { */ -/* t_u32 node_end = iterator.position.bytes; */ -/**/ -/* // The end of this node must extend far enough forward to touch */ -/* // the end of the range and exceed the start of the range. */ -/* if (node_end < range_end) */ -/* continue; */ -/* if (node_end <= range_start) */ -/* continue; */ -/**/ -/* // The start of this node must extend far enough backward to */ -/* // touch the start of the range. */ -/* if (range_start < ts_node_start_byte(child)) */ -/* break; */ -/**/ -/* node = child; */ -/* if (ts_node__is_relevant(node, include_anonymous)) */ -/* { */ -/* last_visible_node = node; */ -/* } */ -/* did_descend = true; */ -/* break; */ -/* } */ -/* } */ -/**/ -/* return last_visible_node; */ -/* } */ -/**/ -/* static inline TSNode ts_node__descendant_for_point_range(TSNode self, TSPoint range_start, TSPoint range_end, bool include_anonymous) */ -/* { */ -/* TSNode node = self; */ -/* TSNode last_visible_node = self; */ -/**/ -/* bool did_descend = true; */ -/* while (did_descend) */ -/* { */ -/* did_descend = false; */ -/**/ -/* TSNode child; */ -/* NodeChildIterator iterator = ts_node_iterate_children(&node); */ -/* while (ts_node_child_iterator_next(&iterator, &child)) */ -/* { */ -/* TSPoint node_end = iterator.position.extent; */ -/**/ -/* // The end of this node must extend far enough forward to touch */ -/* // the end of the range and exceed the start of the range. */ -/* if (point_lt(node_end, range_end)) */ -/* continue; */ -/* if (point_lte(node_end, range_start)) */ -/* continue; */ -/**/ -/* // The start of this node must extend far enough backward to */ -/* // touch the start of the range. */ -/* if (point_lt(range_start, ts_node_start_point(child))) */ -/* break; */ -/**/ -/* node = child; */ -/* if (ts_node__is_relevant(node, include_anonymous)) */ -/* { */ -/* last_visible_node = node; */ -/* } */ -/* did_descend = true; */ -/* break; */ -/* } */ -/* } */ -/**/ -/* return last_visible_node; */ -/* } */ - // TSNode - public t_u32 ts_node_end_byte(TSNode self) @@ -458,11 +197,6 @@ t_u32 ts_node_end_byte(TSNode self) return ts_node_start_byte(self) + ts_subtree_size(ts_node__subtree(self)).bytes; } -TSPoint ts_node_end_point(TSNode self) -{ - return point_add(ts_node_start_point(self), ts_subtree_size(ts_node__subtree(self)).extent); -} - TSSymbol ts_node_symbol(TSNode self) { TSSymbol symbol = ts_node__alias(&self); @@ -479,11 +213,6 @@ t_const_str ts_node_type(TSNode self) return ts_language_symbol_name(self.tree->language, symbol); } -const TSLanguage *ts_node_language(TSNode self) -{ - return self.tree->language; -} - TSSymbol ts_node_grammar_symbol(TSNode self) { return ts_subtree_symbol(ts_node__subtree(self)); @@ -495,23 +224,6 @@ t_const_str ts_node_grammar_type(TSNode self) return ts_language_symbol_name(self.tree->language, symbol); } -char *ts_node_string(TSNode self) -{ - TSSymbol alias_symbol = ts_node__alias(&self); - return ts_subtree_string(ts_node__subtree(self), alias_symbol, ts_language_symbol_metadata(self.tree->language, alias_symbol).visible, - self.tree->language, false); -} - -bool ts_node_eq(TSNode self, TSNode other) -{ - return self.tree == other.tree && self.id == other.id; -} - -bool ts_node_is_null(TSNode self) -{ - return self.id == 0; -} - bool ts_node_is_extra(TSNode self) { return ts_subtree_extra(ts_node__subtree(self)); @@ -523,86 +235,6 @@ bool ts_node_is_named(TSNode self) return alias ? ts_language_symbol_metadata(self.tree->language, alias).named : ts_subtree_named(ts_node__subtree(self)); } -bool ts_node_is_missing(TSNode self) -{ - return ts_subtree_missing(ts_node__subtree(self)); -} - -bool ts_node_has_changes(TSNode self) -{ - return ts_subtree_has_changes(ts_node__subtree(self)); -} - -bool ts_node_has_error(TSNode self) -{ - return ts_subtree_error_cost(ts_node__subtree(self)) > 0; -} - -bool ts_node_is_error(TSNode self) -{ - TSSymbol symbol = ts_node_symbol(self); - return symbol == ts_builtin_sym_error; -} - -t_u32 ts_node_descendant_count(TSNode self) -{ - return ts_subtree_visible_descendant_count(ts_node__subtree(self)) + 1; -} - -TSStateId ts_node_parse_state(TSNode self) -{ - return ts_subtree_parse_state(ts_node__subtree(self)); -} - -TSStateId ts_node_next_parse_state(TSNode self) -{ - const TSLanguage *language = self.tree->language; - t_u16 state = ts_node_parse_state(self); - if (state == TS_TREE_STATE_NONE) - { - return TS_TREE_STATE_NONE; - } - t_u16 symbol = ts_node_grammar_symbol(self); - return ts_language_next_state(language, state, symbol); -} - -TSNode ts_node_parent(TSNode self) -{ - TSNode node = ts_tree_root_node(self.tree); - if (node.id == self.id) - return ts_node__null(); - - while (true) - { - TSNode next_node = ts_node_child_containing_descendant(node, self); - if (ts_node_is_null(next_node)) - break; - node = next_node; - } - - return node; -} - -TSNode ts_node_child_containing_descendant(TSNode self, TSNode subnode) -{ - t_u32 start_byte = ts_node_start_byte(subnode); - t_u32 end_byte = ts_node_end_byte(subnode); - - do - { - NodeChildIterator iter = ts_node_iterate_children(&self); - do - { - if (!ts_node_child_iterator_next(&iter, &self) || ts_node_start_byte(self) > start_byte || self.id == subnode.id) - { - return ts_node__null(); - } - } while (iter.position.bytes < end_byte || ts_node_child_count(self) == 0); - } while (!ts_node__is_relevant(self, true)); - - return self; -} - TSNode ts_node_child(TSNode self, t_u32 child_index) { return ts_node__child(self, child_index, true); @@ -613,96 +245,10 @@ TSNode ts_node_named_child(TSNode self, t_u32 child_index) return ts_node__child(self, child_index, false); } -TSNode ts_node_child_by_field_id(TSNode self, TSFieldId field_id) -{ -recur: - if (!field_id || ts_node_child_count(self) == 0) - return ts_node__null(); - - const TSFieldMapEntry *field_map, *field_map_end; - ts_language_field_map(self.tree->language, ts_node__subtree(self).ptr->production_id, &field_map, &field_map_end); - if (field_map == field_map_end) - return ts_node__null(); - - // The field mappings are sorted by their field id. Scan all - // the mappings to find the ones for the given field id. - while (field_map->field_id < field_id) - { - field_map++; - if (field_map == field_map_end) - return ts_node__null(); - } - while (field_map_end[-1].field_id > field_id) - { - field_map_end--; - if (field_map == field_map_end) - return ts_node__null(); - } - - TSNode child; - NodeChildIterator iterator = ts_node_iterate_children(&self); - while (ts_node_child_iterator_next(&iterator, &child)) - { - if (!ts_subtree_extra(ts_node__subtree(child))) - { - t_u32 index = iterator.structural_child_index - 1; - if (index < field_map->child_index) - continue; - - // Hidden nodes' fields are "inherited" by their visible parent. - if (field_map->inherited) - { - - // If this is the *last* possible child node for this field, - // then perform a tail call to avoid recursion. - if (field_map + 1 == field_map_end) - { - self = child; - goto recur; - } - - // Otherwise, descend into this child, but if it doesn't contain - // the field, continue searching subsequent children. - else - { - TSNode result = ts_node_child_by_field_id(child, field_id); - if (result.id) - return result; - field_map++; - if (field_map == field_map_end) - return ts_node__null(); - } - } - - else if (ts_node__is_relevant(child, true)) - { - return child; - } - - // If the field refers to a hidden node with visible children, - // return the first visible child. - else if (ts_node_child_count(child) > 0) - { - return ts_node_child(child, 0); - } - - // Otherwise, continue searching subsequent children. - else - { - field_map++; - if (field_map == field_map_end) - return ts_node__null(); - } - } - } - - return ts_node__null(); -} - static inline t_const_str ts_node__field_name_from_language(TSNode self, t_u32 structural_child_index) { const TSFieldMapEntry *field_map, *field_map_end; - ts_language_field_map(self.tree->language, ts_node__subtree(self).ptr->production_id, &field_map, &field_map_end); + ts_language_field_map(self.tree->language, ts_node__subtree(self)->production_id, &field_map, &field_map_end); for (; field_map != field_map_end; field_map++) { if (!field_map->inherited && field_map->child_index == structural_child_index) @@ -713,11 +259,45 @@ static inline t_const_str ts_node__field_name_from_language(TSNode self, t_u32 s return NULL; } -t_const_str ts_node_field_name_for_child(TSNode self, t_u32 child_index) +static inline TSFieldId ts_node__field_id_from_language(TSNode self, t_u32 structural_child_index) { - TSNode result = self; - bool did_descend = true; - t_const_str inherited_field_name = NULL; + const TSFieldMapEntry *field_map, *field_map_end; + ts_language_field_map(self.tree->language, ts_node__subtree(self)->production_id, &field_map, &field_map_end); + for (; field_map != field_map_end; field_map++) + { + if (!field_map->inherited && field_map->child_index == structural_child_index) + return field_map->field_id; + } + return 0; +} + +t_u32 ts_node_child_count(TSNode self) +{ + Subtree tree = ts_node__subtree(self); + if (ts_subtree_child_count(tree) > 0) + { + return tree->visible_child_count; + } + else + { + return 0; + } +} + +t_u32 ts_node_named_child_count(TSNode self) +{ + Subtree tree = ts_node__subtree(self); + if (ts_subtree_child_count(tree) > 0) + return tree->named_child_count; + else + return 0; +} + +TSFieldId ts_node_field_id_for_child(TSNode self, t_u32 child_index) +{ + TSNode result = self; + bool did_descend = true; + TSFieldId inherited_field_id = 0; while (did_descend) { @@ -733,13 +313,11 @@ t_const_str ts_node_field_name_for_child(TSNode self, t_u32 child_index) if (index == child_index) { if (ts_node_is_extra(child)) - { - return NULL; - } - t_const_str field_name = ts_node__field_name_from_language(result, iterator.structural_child_index - 1); - if (field_name) - return field_name; - return inherited_field_name; + return 0; + TSFieldId field_id = ts_node__field_id_from_language(result, iterator.structural_child_index - 1); + if (field_id) + return field_id; + return inherited_field_id; } index++; } @@ -749,10 +327,9 @@ t_const_str ts_node_field_name_for_child(TSNode self, t_u32 child_index) t_u32 grandchild_count = ts_node__relevant_child_count(child, true); if (grandchild_index < grandchild_count) { - t_const_str field_name = ts_node__field_name_from_language(result, iterator.structural_child_index - 1); - if (field_name) - inherited_field_name = field_name; - + TSFieldId field_id = ts_node__field_id_from_language(result, iterator.structural_child_index - 1); + if (field_id) + inherited_field_id = field_id; did_descend = true; result = child; child_index = grandchild_index; @@ -762,46 +339,5 @@ t_const_str ts_node_field_name_for_child(TSNode self, t_u32 child_index) } } } - - return NULL; -} - -TSNode ts_node_child_by_field_name(TSNode self, t_const_str name, t_u32 name_length) -{ - TSFieldId field_id = ts_language_field_id_for_name(self.tree->language, name, name_length); - return ts_node_child_by_field_id(self, field_id); -} - -t_u32 ts_node_child_count(TSNode self) -{ - Subtree tree = ts_node__subtree(self); - if (ts_subtree_child_count(tree) > 0) - { - return tree.ptr->visible_child_count; - } - else - { - return 0; - } -} - -t_u32 ts_node_named_child_count(TSNode self) -{ - Subtree tree = ts_node__subtree(self); - if (ts_subtree_child_count(tree) > 0) - { - return tree.ptr->named_child_count; - } - else - { - return 0; - } -} - -TSSymbol ts_node_field_id_for_child(TSNode self, t_u32 child_index) -{ - t_const_str name = ts_node_field_name_for_child(self, child_index); - if (name == NULL) - return (0); - return (ts_language_field_id_for_name(ts_node_language(self), name, strlen(name))); + return 0; } diff --git a/parser/src/parser.c b/parser/src/parser.c index a6bde1f9..bc2d2466 100644 --- a/parser/src/parser.c +++ b/parser/src/parser.c @@ -235,7 +235,7 @@ static ErrorStatus ts_parser__version_status(TSParser *self, StackVersion versio static bool ts_parser__better_version_exists(TSParser *self, StackVersion version, bool is_in_error, t_u32 cost) { - if (self->finished_tree.ptr && ts_subtree_error_cost(self->finished_tree) <= cost) + if (self->finished_tree && ts_subtree_error_cost(self->finished_tree) <= cost) { return true; } @@ -314,10 +314,10 @@ static void ts_parser__external_scanner_deserialize(TSParser *self, Subtree exte { const t_u8 *data = NULL; t_u32 length = 0; - if (external_token.ptr) + if (external_token) { - data = ts_external_scanner_state_data(&external_token.ptr->external_scanner_state); - length = external_token.ptr->external_scanner_state.length; + data = ts_external_scanner_state_data(&external_token->external_scanner_state); + length = external_token->external_scanner_state.length; } self->language->external_scanner.deserialize(self->external_scanner_payload, data, length); @@ -484,8 +484,8 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, TSStateId pa if (found_external_token) { MutableSubtree mut_result = ts_subtree_to_mut_unsafe(result); - ts_external_scanner_state_init(&mut_result.ptr->external_scanner_state, self->lexer.debug_buffer, external_scanner_state_len); - mut_result.ptr->has_external_scanner_state_change = external_scanner_state_changed; + ts_external_scanner_state_init(&mut_result->external_scanner_state, self->lexer.debug_buffer, external_scanner_state_len); + mut_result->has_external_scanner_state_change = external_scanner_state_changed; } } @@ -500,9 +500,9 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, TSStateId pa static bool ts_parser__select_tree(TSParser *self, Subtree left, Subtree right) { (void)(self); - if (!left.ptr) + if (!left) return true; - if (!right.ptr) + if (!right) return false; if (ts_subtree_error_cost(right) < ts_subtree_error_cost(left)) @@ -660,19 +660,19 @@ static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, TSSy TSStateId next_state = ts_language_next_state(self->language, state, symbol); if (end_of_non_terminal_extra && next_state == state) { - parent.ptr->extra = true; + parent->extra = true; } if (is_fragile || pop.size > 1 || initial_version_count > 1) { - parent.ptr->fragile_left = true; - parent.ptr->fragile_right = true; - parent.ptr->parse_state = TS_TREE_STATE_NONE; + parent->fragile_left = true; + parent->fragile_right = true; + parent->parse_state = TS_TREE_STATE_NONE; } else { - parent.ptr->parse_state = state; + parent->parse_state = state; } - parent.ptr->dynamic_precedence += dynamic_precedence; + parent->dynamic_precedence += dynamic_precedence; // Push the parent node onto the stack, along with any extra tokens that // were previously on top of the stack. @@ -721,16 +721,16 @@ static void ts_parser__accept(TSParser *self, StackVersion version, Subtree look ts_subtree_retain(children[k]); } array_splice(&trees, j, 1, child_count, children); - root = ts_subtree_from_mut(ts_subtree_new_node(ts_subtree_symbol(tree), &trees, tree.ptr->production_id, self->language)); + root = ts_subtree_from_mut(ts_subtree_new_node(ts_subtree_symbol(tree), &trees, tree->production_id, self->language)); ts_subtree_release(/*&self->tree_pool, */ tree); break; } } - assert(root.ptr); + assert(root); self->accept_count++; - if (self->finished_tree.ptr) + if (self->finished_tree) { if (ts_parser__select_tree(self, self->finished_tree, root)) { @@ -1192,7 +1192,7 @@ static bool ts_parser__advance(TSParser *self, StackVersion version, bool allow_ if (self->has_scanner_error) return false; - if (lookahead.ptr) + if (lookahead) { ts_language_table_entry(self->language, state, ts_subtree_symbol(lookahead), &table_entry); } @@ -1245,7 +1245,7 @@ static bool ts_parser__advance(TSParser *self, StackVersion version, bool allow_ case TSParseActionTypeReduce: { bool is_fragile = table_entry.action_count > 1; - bool end_of_non_terminal_extra = lookahead.ptr == NULL; + bool end_of_non_terminal_extra = lookahead == NULL; LOG("reduce sym:%s, child_count:%u", SYM_NAME(action.reduce.symbol), action.reduce.child_count); StackVersion reduction_version = ts_parser__reduce(self, version, action.reduce.symbol, action.reduce.child_count, action.reduce.dynamic_precedence, @@ -1285,7 +1285,7 @@ static bool ts_parser__advance(TSParser *self, StackVersion version, bool allow_ // regardless of the lookahead node. After performing that reduction, // (and completing the non-terminal extra rule) run the lexer again based // on the current parse state. - if (!lookahead.ptr) + if (!lookahead) { needs_lex = true; } @@ -1299,7 +1299,7 @@ static bool ts_parser__advance(TSParser *self, StackVersion version, bool allow_ // A non-terminal extra rule was reduced and merged into an existing // stack version. This version can be discarded. - if (!lookahead.ptr) + if (!lookahead) { ts_stack_halt(self->stack, version); return true; @@ -1546,7 +1546,7 @@ void ts_parser_reset(TSParser *self) ts_parser__external_scanner_destroy(self); ts_lexer_reset(&self->lexer, length_zero()); ts_stack_clear(self->stack); - if (self->finished_tree.ptr) + if (self->finished_tree) { ts_subtree_release(/*&self->tree_pool,*/ self->finished_tree); self->finished_tree = NULL_SUBTREE; @@ -1617,7 +1617,7 @@ TSTree *ts_parser_parse(TSParser *self, TSInput input) // then terminate parsing. Clear the parse stack to remove any extra references to subtrees // within the finished tree, ensuring that these subtrees can be safely mutated in-place // for rebalancing. - if (self->finished_tree.ptr && ts_subtree_error_cost(self->finished_tree) < min_error_cost) + if (self->finished_tree && ts_subtree_error_cost(self->finished_tree) < min_error_cost) { ts_stack_clear(self->stack); break; @@ -1625,7 +1625,7 @@ TSTree *ts_parser_parse(TSParser *self, TSInput input) } while (version_count != 0); - assert(self->finished_tree.ptr); + assert(self->finished_tree); ts_subtree_balance(self->finished_tree, /*&self->tree_pool,*/ self->language); LOG("done"); LOG_TREE(self->finished_tree); diff --git a/parser/src/stack.c b/parser/src/stack.c index affad2f7..cde7f22e 100644 --- a/parser/src/stack.c +++ b/parser/src/stack.c @@ -34,24 +34,27 @@ struct StackNode int dynamic_precedence; }; -typedef struct StackIterator +typedef struct StackIterator StackIterator; +struct StackIterator { StackNode *node; SubtreeArray subtrees; t_u32 subtree_count; bool is_pending; -} StackIterator; +}; typedef Array(StackNode *) StackNodeArray; -typedef enum StackStatus +typedef enum StackStatus StackStatus; +enum StackStatus { StackStatusActive, StackStatusPaused, StackStatusHalted, -} StackStatus; +}; -typedef struct StackHead +typedef struct StackHead StackHead; +struct StackHead { StackNode *node; StackSummary *summary; @@ -59,16 +62,14 @@ typedef struct StackHead Subtree last_external_token; Subtree lookahead_when_paused; StackStatus status; -} StackHead; +}; struct Stack { Array(StackHead) heads; StackSliceArray slices; Array(StackIterator) iterators; - StackNodeArray node_pool; - StackNode *base_node; - /* SubtreePool *subtree_pool; */ + StackNode *base_node; }; typedef t_u32 StackAction; @@ -90,7 +91,7 @@ static void stack_node_retain(StackNode *self) assert(self->ref_count != 0); } -static void stack_node_release(StackNode *self /*, StackNodeArray *pool */ /* , SubtreePool *subtree_pool */) +static void stack_node_release(StackNode *self) { recur: assert(self->ref_count != 0); @@ -104,13 +105,13 @@ recur: for (t_u32 i = self->link_count - 1; i > 0; i--) { StackLink link = self->links[i]; - if (link.subtree.ptr) - ts_subtree_release(/*subtree_pool, */ link.subtree); - stack_node_release(link.node /*, pool*/ /* , subtree_pool */); + if (link.subtree) + ts_subtree_release(link.subtree); + stack_node_release(link.node); } StackLink link = self->links[0]; - if (link.subtree.ptr) - ts_subtree_release(/*subtree_pool, */ link.subtree); + if (link.subtree) + ts_subtree_release(link.subtree); first_predecessor = self->links[0].node; } @@ -140,9 +141,9 @@ static t_u32 stack__subtree_node_count(Subtree subtree) return count; } -static StackNode *stack_node_new(StackNode *previous_node, Subtree subtree, bool is_pending, TSStateId state /*, StackNodeArray *pool */) +static StackNode *stack_node_new(StackNode *previous_node, Subtree subtree, bool is_pending, TSStateId state) { - StackNode *node = /* pool->size > 0 ? array_pop(pool) : */ mem_alloc(sizeof(StackNode)); + StackNode *node = mem_alloc(sizeof(StackNode)); *node = (StackNode){.ref_count = 1, .link_count = 0, .state = state}; if (previous_node) @@ -159,7 +160,7 @@ static StackNode *stack_node_new(StackNode *previous_node, Subtree subtree, bool node->dynamic_precedence = previous_node->dynamic_precedence; node->node_count = previous_node->node_count; - if (subtree.ptr) + if (subtree) { node->error_cost += ts_subtree_error_cost(subtree); node->position = length_add(node->position, ts_subtree_total_size(subtree)); @@ -178,9 +179,9 @@ static StackNode *stack_node_new(StackNode *previous_node, Subtree subtree, bool static bool stack__subtree_is_equivalent(Subtree left, Subtree right) { - if (left.ptr == right.ptr) + if (left == right) return true; - if (!left.ptr || !right.ptr) + if (!left || !right) return false; // Symbols must match @@ -196,7 +197,7 @@ static bool stack__subtree_is_equivalent(Subtree left, Subtree right) ts_subtree_extra(left) == ts_subtree_extra(right) && ts_subtree_external_scanner_state_eq(left, right)); } -static void stack_node_add_link(StackNode *self, StackLink link /* , SubtreePool *subtree_pool */) +static void stack_node_add_link(StackNode *self, StackLink link) { if (link.node == self) return; @@ -228,10 +229,10 @@ static void stack_node_add_link(StackNode *self, StackLink link /* , SubtreePool { for (int j = 0; j < link.node->link_count; j++) { - stack_node_add_link(existing_link->node, link.node->links[j] /* , subtree_pool */); + stack_node_add_link(existing_link->node, link.node->links[j]); } t_i32 dynamic_precedence = link.node->dynamic_precedence; - if (link.subtree.ptr) + if (link.subtree) { dynamic_precedence += ts_subtree_dynamic_precedence(link.subtree); } @@ -252,7 +253,7 @@ static void stack_node_add_link(StackNode *self, StackLink link /* , SubtreePool int dynamic_precedence = link.node->dynamic_precedence; self->links[self->link_count++] = link; - if (link.subtree.ptr) + if (link.subtree) { ts_subtree_retain(link.subtree); node_count += stack__subtree_node_count(link.subtree); @@ -265,24 +266,24 @@ static void stack_node_add_link(StackNode *self, StackLink link /* , SubtreePool self->dynamic_precedence = dynamic_precedence; } -static void stack_head_delete(StackHead *self /*, StackNodeArray *pool */ /* , SubtreePool *subtree_pool */) +static void stack_head_delete(StackHead *self) { if (self->node) { - if (self->last_external_token.ptr) + if (self->last_external_token) { - ts_subtree_release(/*subtree_pool, */ self->last_external_token); + ts_subtree_release(self->last_external_token); } - if (self->lookahead_when_paused.ptr) + if (self->lookahead_when_paused) { - ts_subtree_release(/*subtree_pool, */ self->lookahead_when_paused); + ts_subtree_release(self->lookahead_when_paused); } if (self->summary) { array_delete(self->summary); mem_free(self->summary); } - stack_node_release(self->node /* , pool */ /* , subtree_pool */); + stack_node_release(self->node); } } @@ -297,7 +298,7 @@ static StackVersion ts_stack__add_version(Stack *self, StackVersion original_ver }; array_push(&self->heads, head); stack_node_retain(node); - if (head.last_external_token.ptr) + if (head.last_external_token) ts_subtree_retain(head.last_external_token); return (StackVersion)(self->heads.size - 1); } @@ -368,7 +369,7 @@ static StackSliceArray stack__iter(Stack *self, StackVersion version, StackCallb { if (!should_pop) { - ts_subtree_array_delete(/*self->subtree_pool, */ &iterator->subtrees); + ts_subtree_array_delete(&iterator->subtrees); } array_erase(&self->iterators, i); i--, size--; @@ -396,7 +397,7 @@ static StackSliceArray stack__iter(Stack *self, StackVersion version, StackCallb } next_iterator->node = link.node; - if (link.subtree.ptr) + if (link.subtree) { if (include_subtrees) { @@ -425,7 +426,7 @@ static StackSliceArray stack__iter(Stack *self, StackVersion version, StackCallb return self->slices; } -Stack *ts_stack_new(/* SubtreePool *subtree_pool */) +Stack *ts_stack_new(void) { Stack *self; @@ -434,14 +435,12 @@ Stack *ts_stack_new(/* SubtreePool *subtree_pool */) array_init(&self->heads); array_init(&self->slices); array_init(&self->iterators); - array_init(&self->node_pool); array_reserve(&self->heads, 4); array_reserve(&self->slices, 4); array_reserve(&self->iterators, 4); - self->node_pool = (StackNodeArray)array_new(); /* self->subtree_pool = subtree_pool; */ - self->base_node = stack_node_new(NULL, NULL_SUBTREE, false, 1 /* , &self->node_pool */); + self->base_node = stack_node_new(NULL, NULL_SUBTREE, false, 1); ts_stack_clear(self); return self; @@ -453,18 +452,12 @@ void ts_stack_delete(Stack *self) array_delete(&self->slices); if (self->iterators.contents) array_delete(&self->iterators); - stack_node_release(self->base_node /* , &self->node_pool */ /* , self->subtree_pool */); + stack_node_release(self->base_node); for (t_u32 i = 0; i < self->heads.size; i++) { - stack_head_delete(&self->heads.contents[i] /* , &self->node_pool */ /* , self->subtree_pool */); + stack_head_delete(&self->heads.contents[i]); } array_clear(&self->heads); - if (self->node_pool.contents) - { - for (t_u32 i = 0; i < self->node_pool.size; i++) - mem_free(self->node_pool.contents[i]); - array_delete(&self->node_pool); - } array_delete(&self->heads); mem_free(self); } @@ -492,9 +485,9 @@ Subtree ts_stack_last_external_token(const Stack *self, StackVersion version) void ts_stack_set_last_external_token(Stack *self, StackVersion version, Subtree token) { StackHead *head = array_get(&self->heads, version); - if (token.ptr) + if (token) ts_subtree_retain(token); - if (head->last_external_token.ptr) + if (head->last_external_token) ts_subtree_release(/*self->subtree_pool, */ head->last_external_token); head->last_external_token = token; } @@ -503,7 +496,7 @@ t_u32 ts_stack_error_cost(const Stack *self, StackVersion version) { StackHead *head = array_get(&self->heads, version); t_u32 result = head->node->error_cost; - if (head->status == StackStatusPaused || (head->node->state == ERROR_STATE && !head->node->links[0].subtree.ptr)) + if (head->status == StackStatusPaused || (head->node->state == ERROR_STATE && !head->node->links[0].subtree)) { result += ERROR_COST_PER_RECOVERY; } @@ -523,8 +516,8 @@ t_u32 ts_stack_node_count_since_error(const Stack *self, StackVersion version) void ts_stack_push(Stack *self, StackVersion version, Subtree subtree, bool pending, TSStateId state) { StackHead *head = array_get(&self->heads, version); - StackNode *new_node = stack_node_new(head->node, subtree, pending, state /* , &self->node_pool */); - if (!subtree.ptr) + StackNode *new_node = stack_node_new(head->node, subtree, pending, state); + if (!subtree) head->node_count_at_last_error = new_node->node_count; head->node = new_node; } @@ -604,7 +597,7 @@ SubtreeArray ts_stack_pop_error(Stack *self, StackVersion version) StackNode *node = array_get(&self->heads, version)->node; for (t_u32 i = 0; i < node->link_count; i++) { - if (node->links[i].subtree.ptr && ts_subtree_is_error(node->links[i].subtree)) + if (node->links[i].subtree && ts_subtree_is_error(node->links[i].subtree)) { bool found_error = false; StackSliceArray pop = stack__iter(self, version, pop_error_callback, &found_error, 1); @@ -695,7 +688,7 @@ bool ts_stack_has_advanced_since_error(const Stack *self, StackVersion version) if (node->link_count > 0) { Subtree subtree = node->links[0].subtree; - if (subtree.ptr) + if (subtree) { if (ts_subtree_total_bytes(subtree) > 0) { @@ -715,7 +708,7 @@ bool ts_stack_has_advanced_since_error(const Stack *self, StackVersion version) void ts_stack_remove_version(Stack *self, StackVersion version) { - stack_head_delete(array_get(&self->heads, version) /* , &self->node_pool */ /* , self->subtree_pool */); + stack_head_delete(array_get(&self->heads, version)); array_erase(&self->heads, version); } @@ -732,7 +725,7 @@ void ts_stack_renumber_version(Stack *self, StackVersion v1, StackVersion v2) source_head->summary = target_head->summary; target_head->summary = NULL; } - stack_head_delete(target_head /* , &self->node_pool */ /* , self->subtree_pool */); + stack_head_delete(target_head); *target_head = *source_head; array_erase(&self->heads, v1); } @@ -750,7 +743,7 @@ StackVersion ts_stack_copy_version(Stack *self, StackVersion version) array_push(&self->heads, self->heads.contents[version]); StackHead *head = array_back(&self->heads); stack_node_retain(head->node); - if (head->last_external_token.ptr) + if (head->last_external_token) ts_subtree_retain(head->last_external_token); head->summary = NULL; return self->heads.size - 1; @@ -764,7 +757,7 @@ bool ts_stack_merge(Stack *self, StackVersion version1, StackVersion version2) StackHead *head2 = &self->heads.contents[version2]; for (t_u32 i = 0; i < head2->node->link_count; i++) { - stack_node_add_link(head1->node, head2->node->links[i] /* , self->subtree_pool */); + stack_node_add_link(head1->node, head2->node->links[i]); } if (head1->node->state == ERROR_STATE) { @@ -826,7 +819,7 @@ void ts_stack_clear(Stack *self) stack_node_retain(self->base_node); for (t_u32 i = 0; i < self->heads.size; i++) { - stack_head_delete(&self->heads.contents[i] /* , &self->node_pool */ /* , self->subtree_pool */); + stack_head_delete(&self->heads.contents[i]); } array_clear(&self->heads); array_push(&self->heads, ((StackHead){ diff --git a/parser/src/subtree.c b/parser/src/subtree.c index 3a92e77b..179ef683 100644 --- a/parser/src/subtree.c +++ b/parser/src/subtree.c @@ -130,7 +130,7 @@ void ts_subtree_array_reverse(SubtreeArray *self) /* if (self->free_trees.contents) */ /* { */ /* for (t_u32 i = 0; i < self->free_trees.size; i++) */ -/* mem_free(self->free_trees.contents[i].ptr); */ +/* mem_free(self->free_trees.contents[i]); */ /* array_delete(&self->free_trees); */ /* } */ /* if (self->tree_stack.contents) */ @@ -170,7 +170,7 @@ Subtree ts_subtree_new_leaf(TSSymbol symbol, Length padding, Length size, t_u32 .is_missing = false, .is_keyword = is_keyword, {{.first_leaf = {.symbol = 0, .parse_state = 0}}}}; - return (Subtree){.ptr = data}; + return (Subtree)data; } } @@ -178,9 +178,9 @@ void ts_subtree_set_symbol(MutableSubtree *self, TSSymbol symbol, const TSLangua { TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol); { - self->ptr->symbol = symbol; - self->ptr->named = metadata.named; - self->ptr->visible = metadata.visible; + (*self)->symbol = symbol; + (*self)->named = metadata.named; + (*self)->visible = metadata.visible; } } @@ -189,7 +189,7 @@ Subtree ts_subtree_new_error(/*SubtreePool *pool,*/ t_i32 lookahead_char, Length { Subtree result = ts_subtree_new_leaf(/*pool,*/ ts_builtin_sym_error, padding, size, bytes_scanned, parse_state, false, false, false, language); - SubtreeHeapData *data = (SubtreeHeapData *)result.ptr; + SubtreeHeapData *data = (SubtreeHeapData *)result; data->fragile_left = true; data->fragile_right = true; data->lookahead_char = lookahead_char; @@ -199,24 +199,24 @@ Subtree ts_subtree_new_error(/*SubtreePool *pool,*/ t_i32 lookahead_char, Length // Clone a subtree. MutableSubtree ts_subtree_clone(Subtree self) { - size_t alloc_size = ts_subtree_alloc_size(self.ptr->child_count); + size_t alloc_size = ts_subtree_alloc_size(self->child_count); Subtree *new_children = mem_alloc(alloc_size); Subtree *old_children = ts_subtree_children(self); mem_copy(new_children, old_children, alloc_size); - SubtreeHeapData *result = (SubtreeHeapData *)&new_children[self.ptr->child_count]; - if (self.ptr->child_count > 0) + SubtreeHeapData *result = (SubtreeHeapData *)&new_children[self->child_count]; + if (self->child_count > 0) { - for (t_u32 i = 0; i < self.ptr->child_count; i++) + for (t_u32 i = 0; i < self->child_count; i++) { ts_subtree_retain(new_children[i]); } } - else if (self.ptr->has_external_tokens) + else if (self->has_external_tokens) { - result->external_scanner_state = ts_external_scanner_state_copy(&self.ptr->external_scanner_state); + result->external_scanner_state = ts_external_scanner_state_copy(&self->external_scanner_state); } result->ref_count = 1; - return (MutableSubtree){.ptr = result}; + return (MutableSubtree)result; } // Get mutable version of a subtree. @@ -226,7 +226,7 @@ MutableSubtree ts_subtree_clone(Subtree self) // perform a copy. MutableSubtree ts_subtree_make_mut(/*SubtreePool *pool,*/ Subtree self) { - if (self.ptr->ref_count == 1) + if (self->ref_count == 1) return ts_subtree_to_mut_unsafe(self); MutableSubtree result = ts_subtree_clone(self); ts_subtree_release(/*pool, */ self); @@ -238,23 +238,23 @@ static void ts_subtree__compress(MutableSubtree self, t_u32 count, const TSLangu t_u32 initial_stack_size = stack->size; MutableSubtree tree = self; - TSSymbol symbol = tree.ptr->symbol; + TSSymbol symbol = tree->symbol; for (t_u32 i = 0; i < count; i++) { - if (tree.ptr->ref_count > 1 || tree.ptr->child_count < 2) + if (tree->ref_count > 1 || tree->child_count < 2) break; MutableSubtree child = ts_subtree_to_mut_unsafe(ts_subtree_children(tree)[0]); - if (child.ptr->child_count < 2 || child.ptr->ref_count > 1 || child.ptr->symbol != symbol) + if (child->child_count < 2 || child->ref_count > 1 || child->symbol != symbol) break; MutableSubtree grandchild = ts_subtree_to_mut_unsafe(ts_subtree_children(child)[0]); - if (grandchild.ptr->child_count < 2 || grandchild.ptr->ref_count > 1 || grandchild.ptr->symbol != symbol) + if (grandchild->child_count < 2 || grandchild->ref_count > 1 || grandchild->symbol != symbol) break; ts_subtree_children(tree)[0] = ts_subtree_from_mut(grandchild); - ts_subtree_children(child)[0] = ts_subtree_children(grandchild)[grandchild.ptr->child_count - 1]; - ts_subtree_children(grandchild)[grandchild.ptr->child_count - 1] = ts_subtree_from_mut(child); + ts_subtree_children(child)[0] = ts_subtree_children(grandchild)[grandchild->child_count - 1]; + ts_subtree_children(grandchild)[grandchild->child_count - 1] = ts_subtree_from_mut(child); array_push(stack, tree); tree = grandchild; } @@ -263,7 +263,7 @@ static void ts_subtree__compress(MutableSubtree self, t_u32 count, const TSLangu { tree = array_pop(stack); MutableSubtree child = ts_subtree_to_mut_unsafe(ts_subtree_children(tree)[0]); - MutableSubtree grandchild = ts_subtree_to_mut_unsafe(ts_subtree_children(child)[child.ptr->child_count - 1]); + MutableSubtree grandchild = ts_subtree_to_mut_unsafe(ts_subtree_children(child)[child->child_count - 1]); ts_subtree_summarize_children(grandchild, language); ts_subtree_summarize_children(child, language); ts_subtree_summarize_children(tree, language); @@ -278,7 +278,7 @@ void ts_subtree_balance(Subtree self, const TSLanguage *language) MutableSubtreeArray balance_stack = array_new(); array_clear(&balance_stack); - if (ts_subtree_child_count(self) > 0 && self.ptr->ref_count == 1) + if (ts_subtree_child_count(self) > 0 && self->ref_count == 1) { array_push(&balance_stack, ts_subtree_to_mut_unsafe(self)); } @@ -287,10 +287,10 @@ void ts_subtree_balance(Subtree self, const TSLanguage *language) { MutableSubtree tree = array_pop(&balance_stack); - if (tree.ptr->repeat_depth > 0) + if (tree->repeat_depth > 0) { Subtree child1 = ts_subtree_children(tree)[0]; - Subtree child2 = ts_subtree_children(tree)[tree.ptr->child_count - 1]; + Subtree child2 = ts_subtree_children(tree)[tree->child_count - 1]; long repeat_delta = (long)ts_subtree_repeat_depth(child1) - (long)ts_subtree_repeat_depth(child2); if (repeat_delta > 0) { @@ -303,10 +303,10 @@ void ts_subtree_balance(Subtree self, const TSLanguage *language) } } - for (t_u32 i = 0; i < tree.ptr->child_count; i++) + for (t_u32 i = 0; i < tree->child_count; i++) { Subtree child = ts_subtree_children(tree)[i]; - if (ts_subtree_child_count(child) > 0 && child.ptr->ref_count == 1) + if (ts_subtree_child_count(child) > 0 && child->ref_count == 1) { array_push(&balance_stack, ts_subtree_to_mut_unsafe(child)); } @@ -318,46 +318,46 @@ void ts_subtree_balance(Subtree self, const TSLanguage *language) // Assign all of the node's properties that depend on its children. void ts_subtree_summarize_children(MutableSubtree self, const TSLanguage *language) { - self.ptr->named_child_count = 0; - self.ptr->visible_child_count = 0; - self.ptr->error_cost = 0; - self.ptr->repeat_depth = 0; - self.ptr->visible_descendant_count = 0; - self.ptr->has_external_tokens = false; - self.ptr->depends_on_column = false; - self.ptr->has_external_scanner_state_change = false; - self.ptr->dynamic_precedence = 0; + self->named_child_count = 0; + self->visible_child_count = 0; + self->error_cost = 0; + self->repeat_depth = 0; + self->visible_descendant_count = 0; + self->has_external_tokens = false; + self->depends_on_column = false; + self->has_external_scanner_state_change = false; + self->dynamic_precedence = 0; t_u32 structural_index = 0; - const TSSymbol *alias_sequence = ts_language_alias_sequence(language, self.ptr->production_id); + const TSSymbol *alias_sequence = ts_language_alias_sequence(language, self->production_id); t_u32 lookahead_end_byte = 0; const Subtree *children = ts_subtree_children(self); - for (t_u32 i = 0; i < self.ptr->child_count; i++) + for (t_u32 i = 0; i < self->child_count; i++) { Subtree child = children[i]; - if (self.ptr->size.extent.row == 0 && ts_subtree_depends_on_column(child)) + if (self->size.extent.row == 0 && ts_subtree_depends_on_column(child)) { - self.ptr->depends_on_column = true; + self->depends_on_column = true; } if (ts_subtree_has_external_scanner_state_change(child)) { - self.ptr->has_external_scanner_state_change = true; + self->has_external_scanner_state_change = true; } if (i == 0) { - self.ptr->padding = ts_subtree_padding(child); - self.ptr->size = ts_subtree_size(child); + self->padding = ts_subtree_padding(child); + self->size = ts_subtree_size(child); } else { - self.ptr->size = length_add(self.ptr->size, ts_subtree_total_size(child)); + self->size = length_add(self->size, ts_subtree_total_size(child)); } - t_u32 child_lookahead_end_byte = self.ptr->padding.bytes + self.ptr->size.bytes + ts_subtree_lookahead_bytes(child); + t_u32 child_lookahead_end_byte = self->padding.bytes + self->size.bytes + ts_subtree_lookahead_bytes(child); if (child_lookahead_end_byte > lookahead_end_byte) { lookahead_end_byte = child_lookahead_end_byte; @@ -365,93 +365,93 @@ void ts_subtree_summarize_children(MutableSubtree self, const TSLanguage *langua if (ts_subtree_symbol(child) != ts_builtin_sym_error_repeat) { - self.ptr->error_cost += ts_subtree_error_cost(child); + self->error_cost += ts_subtree_error_cost(child); } t_u32 grandchild_count = ts_subtree_child_count(child); - if (self.ptr->symbol == ts_builtin_sym_error || self.ptr->symbol == ts_builtin_sym_error_repeat) + if (self->symbol == ts_builtin_sym_error || self->symbol == ts_builtin_sym_error_repeat) { if (!ts_subtree_extra(child) && !(ts_subtree_is_error(child) && grandchild_count == 0)) { if (ts_subtree_visible(child)) { - self.ptr->error_cost += ERROR_COST_PER_SKIPPED_TREE; + self->error_cost += ERROR_COST_PER_SKIPPED_TREE; } else if (grandchild_count > 0) { - self.ptr->error_cost += ERROR_COST_PER_SKIPPED_TREE * child.ptr->visible_child_count; + self->error_cost += ERROR_COST_PER_SKIPPED_TREE * child->visible_child_count; } } } - self.ptr->dynamic_precedence += ts_subtree_dynamic_precedence(child); - self.ptr->visible_descendant_count += ts_subtree_visible_descendant_count(child); + self->dynamic_precedence += ts_subtree_dynamic_precedence(child); + self->visible_descendant_count += ts_subtree_visible_descendant_count(child); if (alias_sequence && alias_sequence[structural_index] != 0 && !ts_subtree_extra(child)) { - self.ptr->visible_descendant_count++; - self.ptr->visible_child_count++; + self->visible_descendant_count++; + self->visible_child_count++; if (ts_language_symbol_metadata(language, alias_sequence[structural_index]).named) { - self.ptr->named_child_count++; + self->named_child_count++; } } else if (ts_subtree_visible(child)) { - self.ptr->visible_descendant_count++; - self.ptr->visible_child_count++; + self->visible_descendant_count++; + self->visible_child_count++; if (ts_subtree_named(child)) - self.ptr->named_child_count++; + self->named_child_count++; } else if (grandchild_count > 0) { - self.ptr->visible_child_count += child.ptr->visible_child_count; - self.ptr->named_child_count += child.ptr->named_child_count; + self->visible_child_count += child->visible_child_count; + self->named_child_count += child->named_child_count; } if (ts_subtree_has_external_tokens(child)) - self.ptr->has_external_tokens = true; + self->has_external_tokens = true; if (ts_subtree_is_error(child)) { - self.ptr->fragile_left = self.ptr->fragile_right = true; - self.ptr->parse_state = TS_TREE_STATE_NONE; + self->fragile_left = self->fragile_right = true; + self->parse_state = TS_TREE_STATE_NONE; } if (!ts_subtree_extra(child)) structural_index++; } - self.ptr->lookahead_bytes = lookahead_end_byte - self.ptr->size.bytes - self.ptr->padding.bytes; + self->lookahead_bytes = lookahead_end_byte - self->size.bytes - self->padding.bytes; - if (self.ptr->symbol == ts_builtin_sym_error || self.ptr->symbol == ts_builtin_sym_error_repeat) + if (self->symbol == ts_builtin_sym_error || self->symbol == ts_builtin_sym_error_repeat) { - self.ptr->error_cost += ERROR_COST_PER_RECOVERY + ERROR_COST_PER_SKIPPED_CHAR * self.ptr->size.bytes + - ERROR_COST_PER_SKIPPED_LINE * self.ptr->size.extent.row; + self->error_cost += ERROR_COST_PER_RECOVERY + ERROR_COST_PER_SKIPPED_CHAR * self->size.bytes + + ERROR_COST_PER_SKIPPED_LINE * self->size.extent.row; } - if (self.ptr->child_count > 0) + if (self->child_count > 0) { Subtree first_child = children[0]; - Subtree last_child = children[self.ptr->child_count - 1]; + Subtree last_child = children[self->child_count - 1]; - self.ptr->first_leaf.symbol = ts_subtree_leaf_symbol(first_child); - self.ptr->first_leaf.parse_state = ts_subtree_leaf_parse_state(first_child); + self->first_leaf.symbol = ts_subtree_leaf_symbol(first_child); + self->first_leaf.parse_state = ts_subtree_leaf_parse_state(first_child); if (ts_subtree_fragile_left(first_child)) - self.ptr->fragile_left = true; + self->fragile_left = true; if (ts_subtree_fragile_right(last_child)) - self.ptr->fragile_right = true; + self->fragile_right = true; - if (self.ptr->child_count >= 2 && !self.ptr->visible && !self.ptr->named && ts_subtree_symbol(first_child) == self.ptr->symbol) + if (self->child_count >= 2 && !self->visible && !self->named && ts_subtree_symbol(first_child) == self->symbol) { if (ts_subtree_repeat_depth(first_child) > ts_subtree_repeat_depth(last_child)) { - self.ptr->repeat_depth = ts_subtree_repeat_depth(first_child) + 1; + self->repeat_depth = ts_subtree_repeat_depth(first_child) + 1; } else { - self.ptr->repeat_depth = ts_subtree_repeat_depth(last_child) + 1; + self->repeat_depth = ts_subtree_repeat_depth(last_child) + 1; } } } @@ -489,7 +489,7 @@ MutableSubtree ts_subtree_new_node(TSSymbol symbol, SubtreeArray *children, t_u3 .production_id = production_id, .first_leaf = {.symbol = 0, .parse_state = 0}, }}}; - MutableSubtree result = {.ptr = data}; + MutableSubtree result = data; ts_subtree_summarize_children(result, language); return result; } @@ -501,7 +501,7 @@ MutableSubtree ts_subtree_new_node(TSSymbol symbol, SubtreeArray *children, t_u3 Subtree ts_subtree_new_error_node(SubtreeArray *children, bool extra, const TSLanguage *language) { MutableSubtree result = ts_subtree_new_node(ts_builtin_sym_error, children, 0, language); - result.ptr->extra = extra; + result->extra = extra; return ts_subtree_from_mut(result); } @@ -513,15 +513,15 @@ Subtree ts_subtree_new_missing_leaf(/*SubtreePool *pool,*/ TSSymbol symbol, Leng const TSLanguage *language) { Subtree result = ts_subtree_new_leaf(/*pool, */ symbol, padding, length_zero(), lookahead_bytes, 0, false, false, false, language); - ((SubtreeHeapData *)result.ptr)->is_missing = true; + ((SubtreeHeapData *)result)->is_missing = true; return result; } void ts_subtree_retain(Subtree self) { - assert(self.ptr->ref_count > 0); - (*(t_u32 *)(&self.ptr->ref_count))++; - assert(self.ptr->ref_count != 0); + assert(self->ref_count > 0); + (*(t_u32 *)(&self->ref_count))++; + assert(self->ref_count != 0); } void ts_subtree_release(Subtree self) @@ -534,8 +534,8 @@ void ts_subtree_release(Subtree self) array_clear(&to_free); - assert(self.ptr->ref_count > 0); - if (--(*(t_u32 *)(&self.ptr->ref_count)) == 0) + assert(self->ref_count > 0); + if (--(*(t_u32 *)(&self->ref_count)) == 0) { array_push(&to_free, ts_subtree_to_mut_unsafe(self)); } @@ -543,14 +543,14 @@ void ts_subtree_release(Subtree self) while (to_free.size > 0) { MutableSubtree tree = array_pop(&to_free); - if (tree.ptr->child_count > 0) + if (tree->child_count > 0) { Subtree *children = ts_subtree_children(tree); - for (t_u32 i = 0; i < tree.ptr->child_count; i++) + for (t_u32 i = 0; i < tree->child_count; i++) { Subtree child = children[i]; - assert(child.ptr->ref_count > 0); - if (--(*(t_u32 *)(&child.ptr->ref_count)) == 0) + assert(child->ref_count > 0); + if (--(*(t_u32 *)(&child->ref_count)) == 0) { array_push(&to_free, ts_subtree_to_mut_unsafe(child)); } @@ -559,9 +559,9 @@ void ts_subtree_release(Subtree self) } else { - if (tree.ptr->has_external_tokens) - ts_external_scanner_state_delete(&tree.ptr->external_scanner_state); - mem_free(tree.ptr); + if (tree->has_external_tokens) + ts_external_scanner_state_delete(&tree->external_scanner_state); + mem_free(tree); } } array_delete(&to_free); @@ -612,7 +612,7 @@ int ts_subtree_compare(Subtree left, Subtree right) static inline void ts_subtree_set_has_changes(MutableSubtree *self) { - self->ptr->has_changes = true; + (*self)->has_changes = true; } Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit /*, SubtreePool *pool*/) @@ -681,8 +681,8 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit /*, SubtreeP MutableSubtree result = ts_subtree_make_mut(/* pool, */ *entry.tree); { - result.ptr->padding = padding; - result.ptr->size = size; + result->padding = padding; + result->size = size; } ts_subtree_set_has_changes(&result); @@ -704,7 +704,7 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit /*, SubtreeP // Also, if this node's validity depends on its column position, then continue // invaliditing child nodes until reaching a line break. if (((child_left.bytes > edit.old_end.bytes) || (child_left.bytes == edit.old_end.bytes && child_size.bytes > 0 && i > 0)) && - (!invalidate_first_row || child_left.extent.row > entry.tree->ptr->padding.extent.row)) + (!invalidate_first_row || child_left.extent.row > (*entry.tree)->padding.extent.row)) { break; } @@ -747,9 +747,9 @@ Subtree ts_subtree_last_external_token(Subtree tree) { if (!ts_subtree_has_external_tokens(tree)) return NULL_SUBTREE; - while (tree.ptr->child_count > 0) + while (tree->child_count > 0) { - for (t_u32 i = tree.ptr->child_count - 1; i + 1 > 0; i--) + for (t_u32 i = tree->child_count - 1; i + 1 > 0; i--) { Subtree child = ts_subtree_children(tree)[i]; if (ts_subtree_has_external_tokens(child)) @@ -762,216 +762,19 @@ Subtree ts_subtree_last_external_token(Subtree tree) return tree; } -static size_t ts_subtree__write_char_to_string(char *str, size_t n, t_i32 chr) -{ - if (chr == -1) - return snprintf(str, n, "INVALID"); - else if (chr == '\0') - return snprintf(str, n, "'\\0'"); - else if (chr == '\n') - return snprintf(str, n, "'\\n'"); - else if (chr == '\t') - return snprintf(str, n, "'\\t'"); - else if (chr == '\r') - return snprintf(str, n, "'\\r'"); - else if (0 < chr && chr < 128 && isprint(chr)) - return snprintf(str, n, "'%c'", chr); - else - return snprintf(str, n, "%d", chr); -} - -static t_const_str const ROOT_FIELD = "__ROOT__"; - -static size_t ts_subtree__write_to_string(Subtree self, char *string, size_t limit, const TSLanguage *language, bool include_all, - TSSymbol alias_symbol, bool alias_is_named, t_const_str field_name) -{ - if (!self.ptr) - return snprintf(string, limit, "(NULL)"); - - char *cursor = string; - char **writer = (limit > 1) ? &cursor : &string; - bool is_root = field_name == ROOT_FIELD; - bool is_visible = - include_all || ts_subtree_missing(self) || (alias_symbol ? alias_is_named : ts_subtree_visible(self) && ts_subtree_named(self)); - - if (is_visible) - { - if (!is_root) - { - cursor += snprintf(*writer, limit, " "); - if (field_name) - { - cursor += snprintf(*writer, limit, "%s: ", field_name); - } - } - - if (ts_subtree_is_error(self) && ts_subtree_child_count(self) == 0 && self.ptr->size.bytes > 0) - { - cursor += snprintf(*writer, limit, "(UNEXPECTED "); - cursor += ts_subtree__write_char_to_string(*writer, limit, self.ptr->lookahead_char); - } - else - { - TSSymbol symbol = alias_symbol ? alias_symbol : ts_subtree_symbol(self); - t_const_str symbol_name = ts_language_symbol_name(language, symbol); - if (ts_subtree_missing(self)) - { - cursor += snprintf(*writer, limit, "(MISSING "); - if (alias_is_named || ts_subtree_named(self)) - { - cursor += snprintf(*writer, limit, "%s", symbol_name); - } - else - { - cursor += snprintf(*writer, limit, "\"%s\"", symbol_name); - } - } - else - { - cursor += snprintf(*writer, limit, "(%s", symbol_name); - } - } - } - else if (is_root) - { - TSSymbol symbol = alias_symbol ? alias_symbol : ts_subtree_symbol(self); - t_const_str symbol_name = ts_language_symbol_name(language, symbol); - if (ts_subtree_child_count(self) > 0) - { - cursor += snprintf(*writer, limit, "(%s", symbol_name); - } - else if (ts_subtree_named(self)) - { - cursor += snprintf(*writer, limit, "(%s)", symbol_name); - } - else - { - cursor += snprintf(*writer, limit, "(\"%s\")", symbol_name); - } - } - - if (ts_subtree_child_count(self)) - { - const TSSymbol *alias_sequence = ts_language_alias_sequence(language, self.ptr->production_id); - const TSFieldMapEntry *field_map, *field_map_end; - ts_language_field_map(language, self.ptr->production_id, &field_map, &field_map_end); - - t_u32 structural_child_index = 0; - for (t_u32 i = 0; i < self.ptr->child_count; i++) - { - Subtree child = ts_subtree_children(self)[i]; - if (ts_subtree_extra(child)) - { - cursor += ts_subtree__write_to_string(child, *writer, limit, language, include_all, 0, false, NULL); - } - else - { - TSSymbol subtree_alias_symbol = alias_sequence ? alias_sequence[structural_child_index] : 0; - bool subtree_alias_is_named = - subtree_alias_symbol ? ts_language_symbol_metadata(language, subtree_alias_symbol).named : false; - - t_const_str child_field_name = is_visible ? NULL : field_name; - for (const TSFieldMapEntry *map = field_map; map < field_map_end; map++) - { - if (!map->inherited && map->child_index == structural_child_index) - { - child_field_name = language->field_names[map->field_id]; - break; - } - } - - cursor += ts_subtree__write_to_string(child, *writer, limit, language, include_all, subtree_alias_symbol, - subtree_alias_is_named, child_field_name); - structural_child_index++; - } - } - } - - if (is_visible) - cursor += snprintf(*writer, limit, ")"); - - return cursor - string; -} - -char *ts_subtree_string(Subtree self, TSSymbol alias_symbol, bool alias_is_named, const TSLanguage *language, bool include_all) -{ - char scratch_string[1]; - size_t size = ts_subtree__write_to_string(self, scratch_string, 1, language, include_all, alias_symbol, alias_is_named, ROOT_FIELD) + 1; - char *result = mem_alloc(size * sizeof(char)); - ts_subtree__write_to_string(self, result, size, language, include_all, alias_symbol, alias_is_named, ROOT_FIELD); - return result; -} - -/* -void ts_subtree__print_dot_graph(const Subtree *self, t_u32 start_offset, const TSLanguage *language, TSSymbol alias_symbol, FILE *f) -{ - TSSymbol subtree_symbol = ts_subtree_symbol(*self); - TSSymbol symbol = alias_symbol ? alias_symbol : subtree_symbol; - t_u32 end_offset = start_offset + ts_subtree_total_bytes(*self); - fprintf(f, "tree_%p [label=\"", (void *)self); - ts_language_write_symbol_as_dot_string(language, f, symbol); - fprintf(f, "\""); - - if (ts_subtree_child_count(*self) == 0) - fprintf(f, ", shape=plaintext"); - if (ts_subtree_extra(*self)) - fprintf(f, ", fontcolor=gray"); - - fprintf(f, - ", tooltip=\"" - "range: %u - %u\n" - "state: %d\n" - "error-cost: %u\n" - "has-changes: %u\n" - "depends-on-column: %u\n" - "descendant-count: %u\n" - "repeat-depth: %u\n" - "lookahead-bytes: %u", - start_offset, end_offset, ts_subtree_parse_state(*self), ts_subtree_error_cost(*self), ts_subtree_has_changes(*self), - ts_subtree_depends_on_column(*self), ts_subtree_visible_descendant_count(*self), ts_subtree_repeat_depth(*self), - ts_subtree_lookahead_bytes(*self)); - - if (ts_subtree_is_error(*self) && ts_subtree_child_count(*self) == 0 && self->ptr->lookahead_char != 0) - { - fprintf(f, "\ncharacter: '%c'", self->ptr->lookahead_char); - } - - fprintf(f, "\"]\n"); - - t_u32 child_start_offset = start_offset; - t_u32 child_info_offset = language->max_alias_sequence_length * ts_subtree_production_id(*self); - for (t_u32 i = 0, n = ts_subtree_child_count(*self); i < n; i++) - { - const Subtree *child = &ts_subtree_children(*self)[i]; - TSSymbol subtree_alias_symbol = 0; - if (!ts_subtree_extra(*child) && child_info_offset) - { - subtree_alias_symbol = language->alias_sequences[child_info_offset]; - child_info_offset++; - } - ts_subtree__print_dot_graph(child, child_start_offset, language, subtree_alias_symbol, f); - fprintf(f, "tree_%p -> tree_%p [tooltip=%u]\n", (void *)self, (void *)child, i); - child_start_offset += ts_subtree_total_bytes(*child); - } -} -*/ - -/* -void ts_subtree_print_dot_graph(Subtree self, const TSLanguage *language, FILE *f) -{ - fprintf(f, "digraph tree {\n"); - fprintf(f, "edge [arrowhead=none]\n"); - ts_subtree__print_dot_graph(&self, 0, language, 0, f); - fprintf(f, "}\n"); -} -*/ - const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self) { + #ifdef static + #undef static + #define __REAPPLY_STATIC + #endif static const ExternalScannerState empty_state = {{NULL}, .length = 0}; - if (self.ptr && self.ptr->has_external_tokens && self.ptr->child_count == 0) + #ifdef __REAPPLY_STATIC + #define static + #endif + if (self && self->has_external_tokens && self->child_count == 0) { - return &self.ptr->external_scanner_state; + return &self->external_scanner_state; } else { diff --git a/parser/static/char_set/charset_inline.h b/parser/static/char_set/charset_inline.h index 9f732f12..7dfe1a22 100644 --- a/parser/static/char_set/charset_inline.h +++ b/parser/static/char_set/charset_inline.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:31:53 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,27 +17,51 @@ static inline t_char_range *sym__comment_word_character_set_1(void) { + #ifdef static + #undef static + #define static__REAPPLY + #endif static t_char_range val[10] = {{0, 0x08}, {0x0b, 0x1f}, \ {'!', '!'}, {'#', '#'}, {'%', '%'}, {'*', ':'}, {'=', \ '='}, {'?', '_'}, {'a', '{'}, {'}', 0x10ffff}}; + #ifdef static__REAPPLY + #define static + #undef static__REAPPLY + #endif return (val); } static inline t_char_range *sym_word_character_set_1(void) { + #ifdef static + #undef static + #define static__REAPPLY + #endif static t_char_range val[9] = {{0, 0x08}, {0x0b, 0x1f}, \ {'!', '!'}, {'%', '%'}, {'*', ':'}, {'=', '='}, {'?', \ '_'}, {'a', '{'}, {'}', 0x10ffff}}; + #ifdef static__REAPPLY + #define static + #undef static__REAPPLY + #endif return (val); } static inline t_char_range *aux_sym__word_no_brace_token1_character_set_2(void) { + #ifdef static + #undef static + #define static__REAPPLY + #endif static t_char_range val[10] = {{0, 0x08}, {0x0b, 0x1f}, \ {'!', '!'}, {'#', '#'}, {'%', '%'}, {'*', ':'}, {'=', \ '='}, {'?', '_'}, {'a', 'z'}, {'~', 0x10ffff}}; + #ifdef static__REAPPLY + #define static + #undef static__REAPPLY + #endif return (val); } diff --git a/parser/static/create/create_alias_sequences.c b/parser/static/create/create_alias_sequences.c index c827bc66..58d5f2d7 100644 --- a/parser/static/create/create_alias_sequences.c +++ b/parser/static/create/create_alias_sequences.c @@ -6,13 +6,17 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:24:55 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_alias_sequences.h" #include "../alias_sequences/alias_sequences.h" +#ifdef static +# undef static +#endif + t_alias_sequences_array *create_alias_sequences(void) { static t_alias_sequences_array table = {}; diff --git a/parser/static/create/create_external_scanner_states.c b/parser/static/create/create_external_scanner_states.c index e5c3e1bd..e4a378d7 100644 --- a/parser/static/create/create_external_scanner_states.c +++ b/parser/static/create/create_external_scanner_states.c @@ -6,13 +6,17 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:01 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_external_scanner_states.h" #include "../external_scanner_states/external_scanner_states.h" +#ifdef static +# undef static +#endif + t_external_scanner_states_array *create_external_scanner_states(void) { static t_external_scanner_states_array table = {}; diff --git a/parser/static/create/create_external_scanner_symbol_map.c b/parser/static/create/create_external_scanner_symbol_map.c index 6b7f23b3..4298027f 100644 --- a/parser/static/create/create_external_scanner_symbol_map.c +++ b/parser/static/create/create_external_scanner_symbol_map.c @@ -6,13 +6,17 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:05 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_external_scanner_symbol_map.h" #include "../external_scanner_symbol_map/external_scanner_symbol_map.h" +#ifdef static +# undef static +#endif + t_external_scanner_symbol_map_array *create_external_scanner_symbol_map(void) { static t_external_scanner_symbol_map_array table = {}; diff --git a/parser/static/create/create_field_map_entries.c b/parser/static/create/create_field_map_entries.c index cc6da7c9..63a95a95 100644 --- a/parser/static/create/create_field_map_entries.c +++ b/parser/static/create/create_field_map_entries.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:13 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_field_map_entries.h" #include "../field_map_entries/field_map_entries.h" +#ifdef static +# undef static +#endif + + t_field_map_entries_array *create_field_map_entries(void) { static t_field_map_entries_array table = {}; diff --git a/parser/static/create/create_field_map_slices.c b/parser/static/create/create_field_map_slices.c index 4f041438..94efc8e5 100644 --- a/parser/static/create/create_field_map_slices.c +++ b/parser/static/create/create_field_map_slices.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:17 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_field_map_slices.h" #include "../field_map_slices/field_map_slices.h" +#ifdef static +# undef static +#endif + + t_field_map_slices_array *create_field_map_slices(void) { static t_field_map_slices_array table = {}; diff --git a/parser/static/create/create_field_names.c b/parser/static/create/create_field_names.c index 1da5f1eb..496d7e82 100644 --- a/parser/static/create/create_field_names.c +++ b/parser/static/create/create_field_names.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:20 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_field_names.h" #include "../field_names/field_names.h" +#ifdef static +# undef static +#endif + + t_field_names_array *create_field_names(void) { static t_field_names_array table = {}; diff --git a/parser/static/create/create_lex_modes.c b/parser/static/create/create_lex_modes.c index a253edd2..3f9ade48 100644 --- a/parser/static/create/create_lex_modes.c +++ b/parser/static/create/create_lex_modes.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:38 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_lex_modes.h" #include "../lex_modes/lex_modes.h" + +#ifdef static +# undef static +#endif + t_lex_modes_array *create_lex_modes(void) { static t_lex_modes_array table = {}; diff --git a/parser/static/create/create_non_terminal_alias_map.c b/parser/static/create/create_non_terminal_alias_map.c index d5835563..2ad3ca4a 100644 --- a/parser/static/create/create_non_terminal_alias_map.c +++ b/parser/static/create/create_non_terminal_alias_map.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:38 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_non_terminal_alias_map.h" #include "../non_terminal_alias_map/non_terminal_alias_map.h" + +#ifdef static +# undef static +#endif + t_non_terminal_alias_map_array *create_non_terminal_alias_map(void) { static t_non_terminal_alias_map_array table = {}; diff --git a/parser/static/create/create_parse_actions_entries.c b/parser/static/create/create_parse_actions_entries.c index eff5d0dd..39555732 100644 --- a/parser/static/create/create_parse_actions_entries.c +++ b/parser/static/create/create_parse_actions_entries.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:38 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,11 @@ #include "../types/type_parse_actions_entries.h" #include "../parse_actions_entries/parse_actions_entries.h" + +#ifdef static +# undef static +#endif + t_parse_actions_entries_array *create_parse_actions_entries(void) { static t_parse_actions_entries_array table = {}; diff --git a/parser/static/create/create_parse_table.c b/parser/static/create/create_parse_table.c index cfbfd8de..ed6b2a41 100644 --- a/parser/static/create/create_parse_table.c +++ b/parser/static/create/create_parse_table.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:38 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_parse_table.h" #include "../parse_table/parse_table.h" + +#ifdef static +# undef static +#endif + t_parse_table_array *create_parse_table(void) { static t_parse_table_array table = {}; diff --git a/parser/static/create/create_primary_state_ids.c b/parser/static/create/create_primary_state_ids.c index 61435f90..44e963ab 100644 --- a/parser/static/create/create_primary_state_ids.c +++ b/parser/static/create/create_primary_state_ids.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:38 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_primary_state_ids.h" #include "../primary_state_ids/primary_state_ids.h" + +#ifdef static +# undef static +#endif + t_primary_state_ids_array *create_primary_state_ids(void) { static t_primary_state_ids_array table = {}; diff --git a/parser/static/create/create_symbols_metadata.c b/parser/static/create/create_symbols_metadata.c index 928d38d6..d4acfbac 100644 --- a/parser/static/create/create_symbols_metadata.c +++ b/parser/static/create/create_symbols_metadata.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:38 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_symbols_metadata.h" #include "../symbols_metadata/symbols_metadata.h" + +#ifdef static +# undef static +#endif + t_symbols_metadata_array *create_symbols_metadata(void) { static t_symbols_metadata_array table = {}; diff --git a/parser/static/create/create_symbols_names.c b/parser/static/create/create_symbols_names.c index e4387662..ff079530 100644 --- a/parser/static/create/create_symbols_names.c +++ b/parser/static/create/create_symbols_names.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:38 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_symbols_names.h" #include "../symbols_names/symbols_names.h" + +#ifdef static +# undef static +#endif + t_symbols_names_array *create_symbols_names(void) { static t_symbols_names_array table = {}; diff --git a/parser/static/create/create_unique_symbols_map.c b/parser/static/create/create_unique_symbols_map.c index a3bc559e..d96be5f0 100644 --- a/parser/static/create/create_unique_symbols_map.c +++ b/parser/static/create/create_unique_symbols_map.c @@ -6,13 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/14 19:17:54 by maiboyer #+# #+# */ -/* Updated: 2024/04/14 19:18:20 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:25:37 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../types/type_unique_symbols_map.h" #include "../unique_symbols_map/unique_symbols_map.h" + +#ifdef static +# undef static +#endif + t_unique_symbols_map_array *create_unique_symbols_map(void) { static t_unique_symbols_map_array table = {}; diff --git a/sources/node/node.c b/sources/node/node.c index 93734769..2adfd7aa 100644 --- a/sources/node/node.c +++ b/sources/node/node.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/28 18:36:40 by maiboyer #+# #+# */ -/* Updated: 2024/08/02 12:17:33 by rparodi ### ########.fr */ +/* Updated: 2024/08/22 15:58:43 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,15 +16,13 @@ #include "parser/api.h" #include -t_node build_node(t_parse_node current, t_const_str input); +t_node build_node(t_parse_node current, t_const_str input); -t_language *tree_sitter_bash(void); - -t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count) +t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count) { - t_node *ret; - t_usize idx; - t_parse_node child; + t_node *ret; + t_usize idx; + t_parse_node child; ret = mem_alloc_array(sizeof(*ret), count); if (ret == NULL) @@ -34,19 +32,19 @@ t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count) { child = ts_node_child(parent, idx); ret[idx] = build_node(child, input); - ret[idx].field_str = ts_node_field_name_for_child(parent, idx); ret[idx].field = ts_node_field_id_for_child(parent, idx); + ret[idx].field_str = ts_language_field_name_for_id(ts_node_language(parent), ret[idx].field); idx++; } return (ret); } -t_node build_node(t_parse_node curr, t_const_str input) +t_node build_node(t_parse_node curr, t_const_str input) { - t_node out; + t_node out; out.kind = ts_node_symbol(curr); - out.kind_str = ts_node_type(curr); + out.kind_str = ts_language_symbol_name(ts_node_language(curr), out.kind); out.start = ts_node_start_byte(curr); out.end = ts_node_end_byte(curr); out.input = input; @@ -61,10 +59,10 @@ t_node build_node(t_parse_node curr, t_const_str input) return (out); } -t_str node_getstr(t_node *node) +t_str node_getstr(t_node *node) { - t_usize start; - t_usize end; + t_usize start; + t_usize end; t_str ret; if (node->single_str == NULL) @@ -80,9 +78,9 @@ t_str node_getstr(t_node *node) return (node->single_str); } -void free_node(t_node self) +void free_node(t_node self) { - t_usize idx; + t_usize idx; if (self.single_str) mem_free(self.single_str); diff --git a/stdme/src/fs/fs_internal.c b/stdme/src/fs/fs_internal.c index 06c61dbb..c9e921fe 100644 --- a/stdme/src/fs/fs_internal.c +++ b/stdme/src/fs/fs_internal.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/19 15:53:50 by maiboyer #+# #+# */ -/* Updated: 2024/08/05 15:18:22 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:23:04 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,10 @@ #include #include +#ifdef static +# undef static +#endif + t_fd_array *get_fd_arrays(void) { static t_fd_array val = {}; diff --git a/stdme/src/fs/getters.c b/stdme/src/fs/getters.c index 184330f1..64c5fba7 100644 --- a/stdme/src/fs/getters.c +++ b/stdme/src/fs/getters.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/30 16:27:28 by rparodi #+# #+# */ -/* Updated: 2024/07/30 16:28:03 by rparodi ### ########.fr */ +/* Updated: 2024/08/22 16:23:36 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,10 @@ #include #include +#ifdef static +# undef static +#endif + t_fd *get_stdin(void) { t_fd *out; diff --git a/stdme/src/gnl/get_next_line.c b/stdme/src/gnl/get_next_line.c index 64624928..f84b624b 100644 --- a/stdme/src/gnl/get_next_line.c +++ b/stdme/src/gnl/get_next_line.c @@ -6,7 +6,7 @@ /* By: maix +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/23 17:38:21 by maix #+# #+# */ -/* Updated: 2024/07/10 17:45:42 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:29:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,10 @@ #include #include +#ifdef static +#undef static +#endif + static t_static_buffer *get_next_line_buffer(int fd) { t_usize index; diff --git a/stdme/src/mem/allocator.c b/stdme/src/mem/allocator.c index 85102113..45004352 100644 --- a/stdme/src/mem/allocator.c +++ b/stdme/src/mem/allocator.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */ -/* Updated: 2024/07/10 17:48:46 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:23:44 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,10 @@ #include "me/types.h" #include +#ifdef static +# undef static +#endif + t_allocator *global_allocator(void) { static t_allocator global_alloc = {}; diff --git a/stdme/src/printf/matchers.c b/stdme/src/printf/matchers.c index a088441a..fc8b768d 100644 --- a/stdme/src/printf/matchers.c +++ b/stdme/src/printf/matchers.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/16 18:07:40 by maiboyer #+# #+# */ -/* Updated: 2024/07/08 19:37:12 by maiboyer ### ########.fr */ +/* Updated: 2024/08/22 16:23:55 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,10 @@ #include #include +#ifdef static +# undef static +#endif + t_matcher_list *get_matchers(void) { static t_matcher_list printf_matchers = (t_matcher_list){