mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-01 01:41:01 +08:00
Move eval_level into parser_t
This avoids the ping-ponging of eval_level through parse_execution_context. Simply store the global eval level in the parser_t.
This commit is contained in:
parent
8bddce2633
commit
92d5c28730
|
@ -79,9 +79,8 @@ static wcstring profiling_cmd_name_for_redirectable_block(const parse_node_t &no
|
|||
return result;
|
||||
}
|
||||
|
||||
parse_execution_context_t::parse_execution_context_t(parsed_source_ref_t pstree, parser_t *p,
|
||||
int initial_eval_level)
|
||||
: pstree(std::move(pstree)), parser(p), eval_level(initial_eval_level) {}
|
||||
parse_execution_context_t::parse_execution_context_t(parsed_source_ref_t pstree, parser_t *p)
|
||||
: pstree(std::move(pstree)), parser(p) {}
|
||||
|
||||
// Utilities
|
||||
|
||||
|
@ -1115,7 +1114,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
|||
}
|
||||
|
||||
// Increment the eval_level for the duration of this command.
|
||||
scoped_push<int> saved_eval_level(&eval_level, eval_level + 1);
|
||||
scoped_push<int> saved_eval_level(&parser->eval_level, parser->eval_level + 1);
|
||||
|
||||
// Save the node index.
|
||||
scoped_push<tnode_t<grammar::job>> saved_node(&executing_job_node, job_node);
|
||||
|
@ -1162,7 +1161,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
|||
// Block-types profile a little weird. They have no 'parse' time, and their command is
|
||||
// just the block type.
|
||||
exec_time = get_time();
|
||||
profile_item->level = eval_level;
|
||||
profile_item->level = parser->eval_level;
|
||||
profile_item->parse = 0;
|
||||
profile_item->exec = (int)(exec_time - start_time);
|
||||
profile_item->cmd = profiling_cmd_name_for_redirectable_block(
|
||||
|
@ -1231,7 +1230,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
|||
|
||||
if (profile_item != NULL) {
|
||||
exec_time = get_time();
|
||||
profile_item->level = eval_level;
|
||||
profile_item->level = parser->eval_level;
|
||||
profile_item->parse = (int)(parse_time - start_time);
|
||||
profile_item->exec = (int)(exec_time - parse_time);
|
||||
profile_item->cmd = job ? job->command() : wcstring();
|
||||
|
|
|
@ -31,8 +31,6 @@ class parse_execution_context_t {
|
|||
parsed_source_ref_t pstree;
|
||||
io_chain_t block_io;
|
||||
parser_t *const parser;
|
||||
// parse_error_list_t errors;
|
||||
int eval_level;
|
||||
// The currently executing job node, used to indicate the line number.
|
||||
tnode_t<grammar::job> executing_job_node{};
|
||||
// Cached line number information.
|
||||
|
@ -128,10 +126,7 @@ class parse_execution_context_t {
|
|||
int line_offset_of_character_at_offset(size_t char_idx);
|
||||
|
||||
public:
|
||||
parse_execution_context_t(parsed_source_ref_t pstree, parser_t *p, int initial_eval_level);
|
||||
|
||||
/// Returns the current eval level.
|
||||
int current_eval_level() const { return eval_level; }
|
||||
parse_execution_context_t(parsed_source_ref_t pstree, parser_t *p);
|
||||
|
||||
/// Returns the current line number, indexed from 1. Not const since it touches
|
||||
/// cached_lineno_offset.
|
||||
|
|
|
@ -695,15 +695,8 @@ int parser_t::eval_node(parsed_source_ref_t ps, tnode_t<T> node, const io_chain_
|
|||
// Start it up
|
||||
scope_block_t *scope_block = this->push_block<scope_block_t>(block_type);
|
||||
|
||||
// Determine the initial eval level. If this is the first context, it's -1; otherwise it's the
|
||||
// eval level of the top context. This is sort of wonky because we're stitching together a
|
||||
// global notion of eval level from these separate objects. A better approach would be some
|
||||
// profile object that all contexts share, and that tracks the eval levels on its own.
|
||||
int exec_eval_level =
|
||||
(execution_contexts.empty() ? -1 : execution_contexts.back()->current_eval_level());
|
||||
|
||||
// Append to the execution context stack.
|
||||
execution_contexts.push_back(make_unique<parse_execution_context_t>(ps, this, exec_eval_level));
|
||||
execution_contexts.push_back(make_unique<parse_execution_context_t>(ps, this));
|
||||
parse_execution_context_t *ctx = execution_contexts.back().get();
|
||||
|
||||
int result = ctx->eval_node(node, scope_block, io);
|
||||
|
|
|
@ -185,6 +185,8 @@ class parser_t {
|
|||
job_list_t my_job_list;
|
||||
/// The list of blocks
|
||||
std::vector<std::unique_ptr<block_t>> block_stack;
|
||||
/// The 'depth' of the fish call stack.
|
||||
int eval_level = -1;
|
||||
|
||||
#if 0
|
||||
// TODO: Lint says this isn't used (which is true). Should this be removed?
|
||||
|
|
Loading…
Reference in New Issue
Block a user