diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 1c6741df5..70b62fd9e 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -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 jo } // Increment the eval_level for the duration of this command. - scoped_push saved_eval_level(&eval_level, eval_level + 1); + scoped_push saved_eval_level(&parser->eval_level, parser->eval_level + 1); // Save the node index. scoped_push> saved_node(&executing_job_node, job_node); @@ -1162,7 +1161,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t 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 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(); diff --git a/src/parse_execution.h b/src/parse_execution.h index 7b99691a9..5b469ab04 100644 --- a/src/parse_execution.h +++ b/src/parse_execution.h @@ -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 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. diff --git a/src/parser.cpp b/src/parser.cpp index 77818e131..38804af9d 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -695,15 +695,8 @@ int parser_t::eval_node(parsed_source_ref_t ps, tnode_t node, const io_chain_ // Start it up scope_block_t *scope_block = this->push_block(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(ps, this, exec_eval_level)); + execution_contexts.push_back(make_unique(ps, this)); parse_execution_context_t *ctx = execution_contexts.back().get(); int result = ctx->eval_node(node, scope_block, io); diff --git a/src/parser.h b/src/parser.h index 8be14ef2d..57a6c2a2c 100644 --- a/src/parser.h +++ b/src/parser.h @@ -185,6 +185,8 @@ class parser_t { job_list_t my_job_list; /// The list of blocks std::vector> 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?