| 2728 | } |
| 2729 | |
| 2730 | static void sh_walk(sh_t *s, TSNode n) { |
| 2731 | const char *t = ts_node_type(n); |
| 2732 | if (strcmp(t, "program") == 0 || strcmp(t, "compound_statement") == 0 || |
| 2733 | strcmp(t, "negated_command") == 0) { |
| 2734 | sh_walk_children(s, n); |
| 2735 | } else if (strcmp(t, "variable_assignment") == 0) { |
| 2736 | sh_assign(s, n, false); |
| 2737 | } else if (strcmp(t, "variable_assignments") == 0) { |
| 2738 | for (uint32_t i = 0; i < ts_node_named_child_count(n); i++) { |
| 2739 | sh_assign(s, ts_node_named_child(n, i), false); |
| 2740 | } |
| 2741 | } else if (strcmp(t, "declaration_command") == 0) { |
| 2742 | sh_declare(s, n); |
| 2743 | } else if (strcmp(t, "unset_command") == 0) { |
| 2744 | for (uint32_t i = 0; i < ts_node_named_child_count(n); i++) { |
| 2745 | TSNode c = ts_node_named_child(n, i); |
| 2746 | if (sh_type(c, "variable_name") || sh_type(c, "word")) { |
| 2747 | sh_set(s, sh_text(s, c), &SH_UNKNOWN_VAL, false); |
| 2748 | } |
| 2749 | } |
| 2750 | } else if (strcmp(t, "command") == 0) { |
| 2751 | sh_command(s, n); |
| 2752 | } else if (strcmp(t, "redirected_statement") == 0) { |
| 2753 | TSNode body = ts_node_child_by_field_name(n, TS_FIELD("body")); |
| 2754 | if (!ts_node_is_null(body)) { |
| 2755 | sh_walk(s, body); |
| 2756 | } |
| 2757 | sh_mark_t m = sh_mark(s); |
| 2758 | sh_redirects(s, n); |
| 2759 | sh_rewind(s, m); |
| 2760 | } else if (strcmp(t, "pipeline") == 0) { |
| 2761 | sh_pipeline(s, n); |
| 2762 | } else if (strcmp(t, "list") == 0) { |
| 2763 | sh_list(s, n); |
| 2764 | } else if (strcmp(t, "subshell") == 0) { |
| 2765 | sh_mark_t m = sh_mark(s); |
| 2766 | sh_walk_children(s, n); |
| 2767 | sh_rewind(s, m); |
| 2768 | } else if (strcmp(t, "if_statement") == 0) { |
| 2769 | sh_if(s, n); |
| 2770 | } else if (strcmp(t, "case_statement") == 0) { |
| 2771 | sh_case(s, n); |
| 2772 | } else if (strcmp(t, "for_statement") == 0 || strcmp(t, "c_style_for_statement") == 0 || |
| 2773 | strcmp(t, "while_statement") == 0) { |
| 2774 | sh_loop(s, n); |
| 2775 | } else if (strcmp(t, "function_definition") == 0) { |
| 2776 | sh_function(s, n); |
| 2777 | } else { |
| 2778 | sh_walk_substs(s, n); /* [[ -n "$(cmd)" ]], ((...)), a bare word */ |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | /* ── Files ─────────────────────────────────────────────────────────── */ |
| 2783 |
no test coverage detected