diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index e6e51ed2c..72bebf415 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -1196,7 +1196,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t jo (job_control_mode == JOB_CONTROL_ALL) || ((job_control_mode == JOB_CONTROL_INTERACTIVE) && shell_is_interactive())); - job->set_flag(JOB_FOREGROUND, !tree().job_should_be_backgrounded(job_node)); + job->set_flag(JOB_FOREGROUND, !job_node_is_background(job_node)); job->set_flag(JOB_TERMINAL, job->get_flag(JOB_CONTROL) && !is_event); diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index c431fa0e0..600d9818f 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -1405,12 +1405,6 @@ parse_node_tree_t::parse_node_list_t parse_node_tree_t::comment_nodes_for_node( return result; } -bool parse_node_tree_t::job_should_be_backgrounded(const parse_node_t &job) const { - assert(job.type == symbol_job); - const parse_node_t *opt_background = get_child(job, 2, symbol_optional_background); - return opt_background != NULL && opt_background->tag == parse_background; -} - const parse_node_t *parse_node_tree_t::next_node_in_node_list( const parse_node_t &node_list, parse_token_type_t entry_type, const parse_node_t **out_list_tail) const { @@ -1465,3 +1459,8 @@ arguments_node_list_t get_argument_nodes(tnode_t list) { arguments_node_list_t get_argument_nodes(tnode_t list) { return list.descendants(); } + +bool job_node_is_background(tnode_t job) { + tnode_t bg = job.child<2>(); + return bg.tag() == parse_background; +} diff --git a/src/parse_tree.h b/src/parse_tree.h index b7e7287e6..e69b27c1c 100644 --- a/src/parse_tree.h +++ b/src/parse_tree.h @@ -214,9 +214,6 @@ class parse_node_tree_t : public std::vector { /// Given a node, return all of its comment nodes. parse_node_list_t comment_nodes_for_node(const parse_node_t &node) const; - /// Given a job, return whether it should be backgrounded, because it has a & specifier. - bool job_should_be_backgrounded(const parse_node_t &job) const; - private: // Finds the last node of a given type underneath a given node, or NULL if it could not be // found. If parent is NULL, this finds the last node in the tree of that type. @@ -437,6 +434,9 @@ using arguments_node_list_t = std::vector>; arguments_node_list_t get_argument_nodes(tnode_t); arguments_node_list_t get_argument_nodes(tnode_t); +/// Return whether the given job is background because it has a & symbol. +bool job_node_is_background(tnode_t); + /// The big entry point. Parse a string, attempting to produce a tree for the given goal type. bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t flags, parse_node_tree_t *output, parse_error_list_t *errors, diff --git a/src/parse_util.cpp b/src/parse_util.cpp index c2c341b06..0753c4918 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -1163,7 +1163,7 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, // while foo & ; end // If it's not a background job, nothing to do. auto job = tnode_t{&node_tree, &node}; - if (node_tree.job_should_be_backgrounded(job)) { + if (job_node_is_background(job)) { errored |= detect_errors_in_backgrounded_job(node_tree, job, &parse_errors); } } else if (node.type == symbol_plain_statement) {