diff --git a/fish-rust/src/builtins/abbr.rs b/fish-rust/src/builtins/abbr.rs index efda9bd7e..ec8e019f2 100644 --- a/fish-rust/src/builtins/abbr.rs +++ b/fish-rust/src/builtins/abbr.rs @@ -24,7 +24,7 @@ struct Options { } impl Options { - fn validate(&mut self, streams: &mut io_streams_t) -> bool { + fn validate(&mut self, streams: &mut IoStreams) -> bool { // Duplicate options? let mut cmds = vec![]; if self.add { @@ -124,7 +124,7 @@ fn join(list: &[&wstr], sep: &wstr) -> WString { } // Print abbreviations in a fish-script friendly way. -fn abbr_show(streams: &mut io_streams_t) -> Option { +fn abbr_show(streams: &mut IoStreams) -> Option { let style = EscapeStringStyle::Script(Default::default()); abbrs::with_abbrs(|abbrs| { @@ -174,7 +174,7 @@ fn abbr_show(streams: &mut io_streams_t) -> Option { } // Print the list of abbreviation names. -fn abbr_list(opts: &Options, streams: &mut io_streams_t) -> Option { +fn abbr_list(opts: &Options, streams: &mut IoStreams) -> Option { const subcmd: &wstr = L!("--list"); if !opts.args.is_empty() { streams.err.append(wgettext_fmt!( @@ -197,7 +197,7 @@ fn abbr_list(opts: &Options, streams: &mut io_streams_t) -> Option { } // Rename an abbreviation, deleting any existing one with the given name. -fn abbr_rename(opts: &Options, streams: &mut io_streams_t) -> Option { +fn abbr_rename(opts: &Options, streams: &mut IoStreams) -> Option { const subcmd: &wstr = L!("--rename"); if opts.args.len() != 2 { @@ -271,7 +271,7 @@ fn abbr_query(opts: &Options) -> Option { } // Add a named abbreviation. -fn abbr_add(opts: &Options, streams: &mut io_streams_t) -> Option { +fn abbr_add(opts: &Options, streams: &mut IoStreams) -> Option { const subcmd: &wstr = L!("--add"); if opts.args.len() < 2 && opts.function.is_none() { @@ -391,7 +391,7 @@ fn abbr_add(opts: &Options, streams: &mut io_streams_t) -> Option { } // Erase the named abbreviations. -fn abbr_erase(opts: &Options, parser: &mut parser_t) -> Option { +fn abbr_erase(opts: &Options, parser: &mut Parser) -> Option { if opts.args.is_empty() { // This has historically been a silent failure. return STATUS_CMD_ERROR; @@ -419,11 +419,7 @@ fn abbr_erase(opts: &Options, parser: &mut parser_t) -> Option { }) } -pub fn abbr( - parser: &mut parser_t, - streams: &mut io_streams_t, - argv: &mut [&wstr], -) -> Option { +pub fn abbr(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { let mut argv_read = Vec::with_capacity(argv.len()); argv_read.extend_from_slice(argv); diff --git a/fish-rust/src/builtins/argparse.rs b/fish-rust/src/builtins/argparse.rs index 997db1560..c650aebd5 100644 --- a/fish-rust/src/builtins/argparse.rs +++ b/fish-rust/src/builtins/argparse.rs @@ -83,7 +83,7 @@ fn new() -> Self { fn exec_subshell( cmd: &wstr, - parser: &mut parser_t, + parser: &mut Parser, outputs: &mut Vec, apply_exit_status: bool, ) -> Option { @@ -108,7 +108,7 @@ fn exec_subshell( // a short name we only need to check those. fn check_for_mutually_exclusive_flags( opts: &ArgParseCmdOpts, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { for opt_spec in opts.options.values() { if opt_spec.num_seen == 0 { @@ -178,7 +178,7 @@ fn check_for_mutually_exclusive_flags( // This should be called after all the option specs have been parsed. At that point we have enough // information to parse the values associated with any `--exclusive` flags. -fn parse_exclusive_args(opts: &mut ArgParseCmdOpts, streams: &mut io_streams_t) -> Option { +fn parse_exclusive_args(opts: &mut ArgParseCmdOpts, streams: &mut IoStreams) -> Option { for raw_xflags in &opts.raw_exclusive_flags { let xflags = split_string(raw_xflags, ','); if xflags.len() < 2 { @@ -220,7 +220,7 @@ fn parse_flag_modifiers<'args>( opt_spec: &mut OptionSpec<'args>, option_spec: &wstr, opt_spec_str: &mut &'args wstr, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> bool { let mut s = *opt_spec_str; @@ -286,7 +286,7 @@ fn parse_option_spec_sep<'args>( option_spec: &'args wstr, opt_spec_str: &mut &'args wstr, counter: &mut u32, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> bool { let mut s = *opt_spec_str; let mut i = 1usize; @@ -379,7 +379,7 @@ fn parse_option_spec<'args>( opts: &mut ArgParseCmdOpts<'args>, option_spec: &'args wstr, counter: &mut u32, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> bool { if option_spec.is_empty() { streams.err.append(wgettext_fmt!( @@ -452,7 +452,7 @@ fn collect_option_specs<'args>( optind: &mut usize, argc: usize, args: &[&'args wstr], - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { let cmd: &wstr = args[0]; @@ -499,8 +499,8 @@ fn parse_cmd_opts<'args>( optind: &mut usize, argc: usize, args: &mut [&'args wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Option { let cmd = args[0]; @@ -624,12 +624,12 @@ fn populate_option_strings<'args>( } fn validate_arg<'opts>( - parser: &mut parser_t, + parser: &mut Parser, opts_name: &wstr, opt_spec: &mut OptionSpec<'opts>, is_long_flag: bool, woptarg: &'opts wstr, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { // Obviously if there is no arg validation command we assume the arg is okay. if opt_spec.validation_command.is_empty() { @@ -681,12 +681,12 @@ fn is_implicit_int(opts: &ArgParseCmdOpts, val: &wstr) -> bool { // Store this value under the implicit int option. fn validate_and_store_implicit_int<'args>( - parser: &mut parser_t, + parser: &mut Parser, opts: &mut ArgParseCmdOpts<'args>, val: &'args wstr, w: &mut wgetopter_t, is_long_flag: bool, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { let opt_spec = opts.options.get_mut(&opts.implicit_int_flag).unwrap(); let retval = validate_arg(parser, &opts.name, opt_spec, is_long_flag, val, streams); @@ -705,12 +705,12 @@ fn validate_and_store_implicit_int<'args>( } fn handle_flag<'args>( - parser: &mut parser_t, + parser: &mut Parser, opts: &mut ArgParseCmdOpts<'args>, opt: char, is_long_flag: bool, woptarg: Option<&'args wstr>, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { let opt_spec = opts.options.get_mut(&opt).unwrap(); @@ -754,12 +754,12 @@ fn handle_flag<'args>( } fn argparse_parse_flags<'args>( - parser: &mut parser_t, + parser: &mut Parser, opts: &mut ArgParseCmdOpts<'args>, argc: usize, args: &mut [&'args wstr], optind: &mut usize, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { let mut args_read = Vec::with_capacity(args.len()); args_read.extend_from_slice(args); @@ -855,8 +855,8 @@ fn argparse_parse_args<'args>( opts: &mut ArgParseCmdOpts<'args>, args: &mut [&'args wstr], argc: usize, - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Option { if argc <= 1 { return STATUS_CMD_OK; @@ -880,7 +880,7 @@ fn argparse_parse_args<'args>( fn check_min_max_args_constraints( opts: &ArgParseCmdOpts, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { let cmd = &opts.name; @@ -943,11 +943,7 @@ fn set_argparse_result_vars(vars: &EnvStack, opts: &ArgParseCmdOpts) { /// an external command also means its output has to be in a form that can be eval'd. Because our /// version is a builtin it can directly set variables local to the current scope (e.g., a /// function). It doesn't need to write anything to stdout that then needs to be eval'd. -pub fn argparse( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn argparse(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let cmd = args[0]; let argc = args.len(); diff --git a/fish-rust/src/builtins/bg.rs b/fish-rust/src/builtins/bg.rs index 7e0bf2056..3292e7ebe 100644 --- a/fish-rust/src/builtins/bg.rs +++ b/fish-rust/src/builtins/bg.rs @@ -6,8 +6,8 @@ /// Helper function for builtin_bg(). fn send_to_bg( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, cmd: &wstr, job_pos: usize, ) -> Option { @@ -47,7 +47,7 @@ fn send_to_bg( } /// Builtin for putting a job in the background. -pub fn bg(parser: &mut parser_t, streams: &mut io_streams_t, args: &mut [&wstr]) -> Option { +pub fn bg(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let opts = match HelpOnlyCmdOpts::parse(args, parser, streams) { Ok(opts) => opts, Err(err @ Some(_)) if err != STATUS_CMD_OK => return err, diff --git a/fish-rust/src/builtins/block.rs b/fish-rust/src/builtins/block.rs index b15376822..2a146247e 100644 --- a/fish-rust/src/builtins/block.rs +++ b/fish-rust/src/builtins/block.rs @@ -23,8 +23,8 @@ struct Options { fn parse_options( args: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Result<(Options, usize), Option> { let cmd = args[0]; @@ -71,11 +71,7 @@ fn parse_options( } /// The block builtin, used for temporarily blocking events. -pub fn block( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn block(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let cmd = args[0]; let opts = match parse_options(args, parser, streams) { diff --git a/fish-rust/src/builtins/builtin.rs b/fish-rust/src/builtins/builtin.rs index 7d4d964b6..caf753775 100644 --- a/fish-rust/src/builtins/builtin.rs +++ b/fish-rust/src/builtins/builtin.rs @@ -8,8 +8,8 @@ struct builtin_cmd_opts_t { } pub fn r#builtin( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, argv: &mut [&wstr], ) -> Option { let cmd = argv[0]; diff --git a/fish-rust/src/builtins/cd.rs b/fish-rust/src/builtins/cd.rs index b30693dae..6e29eae33 100644 --- a/fish-rust/src/builtins/cd.rs +++ b/fish-rust/src/builtins/cd.rs @@ -12,7 +12,7 @@ // The cd builtin. Changes the current directory to the one specified or to $HOME if none is // specified. The directory can be relative to any directory in the CDPATH variable. -pub fn cd(parser: &mut parser_t, streams: &mut io_streams_t, args: &mut [&wstr]) -> Option { +pub fn cd(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let cmd = args[0]; let opts = match HelpOnlyCmdOpts::parse(args, parser, streams) { diff --git a/fish-rust/src/builtins/command.rs b/fish-rust/src/builtins/command.rs index d1ffa047c..ffaccbe3e 100644 --- a/fish-rust/src/builtins/command.rs +++ b/fish-rust/src/builtins/command.rs @@ -9,8 +9,8 @@ struct command_cmd_opts_t { } pub fn r#command( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, argv: &mut [&wstr], ) -> Option { let cmd = argv[0]; diff --git a/fish-rust/src/builtins/contains.rs b/fish-rust/src/builtins/contains.rs index 03d331e73..a4e1e0ba5 100644 --- a/fish-rust/src/builtins/contains.rs +++ b/fish-rust/src/builtins/contains.rs @@ -9,8 +9,8 @@ struct Options { fn parse_options( args: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Result<(Options, usize), Option> { let cmd = args[0]; @@ -46,11 +46,7 @@ fn parse_options( /// Implementation of the builtin contains command, used to check if a specified string is part of /// a list. -pub fn contains( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn contains(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let cmd = args[0]; let (opts, optind) = match parse_options(args, parser, streams) { diff --git a/fish-rust/src/builtins/count.rs b/fish-rust/src/builtins/count.rs index b01fbb0ed..d82c97fe8 100644 --- a/fish-rust/src/builtins/count.rs +++ b/fish-rust/src/builtins/count.rs @@ -5,11 +5,7 @@ const COUNT_CHUNK_SIZE: usize = 512 * 256; /// Implementation of the builtin count command, used to count the number of arguments sent to it. -pub fn count( - _parser: &mut parser_t, - streams: &mut io_streams_t, - argv: &mut [&wstr], -) -> Option { +pub fn count(_parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { // Always add the size of argv (minus 0, which is "count"). // That means if you call `something | count a b c`, you'll get the count of something _plus 3_. let mut numargs = argv.len() - 1; diff --git a/fish-rust/src/builtins/echo.rs b/fish-rust/src/builtins/echo.rs index d5a0488dc..86a8c8c0e 100644 --- a/fish-rust/src/builtins/echo.rs +++ b/fish-rust/src/builtins/echo.rs @@ -22,8 +22,8 @@ fn default() -> Self { fn parse_options( args: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Result<(Options, usize), Option> { let cmd = args[0]; @@ -135,11 +135,7 @@ fn parse_numeric_sequence(chars: I) -> Option<(usize, u8)> /// /// Bash only respects `-n` if it's the first argument. We'll do the same. We also support a new, /// fish specific, option `-s` to mean "no spaces". -pub fn echo( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn echo(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let (opts, optind) = match parse_options(args, parser, streams) { Ok((opts, optind)) => (opts, optind), Err(err @ Some(_)) if err != STATUS_CMD_OK => return err, diff --git a/fish-rust/src/builtins/emit.rs b/fish-rust/src/builtins/emit.rs index 014f02187..b7c5eed80 100644 --- a/fish-rust/src/builtins/emit.rs +++ b/fish-rust/src/builtins/emit.rs @@ -2,11 +2,7 @@ use crate::event; #[widestrs] -pub fn emit( - parser: &mut parser_t, - streams: &mut io_streams_t, - argv: &mut [&wstr], -) -> Option { +pub fn emit(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { let cmd = argv[0]; let opts = match HelpOnlyCmdOpts::parse(argv, parser, streams) { diff --git a/fish-rust/src/builtins/exit.rs b/fish-rust/src/builtins/exit.rs index f4ca78129..841617d3b 100644 --- a/fish-rust/src/builtins/exit.rs +++ b/fish-rust/src/builtins/exit.rs @@ -2,11 +2,7 @@ use super::r#return::parse_return_value; /// Function for handling the exit builtin. -pub fn exit( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn exit(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let retval = match parse_return_value(args, parser, streams) { Ok(v) => v, Err(e) => return e, diff --git a/fish-rust/src/builtins/function.rs b/fish-rust/src/builtins/function.rs index 1b0eb536e..e889a004b 100644 --- a/fish-rust/src/builtins/function.rs +++ b/fish-rust/src/builtins/function.rs @@ -3,7 +3,7 @@ use crate::common::{valid_func_name, valid_var_name}; use crate::env::environment::Environment; use crate::event::{self, EventDescription, EventHandler}; -use crate::ffi::io_streams_t as io_streams_ffi_t; +use crate::ffi::IoStreams as io_streams_ffi_t; use crate::function; use crate::global_safety::RelaxedAtomicBool; use crate::parse_tree::NodeRef; @@ -58,7 +58,7 @@ fn default() -> Self { /// \return the internal_job_id for a pid, or None if none. /// This looks through both active and finished jobs. -fn job_id_for_pid(pid: i32, parser: &parser_t) -> Option { +fn job_id_for_pid(pid: i32, parser: &Parser) -> Option { if let Some(job) = parser.job_get_from_pid(pid) { Some(job.get_internal_job_id()) } else { @@ -75,8 +75,8 @@ fn parse_cmd_opts( opts: &mut FunctionCmdOpts, optind: &mut usize, argv: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Option { let cmd = L!("function"); let print_hints = false; @@ -219,7 +219,7 @@ fn validate_function_name( argv: &mut [&wstr], function_name: &mut WString, cmd: &wstr, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { if argv.len() < 2 { // This is currently impossible but let's be paranoid. @@ -252,8 +252,8 @@ fn validate_function_name( /// function. Note this isn't strictly a "builtin": it is called directly from parse_execution. /// That is why its signature is different from the other builtins. pub fn function( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, c_args: &mut [&wstr], func_node: NodeRef, ) -> Option { @@ -377,7 +377,7 @@ pub fn function( } fn builtin_function_ffi( - parser: Pin<&mut parser_t>, + parser: Pin<&mut Parser>, streams: Pin<&mut io_streams_ffi_t>, c_args: &wcstring_list_ffi_t, source_u8: *const u8, // unowned ParsedSourceRefFFI @@ -398,7 +398,7 @@ fn builtin_function_ffi( }; function( parser.unpin(), - &mut io_streams_t::new(streams), + &mut IoStreams::new(streams), args.as_mut_slice(), node, ) @@ -411,8 +411,8 @@ mod builtin_function { include!("ast.h"); include!("parser.h"); include!("io.h"); - type parser_t = crate::ffi::parser_t; - type io_streams_t = crate::ffi::io_streams_t; + type Parser = crate::ffi::Parser; + type IoStreams = crate::ffi::IoStreams; type wcstring_list_ffi_t = crate::ffi::wcstring_list_ffi_t; type BlockStatement = crate::ast::BlockStatement; @@ -420,8 +420,8 @@ mod builtin_function { extern "Rust" { fn builtin_function_ffi( - parser: Pin<&mut parser_t>, - streams: Pin<&mut io_streams_t>, + parser: Pin<&mut Parser>, + streams: Pin<&mut IoStreams>, c_args: &wcstring_list_ffi_t, source: *const u8, // unowned ParsedSourceRefFFI func_node: &BlockStatement, diff --git a/fish-rust/src/builtins/functions.rs b/fish-rust/src/builtins/functions.rs index 57a2f3746..2b3c278a0 100644 --- a/fish-rust/src/builtins/functions.rs +++ b/fish-rust/src/builtins/functions.rs @@ -68,8 +68,8 @@ fn parse_cmd_opts<'args>( opts: &mut FunctionsCmdOpts<'args>, optind: &mut usize, argv: &mut [&'args wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Option { let cmd = L!("functions"); let print_hints = false; @@ -112,8 +112,8 @@ fn parse_cmd_opts<'args>( } pub fn functions( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, args: &mut [&wstr], ) -> Option { let cmd = args[0]; diff --git a/fish-rust/src/builtins/math.rs b/fish-rust/src/builtins/math.rs index 5a2992c73..d6a55cbca 100644 --- a/fish-rust/src/builtins/math.rs +++ b/fish-rust/src/builtins/math.rs @@ -17,8 +17,8 @@ struct Options { #[widestrs] fn parse_cmd_opts( args: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Result<(Options, usize), Option> { const cmd: &wstr = "math"L; let print_hints = true; @@ -161,7 +161,7 @@ fn format_double(mut v: f64, opts: &Options) -> WString { #[widestrs] fn evaluate_expression( cmd: &wstr, - streams: &mut io_streams_t, + streams: &mut IoStreams, opts: &Options, expression: &wstr, ) -> Option { @@ -219,11 +219,7 @@ fn evaluate_expression( /// The math builtin evaluates math expressions. #[widestrs] -pub fn math( - parser: &mut parser_t, - streams: &mut io_streams_t, - argv: &mut [&wstr], -) -> Option { +pub fn math(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { let cmd = argv[0]; let (opts, mut optind) = match parse_cmd_opts(argv, parser, streams) { diff --git a/fish-rust/src/builtins/mod.rs b/fish-rust/src/builtins/mod.rs index c397e7515..79c2bbf71 100644 --- a/fish-rust/src/builtins/mod.rs +++ b/fish-rust/src/builtins/mod.rs @@ -36,7 +36,7 @@ mod prelude { pub use libc::c_int; pub(crate) use crate::{ - ffi::{self, parser_t, separation_type_t, Repin}, + ffi::{self, separation_type_t, Parser, Repin}, wchar::prelude::*, wchar_ffi::{c_str, AsWstr, WCharFromFFI, WCharToFFI}, wgetopt::{ diff --git a/fish-rust/src/builtins/path.rs b/fish-rust/src/builtins/path.rs index 0cb9f47a2..4cd243e48 100644 --- a/fish-rust/src/builtins/path.rs +++ b/fish-rust/src/builtins/path.rs @@ -28,12 +28,7 @@ macro_rules! path_error { }; } -fn path_unknown_option( - parser: &mut parser_t, - streams: &mut io_streams_t, - subcmd: &wstr, - opt: &wstr, -) { +fn path_unknown_option(parser: &mut Parser, streams: &mut IoStreams, subcmd: &wstr, opt: &wstr) { path_error!(streams, BUILTIN_ERR_UNKNOWN, subcmd, opt); builtin_print_error_trailer(parser, streams, L!("path")); } @@ -46,7 +41,7 @@ fn path_unknown_option( fn arguments<'iter, 'args>( args: &'iter [&'args wstr], optind: &'iter mut usize, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Arguments<'args, 'iter> { Arguments::new(args, optind, streams, PATH_CHUNK_SIZE) } @@ -160,7 +155,7 @@ struct Options<'args> { } #[inline] -fn path_out(streams: &mut io_streams_t, opts: &Options<'_>, s: impl AsRef) { +fn path_out(streams: &mut IoStreams, opts: &Options<'_>, s: impl AsRef) { let s = s.as_ref(); if !opts.quiet { if !opts.null_out { @@ -226,8 +221,8 @@ fn parse_opts<'args>( optind: &mut usize, n_req_args: usize, args: &mut [&'args wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Option { let cmd = args[0]; let mut args_read = Vec::with_capacity(args.len()); @@ -366,8 +361,8 @@ fn parse_opts<'args>( } fn path_transform( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, args: &mut [&wstr], func: impl Fn(&wstr) -> WString, ) -> Option { @@ -408,18 +403,14 @@ fn path_transform( } fn path_basename( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, args: &mut [&wstr], ) -> Option { path_transform(parser, streams, args, |s| wbasename(s).to_owned()) } -fn path_dirname( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +fn path_dirname(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { path_transform(parser, streams, args, |s| wdirname(s).to_owned()) } @@ -432,18 +423,14 @@ fn normalize_help(path: &wstr) -> WString { } fn path_normalize( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, args: &mut [&wstr], ) -> Option { path_transform(parser, streams, args, normalize_help) } -fn path_mtime( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +fn path_mtime(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let mut opts = Options::default(); opts.relative_valid = true; let mut optind = 0; @@ -528,8 +515,8 @@ fn test_find_extension() { } fn path_extension( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, args: &mut [&wstr], ) -> Option { let mut opts = Options::default(); @@ -569,8 +556,8 @@ fn path_extension( } fn path_change_extension( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, args: &mut [&wstr], ) -> Option { let mut opts = Options::default(); @@ -617,11 +604,7 @@ fn path_change_extension( } } -fn path_resolve( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +fn path_resolve(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let mut opts = Options::default(); let mut optind = 0; let retval = parse_opts(&mut opts, &mut optind, 0, args, parser, streams); @@ -686,11 +669,7 @@ fn path_resolve( } } -fn path_sort( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +fn path_sort(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let mut opts = Options::default(); opts.reverse_valid = true; opts.unique_valid = true; @@ -856,8 +835,8 @@ fn filter_path(opts: &Options, path: &wstr) -> bool { } fn path_filter_maybe_is( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, args: &mut [&wstr], is_is: bool, ) -> Option { @@ -915,24 +894,16 @@ fn path_filter_maybe_is( } } -fn path_filter( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +fn path_filter(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { path_filter_maybe_is(parser, streams, args, false) } -fn path_is(parser: &mut parser_t, streams: &mut io_streams_t, args: &mut [&wstr]) -> Option { +fn path_is(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { path_filter_maybe_is(parser, streams, args, true) } /// The path builtin, for handling paths. -pub fn path( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn path(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let cmd = args[0]; let argc = args.len(); diff --git a/fish-rust/src/builtins/printf.rs b/fish-rust/src/builtins/printf.rs index 167dd4d06..a87c4e7fa 100644 --- a/fish-rust/src/builtins/printf.rs +++ b/fish-rust/src/builtins/printf.rs @@ -79,7 +79,7 @@ fn iswxdigit(c: char) -> bool { struct builtin_printf_state_t<'a> { // Out and err streams. Note this is a captured reference! - streams: &'a mut io_streams_t, + streams: &'a mut IoStreams, // The status of the operation. exit_code: c_int, @@ -763,11 +763,7 @@ fn append_output(&mut self, c: char) { } /// The printf builtin. -pub fn printf( - _parser: &mut parser_t, - streams: &mut io_streams_t, - argv: &mut [&wstr], -) -> Option { +pub fn printf(_parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { let mut argc = argv.len(); // Rebind argv as immutable slice (can't rearrange its elements), skipping the command name. diff --git a/fish-rust/src/builtins/pwd.rs b/fish-rust/src/builtins/pwd.rs index ff875ddb2..68dafa6d6 100644 --- a/fish-rust/src/builtins/pwd.rs +++ b/fish-rust/src/builtins/pwd.rs @@ -12,7 +12,7 @@ wopt(L!("physical"), no_argument, 'P'), ]; -pub fn pwd(parser: &mut parser_t, streams: &mut io_streams_t, argv: &mut [&wstr]) -> Option { +pub fn pwd(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { let cmd = argv[0]; let argc = argv.len(); let mut resolve_symlinks = false; diff --git a/fish-rust/src/builtins/random.rs b/fish-rust/src/builtins/random.rs index ba4bfe890..bbdc25aec 100644 --- a/fish-rust/src/builtins/random.rs +++ b/fish-rust/src/builtins/random.rs @@ -8,11 +8,7 @@ static RNG: Lazy> = Lazy::new(|| Mutex::new(SmallRng::from_entropy())); -pub fn random( - parser: &mut parser_t, - streams: &mut io_streams_t, - argv: &mut [&wstr], -) -> Option { +pub fn random(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { let cmd = argv[0]; let argc = argv.len(); let print_hints = false; @@ -59,7 +55,7 @@ pub fn random( streams.out.appendln(argv[i + 1 + rand]); return STATUS_CMD_OK; } - fn parse_ll(streams: &mut io_streams_t, cmd: &wstr, num: &wstr) -> Result { + fn parse_ll(streams: &mut IoStreams, cmd: &wstr, num: &wstr) -> Result { let res = fish_wcstol(num); if res.is_err() { streams @@ -68,7 +64,7 @@ fn parse_ll(streams: &mut io_streams_t, cmd: &wstr, num: &wstr) -> Result Result { + fn parse_ull(streams: &mut IoStreams, cmd: &wstr, num: &wstr) -> Result { let res = fish_wcstoul(num); if res.is_err() { streams diff --git a/fish-rust/src/builtins/realpath.rs b/fish-rust/src/builtins/realpath.rs index d5583e7e8..04b3c40af 100644 --- a/fish-rust/src/builtins/realpath.rs +++ b/fish-rust/src/builtins/realpath.rs @@ -22,8 +22,8 @@ struct Options { fn parse_options( args: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Result<(Options, usize), Option> { let cmd = args[0]; @@ -53,11 +53,7 @@ fn parse_options( /// An implementation of the external realpath command. Doesn't support any options. /// In general scripts shouldn't invoke this directly. They should just use `realpath` which /// will fallback to this builtin if an external command cannot be found. -pub fn realpath( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn realpath(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let cmd = args[0]; let (opts, optind) = match parse_options(args, parser, streams) { Ok((opts, optind)) => (opts, optind), diff --git a/fish-rust/src/builtins/return.rs b/fish-rust/src/builtins/return.rs index d04689700..f4ef91445 100644 --- a/fish-rust/src/builtins/return.rs +++ b/fish-rust/src/builtins/return.rs @@ -11,8 +11,8 @@ struct Options { fn parse_options( args: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Result<(Options, usize), Option> { let cmd = args[0]; @@ -46,11 +46,7 @@ fn parse_options( } /// Function for handling the return builtin. -pub fn r#return( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn r#return(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let mut retval = match parse_return_value(args, parser, streams) { Ok(v) => v, Err(e) => return e, @@ -84,8 +80,8 @@ pub fn r#return( pub fn parse_return_value( args: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Result> { let cmd = args[0]; let (opts, optind) = match parse_options(args, parser, streams) { diff --git a/fish-rust/src/builtins/set_color.rs b/fish-rust/src/builtins/set_color.rs index 534079516..db01e88e8 100644 --- a/fish-rust/src/builtins/set_color.rs +++ b/fish-rust/src/builtins/set_color.rs @@ -56,7 +56,7 @@ fn print_modifiers( #[allow(clippy::too_many_arguments)] fn print_colors( - streams: &mut io_streams_t, + streams: &mut IoStreams, args: &[&wstr], bold: bool, underline: bool, @@ -117,8 +117,8 @@ fn print_colors( /// set_color builtin. pub fn set_color( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, argv: &mut [&wstr], ) -> Option { // Variables used for parsing the argument list. diff --git a/fish-rust/src/builtins/shared.rs b/fish-rust/src/builtins/shared.rs index 6f0cbaea0..0eeed629e 100644 --- a/fish-rust/src/builtins/shared.rs +++ b/fish-rust/src/builtins/shared.rs @@ -1,7 +1,7 @@ use crate::builtins::{printf, wait}; use crate::common::str2wcstring; use crate::ffi::separation_type_t; -use crate::ffi::{self, parser_t, wcstring_list_ffi_t, Repin, RustBuiltin}; +use crate::ffi::{self, wcstring_list_ffi_t, Parser, Repin, RustBuiltin}; use crate::wchar::{wstr, WString, L}; use crate::wchar_ffi::{c_str, empty_wstring, ToCppWString, WCharFromFFI}; use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t}; @@ -16,7 +16,7 @@ use std::os::fd::{FromRawFd, RawFd}; use std::pin::Pin; -pub type BuiltinCmd = fn(&mut parser_t, &mut io_streams_t, &mut [&wstr]) -> Option; +pub type BuiltinCmd = fn(&mut Parser, &mut IoStreams, &mut [&wstr]) -> Option; #[cxx::bridge] mod builtins_ffi { @@ -27,14 +27,14 @@ mod builtins_ffi { type wcharz_t = crate::ffi::wcharz_t; type wcstring_list_ffi_t = crate::ffi::wcstring_list_ffi_t; - type parser_t = crate::ffi::parser_t; - type io_streams_t = crate::ffi::io_streams_t; + type Parser = crate::ffi::Parser; + type IoStreams = crate::ffi::IoStreams; type RustBuiltin = crate::ffi::RustBuiltin; } extern "Rust" { fn rust_run_builtin( - parser: Pin<&mut parser_t>, - streams: Pin<&mut io_streams_t>, + parser: Pin<&mut Parser>, + streams: Pin<&mut IoStreams>, cpp_args: &wcstring_list_ffi_t, builtin: RustBuiltin, status_code: &mut i32, @@ -42,8 +42,8 @@ fn rust_run_builtin( } } -unsafe impl ExternType for io_streams_t { - type Id = type_id!("io_streams_t"); +unsafe impl ExternType for IoStreams { + type Id = type_id!("IoStreams"); type Kind = cxx::kind::Opaque; } @@ -143,23 +143,23 @@ pub fn flush_and_check_error(&mut self) -> c_int { } } -// Convenience wrappers around C++ io_streams_t. -pub struct io_streams_t { - streams: *mut builtins_ffi::io_streams_t, +// Convenience wrappers around C++ IoStreams. +pub struct IoStreams { + streams: *mut builtins_ffi::IoStreams, pub out: output_stream_t, pub err: output_stream_t, pub out_is_redirected: bool, pub err_is_redirected: bool, } -impl io_streams_t { - pub fn new(mut streams: Pin<&mut builtins_ffi::io_streams_t>) -> io_streams_t { +impl IoStreams { + pub fn new(mut streams: Pin<&mut builtins_ffi::IoStreams>) -> IoStreams { let out = output_stream_t(streams.as_mut().get_out().unpin()); let err = output_stream_t(streams.as_mut().get_err().unpin()); let out_is_redirected = streams.as_mut().get_out_redirected(); let err_is_redirected = streams.as_mut().get_err_redirected(); let streams = streams.unpin(); - io_streams_t { + IoStreams { streams, out, err, @@ -168,11 +168,11 @@ pub fn new(mut streams: Pin<&mut builtins_ffi::io_streams_t>) -> io_streams_t { } } - pub fn ffi_pin(&mut self) -> Pin<&mut builtins_ffi::io_streams_t> { + pub fn ffi_pin(&mut self) -> Pin<&mut builtins_ffi::IoStreams> { unsafe { Pin::new_unchecked(&mut *self.streams) } } - pub fn ffi_ref(&self) -> &builtins_ffi::io_streams_t { + pub fn ffi_ref(&self) -> &builtins_ffi::IoStreams { unsafe { &*self.streams } } @@ -209,15 +209,15 @@ pub fn truncate_args_on_nul(args: &[WString]) -> Vec<&wstr> { } fn rust_run_builtin( - parser: Pin<&mut parser_t>, - streams: Pin<&mut builtins_ffi::io_streams_t>, + parser: Pin<&mut Parser>, + streams: Pin<&mut builtins_ffi::IoStreams>, cpp_args: &wcstring_list_ffi_t, builtin: RustBuiltin, status_code: &mut i32, ) -> bool { let storage: Vec = cpp_args.from_ffi(); let mut args: Vec<&wstr> = truncate_args_on_nul(&storage); - let streams = &mut io_streams_t::new(streams); + let streams = &mut IoStreams::new(streams); match run_builtin(parser.unpin(), streams, args.as_mut_slice(), builtin) { None => false, @@ -229,8 +229,8 @@ fn rust_run_builtin( } pub fn run_builtin( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, args: &mut [&wstr], builtin: RustBuiltin, ) -> Option { @@ -267,8 +267,8 @@ pub fn run_builtin( // Covers of these functions that take care of the pinning, etc. // These all return STATUS_INVALID_ARGS. pub fn builtin_missing_argument( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, cmd: &wstr, opt: &wstr, print_hints: bool, @@ -283,8 +283,8 @@ pub fn builtin_missing_argument( } pub fn builtin_unknown_option( - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, cmd: &wstr, opt: &wstr, print_hints: bool, @@ -298,7 +298,7 @@ pub fn builtin_unknown_option( ); } -pub fn builtin_print_help(parser: &mut parser_t, streams: &io_streams_t, cmd: &wstr) { +pub fn builtin_print_help(parser: &mut Parser, streams: &IoStreams, cmd: &wstr) { ffi::builtin_print_help( parser.pin(), streams.ffi_ref(), @@ -307,7 +307,7 @@ pub fn builtin_print_help(parser: &mut parser_t, streams: &io_streams_t, cmd: &w ); } -pub fn builtin_print_error_trailer(parser: &mut parser_t, streams: &mut io_streams_t, cmd: &wstr) { +pub fn builtin_print_error_trailer(parser: &mut Parser, streams: &mut IoStreams, cmd: &wstr) { ffi::builtin_print_error_trailer(parser.pin(), streams.err.ffi(), c_str!(cmd)); } @@ -319,8 +319,8 @@ pub struct HelpOnlyCmdOpts { impl HelpOnlyCmdOpts { pub fn parse( args: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Result> { let cmd = args[0]; let print_hints = true; @@ -400,7 +400,7 @@ impl<'args, 'iter> Arguments<'args, 'iter> { pub fn new( args: &'iter [&'args wstr], argidx: &'iter mut usize, - streams: &mut io_streams_t, + streams: &mut IoStreams, chunk_size: usize, ) -> Self { let reader = streams.stdin_is_directly_redirected().then(|| { diff --git a/fish-rust/src/builtins/status.rs b/fish-rust/src/builtins/status.rs index 70387d357..8e1baa722 100644 --- a/fish-rust/src/builtins/status.rs +++ b/fish-rust/src/builtins/status.rs @@ -164,7 +164,7 @@ fn default() -> Self { ]; /// Print the features and their values. -fn print_features(streams: &mut io_streams_t) { +fn print_features(streams: &mut IoStreams) { // TODO: move this to features.rs let mut max_len = i32::MIN; for md in features::METADATA { @@ -191,8 +191,8 @@ fn parse_cmd_opts( opts: &mut StatusCmdOpts, optind: &mut usize, args: &mut [&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Option { let cmd = args[0]; @@ -305,11 +305,7 @@ fn parse_cmd_opts( return STATUS_CMD_OK; } -pub fn status( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn status(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let cmd = args[0]; let argc = args.len(); diff --git a/fish-rust/src/builtins/string.rs b/fish-rust/src/builtins/string.rs index 3564590ce..2a5342864 100644 --- a/fish-rust/src/builtins/string.rs +++ b/fish-rust/src/builtins/string.rs @@ -31,12 +31,7 @@ macro_rules! string_error { } use string_error; -fn string_unknown_option( - parser: &mut parser_t, - streams: &mut io_streams_t, - subcmd: &wstr, - opt: &wstr, -) { +fn string_unknown_option(parser: &mut Parser, streams: &mut IoStreams, subcmd: &wstr, opt: &wstr) { string_error!(streams, BUILTIN_ERR_UNKNOWN, subcmd, opt); builtin_print_error_trailer(parser, streams, L!("string")); } @@ -56,8 +51,8 @@ fn parse_opt( fn parse_opts( &mut self, args: &mut [&'args wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, ) -> Result> { let cmd = args[0]; let mut args_read = Vec::with_capacity(args.len()); @@ -94,7 +89,7 @@ fn take_args( &mut self, optind: &mut usize, args: &[&'args wstr], - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { STATUS_CMD_OK } @@ -102,16 +97,16 @@ fn take_args( /// Perform the business logic of the command. fn handle( &mut self, - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&'args wstr], ) -> Option; fn run( &mut self, - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, args: &mut [&'args wstr], ) -> Option { if args.len() >= 3 && (args[2] == "-h" || args[2] == "--help") { @@ -155,7 +150,7 @@ enum RegexError { } impl RegexError { - fn print_error(&self, args: &[&wstr], streams: &mut io_streams_t) { + fn print_error(&self, args: &[&wstr], streams: &mut IoStreams) { let cmd = args[0]; use RegexError::*; match self { @@ -204,8 +199,8 @@ impl StringError { fn print_error( &self, args: &[&wstr], - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, optarg: Option<&wstr>, optind: usize, ) { @@ -290,17 +285,13 @@ fn escape_code_length(code: &wstr) -> Option { fn arguments<'iter, 'args>( args: &'iter [&'args wstr], argidx: &'iter mut usize, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Arguments<'args, 'iter> { Arguments::new(args, argidx, streams, STRING_CHUNK_SIZE) } /// The string builtin, for manipulating strings. -pub fn string( - parser: &mut parser_t, - streams: &mut io_streams_t, - args: &mut [&wstr], -) -> Option { +pub fn string(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option { let cmd = args[0]; let argc = args.len(); diff --git a/fish-rust/src/builtins/string/collect.rs b/fish-rust/src/builtins/string/collect.rs index 9ddcecb94..55cef1749 100644 --- a/fish-rust/src/builtins/string/collect.rs +++ b/fish-rust/src/builtins/string/collect.rs @@ -24,8 +24,8 @@ fn parse_opt(&mut self, _n: &wstr, c: char, _arg: Option<&wstr>) -> Result<(), S fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/escape.rs b/fish-rust/src/builtins/string/escape.rs index 008e87236..7a13e6c6f 100644 --- a/fish-rust/src/builtins/string/escape.rs +++ b/fish-rust/src/builtins/string/escape.rs @@ -30,8 +30,8 @@ fn parse_opt(&mut self, name: &wstr, c: char, arg: Option<&wstr>) -> Result<(), fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/join.rs b/fish-rust/src/builtins/string/join.rs index 1bbff0131..2587f9916 100644 --- a/fish-rust/src/builtins/string/join.rs +++ b/fish-rust/src/builtins/string/join.rs @@ -38,7 +38,7 @@ fn take_args( &mut self, optind: &mut usize, args: &[&'args wstr], - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { if self.is_join0 { return STATUS_CMD_OK; @@ -56,8 +56,8 @@ fn take_args( fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/length.rs b/fish-rust/src/builtins/string/length.rs index 1d0aff9e8..f42faa1d7 100644 --- a/fish-rust/src/builtins/string/length.rs +++ b/fish-rust/src/builtins/string/length.rs @@ -26,8 +26,8 @@ fn parse_opt(&mut self, _n: &wstr, c: char, _arg: Option<&wstr>) -> Result<(), S fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/match.rs b/fish-rust/src/builtins/string/match.rs index 62c268cbb..f95d48332 100644 --- a/fish-rust/src/builtins/string/match.rs +++ b/fish-rust/src/builtins/string/match.rs @@ -53,7 +53,7 @@ fn take_args( &mut self, optind: &mut usize, args: &[&'args wstr], - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { let cmd = args[0]; let Some(arg) = args.get(*optind).copied() else { @@ -67,8 +67,8 @@ fn take_args( fn handle( &mut self, - parser: &mut parser_t, - streams: &mut io_streams_t, + parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { @@ -172,11 +172,7 @@ fn new( } } - fn report_matches( - &mut self, - arg: &wstr, - streams: &mut io_streams_t, - ) -> Result<(), pcre2::Error> { + fn report_matches(&mut self, arg: &wstr, streams: &mut IoStreams) -> Result<(), pcre2::Error> { match self { Self::Regex(m) => m.report_matches(arg, streams)?, Self::WildCard(m) => m.report_matches(arg, streams), @@ -230,11 +226,7 @@ fn new( return Ok(m); } - fn report_matches( - &mut self, - arg: &wstr, - streams: &mut io_streams_t, - ) -> Result<(), pcre2::Error> { + fn report_matches(&mut self, arg: &wstr, streams: &mut IoStreams) -> Result<(), pcre2::Error> { let mut iter = self.regex.captures_iter(arg.as_char_slice()); let cg = iter.next().transpose()?; let rc = self.report_match(arg, cg, streams); @@ -307,7 +299,7 @@ fn report_match<'a>( &self, arg: &'a wstr, cg: Option>, - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> MatchResult<'a> { let Some(cg) = cg else { if self.opts.invert_match && !self.opts.quiet { @@ -376,7 +368,7 @@ fn new(pattern: &'args wstr, opts: &'opts Match<'args>) -> Self { } } - fn report_matches(&mut self, arg: &wstr, streams: &mut io_streams_t) { + fn report_matches(&mut self, arg: &wstr, streams: &mut IoStreams) { // Note: --all is a no-op for glob matching since the pattern is always matched // against the entire argument. let subject = match self.opts.ignore_case { diff --git a/fish-rust/src/builtins/string/pad.rs b/fish-rust/src/builtins/string/pad.rs index 86c151b29..9bd4e7ed4 100644 --- a/fish-rust/src/builtins/string/pad.rs +++ b/fish-rust/src/builtins/string/pad.rs @@ -65,8 +65,8 @@ fn parse_opt(&mut self, name: &wstr, c: char, arg: Option<&wstr>) -> Result<(), fn handle<'args>( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&'args wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/repeat.rs b/fish-rust/src/builtins/string/repeat.rs index acc7f3023..47102cfc5 100644 --- a/fish-rust/src/builtins/string/repeat.rs +++ b/fish-rust/src/builtins/string/repeat.rs @@ -39,8 +39,8 @@ fn parse_opt(&mut self, name: &wstr, c: char, arg: Option<&wstr>) -> Result<(), fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/replace.rs b/fish-rust/src/builtins/string/replace.rs index a76f2b940..edcafddd0 100644 --- a/fish-rust/src/builtins/string/replace.rs +++ b/fish-rust/src/builtins/string/replace.rs @@ -41,7 +41,7 @@ fn take_args( &mut self, optind: &mut usize, args: &[&'args wstr], - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { let cmd = args[0]; let Some(pattern) = args.get(*optind).copied() else { @@ -62,8 +62,8 @@ fn take_args( fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/shorten.rs b/fish-rust/src/builtins/string/shorten.rs index 0dfec32cb..553a1630c 100644 --- a/fish-rust/src/builtins/string/shorten.rs +++ b/fish-rust/src/builtins/string/shorten.rs @@ -64,8 +64,8 @@ fn parse_opt( fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/split.rs b/fish-rust/src/builtins/string/split.rs index 5438d0527..ef9684ace 100644 --- a/fish-rust/src/builtins/string/split.rs +++ b/fish-rust/src/builtins/string/split.rs @@ -146,7 +146,7 @@ fn take_args( &mut self, optind: &mut usize, args: &[&'args wstr], - streams: &mut io_streams_t, + streams: &mut IoStreams, ) -> Option { if self.is_split0 { return STATUS_CMD_OK; @@ -162,8 +162,8 @@ fn take_args( fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&'args wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/sub.rs b/fish-rust/src/builtins/string/sub.rs index 9ca20fd75..9fe94aada 100644 --- a/fish-rust/src/builtins/string/sub.rs +++ b/fish-rust/src/builtins/string/sub.rs @@ -49,8 +49,8 @@ fn parse_opt(&mut self, name: &wstr, c: char, arg: Option<&wstr>) -> Result<(), fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/transform.rs b/fish-rust/src/builtins/string/transform.rs index 8ed6c2cce..3c2ca93d1 100644 --- a/fish-rust/src/builtins/string/transform.rs +++ b/fish-rust/src/builtins/string/transform.rs @@ -18,8 +18,8 @@ fn parse_opt(&mut self, _n: &wstr, c: char, _arg: Option<&wstr>) -> Result<(), S fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/trim.rs b/fish-rust/src/builtins/string/trim.rs index f11a50a8f..f40d77505 100644 --- a/fish-rust/src/builtins/string/trim.rs +++ b/fish-rust/src/builtins/string/trim.rs @@ -46,8 +46,8 @@ fn parse_opt( fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/string/unescape.rs b/fish-rust/src/builtins/string/unescape.rs index 0f311ee54..f39a057b5 100644 --- a/fish-rust/src/builtins/string/unescape.rs +++ b/fish-rust/src/builtins/string/unescape.rs @@ -32,8 +32,8 @@ fn parse_opt(&mut self, name: &wstr, c: char, arg: Option<&wstr>) -> Result<(), fn handle( &mut self, - _parser: &mut parser_t, - streams: &mut io_streams_t, + _parser: &mut Parser, + streams: &mut IoStreams, optind: &mut usize, args: &[&wstr], ) -> Option { diff --git a/fish-rust/src/builtins/test.rs b/fish-rust/src/builtins/test.rs index d3bc785da..109eb18a5 100644 --- a/fish-rust/src/builtins/test.rs +++ b/fish-rust/src/builtins/test.rs @@ -82,7 +82,7 @@ pub(super) fn new(base: i64, delta: f64) -> Self { } // Return true if the number is a tty(). - fn isatty(&self, streams: &io_streams_t) -> bool { + fn isatty(&self, streams: &IoStreams) -> bool { fn istty(fd: libc::c_int) -> bool { // Safety: isatty cannot crash. unsafe { libc::isatty(fd) > 0 } @@ -211,7 +211,7 @@ fn add_error(&mut self, idx: usize, text: WString) { /// Base trait for expressions. pub(super) trait Expression { /// Evaluate returns true if the expression is true (i.e. STATUS_CMD_OK). - fn evaluate(&self, streams: &mut io_streams_t, errors: &mut Vec) -> bool; + fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec) -> bool; /// Return base.range. fn range(&self) -> Range; @@ -264,7 +264,7 @@ struct ParentheticalExpression { } impl Expression for UnaryPrimary { - fn evaluate(&self, streams: &mut io_streams_t, errors: &mut Vec) -> bool { + fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec) -> bool { unary_primary_evaluate(self.token, &self.arg, streams, errors) } @@ -274,7 +274,7 @@ fn range(&self) -> Range { } impl Expression for BinaryPrimary { - fn evaluate(&self, _streams: &mut io_streams_t, errors: &mut Vec) -> bool { + fn evaluate(&self, _streams: &mut IoStreams, errors: &mut Vec) -> bool { binary_primary_evaluate(self.token, &self.arg_left, &self.arg_right, errors) } @@ -284,7 +284,7 @@ fn range(&self) -> Range { } impl Expression for UnaryOperator { - fn evaluate(&self, streams: &mut io_streams_t, errors: &mut Vec) -> bool { + fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec) -> bool { if self.token == Token::bang { !self.subject.evaluate(streams, errors) } else { @@ -299,7 +299,7 @@ fn range(&self) -> Range { } impl Expression for CombiningExpression { - fn evaluate(&self, streams: &mut io_streams_t, errors: &mut Vec) -> bool { + fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec) -> bool { let _res = self.subjects[0].evaluate(streams, errors); if self.token == Token::combine_and || self.token == Token::combine_or { assert!(!self.subjects.is_empty()); @@ -352,7 +352,7 @@ fn range(&self) -> Range { } impl Expression for ParentheticalExpression { - fn evaluate(&self, streams: &mut io_streams_t, errors: &mut Vec) -> bool { + fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec) -> bool { self.contents.evaluate(streams, errors) } @@ -886,7 +886,7 @@ fn binary_primary_evaluate( fn unary_primary_evaluate( token: Token, arg: &wstr, - streams: &mut io_streams_t, + streams: &mut IoStreams, errors: &mut Vec, ) -> bool { const S_ISGID: u32 = 0o2000; @@ -1003,11 +1003,7 @@ fn stat_and(arg: &wstr, f: F) -> bool /// Evaluate a conditional expression given the arguments. For POSIX conformance this /// supports a more limited range of functionality. /// Return status is the final shell status, i.e. 0 for true, 1 for false and 2 for error. -pub fn test( - parser: &mut parser_t, - streams: &mut io_streams_t, - argv: &mut [&wstr], -) -> Option { +pub fn test(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { // The first argument should be the name of the command ('test'). if argv.is_empty() { return STATUS_INVALID_ARGS; diff --git a/fish-rust/src/builtins/tests/string_tests.rs b/fish-rust/src/builtins/tests/string_tests.rs index 920613513..00c25d320 100644 --- a/fish-rust/src/builtins/tests/string_tests.rs +++ b/fish-rust/src/builtins/tests/string_tests.rs @@ -1,7 +1,7 @@ use crate::ffi_tests::add_test; add_test! {"test_string", || { - use crate::ffi::parser_t; + use crate::ffi::Parser; use crate::ffi; use crate::builtins::string::string; use crate::wchar_ffi::WCharFromFFI; @@ -20,9 +20,9 @@ macro_rules! test_cases { // TODO: these should be individual tests, not all in one, port when we can run these with `cargo test` fn string_test(mut args: Vec<&wstr>, expected_rc: Option, expected_out: &wstr) { - let parser: &mut parser_t = unsafe { &mut *parser_t::principal_parser_ffi() }; + let parser: &mut Parser = unsafe { &mut *Parser::principal_parser_ffi() }; let mut streams = ffi::make_test_io_streams_ffi(); - let mut io = crate::builtins::shared::io_streams_t::new(streams.pin_mut()); + let mut io = crate::builtins::shared::IoStreams::new(streams.pin_mut()); let rc = string(parser, &mut io, args.as_mut_slice()).expect("string failed"); diff --git a/fish-rust/src/builtins/tests/test_tests.rs b/fish-rust/src/builtins/tests/test_tests.rs index b01525ef6..0c6bee568 100644 --- a/fish-rust/src/builtins/tests/test_tests.rs +++ b/fish-rust/src/builtins/tests/test_tests.rs @@ -4,7 +4,7 @@ use crate::ffi::make_null_io_streams_ffi; fn run_one_test_test_mbracket(expected: i32, lst: &[&str], bracket: bool) -> bool { - let parser: &mut parser_t = unsafe { &mut *parser_t::principal_parser_ffi() }; + let parser: &mut Parser = unsafe { &mut *Parser::principal_parser_ffi() }; let mut argv = Vec::new(); if bracket { argv.push(L!("[").to_owned()); @@ -22,7 +22,7 @@ fn run_one_test_test_mbracket(expected: i32, lst: &[&str], bracket: bool) -> boo let mut argv = argv.iter().map(|s| s.as_ref()).collect::>(); let mut streams_ffi = make_null_io_streams_ffi(); - let mut streams = io_streams_t::new(streams_ffi.as_mut().unwrap()); + let mut streams = IoStreams::new(streams_ffi.as_mut().unwrap()); let result: Option = builtin_test(parser, &mut streams, &mut argv); if result != Some(expected) { @@ -48,9 +48,9 @@ fn run_test_test(expected: i32, lst: &[&str]) -> bool { #[widestrs] fn test_test_brackets() { // Ensure [ knows it needs a ]. - let parser: &mut parser_t = unsafe { &mut *parser_t::principal_parser_ffi() }; + let parser: &mut Parser = unsafe { &mut *Parser::principal_parser_ffi() }; let mut streams_ffi = make_null_io_streams_ffi(); - let mut streams = io_streams_t::new(streams_ffi.as_mut().unwrap()); + let mut streams = IoStreams::new(streams_ffi.as_mut().unwrap()); let args1 = &mut ["["L, "foo"L]; assert_eq!( diff --git a/fish-rust/src/builtins/type.rs b/fish-rust/src/builtins/type.rs index ba8aaed3d..1c83e03d4 100644 --- a/fish-rust/src/builtins/type.rs +++ b/fish-rust/src/builtins/type.rs @@ -16,11 +16,7 @@ struct type_cmd_opts_t { query: bool, } -pub fn r#type( - parser: &mut parser_t, - streams: &mut io_streams_t, - argv: &mut [&wstr], -) -> Option { +pub fn r#type(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { let cmd = argv[0]; let argc = argv.len(); let print_hints = false; diff --git a/fish-rust/src/builtins/wait.rs b/fish-rust/src/builtins/wait.rs index 0c30db445..f8b6e838a 100644 --- a/fish-rust/src/builtins/wait.rs +++ b/fish-rust/src/builtins/wait.rs @@ -1,7 +1,7 @@ use libc::pid_t; use super::prelude::*; -use crate::ffi::{job_t, parser_t, proc_wait_any}; +use crate::ffi::{job_t, proc_wait_any, Parser}; use crate::signal::SigChecker; use crate::wait_handle::{WaitHandleRef, WaitHandleStore}; use crate::wutil; @@ -35,7 +35,7 @@ enum WaitHandleQuery<'a> { /// \return true if we found a matching job (even if not waitable), false if not. fn find_wait_handles( query: WaitHandleQuery<'_>, - parser: &mut parser_t, + parser: &mut Parser, handles: &mut Vec, ) -> bool { // Has a job already completed? @@ -72,7 +72,7 @@ fn find_wait_handles( matched } -fn get_all_wait_handles(parser: &parser_t) -> Vec { +fn get_all_wait_handles(parser: &Parser) -> Vec { // Get wait handles for reaped jobs. let mut result = parser.get_wait_handles().get_list(); @@ -99,7 +99,7 @@ fn is_completed(wh: &WaitHandleRef) -> bool { /// If \p any_flag is set, wait for the first one; otherwise wait for all. /// \return a status code. fn wait_for_completion( - parser: &mut parser_t, + parser: &mut Parser, whs: &[WaitHandleRef], any_flag: bool, ) -> Option { @@ -135,11 +135,7 @@ fn wait_for_completion( } #[widestrs] -pub fn wait( - parser: &mut parser_t, - streams: &mut io_streams_t, - argv: &mut [&wstr], -) -> Option { +pub fn wait(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option { let cmd = argv[0]; let argc = argv.len(); let mut any_flag = false; // flag for -n option diff --git a/fish-rust/src/event.rs b/fish-rust/src/event.rs index 2a72631d5..6460dc096 100644 --- a/fish-rust/src/event.rs +++ b/fish-rust/src/event.rs @@ -12,9 +12,9 @@ use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; use std::sync::{Arc, Mutex}; -use crate::builtins::shared::io_streams_t; +use crate::builtins::shared::IoStreams; use crate::common::{escape_string, scoped_push, EscapeFlags, EscapeStringStyle, ScopeGuard}; -use crate::ffi::{self, block_t, parser_t, Repin}; +use crate::ffi::{self, block_t, Parser, Repin}; use crate::flog::FLOG; use crate::job_group::{JobId, MaybeJobId}; use crate::signal::{signal_check_cancel, signal_handle, Signal}; @@ -29,8 +29,8 @@ mod event_ffi { include!("parser.h"); include!("io.h"); type wcharz_t = crate::ffi::wcharz_t; - type parser_t = crate::ffi::parser_t; - type io_streams_t = crate::ffi::io_streams_t; + type Parser = crate::ffi::Parser; + type IoStreams = crate::ffi::IoStreams; } enum event_type_t { @@ -77,18 +77,18 @@ struct event_description_t { fn set_removed(self: &mut EventHandler); fn event_fire_generic_ffi( - parser: Pin<&mut parser_t>, + parser: Pin<&mut Parser>, name: &CxxWString, arguments: &CxxVector, ); #[cxx_name = "event_get_desc"] - fn event_get_desc_ffi(parser: &parser_t, evt: &Event) -> UniquePtr; + fn event_get_desc_ffi(parser: &Parser, evt: &Event) -> UniquePtr; #[cxx_name = "event_fire_delayed"] - fn event_fire_delayed_ffi(parser: Pin<&mut parser_t>); + fn event_fire_delayed_ffi(parser: Pin<&mut Parser>); #[cxx_name = "event_fire"] - fn event_fire_ffi(parser: Pin<&mut parser_t>, event: &Event); + fn event_fire_ffi(parser: Pin<&mut Parser>, event: &Event); #[cxx_name = "event_print"] - fn event_print_ffi(streams: Pin<&mut io_streams_t>, type_filter: &CxxWString); + fn event_print_ffi(streams: Pin<&mut IoStreams>, type_filter: &CxxWString); #[cxx_name = "event_enqueue_signal"] fn enqueue_signal(signal: i32); @@ -408,7 +408,7 @@ pub fn caller_exit(internal_job_id: u64, job_id: MaybeJobId) -> Self { } /// Test if specified event is blocked. - fn is_blocked(&self, parser: &mut parser_t) -> bool { + fn is_blocked(&self, parser: &mut Parser) -> bool { let mut i = 0; while let Some(block) = parser.get_block_at_index(i) { i += 1; @@ -564,7 +564,7 @@ pub fn is_signal_observed(sig: libc::c_int) -> bool { .map_or(false, |s| s.load(Ordering::Relaxed) > 0) } -pub fn get_desc(parser: &parser_t, evt: &Event) -> WString { +pub fn get_desc(parser: &Parser, evt: &Event) -> WString { let s = match &evt.desc { EventDescription::Signal { signal } => { format!("signal handler for {} ({})", signal.name(), signal.desc(),) @@ -592,7 +592,7 @@ pub fn get_desc(parser: &parser_t, evt: &Event) -> WString { WString::from_str(&s) } -fn event_get_desc_ffi(parser: &parser_t, evt: &Event) -> UniquePtr { +fn event_get_desc_ffi(parser: &Parser, evt: &Event) -> UniquePtr { get_desc(parser, evt).to_ffi() } @@ -661,7 +661,7 @@ fn event_get_function_handler_descs_ffi(name: &CxxWString) -> Vec= 0, "is_event should not be negative" @@ -746,7 +746,7 @@ fn fire_internal(parser: &mut parser_t, event: &Event) { } /// Fire all delayed events attached to the given parser. -pub fn fire_delayed(parser: &mut parser_t) { +pub fn fire_delayed(parser: &mut Parser) { let ld = parser.libdata_pod(); // Do not invoke new event handlers from within event handlers. @@ -760,7 +760,7 @@ pub fn fire_delayed(parser: &mut parser_t) { // We unfortunately can't keep this locked until we're done with it because the SIGWINCH handler // code might call back into here and we would delay processing of the events, leading to a test - // failure under CI. (Yes, the `&mut parser_t` is a lie.) + // failure under CI. (Yes, the `&mut Parser` is a lie.) let mut to_send = std::mem::take(&mut *BLOCKED_EVENTS.lock().expect("Mutex poisoned!")); // Append all signal events to to_send. @@ -799,7 +799,7 @@ pub fn fire_delayed(parser: &mut parser_t) { } } -fn event_fire_delayed_ffi(parser: Pin<&mut parser_t>) { +fn event_fire_delayed_ffi(parser: Pin<&mut Parser>) { fire_delayed(parser.unpin()) } @@ -810,7 +810,7 @@ pub fn enqueue_signal(signal: libc::c_int) { } /// Fire the specified event event, executing it on `parser`. -pub fn fire(parser: &mut parser_t, event: Event) { +pub fn fire(parser: &mut Parser, event: Event) { // Fire events triggered by signals. fire_delayed(parser); @@ -821,7 +821,7 @@ pub fn fire(parser: &mut parser_t, event: Event) { } } -fn event_fire_ffi(parser: Pin<&mut parser_t>, event: &Event) { +fn event_fire_ffi(parser: Pin<&mut Parser>, event: &Event) { fire(parser.unpin(), event.clone()) } @@ -837,7 +837,7 @@ fn event_fire_ffi(parser: Pin<&mut parser_t>, event: &Event) { ]; /// Print all events. If type_filter is not empty, only output events with that type. -pub fn print(streams: &mut io_streams_t, type_filter: &wstr) { +pub fn print(streams: &mut IoStreams, type_filter: &wstr) { let mut tmp = EVENT_HANDLERS .lock() .expect("event handler list should not be poisoned") @@ -892,13 +892,13 @@ pub fn print(streams: &mut io_streams_t, type_filter: &wstr) { } } -fn event_print_ffi(streams: Pin<&mut ffi::io_streams_t>, type_filter: &CxxWString) { - let mut streams = io_streams_t::new(streams); +fn event_print_ffi(streams: Pin<&mut ffi::IoStreams>, type_filter: &CxxWString) { + let mut streams = IoStreams::new(streams); print(&mut streams, type_filter.as_wstr()); } /// Fire a generic event with the specified name. -pub fn fire_generic(parser: &mut parser_t, name: WString, arguments: Vec) { +pub fn fire_generic(parser: &mut Parser, name: WString, arguments: Vec) { fire( parser, Event { @@ -909,7 +909,7 @@ pub fn fire_generic(parser: &mut parser_t, name: WString, arguments: Vec, + parser: Pin<&mut Parser>, name: &CxxWString, arguments: &CxxVector, ) { diff --git a/fish-rust/src/ffi.rs b/fish-rust/src/ffi.rs index fdfa22ce7..bcaf3f89a 100644 --- a/fish-rust/src/ffi.rs +++ b/fish-rust/src/ffi.rs @@ -94,7 +94,7 @@ generate!("wgettext_ptr") generate!("block_t") - generate!("parser_t") + generate!("Parser") generate!("job_t") generate!("job_control_t") @@ -112,7 +112,7 @@ generate!("proc_wait_any") generate!("output_stream_t") - generate!("io_streams_t") + generate!("IoStreams") generate!("make_null_io_streams_ffi") generate!("make_test_io_streams_ffi") generate!("get_test_output_ffi") @@ -173,7 +173,7 @@ generate!("is_thompson_shell_script") } -impl parser_t { +impl Parser { pub fn get_wait_handles_mut(&mut self) -> &mut WaitHandleStore { let ptr = self.get_wait_handles_void() as *mut Box; assert!(!ptr.is_null()); @@ -341,11 +341,11 @@ fn from(w: wcharz_t) -> Self { /// A bogus trait for turning &mut Foo into Pin<&mut Foo>. /// autocxx enforces that non-const methods must be called through Pin, -/// but this means we can't pass around mutable references to types like parser_t. -/// We also don't want to assert that parser_t is Unpin. +/// but this means we can't pass around mutable references to types like Parser. +/// We also don't want to assert that Parser is Unpin. /// So we just allow constructing a pin from a mutable reference; none of the C++ code. /// It's worth considering disabling this in cxx; for now we use this trait. -/// Eventually parser_t and io_streams_t will not require Pin so we just unsafe-it away. +/// Eventually Parser and IoStreams will not require Pin so we just unsafe-it away. pub trait Repin { fn pin(&mut self) -> Pin<&mut Self> { unsafe { Pin::new_unchecked(self) } @@ -361,10 +361,10 @@ impl Repin for autoload_t {} impl Repin for block_t {} impl Repin for env_stack_t {} impl Repin for env_universal_t {} -impl Repin for io_streams_t {} +impl Repin for IoStreams {} impl Repin for job_t {} impl Repin for output_stream_t {} -impl Repin for parser_t {} +impl Repin for Parser {} impl Repin for process_t {} impl Repin for wcstring_list_ffi_t {} diff --git a/fish-rust/src/fish.rs b/fish-rust/src/fish.rs index 5c9c70dc1..b598f7835 100644 --- a/fish-rust/src/fish.rs +++ b/fish-rust/src/fish.rs @@ -264,7 +264,7 @@ fn determine_config_directory_paths(argv0: impl AsRef) -> ConfigPaths { } // Source the file config.fish in the given directory. -fn source_config_in_directory(parser: &mut ffi::parser_t, dir: &wstr) { +fn source_config_in_directory(parser: &mut ffi::Parser, dir: &wstr) { // If the config.fish file doesn't exist or isn't readable silently return. Fish versions up // thru 2.2.0 would instead try to source the file with stderr redirected to /dev/null to deal // with that possibility. @@ -296,7 +296,7 @@ fn source_config_in_directory(parser: &mut ffi::parser_t, dir: &wstr) { } /// Parse init files. exec_path is the path of fish executable as determined by argv[0]. -fn read_init(parser: &mut ffi::parser_t, paths: &ConfigPaths) { +fn read_init(parser: &mut ffi::Parser, paths: &ConfigPaths) { source_config_in_directory(parser, &str2wcstring(paths.data.as_os_str().as_bytes())); source_config_in_directory(parser, &str2wcstring(paths.sysconf.as_os_str().as_bytes())); @@ -308,7 +308,7 @@ fn read_init(parser: &mut ffi::parser_t, paths: &ConfigPaths) { } } -fn run_command_list(parser: &mut ffi::parser_t, cmds: &[OsString]) -> i32 { +fn run_command_list(parser: &mut ffi::Parser, cmds: &[OsString]) -> i32 { let mut retval = STATUS_CMD_OK; for cmd in cmds { let cmd_wcs = str2wcstring(cmd.as_bytes()); @@ -671,7 +671,7 @@ fn main() -> i32 { ffi::misc_init(); ffi::reader_init(); - let parser = unsafe { &mut *ffi::parser_t::principal_parser_ffi() }; + let parser = unsafe { &mut *ffi::Parser::principal_parser_ffi() }; parser.pin().set_syncs_uvars(!opts.no_config); if !opts.no_exec && !opts.no_config { diff --git a/fish-rust/src/function.rs b/fish-rust/src/function.rs index 41e5535d6..f1b611d2a 100644 --- a/fish-rust/src/function.rs +++ b/fish-rust/src/function.rs @@ -6,7 +6,7 @@ use crate::common::{assert_sync, escape, valid_func_name, FilenameRef}; use crate::env::{EnvStack, Environment}; use crate::event::{self, EventDescription}; -use crate::ffi::{self, parser_t, Repin}; +use crate::ffi::{self, Parser, Repin}; use crate::global_safety::RelaxedAtomicBool; use crate::parse_tree::{NodeRef, ParsedSourceRefFFI}; use crate::parser_keywords::parser_keywords_is_reserved; @@ -114,7 +114,7 @@ unsafe impl Send for FunctionSet {} /// Make sure that if the specified function is a dynamically loaded function, it has been fully /// loaded. Note this executes fish script code. -fn load(name: &wstr, parser: &mut parser_t) -> bool { +fn load(name: &wstr, parser: &mut Parser) -> bool { parser.assert_can_execute(); let mut path_to_autoload: Option = None; // Note we can't autoload while holding the funcset lock. @@ -219,7 +219,7 @@ pub fn get_props(name: &wstr) -> Option> { } /// \return the properties for a function, or None, perhaps triggering autoloading. -pub fn get_props_autoload(name: &wstr, parser: &mut parser_t) -> Option> { +pub fn get_props_autoload(name: &wstr, parser: &mut Parser) -> Option> { parser.assert_can_execute(); if parser_keywords_is_reserved(name) { return None; @@ -230,7 +230,7 @@ pub fn get_props_autoload(name: &wstr, parser: &mut parser_t) -> Option bool { +pub fn exists(cmd: &wstr, parser: &mut Parser) -> bool { parser.assert_can_execute(); if !valid_func_name(cmd) { return false; @@ -291,7 +291,7 @@ fn get_function_body_source(props: &FunctionProperties) -> &wstr { /// Sets the description of the function with the name \c name. /// This triggers autoloading. -pub fn set_desc(name: &wstr, desc: WString, parser: &mut parser_t) { +pub fn set_desc(name: &wstr, desc: WString, parser: &mut Parser) { parser.assert_can_execute(); load(name, parser); let mut funcset = FUNCTION_SET.lock().unwrap(); @@ -306,7 +306,7 @@ pub fn set_desc(name: &wstr, desc: WString, parser: &mut parser_t) { /// Creates a new function using the same definition as the specified function. Returns true if copy /// is successful. -pub fn copy(name: &wstr, new_name: WString, parser: &parser_t) -> bool { +pub fn copy(name: &wstr, new_name: WString, parser: &Parser) -> bool { let filename = parser.current_filename_ffi().from_ffi(); let lineno = parser.get_lineno(); @@ -588,7 +588,7 @@ fn function_get_props_ffi(name: &CxxWString) -> *mut FunctionPropertiesRefFFI { fn function_get_props_autoload_ffi( name: &CxxWString, - parser: Pin<&mut parser_t>, + parser: Pin<&mut Parser>, ) -> *mut FunctionPropertiesRefFFI { let props = get_props_autoload(name.as_wstr(), parser.unpin()); if let Some(props) = props { @@ -598,15 +598,15 @@ fn function_get_props_autoload_ffi( } } -fn function_load_ffi(name: &CxxWString, parser: Pin<&mut parser_t>) -> bool { +fn function_load_ffi(name: &CxxWString, parser: Pin<&mut Parser>) -> bool { load(name.as_wstr(), parser.unpin()) } -fn function_set_desc_ffi(name: &CxxWString, desc: &CxxWString, parser: Pin<&mut parser_t>) { +fn function_set_desc_ffi(name: &CxxWString, desc: &CxxWString, parser: Pin<&mut Parser>) { set_desc(name.as_wstr(), desc.from_ffi(), parser.unpin()); } -fn function_exists_ffi(cmd: &CxxWString, parser: Pin<&mut parser_t>) -> bool { +fn function_exists_ffi(cmd: &CxxWString, parser: Pin<&mut Parser>) -> bool { exists(cmd.as_wstr(), parser.unpin()) } @@ -621,7 +621,7 @@ fn function_get_names_ffi(get_hidden: bool, mut out: Pin<&mut wcstring_list_ffi_ } } -fn function_copy_ffi(name: &CxxWString, new_name: &CxxWString, parser: Pin<&mut parser_t>) -> bool { +fn function_copy_ffi(name: &CxxWString, new_name: &CxxWString, parser: Pin<&mut Parser>) -> bool { copy(name.as_wstr(), new_name.from_ffi(), parser.unpin()) } @@ -632,7 +632,7 @@ mod function_ffi { include!("parse_tree.h"); include!("parser.h"); include!("wutil.h"); - type parser_t = crate::ffi::parser_t; + type Parser = crate::ffi::Parser; type wcstring_list_ffi_t = crate::ffi::wcstring_list_ffi_t; } @@ -675,17 +675,17 @@ mod function_ffi { #[cxx_name = "function_get_props_autoload_raw"] fn function_get_props_autoload_ffi( name: &CxxWString, - parser: Pin<&mut parser_t>, + parser: Pin<&mut Parser>, ) -> *mut FunctionPropertiesRefFFI; #[cxx_name = "function_load"] - fn function_load_ffi(name: &CxxWString, parser: Pin<&mut parser_t>) -> bool; + fn function_load_ffi(name: &CxxWString, parser: Pin<&mut Parser>) -> bool; #[cxx_name = "function_set_desc"] - fn function_set_desc_ffi(name: &CxxWString, desc: &CxxWString, parser: Pin<&mut parser_t>); + fn function_set_desc_ffi(name: &CxxWString, desc: &CxxWString, parser: Pin<&mut Parser>); #[cxx_name = "function_exists"] - fn function_exists_ffi(cmd: &CxxWString, parser: Pin<&mut parser_t>) -> bool; + fn function_exists_ffi(cmd: &CxxWString, parser: Pin<&mut Parser>) -> bool; #[cxx_name = "function_exists_no_autoload"] fn function_exists_no_autoload_ffi(cmd: &CxxWString) -> bool; @@ -697,7 +697,7 @@ fn function_get_props_autoload_ffi( fn function_copy_ffi( name: &CxxWString, new_name: &CxxWString, - parser: Pin<&mut parser_t>, + parser: Pin<&mut Parser>, ) -> bool; #[cxx_name = "function_invalidate_path"] diff --git a/fish-rust/src/termsize.rs b/fish-rust/src/termsize.rs index e5dee42b6..ef63ac999 100644 --- a/fish-rust/src/termsize.rs +++ b/fish-rust/src/termsize.rs @@ -1,7 +1,7 @@ // Support for exposing the terminal size. use crate::common::assert_sync; use crate::env::{EnvMode, EnvStackRefFFI, EnvVar, Environment}; -use crate::ffi::{parser_t, Repin}; +use crate::ffi::{Parser, Repin}; use crate::flog::FLOG; use crate::wchar::prelude::*; use crate::wchar_ffi::WCharToFFI; @@ -179,7 +179,7 @@ pub fn initialize(&self, vars: &dyn Environment) -> Termsize { /// registered for COLUMNS and LINES. /// This requires a shared reference so it can work from a static. /// \return the updated termsize. - pub fn updating(&self, parser: &mut parser_t) -> Termsize { + pub fn updating(&self, parser: &mut Parser) -> Termsize { let new_size; let prev_size; @@ -208,7 +208,7 @@ pub fn updating(&self, parser: &mut parser_t) -> Termsize { new_size } - fn set_columns_lines_vars(&self, val: Termsize, parser: &mut parser_t) { + fn set_columns_lines_vars(&self, val: Termsize, parser: &mut Parser) { let saved = self.setting_env_vars.swap(true, Ordering::Relaxed); parser.pin().set_var_and_fire( &L!("COLUMNS").to_ffi(), @@ -321,7 +321,7 @@ pub fn termsize_initialize_ffi(vars_ptr: *const u8) -> Termsize { /// Called to update termsize. pub fn termsize_update_ffi(parser_ptr: *mut u8) -> Termsize { assert!(!parser_ptr.is_null()); - let parser: &mut parser_t = unsafe { &mut *(parser_ptr as *mut parser_t) }; + let parser: &mut Parser = unsafe { &mut *(parser_ptr as *mut Parser) }; SHARED_CONTAINER.updating(parser) } @@ -337,7 +337,7 @@ pub fn termsize_invalidate_tty() { use crate::ffi_tests::add_test; add_test!("test_termsize", || { let env_global = EnvMode::GLOBAL; - let parser: &mut parser_t = unsafe { &mut *parser_t::principal_parser_ffi() }; + let parser: &mut Parser = unsafe { &mut *Parser::principal_parser_ffi() }; let vars = parser.get_vars(); // Use a static variable so we can pretend we're the kernel exposing a terminal size. diff --git a/fish-rust/src/trace.rs b/fish-rust/src/trace.rs index 593007504..8f734ed52 100644 --- a/fish-rust/src/trace.rs +++ b/fish-rust/src/trace.rs @@ -1,6 +1,6 @@ use crate::{ common::escape, - ffi::{self, parser_t, wcharz_t, wcstring_list_ffi_t}, + ffi::{self, wcharz_t, wcstring_list_ffi_t, Parser}, global_safety::RelaxedAtomicBool, wchar::prelude::*, wchar_ffi::{WCharFromFFI, WCharToFFI}, @@ -13,14 +13,14 @@ mod trace_ffi { include!("parser.h"); type wcstring_list_ffi_t = super::wcstring_list_ffi_t; type wcharz_t = super::wcharz_t; - type parser_t = super::parser_t; + type Parser = super::Parser; } extern "Rust" { fn trace_set_enabled(do_enable: bool); - fn trace_enabled(parser: &parser_t) -> bool; + fn trace_enabled(parser: &Parser) -> bool; #[cxx_name = "trace_argv"] - fn trace_argv_ffi(parser: &parser_t, command: wcharz_t, args: &wcstring_list_ffi_t); + fn trace_argv_ffi(parser: &Parser, command: wcharz_t, args: &wcstring_list_ffi_t); } } @@ -31,7 +31,7 @@ pub fn trace_set_enabled(do_enable: bool) { } /// return whether tracing is enabled. -pub fn trace_enabled(parser: &parser_t) -> bool { +pub fn trace_enabled(parser: &Parser) -> bool { let ld = parser.ffi_libdata_pod_const(); if ld.suppress_fish_trace { return false; @@ -42,14 +42,14 @@ pub fn trace_enabled(parser: &parser_t) -> bool { /// Trace an "argv": a list of arguments where the first is the command. // Allow the `&Vec` parameter as this function only exists temporarily for the FFI #[allow(clippy::ptr_arg)] -fn trace_argv_ffi(parser: &parser_t, command: wcharz_t, args: &wcstring_list_ffi_t) { +fn trace_argv_ffi(parser: &Parser, command: wcharz_t, args: &wcstring_list_ffi_t) { let command: WString = command.into(); let args: Vec = args.from_ffi(); let args_ref: Vec<&wstr> = args.iter().map(WString::as_utfstr).collect(); trace_argv(parser, command.as_utfstr(), &args_ref); } -pub fn trace_argv>(parser: &parser_t, command: &wstr, args: &[S]) { +pub fn trace_argv>(parser: &Parser, command: &wstr, args: &[S]) { // Format into a string to prevent interleaving with flog in other threads. // Add the + prefix. let mut trace_text = L!("-").repeat(parser.blocks_size() - 1); @@ -68,7 +68,7 @@ pub fn trace_argv>(parser: &parser_t, command: &wstr, args: &[S]) } /// Convenience helper to trace a single string if tracing is enabled. -pub fn trace_if_enabled>(parser: &parser_t, command: &wstr, args: &[S]) { +pub fn trace_if_enabled>(parser: &Parser, command: &wstr, args: &[S]) { if trace_enabled(parser) { trace_argv(parser, command, args); } diff --git a/src/autoload.h b/src/autoload.h index d0967c2b3..b52bf5730 100644 --- a/src/autoload.h +++ b/src/autoload.h @@ -16,7 +16,7 @@ class autoload_file_cache_t; class environment_t; -class parser_t; +class Parser; using parser_t = Parser; struct autoload_tester_t; /// autoload_t is a class that knows how to autoload .fish files from a list of directories. This diff --git a/src/builtin.h b/src/builtin.h index 89eca4a50..dbd5730b6 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -9,10 +9,10 @@ #include "maybe.h" #include "wutil.h" -class parser_t; +class Parser; using parser_t = Parser; class proc_status_t; class output_stream_t; -struct io_streams_t; +class IoStreams; using io_streams_t = IoStreams; using completion_list_t = std::vector; /// Data structure to describe a builtin. diff --git a/src/builtins/bind.h b/src/builtins/bind.h index 6218d2638..3b3aa7608 100644 --- a/src/builtins/bind.h +++ b/src/builtins/bind.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/commandline.h b/src/builtins/commandline.h index 1723ed0ee..2189d370c 100644 --- a/src/builtins/commandline.h +++ b/src/builtins/commandline.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_commandline(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/complete.h b/src/builtins/complete.h index 672778b64..dcbed7c4d 100644 --- a/src/builtins/complete.h +++ b/src/builtins/complete.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/disown.h b/src/builtins/disown.h index 1a9d25a6a..e41fb617b 100644 --- a/src/builtins/disown.h +++ b/src/builtins/disown.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_disown(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/eval.h b/src/builtins/eval.h index 042b2aace..b6feb1fc1 100644 --- a/src/builtins/eval.h +++ b/src/builtins/eval.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_eval(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/fg.h b/src/builtins/fg.h index 5487c58ee..ccbb4d040 100644 --- a/src/builtins/fg.h +++ b/src/builtins/fg.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_fg(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/history.h b/src/builtins/history.h index a1a76295c..97bb2408f 100644 --- a/src/builtins/history.h +++ b/src/builtins/history.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_history(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/jobs.h b/src/builtins/jobs.h index d6d8a245f..85f579d23 100644 --- a/src/builtins/jobs.h +++ b/src/builtins/jobs.h @@ -8,7 +8,7 @@ #include "../io.h" #include "../maybe.h" -class parser_t; +class Parser; using parser_t = Parser; maybe_t builtin_jobs(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/read.h b/src/builtins/read.h index 7ad2b549a..1f5492e85 100644 --- a/src/builtins/read.h +++ b/src/builtins/read.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/set.h b/src/builtins/set.h index 4b08f5e42..3c80f2a39 100644 --- a/src/builtins/set.h +++ b/src/builtins/set.h @@ -4,7 +4,7 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_set(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/source.h b/src/builtins/source.h index 7cb5dc5db..a7587980c 100644 --- a/src/builtins/source.h +++ b/src/builtins/source.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_source(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtins/ulimit.cpp b/src/builtins/ulimit.cpp index fd28362a9..c974895c0 100644 --- a/src/builtins/ulimit.cpp +++ b/src/builtins/ulimit.cpp @@ -17,7 +17,7 @@ #include "../wgetopt.h" #include "../wutil.h" // IWYU pragma: keep -class parser_t; +class Parser; using parser_t = Parser; /// Struct describing a resource limit. struct resource_t { diff --git a/src/builtins/ulimit.h b/src/builtins/ulimit.h index b526910fa..1e329e7f7 100644 --- a/src/builtins/ulimit.h +++ b/src/builtins/ulimit.h @@ -4,8 +4,8 @@ #include "../maybe.h" -class parser_t; -struct io_streams_t; +class Parser; using parser_t = Parser; +class IoStreams; using io_streams_t = IoStreams; maybe_t builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/complete.h b/src/complete.h index 301cb0d1d..ccc8782bd 100644 --- a/src/complete.h +++ b/src/complete.h @@ -29,7 +29,7 @@ struct completion_mode_t { /// Character that separates the completion and description on programmable completions. #define PROG_COMPLETE_SEP L'\t' -class parser_t; +class Parser; using parser_t = Parser; enum { /// Do not insert space afterwards if this is the only completion. (The default is to try insert diff --git a/src/env.h b/src/env.h index f4d183917..83d7a8f8c 100644 --- a/src/env.h +++ b/src/env.h @@ -201,7 +201,7 @@ class null_environment_t : public environment_t { /// A mutable environment which allows scopes to be pushed and popped. class env_stack_t final : public environment_t { - friend class parser_t; + friend class Parser; /// \return whether we are the principal stack. bool is_principal() const; diff --git a/src/event.h b/src/event.h index d7ed502cc..b6d233799 100644 --- a/src/event.h +++ b/src/event.h @@ -16,7 +16,7 @@ #include "global_safety.h" #include "wutil.h" -class parser_t; +class Parser; using parser_t = Parser; #if INCLUDE_RUST_HEADERS #include "event.rs.h" #else @@ -32,7 +32,7 @@ struct Event; // TODO: Remove after porting functions.cpp extern const wchar_t *const event_filter_names[]; -class parser_t; +class Parser; using parser_t = Parser; void event_fire_generic(parser_t &parser, const wcstring &name, const std::vector &args = g_empty_string_list); diff --git a/src/exec.h b/src/exec.h index acdabbdd4..e9212c363 100644 --- a/src/exec.h +++ b/src/exec.h @@ -11,7 +11,7 @@ #include "io.h" #include "proc.h" -class parser_t; +class Parser; using parser_t = Parser; /// Execute the processes specified by \p j in the parser \p. /// On a true return, the job was successfully launched and the parser will take responsibility for diff --git a/src/function.h b/src/function.h index 837bcddd5..03dec55c1 100644 --- a/src/function.h +++ b/src/function.h @@ -8,7 +8,7 @@ #include "maybe.h" struct function_properties_t; -class parser_t; +class Parser; using parser_t = Parser; #if INCLUDE_RUST_HEADERS #include "function.rs.h" diff --git a/src/highlight.h b/src/highlight.h index 452a2ccd6..cfa809620 100644 --- a/src/highlight.h +++ b/src/highlight.h @@ -115,7 +115,7 @@ void highlight_shell(const wcstring &buffstr, std::vector &col const operation_context_t &ctx, bool io_ok = false, maybe_t cursor = {}); -class parser_t; +class Parser; using parser_t = Parser; /// Wrapper around colorize(highlight_shell) wcstring colorize_shell(const wcstring &text, parser_t &parser); diff --git a/src/history.h b/src/history.h index fc029509b..eae4fd595 100644 --- a/src/history.h +++ b/src/history.h @@ -20,7 +20,7 @@ #include "maybe.h" #include "wutil.h" // IWYU pragma: keep -struct io_streams_t; +class IoStreams; using io_streams_t = IoStreams; class env_stack_t; class environment_t; class operation_context_t; diff --git a/src/input.h b/src/input.h index 2ca5013fc..a0826ce8d 100644 --- a/src/input.h +++ b/src/input.h @@ -18,7 +18,7 @@ #define DEFAULT_BIND_MODE L"default" class event_queue_peeker_t; -class parser_t; +class Parser; using parser_t = Parser; wcstring describe_char(wint_t c); diff --git a/src/io.h b/src/io.h index 89b9dad3b..f60c3f4c1 100644 --- a/src/io.h +++ b/src/io.h @@ -473,7 +473,11 @@ class buffered_output_stream_t final : public output_stream_t { std::shared_ptr buffer_; }; -struct io_streams_t : noncopyable_t { +class IoStreams; +using io_streams_t = IoStreams; + +class IoStreams : noncopyable_t { + public: // Streams for out and err. output_stream_t &out; output_stream_t &err; @@ -505,13 +509,13 @@ struct io_streams_t : noncopyable_t { // FIXME: this is awkwardly placed. std::shared_ptr job_group{}; - io_streams_t(output_stream_t &out, output_stream_t &err) : out(out), err(err) {} - virtual ~io_streams_t() = default; + IoStreams(output_stream_t &out, output_stream_t &err) : out(out), err(err) {} + virtual ~IoStreams() = default; /// autocxx junk. output_stream_t &get_out() { return out; }; output_stream_t &get_err() { return err; }; - io_streams_t(const io_streams_t &) = delete; + IoStreams(const io_streams_t &) = delete; bool get_out_redirected() { return out_is_redirected; }; bool get_err_redirected() { return err_is_redirected; }; bool ffi_stdin_is_directly_redirected() const { return stdin_is_directly_redirected; }; @@ -519,7 +523,8 @@ struct io_streams_t : noncopyable_t { }; /// FFI helper. -struct owning_io_streams_t : io_streams_t { +class owning_io_streams_t : public io_streams_t { + public: string_output_stream_t out_storage; null_output_stream_t err_storage; owning_io_streams_t() : io_streams_t(out_storage, err_storage) {} diff --git a/src/operation_context.h b/src/operation_context.h index 56649c097..ac8b91ac4 100644 --- a/src/operation_context.h +++ b/src/operation_context.h @@ -8,7 +8,7 @@ #include "common.h" class environment_t; -class parser_t; +class Parser; using parser_t = Parser; struct job_group_t; /// A common helper which always returns false. diff --git a/src/parse_execution.h b/src/parse_execution.h index 6a375d3e9..13c6eb27b 100644 --- a/src/parse_execution.h +++ b/src/parse_execution.h @@ -17,7 +17,7 @@ class block_t; class operation_context_t; -class parser_t; +class Parser; using parser_t = Parser; /// An eval_result represents evaluation errors including wildcards which failed to match, syntax /// errors, or other expansion errors. It also tracks when evaluation was skipped due to signal diff --git a/src/parser.cpp b/src/parser.cpp index 7701f68aa..6b2a47dd0 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -40,7 +40,7 @@ static wcstring user_presentable_path(const wcstring &path, const environment_t return replace_home_directory_with_tilde(path, vars); } -parser_t::parser_t(std::shared_ptr vars, bool is_principal) +parser_t::Parser(std::shared_ptr vars, bool is_principal) : wait_handles(new_wait_handle_store_ffi()), variables(std::move(vars)), is_principal_(is_principal) { @@ -54,7 +54,7 @@ parser_t::parser_t(std::shared_ptr vars, bool is_principal) } // Out of line destructor to enable forward declaration of parse_execution_context_t -parser_t::~parser_t() = default; +parser_t::~Parser() = default; parser_t &parser_t::principal_parser() { static const std::shared_ptr principal{ @@ -590,7 +590,8 @@ eval_res_t parser_t::eval_with(const wcstring &cmd, const io_chain_t &io, eval_res_t parser_t::eval_string_ffi1(const wcstring &cmd) { return eval(cmd, io_chain_t()); } -eval_res_t parser_t::eval_parsed_source_ffi1(const parsed_source_ref_t* ps, enum block_type_t block_type) { +eval_res_t parser_t::eval_parsed_source_ffi1(const parsed_source_ref_t *ps, + enum block_type_t block_type) { return eval_parsed_source(*ps, io_chain_t(), {}, block_type); } @@ -698,8 +699,8 @@ template eval_res_t parser_t::eval_node(const parsed_source_ref_t &, const ast:: template eval_res_t parser_t::eval_node(const parsed_source_ref_t &, const ast::job_list_t &, const io_chain_t &, const job_group_ref_t &, block_type_t); -void parser_t::get_backtrace_ffi(const wcstring &src, const parse_error_list_t* errors, - wcstring &output) const { +void parser_t::get_backtrace_ffi(const wcstring &src, const parse_error_list_t *errors, + wcstring &output) const { return get_backtrace(src, *errors, output); }; void parser_t::get_backtrace(const wcstring &src, const parse_error_list_t &errors, diff --git a/src/parser.h b/src/parser.h index 1d0dcadb4..00695ad2a 100644 --- a/src/parser.h +++ b/src/parser.h @@ -29,7 +29,6 @@ class autoclose_fd_t; class io_chain_t; struct Event; struct job_group_t; -class parser_t; /// Types of blocks. enum class block_type_t : uint8_t { @@ -258,7 +257,10 @@ enum class parser_status_var_t : uint8_t { count_, }; -class parser_t : public std::enable_shared_from_this { +class Parser; +using parser_t = Parser; + +class Parser : public std::enable_shared_from_this { friend class parse_execution_context_t; private: @@ -310,12 +312,12 @@ class parser_t : public std::enable_shared_from_this { bool is_command_substitution() const; /// Create a parser - parser_t(std::shared_ptr vars, bool is_principal = false); + Parser(std::shared_ptr vars, bool is_principal = false); public: // No copying allowed. - parser_t(const parser_t &) = delete; - parser_t &operator=(const parser_t &) = delete; + Parser(const parser_t &) = delete; + Parser &operator=(const parser_t &) = delete; /// Get the "principal" parser, whatever that is. static parser_t &principal_parser(); @@ -349,7 +351,7 @@ class parser_t : public std::enable_shared_from_this { eval_res_t eval_parsed_source(const parsed_source_ref_t &ps, const io_chain_t &io, const job_group_ref_t &job_group = {}, block_type_t block_type = block_type_t::top); - eval_res_t eval_parsed_source_ffi1(const parsed_source_ref_t* ps, block_type_t block_type); + eval_res_t eval_parsed_source_ffi1(const parsed_source_ref_t *ps, block_type_t block_type); /// Evaluates a node. /// The node type must be ast_t::statement_t or ast::job_list_t. template @@ -466,8 +468,8 @@ class parser_t : public std::enable_shared_from_this { /// Output profiling data to the given filename. void emit_profiling(const char *path) const; - void get_backtrace_ffi(const wcstring &src, const parse_error_list_t* errors, - wcstring &output) const; + void get_backtrace_ffi(const wcstring &src, const parse_error_list_t *errors, + wcstring &output) const; void get_backtrace(const wcstring &src, const parse_error_list_t &errors, wcstring &output) const; @@ -527,7 +529,7 @@ class parser_t : public std::enable_shared_from_this { /// autocxx junk. size_t ffi_blocks_size() const; - ~parser_t(); + ~Parser(); }; #endif diff --git a/src/proc.h b/src/proc.h index ad37480db..76ae54d05 100644 --- a/src/proc.h +++ b/src/proc.h @@ -362,7 +362,7 @@ class process_t { using process_ptr_t = std::unique_ptr; using process_list_t = std::vector; -class parser_t; +class Parser; using parser_t = Parser; struct RustFFIProcList { process_ptr_t *procs; diff --git a/src/reader.h b/src/reader.h index 6e9ba9fbd..78765b1d9 100644 --- a/src/reader.h +++ b/src/reader.h @@ -22,7 +22,7 @@ class env_stack_t; class environment_t; class history_t; class io_chain_t; -class parser_t; +class Parser; using parser_t = Parser; /// An edit action that can be undone. struct edit_t {