Rename Rust-side parser_t/io_streams_t to Parser/IoStreams

This reduces noise in the upcoming "Port execution" commit.

I accidentally made IoStreams a "class" instead of a "struct".  Would be
easy to correct that but this will be deleted soon, so I don't think we care.
This commit is contained in:
Johannes Altmanninger
2023-10-08 23:10:05 +02:00
parent aaa48e89a5
commit c4155db933
81 changed files with 348 additions and 454 deletions

View File

@@ -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<c_int> {
fn abbr_show(streams: &mut IoStreams) -> Option<c_int> {
let style = EscapeStringStyle::Script(Default::default());
abbrs::with_abbrs(|abbrs| {
@@ -174,7 +174,7 @@ fn abbr_show(streams: &mut io_streams_t) -> Option<c_int> {
}
// Print the list of abbreviation names.
fn abbr_list(opts: &Options, streams: &mut io_streams_t) -> Option<c_int> {
fn abbr_list(opts: &Options, streams: &mut IoStreams) -> Option<c_int> {
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<c_int> {
}
// Rename an abbreviation, deleting any existing one with the given name.
fn abbr_rename(opts: &Options, streams: &mut io_streams_t) -> Option<c_int> {
fn abbr_rename(opts: &Options, streams: &mut IoStreams) -> Option<c_int> {
const subcmd: &wstr = L!("--rename");
if opts.args.len() != 2 {
@@ -271,7 +271,7 @@ fn abbr_query(opts: &Options) -> Option<c_int> {
}
// Add a named abbreviation.
fn abbr_add(opts: &Options, streams: &mut io_streams_t) -> Option<c_int> {
fn abbr_add(opts: &Options, streams: &mut IoStreams) -> Option<c_int> {
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<c_int> {
}
// Erase the named abbreviations.
fn abbr_erase(opts: &Options, parser: &mut parser_t) -> Option<c_int> {
fn abbr_erase(opts: &Options, parser: &mut Parser) -> Option<c_int> {
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<c_int> {
})
}
pub fn abbr(
parser: &mut parser_t,
streams: &mut io_streams_t,
argv: &mut [&wstr],
) -> Option<c_int> {
pub fn abbr(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
let mut argv_read = Vec::with_capacity(argv.len());
argv_read.extend_from_slice(argv);

View File

@@ -83,7 +83,7 @@ fn new() -> Self {
fn exec_subshell(
cmd: &wstr,
parser: &mut parser_t,
parser: &mut Parser,
outputs: &mut Vec<WString>,
apply_exit_status: bool,
) -> Option<c_int> {
@@ -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<c_int> {
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<c_int> {
fn parse_exclusive_args(opts: &mut ArgParseCmdOpts, streams: &mut IoStreams) -> Option<c_int> {
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<c_int> {
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<c_int> {
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<c_int> {
// 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<c_int> {
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<c_int> {
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<c_int> {
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<c_int> {
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<c_int> {
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<c_int> {
pub fn argparse(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let cmd = args[0];
let argc = args.len();

View File

@@ -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<c_int> {
@@ -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<c_int> {
pub fn bg(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let opts = match HelpOnlyCmdOpts::parse(args, parser, streams) {
Ok(opts) => opts,
Err(err @ Some(_)) if err != STATUS_CMD_OK => return err,

View File

@@ -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<c_int>> {
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<c_int> {
pub fn block(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let cmd = args[0];
let opts = match parse_options(args, parser, streams) {

View File

@@ -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<c_int> {
let cmd = argv[0];

View File

@@ -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<c_int> {
pub fn cd(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let cmd = args[0];
let opts = match HelpOnlyCmdOpts::parse(args, parser, streams) {

View File

@@ -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<c_int> {
let cmd = argv[0];

View File

@@ -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<c_int>> {
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<c_int> {
pub fn contains(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let cmd = args[0];
let (opts, optind) = match parse_options(args, parser, streams) {

View File

@@ -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<c_int> {
pub fn count(_parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
// 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;

View File

@@ -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<c_int>> {
let cmd = args[0];
@@ -135,11 +135,7 @@ fn parse_numeric_sequence<I>(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<c_int> {
pub fn echo(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let (opts, optind) = match parse_options(args, parser, streams) {
Ok((opts, optind)) => (opts, optind),
Err(err @ Some(_)) if err != STATUS_CMD_OK => return err,

View File

@@ -2,11 +2,7 @@
use crate::event;
#[widestrs]
pub fn emit(
parser: &mut parser_t,
streams: &mut io_streams_t,
argv: &mut [&wstr],
) -> Option<c_int> {
pub fn emit(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
let cmd = argv[0];
let opts = match HelpOnlyCmdOpts::parse(argv, parser, streams) {

View File

@@ -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<c_int> {
pub fn exit(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let retval = match parse_return_value(args, parser, streams) {
Ok(v) => v,
Err(e) => return e,

View File

@@ -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<u64> {
fn job_id_for_pid(pid: i32, parser: &Parser) -> Option<u64> {
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<c_int> {
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<c_int> {
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<BlockStatement>,
) -> Option<c_int> {
@@ -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,

View File

@@ -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<c_int> {
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<c_int> {
let cmd = args[0];

View File

@@ -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<c_int>> {
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<c_int> {
@@ -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<c_int> {
pub fn math(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
let cmd = argv[0];
let (opts, mut optind) = match parse_cmd_opts(argv, parser, streams) {

View File

@@ -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::{

View File

@@ -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<wstr>) {
fn path_out(streams: &mut IoStreams, opts: &Options<'_>, s: impl AsRef<wstr>) {
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<c_int> {
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<c_int> {
@@ -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<c_int> {
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<c_int> {
fn path_dirname(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
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<c_int> {
path_transform(parser, streams, args, normalize_help)
}
fn path_mtime(
parser: &mut parser_t,
streams: &mut io_streams_t,
args: &mut [&wstr],
) -> Option<c_int> {
fn path_mtime(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
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<c_int> {
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<c_int> {
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<c_int> {
fn path_resolve(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
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<c_int> {
fn path_sort(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
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<c_int> {
@@ -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<c_int> {
fn path_filter(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
path_filter_maybe_is(parser, streams, args, false)
}
fn path_is(parser: &mut parser_t, streams: &mut io_streams_t, args: &mut [&wstr]) -> Option<c_int> {
fn path_is(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
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<c_int> {
pub fn path(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let cmd = args[0];
let argc = args.len();

View File

@@ -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<c_int> {
pub fn printf(_parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
let mut argc = argv.len();
// Rebind argv as immutable slice (can't rearrange its elements), skipping the command name.

View File

@@ -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<c_int> {
pub fn pwd(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
let cmd = argv[0];
let argc = argv.len();
let mut resolve_symlinks = false;

View File

@@ -8,11 +8,7 @@
static RNG: Lazy<Mutex<SmallRng>> = Lazy::new(|| Mutex::new(SmallRng::from_entropy()));
pub fn random(
parser: &mut parser_t,
streams: &mut io_streams_t,
argv: &mut [&wstr],
) -> Option<c_int> {
pub fn random(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
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<i64, wutil::Error> {
fn parse_ll(streams: &mut IoStreams, cmd: &wstr, num: &wstr) -> Result<i64, wutil::Error> {
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<i64, w
}
return res;
}
fn parse_ull(streams: &mut io_streams_t, cmd: &wstr, num: &wstr) -> Result<u64, wutil::Error> {
fn parse_ull(streams: &mut IoStreams, cmd: &wstr, num: &wstr) -> Result<u64, wutil::Error> {
let res = fish_wcstoul(num);
if res.is_err() {
streams

View File

@@ -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<c_int>> {
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<c_int> {
pub fn realpath(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let cmd = args[0];
let (opts, optind) = match parse_options(args, parser, streams) {
Ok((opts, optind)) => (opts, optind),

View File

@@ -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<c_int>> {
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<c_int> {
pub fn r#return(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
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<i32, Option<c_int>> {
let cmd = args[0];
let (opts, optind) = match parse_options(args, parser, streams) {

View File

@@ -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<c_int> {
// Variables used for parsing the argument list.

View File

@@ -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<c_int>;
pub type BuiltinCmd = fn(&mut Parser, &mut IoStreams, &mut [&wstr]) -> Option<c_int>;
#[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<WString> = 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<c_int> {
@@ -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<Self, Option<c_int>> {
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(|| {

View File

@@ -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<c_int> {
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<c_int> {
pub fn status(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let cmd = args[0];
let argc = args.len();

View File

@@ -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<usize, Option<c_int>> {
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<c_int> {
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<c_int>;
fn run(
&mut self,
parser: &mut parser_t,
streams: &mut io_streams_t,
parser: &mut Parser,
streams: &mut IoStreams,
args: &mut [&'args wstr],
) -> Option<c_int> {
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<usize> {
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<c_int> {
pub fn string(parser: &mut Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Option<c_int> {
let cmd = args[0];
let argc = args.len();

View File

@@ -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<libc::c_int> {

View File

@@ -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<libc::c_int> {

View File

@@ -38,7 +38,7 @@ fn take_args(
&mut self,
optind: &mut usize,
args: &[&'args wstr],
streams: &mut io_streams_t,
streams: &mut IoStreams,
) -> Option<libc::c_int> {
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<libc::c_int> {

View File

@@ -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<libc::c_int> {

View File

@@ -53,7 +53,7 @@ fn take_args(
&mut self,
optind: &mut usize,
args: &[&'args wstr],
streams: &mut io_streams_t,
streams: &mut IoStreams,
) -> Option<libc::c_int> {
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<libc::c_int> {
@@ -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<Captures<'a>>,
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 {

View File

@@ -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<libc::c_int> {

View File

@@ -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<libc::c_int> {

View File

@@ -41,7 +41,7 @@ fn take_args(
&mut self,
optind: &mut usize,
args: &[&'args wstr],
streams: &mut io_streams_t,
streams: &mut IoStreams,
) -> Option<libc::c_int> {
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<libc::c_int> {

View File

@@ -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<libc::c_int> {

View File

@@ -146,7 +146,7 @@ fn take_args(
&mut self,
optind: &mut usize,
args: &[&'args wstr],
streams: &mut io_streams_t,
streams: &mut IoStreams,
) -> Option<libc::c_int> {
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<libc::c_int> {

View File

@@ -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<libc::c_int> {

View File

@@ -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<libc::c_int> {

View File

@@ -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<libc::c_int> {

View File

@@ -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<libc::c_int> {

View File

@@ -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<WString>) -> bool;
fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec<WString>) -> 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<WString>) -> bool {
fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec<WString>) -> 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<WString>) -> bool {
fn evaluate(&self, _streams: &mut IoStreams, errors: &mut Vec<WString>) -> 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<WString>) -> bool {
fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec<WString>) -> 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<WString>) -> bool {
fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec<WString>) -> 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<WString>) -> bool {
fn evaluate(&self, streams: &mut IoStreams, errors: &mut Vec<WString>) -> 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<WString>,
) -> bool {
const S_ISGID: u32 = 0o2000;
@@ -1003,11 +1003,7 @@ fn stat_and<F>(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<c_int> {
pub fn test(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
// The first argument should be the name of the command ('test').
if argv.is_empty() {
return STATUS_INVALID_ARGS;

View File

@@ -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<i32>, 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");

View File

@@ -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::<Vec<_>>();
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<i32> = 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!(

View File

@@ -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<c_int> {
pub fn r#type(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
let cmd = argv[0];
let argc = argv.len();
let print_hints = false;

View File

@@ -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<WaitHandleRef>,
) -> bool {
// Has a job already completed?
@@ -72,7 +72,7 @@ fn find_wait_handles(
matched
}
fn get_all_wait_handles(parser: &parser_t) -> Vec<WaitHandleRef> {
fn get_all_wait_handles(parser: &Parser) -> Vec<WaitHandleRef> {
// 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<c_int> {
@@ -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<c_int> {
pub fn wait(parser: &mut Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Option<c_int> {
let cmd = argv[0];
let argc = argv.len();
let mut any_flag = false; // flag for -n option

View File

@@ -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<wcharz_t>,
);
#[cxx_name = "event_get_desc"]
fn event_get_desc_ffi(parser: &parser_t, evt: &Event) -> UniquePtr<CxxWString>;
fn event_get_desc_ffi(parser: &Parser, evt: &Event) -> UniquePtr<CxxWString>;
#[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<CxxWString> {
fn event_get_desc_ffi(parser: &Parser, evt: &Event) -> UniquePtr<CxxWString> {
get_desc(parser, evt).to_ffi()
}
@@ -661,7 +661,7 @@ fn event_get_function_handler_descs_ffi(name: &CxxWString) -> Vec<event_descript
/// Perform the specified event. Since almost all event firings will not be matched by even a single
/// event handler, we make sure to optimize the 'no matches' path. This means that nothing is
/// allocated/initialized unless needed.
fn fire_internal(parser: &mut parser_t, event: &Event) {
fn fire_internal(parser: &mut Parser, event: &Event) {
assert!(
parser.libdata_pod().is_event >= 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<WString>) {
pub fn fire_generic(parser: &mut Parser, name: WString, arguments: Vec<WString>) {
fire(
parser,
Event {
@@ -909,7 +909,7 @@ pub fn fire_generic(parser: &mut parser_t, name: WString, arguments: Vec<WString
}
fn event_fire_generic_ffi(
parser: Pin<&mut parser_t>,
parser: Pin<&mut Parser>,
name: &CxxWString,
arguments: &CxxVector<wcharz_t>,
) {

View File

@@ -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<WaitHandleStoreFFI>;
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 {}

View File

@@ -264,7 +264,7 @@ fn determine_config_directory_paths(argv0: impl AsRef<Path>) -> 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 {

View File

@@ -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<WString> = None;
// Note we can't autoload while holding the funcset lock.
@@ -219,7 +219,7 @@ pub fn get_props(name: &wstr) -> Option<Arc<FunctionProperties>> {
}
/// \return the properties for a function, or None, perhaps triggering autoloading.
pub fn get_props_autoload(name: &wstr, parser: &mut parser_t) -> Option<Arc<FunctionProperties>> {
pub fn get_props_autoload(name: &wstr, parser: &mut Parser) -> Option<Arc<FunctionProperties>> {
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<Arc<Func
/// Returns true if the function named \p cmd exists.
/// This may autoload.
pub fn exists(cmd: &wstr, parser: &mut parser_t) -> 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"]

View File

@@ -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.

View File

@@ -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<WString> = 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<S: AsRef<wstr>>(parser: &parser_t, command: &wstr, args: &[S]) {
pub fn trace_argv<S: AsRef<wstr>>(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<S: AsRef<wstr>>(parser: &parser_t, command: &wstr, args: &[S])
}
/// Convenience helper to trace a single string if tracing is enabled.
pub fn trace_if_enabled<S: AsRef<wstr>>(parser: &parser_t, command: &wstr, args: &[S]) {
pub fn trace_if_enabled<S: AsRef<wstr>>(parser: &Parser, command: &wstr, args: &[S]) {
if trace_enabled(parser) {
trace_argv(parser, command, args);
}

View File

@@ -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

View File

@@ -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<completion_t>;
/// Data structure to describe a builtin.

View File

@@ -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<int> builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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<int> builtin_commandline(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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<int> builtin_complete(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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<int> builtin_disown(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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<int> builtin_eval(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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<int> builtin_fg(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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<int> builtin_history(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -8,7 +8,7 @@
#include "../io.h"
#include "../maybe.h"
class parser_t;
class Parser; using parser_t = Parser;
maybe_t<int> builtin_jobs(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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<int> builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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<int> builtin_set(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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<int> builtin_source(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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 {

View File

@@ -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<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View File

@@ -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

View File

@@ -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;

View File

@@ -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<wcstring> &args = g_empty_string_list);

View File

@@ -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

View File

@@ -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"

View File

@@ -115,7 +115,7 @@ void highlight_shell(const wcstring &buffstr, std::vector<highlight_spec_t> &col
const operation_context_t &ctx, bool io_ok = false,
maybe_t<size_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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -473,7 +473,11 @@ class buffered_output_stream_t final : public output_stream_t {
std::shared_ptr<io_buffer_t> 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_t> 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) {}

View File

@@ -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.

View File

@@ -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

View File

@@ -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<env_stack_t> vars, bool is_principal)
parser_t::Parser(std::shared_ptr<env_stack_t> 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<env_stack_t> 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<parser_t> 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,

View File

@@ -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<parser_t> {
class Parser;
using parser_t = Parser;
class Parser : public std::enable_shared_from_this<parser_t> {
friend class parse_execution_context_t;
private:
@@ -310,12 +312,12 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
bool is_command_substitution() const;
/// Create a parser
parser_t(std::shared_ptr<env_stack_t> vars, bool is_principal = false);
Parser(std::shared_ptr<env_stack_t> 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<parser_t> {
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 <typename T>
@@ -466,8 +468,8 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
/// 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<parser_t> {
/// autocxx junk.
size_t ffi_blocks_size() const;
~parser_t();
~Parser();
};
#endif

View File

@@ -362,7 +362,7 @@ class process_t {
using process_ptr_t = std::unique_ptr<process_t>;
using process_list_t = std::vector<process_ptr_t>;
class parser_t;
class Parser; using parser_t = Parser;
struct RustFFIProcList {
process_ptr_t *procs;

View File

@@ -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 {