mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 09:58:54 +08:00
Switch executing_node_idx to storing a tnode_t
Avoids annoying index<->node conversions.
This commit is contained in:
parent
c3f1961e36
commit
8251d949f1
@ -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);
|
||||
|
||||
// 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.
|
||||
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;
|
||||
}
|
||||
|
||||
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 (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<int>(node.source_start);
|
||||
if (executing_job_node) {
|
||||
if (auto range = executing_job_node.source_range()) {
|
||||
result = static_cast<int>(range->start);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -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<grammar::job> 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<grammar::job> 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<grammar::job> node);
|
||||
int line_offset_of_character_at_offset(size_t char_idx);
|
||||
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user