aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2023-04-14 08:01:12 +0800
committerPo Lu2023-04-14 08:01:12 +0800
commit2c3ca78e811b288aa4801f78c11ba9ddf9ffe02c (patch)
tree95f2e1dca188f1cb395e1046133a445707825b6a /src
parent361c5fc2d8e52d70aa58956c57eaef9495881197 (diff)
downloademacs-2c3ca78e811b288aa4801f78c11ba9ddf9ffe02c.tar.gz
emacs-2c3ca78e811b288aa4801f78c11ba9ddf9ffe02c.zip
Fix bugs in treesit.o
* src/treesit.c (treesit_traverse_match_predicate): Remove redundant cast. (treesit_search_forward, treesit_traverse_cleanup_cursor) (Ftreesit_search_subtree, Ftreesit_search_forward) (Ftreesit_induce_sparse_tree): Fix coding style and specpdl unwinding.
Diffstat (limited to 'src')
-rw-r--r--src/treesit.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 09d998b56c8..45b5ab15390 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -3243,10 +3243,8 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, Lisp_Object pred,
3243 Lisp_Object cdr = XCDR (pred); 3243 Lisp_Object cdr = XCDR (pred);
3244 3244
3245 if (EQ (car, Qnot)) 3245 if (EQ (car, Qnot))
3246 { 3246 return !treesit_traverse_match_predicate (cursor, XCAR (cdr),
3247 return !treesit_traverse_match_predicate (cursor, XCAR (cdr), 3247 parser, named);
3248 parser, named);
3249 }
3250 else if (EQ (car, Qor)) 3248 else if (EQ (car, Qor))
3251 { 3249 {
3252 FOR_EACH_TAIL (cdr) 3250 FOR_EACH_TAIL (cdr)
@@ -3287,6 +3285,7 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, Lisp_Object pred,
3287 forward, false backward. If SKIP_ROOT is true, don't match ROOT. 3285 forward, false backward. If SKIP_ROOT is true, don't match ROOT.
3288 3286
3289 This function may signal if the predicate function signals. */ 3287 This function may signal if the predicate function signals. */
3288
3290static bool 3289static bool
3291treesit_search_dfs (TSTreeCursor *cursor, 3290treesit_search_dfs (TSTreeCursor *cursor,
3292 Lisp_Object pred, Lisp_Object parser, 3291 Lisp_Object pred, Lisp_Object parser,
@@ -3325,6 +3324,7 @@ treesit_search_dfs (TSTreeCursor *cursor,
3325 position is undefined. 3324 position is undefined.
3326 3325
3327 This function may signal if the predicate function signals. */ 3326 This function may signal if the predicate function signals. */
3327
3328static bool 3328static bool
3329treesit_search_forward (TSTreeCursor *cursor, 3329treesit_search_forward (TSTreeCursor *cursor,
3330 Lisp_Object pred, Lisp_Object parser, 3330 Lisp_Object pred, Lisp_Object parser,
@@ -3334,8 +3334,7 @@ treesit_search_forward (TSTreeCursor *cursor,
3334 nodes. This way repeated call of this function traverses each 3334 nodes. This way repeated call of this function traverses each
3335 node in the tree once and only once: 3335 node in the tree once and only once:
3336 3336
3337 (while node (setq node (treesit-search-forward node))) 3337 (while node (setq node (treesit-search-forward node))) */
3338 */
3339 bool initial = true; 3338 bool initial = true;
3340 while (true) 3339 while (true)
3341 { 3340 {
@@ -3362,10 +3361,12 @@ treesit_search_forward (TSTreeCursor *cursor,
3362 } 3361 }
3363} 3362}
3364 3363
3365/** Cleanup function for cursor. */ 3364/* Clean up the given tree cursor CURSOR. */
3366static void treesit_traverse_cleanup_cursor(void *cursor) 3365
3366static void
3367treesit_traverse_cleanup_cursor (void *cursor)
3367{ 3368{
3368 ts_tree_cursor_delete ((TSTreeCursor *) cursor); 3369 ts_tree_cursor_delete (cursor);
3369} 3370}
3370 3371
3371DEFUN ("treesit-search-subtree", 3372DEFUN ("treesit-search-subtree",
@@ -3421,10 +3422,7 @@ Return the first matched node, or nil if none matches. */)
3421 return_value = make_treesit_node (parser, node); 3422 return_value = make_treesit_node (parser, node);
3422 } 3423 }
3423 3424
3424 unbind_to (count, Qnil); 3425 return unbind_to (count, return_value);
3425
3426 ts_tree_cursor_delete (&cursor);
3427 return return_value;
3428} 3426}
3429 3427
3430DEFUN ("treesit-search-forward", 3428DEFUN ("treesit-search-forward",
@@ -3486,10 +3484,7 @@ always traverse leaf nodes first, then upwards. */)
3486 return_value = make_treesit_node (parser, node); 3484 return_value = make_treesit_node (parser, node);
3487 } 3485 }
3488 3486
3489 unbind_to (count, Qnil); 3487 return unbind_to (count, return_value);
3490
3491 ts_tree_cursor_delete (&cursor);
3492 return return_value;
3493} 3488}
3494 3489
3495/* Recursively traverse the tree under CURSOR, and append the result 3490/* Recursively traverse the tree under CURSOR, and append the result
@@ -3616,8 +3611,8 @@ a regexp. */)
3616 3611
3617 unbind_to (count, Qnil); 3612 unbind_to (count, Qnil);
3618 3613
3619 ts_tree_cursor_delete (&cursor);
3620 Fsetcdr (parent, Fnreverse (Fcdr (parent))); 3614 Fsetcdr (parent, Fnreverse (Fcdr (parent)));
3615
3621 if (NILP (Fcdr (parent))) 3616 if (NILP (Fcdr (parent)))
3622 return Qnil; 3617 return Qnil;
3623 else 3618 else