mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-24 18:07:23 +08:00
Switch parser_t to hold its variables via shared_ptr
Preparation for variable stacks with finite lifetimes.
This commit is contained in:
parent
261198aa3e
commit
ad57133c7f
|
@ -1283,8 +1283,9 @@ env_stack_t &env_stack_t::globals() {
|
|||
return s_globals;
|
||||
}
|
||||
|
||||
env_stack_t &env_stack_t::principal() {
|
||||
static env_stack_t s_principal(env_stack_impl_t::create());
|
||||
const std::shared_ptr<env_stack_t> &env_stack_t::principal_ref() {
|
||||
static const std::shared_ptr<env_stack_t> s_principal{
|
||||
new env_stack_t(env_stack_impl_t::create())};
|
||||
return s_principal;
|
||||
}
|
||||
|
||||
|
|
|
@ -291,7 +291,8 @@ class env_stack_t final : public environment_t {
|
|||
void mark_changed_exported();
|
||||
|
||||
// Compatibility hack; access the "environment stack" from back when there was just one.
|
||||
static env_stack_t &principal();
|
||||
static const std::shared_ptr<env_stack_t> &principal_ref();
|
||||
static env_stack_t &principal() { return *principal_ref(); }
|
||||
|
||||
// Access a variable stack that only represents globals.
|
||||
// Do not push or pop from this.
|
||||
|
|
|
@ -100,7 +100,11 @@ wcstring parser_t::user_presentable_path(const wcstring &path) const {
|
|||
return replace_home_directory_with_tilde(path, vars());
|
||||
}
|
||||
|
||||
parser_t::parser_t() : variables(env_stack_t::principal()) {}
|
||||
parser_t::parser_t(std::shared_ptr<env_stack_t> vars) : variables(std::move(vars)) {
|
||||
assert(variables.get() && "Null variables in parser initializer");
|
||||
}
|
||||
|
||||
parser_t::parser_t() : parser_t(env_stack_t::principal_ref()) {}
|
||||
|
||||
// Out of line destructor to enable forward declaration of parse_execution_context_t
|
||||
parser_t::~parser_t() = default;
|
||||
|
|
|
@ -174,7 +174,7 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
|
|||
/// The 'depth' of the fish call stack.
|
||||
int eval_level = -1;
|
||||
/// Set of variables for the parser.
|
||||
env_stack_t &variables;
|
||||
const std::shared_ptr<env_stack_t> variables;
|
||||
/// Miscellaneous library data.
|
||||
library_data_t library_data{};
|
||||
|
||||
|
@ -204,6 +204,7 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
|
|||
|
||||
/// Create a parser.
|
||||
parser_t();
|
||||
parser_t(std::shared_ptr<env_stack_t> vars);
|
||||
|
||||
/// The main parser.
|
||||
static std::shared_ptr<parser_t> principal;
|
||||
|
@ -271,8 +272,8 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
|
|||
const job_list_t &jobs() const { return job_list; }
|
||||
|
||||
/// Get the variables.
|
||||
env_stack_t &vars() { return variables; }
|
||||
const env_stack_t &vars() const { return variables; }
|
||||
env_stack_t &vars() { return *variables; }
|
||||
const env_stack_t &vars() const { return *variables; }
|
||||
|
||||
/// Get the library data.
|
||||
library_data_t &libdata() { return library_data; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user