Stop storing is_breakpoint inside the parser

This can also be trivially computed from the block list.
This commit is contained in:
ridiculousfish
2021-07-28 13:44:44 -07:00
parent b914c94cc1
commit 789261a40c
4 changed files with 14 additions and 19 deletions

View File

@@ -414,7 +414,7 @@ maybe_t<int> builtin_status(parser_t &parser, io_streams_t &streams, const wchar
}
case STATUS_IS_BREAKPOINT: {
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
retval = parser.libdata().is_breakpoint ? 0 : 1;
retval = parser.is_breakpoint() ? 0 : 1;
break;
}
case STATUS_IS_LOGIN: {

View File

@@ -136,10 +136,6 @@ block_t *parser_t::push_block(block_t &&block) {
new_current.src_filename = intern(filename);
}
if (type == block_type_t::breakpoint) {
libdata().is_breakpoint = true;
}
if (new_current.type() != block_type_t::top) {
bool shadow = (type == block_type_t::function_call);
vars().push(shadow);
@@ -161,16 +157,6 @@ void parser_t::pop_block(const block_t *expected) {
block_list.pop_front();
if (old.wants_pop_env) vars().pop();
// Are we still in a breakpoint?
bool new_is_breakpoint = false;
for (const auto &b : block_list) {
if (b.type() == block_type_t::breakpoint) {
new_is_breakpoint = true;
break;
}
}
libdata().is_breakpoint = new_is_breakpoint;
}
const wchar_t *parser_t::get_block_desc(block_type_t block) {
@@ -419,6 +405,15 @@ bool parser_t::is_block() const {
return false;
}
bool parser_t::is_breakpoint() const {
for (const auto &b : block_list) {
if (b.type() == block_type_t::breakpoint) {
return true;
}
}
return false;
}
maybe_t<wcstring> parser_t::get_function_name(int level) {
if (level == 0) {
// Return the function name for the level preceding the most recent breakpoint. If there

View File

@@ -169,9 +169,6 @@ struct library_data_t {
/// Whether we are running a subshell command.
bool is_subshell{false};
/// Whether we are running due to a `breakpoint` command.
bool is_breakpoint{false};
/// Whether we are running an event handler. This is not a bool because we keep count of the
/// event nesting level.
int is_event{0};
@@ -341,6 +338,9 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
/// This supports 'status is-block'.
bool is_block() const;
/// \return whether we have a breakpoint block.
bool is_breakpoint() const;
/// Returns the block at the given index. 0 corresponds to the innermost block. Returns nullptr
/// when idx is at or equal to the number of blocks.
const block_t *block_at_index(size_t idx) const;

View File

@@ -2747,7 +2747,7 @@ static int read_i(parser_t &parser) {
conf.autosuggest_ok = true;
conf.expand_abbrev_ok = true;
if (parser.libdata().is_breakpoint && function_exists(DEBUG_PROMPT_FUNCTION_NAME, parser)) {
if (parser.is_breakpoint() && function_exists(DEBUG_PROMPT_FUNCTION_NAME, parser)) {
conf.left_prompt_cmd = DEBUG_PROMPT_FUNCTION_NAME;
conf.right_prompt_cmd = wcstring{};
} else {