From e644674724cd56007e226c24f2d1c41c4d42a7c7 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Sun, 11 Apr 2021 18:46:45 +0200 Subject: [PATCH] hide internal_state from all public headers --- include/cubescript/cubescript/state.hh | 4 ++-- include/cubescript/cubescript/value.hh | 2 -- src/cs_bcode.hh | 2 ++ src/cs_state.cc | 19 +++++++++---------- src/cs_strman.cc | 6 ------ 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/include/cubescript/cubescript/state.hh b/include/cubescript/cubescript/state.hh index 63fe41c..d021c7f 100644 --- a/include/cubescript/cubescript/state.hh +++ b/include/cubescript/cubescript/state.hh @@ -127,6 +127,8 @@ struct LIBCUBESCRIPT_EXPORT state { private: friend struct state_p; + LIBCUBESCRIPT_LOCAL state(void *is); + hook_func set_call_hook(hook_func func); command &new_command( @@ -139,8 +141,6 @@ private: return static_cast(data)->alloc(p, os, ns); } - LIBCUBESCRIPT_LOCAL state(internal_state *s); - void *alloc(void *ptr, size_t olds, size_t news); struct thread_state *p_tstate = nullptr; diff --git a/include/cubescript/cubescript/value.hh b/include/cubescript/cubescript/value.hh index 9f92efd..f5d6d9a 100644 --- a/include/cubescript/cubescript/value.hh +++ b/include/cubescript/cubescript/value.hh @@ -7,7 +7,6 @@ namespace cubescript { -struct internal_state; struct ident; struct LIBCUBESCRIPT_EXPORT bcode_ref { @@ -42,7 +41,6 @@ struct LIBCUBESCRIPT_EXPORT string_ref { friend struct string_pool; string_ref() = delete; - string_ref(internal_state *cs, std::string_view str); string_ref(state &cs, std::string_view str); string_ref(string_ref const &ref); diff --git a/src/cs_bcode.hh b/src/cs_bcode.hh index be4dd41..b84807e 100644 --- a/src/cs_bcode.hh +++ b/src/cs_bcode.hh @@ -8,6 +8,8 @@ namespace cubescript { +struct internal_state; + struct bcode { std::uint32_t init; diff --git a/src/cs_state.cc b/src/cs_state.cc index f1af81e..d83a9bc 100644 --- a/src/cs_state.cc +++ b/src/cs_state.cc @@ -63,7 +63,7 @@ ident &internal_state::new_ident(state &cs, std::string_view name, int flags) { }; } auto *inst = create( - cs, string_ref{this, name}, flags + cs, string_ref{cs, name}, flags ); id = add_ident(inst, inst); } @@ -280,7 +280,8 @@ LIBCUBESCRIPT_EXPORT void state::destroy() { p_tstate = nullptr; } -state::state(internal_state *s) { +state::state(void *is) { + auto *s = static_cast(is); p_tstate = s->create(s); p_tstate->pstate = this; p_tstate->istate = s; @@ -422,8 +423,7 @@ LIBCUBESCRIPT_EXPORT integer_var &state::new_ivar( std::string_view n, integer_type v, bool read_only, var_type vtp ) { auto *iv = p_tstate->istate->create( - string_ref{p_tstate->istate, n}, v, - var_flags(read_only, vtp) + string_ref{*this, n}, v, var_flags(read_only, vtp) ); try { var_name_check(*this, p_tstate->istate->get_ident(n), n); @@ -439,8 +439,7 @@ LIBCUBESCRIPT_EXPORT float_var &state::new_fvar( std::string_view n, float_type v, bool read_only, var_type vtp ) { auto *fv = p_tstate->istate->create( - string_ref{p_tstate->istate, n}, v, - var_flags(read_only, vtp) + string_ref{*this, n}, v, var_flags(read_only, vtp) ); try { var_name_check(*this, p_tstate->istate->get_ident(n), n); @@ -456,8 +455,7 @@ LIBCUBESCRIPT_EXPORT string_var &state::new_svar( std::string_view n, std::string_view v, bool read_only, var_type vtp ) { auto *sv = p_tstate->istate->create( - string_ref{p_tstate->istate, n}, string_ref{p_tstate->istate, v}, - var_flags(read_only, vtp) + string_ref{*this, n}, string_ref{*this, v}, var_flags(read_only, vtp) ); try { var_name_check(*this, p_tstate->istate->get_ident(n), n); @@ -517,7 +515,7 @@ LIBCUBESCRIPT_EXPORT void state::set_alias( throw error{*this, "cannot alias invalid name '%s'", name.data()}; } else { auto *a = p_tstate->istate->create( - *this, string_ref{p_tstate->istate, name}, std::move(v), + *this, string_ref{*this, name}, std::move(v), p_tstate->ident_flags ); p_tstate->istate->add_ident(a, a); @@ -588,7 +586,8 @@ LIBCUBESCRIPT_EXPORT command &state::new_command( } auto &is = *p_tstate->istate; auto *cmd = is.create( - string_ref{&is, name}, string_ref{&is, args}, nargs, std::move(func) + string_ref{*this, name}, string_ref{*this, args}, + nargs, std::move(func) ); /* we can set these builtins */ command **bptrs[] = { diff --git a/src/cs_strman.cc b/src/cs_strman.cc index 401035b..c573b2f 100644 --- a/src/cs_strman.cc +++ b/src/cs_strman.cc @@ -122,12 +122,6 @@ std::string_view str_managed_view(char const *str) { /* strref implementation */ -LIBCUBESCRIPT_EXPORT string_ref::string_ref( - internal_state *cs, std::string_view str -) { - p_str = cs->strman->add(str); -} - LIBCUBESCRIPT_EXPORT string_ref::string_ref(state &cs, std::string_view str) { p_str = state_p{cs}.ts().istate->strman->add(str); }