mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 21:21:15 -03:00
Switch executing_node_idx to storing a tnode_t
Avoids annoying index<->node conversions.
This commit is contained in:
@@ -1120,7 +1120,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
|||||||
scoped_push<int> saved_eval_level(&eval_level, eval_level + 1);
|
scoped_push<int> saved_eval_level(&eval_level, eval_level + 1);
|
||||||
|
|
||||||
// Save the node index.
|
// Save the node index.
|
||||||
scoped_push<node_offset_t> saved_node_offset(&executing_node_idx, this->get_offset(job_node));
|
scoped_push<tnode_t<grammar::job>> saved_node(&executing_job_node, job_node);
|
||||||
|
|
||||||
// Profiling support.
|
// Profiling support.
|
||||||
long long start_time = 0, parse_time = 0, exec_time = 0;
|
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<g::job_lis
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_execution_context_t::line_offset_of_node_at_offset(node_offset_t requested_index) {
|
int parse_execution_context_t::line_offset_of_node(tnode_t<g::job> node) {
|
||||||
// If we're not executing anything, return -1.
|
// If we're not executing anything, return -1.
|
||||||
if (requested_index == NODE_OFFSET_INVALID) {
|
if (!node) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If for some reason we're executing a node without source, return -1.
|
// If for some reason we're executing a node without source, return -1.
|
||||||
const parse_node_t &node = tree().at(requested_index);
|
auto range = node.source_range();
|
||||||
if (!node.has_source()) {
|
if (!range) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t char_offset = tree().at(requested_index).source_start;
|
return this->line_offset_of_character_at_offset(range->start);
|
||||||
return this->line_offset_of_character_at_offset(char_offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_execution_context_t::line_offset_of_character_at_offset(size_t offset) {
|
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 parse_execution_context_t::get_current_line_number() {
|
||||||
int line_number = -1;
|
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) {
|
if (line_offset >= 0) {
|
||||||
// The offset is 0 based; the number is 1 based.
|
// The offset is 0 based; the number is 1 based.
|
||||||
line_number = line_offset + 1;
|
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 parse_execution_context_t::get_current_source_offset() const {
|
||||||
int result = -1;
|
int result = -1;
|
||||||
if (executing_node_idx != NODE_OFFSET_INVALID) {
|
if (executing_job_node) {
|
||||||
const parse_node_t &node = tree().at(executing_node_idx);
|
if (auto range = executing_job_node.source_range()) {
|
||||||
if (node.has_source()) {
|
result = static_cast<int>(range->start);
|
||||||
result = static_cast<int>(node.source_start);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ class parse_execution_context_t {
|
|||||||
parser_t *const parser;
|
parser_t *const parser;
|
||||||
// parse_error_list_t errors;
|
// parse_error_list_t errors;
|
||||||
int eval_level;
|
int eval_level;
|
||||||
// The currently executing node index, used to indicate the line number.
|
// The currently executing job node, used to indicate the line number.
|
||||||
node_offset_t executing_node_idx = NODE_OFFSET_INVALID;
|
tnode_t<grammar::job> executing_job_node{};
|
||||||
// Cached line number information.
|
// Cached line number information.
|
||||||
size_t cached_lineno_offset = 0;
|
size_t cached_lineno_offset = 0;
|
||||||
int cached_lineno_count = 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<grammar::job> job_node,
|
parse_execution_result_t populate_job_from_job_node(job_t *j, tnode_t<grammar::job> job_node,
|
||||||
const block_t *associated_block);
|
const block_t *associated_block);
|
||||||
|
|
||||||
// Returns the line number of the node at the given index, indexed from 0. Not const since it
|
// Returns the line number of the node. Not const since it touches cached_lineno_offset.
|
||||||
// touches cached_lineno_offset.
|
int line_offset_of_node(tnode_t<grammar::job> node);
|
||||||
int line_offset_of_node_at_offset(node_offset_t idx);
|
|
||||||
int line_offset_of_character_at_offset(size_t char_idx);
|
int line_offset_of_character_at_offset(size_t char_idx);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user