mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-29 05:13:43 +00:00
Migrate function_block name and args into block_t
The goal is to eliminate this block hierarchy.
This commit is contained in:
parent
cd7e8f4103
commit
fec0e40b5e
2 changed files with 13 additions and 9 deletions
|
@ -377,10 +377,10 @@ void parser_t::stack_trace_internal(size_t block_idx, wcstring *buff) const {
|
||||||
case FUNCTION_CALL:
|
case FUNCTION_CALL:
|
||||||
case FUNCTION_CALL_NO_SHADOW: {
|
case FUNCTION_CALL_NO_SHADOW: {
|
||||||
const function_block_t *fb = static_cast<const function_block_t *>(b);
|
const function_block_t *fb = static_cast<const function_block_t *>(b);
|
||||||
append_format(*buff, _(L"in function '%ls'"), fb->name.c_str());
|
append_format(*buff, _(L"in function '%ls'"), fb->function_name.c_str());
|
||||||
// Print arguments on the same line.
|
// Print arguments on the same line.
|
||||||
wcstring args_str;
|
wcstring args_str;
|
||||||
for (const wcstring &arg : fb->args) {
|
for (const wcstring &arg : fb->function_args) {
|
||||||
if (!args_str.empty()) args_str.push_back(L' ');
|
if (!args_str.empty()) args_str.push_back(L' ');
|
||||||
// We can't quote the arguments because we print this in quotes.
|
// We can't quote the arguments because we print this in quotes.
|
||||||
// As a special-case, add the empty argument as "".
|
// As a special-case, add the empty argument as "".
|
||||||
|
@ -437,7 +437,7 @@ const wchar_t *parser_t::is_function(size_t idx) const {
|
||||||
const block_t *b = this->block_at_index(block_idx);
|
const block_t *b = this->block_at_index(block_idx);
|
||||||
if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW) {
|
if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW) {
|
||||||
const function_block_t *fb = static_cast<const function_block_t *>(b);
|
const function_block_t *fb = static_cast<const function_block_t *>(b);
|
||||||
result = fb->name.c_str();
|
result = fb->function_name.c_str();
|
||||||
break;
|
break;
|
||||||
} else if (b->type() == SOURCE) {
|
} else if (b->type() == SOURCE) {
|
||||||
// If a function sources a file, obviously that function's offset doesn't contribute.
|
// If a function sources a file, obviously that function's offset doesn't contribute.
|
||||||
|
@ -500,7 +500,7 @@ const wchar_t *parser_t::current_filename() const {
|
||||||
const block_t *b = this->block_at_index(i);
|
const block_t *b = this->block_at_index(i);
|
||||||
if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW) {
|
if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW) {
|
||||||
const function_block_t *fb = static_cast<const function_block_t *>(b);
|
const function_block_t *fb = static_cast<const function_block_t *>(b);
|
||||||
return function_get_definition_file(fb->name);
|
return function_get_definition_file(fb->function_name);
|
||||||
} else if (b->type() == SOURCE) {
|
} else if (b->type() == SOURCE) {
|
||||||
const source_block_t *sb = static_cast<const source_block_t *>(b);
|
const source_block_t *sb = static_cast<const source_block_t *>(b);
|
||||||
return sb->source_file;
|
return sb->source_file;
|
||||||
|
@ -839,9 +839,10 @@ if_block_t::if_block_t() : block_t(IF) {}
|
||||||
event_block_t::event_block_t(const event_t &evt) : block_t(EVENT), event(evt) {}
|
event_block_t::event_block_t(const event_t &evt) : block_t(EVENT), event(evt) {}
|
||||||
|
|
||||||
function_block_t::function_block_t(wcstring name, wcstring_list_t args, bool shadows)
|
function_block_t::function_block_t(wcstring name, wcstring_list_t args, bool shadows)
|
||||||
: block_t(shadows ? FUNCTION_CALL : FUNCTION_CALL_NO_SHADOW),
|
: block_t(shadows ? FUNCTION_CALL : FUNCTION_CALL_NO_SHADOW) {
|
||||||
name(std::move(name)),
|
this->function_name = std::move(name);
|
||||||
args(std::move(args)) {}
|
this->function_args = std::move(args);
|
||||||
|
}
|
||||||
|
|
||||||
source_block_t::source_block_t(const wchar_t *src) : block_t(SOURCE), source_file(src) {}
|
source_block_t::source_block_t(const wchar_t *src) : block_t(SOURCE), source_file(src) {}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,11 @@ struct block_t {
|
||||||
/// List of event blocks.
|
/// List of event blocks.
|
||||||
event_blockage_list_t event_blocks{};
|
event_blockage_list_t event_blocks{};
|
||||||
|
|
||||||
|
// If this is a function block, the function name and arguments.
|
||||||
|
// Otherwise empty.
|
||||||
|
wcstring function_name{};
|
||||||
|
wcstring_list_t function_args{};
|
||||||
|
|
||||||
block_type_t type() const { return this->block_type; }
|
block_type_t type() const { return this->block_type; }
|
||||||
|
|
||||||
/// Description of the block, for debugging.
|
/// Description of the block, for debugging.
|
||||||
|
@ -94,8 +99,6 @@ struct event_block_t : public block_t {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct function_block_t : public block_t {
|
struct function_block_t : public block_t {
|
||||||
wcstring name;
|
|
||||||
wcstring_list_t args;
|
|
||||||
function_block_t(wcstring name, wcstring_list_t args, bool shadows);
|
function_block_t(wcstring name, wcstring_list_t args, bool shadows);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue