remove get_raw_type from public interface

users of the library never need to know this
master
Daniel Kolesa 2021-04-07 00:30:39 +02:00
parent 4da0cb54a8
commit 2de2c9b46c
6 changed files with 17 additions and 13 deletions

View File

@ -19,7 +19,6 @@ struct alias;
struct command; struct command;
struct LIBCUBESCRIPT_EXPORT ident { struct LIBCUBESCRIPT_EXPORT ident {
int get_raw_type() const;
ident_type get_type() const; ident_type get_type() const;
std::string_view get_name() const; std::string_view get_name() const;
int get_index() const; int get_index() const;
@ -54,9 +53,9 @@ struct LIBCUBESCRIPT_EXPORT ident {
bool is_persistent(state &cs) const; bool is_persistent(state &cs) const;
protected: protected:
ident() = default; friend struct ident_p;
friend struct internal_state; ident() = default;
struct ident_impl *p_impl{}; struct ident_impl *p_impl{};
}; };

View File

@ -1108,7 +1108,7 @@ static void compile_and_or(
} }
if (!more) { if (!more) {
gs.code.push_back( gs.code.push_back(
((id->get_raw_type() == ID_AND) ((ident_p{*id}.impl().p_type == ID_AND)
? BC_INST_TRUE : BC_INST_FALSE) | ret_code(rettype) ? BC_INST_TRUE : BC_INST_FALSE) | ret_code(rettype)
); );
} else { } else {
@ -1140,7 +1140,7 @@ static void compile_and_or(
); );
gs.code.push_back(numargs); gs.code.push_back(numargs);
} else { } else {
std::uint32_t op = (id->get_raw_type() == ID_AND) std::uint32_t op = (ident_p{*id}.impl().p_type == ID_AND)
? (BC_INST_JUMP_RESULT | BC_INST_FLAG_FALSE) ? (BC_INST_JUMP_RESULT | BC_INST_FLAG_FALSE)
: (BC_INST_JUMP_RESULT | BC_INST_FLAG_TRUE); : (BC_INST_JUMP_RESULT | BC_INST_FLAG_TRUE);
gs.code.push_back(op); gs.code.push_back(op);
@ -1271,7 +1271,7 @@ noid:
} }
gs.code.push_back(BC_INST_RESULT); gs.code.push_back(BC_INST_RESULT);
} else { } else {
switch (id->get_raw_type()) { switch (ident_p{*id}.impl().p_type) {
case ID_ALIAS: case ID_ALIAS:
compile_alias( compile_alias(
gs, static_cast<alias *>(id), more gs, static_cast<alias *>(id), more

View File

@ -156,10 +156,6 @@ void alias_stack::set_alias(alias *a, thread_state &ts, any_value &v) {
/* public interface */ /* public interface */
LIBCUBESCRIPT_EXPORT int ident::get_raw_type() const {
return p_impl->p_type;
}
LIBCUBESCRIPT_EXPORT ident_type ident::get_type() const { LIBCUBESCRIPT_EXPORT ident_type ident::get_type() const {
if (p_impl->p_type > ID_ALIAS) { if (p_impl->p_type > ID_ALIAS) {
return ident_type::SPECIAL; return ident_type::SPECIAL;

View File

@ -135,6 +135,15 @@ struct command_impl: ident_impl, command {
bool ident_is_used_arg(ident *id, thread_state &ts); bool ident_is_used_arg(ident *id, thread_state &ts);
struct ident_p {
ident_p(ident &id): ip{&id} {}
ident_impl &impl() { return *ip->p_impl; }
void impl(ident_impl *impl) { ip->p_impl = impl; }
ident *ip;
};
} /* namespace cubescript */ } /* namespace cubescript */
#endif #endif

View File

@ -22,7 +22,7 @@ internal_state::internal_state(alloc_func af, void *data):
internal_state::~internal_state() { internal_state::~internal_state() {
for (auto &p: idents) { for (auto &p: idents) {
destroy(p.second->p_impl); destroy(&ident_p{*p.second}.impl());
} }
bcode_free_empty(this, empty); bcode_free_empty(this, empty);
destroy(strman); destroy(strman);
@ -48,7 +48,7 @@ ident *internal_state::add_ident(ident *id, ident_impl *impl) {
if (!id) { if (!id) {
return nullptr; return nullptr;
} }
id->p_impl = impl; ident_p{*id}.impl(impl);
idents[id->get_name()] = id; idents[id->get_name()] = id;
impl->p_index = int(identmap.size()); impl->p_index = int(identmap.size());
identmap.push_back(id); identmap.push_back(id);

View File

@ -1116,7 +1116,7 @@ noid:
}; };
} }
result.force_none(); result.force_none();
switch (id->get_raw_type()) { switch (ident_p{*id}.impl().p_type) {
default: default:
if (!ident_is_callable(id)) { if (!ident_is_callable(id)) {
args.resize(offset - 1, any_value{cs}); args.resize(offset - 1, any_value{cs});