mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 19:41:15 -03:00
Move Process's block node into its Type
Previously, for Processes which were BlockNodes, we stored the node separately in the Process via an Option; just promote this to a real field of the ProcessType::BlockNode. No user visible changes expected.
This commit is contained in:
20
src/exec.rs
20
src/exec.rs
@@ -983,13 +983,15 @@ fn get_performer_for_process(
|
||||
let job_group = job.group.clone();
|
||||
let io_chain = io_chain.clone();
|
||||
|
||||
if p.is_block_node() {
|
||||
Some(Box::new(move |parser: &Parser, p: &Process, _out, _err| {
|
||||
let node = p.block_node.as_ref().expect("Process is missing node info");
|
||||
parser
|
||||
.eval_node(node, &io_chain, job_group.as_ref(), BlockType::top)
|
||||
.status
|
||||
}))
|
||||
if let ProcessType::BlockNode(node) = &p.typ {
|
||||
let node = node.clone();
|
||||
Some(Box::new(
|
||||
move |parser: &Parser, _p: &Process, _out, _err| {
|
||||
parser
|
||||
.eval_node(&node, &io_chain, job_group.as_ref(), BlockType::top)
|
||||
.status
|
||||
},
|
||||
))
|
||||
} else {
|
||||
assert!(p.is_function());
|
||||
let Some(props) = function::get_props(p.argv0().unwrap()) else {
|
||||
@@ -1255,7 +1257,7 @@ fn exec_process_in_job(
|
||||
process_net_io_chain.push(Arc::new(IoClose::new(afd.as_raw_fd())));
|
||||
}
|
||||
|
||||
if !matches!(p.typ, ProcessType::BlockNode) {
|
||||
if !p.is_block_node() {
|
||||
// A simple `begin ... end` should not be considered an execution of a command.
|
||||
parser.libdata_mut().exec_count += 1;
|
||||
}
|
||||
@@ -1291,7 +1293,7 @@ fn exec_process_in_job(
|
||||
// Execute the process.
|
||||
p.check_generations_before_launch();
|
||||
match p.typ {
|
||||
ProcessType::Function | ProcessType::BlockNode => exec_block_or_func_process(
|
||||
ProcessType::Function | ProcessType::BlockNode(_) => exec_block_or_func_process(
|
||||
parser,
|
||||
j,
|
||||
p,
|
||||
|
||||
@@ -831,8 +831,7 @@ fn populate_block_process(
|
||||
let mut redirections = RedirectionSpecList::new();
|
||||
let reason = self.determine_redirections(ctx, args_or_redirs, &mut redirections);
|
||||
if reason == EndExecutionReason::ok {
|
||||
proc.typ = ProcessType::BlockNode;
|
||||
proc.block_node = Some(NodeRef::new(Arc::clone(self.pstree()), statement));
|
||||
proc.typ = ProcessType::BlockNode(NodeRef::new(Arc::clone(self.pstree()), statement));
|
||||
proc.set_redirection_specs(redirections);
|
||||
}
|
||||
reason
|
||||
|
||||
11
src/proc.rs
11
src/proc.rs
@@ -56,7 +56,8 @@ pub enum ProcessType {
|
||||
/// A shellscript function.
|
||||
Function,
|
||||
/// A block of commands, represented as a node.
|
||||
BlockNode,
|
||||
/// This is always either block, ifs, or switchs, never boolean or decorated.
|
||||
BlockNode(NodeRef<ast::Statement>),
|
||||
/// The exec builtin.
|
||||
Exec,
|
||||
}
|
||||
@@ -599,10 +600,6 @@ pub struct Process {
|
||||
/// Type of process.
|
||||
pub typ: ProcessType,
|
||||
|
||||
/// For internal block processes only, the node of the statement.
|
||||
/// This is always either block, ifs, or switchs, never boolean or decorated.
|
||||
pub block_node: Option<NodeRef<ast::Statement>>,
|
||||
|
||||
/// The expanded variable assignments for this process, as specified by the `a=b cmd` syntax.
|
||||
pub variable_assignments: Vec<ConcreteAssignment>,
|
||||
|
||||
@@ -741,7 +738,7 @@ pub fn mark_aborted_before_launch(&self) {
|
||||
/// Return whether this process type is internal (block, function, or builtin).
|
||||
pub fn is_internal(&self) -> bool {
|
||||
match self.typ {
|
||||
ProcessType::Builtin | ProcessType::Function | ProcessType::BlockNode => true,
|
||||
ProcessType::Builtin | ProcessType::Function | ProcessType::BlockNode(_) => true,
|
||||
ProcessType::External | ProcessType::Exec => false,
|
||||
}
|
||||
}
|
||||
@@ -754,7 +751,7 @@ pub fn is_function(&self) -> bool {
|
||||
matches!(self.typ, ProcessType::Function)
|
||||
}
|
||||
pub fn is_block_node(&self) -> bool {
|
||||
matches!(self.typ, ProcessType::BlockNode)
|
||||
matches!(self.typ, ProcessType::BlockNode(_))
|
||||
}
|
||||
pub fn is_external(&self) -> bool {
|
||||
matches!(self.typ, ProcessType::External)
|
||||
|
||||
Reference in New Issue
Block a user