From 6ede7f80099ffd2e17b8209e475f9b240f1ad8e8 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 19 Apr 2023 00:19:10 +0200 Subject: [PATCH] Delete wcstring_list_t We don't want it in Rust. Remove it to smoothen the transition. --- build_tools/find_globals.fish | 2 +- build_tools/iwyu.osx.imp | 3 - fish-rust/src/common.rs | 2 +- src/autoload.cpp | 14 ++-- src/autoload.h | 4 +- src/builtin.cpp | 10 +-- src/builtin.h | 4 +- src/builtins/argparse.cpp | 10 +-- src/builtins/bind.cpp | 6 +- src/builtins/complete.cpp | 32 +++++----- src/builtins/function.cpp | 10 +-- src/builtins/function.h | 2 +- src/builtins/functions.cpp | 2 +- src/builtins/history.cpp | 4 +- src/builtins/path.cpp | 6 +- src/builtins/read.cpp | 12 ++-- src/builtins/set.cpp | 22 +++---- src/builtins/set_color.cpp | 4 +- src/builtins/source.cpp | 2 +- src/builtins/status.cpp | 2 +- src/builtins/string.cpp | 14 ++-- src/builtins/test.cpp | 46 +++++++------- src/color.cpp | 4 +- src/color.h | 2 +- src/common.cpp | 8 +-- src/common.h | 7 +- src/complete.cpp | 44 ++++++------- src/complete.h | 6 +- src/env.cpp | 56 ++++++++-------- src/env.h | 30 ++++----- src/env_universal_common.cpp | 8 +-- src/env_universal_common.h | 2 +- src/event.cpp | 2 +- src/event.h | 2 +- src/exec.cpp | 14 ++-- src/exec.h | 4 +- src/expand.cpp | 16 ++--- src/expand.h | 2 +- src/ffi.h | 2 +- src/fish.cpp | 4 +- src/fish_tests.cpp | 116 +++++++++++++++++----------------- src/flog.h | 1 - src/function.cpp | 10 +-- src/function.h | 6 +- src/highlight.cpp | 10 +-- src/highlight.h | 2 +- src/history.cpp | 16 ++--- src/history.h | 4 +- src/input.cpp | 18 +++--- src/input.h | 8 +-- src/kill.cpp | 4 +- src/kill.h | 2 +- src/null_terminated_array.cpp | 2 +- src/null_terminated_array.h | 2 +- src/pager.cpp | 2 +- src/pager.h | 2 +- src/parse_execution.cpp | 20 +++--- src/parse_execution.h | 4 +- src/parser.cpp | 6 +- src/parser.h | 8 +-- src/path.cpp | 16 ++--- src/path.h | 4 +- src/proc.h | 8 +-- src/re.cpp | 4 +- src/re.h | 2 +- src/reader.cpp | 20 +++--- src/screen.h | 2 +- src/wcstringutil.cpp | 14 ++-- src/wcstringutil.h | 10 +-- src/wutil.cpp | 10 +-- src/wutil.h | 4 +- 71 files changed, 379 insertions(+), 384 deletions(-) diff --git a/build_tools/find_globals.fish b/build_tools/find_globals.fish index 1fa1d44ed..7cee77ab4 100755 --- a/build_tools/find_globals.fish +++ b/build_tools/find_globals.fish @@ -39,7 +39,7 @@ end function cleanup_syname set -l symname $argv[1] set symname (string replace --all 'std::__1::basic_string, std::__1::allocator >' 'wcstring' $symname) - set symname (string replace --all 'std::__1::vector >' 'wcstring_list_t' $symname) + set symname (string replace --all 'std::__1::vector >' 'std::vector' $symname) echo $symname end diff --git a/build_tools/iwyu.osx.imp b/build_tools/iwyu.osx.imp index 342d8f301..b6f4bba7f 100644 --- a/build_tools/iwyu.osx.imp +++ b/build_tools/iwyu.osx.imp @@ -92,10 +92,7 @@ { symbol: ["assert", "private", '"../common.h"', "public"] }, { symbol: ["wcstring", "private", '"common.h"', "public"] }, { symbol: ["wcstring", "private", '"../common.h"', "public"] }, - { symbol: ["wcstring_list_t", "private", '"common.h"', "public"] }, - { symbol: ["wcstring_list_t", "private", '"../common.h"', "public"] }, { symbol: ["wcstring", "private", '"flog.h"', "public"] }, - { symbol: ["wcstring_list_t", "private", '"flog.h"', "public"] }, { symbol: ["size_t", "private", "", "public"] }, { symbol: ["mutex", "private", "", "public"] }, { symbol: ["sig_atomic_t", "private", "", "public"] }, diff --git a/fish-rust/src/common.rs b/fish-rust/src/common.rs index 194757c91..8cf775ec8 100644 --- a/fish-rust/src/common.rs +++ b/fish-rust/src/common.rs @@ -1021,7 +1021,7 @@ pub const HAS_WORKING_TTY_TIMESTAMPS: bool = true; /// empty string. pub static EMPTY_STRING: WString = WString::new(); -/// A global, empty wcstring_list_t. This is useful for functions which wish to return a reference +/// A global, empty string list. This is useful for functions which wish to return a reference /// to an empty string. pub static EMPTY_STRING_LIST: Vec = vec![]; diff --git a/src/autoload.cpp b/src/autoload.cpp index ebb57a487..fcfee4298 100644 --- a/src/autoload.cpp +++ b/src/autoload.cpp @@ -37,7 +37,7 @@ class autoload_file_cache_t { using timestamp_t = std::chrono::time_point; /// The directories from which to load. - const wcstring_list_t dirs_{}; + const std::vector dirs_{}; /// Our LRU cache of checks that were misses. /// The key is the command, the value is the time of the check. @@ -64,13 +64,13 @@ class autoload_file_cache_t { public: /// Initialize with a set of directories. - explicit autoload_file_cache_t(wcstring_list_t dirs) : dirs_(std::move(dirs)) {} + explicit autoload_file_cache_t(std::vector dirs) : dirs_(std::move(dirs)) {} /// Initialize with empty directories. autoload_file_cache_t() = default; /// \return the directories. - const wcstring_list_t &dirs() const { return dirs_; } + const std::vector &dirs() const { return dirs_; } /// Check if a command \p cmd can be loaded. /// If \p allow_stale is true, allow stale entries; otherwise discard them. @@ -170,8 +170,8 @@ bool autoload_t::can_autoload(const wcstring &cmd) { bool autoload_t::has_attempted_autoload(const wcstring &cmd) { return cache_->is_cached(cmd); } -wcstring_list_t autoload_t::get_autoloaded_commands() const { - wcstring_list_t result; +std::vector autoload_t::get_autoloaded_commands() const { + std::vector result; result.reserve(autoloaded_files_.size()); for (const auto &kv : autoloaded_files_) { result.push_back(kv.first); @@ -185,11 +185,11 @@ maybe_t autoload_t::resolve_command(const wcstring &cmd, const environ if (maybe_t mvar = env.get(env_var_name_)) { return resolve_command(cmd, mvar->as_list()); } else { - return resolve_command(cmd, wcstring_list_t{}); + return resolve_command(cmd, std::vector{}); } } -maybe_t autoload_t::resolve_command(const wcstring &cmd, const wcstring_list_t &paths) { +maybe_t autoload_t::resolve_command(const wcstring &cmd, const std::vector &paths) { // Are we currently in the process of autoloading this? if (current_autoloading_.count(cmd) > 0) return none(); diff --git a/src/autoload.h b/src/autoload.h index 3842571bd..6fc7c7c5d 100644 --- a/src/autoload.h +++ b/src/autoload.h @@ -47,7 +47,7 @@ class autoload_t { /// Like resolve_autoload(), but accepts the paths directly. /// This is exposed for testing. - maybe_t resolve_command(const wcstring &cmd, const wcstring_list_t &paths); + maybe_t resolve_command(const wcstring &cmd, const std::vector &paths); friend autoload_tester_t; @@ -94,7 +94,7 @@ class autoload_t { /// \return the names of all commands that have been autoloaded. Note this includes "in-flight" /// commands. - wcstring_list_t get_autoloaded_commands() const; + std::vector get_autoloaded_commands() const; /// Mark that all autoloaded files have been forgotten. /// Future calls to path_to_autoload() will return previously-returned paths. diff --git a/src/builtin.cpp b/src/builtin.cpp index b2026d476..7e5690153 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -68,7 +68,7 @@ static maybe_t try_get_rust_builtin(const wcstring &cmd); static maybe_t builtin_run_rust(parser_t &parser, io_streams_t &streams, - const wcstring_list_t &argv, RustBuiltin builtin); + const std::vector &argv, RustBuiltin builtin); /// Counts the number of arguments in the specified null-terminated array int builtin_count_args(const wchar_t *const *argv) { @@ -433,7 +433,7 @@ static const wchar_t *const help_builtins[] = {L"for", L"while", L"function", L static bool cmd_needs_help(const wcstring &cmd) { return contains(help_builtins, cmd); } /// Execute a builtin command -proc_status_t builtin_run(parser_t &parser, const wcstring_list_t &argv, io_streams_t &streams) { +proc_status_t builtin_run(parser_t &parser, const std::vector &argv, io_streams_t &streams) { if (argv.empty()) return proc_status_t::from_exit_code(STATUS_INVALID_ARGS); const wcstring &cmdname = argv.front(); @@ -491,8 +491,8 @@ proc_status_t builtin_run(parser_t &parser, const wcstring_list_t &argv, io_stre } /// Returns a list of all builtin names. -wcstring_list_t builtin_get_names() { - wcstring_list_t result; +std::vector builtin_get_names() { + std::vector result; result.reserve(BUILTIN_COUNT); for (const auto &builtin_data : builtin_datas) { result.push_back(builtin_data.name); @@ -577,7 +577,7 @@ static maybe_t try_get_rust_builtin(const wcstring &cmd) { } static maybe_t builtin_run_rust(parser_t &parser, io_streams_t &streams, - const wcstring_list_t &argv, RustBuiltin builtin) { + const std::vector &argv, RustBuiltin builtin) { int status_code; bool update_status = rust_run_builtin(parser, streams, argv, builtin, status_code); if (update_status) { diff --git a/src/builtin.h b/src/builtin.h index 5aadfdd17..055b8c284 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -80,9 +80,9 @@ struct builtin_data_t { bool builtin_exists(const wcstring &cmd); -proc_status_t builtin_run(parser_t &parser, const wcstring_list_t &argv, io_streams_t &streams); +proc_status_t builtin_run(parser_t &parser, const std::vector &argv, io_streams_t &streams); -wcstring_list_t builtin_get_names(); +std::vector builtin_get_names(); wcstring_list_ffi_t builtin_get_names_ffi(); void builtin_get_names(completion_list_t *list); const wchar_t *builtin_get_desc(const wcstring &name); diff --git a/src/builtins/argparse.cpp b/src/builtins/argparse.cpp index 04dd766ac..9549c4b81 100644 --- a/src/builtins/argparse.cpp +++ b/src/builtins/argparse.cpp @@ -35,7 +35,7 @@ struct option_spec_t { wchar_t short_flag; wcstring long_flag; wcstring validation_command; - wcstring_list_t vals; + std::vector vals; bool short_flag_valid{true}; int num_allowed{0}; int num_seen{0}; @@ -52,8 +52,8 @@ struct argparse_cmd_opts_t { size_t max_args = SIZE_MAX; wchar_t implicit_int_flag = L'\0'; wcstring name; - wcstring_list_t raw_exclusive_flags; - wcstring_list_t argv; + std::vector raw_exclusive_flags; + std::vector argv; std::unordered_map options; std::unordered_map long_to_short_flag; std::vector> exclusive_flag_sets; @@ -124,7 +124,7 @@ static int check_for_mutually_exclusive_flags(const argparse_cmd_opts_t &opts, // information to parse the values associated with any `--exclusive` flags. static int parse_exclusive_args(argparse_cmd_opts_t &opts, io_streams_t &streams) { for (const wcstring &raw_xflags : opts.raw_exclusive_flags) { - const wcstring_list_t xflags = split_string(raw_xflags, L','); + const std::vector xflags = split_string(raw_xflags, L','); if (xflags.size() < 2) { streams.err.append_format(_(L"%ls: exclusive flag string '%ls' is not valid\n"), opts.name.c_str(), raw_xflags.c_str()); @@ -473,7 +473,7 @@ static int validate_arg(parser_t &parser, const argparse_cmd_opts_t &opts, optio // Obviously if there is no arg validation command we assume the arg is okay. if (opt_spec->validation_command.empty()) return STATUS_CMD_OK; - wcstring_list_t cmd_output; + std::vector cmd_output; auto &vars = parser.vars(); diff --git a/src/builtins/bind.cpp b/src/builtins/bind.cpp index 1f52c391e..5b04fa22a 100644 --- a/src/builtins/bind.cpp +++ b/src/builtins/bind.cpp @@ -75,7 +75,7 @@ class builtin_bind_t { /// Returns false if no binding with that sequence and mode exists. bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bool user, parser_t &parser, io_streams_t &streams) { - wcstring_list_t ecmds; + std::vector ecmds; wcstring sets_mode, out; if (!input_mappings_->get(seq, bind_mode, &ecmds, user, &sets_mode)) { @@ -161,7 +161,7 @@ void builtin_bind_t::list(const wchar_t *bind_mode, bool user, parser_t &parser, /// \param all if set, all terminfo key binding names will be printed. If not set, only ones that /// are defined for this terminal are printed. void builtin_bind_t::key_names(bool all, io_streams_t &streams) { - const wcstring_list_t names = input_terminfo_get_names(!all); + const std::vector names = input_terminfo_get_names(!all); for (const wcstring &name : names) { streams.out.append(name); streams.out.push(L'\n'); @@ -170,7 +170,7 @@ void builtin_bind_t::key_names(bool all, io_streams_t &streams) { /// Print all the special key binding functions to string buffer used for standard output. void builtin_bind_t::function_names(io_streams_t &streams) { - wcstring_list_t names = input_function_get_names(); + std::vector names = input_function_get_names(); for (const auto &name : names) { auto seq = name.c_str(); diff --git a/src/builtins/complete.cpp b/src/builtins/complete.cpp index 7b237d643..0385a6fb8 100644 --- a/src/builtins/complete.cpp +++ b/src/builtins/complete.cpp @@ -33,8 +33,8 @@ /// Silly function. static void builtin_complete_add2(const wcstring &cmd, bool cmd_is_path, const wchar_t *short_opt, - const wcstring_list_t &gnu_opts, const wcstring_list_t &old_opts, - completion_mode_t result_mode, const wcstring_list_t &condition, + const std::vector &gnu_opts, const std::vector &old_opts, + completion_mode_t result_mode, const std::vector &condition, const wchar_t *comp, const wchar_t *desc, complete_flags_t flags) { for (const wchar_t *s = short_opt; *s; s++) { @@ -59,10 +59,10 @@ static void builtin_complete_add2(const wcstring &cmd, bool cmd_is_path, const w } /// Silly function. -static void builtin_complete_add(const wcstring_list_t &cmds, const wcstring_list_t &paths, - const wchar_t *short_opt, const wcstring_list_t &gnu_opt, - const wcstring_list_t &old_opt, completion_mode_t result_mode, - const wcstring_list_t &condition, const wchar_t *comp, +static void builtin_complete_add(const std::vector &cmds, const std::vector &paths, + const wchar_t *short_opt, const std::vector &gnu_opt, + const std::vector &old_opt, completion_mode_t result_mode, + const std::vector &condition, const wchar_t *comp, const wchar_t *desc, complete_flags_t flags) { for (const wcstring &cmd : cmds) { builtin_complete_add2(cmd, false /* not path */, short_opt, gnu_opt, old_opt, result_mode, @@ -76,8 +76,8 @@ static void builtin_complete_add(const wcstring_list_t &cmds, const wcstring_lis } static void builtin_complete_remove_cmd(const wcstring &cmd, bool cmd_is_path, - const wchar_t *short_opt, const wcstring_list_t &gnu_opt, - const wcstring_list_t &old_opt) { + const wchar_t *short_opt, const std::vector &gnu_opt, + const std::vector &old_opt) { bool removed = false; for (const wchar_t *s = short_opt; *s; s++) { complete_remove(cmd, cmd_is_path, wcstring{*s}, option_type_short); @@ -100,9 +100,9 @@ static void builtin_complete_remove_cmd(const wcstring &cmd, bool cmd_is_path, } } -static void builtin_complete_remove(const wcstring_list_t &cmds, const wcstring_list_t &paths, - const wchar_t *short_opt, const wcstring_list_t &gnu_opt, - const wcstring_list_t &old_opt) { +static void builtin_complete_remove(const std::vector &cmds, const std::vector &paths, + const wchar_t *short_opt, const std::vector &gnu_opt, + const std::vector &old_opt) { for (const wcstring &cmd : cmds) { builtin_complete_remove_cmd(cmd, false /* not path */, short_opt, gnu_opt, old_opt); } @@ -137,15 +137,15 @@ maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, const wch completion_mode_t result_mode{}; int remove = 0; wcstring short_opt; - wcstring_list_t gnu_opt, old_opt, subcommand; + std::vector gnu_opt, old_opt, subcommand; const wchar_t *comp = L"", *desc = L""; - wcstring_list_t condition; + std::vector condition; bool do_complete = false; bool have_do_complete_param = false; wcstring do_complete_param; - wcstring_list_t cmd_to_complete; - wcstring_list_t path; - wcstring_list_t wrap_targets; + std::vector cmd_to_complete; + std::vector path; + std::vector wrap_targets; bool preserve_order = false; bool unescape_output = true; diff --git a/src/builtins/function.cpp b/src/builtins/function.cpp index 386c65831..56e966775 100644 --- a/src/builtins/function.cpp +++ b/src/builtins/function.cpp @@ -38,9 +38,9 @@ struct function_cmd_opts_t { bool shadow_scope = true; wcstring description; std::vector events; - wcstring_list_t named_arguments; - wcstring_list_t inherit_vars; - wcstring_list_t wrap_targets; + std::vector named_arguments; + std::vector inherit_vars; + std::vector wrap_targets; }; } // namespace @@ -229,13 +229,13 @@ static int validate_function_name(int argc, const wchar_t *const *argv, wcstring /// Define a function. Calls into `function.cpp` to perform the heavy lifting of defining a /// function. -int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args, +int builtin_function(parser_t &parser, io_streams_t &streams, const std::vector &c_args, const parsed_source_ref_t &source, const ast::block_statement_t &func_node) { assert(source.has_value() && "Missing source in builtin_function"); // The wgetopt function expects 'function' as the first argument. Make a new wcstring_list with // that property. This is needed because this builtin has a different signature than the other // builtins. - wcstring_list_t args = {L"function"}; + std::vector args = {L"function"}; args.insert(args.end(), c_args.begin(), c_args.end()); null_terminated_array_t argv_array(args); diff --git a/src/builtins/function.h b/src/builtins/function.h index e0ab70edc..2eb0a8259 100644 --- a/src/builtins/function.h +++ b/src/builtins/function.h @@ -9,6 +9,6 @@ class parser_t; struct io_streams_t; -int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args, +int builtin_function(parser_t &parser, io_streams_t &streams, const std::vector &c_args, const parsed_source_ref_t &source, const ast::block_statement_t &func_node); #endif diff --git a/src/builtins/functions.cpp b/src/builtins/functions.cpp index cb3f77e06..3e62712e1 100644 --- a/src/builtins/functions.cpp +++ b/src/builtins/functions.cpp @@ -298,7 +298,7 @@ maybe_t builtin_functions(parser_t &parser, io_streams_t &streams, const wc } if (opts.list || argc == optind) { - wcstring_list_t names = function_get_names(opts.show_hidden); + std::vector names = function_get_names(opts.show_hidden); std::sort(names.begin(), names.end()); bool is_screen = !streams.out_is_redirected && isatty(STDOUT_FILENO); if (is_screen) { diff --git a/src/builtins/history.cpp b/src/builtins/history.cpp index 3eb5114ef..5c316057d 100644 --- a/src/builtins/history.cpp +++ b/src/builtins/history.cpp @@ -88,7 +88,7 @@ static bool set_hist_cmd(const wchar_t *cmd, hist_cmd_t *hist_cmd, hist_cmd_t su } static bool check_for_unexpected_hist_args(const history_cmd_opts_t &opts, const wchar_t *cmd, - const wcstring_list_t &args, io_streams_t &streams) { + const std::vector &args, io_streams_t &streams) { if (opts.history_search_type_defined || opts.show_time_format || opts.null_terminate) { const wchar_t *subcmd_str = enum_to_str(opts.hist_cmd, hist_enum_map); streams.err.append_format(_(L"%ls: %ls: subcommand takes no options\n"), cmd, subcmd_str); @@ -243,7 +243,7 @@ maybe_t builtin_history(parser_t &parser, io_streams_t &streams, const wcha // Every argument that we haven't consumed already is an argument for a subcommand (e.g., a // search term). - const wcstring_list_t args(argv + optind, argv + argc); + const std::vector args(argv + optind, argv + argc); // Establish appropriate defaults. if (opts.hist_cmd == HIST_UNDEF) opts.hist_cmd = HIST_SEARCH; diff --git a/src/builtins/path.cpp b/src/builtins/path.cpp index 9065fa435..4a59e4a58 100644 --- a/src/builtins/path.cpp +++ b/src/builtins/path.cpp @@ -243,7 +243,7 @@ static int handle_flag_t(const wchar_t **argv, parser_t &parser, io_streams_t &s if (opts->type_valid) { if (!opts->have_type) opts->type = 0; opts->have_type = true; - wcstring_list_t types = split_string_tok(w.woptarg, L","); + std::vector types = split_string_tok(w.woptarg, L","); for (const auto &t : types) { if (t == L"file") { opts->type |= TYPE_FILE; @@ -275,7 +275,7 @@ static int handle_flag_p(const wchar_t **argv, parser_t &parser, io_streams_t &s if (opts->perm_valid) { if (!opts->have_perm) opts->perm = 0; opts->have_perm = true; - wcstring_list_t perms = split_string_tok(w.woptarg, L","); + std::vector perms = split_string_tok(w.woptarg, L","); for (const auto &p : perms) { if (p == L"read") { opts->perm |= PERM_READ; @@ -800,7 +800,7 @@ static int path_sort(parser_t &parser, io_streams_t &streams, int argc, const wc } } - wcstring_list_t list; + std::vector list; arg_iterator_t aiter(argv, optind, streams, opts.null_in); while (const wcstring *arg = aiter.nextstr()) { list.push_back(*arg); diff --git a/src/builtins/read.cpp b/src/builtins/read.cpp index 11ddcec1c..dcf26d95b 100644 --- a/src/builtins/read.cpp +++ b/src/builtins/read.cpp @@ -533,7 +533,7 @@ maybe_t builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t auto tok = new_tokenizer(buff.c_str(), TOK_ACCEPT_UNFINISHED); if (opts.array) { // Array mode: assign each token as a separate element of the sole var. - wcstring_list_t tokens; + std::vector tokens; while (auto t = tok->next()) { auto text = *tok->text_of(*t); if (auto out = unescape_string(text, UNESCAPE_DEFAULT)) { @@ -576,7 +576,7 @@ maybe_t builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t size_t x = std::max(static_cast(1), buff.size()); size_t n_splits = (opts.array || static_cast(vars_left()) > x) ? x : vars_left(); - wcstring_list_t chars; + std::vector chars; chars.reserve(n_splits); int i = 0; @@ -606,11 +606,11 @@ maybe_t builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t if (!opts.have_delimiter) { // We're using IFS, so tokenize the buffer using each IFS char. This is for backward // compatibility with old versions of fish. - wcstring_list_t tokens = split_string_tok(buff, opts.delimiter); + std::vector tokens = split_string_tok(buff, opts.delimiter); parser.set_var_and_fire(*var_ptr++, opts.place, std::move(tokens)); } else { // We're using a delimiter provided by the user so use the `string split` behavior. - wcstring_list_t splits; + std::vector splits; split_about(buff.begin(), buff.end(), opts.delimiter.begin(), opts.delimiter.end(), &splits); @@ -622,7 +622,7 @@ maybe_t builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t // We're using IFS, so tokenize the buffer using each IFS char. This is for backward // compatibility with old versions of fish. // Note the final variable gets any remaining text. - wcstring_list_t var_vals = split_string_tok(buff, opts.delimiter, vars_left()); + std::vector var_vals = split_string_tok(buff, opts.delimiter, vars_left()); size_t val_idx = 0; while (vars_left()) { wcstring val; @@ -633,7 +633,7 @@ maybe_t builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t } } else { // We're using a delimiter provided by the user so use the `string split` behavior. - wcstring_list_t splits; + std::vector splits; // We're making at most argc - 1 splits so the last variable // is set to the remaining string. split_about(buff.begin(), buff.end(), opts.delimiter.begin(), opts.delimiter.end(), diff --git a/src/builtins/set.cpp b/src/builtins/set.cpp index 968638acb..dd858a065 100644 --- a/src/builtins/set.cpp +++ b/src/builtins/set.cpp @@ -301,7 +301,7 @@ static void handle_env_return(int retval, const wchar_t *cmd, const wcstring &ke /// Call vars.set. If this is a path variable, e.g. PATH, validate the elements. On error, print a /// description of the problem to stderr. static int env_set_reporting_errors(const wchar_t *cmd, const wcstring &key, int scope, - wcstring_list_t list, io_streams_t &streams, parser_t &parser) { + std::vector list, io_streams_t &streams, parser_t &parser) { int retval = parser.set_var_and_fire(key, scope | ENV_USER, std::move(list)); // If this returned OK, the parser already fired the event. handle_env_return(retval, cmd, key, streams); @@ -396,7 +396,7 @@ static maybe_t split_var_and_indexes(const wchar_t *arg, env_mode_f /// Given a list of values and 1-based indexes, return a new list with those elements removed. /// Note this deliberately accepts both args by value, as it modifies them both. -static wcstring_list_t erased_at_indexes(wcstring_list_t input, std::vector indexes) { +static std::vector erased_at_indexes(std::vector input, std::vector indexes) { // Sort our indexes into *descending* order. std::sort(indexes.begin(), indexes.end(), std::greater()); @@ -436,7 +436,7 @@ static int builtin_set_list(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, UNUSED(parser); bool names_only = opts.list; - wcstring_list_t names = parser.vars().get_names(compute_scope(opts)); + std::vector names = parser.vars().get_names(compute_scope(opts)); sort(names.begin(), names.end()); for (const auto &key : names) { @@ -538,7 +538,7 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams const wchar_t *exportv = var->exports() ? _(L"exported") : _(L"unexported"); const wchar_t *pathvarv = var->is_pathvar() ? _(L" a path variable") : L""; - wcstring_list_t vals = var->as_list(); + std::vector vals = var->as_list(); streams.out.append_format(_(L"$%ls: set in %ls scope, %ls,%ls with %d elements"), var_name, scope_name, exportv, pathvarv, vals.size()); // HACK: PWD can be set, depending on how you ask. @@ -570,7 +570,7 @@ static int builtin_set_show(const wchar_t *cmd, const set_cmd_opts_t &opts, int const auto &vars = parser.vars(); auto inheriteds = env_get_inherited(); if (argc == 0) { // show all vars - wcstring_list_t names = vars.get_names(ENV_USER); + std::vector names = vars.get_names(ENV_USER); sort(names.begin(), names.end()); for (const auto &name : names) { if (name == L"history") continue; @@ -656,7 +656,7 @@ static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, } } else { // remove just the specified indexes of the var if (!split->var) return STATUS_CMD_ERROR; - wcstring_list_t result = erased_at_indexes(split->var->as_list(), split->indexes); + std::vector result = erased_at_indexes(split->var->as_list(), split->indexes); retval = env_set_reporting_errors(cmd, split->varname, scope, std::move(result), streams, parser); } @@ -674,9 +674,9 @@ static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, /// Return a list of new values for the variable \p varname, respecting the \p opts. /// The arguments are given as the argc, argv pair. /// This handles the simple case where there are no indexes. -static wcstring_list_t new_var_values(const wcstring &varname, const set_cmd_opts_t &opts, int argc, +static std::vector new_var_values(const wcstring &varname, const set_cmd_opts_t &opts, int argc, const wchar_t *const *argv, const environment_t &vars) { - wcstring_list_t result; + std::vector result; if (!opts.prepend && !opts.append) { // Not prepending or appending. result.assign(argv, argv + argc); @@ -704,7 +704,7 @@ static wcstring_list_t new_var_values(const wcstring &varname, const set_cmd_opt } /// This handles the more difficult case of setting individual slices of a var. -static wcstring_list_t new_var_values_by_index(const split_var_t &split, int argc, +static std::vector new_var_values_by_index(const split_var_t &split, int argc, const wchar_t *const *argv) { assert(static_cast(argc) == split.indexes.size() && "Must have the same number of indexes as arguments"); @@ -712,7 +712,7 @@ static wcstring_list_t new_var_values_by_index(const split_var_t &split, int arg // Inherit any existing values. // Note unlike the append/prepend case, we start with a variable in the same scope as we are // setting. - wcstring_list_t result; + std::vector result; if (split.var) result = split.var->as_list(); // For each (index, argument) pair, set the element in our \p result to the replacement string. @@ -788,7 +788,7 @@ static int builtin_set_set(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, c } } - wcstring_list_t new_values; + std::vector new_values; if (split->indexes.empty()) { // Handle the simple, common, case. Set the var to the specified values. new_values = new_var_values(split->varname, opts, argc, argv, parser.vars()); diff --git a/src/builtins/set_color.cpp b/src/builtins/set_color.cpp index 01881fbe0..85d1fe3b3 100644 --- a/src/builtins/set_color.cpp +++ b/src/builtins/set_color.cpp @@ -65,7 +65,7 @@ static void print_modifiers(outputter_t &outp, bool bold, bool underline, bool i } } -static void print_colors(io_streams_t &streams, wcstring_list_t args, bool bold, bool underline, +static void print_colors(io_streams_t &streams, std::vector args, bool bold, bool underline, bool italics, bool dim, bool reverse, rgb_color_t bg) { outputter_t outp; if (args.empty()) args = rgb_color_t::named_color_names(); @@ -184,7 +184,7 @@ maybe_t builtin_set_color(parser_t &parser, io_streams_t &streams, const wc if (bgcolor && bg.is_special()) { bg = rgb_color_t(L""); } - wcstring_list_t args(argv + w.woptind, argv + argc); + std::vector args(argv + w.woptind, argv + argc); print_colors(streams, args, bold, underline, italics, dim, reverse, bg); return STATUS_CMD_OK; } diff --git a/src/builtins/source.cpp b/src/builtins/source.cpp index 75ef81fb6..789c1d835 100644 --- a/src/builtins/source.cpp +++ b/src/builtins/source.cpp @@ -98,7 +98,7 @@ maybe_t builtin_source(parser_t &parser, io_streams_t &streams, const wchar // Construct argv from our null-terminated list. // This is slightly subtle. If this is a bare `source` with no args then `argv + optind` already // points to the end of argv. Otherwise we want to skip the file name to get to the args if any. - wcstring_list_t argv_list; + std::vector argv_list; const wchar_t *const *remaining_args = argv + optind + (argc == optind ? 0 : 1); for (size_t i = 0, len = null_terminated_array_length(remaining_args); i < len; i++) { argv_list.push_back(remaining_args[i]); diff --git a/src/builtins/status.cpp b/src/builtins/status.cpp index 0c57b2b5d..edfbcf8b4 100644 --- a/src/builtins/status.cpp +++ b/src/builtins/status.cpp @@ -314,7 +314,7 @@ maybe_t builtin_status(parser_t &parser, io_streams_t &streams, const wchar } // Every argument that we haven't consumed already is an argument for a subcommand. - const wcstring_list_t args(argv + optind, argv + argc); + const std::vector args(argv + optind, argv + argc); switch (opts.status_cmd) { case STATUS_UNDEF: { diff --git a/src/builtins/string.cpp b/src/builtins/string.cpp index ab02c8406..1a5695575 100644 --- a/src/builtins/string.cpp +++ b/src/builtins/string.cpp @@ -340,7 +340,7 @@ static int handle_flag_f(const wchar_t **argv, parser_t &parser, io_streams_t &s return STATUS_CMD_OK; } else if (opts->fields_valid) { for (const wcstring &s : split_string(w.woptarg, L',')) { - wcstring_list_t range = split_string(s, L'-'); + std::vector range = split_string(s, L'-'); if (range.size() == 2) { int begin = fish_wcstoi(range.at(0).c_str()); if (begin <= 0 || errno == ERANGE) { @@ -919,7 +919,7 @@ static maybe_t try_compile_regex(const wcstring &pattern, const opt /// Check if a list of capture group names is valid for variables. If any are invalid then report an /// error to \p streams. \return true if all names are valid. -static bool validate_capture_group_names(const wcstring_list_t &capture_group_names, +static bool validate_capture_group_names(const std::vector &capture_group_names, io_streams_t &streams) { for (const wcstring &name : capture_group_names) { if (env_var_t::flags_for(name.c_str()) & env_var_t::flag_read_only) { @@ -943,12 +943,12 @@ class regex_matcher_t final : public string_matcher_t { match_data_t match_data_; // map from group name to matched substrings, for the first argument. - std::map first_match_captures_; + std::map> first_match_captures_; void populate_captures_from_match(const wcstring &subject) { for (auto &kv : first_match_captures_) { const auto &name = kv.first; - wcstring_list_t &vals = kv.second; + std::vector &vals = kv.second; // If there are multiple named groups and --all was used, we need to ensure that // the indexes are always in sync between the variables. If an optional named @@ -1011,7 +1011,7 @@ class regex_matcher_t final : public string_matcher_t { : string_matcher_t(opts), regex_(std::move(regex)), match_data_(regex_.prepare()) { // Populate first_match_captures_ with the capture group names and empty lists. for (const wcstring &name : regex_.capture_group_names()) { - first_match_captures_.emplace(name, wcstring_list_t{}); + first_match_captures_.emplace(name, std::vector{}); } } @@ -1372,12 +1372,12 @@ static int string_split_maybe0(parser_t &parser, io_streams_t &streams, int argc const wcstring sep = is_split0 ? wcstring(1, L'\0') : wcstring(opts.arg1); - std::vector all_splits; + std::vector> all_splits; size_t split_count = 0; size_t arg_count = 0; arg_iterator_t aiter(argv, optind, streams, !is_split0); while (const wcstring *arg = aiter.nextstr()) { - wcstring_list_t splits; + std::vector splits; if (opts.right) { split_about(arg->rbegin(), arg->rend(), sep.rbegin(), sep.rend(), &splits, opts.max, opts.no_empty); diff --git a/src/builtins/test.cpp b/src/builtins/test.cpp index b4062ae7a..142bca8c5 100644 --- a/src/builtins/test.cpp +++ b/src/builtins/test.cpp @@ -121,9 +121,9 @@ class number_t { }; static bool binary_primary_evaluate(test_expressions::token_t token, const wcstring &left, - const wcstring &right, wcstring_list_t &errors); + const wcstring &right, std::vector &errors); static bool unary_primary_evaluate(test_expressions::token_t token, const wcstring &arg, - io_streams_t *streams, wcstring_list_t &errors); + io_streams_t *streams, std::vector &errors); enum { UNARY_PRIMARY = 1 << 0, BINARY_PRIMARY = 1 << 1 }; @@ -195,8 +195,8 @@ static const token_info_t *token_for_string(const wcstring &str) { class expression; class test_parser { private: - wcstring_list_t strings; - wcstring_list_t errors; + std::vector strings; + std::vector errors; int error_idx; unique_ptr error(unsigned int idx, const wchar_t *fmt, ...); @@ -205,7 +205,7 @@ class test_parser { const wcstring &arg(unsigned int idx) { return strings.at(idx); } public: - explicit test_parser(wcstring_list_t val) : strings(std::move(val)) {} + explicit test_parser(std::vector val) : strings(std::move(val)) {} unique_ptr parse_expression(unsigned int start, unsigned int end); unique_ptr parse_3_arg_expression(unsigned int start, unsigned int end); @@ -219,7 +219,7 @@ class test_parser { unique_ptr parse_binary_primary(unsigned int start, unsigned int end); unique_ptr parse_just_a_string(unsigned int start, unsigned int end); - static unique_ptr parse_args(const wcstring_list_t &args, wcstring &err, + static unique_ptr parse_args(const std::vector &args, wcstring &err, const wchar_t *program_name); }; @@ -242,7 +242,7 @@ class expression { virtual ~expression() = default; /// Evaluate returns true if the expression is true (i.e. STATUS_CMD_OK). - virtual bool evaluate(io_streams_t *streams, wcstring_list_t &errors) = 0; + virtual bool evaluate(io_streams_t *streams, std::vector &errors) = 0; }; /// Single argument like -n foo or "just a string". @@ -251,7 +251,7 @@ class unary_primary final : public expression { wcstring arg; unary_primary(token_t tok, range_t where, wcstring what) : expression(tok, where), arg(std::move(what)) {} - bool evaluate(io_streams_t *streams, wcstring_list_t &errors) override; + bool evaluate(io_streams_t *streams, std::vector &errors) override; }; /// Two argument primary like foo != bar. @@ -262,7 +262,7 @@ class binary_primary final : public expression { binary_primary(token_t tok, range_t where, wcstring left, wcstring right) : expression(tok, where), arg_left(std::move(left)), arg_right(std::move(right)) {} - bool evaluate(io_streams_t *streams, wcstring_list_t &errors) override; + bool evaluate(io_streams_t *streams, std::vector &errors) override; }; /// Unary operator like bang. @@ -271,7 +271,7 @@ class unary_operator final : public expression { unique_ptr subject; unary_operator(token_t tok, range_t where, unique_ptr exp) : expression(tok, where), subject(std::move(exp)) {} - bool evaluate(io_streams_t *streams, wcstring_list_t &errors) override; + bool evaluate(io_streams_t *streams, std::vector &errors) override; }; /// Combining expression. Contains a list of AND or OR expressions. It takes more than two so that @@ -290,7 +290,7 @@ class combining_expression final : public expression { ~combining_expression() override = default; - bool evaluate(io_streams_t *streams, wcstring_list_t &errors) override; + bool evaluate(io_streams_t *streams, std::vector &errors) override; }; /// Parenthetical expression. @@ -300,7 +300,7 @@ class parenthetical_expression final : public expression { parenthetical_expression(token_t tok, range_t where, unique_ptr expr) : expression(tok, where), contents(std::move(expr)) {} - bool evaluate(io_streams_t *streams, wcstring_list_t &errors) override; + bool evaluate(io_streams_t *streams, std::vector &errors) override; }; void test_parser::add_error(unsigned int idx, const wchar_t *fmt, ...) { @@ -559,7 +559,7 @@ unique_ptr test_parser::parse_expression(unsigned int start, unsigne } } -unique_ptr test_parser::parse_args(const wcstring_list_t &args, wcstring &err, +unique_ptr test_parser::parse_args(const std::vector &args, wcstring &err, const wchar_t *program_name) { // Empty list and one-arg list should be handled by caller. assert(args.size() > 1); @@ -614,15 +614,15 @@ unique_ptr test_parser::parse_args(const wcstring_list_t &args, wcst return result; } -bool unary_primary::evaluate(io_streams_t *streams, wcstring_list_t &errors) { +bool unary_primary::evaluate(io_streams_t *streams, std::vector &errors) { return unary_primary_evaluate(token, arg, streams, errors); } -bool binary_primary::evaluate(io_streams_t *, wcstring_list_t &errors) { +bool binary_primary::evaluate(io_streams_t *, std::vector &errors) { return binary_primary_evaluate(token, arg_left, arg_right, errors); } -bool unary_operator::evaluate(io_streams_t *streams, wcstring_list_t &errors) { +bool unary_operator::evaluate(io_streams_t *streams, std::vector &errors) { if (token == test_bang) { assert(subject.get()); return !subject->evaluate(streams, errors); @@ -632,7 +632,7 @@ bool unary_operator::evaluate(io_streams_t *streams, wcstring_list_t &errors) { return false; } -bool combining_expression::evaluate(io_streams_t *streams, wcstring_list_t &errors) { +bool combining_expression::evaluate(io_streams_t *streams, std::vector &errors) { if (token == test_combine_and || token == test_combine_or) { assert(!subjects.empty()); //!OCLINT(multiple unary operator) assert(combiners.size() + 1 == subjects.size()); @@ -674,7 +674,7 @@ bool combining_expression::evaluate(io_streams_t *streams, wcstring_list_t &erro return false; } -bool parenthetical_expression::evaluate(io_streams_t *streams, wcstring_list_t &errors) { +bool parenthetical_expression::evaluate(io_streams_t *streams, std::vector &errors) { return contents->evaluate(streams, errors); } @@ -696,7 +696,7 @@ static bool parse_double(const wcstring &argstr, double *out_res) { // example, should we interpret 0x10 as 0, 10, or 16? Here we use only base 10 and use wcstoll, // which allows for leading + and -, and whitespace. This is consistent, albeit a bit more lenient // since we allow trailing whitespace, with other implementations such as bash. -static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t &errors) { +static bool parse_number(const wcstring &arg, number_t *number, std::vector &errors) { const wchar_t *argcs = arg.c_str(); double floating = 0; bool got_float = parse_double(arg, &floating); @@ -742,7 +742,7 @@ static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t } static bool binary_primary_evaluate(test_expressions::token_t token, const wcstring &left, - const wcstring &right, wcstring_list_t &errors) { + const wcstring &right, std::vector &errors) { using namespace test_expressions; number_t ln, rn; switch (token) { @@ -793,7 +793,7 @@ static bool binary_primary_evaluate(test_expressions::token_t token, const wcstr } static bool unary_primary_evaluate(test_expressions::token_t token, const wcstring &arg, - io_streams_t *streams, wcstring_list_t &errors) { + io_streams_t *streams, std::vector &errors) { using namespace test_expressions; struct stat buf; switch (token) { @@ -905,7 +905,7 @@ maybe_t builtin_test(parser_t &parser, io_streams_t &streams, const wchar_t } // Collect the arguments into a list. - const wcstring_list_t args(argv + 1, argv + 1 + argc); + const std::vector args(argv + 1, argv + 1 + argc); if (argc == 0) { return STATUS_INVALID_ARGS; // Per 1003.1, exit false. @@ -923,7 +923,7 @@ maybe_t builtin_test(parser_t &parser, io_streams_t &streams, const wchar_t return STATUS_CMD_ERROR; } - wcstring_list_t eval_errors; + std::vector eval_errors; bool result = expr->evaluate(&streams, eval_errors); if (!eval_errors.empty()) { if (!should_suppress_stderr_for_tests()) { diff --git a/src/color.cpp b/src/color.cpp index dee3f65a6..070364b2f 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -139,8 +139,8 @@ static constexpr named_color_t named_colors[] = { }; ASSERT_SORTED_BY_NAME(named_colors); -wcstring_list_t rgb_color_t::named_color_names() { - wcstring_list_t result; +std::vector rgb_color_t::named_color_names() { + std::vector result; constexpr size_t colors_count = sizeof(named_colors) / sizeof(named_colors[0]); result.reserve(1 + colors_count); for (const auto &named_color : named_colors) { diff --git a/src/color.h b/src/color.h index 8bc20ec5d..2097afc31 100644 --- a/src/color.h +++ b/src/color.h @@ -167,7 +167,7 @@ class rgb_color_t { bool operator!=(const rgb_color_t &other) const { return !(*this == other); } /// Returns the names of all named colors. - static wcstring_list_t named_color_names(void); + static std::vector named_color_names(void); }; static_assert(sizeof(rgb_color_t) <= 4, "rgb_color_t is too big"); diff --git a/src/common.cpp b/src/common.cpp index 1e348f63c..144db0b99 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -58,7 +58,7 @@ struct termios shell_modes; const wcstring g_empty_string{}; -const wcstring_list_t g_empty_string_list{}; +const std::vector g_empty_string_list{}; /// This allows us to notice when we've forked. static relaxed_atomic_bool_t is_forked_proc{false}; @@ -172,13 +172,13 @@ bool is_windows_subsystem_for_linux() { #ifdef HAVE_BACKTRACE_SYMBOLS // This function produces a stack backtrace with demangled function & method names. It is based on // https://gist.github.com/fmela/591333 but adapted to the style of the fish project. -[[gnu::noinline]] static wcstring_list_t demangled_backtrace(int max_frames, int skip_levels) { +[[gnu::noinline]] static std::vector demangled_backtrace(int max_frames, int skip_levels) { void *callstack[128]; const int n_max_frames = sizeof(callstack) / sizeof(callstack[0]); int n_frames = backtrace(callstack, n_max_frames); char **symbols = backtrace_symbols(callstack, n_frames); wchar_t text[1024]; - wcstring_list_t backtrace_text; + std::vector backtrace_text; if (skip_levels + max_frames < n_frames) n_frames = skip_levels + max_frames; @@ -207,7 +207,7 @@ bool is_windows_subsystem_for_linux() { [[gnu::noinline]] void show_stackframe(int frame_count, int skip_levels) { if (frame_count < 1) return; - wcstring_list_t bt = demangled_backtrace(frame_count, skip_levels + 2); + std::vector bt = demangled_backtrace(frame_count, skip_levels + 2); FLOG(error, L"Backtrace:\n" + join_strings(bt, L'\n') + L'\n'); } diff --git a/src/common.h b/src/common.h index 7ca0394ef..4fec83f2e 100644 --- a/src/common.h +++ b/src/common.h @@ -57,7 +57,6 @@ // Common string type. typedef std::wstring wcstring; -typedef std::vector wcstring_list_t; struct termsize_t; @@ -200,9 +199,9 @@ extern const bool has_working_tty_timestamps; /// empty string. extern const wcstring g_empty_string; -/// A global, empty wcstring_list_t. This is useful for functions which wish to return a reference -/// to an empty string. -extern const wcstring_list_t g_empty_string_list; +/// A global, empty std::vector. This is useful for functions which wish to return a +/// reference to an empty string. +extern const std::vector g_empty_string_list; // Pause for input, then exit the program. If supported, print a backtrace first. #define FATAL_EXIT() \ diff --git a/src/complete.cpp b/src/complete.cpp index 7dd34b4fe..1d7476bc9 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -97,7 +97,7 @@ struct complete_entry_opt_t { /// Description of the completion. wcstring desc; // Conditions under which to use the option, expanded and evaluated at completion time. - wcstring_list_t conditions; + std::vector conditions; /// Type of the option: args_only, short, single_long, or double_long. complete_option_type_t type; /// Determines how completions should be performed on the argument after the switch. @@ -163,7 +163,7 @@ using completion_entry_map_t = std::map; static owning_lock s_completion_map; /// Completion "wrapper" support. The map goes from wrapping-command to wrapped-command-list. -using wrapper_map_t = std::unordered_map; +using wrapper_map_t = std::unordered_map>; static owning_lock wrapper_map; description_func_t const_desc(const wcstring &s) { @@ -334,7 +334,7 @@ class completer_t { completion_receiver_t completions; /// Commands which we would have tried to load, if we had a parser. - wcstring_list_t needs_load; + std::vector needs_load; /// Table of completions conditions that have already been tested and the corresponding test /// results. @@ -363,7 +363,7 @@ class completer_t { bool complete_variable(const wcstring &str, size_t start_offset); bool condition_test(const wcstring &condition); - bool conditions_test(const wcstring_list_t &conditions); + bool conditions_test(const std::vector &conditions); void complete_strings(const wcstring &wc_escaped, const description_func_t &desc_func, const completion_list_t &possible_comp, complete_flags_t flags, @@ -380,7 +380,7 @@ class completer_t { // Bag of data to support expanding a command's arguments using custom completions, including // the wrap chain. struct custom_arg_data_t { - explicit custom_arg_data_t(wcstring_list_t *vars) : var_assignments(vars) { assert(vars); } + explicit custom_arg_data_t(std::vector *vars) : var_assignments(vars) { assert(vars); } // The unescaped argument before the argument which is being completed, or empty if none. wcstring previous_argument{}; @@ -402,7 +402,7 @@ class completer_t { // The list of variable assignments: escaped strings of the form VAR=VAL. // This may be temporarily appended to as we explore the wrap chain. // When completing, variable assignments are really set in a local scope. - wcstring_list_t *var_assignments; + std::vector *var_assignments; // The set of wrapped commands which we have visited, and so should not be explored again. std::set visited_wrapped_commands{}; @@ -413,7 +413,7 @@ class completer_t { void walk_wrap_chain(const wcstring &cmd, const wcstring &cmdline, source_range_t cmdrange, custom_arg_data_t *ad); - cleanup_t apply_var_assignments(const wcstring_list_t &var_assignments); + cleanup_t apply_var_assignments(const std::vector &var_assignments); bool empty() const { return completions.empty(); } @@ -430,7 +430,7 @@ class completer_t { completion_list_t acquire_completions() { return completions.take(); } - wcstring_list_t acquire_needs_load() { return std::move(needs_load); } + std::vector acquire_needs_load() { return std::move(needs_load); } }; // Autoloader for completions. @@ -462,7 +462,7 @@ bool completer_t::condition_test(const wcstring &condition) { return test_res; } -bool completer_t::conditions_test(const wcstring_list_t &conditions) { +bool completer_t::conditions_test(const std::vector &conditions) { for (const auto &c : conditions) { if (!condition_test(c)) return false; } @@ -575,7 +575,7 @@ void completer_t::complete_cmd_desc(const wcstring &str) { // First locate a list of possible descriptions using a single call to apropos or a direct // search if we know the location of the whatis database. This can take some time on slower // systems with a large set of manuals, but it should be ok since apropos is only called once. - wcstring_list_t list; + std::vector list; (void)exec_subshell(lookup_cmd, *ctx.parser, list, false /* don't apply exit status */); // Then discard anything that is not a possible completion and put the result into a @@ -657,7 +657,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd) { if (str_cmd.empty() || (str_cmd.find(L'/') == wcstring::npos && str_cmd.at(0) != L'~')) { bool include_hidden = !str_cmd.empty() && str_cmd.at(0) == L'_'; - wcstring_list_t names = function_get_names(include_hidden); + std::vector names = function_get_names(include_hidden); for (wcstring &name : names) { // Append all known matching functions append_completion(&possible_comp, std::move(name)); @@ -1312,7 +1312,7 @@ bool completer_t::try_complete_user(const wcstring &str) { // If we have variable assignments, attempt to apply them in our parser. As soon as the return // value goes out of scope, the variables will be removed from the parser. -cleanup_t completer_t::apply_var_assignments(const wcstring_list_t &var_assignments) { +cleanup_t completer_t::apply_var_assignments(const std::vector &var_assignments) { if (!ctx.parser || var_assignments.empty()) return cleanup_t{[] {}}; env_stack_t &vars = ctx.parser->vars(); assert(&vars == &ctx.vars && @@ -1335,7 +1335,7 @@ cleanup_t completer_t::apply_var_assignments(const wcstring_list_t &var_assignme auto expand_ret = expand_string(expression, &expression_expanded, expand_flags, ctx); // If expansion succeeds, set the value; if it fails (e.g. it has a cmdsub) set an empty // value anyways. - wcstring_list_t vals; + std::vector vals; if (expand_ret == expand_result_t::ok) { for (auto &completion : expression_expanded) { vals.emplace_back(std::move(completion.completion)); @@ -1396,7 +1396,7 @@ void completer_t::walk_wrap_chain(const wcstring &cmd, const wcstring &cmdline, // Extract command from the command line and invoke the receiver with it. complete_custom(cmd, cmdline, ad); - wcstring_list_t targets = complete_get_wrap_targets(cmd); + std::vector targets = complete_get_wrap_targets(cmd); scoped_push saved_depth(&ad->wrap_depth, ad->wrap_depth + 1); for (const wcstring &wt : targets) { @@ -1491,7 +1491,7 @@ void completer_t::mark_completions_duplicating_arguments(const wcstring &cmd, const wcstring &prefix, const std::vector &args) { // Get all the arguments, unescaped, into an array that we're going to bsearch. - wcstring_list_t arg_strs; + std::vector arg_strs; for (const auto &arg : args) { wcstring argstr = *arg.get_source(cmd); if (auto argstr_unesc = unescape_string(argstr, UNESCAPE_DEFAULT)) { @@ -1556,7 +1556,7 @@ void completer_t::perform_for_commandline(wcstring cmdline) { // Consume variable assignments in tokens strictly before the cursor. // This is a list of (escaped) strings of the form VAR=VAL. - wcstring_list_t var_assignments; + std::vector var_assignments; for (const tok_t &tok : tokens) { if (tok.location_in_or_at_end_of_source_range(cursor_pos)) break; wcstring tok_src = *tok.get_source(cmdline); @@ -1715,7 +1715,7 @@ void append_completion(completion_list_t *completions, wcstring comp, wcstring d void complete_add(const wcstring &cmd, bool cmd_is_path, const wcstring &option, complete_option_type_t option_type, completion_mode_t result_mode, - wcstring_list_t condition, const wchar_t *comp, const wchar_t *desc, + std::vector condition, const wchar_t *comp, const wchar_t *desc, complete_flags_t flags) { // option should be empty iff the option type is arguments only. assert(option.empty() == (option_type == option_type_args_only)); @@ -1756,7 +1756,7 @@ void complete_remove_all(const wcstring &cmd, bool cmd_is_path) { } completion_list_t complete(const wcstring &cmd_with_subcmds, completion_request_options_t flags, - const operation_context_t &ctx, wcstring_list_t *out_needs_loads) { + const operation_context_t &ctx, std::vector *out_needs_loads) { // Determine the innermost subcommand. const wchar_t *cmdsubst_begin, *cmdsubst_end; parse_util_cmdsubst_extent(cmd_with_subcmds.c_str(), cmd_with_subcmds.size(), &cmdsubst_begin, @@ -1900,7 +1900,7 @@ void complete_invalidate_path() { // TODO: here we unload all completions for commands that are loaded by the autoloader. We also // unload any completions that the user may specified on the command line. We should in // principle track those completions loaded by the autoloader alone. - wcstring_list_t cmds = completion_autoloader.acquire()->get_autoloaded_commands(); + std::vector cmds = completion_autoloader.acquire()->get_autoloaded_commands(); for (const wcstring &cmd : cmds) { complete_remove_all(cmd, false /* not a path */); } @@ -1919,7 +1919,7 @@ bool complete_add_wrapper(const wcstring &command, const wcstring &new_target) { auto locked_map = wrapper_map.acquire(); wrapper_map_t &wraps = *locked_map; - wcstring_list_t *targets = &wraps[command]; + std::vector *targets = &wraps[command]; // If it's already present, we do nothing. if (!contains(*targets, new_target)) { targets->push_back(new_target); @@ -1937,7 +1937,7 @@ bool complete_remove_wrapper(const wcstring &command, const wcstring &target_to_ bool result = false; auto current_targets_iter = wraps.find(command); if (current_targets_iter != wraps.end()) { - wcstring_list_t *targets = ¤t_targets_iter->second; + std::vector *targets = ¤t_targets_iter->second; auto where = std::find(targets->begin(), targets->end(), target_to_remove); if (where != targets->end()) { targets->erase(where); @@ -1947,7 +1947,7 @@ bool complete_remove_wrapper(const wcstring &command, const wcstring &target_to_ return result; } -wcstring_list_t complete_get_wrap_targets(const wcstring &command) { +std::vector complete_get_wrap_targets(const wcstring &command) { if (command.empty()) { return {}; } diff --git a/src/complete.h b/src/complete.h index 80042c0a5..7a725b0c8 100644 --- a/src/complete.h +++ b/src/complete.h @@ -242,7 +242,7 @@ void completions_sort_and_prioritize(completion_list_t *comps, /// \param flags A set of completion flags void complete_add(const wcstring &cmd, bool cmd_is_path, const wcstring &option, complete_option_type_t option_type, completion_mode_t result_mode, - wcstring_list_t condition, const wchar_t *comp, const wchar_t *desc, + std::vector condition, const wchar_t *comp, const wchar_t *desc, complete_flags_t flags); /// Remove a previously defined completion. @@ -263,7 +263,7 @@ bool complete_load(const wcstring &cmd, parser_t &parser); class operation_context_t; completion_list_t complete(const wcstring &cmd, completion_request_options_t flags, const operation_context_t &ctx, - wcstring_list_t *out_needs_load = nullptr); + std::vector *out_needs_load = nullptr); /// Return a list of all current completions. wcstring complete_print(const wcstring &cmd = L""); @@ -283,7 +283,7 @@ bool complete_add_wrapper(const wcstring &command, const wcstring &new_target); bool complete_remove_wrapper(const wcstring &command, const wcstring &target_to_remove); /// Returns a list of wrap targets for a given command. -wcstring_list_t complete_get_wrap_targets(const wcstring &command); +std::vector complete_get_wrap_targets(const wcstring &command); // Observes that fish_complete_path has changed. void complete_invalidate_path(); diff --git a/src/env.cpp b/src/env.cpp index b5e889856..37860bd6a 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -150,7 +150,7 @@ static export_generation_t next_export_generation() { return ++*val; } -const wcstring_list_t &env_var_t::as_list() const { return *vals_; } +const std::vector &env_var_t::as_list() const { return *vals_; } wchar_t env_var_t::get_delimiter() const { return is_pathvar() ? PATH_ARRAY_SEP : NONPATH_ARRAY_SEP; @@ -159,7 +159,7 @@ wchar_t env_var_t::get_delimiter() const { /// Return a string representation of the var. wcstring env_var_t::as_string() const { return join_strings(*vals_, get_delimiter()); } -void env_var_t::to_list(wcstring_list_t &out) const { out = *vals_; } +void env_var_t::to_list(std::vector &out) const { out = *vals_; } env_var_t::env_var_flags_t env_var_t::flags_for(const wchar_t *name) { env_var_flags_t result = 0; @@ -168,8 +168,8 @@ env_var_t::env_var_flags_t env_var_t::flags_for(const wchar_t *name) { } /// \return a singleton empty list, to avoid unnecessary allocations in env_var_t. -std::shared_ptr env_var_t::empty_list() { - static const auto s_empty_result = std::make_shared(); +std::shared_ptr> env_var_t::empty_list() { + static const auto s_empty_result = std::make_shared>(); return s_empty_result; } @@ -204,7 +204,7 @@ maybe_t null_environment_t::get(const wcstring &key, env_mode_flags_t UNUSED(mode); return none(); } -wcstring_list_t null_environment_t::get_names(env_mode_flags_t flags) const { +std::vector null_environment_t::get_names(env_mode_flags_t flags) const { UNUSED(flags); return {}; } @@ -484,7 +484,7 @@ void env_init(const struct config_paths_t *paths, bool do_uvars, bool default_pa } } -static int set_umask(const wcstring_list_t &list_val) { +static int set_umask(const std::vector &list_val) { long mask = -1; if (list_val.size() == 1 && !list_val.front().empty()) { mask = fish_wcstol(list_val.front().c_str(), nullptr, 8); @@ -604,7 +604,7 @@ class env_scoped_impl_t : public environment_t, noncopyable_t { } maybe_t get(const wcstring &key, env_mode_flags_t mode = ENV_DEFAULT) const override; - wcstring_list_t get_names(env_mode_flags_t flags) const override; + std::vector get_names(env_mode_flags_t flags) const override; perproc_data_t &perproc_data() { return perproc_data_; } const perproc_data_t &perproc_data() const { return perproc_data_; } @@ -712,7 +712,7 @@ std::shared_ptr env_scoped_impl_t::create_export get_exported(this->globals_, vals); get_exported(this->locals_, vals); - const wcstring_list_t uni = uvars()->get_names(true, false); + const std::vector uni = uvars()->get_names(true, false); for (const wcstring &key : uni) { auto var = uvars()->get(key); assert(var && "Variable should be present in uvars"); @@ -769,14 +769,14 @@ maybe_t env_scoped_impl_t::try_get_computed(const wcstring &key) cons if (!history) { history = history_t::with_name(history_session_id(*this)); } - wcstring_list_t result; + std::vector result; if (history) history->get_history(result); return env_var_t(L"history", std::move(result)); } else if (key == L"fish_killring") { return env_var_t(L"fish_killring", kill_entries()); } else if (key == L"pipestatus") { const auto &js = perproc_data().statuses; - wcstring_list_t result; + std::vector result; result.reserve(js.pipestatus.size()); for (int i : js.pipestatus) { result.push_back(to_string(i)); @@ -868,7 +868,7 @@ maybe_t env_scoped_impl_t::get(const wcstring &key, env_mode_flags_t return result; } -wcstring_list_t env_scoped_impl_t::get_names(env_mode_flags_t flags) const { +std::vector env_scoped_impl_t::get_names(env_mode_flags_t flags) const { const query_t query(flags); std::set names; @@ -899,7 +899,7 @@ wcstring_list_t env_scoped_impl_t::get_names(env_mode_flags_t flags) const { } if (query.universal) { - const wcstring_list_t uni_list = uvars()->get_names(query.exports, query.unexports); + const std::vector uni_list = uvars()->get_names(query.exports, query.unexports); names.insert(uni_list.begin(), uni_list.end()); } @@ -949,7 +949,7 @@ class env_stack_impl_t final : public env_scoped_impl_t { using env_scoped_impl_t::env_scoped_impl_t; /// Set a variable under the name \p key, using the given \p mode, setting its value to \p val. - mod_result_t set(const wcstring &key, env_mode_flags_t mode, wcstring_list_t val); + mod_result_t set(const wcstring &key, env_mode_flags_t mode, std::vector val); /// Remove a variable under the name \p key. mod_result_t remove(const wcstring &key, int var_mode); @@ -1018,13 +1018,13 @@ class env_stack_impl_t final : public env_scoped_impl_t { /// Try setting\p key as an electric or readonly variable. /// \return an error code, or none() if not an electric or readonly variable. /// \p val will not be modified upon a none() return. - maybe_t try_set_electric(const wcstring &key, const query_t &query, wcstring_list_t &val); + maybe_t try_set_electric(const wcstring &key, const query_t &query, std::vector &val); /// Set a universal value. - void set_universal(const wcstring &key, wcstring_list_t val, const query_t &query); + void set_universal(const wcstring &key, std::vector val, const query_t &query); /// Set a variable in a given node \p node. - void set_in_node(const env_node_ref_t &node, const wcstring &key, wcstring_list_t &&val, + void set_in_node(const env_node_ref_t &node, const wcstring &key, std::vector &&val, const var_flags_t &flags); // Implement the default behavior of 'set' by finding the node for an unspecified scope. @@ -1084,8 +1084,8 @@ env_node_ref_t env_stack_impl_t::pop() { } /// Apply the pathvar behavior, splitting about colons. -static wcstring_list_t colon_split(const wcstring_list_t &val) { - wcstring_list_t split_val; +static std::vector colon_split(const std::vector &val) { + std::vector split_val; split_val.reserve(val.size()); for (const wcstring &str : val) { vec_append(split_val, split_string(str, PATH_ARRAY_SEP)); @@ -1094,7 +1094,7 @@ static wcstring_list_t colon_split(const wcstring_list_t &val) { } void env_stack_impl_t::set_in_node(const env_node_ref_t &node, const wcstring &key, - wcstring_list_t &&val, const var_flags_t &flags) { + std::vector &&val, const var_flags_t &flags) { env_var_t &var = node->env[key]; // Use an explicit exports, or inherit from the existing variable. @@ -1118,7 +1118,7 @@ void env_stack_impl_t::set_in_node(const env_node_ref_t &node, const wcstring &k } maybe_t env_stack_impl_t::try_set_electric(const wcstring &key, const query_t &query, - wcstring_list_t &val) { + std::vector &val) { const electric_var_t *ev = electric_var_t::for_name(key); if (!ev) { return none(); @@ -1164,7 +1164,7 @@ maybe_t env_stack_impl_t::try_set_electric(const wcstring &key, const query } /// Set a universal variable, inheriting as applicable from the given old variable. -void env_stack_impl_t::set_universal(const wcstring &key, wcstring_list_t val, +void env_stack_impl_t::set_universal(const wcstring &key, std::vector val, const query_t &query) { auto oldvar = uvars()->get(key); // Resolve whether or not to export. @@ -1188,7 +1188,7 @@ void env_stack_impl_t::set_universal(const wcstring &key, wcstring_list_t val, // Split about ':' if it's a path variable. if (pathvar) { - wcstring_list_t split_val; + std::vector split_val; for (const wcstring &str : val) { vec_append(split_val, split_string(str, PATH_ARRAY_SEP)); } @@ -1205,7 +1205,7 @@ void env_stack_impl_t::set_universal(const wcstring &key, wcstring_list_t val, } mod_result_t env_stack_impl_t::set(const wcstring &key, env_mode_flags_t mode, - wcstring_list_t val) { + std::vector val) { const query_t query(mode); // Handle electric and read-only variables. auto ret = try_set_electric(key, query, val); @@ -1381,11 +1381,11 @@ maybe_t env_stack_t::get(const wcstring &key, env_mode_flags_t mode) return acquire_impl()->get(key, mode); } -wcstring_list_t env_stack_t::get_names(env_mode_flags_t flags) const { +std::vector env_stack_t::get_names(env_mode_flags_t flags) const { return acquire_impl()->get_names(flags); } -int env_stack_t::set(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals) { +int env_stack_t::set(const wcstring &key, env_mode_flags_t mode, std::vector vals) { // Historical behavior. if (vals.size() == 1 && (key == L"PWD" || key == L"HOME")) { path_make_canonical(vals.front()); @@ -1418,11 +1418,11 @@ int env_stack_t::set(const wcstring &key, env_mode_flags_t mode, wcstring_list_t int env_stack_t::set_ffi(const wcstring &key, env_mode_flags_t mode, const void *vals, size_t count) { const wchar_t *const *ptr = static_cast(vals); - return this->set(key, mode, wcstring_list_t(ptr, ptr + count)); + return this->set(key, mode, std::vector(ptr, ptr + count)); } int env_stack_t::set_one(const wcstring &key, env_mode_flags_t mode, wcstring val) { - wcstring_list_t vals; + std::vector vals; vals.push_back(std::move(val)); return set(key, mode, std::move(vals)); } @@ -1451,7 +1451,7 @@ std::shared_ptr env_stack_t::export_arr() { std::shared_ptr env_stack_t::snapshot() const { return acquire_impl()->snapshot(); } -void env_stack_t::set_argv(wcstring_list_t argv) { set(L"argv", ENV_LOCAL, std::move(argv)); } +void env_stack_t::set_argv(std::vector argv) { set(L"argv", ENV_LOCAL, std::move(argv)); } wcstring env_stack_t::get_pwd_slash() const { wcstring pwd = acquire_impl()->perproc_data().pwd; diff --git a/src/env.h b/src/env.h index 9cf6fba69..cdc3e5aca 100644 --- a/src/env.h +++ b/src/env.h @@ -99,12 +99,12 @@ class env_var_t { using env_var_flags_t = uint8_t; private: - env_var_t(std::shared_ptr vals, env_var_flags_t flags) + env_var_t(std::shared_ptr> vals, env_var_flags_t flags) : vals_(std::move(vals)), flags_(flags) {} /// The list of values in this variable. /// shared_ptr allows for cheap copying. - std::shared_ptr vals_{empty_list()}; + std::shared_ptr> vals_{empty_list()}; /// Flag in this variable. env_var_flags_t flags_{}; @@ -121,14 +121,14 @@ class env_var_t { env_var_t(const env_var_t &) = default; env_var_t(env_var_t &&) = default; - env_var_t(wcstring_list_t vals, env_var_flags_t flags) - : env_var_t(std::make_shared(std::move(vals)), flags) {} + env_var_t(std::vector vals, env_var_flags_t flags) + : env_var_t(std::make_shared>(std::move(vals)), flags) {} env_var_t(wcstring val, env_var_flags_t flags) - : env_var_t(wcstring_list_t{std::move(val)}, flags) {} + : env_var_t(std::vector{std::move(val)}, flags) {} // Constructors that infer the flags from a name. - env_var_t(const wchar_t *name, wcstring_list_t vals) + env_var_t(const wchar_t *name, std::vector vals) : env_var_t(std::move(vals), flags_for(name)) {} env_var_t(const wchar_t *name, wcstring val) : env_var_t(std::move(val), flags_for(name)) {} @@ -139,14 +139,14 @@ class env_var_t { env_var_flags_t get_flags() const { return flags_; } wcstring as_string() const; - void to_list(wcstring_list_t &out) const; - const wcstring_list_t &as_list() const; + void to_list(std::vector &out) const; + const std::vector &as_list() const; /// \return the character used when delimiting quoted expansion. wchar_t get_delimiter() const; /// \return a copy of this variable with new values. - env_var_t setting_vals(wcstring_list_t vals) const { + env_var_t setting_vals(std::vector vals) const { return env_var_t{std::move(vals), flags_}; } @@ -171,7 +171,7 @@ class env_var_t { } static env_var_flags_t flags_for(const wchar_t *name); - static std::shared_ptr empty_list(); + static std::shared_ptr> empty_list(); env_var_t &operator=(const env_var_t &) = default; env_var_t &operator=(env_var_t &&) = default; @@ -191,7 +191,7 @@ class environment_t { public: virtual maybe_t get(const wcstring &key, env_mode_flags_t mode = ENV_DEFAULT) const = 0; - virtual wcstring_list_t get_names(env_mode_flags_t flags) const = 0; + virtual std::vector get_names(env_mode_flags_t flags) const = 0; virtual ~environment_t(); /// \return a environment variable as a unique pointer, or nullptr if none. @@ -209,7 +209,7 @@ class null_environment_t : public environment_t { ~null_environment_t() override; maybe_t get(const wcstring &key, env_mode_flags_t mode = ENV_DEFAULT) const override; - wcstring_list_t get_names(env_mode_flags_t flags) const override; + std::vector get_names(env_mode_flags_t flags) const override; }; /// A mutable environment which allows scopes to be pushed and popped. @@ -237,10 +237,10 @@ class env_stack_t final : public environment_t { maybe_t get(const wcstring &key, env_mode_flags_t mode = ENV_DEFAULT) const override; /// Implementation of environment_t. - wcstring_list_t get_names(env_mode_flags_t flags) const override; + std::vector get_names(env_mode_flags_t flags) const override; /// Sets the variable with the specified name to the given values. - int set(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals); + int set(const wcstring &key, env_mode_flags_t mode, std::vector vals); /// Sets the variable with the specified name to the given values. /// The values should have type const wchar_t *const * (but autocxx doesn't support that). @@ -287,7 +287,7 @@ class env_stack_t final : public environment_t { void set_last_statuses(statuses_t s); /// Sets up argv as the given list of strings. - void set_argv(wcstring_list_t argv); + void set_argv(std::vector argv); /// Slightly optimized implementation. wcstring get_pwd_slash() const override; diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index fc5cd1e0d..7de061951 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -219,13 +219,13 @@ static const wchar_t *const ENV_NULL = L"\x1d"; static const wchar_t UVAR_ARRAY_SEP = 0x1e; /// Decode a serialized universal variable value into a list. -static wcstring_list_t decode_serialized(const wcstring &val) { +static std::vector decode_serialized(const wcstring &val) { if (val == ENV_NULL) return {}; return split_string(val, UVAR_ARRAY_SEP); } /// Decode a a list into a serialized universal variable value. -static wcstring encode_serialized(const wcstring_list_t &vals) { +static wcstring encode_serialized(const std::vector &vals) { if (vals.empty()) return ENV_NULL; return join_strings(vals, UVAR_ARRAY_SEP); } @@ -265,8 +265,8 @@ bool env_universal_t::remove(const wcstring &key) { return false; } -wcstring_list_t env_universal_t::get_names(bool show_exported, bool show_unexported) const { - wcstring_list_t result; +std::vector env_universal_t::get_names(bool show_exported, bool show_unexported) const { + std::vector result; for (const auto &kv : vars) { const wcstring &key = kv.first; const env_var_t &var = kv.second; diff --git a/src/env_universal_common.h b/src/env_universal_common.h index 7ff74998f..158ebf301 100644 --- a/src/env_universal_common.h +++ b/src/env_universal_common.h @@ -57,7 +57,7 @@ class env_universal_t { bool remove(const wcstring &key); // Gets variable names. - wcstring_list_t get_names(bool show_exported, bool show_unexported) const; + std::vector get_names(bool show_exported, bool show_unexported) const; /// Get a view on the universal variable table. const var_table_t &get_table() const { return vars; } diff --git a/src/event.cpp b/src/event.cpp index 61ee29bd3..28d0b2005 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -33,7 +33,7 @@ const wchar_t *const event_filter_names[] = {L"signal", L"variable", L"exi L"process-exit", L"job-exit", L"caller-exit", L"generic", nullptr}; -void event_fire_generic(parser_t &parser, const wcstring &name, const wcstring_list_t &args) { +void event_fire_generic(parser_t &parser, const wcstring &name, const std::vector &args) { std::vector ffi_args; for (const auto &arg : args) ffi_args.push_back(arg.c_str()); event_fire_generic_ffi(parser, name, ffi_args); diff --git a/src/event.h b/src/event.h index 74a3da743..7602d51c4 100644 --- a/src/event.h +++ b/src/event.h @@ -31,7 +31,7 @@ extern const wchar_t *const event_filter_names[]; class parser_t; void event_fire_generic(parser_t &parser, const wcstring &name, - const wcstring_list_t &args = g_empty_string_list); + const std::vector &args = g_empty_string_list); #endif #endif diff --git a/src/exec.cpp b/src/exec.cpp index afd670381..b7e934069 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -573,7 +573,7 @@ static launch_result_t exec_external_command(parser_t &parser, const std::shared // Given that we are about to execute a function, push a function block and set up the // variable environment. -static block_t *function_prepare_environment(parser_t &parser, wcstring_list_t argv, +static block_t *function_prepare_environment(parser_t &parser, std::vector argv, const function_properties_t &props) { // Extract the function name and remaining arguments. wcstring func_name; @@ -650,7 +650,7 @@ static proc_performer_t get_performer_for_process(process_t *p, job_t *job, FLOGF(error, _(L"Unknown function '%ls'"), p->argv0()); return proc_performer_t{}; } - const wcstring_list_t &argv = p->argv(); + const std::vector &argv = p->argv(); return [=](parser_t &parser) { // Pull out the job list from the function. const ast::job_list_t &body = props->func_node->jobs(); @@ -734,7 +734,7 @@ static proc_performer_t get_performer_for_builtin( // Pull out some fields which we want to copy. We don't want to store the process or job in the // returned closure. job_group_ref_t job_group = job->group; - const wcstring_list_t &argv = p->argv(); + const std::vector &argv = p->argv(); // Be careful to not capture p or j by value, as the intent is that this may be run on another // thread. @@ -1140,7 +1140,7 @@ bool exec_job(parser_t &parser, const shared_ptr &j, const io_chain_t &bl } /// Populate \p lst with the output of \p buffer, perhaps splitting lines according to \p split. -static void populate_subshell_output(wcstring_list_t *lst, const separated_buffer_t &buffer, +static void populate_subshell_output(std::vector *lst, const separated_buffer_t &buffer, bool split) { // Walk over all the elements. for (const auto &elem : buffer.elements()) { @@ -1189,7 +1189,7 @@ static void populate_subshell_output(wcstring_list_t *lst, const separated_buffe /// sense that subshells used during string expansion should halt that expansion. \return the value /// of $status. static int exec_subshell_internal(const wcstring &cmd, parser_t &parser, - const job_group_ref_t &job_group, wcstring_list_t *lst, + const job_group_ref_t &job_group, std::vector *lst, bool *break_expand, bool apply_exit_status, bool is_subcmd) { parser.assert_can_execute(); auto &ld = parser.libdata(); @@ -1233,7 +1233,7 @@ static int exec_subshell_internal(const wcstring &cmd, parser_t &parser, } int exec_subshell_for_expand(const wcstring &cmd, parser_t &parser, - const job_group_ref_t &job_group, wcstring_list_t &outputs) { + const job_group_ref_t &job_group, std::vector &outputs) { parser.assert_can_execute(); bool break_expand = false; int ret = exec_subshell_internal(cmd, parser, job_group, &outputs, &break_expand, true, true); @@ -1247,7 +1247,7 @@ int exec_subshell(const wcstring &cmd, parser_t &parser, bool apply_exit_status) false); } -int exec_subshell(const wcstring &cmd, parser_t &parser, wcstring_list_t &outputs, +int exec_subshell(const wcstring &cmd, parser_t &parser, std::vector &outputs, bool apply_exit_status) { bool break_expand = false; return exec_subshell_internal(cmd, parser, nullptr, &outputs, &break_expand, apply_exit_status, diff --git a/src/exec.h b/src/exec.h index 45d5c88ee..6aa648d55 100644 --- a/src/exec.h +++ b/src/exec.h @@ -29,7 +29,7 @@ __warn_unused bool exec_job(parser_t &parser, const std::shared_ptr &j, /// /// \return a value appropriate for populating $status. int exec_subshell(const wcstring &cmd, parser_t &parser, bool apply_exit_status); -int exec_subshell(const wcstring &cmd, parser_t &parser, wcstring_list_t &outputs, +int exec_subshell(const wcstring &cmd, parser_t &parser, std::vector &outputs, bool apply_exit_status); /// Like exec_subshell, but only returns expansion-breaking errors. That is, a zero return means @@ -37,7 +37,7 @@ int exec_subshell(const wcstring &cmd, parser_t &parser, wcstring_list_t &output /// halt expansion. If the \p pgid is supplied, then any spawned external commands should join that /// pgroup. int exec_subshell_for_expand(const wcstring &cmd, parser_t &parser, - const job_group_ref_t &job_group, wcstring_list_t &outputs); + const job_group_ref_t &job_group, std::vector &outputs); /// Add signals that should be masked for external processes in this job. bool blocked_signals_for_job(const job_t &job, sigset_t *sigmask); diff --git a/src/expand.cpp b/src/expand.cpp index 74e0bb650..cdeab497e 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -127,7 +127,7 @@ static bool is_quotable(const wcstring &str) { wcstring expand_escape_variable(const env_var_t &var) { wcstring buff; - const wcstring_list_t &lst = var.as_list(); + const std::vector &lst = var.as_list(); for (size_t j = 0; j < lst.size(); j++) { const wcstring &el = lst.at(j); @@ -410,7 +410,7 @@ static expand_result_t expand_variables(wcstring instr, completion_receiver_t *o // Ok, we have a variable or a history. Let's expand it. // Start by respecting the sliced elements. assert((var || history) && "Should have variable or history here"); - wcstring_list_t var_item_list; + std::vector var_item_list; if (all_values) { if (history) { history->get_history(var_item_list); @@ -430,7 +430,7 @@ static expand_result_t expand_variables(wcstring instr, completion_receiver_t *o } } } else { - const wcstring_list_t &all_var_items = var->as_list(); + const std::vector &all_var_items = var->as_list(); for (long item_index : var_idx_list) { // Check that we are within array bounds. If not, skip the element. Note: // Negative indices (`echo $foo[-1]`) are already converted to positive ones @@ -639,7 +639,7 @@ static expand_result_t expand_cmdsubst(wcstring input, const operation_context_t } } - wcstring_list_t sub_res; + std::vector sub_res; int subshell_status = exec_subshell_for_expand(subcmd, *ctx.parser, ctx.job_group, sub_res); if (subshell_status != 0) { // TODO: Ad-hoc switch, how can we enumerate the possible errors more safely? @@ -699,7 +699,7 @@ static expand_result_t expand_cmdsubst(wcstring input, const operation_context_t return expand_result_t::make_error(STATUS_EXPAND_ERROR); } - wcstring_list_t sub_res2; + std::vector sub_res2; tail_begin = slice_end - in; for (long idx : slice_idx) { if (static_cast(idx) > sub_res.size() || idx < 1) { @@ -1022,7 +1022,7 @@ expand_result_t expander_t::stage_wildcards(wcstring path_to_expand, completion_ // So we're going to treat this input as a file path. Compute the "working directories", // which may be CDPATH if the special flag is set. const wcstring working_dir = ctx.vars.get_pwd_slash(); - wcstring_list_t effective_working_dirs; + std::vector effective_working_dirs; bool for_cd = flags & expand_flag::special_for_cd; bool for_command = flags & expand_flag::special_for_command; if (!for_cd && !for_command) { @@ -1052,7 +1052,7 @@ expand_result_t expander_t::stage_wildcards(wcstring path_to_expand, completion_ } else { // Get the PATH/CDPATH and CWD. Perhaps these should be passed in. An empty CDPATH // implies just the current directory, while an empty PATH is left empty. - wcstring_list_t paths; + std::vector paths; if (auto paths_var = ctx.vars.get(for_cd ? L"CDPATH" : L"PATH")) { paths = paths_var->as_list(); } @@ -1252,7 +1252,7 @@ bool expand_one(wcstring &string, expand_flags_t flags, const operation_context_ } expand_result_t expand_to_command_and_args(const wcstring &instr, const operation_context_t &ctx, - wcstring *out_cmd, wcstring_list_t *out_args, + wcstring *out_cmd, std::vector *out_args, parse_error_list_t *errors, bool skip_wildcards) { // Fast path. if (expand_is_clean(instr)) { diff --git a/src/expand.h b/src/expand.h index e35693f2a..c7313415c 100644 --- a/src/expand.h +++ b/src/expand.h @@ -187,7 +187,7 @@ bool expand_one(wcstring &string, expand_flags_t flags, const operation_context_ /// If \p skip_wildcards is true, then do not do wildcard expansion /// \return an expand error. expand_result_t expand_to_command_and_args(const wcstring &instr, const operation_context_t &ctx, - wcstring *out_cmd, wcstring_list_t *out_args, + wcstring *out_cmd, std::vector *out_args, parse_error_list_t *errors = nullptr, bool skip_wildcards = false); diff --git a/src/ffi.h b/src/ffi.h index a7c3bdc89..7dbb8c7e5 100644 --- a/src/ffi.h +++ b/src/ffi.h @@ -16,7 +16,7 @@ inline std::shared_ptr box_to_shared_ptr(rust::Box &&value) { } inline static void trace_if_enabled(const parser_t &parser, wcharz_t command, - const wcstring_list_t &args = {}) { + const std::vector &args = {}) { if (trace_enabled(parser)) { trace_argv(parser, command, args); } diff --git a/src/fish.cpp b/src/fish.cpp index b53583213..b212b698e 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -559,7 +559,7 @@ int main(int argc, char **argv) { // Pass additional args as $argv. // Note that we *don't* support setting argv[0]/$0, unlike e.g. bash. - wcstring_list_t list; + std::vector list; for (char **ptr = argv + my_optind; *ptr; ptr++) { list.push_back(str2wcstring(*ptr)); } @@ -580,7 +580,7 @@ int main(int argc, char **argv) { FLOGF(error, _(L"Error reading script file '%s':"), file); perror("error"); } else { - wcstring_list_t list; + std::vector list; for (char **ptr = argv + my_optind; *ptr; ptr++) { list.push_back(str2wcstring(*ptr)); } diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 64b50d670..27713869d 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -169,8 +169,8 @@ static void err(const wchar_t *blah, ...) { std::fwprintf(stdout, L"\n"); } -/// Joins a wcstring_list_t via commas. -static wcstring comma_join(const wcstring_list_t &lst) { +/// Joins a std::vector via commas. +static wcstring comma_join(const std::vector &lst) { wcstring result; for (size_t i = 0; i < lst.size(); i++) { if (i > 0) { @@ -1528,7 +1528,7 @@ void test_dir_iter() { const wcstring badlinkname = L"badlink"; // link to nowhere const wcstring selflinkname = L"selflink"; // link to self const wcstring fifoname = L"fifo"; - const wcstring_list_t names = {dirname, regname, reglinkname, dirlinkname, + const std::vector names = {dirname, regname, reglinkname, dirlinkname, badlinkname, selflinkname, fifoname}; const auto is_link_name = [&](const wcstring &name) -> bool { @@ -1929,9 +1929,9 @@ struct test_environment_t : public environment_t { return none(); } - wcstring_list_t get_names(env_mode_flags_t flags) const override { + std::vector get_names(env_mode_flags_t flags) const override { UNUSED(flags); - wcstring_list_t result; + std::vector result; for (const auto &kv : vars) { result.push_back(kv.first); } @@ -1949,7 +1949,7 @@ struct pwd_environment_t : public test_environment_t { return test_environment_t::get(key, mode); } - wcstring_list_t get_names(env_mode_flags_t flags) const override { + std::vector get_names(env_mode_flags_t flags) const override { auto res = test_environment_t::get_names(flags); res.clear(); if (std::count(res.begin(), res.end(), L"PWD") == 0) { @@ -1985,7 +1985,7 @@ static bool expand_test(const wchar_t *in, expand_flags_t flags, ...) { return false; } - wcstring_list_t expected; + std::vector expected; va_start(va, flags); while ((arg = va_arg(va, wchar_t *)) != nullptr) { @@ -2179,7 +2179,7 @@ static void test_expand_overflow() { // Make a list of 64 elements, then expand it cartesian-style 64 times. // This is far too large to expand. - wcstring_list_t vals; + std::vector vals; wcstring expansion; for (int i = 1; i <= 64; i++) { vals.push_back(to_string(i)); @@ -2638,7 +2638,7 @@ static void test_is_potential_path() { if (system("touch test/is_potential_path_test/gamma")) err(L"touch failed"); const wcstring wd = L"test/is_potential_path_test/"; - const wcstring_list_t wds({L".", wd}); + const std::vector wds({L".", wd}); operation_context_t ctx{env_stack_t::principal()}; do_test(is_potential_path(L"al", true, wds, ctx, PATH_REQUIRE_DIR)); @@ -2666,9 +2666,9 @@ static void test_is_potential_path() { /// Test the 'test' builtin. maybe_t builtin_test(parser_t &parser, io_streams_t &streams, const wchar_t **argv); -static bool run_one_test_test(int expected, const wcstring_list_t &lst, bool bracket) { +static bool run_one_test_test(int expected, const std::vector &lst, bool bracket) { parser_t &parser = parser_t::principal_parser(); - wcstring_list_t argv; + std::vector argv; argv.push_back(bracket ? L"[" : L"test"); argv.insert(argv.end(), lst.begin(), lst.end()); if (bracket) argv.push_back(L"]"); @@ -2694,7 +2694,7 @@ static bool run_test_test(int expected, const wcstring &str) { operation_context_t ctx{parser, nullenv, no_cancel}; completion_list_t comps = parser_t::expand_argument_list(str, expand_flags_t{}, ctx); - wcstring_list_t argv; + std::vector argv; for (const auto &c : comps) { argv.push_back(c.completion); } @@ -2916,7 +2916,7 @@ struct autoload_tester_t { char t2[] = "/tmp/fish_test_autoload.XXXXXX"; wcstring p2 = str2wcstring(mkdtemp(t2)); - const wcstring_list_t paths = {p1, p2}; + const std::vector paths = {p1, p2}; autoload_t autoload(L"test_var"); do_test(!autoload.resolve_command(L"file1", paths)); @@ -2931,10 +2931,10 @@ struct autoload_tester_t { do_test(autoload.resolve_command(L"file1", paths)); do_test(!autoload.resolve_command(L"file1", paths)); do_test(autoload.autoload_in_progress(L"file1")); - do_test(autoload.get_autoloaded_commands() == wcstring_list_t{L"file1"}); + do_test(autoload.get_autoloaded_commands() == std::vector{L"file1"}); autoload.mark_autoload_finished(L"file1"); do_test(!autoload.autoload_in_progress(L"file1")); - do_test(autoload.get_autoloaded_commands() == wcstring_list_t{L"file1"}); + do_test(autoload.get_autoloaded_commands() == std::vector{L"file1"}); do_test(!autoload.resolve_command(L"file1", paths)); do_test(!autoload.resolve_command(L"nothing", paths)); @@ -2942,7 +2942,7 @@ struct autoload_tester_t { do_test(!autoload.resolve_command(L"file2", paths)); autoload.mark_autoload_finished(L"file2"); do_test(!autoload.resolve_command(L"file2", paths)); - do_test((autoload.get_autoloaded_commands() == wcstring_list_t{L"file1", L"file2"})); + do_test((autoload.get_autoloaded_commands() == std::vector{L"file1", L"file2"})); autoload.clear(); do_test(autoload.resolve_command(L"file1", paths)); @@ -3014,7 +3014,7 @@ static void test_complete() { auto func_props = make_test_func_props(); struct test_complete_vars_t : environment_t { - wcstring_list_t get_names(env_mode_flags_t flags) const override { + std::vector get_names(env_mode_flags_t flags) const override { UNUSED(flags); return {L"Foo1", L"Foo2", L"Foo3", L"Bar1", L"Bar2", L"Bar3", L"alpha", L"ALPHA!", L"gamma1", L"GAMMA2"}; @@ -3587,9 +3587,9 @@ static void test_autosuggestion_combining() { do_test(combine_command_and_autosuggestion(L"alpha", L"ALPHA") == L"alpha"); } -static void test_history_matches(history_search_t &search, const wcstring_list_t &expected, +static void test_history_matches(history_search_t &search, const std::vector &expected, unsigned from_line) { - wcstring_list_t found; + std::vector found; while (search.go_to_next_match(history_search_direction_t::backward)) { found.push_back(search.current_string()); } @@ -3770,11 +3770,11 @@ static void test_universal_output() { const env_var_t::env_var_flags_t flag_pathvar = env_var_t::flag_pathvar; var_table_t vars; - vars[L"varA"] = env_var_t(wcstring_list_t{L"ValA1", L"ValA2"}, 0); - vars[L"varB"] = env_var_t(wcstring_list_t{L"ValB1"}, flag_export); - vars[L"varC"] = env_var_t(wcstring_list_t{L"ValC1"}, 0); - vars[L"varD"] = env_var_t(wcstring_list_t{L"ValD1"}, flag_export | flag_pathvar); - vars[L"varE"] = env_var_t(wcstring_list_t{L"ValE1", L"ValE2"}, flag_pathvar); + vars[L"varA"] = env_var_t(std::vector{L"ValA1", L"ValA2"}, 0); + vars[L"varB"] = env_var_t(std::vector{L"ValB1"}, flag_export); + vars[L"varC"] = env_var_t(std::vector{L"ValC1"}, 0); + vars[L"varD"] = env_var_t(std::vector{L"ValD1"}, flag_export | flag_pathvar); + vars[L"varE"] = env_var_t(std::vector{L"ValE1", L"ValE2"}, flag_pathvar); std::string text = env_universal_t::serialize_with_vars(vars); const char *expected = @@ -3803,11 +3803,11 @@ static void test_universal_parsing() { const env_var_t::env_var_flags_t flag_pathvar = env_var_t::flag_pathvar; var_table_t vars; - vars[L"varA"] = env_var_t(wcstring_list_t{L"ValA1", L"ValA2"}, 0); - vars[L"varB"] = env_var_t(wcstring_list_t{L"ValB1"}, flag_export); - vars[L"varC"] = env_var_t(wcstring_list_t{L"ValC1"}, 0); - vars[L"varD"] = env_var_t(wcstring_list_t{L"ValD1"}, flag_export | flag_pathvar); - vars[L"varE"] = env_var_t(wcstring_list_t{L"ValE1", L"ValE2"}, flag_pathvar); + vars[L"varA"] = env_var_t(std::vector{L"ValA1", L"ValA2"}, 0); + vars[L"varB"] = env_var_t(std::vector{L"ValB1"}, flag_export); + vars[L"varC"] = env_var_t(std::vector{L"ValC1"}, 0); + vars[L"varD"] = env_var_t(std::vector{L"ValD1"}, flag_export | flag_pathvar); + vars[L"varE"] = env_var_t(std::vector{L"ValE1", L"ValE2"}, flag_pathvar); var_table_t parsed_vars; env_universal_t::populate_variables(input, &parsed_vars); @@ -3822,8 +3822,8 @@ static void test_universal_parsing_legacy() { "SET_EXPORT varB:ValB1\n"; var_table_t vars; - vars[L"varA"] = env_var_t(wcstring_list_t{L"ValA1", L"ValA2"}, 0); - vars[L"varB"] = env_var_t(wcstring_list_t{L"ValB1"}, env_var_t::flag_export); + vars[L"varA"] = env_var_t(std::vector{L"ValA1", L"ValA2"}, 0); + vars[L"varB"] = env_var_t(std::vector{L"ValB1"}, env_var_t::flag_export); var_table_t parsed_vars; env_universal_t::populate_variables(input, &parsed_vars); @@ -4052,7 +4052,7 @@ void history_tests_t::test_history() { history_search_t searcher; say(L"Testing history"); - const wcstring_list_t items = {L"Gamma", L"beta", L"BetA", L"Beta", L"alpha", + const std::vector items = {L"Gamma", L"beta", L"BetA", L"Beta", L"alpha", L"AlphA", L"Alpha", L"alph", L"ALPH", L"ZZZ"}; const history_search_flags_t nocase = history_search_ignore_case; @@ -4064,7 +4064,7 @@ void history_tests_t::test_history() { } // Helper to set expected items to those matching a predicate, in reverse order. - wcstring_list_t expected; + std::vector expected; auto set_expected = [&](const std::function &filt) { expected.clear(); for (const auto &s : items) { @@ -4171,8 +4171,8 @@ static void time_barrier() { } while (time(nullptr) == start); } -static wcstring_list_t generate_history_lines(size_t item_count, size_t idx) { - wcstring_list_t result; +static std::vector generate_history_lines(size_t item_count, size_t idx) { + std::vector result; result.reserve(item_count); for (unsigned long i = 0; i < item_count; i++) { result.push_back(format_string(L"%ld %lu", (unsigned long)idx, (unsigned long)i)); @@ -4183,7 +4183,7 @@ static wcstring_list_t generate_history_lines(size_t item_count, size_t idx) { void history_tests_t::test_history_races_pound_on_history(size_t item_count, size_t idx) { // Called in child thread to modify history. history_t hist(L"race_test"); - const wcstring_list_t hist_lines = generate_history_lines(item_count, idx); + const std::vector hist_lines = generate_history_lines(item_count, idx); for (const wcstring &line : hist_lines) { hist.add(line); hist.save(); @@ -4229,7 +4229,7 @@ void history_tests_t::test_history_races() { } // Compute the expected lines. - std::array expected_lines; + std::array, RACE_COUNT> expected_lines; for (size_t i = 0; i < RACE_COUNT; i++) { expected_lines[i] = generate_history_lines(ITEM_COUNT, i); } @@ -4249,7 +4249,7 @@ void history_tests_t::test_history_races() { if (item.empty()) break; bool found = false; - for (wcstring_list_t &list : expected_lines) { + for (std::vector &list : expected_lines) { auto iter = std::find(list.begin(), list.end(), item.contents); if (iter != list.end()) { found = true; @@ -4267,7 +4267,7 @@ void history_tests_t::test_history_races() { } if (!found) { err(L"Line '%ls' found in history, but not found in some array", item.str().c_str()); - for (wcstring_list_t &list : expected_lines) { + for (std::vector &list : expected_lines) { if (!list.empty()) { fprintf(stderr, "\tRemaining: %ls\n", list.back().c_str()); } @@ -4282,7 +4282,7 @@ void history_tests_t::test_history_races() { } // See if anything is left in the arrays - for (const wcstring_list_t &list : expected_lines) { + for (const std::vector &list : expected_lines) { for (const wcstring &str : list) { err(L"Line '%ls' still left in the array", str.c_str()); } @@ -4345,10 +4345,10 @@ void history_tests_t::test_history_merge() { } // Everyone should also have items in the same order (#2312) - wcstring_list_t hist_vals1; + std::vector hist_vals1; hists[0]->get_history(hist_vals1); for (const auto &hist : hists) { - wcstring_list_t hist_vals2; + std::vector hist_vals2; hist->get_history(hist_vals2); do_test(hist_vals1 == hist_vals2); } @@ -4432,7 +4432,7 @@ void history_tests_t::test_history_path_detection() { } // Expected sets of paths. - wcstring_list_t expected[hist_size] = { + std::vector expected[hist_size] = { {}, // cmd0 {filename}, // cmd1 {tmpdir + L"/" + filename}, // cmd2 @@ -4937,8 +4937,8 @@ static void test_new_parser_errors() { // Given a format string, returns a list of non-empty strings separated by format specifiers. The // format specifiers themselves are omitted. -static wcstring_list_t separate_by_format_specifiers(const wchar_t *format) { - wcstring_list_t result; +static std::vector separate_by_format_specifiers(const wchar_t *format) { + std::vector result; const wchar_t *cursor = format; const wchar_t *end = format + std::wcslen(format); while (cursor < end) { @@ -4989,7 +4989,7 @@ static wcstring_list_t separate_by_format_specifiers(const wchar_t *format) { // that each of the remaining chunks is found (in order) in the string. static bool string_matches_format(const wcstring &string, const wchar_t *format) { bool result = true; - wcstring_list_t components = separate_by_format_specifiers(format); + std::vector components = separate_by_format_specifiers(format); size_t idx = 0; for (const auto &component : components) { size_t where = string.find(component, idx); @@ -5529,7 +5529,7 @@ maybe_t builtin_string(parser_t &parser, io_streams_t &streams, const wchar static void run_one_string_test(const wchar_t *const *argv_raw, int expected_rc, const wchar_t *expected_out) { // Copy to a null terminated array, as builtin_string may wish to rearrange our pointers. - wcstring_list_t argv_list(argv_raw, argv_raw + null_terminated_array_length(argv_raw)); + std::vector argv_list(argv_raw, argv_raw + null_terminated_array_length(argv_raw)); null_terminated_array_t argv(argv_list); parser_t &parser = parser_t::principal_parser(); @@ -5944,9 +5944,9 @@ static void test_env_vars() { // TODO: Add tests for the locale and ncurses vars. env_var_t v1 = {L"abc", env_var_t::flag_export}; - env_var_t v2 = {wcstring_list_t{L"abc"}, env_var_t::flag_export}; - env_var_t v3 = {wcstring_list_t{L"abc"}, 0}; - env_var_t v4 = {wcstring_list_t{L"abc", L"def"}, env_var_t::flag_export}; + env_var_t v2 = {std::vector{L"abc"}, env_var_t::flag_export}; + env_var_t v3 = {std::vector{L"abc"}, 0}; + env_var_t v4 = {std::vector{L"abc", L"def"}, env_var_t::flag_export}; do_test(v1 == v2 && !(v1 != v2)); do_test(v1 != v3 && !(v1 == v3)); do_test(v1 != v4 && !(v1 == v4)); @@ -6416,20 +6416,20 @@ static void test_killring() { kill_add(L"b"); kill_add(L"c"); - do_test((kill_entries() == wcstring_list_t{L"c", L"b", L"a"})); + do_test((kill_entries() == std::vector{L"c", L"b", L"a"})); do_test(kill_yank_rotate() == L"b"); - do_test((kill_entries() == wcstring_list_t{L"b", L"a", L"c"})); + do_test((kill_entries() == std::vector{L"b", L"a", L"c"})); do_test(kill_yank_rotate() == L"a"); - do_test((kill_entries() == wcstring_list_t{L"a", L"c", L"b"})); + do_test((kill_entries() == std::vector{L"a", L"c", L"b"})); kill_add(L"d"); - do_test((kill_entries() == wcstring_list_t{L"d", L"a", L"c", L"b"})); + do_test((kill_entries() == std::vector{L"d", L"a", L"c", L"b"})); do_test(kill_yank_rotate() == L"a"); - do_test((kill_entries() == wcstring_list_t{L"a", L"c", L"b", L"d"})); + do_test((kill_entries() == std::vector{L"a", L"c", L"b", L"d"})); } namespace { @@ -6464,8 +6464,8 @@ static void test_re_basic() { auto re = regex_t::try_compile(L"(.)\\1"); do_test(re.has_value()); auto md = re->prepare(); - wcstring_list_t matches; - wcstring_list_t captures; + std::vector matches; + std::vector captures; while (auto r = re->match(md, subject)) { matches.push_back(substr_from_range(r)); captures.push_back(substr_from_range(re->group(md, 1))); @@ -6602,7 +6602,7 @@ void test_wgetopt() { wgetopter_t w; int opt; int a_count = 0; - wcstring_list_t arguments; + std::vector arguments; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'a': { diff --git a/src/flog.h b/src/flog.h index 085be6d78..594a8279f 100644 --- a/src/flog.h +++ b/src/flog.h @@ -16,7 +16,6 @@ #include "global_safety.h" using wcstring = std::wstring; -using wcstring_list_t = std::vector; namespace flog_details { diff --git a/src/function.cpp b/src/function.cpp index 5f83a922b..f240b3aa3 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -114,7 +114,7 @@ static void autoload_names(std::unordered_set &names, bool get_hidden) const auto path_var = vars.get(L"fish_function_path"); if (path_var.missing_or_empty()) return; - const wcstring_list_t &path_list = path_var->as_list(); + const std::vector &path_list = path_var->as_list(); for (i = 0; i < path_list.size(); i++) { const wcstring &ndir_str = path_list.at(i); @@ -276,7 +276,7 @@ bool function_copy(const wcstring &name, const wcstring &new_name, parser_t &par return true; } -wcstring_list_t function_get_names(bool get_hidden) { +std::vector function_get_names(bool get_hidden) { std::unordered_set names; auto funcset = function_set.acquire(); autoload_names(names, get_hidden); @@ -289,7 +289,7 @@ wcstring_list_t function_get_names(bool get_hidden) { } names.insert(name); } - return wcstring_list_t(names.begin(), names.end()); + return std::vector(names.begin(), names.end()); } void function_invalidate_path() { @@ -297,7 +297,7 @@ void function_invalidate_path() { // Note we don't want to risk removal during iteration; we expect this to be called // infrequently. auto funcset = function_set.acquire(); - wcstring_list_t autoloadees; + std::vector autoloadees; for (const auto &kv : funcset->funcs) { if (kv.second->is_autoload) { autoloadees.push_back(kv.first); @@ -391,7 +391,7 @@ wcstring function_properties_t::annotated_definition(const wcstring &name) const } } - const wcstring_list_t &named = this->named_arguments; + const std::vector &named = this->named_arguments; if (!named.empty()) { append_format(out, L" --argument"); for (const auto &name : named) { diff --git a/src/function.h b/src/function.h index 5d65838ce..b21958597 100644 --- a/src/function.h +++ b/src/function.h @@ -29,14 +29,14 @@ struct function_properties_t { const ast::block_statement_t *func_node; /// List of all named arguments for this function. - wcstring_list_t named_arguments; + std::vector named_arguments; /// Description of the function. wcstring description; /// Mapping of all variables that were inherited from the function definition scope to their /// values. - std::map inherit_vars; + std::map> inherit_vars; /// Set to true if invoking this function shadows the variables of the underlying function. bool shadow_scope{true}; @@ -110,7 +110,7 @@ bool function_exists_no_autoload(const wcstring &cmd); /// Returns all function names. /// /// \param get_hidden whether to include hidden functions, i.e. ones starting with an underscore. -wcstring_list_t function_get_names(bool get_hidden); +std::vector function_get_names(bool get_hidden); /// Creates a new function using the same definition as the specified function. Returns true if copy /// is successful. diff --git a/src/highlight.cpp b/src/highlight.cpp index c43316eed..743b9f9c7 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -188,7 +188,7 @@ static bool fs_is_case_insensitive(const wcstring &path, int fd, /// /// We expect the path to already be unescaped. bool is_potential_path(const wcstring &potential_path_fragment, bool at_cursor, - const wcstring_list_t &directories, const operation_context_t &ctx, + const std::vector &directories, const operation_context_t &ctx, path_flags_t flags) { ASSERT_IS_BACKGROUND_THREAD(); @@ -301,7 +301,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, bool at_cursor, static bool is_potential_cd_path(const wcstring &path, bool at_cursor, const wcstring &working_directory, const operation_context_t &ctx, path_flags_t flags) { - wcstring_list_t directories; + std::vector directories; if (string_prefixes_string(L"./", path)) { // Ignore the CDPATH in this case; just use the working directory. @@ -309,8 +309,8 @@ static bool is_potential_cd_path(const wcstring &path, bool at_cursor, } else { // Get the CDPATH. auto cdpath = ctx.vars.get(L"CDPATH"); - wcstring_list_t pathsv = - cdpath.missing_or_empty() ? wcstring_list_t{L"."} : cdpath->as_list(); + std::vector pathsv = + cdpath.missing_or_empty() ? std::vector{L"."} : cdpath->as_list(); // The current $PWD is always valid. pathsv.push_back(L"."); @@ -889,7 +889,7 @@ static bool range_is_potential_path(const wcstring &src, const source_range_t &r // Put it back. if (!token.empty() && token.at(0) == HOME_DIRECTORY) token.at(0) = L'~'; - const wcstring_list_t working_directory_list(1, working_directory); + const std::vector working_directory_list(1, working_directory); result = is_potential_path(token, at_cursor, working_directory_list, ctx, PATH_EXPAND_TILDE); } diff --git a/src/highlight.h b/src/highlight.h index d9e9f7384..3454fb2b7 100644 --- a/src/highlight.h +++ b/src/highlight.h @@ -157,7 +157,7 @@ enum { }; typedef unsigned int path_flags_t; bool is_potential_path(const wcstring &potential_path_fragment, bool at_cursor, - const wcstring_list_t &directories, const operation_context_t &ctx, + const std::vector &directories, const operation_context_t &ctx, path_flags_t flags); /// Syntax highlighter helper. diff --git a/src/history.cpp b/src/history.cpp index ac9dae85f..71a7e025a 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -342,7 +342,7 @@ struct history_impl_t { // Gets all the history into a list. This is intended for the $history environment variable. // This may be long! - void get_history(wcstring_list_t &result); + void get_history(std::vector &result); // Let indexes be a list of one-based indexes into the history, matching the interpretation of // $history. That is, $history[1] is the most recently executed command. Values less than one @@ -350,7 +350,7 @@ struct history_impl_t { std::unordered_map items_at_indexes(const std::vector &idxs); // Sets the valid file paths for the history item with the given identifier. - void set_valid_file_paths(wcstring_list_t &&valid_file_paths, history_identifier_t ident); + void set_valid_file_paths(std::vector &&valid_file_paths, history_identifier_t ident); // Return the specified history at the specified index. 0 is the index of the current // commandline. (So the most recent item is at index 1.) @@ -470,7 +470,7 @@ void history_impl_t::remove(const wcstring &str_to_remove) { assert(first_unwritten_new_item_index <= new_items.size()); } -void history_impl_t::set_valid_file_paths(wcstring_list_t &&valid_file_paths, +void history_impl_t::set_valid_file_paths(std::vector &&valid_file_paths, history_identifier_t ident) { // 0 identifier is used to mean "not necessary". if (ident == 0) { @@ -486,7 +486,7 @@ void history_impl_t::set_valid_file_paths(wcstring_list_t &&valid_file_paths, } } -void history_impl_t::get_history(wcstring_list_t &result) { +void history_impl_t::get_history(std::vector &result) { // If we have a pending item, we skip the first encountered (i.e. last) new item. bool next_is_pending = this->has_pending_item; std::unordered_set seen; @@ -1296,7 +1296,7 @@ wcstring history_session_id(const environment_t &vars) { path_list_t expand_and_detect_paths(const path_list_t &paths, const environment_t &vars) { ASSERT_IS_BACKGROUND_THREAD(); - wcstring_list_t result; + std::vector result; wcstring working_directory = vars.get_pwd_slash(); operation_context_t ctx(vars, kExpansionLimitBackground); for (const wcstring &path : paths) { @@ -1480,11 +1480,11 @@ static void do_1_history_search(history_t *hist, history_search_type_t search_ty } // Searches history. -bool history_t::search(history_search_type_t search_type, const wcstring_list_t &search_args, +bool history_t::search(history_search_type_t search_type, const std::vector &search_args, const wchar_t *show_time_format, size_t max_items, bool case_sensitive, bool null_terminate, bool reverse, const cancel_checker_t &cancel_check, io_streams_t &streams) { - wcstring_list_t collected; + std::vector collected; wcstring formatted_record; size_t remaining = max_items; bool output_error = false; @@ -1548,7 +1548,7 @@ void history_t::populate_from_bash(FILE *f) { impl()->populate_from_bash(f); } void history_t::incorporate_external_changes() { impl()->incorporate_external_changes(); } -void history_t::get_history(wcstring_list_t &result) { impl()->get_history(result); } +void history_t::get_history(std::vector &result) { impl()->get_history(result); } std::unordered_map history_t::items_at_indexes(const std::vector &idxs) { return impl()->items_at_indexes(idxs); diff --git a/src/history.h b/src/history.h index 0f649486d..fff284321 100644 --- a/src/history.h +++ b/src/history.h @@ -189,7 +189,7 @@ class history_t : noncopyable_t, nonmovable_t { void save(); /// Searches history. - bool search(history_search_type_t search_type, const wcstring_list_t &search_args, + bool search(history_search_type_t search_type, const std::vector &search_args, const wchar_t *show_time_format, size_t max_items, bool case_sensitive, bool null_terminate, bool reverse, const cancel_checker_t &cancel_check, io_streams_t &streams); @@ -211,7 +211,7 @@ class history_t : noncopyable_t, nonmovable_t { /// Gets all the history into a list. This is intended for the $history environment variable. /// This may be long! - void get_history(wcstring_list_t &result); + void get_history(std::vector &result); /// Let indexes be a list of one-based indexes into the history, matching the interpretation of /// $history. That is, $history[1] is the most recently executed command. Values less than one diff --git a/src/input.cpp b/src/input.cpp index 515106b9f..8b66708eb 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -39,7 +39,7 @@ struct input_mapping_t { /// Character sequence which generates this event. wcstring seq; /// Commands that should be evaluated by this mapping. - wcstring_list_t commands; + std::vector commands; /// We wish to preserve the user-specified order. This is just an incrementing value. unsigned int specification_order; /// Mode in which this command should be evaluated. @@ -47,7 +47,7 @@ struct input_mapping_t { /// New mode that should be switched to after command evaluation. wcstring sets_mode; - input_mapping_t(wcstring s, wcstring_list_t c, wcstring m, wcstring sm) + input_mapping_t(wcstring s, std::vector c, wcstring m, wcstring sm) : seq(std::move(s)), commands(std::move(c)), mode(std::move(m)), sets_mode(std::move(sm)) { static unsigned int s_last_input_map_spec_order = 0; specification_order = ++s_last_input_map_spec_order; @@ -250,7 +250,7 @@ void input_mapping_set_t::add(wcstring sequence, const wchar_t *const *commands, all_mappings_cache_.reset(); // Remove existing mappings with this sequence. - const wcstring_list_t commands_vector(commands, commands + commands_len); + const std::vector commands_vector(commands, commands + commands_len); mapping_list_t &ml = user ? mapping_list_ : preset_mapping_list_; @@ -825,7 +825,7 @@ bool input_mapping_set_t::erase(const wcstring &sequence, const wcstring &mode, } bool input_mapping_set_t::get(const wcstring &sequence, const wcstring &mode, - wcstring_list_t *out_cmds, bool user, wcstring *out_sets_mode) const { + std::vector *out_cmds, bool user, wcstring *out_sets_mode) const { bool result = false; const auto &ml = user ? mapping_list_ : preset_mapping_list_; for (const input_mapping_t &m : ml) { @@ -930,9 +930,9 @@ bool input_terminfo_get_name(const wcstring &seq, wcstring *out_name) { return false; } -wcstring_list_t input_terminfo_get_names(bool skip_null) { +std::vector input_terminfo_get_names(bool skip_null) { assert(s_terminfo_mappings.is_set()); - wcstring_list_t result; + std::vector result; const auto &mappings = *s_terminfo_mappings; result.reserve(mappings.size()); for (const terminfo_mapping_t &m : mappings) { @@ -944,10 +944,10 @@ wcstring_list_t input_terminfo_get_names(bool skip_null) { return result; } -const wcstring_list_t &input_function_get_names() { +const std::vector &input_function_get_names() { // The list and names of input functions are hard-coded and never change - static wcstring_list_t result = ([&]() { - wcstring_list_t result; + static std::vector result = ([&]() { + std::vector result; result.reserve(input_function_count); for (const auto &md : input_function_metadata) { if (md.name[0]) { diff --git a/src/input.h b/src/input.h index eeae2115b..04e210272 100644 --- a/src/input.h +++ b/src/input.h @@ -44,7 +44,7 @@ class inputter_t final : private input_event_queue_t { /// \p command_handler is used to run commands. If empty (in the std::function sense), when a /// character is encountered that would invoke a fish command, it is unread and /// char_event_type_t::check_exit is returned. Note the handler is not stored. - using command_handler_t = std::function; + using command_handler_t = std::function &)>; char_event_t read_char(const command_handler_t &command_handler = {}); /// Enqueue a char event to the queue of unread characters that input_readch will return before @@ -114,7 +114,7 @@ class input_mapping_set_t { /// Gets the command bound to the specified key sequence in the specified mode. Returns true if /// it exists, false if not. - bool get(const wcstring &sequence, const wcstring &mode, wcstring_list_t *out_cmds, bool user, + bool get(const wcstring &sequence, const wcstring &mode, std::vector *out_cmds, bool user, wcstring *out_sets_mode) const; /// Returns all mapping names and modes. @@ -149,12 +149,12 @@ bool input_terminfo_get_sequence(const wcstring &name, wcstring *out_seq); bool input_terminfo_get_name(const wcstring &seq, wcstring *out_name); /// Return a list of all known terminfo names. -wcstring_list_t input_terminfo_get_names(bool skip_null); +std::vector input_terminfo_get_names(bool skip_null); /// Returns the input function code for the given input function name. maybe_t input_function_get_code(const wcstring &name); /// Returns a list of all existing input function names. -const wcstring_list_t &input_function_get_names(void); +const std::vector &input_function_get_names(void); #endif diff --git a/src/kill.cpp b/src/kill.cpp index 96f7f4949..cb06e1f7a 100644 --- a/src/kill.cpp +++ b/src/kill.cpp @@ -53,7 +53,7 @@ wcstring kill_yank() { return kill_list->front(); } -wcstring_list_t kill_entries() { +std::vector kill_entries() { auto kill_list = s_kill_list.acquire(); - return wcstring_list_t{kill_list->begin(), kill_list->end()}; + return std::vector{kill_list->begin(), kill_list->end()}; } diff --git a/src/kill.h b/src/kill.h index 90456c9ec..5cab7f098 100644 --- a/src/kill.h +++ b/src/kill.h @@ -20,6 +20,6 @@ wcstring kill_yank_rotate(); wcstring kill_yank(); /// Get copy of kill ring as vector of strings -wcstring_list_t kill_entries(); +std::vector kill_entries(); #endif diff --git a/src/null_terminated_array.cpp b/src/null_terminated_array.cpp index 7d7979f85..d119e7e4e 100644 --- a/src/null_terminated_array.cpp +++ b/src/null_terminated_array.cpp @@ -1,6 +1,6 @@ #include "null_terminated_array.h" -std::vector wide_string_list_to_narrow(const wcstring_list_t &strs) { +std::vector wide_string_list_to_narrow(const std::vector &strs) { std::vector res; res.reserve(strs.size()); for (const wcstring &s : strs) { diff --git a/src/null_terminated_array.h b/src/null_terminated_array.h index 7a19b4e66..0d094bc93 100644 --- a/src/null_terminated_array.h +++ b/src/null_terminated_array.h @@ -61,7 +61,7 @@ class owning_null_terminated_array_t { }; /// Helper to convert a list of wcstring to a list of std::string. -std::vector wide_string_list_to_narrow(const wcstring_list_t &strs); +std::vector wide_string_list_to_narrow(const std::vector &strs); /// \return the length of a null-terminated array of pointers to something. template diff --git a/src/pager.cpp b/src/pager.cpp index a5c5ec199..e72a8a859 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -364,7 +364,7 @@ void pager_t::measure_completion_infos(comp_info_list_t *infos, const wcstring & size_t prefix_len = fish_wcswidth(prefix); for (auto &info : *infos) { comp_t *comp = &info; - const wcstring_list_t &comp_strings = comp->comp; + const std::vector &comp_strings = comp->comp; for (size_t j = 0; j < comp_strings.size(); j++) { // If there's more than one, append the length of ', '. diff --git a/src/pager.h b/src/pager.h index ff74d055b..df20cea15 100644 --- a/src/pager.h +++ b/src/pager.h @@ -83,7 +83,7 @@ class pager_t { /// Data structure describing one or a group of related completions. struct comp_t { /// The list of all completion strings this entry applies to. - wcstring_list_t comp{}; + std::vector comp{}; /// The description. wcstring desc{}; /// The representative completion. diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 369f0b724..bb5ed73a3 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -388,7 +388,7 @@ end_execution_reason_t parse_execution_context_t::run_function_statement( const ast::block_statement_t &statement, const ast::function_header_t &header) { using namespace ast; // Get arguments. - wcstring_list_t arguments; + std::vector arguments; ast_args_list_t arg_nodes = get_argument_nodes(header.args()); arg_nodes.insert(arg_nodes.begin(), &header.first_arg()); end_execution_reason_t result = @@ -449,7 +449,7 @@ end_execution_reason_t parse_execution_context_t::run_for_statement( } // Get the contents to iterate over. - wcstring_list_t arguments; + std::vector arguments; ast_args_list_t arg_nodes = get_argument_nodes(header.args()); end_execution_reason_t ret = this->expand_arguments_from_nodes(arg_nodes, &arguments, nullglob); if (ret != end_execution_reason_t::ok) { @@ -465,7 +465,7 @@ end_execution_reason_t parse_execution_context_t::run_for_statement( auto &vars = parser->vars(); int retval; - retval = vars.set(for_var_name, ENV_LOCAL | ENV_USER, var ? var->as_list() : wcstring_list_t{}); + retval = vars.set(for_var_name, ENV_LOCAL | ENV_USER, var ? var->as_list() : std::vector{}); assert(retval == ENV_OK); trace_if_enabled(*parser, L"for", arguments); @@ -562,7 +562,7 @@ end_execution_reason_t parse_execution_context_t::run_switch_statement( // anything. We also report case errors, but don't stop execution; i.e. a case item that // contains an unexpandable process will report and then fail to match. ast_args_list_t arg_nodes = get_argument_nodes(case_item.arguments()); - wcstring_list_t case_args; + std::vector case_args; end_execution_reason_t case_result = this->expand_arguments_from_nodes(arg_nodes, &case_args, failglob); if (case_result == end_execution_reason_t::ok) { @@ -771,7 +771,7 @@ end_execution_reason_t parse_execution_context_t::handle_command_not_found( // Handle unrecognized commands with standard command not found handler that can make better // error messages. - wcstring_list_t event_args; + std::vector event_args; { ast_args_list_t args = get_argument_nodes(statement.args_or_redirs()); end_execution_reason_t arg_result = @@ -826,7 +826,7 @@ end_execution_reason_t parse_execution_context_t::handle_command_not_found( end_execution_reason_t parse_execution_context_t::expand_command( const ast::decorated_statement_t &statement, wcstring *out_cmd, - wcstring_list_t *out_args) const { + std::vector *out_args) const { // Here we're expanding a command, for example $HOME/bin/stuff or $randomthing. The first // completion becomes the command itself, everything after becomes arguments. Command // substitutions are not supported. @@ -871,7 +871,7 @@ end_execution_reason_t parse_execution_context_t::populate_plain_process( // Get the command and any arguments due to expanding the command. wcstring cmd; - wcstring_list_t args_from_cmd_expansion; + std::vector args_from_cmd_expansion; auto ret = expand_command(statement, &cmd, &args_from_cmd_expansion); if (ret != end_execution_reason_t::ok) { return ret; @@ -909,7 +909,7 @@ end_execution_reason_t parse_execution_context_t::populate_plain_process( } // Produce the full argument list and the set of IO redirections. - wcstring_list_t cmd_args; + std::vector cmd_args; auto redirections = new_redirection_spec_list(); if (use_implicit_cd) { // Implicit cd is simple. @@ -954,7 +954,7 @@ end_execution_reason_t parse_execution_context_t::populate_plain_process( // Determine the list of arguments, expanding stuff. Reports any errors caused by expansion. If we // have a wildcard that could not be expanded, report the error and continue. end_execution_reason_t parse_execution_context_t::expand_arguments_from_nodes( - const ast_args_list_t &argument_nodes, wcstring_list_t *out_arguments, + const ast_args_list_t &argument_nodes, std::vector *out_arguments, globspec_t glob_behavior) { // Get all argument nodes underneath the statement. We guess we'll have that many arguments (but // may have more or fewer, if there are wildcards involved). @@ -1145,7 +1145,7 @@ end_execution_reason_t parse_execution_context_t::apply_variable_assignments( DIE("unexpected expand_string() return value"); } } - wcstring_list_t vals; + std::vector vals; for (auto &completion : expression_expanded) { vals.emplace_back(std::move(completion.completion)); } diff --git a/src/parse_execution.h b/src/parse_execution.h index 52c4718b1..6a375d3e9 100644 --- a/src/parse_execution.h +++ b/src/parse_execution.h @@ -81,7 +81,7 @@ class parse_execution_context_t : noncopyable_t { // Expand a command which may contain variables, producing an expand command and possibly // arguments. Prints an error message on error. end_execution_reason_t expand_command(const ast::decorated_statement_t &statement, - wcstring *out_cmd, wcstring_list_t *out_args) const; + wcstring *out_cmd, std::vector *out_args) const; /// Indicates whether a job is a simple block (one block, no redirections). bool job_is_simple_block(const ast::job_pipeline_t &job) const; @@ -128,7 +128,7 @@ class parse_execution_context_t : noncopyable_t { static ast_args_list_t get_argument_nodes(const ast::argument_or_redirection_list_t &args); end_execution_reason_t expand_arguments_from_nodes(const ast_args_list_t &argument_nodes, - wcstring_list_t *out_arguments, + std::vector *out_arguments, globspec_t glob_behavior); // Determines the list of redirections for a node. diff --git a/src/parser.cpp b/src/parser.cpp index f2f9160ed..f83dfde45 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -70,7 +70,7 @@ rust::Box &parser_t::get_wait_handles_ffi() { return wait_ha const rust::Box &parser_t::get_wait_handles_ffi() const { return wait_handles; } -int parser_t::set_var_and_fire(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals) { +int parser_t::set_var_and_fire(const wcstring &key, env_mode_flags_t mode, std::vector vals) { int res = vars().set(key, mode, std::move(vals)); if (res == ENV_OK) { event_fire(*this, *new_event_variable_set(key)); @@ -79,7 +79,7 @@ int parser_t::set_var_and_fire(const wcstring &key, env_mode_flags_t mode, wcstr } int parser_t::set_var_and_fire(const wcstring &key, env_mode_flags_t mode, wcstring val) { - wcstring_list_t vals; + std::vector vals; vals.push_back(std::move(val)); return set_var_and_fire(key, mode, std::move(vals)); } @@ -798,7 +798,7 @@ block_t block_t::event_block(const void *evt_) { return b; } -block_t block_t::function_block(wcstring name, wcstring_list_t args, bool shadows) { +block_t block_t::function_block(wcstring name, std::vector args, bool shadows) { block_t b{shadows ? block_type_t::function_call : block_type_t::function_call_no_shadow}; b.function_name = std::move(name); b.function_args = std::move(args); diff --git a/src/parser.h b/src/parser.h index 4a78b1d03..1572cc899 100644 --- a/src/parser.h +++ b/src/parser.h @@ -68,7 +68,7 @@ class block_t { uint64_t event_blocks{}; // If this is a function block, the function args. Otherwise empty. - wcstring_list_t function_args{}; + std::vector function_args{}; /// Name of file that created this block. filename_ref_t src_filename{}; @@ -103,7 +103,7 @@ class block_t { /// Entry points for creating blocks. static block_t if_block(); static block_t event_block(const void *evt_); - static block_t function_block(wcstring name, wcstring_list_t args, bool shadows); + static block_t function_block(wcstring name, std::vector args, bool shadows); static block_t source_block(filename_ref_t src); static block_t for_block(); static block_t while_block(); @@ -210,7 +210,7 @@ struct library_data_t : public library_data_pod_t { /// A stack of fake values to be returned by builtin_commandline. This is used by the completion /// machinery when wrapping: e.g. if `tig` wraps `git` then git completions need to see git on /// the command line. - wcstring_list_t transient_commandlines{}; + std::vector transient_commandlines{}; /// A file descriptor holding the current working directory, for use in openat(). /// This is never null and never invalid. @@ -420,7 +420,7 @@ class parser_t : public std::enable_shared_from_this { /// Cover of vars().set(), which also fires any returned event handlers. /// \return a value like ENV_OK. int set_var_and_fire(const wcstring &key, env_mode_flags_t mode, wcstring val); - int set_var_and_fire(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals); + int set_var_and_fire(const wcstring &key, env_mode_flags_t mode, std::vector vals); /// Update any universal variables and send event handlers. /// If \p always is set, then do it even if we have no pending changes (that is, look for diff --git a/src/path.cpp b/src/path.cpp index a1ced74e0..6a8643aba 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -26,9 +26,9 @@ #include "wutil.h" // IWYU pragma: keep // PREFIX is defined at build time. -static const wcstring_list_t kDefaultPath({L"/bin", L"/usr/bin", PREFIX L"/bin"}); +static const std::vector kDefaultPath({L"/bin", L"/usr/bin", PREFIX L"/bin"}); -static get_path_result_t path_get_path_core(const wcstring &cmd, const wcstring_list_t &pathsv) { +static get_path_result_t path_get_path_core(const wcstring &cmd, const std::vector &pathsv) { const get_path_result_t noent_res{ENOENT, wcstring{}}; get_path_result_t result{}; @@ -142,9 +142,9 @@ static dir_remoteness_t path_remoteness(const wcstring &path) { #endif } -wcstring_list_t path_get_paths(const wcstring &cmd, const environment_t &vars) { +std::vector path_get_paths(const wcstring &cmd, const environment_t &vars) { FLOGF(path, L"path_get_paths('%ls')", cmd.c_str()); - wcstring_list_t paths; + std::vector paths; // If the command has a slash, it must be an absolute or relative path and thus we don't bother // looking for matching commands in the PATH var. @@ -157,7 +157,7 @@ wcstring_list_t path_get_paths(const wcstring &cmd, const environment_t &vars) { auto path_var = vars.get(L"PATH"); if (!path_var) return paths; - const wcstring_list_t &pathsv = path_var->as_list(); + const std::vector &pathsv = path_var->as_list(); for (auto path : pathsv) { if (path.empty()) continue; append_path_component(path, cmd); @@ -172,9 +172,9 @@ wcstring_list_ffi_t path_get_paths_ffi(const wcstring &cmd, const parser_t &pars return path_get_paths(cmd, parser.vars()); } -wcstring_list_t path_apply_cdpath(const wcstring &dir, const wcstring &wd, +std::vector path_apply_cdpath(const wcstring &dir, const wcstring &wd, const environment_t &env_vars) { - wcstring_list_t paths; + std::vector paths; if (dir.at(0) == L'/') { // Absolute path. paths.push_back(dir); @@ -184,7 +184,7 @@ wcstring_list_t path_apply_cdpath(const wcstring &dir, const wcstring &wd, paths.push_back(path_normalize_for_cd(wd, dir)); } else { // Respect CDPATH. - wcstring_list_t cdpathsv; + std::vector cdpathsv; if (auto cdpaths = env_vars.get(L"CDPATH")) { cdpathsv = cdpaths->as_list(); } diff --git a/src/path.h b/src/path.h index 8b0e7b481..997b3ecf2 100644 --- a/src/path.h +++ b/src/path.h @@ -64,7 +64,7 @@ struct get_path_result_t { get_path_result_t path_try_get_path(const wcstring &cmd, const environment_t &vars); /// Return all the paths that match the given command. -wcstring_list_t path_get_paths(const wcstring &cmd, const environment_t &vars); +std::vector path_get_paths(const wcstring &cmd, const environment_t &vars); // Needed because of issues with vectors of wstring and environment_t. wcstring_list_ffi_t path_get_paths_ffi(const wcstring &cmd, const parser_t &parser); @@ -84,7 +84,7 @@ maybe_t path_get_cdpath(const wcstring &dir, const wcstring &wd, const environment_t &vars); /// Returns the given directory with all CDPATH components applied. -wcstring_list_t path_apply_cdpath(const wcstring &dir, const wcstring &wd, +std::vector path_apply_cdpath(const wcstring &dir, const wcstring &wd, const environment_t &env_vars); /// Returns the path resolved as an implicit cd command, or none() if none. This requires it to diff --git a/src/proc.h b/src/proc.h index ae321b152..dd9231eb1 100644 --- a/src/proc.h +++ b/src/proc.h @@ -258,16 +258,16 @@ class process_t { struct concrete_assignment { wcstring variable_name; - wcstring_list_t values; + std::vector values; }; /// The expanded variable assignments for this process, as specified by the `a=b cmd` syntax. std::vector variable_assignments; /// Sets argv. - void set_argv(wcstring_list_t argv) { argv_ = std::move(argv); } + void set_argv(std::vector argv) { argv_ = std::move(argv); } /// Returns argv. - const wcstring_list_t &argv() { return argv_; } + const std::vector &argv() { return argv_; } /// Returns argv[0], or nullptr. const wchar_t *argv0() const { return argv_.empty() ? nullptr : argv_.front().c_str(); } @@ -346,7 +346,7 @@ class process_t { process_t &operator=(const process_t &) = delete; private: - wcstring_list_t argv_; + std::vector argv_; rust::Box proc_redirection_specs_; // The wait handle. This is constructed lazily, and cached. diff --git a/src/re.cpp b/src/re.cpp index b14bf3d68..279f94c58 100644 --- a/src/re.cpp +++ b/src/re.cpp @@ -193,7 +193,7 @@ size_t regex_t::capture_group_count() const { return count; } -wcstring_list_t regex_t::capture_group_names() const { +std::vector regex_t::capture_group_names() const { PCRE2_SPTR name_table{}; uint32_t name_entry_size{}; uint32_t name_count{}; @@ -230,7 +230,7 @@ wcstring_list_t regex_t::capture_group_names() const { }; const auto *names = reinterpret_cast(name_table); - wcstring_list_t result; + std::vector result; result.reserve(name_count); for (uint32_t i = 0; i < name_count; ++i) { const auto &name_entry = names[i * name_entry_size]; diff --git a/src/re.h b/src/re.h index c1cd0f34d..7d2a8a09b 100644 --- a/src/re.h +++ b/src/re.h @@ -132,7 +132,7 @@ class regex_t : noncopyable_t { /// \return the list of capture group names. /// Note PCRE provides these in sorted order, not specification order. - wcstring_list_t capture_group_names() const; + std::vector capture_group_names() const; /// Search \p subject for matches for this regex, starting at \p start_idx, and replacing them /// with \p replacement. If \p repl_count is not null, populate it with the number of diff --git a/src/reader.cpp b/src/reader.cpp index 3e57f87e2..e0659d79f 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -575,7 +575,7 @@ struct autosuggestion_t { wcstring search_string{}; // The list of completions which may need loading. - wcstring_list_t needs_load{}; + std::vector needs_load{}; // Whether the autosuggestion should be case insensitive. // This is true for file-generated autosuggestions, but not for history. @@ -875,7 +875,7 @@ class reader_data_t : public std::enable_shared_from_this { void move_word(editable_line_t *el, bool move_right, bool erase, move_word_style_t style, bool newv); - void run_input_command_scripts(const wcstring_list_t &cmds); + void run_input_command_scripts(const std::vector &cmds); maybe_t read_normal_chars(readline_loop_state_t &rls); void handle_readline_command(readline_cmd_t cmd, readline_loop_state_t &rls); @@ -1399,7 +1399,7 @@ maybe_t expand_replacer(SourceRange range, const wcstring & scoped_push not_interactive(&parser.libdata().is_interactive, false); - wcstring_list_t outputs{}; + std::vector outputs{}; int ret = exec_subshell(cmd, parser, outputs, false /* not apply_exit_status */); if (ret != STATUS_CMD_OK) { return none(); @@ -1547,7 +1547,7 @@ void reader_write_title(const wcstring &cmd, parser_t &parser, bool reset_cursor } } - wcstring_list_t lst; + std::vector lst; (void)exec_subshell(fish_title_command, parser, lst, false /* ignore exit status */); if (!lst.empty()) { wcstring title_line = L"\x1B]0;"; @@ -1569,7 +1569,7 @@ void reader_write_title(const wcstring &cmd, parser_t &parser, bool reset_cursor void reader_data_t::exec_mode_prompt() { mode_prompt_buff.clear(); if (function_exists(MODE_PROMPT_FUNCTION_NAME, parser())) { - wcstring_list_t mode_indicator_list; + std::vector mode_indicator_list; exec_subshell(MODE_PROMPT_FUNCTION_NAME, parser(), mode_indicator_list, false); // We do not support multiple lines in the mode indicator, so just concatenate all of // them. @@ -1600,7 +1600,7 @@ void reader_data_t::exec_prompt() { if (!conf.left_prompt_cmd.empty()) { // Status is ignored. - wcstring_list_t prompt_list; + std::vector prompt_list; // Historic compatibility hack. // If the left prompt function is deleted, then use a default prompt instead of // producing an error. @@ -1614,7 +1614,7 @@ void reader_data_t::exec_prompt() { if (!conf.right_prompt_cmd.empty()) { if (function_exists(conf.right_prompt_cmd, parser())) { // Status is ignored. - wcstring_list_t prompt_list; + std::vector prompt_list; exec_subshell(conf.right_prompt_cmd, parser(), prompt_list, false); // Right prompt does not support multiple lines, so just concatenate all of them. for (const auto &i : prompt_list) { @@ -2018,7 +2018,7 @@ static std::function get_autosuggestion_performer( // Try normal completions. completion_request_options_t complete_flags = completion_request_options_t::autosuggest(); - wcstring_list_t needs_load; + std::vector needs_load; completion_list_t completions = complete(search_string, complete_flags, ctx, &needs_load); autosuggestion_t result{}; @@ -3333,7 +3333,7 @@ static bool event_is_normal_char(const char_event_t &evt) { } /// Run a sequence of commands from an input binding. -void reader_data_t::run_input_command_scripts(const wcstring_list_t &cmds) { +void reader_data_t::run_input_command_scripts(const std::vector &cmds) { auto last_statuses = parser().get_last_statuses(); for (const wcstring &cmd : cmds) { update_commandline_state(); @@ -3365,7 +3365,7 @@ maybe_t reader_data_t::read_normal_chars(readline_loop_state_t &rl size_t limit = std::min(rls.nchars - command_line.size(), READAHEAD_MAX); using command_handler_t = inputter_t::command_handler_t; - command_handler_t normal_handler = [this](const wcstring_list_t &cmds) { + command_handler_t normal_handler = [this](const std::vector &cmds) { this->run_input_command_scripts(cmds); }; command_handler_t empty_handler = {}; diff --git a/src/screen.h b/src/screen.h index 26bbb452b..4c667baa6 100644 --- a/src/screen.h +++ b/src/screen.h @@ -256,7 +256,7 @@ class layout_cache_t : noncopyable_t { private: // Cached escape sequences we've already detected in the prompt and similar strings, ordered // lexicographically. - wcstring_list_t esc_cache_; + std::vector esc_cache_; // LRU-list of prompts and their layouts. // Use a list so we can promote to the front on a cache hit. diff --git a/src/wcstringutil.cpp b/src/wcstringutil.cpp index 23ebcf003..4c8519d5c 100644 --- a/src/wcstringutil.cpp +++ b/src/wcstringutil.cpp @@ -245,8 +245,8 @@ size_t ifind(const std::string &haystack, const std::string &needle, bool fuzzy) return fuzzy ? ifind_impl(haystack, needle) : ifind_impl(haystack, needle); } -wcstring_list_t split_string(const wcstring &val, wchar_t sep) { - wcstring_list_t out; +std::vector split_string(const wcstring &val, wchar_t sep) { + std::vector out; size_t pos = 0, end = val.size(); while (pos <= end) { size_t next_pos = val.find(sep, pos); @@ -259,8 +259,8 @@ wcstring_list_t split_string(const wcstring &val, wchar_t sep) { return out; } -wcstring_list_t split_string_tok(const wcstring &val, const wcstring &seps, size_t max_results) { - wcstring_list_t out; +std::vector split_string_tok(const wcstring &val, const wcstring &seps, size_t max_results) { + std::vector out; size_t end = val.size(); size_t pos = 0; while (pos < end && out.size() + 1 < max_results) { @@ -286,7 +286,7 @@ wcstring_list_t split_string_tok(const wcstring &val, const wcstring &seps, size return out; } -static wcstring join_strings_impl(const wcstring_list_t &vals, const wchar_t *sep, size_t seplen) { +static wcstring join_strings_impl(const std::vector &vals, const wchar_t *sep, size_t seplen) { if (vals.empty()) return wcstring{}; // Reserve the size we will need. @@ -310,11 +310,11 @@ static wcstring join_strings_impl(const wcstring_list_t &vals, const wchar_t *se return result; } -wcstring join_strings(const wcstring_list_t &vals, wchar_t c) { +wcstring join_strings(const std::vector &vals, wchar_t c) { return join_strings_impl(vals, &c, 1); } -wcstring join_strings(const wcstring_list_t &vals, const wchar_t *sep) { +wcstring join_strings(const std::vector &vals, const wchar_t *sep) { return join_strings_impl(vals, sep, wcslen(sep)); } diff --git a/src/wcstringutil.h b/src/wcstringutil.h index 1ede27fba..39d33c0cf 100644 --- a/src/wcstringutil.h +++ b/src/wcstringutil.h @@ -128,7 +128,7 @@ inline maybe_t string_fuzzy_match_string(const wcstring &s } /// Split a string by a separator character. -wcstring_list_t split_string(const wcstring &val, wchar_t sep); +std::vector split_string(const wcstring &val, wchar_t sep); /// Split a string by runs of any of the separator characters provided in \p seps. /// Note the delimiters are the characters in \p seps, not \p seps itself. @@ -137,12 +137,12 @@ wcstring_list_t split_string(const wcstring &val, wchar_t sep); /// the last output is the the remainder of the input, including leading delimiters, /// except for the first. This is historical behavior. /// Example: split_string_tok(" a b c ", " ", 3) -> {"a", "b", " c "} -wcstring_list_t split_string_tok(const wcstring &val, const wcstring &seps, +std::vector split_string_tok(const wcstring &val, const wcstring &seps, size_t max_results = std::numeric_limits::max()); /// Join a list of strings by a separator character or string. -wcstring join_strings(const wcstring_list_t &vals, wchar_t sep); -wcstring join_strings(const wcstring_list_t &vals, const wchar_t *sep); +wcstring join_strings(const std::vector &vals, wchar_t sep); +wcstring join_strings(const std::vector &vals, const wchar_t *sep); inline wcstring to_string(long x) { wchar_t buff[64]; @@ -192,7 +192,7 @@ inline bool bool_from_string(const wcstring &x) { /// Max output entries will be max + 1 (after max splits) template void split_about(ITER haystack_start, ITER haystack_end, ITER needle_start, ITER needle_end, - wcstring_list_t *output, long max = LONG_MAX, bool no_empty = false) { + std::vector *output, long max = LONG_MAX, bool no_empty = false) { long remaining = max; ITER haystack_cursor = haystack_start; while (remaining > 0 && haystack_cursor != haystack_end) { diff --git a/src/wutil.cpp b/src/wutil.cpp index ecee1dba5..085858c15 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -369,8 +369,8 @@ wcstring normalize_path(const wcstring &path, bool allow_leading_double_slashes) leading_slashes++; } - wcstring_list_t comps = split_string(path, sep); - wcstring_list_t new_comps; + std::vector comps = split_string(path, sep); + std::vector new_comps; for (wcstring &comp : comps) { if (comp.empty() || comp == L".") { continue; @@ -410,8 +410,8 @@ wcstring path_normalize_for_cd(const wcstring &wd, const wcstring &path) { } // Split our strings by the sep. - wcstring_list_t wd_comps = split_string(wd, sep); - wcstring_list_t path_comps = split_string(path, sep); + std::vector wd_comps = split_string(wd, sep); + std::vector path_comps = split_string(path, sep); // Remove empty segments from wd_comps. // In particular this removes the leading and trailing empties. @@ -903,7 +903,7 @@ bool file_id_t::operator<(const file_id_t &rhs) const { return this->compare_fil // static wcstring_list_ffi_t wcstring_list_ffi_t::get_test_data() { - return wcstring_list_t{L"foo", L"bar", L"baz"}; + return std::vector{L"foo", L"bar", L"baz"}; } // static diff --git a/src/wutil.h b/src/wutil.h index ee0eb4197..8d1aef859 100644 --- a/src/wutil.h +++ b/src/wutil.h @@ -40,10 +40,10 @@ struct wcharz_t { // A helper type for passing vectors of strings back to Rust. // This hides the vector so that autocxx doesn't complain about templates. struct wcstring_list_ffi_t { - wcstring_list_t vals{}; + std::vector vals{}; wcstring_list_ffi_t() = default; - /* implicit */ wcstring_list_ffi_t(wcstring_list_t vals) : vals(std::move(vals)) {} + /* implicit */ wcstring_list_ffi_t(std::vector vals) : vals(std::move(vals)) {} size_t size() const { return vals.size(); } const wcstring &at(size_t idx) const { return vals.at(idx); }