diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index abcf2f9a1..050d01891 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -1120,7 +1120,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t jo scoped_push saved_eval_level(&eval_level, eval_level + 1); // Save the node index. - scoped_push saved_node_offset(&executing_node_idx, this->get_offset(job_node)); + scoped_push> saved_node(&executing_job_node, job_node); // Profiling support. long long start_time = 0, parse_time = 0, exec_time = 0; @@ -1305,20 +1305,19 @@ parse_execution_result_t parse_execution_context_t::eval_node(tnode_t node) { // If we're not executing anything, return -1. - if (requested_index == NODE_OFFSET_INVALID) { + if (!node) { return -1; } // If for some reason we're executing a node without source, return -1. - const parse_node_t &node = tree().at(requested_index); - if (!node.has_source()) { + auto range = node.source_range(); + if (!range) { return -1; } - size_t char_offset = tree().at(requested_index).source_start; - return this->line_offset_of_character_at_offset(char_offset); + return this->line_offset_of_character_at_offset(range->start); } int parse_execution_context_t::line_offset_of_character_at_offset(size_t offset) { @@ -1357,7 +1356,7 @@ int parse_execution_context_t::line_offset_of_character_at_offset(size_t offset) int parse_execution_context_t::get_current_line_number() { int line_number = -1; - int line_offset = this->line_offset_of_node_at_offset(this->executing_node_idx); + int line_offset = this->line_offset_of_node(this->executing_job_node); if (line_offset >= 0) { // The offset is 0 based; the number is 1 based. line_number = line_offset + 1; @@ -1367,10 +1366,9 @@ int parse_execution_context_t::get_current_line_number() { int parse_execution_context_t::get_current_source_offset() const { int result = -1; - if (executing_node_idx != NODE_OFFSET_INVALID) { - const parse_node_t &node = tree().at(executing_node_idx); - if (node.has_source()) { - result = static_cast(node.source_start); + if (executing_job_node) { + if (auto range = executing_job_node.source_range()) { + result = static_cast(range->start); } } return result; diff --git a/src/parse_execution.h b/src/parse_execution.h index 17e178fcc..7b99691a9 100644 --- a/src/parse_execution.h +++ b/src/parse_execution.h @@ -33,8 +33,8 @@ class parse_execution_context_t { parser_t *const parser; // parse_error_list_t errors; int eval_level; - // The currently executing node index, used to indicate the line number. - node_offset_t executing_node_idx = NODE_OFFSET_INVALID; + // The currently executing job node, used to indicate the line number. + tnode_t executing_job_node{}; // Cached line number information. size_t cached_lineno_offset = 0; int cached_lineno_count = 0; @@ -123,9 +123,8 @@ class parse_execution_context_t { parse_execution_result_t populate_job_from_job_node(job_t *j, tnode_t job_node, const block_t *associated_block); - // Returns the line number of the node at the given index, indexed from 0. Not const since it - // touches cached_lineno_offset. - int line_offset_of_node_at_offset(node_offset_t idx); + // Returns the line number of the node. Not const since it touches cached_lineno_offset. + int line_offset_of_node(tnode_t node); int line_offset_of_character_at_offset(size_t char_idx); public: