From 789261a40caf00ad352c9a2cb3a01b0de2e4f19b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 28 Jul 2021 13:44:44 -0700 Subject: [PATCH] Stop storing is_breakpoint inside the parser This can also be trivially computed from the block list. --- src/builtin_status.cpp | 2 +- src/parser.cpp | 23 +++++++++-------------- src/parser.h | 6 +++--- src/reader.cpp | 2 +- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/builtin_status.cpp b/src/builtin_status.cpp index 876c6d0a4..2d873523c 100644 --- a/src/builtin_status.cpp +++ b/src/builtin_status.cpp @@ -414,7 +414,7 @@ maybe_t 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: { diff --git a/src/parser.cpp b/src/parser.cpp index a43722c5e..e6b46bb86 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -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 parser_t::get_function_name(int level) { if (level == 0) { // Return the function name for the level preceding the most recent breakpoint. If there diff --git a/src/parser.h b/src/parser.h index a48981a6e..64731f551 100644 --- a/src/parser.h +++ b/src/parser.h @@ -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 { /// 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; diff --git a/src/reader.cpp b/src/reader.cpp index afee61526..66a4c61a9 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -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 {