From fdcc8a09e989e05e8a1ba8622bacec2760cd0440 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Sun, 9 May 2021 20:01:47 +0200 Subject: [PATCH] remove gap property from stack_state --- include/cubescript/cubescript/error.hh | 13 ++----------- include/cubescript/cubescript/util.hh | 6 ++++-- src/cs_error.cc | 19 ++++++------------- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/include/cubescript/cubescript/error.hh b/include/cubescript/cubescript/error.hh index 58fe24e..6a4b905 100644 --- a/include/cubescript/cubescript/error.hh +++ b/include/cubescript/cubescript/error.hh @@ -38,13 +38,13 @@ struct LIBCUBESCRIPT_EXPORT stack_state { struct node { node const *next; /**< @brief Next level. */ struct ident const *id; /**< @brief The ident of this level. */ - int index; /**< @brief The level index. */ + std::size_t index; /**< @brief The level index. */ }; stack_state() = delete; /** @brief Construct the stack state. */ - stack_state(state &cs, node *nd = nullptr, bool gap = false); + stack_state(state &cs, node *nd = nullptr); stack_state(stack_state const &) = delete; @@ -68,18 +68,9 @@ struct LIBCUBESCRIPT_EXPORT stack_state { /** @brief Get the pointer to the topmost (current) level. */ node const *get() const; - /** @brief Get whether the stack is incomplete. - * - * A value of `true` means the call stack has a gap in it, i.e. the - * bottommost node has index 1 while the node just above it has index - * greater than 2. - */ - bool gap() const; - private: state &p_state; node *p_node; - bool p_gap; }; /** @brief Represents a Cubescript error. diff --git a/include/cubescript/cubescript/util.hh b/include/cubescript/cubescript/util.hh index 806bd4a..b4c8944 100644 --- a/include/cubescript/cubescript/util.hh +++ b/include/cubescript/cubescript/util.hh @@ -296,15 +296,17 @@ template inline R print_stack(R writer, stack_state const &st) { char buf[32] = {0}; auto nd = st.get(); + std::size_t pindex = 1; while (nd) { auto name = nd->id->name(); *writer++ = ' '; *writer++ = ' '; - if ((nd->index == 1) && st.gap()) { + if ((nd->index == 1) && (pindex > 2)) { *writer++ = '.'; *writer++ = '.'; } - snprintf(buf, sizeof(buf), "%d", nd->index); + pindex = nd->index; + snprintf(buf, sizeof(buf), "%zu", nd->index); char const *p = buf; std::copy(p, p + strlen(p), writer); *writer++ = ')'; diff --git a/src/cs_error.cc b/src/cs_error.cc index c0a9252..4a70057 100644 --- a/src/cs_error.cc +++ b/src/cs_error.cc @@ -9,16 +9,15 @@ namespace cubescript { LIBCUBESCRIPT_EXPORT stack_state::stack_state( - state &cs, node *nd, bool gap + state &cs, node *nd ): - p_state{cs}, p_node{nd}, p_gap{gap} + p_state{cs}, p_node{nd} {} LIBCUBESCRIPT_EXPORT stack_state::stack_state(stack_state &&st): - p_state{st.p_state}, p_node{st.p_node}, p_gap{st.p_gap} + p_state{st.p_state}, p_node{st.p_node} { st.p_node = nullptr; - st.p_gap = false; } LIBCUBESCRIPT_EXPORT stack_state::~stack_state() { @@ -31,9 +30,7 @@ LIBCUBESCRIPT_EXPORT stack_state::~stack_state() { LIBCUBESCRIPT_EXPORT stack_state &stack_state::operator=(stack_state &&st) { p_node = st.p_node; - p_gap = st.p_gap; st.p_node = nullptr; - st.p_gap = false; return *this; } @@ -41,10 +38,6 @@ LIBCUBESCRIPT_EXPORT stack_state::node const *stack_state::get() const { return p_node; } -LIBCUBESCRIPT_EXPORT bool stack_state::gap() const { - return p_gap; -} - static stack_state save_stack(state &cs) { auto &ts = state_p{cs}.ts(); builtin_var *dalias = ts.istate->ivar_dbgalias; @@ -52,14 +45,14 @@ static stack_state save_stack(state &cs) { dalias->value().get_integer(), integer_type(0), integer_type(1000) ); if (!dval) { - return stack_state{cs, nullptr, !!ts.callstack}; + return stack_state{cs, nullptr}; } int total = 0, depth = 0; for (ident_link *l = ts.callstack; l; l = l->next) { total++; } if (!total) { - return stack_state{cs, nullptr, false}; + return stack_state{cs, nullptr}; } stack_state::node *st = ts.istate->create_array( std::min(total, dval) @@ -83,7 +76,7 @@ static stack_state save_stack(state &cs) { nd->next = nullptr; } } - return stack_state{cs, ret, total > dval}; + return stack_state{cs, ret}; } LIBCUBESCRIPT_EXPORT error::error(state &cs, std::string_view msg):